Porting simple applications to the ribbon
interface using MapBasic
Peter Horsbøll Møller October 2017
Agenda:
1. Concepts of the ribbon interface
2. Control types available
3. Taking advantage of the Tools window
4. Integrate a tool in the ribbon interface
5. Resources
“The ribbon interface
makes it easier to
discover features and
1. Concepts of
the ribbon
Ribbon:
The Main Ribbon Interface from which all Ribbon controls inherit.
Ribbon Tab:
Individual member of Ribbon Tab Collection (e.g.: HOME, TABLE, MAP,
SPATIAL, etc.).
Ribbon Tab Group:
Group of Ribbon controls under a specific Ribbon Tab that are
typically related tasks (e.g.: File, Clipboard, Windows, etc.).
Ribbon Button Control:
the actual control (e.g.: Tool Button or Split Button, etc.)
that reside within the Ribbon Tab Group.
Working with the .NET SDK from MapBasic
It helps if you try to adopt an “Object Orientated” approach.
First, you need to get the MapInfo Pro instance (or object).
From the MapInfo Pro instance, you can get the Ribbon instance.
The Ribbon instance has a collection of Tab Groups.
Each Tab Group has a collection of Controls.
A control, as well as the other instances the Ribbon, the Tabs and the
Groups, have properties such as captions and icons that can be set.
2. Control types
available
Button Control
SplitButton Control
Button Controls
Gallery Control
ToolButton Control DropDownButton Control
3. Taking
advantage of the
Tools window
Tool window – Addin procedures
Each tool can publish information
Sub procedures:
•
Sub AddIn_About
•
Sub AddIn_Help
•
Sub AddIn_DefaultCommand
Functions:
•
Function AddIn_Name()
•
Function AddIn_Description()
•
Function AddIn_Version()
•
Function AddIn_ImageUri()
•
Function AddIn_DefaultCommandText()
Help File Aboutbox End
Description Version Image Name Default Command activated thru double click
4. Integrate a
tool in the
Running an old application
You can run older applications in the new 64 bit MapInfo Pro
Many of these will work and get loaded
Some will be only loaded into the Tools Window, others also into the
LEGACY tab
Definition files
Typically, you have used a number of standard definition files in your
MapBasic application:
• MapBasic.def: Constants for MapBasic functions like TableInfo() etc.
• Menu.def: Constants for MapInfo Pro menu commands
• Icons.def: Constants for icons used in MapInfo Pro
When building an application for the ribbon interface in MapInfo Pro
you will need to include a few more:
• IMapInfoPro.def: Declaration for the .NET API methods
Includes and Declares
Include the new definition files:
Include "IMapInfoPro.def"
Include "Enums.def"
Declare the Tools window procedures/function you want to use:
Declare Sub AddIn_About
Declare Function AddIn_Name() As String
Declare Function AddIn_Description() As String
Declare Function AddIn_Version() As String
Declare Function AddIn_ImageUri() As String
Declare the EndHandler used to remove controls from the ribbon
Declare Sub EndHandler
Modular level variables
'IMapInfoPro:
Dim mtsMapInfoApplication as This
'The Ribbon:
Dim mtsRibbon as This
'The Tab Collection of the Ribbon:
Dim mtsRibbonTabColl as This
'The Control Collection of the group:
Dim mtsGroupControlColl As This
'The Button we are adding:
Dim mtsBtn As This
Let’s build the interface:
Sub Main
'We need this to get resources, like icons, from .NET assemblies Call RegisterUriParser(New_GenericUriParser(1), "pack", -1)
'Get the IMapInfoPro instance
mtsMapInfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION) 'Get the Ribbon from the MapInfo Pro instance
mtsRibbon = GetRibbon(mtsMapInfoApplication)
'Get the Ribbon Tab Collection from the Ribbon instance mtsRibbonTabColl = GetTabsColl(mtsRibbon)
Still preparing to build the interface:
'Get the Ribbon Tab named "TabSpatial" from the Ribbon Tab Collection Dim tsRibbonTab As This
tsRibbonTab =GetRbnTabCollItemStr(mtsRibbonTabColl, "TabSpatial") 'Get the ribbon group collection.
Dim tsRibbonGroupColl As This
tsRibbonGroupColl = GetRbnTabGrps(tsRibbonTab)
'Get the ribbon group "SpatialCreateBar" from the ribbon group collection Dim tsRibbonGroup As This
tsRibbonGroup = GetRbnCtrlGrpCollItemStr(tsRibbonGroupColl
, "SpatialCreateBar")
Let’s add a control/button:
'Get Group controls collection
mtsGroupControlColl = GetRbnCtrlGrpCtrls(tsRibbonGroup)
'Now add a button to the group's controls collection with a name ', caption, and enumerated ControlType
mtsBtn = MICtrlCollAddStrStrInt(mtsGroupControlColl, "btnConnectDots“
, "Connect The Dots", ControlType_Button) 'Set command to the button
call SetRbnBtnCtrlCallingHandler(mtsBtn, "ConnectTheDots")
Let’s add a tooltip to the control/button:
'Create & Set the button tooltip Dim tsToolTip As This
tsToolTip = New_MapInfoRibbonToolTip()
Call SetMIRbnToolTipToolTipDescription(tsToolTip, "Connect The Dots")
Call SetMIRbnToolTipToolTipText(tsToolTip, "Creates a polygon or polyline from the points selected")
Call SetMIRbnToolTipToolTipDisabledText(tsToolTip, "Make sure to select records from a layer")
Call SetRbnBtnCtrlToolTip(mtsBtn, tsToolTip)
Adding icons and setting the size of the control:
'Set the button icon
Call SetRbnBtnCtrlSmallIcon(mtsBtn, New_Uri("pack://application:, , , /MapInfo.StyleResources;component/Images/Spatial/segmenting_16x16.png", 0))
Call SetRbnBtnCtrlLargeIcon(mtsBtn, New_Uri("pack://application:, , , /MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png", 0))
'Set the size of the button
Call SetRbnBtnCtrlIsLarge(mtsBtn, TRUE)
Removing the control from the ribbon on exit:
Sub EndHandler
Dim bRemoved As Logical OnError Goto HandleError
bRemoved = MICtrlCollRemove(mtsGroupControlColl, mtsBtn)
mtsBtn = NULL_PTR
Exit Sub HandleError:
Note "EndHandler: " + Error$() Resume Next
End Sub
Let’s add the procedures and functions for the Tools window:
Sub AddIn_About Call About
End Function
Function AddIn_Name() As String
AddIn_Name = "Connect The Dots" End Function
Function AddIn_Description() As String
AddIn_Description = "Creates a polygon or polyline from the points selected in the layer the points are selected from."
End Function
Function AddIn_Version() As String AddIn_Version = "2.0"
End Function
Function AddIn_ImageUri() As String
AddIn_ImageUri = "pack://application:, , ,
/MapInfo.StyleResources;component/Images/Spatial/segmenting_16x16.png" End Function
Include Files
Global ribbon variables
Adding a control to the ribbon
Specifying the handler
Adding Tooltip