[gimp/cage: 36/130] app: add gimp_widget_flush_expose() utility function



commit d7bf6b622e2138abe9cf837833ea1cac36790da9
Author: Michael Natterer <mitch gimp org>
Date:   Tue Nov 9 19:33:15 2010 +0100

    app: add gimp_widget_flush_expose() utility function
    
    which flushes all pending exposes for a widget without running the
    main loop. Useful for updating progress bars without returning to the
    main loop.

 app/widgets/gimpwidgets-utils.c |   46 +++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpwidgets-utils.h |    2 +
 2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index d5849e6..664cd21 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -1154,3 +1154,49 @@ gimp_tools_set_tool_options_gui (GimpToolOptions   *tool_options,
                               widget,
                               widget ? (GDestroyNotify) g_object_unref : NULL);
 }
+
+void
+gimp_widget_flush_expose (GtkWidget *widget)
+{
+  GList *event_list = NULL;
+
+  gdk_window_process_updates (gtk_widget_get_window (widget), FALSE);
+
+  while (gdk_events_pending ())
+    {
+      GdkEvent *event = gdk_event_get ();
+
+      if (! event)
+        break;
+
+      if (gtk_get_event_widget (event) == widget &&
+          event->any.type == GDK_EXPOSE)
+        {
+          if (gtk_widget_get_double_buffered (widget))
+            {
+              gdk_window_begin_paint_region (event->any.window,
+                                             event->expose.region);
+              gtk_widget_send_expose (widget, event);
+              gdk_window_end_paint (event->any.window);
+            }
+          else
+            {
+              gdk_window_flush (event->any.window);
+              gtk_widget_send_expose (widget, event);
+            }
+
+          gdk_event_free (event);
+        }
+      else
+        {
+          event_list = g_list_prepend (event_list, event);
+        }
+    }
+
+  event_list = g_list_reverse (event_list);
+
+  g_list_foreach (event_list, (GFunc) gdk_event_put, NULL);
+  g_list_foreach (event_list, (GFunc) gdk_event_free, NULL);
+
+  g_list_free (event_list);
+}
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index 0f60efb..48df46e 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -90,5 +90,7 @@ GtkWidget *       gimp_tools_get_tool_options_gui  (GimpToolOptions      *tool_o
 void              gimp_tools_set_tool_options_gui  (GimpToolOptions      *tool_options,
                                                     GtkWidget            *widget);
 
+void              gimp_widget_flush_expose         (GtkWidget            *widget);
+
 
 #endif /* __GIMP_WIDGETS_UTILS_H__ */



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