Check the event: SplitterGadget release (Win/Mac)

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

Check the event: SplitterGadget release (Win/Mac)

Post by Lebostein »

I search for an Event like "Release the mouse button after moving a slider of a SplitterGadget" to reload some things...
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check the event: SplitterGadget release (Win/Mac)

Post by mk-soft »

For macOS is only one event and check only the last position of splitter gadget.

For window check messages.

Update
- Bugfix Gadget Number

Code: Select all

Procedure WinCallback(hWnd, uMsg, wParam, lParam)
  Protected Gadget
  Select uMsg
    Case #WM_CAPTURECHANGED
      Gadget = GetProp_(hWnd, "PB_ID")
      If GadgetType(Gadget) = #PB_GadgetType_Splitter
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change)
      EndIf
      
  EndSelect
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 

If OpenWindow(0, 0, 0, 230, 195, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  #Button1  = 0 
  #Button2  = 1
  #Splitter = 2
  
  ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1") ; es besteht keine Notwendigkeit, die Größe oder Position
  ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2") ; festzulegen, da sie automatisch in der Größe angepasst werden
  SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)
  
  TextGadget(3, 10, 135, 210, 55, "Obiger GUI-Abschnitt zeigt zwei sich - innerhalb des 220x120 SplitterGadget Bereichs - automatisch in der Größe anpassende Schalter.", #PB_Text_Center)
  
  LastPostion = GetGadgetState(#Splitter)
  
  SetWindowCallback(@WinCallback())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Splitter
            If EventType() = #PB_EventType_Change
              If LastPostion <> GetGadgetState(#Splitter)
                Debug "Splitter Position = " + GetGadgetState(#Splitter)
                LastPostion = GetGadgetState(#Splitter)
              EndIf
            EndIf
        EndSelect
        
    EndSelect
    
  ForEver
  
EndIf
Last edited by mk-soft on Sun Feb 16, 2020 3:07 pm, edited 1 time in total.
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
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Check the event: SplitterGadget release (Win/Mac)

Post by Marc56us »

Check Splitter
(example based on help example)
Case #PB_Event_Gadget
If EventGadget() = #Splitter

Code: Select all

OpenWindow(0, 0, 0, 230, 180, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#Button1  = 0
#Button2  = 1
#Splitter = 2

ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1") 
ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2") 
SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)

TextGadget(3, 10, 135, 210, 40, "Move splitter",#PB_Text_Center )

Repeat
    Select WaitWindowEvent(0)
        Case #PB_Event_CloseWindow
            End
        Case #PB_Event_Gadget 
            If EventGadget() = #Splitter
                Debug "Height B1:" +GadgetHeight(#Button1) + " B2:" + GadgetHeight(#Button2)
            EndIf
    EndSelect
Until WaitWindowEvent() = #PB_Event_CloseWindow
Edit: mk-soft beat me to it with a roughly similar solution. :wink:
(I didn't use a callback, because I still don't understand much of it. :mrgreen: )

Edit: But that may not completely answer your problem, I don't detect the "mouse release" but the movement of the splitter. :?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Check the event: SplitterGadget release (Win/Mac)

Post by Josh »

Lebostein wrote:I search for an Event like "Release the mouse button after moving a slider of a SplitterGadget" to reload some things...
+1

When using a splitter gadget with background color, it often happens that one pixel row is not colored after moving the splitter.

Currently I get the #WM_LBUTTONUP event from Windows and redraw the gadget one time again.
sorry for my bad english
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check the event: SplitterGadget release (Win/Mac)

Post by mk-soft »

Update
- Bugfix Gadget Number

Small bug fixes

P.S.

MSDN Info
WM_CAPTURECHANGED message
- Sent to the window that is losing the mouse capture.
Link: https://docs.microsoft.com/en-us/window ... urechanged
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
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check the event: SplitterGadget release (Win/Mac)

Post by mk-soft »

Update

Now with SetGadgetCallback and the event 'WM_LBUTTONUP'

Update Module v0.03
- Remove Map and Mutex
- Change to Properties

Code: Select all

;-TOP

; Comment : Module SetGadgetCallback (Windows Only)
; Author  : mk-soft
; Version : v0.03
; Created : 10.06.2018
; Updated : 16.02.2020
; Link    : https://www.purebasic.fr/english/viewtopic.php?f=12&t=70842
;
; 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) 
  Declare CallGadgetProc(hWnd, uMsg, wParam, lParam)
  
EndDeclareModule

Module GadgetCallback
  
  EnableExplicit
  
  ; ---------------------------------------------------------------------------
  
  Procedure SetGadgetCallback(Gadget, *lpNewFunc)
    Protected hWnd, *lpPrevFunc
    
    hWnd = GadgetID(Gadget)
    *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
    
    *lpPrevFunc = GetProp_(hWnd, "PB_PrevFunc")
    If *lpPrevFunc
      result = CallWindowProc_(*lpPrevFunc, hWnd, uMsg, wParam, lParam)
    EndIf
    ProcedureReturn result
  EndProcedure
EndModule

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

CompilerIf #PB_Compiler_IsMainFile
  
  UseModule GadgetCallback
  
  Procedure SplitterGadgetCB(hWnd, uMsg, wParam, lParam)
    Protected Gadget
    Select uMsg
      Case #WM_LBUTTONUP
        Gadget = GetProp_(hWnd, "PB_ID")
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_LeftButtonUp)
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure 
  
  If OpenWindow(0, 0, 0, 230, 195, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    #Button1  = 0 
    #Button2  = 1
    #Splitter = 2
    
    ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1") ; es besteht keine Notwendigkeit, die Größe oder Position
    ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2") ; festzulegen, da sie automatisch in der Größe angepasst werden
    SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)
    
    TextGadget(3, 10, 135, 210, 55, "Obiger GUI-Abschnitt zeigt zwei sich - innerhalb des 220x120 SplitterGadget Bereichs - automatisch in der Größe anpassende Schalter.", #PB_Text_Center)
    
    LastPostion = GetGadgetState(#Splitter)
    
    SetGadgetCallback(#Splitter, @SplitterGadgetCB())
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #Splitter
              If EventType() = #PB_EventType_LeftButtonUp
                If LastPostion <> GetGadgetState(#Splitter)
                  Debug "Splitter Position = " + GetGadgetState(#Splitter)
                  LastPostion = GetGadgetState(#Splitter)
                EndIf
              EndIf
          EndSelect
          
      EndSelect
      
    ForEver
    
  EndIf
  
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
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Check the event: SplitterGadget release (Win/Mac)

Post by Lebostein »

mk-soft wrote:For macOS is only one event and check only the last position of splitter gadget.
Seems not correct. If I release a SplitterGadget on Mac OS, PureBasic spitts out hundrets of events one after the other...

With this little example:

Code: Select all

OpenWindow(0, 0, 0, 230, 180, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#Button1  = 0
#Button2  = 1
#Splitter = 2

ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1")
ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2")
SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)

TextGadget(3, 10, 135, 210, 40, "Move splitter",#PB_Text_Center )

Repeat
    Select WaitWindowEvent(0)
        Case #PB_Event_CloseWindow
            End
        Case #PB_Event_Gadget
            If EventGadget() = #Splitter
                Debug "Height B1:" +GadgetHeight(#Button1) + " B2:" + GadgetHeight(#Button2)
            EndIf
    EndSelect
Until WaitWindowEvent() = #PB_Event_CloseWindow
I get this if I move the slider up and down and release the mouse button:
Height B1:56 B2:55
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Height B1:83 B2:28
Every pixel change while moving the slider produces a #PB_Event_Gadget. And all these "collected in silence" events squirt out if I release the mouse....
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Check the event: SplitterGadget release (Win/Mac)

Post by Marc56us »

With this little example:
...
Every pixel change while moving the slider produces a #PB_Event_Gadget. And all these "collected in silence" events squirt out if I release the mouse....
Yes, that why I have added this: :wink:
Edit: But that may not completely answer your problem, I don't detect the "mouse release" but the movement of the splitter.
:!: But the events are not collected, they only come up here because we ask for the display by Debug.

In Windows programming, hundreds of events are posted every second, we just process only the ones we need.
The Debug command slows down (a lot) a program, but all these displays are ignored after compilation.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Check the event: SplitterGadget release (Win/Mac)

Post by netmaestro »

Not better, just different - when dealing with specific gadgets, I prefer the subclass approach shown here:

Code: Select all

; Windows only
; Avoids PB internals which are subject to change (and they do all the time)

#Button1  = 0
#Button2  = 1
#Splitter = 2

Procedure SplitterProc(hWnd, msg, wParam, lParam)
  Static oldpos = -1, oldproc
  If oldpos = -1
    oldpos=GetGadgetState(#Splitter)
    oldproc = GetProp_(hwnd, "oldproc")
  EndIf
    
  Select msg
    Case #WM_LBUTTONUP
      currentpos= GetGadgetState(#Splitter)
      If currentpos<>oldpos 
        Debug "Handle position change from " + oldpos + " to " + currentpos
        oldpos = currentpos
      EndIf
      
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
      
  EndSelect
  
  ProcedureReturn CallWindowProc_(oldproc, hWnd, msg, wParam, lParam)
  
EndProcedure

OpenWindow(0, 0, 0, 230, 195, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1") ; es besteht keine Notwendigkeit, die Größe oder Position
ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2") ; festzulegen, da sie automatisch in der Größe angepasst werden
SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)

TextGadget(3, 10, 135, 210, 55, "Obiger GUI-Abschnitt zeigt zwei sich - innerhalb des 220x120 SplitterGadget Bereichs - automatisch in der Größe anpassende Schalter.", #PB_Text_Center)

SetProp_(GadgetID(#Splitter), "oldproc", SetWindowLongPtr_(GadgetID(#Splitter), #GWL_WNDPROC, @SplitterProc()))

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow

BERESHEIT
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check the event: SplitterGadget release (Win/Mac)

Post by mk-soft »

My module SetGadgetCallback does nothing else. :wink:
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
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check the event: SplitterGadget release (Win/Mac)

Post by mk-soft »

@Lebostein
Seems not correct. If I release a SplitterGadget on Mac OS, PureBasic spitts out hundrets of events one after the other...
With which version of PB and macOS?

Its work with PB v5.71 and macOS Catalina Version 10.15.3 with one event
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
Post Reply