Page 1 of 1

PanelGadget and Item

Posted: Thu Aug 23, 2007 1:20 pm
by Progi1984
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 !

Posted: Thu Aug 23, 2007 1:47 pm
by srod
Do you mean reorder the panels?

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.

Posted: Thu Aug 23, 2007 3:06 pm
by Progi1984
Thanks, it's why i want :D for Windows...

But this code is not so portable. :( Have you the solution for GTK ?

Posted: Thu Aug 23, 2007 3:17 pm
by srod
Afraid not - don't do Linux! :)

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

Posted: Thu Aug 23, 2007 3:36 pm
by Progi1984
Linux is not so horrible...

A simply WmWare (or another virtualization program) image permits you to get some habits with this system and test your PB programs :)

Posted: Thu Aug 23, 2007 3:42 pm
by srod
One day perhaps when all of my hair and teeth fall out and I give up trying to persuade the courts that I am Bill Gates' illegitimate son then I may turn to take a look at Linux!

:wink:

Posted: Thu Aug 23, 2007 3:50 pm
by Progi1984
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 ?

Posted: Thu Aug 23, 2007 3:56 pm
by srod
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 ?
Without api the only way would be to destroy and the recreate the gadget.

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.

Posted: Thu Aug 23, 2007 4:00 pm
by Progi1984
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 

Posted: Thu Aug 23, 2007 4:03 pm
by srod
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.

Posted: Fri Aug 24, 2007 7:44 am
by Progi1984
It's just I want... More pratical for my code :)

Thank you again for your help !