Class XbpMenuBar() Foundation

Class function of the XbpMenuBar class.

Superclass
Subclass
Description

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
:new()
Creates an instance of the XbpMenuBar class.
Life cycle
:create()
Requests system resources for the XbpMenuBar object.
:configure()
Reconfigures the XbpMenuBar object after :create() has been executed.
:destroy()
Releases the system resources of the XbpMenuBar object.
Manipulation
:addItem()
Adds a menu item to the menu.
:checkItem()
Determines whether the specified menu item is prefixed with a check mark .
:delItem()
Deletes a single menu item from a menu.
:disable()
Disables the Xbase Part.
:disableItem()
Disables a menu item.
:enable()
Enables the Xbase Part.
:enableItem()
Enables a menu item.
:getItem()
Returns the specified menu item from the menu object.
:insItem()
Inserts a menu item into the menu.
:isItemChecked()
Returns whether the specified menu item currently has a check mark .
:isItemEnabled()
Returns whether the specified menu item is currently enabled.
:numItems()
Returns the number of menu items in the menu object.
:selectItem()
Sets the default menu item.
:setItem()
Replaces the specified menu item in the menu.
Status
:currentPos()
Returns the current position of the menubar.
:currentSize()
Returns the current size of the menubar.
:getHWND()
Retrieves the handle of a menubar
:isEnabled()
Returns whether an Xbase Part is enabled.
Events
:beginMenu
The user begins with a menu selection
:endMenu
The user has ended the menu selection
:itemMarked
Menu item is highlighted
:itemSelected
Menu item has been activated
:drawItem
Informs the application that an owner-drawn menubar item needs to be redrawn.
:measureItem
Used by the system to determine the dimensions of an owner-drawn menu item.
:onMenuKey
Notifies the application about a menu shortcut.
Examples
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 "Appevent.ch" 

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

   Setcolor( "N/W") 
   CLS 

   // 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 ) 
   ENDDO 
RETURN 

// ************************************************************ 
// 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 
        MyProcedure1() 
   CASE nMenuSelection == 102 
        MyProcedure2() 
   ENDCASE 
RETURN 

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

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

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

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

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

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

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.