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 ();
81 g_signal_connect (notebook, "create-window",
82 G_CALLBACK (window_creation_function), NULL);
84 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook),
85 gtk_notebook_get_group_name (source_notebook));
87 gtk_container_add (GTK_CONTAINER (window), notebook);
89 gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
90 gtk_window_move (GTK_WINDOW (window), x, y);
91 gtk_widget_show_all (window);
93 return GTK_NOTEBOOK (notebook);
97 on_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data)
99 g_print ("page %d reordered\n", page_num);
103 on_notebook_drag_begin (GtkWidget *widget,
104 GdkDragContext *context,
110 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
114 pixbuf = gtk_widget_render_icon_pixbuf (widget,
115 (page_num % 2) ? GTK_STOCK_HELP : GTK_STOCK_STOP,
118 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
119 g_object_unref (pixbuf);
124 on_button_drag_data_received (GtkWidget *widget,
125 GdkDragContext *context,
128 GtkSelectionData *data,
133 GtkWidget *source, *tab_label;
136 source = gtk_drag_get_source_widget (context);
137 child = (void*) gtk_selection_data_get_data (data);
139 tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
140 g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
142 gtk_container_remove (GTK_CONTAINER (source), *child);
146 create_notebook (gchar **labels,
151 GtkWidget *notebook, *title, *page;
154 notebook = gtk_notebook_new ();
155 g_signal_connect (notebook, "create-window",
156 G_CALLBACK (window_creation_function), NULL);
158 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
159 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
160 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
161 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
165 page = gtk_entry_new ();
166 gtk_entry_set_text (GTK_ENTRY (page), *labels);
168 title = gtk_label_new (*labels);
170 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
171 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
172 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
174 if (packing == PACK_END ||
175 (packing == PACK_ALTERNATE && count % 2 == 1))
176 gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
182 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
183 G_CALLBACK (on_page_reordered), NULL);
184 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
185 G_CALLBACK (on_notebook_drag_begin), NULL);
190 create_notebook_with_notebooks (gchar **labels,
195 GtkWidget *notebook, *title, *page;
198 notebook = gtk_notebook_new ();
199 g_signal_connect (notebook, "create-window",
200 G_CALLBACK (window_creation_function), NULL);
202 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
203 gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
204 gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
205 gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
209 page = create_notebook (labels, group, packing, pos);
210 gtk_notebook_popup_enable (GTK_NOTEBOOK (page));
212 title = gtk_label_new (*labels);
214 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
215 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
216 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
218 if (packing == PACK_END ||
219 (packing == PACK_ALTERNATE && count % 2 == 1))
220 gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
226 g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
227 G_CALLBACK (on_page_reordered), NULL);
228 g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
229 G_CALLBACK (on_notebook_drag_begin), NULL);
234 create_trash_button (void)
238 button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
240 gtk_drag_dest_set (button,
241 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
243 G_N_ELEMENTS (button_targets),
246 g_signal_connect_after (G_OBJECT (button), "drag-data-received",
247 G_CALLBACK (on_button_drag_data_received), NULL);
252 main (gint argc, gchar *argv[])
254 GtkWidget *window, *table;
256 gtk_init (&argc, &argv);
258 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
259 table = gtk_table_new (3, 2, FALSE);
261 gtk_table_attach_defaults (GTK_TABLE (table),
262 create_notebook (tabs1, GROUP_A, PACK_ALTERNATE, GTK_POS_TOP),
265 gtk_table_attach_defaults (GTK_TABLE (table),
266 create_notebook (tabs2, GROUP_B, PACK_ALTERNATE, GTK_POS_BOTTOM),
269 gtk_table_attach_defaults (GTK_TABLE (table),
270 create_notebook (tabs3, GROUP_B, PACK_END, GTK_POS_LEFT),
273 gtk_table_attach_defaults (GTK_TABLE (table),
274 create_notebook_with_notebooks (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT),
277 gtk_table_attach (GTK_TABLE (table),
278 create_trash_button (), 1, 2, 2, 3,
279 GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
281 gtk_container_add (GTK_CONTAINER (window), table);
282 gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
283 gtk_widget_show_all (window);