MapInfo Pro

Expand all | Collapse all

Adding control to the ribbon using the Alter/Create Buttonpad statements

  • 1.  Adding control to the ribbon using the Alter/Create Buttonpad statements

    Posted 10-29-2018 08:54
    Edited by Peter Horsbøll Møller 12-19-2018 06:12

    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.

    See Attachment

    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

    See Attachment

    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

       Exit Sub

    End If

    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:

    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)

    Print sCmd

    Run Command sCmd

    See Attachment

    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.


    zip   2K 1 version
    zip   875B 1 version

  • 2.  RE: Adding control to the ribbon using the Alter/Create Buttonpad statements

    Posted 11-01-2018 14:47

    Have the MapBasic docs been updated to reflect this new behavior? I don't believe so...

  • 3.  RE: Adding control to the ribbon using the Alter/Create Buttonpad statements

    Posted 11-01-2018 15:08

    Wow. I looked at the sample code in hopes of figuring out how to add a few simple buttons to execute other MBX routines... almost 600 lines of code to show how to add two buttons?? I know that sample does a whole lot more, but that is absurd. Hope the updated documentation shows an easy way to do what I need!

  • 4.  RE: Adding control to the ribbon using the Alter/Create Buttonpad statements

    Posted 11-01-2018 16:15

    Hi Steve

    The MapBasic docs haven't been updated yet as we haven't released a version of MapBasic that actually supports this feature yet.

    That's why you need to wrap the statement into a string and use the Run Command to execute it. In that way, the command will get executed at Runtime by MapInfo Pro without the MapBasic compiler needs to "know" about at compile time.

    I know, it's bit more more complicated but that's the way to do it right now.

    All the code you need to look at is mentioned directly here in the post. Look for sCmd = ...

    That's "all" you need to do to add a single control to the ribbon. The other 595 lines of code is the functionality of the Connect The Dots application.