xHarbour Reference Documentation > Class Reference (textmode) xHarbour Developers Network  

TopBarMenu()

Creates a new TopBarMenu object.

Syntax

TopBarMenu():new( <nRow>, <nLeft>, <nRight> ) --> oTopBarMenu

Arguments

<nRow>
This is a numeric value specifying the screen row for displaying the menu bar. It is assigned to the instance variable :row. The range for <nRow> is between 0 and MaxRow().
<nLeft>
This is a numeric value specifying the left screen coordinate of the menu bar. It is assigned to the instance variable :left. Usually, <nLeft> is set to the value 0.
<nRight>
This is a numeric value specifying the right screen coordinate of the menu bar. It is assigned to the instance variable :right. Usually, <nRight> is set to the value of MaxCol().

Return

Function TopBarMenu() returns a TobParMenu object and method :new() initializes it.

Description

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().

Instance variables

:cargo
Instance variable for user-defined purposes.
:colorSpec
Color string for the TopBarMenu display.
:current
Currently selected menu item.
:itemCount
Number of menu items.
:left
Numeric left screen column for display.
:right
Numeric right screen column for display.
:row
Numeric screen row for display.

Menu item methods

:addItem( <oMenuItem> ) --> self
Adds a MenuItem object to a TopBarMenu object.
:delItem( <nItemPos> ) --> self
Deletes a MenuItem object from a TopBarMenu object.
:getFirst() --> nFirstMenuItemPos
Retrieves the ordinal position of the first selectable menu item.
:getItem( <nItemPos> ) --> oMenuItem
Retrieves a MenuItem object from a TopBarMenu object.
:getLast() --> nLastMenuItemPos
Retrieves the ordinal position of the last selectable menu item.
:getNext() --> nNextMenuItemPos
Retrieves the ordinal position of the next selectable menu item.
:getPrev() --> nPrevMenuItemPos
Retrieves the ordinal position of the previous selectable menu item.
:insItem( <nItemPos>, <oMenuItem> ) --> self
Inserts a MenuItem object into a TopBarMenu object.
:setItem( <nItemPos>, <oMenuItem> ) --> self
Replaces a MenuItem object in a TopBarMenu object.

Menu display and selection

:display() --> self
Displays the entire TopBarMenu.
:getAccel( <nKey> ) --> nMenuItemPos
Determines if a key code identifies an accelerator key.
:hitTest( <nMouseRow>, <nMouseCol> ) --> nMenuItemPos
Checks if a menu item is clicked with the mouse.
:modal( ... ) --> nMenuItemID
Activates the menu.
:select( <nItemPos> ) --> nMenuItemPos
Changes the currently selected menu item.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe