customizing the ribbon interface (backstage) with MapBasic

410 views
Skip to first unread message

NYS DOH CEH BEOE EHS

unread,
Feb 20, 2015, 1:20:28 PM2/20/15
to mapi...@googlegroups.com
I was trying to customize the backstage using MapBasic, and I ran into an issue that was driving me nuts that

Peter Horsbøll Møller did not mention in his Linkedin post. If you want to use a subroutine as a handler for a button you add, you must use "CREATE MENU" to create a legacy menu as well, with a calling clause (see code below) (You don't have to display the menu). If you don't do this, it won't work.  Even worse, it won't give an error message either.  I haven't seen this documented anywhere, so I hope posting this will save someone some trouble.

Does anyone else have example code for modifying the ribbon interface/backstage?  For some reason, the examples given in the MapBasic User Guide don't seem to be actually written in MapBasic.

'this program will test adding stuff to the backstage
'this is for 64-bit MI 12.5.1, which has ribbon interface
'programmed in MapBasic 12.5.1 under windows 7
'New York State Department of Health, Center for Environmental Health
'Feb 20, 2015
'create a simpler version of the code so that demonstrate need for CREATE MENU to correct handler functioning
'*****************************************************
'if I do not put the full path, mapbasic may grab an older version of these DEF files
include "C:\Program Files (x86)\MapInfo\MapBasic12\MENU.DEF"
include "C:\Program Files (x86)\MapInfo\MapBasic12\MAPBASIC.DEF"
include "C:\Program Files (x86)\MapInfo\MapBasic12\ICONS.DEF"
include "C:\Program Files (x86)\MapInfo\MapBasic12\IMapInfoPro.def"
include "C:\Program Files (x86)\MapInfo\MapBasic12\Enums.def"

declare sub main
declare sub dosomething
   
sub main

dim mapinfoApplication, mybackstage, mybackstagecontrols, mybackstagetabcontrols, mybackstagetab,         
      mynewtab, mynewbuttonintab as this

'check if we have the ribbon interface before we try to do something with it   
if SystemInfo(SYS_INFO_MAPINFO_INTERFACE) = MIINTERFACE_RIBBON then 'check if have ribbon interface before we do this
    print "We have detected the ribbon interface"
   
    'get the Mapinfo application
    mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)

    'get the backstage
    mybackstage = GetRibbonBackStage(mapinfoApplication)

    'get the backstage controls
    mybackstagecontrols=GetRbnBackStageCtrls(mybackstage)

    'use the controls to insert a tab - goes in the blue column to the left
    mynewtab=MICtrlCollInsertIntStrStrInt(mybackstagecontrols,1,"newtab","tab@1",ControlType_BackStageTabItem)

    'get the controls for the new tab
    mybackstagetabcontrols=GetIBackStageTabItemCtrls(mynewtab)
    'use the controls to add a new ribbon button
    mynewbuttonintab=MICtrlCollAddStrStrInt(mybackstagetabcontrols,"newbutton","my ribbon button",1) 'adds a new ribbon control button
    'add a handler to the ribbon button
    call SetRbnBtnCtrlCallingHandler(mynewbuttonintab, "dosomething") 'you need also to create the legacy menu to add the subroutine as a handler
  
end if 'if have ribbon interface

'MUST HAVE LEGACY MENU FOR HANDLERS TO WORK.  You do not need to display it, however.
create menu "&testMenu" as
    "Do it" calling dosomething

end sub

sub dosomething
    note "you have clicked on the button"
end sub

Peter Horsbøll Møller

unread,
Feb 21, 2015, 9:04:17 AM2/21/15
to mapi...@googlegroups.com
That would have droven me nuts as well - how did you come to think of adding a classic menu?

Anyway I have been able to replicate this behaviour and I'll try to figure out what's going on.
I have worked with the Backstage part of the new ribbon yet myself.

Peter Horsbøll Møller
Pitney Bowes Software



Date: Fri, 20 Feb 2015 10:20:28 -0800
From: beoe.e...@gmail.com
To: mapi...@googlegroups.com
Subject: [MI-L] customizing the ribbon interface (backstage) with MapBasic
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Horsbøll Møller

unread,
Feb 23, 2015, 3:25:29 AM2/23/15
to mapi...@googlegroups.com
Hi

Okay, here's the reason:
You need to have at least one of the old event handlers in your application to keep the application a live. I would recommend that you basically add the EndHandler to the application like this:

Declare Sub EndHandler
'....
Sub EndHandler
Print "Application is now terminating!"

'**Here should also be some statements for removing 
'**the controls added by the application from the Ribbon/Backstage area
End Sub 

Also do note that there has been a change from earlier when it comes to clearing up the user interface when your application it terminating. In earlier versions MapInfo Pro removed the menus, menu items, buttonpad and buttons that your application had added to the user interface. With the new Ribbon interface the application needs to remove it's own controls.

If the application doesn't do this, they will stay visible in the interface but they will not do anything when the user clicks them - because the application has been terminated.

This is also what you are seeing here - the button is there on the backstage but your application isn't running anymore.


Peter Horsbøll Møller
Pitney Bowes Software



Date: Fri, 20 Feb 2015 10:20:28 -0800
From: beoe.e...@gmail.com
To: mapi...@googlegroups.com
Subject: [MI-L] customizing the ribbon interface (backstage) with MapBasic

Reply all
Reply to author
Forward
0 new messages