Working with Menus and Toolbars

About this chapter

By adding customized menus and toolbars to your applications, you can make it easy and intuitive for your users to select commands and options. This chapter describes how to define and use menus and toolbars.

Menus and menu items

Usually, all windows in an application have menus except child and response windows. Menus are lists of related commands or options (menu items) that a user can select in the currently active window. Each choice in a menu is called a menu item. Menu items display in a menu bar or in drop-down or cascading menus.

About Menu objects

Each item in a menu is defined as a Menu object in PowerBuilder. You can see the Menu object in the list of objects in the Browser's System tab.

Using menus

You can use menus you build in PowerBuilder in two ways:

  • In the menu bar of windows

    Menu bar menus are associated with a window in the Window painter and display whenever the window is opened.

  • As pop-up menus

    Pop-up menus display only when a script executes the PopMenu function.

Both uses are described in this chapter.

Designing menus

PowerBuilder gives you complete freedom in designing menus, but you should follow conventions to make your applications easy to use. For example, you should keep menus simple and consistent; group related items in a drop-down menu; make sparing use of cascading menus and restrict them to one or two levels.

This chapter describes some guidelines you should follow when designing menus. A full discussion of menu design is beyond the scope of this book. You should acquire a book that specifically addresses design guidelines for graphical applications and apply the rules when you use PowerBuilder to create your menus.

Building menus

When you build a menu, you:

  1. Specify the appearance and behavior of the menu items by setting their properties.

  2. Build scripts that determine how to respond to events in the menu items. To support these scripts, you can declare functions, structures, and variables for the menu.

There are two ways to build a menu. You can:

  1. Build a new menu from scratch. See Building a new menu.

  2. Build a menu that inherits its style, functions, structures, variables, and scripts from an existing menu. You use inheritance to create menus that are derived from existing menus, thereby saving yourself coding and time. See Using inheritance to build a menu.

Using the Menu painter

The Menu painter has several views where you can specify menu items and how they look and behave. For general information about views, how you use them, and how they are related, see Views in painters that edit objects.

In addition to customizing the style of a menu in the Menu painter, you can also customize the style of a toolbar associated with a menu. For information, see Providing toolbars.

Menu painter views

You use two views to specify menu items that display in the menu bar and under menu bar items:

This view

Displays

Tree Menu view

All the menu items at the same time when the tree is fully expanded. To fully expand the tree or collapse the expanded tree, press Ctrl+Shift+*.

WYSIWYG Menu view

The menu as you will see it and use it in your application, with the exception of invisible menu items that do display.


The Tree Menu view and the WYSIWYG Menu view are equivalent. You can use either view to insert new menu items on the menu bar or on drop-down or cascading menus, or to modify existing menu items. The menus in both views change when you make a change in either view.

You specify menu properties in two views:

This view

Displays

Properties view (for the top-level menu object)

General and Appearance tab pages for setting menu-wide properties

Properties view (for submenu items)

General and Toolbar tab pages for setting properties for submenu items and toolbars


Views for the top level menu object

This Menu painter layout is for the top level menu object, m_main. The Tree Menu view is in the top left and the WYSIWYG Menu view is in the top middle. The General and Appearance tab pages display in the Properties view on the right. For more information about these properties, see Setting menu style properties for contemporary menus.


Views for submenu items

This Menu painter layout is for a menu item under the top level, in this case the Exit menu item. The Tree Menu view is in the top left and the WYSIWYG Menu view is in the top middle. The General and Toolbar tab pages display in the Properties view on the right. For more information about these properties, see Setting General properties for menu items.


Menu styles

A menu can have a contemporary or traditional style.

Menu style

Description

Contemporary

A 3D-style menu similar to Microsoft Office 2003 and Visual Studio 2005 menus

Traditional

Window default menu style which has a flat appearance


Menus that you import or migrate from earlier versions of PowerBuilder have the traditional style, and new menus use the traditional menu style by default. The new contemporary menu style has a three-dimensional menu appearance that can include images and menu title bands. With a contemporary menu, you can set the MenuAnimation, MenuImage, and MenuTitleText at runtime using scripts.

You select a menu style on the Appearance tab of the Properties view for the top-level menu object in the Menu painter. You must select the top-level menu object in the Tree Menu view of the Menu painter to display its Properties view.

To specify the menu style

  1. Select the top-level menu object.

  2. In the Appearance tab page, select the menu style you want, contemporarymenu! or traditionalmenu!


    If you select contemporarymenu! in the Menu Style drop-down list, you can customize the display properties for that style and have them apply to all menu items in the current menu. If you select traditionalmenu! the rest of the menu style properties are grayed.

Images for menus and toolbars

Contemporary menus can include images. You can use icons, bitmaps, GIF files, and JPEG files for both contemporary menus and traditional and contemporary toolbars.

All stock icons have a transparent background. Other icon and GIF files with transparent backgrounds are always displayed with a transparent background. If you want a bitmap to display with a transparent background, the bitmap must use button face as its background color. This applies whatever the background color of the menu or toolbar is set to. There is currently no property that allows you to specify that an image has a transparent background.

When an icon file includes several images

With the contemporary menu style and toolbar style, when an icon file includes several images, PowerBuilder uses the following image selection rules:

If the images ...

PowerBuilder displays ...

Are all the same size

8 bit, 16 bit, 24 bit, 32 bit, and 4 bit images in that order.

Include 16 bit*16 bit images and also other sized images

16 bit*16 bit images.

Do not include 16 bit*16 bit images

The image with the image size closest to 16 bit. For example, if one icon file contains 24*24 bit images and another icon file contains 32*32 bit images, then PowerBuilder selects the 24*24 bit images.

Are greater than 16 bit images

The image as 16*16 bit or 32*32 bit. If the icon image is 16*16, then it displays as 16*16. If the icon image is larger than 16*16, it will be displayed as 32*32.


Building a new menu

This section describes how to build menus that are not based on existing menus. To create a new menu using inheritance, see Using inheritance to build a menu.

Creating a new menu

You build a new menu by creating a new Menu object and then working on it in the Menu painter.

To create a new menu

  1. Click the New button in the PowerBar.

  2. On the PB Object tab page, select Menu.

  3. Click OK.

    The Menu painter opens and displays the Tree Menu view and the WYSIWYG view for defining the menu, and the General and Appearance tab pages for setting menu and toolbar properties. For information about menu and toolbar properties, see Defining the appearance and behavior of menu items.

    Because you are creating a new menu and have not added menu items yet, the only content in the Tree Menu view and the WYSIWYG view is an untitled top-level tree view item in the TreeMenu view.

Font size of the menu bar and menu text

You can change the value of the TextSize property for submenu items, but not for the main menu bar. The main menu bar has a fixed height that you cannot change.

Working with menu items

A menu consists of at least one menu item on the menu bar and menu items in a drop-down menu. You can add menu items in three places:

  • To the menu bar

  • To a drop-down menu

  • To a cascading menu

Using the pop-up menu

The procedures in this section use the Insert and Edit menus on the PowerBuilder main menu to insert and edit menu items. You can also use the equivalent items on the selected object's pop-up menu.

How menu items are named

When you add a menu item, PowerBuilder gives it a default name, which displays in the Name box in the Properties view. This is the name by which you refer to a menu item in a script.

About the default menu item names

The default name is a concatenation of the default prefix for menus, m_, and the valid PowerBuilder characters and symbols in the text you typed for the menu item. If there are no valid characters or symbols in the text you typed for the menu item, PowerBuilder creates a unique name m_n, where n is the lowest number that can be combined with the prefix to create a unique name.

Prefix might be different

The default prefix is different if it has been changed in the Design>Options dialog box.

The complete menu item name (prefix and suffix) can be up to 79 characters. If the prefix and suffix exceed this size, PowerBuilder uses only the first 79 characters without displaying a warning message.

Duplicate menu item names

Menu items in the Tree Menu view and WYSIWYG Menu view can have the same names, but they cannot have the same name in the Properties view. If you try to add a menu item using the same name as an existing menu item, PowerBuilder displays a dialog box that suggests a unique name for the menu item.For example, you might already have an Options item on the Edit menu with the default name m_options. If you add an Options item to another menu, PowerBuilder cannot give it the name m_options.

Menu item names are locked by default

After you add a menu item, the name that PowerBuilder assigns to the menu item is locked.Even if you later change the text that displays for the menu item, PowerBuilder does not rename the menu item. This allows you to change the text that displays in a menu without having to revise all your scripts that reference the menu item. (Remember, you reference a menu item through the name that PowerBuilder assigns to it.)

To rename a menu item after changing the text that displays for it, you can unlock the name.

To have PowerBuilder rename a menu item

  1. On the General property page in the Properties view, clear the Lock Name check box.

  2. Change the text that displays for the menu item.

Inserting menu items

There are three choices on the Insert menu: Menu Item, Menu Item At End, and Submenu Item. Use the first two to insert menu items in the same menu as the selected item, and use Insert>Submenu Item to create a new drop-down or cascading menu for the selected item.

For example, suppose you have created a File menu on the menu bar with two menu items: Open and Exit. Here are the results of some insert operations:

  • Select File and select Insert>Menu Item At End

    A new item is added to the menu bar after the File menu.

  • Select Open and select Insert>Menu Item

    A new item is added to the File menu above Open.

  • Select Open and select Insert>Menu Item At End

    A new item is added to the File menu after Exit.

  • Select Open and select Insert>Submenu Item

    A new cascading menu is added to the Open menu item.

Getting the menu started

The first thing you do with a new menu is add the first item to the menu bar. After doing so, you can continue adding new items to the menu bar or to the menu bar item you just created. As you work, the changes you make display in both the WYSIWYG and Tree Menu views.

The first procedure in this section describes how to add a single first item to the menu bar. Use this procedure if you want to add the menu bar item and then work on its drop-down menu. Use the second procedure to add multiple items to the menu bar quickly.

To insert the first menu bar item in a new menu

  1. Select the first menu item, and then select Insert>Submenu Item from the PowerBuilder menu bar.

    PowerBuilder displays an empty box on the menu bar in the WYSIWYG Menu view and as a sub-item in the Tree Menu view.

  2. Type the text you want for the menu item and press Enter.

To insert multiple menu bar items in a new menu

  1. Select Insert>Submenu Item.

    PowerBuilder displays an empty box on the menu bar in the WYSIWYG Menu view and as a submenu item in the Tree Menu view.

  2. Type the text you want for the menu item and press Tab.

    PowerBuilder displays a new empty box on the menu bar in the WYSIWYG Menu view and as a submenu item in the Tree Menu view.

  3. Repeat step 2 until you have added all the menu bar items you need.

  4. Press Enter to save the last menu bar item.

Adding additional menu items

After you have created the first menu bar item, you can add more items to the menu bar or start building drop-down and cascading menus.

To insert additional menu items on the menu bar

  1. Do one of the following:

    • With any menu bar item selected, select Insert>Menu Item At End to add an item to the end of the menu bar.

    • Select a menu bar item and select Insert>Menu Item to add a menu bar item before the selected menu bar item.

  2. Type the text you want for the menu bar item, and then press Enter.

To add a drop-down menu to an item on the menu bar

  1. Select the item in the menu bar for which you want to create a drop-down menu.

  2. Select Insert>Submenu Item.

  3. PowerBuilder displays an empty box.

  4. Type the text you want for the menu item, and then press Tab.

  5. Repeat Step 3 until you have added all the items you want on the drop-down menu.

  6. Press Enter to save the last drop-down menu item.

To add a cascading menu to an item in a drop-down menu

  1. Select the item in a drop-down menu for which you want to create a cascading menu.

  2. Select Insert>Submenu Item.

    PowerBuilder displays an empty box.

  3. Type the text you want for the menu item, and then press Tab.

  4. Repeat step 3 until you have added all the items you want on the cascading menu.

  5. Press Enter to save the last cascading menu item.

To add an item to the end of any menu

  1. Select any item on the menu.

  2. Select Insert>Menu Item At End.

    PowerBuilder displays an empty box.

  3. Type the text you want for the second menu item in the box and press Enter.

To insert an item in any existing menu

  1. Select the item that should follow the new menu item.

  2. Select Insert>Menu Item.

    An empty box displays above the item you selected.

  3. Type the text you want for the menu item and press Enter.

Creating separation lines in menus

You should separate groups of related menu items with lines.

To create a line between items on a menu

  1. Insert a new menu item where you want the separation line to display.

  2. Type a single dash (-) as the menu item text and press Enter.

    A separation line displays.


Duplicating menu items

You might save time creating new menu items if you duplicate existing menu items. A duplicate menu item has the same properties and script as the original menu item. You might be able to modify a long script slightly to make it work for your duplicate menu item.

To duplicate a menu item or a submenu item

  1. Select the menu item or the submenu item to duplicate.

  2. Select Edit>Duplicate or press Ctrl+T.

    The duplicate item displays at the same level of the menu, following the item you selected. The name of the duplicate menu item is unique.

  3. Change the text of the duplicate menu item.

  4. Modify the properties and script associated with the duplicate item as needed.

Changing menu item text

It is often necessary to change the text of a menu item, and if you duplicate a menu item, you need to change the text of the duplicate item.

To change the text of a menu item

  1. Do one of the following:

    • Click the item to select it, then click it again.

    • Select the item and select Edit>Menu Item Text.

  2. Select the item and open the general page in the Properties view.

  3. Type the new text for the menu item in the box in the WYSIWYG Menu or Tree Menu view or in the Text box in the Properties view.

Selecting menu items

You can select multiple menu items to move them, delete them, or change their common properties.

To select multiple individual menu items

  • Press Ctrl and select each item you want.

To select a range of menu items at the same level in the menu

  • Select the first item, press Shift, and select the last item.

Navigating in the menu

As you work in a menu, you can move to another menu item by selecting it. You can also use the Right Arrow, Left Arrow, Up Arrow, and Down Arrow keys on the keyboard to navigate.

Moving menu items

The easiest way to change the order of items in the menu bar or in a drop-down or cascading menu is to drag the item you want to move and drop it where you want it to be. You can drag items at the same level in a menu structure or to another level. For example, you can drag an item in the menu bar to a drop-down menu or an item in a cascading menu to the menu bar.

WYSIWYG Menu and Tree Menu views

You can use drag and drop within each view. You can also drag from one view and drop in another.

To move a menu item or submenu item using drag and drop

  1. Select the item.

  2. Press and hold the left mouse button and drag the item to a new location.

    A feedback line appears at the new location to indicate where to drop the item.

  3. Release the mouse button to drop the menu item.

    The menu item displays in the new location.

Dragging to copy

To copy a menu item by dragging it, press and hold the Ctrl key while you drag and drop the item. A copied menu item has the same properties and scripts as the original menu item.

You can also copy or move a menu item by selecting the item and using the Cut, Copy, and Paste items on the Edit menu or the pop-up menu.

Deleting menu items

To delete a menu item

  1. Select the menu item you want to delete.

  2. Click the Delete button in the PainterBar or select Edit>Delete from the menu bar.

Saving the menu

You can save the menu you are working on at any time. When you save a menu, PowerBuilder saves the compiled menu items and scripts in the library you specify.

To save a menu

  1. Select File>Save from the menu bar.

    If you have previously saved the menu, PowerBuilder saves the new version in the same library and returns you to the Menu painter. If you have not previously saved the menu, PowerBuilder displays the Save Menu dialog box.

  2. Name the menu in the Menus box (see Naming the menu).

  3. Write comments to describe the menu.

    These comments display in the Select Menu dialog box and in the Library painter. It is a good idea to use comments so you and others can easily remember the purpose of the menu later.

  4. Specify the library in which to save the menu and click OK.

Naming the menu

The menu name can be any valid PowerBuilder identifier of up to 40 characters. For information about PowerBuilder identifiers, see the the section called “Identifier names” in PowerScript Reference.

A common convention is to use m_ as a standard prefix, and a suffix that helps you identify the particular menu. For example, you might name a menu used in a sales application m_sales.

Defining the appearance and behavior of menu items

By setting menu properties, you can customize the display of menus in applications that you create with PowerBuilder. You use the Menu painter to change the appearance and behavior of your menu and menu items by choosing different settings in the tab pages in the Properties view. For a list of all menu item properties, see Objects and Controls.

Setting General properties for menu items

This section describes the properties you can set when you select a menu item and then select the General tab page in the Properties view.

Creating MicroHelp and tags

MicroHelp is a brief text description of the menu item that displays on the status bar at the bottom of a Multiple Document Interface (MDI) application window. Type the text you want to display in the MicroHelp box. For examples of MicroHelp text, select an item from a menu in PowerBuilder and look at the text that displays in the status bar.

A tag is a text string that you can associate with an object and use in any way you want.

For information about defining MicroHelp text and tag properties, see the section called “Building an MDI Application” in Application Techniques.

Setting the appearance of a menu item

On the General tab page in the Properties view, you can also specify how a menu item appears at runtime.

Property

Meaning

Visible

Whether the menu item is visible. An invisible menu item still displays in the WYSIWYG and Tree Menu views, but at runtime, it will not display. In WYSIWYG Menu view, an invisible item has faded and dotted text.

Enabled

Whether the menu item can be selected.

Checked

Whether the menu item displays with a check mark next to it.

Default

Whether the menu item text is bold. In a pop-up menu, Default indicates what action occurs if the user double-clicks instead of right-clicks on an item. In dragging, Default indicates what happens when an item is dragged with the left mouse button instead of the right mouse button.

ShiftToRight

Whether the menu item shifts to the right (or down for a drop-down or cascading menu) when you add menu items in a menu that is inherited from this menu. Selecting this property allows you to insert menu items in descendant menus, instead of being able to add them only to the end.

For more information, see Inserting menu items in a descendant menu.

MergeOption

The way menus are modified when an OLE object is activated. Options are: File, Edit, Window, Help, Merge, Exclude.

For more information, see the section called “Using OLE in an Application” in Application Techniques.

MenuItemType

Whether the menu item you are creating is Normal, About, Exit, or Help type.


The settings you specify here determine how the menu items display by default. You can change the values of the properties in scripts at runtime.

Assigning accelerator and shortcut keys

Every menu item should have an accelerator key, also called a mnemonic access key, which allows users to select the item from the keyboard by pressing Alt+key when the menu is displayed. Accelerator keys display with an underline in the menu item text.

You can also define shortcut keys, which are combinations of keys that a user can press to select a menu item whether or not the menu is displayed.

For example, in the following menu all menu items have accelerator keys: the accelerator key is U for Undo, T for Cut, and so on. New, Undo, Cut, Copy, Paste, and Clear each have shortcut keys: the Ctrl key in combination with another key or keys.


You should adopt conventions for using accelerator and shortcut keys in your applications. All menu items should have accelerator keys, and commonly used menu items should have shortcut keys.

If you specify the same shortcut for more than one MenuItem, the command that occurs later in the menu hierarchy is executed.

Some shortcut key combinations, such as Ctrl+C, Ctrl+V, and Ctrl+X, are commonly used by many applications. Avoid using these combinations when you assign shortcut keys for your application.

To assign an accelerator key

  • Type an ampersand (&) before the letter in the menu item text that you want to designate as the accelerator key.

    For example, &File designates the F in File as an accelerator key and Ma&ximize designates the x in Maximize as an accelerator key.

Displaying an ampersand in the text

If you want an ampersand to display in the menu text, type two ampersands. For example, Fish&&Chips displays as Fish&Chips with no accelerator key. To display Fish&Chips as the menu text with the C underlined as the accelerator, type Fish&&&Chips.

To assign a shortcut key

  1. Select the menu item to which you want to assign a shortcut key.

  2. Select the General tab in the Properties view.

  3. Select a key from the Shortcut Key drop-down list.


  4. Select Shortcut Alt, Shortcut Ctrl, and/or Shortcut Shift to create a key combination.

    PowerBuilder displays the shortcut key next to the menu item name.

Setting menu style properties for contemporary menus

Menus with a contemporary style have a three-dimensional menu appearance and can include bitmap and menu title bands. The following figure shows a contemporary style menu:


After you select the contemporary style, you can modify other menu style properties on the top-level menu object and on all lower-level menu items. Since it is important to maintain a consistent look across each menu and toolbar, very few style properties are modifiable at the menu item level.

If you select the traditional menu style

If you select traditionalmenu! for the top-level menu object, you cannot modify any of the menu style properties.

You can modify menu style properties only at design time. After you select the contemporary menu style for a top-level menu object, you can select values for other style properties to manipulate a menu's visual appearance. The following properties are modifiable for the top-level menu object only; you cannot modify them for individual menu items:

Property

Datatype

Use to assign

MenuStyle

Enumerated

Overall menu style. Values are: contemporarymenu! and traditionalmenu!

MenuTextColor

Long

Menu text color. (Default is the Windows menu text color.)

MenuBackColor

Long

Background color of the menu.

MenuHighlightColor

Long

Menu highlight color. (Default is the default Windows highlight color.)

FaceName

String

Font face name.

TextSize

Integer

Font character size in points for menu items. (Does not apply to the main menu bar which has a fixed height.)

Bold

Boolean

Bold font.

Italic

Boolean

Italic font.

Underline

Boolean

Underline font.

TitleBackColor

Long

Background color of the title panel.

BitmapBackColor

Long

Background color of the bitmap band of the menu. (Default is silver.)

MenuBitmaps

Boolean

Bitmap band for the menu.

BitmapGradient

Boolean

Background of the bitmap band to a gradient style.

MenuTitles

Boolean

Menu title band.

TitleGradient

Boolean

Background gradient style for the title panel.


Setting menu item style properties

Menu items have style properties that you set at design time. You cannot use these style properties with a traditional style menu. Unlike the style properties on the Menu object that display on the Appearance tab of the Properties view, the fields where you set these properties are located on the General tab of the Properties view for each menu item.

Property

Datatype

Use to assign

MenuAnimation

Boolean

Visual sizing cue to the menu item bitmap when the associated menu item is selected. This property is ignored if the MenuImage property is not assigned.

MenuImage

String

Bitmap image to be used with the menu item. This property is ignored if the MenuBitmaps property for the menu object is not selected or is set to "false".

MenuTitleText

String

Label for menu item that has a cascading submenu. The label text is set vertically in a column to the left of the submenu items and the bitmaps for submenu items, if any. If the vertical label text is longer than the height of all the submenu items, the label text is cut from the end. This property is ignored if the MenuTitles property for the menu object is not selected.


You select or enter values for the menu item style properties on the General tab of the Properties view for each menu item. You can make selections for the MenuAnimation and MenuImage properties only if the MenuBitmaps check box for the current menu object is selected. The MenuBitmaps check box is selected by default for the contemporary menu style.

You can enter text for the MenuTitleText property only if the MenuTitles check box for the current menu object is selected.

Providing toolbars

To make your application easier to use, you can add toolbars with buttons that users can click as a shortcut for choosing an item from a menu. In PowerBuilder, you can associate a toolbar with the window types listed in the following table.

Window type

Description

Main window

A main window is a standalone window that can be independent of all other windows. You use the main window as the anchor for your application. The first window your application opens is a main window (unless you are building an MDI application, in which case the first window is an MDI frame window).

MDI window

A window in a Multiple Document Interface application, an application in which users work within a frame window that lets them perform activities on multiple sheets of information. This is useful in applications where users require the ability to do several different things at a time. An MDI frame window has a menu bar, a client area, sheets, and (usually) a toolbar. An MDI sheet window is a window that can be opened in the client area of an MDI frame.

MDI Help window

An MDI window with a status area that can display MicroHelp.


Creating windows in PowerBuilder

You can create a main window, an MDI window, or an MDI Help window in PowerBuilder by clicking the New button in the PowerBar and selecting Window on the PB Object tab page. The new window's type is Main by default. To change it to MDI or MDI Help, select the window type on the General page in the Properties view.

In MDI windows, you can associate a toolbar with the MDI frame and a toolbar with the active sheet. This screen shows New, Print, and Exit buttons on the toolbar associated with the MDI Frame, and window management buttons on the toolbar associated with the sheet.The toolbar associated with the MDI frame is called the FrameBar. The toolbar associated with the active sheet is called the SheetBar.


This section provides you with the information you need to create and use toolbars. For information about customizing toolbar behavior and saving and restoring toolbar settings, see the section called “Using toolbars in MDI applications” in Application Techniques.

How toolbars work

Toolbars you add to a window behave like the toolbars provided in the PowerBuilder development environment:

  • Users can choose whether or not to display text in a toolbar, use PowerTips, float the toolbar, move the toolbar around the frame, and dock it underneath or beside any other toolbar. No coding is required to support these basic toolbar operations.

  • Toolbar buttons map directly to menu items. Clicking a toolbar button is the same as clicking its corresponding menu item (or pressing the accelerator key for that item).

  • Toolbars work only in MDI frame, MDI sheet, and Main windows. If you open a pop-up window with a menu that has a toolbar, the toolbar does not display.

  • If both the MDI sheet and the frame have toolbars and the sheet is open, then the menu that is displayed is the menu for the sheet, but both toolbars appear and are operative.

  • If the currently active sheet does not have a menu, then the menu and toolbar for the frame remain in place and are operative. This can be confusing to your user, because the displayed menu is not for the active sheet. If any sheet has a menu, then all sheets should probably have menus.

Menus with multiple toolbars

A single menu can have more than one toolbar. When you associate a menu that has multiple toolbars with a window, PowerBuilder displays all the toolbars when you open the window. This screen shows a sheet open in an MDI frame, with one FrameBar and two SheetBars:


You can work with the toolbars independently. For example, you can float any of the toolbars, move them around the window, and dock them at different locations within the window.

The button associated with a menu item can appear on only one toolbar at a time. To indicate which toolbar a menu item's button belongs to, you set the ToolbarItemBarIndex property for the menu item. All items that have the same index number appear on the same toolbar.

Adding toolbars to a window

PowerBuilder provides an easy way to add toolbars to a window: when you are defining an item in the Menu painter for a menu that will be associated with an MDI frame window, an MDI sheet, or a main window, you simply specify that you want the menu item to display in the toolbar with a specific picture. At runtime, PowerBuilder automatically generates a toolbar for the window containing the menu.

To add toolbars to a window

  1. In the Menu painter, specify the display characteristics of the menu items you want to display in the toolbar.

    For details, see Toolbar item display characteristics.

  2. (Optional) In the Menu painter, specify drop-down toolbars for menu items.

  3. In the Window painter, associate the menu with the window and turn on the display of the toolbar.

  4. (Optional) In the Window painter, specify other properties, such as the size and location of a floating toolbar, on the Toolbar property page.

Selecting a toolbar style

You select a toolbar style on the Appearance tab of the Properties view for the top-level menu object in the Menu painter.

A toolbar can have a contemporary or traditional style.

Menu style

Description

Contemporary

A 3D-style toolbar similar to Microsoft Office 2003 and Visual Studio 2005 toolbars

Traditional

A more traditional and older toolbar style


Toolbars that you import or migrate from earlier versions of PowerBuilder have the traditional style, and new toolbars use the traditional toolbar style by default.

To specify the toolbar style

  1. Select the top-level menu object.

  2. At the bottom of the Appearance tab page, select the toolbar style you want, contemporarytoolbar! or traditionaltoolbar!


    If you select traditionaltoolbar! in the Toolbar Style drop-down list, the rest of the toolbar style properties are grayed. If you select contemporarytoolbar! style, you can customize the display properties for that style and have them apply to all menu items with associated toolbar buttons in the current menu.

Selecting the toolbar button style property. Unless you are using the traditional toolbar style for the current menu object, you can select the ToolbarAnimation check box on the Toolbar tab or the Properties view for each menu item. If you do not select an image for the ToolbarItemName property of a menu item, the selection you make for the ToolbarAnimation property is ignored.

Setting toolbar properties

You can customize the display of toolbars in applications that you create with PowerBuilder by setting toolbar properties.

Toolbar style properties

In addition to customizing the style of a menu, you can customize the style of a toolbar associated with the menu. For example, the following picture shows a contemporary style toolbar with an expanded toolbar cascade and a highlighted Exit button:


Toolbar style properties. Toolbars have style properties that you can change at design time on the top-level menu object. You can modify these properties only if you select contemporarytoolbar! as the toolbar style for the top-level menu object.

Property

Datatype

Use to assign

ToolbarBackColor

Long

Background color of the menu toolbar.

ToolbarGradient

Boolean

Gradient of the menu toolbar background.

ToolbarHighlightColor

Long

Highlight color for the toolbar buttons when they are selected.

ToolbarStyle

Enumerated

Overall style of the menu toolbar. Values are: contemporarytoolbar! and traditionaltoolbar!

ToolbarTextColor

Long

Color of the text in the menu toolbar.


Toolbar item style property. You can select the ToolbarAnimation property for a menu item toolbar button. This property offsets the button image by two pixels to the upper left when a user positions the cursor over the button. You cannot assign this property at the menu object or toolbar level. You must assign it to individual toolbar items (buttons) at design time. This property has a Boolean datatype. You can select it on the Toolbar tab for each menu item below the top-level menu object. With a contemporary menu, you can set the ToolbarAnimation property at runtime at runtime using scripts.

The customizable menu and toolbar styles can be used for MDI and main windows. Pop-up menus can also use menu style properties. The styles do not affect existing PowerBuilder applications that use a traditional style. You can, however, update an existing PowerBuilder application to use the new styleproperties.

Toolbar item display characteristics

In the Menu painter, you specify the menu items you want to display in the toolbar, the text for the toolbar button and tip, the pictures to use to represent the menu items, and other characteristics of the toolbar.

To specify the display characteristics of a toolbar item:

  1. Open the menu in the Menu painter and select the menu item you want to display in the toolbar.

  2. Select the Toolbar property page and set properties of the toolbar item as shown in the following table.

Property

What to specify

ToolbarItemText

Specify two different text values for the toolbar button and PowerTip with a comma-delimited string, as follows:

Text in button, PowerTip

ToolbarItemName

Choose a stock picture from the drop-down list or browse to select a bitmap, GIF, JPEG or icon file. If you choose a stock picture, PowerBuilder uses the up version when the item is not clicked and the down version when the item is clicked. (The up version appears raised and the down version appears lowered.) For the best result, use 16*16 icons on a toolbar. If you are specifying a file, the picture should be 16 pixels wide and 16 pixels high.

ToolbarItemDownName

Specify a different picture to display when the item is clicked (optional).

ToolbarItemVisible

Clear if you want the toolbar button to be hidden. The default is visible.

ToolbarItemDown

Check if you want the down version of the button to display initially.

ToolbarAnimation

If you want the toolbar image to be animated when selected, select the check box.

ToolbarItemSpace

Specify any integer if you want to leave space before the picture in the toolbar. Experiment with values to get the spacing the way you want it. If you leave the value at 0, there will be no spacing before the picture. (Spacing is used only when the toolbar is not displaying text.)

ToolbarItemOrder

Specify the order in which the item displays in the toolbar. If you leave the value 0, PowerBuilder places the item in the order in which it goes through the menu to build the toolbar.

ToolbarItemBarIndex

Specify a number other than 1 if you want multiple toolbars to display for this menu. The number you specify determines which toolbar the current menu item appears on. All items that have the same index number appear on the same toolbar.

ObjectType

Specify Menu or MenuCascade.

Columns

(This property displays only if you choose MenuCascade in the ObjectType drop-down list.) Indicate the number of columns you want to display in the cascading toolbar.

Drop Down

(This property displays only if you choose MenuCascade in the ObjectType drop-down list.) If you want the button to be a drop-down toolbar button, select the check box.


Menu items can have drop-down toolbars

A menu item can have a toolbar button associated with it that displays a drop-down toolbar. When the user clicks on the button, PowerBuilder displays a drop-down toolbar that shows all of the toolbar buttons for menu items defined at the next level. For example, if you define a drop-down toolbar for the File menu item, the drop-down toolbar will show the buttons defined for the items on the File menu (such as New, Open, Close, and Exit).

PowerBuilder displays a drop-down toolbar at runtime by default if the Object Type of the menu item is MenuCascade. You can specify programmatically whether submenu items display in a drop-down toolbar or as normal toolbar items by setting the DropDown property of the menu item. For example, if you want a descendant menu item to have a drop-down toolbar, but not its ancestor, clear the DropDown check box on the ancestor's Toolbar property page, and set the DropDown property of the descendant menu item to "true" in a script.

To specify a drop-down toolbar for a menu item

  1. In the Menu painter, select the menu item for which you want to add a drop-down toolbar.

  2. On the Toolbar property page, change the Object Type to MenuCascade.

  3. (Optional) Specify the number of columns you want to display in the Columns box.

    The default is a single column. If there are many items on the submenu, as there are on the toolbar item for inserting controls in the Window painter, you will probably want to specify three or four columns.

Setting toolbar properties in the Window painter

In the Window painter, you associate the menu with the window on the window's General property page. The window displays the toolbar by default. If you do not want the toolbar to display, clear the ToolbarVisible check box on the window's Toolbar property page. You can also specify the toolbar's alignment and position on this property page.

Setting toolbar properties in the Application painter

You can specify global properties for all toolbars in your application on the Toolbar property page in the Application painter or by setting properties of the Application object in a script. Typically you set these in the application's Open event, but you can set them anywhere.

Property

Meaning

ToolbarFrameTitle

The text that displays as the title for the FrameBar when it is floating.

ToolbarSheetTitle

The text that displays as the title for the SheetBar when it is floating.

ToolbarPopMenuText

(String) Text to display on the pop-up menu for toolbars (see below).

ToolbarUserControl

(Boolean) If TRUE (default), users can use the toolbar pop-up menu to hide or show the toolbars, move toolbars, or show text. If FALSE, users cannot manipulate the toolbar.

ToolbarText

(Boolean) If TRUE, text displays in the buttons. If FALSE (the default), text does not display.

ToolbarTips

(Boolean) If TRUE (default), PowerTips display when text is not displayed in the buttons. If FALSE, PowerTips do not display.


Specifying the text in the toolbar's pop-up menu

By default, PowerBuilder provides a pop-up menu for the toolbar, which users can use to manipulate the toolbar. It is similar to the pop-up menu you use to manipulate the PowerBar and PainterBar.

You can change the text that displays in this menu, but you cannot change the functionality of the menu items in the menu. Typically, you do this when you are building an application in a language other than English.

You change the text as follows:

  • The first two items in the pop-up menu display the titles set in ToolbarFrameTitle and ToolbarSheetTitle (defaults: FrameBar and SheetBar).

  • The remaining text items are specified by the property ToolbarPopMenuText. To specify values for this property, use a comma-delimited list of values to replace the text "Left," "Top," "Right," "Bottom," "Floating," "Show Text," and "Show PowerTips":

    ToolbarPopMenuText = "left, top, right, bottom, floating, showText, showPowerTips"

    For example, to change the text for the toolbar pop-up menu to German and have hot keys underlined for each, you would specify the following:

    ToolbarPopMenuText = "&Links, &Oben, &Rechts, " +   &
       "&Unten, &Frei positionierbar, &Text anzeigen, " &
       + "&PowerTips anzeigen"

Writing scripts for menu items

You write scripts for menu items in the Script view. The scripts specify what happens when users select a menu item.

To write a script for a menu item:

  • Double-click the menu item or select Script from the menu item's pop-up menu.

    The Script view displays for the clicked event, which is the default event for a menu item.

Menu item events

Menu items have the following events:

  • Clicked

    Typically, your application will contain Clicked scripts for each menu item in a drop-down or cascading menu. For example, the script for the Clicked event for the Open menu item on the File menu opens a file.

  • Help

    You can provide Help on a menu item when a user presses the F1 key, or when the user clicks the context Help button [?] on the title bar of the window with which the menu is associated, and then clicks on a menu item.

  • Selected

    You will probably use few Selected scripts since users do not expect things to happen when they simply highlight a menu item. One use of Selected scripts is to change MicroHelp displayed in an MDI application as the user scrolls through a menu.

About the Clicked event

The Clicked event is triggered whenever:

  • The user clicks the menu item

  • The user selects (highlights) the menu item using the keyboard and then presses ENTER

  • The user presses the shortcut key for the menu item

  • The menu containing the menu item is displayed and the user presses the accelerator key Alt+key

  • A script executes the PopMenu function and displays a pop-up menu

  • A menu item responds to a mouse-click or the keyboard only if both its Visible and Enabled properties are set to "true".

  • If the menu item has a drop-down or cascading menu under it, the script for its Clicked event (if any) is executed when the mouse button is pressed, and then the drop-down or cascading menu displays. If the menu item does not have a menu under it, the script for the Clicked event is executed when the mouse button is released.

Using the Clicked event to specify menu item properties

When the user clicks an item on the menu bar to display a drop-down menu, the Clicked event for the menu item on the menu bar is triggered and then the drop-down menu is displayed.

You can use the menu bar's Clicked event to specify the properties of the menu items in the drop-down menu. For example, if you want to disable items in a drop-down menu, you can disable them in the script for the Clicked event for the menu item in the menu bar.

About the Help event

The Help event is triggered when the user presses F1 or clicks the context Help button [?] on a window's title bar and then points and clicks on a menu item.

About the Selected event

The Selected event is triggered when the user selects a menu item.

Using functions and variables

You can use functions and variables in your scripts.

Using functions

PowerBuilder provides built-in functions that act on menu items. You can use these functions in scripts to manipulate menu items at runtime. For example, to hide a menu, you can use the built-in Hide function.

For a complete list of the menu-level built-in functions, look at the Function List view or use the Browser.

Defining menu-level functions

You can define your own menu-level functions to make it easier to manipulate your menus. One way you can do this is in the Function List view, by selecting Add from the pop-up menu.

For more information, see Working with User-Defined Functions.

Using variables

Scripts for menu items have access to all global variables declared for the application. You can also declare local variables, which are accessible only in the script where they are declared.

You can declare instance variables for the menu when you have data that needs to be accessible to scripts in several menu items in a menu. Instance variables are accessible to all menu items in the menu.

For a complete description of variables and how to declare them, see the the section called “Declaring variables” in PowerScript Reference.

Defining menu-level structures

If you need to manipulate a collection of related variables, you can define menu-level structures using the Structure view. You do this by displaying the Structure List view and then selecting Add from the pop-up menu. The Structure and Structure List views are not part of the default layout.

For more information, see Working with Structures.

Referring to objects in your application

You can refer to any object in the application in scripts for menu items. You must fully qualify the reference, using the object name, as follows.

Referring to windows

When referring to a window, you simply name the window. When referring to a property in a window, you must always qualify the property with the window's name:

window.property

For example, this statement moves the window w_cust from within a menu item script:

w_cust.Move(300, 300)

This statement minimizes w_cust:

w_cust.WindowState = Minimized!

You can use the reserved word ParentWindow to refer to the window that the menu is associated with at runtime. For example, the following statement closes the window the menu is associated with:

Close(ParentWindow)

You can also use ParentWindow to refer to properties of the window a menu is associated with, but not to refer to properties of controls or user objects in the window.

For example, the following statement is valid, because it refers to properties of the window itself:

ParentWindow.Height = ParentWindow.Height/2

But the following statement is invalid, because it refers to a control in the window:

ParentWindow.sle_result.Text = "Statement invalid"

Referring to controls and user objects in windows

When referring to a control or user object, you must always qualify the control or user object with the name of the window:

window.control.property
window.userobject.property

For example, this statement enables a CommandButton in window w_cust from a menu item script:

w_cust.cb_print.Enabled = TRUE

Referring to menu items

When referring to a menu item, use this syntax:

menu.menu item
menu.menu item.property

Reference within the same menu

When referring to a menu item within the same menu, you do not have to qualify the reference with the menu name.

When referring to a menu item in a drop-down or cascading menu, you must specify each menu item on the path to the menu item you are referencing, separating the names with periods.

For example, to place a check mark next to the menu item m_bold, which is on a drop-down menu under m_text in the menu saved in the library as m_menu, use this statement:

m_menu.m_text.m_bold.Check( )

If the previous script is for a menu item in the same menu (m_menu), you do not need to qualify the menu item with the name of the menu:

m_text.m_bold.Check( )

Using inheritance to build a menu

When you build a menu that inherits its style, events, functions, structures, variables, and scripts from an existing menu, you save coding time. All you have to do is modify the descendant object to meet the requirements of the current situation.

To use inheritance to build a descendant menu:

  1. Click the Inherit button on the PowerBar.

  2. In the Inherit From Object dialog box, select Menus from the Object Type drop-down list, the library or libraries you want to look in, and the menu you want to use to create the descendant, and click OK.

    Displaying menus from many libraries

    To find a menu more easily, you can select more than one library in the Application Libraries list. Use Ctrl+click to toggle selected libraries and Shift+click to select a range.

    The selected menu displays in the WYSIWYG Menu view and the Tree Menu view in the Menu painter. The title in the painter's title bar indicates that the menu is a descendant.

  3. Make the changes you want to the descendant menu as described in the next section.

  4. Save the menu under a new name.

Using the inherited information

When you build and save a menu, PowerBuilder treats the menu as a unit that includes:

  • All menu items and their scripts

  • Any variables, functions, and structures declared for the menu

  • When you use inheritance to build a menu, everything in the ancestor menu is inherited in all of its descendants.

What you can do

You can do the following in a descendant menu:

  • Add menu items to the end of a menu

  • Insert menu items in a menu (with some restrictions)

    For more information, see Where you can insert menu items in a descendant menu.

  • Modify existing menu items

    For example, you can change the text displayed for a menu item or change its initial appearance, such as making it disabled or invisible.

  • Build scripts for menu items that do not have scripts in the ancestor menu

  • Extend or override inherited scripts

  • Declare functions, structures, and variables for the menu

What you cannot do

You cannot do the following in a descendant menu:

  • Change the order of inherited menu items

  • Delete an inherited menu item

  • Insert menu items between inherited menu items that do not have the ShiftToRight property set (see Modifying the ShiftToRight property)

  • Change the name of an inherited menu item

  • Change the type of an inherited menu item

Hiding a menu item

If you do not need a menu item in a descendant menu, you can hide it by clearing the visible property in the Properties view or by using the Hide function.

About menu item names in a descendant

PowerBuilder uses the following syntax to show names of inherited menu items:

AncestorMenuName::MenuItemName

For example, in a menu inherited from m_update_file, you see m_update_file::m_file for the m_file menu item, which is defined in m_update_file.

The inherited menu item name is also locked, so you cannot change it.

Understanding inheritance

The issues concerning inheritance with menus are similar to the issues concerning inheritance with windows and user objects. For information, see Understanding Inheritance.

Inserting menu items in a descendant menu

Modifying the ShiftToRight property

When defining a descendant menu, you might want to insert menu items in the middle of the menu bar or in the middle of a drop-down or cascading menu. To do this, you set the ShiftToRight property in a menu item's Properties view on the General property page.

If the ancestor menu has no menu items with ShiftToRight set, you can add a new menu item to the end of the descendant menu. To add new menu items elsewhere in the menu, set the ShiftToRight property for the descendant menu items that will follow the new menu item.

The ShiftToRight property is used for menu items on the menu bar (where items need to shift right if a new item is inserted) and for menu items in a drop-down or cascading menu (where items might need to shift down if a new item is inserted). The property name is ShiftToRight, but it means shift down in drop-down or cascading menus.

Where you set the ShiftToRight property

You set the ShiftToRight property in an ancestor menu only if you know that you will always want a group of menu items to shift right (or down) when you inherit from the menu and add a new menu item. For example, if you have File, Edit, Window, and Help menus on the menu bar, set the ShiftToRight property for the Window and Help menu items if you are going to inherit from this menu, because Window and Help are usually the last items on a menu bar.

Where you can insert menu items in a descendant menu

In a descendant menu, a group of menu items can be one of four types. Each type has an insertion rule.

Type of group

Insertion rule

Inherited menu items without ShiftToRight set

You cannot insert a new menu item before any of these menu items

Inherited menu items with ShiftToRight set in ancestor

You can insert before the first menu item in the group but not before the others

New items without ShiftToRight set

You can insert a new menu item before any of these menu items

New items with ShiftToRight set

You can insert a new menu item before any of these menu items


The Example with no ShiftToRight in ancestor and the Example with ShiftToRight in ancestor demonstrate some of these rules.

How to insert menu items in a descendant menu

If you can insert a menu item in a descendant menu, the Insert Menu Item option on the Insert menu and the pop-up menu is enabled. The Insert Menu Item is enabled if ShiftToRight is set in the selected item that will follow the item you are inserting and all menu items following it.

To insert a menu item in a descendant, you use the same method you use to insert an item in a new menu, whether the menu item is on the menu bar or on a drop-down or cascading menu. For information about inserting menu items, see Working with menu items.

The following examples illustrate where you can insert menu items in a descendant menu and demonstrate the rules that govern where you can insert them.

Example with no ShiftToRight in ancestor

Suppose you have a menu with File, Edit, Window, and Help items on the menu bar. The menu is inherited from an ancestor frame menu with no items set as ShiftToRight in the ancestor.


Here is how you might add some new menu items. Since ShiftToRight is not set anywhere at first, you can add a menu item only to the end.

Select any item in the menu bar and select Insert>Menu Item At End.

Name the new menu item New1 and press Enter.

The New1 menu item is added to the right of the Help menu.


Now add a new Menu item before the New1 menu item. You can do this without setting ShiftToRight on New1, because New1 is a new menu item in the inherited menu.

Select Insert Menu Item from the pop-up menu for New1.

Name the new menu item New2 and press Enter.


Now add a new Menu item before the Help menu item. You cannot do this unless you set ShiftToRight on the Help menu item, the New2 Menu item, and the New1 menu item, because Help is an inherited menu item without ShiftToRight set in the ancestor menu. For Help to shift right, New2 and New1 must also be able to shift right.

Select the Help menu item and in the Properties view, select the ShiftToRight property, and then do the same for New1 and New2.

Order for setting ShiftToRight for the three menu items

You can set ShiftToRight in any order, but you see the items shifting only if you set ShiftToRight from left to right.

Now you can add a new menu item before the Help menu item.

Select the Help menu item, then select Insert New Item from the pop-up menu, name the new item New3, and then press Enter.


If you want to add a new Menu item before the New3 menu item, you can do it without setting ShiftToRight on New3, because New3 is a new menu item and ShiftToRight is set in all items that follow.

However, if you want to add a new menu item before the Window menu item, you cannot do this by working only in the descendant menu because the Window menu item is an ancestor menu item and ShiftToRight is not set in the ancestor. To be able to do this, you must set Window as ShiftToRight in the ancestor.

Example with ShiftToRight in ancestor

In this example, the inherited menu has the same four menu bar items, but ShiftToRight has been set in the Window and Help menu items in the ancestor menu. Suppose you want to insert a new menu item before the Help menu item and the Window menu item.

Select the Help menu item and display the pop-up menu.

The Insert Menu Item option is disabled because the Help item is not the first item in a group of ancestor menu items (Window and Help) with ShiftToRight set in the ancestor.

Select the Window menu item and display the pop-up menu.

The Insert Menu Item option is enabled because the Window item is the first item in a group of ancestor menu items with ShiftToRight set in the ancestor.

Select Insert Menu Item At End from the pop-up menu to insert a new menu item after Help, name it New1, and press Enter.

The New1 item's ShiftToRight property is set automatically.

Now the Window, Help, and New1 items are set ShiftToRight. You can insert a new item before Window and New1, but not before Help. This is because the Window and Help menu items are a group for which ShiftToRight is set in the ancestor.

You cannot insert a new item before the Edit menu item because Edit is in a group (File and Edit) that are inherited items with no ShiftToRight set in the ancestor.

Select the Edit menu item, select ShiftToRight in the Properties view, and then add a new menu item.


You could also have set the ShiftToRight property in the ancestor menu, but it is easier to work just in the descendant.

Using menus in your applications

You can use menus in two ways:

  • Place them in the menu bar of a window

  • Display a menu as a pop-up menu

Adding a menu bar to a window

To have a menu bar display when a window is opened by a user, you associate a menu with the window in the Window painter.

To associate a menu with a window

  1. Click the Open button in the PowerBar, select the window with which you want to associate the menu, and open the window.

  2. Do one of the following:

    • In the Properties view for the window, enter the name of the menu in the MenuName text box on the General tab page.

    • Click the Browse button and select the menu from the Select Object dialog box, which lists all menus available to the application.

    • In the Select Object dialog box, you can search for a menu by clicking the Browse button.

  3. Click Save to associate the selected menu with the window.

Identifying menu items in window scripts

You reference menu items in scripts in windows and controls using the following syntax:

menu.menu item

You must always fully qualify the menu item with the name of the menu.

When referring to a menu item in a drop-down or cascading menu, you must specify each menu item on the path to the menu item you are referencing, separating the names with periods.

For example, to refer to the Enabled property of menu item m_open, which is under the menu bar item m_file in the menu saved in the library as m_menu, use:

m_menu.m_file.m_open.Enabled

Changing a window's menu at runtime

You can use the ChangeMenu function in a script to change the menu associated with a window at runtime.

Displaying pop-up menus

To display a pop-up menu in a window, use the PopMenu function to identify the menu and the location at which you want to display the menu.

If the menu is associated with the window

If the menu is currently associated with the window, you can simply call the PopMenu function.

The following statement in a CommandButton script displays m_appl.m_help as a pop-up menu at the current pointer position, assuming menu m_appl is already associated with the window:

m_appl.m_help.PopMenu(PointerX(), PointerY())

If the menu is not associated with the window

If the menu is not already associated with the window, you must create an instance of the menu before you can display it as a pop-up menu.

The following statements create an instance of the menu m_new, then pop up the menu mymenu.m_file at the pointer location, assuming m_new is not associated with the window containing the script:

m_new mymenu
mymenu = create m_new
mymenu.m_file.PopMenu(PointerX(), PointerY())