MapInfo Pro Developers User Group

 View Only
  • 1.  CustomMBXHandler with parameters?

    Posted 06-28-2022 13:26
    Does anyone have tricks to allow passing of a parameter to buttons created in the new ribbon interface?

    For example if I had a button to add a red or blue feature to a map based on Splitbutton.  I would share everything in the code besides the style of the new feature.

    Something similar to how it was done with the 32 bit buttons discussed here or another method:
    Making a Button in mapinfo with conditional function
    Geographic Information Systems Stack Exchange remove preview
    apple-touch-icon@2.png?v=54e3ab1edcf3" width="200" height="200">
    Making a Button in mapinfo with conditional function
    Thanks for contributing an answer to Geographic Information Systems Stack Exchange! Please be sure to answer the question. Provide details and share your research! Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience.
    View this on Geographic Information Systems Stack Exchange >


    ------------------------------
    Jay Russell
    CENTERPOINT ENERGY RESOURCES
    Houston TX
    ------------------------------


  • 2.  RE: CustomMBXHandler with parameters?

    Employee
    Posted 06-29-2022 10:53
    Edited by Peter Møller 12-13-2023 01:58

    Perhaps something like this:

    Include "MapBasic.def"
    Include "Icons.def"
    
    Declare sub main
    Declare Sub create_ButtonFromVendor
    Declare Sub vendor_ButtonAction
    
    Dim Vendors() as string
    
    Sub Main
    Onerror goto ErrorTrap
    Call create_ButtonFromVendor
    
    exit sub
    ErrorTrap:
    Note "Main: " & Err() & ":" & Error$()
    resume next
    end sub
    
    Sub create_ButtonFromVendor
    Dim i As Integer
    i=2
    redim Vendors(i)
    Create ButtonPad "allVendor" As
      ToggleButton
        Icon MI_ICON_ZOOM_QUESTION
        HelpMsg "Button: " & str$(1000)
        Calling vendor_ButtonAction
        Show
    
    For i = 1 To Ubound(vendors)
      Alter ButtonPad "allVendor" Add
        ToggleButton
        ID 1000 + i
        Icon MI_ICON_ZOOM_QUESTION
        Calling vendor_ButtonAction
        HelpMsg "Button: " & str$(1000 + i)
    Next
    
    End Sub
    '#######################################
    Sub vendor_ButtonAction
    Dim nVendorIndex As Integer
    nVendorIndex = CommandInfo(CMD_INFO_TOOLBTN)
    Note "You clicked on vendor " & nVendorIndex
    End Sub
    


    Regards,
    -Bill

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



  • 3.  RE: CustomMBXHandler with parameters?

    Employee
    Posted 08-03-2022 03:35
    Hi Jay

    These days there are multiple ways to build your ribbon interface through MapBasic.

    When I'm using the RibbonLib to build my interface, I use a structure like this:

    For nCtrl = 1 To Ubound(marrFavoriteMaps)
     nCtrlIdx = RBNGroupAddButton("openBaseMap" & nCtrl, marrFavoriteMaps(nCtrl).sName, "", marrAddToRibbon(nTab).sTabName, marrAddToRibbon(nTab).sGroupName)
      If nCtrlIdx > 0 Then
       Call RBNControlSetToolTipIdx(nCtrlIdx, PRGIGetApplicationName(), marrFavoriteMaps(nCtrl).sName, "")
       Call RBNControlSetIconsIdx(nCtrlIdx, mnImageSize, "", marrFavoriteMaps(nCtrl).sImageFile)
       Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "MENUFavoriteMapClicked")
        nCount = Ubound(marrCommand2FavoriteMap) + 1
        ReDim marrCommand2FavoriteMap(nCount)
        marrCommand2FavoriteMap(nCount).nCommandId = RBNControlGetControlIDIdx(nCtrlIdx)
        marrCommand2FavoriteMap(nCount).nFavoriteMapItem = nCtrl
      End If
    Next

    The general idea is that for flexibility, the buttons are stored in an array. This makes it easy to add more, and in this case, I can let the user add as many as they would like.

    To create the buttons on the ribbon, I can now loop over this array:
    For nCtrl = 1 To Ubound(marrFavoriteMaps)

    Every time I have added a new control/button, I get the Control ID and store this in an array too:
        ReDim marrCommand2FavoriteMap(nCount)
        marrCommand2FavoriteMap(nCount).nCommandId = RBNControlGetControlIDIdx(nCtrlIdx)
        marrCommand2FavoriteMap(nCount).nFavoriteMapItem = nCtrl

    Now my example may be a bit more complicated than your solution.
    If you only have a few buttons, you can store the Control IDs in a couple of variables instead.

    This is from a tool called Favorites Maps. You can find the full source code here on GitHub.
    The RibbonLib is part of the MapBasic Library that can be found on Github too.

    If you are using the new Create Ribbon statement that we added to MapBasic v2021, you can use the function RibbonItemInfo to get to the ControlID via the attribute PROPERTY_CONTROLID.

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



  • 4.  RE: CustomMBXHandler with parameters?

    Posted 08-04-2022 15:41
    Thanks Peter.  I've now started rebuilding our MapInfo 16 app using the old ribbon examples into MapInfo 2021 with the new functions.

    Is there any additional documentation on the control property values RibbonControls.def?

    For example, how would I get the controls in a CTRL_TYPE_DROPDOWN_BUTTON to align vertically.
    I'm guessing it's one of the common properties but how would I know the values that could be assigned?

    I looked at the Ribbon Control Definitions section of MapBasic help but only see data types with no example values.
    I also used the CustomHandler provided with the examples but that gives me the current values rather than all possible values for each property.

    ------------------------------
    Jay Russell
    CENTERPOINT ENERGY RESOURCES
    Houston TX
    ------------------------------



  • 5.  RE: CustomMBXHandler with parameters?

    Employee
    Posted 08-05-2022 01:13
    Hi Jay

    There are probably multiple ways to align the controls. I would just set a specific width on the controls.

    Also, note that you can add a panel to your dropdown button and have multiple controls vertically. Have a look at this article on StackPanel and WrapPanel. In that example, I seem to only set the Width of the panel, not on the controls. But you can also set the width of the controls/buttons to align these.

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