[gnome-terminal/gsettings] mdi: Split the MDI implementation out of TerminalWindow
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/gsettings] mdi: Split the MDI implementation out of TerminalWindow
- Date: Sat, 14 Apr 2012 20:56:35 +0000 (UTC)
commit c197bbe3603de355c1527e2407f073529a8ea2bb
Author: Christian Persch <chpe gnome org>
Date: Wed Apr 11 15:28:56 2012 +0200
mdi: Split the MDI implementation out of TerminalWindow
src/Makefile.am | 4 +
src/terminal-mdi-container.c | 179 ++++++++++++++
src/terminal-mdi-container.h | 96 ++++++++
src/terminal-notebook.c | 486 +++++++++++++++++++++++++++++++++++++++
src/terminal-notebook.h | 57 +++++
src/terminal-screen-container.c | 6 +
src/terminal-screen.c | 7 +-
src/terminal-tab-label.c | 35 +++-
src/terminal-tab-label.h | 10 +-
src/terminal-tabs-menu.c | 67 +++----
src/terminal-window.c | 369 ++++++++----------------------
src/terminal-window.h | 4 +-
12 files changed, 992 insertions(+), 328 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 02fb414..50d45c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,10 @@ gnome_terminal_server_SOURCES = \
terminal-info-bar.c \
terminal-info-bar.h \
terminal-intl.h \
+ terminal-mdi-container.c \
+ terminal-mdi-container.h \
+ terminal-notebook.c \
+ terminal-notebook.h \
terminal-schemas.h \
terminal-screen.c \
terminal-screen.h \
diff --git a/src/terminal-mdi-container.c b/src/terminal-mdi-container.c
new file mode 100644
index 0000000..03a2c97
--- /dev/null
+++ b/src/terminal-mdi-container.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright  2008, 2010, 2011, 2012 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "terminal-mdi-container.h"
+#include "terminal-debug.h"
+#include "terminal-intl.h"
+
+enum {
+ SCREEN_ADDED,
+ SCREEN_REMOVED,
+ SCREEN_SWITCHED,
+ SCREENS_REORDERED,
+ SCREEN_CLOSE_REQUEST,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_INTERFACE (TerminalMdiContainer, terminal_mdi_container, GTK_TYPE_WIDGET)
+
+static void
+terminal_mdi_container_default_init (TerminalMdiContainerInterface *iface)
+{
+ signals[SCREEN_ADDED] =
+ g_signal_new (I_("screen-added"),
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalMdiContainerInterface, screen_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, TERMINAL_TYPE_SCREEN);
+
+ signals[SCREEN_ADDED] =
+ g_signal_new (I_("screen-removed"),
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalMdiContainerInterface, screen_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, TERMINAL_TYPE_SCREEN);
+
+ signals[SCREEN_ADDED] =
+ g_signal_new (I_("screen-switched"),
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalMdiContainerInterface, screen_switched),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2, TERMINAL_TYPE_SCREEN, TERMINAL_TYPE_SCREEN);
+
+ signals[SCREENS_REORDERED] =
+ g_signal_new (I_("screens-reordered"),
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalMdiContainerInterface, screens_reordered),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ signals[SCREEN_CLOSE_REQUEST] =
+ g_signal_new (I_("screen-close-request"),
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalMdiContainerInterface, screen_close_request),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, TERMINAL_TYPE_SCREEN);
+
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("active-screen", NULL, NULL,
+ TERMINAL_TYPE_SCREEN,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+/* public API */
+
+void
+terminal_mdi_container_add_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ g_return_if_fail (TERMINAL_IS_MDI_CONTAINER (container));
+ g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+
+ TERMINAL_MDI_CONTAINER_GET_IFACE (container)->add_screen (container, screen);
+}
+
+void
+terminal_mdi_container_remove_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ g_return_if_fail (TERMINAL_IS_MDI_CONTAINER (container));
+ g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+
+ TERMINAL_MDI_CONTAINER_GET_IFACE (container)->remove_screen (container, screen);
+}
+
+TerminalScreen *
+terminal_mdi_container_get_active_screen (TerminalMdiContainer *container)
+{
+ g_return_val_if_fail (TERMINAL_IS_MDI_CONTAINER (container), NULL);
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->get_active_screen (container);
+}
+
+void
+terminal_mdi_container_set_active_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ g_return_if_fail (TERMINAL_IS_MDI_CONTAINER (container));
+ g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+
+ TERMINAL_MDI_CONTAINER_GET_IFACE (container)->set_active_screen (container, screen);
+}
+
+
+GList *
+terminal_mdi_container_list_screens (TerminalMdiContainer *container)
+{
+ g_return_val_if_fail (TERMINAL_IS_MDI_CONTAINER (container), NULL);
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->list_screens (container);
+}
+
+GList *
+terminal_mdi_container_list_screen_containers (TerminalMdiContainer *container)
+{
+ g_return_val_if_fail (TERMINAL_IS_MDI_CONTAINER (container), NULL);
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->list_screen_containers (container);
+}
+
+int
+terminal_mdi_container_get_n_screens (TerminalMdiContainer *container)
+{
+ g_return_val_if_fail (TERMINAL_IS_MDI_CONTAINER (container), 0);
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->get_n_screens (container);
+}
+
+int
+terminal_mdi_container_get_active_screen_num (TerminalMdiContainer *container)
+{
+ g_return_val_if_fail (TERMINAL_IS_MDI_CONTAINER (container), -1);
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->get_active_screen_num (container);
+}
+
+void
+terminal_mdi_container_reorder_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ int new_position)
+{
+ g_return_if_fail (TERMINAL_IS_MDI_CONTAINER (container));
+
+ return TERMINAL_MDI_CONTAINER_GET_IFACE (container)->reorder_screen (container, screen, new_position);
+}
diff --git a/src/terminal-mdi-container.h b/src/terminal-mdi-container.h
new file mode 100644
index 0000000..7ff2469
--- /dev/null
+++ b/src/terminal-mdi-container.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright  2008, 2010, 2012 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef TERMINAL_MDI_CONTAINER_H
+#define TERMINAL_MDI_CONTAINER_H
+
+#include <gtk/gtk.h>
+
+#include "terminal-screen.h"
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_MDI_CONTAINER (terminal_mdi_container_get_type ())
+#define TERMINAL_MDI_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TERMINAL_TYPE_MDI_CONTAINER, TerminalMdiContainer))
+#define TERMINAL_IS_MDI_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TERMINAL_TYPE_MDI_CONTAINER))
+#define TERMINAL_MDI_CONTAINER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TERMINAL_TYPE_MDI_CONTAINER, TerminalMdiContainerInterface))
+
+typedef struct _TerminalMdiContainer TerminalMdiContainer;
+typedef struct _TerminalMdiContainerInterface TerminalMdiContainerInterface;
+
+struct _TerminalMdiContainerInterface {
+ GTypeInterface parent_iface;
+
+ /* vfuncs */
+ void (* add_screen) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+ void (* remove_screen) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+ TerminalScreen * (* get_active_screen) (TerminalMdiContainer *container);
+ void (* set_active_screen) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+ GList * (* list_screens) (TerminalMdiContainer *container);
+ GList * (* list_screen_containers) (TerminalMdiContainer *container);
+ int (* get_n_screens) (TerminalMdiContainer *container);
+ int (* get_active_screen_num) (TerminalMdiContainer *container);
+ void (* reorder_screen) (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ int new_position);
+
+ /* signals */
+ void (* screen_added) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+ void (* screen_removed) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+ void (* screen_switched) (TerminalMdiContainer *container,
+ TerminalScreen *old_active_screen,
+ TerminalScreen *new_active_screen);
+ void (* screens_reordered) (TerminalMdiContainer *container);
+ void (* screen_close_request) (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+};
+
+GType terminal_mdi_container_get_type (void);
+
+void terminal_mdi_container_add_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+
+void terminal_mdi_container_remove_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+
+TerminalScreen *terminal_mdi_container_get_active_screen (TerminalMdiContainer *container);
+
+void terminal_mdi_container_set_active_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen);
+
+GList *terminal_mdi_container_list_screens (TerminalMdiContainer *container);
+
+GList *terminal_mdi_container_list_screen_containers (TerminalMdiContainer *container);
+
+int terminal_mdi_container_get_n_screens (TerminalMdiContainer *container);
+
+int terminal_mdi_container_get_active_screen_num (TerminalMdiContainer *container);
+
+void terminal_mdi_container_reorder_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ int new_position);
+
+G_END_DECLS
+
+#endif /* TERMINAL_MDI_CONTAINER_H */
diff --git a/src/terminal-notebook.c b/src/terminal-notebook.c
new file mode 100644
index 0000000..7831971
--- /dev/null
+++ b/src/terminal-notebook.c
@@ -0,0 +1,486 @@
+/*
+ * Copyright  2001 Havoc Pennington
+ * Copyright  2002 Red Hat, Inc.
+ * Copyright  2008, 2010, 2011, 2012 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "terminal-notebook.h"
+
+#include <gtk/gtk.h>
+
+#include "terminal-debug.h"
+#include "terminal-intl.h"
+#include "terminal-mdi-container.h"
+#include "terminal-screen-container.h"
+#include "terminal-tab-label.h"
+
+#define TERMINAL_NOTEBOOK_GET_PRIVATE(notebook)(G_TYPE_INSTANCE_GET_PRIVATE ((notebook), TERMINAL_TYPE_NOTEBOOK, TerminalNotebookPrivate))
+
+struct _TerminalNotebookPrivate
+{
+ TerminalScreen *active_screen;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ACTIVE_SCREEN
+};
+
+/* helper functions */
+
+static void
+update_tab_visibility (GtkNotebook *notebook,
+ int change)
+{
+ gboolean show_tabs;
+ guint num;
+
+ num = gtk_notebook_get_n_pages (notebook);
+ show_tabs = (num + change) > 1;
+ gtk_notebook_set_show_tabs (notebook, show_tabs);
+}
+
+static void
+close_button_clicked_cb (TerminalTabLabel *tab_label,
+ TerminalNotebook *notebook)
+{
+ TerminalScreen *screen;
+
+ screen = terminal_tab_label_get_screen (tab_label);
+
+ g_signal_emit_by_name (notebook, "screen-close-request", screen);
+}
+
+
+/* TerminalMdiContainer impl */
+
+static void
+terminal_notebook_add_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
+ GtkNotebook *gtk_notebook = GTK_NOTEBOOK (notebook);
+ GtkWidget *screen_container, *tab_label;
+ const int position = -1;
+
+ g_warn_if_fail (gtk_widget_get_parent (GTK_WIDGET (screen)) == NULL);
+
+ screen_container = terminal_screen_container_new (screen);
+ gtk_widget_show (screen_container);
+
+ update_tab_visibility (gtk_notebook, +1);
+
+ tab_label = terminal_tab_label_new (screen);
+ g_signal_connect (tab_label, "close-button-clicked",
+ G_CALLBACK (close_button_clicked_cb), notebook);
+
+ gtk_notebook_insert_page (gtk_notebook,
+ screen_container,
+ tab_label,
+ position);
+ gtk_container_child_set (GTK_CONTAINER (notebook),
+ screen_container,
+ "tab-expand", TRUE,
+ "tab-fill", TRUE,
+ NULL);
+ gtk_notebook_set_tab_reorderable (gtk_notebook, screen_container, TRUE);
+ gtk_notebook_set_tab_detachable (gtk_notebook, screen_container, TRUE);
+}
+
+static void
+terminal_notebook_remove_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
+ TerminalScreenContainer *screen_container;
+
+ g_warn_if_fail (gtk_widget_is_ancestor (GTK_WIDGET (screen), GTK_WIDGET (notebook)));
+
+ update_tab_visibility (GTK_NOTEBOOK (notebook), -1);
+
+ screen_container = terminal_screen_container_get_from_screen (screen);
+ gtk_container_remove (GTK_CONTAINER (notebook),
+ GTK_WIDGET (screen_container));
+}
+
+static TerminalScreen *
+terminal_notebook_get_active_screen (TerminalMdiContainer *container)
+{
+ TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
+ GtkNotebook *gtk_notebook = GTK_NOTEBOOK (notebook);
+ GtkWidget *widget;
+
+ widget = gtk_notebook_get_nth_page (gtk_notebook, gtk_notebook_get_current_page (gtk_notebook));
+ return terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (widget));
+}
+
+static void
+terminal_notebook_set_active_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen)
+{
+ TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
+ GtkNotebook *gtk_notebook = GTK_NOTEBOOK (notebook);
+ TerminalScreenContainer *screen_container;
+ GtkWidget *widget;
+
+ screen_container = terminal_screen_container_get_from_screen (screen);
+ widget = GTK_WIDGET (screen_container);
+
+ gtk_notebook_set_current_page (gtk_notebook,
+ gtk_notebook_page_num (gtk_notebook, widget));
+}
+
+static GList *
+terminal_notebook_list_screen_containers (TerminalMdiContainer *container)
+{
+ /* We are trusting that GtkNotebook will return pages in order */
+ return gtk_container_get_children (GTK_CONTAINER (container));
+}
+
+static GList *
+terminal_notebook_list_screens (TerminalMdiContainer *container)
+{
+ GList *list, *l;
+
+ list = terminal_notebook_list_screen_containers (container);
+ for (l = list; l != NULL; l = l->next)
+ l->data = terminal_screen_container_get_screen ((TerminalScreenContainer *) l->data);
+
+ return list;
+}
+
+static int
+terminal_notebook_get_n_screens (TerminalMdiContainer *container)
+{
+ return gtk_notebook_get_n_pages (GTK_NOTEBOOK (container));
+}
+
+static int
+terminal_notebook_get_active_screen_num (TerminalMdiContainer *container)
+{
+ return gtk_notebook_get_current_page (GTK_NOTEBOOK (container));
+}
+
+static void
+terminal_notebook_reorder_screen (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ int new_position)
+{
+ GtkNotebook *notebook = GTK_NOTEBOOK (container);
+ GtkWidget *child;
+ int n, pos;
+
+ g_return_if_fail (new_position == 1 || new_position == -1);
+
+ child = GTK_WIDGET (terminal_screen_container_get_from_screen (screen));
+ n = gtk_notebook_get_n_pages (notebook);
+ pos = gtk_notebook_page_num (notebook, child);
+
+ pos += new_position;
+ gtk_notebook_reorder_child (notebook, child,
+ pos < 0 ? n - 1 : pos < n ? pos : 0);
+}
+
+static void
+terminal_notebook_mdi_iface_init (TerminalMdiContainerInterface *iface)
+{
+ iface->add_screen = terminal_notebook_add_screen;
+ iface->remove_screen = terminal_notebook_remove_screen;
+ iface->get_active_screen = terminal_notebook_get_active_screen;
+ iface->set_active_screen = terminal_notebook_set_active_screen;
+ iface->list_screens = terminal_notebook_list_screens;
+ iface->list_screen_containers = terminal_notebook_list_screen_containers;
+ iface->get_n_screens = terminal_notebook_get_n_screens;
+ iface->get_active_screen_num = terminal_notebook_get_active_screen_num;
+ iface->reorder_screen = terminal_notebook_reorder_screen;
+}
+
+G_DEFINE_TYPE_WITH_CODE (TerminalNotebook, terminal_notebook, GTK_TYPE_NOTEBOOK,
+ G_IMPLEMENT_INTERFACE (TERMINAL_TYPE_MDI_CONTAINER, terminal_notebook_mdi_iface_init))
+
+/* GtkNotebookClass impl */
+
+static void
+terminal_notebook_switch_page (GtkNotebook *gtk_notebook,
+ GtkWidget *child,
+ guint page_num)
+{
+ TerminalNotebook *notebook = TERMINAL_NOTEBOOK (gtk_notebook);
+ TerminalNotebookPrivate *priv = notebook->priv;
+ TerminalScreen *screen, *old_active_screen;
+
+ GTK_NOTEBOOK_CLASS (terminal_notebook_parent_class)->switch_page (gtk_notebook, child, page_num);
+
+ screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (child));
+
+ old_active_screen = priv->active_screen;
+ if (screen == old_active_screen)
+ return;
+
+ /* Workaround to remove gtknotebook's feature of computing its size based on
+ * all pages. When the widget is hidden, its size will not be taken into
+ * account.
+ * FIXME!
+ */
+// if (old_active_screen)
+// gtk_widget_hide (GTK_WIDGET (terminal_screen_container_get_from_screen (old_active_screen)));
+ /* Make sure that the widget is no longer hidden due to the workaround */
+// if (child)
+// gtk_widget_show (child);
+ if (old_active_screen)
+ gtk_widget_hide (GTK_WIDGET (old_active_screen));
+ if (screen)
+ gtk_widget_show (GTK_WIDGET (screen));
+
+ priv->active_screen = screen;
+
+ g_signal_emit_by_name (notebook, "screen-switched", old_active_screen, screen);
+ g_object_notify (G_OBJECT (notebook), "active-screen");
+}
+
+static void
+terminal_notebook_page_added (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num)
+{
+ void (* page_added) (GtkNotebook *, GtkWidget *, guint) =
+ GTK_NOTEBOOK_CLASS (terminal_notebook_parent_class)->page_added;
+
+ if (page_added)
+ page_added (notebook, child, page_num);
+
+ update_tab_visibility (notebook, 0);
+ g_signal_emit_by_name (notebook, "screen-added",
+ terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (child)));
+}
+
+static void
+terminal_notebook_page_removed (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num)
+{
+ void (* page_removed) (GtkNotebook *, GtkWidget *, guint) =
+ GTK_NOTEBOOK_CLASS (terminal_notebook_parent_class)->page_removed;
+
+ if (page_removed)
+ page_removed (notebook, child, page_num);
+
+ update_tab_visibility (notebook, 0);
+ g_signal_emit_by_name (notebook, "screen-removed",
+ terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (child)));
+}
+
+static void
+terminal_notebook_page_reordered (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num)
+{
+ void (* page_reordered) (GtkNotebook *, GtkWidget *, guint) =
+ GTK_NOTEBOOK_CLASS (terminal_notebook_parent_class)->page_reordered;
+
+ if (page_reordered)
+ page_reordered (notebook, child, page_num);
+
+ g_signal_emit_by_name (notebook, "screens-reordered");
+}
+
+static GtkNotebook *
+terminal_notebook_create_window (GtkNotebook *notebook,
+ GtkWidget *page,
+ gint x,
+ gint y)
+{
+ return GTK_NOTEBOOK_CLASS (terminal_notebook_parent_class)->create_window (notebook, page, x, y);
+}
+
+/* GtkWidgetClass impl */
+
+/* Tab scrolling was removed from GtkNotebook in gtk 3, so reimplement it here */
+static gboolean
+terminal_notebook_scroll_event (GtkWidget *widget,
+ GdkEventScroll *event)
+{
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+ gboolean (* scroll_event) (GtkWidget *, GdkEventScroll *) =
+ GTK_WIDGET_GET_CLASS (widget)->scroll_event;
+ GtkWidget *child, *event_widget, *action_widget;
+
+ child = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
+ if (child == NULL)
+ goto chain_up;
+
+ event_widget = gtk_get_event_widget ((GdkEvent *) event);
+
+ /* Ignore scroll events from the content of the page */
+ if (event_widget == NULL ||
+ event_widget == child ||
+ gtk_widget_is_ancestor (event_widget, child))
+ goto chain_up;
+
+ /* And also from the action widgets */
+ action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_START);
+ if (event_widget == action_widget ||
+ (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget)))
+ goto chain_up;
+ action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_END);
+ if (event_widget == action_widget ||
+ (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget)))
+ goto chain_up;
+
+ switch (event->direction) {
+ case GDK_SCROLL_RIGHT:
+ case GDK_SCROLL_DOWN:
+ gtk_notebook_next_page (notebook);
+ return TRUE;
+ case GDK_SCROLL_LEFT:
+ case GDK_SCROLL_UP:
+ gtk_notebook_prev_page (notebook);
+ return TRUE;
+#if GTK_CHECK_VERSION (3, 3, 17)
+ case GDK_SCROLL_SMOOTH:
+ switch (gtk_notebook_get_tab_pos (notebook)) {
+ case GTK_POS_LEFT:
+ case GTK_POS_RIGHT:
+ if (event->delta_y > 0)
+ gtk_notebook_next_page (notebook);
+ else if (event->delta_y < 0)
+ gtk_notebook_prev_page (notebook);
+ break;
+ case GTK_POS_TOP:
+ case GTK_POS_BOTTOM:
+ if (event->delta_x > 0)
+ gtk_notebook_next_page (notebook);
+ else if (event->delta_x < 0)
+ gtk_notebook_prev_page (notebook);
+ break;
+ }
+ return TRUE;
+#endif
+ }
+
+chain_up:
+ if (scroll_event)
+ return scroll_event (widget, event);
+
+ return FALSE;
+}
+
+/* GObjectClass impl */
+
+static void
+terminal_notebook_init (TerminalNotebook *notebook)
+{
+ TerminalNotebookPrivate *priv;
+
+ priv = notebook->priv = TERMINAL_NOTEBOOK_GET_PRIVATE (notebook);
+
+ priv->active_screen = NULL;
+}
+
+static void
+terminal_notebook_constructed (GObject *object)
+{
+ GtkWidget *widget = GTK_WIDGET (object);
+ GtkNotebook *notebook = GTK_NOTEBOOK (object);
+
+ G_OBJECT_CLASS (terminal_notebook_parent_class)->constructed (object);
+
+ gtk_notebook_set_show_tabs (notebook, FALSE);
+ gtk_notebook_set_scrollable (notebook, TRUE);
+ gtk_notebook_set_show_border (notebook, FALSE);
+ gtk_notebook_set_group_name (notebook, I_("gnome-terminal-window"));
+
+ /* Necessary for scroll events */
+ gtk_widget_add_events (widget, GDK_SCROLL_MASK);
+}
+
+static void
+terminal_notebook_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TerminalMdiContainer *mdi_container = TERMINAL_MDI_CONTAINER (object);
+
+ switch (prop_id) {
+ case PROP_ACTIVE_SCREEN:
+ g_value_set_object (value, terminal_notebook_get_active_screen (mdi_container));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+terminal_notebook_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TerminalMdiContainer *mdi_container = TERMINAL_MDI_CONTAINER (object);
+
+ switch (prop_id) {
+ case PROP_ACTIVE_SCREEN:
+ terminal_notebook_set_active_screen (mdi_container, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+terminal_notebook_class_init (TerminalNotebookClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
+
+ g_type_class_add_private (gobject_class, sizeof (TerminalNotebookPrivate));
+
+ gobject_class->constructed = terminal_notebook_constructed;
+ gobject_class->get_property = terminal_notebook_get_property;
+ gobject_class->set_property = terminal_notebook_set_property;
+
+ g_object_class_override_property (gobject_class, PROP_ACTIVE_SCREEN, "active-screen");
+
+ widget_class->scroll_event = terminal_notebook_scroll_event;
+
+ notebook_class->switch_page = terminal_notebook_switch_page;
+ notebook_class->create_window = terminal_notebook_create_window;
+ notebook_class->page_added = terminal_notebook_page_added;
+ notebook_class->page_removed = terminal_notebook_page_removed;
+ notebook_class->page_reordered = terminal_notebook_page_reordered;
+}
+
+/* public API */
+
+/**
+ * terminal_notebook_new:
+ *
+ * Returns: (transfer full): a new #TerminalNotebook
+ */
+GtkWidget *
+terminal_notebook_new (void)
+{
+ return g_object_new (TERMINAL_TYPE_NOTEBOOK, NULL);
+}
diff --git a/src/terminal-notebook.h b/src/terminal-notebook.h
new file mode 100644
index 0000000..b541237
--- /dev/null
+++ b/src/terminal-notebook.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright  2008, 2010, 2012 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef TERMINAL_NOTEBOOK_H
+#define TERMINAL_NOTEBOOK_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_NOTEBOOK (terminal_notebook_get_type ())
+#define TERMINAL_NOTEBOOK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_NOTEBOOK, TerminalNotebook))
+#define TERMINAL_NOTEBOOK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_NOTEBOOK, TerminalNotebookClass))
+#define TERMINAL_IS_NOTEBOOK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_NOTEBOOK))
+#define TERMINAL_IS_NOTEBOOK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_NOTEBOOK))
+#define TERMINAL_NOTEBOOK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_NOTEBOOK, TerminalNotebookClass))
+
+typedef struct _TerminalNotebook TerminalNotebook;
+typedef struct _TerminalNotebookClass TerminalNotebookClass;
+typedef struct _TerminalNotebookPrivate TerminalNotebookPrivate;
+
+struct _TerminalNotebook
+{
+ GtkNotebook parent_instance;
+
+ /*< private >*/
+ TerminalNotebookPrivate *priv;
+};
+
+struct _TerminalNotebookClass
+{
+ GtkNotebookClass parent_class;
+};
+
+GType terminal_notebook_get_type (void);
+
+GtkWidget *terminal_notebook_new (void);
+
+G_END_DECLS
+
+#endif /* TERMINAL_NOTEBOOK_H */
diff --git a/src/terminal-screen-container.c b/src/terminal-screen-container.c
index de7b8b1..ef57fa1 100644
--- a/src/terminal-screen-container.c
+++ b/src/terminal-screen-container.c
@@ -246,6 +246,9 @@ terminal_screen_container_new (TerminalScreen *screen)
TerminalScreen *
terminal_screen_container_get_screen (TerminalScreenContainer *container)
{
+ if (container == NULL)
+ return NULL;
+
g_return_val_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container), NULL);
return container->priv->screen;
@@ -260,6 +263,9 @@ terminal_screen_container_get_screen (TerminalScreenContainer *container)
TerminalScreenContainer *
terminal_screen_container_get_from_screen (TerminalScreen *screen)
{
+ if (screen == NULL)
+ return NULL;
+
g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
return TERMINAL_SCREEN_CONTAINER (gtk_widget_get_ancestor (GTK_WIDGET (screen), TERMINAL_TYPE_SCREEN_CONTAINER));
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 231eac3..899260e 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1993,8 +1993,6 @@ terminal_screen_drag_data_received (GtkWidget *widget,
TerminalScreen *moving_screen;
TerminalWindow *source_window;
TerminalWindow *dest_window;
- GtkWidget *dest_notebook;
- int page_num;
container = *(GtkWidget**) selection_data_data;
if (!GTK_IS_WIDGET (container))
@@ -2007,10 +2005,7 @@ terminal_screen_drag_data_received (GtkWidget *widget,
source_window = terminal_screen_get_window (moving_screen);
dest_window = terminal_screen_get_window (screen);
- dest_notebook = terminal_window_get_notebook (dest_window);
- page_num = gtk_notebook_page_num (GTK_NOTEBOOK (dest_notebook),
- GTK_WIDGET (screen));
- terminal_window_move_screen (source_window, dest_window, moving_screen, page_num + 1);
+ terminal_window_move_screen (source_window, dest_window, moving_screen, -1);
gtk_drag_finish (context, TRUE, TRUE, timestamp);
}
diff --git a/src/terminal-tab-label.c b/src/terminal-tab-label.c
index 7f461d5..a3907b0 100644
--- a/src/terminal-tab-label.c
+++ b/src/terminal-tab-label.c
@@ -152,6 +152,24 @@ terminal_tab_label_finalize (GObject *object)
}
static void
+terminal_tab_label_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
+
+ switch (prop_id) {
+ case PROP_SCREEN:
+ g_value_set_object (value, terminal_tab_label_get_screen (tab_label));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
terminal_tab_label_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -178,6 +196,7 @@ terminal_tab_label_class_init (TerminalTabLabelClass *klass)
gobject_class->constructor = terminal_tab_label_constructor;
gobject_class->finalize = terminal_tab_label_finalize;
+ gobject_class->get_property = terminal_tab_label_get_property;
gobject_class->set_property = terminal_tab_label_set_property;
widget_class->parent_set = terminal_tab_label_parent_set;
@@ -197,7 +216,7 @@ terminal_tab_label_class_init (TerminalTabLabelClass *klass)
PROP_SCREEN,
g_param_spec_object ("screen", NULL, NULL,
TERMINAL_TYPE_SCREEN,
- G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (gobject_class, sizeof (TerminalTabLabelPrivate));
@@ -263,3 +282,17 @@ terminal_tab_label_set_bold (TerminalTabLabel *tab_label,
if (free_list)
pango_attr_list_unref (attr_list);
}
+
+/**
+ * terminal_tab_label_get_screen:
+ * @tab_label: a #TerminalTabLabel
+ *
+ * Returns: (transfer none): the #TerminalScreen for @tab_label
+ */
+TerminalScreen *
+terminal_tab_label_get_screen (TerminalTabLabel *tab_label)
+{
+ g_return_val_if_fail (TERMINAL_IS_TAB_LABEL (tab_label), NULL);
+
+ return tab_label->priv->screen;
+}
diff --git a/src/terminal-tab-label.h b/src/terminal-tab-label.h
index b5cbcba..6dc3e76 100644
--- a/src/terminal-tab-label.h
+++ b/src/terminal-tab-label.h
@@ -52,12 +52,14 @@ struct _TerminalTabLabelClass
void (* close_button_clicked) (TerminalTabLabel *tab_label);
};
-GType terminal_tab_label_get_type (void);
+GType terminal_tab_label_get_type (void);
-GtkWidget *terminal_tab_label_new (TerminalScreen *screen);
+GtkWidget * terminal_tab_label_new (TerminalScreen *screen);
-void terminal_tab_label_set_bold (TerminalTabLabel *tab_label,
- gboolean bold);
+void terminal_tab_label_set_bold (TerminalTabLabel *tab_label,
+ gboolean bold);
+
+TerminalScreen *terminal_tab_label_get_screen (TerminalTabLabel *tab_label);
G_END_DECLS
diff --git a/src/terminal-tabs-menu.c b/src/terminal-tabs-menu.c
index 4215dc8..78752cb 100644
--- a/src/terminal-tabs-menu.c
+++ b/src/terminal-tabs-menu.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright  2003 David Bordoley
- * Copyright  2003-2004 Christian Persch
+ * Copyright  2003-2004, 2012 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,14 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include "config.h"
+
+#include "terminal-tabs-menu.h"
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
-#include "terminal-tabs-menu.h"
+#include "terminal-mdi-container.h"
#include "terminal-screen.h"
#include "terminal-screen-container.h"
#include "terminal-intl.h"
@@ -178,18 +180,14 @@ sync_tab_title (TerminalScreen *screen,
}
static void
-notebook_page_added_cb (GtkNotebook *notebook,
- TerminalScreenContainer *container,
- guint position,
- TerminalTabsMenu *menu)
+mdi_screen_added_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalTabsMenu *menu)
{
TerminalTabsMenuPrivate *priv = menu->priv;
GtkAction *action;
char verb[ACTION_VERB_FORMAT_LENGTH];
GSList *group;
- TerminalScreen *screen;
-
- screen = terminal_screen_container_get_screen (container);
g_snprintf (verb, sizeof (verb), ACTION_VERB_FORMAT, allocate_tab_id ());
@@ -226,16 +224,12 @@ notebook_page_added_cb (GtkNotebook *notebook,
}
static void
-notebook_page_removed_cb (GtkNotebook *notebook,
- TerminalScreenContainer *container,
- guint position,
- TerminalTabsMenu *menu)
+mdi_screen_removed_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalTabsMenu *menu)
{
TerminalTabsMenuPrivate *priv = menu->priv;
GtkAction *action;
- TerminalScreen *screen;
-
- screen = terminal_screen_container_get_screen (container);
action = g_object_get_data (G_OBJECT (screen), DATA_KEY);
g_return_if_fail (action != NULL);
@@ -255,27 +249,20 @@ notebook_page_removed_cb (GtkNotebook *notebook,
}
static void
-notebook_page_reordered_cb (GtkNotebook *notebook,
- GtkBin *bin,
- guint position,
- TerminalTabsMenu *menu)
+mdi_screens_reordered_cb (GtkNotebook *notebook,
+ TerminalTabsMenu *menu)
{
terminal_tabs_menu_update (menu);
}
static void
-notebook_page_switch_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint position,
- TerminalTabsMenu *menu)
+mdi_screen_switched_cb (TerminalMdiContainer *container,
+ TerminalScreen *old_active_screen,
+ TerminalScreen *screen,
+ TerminalTabsMenu *menu)
{
- TerminalScreenContainer *container;
- TerminalScreen *screen;
GtkAction *action;
- container = TERMINAL_SCREEN_CONTAINER (page);
- screen = terminal_screen_container_get_screen (container);
-
action = g_object_get_data (G_OBJECT (screen), DATA_KEY);
g_signal_handlers_block_by_func (action, G_CALLBACK (tab_action_activate_cb), menu);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
@@ -305,7 +292,7 @@ terminal_tabs_menu_set_window (TerminalTabsMenu *menu,
TerminalWindow *window)
{
TerminalTabsMenuPrivate *priv = menu->priv;
- GtkWidget *notebook;
+ GtkWidget *mdi_container;
GtkUIManager *manager;
priv->window = window;
@@ -324,15 +311,15 @@ terminal_tabs_menu_set_window (TerminalTabsMenu *menu,
g_signal_connect (priv->action_group, "connect-proxy",
G_CALLBACK (connect_proxy_cb), NULL);
- notebook = terminal_window_get_notebook (window);
- g_signal_connect_object (notebook, "page-added",
- G_CALLBACK (notebook_page_added_cb), menu, 0);
- g_signal_connect_object (notebook, "page-removed",
- G_CALLBACK (notebook_page_removed_cb), menu, 0);
- g_signal_connect_object (notebook, "page-reordered",
- G_CALLBACK (notebook_page_reordered_cb), menu, 0);
- g_signal_connect_object (notebook, "switch-page",
- G_CALLBACK (notebook_page_switch_cb), menu, 0);
+ mdi_container = terminal_window_get_mdi_container (window);
+ g_signal_connect_object (mdi_container, "screen-added",
+ G_CALLBACK (mdi_screen_added_cb), menu, 0);
+ g_signal_connect_object (mdi_container, "screen-removed",
+ G_CALLBACK (mdi_screen_removed_cb), menu, 0);
+ g_signal_connect_object (mdi_container, "screens-reordered",
+ G_CALLBACK (mdi_screens_reordered_cb), menu, 0);
+ g_signal_connect_object (mdi_container, "screen-switched",
+ G_CALLBACK (mdi_screen_switched_cb), menu, 0);
}
static void
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 3430837..89442d8 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -32,6 +32,8 @@
#include "terminal-enums.h"
#include "terminal-encoding.h"
#include "terminal-intl.h"
+#include "terminal-mdi-container.h"
+#include "terminal-notebook.h"
#include "terminal-schemas.h"
#include "terminal-screen-container.h"
#include "terminal-search-dialog.h"
@@ -61,7 +63,7 @@ struct _TerminalWindowPrivate
guint new_terminal_ui_id;
GtkWidget *menubar;
- GtkWidget *notebook;
+ TerminalMdiContainer *mdi_container;
TerminalScreen *active_screen;
int old_char_width;
int old_char_height;
@@ -73,9 +75,6 @@ struct _TerminalWindowPrivate
guint menubar_visible : 1;
guint use_default_menubar_visibility : 1;
- /* Compositing manager integration */
- guint have_argb_visual : 1;
-
/* Used to clear stray "demands attention" flashing on our window when we
* unmap and map it to switch to an ARGB visual.
*/
@@ -134,21 +133,19 @@ static gboolean notebook_button_press_cb (GtkWidget *notebook,
TerminalWindow *window);
static gboolean notebook_popup_menu_cb (GtkWidget *notebook,
TerminalWindow *window);
-static void notebook_page_selected_callback (GtkWidget *notebook,
- GtkWidget *page,
- guint page_num,
- TerminalWindow *window);
-static void notebook_page_added_callback (GtkWidget *notebook,
- GtkWidget *container,
- guint page_num,
- TerminalWindow *window);
-static void notebook_page_removed_callback (GtkWidget *notebook,
- GtkWidget *container,
- guint page_num,
- TerminalWindow *window);
-static gboolean notebook_scroll_event_cb (GtkWidget *notebook,
- GdkEventScroll *event,
- TerminalWindow *window);
+static void mdi_screen_switched_cb (TerminalMdiContainer *container,
+ TerminalScreen *old_active_screen,
+ TerminalScreen *screen,
+ TerminalWindow *window);
+static void mdi_screen_added_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window);
+static void mdi_screen_removed_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window);
+static void screen_close_request_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window);
/* Menu action callbacks */
static void file_new_window_callback (GtkAction *action,
@@ -1062,7 +1059,6 @@ static void
terminal_window_update_tabs_menu_sensitivity (TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkNotebook *notebook = GTK_NOTEBOOK (priv->notebook);
GtkActionGroup *action_group = priv->action_group;
GtkAction *action;
int num_pages, page_num;
@@ -1071,8 +1067,8 @@ terminal_window_update_tabs_menu_sensitivity (TerminalWindow *window)
if (priv->disposed)
return;
- num_pages = gtk_notebook_get_n_pages (notebook);
- page_num = gtk_notebook_get_current_page (notebook);
+ num_pages = terminal_mdi_container_get_n_screens (priv->mdi_container);
+ page_num = terminal_mdi_container_get_active_screen_num (priv->mdi_container);
not_first = page_num > 0;
not_last = page_num + 1 < num_pages;
@@ -1109,27 +1105,6 @@ terminal_window_update_tabs_menu_sensitivity (TerminalWindow *window)
gtk_action_set_sensitive (action, num_pages > 1);
}
-gboolean
-terminal_window_uses_argb_visual (TerminalWindow *window)
-{
- TerminalWindowPrivate *priv = window->priv;
- return priv->have_argb_visual;
-}
-
-static void
-update_tab_visibility (TerminalWindow *window,
- int change)
-{
- TerminalWindowPrivate *priv = window->priv;
- gboolean show_tabs;
- guint num;
-
- num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
-
- show_tabs = (num + change) > 1;
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), show_tabs);
-}
-
static GtkNotebook *
handle_tab_droped_on_desktop (GtkNotebook *source_notebook,
GtkWidget *container,
@@ -1149,10 +1124,10 @@ handle_tab_droped_on_desktop (GtkNotebook *source_notebook,
new_priv = new_window->priv;
new_priv->present_on_insert = TRUE;
- update_tab_visibility (source_window, -1);
- update_tab_visibility (new_window, +1);
+// update_tab_visibility (source_window, -1);
+// update_tab_visibility (new_window, +1);
- return GTK_NOTEBOOK (new_priv->notebook);
+ return GTK_NOTEBOOK (new_priv->mdi_container);
}
/* Terminal screen popup menu handling */
@@ -1282,7 +1257,7 @@ popup_clipboard_targets_received_cb (GtkClipboard *clipboard,
priv->popup_info = info; /* adopt the ref added when requesting the clipboard */
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+ n_pages = terminal_mdi_container_get_n_screens (priv->mdi_container);
can_paste = targets != NULL && gtk_targets_include_text (targets, n_targets);
can_paste_uris = targets != NULL && gtk_targets_include_uri (targets, n_targets);
@@ -1867,40 +1842,41 @@ terminal_window_init (TerminalWindow *window)
priv->active_screen = NULL;
priv->menubar_visible = FALSE;
-
+
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
gtk_widget_show (main_vbox);
- priv->notebook = gtk_notebook_new ();
- gtk_notebook_set_scrollable (GTK_NOTEBOOK (priv->notebook), TRUE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
- gtk_notebook_set_group_name (GTK_NOTEBOOK (priv->notebook), I_("gnome-terminal-window"));
+ priv->mdi_container = TERMINAL_MDI_CONTAINER (terminal_notebook_new ());
- g_signal_connect (priv->notebook, "button-press-event",
- G_CALLBACK (notebook_button_press_cb), window);
- g_signal_connect (priv->notebook, "popup-menu",
- G_CALLBACK (notebook_popup_menu_cb), window);
- g_signal_connect_after (priv->notebook, "switch-page",
- G_CALLBACK (notebook_page_selected_callback), window);
- g_signal_connect_after (priv->notebook, "page-added",
- G_CALLBACK (notebook_page_added_callback), window);
- g_signal_connect_after (priv->notebook, "page-removed",
- G_CALLBACK (notebook_page_removed_callback), window);
- g_signal_connect_data (priv->notebook, "page-reordered",
+ g_signal_connect (priv->mdi_container, "screen-close-request",
+ G_CALLBACK (screen_close_request_cb), window);
+
+ g_signal_connect_after (priv->mdi_container, "screen-switched",
+ G_CALLBACK (mdi_screen_switched_cb), window);
+ g_signal_connect_after (priv->mdi_container, "screen-added",
+ G_CALLBACK (mdi_screen_added_cb), window);
+ g_signal_connect_after (priv->mdi_container, "screen-removed",
+ G_CALLBACK (mdi_screen_removed_cb), window);
+ g_signal_connect_data (priv->mdi_container, "screens-reordered",
G_CALLBACK (terminal_window_update_tabs_menu_sensitivity),
window, NULL, G_CONNECT_SWAPPED | G_CONNECT_AFTER);
- g_signal_connect (priv->notebook, "create-window",
- G_CALLBACK (handle_tab_droped_on_desktop), window);
- /* Tab scrolling was removed from GtkNotebook in gtk 3 */
- gtk_widget_add_events (priv->notebook, GDK_SCROLL_MASK);
- g_signal_connect (priv->notebook, "scroll-event",
- G_CALLBACK (notebook_scroll_event_cb), window);
+ /* FIXME hack hack! */
+ if (GTK_IS_NOTEBOOK (priv->mdi_container)) {
+ g_signal_connect (priv->mdi_container, "button-press-event",
+ G_CALLBACK (notebook_button_press_cb), window);
+ g_signal_connect (priv->mdi_container, "popup-menu",
+ G_CALLBACK (notebook_popup_menu_cb), window);
+ }
- gtk_box_pack_end (GTK_BOX (main_vbox), priv->notebook, TRUE, TRUE, 0);
- gtk_widget_show (priv->notebook);
+ /* FIXME hack */
+ if (GTK_IS_NOTEBOOK (priv->mdi_container))
+ g_signal_connect (priv->mdi_container, "create-window",
+ G_CALLBACK (handle_tab_droped_on_desktop), window);
+
+ gtk_box_pack_end (GTK_BOX (main_vbox), GTK_WIDGET (priv->mdi_container), TRUE, TRUE, 0);
+ gtk_widget_show (GTK_WIDGET (priv->mdi_container));
priv->old_char_width = -1;
priv->old_char_height = -1;
@@ -2099,8 +2075,9 @@ terminal_window_show (GtkWidget *widget)
* showing the TerminalWindow, we can get here when the first page has been
* added but not yet set current. By setting the page current, we get the
* right size when we first show the window */
- if (gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook)) == -1)
- gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0);
+ if (GTK_IS_NOTEBOOK (priv->mdi_container) &&
+ gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->mdi_container)) == -1)
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->mdi_container), 0);
if (priv->active_screen != NULL)
{
@@ -2216,26 +2193,13 @@ sync_screen_icon_title_set (TerminalScreen *screen,
/* Re-setting the right title will be done by the notify::title handler which comes after this one */
}
-/* Notebook callbacks */
+/* MDI container callbacks */
static void
-close_button_clicked_cb (GtkWidget *tab_label,
- GtkWidget *screen_container)
+screen_close_request_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window)
{
- GtkWidget *toplevel;
- TerminalWindow *window;
- TerminalScreen *screen;
-
- toplevel = gtk_widget_get_toplevel (screen_container);
- if (!gtk_widget_is_toplevel (toplevel))
- return;
-
- if (!TERMINAL_IS_WINDOW (toplevel))
- return;
-
- window = TERMINAL_WINDOW (toplevel);
-
- screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (screen_container));
if (confirm_close_window_or_tab (window, screen))
return;
@@ -2249,7 +2213,6 @@ terminal_window_add_screen (TerminalWindow *window,
{
TerminalWindowPrivate *priv = window->priv;
GtkWidget *old_window;
- GtkWidget *screen_container, *tab_label;
old_window = gtk_widget_get_toplevel (GTK_WIDGET (screen));
if (gtk_widget_is_toplevel (old_window) &&
@@ -2260,30 +2223,7 @@ terminal_window_add_screen (TerminalWindow *window,
if (TERMINAL_IS_WINDOW (old_window))
terminal_window_remove_screen (TERMINAL_WINDOW (old_window), screen);
- screen_container = terminal_screen_container_new (screen);
- gtk_widget_show (screen_container);
-
- update_tab_visibility (window, +1);
-
- tab_label = terminal_tab_label_new (screen);
- g_signal_connect (tab_label, "close-button-clicked",
- G_CALLBACK (close_button_clicked_cb), screen_container);
-
- gtk_notebook_insert_page (GTK_NOTEBOOK (priv->notebook),
- screen_container,
- tab_label,
- position);
- gtk_container_child_set (GTK_CONTAINER (priv->notebook),
- screen_container,
- "tab-expand", TRUE,
- "tab-fill", TRUE,
- NULL);
- gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook),
- screen_container,
- TRUE);
- gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook),
- screen_container,
- TRUE);
+ terminal_mdi_container_add_screen (priv->mdi_container, screen);
}
void
@@ -2291,15 +2231,8 @@ terminal_window_remove_screen (TerminalWindow *window,
TerminalScreen *screen)
{
TerminalWindowPrivate *priv = window->priv;
- TerminalScreenContainer *screen_container;
-
- g_return_if_fail (gtk_widget_get_toplevel (GTK_WIDGET (screen)) == GTK_WIDGET (window));
- update_tab_visibility (window, -1);
-
- screen_container = terminal_screen_container_get_from_screen (screen);
- gtk_container_remove (GTK_CONTAINER (priv->notebook),
- GTK_WIDGET (screen_container));
+ terminal_mdi_container_remove_screen (priv->mdi_container, screen);
}
void
@@ -2327,7 +2260,7 @@ terminal_window_move_screen (TerminalWindow *source_window,
g_object_ref_sink (screen_container);
g_object_ref_sink (screen);
terminal_window_remove_screen (source_window, screen);
-
+
/* Now we can safely remove the screen from the container and let the container die */
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (screen))), GTK_WIDGET (screen));
g_object_unref (screen_container);
@@ -2340,9 +2273,8 @@ GList*
terminal_window_list_screen_containers (TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
-
- /* We are trusting that GtkNotebook will return pages in order */
- return gtk_container_get_children (GTK_CONTAINER (priv->notebook));
+
+ return terminal_mdi_container_list_screen_containers (priv->mdi_container);
}
void
@@ -2387,13 +2319,13 @@ terminal_window_get_menubar_visible (TerminalWindow *window)
}
GtkWidget *
-terminal_window_get_notebook (TerminalWindow *window)
+terminal_window_get_mdi_container (TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
g_return_val_if_fail (TERMINAL_IS_WINDOW (window), NULL);
- return GTK_WIDGET (priv->notebook);
+ return GTK_WIDGET (priv->mdi_container);
}
void
@@ -2410,18 +2342,12 @@ terminal_window_set_size_force_grid (TerminalWindow *window,
int force_grid_height)
{
GtkWidget *widget;
- GtkWidget *app;
int grid_width;
int grid_height;
/* be sure our geometry is up-to-date */
terminal_window_update_geometry (window);
- widget = GTK_WIDGET (screen);
-
- app = gtk_widget_get_toplevel (widget);
- g_assert (app != NULL);
-
terminal_screen_get_size (screen, &grid_width, &grid_height);
if (force_grid_width >= 0)
@@ -2429,7 +2355,7 @@ terminal_window_set_size_force_grid (TerminalWindow *window,
if (force_grid_height >= 0)
grid_height = force_grid_height;
- gtk_window_resize_to_geometry (GTK_WINDOW (app), grid_width, grid_height);
+ gtk_window_resize_to_geometry (GTK_WINDOW (window), grid_width, grid_height);
}
void
@@ -2437,14 +2363,8 @@ terminal_window_switch_screen (TerminalWindow *window,
TerminalScreen *screen)
{
TerminalWindowPrivate *priv = window->priv;
- TerminalScreenContainer *screen_container;
- int page_num;
- screen_container = terminal_screen_container_get_from_screen (screen);
- g_assert (TERMINAL_IS_SCREEN_CONTAINER (screen_container));
- page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
- GTK_WIDGET (screen_container));
- gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page_num);
+ terminal_mdi_container_set_active_screen (priv->mdi_container, screen);
}
TerminalScreen*
@@ -2452,7 +2372,7 @@ terminal_window_get_active (TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- return priv->active_screen;
+ return terminal_mdi_container_get_active_screen (priv->mdi_container);
}
static gboolean
@@ -2494,14 +2414,14 @@ notebook_popup_menu_cb (GtkWidget *widget,
TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkNotebook *notebook = GTK_NOTEBOOK (priv->notebook);
+ GtkNotebook *notebook = GTK_NOTEBOOK (priv->mdi_container);
GtkWidget *focus_widget, *tab, *tab_label, *menu;
GtkAction *action;
int page_num;
focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
/* Only respond if the notebook is the actual focus */
- if (focus_widget != priv->notebook)
+ if (focus_widget != GTK_WIDGET (priv->mdi_container))
return FALSE;
page_num = gtk_notebook_get_current_page (notebook);
@@ -2521,51 +2441,35 @@ notebook_popup_menu_cb (GtkWidget *widget,
}
static void
-notebook_page_selected_callback (GtkWidget *notebook,
- GtkWidget *page_widget,
- guint page_num,
- TerminalWindow *window)
+mdi_screen_switched_cb (TerminalMdiContainer *container,
+ TerminalScreen *old_active_screen,
+ TerminalScreen *screen,
+ TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkWidget *widget;
- TerminalScreen *screen;
int old_grid_width, old_grid_height;
_terminal_debug_print (TERMINAL_DEBUG_MDI,
- "[window %p] MDI: page-selected %d\n",
- window, page_num);
+ "[window %p] MDI: screen-switched old %p new %p\n",
+ window, old_active_screen, screen);
if (priv->disposed)
return;
- screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (page_widget));
- widget = GTK_WIDGET (screen);
- g_assert (screen != NULL);
+ if (screen == NULL || old_active_screen == screen)
+ return;
_terminal_debug_print (TERMINAL_DEBUG_MDI,
"[window %p] MDI: setting active tab to screen %p (old active screen %p)\n",
window, screen, priv->active_screen);
- if (priv->active_screen == screen)
- return;
-
- if (priv->active_screen != NULL) {
- terminal_screen_get_size (priv->active_screen, &old_grid_width, &old_grid_height);
-
+ if (old_active_screen != NULL && screen != NULL) {
+ terminal_screen_get_size (old_active_screen, &old_grid_width, &old_grid_height);
+
/* This is so that we maintain the same grid */
vte_terminal_set_size (VTE_TERMINAL (screen), old_grid_width, old_grid_height);
}
- /* Workaround to remove gtknotebook's feature of computing its size based on
- * all pages. When the widget is hidden, its size will not be taken into
- * account.
- */
- if (priv->active_screen)
- gtk_widget_hide (GTK_WIDGET (priv->active_screen)); /* FIXME */
-
- /* Make sure that the widget is no longer hidden due to the workaround */
- gtk_widget_show (widget);
-
priv->active_screen = screen;
/* Override menubar setting if it wasn't restored from session */
@@ -2597,15 +2501,11 @@ notebook_page_selected_callback (GtkWidget *notebook,
}
static void
-notebook_page_added_callback (GtkWidget *notebook,
- GtkWidget *container,
- guint page_num,
- TerminalWindow *window)
+mdi_screen_added_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- TerminalScreen *screen;
-
- screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
_terminal_debug_print (TERMINAL_DEBUG_MDI,
"[window %p] MDI: screen %p inserted\n",
@@ -2636,7 +2536,6 @@ notebook_page_added_callback (GtkWidget *notebook,
g_signal_connect (screen, "close-screen",
G_CALLBACK (screen_close_cb), window);
- update_tab_visibility (window, 0);
terminal_window_update_tabs_menu_sensitivity (window);
terminal_window_update_search_sensitivity (screen, window);
@@ -2665,20 +2564,16 @@ notebook_page_added_callback (GtkWidget *notebook,
}
static void
-notebook_page_removed_callback (GtkWidget *notebook,
- GtkWidget *container,
- guint page_num,
- TerminalWindow *window)
+mdi_screen_removed_cb (TerminalMdiContainer *container,
+ TerminalScreen *screen,
+ TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- TerminalScreen *screen;
int pages;
if (priv->disposed)
return;
- screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
-
_terminal_debug_print (TERMINAL_DEBUG_MDI,
"[window %p] MDI: screen %p removed\n",
window, screen);
@@ -2719,10 +2614,9 @@ notebook_page_removed_callback (GtkWidget *notebook,
window);
terminal_window_update_tabs_menu_sensitivity (window);
- update_tab_visibility (window, 0);
terminal_window_update_search_sensitivity (screen, window);
- pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+ pages = terminal_mdi_container_get_n_screens (container);
if (pages == 1)
{
terminal_window_set_size (window, priv->active_screen);
@@ -2733,70 +2627,6 @@ notebook_page_removed_callback (GtkWidget *notebook,
}
}
-static gboolean
-notebook_scroll_event_cb (GtkWidget *widget,
- GdkEventScroll *event,
- TerminalWindow *window)
-{
- GtkNotebook *notebook = GTK_NOTEBOOK (widget);
- GtkWidget *child, *event_widget, *action_widget;
-
- child = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
- if (child == NULL)
- return FALSE;
-
- event_widget = gtk_get_event_widget ((GdkEvent *) event);
-
- /* Ignore scroll events from the content of the page */
- if (event_widget == NULL ||
- event_widget == child ||
- gtk_widget_is_ancestor (event_widget, child))
- return FALSE;
-
- /* And also from the action widgets */
- action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_START);
- if (event_widget == action_widget ||
- (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget)))
- return FALSE;
- action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_END);
- if (event_widget == action_widget ||
- (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget)))
- return FALSE;
-
- switch (event->direction) {
- case GDK_SCROLL_RIGHT:
- case GDK_SCROLL_DOWN:
- gtk_notebook_next_page (notebook);
- break;
- case GDK_SCROLL_LEFT:
- case GDK_SCROLL_UP:
- gtk_notebook_prev_page (notebook);
- break;
-#if GTK_CHECK_VERSION (3, 3, 17)
- case GDK_SCROLL_SMOOTH:
- switch (gtk_notebook_get_tab_pos (notebook)) {
- case GTK_POS_LEFT:
- case GTK_POS_RIGHT:
- if (event->delta_y > 0)
- gtk_notebook_next_page (notebook);
- else if (event->delta_y < 0)
- gtk_notebook_prev_page (notebook);
- break;
- case GTK_POS_TOP:
- case GTK_POS_BOTTOM:
- if (event->delta_x > 0)
- gtk_notebook_next_page (notebook);
- else if (event->delta_x < 0)
- gtk_notebook_prev_page (notebook);
- break;
- }
- break;
-#endif
- }
-
- return TRUE;
-}
-
gboolean
terminal_window_parse_geometry (TerminalWindow *window,
const char *geometry)
@@ -3671,7 +3501,7 @@ tabs_next_or_previous_tab_cb (GtkAction *action,
TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkNotebookClass *klass;
+ GtkWidgetClass *klass;
const char *name;
guint keyval = 0;
@@ -3682,11 +3512,12 @@ tabs_next_or_previous_tab_cb (GtkAction *action,
keyval = GDK_KEY_Page_Up;
}
- klass = GTK_NOTEBOOK_GET_CLASS (GTK_NOTEBOOK (priv->notebook));
+ /* FIXMEchpe GtkNotebook specific? */
+ klass = GTK_WIDGET_GET_CLASS (GTK_WIDGET (priv->mdi_container));
gtk_binding_set_activate (gtk_binding_set_by_class (klass),
keyval,
GDK_CONTROL_MASK,
- G_OBJECT (priv->notebook));
+ G_OBJECT (priv->mdi_container));
}
static void
@@ -3694,15 +3525,10 @@ tabs_move_left_callback (GtkAction *action,
TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkNotebook *notebook = GTK_NOTEBOOK (priv->notebook);
- gint page_num,last_page;
- GtkWidget *page;
-
- page_num = gtk_notebook_get_current_page (notebook);
- last_page = gtk_notebook_get_n_pages (notebook) - 1;
- page = gtk_notebook_get_nth_page (notebook, page_num);
- gtk_notebook_reorder_child (notebook, page, page_num == 0 ? last_page : page_num - 1);
+ terminal_mdi_container_reorder_screen (priv->mdi_container,
+ terminal_mdi_container_get_active_screen (priv->mdi_container),
+ -1);
}
static void
@@ -3710,15 +3536,10 @@ tabs_move_right_callback (GtkAction *action,
TerminalWindow *window)
{
TerminalWindowPrivate *priv = window->priv;
- GtkNotebook *notebook = GTK_NOTEBOOK (priv->notebook);
- gint page_num,last_page;
- GtkWidget *page;
- page_num = gtk_notebook_get_current_page (notebook);
- last_page = gtk_notebook_get_n_pages (notebook) - 1;
- page = gtk_notebook_get_nth_page (notebook, page_num);
-
- gtk_notebook_reorder_child (notebook, page, page_num == last_page ? 0 : page_num + 1);
+ terminal_mdi_container_reorder_screen (priv->mdi_container,
+ terminal_mdi_container_get_active_screen (priv->mdi_container),
+ +1);
}
static void
diff --git a/src/terminal-window.h b/src/terminal-window.h
index ef268cf..250ab60 100644
--- a/src/terminal-window.h
+++ b/src/terminal-window.h
@@ -93,9 +93,7 @@ void terminal_window_set_size_force_grid (TerminalWindow *window,
int force_grid_width,
int force_grid_height);
-GtkWidget* terminal_window_get_notebook (TerminalWindow *window);
-
-gboolean terminal_window_uses_argb_visual (TerminalWindow *window);
+GtkWidget* terminal_window_get_mdi_container (TerminalWindow *window);
void terminal_window_save_state (TerminalWindow *window,
GKeyFile *key_file,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]