MapInfo Pro Developers User Group

 View Only
  • 1.  Set Window map_win_id Front does not work

    Posted 12-09-2024 20:34

    Hello all,

    I am running MapInfo v2023 and MapBasic v2019

    In my MapBasic code, I want to explicitly make the Map Window active. Essentially, I want to replicate the action of clicking on the title bar of the Map Window

    I use the command Set Window map_win_id Front

    But it does not work

    I have confirmed that I do know the correct value for map_win_id. I have already gathered this value by grabbing the value of FrontWindow() during a mouse-click inside the mouse window event

    I need this so that a button in the Ribbon activates. I have already enabled the button with SetRbnToolBtnCtrlEnabled but the button remains greyed out until I click on the title bar of the Map Window



    ------------------------------
    Nick Lawrence
    Senior Spatial Science Officer
    Department of Transport and Main Roads
    Brisbane QLD
    ------------------------------


  • 2.  RE: Set Window map_win_id Front does not work

    Posted 12-09-2024 22:30

    I think I have solved it

    Though I do not like my solution.

    My code is supposed to Enable a greyed-out button after the user clicks inside the Map Window, so they can proceed to the next step of the workflow.

    The bad behaviour occurs when the Map Window is active, then I use my custom Tool button to click inside the map window. The next button along remains greyed out. But it "pops" into being Enabled if I click on the title bar of the Map Window. This is a non-intuitive extra step that I do not want to force upon the users. I use the command Set Window map_win_id Front to force the Map Window to be active, but this does not work.

    Good behaviour occurs if (for some reason) any window that is not the Map Window is active (like the Explorer Window), then I use my custom Tool button to click inside the map window. The next button along is enabled as it should be.

    I suspect that the command Set Window map_win_id Front only really works if a window other than the Map Window is active. I think that MapInfo makes the assessment that the Map Window is already the front window and chooses to not do anything.

    My solution is to first force a different window (I chose the Message Window) to be active and then, on the next line, force the Map Window to be active.

    Set Window WIN_MESSAGE Front
    Set Window gMapWinID Front

    This works. The next button along is enabled like it should be.

    Essentially, I am faking clicking on the title bar of the Message Window and then clicking on the title bar of the Map Window, and this triggers the custom button in the RIbbon to refresh properly.

    It works, but I don't like it, it feels like a hack



    ------------------------------
    Nick Lawrence
    Senior Spatial Science Officer
    Department of Transport and Main Roads
    Brisbane QLD
    ------------------------------



  • 3.  RE: Set Window map_win_id Front does not work

    Posted 12-10-2024 19:10
    Edited by Peter Møller 12-11-2024 01:20

    I am pasting here code that demonstrates the behaviour that I consider an issue

    This mapbasic script creates a ribbon with two tool buttons, and one Exit button

    The second tool button starts off disabled

    Using the first tool button and clicking inside the map window is supposed to Enable the second tool button

    But! The second tool button is only enabled if the user also clicks onto the title bar of the map window, thus "refreshing" the ribbon.

    What I want is for the second tool button to be enabled without having to click onto the title bar of the map window.

    Here is the code that I am pasting

    ' test code to demonstrate problem with map window losing focus
    Include "MapBasic.def"                       '- standard MapBasic definitions
    Include "Icons.def"                          '- standard MapBasic definitions
    Include "Menu.def"                           '- standard MapBasic definitions
    Include "Enums.def"
    Include "IMapInfoPro.def"
    
    Dim mapinfoApplication As This
    Dim Ribbon As This
    Dim RibbonTabColl As This
    Dim RibbonTab As This
    Dim ribbonGroupsColl As This
    Dim ribbonGroup1 As This
    Dim groupControlColl_1 As This
    Dim ribbonGroup2 As This
    Dim groupControlColl_2 As This
    Dim button1a As This
    Dim button1b As This
    Dim button2a As This
    
    Declare Sub Main
    Declare Sub subClickMap1
    Declare Sub subClickMap2
    Declare Sub subExit
    Declare Sub EndHandler
    
    Sub Main
    	
    Dim nCtrlIdx As Integer
    Dim sTabName, sTabCaption As String
    Dim sGroupName, sGroupCaption As String
    Dim sButtonName, sButtonCaption As String
    Dim sDropDButtonName, sDropDButtonCaption, sDropDButtonGroupName, sDropDButtonGroupCaption As String
    
       '--- Create the Tab "Example"
       Call RegisterUriParser(New_GenericUriParser(1),"pack",-1)
       mapinfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)
       Ribbon = GetRibbon(mapinfoApplication)
       RibbonTabColl = GetTabsColl(Ribbon)
       RibbonTab = RbnTabCollAddStrStr(RibbonTabColl,"CLineTabID","Example")
       ribbonGroupsColl = GetRbnTabGrps(RibbonTab)
    
       '--- Create the Group "Test"
       ribbonGroup1 = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"CLineGroup1ID","Test")
       Call SetRbnCtrlGrpIsLauncherVisible(ribbonGroup1,FALSE)
       groupControlColl_1 = GetRbnCtrlGrpCtrls(ribbonGroup1)
    
       '--- Create the button1a "Click in Map 1"
       button1a = MICtrlCollAddStrStrInt(groupControlColl_1,"CLineButton1dID","Click in Map 1",ControlType_ToolButton)
       Call SetRbnToolBtnCtrlIsLarge(button1a,TRUE)
       Call SetRbnToolBtnCtrlCallingHandler(button1a,"subClickMap1")
       Call SetRbnToolBtnCtrlLargeIcon(button1a,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/redo_32x32.png",0))
       Call SetRbnToolBtnCtrlCursorId(button1a,MI_CURSOR_CROSSHAIR)
       Call SetRbnToolBtnCtrlDrawMode(button1a,DM_CUSTOM_POINT)
    
       '--- Create the button1b "Click in Map 2"
       button1b = MICtrlCollAddStrStrInt(groupControlColl_1,"CLineButton1eID","Click in Map 2",ControlType_ToolButton)
       Call SetRbnToolBtnCtrlIsLarge(button1b,TRUE)
       Call SetRbnToolBtnCtrlCallingHandler(button1b,"subClickMap2")
       Call SetRbnToolBtnCtrlLargeIcon(button1b,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/redo_32x32.png",0))
       Call SetRbnToolBtnCtrlCursorId(button1b,MI_CURSOR_CROSSHAIR)
       Call SetRbnToolBtnCtrlDrawMode(button1b,DM_CUSTOM_POINT)
       Call SetRbnToolBtnCtrlEnabled(button1b,FALSE)
    
       '--- Create the Group2 "Admin"
       ribbonGroup2 = RbnCtrlGrpCollAddStrStr(ribbonGroupsColl,"CLineGroup2ID","Admin")
       Call SetRbnCtrlGrpIsLauncherVisible(ribbonGroup2,FALSE)
       groupControlColl_2 = GetRbnCtrlGrpCtrls(ribbonGroup2)
    
       '--- Create the button2a "Exit"
       button2a = MICtrlCollAddStrStrInt(groupControlColl_2,"CLineButton2aID","Exit",ControlType_Button)
       Call SetRbnBtnCtrlIsLarge(button2a,TRUE)
       Call SetRbnBtnCtrlCallingHandler(button2a,"subExit")
       Call SetRbnBtnCtrlLargeIcon(button2a,New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Application/exit_32x32.png",0))
    
    End Sub
    
    Sub subClickMap1
    
       Print "subClickMap1"
       Print "enable button 2"
       Call SetRbnToolBtnCtrlEnabled(button1b,TRUE)
    
    End Sub
    
    Sub subClickMap2
    
       Print "subClickMap2"
    
    End Sub
    
    Sub subExit
    
       Print "subExit"
       End Program
    
    End Sub
    
    Sub EndHandler
    
    Dim bRemoved As Logical
    
       'remove buttons
       'bRemoved = MICtrlCollRemove(groupControlColl_1,button1a)
       'button1a = NULL_PTR
       'bRemoved = MICtrlCollRemove(groupControlColl_1,button1b)
       'button1b = NULL_PTR
       bRemoved = MICtrlCollRemove(groupControlColl_2,button2a)
       button2a = NULL_PTR
       'remove groups
       bRemoved = RbnCtrlGrpCollRemove(ribbonGroupsColl,ribbonGroup1)
       ribbonGroup1 = NULL_PTR
       bRemoved = RbnCtrlGrpCollRemove(ribbonGroupsColl,ribbonGroup2)
       ribbonGroup2 = NULL_PTR
       'remove tab
       bRemoved = RbnTabCollRemove(RibbonTabColl,RibbonTab)
       RibbonTab = NULL_PTR
       
    End Sub



    ------------------------------
    Nick Lawrence
    Senior Spatial Science Officer
    Department of Transport and Main Roads
    Brisbane QLD
    ------------------------------



  • 4.  RE: Set Window map_win_id Front does not work

    Employee
    Posted 12-11-2024 01:42
      |   view attached

    Hi Nick

    Thanks for the write-up.

    When I first tried the tool, it worked fine. I selected the first tool, clicked on my map, and the second tool got enabled - just as it was supposed to work.

    Then I opened a browser window side-by-side with my map, and tried it again.

    Now the second tool only shows enabled when I click on the map title bar, as you say.

    If I move my map and browser onto the same tab so that only one is visible. The tool works fine again.

    I can however also get it to work with the two windows side-by-side. So it's a question of how the map has been made active.

    It seems if the map is made active by clicking on the map title bar, the tool works. If I for example have selected the map in the Layer List, it doesn't work.

    I also asked the tool if it was enable or not, and it replies that it is, even when it doesn't appear to be:

       Print "button 2 is enabled: " + GetRbnToolBtnCtrlEnabled(button1b)

    Have you raised this with our support team? Feel free to refer to this thread.

    I have attached your code and a compiled version of it below.



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

    Attachment(s)

    zip
    NickToolEnableIssue.zip   11 KB 1 version