Turn off Canvas Events during a MessageRequester() is open

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 849
Joined: Fri Jun 11, 2004 7:07 am

Turn off Canvas Events during a MessageRequester() is open

Post 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.
wombats
Enthusiast
Enthusiast
Posts: 722
Joined: Thu Dec 29, 2011 5:03 pm

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

Post 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
Lebostein
Addict
Addict
Posts: 849
Joined: Fri Jun 11, 2004 7:07 am

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

Post 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
User avatar
spikey
Enthusiast
Enthusiast
Posts: 789
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

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

Post 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
Lebostein
Addict
Addict
Posts: 849
Joined: Fri Jun 11, 2004 7:07 am

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

Post 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
mestnyi
Addict
Addict
Posts: 1109
Joined: Mon Nov 25, 2013 6:41 am

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

Post 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( )
User avatar
mk-soft
Always Here
Always Here
Posts: 6410
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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
; ****
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skywalk
Addict
Addict
Posts: 4262
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply