PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 239: How to change tab order - Example 2?
Written by kksou   
Wednesday, 23 May 2007
Problem

This is a series of examples to show you how to change tab orders in PHP-GTK2.

Let's continue to extend Example 1.

Suppose now you would like to change the tab order to start from the bottom right button as shown below:

How to change tab order - Example 2?


Solution

Here are the rules to use GtkContainer::set_focus_chain() again:.

  1. The method takes only one argument - an array of GtkWidgets.
  2. All the widgets in the array must be direct descedents of the container.
  3. It's not necessary to define the tab orders of all levels.

In this example, we need to use GtkContainer::set_focus_chain() two times:

  • To change the tab order to start from the right column.
  • To change the tab order within the right column to start from the bottom right 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   
<?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 2");
$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);
$vbox->pack_start(new GtkLabel("Note that the tab order ".
"now start from the bottom right button"), 0);
$vbox->pack_start(new GtkLabel(), 0);

$hbox = new GtkHBox();
$vbox->pack_start($hbox);
$hbox->pack_start($left_buttons = new GtkVBox());
$hbox->pack_start($right_buttons = new GtkVBox());

$button = array();
setup_buttons($left_buttons, 'left');
setup_buttons($right_buttons, 'right');

// set the tab order
$hbox->set_focus_chain(array($right_buttons, $left_buttons)); // note 1
$right_buttons->set_focus_chain(array( // note 2
    $button['right'][3], $button['right'][2], 
    $button['right'][1], $button['right'][0])); 

$window->show_all();
  • 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
  1. Set the tab order to start from the right column.
  2. Set the tab order to start from the button3, then button2, button1 and button0. As you can see, you can set the tab order in whatever orders you desire.

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.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2008. kksou.com. All Rights Reserved