MapInfo Pro Developers User Group

 View Only
  • 1.  Add new button under existing Ribbon Tab

    Posted 01-11-2022 10:26
    Edited by Peter Møller 01-12-2022 01:47
    Hi

    Newby MapBasic coder problem :). How can I add new Ribbon Button Control under existing Ribbon Tab and under existing Ribbon Tab Group (if it is present in MapInfo). This existing Ribbon Tab (called "PTA lisad") is created for my other MapBasic tool using document "How to Customize the MapInfo Pro Ribbon Interface". 

    I try to use P. H. Møller's mbLibrary to achieve this goal.To begin with I guess I have to check whether Ribbon Tab called "PTA lisad" is present in Ribbon Tab Collection. According to mbLibrary RibbonLib-->RBNLoop the real name for "PTA Lisad" is "Tühi1" (attachment "RibbonElements"). Next I try to call function RBNTabExists from RibbonLib. Now I'm stuck with error (attachment "mb_error_on_compilation") then I compile this .mb. I'm using MapInfo 2019.3.

    Include "mapbasic.def"
    Include "IMapInfoPro.def"
    Include "Enums.def"
    Include "Menu.def"
    Include "Icons.def"
    Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\RIBBONLib.def"

    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\RibbonElements.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\ARRAYLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\ConfigFileLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\FILELib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\RESSTRNGLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\DEBUGLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\ERRORLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\STRINGLib.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\defaults.def"
    'Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\WINAPI 1522.def"

    Declare Sub main
    Declare Sub EndHandler
    'Declare Function RBNTabExists(ByVal sTabName As String) as Logical

    Global mapinfoApplication as This
    Global Ribbon as This
    Global RibbonTabColl as This
    Global RibbonTab as This
    Global ribbonGroupsColl as This
    Global ribbonGroup as This
    Global groupControlColl as This
    Global button1 as This
    Global button1ToolTip as This
    Global rbnTabItem As This
    Global CheckTabExist As Logical
    'Global TabName As String

    Sub main

    Dim kQuery, x, z as String
    Dim NumOfTables, i, j, nArrayIndex as Integer
    Dim k as Logical

    'TabName="Tühi1"

    Call RegisterUriParser(New_GenericUriParser(1), "pack", -1)
    mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)
    Ribbon = GetRibbon(mapinfoApplication)
    RibbonTabColl = GetTabsColl(Ribbon)

    Call RBNTabExists("Tühi1")
    If CheckTabExist then
    Print "Tab exists"
    Else
    Print "Tab does not exist"
    End If

    End Sub

    '*************************************************
    Sub EndHandler
    '*************************************************

    dim bRet as logical

    'bRet = MICtrlCollRemove(RibbonTabColl, RibbonTab)
    'bRet = MICtrlCollRemove(ribbonGroupsColl, button1)
    'bRet = MICtrlCollRemove(ribbonGroup, button1)

    mapinfoApplication = NULL_PTR
    Ribbon = NULL_PTR
    RibbonTabColl = NULL_PTR
    RibbonTab = NULL_PTR
    ribbonGroupsColl = NULL_PTR
    ribbonGroup= NULL_PTR
    groupControlColl= NULL_PTR
    button1= NULL_PTR
    button1ToolTip= NULL_PTR

    End Sub

    ----------------------------------------------------------------------------
    Thanks in advance

    Asko Põder
    Estonian Agriculture and Food Board

    ------------------------------
    Asko Poder
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Add new button under existing Ribbon Tab

    Employee
    Posted 01-12-2022 02:08
    Hi Asko

    You were close. The problem is that RBNTabExists() is a function, not a procedure.

    But be aware that a tab has a name and a caption. The name is internal and only visible to the developer. The caption is the title seen in the ribbon.
    The RIBBONLib has a couple of functions for looking for existing tabs.

    • RBNTabExists(): Looks for a tab using the internal name
    • RBNTabExistsCaption(): Looks for a tab using the caption
    • RBNTabGetNameFromCaption(): Returns the name of the tab with a given caption

    I took a stab at getting you started by initially looking for the tab and if it doesn't exists, I'll it.
    I used the later of the three function above to get the internal name of the tab as that's what I need if I want to add additional groups and controls to a tab.

    I removed all you global variables. You will have access to most, i fnot all, of these as they are declared as global variables in the RIBBONLib.def:
    Global theMapInfoApplication As This,
    theMapBasicApplication As This,
    theMapInfoEvents As This,
    theStatusbar As This,
    theStatusbarControlsColl As This,
    theRibbon As This,
    theBackstage As This,
    theQAT As This,
    theToolContextMenu As This,
    theTabsColl As This,
    theToolContextMenuItemsColl As This,
    theContextMenus As This,
    theMapMTB As This,
    theMapMTBControlsColl As This,
    theNotification As This

    You can get them initiated by calling RBNInitiate, and they will get initiated if you use any of the functions in the RIBBONLib.

    In your EndHandler, I removed all the calls to remove controls etc, and replaced these with a call to the RibbonLib EndHandler, RBNEndHander. This procedure will remove all the controls that you have added through the RIBBONLib

    Include "mapbasic.def"
    Include "IMapInfoPro.def"
    Include "Enums.def"
    Include "Menu.def"
    Include "Icons.def"
    Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\RIBBONLib.def"

    Declare Sub main
    Declare Sub EndHandler

    Sub main

    Dim kQuery, x, z as String
    Dim NumOfTables, i, j, nArrayIndex as Integer
    Dim k as Logical

    Dim sTabName As String
    Dim nCtrlIdx As Integer

    sTabName = RBNTabGetNameFromCaption("Tühi1")

    If sTabName <> "" Then
    Print "Tab exists"
    Else
    Print "Tab does not exist, let's create it"
    sTabName = "tabTuhil"
    nCtrlIdx = RBNAddTab(sTabName, "Tühi1", "")
    End If

    End Sub

    '*************************************************
    Sub EndHandler
    '*************************************************
    'Call the EndHandler from the RibbonLib which will remove elements added to the ribbon
    Call RBNEndHandler

    End Sub

    If you are moving onto MapInfo Pro v2021, be aware that we have added full support for modifying and querying the ribbon through MapBasic with some new statements and functions such as Create Ribbon, Set Ribbon, RibbonInfo, RibbonItemInfo and more.

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



  • 3.  RE: Add new button under existing Ribbon Tab

    Employee
    Posted 01-12-2022 08:26
    Hi Asko:
    if you want to do this without using Peter's RibbonLib nearly all our built-in tools create controls under existing Ribbon Tabs.
    If you look at the MB source code under \Samples\MAPBASIC\Disperse (for one example), you will see how this is done through these extensibility methods in MapBasic.  Peter's RibbonLib is just a wrapper around these Extensibility methods defined in IMapInfoPro.def.
    If you want to do this solely in MapBasic (in version 2100) without calling Extensibility methods as Peter mentions, the \Samples\MAPBASIC\CreateRibbon sample code provided with MapBasic 21 has an example for creating every control type available in the Ribbon using Create Ribbon, Set Ribbon, RibbonInfo, etc.

    ------------------------------
    Bill Wemple
    Principal Software Engineer, Quality Management
    Precisely, Inc
    precisely.com
    ------------------------------



  • 4.  RE: Add new button under existing Ribbon Tab

    Posted 01-14-2022 02:08
    Edited by Asko Poder 01-14-2022 02:11
    Thank you for your answers. They gave me tips I needed to achieve my goal. I got first taste too how to use Peter's mbLibrary. My final Ribbon part of my program is following:

    Include "mapbasic.def"
    Include "IMapInfoPro.def"
    Include "Enums.def"
    Include "Menu.def"
    Include "Icons.def"
    Include "C:\My_documents\MapBasic\mbLibrary\mbLibrary-master\RIBBONLib.def"

    Declare Sub main
    Declare Sub Ruumikuju_vahetamine ' When Ribbon button is clicked this external procedure is activated.
    Declare Sub AddIn_About
    Declare Sub AddIn_Help
    Declare Sub AddIn_DefaultCommand
    Declare Sub EndHandler

    Declare Function AddIn_DefaultCommandText() As String
    Declare Function AddIn_Description() As String
    Declare Function AddIn_ImageUri()As String
    Declare Function AddIn_Name()As String
    Declare Function AddIn_Version()As String


    '*******************************************************************
    Sub main


    Dim nCtrlIdx As Integer
    Dim sTabName As Logical
    Dim LargeIconLocation As String
    Dim SmallIconLocation As String

    'Procedure in RibbonLib, which gives the names and captions in Ribbon
    'Call RBNLoop 


    If not RBNTabExists( "Tühi1") then
    nCtrlIdx = RBNAddTab("Tühi1", "PTA lisad", "")
    nCtrlIdx = RBNTabAddGroup("TabSisestus","Sisestustööriista lisad","Tühi1")
    nCtrlIdx = RBNGroupAddButton("TabRuumikujuVahetamine", "Ruumikuju vahetamine", "", "Tühi1", "TabSisestus")
    Call RBNControlSetToolTipIdx(nCtrlIdx,"Siin on tutvustav tekst tööriista kohta","","")
    LargeIconLocation=ApplicationDirectory$() & "Images\" & "Ruumik_asendamine_32.ico" 'My icon is located in local disc in picture file format not in dll.
    SmallIconLocation=ApplicationDirectory$() & "Images\" & "Ruumik_asendamine_16_ver2.ico"
    Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_LARGE,SmallIconLocation,LargeIconLocation)
    Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "Ruumikuju_vahetamine")

    Else
    nCtrlIdx = RBNTabAddGroup("TabSisestus","Sisestustööriista lisad","Tühi1")
    nCtrlIdx = RBNGroupAddButton("TabRuumikujuVahetamine", "Ruumikuju vahetamine", "", "Tühi1", "TabSisestus")
    Call RBNControlSetToolTipIdx(nCtrlIdx,"Siin on tutvustav tekst tööriista kohta","","")
    LargeIconLocation=ApplicationDirectory$() & "Images\" & "Ruumik_asendamine_32.ico"
    SmallIconLocation=ApplicationDirectory$() & "Images\" & "Ruumik_asendamine_16_ver2.ico"
    Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_LARGE,SmallIconLocation,LargeIconLocation)
    Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "Ruumikuju_vahetamine")

    End If

    End Sub

    '*************************************************
    Sub AddIn_About
    '*************************************************
    Note "See tööriist võimaldab asendada korraga ühe või mitu sisestustööriista ruumikuju mingil kasutaja enda MapInfo kihil oleva ühe või mitme ruumikujuga."

    End Sub


    '*************************************************
    Function AddIn_DefaultCommandText() as string
    '*************************************************
    AddIn_DefaultCommandText = "Käivita tööriist"

    End Function


    '*************************************************

    Function AddIn_Description() as String
    '*************************************************
    ' Note "This describes the tool in use"
    AddIn_Description="See tööriist võimaldab asendada korraga ühe või mitu sisestustööriista ruumikuju mingil kasutaja enda MapInfo kihil oleva ühe või mitme ruumikujuga."
    End function


    '*************************************************
    Sub AddIn_DefaultCommand
    '*************************************************
    call Ruumikuju_vahetamine

    End Sub


    '*************************************************
    Function AddIn_ImageUri() As String
    '*************************************************
    AddIn_ImageUri = ApplicationDirectory$() & "/Images/" & "Ruumik_asendamine_16_ver2.ico"

    End Function


    '*************************************************
    Sub AddIn_Help 
    '*************************************************
    Note "1. Vali sisestustööriista kiht, mille ruumikuju soovid muuta."+Chr$(13)+"2. Vali enda kiht, kus asuvad uued ruumikujud."+Chr$(13)+"3. Vali seoseväljad kahe tabeli vahel."+Chr$(13)+"4. Käivita ""OK"" või katkesta ""Cancel""."

    End Sub


    '*************************************************
    Function AddIn_Name() As String
    '*************************************************
    AddIn_Name = "Ruumikuju vahetamine"

    End Function


    '*************************************************
    Function AddIn_Version() As String
    '*************************************************

    AddIn_Version = "1.0"

    End Function


    '*************************************************
    Sub EndHandler
    '*************************************************
    'Call the EndHandler from the RibbonLib which will remove elements added to the ribbon
    Call RBNEndHandler

    End Sub

    ------------------------------
    Asko Poder
    Knowledge Community Shared Account
    ------------------------------