The RebarGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

The RebarGadget

Post by Guimauve »

Original code from Chris (French forum)
Modified by me

It's to late for V4.00 but I think this very cool gadget should be add to the standard PB gadget in V4.10.

Fred or Freak ????

Regards

Guimauve

Code: Select all

;-Constantes Fenêtres
Enumeration
   #Window_0
EndEnumeration

;-Constantes Gadgets
Enumeration
   
   #Rebar
   
   #RebarItem01
   #Btn_1
   #List_1
   #Cmb_1
   
   #RebarItem02
   #Explorer
   #Btn_Clear
   
   #RebarItem03
   #Calendar
   #Btn_Clear2
   
   #DbgEdit
   #Btn_Quit
EndEnumeration

;- Constantes Diverses
#CCS_VERT = $00000080

;- Variables
; Global hwnRb, g_hinst

Text1.s = "Liste et Combos"
Text2.s = "Explorateur"
Text3.s = "Calendrier"

;- Procedures
Procedure InsertReBarItem(hWndRebar.l, RebarItemID.l, Text.s, BarWidth.l, Index.l, BkColor.l, FgColor)
   
   hItemCont = ContainerGadget(RebarItemID, 0, 0, 0, 0)
   
   rbBand.REBARBANDINFO
   
   rbBand\cbSize = SizeOf(REBARBANDINFO)
   rbBand\fMask  = #RBBIM_STYLE | #RBBIM_CHILD | #RBBIM_CHILDSIZE | #RBBIM_TEXT | #RBBIM_HEADERSIZE | #RBBIM_COLORS
   rbBand\fStyle = #RBBS_CHILDEDGE
   
   rbBand\clrBack    = BkColor
   rbBand\clrFore    = FgColor
   rbBand\lpText     = @Text
   rbBand\hwndChild  = hItemCont
   rbBand\cyMinChild = BarWidth
   rbBand\cxHeader   = 30
   rbBand\cx         = BarWidth
   
   SendMessage_(hWndRebar, #RB_INSERTBAND, Index, @rbBand)
   
EndProcedure

Procedure RebarGadget(GadgetID, x, y, Width, Height)
   
   hMainCont = ContainerGadget(GadgetID, x, y, Width, Height, #PB_Container_Raised)
   
   rbi.REBARINFO
   icex.INITCOMMONCONTROLSEX
   
   icex\dwSize = SizeOf(INITCOMMONCONTROLSEX);
   icex\dwICC   = #ICC_COOL_CLASSES|#ICC_BAR_CLASSES
   InitCommonControlsEx_(@icex);
   
   hwndRB = CreateWindowEx_(#WS_EX_TOOLWINDOW, "ReBarWindow32", #Null, #WS_CHILD|#WS_VISIBLE|#WS_CLIPSIBLINGS|#CCS_VERT , 0,0,0,0, hMainCont, GadgetID, 0, #Null);
   ;/ Sous Windows XP, téléchargez la lib uxtheme. (Lien en bas du message)
   ;/ Pour les autres Windows, (98,ME, etc), désactivez cette ligne
   ; SetWindowTheme_(hwndRB, " ", " ")
   ;/
   
   ProcedureReturn hwndRB;
EndProcedure

;- Boucle principale
hwnd = OpenWindow(#Window_0, 300, 300, 800, 600, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "RebarTest",0)
; g_hinst = GetModuleHandle_(#Null)

If CreateGadgetList(hwnd)
   
   RebarHandle = RebarGadget(#Rebar, 5, 5, 200, 400);>
      
      ;- Rebar 1
      InsertReBarItem(RebarHandle, #RebarItem01, Text1, 185, 0, GetSysColor_(#COLOR_BTNFACE), 0);>
         ButtonGadget(#Btn_1, 45, 10, 100, 25, "Bouton 1")
         ListIconGadget(#List_1, 5, 40, 180, 350, "Liste 1", 125)
         AddGadgetColumn(#List_1, 1, "Valeur", 50)
         ComboBoxGadget(#Cmb_1, 5, 410, 180, 200)
      CloseGadgetList();<
      
      ;- Rebar 2
      InsertReBarItem(RebarHandle, #RebarItem02, Text2, 185, 1, GetSysColor_(#COLOR_BTNFACE), 0);>
         ExplorerTreeGadget(#Explorer, 5, 5, 180, 200, "C:\*.txt;*.pb")
         ButtonGadget(#Btn_Clear, 5, 210, 180, 20, "Effacer l'éditeur")
      CloseGadgetList();<
      
      ;- Rebar 3
      InsertReBarItem(RebarHandle, #RebarItem03, Text3, 185, 2, GetSysColor_(#COLOR_BTNFACE), 0);>
         CalendarGadget(#Calendar, 5, 5, 180, 200)
         ButtonGadget(#Btn_Clear2, 5, 210, 180, 20, "Effacer l'éditeur")
      CloseGadgetList();<
      
   CloseGadgetList();<
   
   
   ;- Retour à la liste de gadgets
   EditorGadget(#DbgEdit, 210, 5, 585, 560)
   ButtonGadget(#Btn_Quit, 450, 570, 100, 25, "Quitter")
   
   ;- Remplissage de la liste et du combo
   For i = 0 To 20
      AddGadgetItem(#Cmb_1,   -1, "Elément du combo " + Str(i))
      AddGadgetItem(#List_1,  -1, "Elément de la liste " + Str(i) + Chr(10) + Str(i))
   Next
   
   SetGadgetState(#Cmb_1, 0)
EndIf


;- Boucle
Repeat
   Select WaitWindowEvent()
      Case #PB_Event_Gadget
         Select EventGadget()
            ;- Evènements dans la bande 1
            Case #Btn_1
               AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
            Case #List_1
               AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
            Case #Cmb_1
               If EventType() = #PB_EventType_RightClick
                  AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
               EndIf
               
               ;- Evènements dans la bande 2
            Case #Btn_Clear
               ClearGadgetItemList(#DbgEdit)
               
            Case #Explorer
               If EventType() = #PB_EventType_LeftDoubleClick And GetGadgetState(#Explorer) = #PB_Explorer_File
                  ClearGadgetItemList(#DbgEdit)
                  
                  If FileSize(GetGadgetText(#Explorer)) < 64900
                     If ReadFile(0, GetGadgetText(#Explorer))
                        Repeat
                           AddGadgetItem(#DbgEdit, -1, ReadString(0))
                        Until Eof(0)
                        CloseFile(0)
                        
                     EndIf
                  EndIf
               EndIf
               
               
               ;- Evènements dans la bande 3
            Case #Calendar
               AddGadgetItem(#DbgEdit, -1, "La date choisie est le "+FormatDate("%dd %mm %yyyy", GetGadgetState(#Calendar)))
               
            Case #Btn_Clear2
               ClearGadgetItemList(#DbgEdit)
               
               ;- Retour à la fenêtre
            Case #Btn_Quit 
               quit = 1
               
         EndSelect
         
      Case #PB_Event_CloseWindow 
         quit = 1
         
   EndSelect
Until quit = 1

End
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Beautiful! I vote for it.
Last edited by netmaestro on Tue Feb 21, 2006 11:56 am, edited 2 times in total.
BERESHEIT
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Wow!
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

cross-platform ?

Post by USCode »

Anyway to make this cross-platform?
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Very nice, useful!
Intrigued - Registered PureBasic, lifetime updates user
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: cross-platform ?

Post by Guimauve »

USCode wrote:Anyway to make this cross-platform?
I don't know if a similar gadget exist in Linux API. If not, this gadget and internal control must built from the scratch.

Regards

Guimauve
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

very nice gadget! (never seen this kind before... 10 points!)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post by Guimauve »

Hello,

Sorry to re-up and old topic but ... Since PB 4.30 my RebarGadget lib need to be modified. So there is the new code.

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : RebarGadget() - InsertReBarItem()
; File : RebarGadget.pbi
; File Version : 1.0.1
; Programmation : Working Good
; Programmed by : Guimauve
; Date : 06-11-2008
; Last Update : 06-11-2008
; Coded for PureBasic V4.30 BETA 4
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ProcedureDLL InsertReBarItem(hWndRebar, RebarItemID, Text.s, BarWidth, Index, BkColor, FgColor)
  
  rbBand.REBARBANDINFO
  
  rbBand\cbSize = SizeOf(REBARBANDINFO)
  rbBand\fMask  = #RBBIM_STYLE | #RBBIM_CHILD | #RBBIM_CHILDSIZE | #RBBIM_TEXT | #RBBIM_HEADERSIZE | #RBBIM_COLORS
  rbBand\fStyle = #RBBS_CHILDEDGE
  
  rbBand\clrBack    = BkColor
  rbBand\clrFore    = FgColor
  rbBand\lpText     = @Text
  rbBand\hwndChild  = ContainerGadget(RebarItemID, 0, 0, 0, 0);<
  rbBand\cyMinChild = BarWidth
  rbBand\cxHeader   = 30
  rbBand\cx         = BarWidth
  
  SendMessage_(hWndRebar, #RB_INSERTBAND, Index, @rbBand)
  
EndProcedure
  
ProcedureDLL RebarGadget(GadgetID, X, Y, Width, Height)
  
  hMainCont = ContainerGadget(GadgetID, X, Y, Width, Height, #PB_Container_Raised);<
  
  icex.INITCOMMONCONTROLSEX
  
  icex\dwSize = SizeOf(INITCOMMONCONTROLSEX);
  icex\dwICC   = #ICC_COOL_CLASSES|#ICC_BAR_CLASSES
  InitCommonControlsEx_(@icex);
  
  hwndRB = CreateWindowEx_(#WS_EX_TOOLWINDOW, "ReBarWindow32", #Null, #WS_CHILD|#WS_VISIBLE|#WS_CLIPSIBLINGS| $00000080 , 0,0,0,0, hMainCont, GadgetID, 0, #Null);
  
  LibHandle = OpenLibrary(#PB_Any, "UxTheme.dll")
  
  If LibHandle
    FunctionHandle = GetFunction(LibHandle, "SetWindowTheme")
    CallFunctionFast(FunctionHandle, hwndRB,"","")
    CloseLibrary(LibHandle)
  EndIf
  
  ProcedureReturn hwndRB
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
By the way I ask one more time again to have this gadget fully supported as any other gadget we already have.

Best regards
Guimauve
Last edited by Guimauve on Thu Nov 06, 2008 7:10 pm, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Very nice! 8)

You need to adjust the GetProcAddress_() though for Unicode apps because there is no Unicode equivalent of this function. Use the PB library commands instead as these will sort out the Unicode / Ascii conversions automatically.
I may look like a mule, but I'm not a complete ass.
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post by Guimauve »

srod wrote:Very nice! 8)

You need to adjust the GetProcAddress_() though for Unicode apps because there is no Unicode equivalent of this function. Use the PB library commands instead as these will sort out the Unicode / Ascii conversions automatically.
Done !

Regards
Guimauve
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

yes, rebars are nice and would be a nice addition.

Your's is very nice indeed! :D

cheers
Post Reply