Event when splitters resized?

Everything else that doesn't fall into one of the other PB categories.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Event when splitters resized?

Post 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.
Last edited by tinman on Sun Jun 06, 2004 6:17 pm, edited 1 time in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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 
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply