SetGadgetWindow, SetGadgetParent

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

SetGadgetWindow, SetGadgetParent

Post 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
Last edited by eddy on Sat Apr 10, 2010 4:43 pm, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: SetGadgetWindow, SetGadgetParent

Post 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
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: SetGadgetWindow, SetGadgetParent

Post 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).
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SetGadgetWindow, SetGadgetParent

Post by eddy »

It's a splitterGadget. In my function, I replace one of its gadget children.

I think it's a bug. :?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SetGadgetWindow, SetGadgetParent

Post by eddy »

Does the PB version (4.50b2) fix your problems on MAC and Linux ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: SetGadgetWindow, SetGadgetParent

Post 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)
Last edited by WilliamL on Sat Apr 10, 2010 6:59 pm, edited 2 times in total.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: SetGadgetWindow, SetGadgetParent

Post 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.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SetGadgetWindow, SetGadgetParent

Post 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:
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply