[gimp] app: get rid of the dnd_window in GimpPanedBox



commit d9b97f2923d1161bc9be7ee14967e4774c5c43d0
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 23 19:47:24 2018 +0200

    app: get rid of the dnd_window in GimpPanedBox
    
    and draw a drop highlight like gimp_highlight_widget() does.

 app/widgets/gimppanedbox.c |  113 +++++++++++++++++--------------------------
 1 files changed, 45 insertions(+), 68 deletions(-)
---
diff --git a/app/widgets/gimppanedbox.c b/app/widgets/gimppanedbox.c
index f9828e7..954fb8e 100644
--- a/app/widgets/gimppanedbox.c
+++ b/app/widgets/gimppanedbox.c
@@ -67,8 +67,9 @@ struct _GimpPanedBoxPrivate
   /* Displays INSTRUCTIONS_TEXT when there are no dockables */
   GtkWidget              *instructions;
 
-  /* Window used for drag-and-drop output */
-  GdkWindow              *dnd_window;
+  /* Is the DND highlight shown */
+  gboolean                dnd_highlight;
+  GdkRectangle            dnd_rectangle;
 
   /* The insert index to use on drop */
   gint                    insert_index;
@@ -97,11 +98,10 @@ static gboolean  gimp_paned_box_drag_drop               (GtkWidget      *widget,
                                                          gint            x,
                                                          gint            y,
                                                          guint           time);
-static void      gimp_paned_box_realize                 (GtkWidget      *widget);
-static void      gimp_paned_box_unrealize               (GtkWidget      *widget);
 static void      gimp_paned_box_set_widget_drag_handler (GtkWidget      *widget,
                                                          GimpPanedBox   *handler);
 static gint      gimp_paned_box_get_drop_area_size      (GimpPanedBox   *paned_box);
+static void      gimp_paned_box_hide_drop_indicator     (GimpPanedBox   *paned_box);
 
 
 G_DEFINE_TYPE (GimpPanedBox, gimp_paned_box, GTK_TYPE_BOX)
@@ -122,8 +122,6 @@ gimp_paned_box_class_init (GimpPanedBoxClass *klass)
   widget_class->drag_leave  = gimp_paned_box_drag_leave;
   widget_class->drag_motion = gimp_paned_box_drag_motion;
   widget_class->drag_drop   = gimp_paned_box_drag_drop;
-  widget_class->realize     = gimp_paned_box_realize;
-  widget_class->unrealize   = gimp_paned_box_unrealize;
 
   g_type_class_add_private (klass, sizeof (GimpPanedBoxPrivate));
 }
@@ -172,6 +170,9 @@ gimp_paned_box_dispose (GObject *object)
 {
   GimpPanedBox *paned_box = GIMP_PANED_BOX (object);
 
+  if (paned_box->p->dnd_highlight)
+    gimp_paned_box_hide_drop_indicator (paned_box);
+
   while (paned_box->p->widgets)
     {
       GtkWidget *widget = paned_box->p->widgets->data;
@@ -186,31 +187,6 @@ gimp_paned_box_dispose (GObject *object)
 }
 
 static void
-gimp_paned_box_realize (GtkWidget *widget)
-{
-  GTK_WIDGET_CLASS (parent_class)->realize (widget);
-
-  /* We realize() dnd_window on demand in
-   * gimp_paned_box_show_separators()
-   */
-}
-
-static void
-gimp_paned_box_unrealize (GtkWidget *widget)
-{
-  GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
-
-  if (paned_box->p->dnd_window)
-    {
-      gdk_window_set_user_data (paned_box->p->dnd_window, NULL);
-      gdk_window_destroy (paned_box->p->dnd_window);
-      paned_box->p->dnd_window = NULL;
-    }
-
-  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
-}
-
-static void
 gimp_paned_box_set_widget_drag_handler (GtkWidget    *widget,
                                         GimpPanedBox *drag_handler)
 {
@@ -269,6 +245,24 @@ gimp_paned_box_get_drop_area_size (GimpPanedBox *paned_box)
   return drop_area_size;
 }
 
+static gboolean
+gimp_paned_box_drop_indicator_draw (GtkWidget *widget,
+                                    cairo_t   *cr,
+                                    gpointer   data)
+{
+  GimpPanedBox *paned_box = GIMP_PANED_BOX (widget);
+
+  cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.2);
+  cairo_rectangle (cr,
+                   paned_box->p->dnd_rectangle.x      + 0.5,
+                   paned_box->p->dnd_rectangle.y      + 0.5,
+                   paned_box->p->dnd_rectangle.width  - 1.0,
+                   paned_box->p->dnd_rectangle.height - 1.0);
+  cairo_fill (cr);
+
+  return FALSE;
+}
+
 static void
 gimp_paned_box_position_drop_indicator (GimpPanedBox *paned_box,
                                         gint          x,
@@ -278,53 +272,36 @@ gimp_paned_box_position_drop_indicator (GimpPanedBox *paned_box,
 {
   GtkWidget *widget = GTK_WIDGET (paned_box);
 
-  if (! gtk_widget_is_drawable (widget))
-    return;
+  paned_box->p->dnd_rectangle.x      = x;
+  paned_box->p->dnd_rectangle.y      = y;
+  paned_box->p->dnd_rectangle.width  = width;
+  paned_box->p->dnd_rectangle.height = height;
 
-  /* Create or move the GdkWindow in place */
-  if (! paned_box->p->dnd_window)
+  if (! paned_box->p->dnd_highlight)
     {
-      GtkStyleContext *style = gtk_widget_get_style_context (widget);
-      GtkAllocation    allocation;
-      GdkWindowAttr    attributes;
-      GdkRGBA          color;
-
-      gtk_widget_get_allocation (widget, &allocation);
-
-      attributes.x           = x;
-      attributes.y           = y;
-      attributes.width       = width;
-      attributes.height      = height;
-      attributes.window_type = GDK_WINDOW_CHILD;
-      attributes.wclass      = GDK_INPUT_OUTPUT;
-      attributes.event_mask  = gtk_widget_get_events (widget);
-
-      paned_box->p->dnd_window = gdk_window_new (gtk_widget_get_window (widget),
-                                                 &attributes,
-                                                 GDK_WA_X | GDK_WA_Y);
-      gdk_window_set_user_data (paned_box->p->dnd_window, widget);
-
-      gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
-                                              &color);
-      gdk_window_set_background_rgba (paned_box->p->dnd_window, &color);
-    }
-  else
-    {
-      gdk_window_move_resize (paned_box->p->dnd_window,
-                              x, y,
-                              width, height);
+      g_signal_connect_after (widget, "draw",
+                              G_CALLBACK (gimp_paned_box_drop_indicator_draw),
+                              NULL);
+      paned_box->p->dnd_highlight = TRUE;
     }
 
-  gdk_window_show (paned_box->p->dnd_window);
+  gtk_widget_queue_draw (widget);
 }
 
 static void
 gimp_paned_box_hide_drop_indicator (GimpPanedBox *paned_box)
 {
-  if (! paned_box->p->dnd_window)
-    return;
+  GtkWidget *widget = GTK_WIDGET (paned_box);
+
+  if (paned_box->p->dnd_highlight)
+    {
+      g_signal_handlers_disconnect_by_func (widget,
+                                            gimp_paned_box_drop_indicator_draw,
+                                            NULL);
+      paned_box->p->dnd_highlight = FALSE;
+    }
 
-  gdk_window_hide (paned_box->p->dnd_window);
+  gtk_widget_queue_draw (widget);
 }
 
 static void


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