KwikPeg Manuals
Home
PegMenu
Examples
Examples
Index
Index


Members
Styles
(none)
Signals
(none)
Overview Derived from class PegThing

The PegMenu class describes an object which displays a list of menu items. Each PegMenu object can contain any number of PegMenuButton objects, the actual menu items. Each of these menu items is described by a PegMenuDescription structure.

The PegMenu object creates and displays all of the menu items present on its menu. The PegMenuDescription specifications are most often defined statically. These static menu descriptions can be generated automatically using the PEG Window Builder.

Alternatively, the PegMenuDescription specifications can be constructed dynamically by your application. In this case, be sure to use the TT_COPY style flag in each PegMenuDescription so that a copy of the menu text will be kept with the menu object.

The PegMenu class provides member functions for finding, adding and removing PegMenuButton objects at any time. PegMenu objects can therefore be easily altered under program control.

PegMenu objects are automatically created by each PegMenuBar object when top-level menu bar options are selected. Each PegMenu object adjusts itself to the size required to display it menu item children. The final position of the PegMenu object is determined when the menu is actually displayed.

The signals generated by each PegMenuButton object on a menu are normally sent to the parent of the PegMenu object. Alternatively, you can use the SetOwner() member function to identify a specific object to which the menu button signals are to be directed.



 See Also

Menu Description Structure (PegMenuDescription)

PegMenuBar

PegMenuButton


Top of page


 Members

Constructors:

PegMenu(PegMenuDescription *pDesc,
  BOOL bPopup = FALSE)

The PegMenu constructor creates a PegMenu object with PegMenuButton children. The children are defined by the PegMenuDescription parameter. pDesc is a pointer to an array of PegMenuDescription structures. The array must be terminated by structure whose wId and wStyle members are both 0.

 

Public Functions:

void CloseSiblings(PegMenuButton *pNotMe)

This function closes all of the menu items that are siblings of the PegMenuButton object referenced by parameter pNotMe.

virtual void Draw(void)

The PegMenu class overrides the Draw() function to draw the menu border and background.

PegMenuButton *FindButton(const PEGCHAR *Who)

This function searches the PegMenu object for a PegMenuButton child with a menu text string matching string Who. This function augments the normal Find() function which can also be used to find specific PegMenuButton menu buttons.

The returned PegMenuButton object pointer can be used to enable, disable or remove the menu button.

PegRect GetMinSize(void)

This function examines all child objects of the PegMenu object to determine the minimum size of rectangle required to display all menu children. The returned rectangle can be used to intelligently position the PegMenu object.

virtual void MenuKeyHandler(
  SIGNED iKey, LONG lFlags)

This function is the default input key handler for the PegMenu class. Parameter iKey is the key code and parameter lFlags is the key shift status sent by the input device driver in a PM_KEY message.

This function checks for keys (such as the TAB and ARROW keys) which can cause an input focus change. These keys are handled explicitly by this function.

This function is only present if your KwikPeg configuration has the following option enabled:
  Input: Keyboard

virtual SIGNED Message(const PegMessage &Mesg)

The PegMenu class catches the PM_SHOW message. When this message is received, the PegMenu message handler adjusts the position of each PegMenuButton child to ensure its proper display.

void SetOwner(PegThing *Who)

This function assigns object Who as the owner of the PegMenu object. If owner Who is not NULL, menu command signals will be routed to owner Who, rather than to the parent of the PegMenu object.

PegMenu objects are usually added directly to the PegPresentationManager so that the PegMenu object can extend beyond the borders of its owner. If the PegMenu object was added to the window with which it is naturally associated, the PegMenu menu would be clipped to the borders of that window. By adding the PegMenu object to the PegPresentationManager, this problem is resolved. The intended window is then made the owner of the PegMenu object so that menu commands are routed to it, rather than to the PegPresentationManager, the menu's real parent.


Top of page


 Examples

The following are examples of PegMenuBar, PegMenu and PegMenuButton objects:



The following example creates a PegMenu from a PegMenuDescription specification. The menu is positioned at the top left corner of the window's client area. A menu owner is assigned. The menu is then added to the 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);
}

Note:
In the above example, the PegMenu object should be removed when a menu command is received or the owner window loses input focus.




Top of page
KwikPeg Manuals
Home
Index
Index

 
Copyright © 2000-2003