forked from AuroraMiddleware/gtk
iconview: Use a CSS node for rubberband drawing
Use a CSS node with name rubberband to draw the rubberband selection.
This commit is contained in:
parent
ee76f9bfed
commit
318269550b
@ -44,6 +44,9 @@
|
|||||||
#include "gtktreednd.h"
|
#include "gtktreednd.h"
|
||||||
#include "gtktypebuiltins.h"
|
#include "gtktypebuiltins.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
|
#include "gtkcssnodeprivate.h"
|
||||||
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkstylecontextprivate.h"
|
||||||
#include "a11y/gtkiconviewaccessibleprivate.h"
|
#include "a11y/gtkiconviewaccessibleprivate.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +68,9 @@
|
|||||||
*
|
*
|
||||||
* # CSS nodes
|
* # CSS nodes
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* GtkIconView has a single CSS node with name iconview and style class .view.
|
* 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
|
#define SCROLL_EDGE_SIZE 15
|
||||||
@ -2537,35 +2542,48 @@ gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
|
|||||||
gint x,
|
gint x,
|
||||||
gint y)
|
gint y)
|
||||||
{
|
{
|
||||||
|
GtkIconViewPrivate *priv = icon_view->priv;
|
||||||
GList *items;
|
GList *items;
|
||||||
|
GtkCssNode *widget_node;
|
||||||
|
|
||||||
if (icon_view->priv->rubberband_device)
|
if (priv->rubberband_device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (items = icon_view->priv->items; items; items = items->next)
|
for (items = priv->items; items; items = items->next)
|
||||||
{
|
{
|
||||||
GtkIconViewItem *item = items->data;
|
GtkIconViewItem *item = items->data;
|
||||||
|
|
||||||
item->selected_before_rubberbanding = item->selected;
|
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;
|
priv->rubberband_x1 = x;
|
||||||
icon_view->priv->rubberband_device = device;
|
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
|
static void
|
||||||
gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
|
gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
|
||||||
{
|
{
|
||||||
if (!icon_view->priv->doing_rubberband)
|
GtkIconViewPrivate *priv = icon_view->priv;
|
||||||
|
|
||||||
|
if (!priv->doing_rubberband)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
icon_view->priv->doing_rubberband = FALSE;
|
priv->doing_rubberband = FALSE;
|
||||||
icon_view->priv->rubberband_device = NULL;
|
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));
|
gtk_widget_queue_draw (GTK_WIDGET (icon_view));
|
||||||
}
|
}
|
||||||
@ -3119,23 +3137,23 @@ gtk_icon_view_paint_item (GtkIconView *icon_view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
|
gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
|
||||||
cairo_t *cr)
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
|
GtkIconViewPrivate *priv = icon_view->priv;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GdkRectangle rect;
|
GdkRectangle rect;
|
||||||
|
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
|
rect.x = MIN (priv->rubberband_x1, priv->rubberband_x2);
|
||||||
rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
|
rect.y = MIN (priv->rubberband_y1, priv->rubberband_y2);
|
||||||
rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
|
rect.width = ABS (priv->rubberband_x1 - priv->rubberband_x2) + 1;
|
||||||
rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
|
rect.height = ABS (priv->rubberband_y1 - priv->rubberband_y2) + 1;
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
|
context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
|
||||||
|
|
||||||
gtk_style_context_save (context);
|
gtk_style_context_save_to_node (context, priv->rubberband_node);
|
||||||
gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
|
|
||||||
|
|
||||||
gdk_cairo_rectangle (cr, &rect);
|
gdk_cairo_rectangle (cr, &rect);
|
||||||
cairo_clip (cr);
|
cairo_clip (cr);
|
||||||
|
Loading…
Reference in New Issue
Block a user