Incorrect event gadget response

Just starting out? Need help? Post your questions and find answers here.
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Incorrect event gadget response

Post 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.
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Incorrect event gadget response

Post 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.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Incorrect event gadget response

Post 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.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Incorrect event gadget response

Post 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.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Incorrect event gadget response

Post 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:
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Incorrect event gadget response

Post 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. :)
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Incorrect event gadget response

Post 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
User avatar
Piero
Addict
Addict
Posts: 863
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Incorrect event gadget response

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Incorrect event gadget response

Post 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?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Incorrect event gadget response

Post 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.
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
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Incorrect event gadget response

Post by jacdelad »

:cry:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Incorrect event gadget response

Post 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
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
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Incorrect event gadget response

Post 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 !
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Incorrect event gadget response

Post 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)
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Incorrect event gadget response

Post 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>
Hygge
Post Reply