Problem
This example is similar to that of How to create detachable toolbar?
The only difference is that in this example, the detachable toolbar is a vertical one with the handle bar on top as shown below:
Solution
- Use GtkToolbar::set_orientation( Gtk::ORIENTATION_VERTICAL) to display a vertical toolbar.
- Use GtkHandleBox::set_handle_position( Gtk::POS_TOP) to set the handle bar on top.
Sample Code
1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 18 19 20 21 23 24 25 26 27 28 29 30 31 33 34 36 37 38 40 42 43 44 46 47 48 49 50 51 53 54 55 56 57 60 61 62 63 64 65 66 68 70 71 72 | <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(400, 360); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox()); $vbox->pack_start($hbox = new GtkHBox(), 0); // define menu definition $toolbar_definition = array('New', 'Open', 'Save', 'Cut', 'Copy', 'Paste', 'Undo','Redo'); setup_toolbar($hbox, $toolbar_definition); // display title $title = new GtkLabel("Create vertical detachable toolbar\n". " with handle bar on top"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $hbox->pack_start($vbox2 = new GtkVBox()); $vbox2->pack_start($title); $vbox2->pack_start(new GtkLabel('')); $window->show_all(); Gtk::main(); // setup toolbar function setup_toolbar($hbox, $toolbar_definition) { $toolbar = new GtkToolBar(); $toolbar->set_orientation(Gtk::ORIENTATION_VERTICAL); // note 1 $handlebox = new GtkHandleBox(); $handlebox->add($toolbar); $handlebox->set_handle_position(Gtk::POS_TOP); // note 2 $toolbar->set_size_request(34, 340); $toolbar->set_property('icon-size', Gtk::ICON_SIZE_MENU); $hbox->pack_start($handlebox, 0); foreach($toolbar_definition as $item) { if ($item=='<hr>') { $toolbar->insert(new GtkSeparatorToolItem(), -1); } else { $stock_image_name = 'Gtk::STOCK_'.strtoupper($item); if (defined($stock_image_name)) { $toolbar_item = GtkToolButton::new_from_stock( constant($stock_image_name)); $toolbar_item->set_label(null); $toolbar->insert($toolbar_item, -1); $toolbar_item->connect('clicked', 'on_toolbar_button', $item); } } } } // process toolbar function on_toolbar_button($button, $item) { echo "toolbar clicked: $item\n"; } ?> |
Output
As shown above.Explanation
This example make use of the code in How to create detachable toolbar?.
What's new here:
- Display the toolbar vertically.
- Place the handle bar on top.
Read more...