home *** CD-ROM | disk | FTP | other *** search
- /*
- Menu.prg
-
- Copyright (c) 1991 Chris Muller and Anton van Straaten
- */
-
- #include "class(y).ch"
- #include "win.ch"
-
-
- create class PopupMenu from BaseMenu
- protected:
- instvar window
- instvar width
-
- method menuTop, menuLeft
-
- export:
- method draw
- method addItem
- method exec
- endclass
-
-
- // this constructor does nothing but pass its parameter up to the superclass
- constructor new (aItems), (aItems)
- return
-
-
- method procedure draw()
- local bottom, right
-
- if ::window == NIL
- bottom := ::menuTop + len(::items) + 1
- right := ::menuLeft + ::width + 1
- ::window := window():new(::menuTop, ::menuLeft, bottom, right, SNGLBORD)
- end
- ::super:draw()
- return
-
-
- method function menuTop
- return winTop() + ::parent:newMenuPos()
-
-
- method function menuLeft
- return winLeft() + 2
-
-
- method procedure addItem(cLabel, oAction, isActive)
- local nRow
-
- // establish screen row for new option
- if len(::items) == 0
- nRow := 0
- else
- // atail() is a 5.01 function; for 5.0, use: ::items[len(::items)]
- nRow := atail(::items):nextRow
- end
-
- ::super:addItem(nRow, 0, cLabel, oAction, isActive)
- if ::width == NIL
- // initialize ::width here, since when addItem is invoked by BaseMenu's
- // constructor, the body of Menu's constructor has not yet executed.
- ::width := 0
- end
- ::width := max(::width, len(cLabel))
- return
-
-
- method procedure exec(oParent)
- // invoke the exec method in the superclass (BaseMenu)
- ::super:exec(oParent)
- ::window:kill()
- ::window := NIL
- return
-
-
- // eof menu.prg
-