]> Pileus Git - ~andy/gtk/blob - gtk/gtktexthandle.c
Add gtk_widget_get/set_opacity
[~andy/gtk] / gtk / gtktexthandle.c
1 /* GTK - The GIMP Toolkit
2  * Copyright © 2012 Carlos Garnacho <carlosg@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19 #include "gtkprivatetypebuiltins.h"
20 #include "gtktexthandleprivate.h"
21 #include "gtkmarshalers.h"
22 #include "gtkprivate.h"
23 #include "gtkintl.h"
24
25 #include <gtk/gtk.h>
26
27 typedef struct _GtkTextHandlePrivate GtkTextHandlePrivate;
28 typedef struct _HandleWindow HandleWindow;
29
30 enum {
31   HANDLE_DRAGGED,
32   DRAG_FINISHED,
33   LAST_SIGNAL
34 };
35
36 enum {
37   PROP_0,
38   PROP_PARENT,
39   PROP_RELATIVE_TO
40 };
41
42 struct _HandleWindow
43 {
44   GdkWindow *window;
45   GdkRectangle pointing_to;
46   gint dx;
47   gint dy;
48   guint dragged : 1;
49 };
50
51 struct _GtkTextHandlePrivate
52 {
53   HandleWindow windows[2];
54   GtkWidget *parent;
55   GdkWindow *relative_to;
56   GtkStyleContext *style_context;
57
58   gulong draw_signal_id;
59   gulong event_signal_id;
60   gulong style_updated_id;
61   gulong composited_changed_id;
62   guint realized : 1;
63   guint mode : 2;
64 };
65
66 G_DEFINE_TYPE (GtkTextHandle, _gtk_text_handle, G_TYPE_OBJECT)
67
68 static guint signals[LAST_SIGNAL] = { 0 };
69
70 static void
71 _gtk_text_handle_get_size (GtkTextHandle *handle,
72                            gint          *width,
73                            gint          *height)
74 {
75   GtkTextHandlePrivate *priv;
76   gint w, h;
77
78   priv = handle->priv;
79
80   gtk_widget_style_get (priv->parent,
81                         "text-handle-width", &w,
82                         "text-handle-height", &h,
83                         NULL);
84   if (width)
85     *width = w;
86
87   if (height)
88     *height = h;
89 }
90
91 static void
92 _gtk_text_handle_draw (GtkTextHandle         *handle,
93                        cairo_t               *cr,
94                        GtkTextHandlePosition  pos)
95 {
96   GtkTextHandlePrivate *priv;
97   gint width, height;
98
99   priv = handle->priv;
100   cairo_save (cr);
101
102   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
103   cairo_set_source_rgba (cr, 0, 0, 0, 0);
104   cairo_paint (cr);
105
106   gtk_style_context_save (priv->style_context);
107   gtk_style_context_add_class (priv->style_context,
108                                GTK_STYLE_CLASS_CURSOR_HANDLE);
109
110   if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
111     {
112       gtk_style_context_add_class (priv->style_context,
113                                    GTK_STYLE_CLASS_BOTTOM);
114
115       if (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR)
116         gtk_style_context_add_class (priv->style_context,
117                                      GTK_STYLE_CLASS_INSERTION_CURSOR);
118     }
119   else
120     gtk_style_context_add_class (priv->style_context,
121                                  GTK_STYLE_CLASS_TOP);
122
123   _gtk_text_handle_get_size (handle, &width, &height);
124   gtk_render_background (priv->style_context, cr, 0, 0, width, height);
125
126   gtk_style_context_restore (priv->style_context);
127   cairo_restore (cr);
128 }
129
130 static void
131 _gtk_text_handle_update_shape (GtkTextHandle         *handle,
132                                GdkWindow             *window,
133                                GtkTextHandlePosition  pos)
134 {
135   GtkTextHandlePrivate *priv;
136   cairo_surface_t *surface;
137   cairo_region_t *region;
138   cairo_t *cr;
139
140   priv = handle->priv;
141
142   surface =
143     gdk_window_create_similar_surface (window,
144                                        CAIRO_CONTENT_COLOR_ALPHA,
145                                        gdk_window_get_width (window),
146                                        gdk_window_get_height (window));
147
148   cr = cairo_create (surface);
149   _gtk_text_handle_draw (handle, cr, pos);
150   cairo_destroy (cr);
151
152   region = gdk_cairo_region_create_from_surface (surface);
153
154   if (gtk_widget_is_composited (priv->parent))
155     gdk_window_shape_combine_region (window, NULL, 0, 0);
156   else
157     gdk_window_shape_combine_region (window, region, 0, 0);
158
159   gdk_window_input_shape_combine_region (window, region, 0, 0);
160
161   cairo_surface_destroy (surface);
162   cairo_region_destroy (region);
163 }
164
165 static GdkWindow *
166 _gtk_text_handle_create_window (GtkTextHandle         *handle,
167                                 GtkTextHandlePosition  pos)
168 {
169   GtkTextHandlePrivate *priv;
170   GdkRGBA bg = { 0, 0, 0, 0 };
171   GdkWindowAttr attributes;
172   GdkWindow *window;
173   GdkVisual *visual;
174   gint mask;
175
176   priv = handle->priv;
177
178   attributes.x = 0;
179   attributes.y = 0;
180   _gtk_text_handle_get_size (handle, &attributes.width, &attributes.height);
181   attributes.window_type = GDK_WINDOW_TEMP;
182   attributes.wclass = GDK_INPUT_OUTPUT;
183   attributes.event_mask = (GDK_EXPOSURE_MASK |
184                            GDK_BUTTON_PRESS_MASK |
185                            GDK_BUTTON_RELEASE_MASK |
186                            GDK_BUTTON1_MOTION_MASK);
187
188   mask = GDK_WA_X | GDK_WA_Y;
189
190   visual = gdk_screen_get_rgba_visual (gtk_widget_get_screen (priv->parent));
191
192   if (visual)
193     {
194       attributes.visual = visual;
195       mask |= GDK_WA_VISUAL;
196     }
197
198   window = gdk_window_new (gtk_widget_get_root_window (priv->parent),
199                            &attributes, mask);
200   gtk_widget_register_window (priv->parent, window);
201   gdk_window_set_background_rgba (window, &bg);
202
203   _gtk_text_handle_update_shape (handle, window, pos);
204
205   return window;
206 }
207
208 static gboolean
209 gtk_text_handle_widget_draw (GtkWidget     *widget,
210                              cairo_t       *cr,
211                              GtkTextHandle *handle)
212 {
213   GtkTextHandlePrivate *priv;
214   GtkTextHandlePosition pos;
215
216   priv = handle->priv;
217
218   if (!priv->realized)
219     return FALSE;
220
221   if (gtk_cairo_should_draw_window (cr, priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window))
222     pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
223   else if (gtk_cairo_should_draw_window (cr, priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window))
224     pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
225   else
226     return FALSE;
227
228   _gtk_text_handle_draw (handle, cr, pos);
229   return TRUE;
230 }
231
232 static gboolean
233 gtk_text_handle_widget_event (GtkWidget     *widget,
234                               GdkEvent      *event,
235                               GtkTextHandle *handle)
236 {
237   GtkTextHandlePrivate *priv;
238   GtkTextHandlePosition pos;
239
240   priv = handle->priv;
241
242   if (event->any.window == priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window)
243     pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
244   else if (event->any.window == priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window)
245     pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
246   else
247     return FALSE;
248
249   if (event->type == GDK_BUTTON_PRESS)
250     {
251       priv->windows[pos].dx = event->button.x;
252       priv->windows[pos].dy = event->button.y;
253       priv->windows[pos].dragged = TRUE;
254     }
255   else if (event->type == GDK_BUTTON_RELEASE)
256     {
257       g_signal_emit (handle, signals[DRAG_FINISHED], 0, pos);
258       priv->windows[pos].dx =  priv->windows[pos].dy = 0;
259       priv->windows[pos].dragged = FALSE;
260     }
261   else if (event->type == GDK_MOTION_NOTIFY && priv->windows[pos].dragged)
262     {
263       gint x, y, width, height;
264
265       _gtk_text_handle_get_size (handle, &width, &height);
266       gdk_window_get_origin (priv->relative_to, &x, &y);
267
268       x = event->motion.x_root - priv->windows[pos].dx + (width / 2) - x;
269       y = event->motion.y_root - priv->windows[pos].dy - y;
270
271       if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_START)
272         y += height;
273
274       g_signal_emit (handle, signals[HANDLE_DRAGGED], 0, pos, x, y);
275     }
276
277   return TRUE;
278 }
279
280 static void
281 _gtk_text_handle_update_window (GtkTextHandle         *handle,
282                                 GtkTextHandlePosition  pos)
283 {
284   GtkTextHandlePrivate *priv;
285   HandleWindow *handle_window;
286   gboolean visible;
287   gint x, y;
288
289   priv = handle->priv;
290   handle_window = &priv->windows[pos];
291
292   if (!handle_window->window)
293     return;
294
295   /* Get current state and destroy */
296   visible = gdk_window_is_visible (handle_window->window);
297
298   if (visible)
299     {
300       gint width;
301
302       _gtk_text_handle_get_size (handle, &width, NULL);
303       gdk_window_get_root_coords (handle_window->window,
304                                   width / 2, 0, &x, &y);
305     }
306
307   gtk_widget_unregister_window (priv->parent, handle_window->window);
308   gdk_window_destroy (handle_window->window);
309
310   /* Create new window and apply old state */
311   handle_window->window = _gtk_text_handle_create_window (handle, pos);
312
313   if (visible)
314     {
315       gdk_window_show (handle_window->window);
316       _gtk_text_handle_set_position (handle, pos,
317                                      &handle_window->pointing_to);
318     }
319 }
320
321 static void
322 _gtk_text_handle_update_windows (GtkTextHandle *handle)
323 {
324   GtkTextHandlePrivate *priv = handle->priv;
325
326   gtk_style_context_invalidate (priv->style_context);
327   _gtk_text_handle_update_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
328   _gtk_text_handle_update_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
329 }
330
331 static void
332 gtk_text_handle_constructed (GObject *object)
333 {
334   GtkTextHandlePrivate *priv;
335
336   priv = GTK_TEXT_HANDLE (object)->priv;
337   g_assert (priv->parent != NULL);
338
339   priv->draw_signal_id =
340     g_signal_connect (priv->parent, "draw",
341                       G_CALLBACK (gtk_text_handle_widget_draw),
342                       object);
343   priv->event_signal_id =
344     g_signal_connect (priv->parent, "event",
345                       G_CALLBACK (gtk_text_handle_widget_event),
346                       object);
347   priv->composited_changed_id =
348     g_signal_connect_swapped (priv->parent, "composited-changed",
349                               G_CALLBACK (_gtk_text_handle_update_windows),
350                               object);
351   priv->style_updated_id =
352     g_signal_connect_swapped (priv->parent, "style-updated",
353                               G_CALLBACK (_gtk_text_handle_update_windows),
354                               object);
355 }
356
357 static void
358 gtk_text_handle_finalize (GObject *object)
359 {
360   GtkTextHandlePrivate *priv;
361
362   priv = GTK_TEXT_HANDLE (object)->priv;
363
364   if (priv->relative_to)
365     g_object_unref (priv->relative_to);
366
367   if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window)
368     gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
369
370   if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window)
371     gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
372
373   if (g_signal_handler_is_connected (priv->parent, priv->draw_signal_id))
374     g_signal_handler_disconnect (priv->parent, priv->draw_signal_id);
375
376   if (g_signal_handler_is_connected (priv->parent, priv->event_signal_id))
377     g_signal_handler_disconnect (priv->parent, priv->event_signal_id);
378
379   if (g_signal_handler_is_connected (priv->parent, priv->composited_changed_id))
380     g_signal_handler_disconnect (priv->parent, priv->composited_changed_id);
381
382   if (g_signal_handler_is_connected (priv->parent, priv->style_updated_id))
383     g_signal_handler_disconnect (priv->parent, priv->style_updated_id);
384
385   g_object_unref (priv->style_context);
386
387   G_OBJECT_CLASS (_gtk_text_handle_parent_class)->finalize (object);
388 }
389
390 static void
391 gtk_text_handle_set_property (GObject      *object,
392                               guint         prop_id,
393                               const GValue *value,
394                               GParamSpec   *pspec)
395 {
396   GtkTextHandlePrivate *priv;
397   GtkTextHandle *handle;
398
399   handle = GTK_TEXT_HANDLE (object);
400   priv = handle->priv;
401
402   switch (prop_id)
403     {
404     case PROP_PARENT:
405       priv->parent = g_value_get_object (value);
406       break;
407     case PROP_RELATIVE_TO:
408       _gtk_text_handle_set_relative_to (handle,
409                                         g_value_get_object (value));
410       break;
411     default:
412       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
413     }
414 }
415
416 static void
417 gtk_text_handle_get_property (GObject    *object,
418                               guint       prop_id,
419                               GValue     *value,
420                               GParamSpec *pspec)
421 {
422   GtkTextHandlePrivate *priv;
423
424   priv = GTK_TEXT_HANDLE (object)->priv;
425
426   switch (prop_id)
427     {
428     case PROP_PARENT:
429       g_value_set_object (value, priv->parent);
430       break;
431     case PROP_RELATIVE_TO:
432       g_value_set_object (value, priv->relative_to);
433       break;
434     default:
435       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
436     }
437 }
438
439 static void
440 _gtk_text_handle_class_init (GtkTextHandleClass *klass)
441 {
442   GObjectClass *object_class = G_OBJECT_CLASS (klass);
443
444   object_class->constructed = gtk_text_handle_constructed;
445   object_class->finalize = gtk_text_handle_finalize;
446   object_class->set_property = gtk_text_handle_set_property;
447   object_class->get_property = gtk_text_handle_get_property;
448
449   signals[HANDLE_DRAGGED] =
450     g_signal_new (I_("handle-dragged"),
451                   G_OBJECT_CLASS_TYPE (object_class),
452                   G_SIGNAL_RUN_LAST,
453                   G_STRUCT_OFFSET (GtkTextHandleClass, handle_dragged),
454                   NULL, NULL,
455                   _gtk_marshal_VOID__ENUM_INT_INT,
456                   G_TYPE_NONE, 3,
457                   GTK_TYPE_TEXT_HANDLE_POSITION,
458                   G_TYPE_INT, G_TYPE_INT);
459   signals[DRAG_FINISHED] =
460     g_signal_new (I_("drag-finished"),
461                   G_OBJECT_CLASS_TYPE (object_class),
462                   G_SIGNAL_RUN_LAST, 0,
463                   NULL, NULL,
464                   g_cclosure_marshal_VOID__ENUM,
465                   G_TYPE_NONE, 1,
466                   GTK_TYPE_TEXT_HANDLE_POSITION);
467
468   g_object_class_install_property (object_class,
469                                    PROP_PARENT,
470                                    g_param_spec_object ("parent",
471                                                         P_("Parent widget"),
472                                                         P_("Parent widget"),
473                                                         GTK_TYPE_WIDGET,
474                                                         GTK_PARAM_READWRITE |
475                                                         G_PARAM_CONSTRUCT_ONLY));
476   g_object_class_install_property (object_class,
477                                    PROP_RELATIVE_TO,
478                                    g_param_spec_object ("relative-to",
479                                                         P_("Window"),
480                                                         P_("Window the coordinates are based upon"),
481                                                         GDK_TYPE_WINDOW,
482                                                         GTK_PARAM_READWRITE));
483
484   g_type_class_add_private (object_class, sizeof (GtkTextHandlePrivate));
485 }
486
487 static void
488 _gtk_text_handle_init (GtkTextHandle *handle)
489 {
490   GtkTextHandlePrivate *priv;
491   GtkWidgetPath *path;
492
493   handle->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (handle,
494                                                      GTK_TYPE_TEXT_HANDLE,
495                                                      GtkTextHandlePrivate);
496
497   path = gtk_widget_path_new ();
498   gtk_widget_path_append_type (path, GTK_TYPE_TEXT_HANDLE);
499
500   priv->style_context = gtk_style_context_new ();
501   gtk_style_context_set_path (priv->style_context, path);
502   gtk_widget_path_free (path);
503 }
504
505 GtkTextHandle *
506 _gtk_text_handle_new (GtkWidget *parent)
507 {
508   return g_object_new (GTK_TYPE_TEXT_HANDLE,
509                        "parent", parent,
510                        NULL);
511 }
512
513 void
514 _gtk_text_handle_set_relative_to (GtkTextHandle *handle,
515                                   GdkWindow     *window)
516 {
517   GtkTextHandlePrivate *priv;
518
519   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
520   g_return_if_fail (!window || GDK_IS_WINDOW (window));
521
522   priv = handle->priv;
523
524   if (priv->relative_to)
525     {
526       gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
527       gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
528       g_object_unref (priv->relative_to);
529     }
530
531   if (window)
532     {
533       priv->relative_to = g_object_ref (window);
534       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window =
535         _gtk_text_handle_create_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
536       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window =
537         _gtk_text_handle_create_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
538       priv->realized = TRUE;
539     }
540   else
541     {
542       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window = NULL;
543       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window = NULL;
544       priv->relative_to = NULL;
545       priv->realized = FALSE;
546     }
547
548   g_object_notify (G_OBJECT (handle), "relative-to");
549 }
550
551 void
552 _gtk_text_handle_set_mode (GtkTextHandle     *handle,
553                            GtkTextHandleMode  mode)
554 {
555   GtkTextHandlePrivate *priv;
556
557   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
558
559   priv = handle->priv;
560
561   if (priv->mode == mode)
562     return;
563
564   switch (mode)
565     {
566     case GTK_TEXT_HANDLE_MODE_CURSOR:
567       /* Only display one handle */
568       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_CURSOR].window);
569       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
570       break;
571       case GTK_TEXT_HANDLE_MODE_SELECTION:
572         /* Display both handles */
573       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
574       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
575       break;
576     case GTK_TEXT_HANDLE_MODE_NONE:
577     default:
578       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
579       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
580       break;
581     }
582
583   priv->mode = mode;
584
585   _gtk_text_handle_update_shape (handle,
586                                  priv->windows[GTK_TEXT_HANDLE_POSITION_CURSOR].window,
587                                  GTK_TEXT_HANDLE_POSITION_CURSOR);
588 }
589
590 GtkTextHandleMode
591 _gtk_text_handle_get_mode (GtkTextHandle *handle)
592 {
593   GtkTextHandlePrivate *priv;
594
595   g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), GTK_TEXT_HANDLE_MODE_NONE);
596
597   priv = handle->priv;
598   return priv->mode;
599 }
600
601 void
602 _gtk_text_handle_set_position (GtkTextHandle         *handle,
603                                GtkTextHandlePosition  pos,
604                                GdkRectangle          *rect)
605 {
606   GtkTextHandlePrivate *priv;
607   gint x, y, width, height;
608   HandleWindow *handle_window;
609
610   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
611
612   priv = handle->priv;
613   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
614                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
615
616   if (!priv->realized)
617     return;
618
619   if (priv->mode == GTK_TEXT_HANDLE_MODE_NONE ||
620       (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
621        pos != GTK_TEXT_HANDLE_POSITION_CURSOR))
622     return;
623
624   gdk_window_get_root_coords (priv->relative_to,
625                               rect->x, rect->y,
626                               &x, &y);
627   _gtk_text_handle_get_size (handle, &width, &height);
628   handle_window = &priv->windows[pos];
629
630   if (pos == GTK_TEXT_HANDLE_POSITION_CURSOR)
631     y += rect->height;
632   else
633     y -= height;
634
635   x -= width / 2;
636
637   gdk_window_move (handle_window->window, x, y);
638   handle_window->pointing_to = *rect;
639 }
640
641 void
642 _gtk_text_handle_set_visible (GtkTextHandle         *handle,
643                               GtkTextHandlePosition  pos,
644                               gboolean               visible)
645 {
646   GtkTextHandlePrivate *priv;
647   GdkWindow *window;
648
649   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
650
651   priv = handle->priv;
652   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
653                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
654
655   if (!priv->realized)
656     return;
657
658   window = priv->windows[pos].window;
659
660   if (!window)
661     return;
662
663   if (!visible)
664     gdk_window_hide (window);
665   else
666     {
667       if (priv->mode == GTK_TEXT_HANDLE_MODE_NONE ||
668           (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
669            pos != GTK_TEXT_HANDLE_POSITION_CURSOR))
670         return;
671
672       if (!gdk_window_is_visible (window))
673         gdk_window_show (window);
674     }
675 }
676
677 gboolean
678 _gtk_text_handle_get_is_dragged (GtkTextHandle         *handle,
679                                  GtkTextHandlePosition  pos)
680 {
681   GtkTextHandlePrivate *priv;
682
683   g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), FALSE);
684
685   priv = handle->priv;
686   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
687                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
688
689   return priv->windows[pos].dragged;
690 }