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.
Original Message:
Sent: 08-23-2024 07:48
From: Peter Møller
Subject: MapInfo Pro 2023 - how to add a "ToolButton" to a Ribbon Group
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 MainDeclare Sub EndHandlerDeclare 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 unloadedEnd Sub'------------------Sub CustomToolHandlerDim 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
Original Message:
Sent: 08-22-2024 10:23
From: Chris Nightingale
Subject: MapInfo Pro 2023 - how to add a "ToolButton" to a Ribbon Group
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
------------------------------