[gtk+] label: Properly handle multi-line selections



commit 36e09f3ad9cd881eb3af0df242da6a1b5b26bb8d
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 5 15:54:49 2018 -0500

    label: Properly handle multi-line selections
    
    They were rendered as a single rectangle, which is not
    what is expected. Same for multi-line links.

 gtk/gtklabel.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 102f199..8df6e8f 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3921,7 +3921,8 @@ gtk_label_snapshot (GtkWidget   *widget,
         {
           gint range[2];
           cairo_region_t *range_clip;
-          cairo_rectangle_int_t clip_extents;
+          cairo_rectangle_int_t clip_rect;
+          int i;
 
           range[0] = info->selection_anchor;
           range[1] = info->selection_end;
@@ -3936,12 +3937,15 @@ gtk_label_snapshot (GtkWidget   *widget,
           gtk_style_context_save_to_node (context, info->selection_node);
 
           range_clip = gdk_pango_layout_get_clip_region (priv->layout, lx, ly, range, 1);
-          cairo_region_get_extents (range_clip, &clip_extents);
+          for (i = 0; i < cairo_region_num_rectangles (range_clip); i++)
+            {
+              cairo_region_get_rectangle (range_clip, i, &clip_rect);
 
-          gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_extents), "Selected Text");
-          gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
-          gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
-          gtk_snapshot_pop (snapshot);
+              gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_rect), "Selected Text");
+              gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
+              gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
+              gtk_snapshot_pop (snapshot);
+            }
 
           cairo_region_destroy (range_clip);
 
@@ -3953,7 +3957,8 @@ gtk_label_snapshot (GtkWidget   *widget,
           GtkLabelLink *active_link;
           gint range[2];
           cairo_region_t *range_clip;
-          cairo_rectangle_int_t clip_extents;
+          cairo_rectangle_int_t clip_rect;
+          int i;
           GdkRectangle rect;
 
           if (info->selectable &&
@@ -3980,12 +3985,15 @@ gtk_label_snapshot (GtkWidget   *widget,
               gtk_style_context_save_to_node (context, active_link->cssnode);
 
               range_clip = gdk_pango_layout_get_clip_region (priv->layout, lx, ly, range, 1);
-              cairo_region_get_extents (range_clip, &clip_extents);
+              for (i = 0; i < cairo_region_num_rectangles (range_clip); i++)
+                {
+                  cairo_region_get_rectangle (range_clip, i, &clip_rect);
 
-              gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_extents), "Active Link");
-              gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
-              gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
-              gtk_snapshot_pop (snapshot);
+                  gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_FROM_RECT (&clip_rect), "Active Link");
+                  gtk_snapshot_render_background (snapshot, context, x, 0, width, height);
+                  gtk_snapshot_render_layout (snapshot, context, lx, ly, priv->layout);
+                  gtk_snapshot_pop (snapshot);
+                }
 
               cairo_region_destroy (range_clip);
 


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