Customizing toolbar behavior

Disabling toolbar buttons

To disable a toolbar button, you need to disable the menu item with which it is associated. Disabling the menu item disables the toolbar button automatically.

To disable a menu item, you need to set the Enabled property of the menu item:

m_test.m_file.m_new.Enabled = FALSE

Hiding toolbar buttons

To hide a menu item, you set the Visible property of the item:

m_test.m_file.m_open.Visible = FALSE

Hiding a menu item does not cause its toolbar button to disappear or be disabled. To hide a toolbar button, you need to set the ToolbarItemVisible property of the menu item:

m_test.m_file.m_open.ToolBarItemVisible = FALSE

Hiding a menu item does not cause the toolbar buttons for the drop-down or cascading menu items at the next level to disappear or be disabled. You need to hide or disable these buttons individually.

Setting the current item in a drop-down toolbar

When a user clicks on a toolbar button in a drop-down toolbar, PowerBuilder makes the selected button the current item. This makes it easy for the user to perform a particular toolbar action repeatedly. You can also make a particular button the current item programmatically by setting the CurrentItem property of the MenuCascade object. For example, to set the current item to the toolbar button for the New option on the File menu, you could execute this line in a script:

m_test.m_file.currentitem = m_test.m_file.m_new

In order for this to work, you would need to specify MenuCascade as the object type for the File menu in the Menu painter.

Testing for whether a toolbar is moved

Whenever a toolbar moves in an MDI frame window, PowerBuilder triggers the ToolBarMoved event for the window. In the script for this event, you can test to see which toolbar has moved and perform some processing. When the user moves the FrameBar or SheetBar, the ToolbarMoved event is triggered and the Message.WordParm and Message.LongParm properties are populated with values that indicate which toolbar was moved:

Table 5-1: Values of Message.WordParm and Message.LongParm properties

Property

Value

Meaning

Message.WordParm

0

FrameBar moved

1

SheetBar moved

Message.LongParm

0

Moved to left

1

Moved to top

2

Moved to right

3

Moved to bottom

4

Set to floating