Page 1 of 2

Incorrect event gadget response

Posted: Tue Apr 29, 2025 3:02 am
by DeanH
I am not sure this is a bug, but the behaviour is different between PB 6.21 Beta 6 and 6.11. Maybe I missed a change.

Code: Select all

OpenWindow(1,0,0,320,200,"Test",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
TextGadget(10,10,60,320,200,"Close this window",#PB_Text_Center)
ButtonGadget(20,238,170,75,23,"Close")
Repeat
		event=WaitWindowEvent()
		If event=#PB_Event_Gadget
			eventgadget=EventGadget()
			If eventgadget
				Debug eventgadget
			EndIf
		EndIf
Until event=#PB_Event_CloseWindow Or eventgadget=20
CloseWindow(1)
End
In PB 6.11 and earlier, the window closes when the Close button is clicked. EventGadget() returns 20.
In 6.21 Beta 6, the value of the TextGadget (10) is returned by EventGadget() and not the button.
The TextGadget is acting as if #SS_NOTIFY has been included in the style, even though it has not.

The height of the TextGadget is, of course, way too large. If it is reduced to 20 or anything that does not overlap the Close button, then the correct value is returned.

I tested this on both Win 10 and 11 systems with the same result.

Again, not sure if this is a bug or a change.

Re: Incorrect event gadget response

Posted: Tue Apr 29, 2025 8:35 am
by Fred
Yes, SS_NOTIFY has been added to support tooltip, and you're right it shouldn't fire an event. That said, we don't support gadget overlapping so I'm not sure if it will work like before event if the event isn't fired. You can use SetWindowLongPtr_() to remove the SS_NOTIFY flag if you really want the old behaviour.

Re: Incorrect event gadget response

Posted: Tue Apr 29, 2025 7:56 pm
by Blue
Fred wrote: Tue Apr 29, 2025 8:35 am Yes, SS_NOTIFY has been added to support tooltip [...]
I hadn't realized that.
Good idea, Fred. Excellent improvement.

@DeanH : Why would you ever want gadgets to overlap ?
If, in your sample code, they don't overlap, then everything works normally... except for the unwanted firing of an event for the TextGadget , of course.

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 12:17 am
by DeanH
Blue wrote: Tue Apr 29, 2025 7:56 pm
Fred wrote: Tue Apr 29, 2025 8:35 am Yes, SS_NOTIFY has been added to support tooltip [...]
I hadn't realized that.
Good idea, Fred. Excellent improvement.

@DeanH : Why would you ever want gadgets to overlap ?
If, in your sample code, they don't overlap, then everything works normally... except for the unwanted firing of an event for the TextGadget , of course.
Not on purpose! I stumbled across this by accident. Years ago I had inadvertently made a text gadget way too high. I didn't know about it and none of my users spotted the problem until last week when I recompiled everything in 6.21 Beta 6 and gave it to one of my users to test. Suddenly a popup dialog wouldn't close by clicking on the Close button. Turned out it was due to a typing mistake in the code. Why didn't this happen until now? I suspected a change but thought I should report just in case.

I don't know if this change will be significant. I use SS_NOTIFY in text gadgets a lot.

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 4:58 am
by Blue
DeanH wrote: Wed Apr 30, 2025 12:17 am [...]
Not on purpose! I stumbled across this by accident.
[...]
:D Glad you did !
You made me stumble on a great feature : the possibility to affect ToolTips to TextGadgets.
Keep your accidents productive...

BTW : (just a suggestion)
During the development phase, always assign a backgroung color to your text gadgets. That way you can see how much real estate they occupy. No more surprises such as the one that jumped on you. :shock:

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 8:22 am
by BarryG
Blue wrote: Wed Apr 30, 2025 4:58 am During the development phase, always assign a backgroung color to your text gadgets. That way you can see how much real estate they occupy.
Nice. I add #PB_Text_Border to them during development, for the same reason. :)

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 5:13 pm
by Fred
We won't block the extra event as probably some code used SS_NOTIFY to have a click on a textgadget(). We will probably add left click support for textGadget for the next version so it will supported on all OS

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 6:09 pm
by Piero
Talking about transparent overlaps behavior:

Code: Select all

; works on mac
; on linux, clicking 0 toggles 1
; on win, 0 is hidden but appears if you hover above it
OpenWindow(0, 0, 0, 300, 100, "", #PB_Window_SystemMenu)
CheckBoxGadget(0, 40, 5, 50, 14, "0")
CheckBoxGadget(1, 5, 5, 85, 14,  "1") ; note: created later!
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Incorrect event gadget response

Posted: Wed Apr 30, 2025 9:33 pm
by jacdelad
Fred wrote: Wed Apr 30, 2025 5:13 pm We won't block the extra event as probably some code used SS_NOTIFY to have a click on a textgadget(). We will probably add left click support for textGadget for the next version so it will supported on all OS
This raises the demand for right click on buttons and so on. Would some kind of

Code: Select all

AddGadgetEventType(#Gadget,#PB_EventType_Something)
or

Code: Select all

RegisterEventType(#PB_GadgetType_Button,#PB_EventType_Something)
be a thing?

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 3:12 am
by mk-soft
jacdelad wrote: Wed Apr 30, 2025 9:33 pm
Fred wrote: Wed Apr 30, 2025 5:13 pm We won't block the extra event as probably some code used SS_NOTIFY to have a click on a textgadget(). We will probably add left click support for textGadget for the next version so it will supported on all OS
This raises the demand for right click on buttons and so on. Would some kind of

Code: Select all

AddGadgetEventType(#Gadget,#PB_EventType_Something)
or

Code: Select all

RegisterEventType(#PB_GadgetType_Button,#PB_EventType_Something)
be a thing?
OS specific not always possible. PB should stick to the standards and not generate something internally that the OS does not normally support.

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 8:07 am
by jacdelad
:cry:

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 12:08 pm
by mk-soft
jacdelad wrote: Thu May 01, 2025 8:07 am:cry:
You can create your own event type and send it with PostEvent. For this there is a constant with which you start the event types.

Code: Select all

;-TOP

; Comment : Module SetGadgetCallback (Windows Only)
; Author  : mk-soft
; Version : v0.05.2
; Created : 10.06.2018
; Updated : 26.05.2023
; Link    : https://www.purebasic.fr/english/viewtopic.php?f=12&t=70842
;
; Description
; - A callback that has already been set is replaced by the new callback!
;
; - Syntax Callback:
;           Procedure GadgetCB(hWnd,uMsg,wParam,lParam)
;             Select uMsg
;               ;TODO
;             EndSelect
;             ; Call previous gadget procedure
;             ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
;           EndProcedure
;
; *****************************************************************************

DeclareModule GadgetCallback
  
  Declare SetGadgetCallback(Gadget, *lpNewFunc, Parent = #False) 
  Declare CallGadgetProc(hWnd, uMsg, wParam, lParam)
  
EndDeclareModule

Module GadgetCallback
  
  EnableExplicit
  
  ; ---------------------------------------------------------------------------
  
  Procedure SetGadgetCallback(Gadget, *lpNewFunc, Parent = #False)
    Protected hWnd, *lpPrevFunc
    
    hWnd = GadgetID(Gadget)
    If Parent
      hwnd = GetParent_(hwnd)
    EndIf
    *lpPrevFunc = GetProp_(hWnd, "PB_PrevFunc")
    ; Remove exists Callback
    If *lpPrevFunc
      SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *lpPrevFunc)
      RemoveProp_(hWnd, "PB_PrevFunc")
    EndIf
    ; Set new Callback  
    If *lpNewFunc
      *lpPrevFunc = SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *lpNewFunc)
      SetProp_(hWnd, "PB_PrevFunc", *lpPrevFunc)
      ProcedureReturn *lpPrevFunc
    EndIf
    ProcedureReturn 0
  EndProcedure
  
  ; ---------------------------------------------------------------------------
  
  Procedure CallGadgetProc(hWnd, uMsg, wParam, lParam)
    Protected result, *lpPrevFunc
    
    If uMsg = #WM_NCDESTROY ; Last Message
      *lpPrevFunc = RemoveProp_(hWnd, "PB_PrevFunc")
    Else
      *lpPrevFunc = GetProp_(hWnd, "PB_PrevFunc")
    EndIf
    If *lpPrevFunc
      result = CallWindowProc_(*lpPrevFunc, hWnd, uMsg, wParam, lParam)
    EndIf
    ProcedureReturn result
  EndProcedure
EndModule

; *****************************************************************************

CompilerIf #PB_Compiler_IsMainFile
  
  ;- Example
  
  EnableExplicit
  
  UseModule GadgetCallback
  
  Enumeration #PB_EventType_FirstCustomValue
    #MyEventType_ButtonRightClick
  EndEnumeration
  
  ; ----
  
  Procedure GadgetButtonCallback(hWnd, uMsg, wParam, lParam)
    Protected Gadget
    Select uMsg
      Case #WM_RBUTTONUP
        Gadget = GetProp_(hwnd, "PB_ID")
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #MyEventType_ButtonRightClick)
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure
  
  ; ----
  
  Procedure Main()
    If OpenWindow(0, 10, 10, 320, 200, "Window", #PB_Window_SystemMenu)
      ButtonGadget(1, 10, 10, 120, 25, "Button 1")
      
      SetGadgetCallback(1, @GadgetButtonCallback())
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case 1
                Select EventType()
                  Case #PB_EventType_LeftClick
                    Debug "Left Click Button 1"
                  Case #MyEventType_ButtonRightClick
                    Debug "Right Click Button 1"
                EndSelect
                
            EndSelect
            
        EndSelect
      ForEver
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 2:25 pm
by Blue
Fred wrote: Wed Apr 30, 2025 5:13 pm We won't block the extra event as probably some code used SS_NOTIFY to have a click on a textgadget(). We will probably add left click support for textGadget for the next version so it will supported on all OS
Things just keep getting better. I like that.
Thank you Fred !

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 2:32 pm
by Blue
mk-soft wrote: Thu May 01, 2025 3:12 am [...]
PB should stick to the standards and not generate something internally that the OS does not normally support.
Makes sense. I certainly agree with that. 8)
Do Fred's proposed additions/adjustments contradict this principle ?

(missing from the smilies : a Thumbs Up icon)

Re: Incorrect event gadget response

Posted: Thu May 01, 2025 3:23 pm
by Kiffi
<OT>
Blue wrote: Thu May 01, 2025 2:32 pm(missing from the smilies : a Thumbs Up icon)
+1

In the meantime, you can use the smiley from the German forum:

Image

</OT>