[gtk+/wip/csoriano/bookmarks: 1/4] gtkdnd: use css class for drag highlight



commit a788a731f0d32fd07ae38f5553c5235a2484e6e8
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Jun 3 16:08:58 2015 +0200

    gtkdnd: use css class for drag highlight
    
    Instead of a temporary style class and a cairo rectangle around the widget.
    
    The only drawback about this is that GtkTreeView applies all the style
    to the widget itself to its cells, so when gtk_drag_highlight is applied,
    the cells show borders.
    To prevent that, remove the dnd style class from the draw function on
    GtkTreeView.The drawback about this solution is that GtkTreeView won't
    draw a border to indicate "general" drop target availability, but
    individual cells will still work as expect for highlight since they are
    drawn in an internal way in GtkTreeView.

 gtk/gtkdnd.c      |   59 ++++++----------------------------------------------
 gtk/gtktreeview.c |    4 +++
 2 files changed, 11 insertions(+), 52 deletions(-)
---
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 59b883d..a86e63d 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -1135,48 +1135,6 @@ gtk_drag_finish (GdkDragContext *context,
     gdk_drop_finish (context, success, time);
 }
 
-static gboolean
-gtk_drag_highlight_draw (GtkWidget *widget,
-                         cairo_t   *cr,
-                         gpointer   data)
-{
-  GtkAllocation alloc;
-  GtkStyleContext *context;
-
-  if (GTK_IS_WINDOW (widget))
-    {
-      /* We don't want to draw the drag highlight around the
-       * CSD window decorations
-       */
-      gtk_widget_get_allocation (gtk_bin_get_child (GTK_BIN (widget)), &alloc);
-    }
-  else
-    {
-      alloc.x = 0;
-      alloc.y = 0;
-      alloc.width = gtk_widget_get_allocated_width (widget);
-      alloc.height = gtk_widget_get_allocated_height (widget);
-    }
-
-  context = gtk_widget_get_style_context (widget);
-
-  gtk_style_context_save (context);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND);
-
-  gtk_render_frame (context, cr, alloc.x, alloc.y, alloc.width, alloc.height);
-
-  gtk_style_context_restore (context);
-
-  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
-  cairo_set_line_width (cr, 1.0);
-  cairo_rectangle (cr,
-                   alloc.x + 0.5, alloc.y + 0.5,
-                   alloc.width - 1, alloc.height - 1);
-  cairo_stroke (cr);
-
-  return FALSE;
-}
-
 /**
  * gtk_drag_highlight: (method)
  * @widget: a widget to highlight
@@ -1186,15 +1144,13 @@ gtk_drag_highlight_draw (GtkWidget *widget,
  * will continue to be displayed until gtk_drag_unhighlight()
  * is called.
  */
-void 
+void
 gtk_drag_highlight (GtkWidget  *widget)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_signal_connect_after (widget, "draw",
-                          G_CALLBACK (gtk_drag_highlight_draw),
-                          NULL);
-
+  gtk_style_context_add_class (gtk_widget_get_style_context (widget),
+                               GTK_STYLE_CLASS_DND);
   gtk_widget_queue_draw (widget);
 }
 
@@ -1205,15 +1161,14 @@ gtk_drag_highlight (GtkWidget  *widget)
  * Removes a highlight set by gtk_drag_highlight() from
  * a widget.
  */
-void 
+void
 gtk_drag_unhighlight (GtkWidget *widget)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_signal_handlers_disconnect_by_func (widget,
-                                        gtk_drag_highlight_draw,
-                                        NULL);
-  
+  gtk_style_context_remove_class (gtk_widget_get_style_context (widget),
+                                  GTK_STYLE_CLASS_DND);
+
   gtk_widget_queue_draw (widget);
 }
 
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 5e1f476..8f45eea 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -5573,6 +5573,10 @@ gtk_tree_view_draw (GtkWidget *widget,
   GtkStyleContext *context;
 
   context = gtk_widget_get_style_context (widget);
+  /* Style to the GtkTreeWidget are applied to every cell as well, so when dragging,
+   * if we apply a border to highligth the drop target it actually draw a border
+   * on every cell. For that, just remove the class here... */
+  gtk_style_context_remove_class (context, "dnd");
 
   if (gtk_cairo_should_draw_window (cr, tree_view->priv->bin_window))
     {


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