| xHarbour Reference Documentation > Class Reference (textmode) |
![]() |
![]() |
![]() |
Creates a new TopBarMenu object.
TopBarMenu():new( <nRow>, <nLeft>, <nRight> ) --> oTopBarMenu
Function TopBarMenu() returns a TobParMenu object and method :new() initializes it.
Objects of the TopBarMenu class are used to build a text-mode menu system. A TopBarMenu object generally serves as the main menu and displays its menu items horizontally in one row on the screen. Each menu item is provided as a MenuItem() object and added using method :addItem(). The creation of submenus is accomplished with the aid of Popup() menu objects.
When the menu is completely build, it is activated using method :modal() or by passing the TopBarMenu object to function MenuModal().
| See also: | @...GET, MenuItem(), MenuModal(), Popup(), READ, SetColor() |
| Category: | Get system , Object functions |
| Header: | Button.ch |
| Source: | rtl\ttopbar.prg |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example outlines the construction of a text-mode
// menu system with user defined routines. CreateMainMenu()
// returns a TopBarMenu object, CreateSubMenu() builds
// pull-down menus, and MenuSelect() branches to subroutines of
// the program. The menu is activated in a DO WHILE .T. loop.
// This requires a separate Exit routine for program termination.
#include "Button.ch"
#include "Inkey.ch"
PROCEDURE Main
LOCAL oTopBar := CreateMainMenu()
CLS
DO WHILE .T.
MenuModal( oTopBar , 1, ;
MaxRow(), 0, MaxCol(), ;
oTopBar:colorSpec )
ENDDO
RETURN
FUNCTION CreateMainMenu()
LOCAL oMainMenu := TopBarMenu():new( 0, 0, MaxCol() )
LOCAL bMenuBlock := {|o| MenuSelect(o) }
LOCAL cMenuColor := "N/BG,W+/R,GR+/BG,GR+/R,N+/BG,N/BG"
LOCAL aItems
oMainMenu:colorSpec := cMenuColor
aItems := { ;
{ " &Open " , K_ALT_O , "Open routine" , 11 }, ;
{ " &Save " , K_ALT_S , "Save routine" , 12 }, ;
{ MENU_SEPARATOR, , , 13 }, ;
{ " E&xit " , K_ALT_X , "Exit program" , 14 } ;
}
CreateSubMenu( oMainMenu, " &File ", bMenuBlock, aItems )
aItems := { ;
{ " Cop&y " , K_CTRL_INS, "Copy routine" , 21 }, ;
{ " &Paste " , K_SH_INS , "Paste routine" , 22 }, ;
{ MENU_SEPARATOR, , , 23 }, ;
{ " C&ut " , K_SH_DEL , "Cut routine" , 24 }, ;
{ " &Delete " , K_DEL , "Delete routine", 25 } ;
}
CreateSubMenu( oMainMenu, " &Edit ", bMenuBlock, aItems )
aItems := { ;
{ " &Info " , K_F1 , "Help routine" , 31 }, ;
{ " &About " , , "About program" , 32 } ;
}
CreateSubMenu( oMainMenu, " &Help ", bMenuBlock, aItems )
RETURN oMainMenu
FUNCTION CreateSubMenu( oMenu, cMenuItem, bBlock, aItems )
LOCAL aItem, oItem, oSubMenu
oSubMenu := PopUp():new()
oSubMenu:colorSpec := oMenu:colorSpec
FOR EACH aItem IN aItems
oItem := MenuItem():new( aItem[1], ;
bBlock , ;
aItem[2], ;
aItem[3], ;
aitem[4] )
oSubMenu:addItem ( oItem )
NEXT
oItem := MenuItem():new( cMenuItem, oSubMenu )
oMenu:addItem( oItem )
RETURN
PROCEDURE MenuSelect( oMenuItem )
@ 1, 0 CLEAR TO MaxRow(), MaxCol()
SWITCH oMenuItem:ID
CASE 14
ExitRoutine() ; EXIT
DEFAULT
Alert( oMenuItem:message )
END
RETURN
PROCEDURE ExitRoutine
IF Alert( "Exit program?", { "Yes", "No" } ) == 1
QUIT
ENDIF
RETURN
http://www.xHarbour.com