[gimp] app: make state checks on tool much more strict



commit e1bc19faf619ba367b84da620328d4c071d8ee47
Author: Michael Natterer <mitch gimp org>
Date:   Fri Apr 1 11:01:36 2011 +0200

    app: make state checks on tool much more strict
    
    so wrong calls will run into precondition checks and warnings. This is
    optional, but currently enabled, to reduce the risk of introducing
    permanent new warnings for 2.8. See STRICT_TOOL_CHECKS in gimptool.h.

 app/tools/gimpdrawtool.c    |   10 +++++++-
 app/tools/gimptool.c        |   56 ++++++++++++++++++++++++++++++++++++++++--
 app/tools/gimptool.h        |    3 ++
 app/tools/gimptoolcontrol.c |    4 +-
 4 files changed, 67 insertions(+), 6 deletions(-)
---
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index cd6edad..73e96e2 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -164,7 +164,8 @@ gimp_draw_tool_control (GimpTool       *tool,
       break;
 
     case GIMP_TOOL_ACTION_HALT:
-      gimp_draw_tool_stop (draw_tool);
+      if (gimp_draw_tool_is_active (draw_tool))
+        gimp_draw_tool_stop (draw_tool);
       break;
     }
 
@@ -239,8 +240,12 @@ gimp_draw_tool_start (GimpDrawTool *draw_tool,
 {
   g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_draw_tool_is_active (draw_tool) == FALSE);
+#else
 
   gimp_draw_tool_stop (draw_tool);
+#endif
 
   draw_tool->display = display;
 
@@ -251,6 +256,9 @@ void
 gimp_draw_tool_stop (GimpDrawTool *draw_tool)
 {
   g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_draw_tool_is_active (draw_tool) == TRUE);
+#endif
 
   gimp_draw_tool_undraw (draw_tool);
 
diff --git a/app/tools/gimptool.c b/app/tools/gimptool.c
index 2e86070..ac4bba5 100644
--- a/app/tools/gimptool.c
+++ b/app/tools/gimptool.c
@@ -644,6 +644,9 @@ gimp_tool_button_release (GimpTool         *tool,
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (coords != NULL);
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == TRUE);
+#endif
 
   g_object_ref (tool);
 
@@ -676,8 +679,22 @@ gimp_tool_button_release (GimpTool         *tool,
   GIMP_TOOL_GET_CLASS (tool)->button_release (tool, &my_coords, time, state,
                                               release_type, display);
 
+#ifdef STRICT_TOOL_CHECKS
+  g_warn_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
+#endif
+
   if (tool->active_modifier_state != 0)
-    gimp_tool_set_active_modifier_state (tool, 0, display);
+    {
+#ifdef STRICT_TOOL_CHECKS
+      gimp_tool_control_activate (tool->control);
+#endif
+
+      gimp_tool_set_active_modifier_state (tool, 0, display);
+
+#ifdef STRICT_TOOL_CHECKS
+      gimp_tool_control_halt (tool->control);
+#endif
+    }
 
   tool->button_press_state = 0;
 
@@ -694,7 +711,7 @@ gimp_tool_motion (GimpTool         *tool,
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (coords != NULL);
   g_return_if_fail (GIMP_IS_DISPLAY (display));
-  g_return_if_fail (gimp_tool_control_is_active (tool->control));
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == TRUE);
 
   tool->got_motion_event = TRUE;
   gimp_tool_check_click_distance (tool, coords, time, display);
@@ -708,6 +725,9 @@ gimp_tool_set_focus_display (GimpTool    *tool,
 {
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (display == NULL || GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
+#endif
 
   GIMP_LOG (TOOL_FOCUS, "tool: %p  focus_display: %p  tool->focus_display: %p",
             tool, display, tool->focus_display);
@@ -717,7 +737,17 @@ gimp_tool_set_focus_display (GimpTool    *tool,
       if (tool->focus_display)
         {
           if (tool->active_modifier_state != 0)
-            gimp_tool_set_active_modifier_state (tool, 0, tool->focus_display);
+            {
+#ifdef STRICT_TOOL_CHECKS
+              gimp_tool_control_activate (tool->control);
+#endif
+
+              gimp_tool_set_active_modifier_state (tool, 0, tool->focus_display);
+
+#ifdef STRICT_TOOL_CHECKS
+              gimp_tool_control_halt (tool->control);
+#endif
+            }
 
           if (tool->modifier_state != 0)
             gimp_tool_set_modifier_state (tool, 0, tool->focus_display);
@@ -735,6 +765,10 @@ gimp_tool_key_press (GimpTool    *tool,
   g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
   g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
   g_return_val_if_fail (display == tool->focus_display, FALSE);
+#ifdef STRICT_TOOL_CHECKS
+  g_return_val_if_fail (gimp_tool_control_is_active (tool->control) == FALSE,
+                        FALSE);
+#endif
 
   return GIMP_TOOL_GET_CLASS (tool)->key_press (tool, kevent, display);
 }
@@ -747,6 +781,10 @@ gimp_tool_key_release (GimpTool    *tool,
   g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
   g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
   g_return_val_if_fail (display == tool->focus_display, FALSE);
+#ifdef STRICT_TOOL_CHECKS
+  g_return_val_if_fail (gimp_tool_control_is_active (tool->control) == FALSE,
+                        FALSE);
+#endif
 
   return GIMP_TOOL_GET_CLASS (tool)->key_release (tool, kevent, display);
 }
@@ -772,6 +810,9 @@ gimp_tool_set_modifier_state (GimpTool        *tool,
 {
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
+#endif
 
   GIMP_LOG (TOOL_FOCUS, "tool: %p  display: %p  tool->focus_display: %p",
             tool, display, tool->focus_display);
@@ -824,6 +865,9 @@ gimp_tool_set_active_modifier_state (GimpTool        *tool,
 {
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == TRUE);
+#endif
 
   GIMP_LOG (TOOL_FOCUS, "tool: %p  display: %p  tool->focus_display: %p",
             tool, display, tool->focus_display);
@@ -909,6 +953,9 @@ gimp_tool_oper_update (GimpTool         *tool,
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (coords != NULL);
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
+#endif
 
   GIMP_TOOL_GET_CLASS (tool)->oper_update (tool, coords, state, proximity,
                                            display);
@@ -932,6 +979,9 @@ gimp_tool_cursor_update (GimpTool         *tool,
   g_return_if_fail (GIMP_IS_TOOL (tool));
   g_return_if_fail (coords != NULL);
   g_return_if_fail (GIMP_IS_DISPLAY (display));
+#ifdef STRICT_TOOL_CHECKS
+  g_return_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
+#endif
 
   GIMP_TOOL_GET_CLASS (tool)->cursor_update (tool, coords, state, display);
 }
diff --git a/app/tools/gimptool.h b/app/tools/gimptool.h
index 805140b..9a4ee80 100644
--- a/app/tools/gimptool.h
+++ b/app/tools/gimptool.h
@@ -22,6 +22,9 @@
 #include "core/gimpobject.h"
 
 
+#define STRICT_TOOL_CHECKS 1
+
+
 #define GIMP_TYPE_TOOL            (gimp_tool_get_type ())
 #define GIMP_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL, GimpTool))
 #define GIMP_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL, GimpToolClass))
diff --git a/app/tools/gimptoolcontrol.c b/app/tools/gimptoolcontrol.c
index bdcd68c..397546e 100644
--- a/app/tools/gimptoolcontrol.c
+++ b/app/tools/gimptoolcontrol.c
@@ -107,7 +107,7 @@ void
 gimp_tool_control_activate (GimpToolControl *control)
 {
   g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
-#ifdef GIMP_UNSTABLE
+#ifdef STRICT_TOOL_CHECKS
   g_return_if_fail (control->active == FALSE);
 #endif
 
@@ -118,7 +118,7 @@ void
 gimp_tool_control_halt (GimpToolControl *control)
 {
   g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
-#ifdef GIMP_UNSTABLE
+#ifdef STRICT_TOOL_CHECKS
   g_return_if_fail (control->active == TRUE);
 #endif
 



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