2006-03-22 16:11:48 +00:00
|
|
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
|
2006-02-23 18:43:15 +00:00
|
|
|
/*
|
2008-07-01 22:57:50 +00:00
|
|
|
* GTK - The GIMP Toolkit
|
2006-02-23 18:43:15 +00:00
|
|
|
* Copyright (C) 2006 Carlos Garnacho Parro <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PACK_START,
|
|
|
|
PACK_END,
|
|
|
|
PACK_ALTERNATE
|
|
|
|
};
|
|
|
|
|
2007-05-19 05:22:00 +00:00
|
|
|
static gpointer GROUP_A = "GROUP_A";
|
|
|
|
static gpointer GROUP_B = "GROUP_B";
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
gchar *tabs1 [] = {
|
2006-08-06 04:10:11 +00:00
|
|
|
"aaaaaaaaaa",
|
|
|
|
"bbbbbbbbbb",
|
|
|
|
"cccccccccc",
|
|
|
|
"dddddddddd",
|
2006-02-23 18:43:15 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gchar *tabs2 [] = {
|
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"4",
|
2006-08-06 04:10:11 +00:00
|
|
|
"55555",
|
2006-02-23 18:43:15 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gchar *tabs3 [] = {
|
|
|
|
"foo",
|
|
|
|
"bar",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gchar *tabs4 [] = {
|
|
|
|
"beer",
|
|
|
|
"water",
|
|
|
|
"lemonade",
|
|
|
|
"coffee",
|
|
|
|
"tea",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2006-03-22 16:11:48 +00:00
|
|
|
static const GtkTargetEntry button_targets[] = {
|
|
|
|
{ "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
|
|
|
|
};
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
static GtkNotebook*
|
|
|
|
window_creation_function (GtkNotebook *source_notebook,
|
|
|
|
GtkWidget *child,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *notebook;
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
notebook = gtk_notebook_new ();
|
2010-09-24 15:53:20 +00:00
|
|
|
g_signal_connect (notebook, "create-window",
|
|
|
|
G_CALLBACK (window_creation_function), NULL);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2010-09-24 15:13:30 +00:00
|
|
|
gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook),
|
|
|
|
gtk_notebook_get_group_name (source_notebook));
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), notebook);
|
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
|
|
|
|
gtk_window_move (GTK_WINDOW (window), x, y);
|
|
|
|
gtk_widget_show_all (window);
|
|
|
|
|
|
|
|
return GTK_NOTEBOOK (notebook);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-08 17:22:14 +00:00
|
|
|
on_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data)
|
2006-02-23 18:43:15 +00:00
|
|
|
{
|
2006-03-08 17:22:14 +00:00
|
|
|
g_print ("page %d reordered\n", page_num);
|
2006-02-23 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2006-03-22 16:11:48 +00:00
|
|
|
static void
|
|
|
|
on_notebook_drag_begin (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
guint page_num;
|
|
|
|
|
|
|
|
page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
|
|
|
|
|
2006-06-01 16:41:40 +00:00
|
|
|
if (page_num > 2)
|
|
|
|
{
|
2010-12-15 11:04:15 +00:00
|
|
|
pixbuf = gtk_widget_render_icon_pixbuf (widget,
|
|
|
|
(page_num % 2) ? GTK_STOCK_HELP : GTK_STOCK_STOP,
|
|
|
|
GTK_ICON_SIZE_DND);
|
2006-03-22 16:11:48 +00:00
|
|
|
|
2006-06-01 16:41:40 +00:00
|
|
|
gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
2006-03-22 16:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_button_drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *source, *tab_label;
|
|
|
|
GtkWidget **child;
|
|
|
|
|
|
|
|
source = gtk_drag_get_source_widget (context);
|
2010-12-15 23:47:45 +00:00
|
|
|
child = (void*) gtk_selection_data_get_data (data);
|
2006-03-22 16:11:48 +00:00
|
|
|
|
|
|
|
tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
|
|
|
|
g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (source), *child);
|
|
|
|
}
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
static GtkWidget*
|
|
|
|
create_notebook (gchar **labels,
|
2010-09-24 15:13:30 +00:00
|
|
|
const gchar *group,
|
2006-02-23 18:43:15 +00:00
|
|
|
gint packing,
|
|
|
|
GtkPositionType pos)
|
|
|
|
{
|
|
|
|
GtkWidget *notebook, *title, *page;
|
|
|
|
gint count = 0;
|
|
|
|
|
|
|
|
notebook = gtk_notebook_new ();
|
2010-09-24 15:53:20 +00:00
|
|
|
g_signal_connect (notebook, "create-window",
|
|
|
|
G_CALLBACK (window_creation_function), NULL);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
|
|
|
|
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
|
2010-09-24 15:13:30 +00:00
|
|
|
gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
while (*labels)
|
|
|
|
{
|
|
|
|
page = gtk_entry_new ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (page), *labels);
|
|
|
|
|
|
|
|
title = gtk_label_new (*labels);
|
|
|
|
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
|
|
|
|
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
|
|
|
|
gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
|
|
|
|
|
|
|
|
if (packing == PACK_END ||
|
|
|
|
(packing == PACK_ALTERNATE && count % 2 == 1))
|
|
|
|
gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
labels++;
|
|
|
|
}
|
|
|
|
|
2006-03-08 17:22:14 +00:00
|
|
|
g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
|
|
|
|
G_CALLBACK (on_page_reordered), NULL);
|
2006-03-22 16:11:48 +00:00
|
|
|
g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
|
|
|
|
G_CALLBACK (on_notebook_drag_begin), NULL);
|
2006-02-23 18:43:15 +00:00
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2006-08-06 04:10:11 +00:00
|
|
|
static GtkWidget*
|
|
|
|
create_notebook_with_notebooks (gchar **labels,
|
2010-09-24 15:13:30 +00:00
|
|
|
const gchar *group,
|
2006-08-06 04:10:11 +00:00
|
|
|
gint packing,
|
|
|
|
GtkPositionType pos)
|
|
|
|
{
|
|
|
|
GtkWidget *notebook, *title, *page;
|
|
|
|
gint count = 0;
|
|
|
|
|
|
|
|
notebook = gtk_notebook_new ();
|
2010-09-24 15:53:20 +00:00
|
|
|
g_signal_connect (notebook, "create-window",
|
|
|
|
G_CALLBACK (window_creation_function), NULL);
|
2006-08-06 04:10:11 +00:00
|
|
|
|
|
|
|
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
|
|
|
|
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
|
2010-09-24 15:13:30 +00:00
|
|
|
gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
|
2006-08-06 04:10:11 +00:00
|
|
|
|
|
|
|
while (*labels)
|
|
|
|
{
|
2007-05-19 05:22:00 +00:00
|
|
|
page = create_notebook (labels, group, packing, pos);
|
2007-12-31 16:26:18 +00:00
|
|
|
gtk_notebook_popup_enable (GTK_NOTEBOOK (page));
|
|
|
|
|
2006-08-06 04:10:11 +00:00
|
|
|
title = gtk_label_new (*labels);
|
|
|
|
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title);
|
|
|
|
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE);
|
|
|
|
gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE);
|
2007-12-31 16:26:18 +00:00
|
|
|
|
2006-08-06 04:10:11 +00:00
|
|
|
if (packing == PACK_END ||
|
|
|
|
(packing == PACK_ALTERNATE && count % 2 == 1))
|
|
|
|
gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
labels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
|
|
|
|
G_CALLBACK (on_page_reordered), NULL);
|
|
|
|
g_signal_connect_after (G_OBJECT (notebook), "drag-begin",
|
|
|
|
G_CALLBACK (on_notebook_drag_begin), NULL);
|
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2006-03-22 16:11:48 +00:00
|
|
|
static GtkWidget*
|
|
|
|
create_trash_button (void)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
|
|
|
|
|
|
|
|
gtk_drag_dest_set (button,
|
|
|
|
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
|
|
|
|
button_targets,
|
|
|
|
G_N_ELEMENTS (button_targets),
|
|
|
|
GDK_ACTION_MOVE);
|
|
|
|
|
|
|
|
g_signal_connect_after (G_OBJECT (button), "drag-data-received",
|
|
|
|
G_CALLBACK (on_button_drag_data_received), NULL);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window, *table;
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2006-03-22 16:11:48 +00:00
|
|
|
table = gtk_table_new (3, 2, FALSE);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table),
|
2006-08-06 04:10:11 +00:00
|
|
|
create_notebook (tabs1, GROUP_A, PACK_ALTERNATE, GTK_POS_TOP),
|
2006-02-23 18:43:15 +00:00
|
|
|
0, 1, 0, 1);
|
|
|
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table),
|
|
|
|
create_notebook (tabs2, GROUP_B, PACK_ALTERNATE, GTK_POS_BOTTOM),
|
|
|
|
0, 1, 1, 2);
|
|
|
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table),
|
|
|
|
create_notebook (tabs3, GROUP_B, PACK_END, GTK_POS_LEFT),
|
|
|
|
1, 2, 0, 1);
|
|
|
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table),
|
2006-08-06 04:10:11 +00:00
|
|
|
create_notebook_with_notebooks (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT),
|
2006-02-23 18:43:15 +00:00
|
|
|
1, 2, 1, 2);
|
|
|
|
|
2006-03-22 16:11:48 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (table),
|
|
|
|
create_trash_button (), 1, 2, 2, 3,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), table);
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
|
|
|
|
gtk_widget_show_all (window);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|