Class XbpMenu() Foundation

Class function of the XbpMenu class.


The XbpMenu class provides objects which display and manage vertical menus (popup menus). A popup menu can be displayed by itself (perhaps as a context menu activated by the right mouse button) or it can be part of a menu system that controls the program within a window. The menu system of a window always starts with a horizontal menu bar displayed under the title bar of the window. A horizontal menu is managed by objects of the XbpMenubar class.

The XbpMenu class is derived from XbpMenuBar and makes use of all the characteristics defined in XbpMenuBar. Constructing a popup menu is identical to constructing a horizontal menu. To define a popup menu, menu items must be specified for the menu. This is done using the method :addItem() that is described in the XbpMenuBar class (see the XbpMenuBar class for more information).

Class methods
Creates an instance of the XbpMenu class.

The instance variables in this group configure system resources. If changes are made to the default values, they must be made before the :create() method is executed or :configure() must be called to activate the changes.

Title of the popup menu.
Life cycle
Requests system resources for the XbpMenu object.
Reconfigures the XbpMenu object after :create() has been executed.
Releases the system resources of the XbpMenu object.
Disables the Xbase Part.
Enables the Xbase Part.
Returns the title of the menu.
Displays and activates a popup menu.
Changes the title of the XbpMenu object.
Returns the current position of the menu.
Returns the current size of the menu.
A context menu

// This example demonstrates the process for creating 
// a context menu using an XbpMenu object. An MLE is 
// created and the methods of the MLE can be executed 
// using the context menu. The program itself is a simple 
// text editor that reads a file, edits the text, and can 
// write the text back to the file. 

#include "" 
#include "" 

PROCEDURE Main( cFileName ) 
   LOCAL nEvent, mp1, mp2, oXbp 
   LOCAL cText, oMLE, oMenu 

   IF Empty(cFileName) .OR. ! File(cFileName) 
      WAIT "File name must be specified" 

   SetAppWindow():mouseMode := XBPCRT_MOUSEMODE_PM 

   // Create MLE, specify position using :create() 
   oMLE := XbpMLE():new():create( ,, {50,50}, {550,300} ) 

   // Copy file to edit buffer 
   oMLE:setData( MemoRead( cFileName ) ) 

   // Create context menu for MLE. Parent is oMLE 
   oMenu := XbpMenu():new( oMLE ):create() 
   oMenu:AddItem( { "~Delete", { || oMLE:deleteMarked() } } ) 
   oMenu:AddItem( { "~Cut"   , { || oMLE:cutMarked()    } } ) 
   oMenu:AddItem( { "C~opy"  , { || oMLE:copyMarked()   } } ) 
   oMenu:AddItem( { "~Paste" , { || oMLE:pasteMarked()  } } ) 
   oMenu:AddItem( { "~Undo"  , { || oMLE:undo()         } } ) 
   oMenu:AddItem( { "~Save"  , { || MemoWrit( cFileName, ; 
                                       oMLE:getData() ) } } ) 
   // Separating line 
   oMenu:AddItem( {NIL, NIL, XBPMENUBAR_MIS_SEPARATOR, 0  } ) 

   // Access to MLE via method :setParent() 
   // obj in the code block is oMenu 
   oMenu:AddItem ( { "C~lear", { |mp1, mp2, obj| ; 
                     obj:setParent():clear() } } ) 

   // Context menu appears when the right mouse button is clicked 
   // at the mouse pointer with "Cut" as the default 
   oMLE:RbDown  := ; 
      { |mp1, mp2, obj| oMenu:PopUp ( obj, mp1, 2 , ; 

   // Event loop 
   nEvent := 0 
   DO WHILE nEvent <> xbeP_Close 
      nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
      oXbp:HandleEvent( nEvent, mp1, mp2 ) 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.