Coolbar

 

horizontal rule

Author Aart Onkenhout
Date 12-08-2005

 

Introduction

In addition to my coolmenu dll I wrote wrappers around the Microsoft rebar and toolbar control to make it possible to have Office Xp and Office 2003 look a like toolbars. Although some of the features will be available in the newest PowerBuilder version (10.5), these wrappers make it possible to give the Office look to applications written in PB7 to PB 10.2 (and 10.5 too).

 Some of the rebar- features include:

bullet

Can have Office Xp, Office 2003 or 'normal' look;

bullet

Add any kind of control (toolbars, singleline edit controls, dropdownlistbox etc.)

bullet

Set image or color as background;

bullet

Let toolbars have chevrons (these little arrows when there are more buttons on the toolbar than possible to show);

bullet

Layout can be changed by an “automatic” popup menu;

bullet

Every band can have a headertext and image;

bullet

Reacts on theme and color changes.

 

Some of the toolbar features include:

bullet

Can have Office Xp, Office 2003 or 'normal' look.

bullet

Supports small and large images;

bullet

Supports hot and normal images (as can be seen within Internet Explorer);

bullet

Supports any kind of button, including normal, check and dropdown buttons;

bullet

Buttons can be shown with selective text on the right, all buttons can have text or they can just have an image;

bullet

Images can be used from image files or from a resource file;

bullet

Toolbars are customizable;

bullet

Toolbar settings can be saved to the registry;

bullet

Layout can be changed by an “automatic” popup menu;

bullet

Reacts on theme and color changes;

You can use the coolbar sample application to see how the controls can be used. Below is a short explanation of the workings and usage of the rebar and toolbar control.

To get the Office 2003 toolbar background color you need to use a rebar and add a toolbar to it because the background is a rebar band property and not a toolbar property.

First some screenshots

Office 2003 style - Xp theme enabled, blue, olive and silver

Office 2003 style, classic style on Windows Xp

Office Xp style, Xp theme enabled, blue, olive and silver

Office Xp style, classic style on Windows Xp

Normal style, Xp theme enabled, blue, olive and silver

Normal style, classic style on Windows Xp

Usage

To use the controls you need to add the commoncontrols.pbl to your librarylist. Furthermore, coolmenu.dll (included in download) is needed as well as the pbutils.dll (written by Roy Kiesler) which contains some functions for doing bitwise operations. Two other controls included are n_gradient (written by Philip Salgannik if I'm correct) and n_comctl_imagelist (written by RC Sizer).

The rebar

The rebar can be used by placing a n_comctl_rebar userobject on your window and add some user events (see below) to the window you place the rebar on. In the rebar.ue_PostOpen event you can add controls to it. To add a ddlb for example, place the ddlb on your window too and put it into the rebar by calling the of_AddBand function (see function description on n_comctl_rebar for the required arguments).

Needed user events

bullet ue_Notify (mapped to pbm_notify): A rebar sends notifications to his parentwindow. These must be catched. Within PB10 you can create a user event and map it to pbm_notify, in earlier versions you have to use the other event and watch Message.Number = 78 (WM_NOTIFY).

bullet ue_parentnotify (map to pbm_parentnotify): fired when rightclicking the rebar. Used to show a popup menu.
bullet ue_command (map to pbm_command): when an option is choosen from the popupmenu a WM_COMMAND message is sent. This  events redirects it to the rebar object.

The toolbar

Usage

A toolbar can have a number of imagelists. To avoid strange effects make sure the images added to one imagelist have the same size. Before adding buttons to a toolbar you need to add images to it. The first image added to an imagelist is used to determine the size of the images that will be added.

A toolbar can be added in two manners, manually or automatic. These two are described here.

Manually

Place a u_toolbar object on the parentwindow and add buttons to it by script. This needs to be done within the constructor event. See the uo_toolbar constructor event on w_coolbar_main for a sample.

Automatically

By using the service object n_srv_toolbar toolbars can be created automatically based on the associated menu. This approach has a couple of advantages:

  1. It takes just 4 line sof code to add them:

inv_Toolbar = Create n_srv_toolbar

inv_Toolbar.of_SetRequestor( Parent )

inv_Toolbar.of_SetRebar( uo_Rebar )

inv_Toolbar.of_CreateToolbars()

  1. The needed button id’s (see below) are extracted from the menu.

 

See the constructor and uo_PostOpen event on uo_rebar on w_coolbar_mdi for a sample.

 

To use the service in the menu there must be taken care of:

bullet Must a button be added to the toolbar? Just check or uncheck the ToolbarItemVisible property. When an image is defined and the ToolbarItemVisible property is unchecked, the button will be added to customize dialog and can be added at runtime.
bullet On which row must the toolbar be placed. This can be set by using the ToolbarIndex (just as is done within PB). To create more than one toolbar from the menuitems of the same toolbarindex, you need to add “nt=1” to the tag property of the first button of the next toolbar (within the sample application this is done on m_coolbar for the Bold menuitem. Within PB you would get one toolbar, now you can get two).
bullet Which icon must be used. You can use the ToolbarItemName for it, or, if a resourcefile is used, add an id to the Tag property of the menuitem. This must be of the form “id=nnn” where “nnn” is the id of the image within the resourcefile. To add a large icon you can use the ToolbarItemDownName property or a resourcefile id: “idl=nnn”.
bullet Within the tag following properties can be set as well:
st=1: show selective text if this option is set to true.
cb=1: this is a checkbutton.
dd=1: this is a dropdown button.
wd=1: this is a dropdown button where the dropdown arrow isn’t drawn separately from the button but within it.
gb=1: this button is part of a group (within a group of checkbuttons just one at a time can be checked. Checking another one automatically unchecks  a previuosly checked one).
bc=color: thee backcolor to use for this button to make it appear transparent.

 

Needed user events

bullet

ue_dropdown (map to pbm_custom01): this event is just needed when a button with dropdwon style has been defined. See the ue_dropdown event on w_coolbar_mdi for a script sample.

 

Button id’s

Every button needs to have a unique id. This is used to determine what button has been clicked. There are two ways for setting button id’s: make them up yourself. This causes a WM_COMMAND message to be sent to the parent window where the childid argument contains the id of the clicked button (see the ue_command event on w_coolbar_main for a sample).

The second possibility is to use the id’s as assigned to corresponding menuitems by PB. You can use an  instance of the n_srv_menu object (a datastore). This object has functions to walk through a menu recursively and get all the id’s. These can be used when adding buttons to a toolbar. The latter is used when automatically adding toolbars (using the n_srv_toolbar object which creates a n_srv_menu object), when manually adding toolbars you need to create an instance first and use the of_GetButtonId( menutext (without &) ) to get an id. See the constructor event of uo_toolbar on w_coolbar_main for a sample of the latter option. When the menu id’s are used, no WM_COMMAND messages are sent. Instead a notification (NM_CLICK) is sent. When processing this notification code is executed to get the button id of the clicked button. This id is used to simulate a selection of the corresponding menuitem. In this way the clicked event of the menuitem is executed and no extra coding needs to be done.

 

Last changes

29-08-2005:

bullet

Change made to u_toolbar functions to add images. Method to set correct size for the imagelist changed.

bullet

Function added to n_srv_toolbar and u_toolbar to show or hide buttons.  On n_srv_toolbar the function of_SetVisible should be called with two arguments, the buttontext (no & in it) and a boolean set to true or false. On u_toolbar the function of_SetVisible should be called with the commandid of the button and a boolean.

bullet

Loading of some stockimages fixed on n_cst_image.

bullet

Function added to n_srv_toolbar and u_toolbar to set buttonspacing. You can use this to set the spacing between buttons.

 

Download

Coolbar_pb9.zip

Coolbar_pb10.zip

 

Feedback

If you find any bugs or have suggestions for improvements please send me an e-mail. I will try to respond to it as soon as possible.