Tech Articles


How to Define Events for RibbonBar Controls


Learning to define user events for items in the RibbonBar control feels like a lot of trial and error.
Different items support different events. Same event type requires different parameters.
My aim with this article is to take "... and error" out of your RibbonBar coding.
For each ribbon item type you get user event definitions that work.

 

 

      

Each ribbon item has its own XML element (here: Print Title is a CheckBox).
Each item binds specific user events via properties (here: Clicked on CheckBox binds to ue_PrintTitle)
Each user event must have the correct parameter list (here: Clicked event for CheckBox always requires al_handle while no other parameters allowed)
Each item type has its own PowerScript class and functions to obtain the object (here: Obtain class = RibbonCheckBoxItem via function GetCheckBox)
 

 

RibbonBar Structure

RibbonBar Builder is an excellent tool to build a ribbon. It's combination of XML editor and visual preview makes it easy to see the layout you define.
There is "autoscript" help in the editor for valid XML elements and XML attributes.
You name the user events within the XML syntax. However, you cannot see how to define the user events. Which parameters are required.

Available event types depend on ribbon item type. Required parameter list depends on event type and ribbon item type.
Each event type (like Clicked and Selected) has its own XML attribute where you name the user event you want it to trigger.
That event is only triggered when it defines correct parameter list.

This article lists which event types require which parameter list for each ribbon item type.

Event Signatures per Ribbon Item Type

This section only lists item types that support user events.
For each item type it lists the XML Element, PowerBuilder class name, and available event types.
For each event type it lists the required parameter list for that item type.
Each combo of item type and event type is documented by screen shot and code snippets.

LargeButton

  • XML Element = LargeButton
  • Class Name = RibbonLargeButtonItem
  • Event Types
    • Clicked = event ue_BoardEmployees( long al_handle )
    • Selected = event ue_HoverBoardItem( long al_handle )
  • Parameters
    • al_handle = Refers to the button.

 

SmallButton

Similar to LargeButton except for picture size.

  • XML Element = SmallButton
  • Class Name = RibbonSmallButtonItem
  • Event Types
    • Identical to LargeButton (see above)

 

TabButton

Similar to LargeButton except for picture size and location within the ribbon.

  • XML Element = TabButton
  • Class Name = RibbonTabButtonItem
  • Event Types
    • Identical to LargeButton (see above)

 

CheckBox

Similar to LargeButton for user events albeit different properties.

  • XML Element = CheckBox
  • Class Name = RibbonCheckBoxItem
  • Event Types
    • Identical to LargeButton (see above)

 

Item (menu item in app's Recent menu)

Item's in app's Recent menu must use Type="2". That item type is prohibited anywhere else in the ribbon.

  • XML Element = Item Type="2"
  • Class Name = RibbonMenuItem
  • Event Types
    • Clicked = event ue_RecentBoardEmployees( long al_handle, long al_index )
    • Selected = event ue_HoverRecentItem( long al_handle, al_index )
  • Parameters
    • al_handle = Refers to ribbon's ApplicationButton.
    • al_index = Refers to menu item in the Recent menu.

 

Item (menu item in app's Master menu)

Item's in app's Master menu must use Type="0" (normal menu items) or Type="1" (separator lines). Separator lines seldomly bind to events.
Items appear either directly in the Master menu's dropdown or in cascading menus for items in the dropdown.

  • XML Element = Item
  • Class Name = RibbonMenuItem
  • Event Types
    • Clicked = event ue_AppAbout( long al_handle, long al_index, long al_subindex )
    • Clicked = event ue_Close( long al_handle, long al_index, long al_subindex )
    • Selected = event ue_ItemSelected( long al_handle, al_index, long al_subindex )
  • Parameters
    • al_handle = Refers to ribbon's ApplicationButton.
    • al_index = Refers to menu item in the Master menu.
    • al_subindex = Refers to menu item in the cascading menu.
      NOTE: About item in cascading menu has al_subindex > 0.
      NOTE: Close item without cascading menu has al_subindex = 0.

 

Item (menu item in other button menus)

Both LargeButton, SmallButton, and TabButton can contain a dropdown menu with optional cascading menus.
Menu items in button menus are similar to menu items in app's Master menu.

  • XML Element = Item
  • Class Name = RibbonMenuItem
  • Event Types
    •  Identical to Item in app's Master menu (see above)
  • Parameters
    • al_handle = Refers to button containing the menu.
    • al_index = Refers to menu item in button's dropdown menu.
    • al_subindex = Refers to menu item in the cascading menu.
      NOTE: Item in cascading menu has al_subindex > 0.
      NOTE: Item without cascading menu has al_subindex = 0.

 

ComboBox

ComboBox can have a dropdown list associated. Item in that list are ComboBox items.´They are different from menu items.
ComboBox itself has different set of event types that the other events.

  • XML Element = ComboBox
  • Class Name = RibbonComboBoxItem
  • Event Types
    • Selected = event ue_ComboSelected( long al_handle )
    • Modified = event ue_ModifiedPaperSize( long al_handle )
    • SelectionChanged = event ue_StandardPaperSize( long al_handle, al_index )
  • Parameters
    • al_handle = Refers to the ComboBox.
    • al_index = Refers to item in the combo dropdown.

SelectionChanged happens before Modified when both are defined and user selects an item from the dropdown.
Modified happens without SelectionChanged when user enters data directly in the edit box.

 

Outro

You cannot assign handle numbers to individual items. They are created at runtime like TreeView's item handles and RowID values in DataWindow objects.

An alternate approach is to assign a unique Tag value to each ribbon item and use GetItemByTag.
Function below adds new paper sizes to the ComboBox of paper size from example above.
It also widens the combo's dropdown list in case longer labels are added to the dropdown.

//  Function of_AddPaperSize(as_name, al_pictureID)
//    1)  Adds item to combo's list
//    2)  Widens combo width to fit longer text
//    3)  Adds VScrollBar
// ---------------------------------------------------
constant long   BOXWIDTH = 600
long   extraWidth
RibbonComboBoxItem   combo

ribbon_demo.GetItemByTag("print.pagesize", ref combo)

combo.InsertItem(as_name, al_pictureID, 1)

extraWidth = BOXWIDTH - combo.BoxWidth
combo.Width += extraWidth
combo.BoxWidth += extraWidth
combo.VScrollBar = true

// Update the RibbonBar
ribbon_demo.SetItem(combo)

Good luck starting out with the new RibbonBar control and its event processing!

 

Comments (9)
Tuesday, Jan 21 2020

Great info Michael, thanks!

0
Tuesday, Jan 21 2020

Thanks, Miguel. Is it worth promoting it to "featured article"?
As a regular article it can be hard to find. Lots of navigation before you discover it.
That's why I put link in Yiannis' Q&A on "menu => ribbon" guidance.

0
Tuesday, Jan 21 2020

Yeah I think so, I would never have seen it if not for the "Yiannis Q&A".

0

Thursday, Mar 26 2020

Buenas tardes
existe codigo fuente de este ejemplo?
Este ejemplo funciona para power builder 2019?

0
Saturday, Apr 25 2020

This is feature of PowerBuilder 2019 R2 not 2019. You need to upgrade your version to get this new feature.

0

Saturday, Jun 13 2020

Very cool Michael.
Would be nice with a video to :-)

0

Wednesday, Apr 07 2021

It would be cool to have a Single Line Edit added to the Ribbonbar to allow for search capabilities seen in other applications.

0
Thursday, Apr 08 2021

I do that by placing a dw control in the ribbonbar area. Not optimal but it works ok if you can live with it being to the right of the last ribbon obj.

0

Thursday, Apr 08 2021

I think that the way of linking the events between the items of the Ribbon Bar and the application according to their type is difficult and inappropriate. Indeed, the definition of each event is specific to the associated Ribbon Bar Item. This makes the use of the Ribbon Bar heavy and tedious.
Why not introduce in the Ribbon Bar control the ItemClicked & ItemSelected events with all the necessary parameters, such as for example the buttonClicked event of the Datawindow control?
This will make it possible to standardize and facilitate the use of the Ribbon Bar by making it possible in particular to centralize the management of events within two events instead of a multitude, while having the possibility of factoring the management of these through the calls to dedicated methods in case of need.
This would be a great enhancement to the Ribbon Bar Control, that will accelerate the adoption of this new control.

Check this in code exchange

Comment was last edited 3 years ago by Patrice Domange
1

Find Articles by Tag

PowerBuilder Compiler PostgreSQL ODBC driver Array ActiveX Branch & Merge Expression Trial Model Repository UI Outlook WebBrowser Data Performance Transaction PowerServer Web Interface JSONParser HTTPClient Stored Procedure 64-bit Validation DataWindow DevOps Oracle Service PowerServer Mobile GhostScript OrcaScript PDF Authorization Git PDFlib Database Painter Design Windows 10 Icons IDE Database Table SnapDevelop Graph Text Error Windows OS .NET Assembly SQL Server SnapObjects .NET Std Framework Platform CI/CD Bug Event Database Profile 32-bit Android REST Import JSON C# Web API Icon Linux OS SqlExecutor RibbonBar CoderObject SOAP UI Modernization Mobile .NET DataStore Menu Event Handler Web Service Proxy Elevate Conference SDK Debugger Syntax API Installation Variable OLE Open Source Migration Application COM DLL Export RESTClient TFS PBDOM Authentication PowerBuilder (Appeon) License Database Object Database MessageBox Export JSON XML Debugging Event Handling Script DataWindow JSON TortoiseGit Debug JSONGenerator PostgreSQL Filter External Functions Sort SVN Deployment Resize Source Code TLS/SSL OAuth Encryption NativePDF Messagging SqlModelMapper Charts DragDrop DataType OAuth 2.0 RibbonBar Builder Import PowerScript (PS) Window Database Connection Class Database Table Data BLOB PowerBuilder Configuration Excel JSON iOS Source Control Encoding PFC SQL Testing CrypterObject File UI Themes RichTextEdit Control InfoMaker Automated Testing TreeView WinAPI Database Table Schema Azure Jenkins ODBC