Home |
Class PegToolBar HMI (Human-Machine Interface) Classes |
Class PegToolBarPegToolBar is a window decoration used to position and display a group of related user objects. These objects could be text or bitmap buttons, user input fields, or any other objects that represent frequently used commands or user data that does not lend itself well to a menu. PegToolBar is designed to work in conjunction with PegDecoratedWindow objects. PegToolBar may be added to any type of object. However, the client area of objects other than PegDecoratedWindow will not properly be reduced unless this is done in the application software. PegToolBar automatically positions and sizes itself to the parent window. PegToolBar may contain any number of PegToolBarPanel objects. It is not recommended that any other objects aside from a PegToolBarPanel be added to a PegToolBar. Any object that is placed on a PegToolBarPanel, and subsequently a PegToolBar, behaves the same way it would if it were added to any other PegThing derived object. For instance, a PegButton derived object sends its PSF_CLICKED message up to the PegToolBarPanel, which in turn posts it to the PegToolBar, which in turn posts the message to its parent, in this case, the PegDecoratedWindow. Therefore, the message is handled within the context of the parent PegDecoratedWindow. This model makes it very easy to handle messages from objects on the tool bar by handling them in the same message loop as all of your other command objects. Also, for example, say you have a PegMenuButton (on the window's menu) and a PegBitmapButton (on the window's tool bar) that share a common ID. Whichever is selected by the end user, the same code will be executed. This makes it very easy to put frequently used commands on a tool bar, and also have them on the menu. class PegToolBar : public PegThing { public: PegToolBar(PEGUINT wID = 0); virtual PEGINT Message(const PegMessage& Mesg); virtual void Draw(void); virtual void AddPanel(PegToolBarPanel * pPanel, BOOL bDraw = TRUE); virtual PegThing * RemovePanel(PegThing * Who, BOOL bDraw = TRUE); virtual void PositionPanels(); }; ConstructorThe PegToolBar constructor creates a PegToolBar object. PegToolBar automatically determines its position and size. Method AddPanelAdds the newly created PegToolBarPanel to the PegToolBar. The panel is sized when it is created, and the PegToolBar positions the panel on the tool bar after any previously added panels. If the panel is already on the tool bar, this method simply does nothing and returns. If the bDraw parameter is set to TRUE, PegToolBar invalidates its clip region and redraws itself and its children (any PegToolBarPanels). If you have a number of panels to add, then it would be a good idea to hold off on redrawing the PegToolBar until all of the panels have been added. Method DrawDraws the tool bar background. Method MessageCatches PM_PARENTSIZED and PM_SHOW messages. Method PositionPanelsThis method is used internally by the PegToolBar to reposition its child panels. It is a public function so that the PegToolBarPanels can trigger all of the child panels to be repositioned. Method RemovePanelRemoves the PegToolBarPanel that is pointed to by pPanel. In doing so, it repositions the PegToolBarPanels that follow this particular panel (if there are any) to fill in the empty space on the PegToolBar left by removing the panel. If you have a number of PegToolBarPanels to remove, then setting bDraw to FALSE on all except the last RemovePanel call will help avoid any unnecessary drawing of the tool bar or the other child panels. ExamplesThe following is an example of two PegDecoratedWindows with PegToolBars and PegToolBarPanels. Note that there are three PegToolBarPanels on the top window and that there are two PegToolBarPanels on the second window. Note also that the PegThing derived objects are added to the PegToolBarPanels, not to the PegToolBar itself. The following example creates a PegToolBar and adds three PegToolBarPanels to the PegToolBar. Usually you would do this in the constructor of your PegDecoratedWindow derived window. extern PegBitmap gbBullsEye; extern PegBitmap gbBlueDot; extern PegBitmap gbGreyDot; extern PegBitmap gbGreenDot; extern PegBitmap gbRedDot; //... some code deleted ... PegToolBar * pToolBar = new PegToolBar(); Add(pToolBar); PegRect Rect; PegToolBarPanel * pPanel = new PegToolBarPanel(); Rect.Set(0, 0, 70, 20); pPanel->Add(new PegTextButton(Rect, "Remove It ->", IDB_ALPHA_BUTTON)); Rect.Set(0, 0, 20, 20); pPanel->AddToEnd(new PegTextButton(Rect, "B")); pToolBar->AddPanel(pPanel); Rect.Set(0, 0, 200, 20); pPanel = new PegToolBarPanel(IDC_STRING_PANEL); pPanel->Add(new PegString(Rect, "String on a ToolBarPanel")); pToolBar->AddPanel(pPanel); Rect.Set(0, 0, 19, 18); pPanel = new PegToolBarPanel(); pPanel->>Add(new PegBitmapButton(Rect, &gbBullsEye, IDB_BULL_BUTTON), FALSE); pPanel->Add(new PegBitmapButton(Rect, &gbBlueDot, IDB_BLUE_BUTTON), FALSE); pPanel->Add(new PegBitmapButton(Rect, &gbGreyDot, IDB_GREY_BUTTON), FALSE); pPanel->Add(new PegBitmapButton(Rect, &gbGreenDot, IDB_GREEN_BUTTON), FALSE); pPanel->Add(new PegBitmapButton(Rect, &gbRedDot, IDB_RED_BUTTON), FALSE); pToolBar->AddPanel(pPanel);
|