[gimp] app: add an "auto overlay" API to GimpToolGui



commit cd479ce04ecc14d5ff02ab2c7d877fb3796e36d1
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jun 9 03:08:43 2014 +0200

    app: add an "auto overlay" API to GimpToolGui
    
    which makes tool dialogs auto-overlay if the canvas is large
    enough. Set all tools dialogs except GimpImageMapTool's dialog to
    auto.

 app/display/gimptoolgui.c            |   92 +++++++++++++++++++++++++++++++++-
 app/display/gimptoolgui.h            |    4 ++
 app/tools/gimpcolorpickertool.c      |    3 +-
 app/tools/gimpforegroundselecttool.c |    2 +
 app/tools/gimpmeasuretool.c          |    3 +-
 app/tools/gimptransformtool.c        |   20 +-------
 app/tools/gimptransformtool.h        |    1 -
 7 files changed, 102 insertions(+), 23 deletions(-)
---
diff --git a/app/display/gimptoolgui.c b/app/display/gimptoolgui.c
index f7495ef..7fa0be4 100644
--- a/app/display/gimptoolgui.c
+++ b/app/display/gimptoolgui.c
@@ -34,6 +34,7 @@
 #include "widgets/gimpdialogfactory.h"
 #include "widgets/gimpoverlaybox.h"
 #include "widgets/gimpoverlaydialog.h"
+#include "widgets/gimpwidgets-utils.h"
 
 #include "gimpdisplayshell.h"
 #include "gimptooldialog.h"
@@ -69,6 +70,7 @@ struct _GimpToolGuiPrivate
   gboolean          focus_on_map;
 
   gboolean          overlay;
+  gboolean          auto_overlay;
 
   GimpDisplayShell *shell;
   GimpViewable     *viewable;
@@ -95,6 +97,9 @@ static void   gimp_tool_gui_update_viewable (GimpToolGui   *gui);
 static void   gimp_tool_gui_dialog_response (GtkWidget     *dialog,
                                              gint           response_id,
                                              GimpToolGui   *gui);
+static void   gimp_tool_gui_canvas_resized  (GtkWidget     *canvas,
+                                             GtkAllocation *allocation,
+                                             GimpToolGui   *gui);
 
 static ResponseEntry * response_entry_new   (gint           response_id,
                                              const gchar   *stock_id);
@@ -165,6 +170,9 @@ gimp_tool_gui_dispose (GObject *object)
 
   if (private->dialog)
     {
+      if (gtk_widget_get_visible (private->dialog))
+        gimp_tool_gui_hide (GIMP_TOOL_GUI (object));
+
       if (private->overlay)
         g_object_unref (private->dialog);
       else
@@ -281,7 +289,7 @@ gimp_tool_gui_set_description (GimpToolGui *gui,
 
   if (private->overlay)
     {
-      g_object_set (private->dialog, "title", description, NULL);
+      /* TODO */
     }
   else
     {
@@ -325,8 +333,26 @@ gimp_tool_gui_set_shell (GimpToolGui      *gui,
   if (shell == private->shell)
     return;
 
+  if (private->shell)
+    {
+      g_object_remove_weak_pointer (G_OBJECT (private->shell),
+                                    (gpointer) &private->shell);
+      g_signal_handlers_disconnect_by_func (private->shell->canvas,
+                                            gimp_tool_gui_canvas_resized,
+                                            gui);
+    }
+
   private->shell = shell;
 
+  if (private->shell)
+    {
+      g_signal_connect (private->shell->canvas, "size-allocate",
+                        G_CALLBACK (gimp_tool_gui_canvas_resized),
+                        gui);
+      g_object_add_weak_pointer (G_OBJECT (private->shell),
+                                 (gpointer) &private->shell);
+    }
+
   gimp_tool_gui_update_shell (gui);
 }
 
@@ -441,6 +467,12 @@ gimp_tool_gui_set_overlay (GimpToolGui *gui,
   if (private->overlay == overlay)
     return;
 
+  if (! private->dialog)
+    {
+      private->overlay = overlay;
+      return;
+    }
+
   visible = gtk_widget_get_visible (private->dialog);
 
   if (visible)
@@ -454,7 +486,7 @@ gimp_tool_gui_set_overlay (GimpToolGui *gui,
   else
     gtk_widget_destroy (private->dialog);
 
-  private->overlay = overlay ? TRUE : FALSE;
+  private->overlay = overlay;
 
   gimp_tool_gui_create_dialog (gui, screen, monitor);
 
@@ -471,6 +503,33 @@ gimp_tool_gui_get_overlay (GimpToolGui *gui)
 }
 
 void
+gimp_tool_gui_set_auto_overlay (GimpToolGui *gui,
+                                gboolean     auto_overlay)
+{
+  GimpToolGuiPrivate *private;
+
+  g_return_if_fail (GIMP_IS_TOOL_GUI (gui));
+
+  private = GET_PRIVATE (gui);
+
+  if (private->auto_overlay != auto_overlay)
+    {
+      private->auto_overlay = auto_overlay;
+
+      if (private->shell)
+        gimp_tool_gui_canvas_resized (private->shell->canvas, NULL, gui);
+    }
+}
+
+gboolean
+gimp_tool_gui_get_auto_overlay (GimpToolGui *gui)
+{
+  g_return_val_if_fail (GIMP_IS_TOOL_GUI (gui), FALSE);
+
+  return GET_PRIVATE (gui)->auto_overlay;
+}
+
+void
 gimp_tool_gui_set_focus_on_map (GimpToolGui *gui,
                                 gboolean     focus_on_map)
 {
@@ -755,6 +814,35 @@ gimp_tool_gui_dialog_response (GtkWidget   *dialog,
                  response_id);
 }
 
+static void
+gimp_tool_gui_canvas_resized (GtkWidget     *canvas,
+                              GtkAllocation *unused,
+                              GimpToolGui   *gui)
+{
+  GimpToolGuiPrivate *private = GET_PRIVATE (gui);
+
+  if (private->auto_overlay)
+    {
+      GtkRequisition requisition;
+      GtkAllocation  allocation;
+      gboolean       overlay = FALSE;
+
+      gtk_widget_size_request (private->vbox, &requisition);
+      gtk_widget_get_allocation (canvas, &allocation);
+
+      if (allocation.width  > 2 * requisition.width &&
+          allocation.height > 3 * requisition.height)
+        {
+          overlay = TRUE;
+        }
+
+      gimp_tool_gui_set_overlay (gui,
+                                 gtk_widget_get_screen (private->dialog),
+                                 gimp_widget_get_monitor (private->dialog),
+                                 overlay);
+    }
+}
+
 static ResponseEntry *
 response_entry_new (gint         response_id,
                     const gchar *stock_id)
diff --git a/app/display/gimptoolgui.h b/app/display/gimptoolgui.h
index a091f9c..9e77e18 100644
--- a/app/display/gimptoolgui.h
+++ b/app/display/gimptoolgui.h
@@ -81,6 +81,10 @@ void          gimp_tool_gui_set_overlay            (GimpToolGui      *gui,
                                                     gboolean          overlay);
 gboolean      gimp_tool_gui_get_overlay            (GimpToolGui      *gui);
 
+void          gimp_tool_gui_set_auto_overlay       (GimpToolGui      *gui,
+                                                    gboolean          auto_overlay);
+gboolean      gimp_tool_gui_get_auto_overlay       (GimpToolGui      *gui);
+
 void          gimp_tool_gui_set_focus_on_map       (GimpToolGui      *gui,
                                                     gboolean          focus_on_map);
 gboolean      gimp_tool_gui_get_focus_on_map       (GimpToolGui      *gui);
diff --git a/app/tools/gimpcolorpickertool.c b/app/tools/gimpcolorpickertool.c
index 1ffb595..10e9e73 100644
--- a/app/tools/gimpcolorpickertool.c
+++ b/app/tools/gimpcolorpickertool.c
@@ -315,12 +315,13 @@ gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool)
                                         _("Color Picker Information"),
                                         gtk_widget_get_screen (GTK_WIDGET (shell)),
                                         gimp_widget_get_monitor (GTK_WIDGET (shell)),
-                                        FALSE,
+                                        TRUE,
 
                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
                                         NULL);
 
+  gimp_tool_gui_set_auto_overlay (picker_tool->gui, TRUE);
   gimp_tool_gui_set_focus_on_map (picker_tool->gui, FALSE);
   gimp_tool_gui_set_viewable (picker_tool->gui,
                               GIMP_VIEWABLE (tool->drawable));
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index 868aa0a..7f5d8b1 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -303,6 +303,8 @@ gimp_foreground_select_tool_initialize (GimpTool     *tool,
                            GIMP_STOCK_TOOL_FOREGROUND_SELECT, GTK_RESPONSE_APPLY,
                            NULL);
 
+      gimp_tool_gui_set_auto_overlay (fg_select->gui, TRUE);
+
       g_signal_connect (fg_select->gui, "response",
                         G_CALLBACK (gimp_foreground_select_tool_response),
                         fg_select);
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index 35a3eee..abd7977 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -1054,12 +1054,13 @@ gimp_measure_tool_dialog_new (GimpMeasureTool *measure)
                            _("Measure Distances and Angles"),
                            gtk_widget_get_screen (GTK_WIDGET (shell)),
                            gimp_widget_get_monitor (GTK_WIDGET (shell)),
-                           FALSE,
+                           TRUE,
 
                            GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
                            NULL);
 
+  gimp_tool_gui_set_auto_overlay (gui, TRUE);
   gimp_tool_gui_set_focus_on_map (gui, FALSE);
 
   g_signal_connect (gui, "response",
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index d96fec3..1fb751c 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -69,7 +69,6 @@
 
 
 #define RESPONSE_RESET  1
-#define RESPONSE_EEK    2
 #define MIN_HANDLE_SIZE 6
 
 
@@ -1642,25 +1641,22 @@ gimp_transform_tool_dialog (GimpTransformTool *tr_tool)
 
   icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info));
 
-  tr_tool->overlay = FALSE;
-
   tr_tool->gui = gimp_tool_gui_new (tool_info,
                                     tool_info->blurb,
                                     gtk_widget_get_screen (GTK_WIDGET (shell)),
                                     gimp_widget_get_monitor (GTK_WIDGET (shell)),
-                                    tr_tool->overlay,
+                                    TRUE,
 
-                                    GIMP_STOCK_WILBER_EEK, RESPONSE_EEK,
                                     GIMP_STOCK_RESET, RESPONSE_RESET,
                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                     icon_name,        GTK_RESPONSE_OK,
 
                                     NULL);
 
+  gimp_tool_gui_set_auto_overlay (tr_tool->gui, TRUE);
   gimp_tool_gui_set_default_response (tr_tool->gui, GTK_RESPONSE_OK);
 
   gimp_tool_gui_set_alternative_button_order (tr_tool->gui,
-                                              RESPONSE_EEK,
                                               RESPONSE_RESET,
                                               GTK_RESPONSE_OK,
                                               GTK_RESPONSE_CANCEL,
@@ -1717,18 +1713,6 @@ gimp_transform_tool_response (GimpToolGui       *gui,
 
   switch (response_id)
     {
-    case RESPONSE_EEK:
-      if (tr_tool->gui)
-        {
-          GimpDisplayShell *shell = gimp_display_get_shell (display);
-
-          gimp_tool_gui_set_overlay (tr_tool->gui,
-                                     gtk_widget_get_screen (GTK_WIDGET (shell)),
-                                     gimp_widget_get_monitor (GTK_WIDGET (shell)),
-                                     ! gimp_tool_gui_get_overlay (tr_tool->gui));
-        }
-      break;
-
     case RESPONSE_RESET:
       /* Move all undo events to redo, and pop off the first
        * one as that's the current one, which always sits on
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 5daad16..2ee4634 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -122,7 +122,6 @@ struct _GimpTransformTool
 
   const gchar    *progress_text;
 
-  gboolean        overlay;
   GimpToolGui    *gui;
 };
 


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