[gtk+] iconview: Use a CSS node for rubberband drawing
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] iconview: Use a CSS node for rubberband drawing
- Date: Tue, 10 Nov 2015 05:31:02 +0000 (UTC)
commit 318269550bd8fdb243390a3624527b558bc37a1c
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 10 00:25:19 2015 -0500
iconview: Use a CSS node for rubberband drawing
Use a CSS node with name rubberband to draw the rubberband
selection.
gtk/gtkiconview.c | 58 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 143acb6..f919cd9 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -44,6 +44,9 @@
#include "gtktreednd.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
+#include "gtkcssnodeprivate.h"
+#include "gtkwidgetprivate.h"
+#include "gtkstylecontextprivate.h"
#include "a11y/gtkiconviewaccessibleprivate.h"
/**
@@ -65,7 +68,9 @@
*
* # CSS nodes
*
+ *
* GtkIconView has a single CSS node with name iconview and style class .view.
+ * For rubberband selection, a subnode with name rubberband is used.
*/
#define SCROLL_EDGE_SIZE 15
@@ -2537,35 +2542,48 @@ gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
gint x,
gint y)
{
+ GtkIconViewPrivate *priv = icon_view->priv;
GList *items;
+ GtkCssNode *widget_node;
- if (icon_view->priv->rubberband_device)
+ if (priv->rubberband_device)
return;
- for (items = icon_view->priv->items; items; items = items->next)
+ for (items = priv->items; items; items = items->next)
{
GtkIconViewItem *item = items->data;
item->selected_before_rubberbanding = item->selected;
}
-
- icon_view->priv->rubberband_x1 = x;
- icon_view->priv->rubberband_y1 = y;
- icon_view->priv->rubberband_x2 = x;
- icon_view->priv->rubberband_y2 = y;
- icon_view->priv->doing_rubberband = TRUE;
- icon_view->priv->rubberband_device = device;
+ priv->rubberband_x1 = x;
+ priv->rubberband_y1 = y;
+ priv->rubberband_x2 = x;
+ priv->rubberband_y2 = y;
+
+ priv->doing_rubberband = TRUE;
+ priv->rubberband_device = device;
+
+ widget_node = gtk_widget_get_css_node (GTK_WIDGET (icon_view));
+ priv->rubberband_node = gtk_css_node_new ();
+ gtk_css_node_set_name (priv->rubberband_node, I_("rubberband"));
+ gtk_css_node_set_parent (priv->rubberband_node, widget_node);
+ gtk_css_node_set_state (priv->rubberband_node, gtk_css_node_get_state (widget_node));
+ g_object_unref (priv->rubberband_node);
}
static void
gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
{
- if (!icon_view->priv->doing_rubberband)
+ GtkIconViewPrivate *priv = icon_view->priv;
+
+ if (!priv->doing_rubberband)
return;
- icon_view->priv->doing_rubberband = FALSE;
- icon_view->priv->rubberband_device = NULL;
+ priv->doing_rubberband = FALSE;
+ priv->rubberband_device = NULL;
+ gtk_css_node_set_parent (priv->rubberband_node, NULL);
+ priv->rubberband_node = NULL;
gtk_widget_queue_draw (GTK_WIDGET (icon_view));
}
@@ -3119,23 +3137,23 @@ gtk_icon_view_paint_item (GtkIconView *icon_view,
}
static void
-gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
- cairo_t *cr)
+gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
+ cairo_t *cr)
{
+ GtkIconViewPrivate *priv = icon_view->priv;
GtkStyleContext *context;
GdkRectangle rect;
cairo_save (cr);
- rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
- rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
- rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
- rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
+ rect.x = MIN (priv->rubberband_x1, priv->rubberband_x2);
+ rect.y = MIN (priv->rubberband_y1, priv->rubberband_y2);
+ rect.width = ABS (priv->rubberband_x1 - priv->rubberband_x2) + 1;
+ rect.height = ABS (priv->rubberband_y1 - priv->rubberband_y2) + 1;
context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
+ gtk_style_context_save_to_node (context, priv->rubberband_node);
gdk_cairo_rectangle (cr, &rect);
cairo_clip (cr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]