PanelGadget+ multi-rows, tab style, drag tabs, right-click

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

PanelGadget+ multi-rows, tab style, drag tabs, right-click

Post by eddy »

Windows only - Updated code for PB 4.xx
- PanelGadgetPlus
- GetPanelTabPosition ( get tab position )
- getPanelTabRows ( get rows count )
- setPanelTabStyle ( min width, padding, mutli-rows )
- setPanelTabDrop ( drag 'n' drop tabs, drag display )
- SetPanelTabClick ( mouseclick advanced functionality )
- eventDropPanel
- eventDropPanelTab
- dragTab (start dragging tab)
- dropTab (drop tab, drop its content, can copy its icon)
  • Icon=#PB_Ignore : copy tab icon
  • Icon=#MyIcon : drop tab with a new specific icon
- support : right-click & left-click events
- support : #PB_Default (setPanelTabDrop, setPanelTabClick, setPanelTabStyle)
- support : x64 platform

Image
old posts

Code: Select all

Global PGP_DefaultStyle=$54030040
Global PGP_DefaultMinWidth=-1
Global PGP_DefaultPadding=6+3<<(SizeOf(Word)*8)
Global PGP_DefaultDrag=0
Global PGP_DefaultDragType=0
Global PGP_DefaultRightClick=1
Global PGP_DragIcon_ImageSrc=#Null
Global PGP_DragIcon_ImageErr=#Null
Global PGP_DragIcon_Region=#Null
Global PGP_DragIcon_Image=#Null
Global PGP_DragIcon=#Null
Global PGP_DragCross=#Null
Global PGP_DragPanel=#Null
Global PGP_DragPanelTab=-1
Structure PGP_PARAMS
   ID.i           ;stored original gadget ID
   CB.i           ;stored original gadget callback
   Drag.b         ;drag state
   CanDrop.b      ;drop enable
   CanDrag.b      ;drop enable
   Sensibility.b  ;drag sensibility
   RightClick.b   ;accept right-click
   DragType.b     ;drag type
EndStructure
Procedure PGP_DragIcon()
   Protected PGP_Owner
   
   If PGP_DragIcon : ProcedureReturn 0 : EndIf
   
   Protected x
   Protected y
   Protected w=30
   Protected h=15
   Protected rg0=CreateRectRgn_(0, 0, w, h)
   Protected rg1=CreateRectRgn_(0, 0, w-8, h-8)
   Protected rg2=CreateRectRgn_(0, 0, w, h)
   Protected pt=CreateRectRgn_(0, 0, 1, 1)
   Protected pt2=CreateRectRgn_(0, 0, 1, 1)
   
   ;{//// DASHED SQUARE
   OffsetRgn_(rg1, 4, 4)
   CombineRgn_(rg0, rg0, rg1, #RGN_XOR)
   
   For y=0 To h Step 2
      For x=0 To w Step 2
         CombineRgn_(rg0, rg0, pt, #RGN_DIFF)
         OffsetRgn_(pt, 1, 1)
         CombineRgn_(rg0, rg0, pt, #RGN_DIFF)
         OffsetRgn_(pt, 1, -1)
      Next
      OffsetRgn_(pt, -w-2, 2)
   Next
   ;}
   
   ;{//// DASHED CROSS
   For y=0 To h
      For x=0 To w
         d=y
         If y<=6 And ((x>=0+d And x<=2+d) Or (x>=6-d And x<=8-d))
            CombineRgn_(rg2, rg2, pt2, #RGN_OR)
         Else
            CombineRgn_(rg2, rg2, pt2, #RGN_DIFF)
         EndIf
         
         OffsetRgn_(pt2, 1, 0)
      Next
      OffsetRgn_(pt2, -w-1, 1)
   Next
   ;}
   
   ;{//// CREATE DRAGICON
   CompilerIf #PB_Compiler_Version<420
      Protected PGP_RestoreGadgetList_Button=ButtonGadget(#PB_Any, 0, 0, 0, 0, "hidden")
      Protected PGP_RestoreGadgetList=GetParent_(GadgetID(PGP_RestoreGadgetList_Button))
      FreeGadget(PGP_RestoreGadgetList_Button)
   CompilerElse
      Protected PGP_RestoreGadgetList=UseGadgetList(0)
   CompilerEndIf
   
   PGP_Owner=OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Invisible)
   If PGP_Owner
      PGP_DragCross=OpenWindow(#PB_Any, 9, 9, 0, 0, "", #PB_Window_BorderLess, WindowID(PGP_Owner))
      PGP_DragIcon=OpenWindow(#PB_Any, 9, 9, 0, 0, "", #PB_Window_BorderLess, WindowID(PGP_Owner))
      PGP_DragIcon_Region=OpenWindow(#PB_Any, 9, 9, 0, 0, "", #PB_Window_Invisible, WindowID(PGP_Owner))
      
      ;add image gadget
      UseGadgetList(WindowID(PGP_DragIcon))
      PGP_DragIcon_ImageSrc=CreateImage(#PB_Any, 1, 1)
      PGP_DragIcon_ImageErr=CreateImage(#PB_Any, 1, 1)
      PGP_DragIcon_Image=ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(PGP_DragIcon_ImageSrc))
      
      ;set transparent mode
      SetWindowLongPtr_(WindowID(PGP_DragIcon), #GWL_EXSTYLE, #WS_EX_LAYERED)
      SetLayeredWindowAttributes_(WindowID(PGP_DragIcon), 0, 0, 2)
      
      ;set sticky mode
      StickyWindow(PGP_DragIcon, 1)
      StickyWindow(PGP_DragCross, 1)
      
      ;set dashed mode
      SetWindowRgn_(WindowID(PGP_DragIcon_Region), rg0, 1)
      SetWindowRgn_(WindowID(PGP_DragCross), rg2, 1)
      
      ;set color
      SetWindowColor(PGP_DragIcon, GetSysColor_(#COLOR_3DSHADOW))
      SetWindowColor(PGP_DragCross, GetSysColor_(#COLOR_3DDKSHADOW))
      
      Protected result=1
   EndIf
   
   UseGadgetList(PGP_RestoreGadgetList)
   ;}
   
   DeleteObject_(rg0)
   DeleteObject_(rg1)
   DeleteObject_(rg2)
   DeleteObject_(pt)
   DeleteObject_(pt2)
   
   ProcedureReturn result
EndProcedure
Procedure PGP_DragIconTimer()
   Protected mx=DesktopMouseX()
   Protected my=DesktopMouseY()
   
   ;{/// DRAG STOP
   If GetAsyncKeyState_(#VK_LBUTTON)=0 And IsWindow(PGP_DragIcon)
      If KillTimer_(WindowID(PGP_DragIcon), 1234)
         SetLayeredWindowAttributes_(WindowID(PGP_DragIcon), 0, 0, #LWA_ALPHA)
         ResizeWindow(PGP_DragIcon, #PB_Ignore, #PB_Ignore, 0, 0)
         ResizeWindow(PGP_DragCross, #PB_Ignore, #PB_Ignore, 0, 0)
      EndIf
      ProcedureReturn 1
   EndIf
   ;}
   
   ;{/// MOVE DRAGICON
   ResizeWindow(PGP_DragIcon, mx, my+12, #PB_Ignore, #PB_Ignore)
   ResizeWindow(PGP_DragCross, mx+22+2, my+21, #PB_Ignore, #PB_Ignore)
   ;}
EndProcedure
Procedure PGP_MouseHoverPanel(ID)
   Protected TC_HITTESTINFO.TC_HITTESTINFO
   TC_HITTESTINFO\pt\x=DesktopMouseX()
   TC_HITTESTINFO\pt\y=DesktopMouseY()
   ScreenToClient_(GadgetID(ID), TC_HITTESTINFO\pt)
   ProcedureReturn SendMessage_(GadgetID(ID), #TCM_HITTEST, 0, @TC_HITTESTINFO)
EndProcedure
Procedure PGP_CB(Window, Message, wParam, lParam)
   Protected ID
   Protected *PGP_PARAMS.PGP_PARAMS=GetWindowLongPtr_(Window, #GWL_USERDATA)
   If *PGP_PARAMS : ID=*PGP_PARAMS\ID : EndIf
   
   With *PGP_PARAMS
      Select Message
         Case #WM_DESTROY
            ;{/// FREE GADGET
            Protected CB=\CB
            SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, CB)
            SetWindowLongPtr_(GadgetID(ID), #GWL_USERDATA, 0)
            FreeMemory(*PGP_PARAMS)
            ProcedureReturn CallWindowProc_(CB, Window, Message, wParam, lParam)
            ;}
            
         Case #WM_RBUTTONDOWN
            ;{/// RIGHT CLICK
            If \RightClick
               \Drag=0
               SetGadgetState(ID, PGP_MouseHoverPanel(ID))
               
               ;EVENT->RIGHTCLICK
               PostMessage_(GetParent_(Window), #WM_COMMAND, ID+#PB_EventType_RightClick<<16, GadgetID(ID))
            EndIf
            ;}
            
         Case #WM_LBUTTONDOWN, #WM_MOUSEACTIVATE
            ;{/// DRAG INIT
            If \CanDrag
               \Drag=1
               
               PGP_DragPanel=0
               PGP_DragPanelTab=0
            EndIf
            ;}
            
         Case #WM_MOUSEMOVE
            ;{/// DRAG START
            Protected mx=DesktopMouseX()
            Protected my=DesktopMouseY()
            
            If \Drag>0 And \Drag<\Sensibility
               \Drag+1
               
               If \Drag=\Sensibility
                  PGP_DragPanel=ID
                  PGP_DragPanelTab=GetGadgetState(ID)
                  
                  ;EVENT->DRAG
                  PostMessage_(GetParent_(Window), #WM_COMMAND, ID+#PB_EventType_DragStart<<16, GadgetID(ID))
               EndIf
            EndIf
            
            If \Drag=0 And WindowHeight(PGP_DragIcon)
               \Drag=\Sensibility
            EndIf
            ;}
            
            ;{/// CHANGE DRAGICON
            If WindowHeight(PGP_DragIcon)
               Select GetGadgetData(PGP_DragIcon_Image)
                  Case 0
                     If Not \CanDrop
                        ResizeWindow(PGP_DragCross, #PB_Ignore, #PB_Ignore, 100, 100)
                     Else
                        ResizeWindow(PGP_DragCross, #PB_Ignore, #PB_Ignore, 0, 0)
                     EndIf
                  Case 1
                     If Not \CanDrop
                        SetGadgetState(PGP_DragIcon_Image, ImageID(PGP_DragIcon_ImageErr))
                     Else
                        SetGadgetState(PGP_DragIcon_Image, ImageID(PGP_DragIcon_ImageSrc))
                     EndIf
               EndSelect
            EndIf
            ;}
            
         Case #WM_MOUSELEAVE
            ;{/// CHANGE DRAGICON
            Select GetGadgetData(PGP_DragIcon_Image)
               Case 0
                  If WindowHeight(PGP_DragCross)
                     ResizeWindow(PGP_DragCross, #PB_Ignore, #PB_Ignore, 0, 0)
                  EndIf
               Case 1
                  SetGadgetState(PGP_DragIcon_Image, ImageID(PGP_DragIcon_ImageSrc))
            EndSelect
            ;}
            
         Case #WM_LBUTTONUP
            ;{/// DRAG STOP
            If \Drag=\Sensibility And \CanDrop And IsGadget(PGP_DragPanel)
               \Drag=0
               SetGadgetState(ID, PGP_MouseHoverPanel(ID))
               
               ;EVENT->DROP
               PostMessage_(GetParent_(Window), #PB_Event_GadgetDrop, ID, 0)
               ;EVENT->NO RIGHTCLICK
               ProcedureReturn 1
            Else
               \Drag=0
               
               ;EVENT->NO RIGHTCLICK
               ProcedureReturn 1
            EndIf
            ;}
            
      EndSelect
   EndWith
   
   ProcedureReturn CallWindowProc_(*PGP_PARAMS\CB, Window, Message, wParam, lParam)
EndProcedure

ProcedureDLL GetPanelTabRows(ID) ;count tab rows
   ProcedureReturn SendMessage_(GadgetID(ID), #TCM_GETROWCOUNT, 0, 0)
EndProcedure
ProcedureDLL GetPanelTabPosition(ID, *pos.POINT, index=#PB_Ignore) ;get tab position (bottom-left)
   If index=#PB_Ignore : index=GetGadgetState(ID) : EndIf
   SendMessage_(GadgetID(ID), #TCM_GETITEMRECT, index, rc.RECT)
   *pos\x=rc\left
   *pos\y=rc\bottom
   ClientToScreen_(GadgetID(ID), *pos)
EndProcedure
ProcedureDLL SetPanelTabStyle(ID, MultiRows.b=0, MinWidth=#PB_Ignore, PaddingX=#PB_Ignore, PaddingY=#PB_Ignore) ; set tab style
   Protected s=$54030040
   If MultiRows
      s | #TCS_MULTILINE      ; enable multi rows
      s | #TCS_RIGHTJUSTIFY
      s & ~#TCS_SINGLELINE
   Else
      s & ~#TCS_MULTILINE
      s & ~#TCS_RAGGEDRIGHT
      s | #TCS_SINGLELINE     ;single line
   EndIf
   
   If MinWidth=#PB_Ignore : MinWidth=-1 : EndIf
   If PaddingX=#PB_Ignore : PaddingX=6 : EndIf
   If PaddingY=#PB_Ignore : PaddingY=3 : EndIf
   
   If ID=#PB_Default
      PGP_DefaultStyle=s
      PGP_DefaultMinWidth=MinWidth
      PGP_DefaultPadding=PaddingX+PaddingY<<(SizeOf(Word)*8)
   Else
      SetWindowLongPtr_(GadgetID(ID), #GWL_STYLE, s)
      SendMessage_(GadgetID(ID), #TCM_SETMINTABWIDTH, 0, MinWidth)
      SendMessage_(GadgetID(ID), #TCM_SETPADDING, 0, PaddingX+PaddingY<<(SizeOf(Word)*8))
   EndIf
EndProcedure
ProcedureDLL SetPanelTabDrop(ID, CanDrag.b=1, CanDrop.b=1, DragType.b=0) ; enable tab drag 'n' drop (DragType=0,1)
   If ID=#PB_Default
      PGP_DefaultDragType=DragType
      PGP_DefaultDrag=0
      If CanDrag : PGP_DefaultDrag | 1 : EndIf
      If CanDrop : PGP_DefaultDrag | 2 : EndIf
   Else
      Protected *PGP_PARAMS.PGP_PARAMS=GetWindowLongPtr_(GadgetID(ID), #GWL_USERDATA)
      *PGP_PARAMS\CanDrag=CanDrag
      *PGP_PARAMS\CanDrop=CanDrop
      *PGP_PARAMS\DragType=DragType
   EndIf
EndProcedure
ProcedureDLL SetPanelTabClick(ID, RightClick.b=1) ; enable tab click
   If ID=#PB_Default
      PGP_DefaultRightClick=RightClick
   Else
      Protected *PGP_PARAMS.PGP_PARAMS=GetWindowLongPtr_(GadgetID(ID), #GWL_USERDATA)
      *PGP_PARAMS\RightClick=RightClick
   EndIf
EndProcedure
ProcedureDLL PanelGadgetPlus(ID, x, y, w, h) ; create panel gadget
   PGP_DragIcon()
   
   ;gadget
   If IsGadget(ID) : FreeGadget(ID) : EndIf
   Protected result=PanelGadget(ID, x, y, w, h)
   If result=0 : ProcedureReturn 0 : EndIf
   If ID=#PB_Any : ID=result : EndIf
   
   ;set callback
   Protected CB=SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, @PGP_CB())
   
   ;set parameters
   Protected *PGP_PARAMS.PGP_PARAMS=AllocateMemory(SizeOf(PGP_PARAMS))
   With *PGP_PARAMS
      \ID=ID
      \CB=CB
      \Drag=0
      \Sensibility=5
      \CanDrag=PGP_DefaultDrag & 1
      \CanDrop=PGP_DefaultDrag & 2
      \RightClick=PGP_DefaultRightClick
      \DragType=PGP_DefaultDragType
   EndWith
   SetWindowLongPtr_(GadgetID(ID), #GWL_USERDATA, *PGP_PARAMS)
   
   ;set style
   SetWindowLongPtr_(GadgetID(ID), #GWL_STYLE, PGP_DefaultStyle)
   SendMessage_(GadgetID(ID), #TCM_SETMINTABWIDTH, 0, PGP_DefaultMinWidth)
   SendMessage_(GadgetID(ID), #TCM_SETPADDING, 0, PGP_DefaultPadding)
   
   ProcedureReturn result
EndProcedure
ProcedureDLL EventDropPanel() ;get panel
   ProcedureReturn PGP_DragPanel
EndProcedure
ProcedureDLL EventDropPanelTab() ;get tab index
   ProcedureReturn PGP_DragPanelTab
EndProcedure
ProcedureDLL DragTab() ;drag tab
   Protected ID=PGP_DragPanel
   Protected *PGP_PARAMS.PGP_PARAMS=GetWindowLongPtr_(GadgetID(ID), #GWL_USERDATA)
   
   Protected w=300
   Protected h=300
   Protected x
   Protected y
   
   Select *PGP_PARAMS\DragType
      Case 0
         ;{/// SHOW DASHED ICON
         
         ;remove image
         HideGadget(PGP_DragIcon_Image, 1)
         SetGadgetData(PGP_DragIcon_Image, *PGP_PARAMS\DragType)
         
         ;remove transparent mode
         SetLayeredWindowAttributes_(WindowID(PGP_DragIcon), 0, 255, 2)
         
         ;set dashed mode
         Protected rg0=CreateRectRgn_(0, 0, 100, 100)
         GetWindowRgn_(WindowID(PGP_DragIcon_Region), rg0)
         SetWindowRgn_(WindowID(PGP_DragIcon), rg0, 1)
         DeleteObject_(rg0)
         
         ;}
      Case 1
         ;{/// SHOW IMAGE ICON
         
         ;get tab size
         Protected index=GetGadgetState(ID)
         SendMessage_(GadgetID(ID), #TCM_GETITEMRECT, index, rc.RECT)
         InflateRect_(@rc, -2, -2)
         x=rc\left
         y=rc\top
         w=rc\right-x
         h=rc\bottom-y
         
         ;capture tab image
         ResizeImage(PGP_DragIcon_ImageSrc, w, h)
         Protected dcSrc=GetDC_(GadgetID(ID))
         Protected dcDest=StartDrawing(ImageOutput(PGP_DragIcon_ImageSrc))
            BitBlt_(dcDest, 0, 0, w, h, dcSrc, x, y, #SRCCOPY)
         StopDrawing()
         ReleaseDC_(GadgetID(ID), dcSrc)
         
         ;create tab gray image
         FreeImage(PGP_DragIcon_ImageErr)
         PGP_DragIcon_ImageErr=CopyImage(PGP_DragIcon_ImageSrc, #PB_Any)
         StartDrawing(ImageOutput(PGP_DragIcon_ImageErr))
            For y=0 To ImageHeight(PGP_DragIcon_ImageErr)-1
               For x=0 To ImageWidth(PGP_DragIcon_ImageErr)-1
                  Protected c=Point(x, y)
                  Protected g=Round(Red(c)*0.56+Green(c)*0.33+Blue(c)*0.11, #PB_Round_Down)-100
                  Plot(x, y, RGB(g, g, g))
               Next
            Next
         StopDrawing()
         
         ;set image
         SetGadgetState(PGP_DragIcon_Image, ImageID(PGP_DragIcon_ImageSrc))
         HideGadget(PGP_DragIcon_Image, 0)
         SetGadgetData(PGP_DragIcon_Image, *PGP_PARAMS\DragType)
         
         ;set transparent mode
         SetLayeredWindowAttributes_(WindowID(PGP_DragIcon), 0, 150, #LWA_ALPHA)
         
         ;remove dashed mode
         SetWindowRgn_(WindowID(PGP_DragIcon), 0, 1)
         
         ;}
   EndSelect
   
   ;show drag icon
   Protected mx=DesktopMouseX()
   Protected my=DesktopMouseY()
   ResizeWindow(PGP_DragIcon, mx, my+12, w, h)
   SetTimer_(WindowID(PGP_DragIcon), 1234, 1, @PGP_DragIconTimer())
EndProcedure
ProcedureDLL DropTab(ID, DropContent.b=1, Icon=#PB_Ignore) ;drop tab (and its content if #TRUE)
   Protected ID1=EventDropPanel()
   Protected pos1=EventDropPanelTab()
   Protected pos=GetGadgetState(ID)
   Protected txt.s=GetGadgetItemText(ID1, pos1)
   
   ;{/// Drag Content
   If DropContent
      Protected temp=OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Invisible)
      Protected gadgetList
      Protected gadget
      
      gadgetList=OpenGadgetList(ID1, pos1)
      While GetWindow_(gadgetList, #GW_CHILD)
         gadget=GetWindow_(gadgetList, #GW_CHILD)
         SetParent_(gadget, WindowID(temp))
         SetWindowLongPtr_(gadget, #GWL_HWNDPARENT, WindowID(temp))
      Wend
   EndIf
   ;}
   Structure PGP_ITEM Extends TC_ITEM
      ImgList.i
      Icon.i
   EndStructure
   Protected drop.PGP_ITEM
   Protected drag.PGP_ITEM
   drop\Mask=#TCIF_IMAGE
   drag\Mask=#TCIF_IMAGE
   
   SendMessage_(GadgetID(ID1), #TCM_GETITEM, pos1, @drag)
   drag\ImgList=SendMessage_(GadgetID(ID1), #TCM_GETIMAGELIST, 0, 0)
   drag\Icon=ImageList_GetIcon_(drag\ImgList, drag\iImage, #ILD_TRANSPARENT)
   
   RemoveGadgetItem(ID1, pos1)
   If Icon=#PB_Ignore And ID=ID1
      AddGadgetItem(ID, pos, txt)
      
      SendMessage_(GadgetID(ID), #TCM_SETITEM, pos, @drag)
   ElseIf Icon=#PB_Ignore And drag\ImgList And drag\iImage>-1
      Icon=CreateImage(#PB_Any, 16, 16)
      AddGadgetItem(ID, pos, txt, ImageID(Icon))
      FreeImage(Icon)
      
      SendMessage_(GadgetID(ID), #TCM_GETITEM, pos, @drop)
      drop\ImgList=SendMessage_(GadgetID(ID), #TCM_GETIMAGELIST, 0, 0)
      
      ImageList_ReplaceIcon_(drop\ImgList, drop\iImage, drag\Icon)
   ElseIf Icon<>#PB_Ignore And IsImage(Icon)
      AddGadgetItem(ID, pos, txt, ImageID(Icon))
   Else
      AddGadgetItem(ID, pos, txt)
   EndIf
   SetGadgetState(ID, pos)
   
   ;{/// Drop Content
   If DropContent
      gadgetList=OpenGadgetList(ID, pos)
      While GetWindow_(WindowID(temp), #GW_CHILD)
         gadget=GetWindow_(WindowID(temp), #GW_CHILD)
         SetParent_(gadget, gadgetList)
         SetWindowLongPtr_(gadget, #GWL_HWNDPARENT, gadgetList)
      Wend
      CloseWindow(temp)
   EndIf
   ;}
   
EndProcedure

;********************
;EXAMPLE @ eddy
;********************

SetGadgetFont(#PB_Default, LoadFont(50, "verdana", 6, #PB_Font_Bold))
SetPanelTabStyle(#PB_Default, 1, 30, 10, 10)
SetPanelTabDrop(#PB_Default)

OpenWindow(0, 50, 50, 450, 150, "Drag 'n' Drop")
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(0))
CompilerEndIf
If PanelGadgetPlus(10, 0, 0, 150, 150)
   AddGadgetItem(10, -1, "A")
   AddGadgetItem(10, -1, "B")
   CloseGadgetList()
   
   OpenGadgetList(10, 0)
   w=GetGadgetAttribute(10, #PB_Panel_ItemWidth)-2
   h=GetGadgetAttribute(10, #PB_Panel_ItemHeight)-2
   ButtonGadget(100, 0, 0, w, h/2, "X")
   ButtonGadget(101, 0, h/2, w, h/2, "Y")
   CloseGadgetList()
EndIf

If PanelGadgetPlus(20, 150, 0, 150, 150)
   AddGadgetItem(20, -1, "C")
   AddGadgetItem(20, -1, "D")
   CloseGadgetList()
EndIf

OpenWindow(1, 250, 250, 200, 50, "No drag and drop")
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(1))
CompilerEndIf
If PanelGadgetPlus(30, 0, 0, 200, 50)
   SetPanelTabClick(30, 0)
   SetPanelTabDrop(30, 0, 0)
   AddGadgetItem(30, -1, "NO RIGHT CLICK")
   CloseGadgetList()
EndIf
Debug "GetPanelTabRows = "+Str(GetPanelTabRows(30))

If CreatePopupMenu(50)
   MenuItem(1, "Open")
   MenuItem(2, "Save")
   CloseSubMenu()
EndIf

Repeat
   e=WaitWindowEvent()
   t=EventType()
   g=EventGadget()
   If e=#PB_Event_Gadget And t=#PB_EventType_RightClick
      If g=10
         Debug "RightClick > Popupmenu (below tab)"
         GetPanelTabPosition(g, pos.POINT)
         DisplayPopupMenu(50, WindowID(0), pos\x, pos\y)
      EndIf
      If g=20
         Debug "RightClick > Popupmenu (mouse position)"
         DisplayPopupMenu(50, WindowID(0), DesktopMouseX(), DesktopMouseY())
      EndIf
   EndIf
   If e=#PB_Event_Gadget And t=#PB_EventType_LeftClick
      Debug "LeftClick > gadget="+Str(g)
   EndIf
   
   If e=#PB_Event_Gadget And (g=10 Or g=20) And t=#PB_EventType_DragStart
      DragTab()
   EndIf
   
   If e=#PB_Event_GadgetDrop And (g=10 Or g=20 Or g=30)
      Debug ""
      Debug "drag panel = "+Str(EventDropPanel())
      Debug "drag tab   = "+Str(EventDropPanelTab())
      Debug "drag tab text="+GetGadgetItemText(EventDropPanel(), EventDropPanelTab())
      Debug ""
      Debug "TARGET panel = "+Str(EventGadget())
      Debug "TARGET tab   = "+Str(GetGadgetState(EventGadget()))
      DropTab(g)
   EndIf
   
Until e=#PB_Event_CloseWindow
Last edited by eddy on Thu Dec 11, 2008 7:18 pm, edited 49 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

You have forgotten to write CreateGadgetList(WindowID(0)) :?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

zxtunes.com wrote:You have forgotten to write CreateGadgetList(WindowID(0)) :?
It's removed in the beta. :roll:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Finally I decided to code a complete panelgadget library.
you can test this beta version. :D


[W.I.P]
:arrow: tab drag 'n' drop ( with special drag icon )
:arrow: supported drag'n'drop events
Last edited by eddy on Sat Oct 11, 2008 8:27 pm, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

very cool eddy :D
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Micko wrote:very cool eddy :D
ty :D

[beta 2]
- drop panel
- drop panel tab
- example : drap tab & drop tab

ToDo
- I have to improve drop detection.
- Find a easy way to transfer tab content.
- Fix window focus problem
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

Post by eddy »

[beta3 ]
- FIXED : focus lost
- ADDED : DropTab
- support : right-click & left-click events
- support : #PB_Default

ToDo
- swap tab content
- function to get tab position
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

Post by eddy »

Updated
- DropTab : we can drop a tab and its content. :)
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Eddy, eddycheeb me boyo!!!

This is fantastic. I think it is a great bit of code! Keep up the good work! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

[Updated]
- GetPanelTabPosition : get tab position (usefull if you want to display popupmenu)
Last edited by eddy on Thu Oct 23, 2008 11:00 pm, edited 1 time in total.
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

Post by eddy »

[Updated]
- new parameter for DropTab function :
DropTab(ID, DropContent.b=1, Icon=#PB_Ignore)
  • Icon=#PB_Ignore (default) : copy tab icon
  • Icon=#MyIcon : drop tab with a new specific icon
Image

Here is a new example :

Code: Select all

;********************
;EXAMPLE @ eddy
;********************

img1=CreateImage(1, 16, 16)
StartDrawing(ImageOutput(1))
   Box(0, 0, 16, 16, $FF00FF)
   Box(0, 0, 14, 14, $770077)
StopDrawing()
img2=CreateImage(2, 16, 16)
StartDrawing(ImageOutput(2))
   Box(0, 0, 16, 16, $CCFF33)
   Box(0, 0, 14, 14, $22EEAA)
StopDrawing()

SetGadgetFont(#PB_Default, LoadFont(50, "verdana", 6, #PB_Font_Bold))
SetPanelTabStyle(#PB_Default, 1, 30, 7, 10)
SetPanelTabDrop(#PB_Default)

OpenWindow(0, 50, 50, 500, 150, "Drag 'n' Drop tab with icons")
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(0))
CompilerEndIf
If PanelGadgetPlus(10, 0, 0, 150, 150)
   AddGadgetItem(10, -1, "A", img1)
   AddGadgetItem(10, -1, "B", img1)
   AddGadgetItem(10, -1, "C", img1)
   CloseGadgetList()
EndIf

If PanelGadgetPlus(20, 150, 0, 200, 150)
   AddGadgetItem(20, -1, "E", img2)
   AddGadgetItem(20, -1, "F", img2)
   CloseGadgetList()
EndIf

Repeat
   e=WaitWindowEvent()
   t=EventType()
   g=EventGadget()
   
   If e=#PB_Event_Gadget And (g=10 Or g=20) And t=#PB_EventType_DragStart
      DragTab()
   EndIf
   
   If e=#PB_Event_GadgetDrop And (g=10 Or g=20)
      DropTab(g)
   EndIf
   
Until e=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

This is excellent. Thanks for sharing. :)
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

Thanks for the code! :wink:

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

[Updated]
- FIXED : supports x64 ( SetWindowlongPtr )
- ADDED : SetPanelTabClick supports #PB_Default
- new parameter DragType for SetPanelTabDrop
  • 0=Drag icon
  • 1=Drag transparent image

Code: Select all

;********************
;EXAMPLE @ eddy
;********************

img1=CreateImage(100, 16, 16)
StartDrawing(ImageOutput(100))
   Box(0, 0, 16, 16, $FF00FF)
   Box(0, 0, 14, 14, $770077)
StopDrawing()
img2=CreateImage(200, 16, 16)
StartDrawing(ImageOutput(200))
   Box(0, 0, 16, 16, $CCFF33)
   Box(0, 0, 14, 14, $22EEAA)
StopDrawing()

SetGadgetFont(#PB_Default, LoadFont(50, "verdana", 6, #PB_Font_Bold))
SetPanelTabStyle(#PB_Default, 1, 30, 10, 10)
SetPanelTabDrop(#PB_Default, #True, #True, 1)

OpenWindow(0, 50, 50, 450, 150, "Drag 'n' Drop")
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(0))
CompilerEndIf
If PanelGadgetPlus(10, 0, 0, 150, 150)
   AddGadgetItem(10, -1, "AH", img1)
   AddGadgetItem(10, -1, "BOOH!")
   CloseGadgetList()
EndIf

If PanelGadgetPlus(20, 150, 0, 150, 150)
   AddGadgetItem(20, -1, "COOL")
   AddGadgetItem(20, -1, "DO IT", img2)
   CloseGadgetList()
EndIf

OpenWindow(1, 250, 250, 200, 50, "No drag and drop")
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(WindowID(1))
CompilerEndIf
If PanelGadgetPlus(30, 0, 0, 200, 50)
   SetPanelTabClick(30, 0)
   SetPanelTabDrop(30, 0, 0)
   AddGadgetItem(30, -1, "NO RIGHT CLICK")
   CloseGadgetList()
EndIf

Repeat
   e=WaitWindowEvent()
   t=EventType()
   g=EventGadget()
   
   If e=#PB_Event_Gadget And t=#PB_EventType_LeftClick
      Debug "LeftClick > gadget="+Str(g)
   EndIf
   
   If e=#PB_Event_Gadget And (g=10 Or g=20) And t=#PB_EventType_DragStart
      DragTab()
   EndIf
   
   If e=#PB_Event_GadgetDrop And (g=10 Or g=20)
      DropTab(g)
   EndIf
Until e=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply