2006-03-22 16:11:48 +00:00
|
|
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
|
2011-01-04 05:55:50 +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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-23 18:43:15 +00:00
|
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static gconstpointer GROUP_A = "GROUP_A";
|
|
|
|
static gconstpointer GROUP_B = "GROUP_B";
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
const char *tabs1 [] = {
|
2006-08-06 04:10:11 +00:00
|
|
|
"aaaaaaaaaa",
|
|
|
|
"bbbbbbbbbb",
|
|
|
|
"cccccccccc",
|
|
|
|
"dddddddddd",
|
2006-02-23 18:43:15 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
const char *tabs2 [] = {
|
2006-02-23 18:43:15 +00:00
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"4",
|
2006-08-06 04:10:11 +00:00
|
|
|
"55555",
|
2006-02-23 18:43:15 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
const char *tabs3 [] = {
|
2006-02-23 18:43:15 +00:00
|
|
|
"foo",
|
|
|
|
"bar",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
const char *tabs4 [] = {
|
2006-02-23 18:43:15 +00:00
|
|
|
"beer",
|
|
|
|
"water",
|
|
|
|
"lemonade",
|
|
|
|
"coffee",
|
|
|
|
"tea",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkNotebook*
|
|
|
|
window_creation_function (GtkNotebook *source_notebook,
|
2011-01-04 05:55:50 +00:00
|
|
|
GtkWidget *child,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gpointer data)
|
2006-02-23 18:43:15 +00:00
|
|
|
{
|
|
|
|
GtkWidget *window, *notebook;
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2006-02-23 18:43:15 +00:00
|
|
|
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),
|
2011-01-04 05:55:50 +00:00
|
|
|
gtk_notebook_get_group_name (source_notebook));
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), notebook);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-30 14:20:04 +00:00
|
|
|
static gboolean
|
|
|
|
remove_in_idle (gpointer data)
|
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
GtkNotebookPage *page = data;
|
|
|
|
GtkWidget *child = gtk_notebook_page_get_child (page);
|
2020-01-02 13:51:20 +00:00
|
|
|
GtkWidget *parent = gtk_widget_get_ancestor (child, GTK_TYPE_NOTEBOOK);
|
2015-01-30 14:20:04 +00:00
|
|
|
GtkWidget *tab_label;
|
|
|
|
|
|
|
|
tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (parent), child);
|
|
|
|
g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
|
|
|
|
gtk_container_remove (GTK_CONTAINER (parent), child);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2020-01-02 13:51:20 +00:00
|
|
|
static gboolean
|
|
|
|
on_button_drag_drop (GtkDropTarget *dest,
|
2020-02-29 02:47:17 +00:00
|
|
|
const GValue *value,
|
|
|
|
double x,
|
|
|
|
double y,
|
2020-01-02 13:51:20 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
GtkNotebookPage *page;
|
2020-01-02 13:51:20 +00:00
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
page = g_value_get_object (value);
|
|
|
|
g_idle_add (remove_in_idle, page);
|
2020-01-02 13:51:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2006-03-22 16:11:48 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 17:21:38 +00:00
|
|
|
static void
|
|
|
|
action_clicked_cb (GtkWidget *button,
|
|
|
|
GtkWidget *notebook)
|
|
|
|
{
|
|
|
|
GtkWidget *page, *title;
|
|
|
|
|
|
|
|
page = gtk_entry_new ();
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (page), "Addition");
|
2015-12-24 17:21:38 +00:00
|
|
|
|
|
|
|
title = gtk_label_new ("Addition");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
static GtkWidget*
|
2020-03-06 17:05:43 +00:00
|
|
|
create_notebook (const char **labels,
|
|
|
|
const char *group,
|
2011-01-04 05:55:50 +00:00
|
|
|
GtkPositionType pos)
|
2006-02-23 18:43:15 +00:00
|
|
|
{
|
2015-12-24 17:21:38 +00:00
|
|
|
GtkWidget *notebook, *title, *page, *action_widget;
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
notebook = gtk_notebook_new ();
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_widget_set_vexpand (notebook, TRUE);
|
|
|
|
gtk_widget_set_hexpand (notebook, TRUE);
|
2015-12-24 17:21:38 +00:00
|
|
|
|
2017-01-20 07:02:48 +00:00
|
|
|
action_widget = gtk_button_new_from_icon_name ("list-add-symbolic");
|
2015-12-24 17:21:38 +00:00
|
|
|
g_signal_connect (action_widget, "clicked", G_CALLBACK (action_clicked_cb), notebook);
|
|
|
|
gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), action_widget, GTK_PACK_END);
|
|
|
|
|
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);
|
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 ();
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (page), *labels);
|
2006-02-23 18:43:15 +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);
|
|
|
|
|
|
|
|
labels++;
|
|
|
|
}
|
|
|
|
|
2006-03-08 17:22:14 +00:00
|
|
|
g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
|
2011-01-04 05:55:50 +00:00
|
|
|
G_CALLBACK (on_page_reordered), NULL);
|
2006-02-23 18:43:15 +00:00
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2016-05-02 09:56:23 +00:00
|
|
|
static GtkWidget*
|
2020-03-06 17:05:43 +00:00
|
|
|
create_notebook_non_dragable_content (const char **labels,
|
2016-05-02 09:56:23 +00:00
|
|
|
const gchar *group,
|
|
|
|
GtkPositionType pos)
|
|
|
|
{
|
|
|
|
GtkWidget *notebook, *title, *page, *action_widget;
|
|
|
|
|
|
|
|
notebook = gtk_notebook_new ();
|
|
|
|
gtk_widget_set_vexpand (notebook, TRUE);
|
|
|
|
gtk_widget_set_hexpand (notebook, TRUE);
|
|
|
|
|
2017-01-20 07:02:48 +00:00
|
|
|
action_widget = gtk_button_new_from_icon_name ("list-add-symbolic");
|
2016-05-02 09:56:23 +00:00
|
|
|
g_signal_connect (action_widget, "clicked", G_CALLBACK (action_clicked_cb), notebook);
|
|
|
|
gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), action_widget, GTK_PACK_END);
|
|
|
|
|
|
|
|
g_signal_connect (notebook, "create-window",
|
|
|
|
G_CALLBACK (window_creation_function), NULL);
|
|
|
|
|
|
|
|
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos);
|
|
|
|
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
|
|
|
|
gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group);
|
|
|
|
|
|
|
|
while (*labels)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2020-01-02 13:51:20 +00:00
|
|
|
button = gtk_button_new_with_label ("example content");
|
2016-05-02 09:56:23 +00:00
|
|
|
/* Use GtkListBox since it bubbles up motion notify event, which can
|
|
|
|
* experience more issues than GtkBox. */
|
|
|
|
page = gtk_list_box_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (page), button);
|
|
|
|
|
2020-01-02 13:51:20 +00:00
|
|
|
button = gtk_button_new_with_label ("row 2");
|
|
|
|
gtk_container_add (GTK_CONTAINER (page), button);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("third row");
|
|
|
|
gtk_container_add (GTK_CONTAINER (page), button);
|
|
|
|
|
2016-05-02 09:56:23 +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);
|
|
|
|
|
|
|
|
labels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
|
|
|
|
G_CALLBACK (on_page_reordered), NULL);
|
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2006-08-06 04:10:11 +00:00
|
|
|
static GtkWidget*
|
2020-03-06 17:05:43 +00:00
|
|
|
create_notebook_with_notebooks (const char **labels,
|
2011-01-04 05:55:50 +00:00
|
|
|
const gchar *group,
|
|
|
|
GtkPositionType pos)
|
2006-08-06 04:10:11 +00:00
|
|
|
{
|
|
|
|
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);
|
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)
|
|
|
|
{
|
2011-01-04 05:55:50 +00:00
|
|
|
page = create_notebook (labels, group, pos);
|
2007-12-31 16:26:18 +00:00
|
|
|
gtk_notebook_popup_enable (GTK_NOTEBOOK (page));
|
2011-01-04 05:55:50 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
labels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (GTK_NOTEBOOK (notebook), "page-reordered",
|
2011-01-04 05:55:50 +00:00
|
|
|
G_CALLBACK (on_page_reordered), NULL);
|
2006-08-06 04:10:11 +00:00
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2006-03-22 16:11:48 +00:00
|
|
|
static GtkWidget*
|
|
|
|
create_trash_button (void)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2020-01-02 13:51:20 +00:00
|
|
|
GtkDropTarget *dest;
|
2006-03-22 16:11:48 +00:00
|
|
|
|
2015-01-30 14:20:04 +00:00
|
|
|
button = gtk_button_new_with_mnemonic ("_Delete");
|
2006-03-22 16:11:48 +00:00
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
dest = gtk_drop_target_new (GTK_TYPE_NOTEBOOK_PAGE, GDK_ACTION_MOVE);
|
|
|
|
g_signal_connect (dest, "drop", G_CALLBACK (on_button_drag_drop), NULL);
|
2020-01-06 05:12:21 +00:00
|
|
|
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
|
2006-03-22 16:11:48 +00:00
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2006-02-23 18:43:15 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
{
|
2011-09-27 03:36:03 +00:00
|
|
|
GtkWidget *window, *grid;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2011-09-27 03:36:03 +00:00
|
|
|
grid = gtk_grid_new ();
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid),
|
2016-05-02 09:56:23 +00:00
|
|
|
create_notebook_non_dragable_content (tabs1, GROUP_A, GTK_POS_TOP),
|
2011-09-27 03:36:03 +00:00
|
|
|
0, 0, 1, 1);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid),
|
|
|
|
create_notebook (tabs2, GROUP_B, GTK_POS_BOTTOM),
|
|
|
|
0, 1, 1, 1);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid),
|
|
|
|
create_notebook (tabs3, GROUP_B, GTK_POS_LEFT),
|
|
|
|
1, 0, 1, 1);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid),
|
|
|
|
create_notebook_with_notebooks (tabs4, GROUP_A, GTK_POS_RIGHT),
|
|
|
|
1, 1, 1, 1);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2011-09-27 03:36:03 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid),
|
|
|
|
create_trash_button (),
|
|
|
|
1, 2, 1, 1);
|
2006-03-22 16:11:48 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), grid);
|
2006-02-23 18:43:15 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
|
2017-06-23 18:33:52 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2017-06-23 18:33:52 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2006-02-23 18:43:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|