Tip : Multi-rows Tab Control

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Tip : Multi-rows Tab Control

Post by BackupUser »

Updated for version 5.20

Restored from previous forum. Originally posted by Eddy.

My contribution...:)
A "Panel Gadget" is a singleline tab control. I convert it into multiline rows tab control.

Code: Select all

;****************************************************************
#GADGET_TABS = 1
Global PanelWidth:  PanelWidth=150 ;change this variable
Global PanelHeight: PanelHeight=21 ;height of one row

Procedure SetMultiRowsTabs()
  NewStyle.l = GetWindowLong_(GadgetID(#GADGET_TABS), #GWL_STYLE)
  NewStyle = NewStyle | #TCS_MULTILINE      ; enable multi rows
  NewStyle = NewStyle | #TCS_RIGHTJUSTIFY   ; optimize the width of each tabs
  NewStyle = NewStyle ! #TCS_SINGLELINE 
  SetWindowLong_(GadgetID(#GADGET_TABS), #GWL_STYLE, NewStyle)
EndProcedure 

Procedure CorrectTabsHeight()
  rows = sendmessage_(GadgetID(#GADGET_TABS),#TCM_GETROWCOUNT,0,0) 
  messagebox_(WindowID(),"Rows Count ="+Str(rows),"",#MB_OK)
  MoveWindow_(GadgetID(#GADGET_TABS),0,0,PanelWidth,PanelHeight * rows, 1)  ; better than ResizeGadget method
EndProcedure 

hwin=OpenWindow(0,50,50,500,250,0,"Test")
CreateGadgetList(hwin)

PanelGadget(#GADGET_TABS,0,0,PanelWidth,PanelHeight)
        AddGadgetItem(#GADGET_TABS,0,"Functions")
        AddGadgetItem(#GADGET_TABS,0,"Types")
        AddGadgetItem(#GADGET_TABS,0,"Labels")
        AddGadgetItem(#GADGET_TABS,0,"Globals")
        AddGadgetItem(#GADGET_TABS,0,"Arrays")
        AddGadgetItem(#GADGET_TABS,0,"Constants")
        AddGadgetItem(#GADGET_TABS,0,"Includes")  
ClosePanelGadget()

SetMultiRowsTabs() 
CorrectTabsHeight()

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
;****************************************************************
Example Use of multiline tab control : (see on the right)


Banzaii
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Eddy.

over 70 read

This tip is usefull.

Armageddon command : Format All +S +Pain \now
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andre.

Works fine here under WinXP home SP1. Thanks a lot for sharing your code

Regards
André

*** German PureBasic Support ***
talun
User
User
Posts: 28
Joined: Mon May 05, 2003 3:53 pm
Location: Italy

Post by talun »

Hi Eddy,
can you say me if it's possible to show also the pages related at each tab?

many thanks

Sergio
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

talun wrote:can you say me if it's possible to show also the pages related at each tab?
try this:

Code: Select all

;-Additional Panel-Gadget
Procedure GetPanelDisplayWindowID(Gadget,Item)
  tc_item.tc_item
  tc_item\imask=#TCIF_PARAM 
  sendmessage_(GadgetID(Gadget),#tcm_getitem,Item,tc_item)
  ProcedureReturn tc_item\lParam
EndProcedure
Procedure GetInnerSizeWidth(Gadget)
  rect.rect
  getwindowrect_(GetPanelDisplayWindowID(Gadget,GetGadgetState(Gadget)),rect)
  ProcedureReturn rect\right-rect\left
EndProcedure
Procedure GetInnersizeHeight(Gadget)
  rect.rect
  getwindowrect_(GetPanelDisplayWindowID(Gadget,GetGadgetState(Gadget)),rect)
  ProcedureReturn rect\bottom-rect\top
EndProcedure
Procedure PanelMultiLine(Gadget,Flag)
  Style=GetWindowLong_(GadgetID(Gadget),#GWL_STYLE )
  If Flag
    Style|#TCS_MULTILINE
    Style!#TCS_SINGLELINE
  Else
    Style!#TCS_MULTILINE
    Style|#TCS_SINGLELINE
  EndIf
  SetWindowLong_(GadgetID(Gadget),#GWL_STYLE,Style)
EndProcedure
Procedure ReCalculatePanel(Gadget)
  sendmessage_(GadgetID(Gadget),#wm_setredraw,#True,0)
  ResizeGadget(Gadget,-1,-1,-1,-1); resize to the default of windows
  getclientrect_(GadgetID(Gadget),rect.rect)
  sendmessage_(GadgetID(Gadget),#tcm_adjustrect,#False,rect)
  y=rect\top
  h=rect\bottom-rect\top+1
  
  hwnd=GetPanelDisplayWindowID(Gadget,0)
  getwindowrect_(hwnd,rect.rect)
  getwindowrect_(getparent_(hwnd),rect2.rect)
  x=rect\left-rect2\left
  w=rect\right-rect\left
  
  For i=0 To CountGadgetItems(Gadget)-1
    hwnd=GetPanelDisplayWindowID(Gadget,i)
    SetWindowPos_(hwnd,0, x,y,w,h,#SWP_NOZORDER)
  Next
  
  sendmessage_(GadgetID(Gadget),#wm_setredraw,#False,0)
EndProcedure
Procedure UsePanelItem(Gadget,Item)
  ProcedureReturn CreateGadgetList(GetPanelDisplayWindowID(Gadget,Item))
EndProcedure


OpenWindow(0,0,200,400,400,0,"TEST")
CreateGadgetList(WindowID())
PanelGadget(0,0,0,400,400)
For i=0 To 20
  AddGadgetItem(0,-1,Str(i))
    ButtonGadget(1,0,0,100,100,"SWITCH "+Str(i))
  ClosePanelGadget()
Next

switch=0
Repeat
  event=WaitWindowEvent()
  If event=#pb_event_gadget
    If EventGadgetID()=1
      d=1-d
      PanelMultiLine(0,d)
      ReCalculatePanel(0)
    EndIf
  EndIf
Until event=#pb_event_closewindow
But i hope, in the next version Fred add a MultiLinePanel-Gadget ( and please make it switchabel, like in the example).

note: Call only ReCalculatePanel, when you have min. one item in it. and Call it allways, when you resize the panel or when you delete/Add items to the panel.

GPI
talun
User
User
Posts: 28
Joined: Mon May 05, 2003 3:53 pm
Location: Italy

Post by talun »

Hi GPI,
thank you for your code; it's works fine.
I also hope that Fred will add the multirows style to Panel gadgets.

Thanks!

Sergio
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

>I also hope that Fred will add the multirows style to Panel gadgets.

Hm, i tested a little bit. It seems, that Fred only set the y-position of the display-window wrong. X and size are right. I would call this a bug :)

Here a little shorter Version of the recalc:

Code: Select all

Procedure ReCalculatePanel(Gadget)
  sendmessage_(GadgetID(Gadget),#wm_setredraw,#True,0)
  ResizeGadget(Gadget,-1,-1,-1,-1); resize to the default of windows
  getclientrect_(GadgetID(Gadget),rect.rect)
  sendmessage_(GadgetID(Gadget),#tcm_adjustrect,#False,rect)
  y=rect\top
  
  hwnd=GetPanelDisplayWindowID(Gadget,0)
  getwindowrect_(hwnd,rect.rect)
  getwindowrect_(getparent_(hwnd),rect2.rect)
  x=rect\left-rect2\left
  
  For i=0 To CountGadgetItems(Gadget)-1
    hwnd=GetPanelDisplayWindowID(Gadget,i)
    SetWindowPos_(hwnd,0, x,y,0,0,#swp_nosize|#SWP_NOZORDER)
  Next
  
  sendmessage_(GadgetID(Gadget),#wm_setredraw,#False,0)
EndProcedure
Post Reply