Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Porting simple applications to the ribbon interface using MapBasic


Published on

Taken from the highly successful webinar - Porting simple applications to the ribbon interface using MapBasic (broadcast on October 23, 2017) - these slides, used by MapInfo Pro expert Peter Horsbøll Møller, introduce you to the all-new MapInfo Pro ribbon interface and provide some handy guidance on integrating your existing MapBasic applications.

Watch the webinar replay:

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Porting simple applications to the ribbon interface using MapBasic

  1. 1. Porting simple applications to the ribbon interface using MapBasic Peter Horsbøll Møller October 2017
  2. 2. Agenda: 1. Concepts of the ribbon interface 2. Control types available 3.Taking advantage of theTools window 4. Integrate a tool in the ribbon interface 5. Resources
  3. 3. “The ribbon interface makes it easier to discover features and functions of MapInfo Pro”
  4. 4. 1. Concepts of the ribbon interface
  5. 5. Ribbon:The Main Ribbon Interface from which all Ribbon controls inherit. RibbonTab: Individual member of RibbonTabCollection (e.g.: HOME,TABLE, MAP, SPATIAL, etc.). RibbonTab Group: Group of Ribbon controls under a specific RibbonTab 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 RibbonTab Group.
  6. 6. 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 ofTab Groups. EachTab Group has a collection of Controls. A control, as well as the other instances the Ribbon, theTabs and the Groups, have properties such as captions and icons that can be set.
  7. 7. 2. Control types available
  8. 8. Button Control SplitButton Control Button Controls Gallery Control GalleryItem Controls
  9. 9. ToolButton Control DropDownButton Control Button Controls
  10. 10. 3.Taking advantage of the Tools window
  11. 11. Tools window on the HOME tab
  12. 12. Tools window as a dockable window
  13. 13. 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 NameDefault Command activated thru double click
  14. 14. 4. Integrate a tool in the ribbon interface
  15. 15. 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 theTools Window, others also into the LEGACY tab
  16. 16. Definition files Typically, you have used a number of standard definition files in your MapBasic application: • MapBasic.def: Constants for MapBasic functions likeTableInfo() 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 • Enums.def: Constants used in the .NET API such as control types etc.
  17. 17. Includes and Declares Include the new definition files: Include "IMapInfoPro.def" Include "Enums.def" Declare theTools 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
  18. 18. 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
  19. 19. 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) Getting the .NET instances
  20. 20. 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") Adding controls to the Ribbon
  21. 21. 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") Adding controls to the Ribbon
  22. 22. 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 controls to the Ribbon
  23. 23. 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) Adding controls to the Ribbon
  24. 24. 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 Adding a Clean up to the EndHandler
  25. 25. Let’s add the procedures and functions for theTools 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 Integrating into theTools window
  26. 26. 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 Integrating into theTools window
  27. 27. Include Files Addin sub/function declares
  28. 28. Global ribbon variables Getting the ribbon elements
  29. 29. Adding a control to the ribbon Specifying the handler Adding Tooltip Specifying icons
  30. 30. EndHandler to remove controls
  31. 31. Addin subs and functions
  32. 32.
  33. 33. “Even though most MapBasic applications will run in 64 bit, spending some time integrating them into the ribbon will be worth the while”
  34. 34. 4. Resources
  35. 35. • Li360 Community • The MapBasicTopic • The MapInfo Pro DeveloperGroup • How to customize the MapInfo Pro ribbon interface document, find it in the MapInfo Pro Developer Group • Attend the upcoming MapBasic webinar in November • Look at the MapBasic samples that ship with MapBasic 16.0 • Look at applications from the Community Download page You have come this far and now you want to learn more?
  36. 36. • Get started, give it a try and ask for help on the Li360 Community, <<go to the Li360 Community>> • Consider looking into using the RIBBONLib module? • Watch this video: Getting started with the RIBBONLib MapBasic library <<Find it here on Li360>> • Consider using .NET to customize the ribbon? What could my next steps be?
  37. 37. What did he just talk about? We looked at the structure and elements of the ribbon and what control types you have access to. We investigated the new tools window and how to integrate your tools into this and finally we ported a very basic tool to the ribbon interface.
  38. 38. Thank you! Peter Horsbøll Møller | Pitney Bowes