This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtktextview.c
9645 lines (7969 loc) · 288 KB
/
gtktextview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* GTK - The GIMP Toolkit
* gtktextview.c Copyright (C) 2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <string.h>
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkimagemenuitem.h"
#include "gtkintl.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkmenu.h"
#include "gtkmenuitem.h"
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
#include "gtkselectionprivate.h"
#include "gtkstock.h"
#include "gtktextbufferrichtext.h"
#include "gtktextdisplay.h"
#include "gtktextview.h"
#include "gtkimmulticontext.h"
#include "gtkprivate.h"
#include "gtktextutil.h"
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
#include "gtkscrollable.h"
#include "gtktypebuiltins.h"
#include "a11y/gtktextviewaccessible.h"
/**
* SECTION:gtktextview
* @Short_description: Widget that displays a GtkTextBuffer
* @Title: GtkTextView
* @See_also: #GtkTextBuffer, #GtkTextIter
*
* You may wish to begin by reading the <link linkend="TextWidget">text widget
* conceptual overview</link> which gives an overview of all the objects and data
* types related to the text widget and how they work together.
*/
/* How scrolling, validation, exposes, etc. work.
*
* The expose_event handler has the invariant that the onscreen lines
* have been validated.
*
* There are two ways that onscreen lines can become invalid. The first
* is to change which lines are onscreen. This happens when the value
* of a scroll adjustment changes. So the code path begins in
* gtk_text_view_value_changed() and goes like this:
* - gdk_window_scroll() to reflect the new adjustment value
* - validate the lines that were moved onscreen
* - gdk_window_process_updates() to handle the exposes immediately
*
* The second way is that you get the "invalidated" signal from the layout,
* indicating that lines have become invalid. This code path begins in
* invalidated_handler() and goes like this:
* - install high-priority idle which does the rest of the steps
* - if a scroll is pending from scroll_to_mark(), do the scroll,
* jumping to the gtk_text_view_value_changed() code path
* - otherwise, validate the onscreen lines
* - DO NOT process updates
*
* In both cases, validating the onscreen lines can trigger a scroll
* due to maintaining the first_para on the top of the screen.
* If validation triggers a scroll, we jump to the top of the code path
* for value_changed, and bail out of the current code path.
*
* Also, in size_allocate, if we invalidate some lines from changing
* the layout width, we need to go ahead and run the high-priority idle,
* because GTK sends exposes right after doing the size allocates without
* returning to the main loop. This is also why the high-priority idle
* is at a higher priority than resizing.
*
*/
#if 0
#define DEBUG_VALIDATION_AND_SCROLLING
#endif
#ifdef DEBUG_VALIDATION_AND_SCROLLING
#define DV(x) (x)
#else
#define DV(x)
#endif
#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->priv->text_window)
#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->priv->text_window)
#define SPACE_FOR_CURSOR 1
#define GTK_TEXT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewPrivate))
typedef struct _GtkTextWindow GtkTextWindow;
typedef struct _GtkTextPendingScroll GtkTextPendingScroll;
struct _GtkTextViewPrivate
{
GtkTextLayout *layout;
GtkTextBuffer *buffer;
guint blink_time; /* time in msec the cursor has blinked since last user event */
guint im_spot_idle;
gchar *im_module;
GdkDevice *grab_device;
GdkDevice *dnd_device;
gulong selection_drag_handler;
GtkTextWindow *text_window;
GtkTextWindow *left_window;
GtkTextWindow *right_window;
GtkTextWindow *top_window;
GtkTextWindow *bottom_window;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
gint xoffset; /* Offsets between widget coordinates and buffer coordinates */
gint yoffset;
gint width; /* Width and height of the buffer */
gint height;
/* This is used to monitor the overall size request
* and decide whether we need to queue resizes when
* the buffer content changes.
*
* FIXME: This could be done in a simpler way by
* consulting the above width/height of the buffer + some
* padding values, however all of this request code needs
* to be changed to use GtkWidget Iface and deserves
* more attention.
*/
GtkRequisition cached_size_request;
/* The virtual cursor position is normally the same as the
* actual (strong) cursor position, except in two circumstances:
*
* a) When the cursor is moved vertically with the keyboard
* b) When the text view is scrolled with the keyboard
*
* In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
* In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
*/
gint virtual_cursor_x; /* -1 means use actual cursor position */
gint virtual_cursor_y; /* -1 means use actual cursor position */
GtkTextMark *first_para_mark; /* Mark at the beginning of the first onscreen paragraph */
gint first_para_pixels; /* Offset of top of screen in the first onscreen paragraph */
guint blink_timeout;
guint scroll_timeout;
guint first_validate_idle; /* Idle to revalidate onscreen portion, runs before resize */
guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
gint pending_place_cursor_button;
GtkTextMark *dnd_mark;
GtkIMContext *im_context;
GtkWidget *popup_menu;
gint drag_start_x;
gint drag_start_y;
GSList *children;
GtkTextPendingScroll *pending_scroll;
/* Default style settings */
gint pixels_above_lines;
gint pixels_below_lines;
gint pixels_inside_wrap;
GtkWrapMode wrap_mode;
GtkJustification justify;
gint left_margin;
gint right_margin;
gint indent;
PangoTabArray *tabs;
guint editable : 1;
guint overwrite_mode : 1;
guint cursor_visible : 1;
/* if we have reset the IM since the last character entered */
guint need_im_reset : 1;
guint accepts_tab : 1;
guint width_changed : 1;
/* debug flag - means that we've validated onscreen since the
* last "invalidate" signal from the layout
*/
guint onscreen_validated : 1;
guint mouse_cursor_obscured : 1;
guint scroll_after_paste : 1;
/* GtkScrollablePolicy needs to be checked when
* driving the scrollable adjustment values */
guint hscroll_policy : 1;
guint vscroll_policy : 1;
};
struct _GtkTextPendingScroll
{
GtkTextMark *mark;
gdouble within_margin;
gboolean use_align;
gdouble xalign;
gdouble yalign;
};
enum
{
POPULATE_POPUP,
MOVE_CURSOR,
PAGE_HORIZONTALLY,
SET_ANCHOR,
INSERT_AT_CURSOR,
DELETE_FROM_CURSOR,
BACKSPACE,
CUT_CLIPBOARD,
COPY_CLIPBOARD,
PASTE_CLIPBOARD,
TOGGLE_OVERWRITE,
MOVE_VIEWPORT,
SELECT_ALL,
TOGGLE_CURSOR_VISIBLE,
PREEDIT_CHANGED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_PIXELS_ABOVE_LINES,
PROP_PIXELS_BELOW_LINES,
PROP_PIXELS_INSIDE_WRAP,
PROP_EDITABLE,
PROP_WRAP_MODE,
PROP_JUSTIFICATION,
PROP_LEFT_MARGIN,
PROP_RIGHT_MARGIN,
PROP_INDENT,
PROP_TABS,
PROP_CURSOR_VISIBLE,
PROP_BUFFER,
PROP_OVERWRITE,
PROP_ACCEPTS_TAB,
PROP_IM_MODULE,
PROP_HADJUSTMENT,
PROP_VADJUSTMENT,
PROP_HSCROLL_POLICY,
PROP_VSCROLL_POLICY
};
static void gtk_text_view_finalize (GObject *object);
static void gtk_text_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_text_view_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_text_view_destroy (GtkWidget *widget);
static void gtk_text_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_text_view_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural);
static void gtk_text_view_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural);
static void gtk_text_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_text_view_realize (GtkWidget *widget);
static void gtk_text_view_unrealize (GtkWidget *widget);
static void gtk_text_view_style_updated (GtkWidget *widget);
static void gtk_text_view_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction);
static void gtk_text_view_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
static void gtk_text_view_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
static gint gtk_text_view_event (GtkWidget *widget,
GdkEvent *event);
static gint gtk_text_view_key_press_event (GtkWidget *widget,
GdkEventKey *event);
static gint gtk_text_view_key_release_event (GtkWidget *widget,
GdkEventKey *event);
static gint gtk_text_view_button_press_event (GtkWidget *widget,
GdkEventButton *event);
static gint gtk_text_view_button_release_event (GtkWidget *widget,
GdkEventButton *event);
static gint gtk_text_view_focus_in_event (GtkWidget *widget,
GdkEventFocus *event);
static gint gtk_text_view_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
static gint gtk_text_view_motion_event (GtkWidget *widget,
GdkEventMotion *event);
static gint gtk_text_view_draw (GtkWidget *widget,
cairo_t *cr);
static void gtk_text_view_draw_focus (GtkWidget *widget,
cairo_t *cr);
static gboolean gtk_text_view_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_text_view_select_all (GtkWidget *widget,
gboolean select);
/* Source side drag signals */
static void gtk_text_view_drag_begin (GtkWidget *widget,
GdkDragContext *context);
static void gtk_text_view_drag_end (GtkWidget *widget,
GdkDragContext *context);
static void gtk_text_view_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time);
static void gtk_text_view_drag_data_delete (GtkWidget *widget,
GdkDragContext *context);
/* Target side drag signals */
static void gtk_text_view_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time);
static gboolean gtk_text_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static void gtk_text_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time);
static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
static void gtk_text_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step,
gint count,
gboolean extend_selection);
static void gtk_text_view_move_viewport (GtkTextView *text_view,
GtkScrollStep step,
gint count);
static void gtk_text_view_set_anchor (GtkTextView *text_view);
static gboolean gtk_text_view_scroll_pages (GtkTextView *text_view,
gint count,
gboolean extend_selection);
static gboolean gtk_text_view_scroll_hpages(GtkTextView *text_view,
gint count,
gboolean extend_selection);
static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
const gchar *str);
static void gtk_text_view_delete_from_cursor (GtkTextView *text_view,
GtkDeleteType type,
gint count);
static void gtk_text_view_backspace (GtkTextView *text_view);
static void gtk_text_view_cut_clipboard (GtkTextView *text_view);
static void gtk_text_view_copy_clipboard (GtkTextView *text_view);
static void gtk_text_view_paste_clipboard (GtkTextView *text_view);
static void gtk_text_view_toggle_overwrite (GtkTextView *text_view);
static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view);
static void gtk_text_view_unselect (GtkTextView *text_view);
static void gtk_text_view_validate_onscreen (GtkTextView *text_view);
static void gtk_text_view_get_first_para_iter (GtkTextView *text_view,
GtkTextIter *iter);
static void gtk_text_view_update_layout_width (GtkTextView *text_view);
static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
GtkTextAttributes *values);
static void gtk_text_view_ensure_layout (GtkTextView *text_view);
static void gtk_text_view_destroy_layout (GtkTextView *text_view);
static void gtk_text_view_check_keymap_direction (GtkTextView *text_view);
static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event);
static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view);
static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventMotion *event);
static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
static void gtk_text_view_value_changed (GtkAdjustment *adjustment,
GtkTextView *view);
static void gtk_text_view_commit_handler (GtkIMContext *context,
const gchar *str,
GtkTextView *text_view);
static void gtk_text_view_commit_text (GtkTextView *text_view,
const gchar *text);
static void gtk_text_view_preedit_changed_handler (GtkIMContext *context,
GtkTextView *text_view);
static gboolean gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
GtkTextView *text_view);
static gboolean gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
gint offset,
gint n_chars,
GtkTextView *text_view);
static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
const GtkTextIter *location,
GtkTextMark *mark,
gpointer data);
static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
const GParamSpec *pspec,
gpointer data);
static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gpointer data);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
gint *x,
gint *y);
static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
gint x,
gint y);
static void gtk_text_view_do_popup (GtkTextView *text_view,
GdkEventButton *event);
static void cancel_pending_scroll (GtkTextView *text_view);
static void gtk_text_view_queue_scroll (GtkTextView *text_view,
GtkTextMark *mark,
gdouble within_margin,
gboolean use_align,
gdouble xalign,
gdouble yalign);
static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
static void gtk_text_view_update_adjustments (GtkTextView *text_view);
static void gtk_text_view_invalidate (GtkTextView *text_view);
static void gtk_text_view_flush_first_validate (GtkTextView *text_view);
static void gtk_text_view_set_hadjustment (GtkTextView *text_view,
GtkAdjustment *adjustment);
static void gtk_text_view_set_vadjustment (GtkTextView *text_view,
GtkAdjustment *adjustment);
static void gtk_text_view_set_hadjustment_values (GtkTextView *text_view);
static void gtk_text_view_set_vadjustment_values (GtkTextView *text_view);
static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
/* Container methods */
static void gtk_text_view_add (GtkContainer *container,
GtkWidget *child);
static void gtk_text_view_remove (GtkContainer *container,
GtkWidget *child);
static void gtk_text_view_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
/* FIXME probably need the focus methods. */
typedef struct _GtkTextViewChild GtkTextViewChild;
struct _GtkTextViewChild
{
GtkWidget *widget;
GtkTextChildAnchor *anchor;
gint from_top_of_line;
gint from_left_of_buffer;
/* These are ignored if anchor != NULL */
GtkTextWindowType type;
gint x;
gint y;
};
static GtkTextViewChild* text_view_child_new_anchored (GtkWidget *child,
GtkTextChildAnchor *anchor,
GtkTextLayout *layout);
static GtkTextViewChild* text_view_child_new_window (GtkWidget *child,
GtkTextWindowType type,
gint x,
gint y);
static void text_view_child_free (GtkTextViewChild *child);
static void text_view_child_set_parent_window (GtkTextView *text_view,
GtkTextViewChild *child);
struct _GtkTextWindow
{
GtkTextWindowType type;
GtkWidget *widget;
GdkWindow *window;
GdkWindow *bin_window;
GtkRequisition requisition;
GdkRectangle allocation;
};
static GtkTextWindow *text_window_new (GtkTextWindowType type,
GtkWidget *widget,
gint width_request,
gint height_request);
static void text_window_free (GtkTextWindow *win);
static void text_window_realize (GtkTextWindow *win,
GtkWidget *widget);
static void text_window_unrealize (GtkTextWindow *win);
static void text_window_size_allocate (GtkTextWindow *win,
GdkRectangle *rect);
static void text_window_scroll (GtkTextWindow *win,
gint dx,
gint dy);
static void text_window_invalidate_rect (GtkTextWindow *win,
GdkRectangle *rect);
static void text_window_invalidate_cursors (GtkTextWindow *win);
static gint text_window_get_width (GtkTextWindow *win);
static gint text_window_get_height (GtkTextWindow *win);
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_CODE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static void
add_move_binding (GtkBindingSet *binding_set,
guint keyval,
guint modmask,
GtkMovementStep step,
gint count)
{
g_assert ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, FALSE);
/* Selection-extending version */
gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, TRUE);
}
static void
gtk_text_view_class_init (GtkTextViewClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
/* Default handlers and virtual methods
*/
gobject_class->set_property = gtk_text_view_set_property;
gobject_class->get_property = gtk_text_view_get_property;
gobject_class->finalize = gtk_text_view_finalize;
widget_class->destroy = gtk_text_view_destroy;
widget_class->realize = gtk_text_view_realize;
widget_class->unrealize = gtk_text_view_unrealize;
widget_class->style_updated = gtk_text_view_style_updated;
widget_class->direction_changed = gtk_text_view_direction_changed;
widget_class->grab_notify = gtk_text_view_grab_notify;
widget_class->state_flags_changed = gtk_text_view_state_flags_changed;
widget_class->get_preferred_width = gtk_text_view_get_preferred_width;
widget_class->get_preferred_height = gtk_text_view_get_preferred_height;
widget_class->size_allocate = gtk_text_view_size_allocate;
widget_class->event = gtk_text_view_event;
widget_class->key_press_event = gtk_text_view_key_press_event;
widget_class->key_release_event = gtk_text_view_key_release_event;
widget_class->button_press_event = gtk_text_view_button_press_event;
widget_class->button_release_event = gtk_text_view_button_release_event;
widget_class->focus_in_event = gtk_text_view_focus_in_event;
widget_class->focus_out_event = gtk_text_view_focus_out_event;
widget_class->motion_notify_event = gtk_text_view_motion_event;
widget_class->draw = gtk_text_view_draw;
widget_class->focus = gtk_text_view_focus;
widget_class->drag_begin = gtk_text_view_drag_begin;
widget_class->drag_end = gtk_text_view_drag_end;
widget_class->drag_data_get = gtk_text_view_drag_data_get;
widget_class->drag_data_delete = gtk_text_view_drag_data_delete;
widget_class->drag_leave = gtk_text_view_drag_leave;
widget_class->drag_motion = gtk_text_view_drag_motion;
widget_class->drag_drop = gtk_text_view_drag_drop;
widget_class->drag_data_received = gtk_text_view_drag_data_received;
widget_class->popup_menu = gtk_text_view_popup_menu;
container_class->add = gtk_text_view_add;
container_class->remove = gtk_text_view_remove;
container_class->forall = gtk_text_view_forall;
klass->move_cursor = gtk_text_view_move_cursor;
klass->set_anchor = gtk_text_view_set_anchor;
klass->insert_at_cursor = gtk_text_view_insert_at_cursor;
klass->delete_from_cursor = gtk_text_view_delete_from_cursor;
klass->backspace = gtk_text_view_backspace;
klass->cut_clipboard = gtk_text_view_cut_clipboard;
klass->copy_clipboard = gtk_text_view_copy_clipboard;
klass->paste_clipboard = gtk_text_view_paste_clipboard;
klass->toggle_overwrite = gtk_text_view_toggle_overwrite;
/*
* Properties
*/
g_object_class_install_property (gobject_class,
PROP_PIXELS_ABOVE_LINES,
g_param_spec_int ("pixels-above-lines",
P_("Pixels Above Lines"),
P_("Pixels of blank space above paragraphs"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PIXELS_BELOW_LINES,
g_param_spec_int ("pixels-below-lines",
P_("Pixels Below Lines"),
P_("Pixels of blank space below paragraphs"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PIXELS_INSIDE_WRAP,
g_param_spec_int ("pixels-inside-wrap",
P_("Pixels Inside Wrap"),
P_("Pixels of blank space between wrapped lines in a paragraph"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_EDITABLE,
g_param_spec_boolean ("editable",
P_("Editable"),
P_("Whether the text can be modified by the user"),
TRUE,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_WRAP_MODE,
g_param_spec_enum ("wrap-mode",
P_("Wrap Mode"),
P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
GTK_TYPE_WRAP_MODE,
GTK_WRAP_NONE,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_JUSTIFICATION,
g_param_spec_enum ("justification",
P_("Justification"),
P_("Left, right, or center justification"),
GTK_TYPE_JUSTIFICATION,
GTK_JUSTIFY_LEFT,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LEFT_MARGIN,
g_param_spec_int ("left-margin",
P_("Left Margin"),
P_("Width of the left margin in pixels"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_RIGHT_MARGIN,
g_param_spec_int ("right-margin",
P_("Right Margin"),
P_("Width of the right margin in pixels"),
0,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_INDENT,
g_param_spec_int ("indent",
P_("Indent"),
P_("Amount to indent the paragraph, in pixels"),
G_MININT,
G_MAXINT,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TABS,
g_param_spec_boxed ("tabs",
P_("Tabs"),
P_("Custom tabs for this text"),
PANGO_TYPE_TAB_ARRAY,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_CURSOR_VISIBLE,
g_param_spec_boolean ("cursor-visible",
P_("Cursor Visible"),
P_("If the insertion cursor is shown"),
TRUE,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_BUFFER,
g_param_spec_object ("buffer",
P_("Buffer"),
P_("The buffer which is displayed"),
GTK_TYPE_TEXT_BUFFER,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_OVERWRITE,
g_param_spec_boolean ("overwrite",
P_("Overwrite mode"),
P_("Whether entered text overwrites existing contents"),
FALSE,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ACCEPTS_TAB,
g_param_spec_boolean ("accepts-tab",
P_("Accepts tab"),
P_("Whether Tab will result in a tab character being entered"),
TRUE,
GTK_PARAM_READWRITE));
/**
* GtkTextView:im-module:
*
* Which IM (input method) module should be used for this entry.
* See #GtkIMContext.
*
* Setting this to a non-%NULL value overrides the
* system-wide IM module setting. See the GtkSettings
* #GtkSettings:gtk-im-module property.
*
* Since: 2.16
*/
g_object_class_install_property (gobject_class,
PROP_IM_MODULE,
g_param_spec_string ("im-module",
P_("IM module"),
P_("Which IM module should be used"),
NULL,
GTK_PARAM_READWRITE));
/* GtkScrollable interface */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
/*
* Style properties
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("error-underline-color",
P_("Error underline color"),
P_("Color with which to draw error-indication underlines"),
GDK_TYPE_COLOR,
GTK_PARAM_READABLE));
/*
* Signals
*/
/**
* GtkTextView::move-cursor:
* @text_view: the object which received the signal
* @step: the granularity of the move, as a #GtkMovementStep
* @count: the number of @step units to move
* @extend_selection: %TRUE if the move should extend the selection
*
* The ::move-cursor signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted when the user initiates a cursor movement.
* If the cursor is not visible in @text_view, this signal causes
* the viewport to be moved instead.
*
* Applications should not connect to it, but may emit it with
* g_signal_emit_by_name() if they need to control the cursor
* programmatically.
*
* The default bindings for this signal come in two variants,
* the variant with the Shift modifier extends the selection,
* the variant without the Shift modifer does not.
* There are too many key combinations to list them all here.
* <itemizedlist>
* <listitem>Arrow keys move by individual characters/lines</listitem>
* <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
* <listitem>Home/End keys move to the ends of the buffer</listitem>
* <listitem>PageUp/PageDown keys move vertically by pages</listitem>
* <listitem>Ctrl-PageUp/PageDown keys move horizontally by pages</listitem>
* </itemizedlist>
*/
signals[MOVE_CURSOR] =
g_signal_new (I_("move-cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
NULL, NULL,
_gtk_marshal_VOID__ENUM_INT_BOOLEAN,
G_TYPE_NONE, 3,
GTK_TYPE_MOVEMENT_STEP,
G_TYPE_INT,
G_TYPE_BOOLEAN);
/**
* GtkTextView::move-viewport:
* @text_view: the object which received the signal
* @step: the granularity of the move, as a #GtkMovementStep
* @count: the number of @step units to move
*
* The ::move-viewport signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which can be bound to key combinations to allow the user
* to move the viewport, i.e. change what part of the text view
* is visible in a containing scrolled window.
*
* There are no default bindings for this signal.
*/
signals[MOVE_VIEWPORT] =
g_signal_new_class_handler (I_("move-viewport"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_CALLBACK (gtk_text_view_move_viewport),
NULL, NULL,
_gtk_marshal_VOID__ENUM_INT,
G_TYPE_NONE, 2,
GTK_TYPE_SCROLL_STEP,
G_TYPE_INT);
/**
* GtkTextView::set-anchor:
* @text_view: the object which received the signal
*
* The ::set-anchor signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted when the user initiates setting the "anchor"
* mark. The "anchor" mark gets placed at the same position as the
* "insert" mark.
*
* This signal has no default bindings.
*/
signals[SET_ANCHOR] =
g_signal_new (I_("set-anchor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkTextView::insert-at-cursor:
* @text_view: the object which received the signal
* @string: the string to insert
*
* The ::insert-at-cursor signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted when the user initiates the insertion of a
* fixed string at the cursor.
*
* This signal has no default bindings.
*/
signals[INSERT_AT_CURSOR] =
g_signal_new (I_("insert-at-cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
NULL, NULL,
_gtk_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
/**
* GtkTextView::delete-from-cursor:
* @text_view: the object which received the signal
* @type: the granularity of the deletion, as a #GtkDeleteType
* @count: the number of @type units to delete
*
* The ::delete-from-cursor signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted when the user initiates a text deletion.
*
* If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
* if there is one, otherwise it deletes the requested number
* of characters.
*
* The default bindings for this signal are
* Delete for deleting a character, Ctrl-Delete for
* deleting a word and Ctrl-Backspace for deleting a word
* backwords.
*/
signals[DELETE_FROM_CURSOR] =
g_signal_new (I_("delete-from-cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
NULL, NULL,
_gtk_marshal_VOID__ENUM_INT,
G_TYPE_NONE, 2,
GTK_TYPE_DELETE_TYPE,
G_TYPE_INT);
/**
* GtkTextView::backspace:
* @text_view: the object which received the signal
*
* The ::backspace signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted when the user asks for it.
*
* The default bindings for this signal are
* Backspace and Shift-Backspace.
*/
signals[BACKSPACE] =
g_signal_new (I_("backspace"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, backspace),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkTextView::cut-clipboard:
* @text_view: the object which received the signal
*
* The ::cut-clipboard signal is a
* <link linkend="keybinding-signals">keybinding signal</link>
* which gets emitted to cut the selection to the clipboard.
*
* The default bindings for this signal are
* Ctrl-x and Shift-Delete.
*/
signals[CUT_CLIPBOARD] =
g_signal_new (I_("cut-clipboard"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkTextView::copy-clipboard:
* @text_view: the object which received the signal