Page 1 of 1

SetGadgetWindow, SetGadgetParent

Posted: Sat Feb 13, 2010 10:06 pm
by eddy
- PB 4.5+
- Set Gadget Window : move gadget to another window
- Set Gadget Parent : move gadget to another container gadget ( containerGadget, panelGadget or scrollareaGadget)
- cross-platform code (but i didn't test on MAC or linux)

Code: Select all

EnableExplicit
Procedure SetGadgetWindow(ID, Window)
   If IsWindow(Window)
      Protected old=UseGadgetList(WindowID(Window))
      Protected x=GadgetX(ID)
      Protected y=GadgetY(ID)
      Protected w=GadgetWidth(ID)
      Protected h=GadgetHeight(ID)
      Protected Dummy1=TextGadget(#PB_Any, 0, 0, 0, 0, "")
      Protected Dummy2=TextGadget(#PB_Any, 0, 0, 0, 0, "")
      Protected GadgerMover=SplitterGadget(#PB_Any, 0, 0, 500, 500, ID, Dummy2)
      SetGadgetAttribute(GadgerMover, #PB_Splitter_FirstGadget, Dummy1)
      FreeGadget(GadgerMover)
      ResizeGadget(ID, x, y, w, h)
      UseGadgetList(old)
   EndIf
EndProcedure
Procedure SetGadgetParent(ID, GadgetParent, item=0)
   Select GadgetType(GadgetParent)
      Case #PB_GadgetType_Container, #PB_GadgetType_Panel, #PB_GadgetType_ScrollArea
         OpenGadgetList(GadgetParent, item)
         Protected x=GadgetX(ID)
         Protected y=GadgetY(ID)
         Protected w=GadgetWidth(ID)
         Protected h=GadgetHeight(ID)
         Protected Dummy1=TextGadget(#PB_Any, 0, 0, 0, 0, "")
         Protected Dummy2=TextGadget(#PB_Any, 0, 0, 0, 0, "")
         Protected GadgerMover=SplitterGadget(#PB_Any, 0, 0, 500, 500, ID, Dummy2)
         SetGadgetAttribute(GadgerMover, #PB_Splitter_FirstGadget, Dummy1)
         FreeGadget(GadgerMover)
         ResizeGadget(ID, x, y, w, h)
         CloseGadgetList()
   EndSelect
EndProcedure

; ********************
; Example @ eddy
; ********************
#w=500
#h=500
If OpenWindow(0, 0, 0, #w, #h, "window1", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
   ButtonGadget(10, 5, 5, 250, 50, "")
   ButtonGadget(20, 5, 65, 250, 50, "")
   
   ContainerGadget(100, 55, 200, 400, 200, #PB_Container_Double)
   CloseGadgetList()
EndIf
If OpenWindow(1, 310, 310, #w, #h, "window2", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
   ButtonGadget(30, 5, 125, 250, 50, "I'm from Window 2")
EndIf

SetGadgetParent(10, 100)
SetGadgetParent(20, 100)
SetGadgetText(10, "I'm inside the Container")
SetGadgetText(20, "Me too!")
SetGadgetWindow(30, 0)

Repeat
   Define e=WaitWindowEvent()
   Define g=EventGadget()
   Define t=EventType()
   
   Select e
      Case #PB_Event_CloseWindow
      Case #PB_Event_SizeWindow
      Case #PB_Event_ActivateWindow
      Case #PB_Event_SysTray
      Case #PB_Event_Gadget
         Debug g
      Case #PB_Event_GadgetDrop
   EndSelect
   
Until e=#PB_Event_CloseWindow
End

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Feb 13, 2010 10:30 pm
by ts-soft
eddy wrote: - cross-platform code (but i didn't test on MAC or linux)
doesn't work on linux. Tested on openSUSE 11.2 x86 and Ubuntu 9.10 x64

greetings
Thomas

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Feb 13, 2010 10:50 pm
by WilliamL
I tried it on a Mac and got an error.

In line 30 ( FreeGadget(GadgerMover) ) gives and '[error /tem/PB_EditOutput.pb (Line:30)'.

In line 31 ( ResizeGadget(ID,x,y,w,h) ) got- '[error] The specified #Gadget not initialized' .. (ID=10).

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Feb 13, 2010 11:11 pm
by eddy
It's a splitterGadget. In my function, I replace one of its gadget children.

I think it's a bug. :?

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Apr 10, 2010 4:42 pm
by eddy
Does the PB version (4.50b2) fix your problems on MAC and Linux ?

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Apr 10, 2010 4:55 pm
by WilliamL
Runs ok on my Mac. I get debugs of 10, 20, 30 and all the gadgets are in window 1. I have a gadget that is from window 2 and two gadgets in the container in window one (as you said below).

You might note that, on a Mac, unless the window is centered, that the window has to be down the number of pixels of the menu bar.

Code: Select all

define menubarheight=22
If OpenWindow(0, 0, menubarheight, #w, #h, "window1", #PB_Window_SizeGadget | #PB_Window_SystemMenu)

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Apr 10, 2010 5:04 pm
by ts-soft
eddy wrote:Does the PB version (4.50b2) fix your problems on MAC and Linux ?
There is nothing in the container on linux.

Re: SetGadgetWindow, SetGadgetParent

Posted: Sat Apr 10, 2010 6:46 pm
by eddy
WilliamL wrote:Runs ok on my Mac. I get debugs of 10, 20, 30 and all the gadgets are in window 1. I'm not sure what else to look for.
If all is OK, you can see :
- one button in the window 1
- two buttons in the containuer of window 1

I suppose that Fred fixed the bug on mac.
I have to report the problem on linux again. :roll: