[gimp] Move shrink_wrap() from the display to the window



commit 32783d7228f25dc67ee98981b46a37d1a0e42361
Author: Michael Natterer <mitch gimp org>
Date:   Fri Sep 25 17:46:09 2009 +0200

    Move shrink_wrap() from the display to the window
    
    Also fix all callers. This clearly needs more cleanup.

 app/display/gimpdisplayshell-handlers.c |   14 +++-
 app/display/gimpdisplayshell-scale.c    |   21 +++++-
 app/display/gimpdisplayshell.c          |  107 ---------------------------
 app/display/gimpdisplayshell.h          |    3 -
 app/display/gimpimagewindow.c           |  122 +++++++++++++++++++++++++++++++
 app/display/gimpimagewindow.h           |    3 +
 6 files changed, 154 insertions(+), 116 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index a242744..926c371 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -500,10 +500,16 @@ gimp_display_shell_size_changed_detailed_handler (GimpImage        *image,
 {
   if (shell->display->config->resize_windows_on_resize)
     {
-      /* If the window is resized just center the image in it when it
-       * has change size
-       */
-      gimp_display_shell_shrink_wrap (shell, FALSE);
+      GtkWidget       *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (shell));
+      GimpImageWindow *window   = GIMP_IMAGE_WINDOW (toplevel);
+
+      if (gimp_image_window_get_active_display (window) == shell->display)
+        {
+          /* If the window is resized just center the image in it when it
+           * has change size
+           */
+          gimp_image_window_shrink_wrap (window, FALSE);
+        }
     }
   else
     {
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 2c1e10f..5439978 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -366,13 +366,22 @@ gimp_display_shell_scale (GimpDisplayShell *shell,
     {
       if (shell->display->config->resize_windows_on_zoom)
         {
+          GtkWidget       *toplevel;
+          GimpImageWindow *window;
+
+          toplevel = gtk_widget_get_toplevel (GTK_WIDGET (shell));
+          window   = GIMP_IMAGE_WINDOW (toplevel);
+
           /* If the window is resized on zoom, simply do the zoom and
            * get things rolling
            */
           gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, real_new_scale);
           gimp_display_shell_scaled (shell);
 
-          gimp_display_shell_shrink_wrap (shell, FALSE);
+          if (gimp_image_window_get_active_display (window) == shell->display)
+            {
+              gimp_image_window_shrink_wrap (window, FALSE);
+            }
         }
       else
         {
@@ -657,7 +666,15 @@ gimp_display_shell_scale_resize (GimpDisplayShell *shell,
   gimp_display_shell_pause (shell);
 
   if (resize_window)
-    gimp_display_shell_shrink_wrap (shell, grow_only);
+    {
+      GtkWidget       *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (shell));
+      GimpImageWindow *window   = GIMP_IMAGE_WINDOW (toplevel);
+
+      if (gimp_image_window_get_active_display (window) == shell->display)
+        {
+          gimp_image_window_shrink_wrap (window, grow_only);
+        }
+    }
 
   gimp_display_shell_scroll_clamp_and_update (shell);
   gimp_display_shell_scaled (shell);
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 2a66392..1aa712e 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -1727,113 +1727,6 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
     }
 }
 
-void
-gimp_display_shell_shrink_wrap (GimpDisplayShell *shell,
-                                gboolean          grow_only)
-{
-  GtkWidget    *widget;
-  GdkScreen    *screen;
-  GdkRectangle  rect;
-  gint          monitor;
-  gint          disp_width, disp_height;
-  gint          width, height;
-  gint          max_auto_width, max_auto_height;
-  gint          border_width, border_height;
-  gboolean      resize = FALSE;
-
-  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
-
-  if (! GTK_WIDGET_REALIZED (shell))
-    return;
-
-  widget = GTK_WIDGET (shell);
-  screen = gtk_widget_get_screen (widget);
-
-  monitor = gdk_screen_get_monitor_at_window (screen,
-                                              gtk_widget_get_window (widget));
-  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
-
-  width  = SCALEX (shell, gimp_image_get_width  (shell->display->image));
-  height = SCALEY (shell, gimp_image_get_height (shell->display->image));
-
-  disp_width  = shell->disp_width;
-  disp_height = shell->disp_height;
-
-
-  /* As long as the disp_width/disp_heightheight is larger than 1 we
-   * can reliably depend on it to calculate the
-   * border_width/border_height because that means there is enough
-   * room in the top-level for the canvas as well as the rulers and
-   * scrollbars. If it is 1 or smaller it is likely that the rulers
-   * and scrollbars are overlapping each other and thus we cannot use
-   * the normal approach to border size, so special case that.
-   */
-  if (disp_width > 1 || !shell->vsb)
-    border_width = widget->allocation.width - disp_width;
-  else
-    border_width = widget->allocation.width - disp_width + shell->vsb->allocation.width;
-
-  if (disp_height > 1 || !shell->hsb)
-    border_height = widget->allocation.height - disp_height;
-  else
-    border_height = widget->allocation.height - disp_height + shell->hsb->allocation.height;
-
-
-  max_auto_width  = (rect.width  - border_width)  * 0.75;
-  max_auto_height = (rect.height - border_height) * 0.75;
-
-  /* If one of the display dimensions has changed and one of the
-   * dimensions fits inside the screen
-   */
-  if (((width + border_width) < rect.width || (height + border_height) < rect.height) &&
-      (width != disp_width || height != disp_height))
-    {
-      width  = ((width  + border_width)  < rect.width)  ? width  : max_auto_width;
-      height = ((height + border_height) < rect.height) ? height : max_auto_height;
-
-      resize = TRUE;
-    }
-
-  /*  If the projected dimension is greater than current, but less than
-   *  3/4 of the screen size, expand automagically
-   */
-  else if ((width > disp_width || height > disp_height) &&
-           (disp_width < max_auto_width || disp_height < max_auto_height))
-    {
-      width  = MIN (max_auto_width,  width);
-      height = MIN (max_auto_height, height);
-
-      resize = TRUE;
-    }
-
-  if (resize)
-    {
-      /* FIXME image window */
-      if (width < GIMP_IMAGE_WINDOW (shell)->statusbar->requisition.width)
-        width = GIMP_IMAGE_WINDOW (shell)->statusbar->requisition.width;
-
-      width  = width  + border_width;
-      height = height + border_height;
-
-      if (grow_only)
-        {
-          if (width < widget->allocation.width)
-            width = widget->allocation.width;
-
-          if (height < widget->allocation.height)
-            height = widget->allocation.height;
-        }
-
-      gtk_window_resize (GTK_WINDOW (shell), width, height);
-    }
-
-  /* A wrap always means that we should center the image too. If the
-   * window changes size another center will be done in
-   * GimpDisplayShell::configure_event().
-   */
-  gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
-}
-
 /**
  * gimp_display_shell_set_highlight:
  * @shell:     a #GimpDisplayShell
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index 649fabe..1a9d3ef 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -277,9 +277,6 @@ void        gimp_display_shell_flush               (GimpDisplayShell   *shell,
 void        gimp_display_shell_pause               (GimpDisplayShell   *shell);
 void        gimp_display_shell_resume              (GimpDisplayShell   *shell);
 
-void        gimp_display_shell_shrink_wrap         (GimpDisplayShell   *shell,
-                                                    gboolean            grow_only);
-
 void        gimp_display_shell_set_highlight       (GimpDisplayShell   *shell,
                                                     const GdkRectangle *highlight);
 void        gimp_display_shell_set_mask            (GimpDisplayShell   *shell,
diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c
index e8e02b1..83f6293 100644
--- a/app/display/gimpimagewindow.c
+++ b/app/display/gimpimagewindow.c
@@ -20,10 +20,13 @@
 #include <gegl.h>
 #include <gtk/gtk.h>
 
+#include "libgimpmath/gimpmath.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
 #include "display-types.h"
 
+#include "core/gimpimage.h"
+
 #include "widgets/gimpactiongroup.h"
 #include "widgets/gimpdialogfactory.h"
 #include "widgets/gimphelp-ids.h"
@@ -37,6 +40,7 @@
 #include "gimpdisplayshell-appearance.h"
 #include "gimpdisplayshell-close.h"
 #include "gimpdisplayshell-progress.h"
+#include "gimpdisplayshell-scroll.h"
 #include "gimpimagewindow.h"
 #include "gimpstatusbar.h"
 
@@ -545,6 +549,124 @@ gimp_image_window_get_fullscreen (GimpImageWindow *window)
   return (window->window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
 }
 
+void
+gimp_image_window_shrink_wrap (GimpImageWindow *window,
+                               gboolean         grow_only)
+{
+  GimpDisplay      *active_display;
+  GimpDisplayShell *active_shell;
+  GtkWidget        *widget;
+  GdkScreen        *screen;
+  GdkRectangle      rect;
+  gint              monitor;
+  gint              disp_width, disp_height;
+  gint              width, height;
+  gint              max_auto_width, max_auto_height;
+  gint              border_width, border_height;
+  gboolean          resize = FALSE;
+
+  g_return_if_fail (GIMP_IS_IMAGE_WINDOW (window));
+
+  if (! GTK_WIDGET_REALIZED (window))
+    return;
+
+  /* FIXME this so needs cleanup and shell/window separation */
+
+  active_display = gimp_image_window_get_active_display (window);
+  active_shell   = GIMP_DISPLAY_SHELL (active_display->shell);
+
+  widget = GTK_WIDGET (window);
+  screen = gtk_widget_get_screen (widget);
+
+  monitor = gdk_screen_get_monitor_at_window (screen,
+                                              gtk_widget_get_window (widget));
+  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
+
+  width  = SCALEX (active_shell, gimp_image_get_width  (active_display->image));
+  height = SCALEY (active_shell, gimp_image_get_height (active_display->image));
+
+  disp_width  = active_shell->disp_width;
+  disp_height = active_shell->disp_height;
+
+
+  /* As long as the disp_width/disp_height is larger than 1 we
+   * can reliably depend on it to calculate the
+   * border_width/border_height because that means there is enough
+   * room in the top-level for the canvas as well as the rulers and
+   * scrollbars. If it is 1 or smaller it is likely that the rulers
+   * and scrollbars are overlapping each other and thus we cannot use
+   * the normal approach to border size, so special case that.
+   */
+  if (disp_width > 1 || !active_shell->vsb)
+    border_width = widget->allocation.width - disp_width;
+  else
+    border_width = widget->allocation.width - disp_width + active_shell->vsb->allocation.width;
+
+  if (disp_height > 1 || !active_shell->hsb)
+    border_height = widget->allocation.height - disp_height;
+  else
+    border_height = widget->allocation.height - disp_height + active_shell->hsb->allocation.height;
+
+
+  max_auto_width  = (rect.width  - border_width)  * 0.75;
+  max_auto_height = (rect.height - border_height) * 0.75;
+
+  /* If one of the display dimensions has changed and one of the
+   * dimensions fits inside the screen
+   */
+  if (((width  + border_width)  < rect.width ||
+       (height + border_height) < rect.height) &&
+      (width  != disp_width ||
+       height != disp_height))
+    {
+      width  = ((width  + border_width)  < rect.width)  ? width  : max_auto_width;
+      height = ((height + border_height) < rect.height) ? height : max_auto_height;
+
+      resize = TRUE;
+    }
+
+  /*  If the projected dimension is greater than current, but less than
+   *  3/4 of the screen size, expand automagically
+   */
+  else if ((width  > disp_width ||
+            height > disp_height) &&
+           (disp_width  < max_auto_width ||
+            disp_height < max_auto_height))
+    {
+      width  = MIN (max_auto_width,  width);
+      height = MIN (max_auto_height, height);
+
+      resize = TRUE;
+    }
+
+  if (resize)
+    {
+      if (width < window->statusbar->requisition.width)
+        width = window->statusbar->requisition.width;
+
+      width  = width  + border_width;
+      height = height + border_height;
+
+      if (grow_only)
+        {
+          if (width < widget->allocation.width)
+            width = widget->allocation.width;
+
+          if (height < widget->allocation.height)
+            height = widget->allocation.height;
+        }
+
+      gtk_window_resize (GTK_WINDOW (window), width, height);
+    }
+
+  /* A wrap always means that we should center the image too. If the
+   * window changes size another center will be done in
+   * GimpDisplayShell::configure_event().
+   */
+  /* FIXME multiple shells */
+  gimp_display_shell_scroll_center_image (active_shell, TRUE, TRUE);
+}
+
 
 /*  private functions  */
 
diff --git a/app/display/gimpimagewindow.h b/app/display/gimpimagewindow.h
index 8575bb4..136e4b5 100644
--- a/app/display/gimpimagewindow.h
+++ b/app/display/gimpimagewindow.h
@@ -64,5 +64,8 @@ void          gimp_image_window_set_fullscreen     (GimpImageWindow *window,
                                                     gboolean         fullscreen);
 gboolean      gimp_image_window_get_fullscreen     (GimpImageWindow *window);
 
+void          gimp_image_window_shrink_wrap        (GimpImageWindow *window,
+                                                    gboolean         grow_only);
+
 
 #endif /* __GIMP_IMAGE_WINDOW_H__ */



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