[gnome-terminal] Add TerminalScreenContainer



commit e68fd8433844d54fe643bb92cfafa9d3b89c9b89
Author: Christian Persch <chpe gnome org>
Date:   Sun Feb 21 20:02:26 2010 +0100

    Add TerminalScreenContainer
    
    Make the terminal screen container a real GObject.

 src/terminal-screen-container.c |  412 ++++++++++++++++++++++++++++++++-------
 src/terminal-screen-container.h |   36 +++-
 src/terminal-screen.c           |  123 +++++--------
 src/terminal-tabs-menu.c        |   10 +-
 src/terminal-window.c           |   14 +-
 5 files changed, 427 insertions(+), 168 deletions(-)
---
diff --git a/src/terminal-screen-container.c b/src/terminal-screen-container.c
index 455dcba..2516d4d 100644
--- a/src/terminal-screen-container.c
+++ b/src/terminal-screen-container.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2008 Christian Persch
+ * Copyright © 2008, 2010 Christian Persch
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,131 +17,393 @@
  * Boston, MA 02111-1307, USA.
  */
 
-
 #include <config.h>
 
 #include "terminal-screen-container.h"
+#include "terminal-debug.h"
+#include "terminal-intl.h"
 
-#define SCREEN_DATA_KEY    "TSC::Screen"
-#define SCROLLBAR_DATA_KEY "TSC::Scrollbar"
+#include <gtk/gtk.h>
 
-GtkWidget *
-terminal_screen_container_new (TerminalScreen *screen)
+#define TERMINAL_SCREEN_CONTAINER_GET_PRIVATE(screen_container)(G_TYPE_INSTANCE_GET_PRIVATE ((screen_container), TERMINAL_TYPE_SCREEN_CONTAINER, TerminalScreenContainerPrivate))
+
+struct _TerminalScreenContainerPrivate
 {
+  TerminalScreen *screen;
 #ifdef USE_SCROLLED_WINDOW
   GtkWidget *scrolled_window;
+#else
+  GtkWidget *hbox;
+  GtkWidget *vscrollbar;
+#endif
+  GtkPolicyType hscrollbar_policy;
+  GtkPolicyType vscrollbar_policy;
+  GtkCornerType window_placement;
+  guint window_placement_set : 1;
+};
 
-  g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
+enum
+{
+  PROP_0,
+  PROP_SCREEN,
+  PROP_HSCROLLBAR_POLICY,
+  PROP_VSCROLLBAR_POLICY,
+  PROP_WINDOW_PLACEMENT,
+  PROP_WINDOW_PLACEMENT_SET
+};
 
-  scrolled_window = gtk_scrolled_window_new (NULL, vte_terminal_get_adjustment (VTE_TERMINAL (screen)));
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
-                                  GTK_POLICY_AUTOMATIC,
-                                  GTK_POLICY_AUTOMATIC);
-  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
-                                       GTK_SHADOW_NONE);
-  gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (screen));
-  gtk_widget_show (GTK_WIDGET (screen));
+G_DEFINE_TYPE (TerminalScreenContainer, terminal_screen_container, GTK_TYPE_VBOX)
 
-  _terminal_screen_update_scrollbar (screen);
-  return scrolled_window;
-#else
-  GtkWidget *hbox, *scrollbar;
+/* helper functions */
 
-  g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
+static void
+terminal_screen_container_set_placement_internal (TerminalScreenContainer *container,
+                                                  GtkCornerType corner)
+{
+  TerminalScreenContainerPrivate *priv = container->priv;
+
+#ifdef USE_SCROLLED_WINDOW
+  gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (priv->scrolled_window), corner);
+#else
+  switch (corner) {
+    case GTK_CORNER_TOP_LEFT:
+    case GTK_CORNER_BOTTOM_LEFT:
+      gtk_box_reorder_child (GTK_BOX (priv->hbox), priv->vscrollbar, 1);
+      break;
+    case GTK_CORNER_TOP_RIGHT:
+    case GTK_CORNER_BOTTOM_RIGHT:
+      gtk_box_reorder_child (GTK_BOX (priv->hbox), priv->vscrollbar, 0);
+      break;
+    default:
+      g_assert_not_reached ();
+  }
+#endif
 
-  hbox = gtk_hbox_new (FALSE, 0);
+  priv->window_placement = corner;
+  g_object_notify (G_OBJECT (container), "window-placement");
+}
 
-  scrollbar = gtk_vscrollbar_new (vte_terminal_get_adjustment (VTE_TERMINAL (screen)));
+static void
+terminal_screen_container_set_placement_set (TerminalScreenContainer *container,
+                                             gboolean set)
+{
+  TerminalScreenContainerPrivate *priv = container->priv;
 
-  gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (screen), TRUE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (hbox), scrollbar, FALSE, FALSE, 0);
+#ifdef USE_SCROLLED_WINDOW
+  g_object_set (priv->scrolled_window, "window-placement-set", set, NULL);
+#endif
 
-  g_object_set_data (G_OBJECT (hbox), SCREEN_DATA_KEY, screen);
-  g_object_set_data (G_OBJECT (hbox), SCROLLBAR_DATA_KEY, scrollbar);
-  
-  gtk_widget_show_all (hbox);
+  priv->window_placement_set = set != FALSE;
+  g_object_notify (G_OBJECT (container), "window-placement-set");
+}
 
-  _terminal_screen_update_scrollbar (screen);
-  return hbox;
+#if defined(USE_SCROLLED_WINDOW) && defined(GNOME_ENABLE_DEBUG)
+static void
+size_request_cb (GtkWidget *widget,
+                 GtkRequisition *req,
+                 TerminalScreenContainer *container)
+{
+  _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
+                         "[screen %p] scrolled-window size req %d : %d\n",
+                         container->priv->screen, req->width, req->height);
+}
 #endif
+
+/* Class implementation */
+
+static void
+terminal_screen_container_init (TerminalScreenContainer *container)
+{
+  TerminalScreenContainerPrivate *priv;
+
+  priv = container->priv = TERMINAL_SCREEN_CONTAINER_GET_PRIVATE (container);
+
+  priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
+  priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
+  priv->window_placement = GTK_CORNER_BOTTOM_RIGHT;
+  priv->window_placement_set = FALSE;
 }
 
-TerminalScreen *
-terminal_screen_container_get_screen (GtkWidget *container)
+static GObject *
+terminal_screen_container_constructor (GType type,
+                                guint n_construct_properties,
+                                GObjectConstructParam *construct_params)
 {
+  GObject *object;
+  TerminalScreenContainer *container;
+  TerminalScreenContainerPrivate *priv;
+
+  object = G_OBJECT_CLASS (terminal_screen_container_parent_class)->constructor
+             (type, n_construct_properties, construct_params);
+
+  container = TERMINAL_SCREEN_CONTAINER (object);
+  priv = container->priv;
+
+  g_assert (priv->screen != NULL);
+
 #ifdef USE_SCROLLED_WINDOW
-  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (container), NULL);
+  priv->scrolled_window = gtk_scrolled_window_new (NULL, vte_terminal_get_adjustment (VTE_TERMINAL (priv->screen)));
 
-  return TERMINAL_SCREEN (gtk_bin_get_child (GTK_BIN (container)));
-#else
-  g_return_val_if_fail (GTK_IS_HBOX (container), NULL);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                  priv->hscrollbar_policy,
+                                  priv->vscrollbar_policy);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                       GTK_SHADOW_NONE);
+  gtk_container_add (GTK_CONTAINER (priv->scrolled_window), GTK_WIDGET (priv->screen));
+  gtk_widget_show (GTK_WIDGET (priv->screen));
+  gtk_box_pack_end (GTK_BOX (container), priv->scrolled_window, TRUE, TRUE, 0);
+  gtk_widget_show (priv->scrolled_window);
 
-  return TERMINAL_SCREEN (g_object_get_data (G_OBJECT (container), SCREEN_DATA_KEY));
+#ifdef GNOME_ENABLE_DEBUG
+  g_signal_connect (priv->scrolled_window, "size-request", G_CALLBACK (size_request_cb), container);
 #endif
+
+#else
+
+  priv->hbox = gtk_hbox_new (FALSE, 0);
+
+  priv->vscrollbar = gtk_vscrollbar_new (vte_terminal_get_adjustment (VTE_TERMINAL (priv->screen)));
+
+  gtk_box_pack_start (GTK_BOX (priv->hbox), GTK_WIDGET (priv->screen), TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (priv->hbox), priv->vscrollbar, FALSE, FALSE, 0);
+
+  gtk_box_pack_end (GTK_BOX (container), priv->hbox, TRUE, TRUE, 0);
+  gtk_widget_show_all (priv->hbox);
+#endif /* USE_SCROLLED_WINDOW */
+
+  _terminal_screen_update_scrollbar (priv->screen);
+
+  return object;
 }
 
-#ifndef USE_SCROLLED_WINDOW
-static GtkWidget *
-terminal_screen_container_get_scrollbar (GtkWidget *container)
+static void
+terminal_screen_container_get_property (GObject *object,
+                                        guint prop_id,
+                                        GValue *value,
+                                        GParamSpec *pspec)
 {
-  return g_object_get_data (G_OBJECT (container), SCROLLBAR_DATA_KEY);
+  TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (object);
+  TerminalScreenContainerPrivate *priv = container->priv;
+
+  switch (prop_id) {
+    case PROP_SCREEN:
+      break;
+    case PROP_HSCROLLBAR_POLICY:
+      g_value_set_enum (value, priv->hscrollbar_policy);
+      break;
+    case PROP_VSCROLLBAR_POLICY:
+      g_value_set_enum (value, priv->vscrollbar_policy);
+      break;
+    case PROP_WINDOW_PLACEMENT:
+      g_value_set_enum (value, priv->window_placement);
+      break;
+    case PROP_WINDOW_PLACEMENT_SET:
+      g_value_set_boolean (value, priv->window_placement_set);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
 }
-#endif
 
+static void
+terminal_screen_container_set_property (GObject *object,
+                                        guint prop_id,
+                                        const GValue *value,
+                                        GParamSpec *pspec)
+{
+  TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (object);
+  TerminalScreenContainerPrivate *priv = container->priv;
+
+  switch (prop_id) {
+    case PROP_SCREEN:
+      priv->screen = g_value_get_object (value);
+      break;
+    case PROP_HSCROLLBAR_POLICY:
+      terminal_screen_container_set_policy (container,
+                                            g_value_get_enum (value),
+                                            priv->vscrollbar_policy);
+      break;
+    case PROP_VSCROLLBAR_POLICY:
+      terminal_screen_container_set_policy (container,
+                                            priv->hscrollbar_policy,
+                                            g_value_get_enum (value));
+      break;
+    case PROP_WINDOW_PLACEMENT:
+      terminal_screen_container_set_placement_internal (container, g_value_get_enum (value));
+      break;
+    case PROP_WINDOW_PLACEMENT_SET:
+      terminal_screen_container_set_placement_set (container, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+terminal_screen_container_class_init (TerminalScreenContainerClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (gobject_class, sizeof (TerminalScreenContainerPrivate));
+
+  gobject_class->constructor = terminal_screen_container_constructor;
+  gobject_class->get_property = terminal_screen_container_get_property;
+  gobject_class->set_property = terminal_screen_container_set_property;
+
+  g_object_class_install_property
+    (gobject_class,
+     PROP_SCREEN,
+     g_param_spec_object ("screen", NULL, NULL,
+                          TERMINAL_TYPE_SCREEN,
+                          G_PARAM_READWRITE |
+                          G_PARAM_CONSTRUCT_ONLY |
+                          G_PARAM_STATIC_STRINGS));
+
+   g_object_class_install_property
+    (gobject_class,
+     PROP_HSCROLLBAR_POLICY,
+     g_param_spec_enum ("hscrollbar-policy", NULL, NULL,
+                        GTK_TYPE_POLICY_TYPE,
+                        GTK_POLICY_AUTOMATIC,
+                        G_PARAM_READWRITE |
+                        G_PARAM_STATIC_STRINGS));
+   g_object_class_install_property
+    (gobject_class,
+     PROP_VSCROLLBAR_POLICY,
+     g_param_spec_enum ("vscrollbar-policy", NULL, NULL,
+                        GTK_TYPE_POLICY_TYPE,
+                        GTK_POLICY_AUTOMATIC,
+                        G_PARAM_READWRITE |
+                        G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property
+    (gobject_class,
+     PROP_WINDOW_PLACEMENT,
+     g_param_spec_enum ("window-placement", NULL, NULL,
+                        GTK_TYPE_CORNER_TYPE,
+                        GTK_CORNER_TOP_LEFT,
+                        G_PARAM_READWRITE |
+                        G_PARAM_STATIC_STRINGS));
+  
+  g_object_class_install_property
+    (gobject_class,
+     PROP_WINDOW_PLACEMENT_SET,
+     g_param_spec_boolean ("window-placement-set", NULL, NULL,
+                           FALSE,
+                           G_PARAM_READWRITE |
+                           G_PARAM_STATIC_STRINGS));
+}
+
+/* public API */
+
+/**
+ * terminal_screen_container_new:
+ * @screen: a #TerminalScreen
+ *
+ * Returns: a new #TerminalScreenContainer for @screen
+ */
+GtkWidget *
+terminal_screen_container_new (TerminalScreen *screen)
+{
+  return g_object_new (TERMINAL_TYPE_SCREEN_CONTAINER,
+                       "screen", screen,
+                       NULL);
+}
+
+/**
+ * terminal_screen_container_get_screen:
+ * @container: a #TerminalScreenContainer
+ *
+ * Returns: @container's #TerminalScreen
+ */
+TerminalScreen *
+terminal_screen_container_get_screen (TerminalScreenContainer *container)
+{
+  g_return_val_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container), NULL);
+
+  return container->priv->screen;
+}
+
+/**
+ * terminal_screen_container_get_from_screen:
+ * @screen: a #TerminalScreenContainerPrivate
+ *
+ * Returns the #TerminalScreenContainer containing @screen.
+ */
+TerminalScreenContainer *
+terminal_screen_container_get_from_screen (TerminalScreen *screen)
+{
+  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));
+}
+
+/**
+ * terminal_screen_container_set_policy:
+ * @container: a #TerminalScreenContainer
+ * @hpolicy: a #GtkPolicyType
+ * @vpolicy: a #GtkPolicyType
+ *
+ * Sets @container's scrollbar policy.
+ */
 void
-terminal_screen_container_set_policy (GtkWidget *container,
+terminal_screen_container_set_policy (TerminalScreenContainer *container,
                                       GtkPolicyType hpolicy G_GNUC_UNUSED,
                                       GtkPolicyType vpolicy)
 {
-#ifdef USE_SCROLLED_WINDOW
-  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
+  TerminalScreenContainerPrivate *priv;
+  GObject *object;
 
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (container), hpolicy, vpolicy);
-#else
-  GtkWidget *scrollbar;
+  g_return_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container));
 
-  g_return_if_fail (GTK_IS_HBOX (container));
+  object = G_OBJECT (container);
+  priv = container->priv;
 
-  scrollbar = terminal_screen_container_get_scrollbar (container);
+  g_object_freeze_notify (object);
+
+  if (priv->hscrollbar_policy != hpolicy) {
+    priv->hscrollbar_policy = hpolicy;
+    g_object_notify (object, "hscrollbar-policy");
+  }
+  if (priv->vscrollbar_policy != vpolicy) {
+    priv->vscrollbar_policy = vpolicy;
+    g_object_notify (object, "vscrollbar-policy");
+  }
+
+#ifdef USE_SCROLLED_WINDOW
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), hpolicy, vpolicy);
+#else
   switch (vpolicy) {
     case GTK_POLICY_NEVER:
-      gtk_widget_hide (scrollbar);
+      gtk_widget_hide (priv->vscrollbar);
       break;
     case GTK_POLICY_AUTOMATIC:
     case GTK_POLICY_ALWAYS:
-      gtk_widget_show (scrollbar);
+      gtk_widget_show (priv->vscrollbar);
       break;
     default:
       g_assert_not_reached ();
   }
 #endif
+
+  g_object_thaw_notify (object);
 }
 
+/**
+ * terminal_screen_container_set_placement:
+ * @container: a #TerminalScreenContainer
+ * @corner: a #GtkCornerType
+ *
+ * Sets @container's window placement.
+ */
 void
-terminal_screen_container_set_placement (GtkWidget *container,
+terminal_screen_container_set_placement (TerminalScreenContainer *container,
                                          GtkCornerType corner)
 {
-#ifdef USE_SCROLLED_WINDOW
-  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
-
-  gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (container), corner);
-#else
-  GtkWidget *scrollbar;
+  g_return_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container));
 
-  g_return_if_fail (GTK_IS_HBOX (container));
-
-  scrollbar = terminal_screen_container_get_scrollbar (container);
-  switch (corner) {
-    case GTK_CORNER_TOP_LEFT:
-    case GTK_CORNER_BOTTOM_LEFT:
-      gtk_box_reorder_child (GTK_BOX (container), scrollbar, 1);
-      break;
-    case GTK_CORNER_TOP_RIGHT:
-    case GTK_CORNER_BOTTOM_RIGHT:
-      gtk_box_reorder_child (GTK_BOX (container), scrollbar, 0);
-      break;
-    default:
-      g_assert_not_reached ();
-  }
-#endif
+  terminal_screen_container_set_placement_internal (container, corner);
+  terminal_screen_container_set_placement_set (container, TRUE);
 }
diff --git a/src/terminal-screen-container.h b/src/terminal-screen-container.h
index 1966a80..5e10da4 100644
--- a/src/terminal-screen-container.h
+++ b/src/terminal-screen-container.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2008 Christian Persch
+ * Copyright © 2008, 2010 Christian Persch
 *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -25,15 +25,43 @@
 
 G_BEGIN_DECLS
 
+#define TERMINAL_TYPE_SCREEN_CONTAINER         (terminal_screen_container_get_type ())
+#define TERMINAL_SCREEN_CONTAINER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_SCREEN_CONTAINER, TerminalScreenContainer))
+#define TERMINAL_SCREEN_CONTAINER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_SCREEN_CONTAINER, TerminalScreenContainerClass))
+#define TERMINAL_IS_SCREEN_CONTAINER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_SCREEN_CONTAINER))
+#define TERMINAL_IS_SCREEN_CONTAINER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_SCREEN_CONTAINER))
+#define TERMINAL_SCREEN_CONTAINER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_SCREEN_CONTAINER, TerminalScreenContainerClass))
+
+typedef struct _TerminalScreenContainer        TerminalScreenContainer;
+typedef struct _TerminalScreenContainerClass   TerminalScreenContainerClass;
+typedef struct _TerminalScreenContainerPrivate TerminalScreenContainerPrivate;
+
+struct _TerminalScreenContainer
+{
+  GtkVBox parent_instance;
+
+  /*< private >*/
+  TerminalScreenContainerPrivate *priv;
+};
+
+struct _TerminalScreenContainerClass
+{
+  GtkVBoxClass parent_class;
+};
+
+GType terminal_screen_container_get_type (void);
+
 GtkWidget *terminal_screen_container_new (TerminalScreen *screen);
 
-TerminalScreen *terminal_screen_container_get_screen (GtkWidget *container);
+TerminalScreen *terminal_screen_container_get_screen (TerminalScreenContainer *container);
+
+TerminalScreenContainer *terminal_screen_container_get_from_screen (TerminalScreen *screen);
 
-void terminal_screen_container_set_policy (GtkWidget *container,
+void terminal_screen_container_set_policy (TerminalScreenContainer *container,
                                            GtkPolicyType hpolicy,
                                            GtkPolicyType vpolicy);
 
-void terminal_screen_container_set_placement (GtkWidget *container,
+void terminal_screen_container_set_placement (TerminalScreenContainer *container,
                                               GtkCornerType corner);
 
 G_END_DECLS
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 0a8126e..259976f 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -55,7 +55,6 @@ typedef struct
 
 struct _TerminalScreenPrivate
 {
-  TerminalWindow *window;
   TerminalProfile *profile; /* may be NULL at times */
   guint profile_changed_id;
   guint profile_forgotten_id;
@@ -240,62 +239,6 @@ free_tag_data (TagData *tagdata)
   g_slice_free (TagData, tagdata);
 }
 
-#ifdef GNOME_ENABLE_DEBUG
-static void
-parent_size_request (GtkWidget *scrolled_window, GtkRequisition *req, GtkWidget *screen)
-{
-  _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
-                         "[screen %p] scrolled-window size req %d : %d\n",
-                         screen, req->width, req->height);
-}
-#endif
-
-static void
-parent_parent_set_cb (GtkWidget *widget,
-                      GtkWidget *old_parent,
-                      TerminalScreen *screen)
-{
-  TerminalScreenPrivate *priv = screen->priv;
-  GtkWidget *toplevel;
-
-  if (widget->parent)
-    {
-      g_return_if_fail (GTK_IS_NOTEBOOK (widget->parent));
-
-      toplevel = gtk_widget_get_toplevel (widget);
-#if GTK_CHECK_VERSION (2, 19, 3)
-      g_return_if_fail (gtk_widget_is_toplevel (toplevel));
-#else
-      g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel));
-#endif
-
-      priv->window = TERMINAL_WINDOW (toplevel);
-    }
-  else
-    priv->window = NULL;
-}
-
-static void
-parent_set_callback (GtkWidget *widget,
-                     GtkWidget *old_parent)
-{
-  if (old_parent)
-    g_signal_handlers_disconnect_by_func (old_parent, G_CALLBACK (parent_parent_set_cb), widget);
-
-  if (widget->parent)
-    g_signal_connect (widget->parent, "parent-set", G_CALLBACK (parent_parent_set_cb), widget);
-
-#ifdef GNOME_ENABLE_DEBUG
-  _TERMINAL_DEBUG_IF (TERMINAL_DEBUG_GEOMETRY)
-    {
-      if (old_parent)
-        g_signal_handlers_disconnect_by_func (old_parent, G_CALLBACK (parent_size_request), widget);
-      if (widget->parent)
-        g_signal_connect (widget->parent, "size-request", G_CALLBACK (parent_size_request), widget);
-    }
-#endif
-}
-
 static void
 terminal_screen_class_enable_menu_bar_accel_notify_cb (TerminalApp *app,
                                                        GParamSpec *pspec,
@@ -320,6 +263,35 @@ terminal_screen_class_enable_menu_bar_accel_notify_cb (TerminalApp *app,
     gtk_binding_entry_skip (binding_set, GDK_F10, GDK_SHIFT_MASK);
 }
 
+static TerminalWindow *
+terminal_screen_get_window (TerminalScreen *screen)
+{
+  GtkWidget *widget = GTK_WIDGET (screen);
+  GtkWidget *toplevel;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+#if GTK_CHECK_VERSION (2, 18, 0)
+  if (!gtk_widget_is_toplevel (toplevel))
+#else
+  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+#endif
+    return NULL;
+
+  return TERMINAL_WINDOW (toplevel);
+}
+
+static gboolean
+window_uses_argb_visual (TerminalScreen *screen)
+{
+  TerminalWindow *window;
+
+  window = terminal_screen_get_window (screen);
+  if (window == NULL || !GTK_WIDGET_REALIZED (window))
+    return FALSE;
+
+  return terminal_window_uses_argb_visual (window);
+}
+
 static void
 terminal_screen_realize (GtkWidget *widget)
 {
@@ -329,13 +301,11 @@ terminal_screen_realize (GtkWidget *widget)
 
   GTK_WIDGET_CLASS (terminal_screen_parent_class)->realize (widget);
 
-  g_assert (priv->window != NULL);
-
   /* FIXME: Don't enable this if we have a compmgr. */
   bg_type = terminal_profile_get_property_enum (priv->profile, TERMINAL_PROFILE_BACKGROUND_TYPE);
   vte_terminal_set_background_transparent (VTE_TERMINAL (screen),
                                            bg_type == TERMINAL_BACKGROUND_TRANSPARENT &&
-                                           !terminal_window_uses_argb_visual (priv->window));
+                                           !window_uses_argb_visual (screen));
 }
 
 static void
@@ -444,8 +414,6 @@ terminal_screen_init (TerminalScreen *screen)
   g_signal_connect (terminal_app_get (), "notify::system-font",
                     G_CALLBACK (terminal_screen_system_font_notify_cb), screen);
 
-  g_signal_connect (screen, "parent-set", G_CALLBACK (parent_set_callback), NULL);
-
 #ifdef GNOME_ENABLE_DEBUG
   _TERMINAL_DEBUG_IF (TERMINAL_DEBUG_GEOMETRY)
     {
@@ -939,6 +907,7 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
   VteTerminal *vte_terminal = VTE_TERMINAL (screen);
   const char *prop_name;
   TerminalBackgroundType bg_type;
+  TerminalWindow *window;
 
   if (pspec)
     prop_name = pspec->name;
@@ -947,12 +916,12 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
 
   g_object_freeze_notify (object);
 
-  if (priv->window)
+  if ((window = terminal_screen_get_window (screen)))
     {
       /* We need these in line for the set_size in
        * update_on_realize
        */
-      terminal_window_update_geometry (priv->window);
+      terminal_window_update_geometry (window);
     }
   
   if (!prop_name || prop_name == I_(TERMINAL_PROFILE_SCROLLBAR_POSITION))
@@ -1064,7 +1033,7 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
       /* FIXME: Don't enable this if we have a compmgr. */
       vte_terminal_set_background_transparent (vte_terminal,
                                                bg_type == TERMINAL_BACKGROUND_TRANSPARENT &&
-                                               (!priv->window || !terminal_window_uses_argb_visual (priv->window)));
+                                               !window_uses_argb_visual (screen));
     }
 
   if (!prop_name || prop_name == I_(TERMINAL_PROFILE_BACKSPACE_BINDING))
@@ -1180,11 +1149,12 @@ terminal_screen_system_font_notify_cb (TerminalApp *app,
 static void
 terminal_screen_change_font (TerminalScreen *screen)
 {
-  TerminalScreenPrivate *priv = screen->priv;
+  TerminalWindow *window;
 
   terminal_screen_set_font (screen);
 
-  terminal_window_set_size (priv->window, screen, TRUE);
+  window = terminal_screen_get_window (screen);
+  terminal_window_set_size (window, screen, TRUE);
 }
 
 static void
@@ -1541,13 +1511,12 @@ terminal_screen_launch_child_on_idle (TerminalScreen *screen)
 static TerminalScreenPopupInfo *
 terminal_screen_popup_info_new (TerminalScreen *screen)
 {
-  TerminalScreenPrivate *priv = screen->priv;
   TerminalScreenPopupInfo *info;
 
   info = g_slice_new0 (TerminalScreenPopupInfo);
   info->ref_count = 1;
   info->screen = g_object_ref (screen);
-  info->window = priv->window;
+  info->window = terminal_screen_get_window (screen);
 
   return info;
 }
@@ -2098,13 +2067,13 @@ terminal_screen_drag_data_received (GtkWidget        *widget,
         if (!GTK_IS_WIDGET (container))
           return;
 
-        moving_screen = terminal_screen_container_get_screen (container);
+        moving_screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
         g_return_if_fail (TERMINAL_IS_SCREEN (moving_screen));
         if (!TERMINAL_IS_SCREEN (moving_screen))
           return;
 
-        source_window = moving_screen->priv->window;
-        dest_window = screen->priv->window;
+        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));
@@ -2123,12 +2092,11 @@ void
 _terminal_screen_update_scrollbar (TerminalScreen *screen)
 {
   TerminalScreenPrivate *priv = screen->priv;
-  GtkWidget *parent;
+  TerminalScreenContainer *container;
   GtkPolicyType policy = GTK_POLICY_ALWAYS;
   GtkCornerType corner = GTK_CORNER_TOP_LEFT;
 
-  parent = GTK_WIDGET (screen)->parent;
-  if (!parent)
+  if (!GTK_WIDGET (screen)->parent)
     return;
 
   switch (terminal_profile_get_property_enum (priv->profile, TERMINAL_PROFILE_SCROLLBAR_POSITION))
@@ -2149,8 +2117,9 @@ _terminal_screen_update_scrollbar (TerminalScreen *screen)
       break;
     }
 
-  terminal_screen_container_set_placement (parent, corner);
-  terminal_screen_container_set_policy (parent, GTK_POLICY_NEVER, policy);
+  container = terminal_screen_container_get_from_screen (screen);
+  terminal_screen_container_set_placement (container, corner);
+  terminal_screen_container_set_policy (container, GTK_POLICY_NEVER, policy);
 }
 
 void
diff --git a/src/terminal-tabs-menu.c b/src/terminal-tabs-menu.c
index d003a1f..4c1f821 100644
--- a/src/terminal-tabs-menu.c
+++ b/src/terminal-tabs-menu.c
@@ -179,7 +179,7 @@ sync_tab_title (TerminalScreen *screen,
 
 static void
 notebook_page_added_cb (GtkNotebook *notebook,
-                        GtkWidget *container,
+                        TerminalScreenContainer *container,
 			guint position,
 			TerminalTabsMenu *menu)
 {
@@ -227,7 +227,7 @@ notebook_page_added_cb (GtkNotebook *notebook,
 
 static void
 notebook_page_removed_cb (GtkNotebook *notebook,
-                          GtkWidget *container,
+                          TerminalScreenContainer *container,
 			  guint position,
 			  TerminalTabsMenu *menu)
 {
@@ -269,11 +269,11 @@ notebook_page_switch_cb (GtkNotebook *notebook,
                          guint position,
                          TerminalTabsMenu *menu)
 {
-        GtkWidget *container;
+        TerminalScreenContainer *container;
         TerminalScreen *screen;
         GtkAction *action;
 
-        container = gtk_notebook_get_nth_page (notebook, position);
+        container = TERMINAL_SCREEN_CONTAINER (gtk_notebook_get_nth_page (notebook, position));
         screen = terminal_screen_container_get_screen (container);
 
 	action = g_object_get_data (G_OBJECT (screen), DATA_KEY);
@@ -459,7 +459,7 @@ terminal_tabs_menu_update (TerminalTabsMenu *menu)
 
 	for (l = tabs; l != NULL; l = l->next)
 	{
-                GtkWidget *container = l->data;
+                TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (l->data);
                 GObject *screen = G_OBJECT (terminal_screen_container_get_screen (container));
 
 		action = g_object_get_data (screen, DATA_KEY);
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 7afd625..3479ca2 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -1104,7 +1104,7 @@ handle_tab_droped_on_desktop (GtkNotebook *source_notebook,
   TerminalWindow *new_window;
   TerminalWindowPrivate *new_priv;
 
-  screen = terminal_screen_container_get_screen (container);
+  screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
   source_window = TERMINAL_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (source_notebook)));
   g_return_val_if_fail (TERMINAL_IS_WINDOW (source_window), NULL);
 
@@ -2268,7 +2268,7 @@ close_button_clicked_cb (GtkWidget *tab_label,
   window = TERMINAL_WINDOW (toplevel);
   priv = window->priv;
 
-  screen = terminal_screen_container_get_screen (screen_container);
+  screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (screen_container));
   if (confirm_close_window_or_tab (window, screen))
     return;
 
@@ -2615,7 +2615,7 @@ notebook_page_selected_callback (GtkWidget       *notebook,
     return;
 
   page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num);
-  screen = terminal_screen_container_get_screen (page_widget);
+  screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (page_widget));
   widget = GTK_WIDGET (screen);
   g_assert (screen != NULL);
 
@@ -2682,7 +2682,7 @@ notebook_page_added_callback (GtkWidget       *notebook,
   TerminalWindowPrivate *priv = window->priv;
   TerminalScreen *screen;
 
-  screen = terminal_screen_container_get_screen (container);
+  screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
 
   _terminal_debug_print (TERMINAL_DEBUG_MDI,
                          "[window %p] MDI: screen %p inserted\n",
@@ -2753,7 +2753,7 @@ notebook_page_removed_callback (GtkWidget       *notebook,
   if (priv->disposed)
     return;
 
-  screen = terminal_screen_container_get_screen (container);
+  screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (container));
 
   _terminal_debug_print (TERMINAL_DEBUG_MDI,
                          "[window %p] MDI: screen %p removed\n",
@@ -3015,7 +3015,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
         {
           TerminalScreen *terminal_screen;
 
-          terminal_screen = terminal_screen_container_get_screen ((GtkWidget *) t->data);
+          terminal_screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (t->data));
           if (terminal_screen_has_foreground_process (terminal_screen))
             {
               do_confirm = TRUE;
@@ -3768,7 +3768,7 @@ terminal_window_save_state (TerminalWindow *window,
       TerminalScreen *screen;
       char *tab_group;
 
-      screen = terminal_screen_container_get_screen (GTK_WIDGET (lt->data));
+      screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (lt->data));
 
       tab_group = g_strdup_printf ("Terminal%p", screen);
       g_ptr_array_add (tab_names_array, tab_group);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]