PanelGadget and Item
PanelGadget and Item
Hi,
i would want to know if it is possible to move an item of a panelgadget. Not in Drag & Drop, but in code...
Thank you for advance !
i would want to know if it is possible to move an item of a panelgadget. Not in Drag & Drop, but in code...
Thank you for advance !
Do you mean reorder the panels?
If so :
**EDIT - bug fixed.
If so :
Code: Select all
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget (0, 8, 50, 306, 130)
AddGadgetItem (0, -1, "Panel 1")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(4, 10, 15, 80, 24,"Button 3")
CloseGadgetList()
ButtonGadget(1, 0,0,120,30,"Reorder panels!")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ;Let's reorder the panels.
tci.TC_ITEM
tci\mask=#TCIF_PARAM
SendMessage_(GadgetID(0), #TCM_GETITEM, 0, tci)
hPanel0 = tci\lparam ;This holds the windows handle of the static control attached to tab 0.
SendMessage_(GadgetID(0), #TCM_GETITEM, 1, tci)
hPanel1 = tci\lparam ;This holds the windows handle of the static control attached to tab 1.
;Switch the panels.
SendMessage_(GadgetID(0), #TCM_SETITEM, 0, tci)
tci\lparam = hPanel0
SendMessage_(GadgetID(0), #TCM_SETITEM, 1, tci)
;Force a redraw.
Select GetGadgetState(0)
Case 0
ShowWindow_(hPanel0, #SW_HIDE)
GetClientRect_(hpanel0,rc.rect)
MapWindowPoints_(hPanel0, GadgetID(0),rc,2)
SetWindowPos_(hPanel1, 0, rc\left,rc\top,rc\right-rc\left,rc\bottom-rc\top, #SWP_NOZORDER|#SWP_SHOWWINDOW)
Case 1
ShowWindow_(hPanel1, #SW_HIDE)
GetClientRect_(hpanel1,rc.rect)
MapWindowPoints_(hPanel1, GadgetID(0),rc,2)
SetWindowPos_(hPanel0, 0, rc\left,rc\top,rc\right-rc\left,rc\bottom-rc\top, #SWP_NOZORDER|#SWP_SHOWWINDOW)
EndSelect
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
**EDIT - bug fixed.
I may look like a mule, but I'm not a complete ass.
Afraid not - don't do Linux!
Here's one which switches the enitre panels; text, images the lot!

Here's one which switches the enitre panels; text, images the lot!
Code: Select all
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget (0, 8, 50, 306, 130)
AddGadgetItem (0, -1, "Panel 1")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(4, 10, 15, 80, 24,"Button 3")
CloseGadgetList()
ButtonGadget(1, 0,0,120,30,"Reorder panels!")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ;Let's reorder the panels.
tci0.TC_ITEM
tci0\mask=#TCIF_TEXT|#TCIF_IMAGE|#TCIF_PARAM
buffer1$=Space(256)
tci0\pszText = @buffer1$
tci0\cchTextMax = 256
tci1.TC_ITEM
tci1\mask=#TCIF_TEXT|#TCIF_IMAGE|#TCIF_PARAM
buffer2$=Space(256)
tci1\pszText = @buffer2$
tci1\cchTextMax = 256
SendMessage_(GadgetID(0), #TCM_GETITEM, 0, tci0)
hPanel0 = tci0\lparam ;This holds the windows handle of the static control attached to tab 0.
SendMessage_(GadgetID(0), #TCM_GETITEM, 1, tci1)
hPanel1 = tci1\lparam ;This holds the windows handle of the static control
;Switch the panels.
SendMessage_(GadgetID(0), #TCM_SETITEM, 0, tci1)
SendMessage_(GadgetID(0), #TCM_SETITEM, 1, tci0)
;Force a redraw.
Select GetGadgetState(0)
Case 0
ShowWindow_(hPanel0, #SW_HIDE)
GetClientRect_(hpanel0,rc.rect)
MapWindowPoints_(hPanel0, GadgetID(0),rc,2)
SetWindowPos_(hPanel1, 0, rc\left,rc\top,rc\right-rc\left,rc\bottom-rc\top, #SWP_NOZORDER|#SWP_SHOWWINDOW)
Case 1
ShowWindow_(hPanel1, #SW_HIDE)
GetClientRect_(hpanel1,rc.rect)
MapWindowPoints_(hPanel1, GadgetID(0),rc,2)
SetWindowPos_(hPanel0, 0, rc\left,rc\top,rc\right-rc\left,rc\bottom-rc\top, #SWP_NOZORDER|#SWP_SHOWWINDOW)
EndSelect
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
I may look like a mule, but I'm not a complete ass.
Without api the only way would be to destroy and the recreate the gadget.Progi1984 wrote:When I see you second code, I have a question :
(May be more portable)
Is there a solution to move a gadget of a tab to an another tab ?
With api, you use SetParent_(). The problem here is that you need to obtain the handle of the static control used for each panel. For this you use the #TCM_GETITEM message (as I did with the code above) and the required handle is then placed in the lparam field of the TC_ITEM structure variable.
I may look like a mule, but I'm not a complete ass.
Find this solution more better for my problem

Code: Select all
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget (0, 8, 50, 306, 130)
AddGadgetItem (0, -1, "Panel 1")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem (0, -1,"Panel 2")
ButtonGadget(4, 10, 15, 80, 24,"Button 3")
CloseGadgetList()
ButtonGadget(1, 0,0,120,30,"Move gadget in panel!")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ;Let's reorder the panels.
tci.TC_ITEM
tci\mask=#TCIF_PARAM
SendMessage_(GadgetID(0), #TCM_GETITEM, 0, tci)
hPanel0 = tci\lparam ;This holds the windows handle of the static control attached to tab 0.
SendMessage_(GadgetID(0), #TCM_GETITEM, 1, tci)
hPanel1 = tci\lparam ;This holds the windows handle of the static control attached to tab 1.
SetParent_(GadgetID(2), HPanel1)
SetParent_(GadgetID(4), HPanel0)
Default
If GadgetType(EventGadget()) = #PB_GadgetType_Button
Debug GetGadgetText(EventGadget())
EndIf
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
Yes; the problem with switching the entire panel is in getting the static controls to then display correctly - particularly if the user is yet to select a tab.
All you need to do now then is find a gtk equivalent and stick in some conditional compilation etc.
All you need to do now then is find a gtk equivalent and stick in some conditional compilation etc.
I may look like a mule, but I'm not a complete ass.