Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Using toolbars in MDI applications – PB Docs 110 – PowerBuilder Library

Using toolbars in MDI applications – PB Docs 110

Using toolbars in MDI applications

This section describes some techniques you can use to customize
the behavior of your toolbars and save and restore toolbar settings.
For information about how to define and use menus and toolbars,
see the User’s Guide
.

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:

Hiding toolbar buttons

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

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:

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:

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  

Saving and restoring toolbar settings

You can save and restore the current toolbar settings using
functions that retrieve information about your toolbar settings,
and you can modify these settings.

GetToolbar and GetToolbarPos allow
you to retrieve the current toolbar settings. SetToolbar and SetToolbarPos allow
you to change the toolbar settings. The syntax you use for the GetToolbarPos and SetToolbarPos functions
varies depending on whether the toolbar you are working with is
floating or docked.

Floating toolbars

The position of a floating toolbar is determined by its x
and y coordinates. The size of a floating toolbar is determined
by its width and height.

When you code the GetToolbarPos and SetToolbarPos functions
for a floating toolbar, you need to include arguments for the x
and y coordinates and the width and height.

Docked toolbars

The position of a docked toolbar is determined by its docking
row and its offset from the beginning of the docking row. For toolbars
at the top or bottom, the offset for a docked toolbar is measured
from the left edge. For toolbars at the left or right, the offset
is measured from the top.

By default, the docking row for a toolbar is the same as its
bar index. If you align the toolbar with a different border in the
window, its docking row may change depending on where you place
it.

When you code the GetToolbarPos and SetToolbarPos functions
for a docked toolbar, you need to include arguments for the docking
row and the offset.

Example

The example below shows how to use a custom class user object
to manage toolbar settings. The user object has two functions, one
for saving the current settings and the other for restoring the
settings later on. Because the logic required to save and restore
the settings is handled in the user object (instead of in the window
itself), this logic can easily be used with any window.

The sample code shown below supports both fixed and floating
toolbars.

Script for the window’s Open event When the window opens, the following script restores the toolbar
settings from an initialization file. To restore the settings, it
creates a custom class user object called u_toolbar and calls
the Restore function:

Script for the window’s Close event When the window closes, the following script saves the toolbar
settings by calling the Save function. Once the
settings have been saved, it destroys the user object:

Script for the Save function The Save function has three arguments:

  • Win – provides
    the window reference
  • File – provides the
    name of the file where the settings should be saved
  • Section – identifies
    the section where the settings should be saved

The Save function uses the GetToolbar and GetToolbarPos functions
to retrieve the current toolbar settings. To write the settings
to the initialization file, it uses the SetProfileString function.

The Save function can handle multiple toolbars
for a single menu. It uses the bar index to keep track of information
for each toolbar:

Script for the Restore function The Restore function has the same three arguments
as the Save function. It uses the ProfileString function
to retrieve toolbar settings from the initialization file. Once
the settings have been retrieved, it uses the SetToolbar and SetToolbarPos functions
to restore the toolbar settings.

Like the Save function, the Restore function
can handle multiple toolbars for a single menu. It uses the bar
index to keep track of information for each toolbar:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x