#!/usr/bin/perl -w use Gtk; use strict; set_locale Gtk; init Gtk; my $false = 0; my $true = 1; my @gtk_xpm = ( '32 39 5 1', '. c none', '+ c black', '@ c #3070E0', '# c #F05050', '$ c #35E035', '................+...............', '..............+++++.............', '............+++++@@++...........', '..........+++++@@@@@@++.........', '........++++@@@@@@@@@@++........', '......++++@@++++++++@@@++.......', '.....+++@@@+++++++++++@@@++.....', '...+++@@@@+++@@@@@@++++@@@@+....', '..+++@@@@+++@@@@@@@@+++@@@@@++..', '.++@@@@@@+++@@@@@@@@@@@@@@@@@@++', '.+#+@@@@@@++@@@@+++@@@@@@@@@@@@+', '.+##++@@@@+++@@@+++++@@@@@@@@$@.', '.+###++@@@@+++@@@+++@@@@@++$$$@.', '.+####+++@@@+++++++@@@@@+@$$$$@.', '.+#####+++@@@@+++@@@@++@$$$$$$+.', '.+######++++@@@@@@@++@$$$$$$$$+.', '.+#######+##+@@@@+++$$$$$$@@$$+.', '.+###+++##+##+@@++@$$$$$$++$$$+.', '.+###++++##+##+@@$$$$$$$@+@$$@+.', '.+###++++++#+++@$$@+@$$@++$$$@+.', '.+####+++++++#++$$@+@$$++$$$$+..', '.++####++++++#++$$@+@$++@$$$$+..', '.+#####+++++##++$$++@+++$$$$$+..', '.++####+++##+#++$$+++++@$$$$$+..', '.++####+++####++$$++++++@$$$@+..', '.+#####++#####++$$+++@++++@$@+..', '.+#####++#####++$$++@$$@+++$@@..', '.++####++#####++$$++$$$$$+@$@++.', '.++####++#####++$$++$$$$$$$$+++.', '.+++####+#####++$$++$$$$$$$@+++.', '..+++#########+@$$+@$$$$$$+++...', '...+++########+@$$$$$$$$@+++....', '.....+++######+@$$$$$$$+++......', '......+++#####+@$$$$$@++........', '.......+++####+@$$$$+++.........', '.........++###+$$$@++...........', '..........++##+$@+++............', '...........+++++++..............', '.............++++...............' ); my $dialog; my $handlebox; my $toolbar; my $icon; my $mask; my $iconw; my $close_button; my $icon_button; my $text_button; my $both_button; my $tooltips_button; my $entry; $dialog = new Gtk::Dialog(); $dialog->set_title( "Toolbar Example" ); $dialog->set_usize( 600, 300 ); $dialog->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } ); # we need to realize the window because we use pixmaps for # items on the toolbar in the context of it $dialog->realize(); # To make it nice we'll put the toolbar into the handle box, so # that it can be detached from the main window. A handle box is # just another box that can be used to pack widgets into. The # difference is that it can be detached from a parent window. This # is often used for a detachable toolbar. $handlebox = new Gtk::HandleBox(); $dialog->vbox->pack_start( $handlebox, $false, $false, 5 ); # toolbar will be horizontal, with both icons and text, and with # 5 pixel spaces between items and finally, we'll also put it into # our handlebox $toolbar = new Gtk::Toolbar( 'horizontal', 'both' ); $toolbar->border_width( 5 ); $toolbar->set_space_size( 5 ); $handlebox->add( $toolbar ); # now we create icon with mask: we'll reuse it to create # icon widgets for toolbar items ( $icon, $mask ) = Gtk::Gdk::Pixmap->create_from_xpm_d( $dialog->window, $dialog->style->white, @gtk_xpm ); # our first item is button $iconw = new Gtk::Pixmap( $icon, $mask ); $close_button = $toolbar->append_item( "Close", "Close this app", "Private", $iconw ); $close_button->signal_connect( "clicked", sub { Gtk->exit( 0 ); } ); $toolbar->append_space(); # now, let's make our radio buttons group... $iconw = new Gtk::Pixmap( $icon, $mask ); $icon_button = $toolbar->append_element( 'radiobutton', new Gtk::RadioButton(), "Icon", "Only icons in toolbar", "Private", $iconw ); $icon_button->signal_connect( "clicked", \&radio_event, $toolbar ); $toolbar->append_space(); # following radio buttons refer to previous ones $iconw = new Gtk::Pixmap( $icon, $mask ); $text_button = $toolbar->append_element( 'radiobutton', $icon_button, "Text", "Only texts in toolbar", "Private", $iconw ); $text_button->signal_connect( "toggled", \&radio_event, $toolbar ); $toolbar->append_space(); $iconw = new Gtk::Pixmap( $icon, $mask ); $both_button = $toolbar->append_element( 'radiobutton', $text_button, "Both", "Icons and text is toolbar", "Private", $iconw ); $both_button->signal_connect( "toggled", \&radio_event, $toolbar ); $toolbar->append_space(); $both_button->set_active( $true ); # following radio buttons refer to previous ones $iconw = new Gtk::Pixmap( $icon, $mask ); $tooltips_button = $toolbar->append_element( 'togglebutton', "", "Tooltips", "Toolbar with or without tips", "Private", $iconw ); $tooltips_button->signal_connect( "toggled", \&toggle_event, $toolbar ); $toolbar->append_space(); $tooltips_button->set_active( $true ); # to pack a widget into toolbar, we only have to # create it and append it with an appropriate tooltip $entry = new Gtk::Entry(); $toolbar->append_widget( $entry, "This is just an entry", "Private" ); # well, it isn't created within thetoolbar, so we must still show it $entry->show(); $toolbar->show(); $handlebox->show(); $dialog->show(); main Gtk; exit( 0 ); ### Subroutines # when one of the buttons is toggled, we just # check which one is active and set the style of the toolbar # accordingly sub radio_event { my ( $widget, $toolbar ) = @_; if ( $text_button->active ) { $toolbar->set_style( 'text' ); } elsif ( $icon_button->active ) { $toolbar->set_style( 'icons' ); } elsif ( $both_button->active ) { $toolbar->set_style( 'both' ); } } # check given toggle button and enable/disable tooltips sub toggle_event { my ( $widget, $toolbar ) = @_; $toolbar->set_tooltips( $widget->active ); } # END EXAMPLE PROGRAM