[gimp] app: add gimp_widget_blink(); use instead of gimp_dockable_blink()



commit e029795dfb28a77a1591c89fe556a9cd3527180f
Author: Ell <ell_se yahoo com>
Date:   Sat Oct 28 08:42:54 2017 -0400

    app: add gimp_widget_blink(); use instead of gimp_dockable_blink()
    
    gimp_dockable_blink() is used to attract the user's attention to a
    specific dockable.  Generalize this to arbitrary widgets, by
    replacing gimp_dockable_blink[_cancel]() with
    gimp_widget_blink[_cancel](), in gimpwidgets-utils.c.

 app/tools/gimpcolortool.c       |    3 +-
 app/widgets/gimpdialogfactory.c |    2 +-
 app/widgets/gimpdockable.c      |   54 --------------------------
 app/widgets/gimpdockable.h      |    3 -
 app/widgets/gimpwidgets-utils.c |   81 +++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpwidgets-utils.h |    2 +
 6 files changed, 86 insertions(+), 59 deletions(-)
---
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 06c764f..57a48e7 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -41,6 +41,7 @@
 #include "widgets/gimpdockable.h"
 #include "widgets/gimpdockcontainer.h"
 #include "widgets/gimppaletteeditor.h"
+#include "widgets/gimpwidgets-utils.h"
 #include "widgets/gimpwindowstrategy.h"
 
 #include "display/gimpcanvasitem.h"
@@ -567,7 +568,7 @@ gimp_color_tool_real_picked (GimpColorTool      *color_tool,
 
             /* don't blink like mad when updating */
             if (pick_state != GIMP_COLOR_PICK_STATE_START)
-              gimp_dockable_blink_cancel (GIMP_DOCKABLE (dockable));
+              gimp_widget_blink_cancel (dockable);
 
             palette_editor = gtk_bin_get_child (GTK_BIN (dockable));
 
diff --git a/app/widgets/gimpdialogfactory.c b/app/widgets/gimpdialogfactory.c
index a18e875..695d8ea 100644
--- a/app/widgets/gimpdialogfactory.c
+++ b/app/widgets/gimpdialogfactory.c
@@ -653,7 +653,7 @@ gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
             {
               gtk_notebook_set_current_page (notebook, num);
 
-              gimp_dockable_blink (dockable);
+              gimp_widget_blink (dialog);
             }
         }
 
diff --git a/app/widgets/gimpdockable.c b/app/widgets/gimpdockable.c
index 4e32e7b..3d11b31 100644
--- a/app/widgets/gimpdockable.c
+++ b/app/widgets/gimpdockable.c
@@ -69,9 +69,6 @@ struct _GimpDockablePrivate
 
   GimpContext  *context;
 
-  guint         blink_timeout_id;
-  gint          blink_counter;
-
   GimpPanedBox *drag_handler;
 
   /*  drag icon hotspot  */
@@ -126,7 +123,6 @@ static void       gimp_dockable_set_aux_info      (GimpSessionManaged
 static GimpTabStyle
                   gimp_dockable_convert_tab_style (GimpDockable   *dockable,
                                                    GimpTabStyle    tab_style);
-static gboolean   gimp_dockable_blink_timeout     (GimpDockable   *dockable);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpDockable, gimp_dockable, GTK_TYPE_BIN,
@@ -204,8 +200,6 @@ gimp_dockable_dispose (GObject *object)
 {
   GimpDockable *dockable = GIMP_DOCKABLE (object);
 
-  gimp_dockable_blink_cancel (dockable);
-
   if (dockable->p->context)
     gimp_dockable_set_context (dockable, NULL);
 
@@ -884,36 +878,6 @@ gimp_dockable_detach (GimpDockable *dockable)
   gtk_widget_show (dock);
 }
 
-void
-gimp_dockable_blink (GimpDockable *dockable)
-{
-  g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
-
-  if (dockable->p->blink_timeout_id)
-    g_source_remove (dockable->p->blink_timeout_id);
-
-  dockable->p->blink_timeout_id =
-    g_timeout_add (150, (GSourceFunc) gimp_dockable_blink_timeout, dockable);
-
-  gimp_highlight_widget (GTK_WIDGET (dockable), TRUE);
-}
-
-void
-gimp_dockable_blink_cancel (GimpDockable *dockable)
-{
-  g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
-
-  if (dockable->p->blink_timeout_id)
-    {
-      g_source_remove (dockable->p->blink_timeout_id);
-
-      dockable->p->blink_timeout_id = 0;
-      dockable->p->blink_counter    = 0;
-
-      gimp_highlight_widget (GTK_WIDGET (dockable), FALSE);
-    }
-}
-
 
 /*  private functions  */
 
@@ -963,21 +927,3 @@ gimp_dockable_convert_tab_style (GimpDockable   *dockable,
 
   return tab_style;
 }
-
-static gboolean
-gimp_dockable_blink_timeout (GimpDockable *dockable)
-{
-  gimp_highlight_widget (GTK_WIDGET (dockable),
-                         dockable->p->blink_counter % 2 == 1);
-  dockable->p->blink_counter++;
-
-  if (dockable->p->blink_counter == 3)
-    {
-      dockable->p->blink_timeout_id = 0;
-      dockable->p->blink_counter    = 0;
-
-      return FALSE;
-    }
-
-  return TRUE;
-}
diff --git a/app/widgets/gimpdockable.h b/app/widgets/gimpdockable.h
index d91c7d7..c3a0819 100644
--- a/app/widgets/gimpdockable.h
+++ b/app/widgets/gimpdockable.h
@@ -106,8 +106,5 @@ void            gimp_dockable_set_drag_handler     (GimpDockable   *dockable,
 
 void            gimp_dockable_detach               (GimpDockable   *dockable);
 
-void            gimp_dockable_blink                (GimpDockable   *dockable);
-void            gimp_dockable_blink_cancel         (GimpDockable   *dockable);
-
 
 #endif /* __GIMP_DOCKABLE_H__ */
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index 473202d..f0385c3 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -1615,3 +1615,84 @@ gimp_color_profile_store_add_defaults (GimpColorProfileStore  *store,
 
   return TRUE;
 }
+
+typedef struct
+{
+  gint timeout_id;
+  gint counter;
+} WidgetBlink;
+
+static WidgetBlink *
+widget_blink_new (void)
+{
+  WidgetBlink *blink;
+
+  blink = g_slice_new (WidgetBlink);
+
+  blink->timeout_id = 0;
+  blink->counter    = 0;
+
+  return blink;
+}
+
+static void
+widget_blink_free (WidgetBlink *blink)
+{
+  if (blink->timeout_id)
+    {
+      g_source_remove (blink->timeout_id);
+      blink->timeout_id = 0;
+    }
+
+  g_slice_free (WidgetBlink, blink);
+}
+
+static gboolean
+gimp_widget_blink_timeout (GtkWidget *widget)
+{
+  WidgetBlink *blink;
+
+  blink = g_object_get_data (G_OBJECT (widget), "gimp-widget-blink");
+
+  gimp_highlight_widget (widget, blink->counter % 2 == 1);
+  blink->counter++;
+
+  if (blink->counter == 3)
+    {
+      blink->timeout_id = 0;
+
+      g_object_set_data (G_OBJECT (widget), "gimp-widget-blink", NULL);
+
+      return G_SOURCE_REMOVE;
+    }
+
+  return G_SOURCE_CONTINUE;
+}
+
+void
+gimp_widget_blink (GtkWidget *widget)
+{
+  WidgetBlink *blink;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  blink = widget_blink_new ();
+
+  g_object_set_data_full (G_OBJECT (widget), "gimp-widget-blink", blink,
+                          (GDestroyNotify) widget_blink_free);
+
+  blink->timeout_id = g_timeout_add (150,
+                                     (GSourceFunc) gimp_widget_blink_timeout,
+                                     widget);
+
+  gimp_highlight_widget (widget, TRUE);
+}
+
+void gimp_widget_blink_cancel (GtkWidget *widget)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  gimp_highlight_widget (widget, FALSE);
+
+  g_object_set_data (G_OBJECT (widget), "gimp-widget-blink", NULL);
+}
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index 67cefc0..b62be0a 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -95,6 +95,8 @@ void              gimp_pango_layout_set_weight     (PangoLayout          *layout
                                                     PangoWeight           weight);
 void              gimp_highlight_widget            (GtkWidget            *widget,
                                                     gboolean              highlight);
+void              gimp_widget_blink                (GtkWidget             *widget);
+void              gimp_widget_blink_cancel         (GtkWidget             *widget);
 GtkWidget       * gimp_dock_with_window_new        (GimpDialogFactory    *factory,
                                                     GdkScreen            *screen,
                                                     gint                  monitor,


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