home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a066 / 1.img / POPUPMEN.PRG < prev    next >
Encoding:
Text File  |  1992-03-20  |  1.7 KB  |  80 lines

  1. /*
  2.     Menu.prg
  3.  
  4.     Copyright (c) 1991 Chris Muller and Anton van Straaten
  5. */
  6.  
  7. #include "class(y).ch"
  8. #include "win.ch"
  9.  
  10.  
  11. create class PopupMenu from BaseMenu
  12.     protected:
  13.         instvar window
  14.         instvar width
  15.  
  16.         method menuTop, menuLeft
  17.  
  18.     export:
  19.         method draw
  20.         method addItem
  21.         method exec
  22. endclass
  23.  
  24.  
  25. // this constructor does nothing but pass its parameter up to the superclass
  26. constructor new (aItems), (aItems)
  27. return
  28.  
  29.  
  30. method procedure draw()
  31.     local bottom, right
  32.  
  33.     if ::window == NIL
  34.         bottom := ::menuTop + len(::items) + 1
  35.         right  := ::menuLeft + ::width + 1
  36.         ::window := window():new(::menuTop, ::menuLeft, bottom, right, SNGLBORD)
  37.     end
  38.     ::super:draw()
  39. return
  40.  
  41.  
  42. method function menuTop
  43. return winTop() + ::parent:newMenuPos()
  44.  
  45.  
  46. method function menuLeft
  47. return winLeft() + 2
  48.  
  49.  
  50. method procedure addItem(cLabel, oAction, isActive)
  51.     local nRow
  52.  
  53.     // establish screen row for new option
  54.     if len(::items) == 0
  55.         nRow := 0
  56.     else
  57.         // atail() is a 5.01 function; for 5.0, use:  ::items[len(::items)]
  58.         nRow := atail(::items):nextRow
  59.     end
  60.  
  61.     ::super:addItem(nRow, 0, cLabel, oAction, isActive)
  62.     if ::width == NIL
  63.         // initialize ::width here, since when addItem is invoked by BaseMenu's
  64.         // constructor, the body of Menu's constructor has not yet executed.
  65.         ::width := 0
  66.     end
  67.     ::width := max(::width, len(cLabel))
  68. return
  69.  
  70.  
  71. method procedure exec(oParent)
  72.     // invoke the exec method in the superclass (BaseMenu)
  73.     ::super:exec(oParent)
  74.     ::window:kill()
  75.     ::window := NIL
  76. return
  77.  
  78.  
  79. // eof menu.prg
  80.