Sample Code 486: How to move tabs between two notebooks with drag and drop? |
|
Written by kksou
|
|
Tuesday, 29 April 2008 |
|
Problem You have set up two GtkNotebooks.
This example shows you how you can move a tab (together with its contents) from one notebook to another using drag and drop as shown below:
Before:

After:

Solution
- Use GtkNotebook::set_group_id() to assign a
group_id to both the notebooks. Make sure both have the sample group_id.
- Use GtkNotebook::set_tab_detachable() to allow moving of tabs between differnet notebooks that have the same
group_id.
Important Note: This only works for PHP-GTK2 compliled with gtk+ v2.10 and above. If you are using an older version, for linux, you may follow the step-by-step instructions to recompile php-gtk2 with gtk+ v2.10. For windows, please refer to How to install php gtk2 on windows? You may also want to take a look here to see some of the new exciting PHP-GTK2 Functionalities.
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(400, 480); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
$notebook1 = setup_notebook($vbox, 1); $vbox->pack_start(new Gtklabel(), 0); $notebook2 = setup_notebook($vbox, 2);
$window->show_all(); Gtk::main();
function setup_notebook($vbox, $id) { // setup notebook
$notebook = new GtkNotebook(); $vbox->pack_start($notebook);
// add two tabs of GtkLabel
add_new_tab($notebook, new GtkLabel('Notebook 1'), "Label #$id.1"); add_new_tab($notebook, new GtkLabel('Notebook 2'), "Label #$id.2");
// add a thrid tab of GtkTextView
$buffer = new GtkTextBuffer(); $view = new GtkTextView(); $view->set_buffer($buffer); $view->set_wrap_mode(Gtk::WRAP_WORD); add_new_tab($notebook, $view, "TextView $id");
$notebook->set_group_id(123); // note 1
return $notebook; }
// add new tab
|
- 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 The code above is based on the code from How to display a popup menu for GtkNotebook tab - Part 1?
What's new here:
- Assign a
group_id to the notebook. Here we assign '123' to both the notebooks.
- Make the tabs detachable!
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. |
|