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.
31 static gpointer GROUP_A = "GROUP_A";
32 static gpointer GROUP_B = "GROUP_B";
66 static const GtkTargetEntry button_targets[] = {
67 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
71 window_creation_function (GtkNotebook *source_notebook,
77 GtkWidget *window, *notebook;
79 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
80 notebook = gtk_notebook_new ();
82 gtk_notebook_set_group (GTK_NOTEBOOK (notebook),
83 gtk_notebook_get_group (source_notebook));
85 gtk_container_add (GTK_CONTAINER (window), notebook);
87 gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
88 gtk_window_move (GTK_WINDOW (window), x, y);
89 gtk_widget_show_all (window);
91 return GTK_NOTEBOOK (notebook);
95 on_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data)
97 g_print ("page %d reordered\n", page_num);
101 on_notebook_drag_begin (GtkWidget *widget,
102 GdkDragContext *context,
108 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
112 pixbuf = gtk_widget_render_icon (widget,
113 (page_num % 2) ? GTK_STOCK_HELP : GTK_STOCK_STOP,
114 GTK_ICON_SIZE_DND, NULL);
116 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
117 g_object_unref (pixbuf);
122 on_button_drag_data_received (GtkWidget *widget,
123 GdkDragContext *context,
126 GtkSelectionData *data,
131 GtkWidget *source, *tab_label;
134 source = gtk_drag_get_source_widget (context);
135 child = (void*) data->data;
137 tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
138 g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
140 gtk_container_remove (GTK_CONTAINER (source), *child);
144 create_notebook (gchar **labels,
149 GtkWidget *notebook, *title, *page;
152 notebook = gtk_notebook_new ();
154 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
155 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
156 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
157 gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group);
161 page = gtk_entry_new ();
162 gtk_entry_set_text (GTK_ENTRY (page), *labels);
164 title = gtk_label_new (*labels);
166 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
167 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
168 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
170 if (packing == PACK_END ||
171 (packing == PACK_ALTERNATE && count % 2 == 1))
172 gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
178 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
179 G_CALLBACK (on_page_reordered), NULL);
180 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
181 G_CALLBACK (on_notebook_drag_begin), NULL);
186 create_notebook_with_notebooks (gchar **labels,
191 GtkWidget *notebook, *title, *page;
194 notebook = gtk_notebook_new ();
196 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
197 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
198 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
199 gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group);
203 page = create_notebook (labels, group, packing, pos);
205 title = gtk_label_new (*labels);
207 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
208 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
209 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
211 if (packing == PACK_END ||
212 (packing == PACK_ALTERNATE && count % 2 == 1))
213 gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
219 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
220 G_CALLBACK (on_page_reordered), NULL);
221 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
222 G_CALLBACK (on_notebook_drag_begin), NULL);
227 create_trash_button (void)
231 button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
233 gtk_drag_dest_set (button,
234 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
236 G_N_ELEMENTS (button_targets),
239 g_signal_connect_after (G_OBJECT (button), "drag-data-received",
240 G_CALLBACK (on_button_drag_data_received), NULL);
245 main (gint argc, gchar *argv[])
247 GtkWidget *window, *table;
249 gtk_init (&argc, &argv);
251 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
252 table = gtk_table_new (3, 2, FALSE);
254 gtk_notebook_set_window_creation_hook (window_creation_function, NULL, NULL);
256 gtk_table_attach_defaults (GTK_TABLE (table),
257 create_notebook (tabs1, GROUP_A, PACK_ALTERNATE, GTK_POS_TOP),
260 gtk_table_attach_defaults (GTK_TABLE (table),
261 create_notebook (tabs2, GROUP_B, PACK_ALTERNATE, GTK_POS_BOTTOM),
264 gtk_table_attach_defaults (GTK_TABLE (table),
265 create_notebook (tabs3, GROUP_B, PACK_END, GTK_POS_LEFT),
268 gtk_table_attach_defaults (GTK_TABLE (table),
269 create_notebook_with_notebooks (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT),
272 gtk_table_attach (GTK_TABLE (table),
273 create_trash_button (), 1, 2, 2, 3,
274 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
276 gtk_container_add (GTK_CONTAINER (window), table);
277 gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
278 gtk_widget_show_all (window);