[PB-Linux 3.94] Proffessional Toolbar (like TBPro on WIN)

Linux specific forum
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

[PB-Linux 3.94] Proffessional Toolbar (like TBPro on WIN)

Post by walker »

Hi,

here is a simple way to use the GTK-Toolbar in your projects which looks quite more proffessional than the build-in toolbar (and the text of the buttons will be automatically translated into the users language - if installed) 8)
The code is commented where necessary (hope so).

Code: Select all

;HowTo include a professional looking toolbar with PB3.94
;using the gtk2 Toolbar
;2006 by walker
;

;to access them everywhere
Global *toolbar1.gtkwidget
Global *toolbutton1.gtkwidget
Global *toolbutton2.gtkwidget
Global *toolbutton3.gtkwidget
Global *toolbutton4.gtkwidget
Global *toolbutton5.gtkwidget
Global *toolbutton6.gtkwidget

;constants
Enumeration 
    #toolbar_0
EndEnumeration

ProcedureCDLL on_new_toolbutton_clicked (toolbutton,user_data)
;Your code here

EndProcedure

ProcedureCDLL on_open_toolbutton_clicked (toolbutton,user_data)
;Your code here

EndProcedure

ProcedureCDLL on_save_toolbutton_clicked (toolbutton,user_data)
;Your code here

EndProcedure

ProcedureCDLL on_preferences_toolbutton_clicked (toolbutton,user_data)
;Your code here

EndProcedure

ProcedureCDLL on_info_toolbutton_clicked (toolbutton,user_data)
;Your code here

EndProcedure

ProcedureCDLL on_exit_toolbutton_clicked (toolbutton,user_data)
;Your code here
    End;for example
EndProcedure

Procedure Open_Window_0()
    If OpenWindow(0,0,0,500,350,#PB_Window_ScreenCentered,"GTK2-Toolbar")
        If CreateGadgetList(WindowID())
        *toolbar1= CreateToolBar(#toolbar_0,WindowID())
         gtk_widget_show_(*toolbar1);
         gtk_toolbar_set_style_(*toolbar1, #GTK_TOOLBAR_ICONS); use #GTK_TOOLBAR_TEXT to show text only and  #GTK_TOOLBAR_BOTH for both, text and Icon
         tmp_toolbar_icon_size = gtk_toolbar_get_icon_size_(*toolbar1);
          
        *toolbutton1 = gtk_tool_button_new_from_stock_("gtk-new");
        gtk_widget_show_(*toolbutton1);
        gtk_container_add_(*toolbar1, *toolbutton1);
        
        *toolbutton2 = gtk_tool_button_new_from_stock_("gtk-open");
        gtk_widget_show_(*toolbutton2);
        gtk_container_add_(*toolbar1, *toolbutton2);
        
        *toolbutton3 = gtk_tool_button_new_from_stock_("gtk-save-as");
        gtk_widget_show_(*toolbutton3);
        gtk_container_add_(*toolbar1, *toolbutton3);
        
        *separatortoolitem1 = gtk_separator_tool_item_new_();
        gtk_widget_show_(*separatortoolitem1);
        gtk_container_add_(*toolbar1, *separatortoolitem1);
        
        *toolbutton4 = gtk_tool_button_new_from_stock_("gtk-preferences");
        gtk_widget_show_(*toolbutton4);
        gtk_container_add_(*toolbar1, *toolbutton4);
        
        *toolbutton5 = gtk_tool_button_new_from_stock_("gtk-info");
        gtk_widget_show_(*toolbutton5);
        gtk_container_add_(*toolbar1, *toolbutton5);
        
        *separatortoolitem3 = gtk_separator_tool_item_new_();
        gtk_widget_show_(*separatortoolitem3);
        gtk_tool_item_set_expand_(*separatortoolitem3, #True);to move the last button to the right side of the window, otherwise comment this line
        gtk_container_add_(*toolbar1, *separatortoolitem3);
        
        *toolbutton6 = gtk_tool_button_new_from_stock_("gtk-quit");
        gtk_widget_show_(*toolbutton6);
        gtk_container_add_(*toolbar1, *toolbutton6);
        
        ;add any pb gadgets here - you can use 0 as y-parameter - the gadget will properly shown below the toolbar
        
        
        ;close the gadgetlist properly
        CloseGadgetList()
        ;connect each button of the toolbar to a procedure
        g_signal_connect_object_( *toolbutton1, "clicked",@on_new_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton2, "clicked",@on_open_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton3, "clicked",@on_save_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton4, "clicked",@on_preferences_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton5, "clicked",@on_info_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton6, "clicked",@on_exit_toolbutton_clicked(),*pointer,0)
      EndIf
  EndIf
  EndProcedure
  ;the gtk-events of the toolbar doesn't appear in the wait_window_event() (maybe tey do, but aren't reported by WaitWindowEvent()
  ;if you have a menu entry with the same action as a toolbarbutton, simply call the ProcedureCDLL when the MenuID is fired
  
Open_Window_0()
Repeat
event=WaitWindowEvent()
Until event = #PB_Event_CloseWindow
End  
 
The Stock-Items on GTK2 are listed on http://developer.gnome.org/doc/API/2.0/ ... Items.html
if you need other ones.

Compile with GTK2 as subsystem!

Questions, comments etc. are appreciated
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Cool, maybe you could make a TailBite PB userlibrary of it?
bye,
Daniel
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

Hi,

Is there a Linux-Version of Tailbite? (never used it before.... :shock: )
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

walker wrote:Hi,

Is there a Linux-Version of Tailbite? (never used it before.... :shock: )
Yes, look into the TB topic, I wrote it, also the sourcecode is somewhere IIRC.
bye,
Daniel
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Looks great here
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

@Dark Dragon:
Found the Tailbite for Linux... but it isn't working.. this version don't know anything about gtk2.... :cry: so it is not usable...
I also found the Thread where you complain the lost of the tailbite-source for linux....

So I tried to make the Userlib by hand.. but I think, Userlibs are not working, when using ASM. Maybe I'm wrong, but i tried several hours with no result.
The Lib is compiled and the little helb (from the desc-file) is shown in the statusbar of the IDE... but when i try to compile a short demo....I'll always get these errors:

Image

I'd searched everywhere (this forum, german forum, old forum) but found no solution.
Does anybody get a working userlib (ASM) on Linux?

Any hint/help is appreciated....
Post Reply