[gimp] Remove all code from gimp_display_shell_new()



commit deed1636f92a02d9fd6b8e1d5616f29bc02ffb63
Author: Michael Natterer <mitch gimp org>
Date:   Sun Nov 1 18:18:17 2009 +0100

    Remove all code from gimp_display_shell_new()
    
    Move the entire widget construction code to constructor().

 app/display/gimpdisplayshell.c |  768 ++++++++++++++++++++--------------------
 1 files changed, 385 insertions(+), 383 deletions(-)
---
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 5282320..ea14a33 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -126,14 +126,19 @@ static gboolean  gimp_display_shell_popup_menu     (GtkWidget        *widget);
 
 static void      gimp_display_shell_real_scaled    (GimpDisplayShell *shell);
 
+static const guint8 * gimp_display_shell_get_icc_profile
+                                                   (GimpColorManaged *managed,
+                                                    gsize            *len);
+
 static void      gimp_display_shell_menu_position  (GtkMenu          *menu,
                                                     gint             *x,
                                                     gint             *y,
                                                     gpointer          data);
-
-static const guint8 * gimp_display_shell_get_icc_profile
-                                                   (GimpColorManaged *managed,
-                                                    gsize            *len);
+static void      gimp_display_shell_zoom_button_callback
+                                                   (GimpDisplayShell *shell,
+                                                    GtkWidget        *zoom_button);
+static void      gimp_display_shell_sync_config    (GimpDisplayShell  *shell,
+                                                    GimpDisplayConfig *config);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpDisplayShell, gimp_display_shell,
@@ -245,6 +250,12 @@ gimp_display_shell_class_init (GimpDisplayShellClass *klass)
 }
 
 static void
+gimp_color_managed_iface_init (GimpColorManagedInterface *iface)
+{
+  iface->get_icc_profile = gimp_display_shell_get_icc_profile;
+}
+
+static void
 gimp_display_shell_init (GimpDisplayShell *shell)
 {
   shell->options            = g_object_new (GIMP_TYPE_DISPLAY_OPTIONS, NULL);
@@ -306,372 +317,14 @@ gimp_display_shell_init (GimpDisplayShell *shell)
                      GIMP_HELP_IMAGE_WINDOW, NULL);
 }
 
-static void
-gimp_color_managed_iface_init (GimpColorManagedInterface *iface)
-{
-  iface->get_icc_profile = gimp_display_shell_get_icc_profile;
-}
-
 static GObject *
 gimp_display_shell_constructor (GType                  type,
                                 guint                  n_params,
                                 GObjectConstructParam *params)
 {
-  GObject          *object;
-  GimpDisplayShell *shell;
-
-  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
-
-  shell = GIMP_DISPLAY_SHELL (object);
-
-  g_assert (GIMP_IS_UI_MANAGER (shell->popup_manager));
-  g_assert (GIMP_IS_DISPLAY (shell->display));
-
-  return object;
-}
-
-static void
-gimp_display_shell_finalize (GObject *object)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
-
-  g_object_unref (shell->zoom);
-
-  if (shell->options)
-    g_object_unref (shell->options);
-
-  if (shell->fullscreen_options)
-    g_object_unref (shell->fullscreen_options);
-
-  if (shell->no_image_options)
-    g_object_unref (shell->no_image_options);
-
-  if (shell->title)
-    g_free (shell->title);
-
-  if (shell->status)
-    g_free (shell->status);
-
-  if (shell->icon)
-    g_object_unref (shell->icon);
-
-  G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-gimp_display_shell_set_property (GObject      *object,
-                                 guint         property_id,
-                                 const GValue *value,
-                                 GParamSpec   *pspec)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
-
-  switch (property_id)
-    {
-    case PROP_POPUP_MANAGER:
-      shell->popup_manager = g_value_get_object (value);
-      break;
-    case PROP_DISPLAY:
-      shell->display = g_value_get_object (value);
-      break;
-    case PROP_UNIT:
-      gimp_display_shell_set_unit (shell, g_value_get_int (value));
-      break;
-    case PROP_TITLE:
-      g_free (shell->title);
-      shell->title = g_value_dup_string (value);
-      break;
-    case PROP_STATUS:
-      g_free (shell->status);
-      shell->status = g_value_dup_string (value);
-      break;
-    case PROP_ICON:
-      if (shell->icon)
-        g_object_unref (shell->icon);
-      shell->icon = g_value_dup_object (value);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
-    }
-}
-
-static void
-gimp_display_shell_get_property (GObject    *object,
-                                 guint       property_id,
-                                 GValue     *value,
-                                 GParamSpec *pspec)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
-
-  switch (property_id)
-    {
-    case PROP_POPUP_MANAGER:
-      g_value_set_object (value, shell->popup_manager);
-      break;
-    case PROP_DISPLAY:
-      g_value_set_object (value, shell->display);
-      break;
-    case PROP_UNIT:
-      g_value_set_int (value, shell->unit);
-      break;
-    case PROP_TITLE:
-      g_value_set_string (value, shell->title);
-      break;
-    case PROP_STATUS:
-      g_value_set_string (value, shell->status);
-      break;
-    case PROP_ICON:
-      g_value_set_object (value, shell->icon);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
-    }
-}
-
-static void
-gimp_display_shell_destroy (GtkObject *object)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
-
-  if (shell->display && gimp_display_get_shell (shell->display))
-    gimp_display_shell_disconnect (shell);
-
-  shell->popup_manager = NULL;
-
-  gimp_display_shell_selection_free (shell);
-
-  if (shell->filter_stack)
-    gimp_display_shell_filter_set (shell, NULL);
-
-  if (shell->filter_idle_id)
-    {
-      g_source_remove (shell->filter_idle_id);
-      shell->filter_idle_id = 0;
-    }
-
-  if (shell->render_buf)
-    {
-      g_free (shell->render_buf);
-      shell->render_buf = NULL;
-    }
-
-  if (shell->highlight)
-    {
-      g_slice_free (GdkRectangle, shell->highlight);
-      shell->highlight = NULL;
-    }
-
-  if (shell->mask)
-    {
-      g_object_unref (shell->mask);
-      shell->mask = NULL;
-    }
-
-  if (shell->event_history)
-    {
-      g_array_free (shell->event_history, TRUE);
-      shell->event_history = NULL;
-    }
-
-  if (shell->event_queue)
-    {
-      g_array_free (shell->event_queue, TRUE);
-      shell->event_queue = NULL;
-    }
-
-  if (shell->title_idle_id)
-    {
-      g_source_remove (shell->title_idle_id);
-      shell->title_idle_id = 0;
-    }
-
-  if (shell->fill_idle_id)
-    {
-      g_source_remove (shell->fill_idle_id);
-      shell->fill_idle_id = 0;
-    }
-
-  if (shell->nav_popup)
-    {
-      gtk_widget_destroy (shell->nav_popup);
-      shell->nav_popup = NULL;
-    }
-
-  if (shell->grid_dialog)
-    {
-      gtk_widget_destroy (shell->grid_dialog);
-      shell->grid_dialog = NULL;
-    }
-
-  shell->display = NULL;
-
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
-}
-
-static void
-gimp_display_shell_unrealize (GtkWidget *widget)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
-
-  if (shell->grid_gc)
-    {
-      g_object_unref (shell->grid_gc);
-      shell->grid_gc = NULL;
-    }
-
-  if (shell->pen_gc)
-    {
-      g_object_unref (shell->pen_gc);
-      shell->pen_gc = NULL;
-    }
-
-  if (shell->nav_popup)
-    gtk_widget_unrealize (shell->nav_popup);
-
-  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
-}
-
-static void
-gimp_display_shell_screen_changed (GtkWidget *widget,
-                                   GdkScreen *previous)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
-
-  if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
-    GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous);
-
-  if (shell->display->config->monitor_res_from_gdk)
-    {
-      gimp_get_screen_resolution (gtk_widget_get_screen (widget),
-                                  &shell->monitor_xres,
-                                  &shell->monitor_yres);
-    }
-  else
-    {
-      shell->monitor_xres = shell->display->config->monitor_xres;
-      shell->monitor_yres = shell->display->config->monitor_yres;
-    }
-}
-
-static gboolean
-gimp_display_shell_popup_menu (GtkWidget *widget)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
-
-  gimp_context_set_display (gimp_get_user_context (shell->display->gimp),
-                            shell->display);
-
-  gimp_ui_manager_ui_popup (shell->popup_manager, "/dummy-menubar/image-popup",
-                            GTK_WIDGET (shell),
-                            gimp_display_shell_menu_position,
-                            shell->origin,
-                            NULL, NULL);
-
-  return TRUE;
-}
-
-static void
-gimp_display_shell_real_scaled (GimpDisplayShell *shell)
-{
-  GimpContext *user_context;
-
-  if (! shell->display)
-    return;
-
-  gimp_display_shell_title_update (shell);
-
-  user_context = gimp_get_user_context (shell->display->gimp);
-
-  if (shell->display == gimp_context_get_display (user_context))
-    gimp_ui_manager_update (shell->popup_manager, shell->display);
-}
-
-static void
-gimp_display_shell_menu_position (GtkMenu  *menu,
-                                  gint     *x,
-                                  gint     *y,
-                                  gpointer  data)
-{
-  gimp_button_menu_position (GTK_WIDGET (data), menu, GTK_POS_RIGHT, x, y);
-}
-
-static const guint8 *
-gimp_display_shell_get_icc_profile (GimpColorManaged *managed,
-                                    gsize            *len)
-{
-  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (managed);
-  GimpImage        *image = gimp_display_get_image (shell->display);
-
-  if (image)
-    return gimp_color_managed_get_icc_profile (GIMP_COLOR_MANAGED (image), len);
-
-  return NULL;
-}
-
-static void
-gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell,
-                                         GtkWidget        *zoom_button)
-{
-  shell->zoom_on_resize =
-    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (zoom_button));
-
-  if (shell->zoom_on_resize &&
-      gimp_display_shell_scale_image_is_within_viewport (shell, NULL, NULL))
-    {
-      /* Implicitly make a View -> Fit Image in Window */
-      gimp_display_shell_scale_fit_in (shell);
-    }
-}
-
-static void
-gimp_display_shell_sync_config (GimpDisplayShell  *shell,
-                                GimpDisplayConfig *config)
-{
-  gimp_config_sync (G_OBJECT (config->default_view),
-                    G_OBJECT (shell->options), 0);
-  gimp_config_sync (G_OBJECT (config->default_fullscreen_view),
-                    G_OBJECT (shell->fullscreen_options), 0);
-
-  if (shell->display && gimp_display_get_shell (shell->display))
-    {
-      /*  if the shell is already fully constructed, use proper API
-       *  so the actions are updated accordingly.
-       */
-      gimp_display_shell_set_snap_to_guides  (shell,
-                                              config->default_snap_to_guides);
-      gimp_display_shell_set_snap_to_grid    (shell,
-                                              config->default_snap_to_grid);
-      gimp_display_shell_set_snap_to_canvas  (shell,
-                                              config->default_snap_to_canvas);
-      gimp_display_shell_set_snap_to_vectors (shell,
-                                              config->default_snap_to_path);
-    }
-  else
-    {
-      /*  otherwise the shell is currently being constructed and
-       *  display->shell is NULL.
-       */
-      shell->snap_to_guides  = config->default_snap_to_guides;
-      shell->snap_to_grid    = config->default_snap_to_grid;
-      shell->snap_to_canvas  = config->default_snap_to_canvas;
-      shell->snap_to_vectors = config->default_snap_to_path;
-    }
-}
-
-
-/*  public functions  */
-
-GtkWidget *
-gimp_display_shell_new (GimpDisplay       *display,
-                        GimpUnit           unit,
-                        gdouble            scale,
-                        GimpUIManager     *popup_manager)
-{
+  GObject               *object;
   GimpDisplayShell      *shell;
+  GimpDisplayConfig     *config;
   GimpImage             *image;
   GimpColorDisplayStack *filter;
   GtkWidget             *upper_hbox;
@@ -686,17 +339,15 @@ gimp_display_shell_new (GimpDisplay       *display,
   gint                   shell_width;
   gint                   shell_height;
 
-  g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
-  g_return_val_if_fail (GIMP_IS_UI_MANAGER (popup_manager), NULL);
+  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
-  /*  the toplevel shell */
-  shell = g_object_new (GIMP_TYPE_DISPLAY_SHELL,
-                        "popup-manager", popup_manager,
-                        "display",       display,
-                        "unit",          unit,
-                        NULL);
+  shell = GIMP_DISPLAY_SHELL (object);
+
+  g_assert (GIMP_IS_UI_MANAGER (shell->popup_manager));
+  g_assert (GIMP_IS_DISPLAY (shell->display));
 
-  image = gimp_display_get_image (display);
+  config = shell->display->config;
+  image  = gimp_display_get_image (shell->display);
 
   if (image)
     {
@@ -713,25 +364,25 @@ gimp_display_shell_new (GimpDisplay       *display,
       image_height = GIMP_DEFAULT_IMAGE_HEIGHT / 3;
     }
 
-  shell->dot_for_dot = display->config->default_dot_for_dot;
+  shell->dot_for_dot = config->default_dot_for_dot;
 
   screen = gtk_widget_get_screen (GTK_WIDGET (shell));
 
-  if (display->config->monitor_res_from_gdk)
+  if (config->monitor_res_from_gdk)
     {
       gimp_get_screen_resolution (screen,
                                   &shell->monitor_xres, &shell->monitor_yres);
     }
   else
     {
-      shell->monitor_xres = display->config->monitor_xres;
-      shell->monitor_yres = display->config->monitor_yres;
+      shell->monitor_xres = config->monitor_xres;
+      shell->monitor_yres = config->monitor_yres;
     }
 
   /* adjust the initial scale -- so that window fits on screen. */
   if (image)
     {
-      gimp_display_shell_set_initial_scale (shell, scale,
+      gimp_display_shell_set_initial_scale (shell, 1.0, //scale,
                                             &shell_width, &shell_height);
     }
   else
@@ -740,7 +391,7 @@ gimp_display_shell_new (GimpDisplay       *display,
       shell_height = image_height;
     }
 
-  gimp_display_shell_sync_config (shell, display->config);
+  gimp_display_shell_sync_config (shell, config);
 
   /*  GtkTable widgets are not able to shrink a row/column correctly if
    *  widgets are attached with GTK_EXPAND even if those widgets have
@@ -833,7 +484,7 @@ gimp_display_shell_new (GimpDisplay       *display,
                            _("Access the image menu"),
                            GIMP_HELP_IMAGE_WINDOW_ORIGIN);
 
-  shell->canvas = gimp_canvas_new (display->config);
+  shell->canvas = gimp_canvas_new (config);
   gtk_widget_set_size_request (shell->canvas, shell_width, shell_height);
   gtk_container_set_border_width (GTK_CONTAINER (shell->canvas), 10);
 
@@ -960,7 +611,7 @@ gimp_display_shell_new (GimpDisplay       *display,
   gtk_container_add (GTK_CONTAINER (shell->quick_mask_button), gtk_image);
   gtk_widget_show (gtk_image);
 
-  action = gimp_ui_manager_find_action (popup_manager,
+  action = gimp_ui_manager_find_action (shell->popup_manager,
                                         "quick-mask", "quick-mask-toggle");
   if (action)
     gimp_widget_set_accel_help (shell->quick_mask_button, action);
@@ -1034,7 +685,7 @@ gimp_display_shell_new (GimpDisplay       *display,
   /*  add display filter for color management  */
 
   filter = gimp_display_shell_filter_new (shell,
-                                          display->gimp->config->color_management);
+                                          GIMP_CORE_CONFIG (config)->color_management);
 
   if (filter)
     {
@@ -1066,7 +717,358 @@ gimp_display_shell_new (GimpDisplay       *display,
   /* make sure the information is up-to-date */
   gimp_display_shell_scale_changed (shell);
 
-  return GTK_WIDGET (shell);
+  return object;
+}
+
+static void
+gimp_display_shell_finalize (GObject *object)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
+
+  g_object_unref (shell->zoom);
+
+  if (shell->options)
+    g_object_unref (shell->options);
+
+  if (shell->fullscreen_options)
+    g_object_unref (shell->fullscreen_options);
+
+  if (shell->no_image_options)
+    g_object_unref (shell->no_image_options);
+
+  if (shell->title)
+    g_free (shell->title);
+
+  if (shell->status)
+    g_free (shell->status);
+
+  if (shell->icon)
+    g_object_unref (shell->icon);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gimp_display_shell_set_property (GObject      *object,
+                                 guint         property_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
+
+  switch (property_id)
+    {
+    case PROP_POPUP_MANAGER:
+      shell->popup_manager = g_value_get_object (value);
+      break;
+    case PROP_DISPLAY:
+      shell->display = g_value_get_object (value);
+      break;
+    case PROP_UNIT:
+      gimp_display_shell_set_unit (shell, g_value_get_int (value));
+      break;
+    case PROP_TITLE:
+      g_free (shell->title);
+      shell->title = g_value_dup_string (value);
+      break;
+    case PROP_STATUS:
+      g_free (shell->status);
+      shell->status = g_value_dup_string (value);
+      break;
+    case PROP_ICON:
+      if (shell->icon)
+        g_object_unref (shell->icon);
+      shell->icon = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_display_shell_get_property (GObject    *object,
+                                 guint       property_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
+
+  switch (property_id)
+    {
+    case PROP_POPUP_MANAGER:
+      g_value_set_object (value, shell->popup_manager);
+      break;
+    case PROP_DISPLAY:
+      g_value_set_object (value, shell->display);
+      break;
+    case PROP_UNIT:
+      g_value_set_int (value, shell->unit);
+      break;
+    case PROP_TITLE:
+      g_value_set_string (value, shell->title);
+      break;
+    case PROP_STATUS:
+      g_value_set_string (value, shell->status);
+      break;
+    case PROP_ICON:
+      g_value_set_object (value, shell->icon);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_display_shell_destroy (GtkObject *object)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
+
+  if (shell->display && gimp_display_get_shell (shell->display))
+    gimp_display_shell_disconnect (shell);
+
+  shell->popup_manager = NULL;
+
+  gimp_display_shell_selection_free (shell);
+
+  if (shell->filter_stack)
+    gimp_display_shell_filter_set (shell, NULL);
+
+  if (shell->filter_idle_id)
+    {
+      g_source_remove (shell->filter_idle_id);
+      shell->filter_idle_id = 0;
+    }
+
+  if (shell->render_buf)
+    {
+      g_free (shell->render_buf);
+      shell->render_buf = NULL;
+    }
+
+  if (shell->highlight)
+    {
+      g_slice_free (GdkRectangle, shell->highlight);
+      shell->highlight = NULL;
+    }
+
+  if (shell->mask)
+    {
+      g_object_unref (shell->mask);
+      shell->mask = NULL;
+    }
+
+  if (shell->event_history)
+    {
+      g_array_free (shell->event_history, TRUE);
+      shell->event_history = NULL;
+    }
+
+  if (shell->event_queue)
+    {
+      g_array_free (shell->event_queue, TRUE);
+      shell->event_queue = NULL;
+    }
+
+  if (shell->title_idle_id)
+    {
+      g_source_remove (shell->title_idle_id);
+      shell->title_idle_id = 0;
+    }
+
+  if (shell->fill_idle_id)
+    {
+      g_source_remove (shell->fill_idle_id);
+      shell->fill_idle_id = 0;
+    }
+
+  if (shell->nav_popup)
+    {
+      gtk_widget_destroy (shell->nav_popup);
+      shell->nav_popup = NULL;
+    }
+
+  if (shell->grid_dialog)
+    {
+      gtk_widget_destroy (shell->grid_dialog);
+      shell->grid_dialog = NULL;
+    }
+
+  shell->display = NULL;
+
+  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+static void
+gimp_display_shell_unrealize (GtkWidget *widget)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
+
+  if (shell->grid_gc)
+    {
+      g_object_unref (shell->grid_gc);
+      shell->grid_gc = NULL;
+    }
+
+  if (shell->pen_gc)
+    {
+      g_object_unref (shell->pen_gc);
+      shell->pen_gc = NULL;
+    }
+
+  if (shell->nav_popup)
+    gtk_widget_unrealize (shell->nav_popup);
+
+  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+}
+
+static void
+gimp_display_shell_screen_changed (GtkWidget *widget,
+                                   GdkScreen *previous)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
+
+  if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
+    GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous);
+
+  if (shell->display->config->monitor_res_from_gdk)
+    {
+      gimp_get_screen_resolution (gtk_widget_get_screen (widget),
+                                  &shell->monitor_xres,
+                                  &shell->monitor_yres);
+    }
+  else
+    {
+      shell->monitor_xres = shell->display->config->monitor_xres;
+      shell->monitor_yres = shell->display->config->monitor_yres;
+    }
+}
+
+static gboolean
+gimp_display_shell_popup_menu (GtkWidget *widget)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
+
+  gimp_context_set_display (gimp_get_user_context (shell->display->gimp),
+                            shell->display);
+
+  gimp_ui_manager_ui_popup (shell->popup_manager, "/dummy-menubar/image-popup",
+                            GTK_WIDGET (shell),
+                            gimp_display_shell_menu_position,
+                            shell->origin,
+                            NULL, NULL);
+
+  return TRUE;
+}
+
+static void
+gimp_display_shell_real_scaled (GimpDisplayShell *shell)
+{
+  GimpContext *user_context;
+
+  if (! shell->display)
+    return;
+
+  gimp_display_shell_title_update (shell);
+
+  user_context = gimp_get_user_context (shell->display->gimp);
+
+  if (shell->display == gimp_context_get_display (user_context))
+    gimp_ui_manager_update (shell->popup_manager, shell->display);
+}
+
+static const guint8 *
+gimp_display_shell_get_icc_profile (GimpColorManaged *managed,
+                                    gsize            *len)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (managed);
+  GimpImage        *image = gimp_display_get_image (shell->display);
+
+  if (image)
+    return gimp_color_managed_get_icc_profile (GIMP_COLOR_MANAGED (image), len);
+
+  return NULL;
+}
+
+static void
+gimp_display_shell_menu_position (GtkMenu  *menu,
+                                  gint     *x,
+                                  gint     *y,
+                                  gpointer  data)
+{
+  gimp_button_menu_position (GTK_WIDGET (data), menu, GTK_POS_RIGHT, x, y);
+}
+
+static void
+gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell,
+                                         GtkWidget        *zoom_button)
+{
+  shell->zoom_on_resize =
+    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (zoom_button));
+
+  if (shell->zoom_on_resize &&
+      gimp_display_shell_scale_image_is_within_viewport (shell, NULL, NULL))
+    {
+      /* Implicitly make a View -> Fit Image in Window */
+      gimp_display_shell_scale_fit_in (shell);
+    }
+}
+
+static void
+gimp_display_shell_sync_config (GimpDisplayShell  *shell,
+                                GimpDisplayConfig *config)
+{
+  gimp_config_sync (G_OBJECT (config->default_view),
+                    G_OBJECT (shell->options), 0);
+  gimp_config_sync (G_OBJECT (config->default_fullscreen_view),
+                    G_OBJECT (shell->fullscreen_options), 0);
+
+  if (shell->display && gimp_display_get_shell (shell->display))
+    {
+      /*  if the shell is already fully constructed, use proper API
+       *  so the actions are updated accordingly.
+       */
+      gimp_display_shell_set_snap_to_guides  (shell,
+                                              config->default_snap_to_guides);
+      gimp_display_shell_set_snap_to_grid    (shell,
+                                              config->default_snap_to_grid);
+      gimp_display_shell_set_snap_to_canvas  (shell,
+                                              config->default_snap_to_canvas);
+      gimp_display_shell_set_snap_to_vectors (shell,
+                                              config->default_snap_to_path);
+    }
+  else
+    {
+      /*  otherwise the shell is currently being constructed and
+       *  display->shell is NULL.
+       */
+      shell->snap_to_guides  = config->default_snap_to_guides;
+      shell->snap_to_grid    = config->default_snap_to_grid;
+      shell->snap_to_canvas  = config->default_snap_to_canvas;
+      shell->snap_to_vectors = config->default_snap_to_path;
+    }
+}
+
+
+/*  public functions  */
+
+GtkWidget *
+gimp_display_shell_new (GimpDisplay       *display,
+                        GimpUnit           unit,
+                        gdouble            scale,
+                        GimpUIManager     *popup_manager)
+{
+  g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
+  g_return_val_if_fail (GIMP_IS_UI_MANAGER (popup_manager), NULL);
+
+  return g_object_new (GIMP_TYPE_DISPLAY_SHELL,
+                       "popup-manager", popup_manager,
+                       "display",       display,
+                       "unit",          unit,
+                       NULL);
 }
 
 GimpImageWindow *



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