Class XbpToolBar() Foundation
Class function of the XbpToolBar() class
The class XbpToolBar implements an Xbase Part that can be used to provide users with quick access to certain commands of the application. An instance of the XbpToolBar class displays buttons that can be selected with the mouse. A tool bar button is similar to a push button in its behaviour and represents one application tool or command. If a button is activated, the command associated with the button is executed. Tool bar objects generally define buttons for a sub-set of the commands available through the application's menus.
Using the XbpToolBar Xbase Part
An instance of the XbpToolBar class is created by calling its :new() method followed by :create(). After the object is created, an application uses the object's instance variables and methods to add or remove tool bar buttons. Each button can have its own caption and/or image associated with it. Tool bar buttons may also serve as a container for other Xbase Parts, such as an XbpCombobox. A button is added to an XbpToolBar instance by calling the tool bar's :addItem() method.
If a tool bar button is selected by the user, an event is generated. This allows the application to respond by activating the function associated with the button selected.
Usage in MDI applications
In so-called MDI applications, one or more child or document windows can be displayed within the main window of the application. MDI applications are created by making the XbpDialog objects representing the child windows a child of the :drawingArea of the main window. Afterwards, the child windows can moved freely within the drawing area of the main window. The child dialogs overlap each other as well as all other childs defined in the :drawingArea of the main window. This is to be taken into account when using the XbpToolBar class within the main window of an MDI application. In this case, the tool bar often visualizes global application commands and hence should be visible at all times. In order to prevent the tool bar from being hidden by overlapping child dialogs, the tool bar should be created as a child of the main window (XbpDialog), and not as a child of the main window's drawing area. Also, the dimension of the drawing area must be reduced by the height of the tool bar, and the position must be adjusted accordingly.
//
// Example for using the XbpToolBar Xbase Part.
// The example creates a tool bar object with
// two tool buttons. Furthermore, it uses a
// callback code block to respond to mouse
// clicks on the toolbar's buttons.
//
#include "XBP.CH"
#include "GRA.CH"
#include "AppEvent.CH"
PROCEDURE Main()
LOCAL oDlg
LOCAL oTBar
LOCAL nEvent, mp1, mp2, oXbp
LOCAL oButton
LOCAL oDA
//
// Create application's main dialog
//
oDlg := XbpDialog():new( Appdesktop() )
oDlg:title := "Toolbar Example"
oDlg:taskList := .T.
oDlg:close := {|| PostAppEvent(xbeP_Quit,,, oDlg) }
oDA := oDlg:drawingArea
oDlg:create( ,, {50,50}, {640,480},, .F. )
oDA:resize := {|| ResizeToolbar(oTBar)}
//
// Create an XbpToolBar object and
// add it at the top of the dialog
//
oTBar := XbpToolBar():new( oDA )
oTBar:create( ,, {0,oDA:currentSize()[2]-60}, ;
{oDA:currentSize()[1],60} )
//
// Add two tool bar buttons, each with a
// caption and an image. Constrict the
// button image sizes to 32 pixels and
// ensure transparency is turned off.
//
oTBar:imageWidth := 32
oTBar:imageHeight := 32
oTBar:addItem("Button #1", 100)
oTBar:addItem("Button #2", 101)
oTBar:transparentColor := GRA_CLR_INVALID
oTBar:buttonClick := {|oButton| MsgBox("Button [" + ;
oButton:caption + ;
"] clicked!")}
//
// Display the main dialog and process
// application events until the dialog
// is closed
//
oDlg:show()
SetAppWindow( oDlg )
SetAppFocus( oDlg )
nEvent := xbeP_Quit
DO WHILE nEvent != xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:handleEvent( nEvent, mp1, mp2 )
ENDDO
oDlg:destroy()
RETURN
// Resize XbpToolBar object to always span the
// whole width of the dialog's drawing area.
// Also, the object is always kept at the top
// of the dialog's display area
PROCEDURE ResizeToolbar( oTBar )
LOCAL oParent
LOCAL aPos
LOCAL aSize
IF GetParentForm(oTBar):getFrameState() == ;
XBPDLG_FRAMESTAT_MINIMIZED
RETURN
ENDIF
oParent := oTBar:setParent()
aPos := oTBar:currentPos()
aSize := oTBar:currentSize()
oTBar:setPosAndSize( {aPos[1],oParent:currentSize()[2]-aSize[2]},;
{oParent:currentSize()[1],aSize[2]} )
RETURN
// Overloaded AppSys() procedure to prevent
// creation of the default XbpCrt window
PROCEDURE AppSys()
RETURN
// Use this ARC file to define the image resource.
// Compile with ARC and link the .RES-file to the
// .EXE
#ifdef __ARC__
BITMAP
100 = FILE "Tile5.bmp"
101 = FILE "Tile7.bmp"
#endif
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.