1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
2 /* GTK - The GIMP Toolkit
3 * gtktextview.c Copyright (C) 2000 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
32 #include "gtkbindings.h"
34 #include "gtkimagemenuitem.h"
37 #include "gtkmarshalers.h"
39 #include "gtkmenuitem.h"
40 #include "gtkseparatormenuitem.h"
41 #include "gtksettings.h"
43 #include "gtktextbufferrichtext.h"
44 #include "gtktextdisplay.h"
45 #include "gtktextview.h"
46 #include "gtkimmulticontext.h"
47 #include "gdk/gdkkeysyms.h"
48 #include "gtkprivate.h"
49 #include "gtktextutil.h"
50 #include "gtkwidgetprivate.h"
51 #include "gtkwindow.h"
54 /* How scrolling, validation, exposes, etc. work.
56 * The expose_event handler has the invariant that the onscreen lines
57 * have been validated.
59 * There are two ways that onscreen lines can become invalid. The first
60 * is to change which lines are onscreen. This happens when the value
61 * of a scroll adjustment changes. So the code path begins in
62 * gtk_text_view_value_changed() and goes like this:
63 * - gdk_window_scroll() to reflect the new adjustment value
64 * - validate the lines that were moved onscreen
65 * - gdk_window_process_updates() to handle the exposes immediately
67 * The second way is that you get the "invalidated" signal from the layout,
68 * indicating that lines have become invalid. This code path begins in
69 * invalidated_handler() and goes like this:
70 * - install high-priority idle which does the rest of the steps
71 * - if a scroll is pending from scroll_to_mark(), do the scroll,
72 * jumping to the gtk_text_view_value_changed() code path
73 * - otherwise, validate the onscreen lines
74 * - DO NOT process updates
76 * In both cases, validating the onscreen lines can trigger a scroll
77 * due to maintaining the first_para on the top of the screen.
78 * If validation triggers a scroll, we jump to the top of the code path
79 * for value_changed, and bail out of the current code path.
81 * Also, in size_allocate, if we invalidate some lines from changing
82 * the layout width, we need to go ahead and run the high-priority idle,
83 * because GTK sends exposes right after doing the size allocates without
84 * returning to the main loop. This is also why the high-priority idle
85 * is at a higher priority than resizing.
90 #define DEBUG_VALIDATION_AND_SCROLLING
93 #ifdef DEBUG_VALIDATION_AND_SCROLLING
99 #define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->priv->text_window)
100 #define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->priv->text_window)
102 #define SPACE_FOR_CURSOR 1
104 #define GTK_TEXT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewPrivate))
106 typedef struct _GtkTextWindow GtkTextWindow;
107 typedef struct _GtkTextPendingScroll GtkTextPendingScroll;
109 struct _GtkTextViewPrivate
111 GtkTextLayout *layout;
112 GtkTextBuffer *buffer;
114 guint blink_time; /* time in msec the cursor has blinked since last user event */
117 GdkDevice *grab_device;
118 GdkDevice *dnd_device;
120 guint selection_drag_handler;
121 guint scroll_timeout;
123 GtkTextWindow *text_window;
124 GtkTextWindow *left_window;
125 GtkTextWindow *right_window;
126 GtkTextWindow *top_window;
127 GtkTextWindow *bottom_window;
129 GtkAdjustment *hadjustment;
130 GtkAdjustment *vadjustment;
132 gint xoffset; /* Offsets between widget coordinates and buffer coordinates */
134 gint width; /* Width and height of the buffer */
137 /* This is used to monitor the overall size request
138 * and decide whether we need to queue resizes when
139 * the buffer content changes.
141 * FIXME: This could be done in a simpler way by
142 * consulting the above width/height of the buffer + some
143 * padding values, however all of this request code needs
144 * to be changed to use GtkWidget Iface and deserves
147 GtkRequisition cached_size_request;
149 /* The virtual cursor position is normally the same as the
150 * actual (strong) cursor position, except in two circumstances:
152 * a) When the cursor is moved vertically with the keyboard
153 * b) When the text view is scrolled with the keyboard
155 * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
156 * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
158 gint virtual_cursor_x; /* -1 means use actual cursor position */
159 gint virtual_cursor_y; /* -1 means use actual cursor position */
161 GtkTextMark *first_para_mark; /* Mark at the beginning of the first onscreen paragraph */
162 gint first_para_pixels; /* Offset of top of screen in the first onscreen paragraph */
164 GtkTextMark *dnd_mark;
167 guint first_validate_idle; /* Idle to revalidate onscreen portion, runs before resize */
168 guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
170 GtkIMContext *im_context;
171 GtkWidget *popup_menu;
178 GtkTextPendingScroll *pending_scroll;
180 gint pending_place_cursor_button;
182 /* Default style settings */
183 gint pixels_above_lines;
184 gint pixels_below_lines;
185 gint pixels_inside_wrap;
186 GtkWrapMode wrap_mode;
187 GtkJustification justify;
194 guint overwrite_mode : 1;
195 guint cursor_visible : 1;
197 /* if we have reset the IM since the last character entered */
198 guint need_im_reset : 1;
200 guint accepts_tab : 1;
202 guint width_changed : 1;
204 /* debug flag - means that we've validated onscreen since the
205 * last "invalidate" signal from the layout
207 guint onscreen_validated : 1;
209 guint mouse_cursor_obscured : 1;
211 guint scroll_after_paste : 1;
214 struct _GtkTextPendingScroll
217 gdouble within_margin;
225 SET_SCROLL_ADJUSTMENTS,
239 TOGGLE_CURSOR_VISIBLE,
247 PROP_PIXELS_ABOVE_LINES,
248 PROP_PIXELS_BELOW_LINES,
249 PROP_PIXELS_INSIDE_WRAP,
264 static void gtk_text_view_finalize (GObject *object);
265 static void gtk_text_view_set_property (GObject *object,
269 static void gtk_text_view_get_property (GObject *object,
273 static void gtk_text_view_destroy (GtkWidget *widget);
274 static void gtk_text_view_size_request (GtkWidget *widget,
275 GtkRequisition *requisition);
276 static void gtk_text_view_size_allocate (GtkWidget *widget,
277 GtkAllocation *allocation);
278 static void gtk_text_view_realize (GtkWidget *widget);
279 static void gtk_text_view_unrealize (GtkWidget *widget);
280 static void gtk_text_view_style_set (GtkWidget *widget,
281 GtkStyle *previous_style);
282 static void gtk_text_view_direction_changed (GtkWidget *widget,
283 GtkTextDirection previous_direction);
284 static void gtk_text_view_grab_notify (GtkWidget *widget,
285 gboolean was_grabbed);
286 static void gtk_text_view_state_changed (GtkWidget *widget,
287 GtkStateType previous_state);
289 static gint gtk_text_view_event (GtkWidget *widget,
291 static gint gtk_text_view_key_press_event (GtkWidget *widget,
293 static gint gtk_text_view_key_release_event (GtkWidget *widget,
295 static gint gtk_text_view_button_press_event (GtkWidget *widget,
296 GdkEventButton *event);
297 static gint gtk_text_view_button_release_event (GtkWidget *widget,
298 GdkEventButton *event);
299 static gint gtk_text_view_focus_in_event (GtkWidget *widget,
300 GdkEventFocus *event);
301 static gint gtk_text_view_focus_out_event (GtkWidget *widget,
302 GdkEventFocus *event);
303 static gint gtk_text_view_motion_event (GtkWidget *widget,
304 GdkEventMotion *event);
305 static gint gtk_text_view_draw (GtkWidget *widget,
307 static void gtk_text_view_draw_focus (GtkWidget *widget,
309 static gboolean gtk_text_view_focus (GtkWidget *widget,
310 GtkDirectionType direction);
311 static void gtk_text_view_select_all (GtkWidget *widget,
315 /* Source side drag signals */
316 static void gtk_text_view_drag_begin (GtkWidget *widget,
317 GdkDragContext *context);
318 static void gtk_text_view_drag_end (GtkWidget *widget,
319 GdkDragContext *context);
320 static void gtk_text_view_drag_data_get (GtkWidget *widget,
321 GdkDragContext *context,
322 GtkSelectionData *selection_data,
325 static void gtk_text_view_drag_data_delete (GtkWidget *widget,
326 GdkDragContext *context);
328 /* Target side drag signals */
329 static void gtk_text_view_drag_leave (GtkWidget *widget,
330 GdkDragContext *context,
332 static gboolean gtk_text_view_drag_motion (GtkWidget *widget,
333 GdkDragContext *context,
337 static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
338 GdkDragContext *context,
342 static void gtk_text_view_drag_data_received (GtkWidget *widget,
343 GdkDragContext *context,
346 GtkSelectionData *selection_data,
350 static void gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
352 GtkAdjustment *vadj);
353 static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
355 static void gtk_text_view_move_cursor (GtkTextView *text_view,
356 GtkMovementStep step,
358 gboolean extend_selection);
359 static gboolean gtk_text_view_move_viewport (GtkTextView *text_view,
362 static void gtk_text_view_set_anchor (GtkTextView *text_view);
363 static gboolean gtk_text_view_scroll_pages (GtkTextView *text_view,
365 gboolean extend_selection);
366 static gboolean gtk_text_view_scroll_hpages(GtkTextView *text_view,
368 gboolean extend_selection);
369 static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
371 static void gtk_text_view_delete_from_cursor (GtkTextView *text_view,
374 static void gtk_text_view_backspace (GtkTextView *text_view);
375 static void gtk_text_view_cut_clipboard (GtkTextView *text_view);
376 static void gtk_text_view_copy_clipboard (GtkTextView *text_view);
377 static void gtk_text_view_paste_clipboard (GtkTextView *text_view);
378 static void gtk_text_view_toggle_overwrite (GtkTextView *text_view);
379 static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view);
381 static void gtk_text_view_unselect (GtkTextView *text_view);
383 static void gtk_text_view_validate_onscreen (GtkTextView *text_view);
384 static void gtk_text_view_get_first_para_iter (GtkTextView *text_view,
386 static void gtk_text_view_update_layout_width (GtkTextView *text_view);
387 static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
388 GtkTextAttributes *values,
390 static void gtk_text_view_ensure_layout (GtkTextView *text_view);
391 static void gtk_text_view_destroy_layout (GtkTextView *text_view);
392 static void gtk_text_view_check_keymap_direction (GtkTextView *text_view);
393 static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
394 const GtkTextIter *iter,
395 GdkEventButton *event);
396 static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view);
397 static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
398 const GtkTextIter *iter,
399 GdkEventMotion *event);
400 static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
401 static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
402 static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
403 static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
405 static void gtk_text_view_value_changed (GtkAdjustment *adj,
407 static void gtk_text_view_commit_handler (GtkIMContext *context,
409 GtkTextView *text_view);
410 static void gtk_text_view_commit_text (GtkTextView *text_view,
412 static void gtk_text_view_preedit_changed_handler (GtkIMContext *context,
413 GtkTextView *text_view);
414 static gboolean gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
415 GtkTextView *text_view);
416 static gboolean gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
419 GtkTextView *text_view);
421 static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
422 const GtkTextIter *location,
425 static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
426 const GParamSpec *pspec,
428 static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
429 GtkClipboard *clipboard,
431 static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
433 static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
437 static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
441 static GtkAdjustment* get_hadjustment (GtkTextView *text_view);
442 static GtkAdjustment* get_vadjustment (GtkTextView *text_view);
444 static void gtk_text_view_do_popup (GtkTextView *text_view,
445 GdkEventButton *event);
447 static void cancel_pending_scroll (GtkTextView *text_view);
448 static void gtk_text_view_queue_scroll (GtkTextView *text_view,
450 gdouble within_margin,
455 static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
456 static void gtk_text_view_update_adjustments (GtkTextView *text_view);
457 static void gtk_text_view_invalidate (GtkTextView *text_view);
458 static void gtk_text_view_flush_first_validate (GtkTextView *text_view);
460 static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
462 /* Container methods */
463 static void gtk_text_view_add (GtkContainer *container,
465 static void gtk_text_view_remove (GtkContainer *container,
467 static void gtk_text_view_forall (GtkContainer *container,
468 gboolean include_internals,
469 GtkCallback callback,
470 gpointer callback_data);
472 /* FIXME probably need the focus methods. */
474 typedef struct _GtkTextViewChild GtkTextViewChild;
476 struct _GtkTextViewChild
480 GtkTextChildAnchor *anchor;
482 gint from_top_of_line;
483 gint from_left_of_buffer;
485 /* These are ignored if anchor != NULL */
486 GtkTextWindowType type;
491 static GtkTextViewChild* text_view_child_new_anchored (GtkWidget *child,
492 GtkTextChildAnchor *anchor,
493 GtkTextLayout *layout);
494 static GtkTextViewChild* text_view_child_new_window (GtkWidget *child,
495 GtkTextWindowType type,
498 static void text_view_child_free (GtkTextViewChild *child);
499 static void text_view_child_set_parent_window (GtkTextView *text_view,
500 GtkTextViewChild *child);
502 struct _GtkTextWindow
504 GtkTextWindowType type;
507 GdkWindow *bin_window;
508 GtkRequisition requisition;
509 GdkRectangle allocation;
512 static GtkTextWindow *text_window_new (GtkTextWindowType type,
515 gint height_request);
516 static void text_window_free (GtkTextWindow *win);
517 static void text_window_realize (GtkTextWindow *win,
519 static void text_window_unrealize (GtkTextWindow *win);
520 static void text_window_size_allocate (GtkTextWindow *win,
522 static void text_window_scroll (GtkTextWindow *win,
525 static void text_window_invalidate_rect (GtkTextWindow *win,
527 static void text_window_invalidate_cursors (GtkTextWindow *win);
529 static gint text_window_get_width (GtkTextWindow *win);
530 static gint text_window_get_height (GtkTextWindow *win);
533 static guint signals[LAST_SIGNAL] = { 0 };
535 G_DEFINE_TYPE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER)
538 add_move_binding (GtkBindingSet *binding_set,
541 GtkMovementStep step,
544 g_assert ((modmask & GDK_SHIFT_MASK) == 0);
546 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
550 G_TYPE_BOOLEAN, FALSE);
552 /* Selection-extending version */
553 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
557 G_TYPE_BOOLEAN, TRUE);
561 gtk_text_view_class_init (GtkTextViewClass *klass)
563 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
564 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
565 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
566 GtkBindingSet *binding_set;
568 /* Default handlers and virtual methods
570 gobject_class->set_property = gtk_text_view_set_property;
571 gobject_class->get_property = gtk_text_view_get_property;
572 gobject_class->finalize = gtk_text_view_finalize;
574 widget_class->destroy = gtk_text_view_destroy;
575 widget_class->realize = gtk_text_view_realize;
576 widget_class->unrealize = gtk_text_view_unrealize;
577 widget_class->style_set = gtk_text_view_style_set;
578 widget_class->direction_changed = gtk_text_view_direction_changed;
579 widget_class->grab_notify = gtk_text_view_grab_notify;
580 widget_class->state_changed = gtk_text_view_state_changed;
581 widget_class->size_request = gtk_text_view_size_request;
582 widget_class->size_allocate = gtk_text_view_size_allocate;
583 widget_class->event = gtk_text_view_event;
584 widget_class->key_press_event = gtk_text_view_key_press_event;
585 widget_class->key_release_event = gtk_text_view_key_release_event;
586 widget_class->button_press_event = gtk_text_view_button_press_event;
587 widget_class->button_release_event = gtk_text_view_button_release_event;
588 widget_class->focus_in_event = gtk_text_view_focus_in_event;
589 widget_class->focus_out_event = gtk_text_view_focus_out_event;
590 widget_class->motion_notify_event = gtk_text_view_motion_event;
591 widget_class->draw = gtk_text_view_draw;
592 widget_class->focus = gtk_text_view_focus;
593 widget_class->drag_begin = gtk_text_view_drag_begin;
594 widget_class->drag_end = gtk_text_view_drag_end;
595 widget_class->drag_data_get = gtk_text_view_drag_data_get;
596 widget_class->drag_data_delete = gtk_text_view_drag_data_delete;
598 widget_class->drag_leave = gtk_text_view_drag_leave;
599 widget_class->drag_motion = gtk_text_view_drag_motion;
600 widget_class->drag_drop = gtk_text_view_drag_drop;
601 widget_class->drag_data_received = gtk_text_view_drag_data_received;
603 widget_class->popup_menu = gtk_text_view_popup_menu;
605 container_class->add = gtk_text_view_add;
606 container_class->remove = gtk_text_view_remove;
607 container_class->forall = gtk_text_view_forall;
609 klass->move_cursor = gtk_text_view_move_cursor;
610 klass->set_anchor = gtk_text_view_set_anchor;
611 klass->insert_at_cursor = gtk_text_view_insert_at_cursor;
612 klass->delete_from_cursor = gtk_text_view_delete_from_cursor;
613 klass->backspace = gtk_text_view_backspace;
614 klass->cut_clipboard = gtk_text_view_cut_clipboard;
615 klass->copy_clipboard = gtk_text_view_copy_clipboard;
616 klass->paste_clipboard = gtk_text_view_paste_clipboard;
617 klass->toggle_overwrite = gtk_text_view_toggle_overwrite;
618 klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
624 g_object_class_install_property (gobject_class,
625 PROP_PIXELS_ABOVE_LINES,
626 g_param_spec_int ("pixels-above-lines",
627 P_("Pixels Above Lines"),
628 P_("Pixels of blank space above paragraphs"),
632 GTK_PARAM_READWRITE));
634 g_object_class_install_property (gobject_class,
635 PROP_PIXELS_BELOW_LINES,
636 g_param_spec_int ("pixels-below-lines",
637 P_("Pixels Below Lines"),
638 P_("Pixels of blank space below paragraphs"),
642 GTK_PARAM_READWRITE));
644 g_object_class_install_property (gobject_class,
645 PROP_PIXELS_INSIDE_WRAP,
646 g_param_spec_int ("pixels-inside-wrap",
647 P_("Pixels Inside Wrap"),
648 P_("Pixels of blank space between wrapped lines in a paragraph"),
652 GTK_PARAM_READWRITE));
654 g_object_class_install_property (gobject_class,
656 g_param_spec_boolean ("editable",
658 P_("Whether the text can be modified by the user"),
660 GTK_PARAM_READWRITE));
662 g_object_class_install_property (gobject_class,
664 g_param_spec_enum ("wrap-mode",
666 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
669 GTK_PARAM_READWRITE));
671 g_object_class_install_property (gobject_class,
673 g_param_spec_enum ("justification",
675 P_("Left, right, or center justification"),
676 GTK_TYPE_JUSTIFICATION,
678 GTK_PARAM_READWRITE));
680 g_object_class_install_property (gobject_class,
682 g_param_spec_int ("left-margin",
684 P_("Width of the left margin in pixels"),
688 GTK_PARAM_READWRITE));
690 g_object_class_install_property (gobject_class,
692 g_param_spec_int ("right-margin",
694 P_("Width of the right margin in pixels"),
698 GTK_PARAM_READWRITE));
700 g_object_class_install_property (gobject_class,
702 g_param_spec_int ("indent",
704 P_("Amount to indent the paragraph, in pixels"),
708 GTK_PARAM_READWRITE));
710 g_object_class_install_property (gobject_class,
712 g_param_spec_boxed ("tabs",
714 P_("Custom tabs for this text"),
715 PANGO_TYPE_TAB_ARRAY,
716 GTK_PARAM_READWRITE));
718 g_object_class_install_property (gobject_class,
720 g_param_spec_boolean ("cursor-visible",
721 P_("Cursor Visible"),
722 P_("If the insertion cursor is shown"),
724 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_object ("buffer",
730 P_("The buffer which is displayed"),
731 GTK_TYPE_TEXT_BUFFER,
732 GTK_PARAM_READWRITE));
734 g_object_class_install_property (gobject_class,
736 g_param_spec_boolean ("overwrite",
737 P_("Overwrite mode"),
738 P_("Whether entered text overwrites existing contents"),
740 GTK_PARAM_READWRITE));
742 g_object_class_install_property (gobject_class,
744 g_param_spec_boolean ("accepts-tab",
746 P_("Whether Tab will result in a tab character being entered"),
748 GTK_PARAM_READWRITE));
751 * GtkTextView:im-module:
753 * Which IM (input method) module should be used for this entry.
756 * Setting this to a non-%NULL value overrides the
757 * system-wide IM module setting. See the GtkSettings
758 * #GtkSettings:gtk-im-module property.
762 g_object_class_install_property (gobject_class,
764 g_param_spec_string ("im-module",
766 P_("Which IM module should be used"),
768 GTK_PARAM_READWRITE));
773 gtk_widget_class_install_style_property (widget_class,
774 g_param_spec_boxed ("error-underline-color",
775 P_("Error underline color"),
776 P_("Color with which to draw error-indication underlines"),
778 GTK_PARAM_READABLE));
785 * GtkTextView::move-cursor:
786 * @text_view: the object which received the signal
787 * @step: the granularity of the move, as a #GtkMovementStep
788 * @count: the number of @step units to move
789 * @extend_selection: %TRUE if the move should extend the selection
791 * The ::move-cursor signal is a
792 * <link linkend="keybinding-signals">keybinding signal</link>
793 * which gets emitted when the user initiates a cursor movement.
794 * If the cursor is not visible in @text_view, this signal causes
795 * the viewport to be moved instead.
797 * Applications should not connect to it, but may emit it with
798 * g_signal_emit_by_name() if they need to control the cursor
801 * The default bindings for this signal come in two variants,
802 * the variant with the Shift modifier extends the selection,
803 * the variant without the Shift modifer does not.
804 * There are too many key combinations to list them all here.
806 * <listitem>Arrow keys move by individual characters/lines</listitem>
807 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
808 * <listitem>Home/End keys move to the ends of the buffer</listitem>
809 * <listitem>PageUp/PageDown keys move vertically by pages</listitem>
810 * <listitem>Ctrl-PageUp/PageDown keys move horizontally by pages</listitem>
813 signals[MOVE_CURSOR] =
814 g_signal_new (I_("move-cursor"),
815 G_OBJECT_CLASS_TYPE (gobject_class),
816 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
817 G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
819 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
821 GTK_TYPE_MOVEMENT_STEP,
826 * GtkTextView::move-viewport:
827 * @text_view: the object which received the signal
828 * @step: the granularity of the move, as a #GtkMovementStep
829 * @count: the number of @step units to move
831 * The ::move-viewport signal is a
832 * <link linkend="keybinding-signals">keybinding signal</link>
833 * which can be bound to key combinations to allow the user
834 * to move the viewport, i.e. change what part of the text view
835 * is visible in a containing scrolled window.
837 * There are no default bindings for this signal.
839 signals[MOVE_VIEWPORT] =
840 g_signal_new_class_handler (I_("move-viewport"),
841 G_OBJECT_CLASS_TYPE (gobject_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_CALLBACK (gtk_text_view_move_viewport),
845 _gtk_marshal_VOID__ENUM_INT,
847 GTK_TYPE_SCROLL_STEP,
851 * GtkTextView::set-anchor:
852 * @text_view: the object which received the signal
854 * The ::set-anchor signal is a
855 * <link linkend="keybinding-signals">keybinding signal</link>
856 * which gets emitted when the user initiates setting the "anchor"
857 * mark. The "anchor" mark gets placed at the same position as the
860 * This signal has no default bindings.
862 signals[SET_ANCHOR] =
863 g_signal_new (I_("set-anchor"),
864 G_OBJECT_CLASS_TYPE (gobject_class),
865 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
866 G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
868 _gtk_marshal_VOID__VOID,
872 * GtkTextView::insert-at-cursor:
873 * @text_view: the object which received the signal
874 * @string: the string to insert
876 * The ::insert-at-cursor signal is a
877 * <link linkend="keybinding-signals">keybinding signal</link>
878 * which gets emitted when the user initiates the insertion of a
879 * fixed string at the cursor.
881 * This signal has no default bindings.
883 signals[INSERT_AT_CURSOR] =
884 g_signal_new (I_("insert-at-cursor"),
885 G_OBJECT_CLASS_TYPE (gobject_class),
886 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
887 G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
889 _gtk_marshal_VOID__STRING,
894 * GtkTextView::delete-from-cursor:
895 * @text_view: the object which received the signal
896 * @type: the granularity of the deletion, as a #GtkDeleteType
897 * @count: the number of @type units to delete
899 * The ::delete-from-cursor signal is a
900 * <link linkend="keybinding-signals">keybinding signal</link>
901 * which gets emitted when the user initiates a text deletion.
903 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
904 * if there is one, otherwise it deletes the requested number
907 * The default bindings for this signal are
908 * Delete for deleting a character, Ctrl-Delete for
909 * deleting a word and Ctrl-Backspace for deleting a word
912 signals[DELETE_FROM_CURSOR] =
913 g_signal_new (I_("delete-from-cursor"),
914 G_OBJECT_CLASS_TYPE (gobject_class),
915 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
916 G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
918 _gtk_marshal_VOID__ENUM_INT,
920 GTK_TYPE_DELETE_TYPE,
924 * GtkTextView::backspace:
925 * @text_view: the object which received the signal
927 * The ::backspace signal is a
928 * <link linkend="keybinding-signals">keybinding signal</link>
929 * which gets emitted when the user asks for it.
931 * The default bindings for this signal are
932 * Backspace and Shift-Backspace.
935 g_signal_new (I_("backspace"),
936 G_OBJECT_CLASS_TYPE (gobject_class),
937 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
938 G_STRUCT_OFFSET (GtkTextViewClass, backspace),
940 _gtk_marshal_VOID__VOID,
944 * GtkTextView::cut-clipboard:
945 * @text_view: the object which received the signal
947 * The ::cut-clipboard signal is a
948 * <link linkend="keybinding-signals">keybinding signal</link>
949 * which gets emitted to cut the selection to the clipboard.
951 * The default bindings for this signal are
952 * Ctrl-x and Shift-Delete.
954 signals[CUT_CLIPBOARD] =
955 g_signal_new (I_("cut-clipboard"),
956 G_OBJECT_CLASS_TYPE (gobject_class),
957 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
958 G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
960 _gtk_marshal_VOID__VOID,
964 * GtkTextView::copy-clipboard:
965 * @text_view: the object which received the signal
967 * The ::copy-clipboard signal is a
968 * <link linkend="keybinding-signals">keybinding signal</link>
969 * which gets emitted to copy the selection to the clipboard.
971 * The default bindings for this signal are
972 * Ctrl-c and Ctrl-Insert.
974 signals[COPY_CLIPBOARD] =
975 g_signal_new (I_("copy-clipboard"),
976 G_OBJECT_CLASS_TYPE (gobject_class),
977 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
978 G_STRUCT_OFFSET (GtkTextViewClass, copy_clipboard),
980 _gtk_marshal_VOID__VOID,
984 * GtkTextView::paste-clipboard:
985 * @text_view: the object which received the signal
987 * The ::paste-clipboard signal is a
988 * <link linkend="keybinding-signals">keybinding signal</link>
989 * which gets emitted to paste the contents of the clipboard
990 * into the text view.
992 * The default bindings for this signal are
993 * Ctrl-v and Shift-Insert.
995 signals[PASTE_CLIPBOARD] =
996 g_signal_new (I_("paste-clipboard"),
997 G_OBJECT_CLASS_TYPE (gobject_class),
998 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
999 G_STRUCT_OFFSET (GtkTextViewClass, paste_clipboard),
1001 _gtk_marshal_VOID__VOID,
1005 * GtkTextView::toggle-overwrite:
1006 * @text_view: the object which received the signal
1008 * The ::toggle-overwrite signal is a
1009 * <link linkend="keybinding-signals">keybinding signal</link>
1010 * which gets emitted to toggle the overwrite mode of the text view.
1012 * The default bindings for this signal is Insert.
1014 signals[TOGGLE_OVERWRITE] =
1015 g_signal_new (I_("toggle-overwrite"),
1016 G_OBJECT_CLASS_TYPE (gobject_class),
1017 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1018 G_STRUCT_OFFSET (GtkTextViewClass, toggle_overwrite),
1020 _gtk_marshal_VOID__VOID,
1024 * GtkTextView::set-scroll-adjustments
1025 * @horizontal: the horizontal #GtkAdjustment
1026 * @vertical: the vertical #GtkAdjustment
1028 * Set the scroll adjustments for the text view. Usually scrolled containers
1029 * like #GtkScrolledWindow will emit this signal to connect two instances
1030 * of #GtkScrollbar to the scroll directions of the #GtkTextView.
1032 signals[SET_SCROLL_ADJUSTMENTS] =
1033 g_signal_new (I_("set-scroll-adjustments"),
1034 G_OBJECT_CLASS_TYPE (gobject_class),
1035 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1036 G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments),
1038 _gtk_marshal_VOID__OBJECT_OBJECT,
1040 GTK_TYPE_ADJUSTMENT,
1041 GTK_TYPE_ADJUSTMENT);
1042 widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
1045 * GtkTextView::populate-popup:
1046 * @entry: The text view on which the signal is emitted
1047 * @menu: the menu that is being populated
1049 * The ::populate-popup signal gets emitted before showing the
1050 * context menu of the text view.
1052 * If you need to add items to the context menu, connect
1053 * to this signal and append your menuitems to the @menu.
1055 signals[POPULATE_POPUP] =
1056 g_signal_new (I_("populate-popup"),
1057 G_OBJECT_CLASS_TYPE (gobject_class),
1059 G_STRUCT_OFFSET (GtkTextViewClass, populate_popup),
1061 _gtk_marshal_VOID__OBJECT,
1066 * GtkTextView::select-all:
1067 * @text_view: the object which received the signal
1068 * @select: %TRUE to select, %FALSE to unselect
1070 * The ::select-all signal is a
1071 * <link linkend="keybinding-signals">keybinding signal</link>
1072 * which gets emitted to select or unselect the complete
1073 * contents of the text view.
1075 * The default bindings for this signal are Ctrl-a and Ctrl-/
1076 * for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
1078 signals[SELECT_ALL] =
1079 g_signal_new_class_handler (I_("select-all"),
1080 G_OBJECT_CLASS_TYPE (gobject_class),
1081 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1082 G_CALLBACK (gtk_text_view_select_all),
1084 _gtk_marshal_VOID__BOOLEAN,
1085 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
1088 * GtkTextView::toggle-cursor-visible:
1089 * @text_view: the object which received the signal
1091 * The ::toggle-cursor-visible signal is a
1092 * <link linkend="keybinding-signals">keybinding signal</link>
1093 * which gets emitted to toggle the visibility of the cursor.
1095 * The default binding for this signal is F7.
1097 signals[TOGGLE_CURSOR_VISIBLE] =
1098 g_signal_new_class_handler (I_("toggle-cursor-visible"),
1099 G_OBJECT_CLASS_TYPE (gobject_class),
1100 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1101 G_CALLBACK (gtk_text_view_toggle_cursor_visible),
1103 _gtk_marshal_VOID__VOID,
1107 * GtkTextView::preedit-changed:
1108 * @text_view: the object which received the signal
1109 * @preedit: the current preedit string
1111 * If an input method is used, the typed text will not immediately
1112 * be committed to the buffer. So if you are interested in the text,
1113 * connect to this signal.
1115 * This signal is only emitted if the text at the given position
1116 * is actually editable.
1120 signals[PREEDIT_CHANGED] =
1121 g_signal_new_class_handler (I_("preedit-changed"),
1122 G_OBJECT_CLASS_TYPE (gobject_class),
1123 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1126 _gtk_marshal_VOID__STRING,
1134 binding_set = gtk_binding_set_by_class (klass);
1136 /* Moving the insertion point */
1137 add_move_binding (binding_set, GDK_KEY_Right, 0,
1138 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1140 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1141 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1143 add_move_binding (binding_set, GDK_KEY_Left, 0,
1144 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1146 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1147 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1149 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1150 GTK_MOVEMENT_WORDS, 1);
1152 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1153 GTK_MOVEMENT_WORDS, 1);
1155 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1156 GTK_MOVEMENT_WORDS, -1);
1158 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1159 GTK_MOVEMENT_WORDS, -1);
1161 add_move_binding (binding_set, GDK_KEY_Up, 0,
1162 GTK_MOVEMENT_DISPLAY_LINES, -1);
1164 add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1165 GTK_MOVEMENT_DISPLAY_LINES, -1);
1167 add_move_binding (binding_set, GDK_KEY_Down, 0,
1168 GTK_MOVEMENT_DISPLAY_LINES, 1);
1170 add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1171 GTK_MOVEMENT_DISPLAY_LINES, 1);
1173 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK,
1174 GTK_MOVEMENT_PARAGRAPHS, -1);
1176 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK,
1177 GTK_MOVEMENT_PARAGRAPHS, -1);
1179 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK,
1180 GTK_MOVEMENT_PARAGRAPHS, 1);
1182 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK,
1183 GTK_MOVEMENT_PARAGRAPHS, 1);
1185 add_move_binding (binding_set, GDK_KEY_Home, 0,
1186 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1188 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1189 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1191 add_move_binding (binding_set, GDK_KEY_End, 0,
1192 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1194 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1195 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1197 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1198 GTK_MOVEMENT_BUFFER_ENDS, -1);
1200 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1201 GTK_MOVEMENT_BUFFER_ENDS, -1);
1203 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1204 GTK_MOVEMENT_BUFFER_ENDS, 1);
1206 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1207 GTK_MOVEMENT_BUFFER_ENDS, 1);
1209 add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1210 GTK_MOVEMENT_PAGES, -1);
1212 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1213 GTK_MOVEMENT_PAGES, -1);
1215 add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1216 GTK_MOVEMENT_PAGES, 1);
1218 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1219 GTK_MOVEMENT_PAGES, 1);
1221 add_move_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
1222 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1224 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK,
1225 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1227 add_move_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK,
1228 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1230 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK,
1231 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1234 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1236 G_TYPE_BOOLEAN, TRUE);
1238 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1240 G_TYPE_BOOLEAN, TRUE);
1243 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1245 G_TYPE_BOOLEAN, FALSE);
1247 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1249 G_TYPE_BOOLEAN, FALSE);
1252 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1253 "delete-from-cursor", 2,
1254 G_TYPE_ENUM, GTK_DELETE_CHARS,
1257 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1258 "delete-from-cursor", 2,
1259 G_TYPE_ENUM, GTK_DELETE_CHARS,
1262 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1265 /* Make this do the same as Backspace, to help with mis-typing */
1266 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1269 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1270 "delete-from-cursor", 2,
1271 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1274 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1275 "delete-from-cursor", 2,
1276 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1279 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1280 "delete-from-cursor", 2,
1281 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1284 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1285 "delete-from-cursor", 2,
1286 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1289 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1290 "delete-from-cursor", 2,
1291 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1294 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1295 "delete-from-cursor", 2,
1296 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1299 /* Cut/copy/paste */
1301 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1302 "cut-clipboard", 0);
1303 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1304 "copy-clipboard", 0);
1305 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1306 "paste-clipboard", 0);
1308 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1309 "cut-clipboard", 0);
1310 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1311 "copy-clipboard", 0);
1312 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1313 "paste-clipboard", 0);
1316 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1317 "toggle-overwrite", 0);
1318 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1319 "toggle-overwrite", 0);
1322 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F7, 0,
1323 "toggle-cursor-visible", 0);
1325 /* Control-tab focus motion */
1326 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_CONTROL_MASK,
1328 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1329 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
1331 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1333 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1335 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1336 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1338 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1340 g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
1344 gtk_text_view_init (GtkTextView *text_view)
1346 GtkWidget *widget = GTK_WIDGET (text_view);
1347 GtkTargetList *target_list;
1348 GtkTextViewPrivate *priv;
1350 text_view->priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
1351 priv = text_view->priv;
1353 gtk_widget_set_can_focus (widget, TRUE);
1355 /* Set up default style */
1356 priv->wrap_mode = GTK_WRAP_NONE;
1357 priv->pixels_above_lines = 0;
1358 priv->pixels_below_lines = 0;
1359 priv->pixels_inside_wrap = 0;
1360 priv->justify = GTK_JUSTIFY_LEFT;
1361 priv->left_margin = 0;
1362 priv->right_margin = 0;
1365 priv->editable = TRUE;
1367 priv->scroll_after_paste = TRUE;
1369 gtk_drag_dest_set (widget, 0, NULL, 0,
1370 GDK_ACTION_COPY | GDK_ACTION_MOVE);
1372 target_list = gtk_target_list_new (NULL, 0);
1373 gtk_drag_dest_set_target_list (widget, target_list);
1374 gtk_target_list_unref (target_list);
1376 priv->virtual_cursor_x = -1;
1377 priv->virtual_cursor_y = -1;
1379 /* This object is completely private. No external entity can gain a reference
1380 * to it; so we create it here and destroy it in finalize ().
1382 priv->im_context = gtk_im_multicontext_new ();
1384 g_signal_connect (priv->im_context, "commit",
1385 G_CALLBACK (gtk_text_view_commit_handler), text_view);
1386 g_signal_connect (priv->im_context, "preedit-changed",
1387 G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
1388 g_signal_connect (priv->im_context, "retrieve-surrounding",
1389 G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
1390 g_signal_connect (priv->im_context, "delete-surrounding",
1391 G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
1393 priv->cursor_visible = TRUE;
1395 priv->accepts_tab = TRUE;
1397 priv->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT,
1400 priv->drag_start_x = -1;
1401 priv->drag_start_y = -1;
1403 priv->pending_place_cursor_button = 0;
1405 /* We handle all our own redrawing */
1406 gtk_widget_set_redraw_on_allocate (widget, FALSE);
1410 * gtk_text_view_new:
1412 * Creates a new #GtkTextView. If you don't call gtk_text_view_set_buffer()
1413 * before using the text view, an empty default buffer will be created
1414 * for you. Get the buffer with gtk_text_view_get_buffer(). If you want
1415 * to specify your own buffer, consider gtk_text_view_new_with_buffer().
1417 * Return value: a new #GtkTextView
1420 gtk_text_view_new (void)
1422 return g_object_new (GTK_TYPE_TEXT_VIEW, NULL);
1426 * gtk_text_view_new_with_buffer:
1427 * @buffer: a #GtkTextBuffer
1429 * Creates a new #GtkTextView widget displaying the buffer
1430 * @buffer. One buffer can be shared among many widgets.
1431 * @buffer may be %NULL to create a default buffer, in which case
1432 * this function is equivalent to gtk_text_view_new(). The
1433 * text view adds its own reference count to the buffer; it does not
1434 * take over an existing reference.
1436 * Return value: a new #GtkTextView.
1439 gtk_text_view_new_with_buffer (GtkTextBuffer *buffer)
1441 GtkTextView *text_view;
1443 text_view = (GtkTextView*)gtk_text_view_new ();
1445 gtk_text_view_set_buffer (text_view, buffer);
1447 return GTK_WIDGET (text_view);
1451 * gtk_text_view_set_buffer:
1452 * @text_view: a #GtkTextView
1453 * @buffer: (allow-none): a #GtkTextBuffer
1455 * Sets @buffer as the buffer being displayed by @text_view. The previous
1456 * buffer displayed by the text view is unreferenced, and a reference is
1457 * added to @buffer. If you owned a reference to @buffer before passing it
1458 * to this function, you must remove that reference yourself; #GtkTextView
1459 * will not "adopt" it.
1462 gtk_text_view_set_buffer (GtkTextView *text_view,
1463 GtkTextBuffer *buffer)
1465 GtkTextViewPrivate *priv;
1467 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1468 g_return_if_fail (buffer == NULL || GTK_IS_TEXT_BUFFER (buffer));
1470 priv = text_view->priv;
1472 if (priv->buffer == buffer)
1475 if (priv->buffer != NULL)
1477 /* Destroy all anchored children */
1481 copy = g_slist_copy (priv->children);
1483 while (tmp_list != NULL)
1485 GtkTextViewChild *vc = tmp_list->data;
1489 gtk_widget_destroy (vc->widget);
1490 /* vc may now be invalid! */
1493 tmp_list = g_slist_next (tmp_list);
1496 g_slist_free (copy);
1498 g_signal_handlers_disconnect_by_func (priv->buffer,
1499 gtk_text_view_mark_set_handler,
1501 g_signal_handlers_disconnect_by_func (priv->buffer,
1502 gtk_text_view_target_list_notify,
1504 g_signal_handlers_disconnect_by_func (priv->buffer,
1505 gtk_text_view_paste_done_handler,
1508 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1510 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1511 GDK_SELECTION_PRIMARY);
1512 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
1516 gtk_text_layout_set_buffer (priv->layout, NULL);
1518 g_object_unref (priv->buffer);
1519 priv->dnd_mark = NULL;
1520 priv->first_para_mark = NULL;
1521 cancel_pending_scroll (text_view);
1524 priv->buffer = buffer;
1527 gtk_text_layout_set_buffer (priv->layout, buffer);
1533 g_object_ref (buffer);
1535 gtk_text_buffer_get_iter_at_offset (priv->buffer, &start, 0);
1537 priv->dnd_mark = gtk_text_buffer_create_mark (priv->buffer,
1541 priv->first_para_mark = gtk_text_buffer_create_mark (priv->buffer,
1545 priv->first_para_pixels = 0;
1548 g_signal_connect (priv->buffer, "mark-set",
1549 G_CALLBACK (gtk_text_view_mark_set_handler),
1551 g_signal_connect (priv->buffer, "notify::paste-target-list",
1552 G_CALLBACK (gtk_text_view_target_list_notify),
1554 g_signal_connect (priv->buffer, "paste-done",
1555 G_CALLBACK (gtk_text_view_paste_done_handler),
1558 gtk_text_view_target_list_notify (priv->buffer, NULL, text_view);
1560 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1562 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1563 GDK_SELECTION_PRIMARY);
1564 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
1568 g_object_notify (G_OBJECT (text_view), "buffer");
1570 if (gtk_widget_get_visible (GTK_WIDGET (text_view)))
1571 gtk_widget_queue_draw (GTK_WIDGET (text_view));
1573 DV(g_print ("Invalidating due to set_buffer\n"));
1574 gtk_text_view_invalidate (text_view);
1577 static GtkTextBuffer*
1578 get_buffer (GtkTextView *text_view)
1580 if (text_view->priv->buffer == NULL)
1583 b = gtk_text_buffer_new (NULL);
1584 gtk_text_view_set_buffer (text_view, b);
1588 return text_view->priv->buffer;
1592 * gtk_text_view_get_buffer:
1593 * @text_view: a #GtkTextView
1595 * Returns the #GtkTextBuffer being displayed by this text view.
1596 * The reference count on the buffer is not incremented; the caller
1597 * of this function won't own a new reference.
1599 * Return value: (transfer none): a #GtkTextBuffer
1602 gtk_text_view_get_buffer (GtkTextView *text_view)
1604 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
1606 return get_buffer (text_view);
1610 * gtk_text_view_get_iter_at_location:
1611 * @text_view: a #GtkTextView
1612 * @iter: (out): a #GtkTextIter
1613 * @x: x position, in buffer coordinates
1614 * @y: y position, in buffer coordinates
1616 * Retrieves the iterator at buffer coordinates @x and @y. Buffer
1617 * coordinates are coordinates for the entire buffer, not just the
1618 * currently-displayed portion. If you have coordinates from an
1619 * event, you have to convert those to buffer coordinates with
1620 * gtk_text_view_window_to_buffer_coords().
1623 gtk_text_view_get_iter_at_location (GtkTextView *text_view,
1628 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1629 g_return_if_fail (iter != NULL);
1631 gtk_text_view_ensure_layout (text_view);
1633 gtk_text_layout_get_iter_at_pixel (text_view->priv->layout,
1638 * gtk_text_view_get_iter_at_position:
1639 * @text_view: a #GtkTextView
1640 * @iter: (out): a #GtkTextIter
1641 * @trailing: (out) (allow-none): if non-%NULL, location to store an integer indicating where
1642 * in the grapheme the user clicked. It will either be
1643 * zero, or the number of characters in the grapheme.
1644 * 0 represents the trailing edge of the grapheme.
1645 * @x: x position, in buffer coordinates
1646 * @y: y position, in buffer coordinates
1648 * Retrieves the iterator pointing to the character at buffer
1649 * coordinates @x and @y. Buffer coordinates are coordinates for
1650 * the entire buffer, not just the currently-displayed portion.
1651 * If you have coordinates from an event, you have to convert
1652 * those to buffer coordinates with
1653 * gtk_text_view_window_to_buffer_coords().
1655 * Note that this is different from gtk_text_view_get_iter_at_location(),
1656 * which returns cursor locations, i.e. positions <emphasis>between</emphasis>
1662 gtk_text_view_get_iter_at_position (GtkTextView *text_view,
1668 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1669 g_return_if_fail (iter != NULL);
1671 gtk_text_view_ensure_layout (text_view);
1673 gtk_text_layout_get_iter_at_position (text_view->priv->layout,
1674 iter, trailing, x, y);
1678 * gtk_text_view_get_iter_location:
1679 * @text_view: a #GtkTextView
1680 * @iter: a #GtkTextIter
1681 * @location: (out): bounds of the character at @iter
1683 * Gets a rectangle which roughly contains the character at @iter.
1684 * The rectangle position is in buffer coordinates; use
1685 * gtk_text_view_buffer_to_window_coords() to convert these
1686 * coordinates to coordinates for one of the windows in the text view.
1689 gtk_text_view_get_iter_location (GtkTextView *text_view,
1690 const GtkTextIter *iter,
1691 GdkRectangle *location)
1693 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1694 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1696 gtk_text_view_ensure_layout (text_view);
1698 gtk_text_layout_get_iter_location (text_view->priv->layout, iter, location);
1702 * gtk_text_view_get_line_yrange:
1703 * @text_view: a #GtkTextView
1704 * @iter: a #GtkTextIter
1705 * @y: (out): return location for a y coordinate
1706 * @height: (out): return location for a height
1708 * Gets the y coordinate of the top of the line containing @iter,
1709 * and the height of the line. The coordinate is a buffer coordinate;
1710 * convert to window coordinates with gtk_text_view_buffer_to_window_coords().
1713 gtk_text_view_get_line_yrange (GtkTextView *text_view,
1714 const GtkTextIter *iter,
1718 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1719 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1721 gtk_text_view_ensure_layout (text_view);
1723 gtk_text_layout_get_line_yrange (text_view->priv->layout,
1730 * gtk_text_view_get_line_at_y:
1731 * @text_view: a #GtkTextView
1732 * @target_iter: (out): a #GtkTextIter
1733 * @y: a y coordinate
1734 * @line_top: (out): return location for top coordinate of the line
1736 * Gets the #GtkTextIter at the start of the line containing
1737 * the coordinate @y. @y is in buffer coordinates, convert from
1738 * window coordinates with gtk_text_view_window_to_buffer_coords().
1739 * If non-%NULL, @line_top will be filled with the coordinate of the top
1743 gtk_text_view_get_line_at_y (GtkTextView *text_view,
1744 GtkTextIter *target_iter,
1748 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1750 gtk_text_view_ensure_layout (text_view);
1752 gtk_text_layout_get_line_at_y (text_view->priv->layout,
1759 set_adjustment_clamped (GtkAdjustment *adj, gdouble val)
1761 DV (g_print (" Setting adj to raw value %g\n", val));
1763 /* We don't really want to clamp to upper; we want to clamp to
1764 upper - page_size which is the highest value the scrollbar
1765 will let us reach. */
1766 if (val > (adj->upper - adj->page_size))
1767 val = adj->upper - adj->page_size;
1769 if (val < adj->lower)
1772 if (val != adj->value)
1774 DV (g_print (" Setting adj to clamped value %g\n", val));
1775 gtk_adjustment_set_value (adj, val);
1783 * gtk_text_view_scroll_to_iter:
1784 * @text_view: a #GtkTextView
1785 * @iter: a #GtkTextIter
1786 * @within_margin: margin as a [0.0,0.5) fraction of screen size
1787 * @use_align: whether to use alignment arguments (if %FALSE,
1788 * just get the mark onscreen)
1789 * @xalign: horizontal alignment of mark within visible area
1790 * @yalign: vertical alignment of mark within visible area
1792 * Scrolls @text_view so that @iter is on the screen in the position
1793 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
1794 * left or top, 1.0 indicates right or bottom, 0.5 means center.
1795 * If @use_align is %FALSE, the text scrolls the minimal distance to
1796 * get the mark onscreen, possibly not scrolling at all. The effective
1797 * screen for purposes of this function is reduced by a margin of size
1800 * Note that this function uses the currently-computed height of the
1801 * lines in the text buffer. Line heights are computed in an idle
1802 * handler; so this function may not have the desired effect if it's
1803 * called before the height computations. To avoid oddness, consider
1804 * using gtk_text_view_scroll_to_mark() which saves a point to be
1805 * scrolled to after line validation.
1807 * Return value: %TRUE if scrolling occurred
1810 gtk_text_view_scroll_to_iter (GtkTextView *text_view,
1812 gdouble within_margin,
1818 GdkRectangle screen;
1823 gboolean retval = FALSE;
1825 gint screen_xoffset, screen_yoffset;
1826 gint current_x_scroll, current_y_scroll;
1828 /* FIXME why don't we do the validate-at-scroll-destination thing
1829 * from flush_scroll in this function? I think it wasn't done before
1830 * because changed_handler was screwed up, but I could be wrong.
1833 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
1834 g_return_val_if_fail (iter != NULL, FALSE);
1835 g_return_val_if_fail (within_margin >= 0.0 && within_margin < 0.5, FALSE);
1836 g_return_val_if_fail (xalign >= 0.0 && xalign <= 1.0, FALSE);
1837 g_return_val_if_fail (yalign >= 0.0 && yalign <= 1.0, FALSE);
1839 widget = GTK_WIDGET (text_view);
1841 DV(g_print(G_STRLOC"\n"));
1843 gtk_text_layout_get_iter_location (text_view->priv->layout,
1847 DV (g_print (" target rect %d,%d %d x %d\n", rect.x, rect.y, rect.width, rect.height));
1849 current_x_scroll = text_view->priv->xoffset;
1850 current_y_scroll = text_view->priv->yoffset;
1852 screen.x = current_x_scroll;
1853 screen.y = current_y_scroll;
1854 screen.width = SCREEN_WIDTH (widget);
1855 screen.height = SCREEN_HEIGHT (widget);
1857 screen_xoffset = screen.width * within_margin;
1858 screen_yoffset = screen.height * within_margin;
1860 screen.x += screen_xoffset;
1861 screen.y += screen_yoffset;
1862 screen.width -= screen_xoffset * 2;
1863 screen.height -= screen_yoffset * 2;
1865 /* paranoia check */
1866 if (screen.width < 1)
1868 if (screen.height < 1)
1871 /* The -1 here ensures that we leave enough space to draw the cursor
1872 * when this function is used for horizontal scrolling.
1874 screen_right = screen.x + screen.width - 1;
1875 screen_bottom = screen.y + screen.height;
1877 /* The alignment affects the point in the target character that we
1878 * choose to align. If we're doing right/bottom alignment, we align
1879 * the right/bottom edge of the character the mark is at; if we're
1880 * doing left/top we align the left/top edge of the character; if
1881 * we're doing center alignment we align the center of the
1885 /* Vertical scroll */
1888 scroll_dest = current_y_scroll;
1892 scroll_dest = rect.y + (rect.height * yalign) - (screen.height * yalign);
1894 /* if scroll_dest < screen.y, we move a negative increment (up),
1895 * else a positive increment (down)
1897 scroll_inc = scroll_dest - screen.y + screen_yoffset;
1901 /* move minimum to get onscreen */
1902 if (rect.y < screen.y)
1904 scroll_dest = rect.y;
1905 scroll_inc = scroll_dest - screen.y - screen_yoffset;
1907 else if ((rect.y + rect.height) > screen_bottom)
1909 scroll_dest = rect.y + rect.height;
1910 scroll_inc = scroll_dest - screen_bottom + screen_yoffset;
1914 if (scroll_inc != 0)
1916 retval = set_adjustment_clamped (get_vadjustment (text_view),
1917 current_y_scroll + scroll_inc);
1919 DV (g_print (" vert increment %d\n", scroll_inc));
1922 /* Horizontal scroll */
1925 scroll_dest = current_x_scroll;
1929 scroll_dest = rect.x + (rect.width * xalign) - (screen.width * xalign);
1931 /* if scroll_dest < screen.y, we move a negative increment (left),
1932 * else a positive increment (right)
1934 scroll_inc = scroll_dest - screen.x + screen_xoffset;
1938 /* move minimum to get onscreen */
1939 if (rect.x < screen.x)
1941 scroll_dest = rect.x;
1942 scroll_inc = scroll_dest - screen.x - screen_xoffset;
1944 else if ((rect.x + rect.width) > screen_right)
1946 scroll_dest = rect.x + rect.width;
1947 scroll_inc = scroll_dest - screen_right + screen_xoffset;
1951 if (scroll_inc != 0)
1953 retval = set_adjustment_clamped (get_hadjustment (text_view),
1954 current_x_scroll + scroll_inc);
1956 DV (g_print (" horiz increment %d\n", scroll_inc));
1961 DV(g_print (">Actually scrolled ("G_STRLOC")\n"));
1965 DV(g_print (">Didn't end up scrolling ("G_STRLOC")\n"));
1972 free_pending_scroll (GtkTextPendingScroll *scroll)
1974 if (!gtk_text_mark_get_deleted (scroll->mark))
1975 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (scroll->mark),
1977 g_object_unref (scroll->mark);
1982 cancel_pending_scroll (GtkTextView *text_view)
1984 if (text_view->priv->pending_scroll)
1986 free_pending_scroll (text_view->priv->pending_scroll);
1987 text_view->priv->pending_scroll = NULL;
1992 gtk_text_view_queue_scroll (GtkTextView *text_view,
1994 gdouble within_margin,
2000 GtkTextPendingScroll *scroll;
2002 DV(g_print(G_STRLOC"\n"));
2004 scroll = g_new (GtkTextPendingScroll, 1);
2006 scroll->within_margin = within_margin;
2007 scroll->use_align = use_align;
2008 scroll->xalign = xalign;
2009 scroll->yalign = yalign;
2011 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2013 scroll->mark = gtk_text_buffer_create_mark (get_buffer (text_view),
2016 gtk_text_mark_get_left_gravity (mark));
2018 g_object_ref (scroll->mark);
2020 cancel_pending_scroll (text_view);
2022 text_view->priv->pending_scroll = scroll;
2026 gtk_text_view_flush_scroll (GtkTextView *text_view)
2028 GtkAllocation allocation;
2030 GtkTextPendingScroll *scroll;
2034 widget = GTK_WIDGET (text_view);
2036 DV(g_print(G_STRLOC"\n"));
2038 if (text_view->priv->pending_scroll == NULL)
2040 DV (g_print ("in flush scroll, no pending scroll\n"));
2044 scroll = text_view->priv->pending_scroll;
2046 /* avoid recursion */
2047 text_view->priv->pending_scroll = NULL;
2049 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, scroll->mark);
2051 /* Validate area around the scroll destination, so the adjustment
2052 * can meaningfully point into that area. We must validate
2053 * enough area to be sure that after we scroll, everything onscreen
2054 * is valid; otherwise, validation will maintain the first para
2055 * in one place, but may push the target iter off the bottom of
2058 DV(g_print (">Validating scroll destination ("G_STRLOC")\n"));
2059 gtk_widget_get_allocation (widget, &allocation);
2060 gtk_text_layout_validate_yrange (text_view->priv->layout, &iter,
2061 -(allocation.height * 2),
2062 allocation.height * 2);
2064 DV(g_print (">Done validating scroll destination ("G_STRLOC")\n"));
2066 /* Ensure we have updated width/height */
2067 gtk_text_view_update_adjustments (text_view);
2069 retval = gtk_text_view_scroll_to_iter (text_view,
2071 scroll->within_margin,
2076 free_pending_scroll (scroll);
2082 gtk_text_view_set_adjustment_upper (GtkAdjustment *adj, gdouble upper)
2084 if (upper != adj->upper)
2086 gdouble min = MAX (0.0, upper - adj->page_size);
2087 gboolean value_changed = FALSE;
2091 if (adj->value > min)
2094 value_changed = TRUE;
2097 gtk_adjustment_changed (adj);
2098 DV(g_print(">Changed adj upper to %g ("G_STRLOC")\n", upper));
2102 DV(g_print(">Changed adj value because upper decreased ("G_STRLOC")\n"));
2103 gtk_adjustment_value_changed (adj);
2109 gtk_text_view_update_adjustments (GtkTextView *text_view)
2111 GtkTextViewPrivate *priv;
2112 gint width = 0, height = 0;
2114 DV(g_print(">Updating adjustments ("G_STRLOC")\n"));
2116 priv = text_view->priv;
2119 gtk_text_layout_get_size (priv->layout, &width, &height);
2121 /* Make room for the cursor after the last character in the widest line */
2122 width += SPACE_FOR_CURSOR;
2124 if (priv->width != width || priv->height != height)
2126 if (priv->width != width)
2127 priv->width_changed = TRUE;
2129 priv->width = width;
2130 priv->height = height;
2132 gtk_text_view_set_adjustment_upper (get_hadjustment (text_view),
2133 MAX (SCREEN_WIDTH (text_view), width));
2134 gtk_text_view_set_adjustment_upper (get_vadjustment (text_view),
2135 MAX (SCREEN_HEIGHT (text_view), height));
2137 /* hadj/vadj exist since we called get_hadjustment/get_vadjustment above */
2139 /* Set up the step sizes; we'll say that a page is
2140 our allocation minus one step, and a step is
2141 1/10 of our allocation. */
2142 priv->hadjustment->step_increment =
2143 SCREEN_WIDTH (text_view) / 10.0;
2144 priv->hadjustment->page_increment =
2145 SCREEN_WIDTH (text_view) * 0.9;
2147 priv->vadjustment->step_increment =
2148 SCREEN_HEIGHT (text_view) / 10.0;
2149 priv->vadjustment->page_increment =
2150 SCREEN_HEIGHT (text_view) * 0.9;
2152 gtk_adjustment_changed (get_hadjustment (text_view));
2153 gtk_adjustment_changed (get_vadjustment (text_view));
2158 gtk_text_view_update_layout_width (GtkTextView *text_view)
2160 DV(g_print(">Updating layout width ("G_STRLOC")\n"));
2162 gtk_text_view_ensure_layout (text_view);
2164 gtk_text_layout_set_screen_width (text_view->priv->layout,
2165 MAX (1, SCREEN_WIDTH (text_view) - SPACE_FOR_CURSOR));
2169 gtk_text_view_update_im_spot_location (GtkTextView *text_view)
2173 if (text_view->priv->layout == NULL)
2176 gtk_text_view_get_cursor_location (text_view, &area);
2178 area.x -= text_view->priv->xoffset;
2179 area.y -= text_view->priv->yoffset;
2181 /* Width returned by Pango indicates direction of cursor,
2182 * by it's sign more than the size of cursor.
2186 gtk_im_context_set_cursor_location (text_view->priv->im_context, &area);
2190 do_update_im_spot_location (gpointer text_view)
2192 GtkTextViewPrivate *priv;
2194 priv = GTK_TEXT_VIEW (text_view)->priv;
2195 priv->im_spot_idle = 0;
2197 gtk_text_view_update_im_spot_location (text_view);
2202 queue_update_im_spot_location (GtkTextView *text_view)
2204 GtkTextViewPrivate *priv;
2206 priv = text_view->priv;
2208 /* Use priority a little higher than GTK_TEXT_VIEW_PRIORITY_VALIDATE,
2209 * so we don't wait until the entire buffer has been validated. */
2210 if (!priv->im_spot_idle)
2211 priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
2212 do_update_im_spot_location,
2218 flush_update_im_spot_location (GtkTextView *text_view)
2220 GtkTextViewPrivate *priv;
2222 priv = text_view->priv;
2224 if (priv->im_spot_idle)
2226 g_source_remove (priv->im_spot_idle);
2227 priv->im_spot_idle = 0;
2228 gtk_text_view_update_im_spot_location (text_view);
2233 * gtk_text_view_scroll_to_mark:
2234 * @text_view: a #GtkTextView
2235 * @mark: a #GtkTextMark
2236 * @within_margin: margin as a [0.0,0.5) fraction of screen size
2237 * @use_align: whether to use alignment arguments (if %FALSE, just
2238 * get the mark onscreen)
2239 * @xalign: horizontal alignment of mark within visible area
2240 * @yalign: vertical alignment of mark within visible area
2242 * Scrolls @text_view so that @mark is on the screen in the position
2243 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
2244 * left or top, 1.0 indicates right or bottom, 0.5 means center.
2245 * If @use_align is %FALSE, the text scrolls the minimal distance to
2246 * get the mark onscreen, possibly not scrolling at all. The effective
2247 * screen for purposes of this function is reduced by a margin of size
2251 gtk_text_view_scroll_to_mark (GtkTextView *text_view,
2253 gdouble within_margin,
2258 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2259 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2260 g_return_if_fail (within_margin >= 0.0 && within_margin < 0.5);
2261 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
2262 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
2264 /* We need to verify that the buffer contains the mark, otherwise this
2265 * can lead to data structure corruption later on.
2267 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2269 gtk_text_view_queue_scroll (text_view, mark,
2275 /* If no validation is pending, we need to go ahead and force an
2278 if (text_view->priv->layout &&
2279 gtk_text_layout_is_valid (text_view->priv->layout))
2280 gtk_text_view_flush_scroll (text_view);
2284 * gtk_text_view_scroll_mark_onscreen:
2285 * @text_view: a #GtkTextView
2286 * @mark: a mark in the buffer for @text_view
2288 * Scrolls @text_view the minimum distance such that @mark is contained
2289 * within the visible area of the widget.
2292 gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
2295 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2296 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2298 /* We need to verify that the buffer contains the mark, otherwise this
2299 * can lead to data structure corruption later on.
2301 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2303 gtk_text_view_scroll_to_mark (text_view, mark, 0.0, FALSE, 0.0, 0.0);
2307 clamp_iter_onscreen (GtkTextView *text_view, GtkTextIter *iter)
2309 GdkRectangle visible_rect;
2310 gtk_text_view_get_visible_rect (text_view, &visible_rect);
2312 return gtk_text_layout_clamp_iter_to_vrange (text_view->priv->layout, iter,
2314 visible_rect.y + visible_rect.height);
2318 * gtk_text_view_move_mark_onscreen:
2319 * @text_view: a #GtkTextView
2320 * @mark: a #GtkTextMark
2322 * Moves a mark within the buffer so that it's
2323 * located within the currently-visible text area.
2325 * Return value: %TRUE if the mark moved (wasn't already onscreen)
2328 gtk_text_view_move_mark_onscreen (GtkTextView *text_view,
2333 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2334 g_return_val_if_fail (mark != NULL, FALSE);
2336 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2338 if (clamp_iter_onscreen (text_view, &iter))
2340 gtk_text_buffer_move_mark (get_buffer (text_view), mark, &iter);
2348 * gtk_text_view_get_visible_rect:
2349 * @text_view: a #GtkTextView
2350 * @visible_rect: rectangle to fill
2352 * Fills @visible_rect with the currently-visible
2353 * region of the buffer, in buffer coordinates. Convert to window coordinates
2354 * with gtk_text_view_buffer_to_window_coords().
2357 gtk_text_view_get_visible_rect (GtkTextView *text_view,
2358 GdkRectangle *visible_rect)
2362 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2364 widget = GTK_WIDGET (text_view);
2368 visible_rect->x = text_view->priv->xoffset;
2369 visible_rect->y = text_view->priv->yoffset;
2370 visible_rect->width = SCREEN_WIDTH (widget);
2371 visible_rect->height = SCREEN_HEIGHT (widget);
2373 DV(g_print(" visible rect: %d,%d %d x %d\n",
2376 visible_rect->width,
2377 visible_rect->height));
2382 * gtk_text_view_set_wrap_mode:
2383 * @text_view: a #GtkTextView
2384 * @wrap_mode: a #GtkWrapMode
2386 * Sets the line wrapping for the view.
2389 gtk_text_view_set_wrap_mode (GtkTextView *text_view,
2390 GtkWrapMode wrap_mode)
2392 GtkTextViewPrivate *priv;
2394 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2396 priv = text_view->priv;
2398 if (priv->wrap_mode != wrap_mode)
2400 priv->wrap_mode = wrap_mode;
2404 priv->layout->default_style->wrap_mode = wrap_mode;
2405 gtk_text_layout_default_style_changed (priv->layout);
2409 g_object_notify (G_OBJECT (text_view), "wrap-mode");
2413 * gtk_text_view_get_wrap_mode:
2414 * @text_view: a #GtkTextView
2416 * Gets the line wrapping for the view.
2418 * Return value: the line wrap setting
2421 gtk_text_view_get_wrap_mode (GtkTextView *text_view)
2423 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_WRAP_NONE);
2425 return text_view->priv->wrap_mode;
2429 * gtk_text_view_set_editable:
2430 * @text_view: a #GtkTextView
2431 * @setting: whether it's editable
2433 * Sets the default editability of the #GtkTextView. You can override
2434 * this default setting with tags in the buffer, using the "editable"
2435 * attribute of tags.
2438 gtk_text_view_set_editable (GtkTextView *text_view,
2441 GtkTextViewPrivate *priv;
2443 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2445 priv = text_view->priv;
2446 setting = setting != FALSE;
2448 if (priv->editable != setting)
2452 gtk_text_view_reset_im_context(text_view);
2453 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2454 gtk_im_context_focus_out (priv->im_context);
2457 priv->editable = setting;
2459 if (setting && gtk_widget_has_focus (GTK_WIDGET (text_view)))
2460 gtk_im_context_focus_in (priv->im_context);
2464 gtk_text_layout_set_overwrite_mode (priv->layout,
2465 priv->overwrite_mode && priv->editable);
2466 priv->layout->default_style->editable = priv->editable;
2467 gtk_text_layout_default_style_changed (priv->layout);
2470 g_object_notify (G_OBJECT (text_view), "editable");
2475 * gtk_text_view_get_editable:
2476 * @text_view: a #GtkTextView
2478 * Returns the default editability of the #GtkTextView. Tags in the
2479 * buffer may override this setting for some ranges of text.
2481 * Return value: whether text is editable by default
2484 gtk_text_view_get_editable (GtkTextView *text_view)
2486 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2488 return text_view->priv->editable;
2492 * gtk_text_view_set_pixels_above_lines:
2493 * @text_view: a #GtkTextView
2494 * @pixels_above_lines: pixels above paragraphs
2496 * Sets the default number of blank pixels above paragraphs in @text_view.
2497 * Tags in the buffer for @text_view may override the defaults.
2500 gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
2501 gint pixels_above_lines)
2503 GtkTextViewPrivate *priv;
2505 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2507 priv = text_view->priv;
2509 if (priv->pixels_above_lines != pixels_above_lines)
2511 priv->pixels_above_lines = pixels_above_lines;
2515 priv->layout->default_style->pixels_above_lines = pixels_above_lines;
2516 gtk_text_layout_default_style_changed (priv->layout);
2519 g_object_notify (G_OBJECT (text_view), "pixels-above-lines");
2524 * gtk_text_view_get_pixels_above_lines:
2525 * @text_view: a #GtkTextView
2527 * Gets the default number of pixels to put above paragraphs.
2529 * Return value: default number of pixels above paragraphs
2532 gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
2534 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2536 return text_view->priv->pixels_above_lines;
2540 * gtk_text_view_set_pixels_below_lines:
2541 * @text_view: a #GtkTextView
2542 * @pixels_below_lines: pixels below paragraphs
2544 * Sets the default number of pixels of blank space
2545 * to put below paragraphs in @text_view. May be overridden
2546 * by tags applied to @text_view's buffer.
2549 gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
2550 gint pixels_below_lines)
2552 GtkTextViewPrivate *priv;
2554 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2556 priv = text_view->priv;
2558 if (priv->pixels_below_lines != pixels_below_lines)
2560 priv->pixels_below_lines = pixels_below_lines;
2564 priv->layout->default_style->pixels_below_lines = pixels_below_lines;
2565 gtk_text_layout_default_style_changed (priv->layout);
2568 g_object_notify (G_OBJECT (text_view), "pixels-below-lines");
2573 * gtk_text_view_get_pixels_below_lines:
2574 * @text_view: a #GtkTextView
2576 * Gets the value set by gtk_text_view_set_pixels_below_lines().
2578 * Return value: default number of blank pixels below paragraphs
2581 gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
2583 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2585 return text_view->priv->pixels_below_lines;
2589 * gtk_text_view_set_pixels_inside_wrap:
2590 * @text_view: a #GtkTextView
2591 * @pixels_inside_wrap: default number of pixels between wrapped lines
2593 * Sets the default number of pixels of blank space to leave between
2594 * display/wrapped lines within a paragraph. May be overridden by
2595 * tags in @text_view's buffer.
2598 gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
2599 gint pixels_inside_wrap)
2601 GtkTextViewPrivate *priv;
2603 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2605 priv = text_view->priv;
2607 if (priv->pixels_inside_wrap != pixels_inside_wrap)
2609 priv->pixels_inside_wrap = pixels_inside_wrap;
2613 priv->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
2614 gtk_text_layout_default_style_changed (priv->layout);
2617 g_object_notify (G_OBJECT (text_view), "pixels-inside-wrap");
2622 * gtk_text_view_get_pixels_inside_wrap:
2623 * @text_view: a #GtkTextView
2625 * Gets the value set by gtk_text_view_set_pixels_inside_wrap().
2627 * Return value: default number of pixels of blank space between wrapped lines
2630 gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
2632 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2634 return text_view->priv->pixels_inside_wrap;
2638 * gtk_text_view_set_justification:
2639 * @text_view: a #GtkTextView
2640 * @justification: justification
2642 * Sets the default justification of text in @text_view.
2643 * Tags in the view's buffer may override the default.
2647 gtk_text_view_set_justification (GtkTextView *text_view,
2648 GtkJustification justification)
2650 GtkTextViewPrivate *priv;
2652 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2654 priv = text_view->priv;
2656 if (priv->justify != justification)
2658 priv->justify = justification;
2662 priv->layout->default_style->justification = justification;
2663 gtk_text_layout_default_style_changed (priv->layout);
2666 g_object_notify (G_OBJECT (text_view), "justification");
2671 * gtk_text_view_get_justification:
2672 * @text_view: a #GtkTextView
2674 * Gets the default justification of paragraphs in @text_view.
2675 * Tags in the buffer may override the default.
2677 * Return value: default justification
2680 gtk_text_view_get_justification (GtkTextView *text_view)
2682 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_JUSTIFY_LEFT);
2684 return text_view->priv->justify;
2688 * gtk_text_view_set_left_margin:
2689 * @text_view: a #GtkTextView
2690 * @left_margin: left margin in pixels
2692 * Sets the default left margin for text in @text_view.
2693 * Tags in the buffer may override the default.
2696 gtk_text_view_set_left_margin (GtkTextView *text_view,
2699 GtkTextViewPrivate *priv;
2701 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2703 priv = text_view->priv;
2705 if (priv->left_margin != left_margin)
2707 priv->left_margin = left_margin;
2711 priv->layout->default_style->left_margin = left_margin;
2712 gtk_text_layout_default_style_changed (priv->layout);
2715 g_object_notify (G_OBJECT (text_view), "left-margin");
2720 * gtk_text_view_get_left_margin:
2721 * @text_view: a #GtkTextView
2723 * Gets the default left margin size of paragraphs in the @text_view.
2724 * Tags in the buffer may override the default.
2726 * Return value: left margin in pixels
2729 gtk_text_view_get_left_margin (GtkTextView *text_view)
2731 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2733 return text_view->priv->left_margin;
2737 * gtk_text_view_set_right_margin:
2738 * @text_view: a #GtkTextView
2739 * @right_margin: right margin in pixels
2741 * Sets the default right margin for text in the text view.
2742 * Tags in the buffer may override the default.
2745 gtk_text_view_set_right_margin (GtkTextView *text_view,
2748 GtkTextViewPrivate *priv = text_view->priv;
2750 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2752 if (priv->right_margin != right_margin)
2754 priv->right_margin = right_margin;
2758 priv->layout->default_style->right_margin = right_margin;
2759 gtk_text_layout_default_style_changed (priv->layout);
2762 g_object_notify (G_OBJECT (text_view), "right-margin");
2767 * gtk_text_view_get_right_margin:
2768 * @text_view: a #GtkTextView
2770 * Gets the default right margin for text in @text_view. Tags
2771 * in the buffer may override the default.
2773 * Return value: right margin in pixels
2776 gtk_text_view_get_right_margin (GtkTextView *text_view)
2778 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2780 return text_view->priv->right_margin;
2784 * gtk_text_view_set_indent:
2785 * @text_view: a #GtkTextView
2786 * @indent: indentation in pixels
2788 * Sets the default indentation for paragraphs in @text_view.
2789 * Tags in the buffer may override the default.
2792 gtk_text_view_set_indent (GtkTextView *text_view,
2795 GtkTextViewPrivate *priv;
2797 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2799 priv = text_view->priv;
2801 if (priv->indent != indent)
2803 priv->indent = indent;
2807 priv->layout->default_style->indent = indent;
2808 gtk_text_layout_default_style_changed (priv->layout);
2811 g_object_notify (G_OBJECT (text_view), "indent");
2816 * gtk_text_view_get_indent:
2817 * @text_view: a #GtkTextView
2819 * Gets the default indentation of paragraphs in @text_view.
2820 * Tags in the view's buffer may override the default.
2821 * The indentation may be negative.
2823 * Return value: number of pixels of indentation
2826 gtk_text_view_get_indent (GtkTextView *text_view)
2828 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2830 return text_view->priv->indent;
2834 * gtk_text_view_set_tabs:
2835 * @text_view: a #GtkTextView
2836 * @tabs: tabs as a #PangoTabArray
2838 * Sets the default tab stops for paragraphs in @text_view.
2839 * Tags in the buffer may override the default.
2842 gtk_text_view_set_tabs (GtkTextView *text_view,
2843 PangoTabArray *tabs)
2845 GtkTextViewPrivate *priv;
2847 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2849 priv = text_view->priv;
2852 pango_tab_array_free (priv->tabs);
2854 priv->tabs = tabs ? pango_tab_array_copy (tabs) : NULL;
2858 /* some unkosher futzing in internal struct details... */
2859 if (priv->layout->default_style->tabs)
2860 pango_tab_array_free (priv->layout->default_style->tabs);
2862 priv->layout->default_style->tabs =
2863 priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
2865 gtk_text_layout_default_style_changed (priv->layout);
2868 g_object_notify (G_OBJECT (text_view), "tabs");
2872 * gtk_text_view_get_tabs:
2873 * @text_view: a #GtkTextView
2875 * Gets the default tabs for @text_view. Tags in the buffer may
2876 * override the defaults. The returned array will be %NULL if
2877 * "standard" (8-space) tabs are used. Free the return value
2878 * with pango_tab_array_free().
2880 * Return value: copy of default tab array, or %NULL if "standard"
2881 * tabs are used; must be freed with pango_tab_array_free().
2884 gtk_text_view_get_tabs (GtkTextView *text_view)
2886 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
2888 return text_view->priv->tabs ? pango_tab_array_copy (text_view->priv->tabs) : NULL;
2892 gtk_text_view_toggle_cursor_visible (GtkTextView *text_view)
2894 gtk_text_view_set_cursor_visible (text_view, !text_view->priv->cursor_visible);
2898 * gtk_text_view_set_cursor_visible:
2899 * @text_view: a #GtkTextView
2900 * @setting: whether to show the insertion cursor
2902 * Toggles whether the insertion point is displayed. A buffer with no editable
2903 * text probably shouldn't have a visible cursor, so you may want to turn
2907 gtk_text_view_set_cursor_visible (GtkTextView *text_view,
2910 GtkTextViewPrivate *priv;
2912 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2914 priv = text_view->priv;
2915 setting = (setting != FALSE);
2917 if (priv->cursor_visible != setting)
2919 priv->cursor_visible = setting;
2921 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2925 gtk_text_layout_set_cursor_visible (priv->layout, setting);
2926 gtk_text_view_check_cursor_blink (text_view);
2930 g_object_notify (G_OBJECT (text_view), "cursor-visible");
2935 * gtk_text_view_get_cursor_visible:
2936 * @text_view: a #GtkTextView
2938 * Find out whether the cursor is being displayed.
2940 * Return value: whether the insertion mark is visible
2943 gtk_text_view_get_cursor_visible (GtkTextView *text_view)
2945 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2947 return text_view->priv->cursor_visible;
2952 * gtk_text_view_place_cursor_onscreen:
2953 * @text_view: a #GtkTextView
2955 * Moves the cursor to the currently visible region of the
2956 * buffer, it it isn't there already.
2958 * Return value: %TRUE if the cursor had to be moved.
2961 gtk_text_view_place_cursor_onscreen (GtkTextView *text_view)
2965 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2967 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
2968 gtk_text_buffer_get_insert (get_buffer (text_view)));
2970 if (clamp_iter_onscreen (text_view, &insert))
2972 gtk_text_buffer_place_cursor (get_buffer (text_view), &insert);
2980 gtk_text_view_remove_validate_idles (GtkTextView *text_view)
2982 GtkTextViewPrivate *priv = text_view->priv;
2984 if (priv->first_validate_idle != 0)
2986 DV (g_print ("Removing first validate idle: %s\n", G_STRLOC));
2987 g_source_remove (priv->first_validate_idle);
2988 priv->first_validate_idle = 0;
2991 if (priv->incremental_validate_idle != 0)
2993 g_source_remove (priv->incremental_validate_idle);
2994 priv->incremental_validate_idle = 0;
2999 gtk_text_view_destroy (GtkWidget *widget)
3001 GtkTextView *text_view;
3002 GtkTextViewPrivate *priv;
3004 text_view = GTK_TEXT_VIEW (widget);
3005 priv = text_view->priv;
3007 gtk_text_view_remove_validate_idles (text_view);
3008 gtk_text_view_set_buffer (text_view, NULL);
3009 gtk_text_view_destroy_layout (text_view);
3011 if (text_view->priv->scroll_timeout)
3013 g_source_remove (text_view->priv->scroll_timeout);
3014 text_view->priv->scroll_timeout = 0;
3017 if (priv->im_spot_idle)
3019 g_source_remove (priv->im_spot_idle);
3020 priv->im_spot_idle = 0;
3023 GTK_WIDGET_CLASS (gtk_text_view_parent_class)->destroy (widget);
3027 gtk_text_view_finalize (GObject *object)
3029 GtkTextView *text_view;
3030 GtkTextViewPrivate *priv;
3032 text_view = GTK_TEXT_VIEW (object);
3033 priv = text_view->priv;
3035 g_assert (priv->buffer == NULL);
3037 gtk_text_view_destroy_layout (text_view);
3038 gtk_text_view_set_buffer (text_view, NULL);
3040 cancel_pending_scroll (text_view);
3043 pango_tab_array_free (priv->tabs);
3045 if (priv->hadjustment)
3046 g_object_unref (priv->hadjustment);
3047 if (priv->vadjustment)
3048 g_object_unref (priv->vadjustment);
3050 text_window_free (priv->text_window);
3052 if (priv->left_window)
3053 text_window_free (priv->left_window);
3055 if (priv->top_window)
3056 text_window_free (priv->top_window);
3058 if (priv->right_window)
3059 text_window_free (priv->right_window);
3061 if (priv->bottom_window)
3062 text_window_free (priv->bottom_window);
3064 g_object_unref (priv->im_context);
3066 g_free (priv->im_module);
3068 G_OBJECT_CLASS (gtk_text_view_parent_class)->finalize (object);
3072 gtk_text_view_set_property (GObject *object,
3074 const GValue *value,
3077 GtkTextView *text_view;
3078 GtkTextViewPrivate *priv;
3080 text_view = GTK_TEXT_VIEW (object);
3081 priv = text_view->priv;
3085 case PROP_PIXELS_ABOVE_LINES:
3086 gtk_text_view_set_pixels_above_lines (text_view, g_value_get_int (value));
3089 case PROP_PIXELS_BELOW_LINES:
3090 gtk_text_view_set_pixels_below_lines (text_view, g_value_get_int (value));
3093 case PROP_PIXELS_INSIDE_WRAP:
3094 gtk_text_view_set_pixels_inside_wrap (text_view, g_value_get_int (value));
3098 gtk_text_view_set_editable (text_view, g_value_get_boolean (value));
3101 case PROP_WRAP_MODE:
3102 gtk_text_view_set_wrap_mode (text_view, g_value_get_enum (value));
3105 case PROP_JUSTIFICATION:
3106 gtk_text_view_set_justification (text_view, g_value_get_enum (value));
3109 case PROP_LEFT_MARGIN:
3110 gtk_text_view_set_left_margin (text_view, g_value_get_int (value));
3113 case PROP_RIGHT_MARGIN:
3114 gtk_text_view_set_right_margin (text_view, g_value_get_int (value));
3118 gtk_text_view_set_indent (text_view, g_value_get_int (value));
3122 gtk_text_view_set_tabs (text_view, g_value_get_boxed (value));
3125 case PROP_CURSOR_VISIBLE:
3126 gtk_text_view_set_cursor_visible (text_view, g_value_get_boolean (value));
3129 case PROP_OVERWRITE:
3130 gtk_text_view_set_overwrite (text_view, g_value_get_boolean (value));
3134 gtk_text_view_set_buffer (text_view, GTK_TEXT_BUFFER (g_value_get_object (value)));
3137 case PROP_ACCEPTS_TAB:
3138 gtk_text_view_set_accepts_tab (text_view, g_value_get_boolean (value));
3141 case PROP_IM_MODULE:
3142 g_free (priv->im_module);
3143 priv->im_module = g_value_dup_string (value);
3144 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
3145 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
3149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3155 gtk_text_view_get_property (GObject *object,
3160 GtkTextView *text_view;
3161 GtkTextViewPrivate *priv;
3163 text_view = GTK_TEXT_VIEW (object);
3164 priv = text_view->priv;
3168 case PROP_PIXELS_ABOVE_LINES:
3169 g_value_set_int (value, priv->pixels_above_lines);
3172 case PROP_PIXELS_BELOW_LINES:
3173 g_value_set_int (value, priv->pixels_below_lines);
3176 case PROP_PIXELS_INSIDE_WRAP:
3177 g_value_set_int (value, priv->pixels_inside_wrap);
3181 g_value_set_boolean (value, priv->editable);
3184 case PROP_WRAP_MODE:
3185 g_value_set_enum (value, priv->wrap_mode);
3188 case PROP_JUSTIFICATION:
3189 g_value_set_enum (value, priv->justify);
3192 case PROP_LEFT_MARGIN:
3193 g_value_set_int (value, priv->left_margin);
3196 case PROP_RIGHT_MARGIN:
3197 g_value_set_int (value, priv->right_margin);
3201 g_value_set_int (value, priv->indent);
3205 g_value_set_boxed (value, priv->tabs);
3208 case PROP_CURSOR_VISIBLE:
3209 g_value_set_boolean (value, priv->cursor_visible);
3213 g_value_set_object (value, get_buffer (text_view));
3216 case PROP_OVERWRITE:
3217 g_value_set_boolean (value, priv->overwrite_mode);
3220 case PROP_ACCEPTS_TAB:
3221 g_value_set_boolean (value, priv->accepts_tab);
3224 case PROP_IM_MODULE:
3225 g_value_set_string (value, priv->im_module);
3229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3235 gtk_text_view_size_request (GtkWidget *widget,
3236 GtkRequisition *requisition)
3238 GtkTextView *text_view;
3239 GtkTextViewPrivate *priv;
3241 gint focus_edge_width;
3244 gboolean interior_focus;
3246 text_view = GTK_TEXT_VIEW (widget);
3247 priv = text_view->priv;
3249 gtk_widget_style_get (widget,
3250 "interior-focus", &interior_focus,
3251 "focus-line-width", &focus_width,
3255 focus_edge_width = 0;
3257 focus_edge_width = focus_width;
3261 priv->text_window->requisition.width = priv->layout->width;
3262 priv->text_window->requisition.height = priv->layout->height;
3266 priv->text_window->requisition.width = 0;
3267 priv->text_window->requisition.height = 0;
3270 requisition->width = priv->text_window->requisition.width + focus_edge_width * 2;
3271 requisition->height = priv->text_window->requisition.height + focus_edge_width * 2;
3273 if (priv->left_window)
3274 requisition->width += priv->left_window->requisition.width;
3276 if (priv->right_window)
3277 requisition->width += priv->right_window->requisition.width;
3279 if (priv->top_window)
3280 requisition->height += priv->top_window->requisition.height;
3282 if (priv->bottom_window)
3283 requisition->height += priv->bottom_window->requisition.height;
3285 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3286 requisition->width += border_width * 2;
3287 requisition->height += border_width * 2;
3289 tmp_list = priv->children;
3290 while (tmp_list != NULL)
3292 GtkTextViewChild *child = tmp_list->data;
3296 GtkRequisition child_req;
3297 GtkRequisition old_req;
3299 gtk_widget_get_preferred_size (child->widget, &old_req, NULL);
3301 gtk_widget_get_preferred_size (child->widget, &child_req, NULL);
3303 /* Invalidate layout lines if required */
3305 (old_req.width != child_req.width ||
3306 old_req.height != child_req.height))
3307 gtk_text_child_anchor_queue_resize (child->anchor,
3312 GtkRequisition child_req;
3314 gtk_widget_get_preferred_size (child->widget,
3318 tmp_list = g_slist_next (tmp_list);
3321 /* Cache the requested size of the text view so we can
3322 * compare it in the changed_handler() */
3323 priv->cached_size_request = *requisition;
3327 gtk_text_view_compute_child_allocation (GtkTextView *text_view,
3328 GtkTextViewChild *vc,
3329 GtkAllocation *allocation)
3335 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3339 gtk_text_layout_get_line_yrange (text_view->priv->layout, &iter,
3342 buffer_y += vc->from_top_of_line;
3344 allocation->x = vc->from_left_of_buffer - text_view->priv->xoffset;
3345 allocation->y = buffer_y - text_view->priv->yoffset;
3347 gtk_widget_get_preferred_size (vc->widget, &req, NULL);
3348 allocation->width = req.width;
3349 allocation->height = req.height;
3353 gtk_text_view_update_child_allocation (GtkTextView *text_view,
3354 GtkTextViewChild *vc)
3356 GtkAllocation allocation;
3358 gtk_text_view_compute_child_allocation (text_view, vc, &allocation);
3360 gtk_widget_size_allocate (vc->widget, &allocation);
3363 g_print ("allocation for %p allocated to %d,%d yoffset = %d\n",
3365 vc->widget->allocation.x,
3366 vc->widget->allocation.y,
3367 text_view->priv->yoffset);
3372 gtk_text_view_child_allocated (GtkTextLayout *layout,
3378 GtkTextViewChild *vc = NULL;
3379 GtkTextView *text_view = data;
3381 /* x,y is the position of the child from the top of the line, and
3382 * from the left of the buffer. We have to translate that into text
3383 * window coordinates, then size_allocate the child.
3386 vc = g_object_get_data (G_OBJECT (child),
3387 "gtk-text-view-child");
3389 g_assert (vc != NULL);
3391 DV (g_print ("child allocated at %d,%d\n", x, y));
3393 vc->from_left_of_buffer = x;
3394 vc->from_top_of_line = y;
3396 gtk_text_view_update_child_allocation (text_view, vc);
3400 gtk_text_view_allocate_children (GtkTextView *text_view)
3404 DV(g_print(G_STRLOC"\n"));
3406 tmp_list = text_view->priv->children;
3407 while (tmp_list != NULL)
3409 GtkTextViewChild *child = tmp_list->data;
3411 g_assert (child != NULL);
3415 /* We need to force-validate the regions containing
3418 GtkTextIter child_loc;
3419 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3423 /* Since anchored children are only ever allocated from
3424 * gtk_text_layout_get_line_display() we have to make sure
3425 * that the display line caching in the layout doesn't
3426 * get in the way. Invalidating the layout around the anchor
3429 if (_gtk_widget_get_alloc_needed (child->widget))
3431 GtkTextIter end = child_loc;
3432 gtk_text_iter_forward_char (&end);
3433 gtk_text_layout_invalidate (text_view->priv->layout, &child_loc, &end);
3436 gtk_text_layout_validate_yrange (text_view->priv->layout,
3442 GtkAllocation allocation;
3443 GtkRequisition child_req;
3445 allocation.x = child->x;
3446 allocation.y = child->y;
3448 gtk_widget_get_preferred_size (child->widget, &child_req, NULL);
3450 allocation.width = child_req.width;
3451 allocation.height = child_req.height;
3453 gtk_widget_size_allocate (child->widget, &allocation);
3456 tmp_list = g_slist_next (tmp_list);
3461 gtk_text_view_size_allocate (GtkWidget *widget,
3462 GtkAllocation *allocation)
3464 GtkAllocation widget_allocation;
3465 GtkTextView *text_view;
3466 GtkTextViewPrivate *priv;
3467 GtkTextIter first_para;
3470 GdkRectangle text_rect;
3471 GdkRectangle left_rect;
3472 GdkRectangle right_rect;
3473 GdkRectangle top_rect;
3474 GdkRectangle bottom_rect;
3475 gint focus_edge_width;
3478 gboolean interior_focus;
3479 gboolean size_changed;
3481 text_view = GTK_TEXT_VIEW (widget);
3482 priv = text_view->priv;
3484 DV(g_print(G_STRLOC"\n"));
3486 gtk_widget_get_allocation (widget, &widget_allocation);
3488 widget_allocation.width != allocation->width ||
3489 widget_allocation.height != allocation->height;
3491 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3493 gtk_widget_set_allocation (widget, allocation);
3495 if (gtk_widget_get_realized (widget))
3497 gdk_window_move_resize (gtk_widget_get_window (widget),
3498 allocation->x, allocation->y,
3499 allocation->width, allocation->height);
3502 /* distribute width/height among child windows. Ensure all
3503 * windows get at least a 1x1 allocation.
3506 gtk_widget_style_get (widget,
3507 "interior-focus", &interior_focus,
3508 "focus-line-width", &focus_width,
3512 focus_edge_width = 0;
3514 focus_edge_width = focus_width;
3516 width = allocation->width - focus_edge_width * 2 - border_width * 2;
3518 if (priv->left_window)
3519 left_rect.width = priv->left_window->requisition.width;
3521 left_rect.width = 0;
3523 width -= left_rect.width;
3525 if (priv->right_window)
3526 right_rect.width = priv->right_window->requisition.width;
3528 right_rect.width = 0;
3530 width -= right_rect.width;
3532 text_rect.width = MAX (1, width);
3534 top_rect.width = text_rect.width;
3535 bottom_rect.width = text_rect.width;
3538 height = allocation->height - focus_edge_width * 2 - border_width * 2;
3540 if (priv->top_window)
3541 top_rect.height = priv->top_window->requisition.height;
3543 top_rect.height = 0;
3545 height -= top_rect.height;
3547 if (priv->bottom_window)
3548 bottom_rect.height = priv->bottom_window->requisition.height;
3550 bottom_rect.height = 0;
3552 height -= bottom_rect.height;
3554 text_rect.height = MAX (1, height);
3556 left_rect.height = text_rect.height;
3557 right_rect.height = text_rect.height;
3560 left_rect.x = focus_edge_width + border_width;
3561 top_rect.y = focus_edge_width + border_width;
3563 text_rect.x = left_rect.x + left_rect.width;
3564 text_rect.y = top_rect.y + top_rect.height;
3566 left_rect.y = text_rect.y;
3567 right_rect.y = text_rect.y;
3569 top_rect.x = text_rect.x;
3570 bottom_rect.x = text_rect.x;
3572 right_rect.x = text_rect.x + text_rect.width;
3573 bottom_rect.y = text_rect.y + text_rect.height;
3575 text_window_size_allocate (priv->text_window,
3578 if (priv->left_window)
3579 text_window_size_allocate (priv->left_window,
3582 if (priv->right_window)
3583 text_window_size_allocate (priv->right_window,
3586 if (priv->top_window)
3587 text_window_size_allocate (priv->top_window,
3590 if (priv->bottom_window)
3591 text_window_size_allocate (priv->bottom_window,
3594 gtk_text_view_update_layout_width (text_view);
3596 /* Note that this will do some layout validation */
3597 gtk_text_view_allocate_children (text_view);
3599 /* Ensure h/v adj exist */
3600 get_hadjustment (text_view);
3601 get_vadjustment (text_view);
3603 priv->hadjustment->page_size = SCREEN_WIDTH (text_view);
3604 priv->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9;
3605 priv->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1;
3606 priv->hadjustment->lower = 0;
3607 priv->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
3610 if (priv->hadjustment->value > priv->hadjustment->upper - priv->hadjustment->page_size)
3611 gtk_adjustment_set_value (priv->hadjustment, MAX (0, priv->hadjustment->upper - priv->hadjustment->page_size));
3613 gtk_adjustment_changed (priv->hadjustment);
3615 priv->vadjustment->page_size = SCREEN_HEIGHT (text_view);
3616 priv->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9;
3617 priv->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1;
3618 priv->vadjustment->lower = 0;
3619 priv->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
3622 /* Now adjust the value of the adjustment to keep the cursor at the
3623 * same place in the buffer
3625 gtk_text_view_get_first_para_iter (text_view, &first_para);
3626 gtk_text_layout_get_line_yrange (priv->layout, &first_para, &y, NULL);
3628 y += priv->first_para_pixels;
3630 if (y > priv->vadjustment->upper - priv->vadjustment->page_size)
3631 y = MAX (0, priv->vadjustment->upper - priv->vadjustment->page_size);
3633 if (y != priv->yoffset)
3634 gtk_adjustment_set_value (priv->vadjustment, y);
3636 gtk_adjustment_changed (priv->vadjustment);
3638 /* The GTK resize loop processes all the pending exposes right
3639 * after doing the resize stuff, so the idle sizer won't have a
3640 * chance to run. So we do the work here.
3642 gtk_text_view_flush_first_validate (text_view);
3644 /* widget->window doesn't get auto-redrawn as the layout is computed, so has to
3647 if (size_changed && gtk_widget_get_realized (widget))
3648 gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE);
3652 gtk_text_view_get_first_para_iter (GtkTextView *text_view,
3655 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), iter,
3656 text_view->priv->first_para_mark);
3660 gtk_text_view_validate_onscreen (GtkTextView *text_view)
3663 GtkTextViewPrivate *priv;
3665 widget = GTK_WIDGET (text_view);
3666 priv = text_view->priv;
3668 DV(g_print(">Validating onscreen ("G_STRLOC")\n"));
3670 if (SCREEN_HEIGHT (widget) > 0)
3672 GtkTextIter first_para;
3674 /* Be sure we've validated the stuff onscreen; if we
3675 * scrolled, these calls won't have any effect, because
3676 * they were called in the recursive validate_onscreen
3678 gtk_text_view_get_first_para_iter (text_view, &first_para);
3680 gtk_text_layout_validate_yrange (priv->layout,
3683 priv->first_para_pixels +
3684 SCREEN_HEIGHT (widget));
3687 priv->onscreen_validated = TRUE;
3689 DV(g_print(">Done validating onscreen, onscreen_validated = TRUE ("G_STRLOC")\n"));
3691 /* This can have the odd side effect of triggering a scroll, which should
3692 * flip "onscreen_validated" back to FALSE, but should also get us
3693 * back into this function to turn it on again.
3695 gtk_text_view_update_adjustments (text_view);
3697 g_assert (priv->onscreen_validated);
3701 gtk_text_view_flush_first_validate (GtkTextView *text_view)
3703 GtkTextViewPrivate *priv = text_view->priv;
3705 if (priv->first_validate_idle == 0)
3708 /* Do this first, which means that if an "invalidate"
3709 * occurs during any of this process, a new first_validate_callback
3710 * will be installed, and we'll start again.
3712 DV (g_print ("removing first validate in %s\n", G_STRLOC));
3713 g_source_remove (priv->first_validate_idle);
3714 priv->first_validate_idle = 0;
3716 /* be sure we have up-to-date screen size set on the
3719 gtk_text_view_update_layout_width (text_view);
3721 /* Bail out if we invalidated stuff; scrolling right away will just
3722 * confuse the issue.
3724 if (priv->first_validate_idle != 0)
3726 DV(g_print(">Width change forced requeue ("G_STRLOC")\n"));
3730 /* scroll to any marks, if that's pending. This can jump us to
3731 * the validation codepath used for scrolling onscreen, if so we
3732 * bail out. It won't jump if already in that codepath since
3733 * value_changed is not recursive, so also validate if
3736 if (!gtk_text_view_flush_scroll (text_view) ||
3737 !priv->onscreen_validated)
3738 gtk_text_view_validate_onscreen (text_view);
3740 DV(g_print(">Leaving first validate idle ("G_STRLOC")\n"));
3742 g_assert (priv->onscreen_validated);
3747 first_validate_callback (gpointer data)
3749 GtkTextView *text_view = data;
3751 /* Note that some of this code is duplicated at the end of size_allocate,
3752 * keep in sync with that.
3755 DV(g_print(G_STRLOC"\n"));
3757 gtk_text_view_flush_first_validate (text_view);
3763 incremental_validate_callback (gpointer data)
3765 GtkTextView *text_view = data;
3766 gboolean result = TRUE;
3768 DV(g_print(G_STRLOC"\n"));
3770 gtk_text_layout_validate (text_view->priv->layout, 2000);
3772 gtk_text_view_update_adjustments (text_view);
3774 if (gtk_text_layout_is_valid (text_view->priv->layout))
3776 text_view->priv->incremental_validate_idle = 0;
3784 gtk_text_view_invalidate (GtkTextView *text_view)
3786 GtkTextViewPrivate *priv = text_view->priv;
3788 DV (g_print (">Invalidate, onscreen_validated = %d now FALSE ("G_STRLOC")\n",
3789 priv->onscreen_validated));
3791 priv->onscreen_validated = FALSE;
3793 /* We'll invalidate when the layout is created */
3794 if (priv->layout == NULL)
3797 if (!priv->first_validate_idle)
3799 priv->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
3800 DV (g_print (G_STRLOC": adding first validate idle %d\n",
3801 priv->first_validate_idle));
3804 if (!priv->incremental_validate_idle)
3806 priv->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
3807 DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
3808 priv->incremental_validate_idle));
3813 invalidated_handler (GtkTextLayout *layout,
3816 GtkTextView *text_view;
3818 text_view = GTK_TEXT_VIEW (data);
3820 DV (g_print ("Invalidating due to layout invalidate signal\n"));
3821 gtk_text_view_invalidate (text_view);
3825 changed_handler (GtkTextLayout *layout,
3831 GtkTextView *text_view;
3832 GtkTextViewPrivate *priv;
3834 GdkRectangle visible_rect;
3835 GdkRectangle redraw_rect;
3837 text_view = GTK_TEXT_VIEW (data);
3838 priv = text_view->priv;
3839 widget = GTK_WIDGET (data);
3841 DV(g_print(">Lines Validated ("G_STRLOC")\n"));
3843 if (gtk_widget_get_realized (widget))
3845 gtk_text_view_get_visible_rect (text_view, &visible_rect);
3847 redraw_rect.x = visible_rect.x;
3848 redraw_rect.width = visible_rect.width;
3849 redraw_rect.y = start_y;
3851 if (old_height == new_height)
3852 redraw_rect.height = old_height;
3853 else if (start_y + old_height > visible_rect.y)
3854 redraw_rect.height = MAX (0, visible_rect.y + visible_rect.height - start_y);
3856 redraw_rect.height = 0;
3858 if (gdk_rectangle_intersect (&redraw_rect, &visible_rect, &redraw_rect))
3860 /* text_window_invalidate_rect() takes buffer coordinates */
3861 text_window_invalidate_rect (priv->text_window,
3864 DV(g_print(" invalidated rect: %d,%d %d x %d\n",
3868 redraw_rect.height));
3870 if (priv->left_window)
3871 text_window_invalidate_rect (priv->left_window,
3873 if (priv->right_window)
3874 text_window_invalidate_rect (priv->right_window,
3876 if (priv->top_window)
3877 text_window_invalidate_rect (priv->top_window,
3879 if (priv->bottom_window)
3880 text_window_invalidate_rect (priv->bottom_window,
3883 queue_update_im_spot_location (text_view);
3887 if (old_height != new_height)
3889 gboolean yoffset_changed = FALSE;
3891 int new_first_para_top;
3892 int old_first_para_top;
3895 /* If the bottom of the old area was above the top of the
3896 * screen, we need to scroll to keep the current top of the
3897 * screen in place. Remember that first_para_pixels is the
3898 * position of the top of the screen in coordinates relative to
3899 * the first paragraph onscreen.
3901 * In short we are adding the height delta of the portion of the
3902 * changed region above first_para_mark to priv->yoffset.
3904 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &first,
3905 priv->first_para_mark);
3907 gtk_text_layout_get_line_yrange (layout, &first, &new_first_para_top, NULL);
3909 old_first_para_top = priv->yoffset - priv->first_para_pixels;
3911 if (new_first_para_top != old_first_para_top)
3913 priv->yoffset += new_first_para_top - old_first_para_top;
3915 get_vadjustment (text_view)->value = priv->yoffset;
3916 yoffset_changed = TRUE;
3919 if (yoffset_changed)
3921 DV(g_print ("Changing scroll position (%s)\n", G_STRLOC));
3922 gtk_adjustment_value_changed (get_vadjustment (text_view));
3925 /* FIXME be smarter about which anchored widgets we update */
3927 tmp_list = priv->children;
3928 while (tmp_list != NULL)
3930 GtkTextViewChild *child = tmp_list->data;
3933 gtk_text_view_update_child_allocation (text_view, child);
3935 tmp_list = g_slist_next (tmp_list);
3940 GtkRequisition old_req = priv->cached_size_request;
3941 GtkRequisition new_req;
3943 /* Use this instead of gtk_widget_size_request wrapper
3944 * to avoid the optimization which just returns widget->requisition
3945 * if a resize hasn't been queued.
3947 GTK_WIDGET_GET_CLASS (widget)->size_request (widget, &new_req);
3949 if (old_req.width != new_req.width ||
3950 old_req.height != new_req.height)
3952 gtk_widget_queue_resize_no_redraw (widget);
3958 gtk_text_view_realize (GtkWidget *widget)
3960 GtkAllocation allocation;
3961 GtkTextView *text_view;
3962 GtkTextViewPrivate *priv;
3964 GdkWindowAttr attributes;
3965 gint attributes_mask;
3968 text_view = GTK_TEXT_VIEW (widget);
3969 priv = text_view->priv;
3971 gtk_widget_set_realized (widget, TRUE);
3973 gtk_widget_get_allocation (widget, &allocation);
3975 attributes.window_type = GDK_WINDOW_CHILD;
3976 attributes.x = allocation.x;
3977 attributes.y = allocation.y;
3978 attributes.width = allocation.width;
3979 attributes.height = allocation.height;
3980 attributes.wclass = GDK_INPUT_OUTPUT;
3981 attributes.visual = gtk_widget_get_visual (widget);
3982 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK;
3984 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
3986 window = gdk_window_new (gtk_widget_get_parent_window (widget),
3987 &attributes, attributes_mask);
3988 gtk_widget_set_window (widget, window);
3989 gdk_window_set_user_data (window, widget);
3991 /* must come before text_window_realize calls */
3992 gtk_widget_style_attach (widget);
3994 gdk_window_set_background (window,
3995 >k_widget_get_style (widget)->bg[gtk_widget_get_state (widget)]);
3997 text_window_realize (priv->text_window, widget);
3999 if (priv->left_window)
4000 text_window_realize (priv->left_window, widget);
4002 if (priv->top_window)
4003 text_window_realize (priv->top_window, widget);
4005 if (priv->right_window)
4006 text_window_realize (priv->right_window, widget);
4008 if (priv->bottom_window)
4009 text_window_realize (priv->bottom_window, widget);
4011 gtk_text_view_ensure_layout (text_view);
4015 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4016 GDK_SELECTION_PRIMARY);
4017 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
4020 tmp_list = priv->children;
4021 while (tmp_list != NULL)
4023 GtkTextViewChild *vc = tmp_list->data;
4025 text_view_child_set_parent_window (text_view, vc);
4027 tmp_list = tmp_list->next;
4030 /* Ensure updating the spot location. */
4031 gtk_text_view_update_im_spot_location (text_view);
4035 gtk_text_view_unrealize (GtkWidget *widget)
4037 GtkTextView *text_view;
4038 GtkTextViewPrivate *priv;
4040 text_view = GTK_TEXT_VIEW (widget);
4041 priv = text_view->priv;
4045 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4046 GDK_SELECTION_PRIMARY);
4047 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
4050 gtk_text_view_remove_validate_idles (text_view);
4052 if (priv->popup_menu)
4054 gtk_widget_destroy (priv->popup_menu);
4055 priv->popup_menu = NULL;
4058 text_window_unrealize (priv->text_window);
4060 if (priv->left_window)
4061 text_window_unrealize (priv->left_window);
4063 if (priv->top_window)
4064 text_window_unrealize (priv->top_window);
4066 if (priv->right_window)
4067 text_window_unrealize (priv->right_window);
4069 if (priv->bottom_window)
4070 text_window_unrealize (priv->bottom_window);
4072 gtk_text_view_destroy_layout (text_view);
4074 GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize (widget);
4078 gtk_text_view_set_background (GtkTextView *text_view)
4083 GtkTextViewPrivate *priv;
4085 widget = GTK_WIDGET (text_view);
4086 priv = text_view->priv;
4088 style = gtk_widget_get_style (widget);
4089 state = gtk_widget_get_state (widget);
4091 gdk_window_set_background (gtk_widget_get_window (widget),
4094 gdk_window_set_background (priv->text_window->bin_window,
4095 &style->base[state]);
4097 if (priv->left_window)
4098 gdk_window_set_background (priv->left_window->bin_window,
4100 if (priv->right_window)
4101 gdk_window_set_background (priv->right_window->bin_window,
4104 if (priv->top_window)
4105 gdk_window_set_background (priv->top_window->bin_window,
4108 if (priv->bottom_window)
4109 gdk_window_set_background (priv->bottom_window->bin_window,
4114 gtk_text_view_style_set (GtkWidget *widget,
4115 GtkStyle *previous_style)
4117 GtkTextView *text_view;
4118 GtkTextViewPrivate *priv;
4119 PangoContext *ltr_context, *rtl_context;
4121 text_view = GTK_TEXT_VIEW (widget);
4122 priv = text_view->priv;
4124 if (gtk_widget_get_realized (widget))
4126 gtk_text_view_set_background (text_view);
4129 if (priv->layout && previous_style)
4131 gtk_text_view_set_attributes_from_style (text_view,
4132 priv->layout->default_style,
4133 gtk_widget_get_style (widget));
4135 ltr_context = gtk_widget_create_pango_context (widget);
4136 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
4137 rtl_context = gtk_widget_create_pango_context (widget);
4138 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
4140 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
4142 g_object_unref (ltr_context);
4143 g_object_unref (rtl_context);
4148 gtk_text_view_direction_changed (GtkWidget *widget,
4149 GtkTextDirection previous_direction)
4151 GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
4155 priv->layout->default_style->direction = gtk_widget_get_direction (widget);
4157 gtk_text_layout_default_style_changed (priv->layout);
4162 gtk_text_view_state_changed (GtkWidget *widget,
4163 GtkStateType previous_state)
4165 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
4168 if (gtk_widget_get_realized (widget))
4170 gtk_text_view_set_background (text_view);
4172 if (gtk_widget_is_sensitive (widget))
4173 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4177 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4180 gdk_cursor_unref (cursor);
4182 text_view->priv->mouse_cursor_obscured = FALSE;
4185 if (!gtk_widget_is_sensitive (widget))
4187 /* Clear any selection */
4188 gtk_text_view_unselect (text_view);
4191 gtk_widget_queue_draw (widget);
4195 set_invisible_cursor (GdkWindow *window)
4197 GdkDisplay *display;
4200 display = gdk_window_get_display (window);
4201 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4203 gdk_window_set_cursor (window, cursor);
4205 gdk_cursor_unref (cursor);
4209 gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
4211 if (text_view->priv->mouse_cursor_obscured)
4214 set_invisible_cursor (text_view->priv->text_window->bin_window);
4216 text_view->priv->mouse_cursor_obscured = TRUE;
4220 gtk_text_view_unobscure_mouse_cursor (GtkTextView *text_view)
4222 if (text_view->priv->mouse_cursor_obscured)
4226 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)),
4228 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4229 gdk_cursor_unref (cursor);
4230 text_view->priv->mouse_cursor_obscured = FALSE;
4235 gtk_text_view_grab_notify (GtkWidget *widget,
4236 gboolean was_grabbed)
4238 GtkTextViewPrivate *priv;
4240 priv = GTK_TEXT_VIEW (widget)->priv;
4242 if (priv->grab_device &&
4243 gtk_widget_device_is_shadowed (widget, priv->grab_device))
4245 gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget));
4246 gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
4256 get_event_coordinates (GdkEvent *event, gint *x, gint *y)
4259 switch (event->type)
4261 case GDK_MOTION_NOTIFY:
4262 *x = event->motion.x;
4263 *y = event->motion.y;
4267 case GDK_BUTTON_PRESS:
4268 case GDK_2BUTTON_PRESS:
4269 case GDK_3BUTTON_PRESS:
4270 case GDK_BUTTON_RELEASE:
4271 *x = event->button.x;
4272 *y = event->button.y;
4277 case GDK_KEY_RELEASE:
4278 case GDK_ENTER_NOTIFY:
4279 case GDK_LEAVE_NOTIFY:
4280 case GDK_PROPERTY_NOTIFY:
4281 case GDK_SELECTION_CLEAR:
4282 case GDK_SELECTION_REQUEST:
4283 case GDK_SELECTION_NOTIFY:
4284 case GDK_PROXIMITY_IN:
4285 case GDK_PROXIMITY_OUT:
4286 case GDK_DRAG_ENTER:
4287 case GDK_DRAG_LEAVE:
4288 case GDK_DRAG_MOTION:
4289 case GDK_DRAG_STATUS:
4290 case GDK_DROP_START:
4291 case GDK_DROP_FINISHED:
4301 emit_event_on_tags (GtkWidget *widget,
4307 gboolean retval = FALSE;
4309 tags = gtk_text_iter_get_tags (iter);
4314 GtkTextTag *tag = tmp->data;
4316 if (gtk_text_tag_event (tag, G_OBJECT (widget), event, iter))
4322 tmp = g_slist_next (tmp);
4325 g_slist_free (tags);
4331 gtk_text_view_event (GtkWidget *widget, GdkEvent *event)
4333 GtkTextView *text_view;
4334 GtkTextViewPrivate *priv;
4337 text_view = GTK_TEXT_VIEW (widget);
4338 priv = text_view->priv;
4340 if (priv->layout == NULL ||
4341 get_buffer (text_view) == NULL)
4344 if (event->any.window != priv->text_window->bin_window)
4347 if (get_event_coordinates (event, &x, &y))
4354 /* FIXME this is slow and we do it twice per event.
4355 * My favorite solution is to have GtkTextLayout cache
4356 * the last couple lookups.
4358 gtk_text_layout_get_iter_at_pixel (priv->layout,
4362 return emit_event_on_tags (widget, event, &iter);
4364 else if (event->type == GDK_KEY_PRESS ||
4365 event->type == GDK_KEY_RELEASE)
4369 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
4370 gtk_text_buffer_get_insert (get_buffer (text_view)));
4372 return emit_event_on_tags (widget, event, &iter);
4379 gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
4381 GtkTextView *text_view;
4382 GtkTextViewPrivate *priv;
4383 GtkTextMark *insert;
4385 gboolean can_insert;
4386 gboolean retval = FALSE;
4387 gboolean obscure = FALSE;
4389 text_view = GTK_TEXT_VIEW (widget);
4390 priv = text_view->priv;
4392 if (priv->layout == NULL ||
4393 get_buffer (text_view) == NULL)
4396 /* Make sure input method knows where it is */
4397 flush_update_im_spot_location (text_view);
4399 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4400 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4401 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
4402 if (gtk_im_context_filter_keypress (priv->im_context, event))
4404 priv->need_im_reset = TRUE;
4406 gtk_text_view_reset_im_context (text_view);
4407 obscure = can_insert;
4411 else if (GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_press_event (widget, event))
4415 /* use overall editability not can_insert, more predictable for users */
4416 else if (priv->editable &&
4417 (event->keyval == GDK_KEY_Return ||
4418 event->keyval == GDK_KEY_ISO_Enter ||
4419 event->keyval == GDK_KEY_KP_Enter))
4421 /* this won't actually insert the newline if the cursor isn't
4424 gtk_text_view_reset_im_context (text_view);
4425 gtk_text_view_commit_text (text_view, "\n");
4430 /* Pass through Tab as literal tab, unless Control is held down */
4431 else if ((event->keyval == GDK_KEY_Tab ||
4432 event->keyval == GDK_KEY_KP_Tab ||
4433 event->keyval == GDK_KEY_ISO_Left_Tab) &&
4434 !(event->state & GDK_CONTROL_MASK))
4436 /* If the text widget isn't editable overall, or if the application
4437 * has turned off "accepts_tab", move the focus instead
4439 if (priv->accepts_tab && priv->editable)
4441 gtk_text_view_reset_im_context (text_view);
4442 gtk_text_view_commit_text (text_view, "\t");
4446 g_signal_emit_by_name (text_view, "move-focus",
4447 (event->state & GDK_SHIFT_MASK) ?
4448 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
4456 gtk_text_view_obscure_mouse_cursor (text_view);
4458 gtk_text_view_reset_blink_time (text_view);
4459 gtk_text_view_pend_cursor_blink (text_view);
4465 gtk_text_view_key_release_event (GtkWidget *widget, GdkEventKey *event)
4467 GtkTextView *text_view;
4468 GtkTextViewPrivate *priv;
4469 GtkTextMark *insert;
4472 text_view = GTK_TEXT_VIEW (widget);
4473 priv = text_view->priv;
4475 if (priv->layout == NULL || get_buffer (text_view) == NULL)
4478 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4479 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4480 if (gtk_text_iter_can_insert (&iter, priv->editable) &&
4481 gtk_im_context_filter_keypress (priv->im_context, event))
4483 priv->need_im_reset = TRUE;
4487 return GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_release_event (widget, event);
4491 gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
4493 GtkTextView *text_view;
4494 GtkTextViewPrivate *priv;
4496 text_view = GTK_TEXT_VIEW (widget);
4497 priv = text_view->priv;
4499 gtk_widget_grab_focus (widget);
4501 if (event->window != priv->text_window->bin_window)
4503 /* Remove selection if any. */
4504 gtk_text_view_unselect (text_view);
4508 gtk_text_view_reset_blink_time (text_view);
4512 if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
4513 _gtk_text_buffer_spew (GTK_TEXT_VIEW (widget)->buffer);
4514 else if (event->button == 3)
4515 gtk_text_layout_spew (GTK_TEXT_VIEW (widget)->layout);
4518 if (event->type == GDK_BUTTON_PRESS)
4520 gtk_text_view_reset_im_context (text_view);
4522 if (event->button == 1)
4524 /* If we're in the selection, start a drag copy/move of the
4525 * selection; otherwise, start creating a new selection.
4528 GtkTextIter start, end;
4530 gtk_text_layout_get_iter_at_pixel (priv->layout,
4532 event->x + priv->xoffset,
4533 event->y + priv->yoffset);
4535 if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
4537 gtk_text_iter_in_range (&iter, &start, &end) &&
4538 !(event->state & GDK_SHIFT_MASK))
4540 priv->drag_start_x = event->x;
4541 priv->drag_start_y = event->y;
4542 priv->pending_place_cursor_button = event->button;
4546 gtk_text_view_start_selection_drag (text_view, &iter, event);
4551 else if (event->button == 2)
4555 /* We do not want to scroll back to the insert iter when we paste
4556 with the middle button */
4557 priv->scroll_after_paste = FALSE;
4559 gtk_text_layout_get_iter_at_pixel (priv->layout,
4561 event->x + priv->xoffset,
4562 event->y + priv->yoffset);
4564 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
4565 gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY),
4570 else if (event->button == 3)
4572 gtk_text_view_do_popup (text_view, event);
4576 else if ((event->type == GDK_2BUTTON_PRESS ||
4577 event->type == GDK_3BUTTON_PRESS) &&
4582 gtk_text_view_end_selection_drag (text_view);
4584 gtk_text_layout_get_iter_at_pixel (priv->layout,
4586 event->x + priv->xoffset,
4587 event->y + priv->yoffset);
4589 gtk_text_view_start_selection_drag (text_view, &iter, event);
4597 gtk_text_view_button_release_event (GtkWidget *widget, GdkEventButton *event)
4599 GtkTextView *text_view;
4600 GtkTextViewPrivate *priv;
4602 text_view = GTK_TEXT_VIEW (widget);
4603 priv = text_view->priv;
4605 if (event->window != priv->text_window->bin_window)
4608 if (event->button == 1)
4610 if (priv->drag_start_x >= 0)
4612 priv->drag_start_x = -1;
4613 priv->drag_start_y = -1;
4616 if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget)))
4618 else if (priv->pending_place_cursor_button == event->button)
4622 /* Unselect everything; we clicked inside selection, but
4623 * didn't move by the drag threshold, so just clear selection
4626 gtk_text_layout_get_iter_at_pixel (priv->layout,
4628 event->x + priv->xoffset,
4629 event->y + priv->yoffset);
4631 gtk_text_buffer_place_cursor (get_buffer (text_view), &iter);
4632 gtk_text_view_check_cursor_blink (text_view);
4634 priv->pending_place_cursor_button = 0;
4644 keymap_direction_changed (GdkKeymap *keymap,
4645 GtkTextView *text_view)
4647 gtk_text_view_check_keymap_direction (text_view);
4651 gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
4653 GtkTextView *text_view;
4654 GtkTextViewPrivate *priv;
4656 text_view = GTK_TEXT_VIEW (widget);
4657 priv = text_view->priv;
4659 gtk_widget_queue_draw (widget);
4661 DV(g_print (G_STRLOC": focus_in_event\n"));
4663 gtk_text_view_reset_blink_time (text_view);
4665 if (priv->cursor_visible && priv->layout)
4667 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
4668 gtk_text_view_check_cursor_blink (text_view);
4671 g_signal_connect (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4672 "direction-changed",
4673 G_CALLBACK (keymap_direction_changed), text_view);
4674 gtk_text_view_check_keymap_direction (text_view);
4678 priv->need_im_reset = TRUE;
4679 gtk_im_context_focus_in (priv->im_context);
4686 gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
4688 GtkTextView *text_view;
4689 GtkTextViewPrivate *priv;
4691 text_view = GTK_TEXT_VIEW (widget);
4692 priv = text_view->priv;
4694 gtk_text_view_end_selection_drag (text_view);
4696 gtk_widget_queue_draw (widget);
4698 DV(g_print (G_STRLOC": focus_out_event\n"));
4700 if (priv->cursor_visible && priv->layout)
4702 gtk_text_view_check_cursor_blink (text_view);
4703 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
4706 g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4707 keymap_direction_changed,
4712 priv->need_im_reset = TRUE;
4713 gtk_im_context_focus_out (priv->im_context);
4720 gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
4722 GtkTextView *text_view;
4723 GtkTextViewPrivate *priv;
4725 text_view = GTK_TEXT_VIEW (widget);
4726 priv = text_view->priv;
4728 gtk_text_view_unobscure_mouse_cursor (text_view);
4730 if (event->window == priv->text_window->bin_window &&
4731 priv->drag_start_x >= 0)
4736 gdk_event_request_motions (event);
4738 if (gtk_drag_check_threshold (widget,
4744 gint buffer_x, buffer_y;
4746 gtk_text_view_window_to_buffer_coords (text_view,
4747 GTK_TEXT_WINDOW_TEXT,
4753 gtk_text_layout_get_iter_at_pixel (priv->layout,
4755 buffer_x, buffer_y);
4757 gtk_text_view_start_selection_dnd (text_view, &iter, event);
4766 gtk_text_view_paint (GtkWidget *widget,
4769 GtkTextView *text_view;
4770 GtkTextViewPrivate *priv;
4771 GList *child_exposes;
4774 text_view = GTK_TEXT_VIEW (widget);
4775 priv = text_view->priv;
4777 g_return_if_fail (priv->layout != NULL);
4778 g_return_if_fail (priv->xoffset >= 0);
4779 g_return_if_fail (priv->yoffset >= 0);
4781 while (priv->first_validate_idle != 0)
4783 DV (g_print (G_STRLOC": first_validate_idle: %d\n",
4784 priv->first_validate_idle));
4785 gtk_text_view_flush_first_validate (text_view);
4788 if (!priv->onscreen_validated)
4790 g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen - may be a text widget bug.");
4791 g_assert_not_reached ();
4795 printf ("painting %d,%d %d x %d\n",
4797 area->width, area->height);
4800 child_exposes = NULL;
4803 cairo_translate (cr, -priv->xoffset, -priv->yoffset);
4805 gtk_text_layout_draw (priv->layout,
4812 tmp_list = child_exposes;
4813 while (tmp_list != NULL)
4815 GtkWidget *child = tmp_list->data;
4817 gtk_container_propagate_draw (GTK_CONTAINER (text_view),
4821 g_object_unref (child);
4823 tmp_list = tmp_list->next;
4826 g_list_free (child_exposes);
4830 gtk_text_view_draw (GtkWidget *widget,
4836 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
4837 gtk_text_view_draw_focus (widget, cr);
4839 window = gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
4840 GTK_TEXT_WINDOW_TEXT);
4841 if (gtk_cairo_should_draw_window (cr, window))
4843 DV(g_print (">Exposed ("G_STRLOC")\n"));
4845 gtk_cairo_transform_to_window (cr, widget, window);
4846 gtk_text_view_paint (widget, cr);
4850 /* Propagate exposes to all unanchored children.
4851 * Anchored children are handled in gtk_text_view_paint().
4853 tmp_list = GTK_TEXT_VIEW (widget)->priv->children;
4854 while (tmp_list != NULL)
4856 GtkTextViewChild *vc = tmp_list->data;
4858 /* propagate_draw checks that event->window matches
4862 gtk_container_propagate_draw (GTK_CONTAINER (widget),
4866 tmp_list = tmp_list->next;
4873 gtk_text_view_draw_focus (GtkWidget *widget,
4876 gboolean interior_focus;
4878 /* We clear the focus if we are in interior focus mode. */
4879 gtk_widget_style_get (widget,
4880 "interior-focus", &interior_focus,
4883 if (gtk_widget_has_focus (widget) && !interior_focus)
4885 gtk_paint_focus (gtk_widget_get_style (widget), cr,
4886 gtk_widget_get_state (widget),
4889 gtk_widget_get_allocated_width (widget),
4890 gtk_widget_get_allocated_height (widget));
4895 gtk_text_view_focus (GtkWidget *widget,
4896 GtkDirectionType direction)
4898 GtkContainer *container;
4901 container = GTK_CONTAINER (widget);
4903 if (!gtk_widget_is_focus (widget) &&
4904 gtk_container_get_focus_child (container) == NULL)
4906 gtk_widget_grab_focus (widget);
4912 * Unset CAN_FOCUS flag so that gtk_container_focus() allows
4913 * children to get the focus
4915 gtk_widget_set_can_focus (widget, FALSE);
4916 result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
4917 gtk_widget_set_can_focus (widget, TRUE);
4928 gtk_text_view_add (GtkContainer *container,
4931 /* This is pretty random. */
4932 gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container),
4934 GTK_TEXT_WINDOW_WIDGET,
4939 gtk_text_view_remove (GtkContainer *container,
4942 GtkTextView *text_view;
4943 GtkTextViewPrivate *priv;
4944 GtkTextViewChild *vc;
4947 text_view = GTK_TEXT_VIEW (container);
4948 priv = text_view->priv;
4951 iter = priv->children;
4953 while (iter != NULL)
4957 if (vc->widget == child)
4960 iter = g_slist_next (iter);
4963 g_assert (iter != NULL); /* be sure we had the child in the list */
4965 priv->children = g_slist_remove (priv->children, vc);
4967 gtk_widget_unparent (vc->widget);
4969 text_view_child_free (vc);
4973 gtk_text_view_forall (GtkContainer *container,
4974 gboolean include_internals,
4975 GtkCallback callback,
4976 gpointer callback_data)
4979 GtkTextView *text_view;
4982 g_return_if_fail (GTK_IS_TEXT_VIEW (container));
4983 g_return_if_fail (callback != NULL);
4985 text_view = GTK_TEXT_VIEW (container);
4987 copy = g_slist_copy (text_view->priv->children);
4990 while (iter != NULL)
4992 GtkTextViewChild *vc = iter->data;
4994 (* callback) (vc->widget, callback_data);
4996 iter = g_slist_next (iter);
4999 g_slist_free (copy);
5002 #define CURSOR_ON_MULTIPLIER 2
5003 #define CURSOR_OFF_MULTIPLIER 1
5004 #define CURSOR_PEND_MULTIPLIER 3
5005 #define CURSOR_DIVIDER 3
5008 cursor_blinks (GtkTextView *text_view)
5010 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5013 #ifdef DEBUG_VALIDATION_AND_SCROLLING
5016 if (gtk_get_debug_flags () & GTK_DEBUG_UPDATES)
5019 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
5024 if (text_view->priv->editable)
5026 GtkTextMark *insert;
5029 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
5030 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
5032 if (gtk_text_iter_editable (&iter, text_view->priv->editable))
5040 get_cursor_time (GtkTextView *text_view)
5042 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5045 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
5051 get_cursor_blink_timeout (GtkTextView *text_view)
5053 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5056 g_object_get (settings, "gtk-cursor-blink-timeout", &time, NULL);
5067 blink_cb (gpointer data)
5069 GtkTextView *text_view;
5070 GtkTextViewPrivate *priv;
5074 text_view = GTK_TEXT_VIEW (data);
5075 priv = text_view->priv;
5077 if (!gtk_widget_has_focus (GTK_WIDGET (text_view)))
5079 g_warning ("GtkTextView - did not receive focus-out-event. If you\n"
5080 "connect a handler to this signal, it must return\n"
5081 "FALSE so the text view gets the event as well");
5083 gtk_text_view_check_cursor_blink (text_view);
5088 g_assert (priv->layout);
5089 g_assert (priv->cursor_visible);
5091 visible = gtk_text_layout_get_cursor_visible (priv->layout);
5093 blink_timeout = get_cursor_blink_timeout (text_view);
5094 if (priv->blink_time > 1000 * blink_timeout &&
5095 blink_timeout < G_MAXINT/1000)
5097 /* we've blinked enough without the user doing anything, stop blinking */
5099 priv->blink_timeout = 0;
5102 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5107 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
5110 priv->blink_time += get_cursor_time (text_view);
5113 /* Block changed_handler while changing the layout's cursor visibility
5114 * because it would expose the whole paragraph. Instead, we expose
5115 * the cursor's area(s) manually below.
5117 g_signal_handlers_block_by_func (priv->layout,
5120 gtk_text_layout_set_cursor_visible (priv->layout, !visible);
5121 g_signal_handlers_unblock_by_func (priv->layout,
5125 text_window_invalidate_cursors (priv->text_window);
5127 /* Remove ourselves */
5133 gtk_text_view_stop_cursor_blink (GtkTextView *text_view)
5135 if (text_view->priv->blink_timeout)
5137 g_source_remove (text_view->priv->blink_timeout);
5138 text_view->priv->blink_timeout = 0;
5143 gtk_text_view_check_cursor_blink (GtkTextView *text_view)
5145 GtkTextViewPrivate *priv = text_view->priv;
5147 if (priv->layout != NULL &&
5148 priv->cursor_visible &&
5149 gtk_widget_has_focus (GTK_WIDGET (text_view)))
5151 if (cursor_blinks (text_view))
5153 if (priv->blink_timeout == 0)
5155 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5157 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5164 gtk_text_view_stop_cursor_blink (text_view);
5165 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5170 gtk_text_view_stop_cursor_blink (text_view);
5171 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
5176 gtk_text_view_pend_cursor_blink (GtkTextView *text_view)
5178 GtkTextViewPrivate *priv = text_view->priv;
5180 if (priv->layout != NULL &&
5181 priv->cursor_visible &&
5182 gtk_widget_has_focus (GTK_WIDGET (text_view)) &&
5183 cursor_blinks (text_view))
5185 gtk_text_view_stop_cursor_blink (text_view);
5186 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5188 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
5195 gtk_text_view_reset_blink_time (GtkTextView *text_view)
5197 GtkTextViewPrivate *priv = text_view->priv;
5199 priv->blink_time = 0;
5204 * Key binding handlers
5208 gtk_text_view_move_iter_by_lines (GtkTextView *text_view,
5209 GtkTextIter *newplace,
5212 gboolean ret = TRUE;
5216 ret = gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, newplace);
5222 ret = gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, newplace);
5230 move_cursor (GtkTextView *text_view,
5231 const GtkTextIter *new_location,
5232 gboolean extend_selection)
5234 if (extend_selection)
5235 gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
5239 gtk_text_buffer_place_cursor (get_buffer (text_view),
5241 gtk_text_view_check_cursor_blink (text_view);
5245 gtk_text_view_move_cursor_internal (GtkTextView *text_view,
5246 GtkMovementStep step,
5248 gboolean extend_selection)
5250 GtkTextViewPrivate *priv;
5252 GtkTextIter newplace;
5253 gboolean cancel_selection = FALSE;
5254 gint cursor_x_pos = 0;
5255 GtkDirectionType leave_direction = -1;
5257 priv = text_view->priv;
5259 if (!priv->cursor_visible)
5261 GtkScrollStep scroll_step;
5265 case GTK_MOVEMENT_VISUAL_POSITIONS:
5266 leave_direction = count > 0 ? GTK_DIR_RIGHT : GTK_DIR_LEFT;
5268 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5269 case GTK_MOVEMENT_WORDS:
5270 scroll_step = GTK_SCROLL_HORIZONTAL_STEPS;
5272 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5273 scroll_step = GTK_SCROLL_HORIZONTAL_ENDS;
5275 case GTK_MOVEMENT_DISPLAY_LINES:
5276 leave_direction = count > 0 ? GTK_DIR_DOWN : GTK_DIR_UP;
5278 case GTK_MOVEMENT_PARAGRAPHS:
5279 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5280 scroll_step = GTK_SCROLL_STEPS;
5282 case GTK_MOVEMENT_PAGES:
5283 scroll_step = GTK_SCROLL_PAGES;
5285 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5286 scroll_step = GTK_SCROLL_HORIZONTAL_PAGES;
5288 case GTK_MOVEMENT_BUFFER_ENDS:
5289 scroll_step = GTK_SCROLL_ENDS;
5292 scroll_step = GTK_SCROLL_PAGES;
5296 if (!gtk_text_view_move_viewport (text_view, scroll_step, count))
5298 if (leave_direction != -1 &&
5299 !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5302 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5309 gtk_text_view_reset_im_context (text_view);
5311 if (step == GTK_MOVEMENT_PAGES)
5313 if (!gtk_text_view_scroll_pages (text_view, count, extend_selection))
5314 gtk_widget_error_bell (GTK_WIDGET (text_view));
5316 gtk_text_view_check_cursor_blink (text_view);
5317 gtk_text_view_pend_cursor_blink (text_view);
5320 else if (step == GTK_MOVEMENT_HORIZONTAL_PAGES)
5322 if (!gtk_text_view_scroll_hpages (text_view, count, extend_selection))
5323 gtk_widget_error_bell (GTK_WIDGET (text_view));
5325 gtk_text_view_check_cursor_blink (text_view);
5326 gtk_text_view_pend_cursor_blink (text_view);
5330 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5331 gtk_text_buffer_get_insert (get_buffer (text_view)));
5333 if (! extend_selection)
5335 GtkTextIter sel_bound;
5337 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
5338 gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
5340 /* if we move forward, assume the cursor is at the end of the selection;
5341 * if we move backward, assume the cursor is at the start
5344 gtk_text_iter_order (&sel_bound, &insert);
5346 gtk_text_iter_order (&insert, &sel_bound);
5348 /* if we actually have a selection, just move *to* the beginning/end
5349 * of the selection and not *from* there on LOGICAL_POSITIONS
5350 * and VISUAL_POSITIONS movement
5352 if (! gtk_text_iter_equal (&sel_bound, &insert))
5353 cancel_selection = TRUE;
5358 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5359 gtk_text_view_get_virtual_cursor_pos (text_view, &insert, &cursor_x_pos, NULL);
5363 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5364 if (! cancel_selection)
5365 gtk_text_iter_forward_visible_cursor_positions (&newplace, count);
5368 case GTK_MOVEMENT_VISUAL_POSITIONS:
5369 if (! cancel_selection)
5370 gtk_text_layout_move_iter_visually (priv->layout,
5374 case GTK_MOVEMENT_WORDS:
5376 gtk_text_iter_backward_visible_word_starts (&newplace, -count);
5379 if (!gtk_text_iter_forward_visible_word_ends (&newplace, count))
5380 gtk_text_iter_forward_to_line_end (&newplace);
5384 case GTK_MOVEMENT_DISPLAY_LINES:
5387 leave_direction = GTK_DIR_UP;
5389 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5390 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5392 gtk_text_iter_set_line_offset (&newplace, 0);
5396 leave_direction = GTK_DIR_DOWN;
5398 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5399 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5401 gtk_text_iter_forward_to_line_end (&newplace);
5405 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5407 gtk_text_view_move_iter_by_lines (text_view, &newplace, --count);
5408 else if (count < -1)
5409 gtk_text_view_move_iter_by_lines (text_view, &newplace, ++count);
5412 gtk_text_layout_move_iter_to_line_end (priv->layout, &newplace, count);
5415 case GTK_MOVEMENT_PARAGRAPHS:
5418 if (!gtk_text_iter_ends_line (&newplace))
5420 gtk_text_iter_forward_to_line_end (&newplace);
5423 gtk_text_iter_forward_visible_lines (&newplace, count);
5424 gtk_text_iter_forward_to_line_end (&newplace);
5428 if (gtk_text_iter_get_line_offset (&newplace) > 0)
5429 gtk_text_iter_set_line_offset (&newplace, 0);
5430 gtk_text_iter_forward_visible_lines (&newplace, count);
5431 gtk_text_iter_set_line_offset (&newplace, 0);
5435 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5438 if (!gtk_text_iter_ends_line (&newplace))
5439 gtk_text_iter_forward_to_line_end (&newplace);
5443 gtk_text_iter_set_line_offset (&newplace, 0);
5447 case GTK_MOVEMENT_BUFFER_ENDS:
5449 gtk_text_buffer_get_end_iter (get_buffer (text_view), &newplace);
5451 gtk_text_buffer_get_iter_at_offset (get_buffer (text_view), &newplace, 0);
5458 /* call move_cursor() even if the cursor hasn't moved, since it
5459 cancels the selection
5461 move_cursor (text_view, &newplace, extend_selection);
5463 if (!gtk_text_iter_equal (&insert, &newplace))
5465 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5466 gtk_text_view_scroll_mark_onscreen (text_view,
5467 gtk_text_buffer_get_insert (get_buffer (text_view)));
5469 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5470 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, -1);
5472 else if (leave_direction != -1)
5474 if (!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5477 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5480 else if (! cancel_selection)
5482 gtk_widget_error_bell (GTK_WIDGET (text_view));
5485 gtk_text_view_check_cursor_blink (text_view);
5486 gtk_text_view_pend_cursor_blink (text_view);
5490 gtk_text_view_move_cursor (GtkTextView *text_view,
5491 GtkMovementStep step,
5493 gboolean extend_selection)
5495 gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
5499 gtk_text_view_move_viewport (GtkTextView *text_view,
5503 GtkAdjustment *adjustment;
5508 case GTK_SCROLL_STEPS:
5509 case GTK_SCROLL_PAGES:
5510 case GTK_SCROLL_ENDS:
5511 adjustment = get_vadjustment (text_view);
5513 case GTK_SCROLL_HORIZONTAL_STEPS:
5514 case GTK_SCROLL_HORIZONTAL_PAGES:
5515 case GTK_SCROLL_HORIZONTAL_ENDS:
5516 adjustment = get_hadjustment (text_view);
5519 adjustment = get_vadjustment (text_view);
5525 case GTK_SCROLL_STEPS:
5526 case GTK_SCROLL_HORIZONTAL_STEPS:
5527 increment = adjustment->step_increment;
5529 case GTK_SCROLL_PAGES:
5530 case GTK_SCROLL_HORIZONTAL_PAGES:
5531 increment = adjustment->page_increment;
5533 case GTK_SCROLL_ENDS:
5534 case GTK_SCROLL_HORIZONTAL_ENDS:
5535 increment = adjustment->upper - adjustment->lower;
5542 return set_adjustment_clamped (adjustment, adjustment->value + count * increment);
5546 gtk_text_view_set_anchor (GtkTextView *text_view)
5550 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5551 gtk_text_buffer_get_insert (get_buffer (text_view)));
5553 gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
5557 gtk_text_view_scroll_pages (GtkTextView *text_view,
5559 gboolean extend_selection)
5561 GtkTextViewPrivate *priv;
5563 gint cursor_x_pos, cursor_y_pos;
5564 GtkTextMark *insert_mark;
5565 GtkTextIter old_insert;
5566 GtkTextIter new_insert;
5572 priv = text_view->priv;
5574 g_return_val_if_fail (priv->vadjustment != NULL, FALSE);
5576 adj = priv->vadjustment;
5578 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5580 /* Make sure we start from the current cursor position, even
5581 * if it was offscreen, but don't queue more scrolls if we're
5584 if (priv->pending_scroll)
5585 cancel_pending_scroll (text_view);
5587 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5589 /* Validate the region that will be brought into view by the cursor motion
5591 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5592 &old_insert, insert_mark);
5596 gtk_text_view_get_first_para_iter (text_view, &anchor);
5597 y0 = adj->page_size;
5598 y1 = adj->page_size + count * adj->page_increment;
5602 gtk_text_view_get_first_para_iter (text_view, &anchor);
5603 y0 = count * adj->page_increment + adj->page_size;
5607 gtk_text_layout_validate_yrange (priv->layout, &anchor, y0, y1);
5608 /* FIXME do we need to update the adjustment ranges here? */
5610 new_insert = old_insert;
5612 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5614 /* already at top, just be sure we are at offset 0 */
5615 gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
5616 move_cursor (text_view, &new_insert, extend_selection);
5618 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5620 /* already at bottom, just be sure we are at the end */
5621 gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
5622 move_cursor (text_view, &new_insert, extend_selection);
5626 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5628 oldval = adj->value;
5629 newval = adj->value;
5631 newval += count * adj->page_increment;
5633 set_adjustment_clamped (adj, newval);
5634 cursor_y_pos += adj->value - oldval;
5636 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5637 clamp_iter_onscreen (text_view, &new_insert);
5638 move_cursor (text_view, &new_insert, extend_selection);
5640 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5643 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5644 * only guarantees 1 pixel onscreen.
5646 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5647 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5649 return !gtk_text_iter_equal (&old_insert, &new_insert);
5653 gtk_text_view_scroll_hpages (GtkTextView *text_view,
5655 gboolean extend_selection)
5657 GtkTextViewPrivate *priv;
5659 gint cursor_x_pos, cursor_y_pos;
5660 GtkTextMark *insert_mark;
5661 GtkTextIter old_insert;
5662 GtkTextIter new_insert;
5667 priv = text_view->priv;
5669 g_return_val_if_fail (priv->hadjustment != NULL, FALSE);
5671 adj = priv->hadjustment;
5673 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5675 /* Make sure we start from the current cursor position, even
5676 * if it was offscreen, but don't queue more scrolls if we're
5679 if (priv->pending_scroll)
5680 cancel_pending_scroll (text_view);
5682 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5684 /* Validate the line that we're moving within.
5686 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5687 &old_insert, insert_mark);
5689 gtk_text_layout_get_line_yrange (priv->layout, &old_insert, &y, &height);
5690 gtk_text_layout_validate_yrange (priv->layout, &old_insert, y, y + height);
5691 /* FIXME do we need to update the adjustment ranges here? */
5693 new_insert = old_insert;
5695 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5697 /* already at far left, just be sure we are at offset 0 */
5698 gtk_text_iter_set_line_offset (&new_insert, 0);
5699 move_cursor (text_view, &new_insert, extend_selection);
5701 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5703 /* already at far right, just be sure we are at the end */
5704 if (!gtk_text_iter_ends_line (&new_insert))
5705 gtk_text_iter_forward_to_line_end (&new_insert);
5706 move_cursor (text_view, &new_insert, extend_selection);
5710 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5712 oldval = adj->value;
5713 newval = adj->value;
5715 newval += count * adj->page_increment;
5717 set_adjustment_clamped (adj, newval);
5718 cursor_x_pos += adj->value - oldval;
5720 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5721 clamp_iter_onscreen (text_view, &new_insert);
5722 move_cursor (text_view, &new_insert, extend_selection);
5724 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5727 /* FIXME for lines shorter than the overall widget width, this results in a
5728 * "bounce" effect as we scroll to the right of the widget, then scroll
5729 * back to get the end of the line onscreen.
5730 * http://bugzilla.gnome.org/show_bug.cgi?id=68963
5733 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5734 * only guarantees 1 pixel onscreen.
5736 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5737 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5739 return !gtk_text_iter_equal (&old_insert, &new_insert);
5743 whitespace (gunichar ch, gpointer user_data)
5745 return (ch == ' ' || ch == '\t');
5749 not_whitespace (gunichar ch, gpointer user_data)
5751 return !whitespace (ch, user_data);
5755 find_whitepace_region (const GtkTextIter *center,
5756 GtkTextIter *start, GtkTextIter *end)
5761 if (gtk_text_iter_backward_find_char (start, not_whitespace, NULL, NULL))
5762 gtk_text_iter_forward_char (start); /* we want the first whitespace... */
5763 if (whitespace (gtk_text_iter_get_char (end), NULL))
5764 gtk_text_iter_forward_find_char (end, not_whitespace, NULL, NULL);
5766 return !gtk_text_iter_equal (start, end);
5770 gtk_text_view_insert_at_cursor (GtkTextView *text_view,
5773 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
5774 text_view->priv->editable))
5776 gtk_widget_error_bell (GTK_WIDGET (text_view));
5781 gtk_text_view_delete_from_cursor (GtkTextView *text_view,
5785 GtkTextViewPrivate *priv;
5789 gboolean leave_one = FALSE;
5791 priv = text_view->priv;
5793 gtk_text_view_reset_im_context (text_view);
5795 if (type == GTK_DELETE_CHARS)
5797 /* Char delete deletes the selection, if one exists */
5798 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5803 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5804 gtk_text_buffer_get_insert (get_buffer (text_view)));
5811 case GTK_DELETE_CHARS:
5812 gtk_text_iter_forward_cursor_positions (&end, count);
5815 case GTK_DELETE_WORD_ENDS:
5817 gtk_text_iter_forward_word_ends (&end, count);
5819 gtk_text_iter_backward_word_starts (&start, 0 - count);
5822 case GTK_DELETE_WORDS:
5825 case GTK_DELETE_DISPLAY_LINE_ENDS:
5828 case GTK_DELETE_DISPLAY_LINES:
5831 case GTK_DELETE_PARAGRAPH_ENDS:
5834 /* If we're already at a newline, we need to
5835 * simply delete that newline, instead of
5836 * moving to the next one.
5838 if (gtk_text_iter_ends_line (&end))
5840 gtk_text_iter_forward_line (&end);
5846 if (!gtk_text_iter_forward_to_line_end (&end))
5854 if (gtk_text_iter_starts_line (&start))
5856 gtk_text_iter_backward_line (&start);
5857 if (!gtk_text_iter_ends_line (&end))
5858 gtk_text_iter_forward_to_line_end (&start);
5862 gtk_text_iter_set_line_offset (&start, 0);
5866 gtk_text_iter_backward_lines (&start, -count);
5870 case GTK_DELETE_PARAGRAPHS:
5873 gtk_text_iter_set_line_offset (&start, 0);
5874 gtk_text_iter_forward_to_line_end (&end);
5876 /* Do the lines beyond the first. */
5879 gtk_text_iter_forward_to_line_end (&end);
5885 /* FIXME negative count? */
5889 case GTK_DELETE_WHITESPACE:
5891 find_whitepace_region (&insert, &start, &end);
5899 if (!gtk_text_iter_equal (&start, &end))
5901 gtk_text_buffer_begin_user_action (get_buffer (text_view));
5903 if (gtk_text_buffer_delete_interactive (get_buffer (text_view), &start, &end,
5907 gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view),
5913 gtk_widget_error_bell (GTK_WIDGET (text_view));
5916 gtk_text_buffer_end_user_action (get_buffer (text_view));
5917 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5919 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5920 gtk_text_view_scroll_mark_onscreen (text_view,
5921 gtk_text_buffer_get_insert (get_buffer (text_view)));
5925 gtk_widget_error_bell (GTK_WIDGET (text_view));
5930 gtk_text_view_backspace (GtkTextView *text_view)
5932 GtkTextViewPrivate *priv;
5935 priv = text_view->priv;
5937 gtk_text_view_reset_im_context (text_view);
5939 /* Backspace deletes the selection, if one exists */
5940 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5944 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5946 gtk_text_buffer_get_insert (get_buffer (text_view)));
5948 if (gtk_text_buffer_backspace (get_buffer (text_view), &insert,
5949 TRUE, priv->editable))
5951 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5952 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5953 gtk_text_view_scroll_mark_onscreen (text_view,
5954 gtk_text_buffer_get_insert (get_buffer (text_view)));
5958 gtk_widget_error_bell (GTK_WIDGET (text_view));
5963 gtk_text_view_cut_clipboard (GtkTextView *text_view)
5965 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5966 GDK_SELECTION_CLIPBOARD);
5968 gtk_text_buffer_cut_clipboard (get_buffer (text_view),
5970 text_view->priv->editable);
5971 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5972 gtk_text_view_scroll_mark_onscreen (text_view,
5973 gtk_text_buffer_get_insert (get_buffer (text_view)));
5977 gtk_text_view_copy_clipboard (GtkTextView *text_view)
5979 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5980 GDK_SELECTION_CLIPBOARD);
5982 gtk_text_buffer_copy_clipboard (get_buffer (text_view),
5985 /* on copy do not scroll, we are already onscreen */
5989 gtk_text_view_paste_clipboard (GtkTextView *text_view)
5991 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5992 GDK_SELECTION_CLIPBOARD);
5994 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
5997 text_view->priv->editable);
6001 gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
6002 GtkClipboard *clipboard,
6005 GtkTextView *text_view = data;
6006 GtkTextViewPrivate *priv;
6008 priv = text_view->priv;
6010 if (priv->scroll_after_paste)
6012 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6013 gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer));
6016 priv->scroll_after_paste = TRUE;
6020 gtk_text_view_toggle_overwrite (GtkTextView *text_view)
6022 GtkTextViewPrivate *priv = text_view->priv;
6024 if (priv->text_window)
6025 text_window_invalidate_cursors (priv->text_window);
6027 priv->overwrite_mode = !priv->overwrite_mode;
6030 gtk_text_layout_set_overwrite_mode (priv->layout,
6031 priv->overwrite_mode && priv->editable);
6033 if (priv->text_window)
6034 text_window_invalidate_cursors (priv->text_window);
6036 gtk_text_view_pend_cursor_blink (text_view);
6038 g_object_notify (G_OBJECT (text_view), "overwrite");
6042 * gtk_text_view_get_overwrite:
6043 * @text_view: a #GtkTextView
6045 * Returns whether the #GtkTextView is in overwrite mode or not.
6047 * Return value: whether @text_view is in overwrite mode or not.
6052 gtk_text_view_get_overwrite (GtkTextView *text_view)
6054 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6056 return text_view->priv->overwrite_mode;
6060 * gtk_text_view_set_overwrite:
6061 * @text_view: a #GtkTextView
6062 * @overwrite: %TRUE to turn on overwrite mode, %FALSE to turn it off
6064 * Changes the #GtkTextView overwrite mode.
6069 gtk_text_view_set_overwrite (GtkTextView *text_view,
6072 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6073 overwrite = overwrite != FALSE;
6075 if (text_view->priv->overwrite_mode != overwrite)
6076 gtk_text_view_toggle_overwrite (text_view);
6080 * gtk_text_view_set_accepts_tab:
6081 * @text_view: A #GtkTextView
6082 * @accepts_tab: %TRUE if pressing the Tab key should insert a tab
6083 * character, %FALSE, if pressing the Tab key should move the
6086 * Sets the behavior of the text widget when the Tab key is pressed.
6087 * If @accepts_tab is %TRUE, a tab character is inserted. If @accepts_tab
6088 * is %FALSE the keyboard focus is moved to the next widget in the focus
6094 gtk_text_view_set_accepts_tab (GtkTextView *text_view,
6095 gboolean accepts_tab)
6097 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6099 accepts_tab = accepts_tab != FALSE;
6101 if (text_view->priv->accepts_tab != accepts_tab)
6103 text_view->priv->accepts_tab = accepts_tab;
6105 g_object_notify (G_OBJECT (text_view), "accepts-tab");
6110 * gtk_text_view_get_accepts_tab:
6111 * @text_view: A #GtkTextView
6113 * Returns whether pressing the Tab key inserts a tab characters.
6114 * gtk_text_view_set_accepts_tab().
6116 * Return value: %TRUE if pressing the Tab key inserts a tab character,
6117 * %FALSE if pressing the Tab key moves the keyboard focus.
6122 gtk_text_view_get_accepts_tab (GtkTextView *text_view)
6124 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6126 return text_view->priv->accepts_tab;
6134 gtk_text_view_unselect (GtkTextView *text_view)
6138 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
6139 gtk_text_buffer_get_insert (get_buffer (text_view)));
6141 gtk_text_buffer_move_mark (get_buffer (text_view),
6142 gtk_text_buffer_get_selection_bound (get_buffer (text_view)),
6147 get_iter_at_pointer (GtkTextView *text_view,
6153 GtkTextViewPrivate *priv;
6154 gint xcoord, ycoord;
6155 GdkModifierType state;
6157 priv = text_view->priv;
6159 gdk_window_get_device_position (priv->text_window->bin_window,
6160 device, &xcoord, &ycoord, &state);
6162 gtk_text_layout_get_iter_at_pixel (priv->layout,
6164 xcoord + priv->xoffset,
6165 ycoord + priv->yoffset);
6174 move_mark_to_pointer_and_scroll (GtkTextView *text_view,
6175 const gchar *mark_name,
6178 GtkTextIter newplace;
6181 get_iter_at_pointer (text_view, device, &newplace, NULL, NULL);
6183 mark = gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
6185 /* This may invalidate the layout */
6186 DV(g_print (G_STRLOC": move mark\n"));
6188 gtk_text_buffer_move_mark (get_buffer (text_view),
6192 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6193 gtk_text_view_scroll_mark_onscreen (text_view, mark);
6195 DV (g_print ("first validate idle leaving %s is %d\n",
6196 G_STRLOC, text_view->priv->first_validate_idle));
6200 selection_scan_timeout (gpointer data)
6202 GtkTextView *text_view;
6204 text_view = GTK_TEXT_VIEW (data);
6206 gtk_text_view_scroll_mark_onscreen (text_view,
6207 gtk_text_buffer_get_insert (get_buffer (text_view)));
6209 return TRUE; /* remain installed. */
6212 #define UPPER_OFFSET_ANCHOR 0.8
6213 #define LOWER_OFFSET_ANCHOR 0.2
6216 check_scroll (gdouble offset, GtkAdjustment *adj)
6218 if ((offset > UPPER_OFFSET_ANCHOR &&
6219 adj->value + adj->page_size < adj->upper) ||
6220 (offset < LOWER_OFFSET_ANCHOR &&
6221 adj->value > adj->lower))
6228 drag_scan_timeout (gpointer data)
6230 GtkTextView *text_view;
6231 GtkTextViewPrivate *priv;
6232 GtkTextIter newplace;
6234 gdouble pointer_xoffset, pointer_yoffset;
6236 text_view = GTK_TEXT_VIEW (data);
6237 priv = text_view->priv;
6239 get_iter_at_pointer (text_view, priv->dnd_device, &newplace, &x, &y);
6241 gtk_text_buffer_move_mark (get_buffer (text_view),
6245 pointer_xoffset = (gdouble) x / gdk_window_get_width (priv->text_window->bin_window);
6246 pointer_yoffset = (gdouble) y / gdk_window_get_height (priv->text_window->bin_window);
6248 if (check_scroll (pointer_xoffset, priv->hadjustment) ||
6249 check_scroll (pointer_yoffset, priv->vadjustment))
6251 /* do not make offsets surpass lower nor upper anchors, this makes
6252 * scrolling speed relative to the distance of the pointer to the
6253 * anchors when it moves beyond them.
6255 pointer_xoffset = CLAMP (pointer_xoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6256 pointer_yoffset = CLAMP (pointer_yoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6258 gtk_text_view_scroll_to_mark (text_view,
6260 0., TRUE, pointer_xoffset, pointer_yoffset);
6271 } SelectionGranularity;
6274 * Move @start and @end to the boundaries of the selection unit (indicated by
6275 * @granularity) which contained @start initially.
6276 * If the selction unit is SELECT_WORDS and @start is not contained in a word
6277 * the selection is extended to all the white spaces between the end of the
6278 * word preceding @start and the start of the one following.
6281 extend_selection (GtkTextView *text_view,
6282 SelectionGranularity granularity,
6288 if (granularity == SELECT_WORDS)
6290 if (gtk_text_iter_inside_word (start))
6292 if (!gtk_text_iter_starts_word (start))
6293 gtk_text_iter_backward_visible_word_start (start);
6295 if (!gtk_text_iter_ends_word (end))
6297 if (!gtk_text_iter_forward_visible_word_end (end))
6298 gtk_text_iter_forward_to_end (end);
6306 if (gtk_text_iter_backward_visible_word_start (&tmp))
6307 gtk_text_iter_forward_visible_word_end (&tmp);
6309 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (start))
6312 gtk_text_iter_set_line_offset (start, 0);
6315 if (!gtk_text_iter_forward_visible_word_end (&tmp))
6316 gtk_text_iter_forward_to_end (&tmp);
6318 if (gtk_text_iter_ends_word (&tmp))
6319 gtk_text_iter_backward_visible_word_start (&tmp);
6321 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (end))
6324 gtk_text_iter_forward_to_line_end (end);
6327 else if (granularity == SELECT_LINES)
6329 if (gtk_text_view_starts_display_line (text_view, start))
6331 /* If on a display line boundary, we assume the user
6332 * clicked off the end of a line and we therefore select
6333 * the line before the boundary.
6335 gtk_text_view_backward_display_line_start (text_view, start);
6339 /* start isn't on the start of a line, so we move it to the
6340 * start, and move end to the end unless it's already there.
6342 gtk_text_view_backward_display_line_start (text_view, start);
6344 if (!gtk_text_view_starts_display_line (text_view, end))
6345 gtk_text_view_forward_display_line_end (text_view, end);
6353 SelectionGranularity granularity;
6354 GtkTextMark *orig_start;
6355 GtkTextMark *orig_end;
6359 selection_data_free (SelectionData *data)
6361 if (data->orig_start != NULL)
6362 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start),
6364 if (data->orig_end != NULL)
6365 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end),
6371 selection_motion_event_handler (GtkTextView *text_view,
6372 GdkEventMotion *event,
6373 SelectionData *data)
6375 GtkTextViewPrivate *priv;
6377 priv = text_view->priv;
6378 gdk_event_request_motions (event);
6380 if (priv->grab_device != event->device)
6383 if (data->granularity == SELECT_CHARACTERS)
6385 move_mark_to_pointer_and_scroll (text_view, "insert", event->device);
6389 GtkTextIter cursor, start, end;
6390 GtkTextIter orig_start, orig_end;
6391 GtkTextBuffer *buffer;
6393 buffer = get_buffer (text_view);
6395 gtk_text_buffer_get_iter_at_mark (buffer, &orig_start, data->orig_start);
6396 gtk_text_buffer_get_iter_at_mark (buffer, &orig_end, data->orig_end);
6398 get_iter_at_pointer (text_view, event->device, &cursor, NULL, NULL);
6401 extend_selection (text_view, data->granularity, &start, &end);
6403 /* either the selection extends to the front, or end (or not) */
6404 if (gtk_text_iter_compare (&cursor, &orig_start) < 0)
6405 gtk_text_buffer_select_range (buffer, &start, &orig_end);
6407 gtk_text_buffer_select_range (buffer, &end, &orig_start);
6409 gtk_text_view_scroll_mark_onscreen (text_view,
6410 gtk_text_buffer_get_insert (buffer));
6413 /* If we had to scroll offscreen, insert a timeout to do so
6414 * again. Note that in the timeout, even if the mouse doesn't
6415 * move, due to this scroll xoffset/yoffset will have changed
6416 * and we'll need to scroll again.
6418 if (text_view->priv->scroll_timeout != 0) /* reset on every motion event */
6419 g_source_remove (text_view->priv->scroll_timeout);
6421 text_view->priv->scroll_timeout =
6422 gdk_threads_add_timeout (50, selection_scan_timeout, text_view);
6428 gtk_text_view_start_selection_drag (GtkTextView *text_view,
6429 const GtkTextIter *iter,
6430 GdkEventButton *button)
6432 GtkTextViewPrivate *priv;
6433 GtkTextIter cursor, ins, bound;
6434 GtkTextIter orig_start, orig_end;
6435 GtkTextBuffer *buffer;
6436 SelectionData *data;
6438 if (text_view->priv->selection_drag_handler != 0)
6441 priv = text_view->priv;
6442 data = g_new0 (SelectionData, 1);
6444 if (button->type == GDK_2BUTTON_PRESS)
6445 data->granularity = SELECT_WORDS;
6446 else if (button->type == GDK_3BUTTON_PRESS)
6447 data->granularity = SELECT_LINES;
6449 data->granularity = SELECT_CHARACTERS;
6451 priv->grab_device = button->device;
6452 gtk_device_grab_add (GTK_WIDGET (text_view),
6456 buffer = get_buffer (text_view);
6461 extend_selection (text_view, data->granularity, &ins, &bound);
6465 if (button->state & GDK_SHIFT_MASK)
6467 /* Extend selection */
6468 GtkTextIter old_ins, old_bound;
6469 GtkTextIter old_start, old_end;
6471 gtk_text_buffer_get_iter_at_mark (buffer, &old_ins, gtk_text_buffer_get_insert (buffer));
6472 gtk_text_buffer_get_iter_at_mark (buffer, &old_bound, gtk_text_buffer_get_selection_bound (buffer));
6473 old_start = old_ins;
6474 old_end = old_bound;
6475 gtk_text_iter_order (&old_start, &old_end);
6477 /* move the front cursor, if the mouse is in front of the selection. Should the
6478 * cursor however be inside the selection (this happens on tripple click) then we
6479 * move the side which was last moved (current insert mark) */
6480 if (gtk_text_iter_compare (&cursor, &old_start) <= 0 ||
6481 (gtk_text_iter_compare (&cursor, &old_end) < 0 &&
6482 gtk_text_iter_compare (&old_ins, &old_bound) <= 0))
6485 orig_start = old_end;
6497 gtk_text_buffer_select_range (buffer, &ins, &bound);
6499 gtk_text_iter_order (&orig_start, &orig_end);
6500 data->orig_start = gtk_text_buffer_create_mark (buffer, NULL,
6502 data->orig_end = gtk_text_buffer_create_mark (buffer, NULL,
6504 gtk_text_view_check_cursor_blink (text_view);
6506 text_view->priv->selection_drag_handler = g_signal_connect_data (text_view,
6507 "motion-notify-event",
6508 G_CALLBACK (selection_motion_event_handler),
6510 (GClosureNotify) selection_data_free, 0);
6513 /* returns whether we were really dragging */
6515 gtk_text_view_end_selection_drag (GtkTextView *text_view)
6517 GtkTextViewPrivate *priv;
6519 priv = text_view->priv;
6521 if (!priv->grab_device)
6524 if (priv->selection_drag_handler == 0)
6527 g_signal_handler_disconnect (text_view, priv->selection_drag_handler);
6528 priv->selection_drag_handler = 0;
6530 if (priv->scroll_timeout != 0)
6532 g_source_remove (priv->scroll_timeout);
6533 priv->scroll_timeout = 0;
6536 gtk_device_grab_remove (GTK_WIDGET (text_view),
6538 priv->grab_device = NULL;
6548 gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
6549 GtkTextAttributes *values,
6552 values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
6553 values->appearance.fg_color = style->text[GTK_STATE_NORMAL];
6556 pango_font_description_free (values->font);
6558 values->font = pango_font_description_copy (style->font_desc);
6562 gtk_text_view_check_keymap_direction (GtkTextView *text_view)
6564 GtkTextViewPrivate *priv = text_view->priv;
6568 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
6569 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)));
6570 GtkTextDirection new_cursor_dir;
6571 GtkTextDirection new_keyboard_dir;
6572 gboolean split_cursor;
6574 g_object_get (settings,
6575 "gtk-split-cursor", &split_cursor,
6578 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
6579 new_keyboard_dir = GTK_TEXT_DIR_RTL;
6581 new_keyboard_dir = GTK_TEXT_DIR_LTR;
6584 new_cursor_dir = GTK_TEXT_DIR_NONE;
6586 new_cursor_dir = new_keyboard_dir;
6588 gtk_text_layout_set_cursor_direction (priv->layout, new_cursor_dir);
6589 gtk_text_layout_set_keyboard_direction (priv->layout, new_keyboard_dir);
6594 gtk_text_view_ensure_layout (GtkTextView *text_view)
6597 GtkTextViewPrivate *priv;
6599 widget = GTK_WIDGET (text_view);
6600 priv = text_view->priv;
6602 if (priv->layout == NULL)
6604 GtkTextAttributes *style;
6605 PangoContext *ltr_context, *rtl_context;
6608 DV(g_print(G_STRLOC"\n"));
6610 priv->layout = gtk_text_layout_new ();
6612 g_signal_connect (priv->layout,
6614 G_CALLBACK (invalidated_handler),
6617 g_signal_connect (priv->layout,
6619 G_CALLBACK (changed_handler),
6622 g_signal_connect (priv->layout,
6624 G_CALLBACK (gtk_text_view_child_allocated),
6627 if (get_buffer (text_view))
6628 gtk_text_layout_set_buffer (priv->layout, get_buffer (text_view));
6630 if ((gtk_widget_has_focus (widget) && priv->cursor_visible))
6631 gtk_text_view_pend_cursor_blink (text_view);
6633 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
6635 gtk_text_layout_set_overwrite_mode (priv->layout,
6636 priv->overwrite_mode && priv->editable);
6638 ltr_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6639 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
6640 rtl_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6641 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
6643 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
6645 g_object_unref (ltr_context);
6646 g_object_unref (rtl_context);
6648 gtk_text_view_check_keymap_direction (text_view);
6650 style = gtk_text_attributes_new ();
6652 gtk_widget_ensure_style (widget);
6653 gtk_text_view_set_attributes_from_style (text_view,
6655 gtk_widget_get_style (widget));
6657 style->pixels_above_lines = priv->pixels_above_lines;
6658 style->pixels_below_lines = priv->pixels_below_lines;
6659 style->pixels_inside_wrap = priv->pixels_inside_wrap;
6660 style->left_margin = priv->left_margin;
6661 style->right_margin = priv->right_margin;
6662 style->indent = priv->indent;
6663 style->tabs = priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
6665 style->wrap_mode = priv->wrap_mode;
6666 style->justification = priv->justify;
6667 style->direction = gtk_widget_get_direction (GTK_WIDGET (text_view));
6669 gtk_text_layout_set_default_style (priv->layout, style);
6671 gtk_text_attributes_unref (style);
6673 /* Set layout for all anchored children */
6675 tmp_list = priv->children;
6676 while (tmp_list != NULL)
6678 GtkTextViewChild *vc = tmp_list->data;
6682 gtk_text_anchored_child_set_layout (vc->widget,
6684 /* vc may now be invalid! */
6687 tmp_list = g_slist_next (tmp_list);
6690 gtk_text_view_invalidate (text_view);
6695 * gtk_text_view_get_default_attributes:
6696 * @text_view: a #GtkTextView
6698 * Obtains a copy of the default text attributes. These are the
6699 * attributes used for text unless a tag overrides them.
6700 * You'd typically pass the default attributes in to
6701 * gtk_text_iter_get_attributes() in order to get the
6702 * attributes in effect at a given text position.
6704 * The return value is a copy owned by the caller of this function,
6705 * and should be freed.
6707 * Return value: a new #GtkTextAttributes
6710 gtk_text_view_get_default_attributes (GtkTextView *text_view)
6712 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
6714 gtk_text_view_ensure_layout (text_view);
6716 return gtk_text_attributes_copy (text_view->priv->layout->default_style);
6720 gtk_text_view_destroy_layout (GtkTextView *text_view)
6722 GtkTextViewPrivate *priv = text_view->priv;
6728 gtk_text_view_remove_validate_idles (text_view);
6730 g_signal_handlers_disconnect_by_func (priv->layout,
6731 invalidated_handler,
6733 g_signal_handlers_disconnect_by_func (priv->layout,
6737 /* Remove layout from all anchored children */
6738 tmp_list = priv->children;
6739 while (tmp_list != NULL)
6741 GtkTextViewChild *vc = tmp_list->data;
6745 gtk_text_anchored_child_set_layout (vc->widget, NULL);
6746 /* vc may now be invalid! */
6749 tmp_list = g_slist_next (tmp_list);
6752 gtk_text_view_stop_cursor_blink (text_view);
6753 gtk_text_view_end_selection_drag (text_view);
6755 g_object_unref (priv->layout);
6756 priv->layout = NULL;
6761 * gtk_text_view_reset_im_context:
6762 * @text_view: a #GtkTextView
6764 * Reset the input method context of the text view if needed.
6766 * This can be necessary in the case where modifying the buffer
6767 * would confuse on-going input method behavior.
6772 gtk_text_view_reset_im_context (GtkTextView *text_view)
6774 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6776 if (text_view->priv->need_im_reset)
6778 text_view->priv->need_im_reset = FALSE;
6779 gtk_im_context_reset (text_view->priv->im_context);
6784 * gtk_text_view_im_context_filter_keypress:
6785 * @text_view: a #GtkTextView
6786 * @event: the key event
6788 * Allow the #GtkTextView input method to internally handle key press
6789 * and release events. If this function returns %TRUE, then no further
6790 * processing should be done for this key event. See
6791 * gtk_im_context_filter_keypress().
6793 * Note that you are expected to call this function from your handler
6794 * when overriding key event handling. This is needed in the case when
6795 * you need to insert your own key handling between the input method
6796 * and the default key event handling of the #GtkTextView.
6800 * gtk_foo_bar_key_press_event (GtkWidget *widget,
6801 * GdkEventKey *event)
6803 * if ((key->keyval == GDK_Return || key->keyval == GDK_KP_Enter))
6805 * if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
6809 * /* Do some stuff */
6811 * return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event);
6815 * Return value: %TRUE if the input method handled the key event.
6820 gtk_text_view_im_context_filter_keypress (GtkTextView *text_view,
6823 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6825 return gtk_im_context_filter_keypress (text_view->priv->im_context, event);
6833 drag_begin_cb (GtkWidget *widget,
6834 GdkDragContext *context,
6837 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6838 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6841 cairo_surface_t *surface = NULL;
6843 g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
6845 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6846 surface = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
6850 gtk_drag_set_icon_surface (context, surface);
6851 cairo_surface_destroy (surface);
6855 gtk_drag_set_icon_default (context);
6860 gtk_text_view_start_selection_dnd (GtkTextView *text_view,
6861 const GtkTextIter *iter,
6862 GdkEventMotion *event)
6864 GtkTargetList *target_list;
6866 text_view->priv->drag_start_x = -1;
6867 text_view->priv->drag_start_y = -1;
6868 text_view->priv->pending_place_cursor_button = 0;
6870 target_list = gtk_text_buffer_get_copy_target_list (get_buffer (text_view));
6872 g_signal_connect (text_view, "drag-begin",
6873 G_CALLBACK (drag_begin_cb), NULL);
6874 gtk_drag_begin (GTK_WIDGET (text_view), target_list,
6875 GDK_ACTION_COPY | GDK_ACTION_MOVE,
6876 1, (GdkEvent*)event);
6880 gtk_text_view_drag_begin (GtkWidget *widget,
6881 GdkDragContext *context)
6887 gtk_text_view_drag_end (GtkWidget *widget,
6888 GdkDragContext *context)
6893 gtk_text_view_drag_data_get (GtkWidget *widget,
6894 GdkDragContext *context,
6895 GtkSelectionData *selection_data,
6899 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6900 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6902 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
6904 gtk_selection_data_set (selection_data,
6905 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
6910 else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
6917 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6919 /* Extract the selected text */
6920 str = gtk_text_buffer_serialize (buffer, buffer,
6921 selection_data->target,
6928 gtk_selection_data_set (selection_data,
6929 selection_data->target,
6931 (guchar *) str, len);
6941 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6943 /* Extract the selected text */
6944 str = gtk_text_iter_get_visible_text (&start, &end);
6949 gtk_selection_data_set_text (selection_data, str, -1);
6956 gtk_text_view_drag_data_delete (GtkWidget *widget,
6957 GdkDragContext *context)
6959 gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->priv->buffer,
6960 TRUE, GTK_TEXT_VIEW (widget)->priv->editable);
6964 gtk_text_view_drag_leave (GtkWidget *widget,
6965 GdkDragContext *context,
6968 GtkTextView *text_view;
6969 GtkTextViewPrivate *priv;
6971 text_view = GTK_TEXT_VIEW (widget);
6972 priv = text_view->priv;
6974 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
6976 if (priv->dnd_device)
6977 priv->dnd_device = NULL;
6979 if (priv->scroll_timeout != 0)
6980 g_source_remove (priv->scroll_timeout);
6982 priv->scroll_timeout = 0;
6986 gtk_text_view_drag_motion (GtkWidget *widget,
6987 GdkDragContext *context,
6992 GtkTextIter newplace;
6993 GtkTextView *text_view;
6994 GtkTextViewPrivate *priv;
6997 GdkRectangle target_rect;
7000 GdkDragAction suggested_action = 0;
7002 text_view = GTK_TEXT_VIEW (widget);
7003 priv = text_view->priv;
7005 target_rect = priv->text_window->allocation;
7007 if (x < target_rect.x ||
7008 y < target_rect.y ||
7009 x > (target_rect.x + target_rect.width) ||
7010 y > (target_rect.y + target_rect.height))
7011 return FALSE; /* outside the text window, allow parent widgets to handle event */
7013 gtk_text_view_window_to_buffer_coords (text_view,
7014 GTK_TEXT_WINDOW_WIDGET,
7018 gtk_text_layout_get_iter_at_pixel (priv->layout,
7022 target = gtk_drag_dest_find_target (widget, context,
7023 gtk_drag_dest_get_target_list (widget));
7025 if (target == GDK_NONE)
7027 /* can't accept any of the offered targets */
7029 else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7031 gtk_text_iter_compare (&newplace, &start) >= 0 &&
7032 gtk_text_iter_compare (&newplace, &end) <= 0)
7034 /* We're inside the selection. */
7038 if (gtk_text_iter_can_insert (&newplace, priv->editable))
7040 GtkWidget *source_widget;
7042 suggested_action = context->suggested_action;
7044 source_widget = gtk_drag_get_source_widget (context);
7046 if (source_widget == widget)
7048 /* Default to MOVE, unless the user has
7049 * pressed ctrl or alt to affect available actions
7051 if ((context->actions & GDK_ACTION_MOVE) != 0)
7052 suggested_action = GDK_ACTION_MOVE;
7057 /* Can't drop here. */
7061 if (suggested_action != 0)
7063 gtk_text_mark_set_visible (priv->dnd_mark,
7064 priv->cursor_visible);
7066 gdk_drag_status (context, suggested_action, time);
7070 gdk_drag_status (context, 0, time);
7071 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7074 priv->dnd_device = gdk_drag_context_get_device (context);
7076 if (!priv->scroll_timeout)
7077 priv->scroll_timeout =
7078 gdk_threads_add_timeout (100, drag_scan_timeout, text_view);
7080 /* TRUE return means don't propagate the drag motion to parent
7081 * widgets that may also be drop sites.
7087 gtk_text_view_drag_drop (GtkWidget *widget,
7088 GdkDragContext *context,
7093 GtkTextView *text_view;
7094 GtkTextViewPrivate *priv;
7095 GtkTextIter drop_point;
7096 GdkAtom target = GDK_NONE;
7098 text_view = GTK_TEXT_VIEW (widget);
7099 priv = text_view->priv;
7101 if (priv->scroll_timeout != 0)
7102 g_source_remove (priv->scroll_timeout);
7104 priv->scroll_timeout = 0;
7106 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7108 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7112 if (gtk_text_iter_can_insert (&drop_point, priv->editable))
7113 target = gtk_drag_dest_find_target (widget, context, NULL);
7115 if (target != GDK_NONE)
7116 gtk_drag_get_data (widget, context, target, time);
7118 gtk_drag_finish (context, FALSE, FALSE, time);
7124 insert_text_data (GtkTextView *text_view,
7125 GtkTextIter *drop_point,
7126 GtkSelectionData *selection_data)
7130 str = gtk_selection_data_get_text (selection_data);
7134 if (!gtk_text_buffer_insert_interactive (get_buffer (text_view),
7135 drop_point, (gchar *) str, -1,
7136 text_view->priv->editable))
7138 gtk_widget_error_bell (GTK_WIDGET (text_view));
7146 gtk_text_view_drag_data_received (GtkWidget *widget,
7147 GdkDragContext *context,
7150 GtkSelectionData *selection_data,
7154 GtkTextIter drop_point;
7155 GtkTextView *text_view;
7156 GtkTextViewPrivate *priv;
7157 gboolean success = FALSE;
7158 GtkTextBuffer *buffer = NULL;
7160 text_view = GTK_TEXT_VIEW (widget);
7161 priv = text_view->priv;
7163 if (!priv->dnd_mark)
7166 buffer = get_buffer (text_view);
7168 gtk_text_buffer_get_iter_at_mark (buffer,
7172 if (!gtk_text_iter_can_insert (&drop_point, priv->editable))
7177 gtk_text_buffer_begin_user_action (buffer);
7179 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7181 GtkTextBuffer *src_buffer = NULL;
7182 GtkTextIter start, end;
7183 gboolean copy_tags = TRUE;
7185 if (selection_data->length != sizeof (src_buffer))
7188 memcpy (&src_buffer, selection_data->data, sizeof (src_buffer));
7190 if (src_buffer == NULL)
7193 g_return_if_fail (GTK_IS_TEXT_BUFFER (src_buffer));
7195 if (gtk_text_buffer_get_tag_table (src_buffer) !=
7196 gtk_text_buffer_get_tag_table (buffer))
7198 /* try to find a suitable rich text target instead */
7202 GdkAtom target = GDK_NONE;
7206 atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms);
7208 for (list = context->targets; list; list = g_list_next (list))
7212 for (i = 0; i < n_atoms; i++)
7213 if (GUINT_TO_POINTER (atoms[i]) == list->data)
7222 if (target != GDK_NONE)
7224 gtk_drag_get_data (widget, context, target, time);
7225 gtk_text_buffer_end_user_action (buffer);
7230 if (gtk_text_buffer_get_selection_bounds (src_buffer,
7235 gtk_text_buffer_insert_range_interactive (buffer,
7244 str = gtk_text_iter_get_visible_text (&start, &end);
7245 gtk_text_buffer_insert_interactive (buffer,
7246 &drop_point, str, -1,
7252 else if (selection_data->length > 0 &&
7253 info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
7256 GError *error = NULL;
7258 retval = gtk_text_buffer_deserialize (buffer, buffer,
7259 selection_data->target,
7261 (guint8 *) selection_data->data,
7262 selection_data->length,
7267 g_warning ("error pasting: %s\n", error->message);
7268 g_clear_error (&error);
7272 insert_text_data (text_view, &drop_point, selection_data);
7275 gtk_drag_finish (context, success,
7276 success && context->action == GDK_ACTION_MOVE,
7281 gtk_text_buffer_get_iter_at_mark (buffer,
7284 gtk_text_buffer_place_cursor (buffer, &drop_point);
7286 gtk_text_buffer_end_user_action (buffer);
7291 * gtk_text_view_get_hadjustment:
7292 * @text_view: a #GtkTextView
7294 * Gets the horizontal-scrolling #GtkAdjustment.
7296 * Returns: (transfer none): pointer to the horizontal #GtkAdjustment
7301 gtk_text_view_get_hadjustment (GtkTextView *text_view)
7303 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7305 return get_hadjustment (text_view);
7309 * gtk_text_view_get_vadjustment:
7310 * @text_view: a #GtkTextView
7312 * Gets the vertical-scrolling #GtkAdjustment.
7314 * Returns: (transfer none): pointer to the vertical #GtkAdjustment
7319 gtk_text_view_get_vadjustment (GtkTextView *text_view)
7321 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7323 return get_vadjustment (text_view);
7326 static GtkAdjustment*
7327 get_hadjustment (GtkTextView *text_view)
7329 if (text_view->priv->hadjustment == NULL)
7330 gtk_text_view_set_scroll_adjustments (text_view,
7331 NULL, /* forces creation */
7332 text_view->priv->vadjustment);
7334 return text_view->priv->hadjustment;
7337 static GtkAdjustment*
7338 get_vadjustment (GtkTextView *text_view)
7340 if (text_view->priv->vadjustment == NULL)
7341 gtk_text_view_set_scroll_adjustments (text_view,
7342 text_view->priv->hadjustment,
7343 NULL); /* forces creation */
7344 return text_view->priv->vadjustment;
7349 gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
7350 GtkAdjustment *hadj,
7351 GtkAdjustment *vadj)
7353 GtkTextViewPrivate *priv = text_view->priv;
7354 gboolean need_adjust = FALSE;
7357 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7359 hadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
7361 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7363 vadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
7365 if (priv->hadjustment && (priv->hadjustment != hadj))
7367 g_signal_handlers_disconnect_by_func (priv->hadjustment,
7368 gtk_text_view_value_changed,
7370 g_object_unref (priv->hadjustment);
7373 if (priv->vadjustment && (priv->vadjustment != vadj))
7375 g_signal_handlers_disconnect_by_func (priv->vadjustment,
7376 gtk_text_view_value_changed,
7378 g_object_unref (priv->vadjustment);
7381 if (priv->hadjustment != hadj)
7383 priv->hadjustment = hadj;
7384 g_object_ref_sink (priv->hadjustment);
7386 g_signal_connect (priv->hadjustment, "value-changed",
7387 G_CALLBACK (gtk_text_view_value_changed),
7392 if (priv->vadjustment != vadj)
7394 priv->vadjustment = vadj;
7395 g_object_ref_sink (priv->vadjustment);
7397 g_signal_connect (priv->vadjustment, "value-changed",
7398 G_CALLBACK (gtk_text_view_value_changed),
7404 gtk_text_view_value_changed (NULL, text_view);
7407 /* FIXME this adjust_allocation is a big cut-and-paste from
7408 * GtkCList, needs to be some "official" way to do this
7418 /* The window to which widget->window is relative */
7419 #define ALLOCATION_WINDOW(widget) \
7420 (!gtk_widget_get_has_window (widget) ? \
7421 gtk_widget_get_window (widget) : \
7422 gdk_window_get_parent (gtk_widget_get_window (widget)))
7425 adjust_allocation_recurse (GtkWidget *widget,
7428 GtkAllocation allocation;
7429 ScrollData *scroll_data = data;
7431 /* Need to really size allocate instead of just poking
7432 * into widget->allocation if the widget is not realized.
7433 * FIXME someone figure out why this was.
7435 if (!gtk_widget_get_realized (widget))
7437 if (gtk_widget_get_visible (widget))
7439 GdkRectangle tmp_rectangle;
7441 tmp_rectangle = allocation;
7442 tmp_rectangle.x += scroll_data->dx;
7443 tmp_rectangle.y += scroll_data->dy;
7445 gtk_widget_size_allocate (widget, &tmp_rectangle);
7450 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
7452 allocation.x += scroll_data->dx;
7453 allocation.y += scroll_data->dy;
7454 gtk_widget_set_allocation (widget, &allocation);
7456 if (GTK_IS_CONTAINER (widget))
7457 gtk_container_forall (GTK_CONTAINER (widget),
7458 adjust_allocation_recurse,
7465 adjust_allocation (GtkWidget *widget,
7469 ScrollData scroll_data;
7471 if (gtk_widget_get_realized (widget))
7472 scroll_data.window = ALLOCATION_WINDOW (widget);
7474 scroll_data.window = NULL;
7476 scroll_data.dx = dx;
7477 scroll_data.dy = dy;
7479 adjust_allocation_recurse (widget, &scroll_data);
7483 gtk_text_view_value_changed (GtkAdjustment *adj,
7484 GtkTextView *text_view)
7486 GtkTextViewPrivate *priv;
7492 priv = text_view->priv;
7494 /* Note that we oddly call this function with adj == NULL
7498 priv->onscreen_validated = FALSE;
7500 DV(g_print(">Scroll offset changed %s/%g, onscreen_validated = FALSE ("G_STRLOC")\n",
7501 adj == priv->hadjustment ? "hadj" : adj == priv->vadjustment ? "vadj" : "none",
7502 adj ? adj->value : 0.0));
7504 if (adj == priv->hadjustment)
7506 dx = priv->xoffset - (gint)adj->value;
7507 priv->xoffset = adj->value;
7509 /* If the change is due to a size change we need
7510 * to invalidate the entire text window because there might be
7511 * right-aligned or centered text
7513 if (priv->width_changed)
7515 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7516 gdk_window_invalidate_rect (priv->text_window->bin_window, NULL, FALSE);
7518 priv->width_changed = FALSE;
7521 else if (adj == priv->vadjustment)
7523 dy = priv->yoffset - (gint)adj->value;
7524 priv->yoffset = adj->value;
7528 gtk_text_layout_get_line_at_y (priv->layout, &iter, adj->value, &line_top);
7530 gtk_text_buffer_move_mark (get_buffer (text_view), priv->first_para_mark, &iter);
7532 priv->first_para_pixels = adj->value - line_top;
7536 if (dx != 0 || dy != 0)
7540 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7544 if (priv->left_window)
7545 text_window_scroll (priv->left_window, 0, dy);
7546 if (priv->right_window)
7547 text_window_scroll (priv->right_window, 0, dy);
7552 if (priv->top_window)
7553 text_window_scroll (priv->top_window, dx, 0);
7554 if (priv->bottom_window)
7555 text_window_scroll (priv->bottom_window, dx, 0);
7558 /* It looks nicer to scroll the main area last, because
7559 * it takes a while, and making the side areas update
7560 * afterward emphasizes the slowness of scrolling the
7563 text_window_scroll (priv->text_window, dx, dy);
7566 /* Children are now "moved" in the text window, poke
7567 * into widget->allocation for each child
7569 tmp_list = priv->children;
7570 while (tmp_list != NULL)
7572 GtkTextViewChild *child = tmp_list->data;
7575 adjust_allocation (child->widget, dx, dy);
7577 tmp_list = g_slist_next (tmp_list);
7581 /* This could result in invalidation, which would install the
7582 * first_validate_idle, which would validate onscreen;
7583 * but we're going to go ahead and validate here, so
7584 * first_validate_idle shouldn't have anything to do.
7586 gtk_text_view_update_layout_width (text_view);
7588 /* We also update the IM spot location here, since the IM context
7589 * might do something that leads to validation.
7591 gtk_text_view_update_im_spot_location (text_view);
7593 /* note that validation of onscreen could invoke this function
7594 * recursively, by scrolling to maintain first_para, or in response
7595 * to updating the layout width, however there is no problem with
7596 * that, or shouldn't be.
7598 gtk_text_view_validate_onscreen (text_view);
7600 /* process exposes */
7601 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7603 DV (g_print ("Processing updates (%s)\n", G_STRLOC));
7605 if (priv->left_window)
7606 gdk_window_process_updates (priv->left_window->bin_window, TRUE);
7608 if (priv->right_window)
7609 gdk_window_process_updates (priv->right_window->bin_window, TRUE);
7611 if (priv->top_window)
7612 gdk_window_process_updates (priv->top_window->bin_window, TRUE);
7614 if (priv->bottom_window)
7615 gdk_window_process_updates (priv->bottom_window->bin_window, TRUE);
7617 gdk_window_process_updates (priv->text_window->bin_window, TRUE);
7620 /* If this got installed, get rid of it, it's just a waste of time. */
7621 if (priv->first_validate_idle != 0)
7623 g_source_remove (priv->first_validate_idle);
7624 priv->first_validate_idle = 0;
7627 /* Finally we update the IM cursor location again, to ensure any
7628 * changes made by the validation are pushed through.
7630 gtk_text_view_update_im_spot_location (text_view);
7632 DV(g_print(">End scroll offset changed handler ("G_STRLOC")\n"));
7636 gtk_text_view_commit_handler (GtkIMContext *context,
7638 GtkTextView *text_view)
7640 gtk_text_view_commit_text (text_view, str);
7644 gtk_text_view_commit_text (GtkTextView *text_view,
7647 GtkTextViewPrivate *priv;
7648 gboolean had_selection;
7650 priv = text_view->priv;
7652 gtk_text_buffer_begin_user_action (get_buffer (text_view));
7654 had_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7657 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
7660 if (!strcmp (str, "\n"))
7662 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
7665 gtk_widget_error_bell (GTK_WIDGET (text_view));
7670 if (!had_selection && priv->overwrite_mode)
7674 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7676 gtk_text_buffer_get_insert (get_buffer (text_view)));
7677 if (!gtk_text_iter_ends_line (&insert))
7678 gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
7681 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
7684 gtk_widget_error_bell (GTK_WIDGET (text_view));
7688 gtk_text_buffer_end_user_action (get_buffer (text_view));
7690 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
7691 DV(g_print (G_STRLOC": scrolling onscreen\n"));
7692 gtk_text_view_scroll_mark_onscreen (text_view,
7693 gtk_text_buffer_get_insert (get_buffer (text_view)));
7697 gtk_text_view_preedit_changed_handler (GtkIMContext *context,
7698 GtkTextView *text_view)
7700 GtkTextViewPrivate *priv;
7702 PangoAttrList *attrs;
7706 priv = text_view->priv;
7708 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
7709 gtk_text_buffer_get_insert (priv->buffer));
7711 /* Keypress events are passed to input method even if cursor position is
7712 * not editable; so beep here if it's multi-key input sequence, input
7713 * method will be reset in key-press-event handler.
7715 gtk_im_context_get_preedit_string (context, &str, &attrs, &cursor_pos);
7717 if (str && str[0] && !gtk_text_iter_can_insert (&iter, priv->editable))
7719 gtk_widget_error_bell (GTK_WIDGET (text_view));
7723 g_signal_emit (text_view, signals[PREEDIT_CHANGED], 0, str);
7726 gtk_text_layout_set_preedit_string (priv->layout, str, attrs, cursor_pos);
7727 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
7728 gtk_text_view_scroll_mark_onscreen (text_view,
7729 gtk_text_buffer_get_insert (get_buffer (text_view)));
7732 pango_attr_list_unref (attrs);
7737 gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
7738 GtkTextView *text_view)
7745 gtk_text_buffer_get_iter_at_mark (text_view->priv->buffer, &start,
7746 gtk_text_buffer_get_insert (text_view->priv->buffer));
7749 pos = gtk_text_iter_get_line_index (&start);
7750 gtk_text_iter_set_line_offset (&start, 0);
7751 gtk_text_iter_forward_to_line_end (&end);
7753 text = gtk_text_iter_get_slice (&start, &end);
7754 gtk_im_context_set_surrounding (context, text, -1, pos);
7761 gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
7764 GtkTextView *text_view)
7766 GtkTextViewPrivate *priv;
7770 priv = text_view->priv;
7772 gtk_text_buffer_get_iter_at_mark (priv->buffer, &start,
7773 gtk_text_buffer_get_insert (priv->buffer));
7776 gtk_text_iter_forward_chars (&start, offset);
7777 gtk_text_iter_forward_chars (&end, offset + n_chars);
7779 gtk_text_buffer_delete_interactive (priv->buffer, &start, &end,
7786 gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
7787 const GtkTextIter *location,
7791 GtkTextView *text_view = GTK_TEXT_VIEW (data);
7792 gboolean need_reset = FALSE;
7794 if (mark == gtk_text_buffer_get_insert (buffer))
7796 text_view->priv->virtual_cursor_x = -1;
7797 text_view->priv->virtual_cursor_y = -1;
7798 gtk_text_view_update_im_spot_location (text_view);
7801 else if (mark == gtk_text_buffer_get_selection_bound (buffer))
7807 gtk_text_view_reset_im_context (text_view);
7811 gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
7812 const GParamSpec *pspec,
7815 GtkWidget *widget = GTK_WIDGET (data);
7816 GtkTargetList *view_list;
7817 GtkTargetList *buffer_list;
7820 view_list = gtk_drag_dest_get_target_list (widget);
7821 buffer_list = gtk_text_buffer_get_paste_target_list (buffer);
7824 gtk_target_list_ref (view_list);
7826 view_list = gtk_target_list_new (NULL, 0);
7828 list = view_list->list;
7831 GtkTargetPair *pair = list->data;
7833 list = g_list_next (list); /* get next element before removing */
7835 if (pair->info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT &&
7836 pair->info <= GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7838 gtk_target_list_remove (view_list, pair->target);
7842 for (list = buffer_list->list; list; list = g_list_next (list))
7844 GtkTargetPair *pair = list->data;
7846 gtk_target_list_add (view_list, pair->target, pair->flags, pair->info);
7849 gtk_drag_dest_set_target_list (widget, view_list);
7850 gtk_target_list_unref (view_list);
7854 gtk_text_view_get_cursor_location (GtkTextView *text_view,
7859 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7860 gtk_text_buffer_get_insert (get_buffer (text_view)));
7862 gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert, pos, NULL);
7866 gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
7867 GtkTextIter *cursor,
7871 GtkTextViewPrivate *priv;
7875 priv = text_view->priv;
7880 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7881 gtk_text_buffer_get_insert (get_buffer (text_view)));
7883 if ((x && priv->virtual_cursor_x == -1) ||
7884 (y && priv->virtual_cursor_y == -1))
7885 gtk_text_layout_get_cursor_locations (priv->layout, &insert, &pos, NULL);
7889 if (priv->virtual_cursor_x != -1)
7890 *x = priv->virtual_cursor_x;
7897 if (priv->virtual_cursor_x != -1)
7898 *y = priv->virtual_cursor_y;
7900 *y = pos.y + pos.height / 2;
7905 gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
7911 if (!text_view->priv->layout)
7914 if (x == -1 || y == -1)
7915 gtk_text_view_get_cursor_location (text_view, &pos);
7917 text_view->priv->virtual_cursor_x = (x == -1) ? pos.x : x;
7918 text_view->priv->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
7921 /* Quick hack of a popup menu
7924 activate_cb (GtkWidget *menuitem,
7925 GtkTextView *text_view)
7927 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
7928 g_signal_emit_by_name (text_view, signal);
7932 append_action_signal (GtkTextView *text_view,
7934 const gchar *stock_id,
7935 const gchar *signal,
7938 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
7940 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
7941 g_signal_connect (menuitem, "activate",
7942 G_CALLBACK (activate_cb), text_view);
7944 gtk_widget_set_sensitive (menuitem, sensitive);
7946 gtk_widget_show (menuitem);
7947 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
7951 gtk_text_view_select_all (GtkWidget *widget,
7954 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
7955 GtkTextBuffer *buffer;
7956 GtkTextIter start_iter, end_iter, insert;
7958 buffer = text_view->priv->buffer;
7961 gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
7962 gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
7966 gtk_text_buffer_get_iter_at_mark (buffer, &insert,
7967 gtk_text_buffer_get_insert (buffer));
7968 gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &insert);
7973 select_all_cb (GtkWidget *menuitem,
7974 GtkTextView *text_view)
7976 gtk_text_view_select_all (GTK_WIDGET (text_view), TRUE);
7980 delete_cb (GtkTextView *text_view)
7982 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
7983 text_view->priv->editable);
7987 popup_menu_detach (GtkWidget *attach_widget,
7990 GTK_TEXT_VIEW (attach_widget)->priv->popup_menu = NULL;
7994 popup_position_func (GtkMenu *menu,
8000 GtkAllocation allocation;
8001 GtkTextView *text_view;
8003 GdkRectangle cursor_rect;
8004 GdkRectangle onscreen_rect;
8005 gint root_x, root_y;
8010 GdkRectangle monitor;
8012 text_view = GTK_TEXT_VIEW (user_data);
8013 widget = GTK_WIDGET (text_view);
8015 g_return_if_fail (gtk_widget_get_realized (widget));
8017 screen = gtk_widget_get_screen (widget);
8019 gdk_window_get_origin (gtk_widget_get_window (widget),
8022 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8024 gtk_text_buffer_get_insert (get_buffer (text_view)));
8026 gtk_text_view_get_iter_location (text_view,
8030 gtk_text_view_get_visible_rect (text_view, &onscreen_rect);
8032 gtk_widget_get_preferred_size (text_view->priv->popup_menu,
8035 gtk_widget_get_allocation (widget, &allocation);
8037 /* can't use rectangle_intersect since cursor rect can have 0 width */
8038 if (cursor_rect.x >= onscreen_rect.x &&
8039 cursor_rect.x < onscreen_rect.x + onscreen_rect.width &&
8040 cursor_rect.y >= onscreen_rect.y &&
8041 cursor_rect.y < onscreen_rect.y + onscreen_rect.height)
8043 gtk_text_view_buffer_to_window_coords (text_view,
8044 GTK_TEXT_WINDOW_WIDGET,
8045 cursor_rect.x, cursor_rect.y,
8046 &cursor_rect.x, &cursor_rect.y);
8048 *x = root_x + cursor_rect.x + cursor_rect.width;
8049 *y = root_y + cursor_rect.y + cursor_rect.height;
8053 /* Just center the menu, since cursor is offscreen. */
8054 *x = root_x + (allocation.width / 2 - req.width / 2);
8055 *y = root_y + (allocation.height / 2 - req.height / 2);
8059 *x = CLAMP (*x, root_x, (root_x + allocation.width));
8060 *y = CLAMP (*y, root_y, (root_y + allocation.height));
8062 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
8063 gtk_menu_set_monitor (menu, monitor_num);
8064 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8066 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
8067 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
8074 GtkTextView *text_view;
8080 range_contains_editable_text (const GtkTextIter *start,
8081 const GtkTextIter *end,
8082 gboolean default_editability)
8084 GtkTextIter iter = *start;
8086 while (gtk_text_iter_compare (&iter, end) < 0)
8088 if (gtk_text_iter_editable (&iter, default_editability))
8091 gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
8098 unichar_chosen_func (const char *text,
8101 GtkTextView *text_view = GTK_TEXT_VIEW (data);
8103 gtk_text_view_commit_text (text_view, text);
8107 popup_targets_received (GtkClipboard *clipboard,
8108 GtkSelectionData *data,
8111 PopupInfo *info = user_data;
8112 GtkTextView *text_view;
8113 GtkTextViewPrivate *priv;
8115 text_view = info->text_view;
8116 priv = text_view->priv;
8118 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
8120 /* We implicitely rely here on the fact that if we are pasting ourself, we'll
8121 * have text targets as well as the private GTK_TEXT_BUFFER_CONTENTS target.
8123 gboolean clipboard_contains_text;
8124 GtkWidget *menuitem;
8126 gboolean have_selection;
8127 gboolean can_insert;
8129 GtkTextIter sel_start, sel_end;
8130 gboolean show_input_method_menu;
8131 gboolean show_unicode_menu;
8133 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8135 if (priv->popup_menu)
8136 gtk_widget_destroy (priv->popup_menu);
8138 priv->popup_menu = gtk_menu_new ();
8140 gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
8141 GTK_WIDGET (text_view),
8144 have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
8145 &sel_start, &sel_end);
8147 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8149 gtk_text_buffer_get_insert (get_buffer (text_view)));
8151 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
8153 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8155 range_contains_editable_text (&sel_start, &sel_end,
8157 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8159 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8160 can_insert && clipboard_contains_text);
8162 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8163 gtk_widget_set_sensitive (menuitem,
8165 range_contains_editable_text (&sel_start, &sel_end,
8167 g_signal_connect_swapped (menuitem, "activate",
8168 G_CALLBACK (delete_cb), text_view);
8169 gtk_widget_show (menuitem);
8170 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8172 menuitem = gtk_separator_menu_item_new ();
8173 gtk_widget_show (menuitem);
8174 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8176 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8177 g_signal_connect (menuitem, "activate",
8178 G_CALLBACK (select_all_cb), text_view);
8179 gtk_widget_show (menuitem);
8180 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8182 g_object_get (gtk_widget_get_settings (GTK_WIDGET (text_view)),
8183 "gtk-show-input-method-menu", &show_input_method_menu,
8184 "gtk-show-unicode-menu", &show_unicode_menu,
8187 if (show_input_method_menu || show_unicode_menu)
8189 menuitem = gtk_separator_menu_item_new ();
8190 gtk_widget_show (menuitem);
8191 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8194 if (show_input_method_menu)
8196 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8197 gtk_widget_show (menuitem);
8198 gtk_widget_set_sensitive (menuitem, can_insert);
8200 submenu = gtk_menu_new ();
8201 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8202 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8204 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (priv->im_context),
8205 GTK_MENU_SHELL (submenu));
8208 if (show_unicode_menu)
8210 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8211 gtk_widget_show (menuitem);
8212 gtk_widget_set_sensitive (menuitem, can_insert);
8214 submenu = gtk_menu_new ();
8215 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8216 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8218 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8219 unichar_chosen_func,
8223 g_signal_emit (text_view,
8224 signals[POPULATE_POPUP],
8229 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8231 info->button, info->time);
8234 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8235 popup_position_func, text_view,
8236 0, gtk_get_current_event_time ());
8237 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->popup_menu), FALSE);
8241 g_object_unref (text_view);
8246 gtk_text_view_do_popup (GtkTextView *text_view,
8247 GdkEventButton *event)
8249 PopupInfo *info = g_new (PopupInfo, 1);
8251 /* In order to know what entries we should make sensitive, we
8252 * ask for the current targets of the clipboard, and when
8253 * we get them, then we actually pop up the menu.
8255 info->text_view = g_object_ref (text_view);
8259 info->button = event->button;
8260 info->time = event->time;
8265 info->time = gtk_get_current_event_time ();
8268 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
8269 GDK_SELECTION_CLIPBOARD),
8270 gdk_atom_intern_static_string ("TARGETS"),
8271 popup_targets_received,
8276 gtk_text_view_popup_menu (GtkWidget *widget)
8278 gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
8282 /* Child GdkWindows */
8285 static GtkTextWindow*
8286 text_window_new (GtkTextWindowType type,
8289 gint height_request)
8293 win = g_new (GtkTextWindow, 1);
8296 win->widget = widget;
8298 win->bin_window = NULL;
8299 win->requisition.width = width_request;
8300 win->requisition.height = height_request;
8301 win->allocation.width = width_request;
8302 win->allocation.height = height_request;
8303 win->allocation.x = 0;
8304 win->allocation.y = 0;
8310 text_window_free (GtkTextWindow *win)
8313 text_window_unrealize (win);
8319 text_window_realize (GtkTextWindow *win,
8323 GdkWindowAttr attributes;
8324 gint attributes_mask;
8327 attributes.window_type = GDK_WINDOW_CHILD;
8328 attributes.x = win->allocation.x;
8329 attributes.y = win->allocation.y;
8330 attributes.width = win->allocation.width;
8331 attributes.height = win->allocation.height;
8332 attributes.wclass = GDK_INPUT_OUTPUT;
8333 attributes.visual = gtk_widget_get_visual (win->widget);
8334 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
8336 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
8338 window = gtk_widget_get_window (widget);
8340 win->window = gdk_window_new (window,
8341 &attributes, attributes_mask);
8343 gdk_window_show (win->window);
8344 gdk_window_set_user_data (win->window, win->widget);
8345 gdk_window_lower (win->window);
8349 attributes.width = win->allocation.width;
8350 attributes.height = win->allocation.height;
8351 attributes.event_mask = (GDK_EXPOSURE_MASK |
8353 GDK_KEY_PRESS_MASK |
8354 GDK_BUTTON_PRESS_MASK |
8355 GDK_BUTTON_RELEASE_MASK |
8356 GDK_POINTER_MOTION_MASK |
8357 GDK_POINTER_MOTION_HINT_MASK |
8358 gtk_widget_get_events (win->widget));
8360 win->bin_window = gdk_window_new (win->window,
8364 gdk_window_show (win->bin_window);
8365 gdk_window_set_user_data (win->bin_window, win->widget);
8367 if (win->type == GTK_TEXT_WINDOW_TEXT)
8369 if (gtk_widget_is_sensitive (widget))
8372 cursor = gdk_cursor_new_for_display (gdk_window_get_display (window),
8374 gdk_window_set_cursor (win->bin_window, cursor);
8375 gdk_cursor_unref (cursor);
8378 gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->priv->im_context,
8382 gdk_window_set_background (win->bin_window,
8383 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
8387 gdk_window_set_background (win->bin_window,
8388 >k_widget_get_style (widget)->bg[gtk_widget_get_state (widget)]);
8391 g_object_set_qdata (G_OBJECT (win->window),
8392 g_quark_from_static_string ("gtk-text-view-text-window"),
8395 g_object_set_qdata (G_OBJECT (win->bin_window),
8396 g_quark_from_static_string ("gtk-text-view-text-window"),
8401 text_window_unrealize (GtkTextWindow *win)
8403 if (win->type == GTK_TEXT_WINDOW_TEXT)
8405 gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->priv->im_context,
8409 gdk_window_set_user_data (win->window, NULL);
8410 gdk_window_set_user_data (win->bin_window, NULL);
8411 gdk_window_destroy (win->bin_window);
8412 gdk_window_destroy (win->window);
8414 win->bin_window = NULL;
8418 text_window_size_allocate (GtkTextWindow *win,
8421 win->allocation = *rect;
8425 gdk_window_move_resize (win->window,
8427 rect->width, rect->height);
8429 gdk_window_resize (win->bin_window,
8430 rect->width, rect->height);
8435 text_window_scroll (GtkTextWindow *win,
8439 if (dx != 0 || dy != 0)
8441 gdk_window_scroll (win->bin_window, dx, dy);
8446 text_window_invalidate_rect (GtkTextWindow *win,
8449 GdkRectangle window_rect;
8451 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (win->widget),
8458 window_rect.width = rect->width;
8459 window_rect.height = rect->height;
8461 /* Adjust the rect as appropriate */
8465 case GTK_TEXT_WINDOW_TEXT:
8468 case GTK_TEXT_WINDOW_LEFT:
8469 case GTK_TEXT_WINDOW_RIGHT:
8471 window_rect.width = win->allocation.width;
8474 case GTK_TEXT_WINDOW_TOP:
8475 case GTK_TEXT_WINDOW_BOTTOM:
8477 window_rect.height = win->allocation.height;
8481 g_warning ("%s: bug!", G_STRFUNC);
8486 gdk_window_invalidate_rect (win->bin_window, &window_rect, FALSE);
8490 cairo_t *cr = gdk_cairo_create (win->bin_window);
8491 gdk_cairo_rectangle (cr, &window_rect);
8492 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
8500 text_window_invalidate_cursors (GtkTextWindow *win)
8502 GtkTextView *text_view;
8503 GtkTextViewPrivate *priv;
8505 GdkRectangle strong;
8507 gboolean draw_arrow;
8508 gfloat cursor_aspect_ratio;
8512 text_view = GTK_TEXT_VIEW (win->widget);
8513 priv = text_view->priv;
8515 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
8516 gtk_text_buffer_get_insert (priv->buffer));
8518 if (_gtk_text_layout_get_block_cursor (priv->layout, &strong))
8520 text_window_invalidate_rect (win, &strong);
8524 gtk_text_layout_get_cursor_locations (priv->layout, &iter,
8527 /* cursor width calculation as in gtkstyle.c:draw_insertion_cursor(),
8528 * ignoring the text direction be exposing both sides of the cursor
8531 draw_arrow = (strong.x != weak.x || strong.y != weak.y);
8533 gtk_widget_style_get (win->widget,
8534 "cursor-aspect-ratio", &cursor_aspect_ratio,
8537 stem_width = strong.height * cursor_aspect_ratio + 1;
8538 arrow_width = stem_width + 1;
8540 strong.width = stem_width;
8542 /* round up to the next even number */
8546 strong.x -= stem_width / 2;
8547 strong.width += stem_width;
8551 strong.x -= arrow_width;
8552 strong.width += arrow_width * 2;
8555 text_window_invalidate_rect (win, &strong);
8557 if (draw_arrow) /* == have weak */
8559 stem_width = weak.height * cursor_aspect_ratio + 1;
8560 arrow_width = stem_width + 1;
8562 weak.width = stem_width;
8564 /* round up to the next even number */
8568 weak.x -= stem_width / 2;
8569 weak.width += stem_width;
8571 weak.x -= arrow_width;
8572 weak.width += arrow_width * 2;
8574 text_window_invalidate_rect (win, &weak);
8579 text_window_get_width (GtkTextWindow *win)
8581 return win->allocation.width;
8585 text_window_get_height (GtkTextWindow *win)
8587 return win->allocation.height;
8594 * gtk_text_view_get_window:
8595 * @text_view: a #GtkTextView
8596 * @win: window to get
8598 * Retrieves the #GdkWindow corresponding to an area of the text view;
8599 * possible windows include the overall widget window, child windows
8600 * on the left, right, top, bottom, and the window that displays the
8601 * text buffer. Windows are %NULL and nonexistent if their width or
8602 * height is 0, and are nonexistent before the widget has been
8605 * Return value: (transfer none): a #GdkWindow, or %NULL
8608 gtk_text_view_get_window (GtkTextView *text_view,
8609 GtkTextWindowType win)
8611 GtkTextViewPrivate *priv = text_view->priv;
8613 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
8617 case GTK_TEXT_WINDOW_WIDGET:
8618 return gtk_widget_get_window (GTK_WIDGET (text_view));
8621 case GTK_TEXT_WINDOW_TEXT:
8622 return priv->text_window->bin_window;
8625 case GTK_TEXT_WINDOW_LEFT:
8626 if (priv->left_window)
8627 return priv->left_window->bin_window;
8632 case GTK_TEXT_WINDOW_RIGHT:
8633 if (priv->right_window)
8634 return priv->right_window->bin_window;
8639 case GTK_TEXT_WINDOW_TOP:
8640 if (priv->top_window)
8641 return priv->top_window->bin_window;
8646 case GTK_TEXT_WINDOW_BOTTOM:
8647 if (priv->bottom_window)
8648 return priv->bottom_window->bin_window;
8653 case GTK_TEXT_WINDOW_PRIVATE:
8654 g_warning ("%s: You can't get GTK_TEXT_WINDOW_PRIVATE, it has \"PRIVATE\" in the name because it is private.", G_STRFUNC);
8659 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8664 * gtk_text_view_get_window_type:
8665 * @text_view: a #GtkTextView
8666 * @window: a window type
8668 * Usually used to find out which window an event corresponds to.
8669 * If you connect to an event signal on @text_view, this function
8670 * should be called on <literal>event->window</literal> to
8671 * see which window it was.
8673 * Return value: the window type.
8676 gtk_text_view_get_window_type (GtkTextView *text_view,
8681 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
8682 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8684 if (window == gtk_widget_get_window (GTK_WIDGET (text_view)))
8685 return GTK_TEXT_WINDOW_WIDGET;
8687 win = g_object_get_qdata (G_OBJECT (window),
8688 g_quark_try_string ("gtk-text-view-text-window"));
8694 return GTK_TEXT_WINDOW_PRIVATE;
8699 buffer_to_widget (GtkTextView *text_view,
8705 GtkTextViewPrivate *priv = text_view->priv;
8709 *window_x = buffer_x - priv->xoffset;
8710 *window_x += priv->text_window->allocation.x;
8715 *window_y = buffer_y - priv->yoffset;
8716 *window_y += priv->text_window->allocation.y;
8721 widget_to_text_window (GtkTextWindow *win,
8728 *window_x = widget_x - win->allocation.x;
8731 *window_y = widget_y - win->allocation.y;
8735 buffer_to_text_window (GtkTextView *text_view,
8744 g_warning ("Attempt to convert text buffer coordinates to coordinates "
8745 "for a nonexistent or private child window of GtkTextView");
8749 buffer_to_widget (text_view,
8751 window_x, window_y);
8753 widget_to_text_window (win,
8754 window_x ? *window_x : 0,
8755 window_y ? *window_y : 0,
8761 * gtk_text_view_buffer_to_window_coords:
8762 * @text_view: a #GtkTextView
8763 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8764 * @buffer_x: buffer x coordinate
8765 * @buffer_y: buffer y coordinate
8766 * @window_x: (out) (allow-none): window x coordinate return location or %NULL
8767 * @window_y: (out) (allow-none): window y coordinate return location or %NULL
8769 * Converts coordinate (@buffer_x, @buffer_y) to coordinates for the window
8770 * @win, and stores the result in (@window_x, @window_y).
8772 * Note that you can't convert coordinates for a nonexisting window (see
8773 * gtk_text_view_set_border_window_size()).
8776 gtk_text_view_buffer_to_window_coords (GtkTextView *text_view,
8777 GtkTextWindowType win,
8783 GtkTextViewPrivate *priv = text_view->priv;
8785 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
8789 case GTK_TEXT_WINDOW_WIDGET:
8790 buffer_to_widget (text_view,
8792 window_x, window_y);
8795 case GTK_TEXT_WINDOW_TEXT:
8797 *window_x = buffer_x - priv->xoffset;
8799 *window_y = buffer_y - priv->yoffset;
8802 case GTK_TEXT_WINDOW_LEFT:
8803 buffer_to_text_window (text_view,
8806 window_x, window_y);
8809 case GTK_TEXT_WINDOW_RIGHT:
8810 buffer_to_text_window (text_view,
8813 window_x, window_y);
8816 case GTK_TEXT_WINDOW_TOP:
8817 buffer_to_text_window (text_view,
8820 window_x, window_y);
8823 case GTK_TEXT_WINDOW_BOTTOM:
8824 buffer_to_text_window (text_view,
8825 priv->bottom_window,
8827 window_x, window_y);
8830 case GTK_TEXT_WINDOW_PRIVATE:
8831 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
8835 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8841 widget_to_buffer (GtkTextView *text_view,
8847 GtkTextViewPrivate *priv = text_view->priv;
8851 *buffer_x = widget_x + priv->xoffset;
8852 *buffer_x -= priv->text_window->allocation.x;
8857 *buffer_y = widget_y + priv->yoffset;
8858 *buffer_y -= priv->text_window->allocation.y;
8863 text_window_to_widget (GtkTextWindow *win,
8870 *widget_x = window_x + win->allocation.x;
8873 *widget_y = window_y + win->allocation.y;
8877 text_window_to_buffer (GtkTextView *text_view,
8886 g_warning ("Attempt to convert GtkTextView buffer coordinates into "
8887 "coordinates for a nonexistent child window.");
8891 text_window_to_widget (win,
8897 widget_to_buffer (text_view,
8898 buffer_x ? *buffer_x : 0,
8899 buffer_y ? *buffer_y : 0,
8905 * gtk_text_view_window_to_buffer_coords:
8906 * @text_view: a #GtkTextView
8907 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8908 * @window_x: window x coordinate
8909 * @window_y: window y coordinate
8910 * @buffer_x: (out) (allow-none): buffer x coordinate return location or %NULL
8911 * @buffer_y: (out) (allow-none): buffer y coordinate return location or %NULL
8913 * Converts coordinates on the window identified by @win to buffer
8914 * coordinates, storing the result in (@buffer_x,@buffer_y).
8916 * Note that you can't convert coordinates for a nonexisting window (see
8917 * gtk_text_view_set_border_window_size()).
8920 gtk_text_view_window_to_buffer_coords (GtkTextView *text_view,
8921 GtkTextWindowType win,
8927 GtkTextViewPrivate *priv = text_view->priv;
8929 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
8933 case GTK_TEXT_WINDOW_WIDGET:
8934 widget_to_buffer (text_view,
8936 buffer_x, buffer_y);
8939 case GTK_TEXT_WINDOW_TEXT:
8941 *buffer_x = window_x + priv->xoffset;
8943 *buffer_y = window_y + priv->yoffset;
8946 case GTK_TEXT_WINDOW_LEFT:
8947 text_window_to_buffer (text_view,
8950 buffer_x, buffer_y);
8953 case GTK_TEXT_WINDOW_RIGHT:
8954 text_window_to_buffer (text_view,
8957 buffer_x, buffer_y);
8960 case GTK_TEXT_WINDOW_TOP:
8961 text_window_to_buffer (text_view,
8964 buffer_x, buffer_y);
8967 case GTK_TEXT_WINDOW_BOTTOM:
8968 text_window_to_buffer (text_view,
8969 priv->bottom_window,
8971 buffer_x, buffer_y);
8974 case GTK_TEXT_WINDOW_PRIVATE:
8975 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
8979 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8985 set_window_width (GtkTextView *text_view,
8987 GtkTextWindowType type,
8988 GtkTextWindow **winp)
8994 text_window_free (*winp);
8996 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9003 *winp = text_window_new (type,
9004 GTK_WIDGET (text_view),
9006 /* if the widget is already realized we need to realize the child manually */
9007 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9008 text_window_realize (*winp, GTK_WIDGET (text_view));
9012 if ((*winp)->requisition.width == width)
9015 (*winp)->requisition.width = width;
9018 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9024 set_window_height (GtkTextView *text_view,
9026 GtkTextWindowType type,
9027 GtkTextWindow **winp)
9033 text_window_free (*winp);
9035 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9042 *winp = text_window_new (type,
9043 GTK_WIDGET (text_view),
9046 /* if the widget is already realized we need to realize the child manually */
9047 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9048 text_window_realize (*winp, GTK_WIDGET (text_view));
9052 if ((*winp)->requisition.height == height)
9055 (*winp)->requisition.height = height;
9058 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9063 * gtk_text_view_set_border_window_size:
9064 * @text_view: a #GtkTextView
9065 * @type: window to affect
9066 * @size: width or height of the window
9068 * Sets the width of %GTK_TEXT_WINDOW_LEFT or %GTK_TEXT_WINDOW_RIGHT,
9069 * or the height of %GTK_TEXT_WINDOW_TOP or %GTK_TEXT_WINDOW_BOTTOM.
9070 * Automatically destroys the corresponding window if the size is set
9071 * to 0, and creates the window if the size is set to non-zero. This
9072 * function can only be used for the "border windows," it doesn't work
9073 * with #GTK_TEXT_WINDOW_WIDGET, #GTK_TEXT_WINDOW_TEXT, or
9074 * #GTK_TEXT_WINDOW_PRIVATE.
9077 gtk_text_view_set_border_window_size (GtkTextView *text_view,
9078 GtkTextWindowType type,
9081 GtkTextViewPrivate *priv = text_view->priv;
9083 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9084 g_return_if_fail (size >= 0);
9088 case GTK_TEXT_WINDOW_LEFT:
9089 set_window_width (text_view, size, GTK_TEXT_WINDOW_LEFT,
9090 &priv->left_window);
9093 case GTK_TEXT_WINDOW_RIGHT:
9094 set_window_width (text_view, size, GTK_TEXT_WINDOW_RIGHT,
9095 &priv->right_window);
9098 case GTK_TEXT_WINDOW_TOP:
9099 set_window_height (text_view, size, GTK_TEXT_WINDOW_TOP,
9103 case GTK_TEXT_WINDOW_BOTTOM:
9104 set_window_height (text_view, size, GTK_TEXT_WINDOW_BOTTOM,
9105 &priv->bottom_window);
9109 g_warning ("Can only set size of left/right/top/bottom border windows with gtk_text_view_set_border_window_size()");
9115 * gtk_text_view_get_border_window_size:
9116 * @text_view: a #GtkTextView
9117 * @type: window to return size from
9119 * Gets the width of the specified border window. See
9120 * gtk_text_view_set_border_window_size().
9122 * Return value: width of window
9125 gtk_text_view_get_border_window_size (GtkTextView *text_view,
9126 GtkTextWindowType type)
9128 GtkTextViewPrivate *priv = text_view->priv;
9130 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
9134 case GTK_TEXT_WINDOW_LEFT:
9135 if (priv->left_window)
9136 return priv->left_window->requisition.width;
9139 case GTK_TEXT_WINDOW_RIGHT:
9140 if (priv->right_window)
9141 return priv->right_window->requisition.width;
9144 case GTK_TEXT_WINDOW_TOP:
9145 if (priv->top_window)
9146 return priv->top_window->requisition.height;
9149 case GTK_TEXT_WINDOW_BOTTOM:
9150 if (priv->bottom_window)
9151 return priv->bottom_window->requisition.height;
9155 g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size()");
9166 static GtkTextViewChild*
9167 text_view_child_new_anchored (GtkWidget *child,
9168 GtkTextChildAnchor *anchor,
9169 GtkTextLayout *layout)
9171 GtkTextViewChild *vc;
9173 vc = g_new (GtkTextViewChild, 1);
9175 vc->type = GTK_TEXT_WINDOW_PRIVATE;
9177 vc->anchor = anchor;
9179 vc->from_top_of_line = 0;
9180 vc->from_left_of_buffer = 0;
9182 g_object_ref (vc->widget);
9183 g_object_ref (vc->anchor);
9185 g_object_set_data (G_OBJECT (child),
9186 I_("gtk-text-view-child"),
9189 gtk_text_child_anchor_register_child (anchor, child, layout);
9194 static GtkTextViewChild*
9195 text_view_child_new_window (GtkWidget *child,
9196 GtkTextWindowType type,
9200 GtkTextViewChild *vc;
9202 vc = g_new (GtkTextViewChild, 1);
9207 vc->from_top_of_line = 0;
9208 vc->from_left_of_buffer = 0;
9210 g_object_ref (vc->widget);
9216 g_object_set_data (G_OBJECT (child),
9217 I_("gtk-text-view-child"),
9224 text_view_child_free (GtkTextViewChild *child)
9226 g_object_set_data (G_OBJECT (child->widget),
9227 I_("gtk-text-view-child"), NULL);
9231 gtk_text_child_anchor_unregister_child (child->anchor,
9233 g_object_unref (child->anchor);
9236 g_object_unref (child->widget);
9242 text_view_child_set_parent_window (GtkTextView *text_view,
9243 GtkTextViewChild *vc)
9246 gtk_widget_set_parent_window (vc->widget,
9247 text_view->priv->text_window->bin_window);
9251 window = gtk_text_view_get_window (text_view,
9253 gtk_widget_set_parent_window (vc->widget, window);
9258 add_child (GtkTextView *text_view,
9259 GtkTextViewChild *vc)
9261 text_view->priv->children = g_slist_prepend (text_view->priv->children,
9264 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9265 text_view_child_set_parent_window (text_view, vc);
9267 gtk_widget_set_parent (vc->widget, GTK_WIDGET (text_view));
9271 * gtk_text_view_add_child_at_anchor:
9272 * @text_view: a #GtkTextView
9273 * @child: a #GtkWidget
9274 * @anchor: a #GtkTextChildAnchor in the #GtkTextBuffer for @text_view
9276 * Adds a child widget in the text buffer, at the given @anchor.
9279 gtk_text_view_add_child_at_anchor (GtkTextView *text_view,
9281 GtkTextChildAnchor *anchor)
9283 GtkTextViewChild *vc;
9285 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9286 g_return_if_fail (GTK_IS_WIDGET (child));
9287 g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
9288 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
9290 gtk_text_view_ensure_layout (text_view);
9292 vc = text_view_child_new_anchored (child, anchor,
9293 text_view->priv->layout);
9295 add_child (text_view, vc);
9297 g_assert (vc->widget == child);
9298 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9302 * gtk_text_view_add_child_in_window:
9303 * @text_view: a #GtkTextView
9304 * @child: a #GtkWidget
9305 * @which_window: which window the child should appear in
9306 * @xpos: X position of child in window coordinates
9307 * @ypos: Y position of child in window coordinates
9309 * Adds a child at fixed coordinates in one of the text widget's
9310 * windows. The window must have nonzero size (see
9311 * gtk_text_view_set_border_window_size()). Note that the child
9312 * coordinates are given relative to the #GdkWindow in question, and
9313 * that these coordinates have no sane relationship to scrolling. When
9314 * placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
9315 * irrelevant, the child floats above all scrollable areas. But when
9316 * placing a child in one of the scrollable windows (border windows or
9317 * text window), you'll need to compute the child's correct position
9318 * in buffer coordinates any time scrolling occurs or buffer changes
9319 * occur, and then call gtk_text_view_move_child() to update the
9320 * child's position. Unfortunately there's no good way to detect that
9321 * scrolling has occurred, using the current API; a possible hack
9322 * would be to update all child positions when the scroll adjustments
9323 * change or the text buffer changes. See bug 64518 on
9324 * bugzilla.gnome.org for status of fixing this issue.
9327 gtk_text_view_add_child_in_window (GtkTextView *text_view,
9329 GtkTextWindowType which_window,
9333 GtkTextViewChild *vc;
9335 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9336 g_return_if_fail (GTK_IS_WIDGET (child));
9337 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
9339 vc = text_view_child_new_window (child, which_window,
9342 add_child (text_view, vc);
9344 g_assert (vc->widget == child);
9345 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9349 * gtk_text_view_move_child:
9350 * @text_view: a #GtkTextView
9351 * @child: child widget already added to the text view
9352 * @xpos: new X position in window coordinates
9353 * @ypos: new Y position in window coordinates
9355 * Updates the position of a child, as for gtk_text_view_add_child_in_window().
9358 gtk_text_view_move_child (GtkTextView *text_view,
9363 GtkTextViewChild *vc;
9365 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9366 g_return_if_fail (GTK_IS_WIDGET (child));
9367 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9369 vc = g_object_get_data (G_OBJECT (child),
9370 "gtk-text-view-child");
9372 g_assert (vc != NULL);
9374 if (vc->x == xpos &&
9381 if (gtk_widget_get_visible (child) &&
9382 gtk_widget_get_visible (GTK_WIDGET (text_view)))
9383 gtk_widget_queue_resize (child);
9387 /* Iterator operations */
9390 * gtk_text_view_forward_display_line:
9391 * @text_view: a #GtkTextView
9392 * @iter: a #GtkTextIter
9394 * Moves the given @iter forward by one display (wrapped) line.
9395 * A display line is different from a paragraph. Paragraphs are
9396 * separated by newlines or other paragraph separator characters.
9397 * Display lines are created by line-wrapping a paragraph. If
9398 * wrapping is turned off, display lines and paragraphs will be the
9399 * same. Display lines are divided differently for each view, since
9400 * they depend on the view's width; paragraphs are the same in all
9401 * views, since they depend on the contents of the #GtkTextBuffer.
9403 * Return value: %TRUE if @iter was moved and is not on the end iterator
9406 gtk_text_view_forward_display_line (GtkTextView *text_view,
9409 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9410 g_return_val_if_fail (iter != NULL, FALSE);
9412 gtk_text_view_ensure_layout (text_view);
9414 return gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, iter);
9418 * gtk_text_view_backward_display_line:
9419 * @text_view: a #GtkTextView
9420 * @iter: a #GtkTextIter
9422 * Moves the given @iter backward by one display (wrapped) line.
9423 * A display line is different from a paragraph. Paragraphs are
9424 * separated by newlines or other paragraph separator characters.
9425 * Display lines are created by line-wrapping a paragraph. If
9426 * wrapping is turned off, display lines and paragraphs will be the
9427 * same. Display lines are divided differently for each view, since
9428 * they depend on the view's width; paragraphs are the same in all
9429 * views, since they depend on the contents of the #GtkTextBuffer.
9431 * Return value: %TRUE if @iter was moved and is not on the end iterator
9434 gtk_text_view_backward_display_line (GtkTextView *text_view,
9437 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9438 g_return_val_if_fail (iter != NULL, FALSE);
9440 gtk_text_view_ensure_layout (text_view);
9442 return gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, iter);
9446 * gtk_text_view_forward_display_line_end:
9447 * @text_view: a #GtkTextView
9448 * @iter: a #GtkTextIter
9450 * Moves the given @iter forward to the next display line end.
9451 * A display line is different from a paragraph. Paragraphs are
9452 * separated by newlines or other paragraph separator characters.
9453 * Display lines are created by line-wrapping a paragraph. If
9454 * wrapping is turned off, display lines and paragraphs will be the
9455 * same. Display lines are divided differently for each view, since
9456 * they depend on the view's width; paragraphs are the same in all
9457 * views, since they depend on the contents of the #GtkTextBuffer.
9459 * Return value: %TRUE if @iter was moved and is not on the end iterator
9462 gtk_text_view_forward_display_line_end (GtkTextView *text_view,
9465 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9466 g_return_val_if_fail (iter != NULL, FALSE);
9468 gtk_text_view_ensure_layout (text_view);
9470 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, 1);
9474 * gtk_text_view_backward_display_line_start:
9475 * @text_view: a #GtkTextView
9476 * @iter: a #GtkTextIter
9478 * Moves the given @iter backward to the next display line start.
9479 * A display line is different from a paragraph. Paragraphs are
9480 * separated by newlines or other paragraph separator characters.
9481 * Display lines are created by line-wrapping a paragraph. If
9482 * wrapping is turned off, display lines and paragraphs will be the
9483 * same. Display lines are divided differently for each view, since
9484 * they depend on the view's width; paragraphs are the same in all
9485 * views, since they depend on the contents of the #GtkTextBuffer.
9487 * Return value: %TRUE if @iter was moved and is not on the end iterator
9490 gtk_text_view_backward_display_line_start (GtkTextView *text_view,
9493 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9494 g_return_val_if_fail (iter != NULL, FALSE);
9496 gtk_text_view_ensure_layout (text_view);
9498 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, -1);
9502 * gtk_text_view_starts_display_line:
9503 * @text_view: a #GtkTextView
9504 * @iter: a #GtkTextIter
9506 * Determines whether @iter is at the start of a display line.
9507 * See gtk_text_view_forward_display_line() for an explanation of
9508 * display lines vs. paragraphs.
9510 * Return value: %TRUE if @iter begins a wrapped line
9513 gtk_text_view_starts_display_line (GtkTextView *text_view,
9514 const GtkTextIter *iter)
9516 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9517 g_return_val_if_fail (iter != NULL, FALSE);
9519 gtk_text_view_ensure_layout (text_view);
9521 return gtk_text_layout_iter_starts_line (text_view->priv->layout, iter);
9525 * gtk_text_view_move_visually:
9526 * @text_view: a #GtkTextView
9527 * @iter: a #GtkTextIter
9528 * @count: number of characters to move (negative moves left,
9529 * positive moves right)
9531 * Move the iterator a given number of characters visually, treating
9532 * it as the strong cursor position. If @count is positive, then the
9533 * new strong cursor position will be @count positions to the right of
9534 * the old cursor position. If @count is negative then the new strong
9535 * cursor position will be @count positions to the left of the old
9538 * In the presence of bi-directional text, the correspondence
9539 * between logical and visual order will depend on the direction
9540 * of the current run, and there may be jumps when the cursor
9541 * is moved off of the end of a run.
9543 * Return value: %TRUE if @iter moved and is not on the end iterator
9546 gtk_text_view_move_visually (GtkTextView *text_view,
9550 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9551 g_return_val_if_fail (iter != NULL, FALSE);
9553 gtk_text_view_ensure_layout (text_view);
9555 return gtk_text_layout_move_iter_visually (text_view->priv->layout, iter, count);