
Home |
|
PegToolBar
|

Examples |

Index |
|
 |
|
|
 |
|
Overview |
Derived from class
PegThing
|
 |
|
The PegToolBar class provides a window
decoration used to position and display a group of related user objects.
These objects can be text strings, bitmap buttons or user editable text fields.
Other objects may represent frequently used commands or user data that
is not well suited for use on a menu.
The PegToolBar is designed for use with
PegDecoratedWindow objects.
Although a PegToolBar object may be added to any type of object,
it must be done with care. If you add a PegToolBar object
to an object other than a PegDecoratedWindow object,
you must be sure to reduce the size of the client area of that object
to accommodate the tool bar.
The PegToolBar automatically
positions and sizes itself within the client area of its parent window.
Each PegToolBar object can contain any number
of PegToolBarPanel objects, the actual tool bar elements.
The PegToolBar also automatically sizes itself to hold
the tallest PegToolBarPanel object as the panels are added.
However, once the tool bar is added to a parent, it will no longer
size itself in this manner. It is therefore recommended that you create a
PegToolBar object, add all of the PegToolBarPanel
objects to the tool bar and then add the PegToolBar object to its
parent object. This procedure will ensure that the tool bar will be
the proper height.
It is not recommended that objects other than PegToolBarPanel
objects be added to a PegToolBar object.
Any object that is placed on a PegToolBarPanel, and
subsequently on a PegToolBar, behaves as it would
if added to any other PegThing object.
For example, a PegButton object will send its
PSF_CLICKED message to its PegToolBarPanel parent,
which, in turn, posts the message to its PegToolBar parent.
Finally, the PegToolBar object will post the message to its
parent, usually the PegDecoratedWindow object containing
the tool bar. Therefore, the message is handled within the context
of the parent PegDecoratedWindow object.
Messages from objects on the tool bar can therefore be serviced
by the same message handler used to service messages from all
other objects attached to the window.
The message routing used by tool bars makes it easy to implement
a tool bar button which duplicates the service provided by a menu item.
To do so, create a PegMenuButton (on the window's menu)
and a PegBitmapButton (on the window's tool bar), giving
each of these objects the same object ID. When either of these objects
is selected, the window's message handler will receive a signal
from that object. Since the signal identifies the signal source
by its object ID, the message handler will properly service the signal
without knowing if it was generated by the menu or tool bar object.
|
|
 |
 |
|
PegToolBarPanel
Constructors:
 |
 |
PegToolBar(WORD wID = 0)
|
The PegToolBar constructor
creates a PegToolBar object, automatically determining
its position and size.
Public Functions:
 |
 |
virtual void AddPanel(PegToolBarPanel *pPanel,
|
| |

BOOL bDraw = TRUE)
|
This function adds a PegToolBarPanel object to
the PegToolBar object. The panel is positioned on the tool
bar after any previously added panels. If the panel is already
on the tool bar, this function simply ignores the request.
If the bDraw parameter is TRUE,
the function invalidates the clip region of the
PegToolBar object and redraws the tool bar and its child
PegToolBarPanel objects. If you must add a number of
panels to the tool bar, it is wise to avoid the drawing operation until the last
PegToolBarPanel object is added.
 |
 |
virtual void Draw(void)
|
The PegToolBar class overrides
the Draw() function to draw the tool bar background.
 |
 |
virtual SIGNED Message(const PegMessage &Mesg)
|
The PegToolBar class catches
PM_PARENTSIZED and PM_SHOW messages
in order to properly reposition and draw itself.
 |
 |
virtual void PositionPanels(void)
|
This function is used privately by a PegToolBar object
to reposition its child panels. The function is public
so that a PegToolBarPanel object can force
all child panels to be repositioned.
 |
 |
virtual void RemovePanel(PegToolBarPanel *pPanel,
|
| |

BOOL bDraw = TRUE)
|
This function removes
the PegToolBarPanel object referenced by pPanel
from the tool bar. In doing so, it repositions the
PegToolBarPanel objects, if any, which follow the removed panel
to fill the gap left by the removal of a panel.
If the bDraw parameter is TRUE,
the function invalidates the clip region of the
PegToolBar object and redraws the tool bar and its child
PegToolBarPanel objects. If you must remove a number of
panels from the tool bar, it is wise to avoid the drawing operation until the last
PegToolBarPanel object is removed.
The following example illustrates two PegDecoratedWindow
objects containing PegToolBar and PegToolBarPanel
objects. Note that there are three tool bar panels
on the front window and two tool bar panels on the back window.
Also note that the PegThing derived objects
have been added to the PegToolBarPanel objects,
not to the PegToolBar object.

The following code fragment
creates a PegToolBar object and adds three
PegToolBarPanels objects to it.
This example was used to generate the tool bar
on the front window shown above. Use this example code to build
your tool bar in the constructor which creates the derived
PegDecoratedWindow object which will hold the tool bar.
extern PegBitmap gbBullsEyeBitmap;
extern PegBitmap gbBlueDotBitmap;
extern PegBitmap gbGreyDotBitmap;
extern PegBitmap gbGreenDotBitmap;
extern PegBitmap gbRedDotBitmap;
:
:
PegToolBar *pToolBar = new PegToolBar();
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,
&gbBullsEyeBitmap, IDB_BULL_BUTTON), FALSE);
pPanel->Add(new PegBitmapButton(Rect,
&gbBlueDotBitmap, IDB_BLUE_BUTTON), FALSE);
pPanel->Add(new PegBitmapButton(Rect,
&gbGreyDotBitmap, IDB_GREY_BUTTON), FALSE);
pPanel->Add(new PegBitmapButton(Rect,
&gbGreenDotBitmap, IDB_GREEN_BUTTON), FALSE);
pPanel->Add(new PegBitmapButton(Rect,
&gbRedDotBitmap, IDB_RED_BUTTON), FALSE);
pToolBar->AddPanel(pPanel);
Add(pToolBar);
 |