1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
3 * GTK - The GIMP Toolkit
4 * Copyright (C) 2006 Carlos Garnacho Parro <carlosg@gnome.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 static gpointer GROUP_A = "GROUP_A";
26 static gpointer GROUP_B = "GROUP_B";
60 static const GtkTargetEntry button_targets[] = {
61 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
65 window_creation_function (GtkNotebook *source_notebook,
71 GtkWidget *window, *notebook;
73 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
74 notebook = gtk_notebook_new ();
75 g_signal_connect (notebook, "create-window",
76 G_CALLBACK (window_creation_function), NULL);
78 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook),
79 gtk_notebook_get_group_name (source_notebook));
81 gtk_container_add (GTK_CONTAINER (window), notebook);
83 gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
84 gtk_window_move (GTK_WINDOW (window), x, y);
85 gtk_widget_show_all (window);
87 return GTK_NOTEBOOK (notebook);
91 on_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data)
93 g_print ("page %d reordered\n", page_num);
97 on_notebook_drag_begin (GtkWidget *widget,
98 GdkDragContext *context,
104 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
108 pixbuf = gtk_widget_render_icon_pixbuf (widget,
109 (page_num % 2) ? GTK_STOCK_HELP : GTK_STOCK_STOP,
112 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
113 g_object_unref (pixbuf);
118 on_button_drag_data_received (GtkWidget *widget,
119 GdkDragContext *context,
122 GtkSelectionData *data,
127 GtkWidget *source, *tab_label;
130 source = gtk_drag_get_source_widget (context);
131 child = (void*) gtk_selection_data_get_data (data);
133 tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
134 g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
136 gtk_container_remove (GTK_CONTAINER (source), *child);
140 create_notebook (gchar **labels,
144 GtkWidget *notebook, *title, *page;
147 notebook = gtk_notebook_new ();
148 g_signal_connect (notebook, "create-window",
149 G_CALLBACK (window_creation_function), NULL);
151 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
152 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
153 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
154 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
158 page = gtk_entry_new ();
159 gtk_entry_set_text (GTK_ENTRY (page), *labels);
161 title = gtk_label_new (*labels);
163 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
164 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
165 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
171 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
172 G_CALLBACK (on_page_reordered), NULL);
173 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
174 G_CALLBACK (on_notebook_drag_begin), NULL);
179 create_notebook_with_notebooks (gchar **labels,
183 GtkWidget *notebook, *title, *page;
186 notebook = gtk_notebook_new ();
187 g_signal_connect (notebook, "create-window",
188 G_CALLBACK (window_creation_function), NULL);
190 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
191 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
192 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
193 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
197 page = create_notebook (labels, group, pos);
198 gtk_notebook_popup_enable (GTK_NOTEBOOK (page));
200 title = gtk_label_new (*labels);
202 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
203 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
204 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
210 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
211 G_CALLBACK (on_page_reordered), NULL);
212 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
213 G_CALLBACK (on_notebook_drag_begin), NULL);
218 create_trash_button (void)
222 button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
224 gtk_drag_dest_set (button,
225 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
227 G_N_ELEMENTS (button_targets),
230 g_signal_connect_after (G_OBJECT (button), "drag-data-received",
231 G_CALLBACK (on_button_drag_data_received), NULL);
236 main (gint argc, gchar *argv[])
238 GtkWidget *window, *table;
240 gtk_init (&argc, &argv);
242 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
243 table = gtk_table_new (3, 2, FALSE);
245 gtk_table_attach_defaults (GTK_TABLE (table),
246 create_notebook (tabs1, GROUP_A, GTK_POS_TOP),
249 gtk_table_attach_defaults (GTK_TABLE (table),
250 create_notebook (tabs2, GROUP_B, GTK_POS_BOTTOM),
253 gtk_table_attach_defaults (GTK_TABLE (table),
254 create_notebook (tabs3, GROUP_B, GTK_POS_LEFT),
257 gtk_table_attach_defaults (GTK_TABLE (table),
258 create_notebook_with_notebooks (tabs4, GROUP_A, GTK_POS_RIGHT),
261 gtk_table_attach (GTK_TABLE (table),
262 create_trash_button (), 1, 2, 2, 3,
263 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
265 gtk_container_add (GTK_CONTAINER (window), table);
266 gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
267 gtk_widget_show_all (window);