Class XbpMenuBar() Foundation

Class function of the XbpMenuBar class.


The XbpMenubar class provides objects which display and manage horizontal menus (menu bars). A menu bar is displayed within a window and is the general access point into the menu system. The menu system can be used to control the program running within the window. The individual items of the menu bar are generally used to access submenus. These submenus are managed by objects of the XbpMenu class.

The pattern for using Xbase Parts normally includes the methods :new() and :create(). When creating menu bar objects there is an additional, easier way to generate XbpMenuBar objects. This is based on the fact that a menu bar must always be installed in a window. For this reason the XbpCrt and XbpDialog classes both include the method :menuBar() that returns a fully functional XbpMenuBar object that is already installed in the window.

After the XbpMenubar object is created, the items of the menu system must be added using the :addItem() method. If they are used, submenus (objects of the XbpMenu class) must be separately created.

The window area in which a menubar object is displayed is maintained automatically by the operating system. Consequently, most member variables and methods inherited from base class XbpWindow have no effect on menubar objects and should not be used.

Class methods
Creates an instance of the XbpMenuBar class.
Life cycle
Requests system resources for the XbpMenuBar object.
Reconfigures the XbpMenuBar object after :create() has been executed.
Releases the system resources of the XbpMenuBar object.
Adds a menu item to the menu.
Determines whether the specified menu item is prefixed with a check mark .
Deletes a single menu item from a menu.
Disables the Xbase Part.
Disables a menu item.
Enables the Xbase Part.
Enables a menu item.
Returns the specified menu item from the menu object.
Inserts a menu item into the menu.
Returns whether the specified menu item currently has a check mark .
Returns whether the specified menu item is currently enabled.
Returns the number of menu items in the menu object.
Sets the default menu item.
Replaces the specified menu item in the menu.
Returns the current position of the menubar.
Returns the current size of the menubar.
Retrieves the handle of a menubar
Returns whether an Xbase Part is enabled.
The user begins with a menu selection
The user has ended the menu selection
Menu item is highlighted
Menu item has been activated
Informs the application that an owner-drawn menubar item needs to be redrawn.
Used by the system to determine the dimensions of an owner-drawn menu item.
Notifies the application about a menu shortcut.
Menu system using Xbase Parts

// This example shows two different ways that a menu 
// can be programmed using Xbase++. A menu bar is installed 
// in an XbpCrt window and two submenus are added to it. 
// The first submenu is programmed procedurally. Control 
// occurs using the :itemSelected callback code block. This 
// design is suitable for porting existing menu systems that 
// are designed using DO..CASE control structures to a 
// GUI application. This maintains as much existing code 
// as possible. The second submenu uses the capabilities 
// of the XbpMenu object for program control and uses code 
// blocks assigned to each menu item. 

#include "" 

   LOCAL nEvent, mp1, mp2, oXbp 
   LOCAL oMenuBar, oSubMenu, aItem 

   Setcolor( "N/W") 

   // Allow use of shortcut keys 
   SetAppWindow():useShortCuts := .T. 

   // Install menu bar in the XbpCrt window 
   oMenuBar := SetAppWindow():MenuBar() 

   // Define submenu in procedural style. 
   // The numeric index of the selected menu item 
   // is passed to the Callback code block -> mp1 
   oSubMenu       := XbpMenu():new(oMenuBar):create() 
   oSubMenu:title := "~Procedural" 
   oSubMenu:addItem( { "Procedure ~1", } ) 
   oSubMenu:addItem( { "Procedure ~2", } ) 
   oSubMenu:itemSelected := {|mp1| MyMenuProcedure( 100+mp1 ) } 
   oMenuBar:addItem( { oSubMenu, NIL } ) 

   // Define submenu in the functional style: 
   // A menu item executes a code block that 
   // calls a function 
   oSubMenu       := XbpMenu():new(oMenuBar):create() 
   oSubMenu:title := "~Functional" 
   oSubMenu:addItem( { "Function ~1", {|| MyFunction1() } } ) 
   oSubMenu:addItem( { "Function ~2", {|| MyFunction2() } } ) 
   oSubMenu:addItem( { "~End"       , {|| MyFunction3() } } ) 

   oMenuBar:addItem( { oSubMenu, NIL } ) 

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

// ************************************************************ 
// Example for integrating an existing menu system into 
// event driven Xbase++ 
PROCEDURE MyMenuProcedure( nMenuSelection ) 
   DO CASE                         // Process usual menu 
   CASE nMenuSelection == 101      // indexes with DO CASE 
   CASE nMenuSelection == 102 

PROCEDURE MyProcedure1() 
   ? "MyProcedure1() was called" 

PROCEDURE MyProcedure2() 
   ? "MyProcedure2() was called" 

// ************************************************************ 
// These functions are called by the menu via code blocks 
FUNCTION MyFunction1() 
   ? "MyFunction1() was called" 

FUNCTION MyFunction2() 
   ? "MyFunction2() was called" 

FUNCTION MyFunction3() 
   ? "MyFunction3() was called -> End of program" 

   // Send message to program: 
   // The user will terminate 
   PostAppEvent( xbeP_Close ) 

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.