]> Pileus Git - ~andy/gtk/blob - gtk/gtktexthandle.c
Improve AtkAction implementations
[~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   gdk_window_set_user_data (window, priv->parent);
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   gdk_window_destroy (handle_window->window);
308
309   /* Create new window and apply old state */
310   handle_window->window = _gtk_text_handle_create_window (handle, pos);
311
312   if (visible)
313     {
314       gdk_window_show (handle_window->window);
315       _gtk_text_handle_set_position (handle, pos,
316                                      &handle_window->pointing_to);
317     }
318 }
319
320 static void
321 _gtk_text_handle_update_windows (GtkTextHandle *handle)
322 {
323   GtkTextHandlePrivate *priv = handle->priv;
324
325   gtk_style_context_invalidate (priv->style_context);
326   _gtk_text_handle_update_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
327   _gtk_text_handle_update_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
328 }
329
330 static void
331 gtk_text_handle_constructed (GObject *object)
332 {
333   GtkTextHandlePrivate *priv;
334
335   priv = GTK_TEXT_HANDLE (object)->priv;
336   g_assert (priv->parent != NULL);
337
338   priv->draw_signal_id =
339     g_signal_connect (priv->parent, "draw",
340                       G_CALLBACK (gtk_text_handle_widget_draw),
341                       object);
342   priv->event_signal_id =
343     g_signal_connect (priv->parent, "event",
344                       G_CALLBACK (gtk_text_handle_widget_event),
345                       object);
346   priv->composited_changed_id =
347     g_signal_connect_swapped (priv->parent, "composited-changed",
348                               G_CALLBACK (_gtk_text_handle_update_windows),
349                               object);
350   priv->style_updated_id =
351     g_signal_connect_swapped (priv->parent, "style-updated",
352                               G_CALLBACK (_gtk_text_handle_update_windows),
353                               object);
354 }
355
356 static void
357 gtk_text_handle_finalize (GObject *object)
358 {
359   GtkTextHandlePrivate *priv;
360
361   priv = GTK_TEXT_HANDLE (object)->priv;
362
363   if (priv->relative_to)
364     g_object_unref (priv->relative_to);
365
366   if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window)
367     gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
368
369   if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window)
370     gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
371
372   if (g_signal_handler_is_connected (priv->parent, priv->draw_signal_id))
373     g_signal_handler_disconnect (priv->parent, priv->draw_signal_id);
374
375   if (g_signal_handler_is_connected (priv->parent, priv->event_signal_id))
376     g_signal_handler_disconnect (priv->parent, priv->event_signal_id);
377
378   if (g_signal_handler_is_connected (priv->parent, priv->composited_changed_id))
379     g_signal_handler_disconnect (priv->parent, priv->composited_changed_id);
380
381   if (g_signal_handler_is_connected (priv->parent, priv->style_updated_id))
382     g_signal_handler_disconnect (priv->parent, priv->style_updated_id);
383
384   g_object_unref (priv->style_context);
385
386   G_OBJECT_CLASS (_gtk_text_handle_parent_class)->finalize (object);
387 }
388
389 static void
390 gtk_text_handle_set_property (GObject      *object,
391                               guint         prop_id,
392                               const GValue *value,
393                               GParamSpec   *pspec)
394 {
395   GtkTextHandlePrivate *priv;
396   GtkTextHandle *handle;
397
398   handle = GTK_TEXT_HANDLE (object);
399   priv = handle->priv;
400
401   switch (prop_id)
402     {
403     case PROP_PARENT:
404       priv->parent = g_value_get_object (value);
405       break;
406     case PROP_RELATIVE_TO:
407       _gtk_text_handle_set_relative_to (handle,
408                                         g_value_get_object (value));
409       break;
410     default:
411       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
412     }
413 }
414
415 static void
416 gtk_text_handle_get_property (GObject    *object,
417                               guint       prop_id,
418                               GValue     *value,
419                               GParamSpec *pspec)
420 {
421   GtkTextHandlePrivate *priv;
422
423   priv = GTK_TEXT_HANDLE (object)->priv;
424
425   switch (prop_id)
426     {
427     case PROP_PARENT:
428       g_value_set_object (value, priv->parent);
429       break;
430     case PROP_RELATIVE_TO:
431       g_value_set_object (value, priv->relative_to);
432       break;
433     default:
434       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
435     }
436 }
437
438 static void
439 _gtk_text_handle_class_init (GtkTextHandleClass *klass)
440 {
441   GObjectClass *object_class = G_OBJECT_CLASS (klass);
442
443   object_class->constructed = gtk_text_handle_constructed;
444   object_class->finalize = gtk_text_handle_finalize;
445   object_class->set_property = gtk_text_handle_set_property;
446   object_class->get_property = gtk_text_handle_get_property;
447
448   signals[HANDLE_DRAGGED] =
449     g_signal_new (I_("handle-dragged"),
450                   G_OBJECT_CLASS_TYPE (object_class),
451                   G_SIGNAL_RUN_LAST,
452                   G_STRUCT_OFFSET (GtkTextHandleClass, handle_dragged),
453                   NULL, NULL,
454                   _gtk_marshal_VOID__ENUM_INT_INT,
455                   G_TYPE_NONE, 3,
456                   GTK_TYPE_TEXT_HANDLE_POSITION,
457                   G_TYPE_INT, G_TYPE_INT);
458   signals[DRAG_FINISHED] =
459     g_signal_new (I_("drag-finished"),
460                   G_OBJECT_CLASS_TYPE (object_class),
461                   G_SIGNAL_RUN_LAST, 0,
462                   NULL, NULL,
463                   g_cclosure_marshal_VOID__ENUM,
464                   G_TYPE_NONE, 1,
465                   GTK_TYPE_TEXT_HANDLE_POSITION);
466
467   g_object_class_install_property (object_class,
468                                    PROP_PARENT,
469                                    g_param_spec_object ("parent",
470                                                         P_("Parent widget"),
471                                                         P_("Parent widget"),
472                                                         GTK_TYPE_WIDGET,
473                                                         GTK_PARAM_READWRITE |
474                                                         G_PARAM_CONSTRUCT_ONLY));
475   g_object_class_install_property (object_class,
476                                    PROP_RELATIVE_TO,
477                                    g_param_spec_object ("relative-to",
478                                                         P_("Window"),
479                                                         P_("Window the coordinates are based upon"),
480                                                         GDK_TYPE_WINDOW,
481                                                         GTK_PARAM_READWRITE));
482
483   g_type_class_add_private (object_class, sizeof (GtkTextHandlePrivate));
484 }
485
486 static void
487 _gtk_text_handle_init (GtkTextHandle *handle)
488 {
489   GtkTextHandlePrivate *priv;
490   GtkWidgetPath *path;
491
492   handle->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (handle,
493                                                      GTK_TYPE_TEXT_HANDLE,
494                                                      GtkTextHandlePrivate);
495
496   path = gtk_widget_path_new ();
497   gtk_widget_path_append_type (path, GTK_TYPE_TEXT_HANDLE);
498
499   priv->style_context = gtk_style_context_new ();
500   gtk_style_context_set_path (priv->style_context, path);
501   gtk_widget_path_free (path);
502 }
503
504 GtkTextHandle *
505 _gtk_text_handle_new (GtkWidget *parent)
506 {
507   return g_object_new (GTK_TYPE_TEXT_HANDLE,
508                        "parent", parent,
509                        NULL);
510 }
511
512 void
513 _gtk_text_handle_set_relative_to (GtkTextHandle *handle,
514                                   GdkWindow     *window)
515 {
516   GtkTextHandlePrivate *priv;
517
518   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
519   g_return_if_fail (!window || GDK_IS_WINDOW (window));
520
521   priv = handle->priv;
522
523   if (priv->relative_to)
524     {
525       gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
526       gdk_window_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
527       g_object_unref (priv->relative_to);
528     }
529
530   if (window)
531     {
532       priv->relative_to = g_object_ref (window);
533       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window =
534         _gtk_text_handle_create_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
535       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window =
536         _gtk_text_handle_create_window (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
537       priv->realized = TRUE;
538     }
539   else
540     {
541       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window = NULL;
542       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window = NULL;
543       priv->relative_to = NULL;
544       priv->realized = FALSE;
545     }
546
547   g_object_notify (G_OBJECT (handle), "relative-to");
548 }
549
550 void
551 _gtk_text_handle_set_mode (GtkTextHandle     *handle,
552                            GtkTextHandleMode  mode)
553 {
554   GtkTextHandlePrivate *priv;
555
556   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
557
558   priv = handle->priv;
559
560   if (priv->mode == mode)
561     return;
562
563   switch (mode)
564     {
565     case GTK_TEXT_HANDLE_MODE_CURSOR:
566       /* Only display one handle */
567       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_CURSOR].window);
568       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
569       break;
570       case GTK_TEXT_HANDLE_MODE_SELECTION:
571         /* Display both handles */
572       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
573       gdk_window_show (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
574       break;
575     case GTK_TEXT_HANDLE_MODE_NONE:
576     default:
577       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].window);
578       gdk_window_hide (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].window);
579       break;
580     }
581
582   priv->mode = mode;
583
584   _gtk_text_handle_update_shape (handle,
585                                  priv->windows[GTK_TEXT_HANDLE_POSITION_CURSOR].window,
586                                  GTK_TEXT_HANDLE_POSITION_CURSOR);
587 }
588
589 GtkTextHandleMode
590 _gtk_text_handle_get_mode (GtkTextHandle *handle)
591 {
592   GtkTextHandlePrivate *priv;
593
594   g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), GTK_TEXT_HANDLE_MODE_NONE);
595
596   priv = handle->priv;
597   return priv->mode;
598 }
599
600 void
601 _gtk_text_handle_set_position (GtkTextHandle         *handle,
602                                GtkTextHandlePosition  pos,
603                                GdkRectangle          *rect)
604 {
605   GtkTextHandlePrivate *priv;
606   gint x, y, width, height;
607   HandleWindow *handle_window;
608
609   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
610
611   priv = handle->priv;
612   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
613                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
614
615   if (!priv->realized)
616     return;
617
618   if (priv->mode == GTK_TEXT_HANDLE_MODE_NONE ||
619       (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
620        pos != GTK_TEXT_HANDLE_POSITION_CURSOR))
621     return;
622
623   gdk_window_get_root_coords (priv->relative_to,
624                               rect->x, rect->y,
625                               &x, &y);
626   _gtk_text_handle_get_size (handle, &width, &height);
627   handle_window = &priv->windows[pos];
628
629   if (pos == GTK_TEXT_HANDLE_POSITION_CURSOR)
630     y += rect->height;
631   else
632     y -= height;
633
634   x -= width / 2;
635
636   gdk_window_move (handle_window->window, x, y);
637   handle_window->pointing_to = *rect;
638 }
639
640 void
641 _gtk_text_handle_set_visible (GtkTextHandle         *handle,
642                               GtkTextHandlePosition  pos,
643                               gboolean               visible)
644 {
645   GtkTextHandlePrivate *priv;
646   GdkWindow *window;
647
648   g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
649
650   priv = handle->priv;
651   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
652                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
653
654   if (!priv->realized)
655     return;
656
657   window = priv->windows[pos].window;
658
659   if (!window)
660     return;
661
662   if (!visible)
663     gdk_window_hide (window);
664   else
665     {
666       if (priv->mode == GTK_TEXT_HANDLE_MODE_NONE ||
667           (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
668            pos != GTK_TEXT_HANDLE_POSITION_CURSOR))
669         return;
670
671       if (!gdk_window_is_visible (window))
672         gdk_window_show (window);
673     }
674 }
675
676 gboolean
677 _gtk_text_handle_get_is_dragged (GtkTextHandle         *handle,
678                                  GtkTextHandlePosition  pos)
679 {
680   GtkTextHandlePrivate *priv;
681
682   g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), FALSE);
683
684   priv = handle->priv;
685   pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
686                GTK_TEXT_HANDLE_POSITION_SELECTION_START);
687
688   return priv->windows[pos].dragged;
689 }