Linux Lib: Toolbar_pro - Create a professional Toolbar

Developed or developing a new product in PureBasic? Tell the world about it.
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Linux Lib: Toolbar_pro - Create a professional Toolbar

Post by walker »

Some month ago I'd released a includefile for creation of a toolbar like the one you can crate on Windows with Danilo's toolbar_pro and some weeks ago a first version of the toolbar_pro.

Now I'd created 2 small user libs containing the following commands :

toolbar_pro:
- CreateTB (tbar.l, hwnd.l, type.l, orientation.l)
Parameters:
tbar.l = a number of your toolbar (i.e 0 or 1 or 2 ...)
hwnd.l= the handle of the window where the Toolbar is created
type.l = one of the following: #GTK_TOOLBAR_TEXT to show text only #GTK_TOOLBAR_BOTH for both, text and Icon , #GTK_TOOLBAR_ICONS for icons only
orientation.l = 0 = horizontal; 1 = vertical

- AddTBbutton(*tbar.l, tb_stock_button.s, Callback_Proc.l, txt.s, img.s)
Parameters:
*tbar.l= the toolbar returned by CreateTB
tb_stockbutton.s= a gtk stock image (can be empty string)
Callback_Proc= Pointer to a Procedure (that MUST exist) to handle the action when the toolbarbutton is pressed
txt.s= name the button as you wish (overrides the text from stock image) can be empty string
img.s= use your own image for the button; can be empty string...

- SetTBbuttonTooltip(*tb_button, Tooltip.s)
Parameters:
*tb_button = the button returned by AddTBbutton
Tooltip.s = the tooltip text

- AddTBseparator(*tbar, visible.l, stretch.l)
Parameters:
tbar = the toolbar returned by CreateTB
visible = #true or #false
stretch = #true or #false

- NEW 20.12.2007
- AddTBmenubutton(*tbar.l, tb_stock_button.s, Callback_Proc.l, txt.s, img.s)
Creates a ToolbarButton with Dropdown menu
Parameters:
*tbar = the toolbar returned by CreateTB
tb_stockbutton.s= a gtk stock image (can be empty string)
Callback_Proc= Pointer to a Procedure (that MUST exist) to handle the action when the toolbarbutton is pressed
txt.s= name the button as you wish (overrides the text from stock image) can be empty string
img.s= use your own image for the button; can be empty string...
Returns: the handle of the newly created ToolMenuButton

- AddTBmenuButtonEntry(*menutoolbutton,Callback_proc.l, entry.s);
add a menu entry to a MenuToolButton
Parameters:
*menutoolbutton = the handle of the ToolMenuButton returned by AddTBmenubutton()
Callback_Proc= Pointer to a Procedure (that MUST exist) to handle the action when the entry is selected
entry.s = the Text for the enty shown in the dropdown list
Returns: the handle for the added entry

- SetTBmenubuttonTooltip(*menutoolbutton,Tooltip.s)
Adds a Tooltip to the given Toolbarbutton's dropdown arrow
Parameters:
*menutoolbutton = the handle of the ToolMenuButton returned by AddTBmenubutton()
Tooltip.s = the tooltip text
Returns: nothing

Download see below

The second lib handels a ComboBox to be used in a Toolbar (I decided to divide this in 2 parts as a toobar does not necessary contain a combobox)

toolbar_pro_combobox
- AddTBcomboBox(*tbar, Callback_Proc.l ,xsize, ysize, list_of_entrys.s)
Parameters
*tbar = the retuned Toolbar from CreateTB()
Callback_Proc = a pointer to a procedure to handle the action when the combobox is used
xsize = the length of the combobox
ysize = the height of the combobox
list_of_entrys = initial content of the combobox; comma seperated string

- GetTBcomboBoxEntryNr(*box)
Parameters
*box = the combobox returned by AddTBcombobox()
returns the actual selected entry or -1 if none

- ClearTBcomboBox(*box)
Parameters
*box = the combobox from which should be clreared

- RemoveTBcomboBoxEntry(*box, entry_nr)
Parameters
*box = the combobox from which a entry should be removed
*entry_nr = the number of the entry

- AddTBcomboBoxEntry(*box, entry.s)
Parameters
*box = the combobox to which a entry should be added
*entry = string to be added

- GetTBcomboBoxEntryName (*box)
Parameters
*box = the combobox from where you want to retrieve the name of the current entry
returns a string containing the text of the selected entry

- NEW 20.12.2007
- SetTBcomboEntryActive(*box,entry_nr.l)
activates the entry number in the given Combobox (this causes an "changed" event)
Parameters:
*box = the combobox to which a entry should be changed
entry_nr.l = the entry number which should be shown (0 = first entry)
Returns: nothing

Download see below

[Edit]19.02.2007 added the description for the combobox commands[/Edit]
[Edit]13.08.2007 added the parameter orientation.l to the CreateTB command [/Edit]
[EDIT]20.12.2007
- added a TollbarMenubutton (3 Commands)
- a new command for the Combobox to select an entry
- added a Textfile with the description of all commands
- added a small demo
- download - now all files are in a single archive
[/Edit]

DOWNLOAD:
http://home.arcor.de/x-linux/pure/toolb ... ar_pro.zip
Last edited by walker on Thu Dec 20, 2007 9:02 pm, edited 4 times in total.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Cool, this will be handy
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

Right, Linux definitely needs a better support, thanks :)
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

added the descriptions of the commands for the toolbar-combobox
see first post
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Walker,

exist a possibility to set the toolbar vertical ?

or use a function similar at the toolbar from pbosl like

SetTBparent(#tb,container1)

best
jpd
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

yes it is... 8) added the parameter orientation to the command CreateTB()
Description and download see first post.

for your second question... you can use gtk_widget_set_parent(gtk_widget, *parent) / gtk_widget_set_parent_window(*gtk_widget,*parent_window) to achive this ...

the id returned by CreateTB can be used directly, the *parent/*parent_window must be the gadgetid/windowid of the parent gadget/window (not tested but shoud work)
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Walker,

thanks for adding the new parameter ,

but the result effect is strange,
If you set the parameter =1 (vertical)

the result is:
the first entry is a direction arrow ,If you clicking on this then you see the toolbarmenu,

my idea was more a list of button on vertical position directly.

For the other question setparent...

If add the line

gtk_widget_set_parent_(*tbar,*panel);,*hwnd)
Or
gtk_widget_set_parent_window_(*tbar, *panel)

Or switched gtk_widget_set_parent_window_(*panel, *tbarl)

nothing will happen!

Many Thanks for your help
jpd
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

... yes.. it looks like there is an issue with the Toolbar Fred uses (i use the PB CreateToolbar() command to get a toolbar that is attached to a PB created window .. if I use gtk_toolbar_new() and a PB created window, I can't get it to work...)
try

Code: Select all

gtk_toolbar_set_show_arrow_(*toolbar,#False)
after creating the toolbar... the result is strange either.. but all items of the toolbar are shown....

I'll report this in the bugs section....

The answer to the second question... the toolbar acts like a menu... so I guess it can be attached to a window only...
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

cool!

with this line the arrow disappear ,

the only problem is that the toolbar width is same as the windowwidth ..

I will try to create a second window on a fix position of the main window
without title_bar and position my toolbar on this other window

then is a parent given!! I hope so :)

Best
jpd
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Walker,

here a little example that works as needed :)

the only problem is the resize speed of the child window,

existing a methode that faster as the methode used here on this code?

thanks
jpd

Code: Select all

Enumeration
  #win
  #panel
  #tbar
  #win1
  #button
EndEnumeration

  

ProcedureCDLL meineproc()

Debug "Purebasic is cool on Linux"
EndProcedure

ProcedureCDLL meineproc1()
;your code here
EndProcedure

ProcedureCDLL meineproc2()
;your code here
End
EndProcedure

*hwnd=OpenWindow(#win,0,0,400,300,"Toolbar",#PB_Window_ScreenCentered)
*hwnd2=OpenWindow(#win1,0,0,100,200,"Toolbar2",#PB_Window_ScreenCentered|#PB_Window_BorderLess ,*hwnd)


If CreateGadgetList(*hwnd2)   
  *tool=CreateTB(#tbar,*hwnd2,#GTK_TOOLBAR_BOTH,1);one of #GTK_TOOLBAR_ICONS, #GTK_TOOLBAR_TEXT or #GTK_TOOLBAR_BOTH
  gtk_toolbar_set_show_arrow_(*tool,#False)
 
  AddTBseparator(*tool,#False,#False)
  
    *btn=AddTBbutton(*tool,"gtk-new",@meineproc(),"test",""); a standard button with standard image and text - leave the last 2 parameter empty
    SetTBbuttonTooltip(*btn,"Demo tooltip")
   
    AddTBseparator(*tool,#False,#False)
   
    *btn1=AddTBbutton(*tool,"gtk-open",@meineproc1(),"",""); a standard button with standard image and text
    SetTBbuttonTooltip(*btn1,"another tooltip")
   
    AddTBseparator(*tool,#False,#False)
   
    *btn2=AddTBbutton(*tool,"gtk-delete",@meineproc1(),"",""); a standard button with standard image and text
    SetTBbuttonTooltip(*btn2,"delete something.....")
     
    AddTBseparator(*tool,#False,#False);if #true, the button(s) after this will be on the most right side of the window
   
    *btn4=AddTBbutton(*tool,"gtk-quit",@meineproc2(),"MyExit",""); a button with standard image and own text - leave only he last parameter empty
    SetTBbuttonTooltip(*btn4,"Exit")
   
EndIf


Repeat
    ev = WaitWindowEvent()
    
    Select ev
      ;Case #PB_Event_Gadget
      Case #PB_Event_MoveWindow
        ResizeWindow(#win1,WindowX(#win)+20,WindowY(#win)+30,100,250)
    EndSelect 
Until ev=#PB_Event_CloseWindow
End
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

yep.. that works... may you have seen that I'd reported the toolbar issue as bug in the bug section... would be nice to have a "native vertical" toolbar :wink: (it is working if you use no PB window... here an example:
http://home.arcor.de/x-linux/pure/toolbartest_src.zip
(extract all files in a directory and comment the first Xinclude in the main.pb .. i guess you don't have this file at this place :wink:

don't know how to speed up your example....(faster cpu?)
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi walker,

nice job.

is a really "advanced piece of code" for me! :shock:

I think that this can help me to learning more and more this big unknow linux world. :)


don't know how to speed up your example....(faster cpu?)
I will increase the memory in the Linux VM.

Thanks
jpd
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

well... if you're interested.. this piece of code is generate by my little app Glade2PB .. you only need Galde installed to design your application and Glade2PB to transform the code to PB-sourcecode... (i'd written this little proggie because of the lack of a visual designer on linux)

Download Glade2PB: http://home.arcor.de/x-linux/pure/g2pb
A little tutorial: http://home.arcor.de/x-linux/pure/glade_tut.sxw

original threads regarding Glade2PB:
http://www.purebasic.fr/english/viewtop ... t=glade2pb
and
http://www.purebasic.fr/english/viewtop ... t=glade2pb

Glade2PB isn't finished yet (v0.62) if you encounter misstranslated parts or missing constants/commands... tell me and I'll add them...
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Walker,

Glade is a little bit strange to use but after a couple hours of test is the result impressiv!

and g2pb is really easy.

thanks
jpd
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

a little strange... yes.. but worth to learn (if you don't need a fixed container, all resizing of widgets is done by gtk !) and very powerful too!!

Try the following code (change the path to the lib and to a .glade file on your PC):

Code: Select all


gtk_init_(0,0)
If OpenLibrary(0, "/usr/lib/libglade-2.0.so.0")
    glade_xml_new=GetFunction(0,"glade_xml_new")
    glade_xml_get_widget=GetFunction(0,"glade_xml_get_widget")
    glade_init=GetFunction(0,"glade_init")
    glade_xml_signal_autoconnect=GetFunction(0,"glade_xml_signal_autoconnect")

    main_window =CallCFunctionFast(glade_xml_new,"/home/xxx/testgui.glade", "window1", "" ) 
    CallCFunctionFast(glade_xml_signal_autoconnect,main_window)  
    gtk_main_()
EndIf
and you have no line of code for the gui in your app.... it's created at runtime
Post Reply