Home |
Class PegMenu HMI (Human-Machine Interface) Classes |
Class PegMenuPegMenu is that background object used to display a list of menu items. PegMenu may contain any number of PegMenuButton objects. PegMenu accepts a PegMenuDescription parameter. This description defines the PegMenuButton objects that will initially be created and displayed on the menu. The PegMenuDescription is most often defined statically, or defined by WindowBuilder, but the PegMenuDescription can also be created dynamically during program execution. When dynamically created PegMenuDescriptions are used to create instances of PegMenu, it is important to include the TT_COPY flag in each PegMenuDescription style. By default, the menu descriptions are not copied. PegMenu also provides functions for finding, adding, and removing PegMenuButton objects at any time. This allows PegMenu objects to be altered at run time under program control. PegMenu objects are automatically created by PegMenuBar when top-level menu bar options are selected. PegMenu sizes itself to the size required to display all children. The position of the PegMenu is defined when the menu is displayed. struct PegMenuDescription { const PEGCHAR * pText; PEGUINT wId; PEGUINT wStyle; PegMenuDescription * pSubMenu; }; class PegMenu : public PegThing { public: PegMenu(PegMenuDescription * pDesc, BOOL bPopup = FALSE); virtual PEGINT Message(const PegMessage &Mesg); virtual void Draw(void); PegRect GetMinSize(void); void CloseSiblings(PegMenuButton * pNotMe); PegMenuButton * FindButton(const PEGCHAR * Who); void SetOwner(PegThing * Who); virtual void MenuKeyHandler(int iKey); }; ConstructorThe PegMenu constructor creates a PegMenu object with PegMenuButton children. The children are defined by the PegMenuDescription parameter. Method CloseSiblingsCloses all of the menu items that are siblings of pNotMe. Method DrawOverrides the Draw() function to draw menu border and background. Method FindButtonSearches for a PegMenuButton child with a matching command string. This function is in addition to the normal Find(PEGUINT wId) which may also be used to find specific PegMenu command buttons. The pointer returned can be used to Enable/Disable/Remove the PegMenuButton. Method GetMinSizeExamines all child objects of the PegMenu to determine the minimum size required to display all children. The resulting rectangle is returned. This result can be used to intelligently position the PegMenu. Method MessageCatches the PM_SHOW message. When this message is receive the menu positions child PegMenuButtons for proper display. Method SetOwnerAssigns the owner of the menu. Menu command signals are routed to the PegMenu owner if this value is not NULL. This is often required as PegMenu objects are usually added directly to PegPresentationManager. This is done since the PegMenu may extend beyond the borders of the owner window and it is not intended that the PegMenu be clipped to the borders of the owner window. Assigning the PegMenu an owner routes menu commands to the owner window, rather than to the PegMenu parent, which in the case described would be PegPresentationManager. Examples:The following are examples of PegMenuBar, PegMenu, and PegMenuButton: The following example creates a PegMenu from a PegMenuDescription. The menu is positioned at the top left corner of the window client area, and the menu owner is assigned. The menu is then added to PegPresentationManager: static PegMenuDescription FileMenu[] = { {"Exit", IDB_DEMO_EXIT, AF_ENABLED, NULL}, {"Close", IDB_CLOSE, AF_ENABLED, NULL}, {"Save", 0, 0, NULL}, {"", 0, BF_SEPARATOR, NULL}, {"Restore", IDB_RESTORE, AF_ENABLED, NULL}, {"Minimize", IDB_MINIMIZE, AF_ENABLED, NULL}, {"Maximize", IDB_MAXIMIZE, AF_ENABLED, NULL}, {"", 0, 0, NULL} }; void MyWindow::PopUpFileMenu(void) { PegMenu * pMenu = new PegMenu(FileMenu); PegRect SizeRect = pMenu->GetMinSize(); SizeRect.MoveTo(mClient.wLeft, mClient.wTop); pMenu->Resize(SizeRect); pMenu->SetOwner(this); Presentation()->Add(pMenu); } In the above example, the PegMenu should be removed when a menu command is received or the owner window loses input focus.
|