With MapInfo Pro 17.0.1, the Alter Buttonpad and Create Buttonpad statements have been modified to also support adding controls to the ribbon interface. This makes it possible to very easy change your existing MapBasic code to adopt the ribbon interface.
Both statements have been extended to support dedicated ribbon features such as the Tab, the size of the control and the URI syntax for icons.
The statement will only support the Button types known from 32 bit: PushButton, ToolButton and ToggleButton.
We haven't released a MapBasic 17.0.1. We are considering releasing a new MapBasic for MapInfo Pro 17.0.2 which comes later this year (2018). But you can still take advantage of this new feature using the Run Command Statement.
Example using Connect The Dots
Connect the Dots is a famous application developed by one of the founders of MapInfo Corp back in 1999. In the example below I will show how you can make this application add a PushButton to an existing group on an existing tab on the ribbon interface.
First step is to comment out the old code adding menu items to the classic menu based interface of MapInfo Pro 32 bit.
Then I used the Alter Menu statement to add a new Menu Item to the Tools menu. In the ribbon interface, this will create a new menu item on the context menu of the application in the Tools window.
'**Adding a single menu item to the Tools Context menu
'**In 64 bit, the menu item will be added to the Application Context menu
Alter Menu ID M_TOOLS Add
"&Connect the Dots..." Calling ConnectTheDots
Next I make sure the user is running MapInfo Pro 17.0.1 or newer. Otherwise I will not be able to use the Alter Buttonpad statement to modify the Ribbon interface and the user will have to settle with the access to Connect the Dots via the application context menu shown above.
If SystemInfo(SYS_INFO_MIFULLVERSION) < 1701 Then
'Alter Buttonpad statement not yet supported for modifying ribbon
Finally, it is time to add a PushButton calling the Connect the Dots feature to the ribbon interface. I'll add the button to the Create group on the SPATIAL tab.
As I'm building this using MapBasic 17.0, I need to construct a string with the statement and use Run Command to make MapInfo Pro 17.0.1 execute the statement. If you are using a newer version of MapBasic (once we release one), you can run the statement directly from within the application and therefor avoid the Run Command.
You need to use the programmatic names of the Tab and the Group, not the Captions which is what you see in the interface. You can find these names in the RibbonElements.def file that I have attached to the this post. This file is also part of the MapBasic Common Library that you can find on Github: https://github.com/PeterHorsbollMoller/mbLibrary.
The Print statement below is only used for debugging purpose. It can be removed once the statement is working properly.
'**Adding a PushButton to the Create group on the SPATIAL tab
sCmd = "Alter ButtonPad " & Chr$(34) & "SpatialCreateBar" & Chr$(34)
& " Add PushButton"
& " Calling ConnectTheDots"
& " Large Icon -1 File " & Chr$(34) & "pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png" & Chr$(34)
& " HelpMsg " & Chr$(34) & "Connect the Dots\nConnect the Dots" & Chr$(34)
& " Tab " & Chr$(34) & "TabSpatial" & Chr$(34)
Run Command sCmd
I have included the sourcecode for the updated Connect The Dots application. The application has also be extended with the new application specific subprocedures and functions which makes the tool integrate better into the Tools window.
Notice that you have to remove the controls manually when you tool is being unloaded. MapInfo Pro will do this automatically if you are using this method for adding controls to the ribbon interface.