Page 1 of 1

Turn off Canvas Events during a MessageRequester() is open

Posted: Sat Nov 08, 2025 6:37 pm
by Lebostein
If a MessageRequester() is poped up in front of your main window, all events from menus and gadgets seems blocked, except for some CanvasGadget Events. If you move your mouse cursor over the blocked main window with a CanvasGadget on it, the events
#PB_EventType_MouseLeave
#PB_EventType_MouseEnter
#PB_EventType_MouseMove
are still being triggered. I don't know if this is a bug or intended behavior. But I want no events to happen in the background when a requester is open. Does anyone have any ideas? I use BindGadgetEvent(#GID_Canvas...) for my GagedEvents.

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sat Nov 08, 2025 7:42 pm
by wombats
What OS are you using? I don't get any events when a message requester is open on Windows.

You could try unbinding the events before opening a message requester and then binding them after it. Does this work? I haven't tested it on macOS.

Code: Select all

Procedure OnCanvasEvents()
  Select EventType()
    Case #PB_EventType_MouseLeave
      Debug "leave"
    Case #PB_EventType_MouseEnter
      Debug "enter"
    Case #PB_EventType_MouseMove
      Debug "move"
  EndSelect
EndProcedure

Procedure OnButtonEvent()
  UnbindEvent(#PB_Event_Gadget, @OnCanvasEvents(), 0, 0, #PB_All)
  MessageRequester("", "...", #PB_MessageRequester_Ok)
  BindGadgetEvent(0, @OnCanvasEvents(), #PB_All)
EndProcedure

If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 10, 40, 200, 170)
  ButtonGadget(1, 10, 10, 90, 25, "Click")
  
  BindGadgetEvent(0, @OnCanvasEvents(), #PB_All)
  BindGadgetEvent(1, @OnButtonEvent())
  
  Repeat
    Event = WaitWindowEvent()   
    
  Until Event = #PB_Event_CloseWindow
EndIf

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sat Nov 08, 2025 8:51 pm
by Lebostein
Thanks.It seems that could be the way...
I wonder why the #PB_EventType_LeftButtonDown for example is blocked with Requester, but not the #PB_EventType_MouseMove

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sat Nov 08, 2025 10:36 pm
by spikey
Lebostein wrote: Sat Nov 08, 2025 8:51 pm I wonder why the #PB_EventType_LeftButtonDown for example is blocked with Requester, but not the #PB_EventType_MouseMove
It's in use by the modal dialog, whereas the mouse position isn't especially significant and hasn't been overriden by a dialog specific function. It's an emergent behaviour of a hierarchical object structure, rather than something intentional.
wombats wrote: Sat Nov 08, 2025 7:42 pm You could try unbinding the events before opening a message requester and then binding them after it.
This gets cumbersome in a big application and is prone to introducing bugs if you forget to unbind/rebind something along the way. I usually define a flag variable something like "EventsActive" and have something like this at the top of the event procedures:

Code: Select all

Procedure SomeBoundEvent()

  If EventsActive = #False
    ProcedureReturn 
  Endif

EndProcedure

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sun Nov 09, 2025 6:39 am
by Lebostein
I found another solution! With DisableWindow()! I always thought a requester did exactly that (the manual says "Opens a blocking requester"), but apparently a requester does not have such strict blocking conditions on the underlying window. In my opinion, this is still a bug/inconsistency. At least in the manual.

Code: Select all

Procedure OnCanvasEvents()
  Select EventType()
    Case #PB_EventType_MouseLeave
      Debug "leave"
    Case #PB_EventType_MouseEnter
      Debug "enter"
    Case #PB_EventType_MouseMove
      Debug "move"
  EndSelect
EndProcedure

Procedure OnButtonEvent()
  DisableWindow(0, #True)
  MessageRequester("", "...", #PB_MessageRequester_Ok)
  DisableWindow(0, #False)
EndProcedure

If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 10, 40, 200, 170)
  ButtonGadget(1, 10, 10, 90, 25, "Click")
  
  BindGadgetEvent(0, @OnCanvasEvents(), #PB_All)
  BindGadgetEvent(1, @OnButtonEvent())
  
  Repeat
    Event = WaitWindowEvent()   
    
  Until Event = #PB_Event_CloseWindow
EndIf

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sun Nov 09, 2025 9:18 am
by mestnyi
In fact, this is the correct solution. Use the DisableWindow( ) function. As for the events, they should have worked until I enabled DisableWindow( )

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sun Nov 09, 2025 10:52 am
by mk-soft
That's how I would have solved it.

But with a macro. So you don't have to search the whole program ;)

Update

Code: Select all

;- Fix MessageRequester lock events
Procedure MyMessageRequester(Title.s, Text.s, Flags=0, ParentID=0)
  Protected r1, ActWindow
  ActWindow = GetActiveWindow()
  DisableWindow(ActWindow, #True)
  r1 = MessageRequester(Title, Text, Flags, ParentID)
  DisableWindow(ActWindow, #False)
  ProcedureReturn r1
EndProcedure

Macro MessageRequester(Title, Text, Flags=0, ParentID=0)
  MyMessageRequester(Title, Text, Flags, ParentID)
EndMacro
; ****

Re: Turn off Canvas Events during a MessageRequester() is open

Posted: Sun Nov 09, 2025 4:26 pm
by skywalk
Yes, this happens a lot.
I am on the side of "roll your own requester" window at startup and make hidden until activated.
Then you get full control of the size, position, fonts and context.