gimp r27416 - in trunk: . app/display app/tools



Author: mitch
Date: Sun Oct 26 16:25:24 2008
New Revision: 27416
URL: http://svn.gnome.org/viewvc/gimp?rev=27416&view=rev

Log:
2008-10-26  Michael Natterer  <mitch gimp org>

	Add some infrastructure for the on-canvas text editing GSoC
	project:

	* app/tools/gimptoolcontrol.[ch]: add boolean wants_all_key_events
	member and API to set and get it.

	* app/tools/gimptool.[ch]: add GimpTool::get_popup() which returns
	the tool's context menu if it has one, or NULL otherwise.

	* app/tools/tool_manager.[ch]: add tool_manager_get_popup_active()
	wrapper.

	* app/display/gimpdisplayshell-callbacks.c: check if the tool has
	a popup menu and show it instead of the usual right-click menu.

	Also call the tool's key_press() unconditionally if it wants all
	key events, but this code needs more thinking.



Modified:
   trunk/ChangeLog
   trunk/app/display/gimpdisplayshell-callbacks.c
   trunk/app/tools/gimptool.c
   trunk/app/tools/gimptool.h
   trunk/app/tools/gimptoolcontrol.c
   trunk/app/tools/gimptoolcontrol.h
   trunk/app/tools/tool_manager.c
   trunk/app/tools/tool_manager.h

Modified: trunk/app/display/gimpdisplayshell-callbacks.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-callbacks.c	(original)
+++ trunk/app/display/gimpdisplayshell-callbacks.c	Sun Oct 26 16:25:24 2008
@@ -934,11 +934,32 @@
             break;
 
           case 3:
-            state |= GDK_BUTTON3_MASK;
-            gimp_ui_manager_ui_popup (shell->popup_manager,
-                                      "/dummy-menubar/image-popup",
-                                      GTK_WIDGET (shell),
-                                      NULL, NULL, NULL, NULL);
+            {
+              GimpUIManager *ui_manager;
+              const gchar   *ui_path;
+
+              state |= GDK_BUTTON3_MASK;
+
+              ui_manager = tool_manager_get_popup_active (gimp,
+                                                          &image_coords, state,
+                                                          display,
+                                                          &ui_path);
+
+              if (ui_manager)
+                {
+                  gimp_ui_manager_ui_popup (ui_manager,
+                                            ui_path,
+                                            GTK_WIDGET (shell),
+                                            NULL, NULL, NULL, NULL);
+                }
+              else
+                {
+                  gimp_ui_manager_ui_popup (shell->popup_manager,
+                                            "/dummy-menubar/image-popup",
+                                            GTK_WIDGET (shell),
+                                            NULL, NULL, NULL, NULL);
+                }
+            }
             break;
 
           default:
@@ -1359,6 +1380,17 @@
           {
             tool_manager_focus_display_active (gimp, display);
 
+            if (gimp_tool_control_get_wants_all_key_events (active_tool->control))
+              {
+                tool_manager_key_press_active (gimp, kevent, display);
+
+                /* FIXME: need to do some of the stuff below, like
+                 * calling oper_update()
+                 */
+
+                return TRUE;
+              }
+
             switch (kevent->keyval)
               {
               case GDK_Return:

Modified: trunk/app/tools/gimptool.c
==============================================================================
--- trunk/app/tools/gimptool.c	(original)
+++ trunk/app/tools/gimptool.c	Sun Oct 26 16:25:24 2008
@@ -106,6 +106,11 @@
                                                  GimpCoords            *coords,
                                                  GdkModifierType        state,
                                                  GimpDisplay           *display);
+static GimpUIManager * gimp_tool_real_get_popup (GimpTool              *tool,
+                                                 GimpCoords            *coords,
+                                                 GdkModifierType        state,
+                                                 GimpDisplay           *display,
+                                                 const gchar          **ui_path);
 
 static void       gimp_tool_clear_status        (GimpTool              *tool);
 
@@ -138,6 +143,7 @@
   klass->active_modifier_key = gimp_tool_real_active_modifier_key;
   klass->oper_update         = gimp_tool_real_oper_update;
   klass->cursor_update       = gimp_tool_real_cursor_update;
+  klass->get_popup           = gimp_tool_real_get_popup;
 
   g_object_class_install_property (object_class, PROP_TOOL_INFO,
                                    g_param_spec_object ("tool-info",
@@ -361,6 +367,18 @@
                         gimp_tool_control_get_cursor_modifier (tool->control));
 }
 
+static GimpUIManager *
+gimp_tool_real_get_popup (GimpTool         *tool,
+                          GimpCoords       *coords,
+                          GdkModifierType   state,
+                          GimpDisplay      *display,
+                          const gchar     **ui_path)
+{
+  *ui_path = NULL;
+
+  return NULL;
+}
+
 
 /*  public functions  */
 
@@ -834,6 +852,22 @@
   GIMP_TOOL_GET_CLASS (tool)->cursor_update (tool, coords, state, display);
 }
 
+GimpUIManager *
+gimp_tool_get_popup (GimpTool         *tool,
+                     GimpCoords       *coords,
+                     GdkModifierType   state,
+                     GimpDisplay      *display,
+                     const gchar     **ui_path)
+{
+  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 (ui_path != NULL);
+
+  return GIMP_TOOL_GET_CLASS (tool)->get_popup (tool, coords, state, display,
+                                                ui_path);
+}
+
 void
 gimp_tool_push_status (GimpTool    *tool,
                        GimpDisplay *display,

Modified: trunk/app/tools/gimptool.h
==============================================================================
--- trunk/app/tools/gimptool.h	(original)
+++ trunk/app/tools/gimptool.h	Sun Oct 26 16:25:24 2008
@@ -76,58 +76,64 @@
 
   /*  virtual functions  */
 
-  gboolean      (* has_display)         (GimpTool              *tool,
-                                         GimpDisplay           *display);
-  GimpDisplay * (* has_image)           (GimpTool              *tool,
-                                         GimpImage             *image);
-
-  gboolean      (* initialize)          (GimpTool              *tool,
-                                         GimpDisplay           *display,
-                                         GError               **error);
-  void          (* control)             (GimpTool              *tool,
-                                         GimpToolAction         action,
-                                         GimpDisplay           *display);
-
-  void          (* button_press)        (GimpTool              *tool,
-                                         GimpCoords            *coords,
-                                         guint32                time,
-                                         GdkModifierType        state,
-                                         GimpDisplay           *display);
-  void          (* button_release)      (GimpTool              *tool,
-                                         GimpCoords            *coords,
-                                         guint32                time,
-                                         GdkModifierType        state,
-                                         GimpButtonReleaseType  release_type,
-                                         GimpDisplay           *display);
-  void          (* motion)              (GimpTool              *tool,
-                                         GimpCoords            *coords,
-                                         guint32                time,
-                                         GdkModifierType        state,
-                                         GimpDisplay           *display);
-
-  gboolean      (* key_press)           (GimpTool              *tool,
-                                         GdkEventKey           *kevent,
-                                         GimpDisplay           *display);
-  void          (* modifier_key)        (GimpTool              *tool,
-                                         GdkModifierType        key,
-                                         gboolean               press,
-                                         GdkModifierType        state,
-                                         GimpDisplay           *display);
-  void          (* active_modifier_key) (GimpTool              *tool,
-                                         GdkModifierType        key,
-                                         gboolean               press,
-                                         GdkModifierType        state,
-                                         GimpDisplay           *display);
-
-  void          (* oper_update)         (GimpTool              *tool,
-                                         GimpCoords            *coords,
-                                         GdkModifierType        state,
-                                         gboolean               proximity,
-                                         GimpDisplay           *display);
-  void          (* cursor_update)       (GimpTool              *tool,
-                                         GimpCoords            *coords,
-                                         GdkModifierType        state,
-                                         GimpDisplay           *display);
+  gboolean        (* has_display)         (GimpTool              *tool,
+                                           GimpDisplay           *display);
+  GimpDisplay   * (* has_image)           (GimpTool              *tool,
+                                           GimpImage             *image);
+
+  gboolean        (* initialize)          (GimpTool              *tool,
+                                           GimpDisplay           *display,
+                                           GError               **error);
+  void            (* control)             (GimpTool              *tool,
+                                           GimpToolAction         action,
+                                           GimpDisplay           *display);
+
+  void            (* button_press)        (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           guint32                time,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display);
+  void            (* button_release)      (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           guint32                time,
+                                           GdkModifierType        state,
+                                           GimpButtonReleaseType  release_type,
+                                           GimpDisplay           *display);
+  void            (* motion)              (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           guint32                time,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display);
+
+  gboolean        (* key_press)           (GimpTool              *tool,
+                                           GdkEventKey           *kevent,
+                                           GimpDisplay           *display);
+  void            (* modifier_key)        (GimpTool              *tool,
+                                           GdkModifierType        key,
+                                           gboolean               press,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display);
+  void            (* active_modifier_key) (GimpTool              *tool,
+                                           GdkModifierType        key,
+                                           gboolean               press,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display);
+
+  void            (* oper_update)         (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           GdkModifierType        state,
+                                           gboolean               proximity,
+                                           GimpDisplay           *display);
+  void            (* cursor_update)       (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display);
+
+  GimpUIManager * (* get_popup)           (GimpTool              *tool,
+                                           GimpCoords            *coords,
+                                           GdkModifierType        state,
+                                           GimpDisplay           *display,
+                                           const gchar          **ui_path);
 };
 
 
@@ -185,6 +191,12 @@
                                              GdkModifierType      state,
                                              GimpDisplay         *display);
 
+GimpUIManager * gimp_tool_get_popup         (GimpTool            *tool,
+                                             GimpCoords          *coords,
+                                             GdkModifierType      state,
+                                             GimpDisplay         *display,
+                                             const gchar        **ui_path);
+
 void          gimp_tool_push_status         (GimpTool            *tool,
                                              GimpDisplay         *display,
                                              const gchar         *format,

Modified: trunk/app/tools/gimptoolcontrol.c
==============================================================================
--- trunk/app/tools/gimptoolcontrol.c	(original)
+++ trunk/app/tools/gimptoolcontrol.c	Sun Oct 26 16:25:24 2008
@@ -64,6 +64,8 @@
 
   control->toggled                = FALSE;
 
+  control->wants_all_key_events   = FALSE;
+
   control->cursor                 = GIMP_CURSOR_MOUSE;
   control->tool_cursor            = GIMP_TOOL_CURSOR_NONE;
   control->cursor_modifier        = GIMP_CURSOR_MODIFIER_NONE;
@@ -273,6 +275,23 @@
 }
 
 void
+gimp_tool_control_set_wants_all_key_events (GimpToolControl *control,
+                                            gboolean         wants_key_events)
+{
+  g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
+
+  control->wants_all_key_events = wants_key_events ? TRUE : FALSE;
+}
+
+gboolean
+gimp_tool_control_get_wants_all_key_events (GimpToolControl *control)
+{
+  g_return_val_if_fail (GIMP_IS_TOOL_CONTROL (control), FALSE);
+
+  return control->wants_all_key_events;
+}
+
+void
 gimp_tool_control_set_snap_offsets (GimpToolControl *control,
                                     gint             offset_x,
                                     gint             offset_y,

Modified: trunk/app/tools/gimptoolcontrol.h
==============================================================================
--- trunk/app/tools/gimptoolcontrol.h	(original)
+++ trunk/app/tools/gimptoolcontrol.h	Sun Oct 26 16:25:24 2008
@@ -59,6 +59,8 @@
 
   GimpCursorPrecision  precision;
 
+  gboolean             wants_all_key_events;
+
   gboolean             toggled;
 
   GimpCursorType       cursor;
@@ -121,6 +123,10 @@
                                                    gboolean         snap_to);
 gboolean       gimp_tool_control_get_snap_to      (GimpToolControl *control);
 
+void           gimp_tool_control_set_wants_all_key_events  (GimpToolControl *control,
+                                                            gboolean         wants_key_events);
+gboolean       gimp_tool_control_get_wants_all_key_events  (GimpToolControl *control);
+
 void           gimp_tool_control_set_snap_offsets (GimpToolControl *control,
                                                    gint             offset_x,
                                                    gint             offset_y,

Modified: trunk/app/tools/tool_manager.c
==============================================================================
--- trunk/app/tools/tool_manager.c	(original)
+++ trunk/app/tools/tool_manager.c	Sun Oct 26 16:25:24 2008
@@ -452,6 +452,30 @@
     }
 }
 
+GimpUIManager *
+tool_manager_get_popup_active (Gimp             *gimp,
+                               GimpCoords       *coords,
+                               GdkModifierType   state,
+                               GimpDisplay      *display,
+                               const gchar     **ui_path)
+{
+  GimpToolManager *tool_manager;
+
+  g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+  tool_manager = tool_manager_get (gimp);
+
+  if (tool_manager->active_tool)
+    {
+      return gimp_tool_get_popup (tool_manager->active_tool,
+                                  coords, state,
+                                  display,
+                                  ui_path);
+    }
+
+  return NULL;
+}
+
 
 /*  private functions  */
 

Modified: trunk/app/tools/tool_manager.h
==============================================================================
--- trunk/app/tools/tool_manager.h	(original)
+++ trunk/app/tools/tool_manager.h	Sun Oct 26 16:25:24 2008
@@ -77,5 +77,11 @@
                                                     GdkModifierType   state,
                                                     GimpDisplay      *display);
 
+GimpUIManager * tool_manager_get_popup_active      (Gimp             *gimp,
+                                                    GimpCoords       *coords,
+                                                    GdkModifierType   state,
+                                                    GimpDisplay      *display,
+                                                    const gchar     **ui_path);
+
 
 #endif  /*  __TOOL_MANAGER_H__  */



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