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: 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)

    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.

    Attachment(s)

    zip
    ConnectTheDots.zip   2K 1 version
    zip
    RibbonElements.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.



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

    Posted 12-13-2019 06:39

    With the MapBasic 17.0.3 and the upcoming MapBasic v2019, you can write the statement directly and get around the use of the Run Command.

    The statement will look like this:

    '**Adding a PushButton to the Create group on the SPATIAL tab
    Alter ButtonPad "SpatialCreateBar"
       Add PushButton
          Calling ConnectTheDots
          Large Icon -1 File "pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png"
          HelpMsg "Connect the Dots\nConnect the Dots"
       Tab "TabSpatial"

    Notice that the Tab keyword specified the ribbon tab and that the buttonpad name specifies the tab group. The Alter Buttonpad statement is used to add a button to an existing tab group on an existing tab.

    You can use the Create Buttonpad to create a new tab/tab group.



    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------



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

    Posted 01-07-2020 20:32
    Thanks Peter

    This is definitely simpler than the methods I've used in my tools to date.

    I've tested (on MapBasic 17.0.3) by creating simple tool (as shown below).

    Is there a simpler method to create new ribbons and ribbon groups to then add buttons too?

    Regards, Kalu


    '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include "MAPBASIC.DEF"
    Include "Menu.def"

    declare sub Main
    declare sub SayHello

    Sub Main

    OnError Goto HandleError

          '**Adding a PushButton to the Create group on the SPATIAL tab
          Alter ButtonPad "SpatialCreateBar"
             Add PushButton
                Calling SayHello
                Large Icon -1 File ApplicationDirectory$() & "_Icons\Star_32.png"
                HelpMsg "Say Hello\nSay Hello"
                Tab "TabSpatial"

    Exit Sub
         HandleError:
            Note "Main: " + Error$()
            Resume Next

    End Sub

    ' *******************************
    Sub SayHello

        Note "Hello!"

    End Sub

    ------------------------------
    Kalu Ribush
    Senior Mapping Specialist
    Department of Economic Development, Jobs, Transport and Resources (DEDJTR)
    Melbourne
    ------------------------------



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

    Posted 01-08-2020 03:57
    Edited by Peter Horsbøll Møller 01-10-2020 03:29
    Hi Kalu

    Yes, I agree. This is a great improvement for the MapBasic developers that are looking for an easy way to add a few controls/buttons to the ribbon interface without having to dive into the marvelous world of the ribbon.

    And yes, you can create new tabs and tab groups using the Create ButtonPad statement too. Remember that the ButtonPad is translated into a tab group. That means that Create ButtonPad will create a new tab group where Alter ButtonPad will modify an existing tab group.

    Here is a basic example of creating a new tab called BASE MAPS with two tab groups, Raster and Vector. If the tab doesn't exist, it will get created.
    Create ButtonPad "Raster" As
       PushButton
          Calling OpenBaseMap
          Large Icon -1 File ApplicationDirectory$() & "Images\TOP10DK_24.bmp"
          HelpMsg "Open a Base Map with roads, houses and water\nBase Map"
       PushButton
          Calling OpenBaseMap
          Large Icon -1 File ApplicationDirectory$() & "Images\Ortho_24.bmp"
          HelpMsg "Open an Aerial Base Map\nAerial Map"
       Tab "tabBaseMaps|BASE MAPS"
    
    Create ButtonPad "Vector" As
       PushButton
          Calling OpenBaseMap
          Large Icon -1 File ApplicationDirectory$() & "Images\Matrikelkort_24.bmp"
          HelpMsg "Open a map with cadastre information\nCadastre Map"
          Tab "tabBaseMaps"​


    Notice the naming of the new tab: "tabBaseMap|BASE MAPS". The first part is the internal name to use when referencing the tab. The internal name can't contain spaces. The second part is the caption, the visible name of the tab. You separate the two with a pipe (|).


    Here's how the end result looks:


    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------