MapInfo Pro Developers User Group

 View Only
  • 1.  MapInfo Pro 2023 - how to add a "ToolButton" to a Ribbon Group

    Posted 08-22-2024 10:24
    Edited by Chris Nightingale 08-23-2024 03:57

    Hi Everybody,

    I've been tasked with updating our MapBasic app to work with MapInfo Pro 2023.  A lot of it still works (except having to replace the rather out of date DDE comms with something a little more modern!!) but there are some things I'm struggling to convert.

    One of those is our MapBasic app has (or should I say "had") a menu with a number of menu items as well as two tool buttons (which require the user to select a region before the rest of the functionality kicks in) and these were ending up in a "Legacy" Ribbon Tab.

    I have managed to move our menu items into a new Ribbon as Push Buttons using code such as

    'Get MIPro interface
    mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)
    'Get Ribbon
    ribbon = GetRibbon(mapinfoApplication)
    'Get RibbonTabs Collection
    ribbonTabColl = GetTabsColl(Ribbon)
    'Create the new Tab
    ourAppRibbonTab = RbnTabCollAddStrStr(ribbonTabColl, "ourApp", "ourApp")
     'Access the groups collection of the ribbon
    ourAppTabGroupCollection = GetRbnTabGrps(ourAppRibbonTab)
    'Create the "Actions" and "Tools" group
    ourAppActionsGroup = RbnCtrlGrpCollAddStrStr(ourAppTabGroupCollection, "ourAppActions", TranslateText("Actions"))
    ourAppToolsGroup = RbnCtrlGrpCollAddStrStr(ourAppTabGroupCollection, "ourAppTools", TranslateText("Tools"))
    ' Add the "Actions" buttons
    Alter ButtonPad "ourAppActions"
    Add PushButton
    Calling ShowButtonHandler
    Large Icon -1 File ApplicationDirectory$() & "Images\Show_selected_records_in_ourApp_32.png"
    HelpMsg TranslateText("Show the selected item(s) in ourApp") & "\n" & TranslateText("Show...")

    But if I try the same with a ToolButton, it still ends up on the Legacy Tab.

    I found this comment in the MapInfo Pro 2023 MapBasic User Guide.pdf file which implies it cannot be done:

    Custom drawing tools (created using the Create ButtonPad or Alter ButtonPad statements, with
    the ToolButton subclause) are not supported by the current Layout window. Custom drawing tools
    that work with Map windows are supported inside of map frames, but such tools only work on the
    map frame after the frame is activated.

    Is this actually the case - if so, how have tools like "Zoom In" and "Zoom Out" managed to get into ribbon groups as found on the "Map" Ribbon Tab as they are clearly Tool Buttons are they not?

    Is there a way this can be done or is what was written in the pdf file correct?  Otherwise what options do I have and could you provide maybe a simple example of how I do this in MapBasic 2023?

    I found this post from a while back which seems to suggest it was possible in v17 but I guess it's not longer the case:

    Adding Tool Button to Ribbon Interface (google.com)

    Thanks in advance for your time,


    Chris Nightingale



    ------------------------------
    Chris Nightingale
    Knowledge Community Shared Account
    Burlington MA
    ------------------------------



  • 2.  RE: MapInfo Pro 2023 - how to add a "ToolButton" to a Ribbon Group

    Employee
    Posted 08-23-2024 07:48
      |   view attached

    Hi Chris

    At some point, I recall we had some issues using the built-in Toolhandler for a ToolButton. I'd recommend using a custom handler for your tool instead and use this to grab the coordinate where the user clicked.

    That can be done using the Alter/Create Buttonpad command.

    Below you can see such an example. Note that I add the same button in 3 different places: to an existing group on the Map tab, to a new group on the Map tab, and to a new group on a new tab.

    Include "MapBasic.def"
    Include "Menu.def"
    Include "Icons.def"
    
    Declare Sub Main
    Declare Sub EndHandler
    Declare Sub CustomToolHandler
    
    '------------------
    Sub Main
    
    	'**Add ToolButton to existing Create group on the Map tab
    	Alter ButtonPad "MapCreateBar" Add
    		ToolButton
    			Calling CustomToolHandler
    			Large Icon -1 File "pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png"
    			Cursor MI_CURSOR_CROSSHAIR
    			DrawMode DM_CUSTOM_POINT
    			HelpMsg "Capture Coordinate where you click\nCapture Coordinate"
    		Tab "TabMap"
    
    	'**Add ToolButton to a new group called Capture on the Map tab
    	Create ButtonPad "Capture" As
    		ToolButton
    			Calling CustomToolHandler
    			Large Icon -1 File "pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png"
    			Cursor MI_CURSOR_CROSSHAIR
    			DrawMode DM_CUSTOM_POINT
    			HelpMsg "Capture Coordinate where you click\nCapture Coordinate"
    		Tab "TabMap"
    
    	'**Add ToolButton to a new group called Capture on a new tab called Capture
    	Create ButtonPad "Capture" As
    		ToolButton
    			Calling CustomToolHandler
    			Large Icon -1 File "pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png"
    			Cursor MI_CURSOR_CROSSHAIR
    			DrawMode DM_CUSTOM_POINT
    			HelpMsg "Capture Coordinate where you click\nCapture Coordinate"
    		Tab "TabCapture|Capture"
    
    End Sub
    
    '------------------
    Sub EndHandler
    
    	'**Doesn't have to do anything, but has to be here
    	'**To avoid the tool from being unloaded
    
    End Sub
    
    '------------------
    Sub CustomToolHandler
    
    Dim	fX, fY As Float,
    	nMID As Integer
    
    	nMID = FrontWindow()
    
    	Set CoordSys Window nMID
    	fX = CommandInfo(CMD_INFO_X)
    	fY = CommandInfo(CMD_INFO_Y)
    
    	Note "You clicked at ( " & FormatNumber$(Round(fX, 0.01)) & " | " & FormatNumber$(Round(fY, 0.01)) & " )"
    
    End Sub

    I have also attached the small sample code as a MapBasic source file.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    ToolButtonButtonPad.zip   763 B 1 version


  • 3.  RE: MapInfo Pro 2023 - how to add a "ToolButton" to a Ribbon Group

    Posted 08-23-2024 07:54
    Edited by Chris Nightingale 08-23-2024 09:41

    Hi Peter,

    Many thanks for the reply and the very detailed example.

    I will give this a try.

    I'm still very new to all this but hopefully will gradually get the hang of it!!

    [Update]

    With a bit of tweaking that has worked for me - I had to change "DM_CUSTOM_POINT" to "DM_CUSTOM_RECT" to give the rectangle selection tool and also found I still had to make calls like this:

    ourAppActionsGroup = RbnCtrlGrpCollAddStrStr(ourAppTabGroupCollection, "ourAppActions", TranslateText("Actions"))

    Otherwise they all ended up on the Legacy tab again - but seems happier now.


    So thanks again
    ------------------------------
    Chris Nightingale
    i2 Group
    Burlington MA
    ------------------------------