|
Problem This is a series of examples to show you how to change tab orders in PHP-GTK2.
Let's continue to extend Example 2.
Suppose now you would like to change the tab order to start from the bottom right button, followed by bottom left button, and then traverse upwards, as shown below:

Solution Here are the rules to use GtkContainer::set_focus_chain() again:.
- The method takes only one argument - an array of GtkWidgets.
- All the widgets in the array must be direct descedents of the container.
- It's not necessary to define the tab orders of all levels.
Note: If you tried to use the previous example and do something like:
$vbox->set_focus_chain(array(
$button['right'][3], $button['left'][3],
$button['right'][2], $button['left'][2]));
It won't work because of Rule #2 above.
To be able to set the tab orders so that they traverse horizontally, you have to rework the buttons so that they are packed in horizontal hboxes. Once you have the hboxes in place, you then apply GtkContainer::set_focus_chain():
- To change the tab order to start from bottom hbox to top hbox.
- Within each hbox, change the tab order to start from the righ button first, then the left button.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(480, 240); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set tab order - Example 4"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0.5, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0); $alignment = new GtkAlignment(0.5, 0.5, 0, 0); $alignment->add($label = new GtkLabel( "The tab orders are as indicated on the button.\n". "It starts from the bottom right button and traverse ". "horizontally upwards")); $label->set_justify(Gtk::JUSTIFY_CENTER); $vbox->pack_start($alignment); $vbox->pack_start(new GtkLabel(), 0);
$button = array(); $hbox = array(); for ($row=0; $row<4; ++$row) { setup_buttons($vbox, $row); }
// set the tab order
//$vbox->set_focus_chain(array( //does not work
// $button['right'][3], $button['left'][3], //does not work
// $button['right'][2], $button['left'][2])); //does not work
$vbox->set_focus_chain(array( $hbox[3], $hbox[2], $hbox[1], $hbox[0]));
for ($row=0; $row<4; ++$row) { $hbox[$row]->set_focus_chain(array( $button['right'][$row], $button['left'][$row])); }
$window->show_all(); Gtk::main();
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Set the tab order to start from the bottom hbox to the top hbox.
- Set the tab order to start from the right button, then left button. Note that you have to do this for each of the hbox.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |