MaxGUI - pop up menu events
BlitzMax Forums/BlitzMax Beginners Area/MaxGUI - pop up menu events
| ||
Hi, Is there a way to detect when a pop up menu is closed? (ie. for when no menu item is selected). |
| ||
Is there noone with a solution to this? What I want it to be able to use a pop up menu over the top of a windowed mode Max2D application. Currently, I create an invisible window and attach the menu to it's windowmenu. I need to end the message pump loop when the menu is closing (this occurs either when an item is selected or the user clicks somewhere off the menu). Unfortunately, there's no event in the blitzmax GUI which is triggered when the menu closes... so I'm locked in the loop waiting for a menu selection (which now can't happen). Any ideas? |
| ||
check to see if its visible each message loop?? |
| ||
Ive tried that one Chris, thanks. It's visible property remains set apparently. |
| ||
errm see if it still has the focus???? if not ActiveGadget(popupmenu) then .... |
| ||
nope not that either! |
| ||
Hi Chris, Great idea, thanks. And........ it works! But, there's a problem. Check out the following code :- If( MouseHit( 2 )) Local window:TGadget = CreateWindow("win", 0,0,10,10, Null, WINDOW_HIDDEN | WINDOW_MENU ) Local menu:TGadget = CreateMenu( "Menu", 0, WindowMenu( window )) CreateMenu( "Item 1", 1, menu ) Local done = False ShowMouse() PopupWindowMenu( window, menu ) While Not done WaitEvent Local id = EventID() Local dat = EventData() Select id Case EVENT_MENUACTION Select dat Case 1 Notify("Item 1 clicked") done = True EndSelect EndSelect If( ActiveGadget() <> menu ) Notify( "Menu closed") done = True EndIf Wend FreeGadget( window ) HideMouse() FlushMouse() EndIf IF the activegadget is not the menu for any reason - the code which selects the eventID does not appear to be executed. What's going on here? Am I going mad, is there some kind of early-out compiler optimisation getting in the way? |
| ||
you can use the main window to parent the popup btw (and the event processing too...) I didnt seem to get activegadget to return anything but null, so I must have been doing somthing wrong... Do you have a complete example as opposed to a code fragment? |
| ||
How do I get the main window? I have been trawling the docs for that. I understand what's going on then. The ActiveGadget is never actually set to the menu - therefore the next message (a mousedown event) is causing the loop to terminate. Here is the original problem with a test graphics window Strict Graphics 640,480 While Not KeyDown(KEY_ESCAPE) Cls DrawText "Right mouse to invoke popup menu", 10,10 Flip If( MouseHit( 2 )) Local window:TGadget = CreateWindow("win", 0,0,10,10, Null, WINDOW_HIDDEN | WINDOW_MENU ) Local menu:TGadget = CreateMenu( "Menu", 0, WindowMenu( window )) CreateMenu( "Item 1", 1, menu ) Local done = False PopupWindowMenu( window, menu ) While Not done WaitEvent Local id = EventID() Local dat = EventData() Select id Case EVENT_MENUACTION Select dat Case 1 Notify("Item 1 clicked") done = True EndSelect EndSelect Wend FreeGadget( window ) FlushMouse() EndIf Wend |
| ||
Problem solved : The problem is that the PopUpWindowMenu does not send messages to the window until after the menu closes (under Windows at least). At which point all the buffered messages are sent to the window - one of which might be a menu action event. I've changed the message loop to poll the message queue until it's empty.. this way it drops out once all the messages have been processed. Strict Graphics 640,480 While Not KeyDown(KEY_ESCAPE) Cls DrawText "Right mouse to invoke popup menu", 10,10 Flip If( MouseHit( 2 )) Local window:TGadget = CreateWindow("win", 0,0,10,10, Null, WINDOW_HIDDEN | WINDOW_MENU ) Local menu:TGadget = CreateMenu( "Menu", 0, WindowMenu( window )) CreateMenu( "Item 1", 1, menu ) CreateMenu( "Item 2", 2, menu ) CreateMenu( "Item 3", 3, menu ) CreateMenu( "Item 4", 4, menu ) PopupWindowMenu( window, menu ) Local nEvents = 0 While PollEvent() Select CurrentEvent.id Case EVENT_MENUACTION Select EventData() Case 1 DebugLog("Item 1 clicked") Case 2 DebugLog("Item 2 clicked") Case 3 DebugLog("Item 3 clicked") Case 4 DebugLog("Item 4 clicked") EndSelect EndSelect Wend FreeGadget( window ) FlushMouse() EndIf Wend |
| ||
nice work! well done. |
| ||
Thanks Chris. It would be interesting to know if this works the same on other platforms (I only use windows at the moment). Anyone willing to test it? |