Page 1 of 1

Event when splitters resized?

Posted: Sun Jun 06, 2004 3:52 pm
by tinman
Is there any way to get an event when a splitter gadget is resized? I need it to automatically resize the contents of a container gadget on either side of the separator bar (it's not just a simple single gadget thing).

Edit2: Here is some updated code which shows what I'm after. Perhaps it will be useful to others (although you will need to change how the state of the separator is stored and detected - this will only work for one gadget):

Code: Select all

Global hSplitterGadget.l
Global old_func.l

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

Procedure.l foo(WindowID, Message, wParam, lParam)
    Static state
    
    result.l = CallWindowProc_(old_func, WindowID, Message, wParam, lParam)
    Select Message
        Case #WM_LBUTTONDOWN
            state = 1
            Debug "pressed"
            
        Case #WM_MOUSEMOVE
            If state = 1
                Debug "resizing"
            EndIf
            
        Case #WM_LBUTTONUP
            state = 0
            Debug "released"
    EndSelect
    ProcedureReturn result
EndProcedure


  If OpenWindow(0, 0, 0, 230, 180, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "SplitterGadget")
    If CreateGadgetList(WindowID(0))
      hButtonGadget1 = ButtonGadget(#Button1,0, 0, 0, 0, "Button 1") ; No need to specify size or coordiantes
      hButtonGadget2 = ButtonGadget(#Button2,0, 0, 0, 0, "Button 2") ; as they will be sized automatically
      hSplitterGadget = SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)
      hSplitterGadget = GadgetID(#Splitter)

      old_func.l = GetWindowLong_(hSplitterGadget, #GWL_WNDPROC)
      If old_func = 0
        old_func = GetClassLong_(hSplitterGadget, #GCL_WNDPROC)
      EndIf
      SetWindowLong_(hSplitterGadget, #GWL_WNDPROC, @foo())


      SetGadgetAttribute(#Splitter, #PB_Splitter_FirstMinimumSize, 20)
      SetGadgetAttribute(#Splitter, #PB_Splitter_SecondMinimumSize, 20)
      hTextGadget = TextGadget(3, 10, 135, 210, 40, "Above GUI part shows two automatically resizing buttons inside the 230x130 SplitterGadget area.",#PB_Text_Center )

      Repeat
        ev = WaitWindowEvent()
        Select ev
            Case #PB_Event_CloseWindow : quit =1
            Case #PB_Event_Gadget
              EventGadgetID = EventGadgetID()
              Debug "Gadget# = " + Str(EventGadgetID) + " Gadget handle = " + Str(GadgetID(EventGadgetID))
        EndSelect
      Until quit=1
    EndIf
  EndIf
  
  SetWindowLong_(hSplitterGadget, #GWL_WNDPROC, old_func)
End
Cheers.

Posted: Sun Jun 06, 2004 4:29 pm
by fweil
After searching a bit, I discovered that the handle returned by SplitterGadget is not the handle of the splitter bar itself. The handle of the splitter bar is the parent handle of the handle returned ... !!!

That'it.

Then you can use something like :

Code: Select all

Global hSplitterGadget.l

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

Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 
  Result = #PB_ProcessPureBasicEvents 
  Select Message
    Case #WM_MOUSEACTIVATE
      If wParam = hSplitterGadget
          Debug "Splitter touched"
      EndIf
  EndSelect
  ProcedureReturn Result 
EndProcedure 


  If OpenWindow(0, 0, 0, 230, 180, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "SplitterGadget") 
    If CreateGadgetList(WindowID(0)) 
      hButtonGadget1 = ButtonGadget(#Button1,0, 0, 0, 0, "Button 1") ; No need to specify size or coordiantes 
      hButtonGadget2 = ButtonGadget(#Button2,0, 0, 0, 0, "Button 2") ; as they will be sized automatically 
      hSplitterGadget = SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator) 
      hSplitterGadget = GetParent_(hSplitterGadget)
      SetGadgetAttribute(#Splitter, #PB_Splitter_FirstMinimumSize, 20) 
      SetGadgetAttribute(#Splitter, #PB_Splitter_SecondMinimumSize, 20) 
      hTextGadget = TextGadget(3, 10, 135, 210, 40, "Above GUI part shows two automatically resizing buttons inside the 230x130 SplitterGadget area.",#PB_Text_Center ) 
      SetWindowCallback(@MyWindowCallback())
      Repeat 
        ev = WaitWindowEvent() 
        Select ev 
            Case #PB_Event_CloseWindow : quit =1 
            Case #PB_Event_Gadget 
              EventGadgetID = EventGadgetID()
              Debug "Gadget# = " + Str(EventGadgetID) + " Gadget handle = " + Str(GadgetID(EventGadgetID))
        EndSelect 
      Until quit=1 
    EndIf 
  EndIf 
End 

Posted: Sun Jun 06, 2004 6:07 pm
by tinman
I must apologise for being such an idiot. Note the type in the "CallWindowProc_" function. Correcting this allows me to get all the events I need. Doh.

Although thanks for the time and code fweil - it works really well.

Edit: Code above fixed to show operation.