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 "gtksizerequest.h"
44 #include "gtktextbufferrichtext.h"
45 #include "gtktextdisplay.h"
46 #include "gtktextview.h"
47 #include "gtkimmulticontext.h"
48 #include "gdk/gdkkeysyms.h"
49 #include "gtkprivate.h"
50 #include "gtktextutil.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 /* The virtual cursor position is normally the same as the
138 * actual (strong) cursor position, except in two circumstances:
140 * a) When the cursor is moved vertically with the keyboard
141 * b) When the text view is scrolled with the keyboard
143 * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
144 * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
146 gint virtual_cursor_x; /* -1 means use actual cursor position */
147 gint virtual_cursor_y; /* -1 means use actual cursor position */
149 GtkTextMark *first_para_mark; /* Mark at the beginning of the first onscreen paragraph */
150 gint first_para_pixels; /* Offset of top of screen in the first onscreen paragraph */
152 GtkTextMark *dnd_mark;
155 guint first_validate_idle; /* Idle to revalidate onscreen portion, runs before resize */
156 guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
158 GtkIMContext *im_context;
159 GtkWidget *popup_menu;
166 GtkTextPendingScroll *pending_scroll;
168 gint pending_place_cursor_button;
170 /* Default style settings */
171 gint pixels_above_lines;
172 gint pixels_below_lines;
173 gint pixels_inside_wrap;
174 GtkWrapMode wrap_mode;
175 GtkJustification justify;
182 guint overwrite_mode : 1;
183 guint cursor_visible : 1;
185 /* if we have reset the IM since the last character entered */
186 guint need_im_reset : 1;
188 guint accepts_tab : 1;
190 guint width_changed : 1;
192 /* debug flag - means that we've validated onscreen since the
193 * last "invalidate" signal from the layout
195 guint onscreen_validated : 1;
197 guint mouse_cursor_obscured : 1;
199 guint scroll_after_paste : 1;
202 struct _GtkTextPendingScroll
205 gdouble within_margin;
213 SET_SCROLL_ADJUSTMENTS,
227 TOGGLE_CURSOR_VISIBLE,
235 PROP_PIXELS_ABOVE_LINES,
236 PROP_PIXELS_BELOW_LINES,
237 PROP_PIXELS_INSIDE_WRAP,
252 static void gtk_text_view_destroy (GtkObject *object);
253 static void gtk_text_view_finalize (GObject *object);
254 static void gtk_text_view_set_property (GObject *object,
258 static void gtk_text_view_get_property (GObject *object,
262 static void gtk_text_view_size_request (GtkWidget *widget,
263 GtkRequisition *requisition);
264 static void gtk_text_view_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static void gtk_text_view_realize (GtkWidget *widget);
267 static void gtk_text_view_unrealize (GtkWidget *widget);
268 static void gtk_text_view_style_set (GtkWidget *widget,
269 GtkStyle *previous_style);
270 static void gtk_text_view_direction_changed (GtkWidget *widget,
271 GtkTextDirection previous_direction);
272 static void gtk_text_view_grab_notify (GtkWidget *widget,
273 gboolean was_grabbed);
274 static void gtk_text_view_state_changed (GtkWidget *widget,
275 GtkStateType previous_state);
277 static gint gtk_text_view_event (GtkWidget *widget,
279 static gint gtk_text_view_key_press_event (GtkWidget *widget,
281 static gint gtk_text_view_key_release_event (GtkWidget *widget,
283 static gint gtk_text_view_button_press_event (GtkWidget *widget,
284 GdkEventButton *event);
285 static gint gtk_text_view_button_release_event (GtkWidget *widget,
286 GdkEventButton *event);
287 static gint gtk_text_view_focus_in_event (GtkWidget *widget,
288 GdkEventFocus *event);
289 static gint gtk_text_view_focus_out_event (GtkWidget *widget,
290 GdkEventFocus *event);
291 static gint gtk_text_view_motion_event (GtkWidget *widget,
292 GdkEventMotion *event);
293 static gint gtk_text_view_expose_event (GtkWidget *widget,
294 GdkEventExpose *expose);
295 static void gtk_text_view_draw_focus (GtkWidget *widget);
296 static gboolean gtk_text_view_focus (GtkWidget *widget,
297 GtkDirectionType direction);
298 static void gtk_text_view_move_focus (GtkWidget *widget,
299 GtkDirectionType direction_type);
300 static void gtk_text_view_select_all (GtkWidget *widget,
304 /* Source side drag signals */
305 static void gtk_text_view_drag_begin (GtkWidget *widget,
306 GdkDragContext *context);
307 static void gtk_text_view_drag_end (GtkWidget *widget,
308 GdkDragContext *context);
309 static void gtk_text_view_drag_data_get (GtkWidget *widget,
310 GdkDragContext *context,
311 GtkSelectionData *selection_data,
314 static void gtk_text_view_drag_data_delete (GtkWidget *widget,
315 GdkDragContext *context);
317 /* Target side drag signals */
318 static void gtk_text_view_drag_leave (GtkWidget *widget,
319 GdkDragContext *context,
321 static gboolean gtk_text_view_drag_motion (GtkWidget *widget,
322 GdkDragContext *context,
326 static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
327 GdkDragContext *context,
331 static void gtk_text_view_drag_data_received (GtkWidget *widget,
332 GdkDragContext *context,
335 GtkSelectionData *selection_data,
339 static void gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
341 GtkAdjustment *vadj);
342 static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
344 static void gtk_text_view_move_cursor (GtkTextView *text_view,
345 GtkMovementStep step,
347 gboolean extend_selection);
348 static gboolean gtk_text_view_move_viewport (GtkTextView *text_view,
351 static void gtk_text_view_set_anchor (GtkTextView *text_view);
352 static gboolean gtk_text_view_scroll_pages (GtkTextView *text_view,
354 gboolean extend_selection);
355 static gboolean gtk_text_view_scroll_hpages(GtkTextView *text_view,
357 gboolean extend_selection);
358 static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
360 static void gtk_text_view_delete_from_cursor (GtkTextView *text_view,
363 static void gtk_text_view_backspace (GtkTextView *text_view);
364 static void gtk_text_view_cut_clipboard (GtkTextView *text_view);
365 static void gtk_text_view_copy_clipboard (GtkTextView *text_view);
366 static void gtk_text_view_paste_clipboard (GtkTextView *text_view);
367 static void gtk_text_view_toggle_overwrite (GtkTextView *text_view);
368 static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view);
369 static void gtk_text_view_compat_move_focus(GtkTextView *text_view,
370 GtkDirectionType direction_type);
371 static void gtk_text_view_unselect (GtkTextView *text_view);
373 static void gtk_text_view_validate_onscreen (GtkTextView *text_view);
374 static void gtk_text_view_get_first_para_iter (GtkTextView *text_view,
376 static void gtk_text_view_update_layout_width (GtkTextView *text_view);
377 static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
378 GtkTextAttributes *values,
380 static void gtk_text_view_ensure_layout (GtkTextView *text_view);
381 static void gtk_text_view_destroy_layout (GtkTextView *text_view);
382 static void gtk_text_view_check_keymap_direction (GtkTextView *text_view);
383 static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
384 const GtkTextIter *iter,
385 GdkEventButton *event);
386 static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view);
387 static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
388 const GtkTextIter *iter,
389 GdkEventMotion *event);
390 static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
391 static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
392 static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
393 static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
395 static void gtk_text_view_value_changed (GtkAdjustment *adj,
397 static void gtk_text_view_commit_handler (GtkIMContext *context,
399 GtkTextView *text_view);
400 static void gtk_text_view_commit_text (GtkTextView *text_view,
402 static void gtk_text_view_preedit_changed_handler (GtkIMContext *context,
403 GtkTextView *text_view);
404 static gboolean gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
405 GtkTextView *text_view);
406 static gboolean gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
409 GtkTextView *text_view);
411 static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
412 const GtkTextIter *location,
415 static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
416 const GParamSpec *pspec,
418 static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
419 GtkClipboard *clipboard,
421 static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
423 static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
427 static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
431 static GtkAdjustment* get_hadjustment (GtkTextView *text_view);
432 static GtkAdjustment* get_vadjustment (GtkTextView *text_view);
434 static void gtk_text_view_do_popup (GtkTextView *text_view,
435 GdkEventButton *event);
437 static void cancel_pending_scroll (GtkTextView *text_view);
438 static void gtk_text_view_queue_scroll (GtkTextView *text_view,
440 gdouble within_margin,
445 static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
446 static void gtk_text_view_update_adjustments (GtkTextView *text_view);
447 static void gtk_text_view_invalidate (GtkTextView *text_view);
448 static void gtk_text_view_flush_first_validate (GtkTextView *text_view);
450 static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
452 /* Container methods */
453 static void gtk_text_view_add (GtkContainer *container,
455 static void gtk_text_view_remove (GtkContainer *container,
457 static void gtk_text_view_forall (GtkContainer *container,
458 gboolean include_internals,
459 GtkCallback callback,
460 gpointer callback_data);
462 /* FIXME probably need the focus methods. */
464 typedef struct _GtkTextViewChild GtkTextViewChild;
466 struct _GtkTextViewChild
470 GtkTextChildAnchor *anchor;
472 gint from_top_of_line;
473 gint from_left_of_buffer;
475 /* These are ignored if anchor != NULL */
476 GtkTextWindowType type;
481 static GtkTextViewChild* text_view_child_new_anchored (GtkWidget *child,
482 GtkTextChildAnchor *anchor,
483 GtkTextLayout *layout);
484 static GtkTextViewChild* text_view_child_new_window (GtkWidget *child,
485 GtkTextWindowType type,
488 static void text_view_child_free (GtkTextViewChild *child);
489 static void text_view_child_set_parent_window (GtkTextView *text_view,
490 GtkTextViewChild *child);
492 struct _GtkTextWindow
494 GtkTextWindowType type;
497 GdkWindow *bin_window;
498 GtkRequisition requisition;
499 GdkRectangle allocation;
502 static GtkTextWindow *text_window_new (GtkTextWindowType type,
505 gint height_request);
506 static void text_window_free (GtkTextWindow *win);
507 static void text_window_realize (GtkTextWindow *win,
509 static void text_window_unrealize (GtkTextWindow *win);
510 static void text_window_size_allocate (GtkTextWindow *win,
512 static void text_window_scroll (GtkTextWindow *win,
515 static void text_window_invalidate_rect (GtkTextWindow *win,
517 static void text_window_invalidate_cursors (GtkTextWindow *win);
519 static gint text_window_get_width (GtkTextWindow *win);
520 static gint text_window_get_height (GtkTextWindow *win);
523 static guint signals[LAST_SIGNAL] = { 0 };
525 G_DEFINE_TYPE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER)
528 add_move_binding (GtkBindingSet *binding_set,
531 GtkMovementStep step,
534 g_assert ((modmask & GDK_SHIFT_MASK) == 0);
536 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
540 G_TYPE_BOOLEAN, FALSE);
542 /* Selection-extending version */
543 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
547 G_TYPE_BOOLEAN, TRUE);
551 gtk_text_view_class_init (GtkTextViewClass *klass)
553 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
554 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
555 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
556 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
557 GtkBindingSet *binding_set;
559 /* Default handlers and virtual methods
561 gobject_class->set_property = gtk_text_view_set_property;
562 gobject_class->get_property = gtk_text_view_get_property;
564 object_class->destroy = gtk_text_view_destroy;
565 gobject_class->finalize = gtk_text_view_finalize;
567 widget_class->realize = gtk_text_view_realize;
568 widget_class->unrealize = gtk_text_view_unrealize;
569 widget_class->style_set = gtk_text_view_style_set;
570 widget_class->direction_changed = gtk_text_view_direction_changed;
571 widget_class->grab_notify = gtk_text_view_grab_notify;
572 widget_class->state_changed = gtk_text_view_state_changed;
573 widget_class->size_request = gtk_text_view_size_request;
574 widget_class->size_allocate = gtk_text_view_size_allocate;
575 widget_class->event = gtk_text_view_event;
576 widget_class->key_press_event = gtk_text_view_key_press_event;
577 widget_class->key_release_event = gtk_text_view_key_release_event;
578 widget_class->button_press_event = gtk_text_view_button_press_event;
579 widget_class->button_release_event = gtk_text_view_button_release_event;
580 widget_class->focus_in_event = gtk_text_view_focus_in_event;
581 widget_class->focus_out_event = gtk_text_view_focus_out_event;
582 widget_class->motion_notify_event = gtk_text_view_motion_event;
583 widget_class->expose_event = gtk_text_view_expose_event;
584 widget_class->focus = gtk_text_view_focus;
586 /* need to override the base class function via override_class_handler,
587 * because the signal slot is not available in GtkWidgetCLass
589 g_signal_override_class_handler ("move-focus",
591 G_CALLBACK (gtk_text_view_move_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->move_focus = gtk_text_view_compat_move_focus;
619 klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
625 g_object_class_install_property (gobject_class,
626 PROP_PIXELS_ABOVE_LINES,
627 g_param_spec_int ("pixels-above-lines",
628 P_("Pixels Above Lines"),
629 P_("Pixels of blank space above paragraphs"),
633 GTK_PARAM_READWRITE));
635 g_object_class_install_property (gobject_class,
636 PROP_PIXELS_BELOW_LINES,
637 g_param_spec_int ("pixels-below-lines",
638 P_("Pixels Below Lines"),
639 P_("Pixels of blank space below paragraphs"),
643 GTK_PARAM_READWRITE));
645 g_object_class_install_property (gobject_class,
646 PROP_PIXELS_INSIDE_WRAP,
647 g_param_spec_int ("pixels-inside-wrap",
648 P_("Pixels Inside Wrap"),
649 P_("Pixels of blank space between wrapped lines in a paragraph"),
653 GTK_PARAM_READWRITE));
655 g_object_class_install_property (gobject_class,
657 g_param_spec_boolean ("editable",
659 P_("Whether the text can be modified by the user"),
661 GTK_PARAM_READWRITE));
663 g_object_class_install_property (gobject_class,
665 g_param_spec_enum ("wrap-mode",
667 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
670 GTK_PARAM_READWRITE));
672 g_object_class_install_property (gobject_class,
674 g_param_spec_enum ("justification",
676 P_("Left, right, or center justification"),
677 GTK_TYPE_JUSTIFICATION,
679 GTK_PARAM_READWRITE));
681 g_object_class_install_property (gobject_class,
683 g_param_spec_int ("left-margin",
685 P_("Width of the left margin in pixels"),
689 GTK_PARAM_READWRITE));
691 g_object_class_install_property (gobject_class,
693 g_param_spec_int ("right-margin",
695 P_("Width of the right margin in pixels"),
699 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_int ("indent",
705 P_("Amount to indent the paragraph, in pixels"),
709 GTK_PARAM_READWRITE));
711 g_object_class_install_property (gobject_class,
713 g_param_spec_boxed ("tabs",
715 P_("Custom tabs for this text"),
716 PANGO_TYPE_TAB_ARRAY,
717 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_boolean ("cursor-visible",
722 P_("Cursor Visible"),
723 P_("If the insertion cursor is shown"),
725 GTK_PARAM_READWRITE));
727 g_object_class_install_property (gobject_class,
729 g_param_spec_object ("buffer",
731 P_("The buffer which is displayed"),
732 GTK_TYPE_TEXT_BUFFER,
733 GTK_PARAM_READWRITE));
735 g_object_class_install_property (gobject_class,
737 g_param_spec_boolean ("overwrite",
738 P_("Overwrite mode"),
739 P_("Whether entered text overwrites existing contents"),
741 GTK_PARAM_READWRITE));
743 g_object_class_install_property (gobject_class,
745 g_param_spec_boolean ("accepts-tab",
747 P_("Whether Tab will result in a tab character being entered"),
749 GTK_PARAM_READWRITE));
752 * GtkTextView:im-module:
754 * Which IM (input method) module should be used for this entry.
757 * Setting this to a non-%NULL value overrides the
758 * system-wide IM module setting. See the GtkSettings
759 * #GtkSettings:gtk-im-module property.
763 g_object_class_install_property (gobject_class,
765 g_param_spec_string ("im-module",
767 P_("Which IM module should be used"),
769 GTK_PARAM_READWRITE));
774 gtk_widget_class_install_style_property (widget_class,
775 g_param_spec_boxed ("error-underline-color",
776 P_("Error underline color"),
777 P_("Color with which to draw error-indication underlines"),
779 GTK_PARAM_READABLE));
786 * GtkTextView::move-cursor:
787 * @text_view: the object which received the signal
788 * @step: the granularity of the move, as a #GtkMovementStep
789 * @count: the number of @step units to move
790 * @extend_selection: %TRUE if the move should extend the selection
792 * The ::move-cursor signal is a
793 * <link linkend="keybinding-signals">keybinding signal</link>
794 * which gets emitted when the user initiates a cursor movement.
795 * If the cursor is not visible in @text_view, this signal causes
796 * the viewport to be moved instead.
798 * Applications should not connect to it, but may emit it with
799 * g_signal_emit_by_name() if they need to control the cursor
802 * The default bindings for this signal come in two variants,
803 * the variant with the Shift modifier extends the selection,
804 * the variant without the Shift modifer does not.
805 * There are too many key combinations to list them all here.
807 * <listitem>Arrow keys move by individual characters/lines</listitem>
808 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
809 * <listitem>Home/End keys move to the ends of the buffer</listitem>
810 * <listitem>PageUp/PageDown keys move vertically by pages</listitem>
811 * <listitem>Ctrl-PageUp/PageDown keys move horizontally by pages</listitem>
814 signals[MOVE_CURSOR] =
815 g_signal_new (I_("move-cursor"),
816 G_OBJECT_CLASS_TYPE (gobject_class),
817 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
818 G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
820 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
822 GTK_TYPE_MOVEMENT_STEP,
827 * GtkTextView::move-viewport:
828 * @text_view: the object which received the signal
829 * @step: the granularity of the move, as a #GtkMovementStep
830 * @count: the number of @step units to move
832 * The ::move-viewport signal is a
833 * <link linkend="keybinding-signals">keybinding signal</link>
834 * which can be bound to key combinations to allow the user
835 * to move the viewport, i.e. change what part of the text view
836 * is visible in a containing scrolled window.
838 * There are no default bindings for this signal.
840 signals[MOVE_VIEWPORT] =
841 g_signal_new_class_handler (I_("move-viewport"),
842 G_OBJECT_CLASS_TYPE (gobject_class),
843 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
844 G_CALLBACK (gtk_text_view_move_viewport),
846 _gtk_marshal_VOID__ENUM_INT,
848 GTK_TYPE_SCROLL_STEP,
852 * GtkTextView::set-anchor:
853 * @text_view: the object which received the signal
855 * The ::set-anchor signal is a
856 * <link linkend="keybinding-signals">keybinding signal</link>
857 * which gets emitted when the user initiates setting the "anchor"
858 * mark. The "anchor" mark gets placed at the same position as the
861 * This signal has no default bindings.
863 signals[SET_ANCHOR] =
864 g_signal_new (I_("set-anchor"),
865 G_OBJECT_CLASS_TYPE (gobject_class),
866 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
867 G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
869 _gtk_marshal_VOID__VOID,
873 * GtkTextView::insert-at-cursor:
874 * @text_view: the object which received the signal
875 * @string: the string to insert
877 * The ::insert-at-cursor signal is a
878 * <link linkend="keybinding-signals">keybinding signal</link>
879 * which gets emitted when the user initiates the insertion of a
880 * fixed string at the cursor.
882 * This signal has no default bindings.
884 signals[INSERT_AT_CURSOR] =
885 g_signal_new (I_("insert-at-cursor"),
886 G_OBJECT_CLASS_TYPE (gobject_class),
887 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
888 G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
890 _gtk_marshal_VOID__STRING,
895 * GtkTextView::delete-from-cursor:
896 * @text_view: the object which received the signal
897 * @type: the granularity of the deletion, as a #GtkDeleteType
898 * @count: the number of @type units to delete
900 * The ::delete-from-cursor signal is a
901 * <link linkend="keybinding-signals">keybinding signal</link>
902 * which gets emitted when the user initiates a text deletion.
904 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
905 * if there is one, otherwise it deletes the requested number
908 * The default bindings for this signal are
909 * Delete for deleting a character, Ctrl-Delete for
910 * deleting a word and Ctrl-Backspace for deleting a word
913 signals[DELETE_FROM_CURSOR] =
914 g_signal_new (I_("delete-from-cursor"),
915 G_OBJECT_CLASS_TYPE (gobject_class),
916 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
917 G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
919 _gtk_marshal_VOID__ENUM_INT,
921 GTK_TYPE_DELETE_TYPE,
925 * GtkTextView::backspace:
926 * @text_view: the object which received the signal
928 * The ::backspace signal is a
929 * <link linkend="keybinding-signals">keybinding signal</link>
930 * which gets emitted when the user asks for it.
932 * The default bindings for this signal are
933 * Backspace and Shift-Backspace.
936 g_signal_new (I_("backspace"),
937 G_OBJECT_CLASS_TYPE (gobject_class),
938 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
939 G_STRUCT_OFFSET (GtkTextViewClass, backspace),
941 _gtk_marshal_VOID__VOID,
945 * GtkTextView::cut-clipboard:
946 * @text_view: the object which received the signal
948 * The ::cut-clipboard signal is a
949 * <link linkend="keybinding-signals">keybinding signal</link>
950 * which gets emitted to cut the selection to the clipboard.
952 * The default bindings for this signal are
953 * Ctrl-x and Shift-Delete.
955 signals[CUT_CLIPBOARD] =
956 g_signal_new (I_("cut-clipboard"),
957 G_OBJECT_CLASS_TYPE (gobject_class),
958 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
959 G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
961 _gtk_marshal_VOID__VOID,
965 * GtkTextView::copy-clipboard:
966 * @text_view: the object which received the signal
968 * The ::copy-clipboard signal is a
969 * <link linkend="keybinding-signals">keybinding signal</link>
970 * which gets emitted to copy the selection to the clipboard.
972 * The default bindings for this signal are
973 * Ctrl-c and Ctrl-Insert.
975 signals[COPY_CLIPBOARD] =
976 g_signal_new (I_("copy-clipboard"),
977 G_OBJECT_CLASS_TYPE (gobject_class),
978 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
979 G_STRUCT_OFFSET (GtkTextViewClass, copy_clipboard),
981 _gtk_marshal_VOID__VOID,
985 * GtkTextView::paste-clipboard:
986 * @text_view: the object which received the signal
988 * The ::paste-clipboard signal is a
989 * <link linkend="keybinding-signals">keybinding signal</link>
990 * which gets emitted to paste the contents of the clipboard
991 * into the text view.
993 * The default bindings for this signal are
994 * Ctrl-v and Shift-Insert.
996 signals[PASTE_CLIPBOARD] =
997 g_signal_new (I_("paste-clipboard"),
998 G_OBJECT_CLASS_TYPE (gobject_class),
999 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1000 G_STRUCT_OFFSET (GtkTextViewClass, paste_clipboard),
1002 _gtk_marshal_VOID__VOID,
1006 * GtkTextView::toggle-overwrite:
1007 * @text_view: the object which received the signal
1009 * The ::toggle-overwrite signal is a
1010 * <link linkend="keybinding-signals">keybinding signal</link>
1011 * which gets emitted to toggle the overwrite mode of the text view.
1013 * The default bindings for this signal is Insert.
1015 signals[TOGGLE_OVERWRITE] =
1016 g_signal_new (I_("toggle-overwrite"),
1017 G_OBJECT_CLASS_TYPE (gobject_class),
1018 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1019 G_STRUCT_OFFSET (GtkTextViewClass, toggle_overwrite),
1021 _gtk_marshal_VOID__VOID,
1025 * GtkTextView::set-scroll-adjustments
1026 * @horizontal: the horizontal #GtkAdjustment
1027 * @vertical: the vertical #GtkAdjustment
1029 * Set the scroll adjustments for the text view. Usually scrolled containers
1030 * like #GtkScrolledWindow will emit this signal to connect two instances
1031 * of #GtkScrollbar to the scroll directions of the #GtkTextView.
1033 signals[SET_SCROLL_ADJUSTMENTS] =
1034 g_signal_new (I_("set-scroll-adjustments"),
1035 G_OBJECT_CLASS_TYPE (gobject_class),
1036 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1037 G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments),
1039 _gtk_marshal_VOID__OBJECT_OBJECT,
1041 GTK_TYPE_ADJUSTMENT,
1042 GTK_TYPE_ADJUSTMENT);
1043 widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
1046 * GtkTextView::populate-popup:
1047 * @entry: The text view on which the signal is emitted
1048 * @menu: the menu that is being populated
1050 * The ::populate-popup signal gets emitted before showing the
1051 * context menu of the text view.
1053 * If you need to add items to the context menu, connect
1054 * to this signal and append your menuitems to the @menu.
1056 signals[POPULATE_POPUP] =
1057 g_signal_new (I_("populate-popup"),
1058 G_OBJECT_CLASS_TYPE (gobject_class),
1060 G_STRUCT_OFFSET (GtkTextViewClass, populate_popup),
1062 _gtk_marshal_VOID__OBJECT,
1067 * GtkTextView::select-all:
1068 * @text_view: the object which received the signal
1069 * @select: %TRUE to select, %FALSE to unselect
1071 * The ::select-all signal is a
1072 * <link linkend="keybinding-signals">keybinding signal</link>
1073 * which gets emitted to select or unselect the complete
1074 * contents of the text view.
1076 * The default bindings for this signal are Ctrl-a and Ctrl-/
1077 * for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
1079 signals[SELECT_ALL] =
1080 g_signal_new_class_handler (I_("select-all"),
1081 G_OBJECT_CLASS_TYPE (object_class),
1082 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1083 G_CALLBACK (gtk_text_view_select_all),
1085 _gtk_marshal_VOID__BOOLEAN,
1086 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
1089 * GtkTextView::toggle-cursor-visible:
1090 * @text_view: the object which received the signal
1092 * The ::toggle-cursor-visible signal is a
1093 * <link linkend="keybinding-signals">keybinding signal</link>
1094 * which gets emitted to toggle the visibility of the cursor.
1096 * The default binding for this signal is F7.
1098 signals[TOGGLE_CURSOR_VISIBLE] =
1099 g_signal_new_class_handler (I_("toggle-cursor-visible"),
1100 G_OBJECT_CLASS_TYPE (object_class),
1101 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1102 G_CALLBACK (gtk_text_view_toggle_cursor_visible),
1104 _gtk_marshal_VOID__VOID,
1108 * GtkTextView::preedit-changed:
1109 * @text_view: the object which received the signal
1110 * @preedit: the current preedit string
1112 * If an input method is used, the typed text will not immediately
1113 * be committed to the buffer. So if you are interested in the text,
1114 * connect to this signal.
1116 * This signal is only emitted if the text at the given position
1117 * is actually editable.
1121 signals[PREEDIT_CHANGED] =
1122 g_signal_new_class_handler (I_("preedit-changed"),
1123 G_OBJECT_CLASS_TYPE (object_class),
1124 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1127 _gtk_marshal_VOID__STRING,
1135 binding_set = gtk_binding_set_by_class (klass);
1137 /* Moving the insertion point */
1138 add_move_binding (binding_set, GDK_Right, 0,
1139 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1141 add_move_binding (binding_set, GDK_KP_Right, 0,
1142 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1144 add_move_binding (binding_set, GDK_Left, 0,
1145 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1147 add_move_binding (binding_set, GDK_KP_Left, 0,
1148 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1150 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
1151 GTK_MOVEMENT_WORDS, 1);
1153 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
1154 GTK_MOVEMENT_WORDS, 1);
1156 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
1157 GTK_MOVEMENT_WORDS, -1);
1159 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
1160 GTK_MOVEMENT_WORDS, -1);
1162 add_move_binding (binding_set, GDK_Up, 0,
1163 GTK_MOVEMENT_DISPLAY_LINES, -1);
1165 add_move_binding (binding_set, GDK_KP_Up, 0,
1166 GTK_MOVEMENT_DISPLAY_LINES, -1);
1168 add_move_binding (binding_set, GDK_Down, 0,
1169 GTK_MOVEMENT_DISPLAY_LINES, 1);
1171 add_move_binding (binding_set, GDK_KP_Down, 0,
1172 GTK_MOVEMENT_DISPLAY_LINES, 1);
1174 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK,
1175 GTK_MOVEMENT_PARAGRAPHS, -1);
1177 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK,
1178 GTK_MOVEMENT_PARAGRAPHS, -1);
1180 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK,
1181 GTK_MOVEMENT_PARAGRAPHS, 1);
1183 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK,
1184 GTK_MOVEMENT_PARAGRAPHS, 1);
1186 add_move_binding (binding_set, GDK_Home, 0,
1187 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1189 add_move_binding (binding_set, GDK_KP_Home, 0,
1190 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1192 add_move_binding (binding_set, GDK_End, 0,
1193 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1195 add_move_binding (binding_set, GDK_KP_End, 0,
1196 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1198 add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
1199 GTK_MOVEMENT_BUFFER_ENDS, -1);
1201 add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
1202 GTK_MOVEMENT_BUFFER_ENDS, -1);
1204 add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
1205 GTK_MOVEMENT_BUFFER_ENDS, 1);
1207 add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
1208 GTK_MOVEMENT_BUFFER_ENDS, 1);
1210 add_move_binding (binding_set, GDK_Page_Up, 0,
1211 GTK_MOVEMENT_PAGES, -1);
1213 add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1214 GTK_MOVEMENT_PAGES, -1);
1216 add_move_binding (binding_set, GDK_Page_Down, 0,
1217 GTK_MOVEMENT_PAGES, 1);
1219 add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1220 GTK_MOVEMENT_PAGES, 1);
1222 add_move_binding (binding_set, GDK_Page_Up, GDK_CONTROL_MASK,
1223 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1225 add_move_binding (binding_set, GDK_KP_Page_Up, GDK_CONTROL_MASK,
1226 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1228 add_move_binding (binding_set, GDK_Page_Down, GDK_CONTROL_MASK,
1229 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1231 add_move_binding (binding_set, GDK_KP_Page_Down, GDK_CONTROL_MASK,
1232 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1235 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1237 G_TYPE_BOOLEAN, TRUE);
1239 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
1241 G_TYPE_BOOLEAN, TRUE);
1244 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
1246 G_TYPE_BOOLEAN, FALSE);
1248 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1250 G_TYPE_BOOLEAN, FALSE);
1253 gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
1254 "delete-from-cursor", 2,
1255 G_TYPE_ENUM, GTK_DELETE_CHARS,
1258 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
1259 "delete-from-cursor", 2,
1260 G_TYPE_ENUM, GTK_DELETE_CHARS,
1263 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
1266 /* Make this do the same as Backspace, to help with mis-typing */
1267 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
1270 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
1271 "delete-from-cursor", 2,
1272 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1275 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
1276 "delete-from-cursor", 2,
1277 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1280 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
1281 "delete-from-cursor", 2,
1282 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1285 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1286 "delete-from-cursor", 2,
1287 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1290 gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1291 "delete-from-cursor", 2,
1292 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1295 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1296 "delete-from-cursor", 2,
1297 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1300 /* Cut/copy/paste */
1302 gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
1303 "cut-clipboard", 0);
1304 gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
1305 "copy-clipboard", 0);
1306 gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
1307 "paste-clipboard", 0);
1309 gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
1310 "cut-clipboard", 0);
1311 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
1312 "copy-clipboard", 0);
1313 gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
1314 "paste-clipboard", 0);
1317 gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
1318 "toggle-overwrite", 0);
1319 gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
1320 "toggle-overwrite", 0);
1323 gtk_binding_entry_add_signal (binding_set, GDK_F7, 0,
1324 "toggle-cursor-visible", 0);
1326 /* Control-tab focus motion */
1327 gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_CONTROL_MASK,
1329 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1330 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_CONTROL_MASK,
1332 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1334 gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1336 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1337 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1339 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1341 g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
1345 gtk_text_view_init (GtkTextView *text_view)
1347 GtkWidget *widget = GTK_WIDGET (text_view);
1348 GtkTargetList *target_list;
1349 GtkTextViewPrivate *priv;
1351 text_view->priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
1352 priv = text_view->priv;
1354 gtk_widget_set_can_focus (widget, TRUE);
1356 /* Set up default style */
1357 priv->wrap_mode = GTK_WRAP_NONE;
1358 priv->pixels_above_lines = 0;
1359 priv->pixels_below_lines = 0;
1360 priv->pixels_inside_wrap = 0;
1361 priv->justify = GTK_JUSTIFY_LEFT;
1362 priv->left_margin = 0;
1363 priv->right_margin = 0;
1366 priv->editable = TRUE;
1368 priv->scroll_after_paste = TRUE;
1370 gtk_drag_dest_set (widget, 0, NULL, 0,
1371 GDK_ACTION_COPY | GDK_ACTION_MOVE);
1373 target_list = gtk_target_list_new (NULL, 0);
1374 gtk_drag_dest_set_target_list (widget, target_list);
1375 gtk_target_list_unref (target_list);
1377 priv->virtual_cursor_x = -1;
1378 priv->virtual_cursor_y = -1;
1380 /* This object is completely private. No external entity can gain a reference
1381 * to it; so we create it here and destroy it in finalize ().
1383 priv->im_context = gtk_im_multicontext_new ();
1385 g_signal_connect (priv->im_context, "commit",
1386 G_CALLBACK (gtk_text_view_commit_handler), text_view);
1387 g_signal_connect (priv->im_context, "preedit-changed",
1388 G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
1389 g_signal_connect (priv->im_context, "retrieve-surrounding",
1390 G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
1391 g_signal_connect (priv->im_context, "delete-surrounding",
1392 G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
1394 priv->cursor_visible = TRUE;
1396 priv->accepts_tab = TRUE;
1398 priv->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT,
1401 priv->drag_start_x = -1;
1402 priv->drag_start_y = -1;
1404 priv->pending_place_cursor_button = 0;
1406 /* We handle all our own redrawing */
1407 gtk_widget_set_redraw_on_allocate (widget, FALSE);
1411 * gtk_text_view_new:
1413 * Creates a new #GtkTextView. If you don't call gtk_text_view_set_buffer()
1414 * before using the text view, an empty default buffer will be created
1415 * for you. Get the buffer with gtk_text_view_get_buffer(). If you want
1416 * to specify your own buffer, consider gtk_text_view_new_with_buffer().
1418 * Return value: a new #GtkTextView
1421 gtk_text_view_new (void)
1423 return g_object_new (GTK_TYPE_TEXT_VIEW, NULL);
1427 * gtk_text_view_new_with_buffer:
1428 * @buffer: a #GtkTextBuffer
1430 * Creates a new #GtkTextView widget displaying the buffer
1431 * @buffer. One buffer can be shared among many widgets.
1432 * @buffer may be %NULL to create a default buffer, in which case
1433 * this function is equivalent to gtk_text_view_new(). The
1434 * text view adds its own reference count to the buffer; it does not
1435 * take over an existing reference.
1437 * Return value: a new #GtkTextView.
1440 gtk_text_view_new_with_buffer (GtkTextBuffer *buffer)
1442 GtkTextView *text_view;
1444 text_view = (GtkTextView*)gtk_text_view_new ();
1446 gtk_text_view_set_buffer (text_view, buffer);
1448 return GTK_WIDGET (text_view);
1452 * gtk_text_view_set_buffer:
1453 * @text_view: a #GtkTextView
1454 * @buffer: (allow-none): a #GtkTextBuffer
1456 * Sets @buffer as the buffer being displayed by @text_view. The previous
1457 * buffer displayed by the text view is unreferenced, and a reference is
1458 * added to @buffer. If you owned a reference to @buffer before passing it
1459 * to this function, you must remove that reference yourself; #GtkTextView
1460 * will not "adopt" it.
1463 gtk_text_view_set_buffer (GtkTextView *text_view,
1464 GtkTextBuffer *buffer)
1466 GtkTextViewPrivate *priv;
1468 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1469 g_return_if_fail (buffer == NULL || GTK_IS_TEXT_BUFFER (buffer));
1471 priv = text_view->priv;
1473 if (priv->buffer == buffer)
1476 if (priv->buffer != NULL)
1478 /* Destroy all anchored children */
1482 copy = g_slist_copy (priv->children);
1484 while (tmp_list != NULL)
1486 GtkTextViewChild *vc = tmp_list->data;
1490 gtk_widget_destroy (vc->widget);
1491 /* vc may now be invalid! */
1494 tmp_list = g_slist_next (tmp_list);
1497 g_slist_free (copy);
1499 g_signal_handlers_disconnect_by_func (priv->buffer,
1500 gtk_text_view_mark_set_handler,
1502 g_signal_handlers_disconnect_by_func (priv->buffer,
1503 gtk_text_view_target_list_notify,
1505 g_signal_handlers_disconnect_by_func (priv->buffer,
1506 gtk_text_view_paste_done_handler,
1509 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1511 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1512 GDK_SELECTION_PRIMARY);
1513 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
1517 gtk_text_layout_set_buffer (priv->layout, NULL);
1519 g_object_unref (priv->buffer);
1520 priv->dnd_mark = NULL;
1521 priv->first_para_mark = NULL;
1522 cancel_pending_scroll (text_view);
1525 priv->buffer = buffer;
1528 gtk_text_layout_set_buffer (priv->layout, buffer);
1534 g_object_ref (buffer);
1536 gtk_text_buffer_get_iter_at_offset (priv->buffer, &start, 0);
1538 priv->dnd_mark = gtk_text_buffer_create_mark (priv->buffer,
1542 priv->first_para_mark = gtk_text_buffer_create_mark (priv->buffer,
1546 priv->first_para_pixels = 0;
1549 g_signal_connect (priv->buffer, "mark-set",
1550 G_CALLBACK (gtk_text_view_mark_set_handler),
1552 g_signal_connect (priv->buffer, "notify::paste-target-list",
1553 G_CALLBACK (gtk_text_view_target_list_notify),
1555 g_signal_connect (priv->buffer, "paste-done",
1556 G_CALLBACK (gtk_text_view_paste_done_handler),
1559 gtk_text_view_target_list_notify (priv->buffer, NULL, text_view);
1561 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1563 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1564 GDK_SELECTION_PRIMARY);
1565 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
1569 g_object_notify (G_OBJECT (text_view), "buffer");
1571 if (gtk_widget_get_visible (GTK_WIDGET (text_view)))
1572 gtk_widget_queue_draw (GTK_WIDGET (text_view));
1574 DV(g_print ("Invalidating due to set_buffer\n"));
1575 gtk_text_view_invalidate (text_view);
1578 static GtkTextBuffer*
1579 get_buffer (GtkTextView *text_view)
1581 if (text_view->priv->buffer == NULL)
1584 b = gtk_text_buffer_new (NULL);
1585 gtk_text_view_set_buffer (text_view, b);
1589 return text_view->priv->buffer;
1593 * gtk_text_view_get_buffer:
1594 * @text_view: a #GtkTextView
1596 * Returns the #GtkTextBuffer being displayed by this text view.
1597 * The reference count on the buffer is not incremented; the caller
1598 * of this function won't own a new reference.
1600 * Return value: (transfer none): a #GtkTextBuffer
1603 gtk_text_view_get_buffer (GtkTextView *text_view)
1605 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
1607 return get_buffer (text_view);
1611 * gtk_text_view_get_iter_at_location:
1612 * @text_view: a #GtkTextView
1613 * @iter: (out): a #GtkTextIter
1614 * @x: x position, in buffer coordinates
1615 * @y: y position, in buffer coordinates
1617 * Retrieves the iterator at buffer coordinates @x and @y. Buffer
1618 * coordinates are coordinates for the entire buffer, not just the
1619 * currently-displayed portion. If you have coordinates from an
1620 * event, you have to convert those to buffer coordinates with
1621 * gtk_text_view_window_to_buffer_coords().
1624 gtk_text_view_get_iter_at_location (GtkTextView *text_view,
1629 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1630 g_return_if_fail (iter != NULL);
1632 gtk_text_view_ensure_layout (text_view);
1634 gtk_text_layout_get_iter_at_pixel (text_view->priv->layout,
1639 * gtk_text_view_get_iter_at_position:
1640 * @text_view: a #GtkTextView
1641 * @iter: (out): a #GtkTextIter
1642 * @trailing: (out) (allow-none): if non-%NULL, location to store an integer indicating where
1643 * in the grapheme the user clicked. It will either be
1644 * zero, or the number of characters in the grapheme.
1645 * 0 represents the trailing edge of the grapheme.
1646 * @x: x position, in buffer coordinates
1647 * @y: y position, in buffer coordinates
1649 * Retrieves the iterator pointing to the character at buffer
1650 * coordinates @x and @y. Buffer coordinates are coordinates for
1651 * the entire buffer, not just the currently-displayed portion.
1652 * If you have coordinates from an event, you have to convert
1653 * those to buffer coordinates with
1654 * gtk_text_view_window_to_buffer_coords().
1656 * Note that this is different from gtk_text_view_get_iter_at_location(),
1657 * which returns cursor locations, i.e. positions <emphasis>between</emphasis>
1663 gtk_text_view_get_iter_at_position (GtkTextView *text_view,
1669 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1670 g_return_if_fail (iter != NULL);
1672 gtk_text_view_ensure_layout (text_view);
1674 gtk_text_layout_get_iter_at_position (text_view->priv->layout,
1675 iter, trailing, x, y);
1679 * gtk_text_view_get_iter_location:
1680 * @text_view: a #GtkTextView
1681 * @iter: a #GtkTextIter
1682 * @location: (out): bounds of the character at @iter
1684 * Gets a rectangle which roughly contains the character at @iter.
1685 * The rectangle position is in buffer coordinates; use
1686 * gtk_text_view_buffer_to_window_coords() to convert these
1687 * coordinates to coordinates for one of the windows in the text view.
1690 gtk_text_view_get_iter_location (GtkTextView *text_view,
1691 const GtkTextIter *iter,
1692 GdkRectangle *location)
1694 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1695 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1697 gtk_text_view_ensure_layout (text_view);
1699 gtk_text_layout_get_iter_location (text_view->priv->layout, iter, location);
1703 * gtk_text_view_get_line_yrange:
1704 * @text_view: a #GtkTextView
1705 * @iter: a #GtkTextIter
1706 * @y: (out): return location for a y coordinate
1707 * @height: (out): return location for a height
1709 * Gets the y coordinate of the top of the line containing @iter,
1710 * and the height of the line. The coordinate is a buffer coordinate;
1711 * convert to window coordinates with gtk_text_view_buffer_to_window_coords().
1714 gtk_text_view_get_line_yrange (GtkTextView *text_view,
1715 const GtkTextIter *iter,
1719 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1720 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1722 gtk_text_view_ensure_layout (text_view);
1724 gtk_text_layout_get_line_yrange (text_view->priv->layout,
1731 * gtk_text_view_get_line_at_y:
1732 * @text_view: a #GtkTextView
1733 * @target_iter: (out): a #GtkTextIter
1734 * @y: a y coordinate
1735 * @line_top: (out): return location for top coordinate of the line
1737 * Gets the #GtkTextIter at the start of the line containing
1738 * the coordinate @y. @y is in buffer coordinates, convert from
1739 * window coordinates with gtk_text_view_window_to_buffer_coords().
1740 * If non-%NULL, @line_top will be filled with the coordinate of the top
1744 gtk_text_view_get_line_at_y (GtkTextView *text_view,
1745 GtkTextIter *target_iter,
1749 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1751 gtk_text_view_ensure_layout (text_view);
1753 gtk_text_layout_get_line_at_y (text_view->priv->layout,
1760 set_adjustment_clamped (GtkAdjustment *adj, gdouble val)
1762 DV (g_print (" Setting adj to raw value %g\n", val));
1764 /* We don't really want to clamp to upper; we want to clamp to
1765 upper - page_size which is the highest value the scrollbar
1766 will let us reach. */
1767 if (val > (adj->upper - adj->page_size))
1768 val = adj->upper - adj->page_size;
1770 if (val < adj->lower)
1773 if (val != adj->value)
1775 DV (g_print (" Setting adj to clamped value %g\n", val));
1776 gtk_adjustment_set_value (adj, val);
1784 * gtk_text_view_scroll_to_iter:
1785 * @text_view: a #GtkTextView
1786 * @iter: a #GtkTextIter
1787 * @within_margin: margin as a [0.0,0.5) fraction of screen size
1788 * @use_align: whether to use alignment arguments (if %FALSE,
1789 * just get the mark onscreen)
1790 * @xalign: horizontal alignment of mark within visible area
1791 * @yalign: vertical alignment of mark within visible area
1793 * Scrolls @text_view so that @iter is on the screen in the position
1794 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
1795 * left or top, 1.0 indicates right or bottom, 0.5 means center.
1796 * If @use_align is %FALSE, the text scrolls the minimal distance to
1797 * get the mark onscreen, possibly not scrolling at all. The effective
1798 * screen for purposes of this function is reduced by a margin of size
1801 * Note that this function uses the currently-computed height of the
1802 * lines in the text buffer. Line heights are computed in an idle
1803 * handler; so this function may not have the desired effect if it's
1804 * called before the height computations. To avoid oddness, consider
1805 * using gtk_text_view_scroll_to_mark() which saves a point to be
1806 * scrolled to after line validation.
1808 * Return value: %TRUE if scrolling occurred
1811 gtk_text_view_scroll_to_iter (GtkTextView *text_view,
1813 gdouble within_margin,
1819 GdkRectangle screen;
1824 gboolean retval = FALSE;
1826 gint screen_xoffset, screen_yoffset;
1827 gint current_x_scroll, current_y_scroll;
1829 /* FIXME why don't we do the validate-at-scroll-destination thing
1830 * from flush_scroll in this function? I think it wasn't done before
1831 * because changed_handler was screwed up, but I could be wrong.
1834 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
1835 g_return_val_if_fail (iter != NULL, FALSE);
1836 g_return_val_if_fail (within_margin >= 0.0 && within_margin < 0.5, FALSE);
1837 g_return_val_if_fail (xalign >= 0.0 && xalign <= 1.0, FALSE);
1838 g_return_val_if_fail (yalign >= 0.0 && yalign <= 1.0, FALSE);
1840 widget = GTK_WIDGET (text_view);
1842 DV(g_print(G_STRLOC"\n"));
1844 gtk_text_layout_get_iter_location (text_view->priv->layout,
1848 DV (g_print (" target rect %d,%d %d x %d\n", rect.x, rect.y, rect.width, rect.height));
1850 current_x_scroll = text_view->priv->xoffset;
1851 current_y_scroll = text_view->priv->yoffset;
1853 screen.x = current_x_scroll;
1854 screen.y = current_y_scroll;
1855 screen.width = SCREEN_WIDTH (widget);
1856 screen.height = SCREEN_HEIGHT (widget);
1858 screen_xoffset = screen.width * within_margin;
1859 screen_yoffset = screen.height * within_margin;
1861 screen.x += screen_xoffset;
1862 screen.y += screen_yoffset;
1863 screen.width -= screen_xoffset * 2;
1864 screen.height -= screen_yoffset * 2;
1866 /* paranoia check */
1867 if (screen.width < 1)
1869 if (screen.height < 1)
1872 /* The -1 here ensures that we leave enough space to draw the cursor
1873 * when this function is used for horizontal scrolling.
1875 screen_right = screen.x + screen.width - 1;
1876 screen_bottom = screen.y + screen.height;
1878 /* The alignment affects the point in the target character that we
1879 * choose to align. If we're doing right/bottom alignment, we align
1880 * the right/bottom edge of the character the mark is at; if we're
1881 * doing left/top we align the left/top edge of the character; if
1882 * we're doing center alignment we align the center of the
1886 /* Vertical scroll */
1889 scroll_dest = current_y_scroll;
1893 scroll_dest = rect.y + (rect.height * yalign) - (screen.height * yalign);
1895 /* if scroll_dest < screen.y, we move a negative increment (up),
1896 * else a positive increment (down)
1898 scroll_inc = scroll_dest - screen.y + screen_yoffset;
1902 /* move minimum to get onscreen */
1903 if (rect.y < screen.y)
1905 scroll_dest = rect.y;
1906 scroll_inc = scroll_dest - screen.y - screen_yoffset;
1908 else if ((rect.y + rect.height) > screen_bottom)
1910 scroll_dest = rect.y + rect.height;
1911 scroll_inc = scroll_dest - screen_bottom + screen_yoffset;
1915 if (scroll_inc != 0)
1917 retval = set_adjustment_clamped (get_vadjustment (text_view),
1918 current_y_scroll + scroll_inc);
1920 DV (g_print (" vert increment %d\n", scroll_inc));
1923 /* Horizontal scroll */
1926 scroll_dest = current_x_scroll;
1930 scroll_dest = rect.x + (rect.width * xalign) - (screen.width * xalign);
1932 /* if scroll_dest < screen.y, we move a negative increment (left),
1933 * else a positive increment (right)
1935 scroll_inc = scroll_dest - screen.x + screen_xoffset;
1939 /* move minimum to get onscreen */
1940 if (rect.x < screen.x)
1942 scroll_dest = rect.x;
1943 scroll_inc = scroll_dest - screen.x - screen_xoffset;
1945 else if ((rect.x + rect.width) > screen_right)
1947 scroll_dest = rect.x + rect.width;
1948 scroll_inc = scroll_dest - screen_right + screen_xoffset;
1952 if (scroll_inc != 0)
1954 retval = set_adjustment_clamped (get_hadjustment (text_view),
1955 current_x_scroll + scroll_inc);
1957 DV (g_print (" horiz increment %d\n", scroll_inc));
1962 DV(g_print (">Actually scrolled ("G_STRLOC")\n"));
1966 DV(g_print (">Didn't end up scrolling ("G_STRLOC")\n"));
1973 free_pending_scroll (GtkTextPendingScroll *scroll)
1975 if (!gtk_text_mark_get_deleted (scroll->mark))
1976 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (scroll->mark),
1978 g_object_unref (scroll->mark);
1983 cancel_pending_scroll (GtkTextView *text_view)
1985 if (text_view->priv->pending_scroll)
1987 free_pending_scroll (text_view->priv->pending_scroll);
1988 text_view->priv->pending_scroll = NULL;
1993 gtk_text_view_queue_scroll (GtkTextView *text_view,
1995 gdouble within_margin,
2001 GtkTextPendingScroll *scroll;
2003 DV(g_print(G_STRLOC"\n"));
2005 scroll = g_new (GtkTextPendingScroll, 1);
2007 scroll->within_margin = within_margin;
2008 scroll->use_align = use_align;
2009 scroll->xalign = xalign;
2010 scroll->yalign = yalign;
2012 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2014 scroll->mark = gtk_text_buffer_create_mark (get_buffer (text_view),
2017 gtk_text_mark_get_left_gravity (mark));
2019 g_object_ref (scroll->mark);
2021 cancel_pending_scroll (text_view);
2023 text_view->priv->pending_scroll = scroll;
2027 gtk_text_view_flush_scroll (GtkTextView *text_view)
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_text_layout_validate_yrange (text_view->priv->layout, &iter,
2060 - (widget->allocation.height * 2),
2061 widget->allocation.height * 2);
2063 DV(g_print (">Done validating scroll destination ("G_STRLOC")\n"));
2065 /* Ensure we have updated width/height */
2066 gtk_text_view_update_adjustments (text_view);
2068 retval = gtk_text_view_scroll_to_iter (text_view,
2070 scroll->within_margin,
2075 free_pending_scroll (scroll);
2081 gtk_text_view_set_adjustment_upper (GtkAdjustment *adj, gdouble upper)
2083 if (upper != adj->upper)
2085 gdouble min = MAX (0.0, upper - adj->page_size);
2086 gboolean value_changed = FALSE;
2090 if (adj->value > min)
2093 value_changed = TRUE;
2096 gtk_adjustment_changed (adj);
2097 DV(g_print(">Changed adj upper to %g ("G_STRLOC")\n", upper));
2101 DV(g_print(">Changed adj value because upper decreased ("G_STRLOC")\n"));
2102 gtk_adjustment_value_changed (adj);
2108 gtk_text_view_update_adjustments (GtkTextView *text_view)
2110 GtkTextViewPrivate *priv;
2111 gint width = 0, height = 0;
2113 DV(g_print(">Updating adjustments ("G_STRLOC")\n"));
2115 priv = text_view->priv;
2118 gtk_text_layout_get_size (priv->layout, &width, &height);
2120 /* Make room for the cursor after the last character in the widest line */
2121 width += SPACE_FOR_CURSOR;
2123 if (priv->width != width || priv->height != height)
2125 if (priv->width != width)
2126 priv->width_changed = TRUE;
2128 priv->width = width;
2129 priv->height = height;
2131 gtk_text_view_set_adjustment_upper (get_hadjustment (text_view),
2132 MAX (SCREEN_WIDTH (text_view), width));
2133 gtk_text_view_set_adjustment_upper (get_vadjustment (text_view),
2134 MAX (SCREEN_HEIGHT (text_view), height));
2136 /* hadj/vadj exist since we called get_hadjustment/get_vadjustment above */
2138 /* Set up the step sizes; we'll say that a page is
2139 our allocation minus one step, and a step is
2140 1/10 of our allocation. */
2141 priv->hadjustment->step_increment =
2142 SCREEN_WIDTH (text_view) / 10.0;
2143 priv->hadjustment->page_increment =
2144 SCREEN_WIDTH (text_view) * 0.9;
2146 priv->vadjustment->step_increment =
2147 SCREEN_HEIGHT (text_view) / 10.0;
2148 priv->vadjustment->page_increment =
2149 SCREEN_HEIGHT (text_view) * 0.9;
2151 gtk_adjustment_changed (get_hadjustment (text_view));
2152 gtk_adjustment_changed (get_vadjustment (text_view));
2157 gtk_text_view_update_layout_width (GtkTextView *text_view)
2159 DV(g_print(">Updating layout width ("G_STRLOC")\n"));
2161 gtk_text_view_ensure_layout (text_view);
2163 gtk_text_layout_set_screen_width (text_view->priv->layout,
2164 MAX (1, SCREEN_WIDTH (text_view) - SPACE_FOR_CURSOR));
2168 gtk_text_view_update_im_spot_location (GtkTextView *text_view)
2172 if (text_view->priv->layout == NULL)
2175 gtk_text_view_get_cursor_location (text_view, &area);
2177 area.x -= text_view->priv->xoffset;
2178 area.y -= text_view->priv->yoffset;
2180 /* Width returned by Pango indicates direction of cursor,
2181 * by it's sign more than the size of cursor.
2185 gtk_im_context_set_cursor_location (text_view->priv->im_context, &area);
2189 do_update_im_spot_location (gpointer text_view)
2191 GtkTextViewPrivate *priv;
2193 priv = GTK_TEXT_VIEW (text_view)->priv;
2194 priv->im_spot_idle = 0;
2196 gtk_text_view_update_im_spot_location (text_view);
2201 queue_update_im_spot_location (GtkTextView *text_view)
2203 GtkTextViewPrivate *priv;
2205 priv = text_view->priv;
2207 /* Use priority a little higher than GTK_TEXT_VIEW_PRIORITY_VALIDATE,
2208 * so we don't wait until the entire buffer has been validated. */
2209 if (!priv->im_spot_idle)
2210 priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
2211 do_update_im_spot_location,
2217 flush_update_im_spot_location (GtkTextView *text_view)
2219 GtkTextViewPrivate *priv;
2221 priv = text_view->priv;
2223 if (priv->im_spot_idle)
2225 g_source_remove (priv->im_spot_idle);
2226 priv->im_spot_idle = 0;
2227 gtk_text_view_update_im_spot_location (text_view);
2232 * gtk_text_view_scroll_to_mark:
2233 * @text_view: a #GtkTextView
2234 * @mark: a #GtkTextMark
2235 * @within_margin: margin as a [0.0,0.5) fraction of screen size
2236 * @use_align: whether to use alignment arguments (if %FALSE, just
2237 * get the mark onscreen)
2238 * @xalign: horizontal alignment of mark within visible area
2239 * @yalign: vertical alignment of mark within visible area
2241 * Scrolls @text_view so that @mark is on the screen in the position
2242 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
2243 * left or top, 1.0 indicates right or bottom, 0.5 means center.
2244 * If @use_align is %FALSE, the text scrolls the minimal distance to
2245 * get the mark onscreen, possibly not scrolling at all. The effective
2246 * screen for purposes of this function is reduced by a margin of size
2250 gtk_text_view_scroll_to_mark (GtkTextView *text_view,
2252 gdouble within_margin,
2257 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2258 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2259 g_return_if_fail (within_margin >= 0.0 && within_margin < 0.5);
2260 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
2261 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
2263 /* We need to verify that the buffer contains the mark, otherwise this
2264 * can lead to data structure corruption later on.
2266 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2268 gtk_text_view_queue_scroll (text_view, mark,
2274 /* If no validation is pending, we need to go ahead and force an
2277 if (text_view->priv->layout &&
2278 gtk_text_layout_is_valid (text_view->priv->layout))
2279 gtk_text_view_flush_scroll (text_view);
2283 * gtk_text_view_scroll_mark_onscreen:
2284 * @text_view: a #GtkTextView
2285 * @mark: a mark in the buffer for @text_view
2287 * Scrolls @text_view the minimum distance such that @mark is contained
2288 * within the visible area of the widget.
2291 gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
2294 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2295 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2297 /* We need to verify that the buffer contains the mark, otherwise this
2298 * can lead to data structure corruption later on.
2300 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2302 gtk_text_view_scroll_to_mark (text_view, mark, 0.0, FALSE, 0.0, 0.0);
2306 clamp_iter_onscreen (GtkTextView *text_view, GtkTextIter *iter)
2308 GdkRectangle visible_rect;
2309 gtk_text_view_get_visible_rect (text_view, &visible_rect);
2311 return gtk_text_layout_clamp_iter_to_vrange (text_view->priv->layout, iter,
2313 visible_rect.y + visible_rect.height);
2317 * gtk_text_view_move_mark_onscreen:
2318 * @text_view: a #GtkTextView
2319 * @mark: a #GtkTextMark
2321 * Moves a mark within the buffer so that it's
2322 * located within the currently-visible text area.
2324 * Return value: %TRUE if the mark moved (wasn't already onscreen)
2327 gtk_text_view_move_mark_onscreen (GtkTextView *text_view,
2332 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2333 g_return_val_if_fail (mark != NULL, FALSE);
2335 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2337 if (clamp_iter_onscreen (text_view, &iter))
2339 gtk_text_buffer_move_mark (get_buffer (text_view), mark, &iter);
2347 * gtk_text_view_get_visible_rect:
2348 * @text_view: a #GtkTextView
2349 * @visible_rect: rectangle to fill
2351 * Fills @visible_rect with the currently-visible
2352 * region of the buffer, in buffer coordinates. Convert to window coordinates
2353 * with gtk_text_view_buffer_to_window_coords().
2356 gtk_text_view_get_visible_rect (GtkTextView *text_view,
2357 GdkRectangle *visible_rect)
2361 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2363 widget = GTK_WIDGET (text_view);
2367 visible_rect->x = text_view->priv->xoffset;
2368 visible_rect->y = text_view->priv->yoffset;
2369 visible_rect->width = SCREEN_WIDTH (widget);
2370 visible_rect->height = SCREEN_HEIGHT (widget);
2372 DV(g_print(" visible rect: %d,%d %d x %d\n",
2375 visible_rect->width,
2376 visible_rect->height));
2381 * gtk_text_view_set_wrap_mode:
2382 * @text_view: a #GtkTextView
2383 * @wrap_mode: a #GtkWrapMode
2385 * Sets the line wrapping for the view.
2388 gtk_text_view_set_wrap_mode (GtkTextView *text_view,
2389 GtkWrapMode wrap_mode)
2391 GtkTextViewPrivate *priv;
2393 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2395 priv = text_view->priv;
2397 if (priv->wrap_mode != wrap_mode)
2399 priv->wrap_mode = wrap_mode;
2403 priv->layout->default_style->wrap_mode = wrap_mode;
2404 gtk_text_layout_default_style_changed (priv->layout);
2408 g_object_notify (G_OBJECT (text_view), "wrap-mode");
2412 * gtk_text_view_get_wrap_mode:
2413 * @text_view: a #GtkTextView
2415 * Gets the line wrapping for the view.
2417 * Return value: the line wrap setting
2420 gtk_text_view_get_wrap_mode (GtkTextView *text_view)
2422 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_WRAP_NONE);
2424 return text_view->priv->wrap_mode;
2428 * gtk_text_view_set_editable:
2429 * @text_view: a #GtkTextView
2430 * @setting: whether it's editable
2432 * Sets the default editability of the #GtkTextView. You can override
2433 * this default setting with tags in the buffer, using the "editable"
2434 * attribute of tags.
2437 gtk_text_view_set_editable (GtkTextView *text_view,
2440 GtkTextViewPrivate *priv;
2442 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2444 priv = text_view->priv;
2445 setting = setting != FALSE;
2447 if (priv->editable != setting)
2451 gtk_text_view_reset_im_context(text_view);
2452 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2453 gtk_im_context_focus_out (priv->im_context);
2456 priv->editable = setting;
2458 if (setting && gtk_widget_has_focus (GTK_WIDGET (text_view)))
2459 gtk_im_context_focus_in (priv->im_context);
2463 gtk_text_layout_set_overwrite_mode (priv->layout,
2464 priv->overwrite_mode && priv->editable);
2465 priv->layout->default_style->editable = priv->editable;
2466 gtk_text_layout_default_style_changed (priv->layout);
2469 g_object_notify (G_OBJECT (text_view), "editable");
2474 * gtk_text_view_get_editable:
2475 * @text_view: a #GtkTextView
2477 * Returns the default editability of the #GtkTextView. Tags in the
2478 * buffer may override this setting for some ranges of text.
2480 * Return value: whether text is editable by default
2483 gtk_text_view_get_editable (GtkTextView *text_view)
2485 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2487 return text_view->priv->editable;
2491 * gtk_text_view_set_pixels_above_lines:
2492 * @text_view: a #GtkTextView
2493 * @pixels_above_lines: pixels above paragraphs
2495 * Sets the default number of blank pixels above paragraphs in @text_view.
2496 * Tags in the buffer for @text_view may override the defaults.
2499 gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
2500 gint pixels_above_lines)
2502 GtkTextViewPrivate *priv;
2504 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2506 priv = text_view->priv;
2508 if (priv->pixels_above_lines != pixels_above_lines)
2510 priv->pixels_above_lines = pixels_above_lines;
2514 priv->layout->default_style->pixels_above_lines = pixels_above_lines;
2515 gtk_text_layout_default_style_changed (priv->layout);
2518 g_object_notify (G_OBJECT (text_view), "pixels-above-lines");
2523 * gtk_text_view_get_pixels_above_lines:
2524 * @text_view: a #GtkTextView
2526 * Gets the default number of pixels to put above paragraphs.
2528 * Return value: default number of pixels above paragraphs
2531 gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
2533 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2535 return text_view->priv->pixels_above_lines;
2539 * gtk_text_view_set_pixels_below_lines:
2540 * @text_view: a #GtkTextView
2541 * @pixels_below_lines: pixels below paragraphs
2543 * Sets the default number of pixels of blank space
2544 * to put below paragraphs in @text_view. May be overridden
2545 * by tags applied to @text_view's buffer.
2548 gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
2549 gint pixels_below_lines)
2551 GtkTextViewPrivate *priv;
2553 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2555 priv = text_view->priv;
2557 if (priv->pixels_below_lines != pixels_below_lines)
2559 priv->pixels_below_lines = pixels_below_lines;
2563 priv->layout->default_style->pixels_below_lines = pixels_below_lines;
2564 gtk_text_layout_default_style_changed (priv->layout);
2567 g_object_notify (G_OBJECT (text_view), "pixels-below-lines");
2572 * gtk_text_view_get_pixels_below_lines:
2573 * @text_view: a #GtkTextView
2575 * Gets the value set by gtk_text_view_set_pixels_below_lines().
2577 * Return value: default number of blank pixels below paragraphs
2580 gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
2582 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2584 return text_view->priv->pixels_below_lines;
2588 * gtk_text_view_set_pixels_inside_wrap:
2589 * @text_view: a #GtkTextView
2590 * @pixels_inside_wrap: default number of pixels between wrapped lines
2592 * Sets the default number of pixels of blank space to leave between
2593 * display/wrapped lines within a paragraph. May be overridden by
2594 * tags in @text_view's buffer.
2597 gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
2598 gint pixels_inside_wrap)
2600 GtkTextViewPrivate *priv;
2602 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2604 priv = text_view->priv;
2606 if (priv->pixels_inside_wrap != pixels_inside_wrap)
2608 priv->pixels_inside_wrap = pixels_inside_wrap;
2612 priv->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
2613 gtk_text_layout_default_style_changed (priv->layout);
2616 g_object_notify (G_OBJECT (text_view), "pixels-inside-wrap");
2621 * gtk_text_view_get_pixels_inside_wrap:
2622 * @text_view: a #GtkTextView
2624 * Gets the value set by gtk_text_view_set_pixels_inside_wrap().
2626 * Return value: default number of pixels of blank space between wrapped lines
2629 gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
2631 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2633 return text_view->priv->pixels_inside_wrap;
2637 * gtk_text_view_set_justification:
2638 * @text_view: a #GtkTextView
2639 * @justification: justification
2641 * Sets the default justification of text in @text_view.
2642 * Tags in the view's buffer may override the default.
2646 gtk_text_view_set_justification (GtkTextView *text_view,
2647 GtkJustification justification)
2649 GtkTextViewPrivate *priv;
2651 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2653 priv = text_view->priv;
2655 if (priv->justify != justification)
2657 priv->justify = justification;
2661 priv->layout->default_style->justification = justification;
2662 gtk_text_layout_default_style_changed (priv->layout);
2665 g_object_notify (G_OBJECT (text_view), "justification");
2670 * gtk_text_view_get_justification:
2671 * @text_view: a #GtkTextView
2673 * Gets the default justification of paragraphs in @text_view.
2674 * Tags in the buffer may override the default.
2676 * Return value: default justification
2679 gtk_text_view_get_justification (GtkTextView *text_view)
2681 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_JUSTIFY_LEFT);
2683 return text_view->priv->justify;
2687 * gtk_text_view_set_left_margin:
2688 * @text_view: a #GtkTextView
2689 * @left_margin: left margin in pixels
2691 * Sets the default left margin for text in @text_view.
2692 * Tags in the buffer may override the default.
2695 gtk_text_view_set_left_margin (GtkTextView *text_view,
2698 GtkTextViewPrivate *priv;
2700 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2702 priv = text_view->priv;
2704 if (priv->left_margin != left_margin)
2706 priv->left_margin = left_margin;
2710 priv->layout->default_style->left_margin = left_margin;
2711 gtk_text_layout_default_style_changed (priv->layout);
2714 g_object_notify (G_OBJECT (text_view), "left-margin");
2719 * gtk_text_view_get_left_margin:
2720 * @text_view: a #GtkTextView
2722 * Gets the default left margin size of paragraphs in the @text_view.
2723 * Tags in the buffer may override the default.
2725 * Return value: left margin in pixels
2728 gtk_text_view_get_left_margin (GtkTextView *text_view)
2730 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2732 return text_view->priv->left_margin;
2736 * gtk_text_view_set_right_margin:
2737 * @text_view: a #GtkTextView
2738 * @right_margin: right margin in pixels
2740 * Sets the default right margin for text in the text view.
2741 * Tags in the buffer may override the default.
2744 gtk_text_view_set_right_margin (GtkTextView *text_view,
2747 GtkTextViewPrivate *priv = text_view->priv;
2749 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2751 if (priv->right_margin != right_margin)
2753 priv->right_margin = right_margin;
2757 priv->layout->default_style->right_margin = right_margin;
2758 gtk_text_layout_default_style_changed (priv->layout);
2761 g_object_notify (G_OBJECT (text_view), "right-margin");
2766 * gtk_text_view_get_right_margin:
2767 * @text_view: a #GtkTextView
2769 * Gets the default right margin for text in @text_view. Tags
2770 * in the buffer may override the default.
2772 * Return value: right margin in pixels
2775 gtk_text_view_get_right_margin (GtkTextView *text_view)
2777 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2779 return text_view->priv->right_margin;
2783 * gtk_text_view_set_indent:
2784 * @text_view: a #GtkTextView
2785 * @indent: indentation in pixels
2787 * Sets the default indentation for paragraphs in @text_view.
2788 * Tags in the buffer may override the default.
2791 gtk_text_view_set_indent (GtkTextView *text_view,
2794 GtkTextViewPrivate *priv;
2796 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2798 priv = text_view->priv;
2800 if (priv->indent != indent)
2802 priv->indent = indent;
2806 priv->layout->default_style->indent = indent;
2807 gtk_text_layout_default_style_changed (priv->layout);
2810 g_object_notify (G_OBJECT (text_view), "indent");
2815 * gtk_text_view_get_indent:
2816 * @text_view: a #GtkTextView
2818 * Gets the default indentation of paragraphs in @text_view.
2819 * Tags in the view's buffer may override the default.
2820 * The indentation may be negative.
2822 * Return value: number of pixels of indentation
2825 gtk_text_view_get_indent (GtkTextView *text_view)
2827 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2829 return text_view->priv->indent;
2833 * gtk_text_view_set_tabs:
2834 * @text_view: a #GtkTextView
2835 * @tabs: tabs as a #PangoTabArray
2837 * Sets the default tab stops for paragraphs in @text_view.
2838 * Tags in the buffer may override the default.
2841 gtk_text_view_set_tabs (GtkTextView *text_view,
2842 PangoTabArray *tabs)
2844 GtkTextViewPrivate *priv;
2846 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2848 priv = text_view->priv;
2851 pango_tab_array_free (priv->tabs);
2853 priv->tabs = tabs ? pango_tab_array_copy (tabs) : NULL;
2857 /* some unkosher futzing in internal struct details... */
2858 if (priv->layout->default_style->tabs)
2859 pango_tab_array_free (priv->layout->default_style->tabs);
2861 priv->layout->default_style->tabs =
2862 priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
2864 gtk_text_layout_default_style_changed (priv->layout);
2867 g_object_notify (G_OBJECT (text_view), "tabs");
2871 * gtk_text_view_get_tabs:
2872 * @text_view: a #GtkTextView
2874 * Gets the default tabs for @text_view. Tags in the buffer may
2875 * override the defaults. The returned array will be %NULL if
2876 * "standard" (8-space) tabs are used. Free the return value
2877 * with pango_tab_array_free().
2879 * Return value: copy of default tab array, or %NULL if "standard"
2880 * tabs are used; must be freed with pango_tab_array_free().
2883 gtk_text_view_get_tabs (GtkTextView *text_view)
2885 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
2887 return text_view->priv->tabs ? pango_tab_array_copy (text_view->priv->tabs) : NULL;
2891 gtk_text_view_toggle_cursor_visible (GtkTextView *text_view)
2893 gtk_text_view_set_cursor_visible (text_view, !text_view->priv->cursor_visible);
2897 * gtk_text_view_set_cursor_visible:
2898 * @text_view: a #GtkTextView
2899 * @setting: whether to show the insertion cursor
2901 * Toggles whether the insertion point is displayed. A buffer with no editable
2902 * text probably shouldn't have a visible cursor, so you may want to turn
2906 gtk_text_view_set_cursor_visible (GtkTextView *text_view,
2909 GtkTextViewPrivate *priv;
2911 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2913 priv = text_view->priv;
2914 setting = (setting != FALSE);
2916 if (priv->cursor_visible != setting)
2918 priv->cursor_visible = setting;
2920 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2924 gtk_text_layout_set_cursor_visible (priv->layout, setting);
2925 gtk_text_view_check_cursor_blink (text_view);
2929 g_object_notify (G_OBJECT (text_view), "cursor-visible");
2934 * gtk_text_view_get_cursor_visible:
2935 * @text_view: a #GtkTextView
2937 * Find out whether the cursor is being displayed.
2939 * Return value: whether the insertion mark is visible
2942 gtk_text_view_get_cursor_visible (GtkTextView *text_view)
2944 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2946 return text_view->priv->cursor_visible;
2951 * gtk_text_view_place_cursor_onscreen:
2952 * @text_view: a #GtkTextView
2954 * Moves the cursor to the currently visible region of the
2955 * buffer, it it isn't there already.
2957 * Return value: %TRUE if the cursor had to be moved.
2960 gtk_text_view_place_cursor_onscreen (GtkTextView *text_view)
2964 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2966 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
2967 gtk_text_buffer_get_insert (get_buffer (text_view)));
2969 if (clamp_iter_onscreen (text_view, &insert))
2971 gtk_text_buffer_place_cursor (get_buffer (text_view), &insert);
2979 gtk_text_view_remove_validate_idles (GtkTextView *text_view)
2981 GtkTextViewPrivate *priv = text_view->priv;
2983 if (priv->first_validate_idle != 0)
2985 DV (g_print ("Removing first validate idle: %s\n", G_STRLOC));
2986 g_source_remove (priv->first_validate_idle);
2987 priv->first_validate_idle = 0;
2990 if (priv->incremental_validate_idle != 0)
2992 g_source_remove (priv->incremental_validate_idle);
2993 priv->incremental_validate_idle = 0;
2998 gtk_text_view_destroy (GtkObject *object)
3000 GtkTextView *text_view;
3001 GtkTextViewPrivate *priv;
3003 text_view = GTK_TEXT_VIEW (object);
3004 priv = text_view->priv;
3006 gtk_text_view_remove_validate_idles (text_view);
3007 gtk_text_view_set_buffer (text_view, NULL);
3008 gtk_text_view_destroy_layout (text_view);
3010 if (text_view->priv->scroll_timeout)
3012 g_source_remove (text_view->priv->scroll_timeout);
3013 text_view->priv->scroll_timeout = 0;
3016 if (priv->im_spot_idle)
3018 g_source_remove (priv->im_spot_idle);
3019 priv->im_spot_idle = 0;
3022 GTK_OBJECT_CLASS (gtk_text_view_parent_class)->destroy (object);
3026 gtk_text_view_finalize (GObject *object)
3028 GtkTextView *text_view;
3029 GtkTextViewPrivate *priv;
3031 text_view = GTK_TEXT_VIEW (object);
3032 priv = text_view->priv;
3034 g_assert (priv->buffer == NULL);
3036 gtk_text_view_destroy_layout (text_view);
3037 gtk_text_view_set_buffer (text_view, NULL);
3039 cancel_pending_scroll (text_view);
3042 pango_tab_array_free (priv->tabs);
3044 if (priv->hadjustment)
3045 g_object_unref (priv->hadjustment);
3046 if (priv->vadjustment)
3047 g_object_unref (priv->vadjustment);
3049 text_window_free (priv->text_window);
3051 if (priv->left_window)
3052 text_window_free (priv->left_window);
3054 if (priv->top_window)
3055 text_window_free (priv->top_window);
3057 if (priv->right_window)
3058 text_window_free (priv->right_window);
3060 if (priv->bottom_window)
3061 text_window_free (priv->bottom_window);
3063 g_object_unref (priv->im_context);
3065 g_free (priv->im_module);
3067 G_OBJECT_CLASS (gtk_text_view_parent_class)->finalize (object);
3071 gtk_text_view_set_property (GObject *object,
3073 const GValue *value,
3076 GtkTextView *text_view;
3077 GtkTextViewPrivate *priv;
3079 text_view = GTK_TEXT_VIEW (object);
3080 priv = text_view->priv;
3084 case PROP_PIXELS_ABOVE_LINES:
3085 gtk_text_view_set_pixels_above_lines (text_view, g_value_get_int (value));
3088 case PROP_PIXELS_BELOW_LINES:
3089 gtk_text_view_set_pixels_below_lines (text_view, g_value_get_int (value));
3092 case PROP_PIXELS_INSIDE_WRAP:
3093 gtk_text_view_set_pixels_inside_wrap (text_view, g_value_get_int (value));
3097 gtk_text_view_set_editable (text_view, g_value_get_boolean (value));
3100 case PROP_WRAP_MODE:
3101 gtk_text_view_set_wrap_mode (text_view, g_value_get_enum (value));
3104 case PROP_JUSTIFICATION:
3105 gtk_text_view_set_justification (text_view, g_value_get_enum (value));
3108 case PROP_LEFT_MARGIN:
3109 gtk_text_view_set_left_margin (text_view, g_value_get_int (value));
3112 case PROP_RIGHT_MARGIN:
3113 gtk_text_view_set_right_margin (text_view, g_value_get_int (value));
3117 gtk_text_view_set_indent (text_view, g_value_get_int (value));
3121 gtk_text_view_set_tabs (text_view, g_value_get_boxed (value));
3124 case PROP_CURSOR_VISIBLE:
3125 gtk_text_view_set_cursor_visible (text_view, g_value_get_boolean (value));
3128 case PROP_OVERWRITE:
3129 gtk_text_view_set_overwrite (text_view, g_value_get_boolean (value));
3133 gtk_text_view_set_buffer (text_view, GTK_TEXT_BUFFER (g_value_get_object (value)));
3136 case PROP_ACCEPTS_TAB:
3137 gtk_text_view_set_accepts_tab (text_view, g_value_get_boolean (value));
3140 case PROP_IM_MODULE:
3141 g_free (priv->im_module);
3142 priv->im_module = g_value_dup_string (value);
3143 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
3144 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
3148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3154 gtk_text_view_get_property (GObject *object,
3159 GtkTextView *text_view;
3160 GtkTextViewPrivate *priv;
3162 text_view = GTK_TEXT_VIEW (object);
3163 priv = text_view->priv;
3167 case PROP_PIXELS_ABOVE_LINES:
3168 g_value_set_int (value, priv->pixels_above_lines);
3171 case PROP_PIXELS_BELOW_LINES:
3172 g_value_set_int (value, priv->pixels_below_lines);
3175 case PROP_PIXELS_INSIDE_WRAP:
3176 g_value_set_int (value, priv->pixels_inside_wrap);
3180 g_value_set_boolean (value, priv->editable);
3183 case PROP_WRAP_MODE:
3184 g_value_set_enum (value, priv->wrap_mode);
3187 case PROP_JUSTIFICATION:
3188 g_value_set_enum (value, priv->justify);
3191 case PROP_LEFT_MARGIN:
3192 g_value_set_int (value, priv->left_margin);
3195 case PROP_RIGHT_MARGIN:
3196 g_value_set_int (value, priv->right_margin);
3200 g_value_set_int (value, priv->indent);
3204 g_value_set_boxed (value, priv->tabs);
3207 case PROP_CURSOR_VISIBLE:
3208 g_value_set_boolean (value, priv->cursor_visible);
3212 g_value_set_object (value, get_buffer (text_view));
3215 case PROP_OVERWRITE:
3216 g_value_set_boolean (value, priv->overwrite_mode);
3219 case PROP_ACCEPTS_TAB:
3220 g_value_set_boolean (value, priv->accepts_tab);
3223 case PROP_IM_MODULE:
3224 g_value_set_string (value, priv->im_module);
3228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3234 gtk_text_view_size_request (GtkWidget *widget,
3235 GtkRequisition *requisition)
3237 GtkTextView *text_view;
3238 GtkTextViewPrivate *priv;
3240 gint focus_edge_width;
3243 gboolean interior_focus;
3245 text_view = GTK_TEXT_VIEW (widget);
3246 priv = text_view->priv;
3248 gtk_widget_style_get (widget,
3249 "interior-focus", &interior_focus,
3250 "focus-line-width", &focus_width,
3254 focus_edge_width = 0;
3256 focus_edge_width = focus_width;
3260 priv->text_window->requisition.width = priv->layout->width;
3261 priv->text_window->requisition.height = priv->layout->height;
3265 priv->text_window->requisition.width = 0;
3266 priv->text_window->requisition.height = 0;
3269 requisition->width = priv->text_window->requisition.width + focus_edge_width * 2;
3270 requisition->height = priv->text_window->requisition.height + focus_edge_width * 2;
3272 if (priv->left_window)
3273 requisition->width += priv->left_window->requisition.width;
3275 if (priv->right_window)
3276 requisition->width += priv->right_window->requisition.width;
3278 if (priv->top_window)
3279 requisition->height += priv->top_window->requisition.height;
3281 if (priv->bottom_window)
3282 requisition->height += priv->bottom_window->requisition.height;
3284 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3285 requisition->width += border_width * 2;
3286 requisition->height += border_width * 2;
3288 tmp_list = priv->children;
3289 while (tmp_list != NULL)
3291 GtkTextViewChild *child = tmp_list->data;
3295 GtkRequisition child_req;
3296 GtkRequisition old_req;
3298 gtk_widget_get_child_requisition (child->widget, &old_req);
3300 gtk_widget_size_request (child->widget, &child_req);
3302 gtk_widget_get_child_requisition (child->widget, &child_req);
3304 /* Invalidate layout lines if required */
3306 (old_req.width != child_req.width ||
3307 old_req.height != child_req.height))
3308 gtk_text_child_anchor_queue_resize (child->anchor,
3313 GtkRequisition child_req;
3315 gtk_widget_size_request (child->widget, &child_req);
3318 tmp_list = g_slist_next (tmp_list);
3323 gtk_text_view_compute_child_allocation (GtkTextView *text_view,
3324 GtkTextViewChild *vc,
3325 GtkAllocation *allocation)
3331 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3335 gtk_text_layout_get_line_yrange (text_view->priv->layout, &iter,
3338 buffer_y += vc->from_top_of_line;
3340 allocation->x = vc->from_left_of_buffer - text_view->priv->xoffset;
3341 allocation->y = buffer_y - text_view->priv->yoffset;
3343 gtk_widget_get_child_requisition (vc->widget, &req);
3344 allocation->width = req.width;
3345 allocation->height = req.height;
3349 gtk_text_view_update_child_allocation (GtkTextView *text_view,
3350 GtkTextViewChild *vc)
3352 GtkAllocation allocation;
3354 gtk_text_view_compute_child_allocation (text_view, vc, &allocation);
3356 gtk_widget_size_allocate (vc->widget, &allocation);
3359 g_print ("allocation for %p allocated to %d,%d yoffset = %d\n",
3361 vc->widget->allocation.x,
3362 vc->widget->allocation.y,
3363 text_view->priv->yoffset);
3368 gtk_text_view_child_allocated (GtkTextLayout *layout,
3374 GtkTextViewChild *vc = NULL;
3375 GtkTextView *text_view = data;
3377 /* x,y is the position of the child from the top of the line, and
3378 * from the left of the buffer. We have to translate that into text
3379 * window coordinates, then size_allocate the child.
3382 vc = g_object_get_data (G_OBJECT (child),
3383 "gtk-text-view-child");
3385 g_assert (vc != NULL);
3387 DV (g_print ("child allocated at %d,%d\n", x, y));
3389 vc->from_left_of_buffer = x;
3390 vc->from_top_of_line = y;
3392 gtk_text_view_update_child_allocation (text_view, vc);
3396 gtk_text_view_allocate_children (GtkTextView *text_view)
3400 DV(g_print(G_STRLOC"\n"));
3402 tmp_list = text_view->priv->children;
3403 while (tmp_list != NULL)
3405 GtkTextViewChild *child = tmp_list->data;
3407 g_assert (child != NULL);
3411 /* We need to force-validate the regions containing
3414 GtkTextIter child_loc;
3415 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3419 /* Since anchored children are only ever allocated from
3420 * gtk_text_layout_get_line_display() we have to make sure
3421 * that the display line caching in the layout doesn't
3422 * get in the way. Invalidating the layout around the anchor
3425 if (GTK_WIDGET_ALLOC_NEEDED (child->widget))
3427 GtkTextIter end = child_loc;
3428 gtk_text_iter_forward_char (&end);
3429 gtk_text_layout_invalidate (text_view->priv->layout, &child_loc, &end);
3432 gtk_text_layout_validate_yrange (text_view->priv->layout,
3438 GtkAllocation allocation;
3439 GtkRequisition child_req;
3441 allocation.x = child->x;
3442 allocation.y = child->y;
3444 gtk_widget_get_child_requisition (child->widget, &child_req);
3446 allocation.width = child_req.width;
3447 allocation.height = child_req.height;
3449 gtk_widget_size_allocate (child->widget, &allocation);
3452 tmp_list = g_slist_next (tmp_list);
3457 gtk_text_view_size_allocate (GtkWidget *widget,
3458 GtkAllocation *allocation)
3460 GtkTextView *text_view;
3461 GtkTextViewPrivate *priv;
3462 GtkTextIter first_para;
3465 GdkRectangle text_rect;
3466 GdkRectangle left_rect;
3467 GdkRectangle right_rect;
3468 GdkRectangle top_rect;
3469 GdkRectangle bottom_rect;
3470 gint focus_edge_width;
3473 gboolean interior_focus;
3474 gboolean size_changed;
3476 text_view = GTK_TEXT_VIEW (widget);
3477 priv = text_view->priv;
3479 DV(g_print(G_STRLOC"\n"));
3482 widget->allocation.width != allocation->width ||
3483 widget->allocation.height != allocation->height;
3485 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3487 widget->allocation = *allocation;
3489 if (gtk_widget_get_realized (widget))
3491 gdk_window_move_resize (widget->window,
3492 allocation->x, allocation->y,
3493 allocation->width, allocation->height);
3496 /* distribute width/height among child windows. Ensure all
3497 * windows get at least a 1x1 allocation.
3500 gtk_widget_style_get (widget,
3501 "interior-focus", &interior_focus,
3502 "focus-line-width", &focus_width,
3506 focus_edge_width = 0;
3508 focus_edge_width = focus_width;
3510 width = allocation->width - focus_edge_width * 2 - border_width * 2;
3512 if (priv->left_window)
3513 left_rect.width = priv->left_window->requisition.width;
3515 left_rect.width = 0;
3517 width -= left_rect.width;
3519 if (priv->right_window)
3520 right_rect.width = priv->right_window->requisition.width;
3522 right_rect.width = 0;
3524 width -= right_rect.width;
3526 text_rect.width = MAX (1, width);
3528 top_rect.width = text_rect.width;
3529 bottom_rect.width = text_rect.width;
3532 height = allocation->height - focus_edge_width * 2 - border_width * 2;
3534 if (priv->top_window)
3535 top_rect.height = priv->top_window->requisition.height;
3537 top_rect.height = 0;
3539 height -= top_rect.height;
3541 if (priv->bottom_window)
3542 bottom_rect.height = priv->bottom_window->requisition.height;
3544 bottom_rect.height = 0;
3546 height -= bottom_rect.height;
3548 text_rect.height = MAX (1, height);
3550 left_rect.height = text_rect.height;
3551 right_rect.height = text_rect.height;
3554 left_rect.x = focus_edge_width + border_width;
3555 top_rect.y = focus_edge_width + border_width;
3557 text_rect.x = left_rect.x + left_rect.width;
3558 text_rect.y = top_rect.y + top_rect.height;
3560 left_rect.y = text_rect.y;
3561 right_rect.y = text_rect.y;
3563 top_rect.x = text_rect.x;
3564 bottom_rect.x = text_rect.x;
3566 right_rect.x = text_rect.x + text_rect.width;
3567 bottom_rect.y = text_rect.y + text_rect.height;
3569 text_window_size_allocate (priv->text_window,
3572 if (priv->left_window)
3573 text_window_size_allocate (priv->left_window,
3576 if (priv->right_window)
3577 text_window_size_allocate (priv->right_window,
3580 if (priv->top_window)
3581 text_window_size_allocate (priv->top_window,
3584 if (priv->bottom_window)
3585 text_window_size_allocate (priv->bottom_window,
3588 gtk_text_view_update_layout_width (text_view);
3590 /* Note that this will do some layout validation */
3591 gtk_text_view_allocate_children (text_view);
3593 /* Ensure h/v adj exist */
3594 get_hadjustment (text_view);
3595 get_vadjustment (text_view);
3597 priv->hadjustment->page_size = SCREEN_WIDTH (text_view);
3598 priv->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9;
3599 priv->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1;
3600 priv->hadjustment->lower = 0;
3601 priv->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
3604 if (priv->hadjustment->value > priv->hadjustment->upper - priv->hadjustment->page_size)
3605 gtk_adjustment_set_value (priv->hadjustment, MAX (0, priv->hadjustment->upper - priv->hadjustment->page_size));
3607 gtk_adjustment_changed (priv->hadjustment);
3609 priv->vadjustment->page_size = SCREEN_HEIGHT (text_view);
3610 priv->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9;
3611 priv->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1;
3612 priv->vadjustment->lower = 0;
3613 priv->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
3616 /* Now adjust the value of the adjustment to keep the cursor at the
3617 * same place in the buffer
3619 gtk_text_view_get_first_para_iter (text_view, &first_para);
3620 gtk_text_layout_get_line_yrange (priv->layout, &first_para, &y, NULL);
3622 y += priv->first_para_pixels;
3624 if (y > priv->vadjustment->upper - priv->vadjustment->page_size)
3625 y = MAX (0, priv->vadjustment->upper - priv->vadjustment->page_size);
3627 if (y != priv->yoffset)
3628 gtk_adjustment_set_value (priv->vadjustment, y);
3630 gtk_adjustment_changed (priv->vadjustment);
3632 /* The GTK resize loop processes all the pending exposes right
3633 * after doing the resize stuff, so the idle sizer won't have a
3634 * chance to run. So we do the work here.
3636 gtk_text_view_flush_first_validate (text_view);
3638 /* widget->window doesn't get auto-redrawn as the layout is computed, so has to
3641 if (size_changed && gtk_widget_get_realized (widget))
3642 gdk_window_invalidate_rect (widget->window, NULL, FALSE);
3646 gtk_text_view_get_first_para_iter (GtkTextView *text_view,
3649 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), iter,
3650 text_view->priv->first_para_mark);
3654 gtk_text_view_validate_onscreen (GtkTextView *text_view)
3657 GtkTextViewPrivate *priv;
3659 widget = GTK_WIDGET (text_view);
3660 priv = text_view->priv;
3662 DV(g_print(">Validating onscreen ("G_STRLOC")\n"));
3664 if (SCREEN_HEIGHT (widget) > 0)
3666 GtkTextIter first_para;
3668 /* Be sure we've validated the stuff onscreen; if we
3669 * scrolled, these calls won't have any effect, because
3670 * they were called in the recursive validate_onscreen
3672 gtk_text_view_get_first_para_iter (text_view, &first_para);
3674 gtk_text_layout_validate_yrange (priv->layout,
3677 priv->first_para_pixels +
3678 SCREEN_HEIGHT (widget));
3681 priv->onscreen_validated = TRUE;
3683 DV(g_print(">Done validating onscreen, onscreen_validated = TRUE ("G_STRLOC")\n"));
3685 /* This can have the odd side effect of triggering a scroll, which should
3686 * flip "onscreen_validated" back to FALSE, but should also get us
3687 * back into this function to turn it on again.
3689 gtk_text_view_update_adjustments (text_view);
3691 g_assert (priv->onscreen_validated);
3695 gtk_text_view_flush_first_validate (GtkTextView *text_view)
3697 GtkTextViewPrivate *priv = text_view->priv;
3699 if (priv->first_validate_idle == 0)
3702 /* Do this first, which means that if an "invalidate"
3703 * occurs during any of this process, a new first_validate_callback
3704 * will be installed, and we'll start again.
3706 DV (g_print ("removing first validate in %s\n", G_STRLOC));
3707 g_source_remove (priv->first_validate_idle);
3708 priv->first_validate_idle = 0;
3710 /* be sure we have up-to-date screen size set on the
3713 gtk_text_view_update_layout_width (text_view);
3715 /* Bail out if we invalidated stuff; scrolling right away will just
3716 * confuse the issue.
3718 if (priv->first_validate_idle != 0)
3720 DV(g_print(">Width change forced requeue ("G_STRLOC")\n"));
3724 /* scroll to any marks, if that's pending. This can jump us to
3725 * the validation codepath used for scrolling onscreen, if so we
3726 * bail out. It won't jump if already in that codepath since
3727 * value_changed is not recursive, so also validate if
3730 if (!gtk_text_view_flush_scroll (text_view) ||
3731 !priv->onscreen_validated)
3732 gtk_text_view_validate_onscreen (text_view);
3734 DV(g_print(">Leaving first validate idle ("G_STRLOC")\n"));
3736 g_assert (priv->onscreen_validated);
3741 first_validate_callback (gpointer data)
3743 GtkTextView *text_view = data;
3745 /* Note that some of this code is duplicated at the end of size_allocate,
3746 * keep in sync with that.
3749 DV(g_print(G_STRLOC"\n"));
3751 gtk_text_view_flush_first_validate (text_view);
3757 incremental_validate_callback (gpointer data)
3759 GtkTextView *text_view = data;
3760 gboolean result = TRUE;
3762 DV(g_print(G_STRLOC"\n"));
3764 gtk_text_layout_validate (text_view->priv->layout, 2000);
3766 gtk_text_view_update_adjustments (text_view);
3768 if (gtk_text_layout_is_valid (text_view->priv->layout))
3770 text_view->priv->incremental_validate_idle = 0;
3778 gtk_text_view_invalidate (GtkTextView *text_view)
3780 GtkTextViewPrivate *priv = text_view->priv;
3782 DV (g_print (">Invalidate, onscreen_validated = %d now FALSE ("G_STRLOC")\n",
3783 priv->onscreen_validated));
3785 priv->onscreen_validated = FALSE;
3787 /* We'll invalidate when the layout is created */
3788 if (priv->layout == NULL)
3791 if (!priv->first_validate_idle)
3793 priv->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
3794 DV (g_print (G_STRLOC": adding first validate idle %d\n",
3795 priv->first_validate_idle));
3798 if (!priv->incremental_validate_idle)
3800 priv->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
3801 DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
3802 priv->incremental_validate_idle));
3807 invalidated_handler (GtkTextLayout *layout,
3810 GtkTextView *text_view;
3812 text_view = GTK_TEXT_VIEW (data);
3814 DV (g_print ("Invalidating due to layout invalidate signal\n"));
3815 gtk_text_view_invalidate (text_view);
3819 changed_handler (GtkTextLayout *layout,
3825 GtkTextView *text_view;
3826 GtkTextViewPrivate *priv;
3828 GdkRectangle visible_rect;
3829 GdkRectangle redraw_rect;
3831 text_view = GTK_TEXT_VIEW (data);
3832 priv = text_view->priv;
3833 widget = GTK_WIDGET (data);
3835 DV(g_print(">Lines Validated ("G_STRLOC")\n"));
3837 if (gtk_widget_get_realized (widget))
3839 gtk_text_view_get_visible_rect (text_view, &visible_rect);
3841 redraw_rect.x = visible_rect.x;
3842 redraw_rect.width = visible_rect.width;
3843 redraw_rect.y = start_y;
3845 if (old_height == new_height)
3846 redraw_rect.height = old_height;
3847 else if (start_y + old_height > visible_rect.y)
3848 redraw_rect.height = MAX (0, visible_rect.y + visible_rect.height - start_y);
3850 redraw_rect.height = 0;
3852 if (gdk_rectangle_intersect (&redraw_rect, &visible_rect, &redraw_rect))
3854 /* text_window_invalidate_rect() takes buffer coordinates */
3855 text_window_invalidate_rect (priv->text_window,
3858 DV(g_print(" invalidated rect: %d,%d %d x %d\n",
3862 redraw_rect.height));
3864 if (priv->left_window)
3865 text_window_invalidate_rect (priv->left_window,
3867 if (priv->right_window)
3868 text_window_invalidate_rect (priv->right_window,
3870 if (priv->top_window)
3871 text_window_invalidate_rect (priv->top_window,
3873 if (priv->bottom_window)
3874 text_window_invalidate_rect (priv->bottom_window,
3877 queue_update_im_spot_location (text_view);
3881 if (old_height != new_height)
3883 gboolean yoffset_changed = FALSE;
3885 int new_first_para_top;
3886 int old_first_para_top;
3889 /* If the bottom of the old area was above the top of the
3890 * screen, we need to scroll to keep the current top of the
3891 * screen in place. Remember that first_para_pixels is the
3892 * position of the top of the screen in coordinates relative to
3893 * the first paragraph onscreen.
3895 * In short we are adding the height delta of the portion of the
3896 * changed region above first_para_mark to priv->yoffset.
3898 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &first,
3899 priv->first_para_mark);
3901 gtk_text_layout_get_line_yrange (layout, &first, &new_first_para_top, NULL);
3903 old_first_para_top = priv->yoffset - priv->first_para_pixels;
3905 if (new_first_para_top != old_first_para_top)
3907 priv->yoffset += new_first_para_top - old_first_para_top;
3909 get_vadjustment (text_view)->value = priv->yoffset;
3910 yoffset_changed = TRUE;
3913 if (yoffset_changed)
3915 DV(g_print ("Changing scroll position (%s)\n", G_STRLOC));
3916 gtk_adjustment_value_changed (get_vadjustment (text_view));
3919 /* FIXME be smarter about which anchored widgets we update */
3921 tmp_list = priv->children;
3922 while (tmp_list != NULL)
3924 GtkTextViewChild *child = tmp_list->data;
3927 gtk_text_view_update_child_allocation (text_view, child);
3929 tmp_list = g_slist_next (tmp_list);
3934 GtkRequisition old_req;
3935 GtkRequisition new_req;
3937 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &old_req, NULL);
3939 /* Use this instead of gtk_widget_size_request wrapper
3940 * to avoid the optimization which just returns widget->requisition
3941 * if a resize hasn't been queued.
3943 GTK_WIDGET_GET_CLASS (widget)->size_request (widget, &new_req);
3945 if (old_req.width != new_req.width ||
3946 old_req.height != new_req.height)
3948 gtk_widget_queue_resize_no_redraw (widget);
3954 gtk_text_view_realize (GtkWidget *widget)
3956 GtkTextView *text_view;
3957 GtkTextViewPrivate *priv;
3958 GdkWindowAttr attributes;
3959 gint attributes_mask;
3962 text_view = GTK_TEXT_VIEW (widget);
3963 priv = text_view->priv;
3965 gtk_widget_set_realized (widget, TRUE);
3967 attributes.window_type = GDK_WINDOW_CHILD;
3968 attributes.x = widget->allocation.x;
3969 attributes.y = widget->allocation.y;
3970 attributes.width = widget->allocation.width;
3971 attributes.height = widget->allocation.height;
3972 attributes.wclass = GDK_INPUT_OUTPUT;
3973 attributes.visual = gtk_widget_get_visual (widget);
3974 attributes.colormap = gtk_widget_get_colormap (widget);
3975 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK;
3977 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3979 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
3980 &attributes, attributes_mask);
3981 gdk_window_set_user_data (widget->window, widget);
3983 /* must come before text_window_realize calls */
3984 widget->style = gtk_style_attach (widget->style, widget->window);
3986 gdk_window_set_background (widget->window,
3987 &widget->style->bg[gtk_widget_get_state (widget)]);
3989 text_window_realize (priv->text_window, widget);
3991 if (priv->left_window)
3992 text_window_realize (priv->left_window, widget);
3994 if (priv->top_window)
3995 text_window_realize (priv->top_window, widget);
3997 if (priv->right_window)
3998 text_window_realize (priv->right_window, widget);
4000 if (priv->bottom_window)
4001 text_window_realize (priv->bottom_window, widget);
4003 gtk_text_view_ensure_layout (text_view);
4007 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4008 GDK_SELECTION_PRIMARY);
4009 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
4012 tmp_list = priv->children;
4013 while (tmp_list != NULL)
4015 GtkTextViewChild *vc = tmp_list->data;
4017 text_view_child_set_parent_window (text_view, vc);
4019 tmp_list = tmp_list->next;
4022 /* Ensure updating the spot location. */
4023 gtk_text_view_update_im_spot_location (text_view);
4027 gtk_text_view_unrealize (GtkWidget *widget)
4029 GtkTextView *text_view;
4030 GtkTextViewPrivate *priv;
4032 text_view = GTK_TEXT_VIEW (widget);
4033 priv = text_view->priv;
4037 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4038 GDK_SELECTION_PRIMARY);
4039 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
4042 gtk_text_view_remove_validate_idles (text_view);
4044 if (priv->popup_menu)
4046 gtk_widget_destroy (priv->popup_menu);
4047 priv->popup_menu = NULL;
4050 text_window_unrealize (priv->text_window);
4052 if (priv->left_window)
4053 text_window_unrealize (priv->left_window);
4055 if (priv->top_window)
4056 text_window_unrealize (priv->top_window);
4058 if (priv->right_window)
4059 text_window_unrealize (priv->right_window);
4061 if (priv->bottom_window)
4062 text_window_unrealize (priv->bottom_window);
4064 gtk_text_view_destroy_layout (text_view);
4066 GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize (widget);
4070 gtk_text_view_set_background (GtkTextView *text_view)
4073 GtkTextViewPrivate *priv;
4075 widget = GTK_WIDGET (text_view);
4076 priv = text_view->priv;
4078 gdk_window_set_background (widget->window,
4079 &widget->style->bg[gtk_widget_get_state (widget)]);
4081 gdk_window_set_background (priv->text_window->bin_window,
4082 &widget->style->base[gtk_widget_get_state (widget)]);
4084 if (priv->left_window)
4085 gdk_window_set_background (priv->left_window->bin_window,
4086 &widget->style->bg[gtk_widget_get_state (widget)]);
4087 if (priv->right_window)
4088 gdk_window_set_background (priv->right_window->bin_window,
4089 &widget->style->bg[gtk_widget_get_state (widget)]);
4091 if (priv->top_window)
4092 gdk_window_set_background (priv->top_window->bin_window,
4093 &widget->style->bg[gtk_widget_get_state (widget)]);
4095 if (priv->bottom_window)
4096 gdk_window_set_background (priv->bottom_window->bin_window,
4097 &widget->style->bg[gtk_widget_get_state (widget)]);
4101 gtk_text_view_style_set (GtkWidget *widget,
4102 GtkStyle *previous_style)
4104 GtkTextView *text_view;
4105 GtkTextViewPrivate *priv;
4106 PangoContext *ltr_context, *rtl_context;
4108 text_view = GTK_TEXT_VIEW (widget);
4109 priv = text_view->priv;
4111 if (gtk_widget_get_realized (widget))
4113 gtk_text_view_set_background (text_view);
4116 if (priv->layout && previous_style)
4118 gtk_text_view_set_attributes_from_style (text_view,
4119 priv->layout->default_style,
4123 ltr_context = gtk_widget_create_pango_context (widget);
4124 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
4125 rtl_context = gtk_widget_create_pango_context (widget);
4126 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
4128 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
4130 g_object_unref (ltr_context);
4131 g_object_unref (rtl_context);
4136 gtk_text_view_direction_changed (GtkWidget *widget,
4137 GtkTextDirection previous_direction)
4139 GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
4143 priv->layout->default_style->direction = gtk_widget_get_direction (widget);
4145 gtk_text_layout_default_style_changed (priv->layout);
4150 gtk_text_view_state_changed (GtkWidget *widget,
4151 GtkStateType previous_state)
4153 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
4156 if (gtk_widget_get_realized (widget))
4158 gtk_text_view_set_background (text_view);
4160 if (gtk_widget_is_sensitive (widget))
4161 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4165 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4168 gdk_cursor_unref (cursor);
4170 text_view->priv->mouse_cursor_obscured = FALSE;
4173 if (!gtk_widget_is_sensitive (widget))
4175 /* Clear any selection */
4176 gtk_text_view_unselect (text_view);
4179 gtk_widget_queue_draw (widget);
4183 set_invisible_cursor (GdkWindow *window)
4185 GdkDisplay *display;
4188 display = gdk_drawable_get_display (window);
4189 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4191 gdk_window_set_cursor (window, cursor);
4193 gdk_cursor_unref (cursor);
4197 gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
4199 if (text_view->priv->mouse_cursor_obscured)
4202 set_invisible_cursor (text_view->priv->text_window->bin_window);
4204 text_view->priv->mouse_cursor_obscured = TRUE;
4208 gtk_text_view_unobscure_mouse_cursor (GtkTextView *text_view)
4210 if (text_view->priv->mouse_cursor_obscured)
4214 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)),
4216 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4217 gdk_cursor_unref (cursor);
4218 text_view->priv->mouse_cursor_obscured = FALSE;
4223 gtk_text_view_grab_notify (GtkWidget *widget,
4224 gboolean was_grabbed)
4226 GtkTextViewPrivate *priv;
4228 priv = GTK_TEXT_VIEW (widget)->priv;
4230 if (priv->grab_device &&
4231 gtk_widget_device_is_shadowed (widget, priv->grab_device))
4233 gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget));
4234 gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
4244 get_event_coordinates (GdkEvent *event, gint *x, gint *y)
4247 switch (event->type)
4249 case GDK_MOTION_NOTIFY:
4250 *x = event->motion.x;
4251 *y = event->motion.y;
4255 case GDK_BUTTON_PRESS:
4256 case GDK_2BUTTON_PRESS:
4257 case GDK_3BUTTON_PRESS:
4258 case GDK_BUTTON_RELEASE:
4259 *x = event->button.x;
4260 *y = event->button.y;
4265 case GDK_KEY_RELEASE:
4266 case GDK_ENTER_NOTIFY:
4267 case GDK_LEAVE_NOTIFY:
4268 case GDK_PROPERTY_NOTIFY:
4269 case GDK_SELECTION_CLEAR:
4270 case GDK_SELECTION_REQUEST:
4271 case GDK_SELECTION_NOTIFY:
4272 case GDK_PROXIMITY_IN:
4273 case GDK_PROXIMITY_OUT:
4274 case GDK_DRAG_ENTER:
4275 case GDK_DRAG_LEAVE:
4276 case GDK_DRAG_MOTION:
4277 case GDK_DRAG_STATUS:
4278 case GDK_DROP_START:
4279 case GDK_DROP_FINISHED:
4289 emit_event_on_tags (GtkWidget *widget,
4295 gboolean retval = FALSE;
4297 tags = gtk_text_iter_get_tags (iter);
4302 GtkTextTag *tag = tmp->data;
4304 if (gtk_text_tag_event (tag, G_OBJECT (widget), event, iter))
4310 tmp = g_slist_next (tmp);
4313 g_slist_free (tags);
4319 gtk_text_view_event (GtkWidget *widget, GdkEvent *event)
4321 GtkTextView *text_view;
4322 GtkTextViewPrivate *priv;
4325 text_view = GTK_TEXT_VIEW (widget);
4326 priv = text_view->priv;
4328 if (priv->layout == NULL ||
4329 get_buffer (text_view) == NULL)
4332 if (event->any.window != priv->text_window->bin_window)
4335 if (get_event_coordinates (event, &x, &y))
4342 /* FIXME this is slow and we do it twice per event.
4343 * My favorite solution is to have GtkTextLayout cache
4344 * the last couple lookups.
4346 gtk_text_layout_get_iter_at_pixel (priv->layout,
4350 return emit_event_on_tags (widget, event, &iter);
4352 else if (event->type == GDK_KEY_PRESS ||
4353 event->type == GDK_KEY_RELEASE)
4357 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
4358 gtk_text_buffer_get_insert (get_buffer (text_view)));
4360 return emit_event_on_tags (widget, event, &iter);
4367 gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
4369 GtkTextView *text_view;
4370 GtkTextViewPrivate *priv;
4371 GtkTextMark *insert;
4373 gboolean can_insert;
4374 gboolean retval = FALSE;
4375 gboolean obscure = FALSE;
4377 text_view = GTK_TEXT_VIEW (widget);
4378 priv = text_view->priv;
4380 if (priv->layout == NULL ||
4381 get_buffer (text_view) == NULL)
4384 /* Make sure input method knows where it is */
4385 flush_update_im_spot_location (text_view);
4387 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4388 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4389 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
4390 if (gtk_im_context_filter_keypress (priv->im_context, event))
4392 priv->need_im_reset = TRUE;
4394 gtk_text_view_reset_im_context (text_view);
4395 obscure = can_insert;
4399 else if (GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_press_event (widget, event))
4403 /* use overall editability not can_insert, more predictable for users */
4404 else if (priv->editable &&
4405 (event->keyval == GDK_Return ||
4406 event->keyval == GDK_ISO_Enter ||
4407 event->keyval == GDK_KP_Enter))
4409 /* this won't actually insert the newline if the cursor isn't
4412 gtk_text_view_reset_im_context (text_view);
4413 gtk_text_view_commit_text (text_view, "\n");
4418 /* Pass through Tab as literal tab, unless Control is held down */
4419 else if ((event->keyval == GDK_Tab ||
4420 event->keyval == GDK_KP_Tab ||
4421 event->keyval == GDK_ISO_Left_Tab) &&
4422 !(event->state & GDK_CONTROL_MASK))
4424 /* If the text widget isn't editable overall, or if the application
4425 * has turned off "accepts_tab", move the focus instead
4427 if (priv->accepts_tab && priv->editable)
4429 gtk_text_view_reset_im_context (text_view);
4430 gtk_text_view_commit_text (text_view, "\t");
4434 g_signal_emit_by_name (text_view, "move-focus",
4435 (event->state & GDK_SHIFT_MASK) ?
4436 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
4444 gtk_text_view_obscure_mouse_cursor (text_view);
4446 gtk_text_view_reset_blink_time (text_view);
4447 gtk_text_view_pend_cursor_blink (text_view);
4453 gtk_text_view_key_release_event (GtkWidget *widget, GdkEventKey *event)
4455 GtkTextView *text_view;
4456 GtkTextViewPrivate *priv;
4457 GtkTextMark *insert;
4460 text_view = GTK_TEXT_VIEW (widget);
4461 priv = text_view->priv;
4463 if (priv->layout == NULL || get_buffer (text_view) == NULL)
4466 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4467 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4468 if (gtk_text_iter_can_insert (&iter, priv->editable) &&
4469 gtk_im_context_filter_keypress (priv->im_context, event))
4471 priv->need_im_reset = TRUE;
4475 return GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_release_event (widget, event);
4479 gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
4481 GtkTextView *text_view;
4482 GtkTextViewPrivate *priv;
4484 text_view = GTK_TEXT_VIEW (widget);
4485 priv = text_view->priv;
4487 gtk_widget_grab_focus (widget);
4489 if (event->window != priv->text_window->bin_window)
4491 /* Remove selection if any. */
4492 gtk_text_view_unselect (text_view);
4496 gtk_text_view_reset_blink_time (text_view);
4500 if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
4501 _gtk_text_buffer_spew (GTK_TEXT_VIEW (widget)->buffer);
4502 else if (event->button == 3)
4503 gtk_text_layout_spew (GTK_TEXT_VIEW (widget)->layout);
4506 if (event->type == GDK_BUTTON_PRESS)
4508 gtk_text_view_reset_im_context (text_view);
4510 if (event->button == 1)
4512 /* If we're in the selection, start a drag copy/move of the
4513 * selection; otherwise, start creating a new selection.
4516 GtkTextIter start, end;
4518 gtk_text_layout_get_iter_at_pixel (priv->layout,
4520 event->x + priv->xoffset,
4521 event->y + priv->yoffset);
4523 if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
4525 gtk_text_iter_in_range (&iter, &start, &end) &&
4526 !(event->state & GDK_SHIFT_MASK))
4528 priv->drag_start_x = event->x;
4529 priv->drag_start_y = event->y;
4530 priv->pending_place_cursor_button = event->button;
4534 gtk_text_view_start_selection_drag (text_view, &iter, event);
4539 else if (event->button == 2)
4543 /* We do not want to scroll back to the insert iter when we paste
4544 with the middle button */
4545 priv->scroll_after_paste = FALSE;
4547 gtk_text_layout_get_iter_at_pixel (priv->layout,
4549 event->x + priv->xoffset,
4550 event->y + priv->yoffset);
4552 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
4553 gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY),
4558 else if (event->button == 3)
4560 gtk_text_view_do_popup (text_view, event);
4564 else if ((event->type == GDK_2BUTTON_PRESS ||
4565 event->type == GDK_3BUTTON_PRESS) &&
4570 gtk_text_view_end_selection_drag (text_view);
4572 gtk_text_layout_get_iter_at_pixel (priv->layout,
4574 event->x + priv->xoffset,
4575 event->y + priv->yoffset);
4577 gtk_text_view_start_selection_drag (text_view, &iter, event);
4585 gtk_text_view_button_release_event (GtkWidget *widget, GdkEventButton *event)
4587 GtkTextView *text_view;
4588 GtkTextViewPrivate *priv;
4590 text_view = GTK_TEXT_VIEW (widget);
4591 priv = text_view->priv;
4593 if (event->window != priv->text_window->bin_window)
4596 if (event->button == 1)
4598 if (priv->drag_start_x >= 0)
4600 priv->drag_start_x = -1;
4601 priv->drag_start_y = -1;
4604 if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget)))
4606 else if (priv->pending_place_cursor_button == event->button)
4610 /* Unselect everything; we clicked inside selection, but
4611 * didn't move by the drag threshold, so just clear selection
4614 gtk_text_layout_get_iter_at_pixel (priv->layout,
4616 event->x + priv->xoffset,
4617 event->y + priv->yoffset);
4619 gtk_text_buffer_place_cursor (get_buffer (text_view), &iter);
4620 gtk_text_view_check_cursor_blink (text_view);
4622 priv->pending_place_cursor_button = 0;
4632 keymap_direction_changed (GdkKeymap *keymap,
4633 GtkTextView *text_view)
4635 gtk_text_view_check_keymap_direction (text_view);
4639 gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
4641 GtkTextView *text_view;
4642 GtkTextViewPrivate *priv;
4644 text_view = GTK_TEXT_VIEW (widget);
4645 priv = text_view->priv;
4647 gtk_widget_queue_draw (widget);
4649 DV(g_print (G_STRLOC": focus_in_event\n"));
4651 gtk_text_view_reset_blink_time (text_view);
4653 if (priv->cursor_visible && priv->layout)
4655 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
4656 gtk_text_view_check_cursor_blink (text_view);
4659 g_signal_connect (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4660 "direction-changed",
4661 G_CALLBACK (keymap_direction_changed), text_view);
4662 gtk_text_view_check_keymap_direction (text_view);
4666 priv->need_im_reset = TRUE;
4667 gtk_im_context_focus_in (priv->im_context);
4674 gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
4676 GtkTextView *text_view;
4677 GtkTextViewPrivate *priv;
4679 text_view = GTK_TEXT_VIEW (widget);
4680 priv = text_view->priv;
4682 gtk_text_view_end_selection_drag (text_view);
4684 gtk_widget_queue_draw (widget);
4686 DV(g_print (G_STRLOC": focus_out_event\n"));
4688 if (priv->cursor_visible && priv->layout)
4690 gtk_text_view_check_cursor_blink (text_view);
4691 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
4694 g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4695 keymap_direction_changed,
4700 priv->need_im_reset = TRUE;
4701 gtk_im_context_focus_out (priv->im_context);
4708 gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
4710 GtkTextView *text_view;
4711 GtkTextViewPrivate *priv;
4713 text_view = GTK_TEXT_VIEW (widget);
4714 priv = text_view->priv;
4716 gtk_text_view_unobscure_mouse_cursor (text_view);
4718 if (event->window == priv->text_window->bin_window &&
4719 priv->drag_start_x >= 0)
4724 gdk_event_request_motions (event);
4726 if (gtk_drag_check_threshold (widget,
4732 gint buffer_x, buffer_y;
4734 gtk_text_view_window_to_buffer_coords (text_view,
4735 GTK_TEXT_WINDOW_TEXT,
4741 gtk_text_layout_get_iter_at_pixel (priv->layout,
4743 buffer_x, buffer_y);
4745 gtk_text_view_start_selection_dnd (text_view, &iter, event);
4754 gtk_text_view_paint (GtkWidget *widget,
4756 GdkEventExpose *event)
4758 GtkTextView *text_view;
4759 GtkTextViewPrivate *priv;
4760 GList *child_exposes;
4763 text_view = GTK_TEXT_VIEW (widget);
4764 priv = text_view->priv;
4766 g_return_if_fail (priv->layout != NULL);
4767 g_return_if_fail (priv->xoffset >= 0);
4768 g_return_if_fail (priv->yoffset >= 0);
4770 while (priv->first_validate_idle != 0)
4772 DV (g_print (G_STRLOC": first_validate_idle: %d\n",
4773 priv->first_validate_idle));
4774 gtk_text_view_flush_first_validate (text_view);
4777 if (!priv->onscreen_validated)
4779 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.");
4780 g_assert_not_reached ();
4784 printf ("painting %d,%d %d x %d\n",
4786 area->width, area->height);
4789 child_exposes = NULL;
4790 gtk_text_layout_draw (priv->layout,
4792 priv->text_window->bin_window,
4797 area->width, area->height,
4800 tmp_list = child_exposes;
4801 while (tmp_list != NULL)
4803 GtkWidget *child = tmp_list->data;
4805 gtk_container_propagate_expose (GTK_CONTAINER (text_view),
4809 g_object_unref (child);
4811 tmp_list = tmp_list->next;
4814 g_list_free (child_exposes);
4818 gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
4822 if (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
4823 GTK_TEXT_WINDOW_TEXT))
4825 DV(g_print (">Exposed ("G_STRLOC")\n"));
4826 gtk_text_view_paint (widget, &event->area, event);
4829 if (event->window == widget->window)
4830 gtk_text_view_draw_focus (widget);
4832 /* Propagate exposes to all unanchored children.
4833 * Anchored children are handled in gtk_text_view_paint().
4835 tmp_list = GTK_TEXT_VIEW (widget)->priv->children;
4836 while (tmp_list != NULL)
4838 GtkTextViewChild *vc = tmp_list->data;
4840 /* propagate_expose checks that event->window matches
4844 gtk_container_propagate_expose (GTK_CONTAINER (widget),
4848 tmp_list = tmp_list->next;
4855 gtk_text_view_draw_focus (GtkWidget *widget)
4857 gboolean interior_focus;
4859 /* We clear the focus if we are in interior focus mode. */
4860 gtk_widget_style_get (widget,
4861 "interior-focus", &interior_focus,
4864 if (gtk_widget_is_drawable (widget))
4866 if (gtk_widget_has_focus (widget) && !interior_focus)
4868 gtk_paint_focus (widget->style, widget->window, gtk_widget_get_state (widget),
4869 NULL, widget, "textview",
4871 widget->allocation.width,
4872 widget->allocation.height);
4876 gdk_window_clear (widget->window);
4882 gtk_text_view_focus (GtkWidget *widget,
4883 GtkDirectionType direction)
4885 GtkContainer *container;
4888 container = GTK_CONTAINER (widget);
4890 if (!gtk_widget_is_focus (widget) &&
4891 gtk_container_get_focus_child (container) == NULL)
4893 gtk_widget_grab_focus (widget);
4899 * Unset CAN_FOCUS flag so that gtk_container_focus() allows
4900 * children to get the focus
4902 gtk_widget_set_can_focus (widget, FALSE);
4903 result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
4904 gtk_widget_set_can_focus (widget, TRUE);
4911 gtk_text_view_move_focus (GtkWidget *widget,
4912 GtkDirectionType direction_type)
4914 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
4916 if (GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus)
4917 GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus (text_view,
4926 gtk_text_view_add (GtkContainer *container,
4929 /* This is pretty random. */
4930 gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container),
4932 GTK_TEXT_WINDOW_WIDGET,
4937 gtk_text_view_remove (GtkContainer *container,
4940 GtkTextView *text_view;
4941 GtkTextViewPrivate *priv;
4942 GtkTextViewChild *vc;
4945 text_view = GTK_TEXT_VIEW (container);
4946 priv = text_view->priv;
4949 iter = priv->children;
4951 while (iter != NULL)
4955 if (vc->widget == child)
4958 iter = g_slist_next (iter);
4961 g_assert (iter != NULL); /* be sure we had the child in the list */
4963 priv->children = g_slist_remove (priv->children, vc);
4965 gtk_widget_unparent (vc->widget);
4967 text_view_child_free (vc);
4971 gtk_text_view_forall (GtkContainer *container,
4972 gboolean include_internals,
4973 GtkCallback callback,
4974 gpointer callback_data)
4977 GtkTextView *text_view;
4980 g_return_if_fail (GTK_IS_TEXT_VIEW (container));
4981 g_return_if_fail (callback != NULL);
4983 text_view = GTK_TEXT_VIEW (container);
4985 copy = g_slist_copy (text_view->priv->children);
4988 while (iter != NULL)
4990 GtkTextViewChild *vc = iter->data;
4992 (* callback) (vc->widget, callback_data);
4994 iter = g_slist_next (iter);
4997 g_slist_free (copy);
5000 #define CURSOR_ON_MULTIPLIER 2
5001 #define CURSOR_OFF_MULTIPLIER 1
5002 #define CURSOR_PEND_MULTIPLIER 3
5003 #define CURSOR_DIVIDER 3
5006 cursor_blinks (GtkTextView *text_view)
5008 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5011 #ifdef DEBUG_VALIDATION_AND_SCROLLING
5014 if (gtk_get_debug_flags () & GTK_DEBUG_UPDATES)
5017 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
5022 if (text_view->priv->editable)
5024 GtkTextMark *insert;
5027 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
5028 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
5030 if (gtk_text_iter_editable (&iter, text_view->priv->editable))
5038 get_cursor_time (GtkTextView *text_view)
5040 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5043 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
5049 get_cursor_blink_timeout (GtkTextView *text_view)
5051 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5054 g_object_get (settings, "gtk-cursor-blink-timeout", &time, NULL);
5065 blink_cb (gpointer data)
5067 GtkTextView *text_view;
5068 GtkTextViewPrivate *priv;
5072 text_view = GTK_TEXT_VIEW (data);
5073 priv = text_view->priv;
5075 if (!gtk_widget_has_focus (GTK_WIDGET (text_view)))
5077 g_warning ("GtkTextView - did not receive focus-out-event. If you\n"
5078 "connect a handler to this signal, it must return\n"
5079 "FALSE so the text view gets the event as well");
5081 gtk_text_view_check_cursor_blink (text_view);
5086 g_assert (priv->layout);
5087 g_assert (priv->cursor_visible);
5089 visible = gtk_text_layout_get_cursor_visible (priv->layout);
5091 blink_timeout = get_cursor_blink_timeout (text_view);
5092 if (priv->blink_time > 1000 * blink_timeout &&
5093 blink_timeout < G_MAXINT/1000)
5095 /* we've blinked enough without the user doing anything, stop blinking */
5097 priv->blink_timeout = 0;
5100 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5105 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
5108 priv->blink_time += get_cursor_time (text_view);
5111 /* Block changed_handler while changing the layout's cursor visibility
5112 * because it would expose the whole paragraph. Instead, we expose
5113 * the cursor's area(s) manually below.
5115 g_signal_handlers_block_by_func (priv->layout,
5118 gtk_text_layout_set_cursor_visible (priv->layout, !visible);
5119 g_signal_handlers_unblock_by_func (priv->layout,
5123 text_window_invalidate_cursors (priv->text_window);
5125 /* Remove ourselves */
5131 gtk_text_view_stop_cursor_blink (GtkTextView *text_view)
5133 if (text_view->priv->blink_timeout)
5135 g_source_remove (text_view->priv->blink_timeout);
5136 text_view->priv->blink_timeout = 0;
5141 gtk_text_view_check_cursor_blink (GtkTextView *text_view)
5143 GtkTextViewPrivate *priv = text_view->priv;
5145 if (priv->layout != NULL &&
5146 priv->cursor_visible &&
5147 gtk_widget_has_focus (GTK_WIDGET (text_view)))
5149 if (cursor_blinks (text_view))
5151 if (priv->blink_timeout == 0)
5153 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5155 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5162 gtk_text_view_stop_cursor_blink (text_view);
5163 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5168 gtk_text_view_stop_cursor_blink (text_view);
5169 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
5174 gtk_text_view_pend_cursor_blink (GtkTextView *text_view)
5176 GtkTextViewPrivate *priv = text_view->priv;
5178 if (priv->layout != NULL &&
5179 priv->cursor_visible &&
5180 gtk_widget_has_focus (GTK_WIDGET (text_view)) &&
5181 cursor_blinks (text_view))
5183 gtk_text_view_stop_cursor_blink (text_view);
5184 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5186 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
5193 gtk_text_view_reset_blink_time (GtkTextView *text_view)
5195 GtkTextViewPrivate *priv = text_view->priv;
5197 priv->blink_time = 0;
5202 * Key binding handlers
5206 gtk_text_view_move_iter_by_lines (GtkTextView *text_view,
5207 GtkTextIter *newplace,
5210 gboolean ret = TRUE;
5214 ret = gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, newplace);
5220 ret = gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, newplace);
5228 move_cursor (GtkTextView *text_view,
5229 const GtkTextIter *new_location,
5230 gboolean extend_selection)
5232 if (extend_selection)
5233 gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
5237 gtk_text_buffer_place_cursor (get_buffer (text_view),
5239 gtk_text_view_check_cursor_blink (text_view);
5243 gtk_text_view_move_cursor_internal (GtkTextView *text_view,
5244 GtkMovementStep step,
5246 gboolean extend_selection)
5248 GtkTextViewPrivate *priv;
5250 GtkTextIter newplace;
5251 gboolean cancel_selection = FALSE;
5252 gint cursor_x_pos = 0;
5253 GtkDirectionType leave_direction = -1;
5255 priv = text_view->priv;
5257 if (!priv->cursor_visible)
5259 GtkScrollStep scroll_step;
5263 case GTK_MOVEMENT_VISUAL_POSITIONS:
5264 leave_direction = count > 0 ? GTK_DIR_RIGHT : GTK_DIR_LEFT;
5266 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5267 case GTK_MOVEMENT_WORDS:
5268 scroll_step = GTK_SCROLL_HORIZONTAL_STEPS;
5270 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5271 scroll_step = GTK_SCROLL_HORIZONTAL_ENDS;
5273 case GTK_MOVEMENT_DISPLAY_LINES:
5274 leave_direction = count > 0 ? GTK_DIR_DOWN : GTK_DIR_UP;
5276 case GTK_MOVEMENT_PARAGRAPHS:
5277 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5278 scroll_step = GTK_SCROLL_STEPS;
5280 case GTK_MOVEMENT_PAGES:
5281 scroll_step = GTK_SCROLL_PAGES;
5283 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5284 scroll_step = GTK_SCROLL_HORIZONTAL_PAGES;
5286 case GTK_MOVEMENT_BUFFER_ENDS:
5287 scroll_step = GTK_SCROLL_ENDS;
5290 scroll_step = GTK_SCROLL_PAGES;
5294 if (!gtk_text_view_move_viewport (text_view, scroll_step, count))
5296 if (leave_direction != -1 &&
5297 !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5300 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5307 gtk_text_view_reset_im_context (text_view);
5309 if (step == GTK_MOVEMENT_PAGES)
5311 if (!gtk_text_view_scroll_pages (text_view, count, extend_selection))
5312 gtk_widget_error_bell (GTK_WIDGET (text_view));
5314 gtk_text_view_check_cursor_blink (text_view);
5315 gtk_text_view_pend_cursor_blink (text_view);
5318 else if (step == GTK_MOVEMENT_HORIZONTAL_PAGES)
5320 if (!gtk_text_view_scroll_hpages (text_view, count, extend_selection))
5321 gtk_widget_error_bell (GTK_WIDGET (text_view));
5323 gtk_text_view_check_cursor_blink (text_view);
5324 gtk_text_view_pend_cursor_blink (text_view);
5328 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5329 gtk_text_buffer_get_insert (get_buffer (text_view)));
5331 if (! extend_selection)
5333 GtkTextIter sel_bound;
5335 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
5336 gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
5338 /* if we move forward, assume the cursor is at the end of the selection;
5339 * if we move backward, assume the cursor is at the start
5342 gtk_text_iter_order (&sel_bound, &insert);
5344 gtk_text_iter_order (&insert, &sel_bound);
5346 /* if we actually have a selection, just move *to* the beginning/end
5347 * of the selection and not *from* there on LOGICAL_POSITIONS
5348 * and VISUAL_POSITIONS movement
5350 if (! gtk_text_iter_equal (&sel_bound, &insert))
5351 cancel_selection = TRUE;
5356 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5357 gtk_text_view_get_virtual_cursor_pos (text_view, &insert, &cursor_x_pos, NULL);
5361 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5362 if (! cancel_selection)
5363 gtk_text_iter_forward_visible_cursor_positions (&newplace, count);
5366 case GTK_MOVEMENT_VISUAL_POSITIONS:
5367 if (! cancel_selection)
5368 gtk_text_layout_move_iter_visually (priv->layout,
5372 case GTK_MOVEMENT_WORDS:
5374 gtk_text_iter_backward_visible_word_starts (&newplace, -count);
5377 if (!gtk_text_iter_forward_visible_word_ends (&newplace, count))
5378 gtk_text_iter_forward_to_line_end (&newplace);
5382 case GTK_MOVEMENT_DISPLAY_LINES:
5385 leave_direction = GTK_DIR_UP;
5387 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5388 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5390 gtk_text_iter_set_line_offset (&newplace, 0);
5394 leave_direction = GTK_DIR_DOWN;
5396 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5397 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5399 gtk_text_iter_forward_to_line_end (&newplace);
5403 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5405 gtk_text_view_move_iter_by_lines (text_view, &newplace, --count);
5406 else if (count < -1)
5407 gtk_text_view_move_iter_by_lines (text_view, &newplace, ++count);
5410 gtk_text_layout_move_iter_to_line_end (priv->layout, &newplace, count);
5413 case GTK_MOVEMENT_PARAGRAPHS:
5416 if (!gtk_text_iter_ends_line (&newplace))
5418 gtk_text_iter_forward_to_line_end (&newplace);
5421 gtk_text_iter_forward_visible_lines (&newplace, count);
5422 gtk_text_iter_forward_to_line_end (&newplace);
5426 if (gtk_text_iter_get_line_offset (&newplace) > 0)
5427 gtk_text_iter_set_line_offset (&newplace, 0);
5428 gtk_text_iter_forward_visible_lines (&newplace, count);
5429 gtk_text_iter_set_line_offset (&newplace, 0);
5433 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5436 if (!gtk_text_iter_ends_line (&newplace))
5437 gtk_text_iter_forward_to_line_end (&newplace);
5441 gtk_text_iter_set_line_offset (&newplace, 0);
5445 case GTK_MOVEMENT_BUFFER_ENDS:
5447 gtk_text_buffer_get_end_iter (get_buffer (text_view), &newplace);
5449 gtk_text_buffer_get_iter_at_offset (get_buffer (text_view), &newplace, 0);
5456 /* call move_cursor() even if the cursor hasn't moved, since it
5457 cancels the selection
5459 move_cursor (text_view, &newplace, extend_selection);
5461 if (!gtk_text_iter_equal (&insert, &newplace))
5463 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5464 gtk_text_view_scroll_mark_onscreen (text_view,
5465 gtk_text_buffer_get_insert (get_buffer (text_view)));
5467 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5468 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, -1);
5470 else if (leave_direction != -1)
5472 if (!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5475 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5478 else if (! cancel_selection)
5480 gtk_widget_error_bell (GTK_WIDGET (text_view));
5483 gtk_text_view_check_cursor_blink (text_view);
5484 gtk_text_view_pend_cursor_blink (text_view);
5488 gtk_text_view_move_cursor (GtkTextView *text_view,
5489 GtkMovementStep step,
5491 gboolean extend_selection)
5493 gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
5497 gtk_text_view_move_viewport (GtkTextView *text_view,
5501 GtkAdjustment *adjustment;
5506 case GTK_SCROLL_STEPS:
5507 case GTK_SCROLL_PAGES:
5508 case GTK_SCROLL_ENDS:
5509 adjustment = get_vadjustment (text_view);
5511 case GTK_SCROLL_HORIZONTAL_STEPS:
5512 case GTK_SCROLL_HORIZONTAL_PAGES:
5513 case GTK_SCROLL_HORIZONTAL_ENDS:
5514 adjustment = get_hadjustment (text_view);
5517 adjustment = get_vadjustment (text_view);
5523 case GTK_SCROLL_STEPS:
5524 case GTK_SCROLL_HORIZONTAL_STEPS:
5525 increment = adjustment->step_increment;
5527 case GTK_SCROLL_PAGES:
5528 case GTK_SCROLL_HORIZONTAL_PAGES:
5529 increment = adjustment->page_increment;
5531 case GTK_SCROLL_ENDS:
5532 case GTK_SCROLL_HORIZONTAL_ENDS:
5533 increment = adjustment->upper - adjustment->lower;
5540 return set_adjustment_clamped (adjustment, adjustment->value + count * increment);
5544 gtk_text_view_set_anchor (GtkTextView *text_view)
5548 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5549 gtk_text_buffer_get_insert (get_buffer (text_view)));
5551 gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
5555 gtk_text_view_scroll_pages (GtkTextView *text_view,
5557 gboolean extend_selection)
5559 GtkTextViewPrivate *priv;
5561 gint cursor_x_pos, cursor_y_pos;
5562 GtkTextMark *insert_mark;
5563 GtkTextIter old_insert;
5564 GtkTextIter new_insert;
5570 priv = text_view->priv;
5572 g_return_val_if_fail (priv->vadjustment != NULL, FALSE);
5574 adj = priv->vadjustment;
5576 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5578 /* Make sure we start from the current cursor position, even
5579 * if it was offscreen, but don't queue more scrolls if we're
5582 if (priv->pending_scroll)
5583 cancel_pending_scroll (text_view);
5585 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5587 /* Validate the region that will be brought into view by the cursor motion
5589 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5590 &old_insert, insert_mark);
5594 gtk_text_view_get_first_para_iter (text_view, &anchor);
5595 y0 = adj->page_size;
5596 y1 = adj->page_size + count * adj->page_increment;
5600 gtk_text_view_get_first_para_iter (text_view, &anchor);
5601 y0 = count * adj->page_increment + adj->page_size;
5605 gtk_text_layout_validate_yrange (priv->layout, &anchor, y0, y1);
5606 /* FIXME do we need to update the adjustment ranges here? */
5608 new_insert = old_insert;
5610 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5612 /* already at top, just be sure we are at offset 0 */
5613 gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
5614 move_cursor (text_view, &new_insert, extend_selection);
5616 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5618 /* already at bottom, just be sure we are at the end */
5619 gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
5620 move_cursor (text_view, &new_insert, extend_selection);
5624 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5626 oldval = adj->value;
5627 newval = adj->value;
5629 newval += count * adj->page_increment;
5631 set_adjustment_clamped (adj, newval);
5632 cursor_y_pos += adj->value - oldval;
5634 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5635 clamp_iter_onscreen (text_view, &new_insert);
5636 move_cursor (text_view, &new_insert, extend_selection);
5638 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5641 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5642 * only guarantees 1 pixel onscreen.
5644 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5645 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5647 return !gtk_text_iter_equal (&old_insert, &new_insert);
5651 gtk_text_view_scroll_hpages (GtkTextView *text_view,
5653 gboolean extend_selection)
5655 GtkTextViewPrivate *priv;
5657 gint cursor_x_pos, cursor_y_pos;
5658 GtkTextMark *insert_mark;
5659 GtkTextIter old_insert;
5660 GtkTextIter new_insert;
5665 priv = text_view->priv;
5667 g_return_val_if_fail (priv->hadjustment != NULL, FALSE);
5669 adj = priv->hadjustment;
5671 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5673 /* Make sure we start from the current cursor position, even
5674 * if it was offscreen, but don't queue more scrolls if we're
5677 if (priv->pending_scroll)
5678 cancel_pending_scroll (text_view);
5680 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5682 /* Validate the line that we're moving within.
5684 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5685 &old_insert, insert_mark);
5687 gtk_text_layout_get_line_yrange (priv->layout, &old_insert, &y, &height);
5688 gtk_text_layout_validate_yrange (priv->layout, &old_insert, y, y + height);
5689 /* FIXME do we need to update the adjustment ranges here? */
5691 new_insert = old_insert;
5693 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5695 /* already at far left, just be sure we are at offset 0 */
5696 gtk_text_iter_set_line_offset (&new_insert, 0);
5697 move_cursor (text_view, &new_insert, extend_selection);
5699 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5701 /* already at far right, just be sure we are at the end */
5702 if (!gtk_text_iter_ends_line (&new_insert))
5703 gtk_text_iter_forward_to_line_end (&new_insert);
5704 move_cursor (text_view, &new_insert, extend_selection);
5708 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5710 oldval = adj->value;
5711 newval = adj->value;
5713 newval += count * adj->page_increment;
5715 set_adjustment_clamped (adj, newval);
5716 cursor_x_pos += adj->value - oldval;
5718 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5719 clamp_iter_onscreen (text_view, &new_insert);
5720 move_cursor (text_view, &new_insert, extend_selection);
5722 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5725 /* FIXME for lines shorter than the overall widget width, this results in a
5726 * "bounce" effect as we scroll to the right of the widget, then scroll
5727 * back to get the end of the line onscreen.
5728 * http://bugzilla.gnome.org/show_bug.cgi?id=68963
5731 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5732 * only guarantees 1 pixel onscreen.
5734 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5735 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5737 return !gtk_text_iter_equal (&old_insert, &new_insert);
5741 whitespace (gunichar ch, gpointer user_data)
5743 return (ch == ' ' || ch == '\t');
5747 not_whitespace (gunichar ch, gpointer user_data)
5749 return !whitespace (ch, user_data);
5753 find_whitepace_region (const GtkTextIter *center,
5754 GtkTextIter *start, GtkTextIter *end)
5759 if (gtk_text_iter_backward_find_char (start, not_whitespace, NULL, NULL))
5760 gtk_text_iter_forward_char (start); /* we want the first whitespace... */
5761 if (whitespace (gtk_text_iter_get_char (end), NULL))
5762 gtk_text_iter_forward_find_char (end, not_whitespace, NULL, NULL);
5764 return !gtk_text_iter_equal (start, end);
5768 gtk_text_view_insert_at_cursor (GtkTextView *text_view,
5771 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
5772 text_view->priv->editable))
5774 gtk_widget_error_bell (GTK_WIDGET (text_view));
5779 gtk_text_view_delete_from_cursor (GtkTextView *text_view,
5783 GtkTextViewPrivate *priv;
5787 gboolean leave_one = FALSE;
5789 priv = text_view->priv;
5791 gtk_text_view_reset_im_context (text_view);
5793 if (type == GTK_DELETE_CHARS)
5795 /* Char delete deletes the selection, if one exists */
5796 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5801 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5802 gtk_text_buffer_get_insert (get_buffer (text_view)));
5809 case GTK_DELETE_CHARS:
5810 gtk_text_iter_forward_cursor_positions (&end, count);
5813 case GTK_DELETE_WORD_ENDS:
5815 gtk_text_iter_forward_word_ends (&end, count);
5817 gtk_text_iter_backward_word_starts (&start, 0 - count);
5820 case GTK_DELETE_WORDS:
5823 case GTK_DELETE_DISPLAY_LINE_ENDS:
5826 case GTK_DELETE_DISPLAY_LINES:
5829 case GTK_DELETE_PARAGRAPH_ENDS:
5832 /* If we're already at a newline, we need to
5833 * simply delete that newline, instead of
5834 * moving to the next one.
5836 if (gtk_text_iter_ends_line (&end))
5838 gtk_text_iter_forward_line (&end);
5844 if (!gtk_text_iter_forward_to_line_end (&end))
5852 if (gtk_text_iter_starts_line (&start))
5854 gtk_text_iter_backward_line (&start);
5855 if (!gtk_text_iter_ends_line (&end))
5856 gtk_text_iter_forward_to_line_end (&start);
5860 gtk_text_iter_set_line_offset (&start, 0);
5864 gtk_text_iter_backward_lines (&start, -count);
5868 case GTK_DELETE_PARAGRAPHS:
5871 gtk_text_iter_set_line_offset (&start, 0);
5872 gtk_text_iter_forward_to_line_end (&end);
5874 /* Do the lines beyond the first. */
5877 gtk_text_iter_forward_to_line_end (&end);
5883 /* FIXME negative count? */
5887 case GTK_DELETE_WHITESPACE:
5889 find_whitepace_region (&insert, &start, &end);
5897 if (!gtk_text_iter_equal (&start, &end))
5899 gtk_text_buffer_begin_user_action (get_buffer (text_view));
5901 if (gtk_text_buffer_delete_interactive (get_buffer (text_view), &start, &end,
5905 gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view),
5911 gtk_widget_error_bell (GTK_WIDGET (text_view));
5914 gtk_text_buffer_end_user_action (get_buffer (text_view));
5915 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5917 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5918 gtk_text_view_scroll_mark_onscreen (text_view,
5919 gtk_text_buffer_get_insert (get_buffer (text_view)));
5923 gtk_widget_error_bell (GTK_WIDGET (text_view));
5928 gtk_text_view_backspace (GtkTextView *text_view)
5930 GtkTextViewPrivate *priv;
5933 priv = text_view->priv;
5935 gtk_text_view_reset_im_context (text_view);
5937 /* Backspace deletes the selection, if one exists */
5938 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5942 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5944 gtk_text_buffer_get_insert (get_buffer (text_view)));
5946 if (gtk_text_buffer_backspace (get_buffer (text_view), &insert,
5947 TRUE, priv->editable))
5949 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5950 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5951 gtk_text_view_scroll_mark_onscreen (text_view,
5952 gtk_text_buffer_get_insert (get_buffer (text_view)));
5956 gtk_widget_error_bell (GTK_WIDGET (text_view));
5961 gtk_text_view_cut_clipboard (GtkTextView *text_view)
5963 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5964 GDK_SELECTION_CLIPBOARD);
5966 gtk_text_buffer_cut_clipboard (get_buffer (text_view),
5968 text_view->priv->editable);
5969 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5970 gtk_text_view_scroll_mark_onscreen (text_view,
5971 gtk_text_buffer_get_insert (get_buffer (text_view)));
5975 gtk_text_view_copy_clipboard (GtkTextView *text_view)
5977 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5978 GDK_SELECTION_CLIPBOARD);
5980 gtk_text_buffer_copy_clipboard (get_buffer (text_view),
5983 /* on copy do not scroll, we are already onscreen */
5987 gtk_text_view_paste_clipboard (GtkTextView *text_view)
5989 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
5990 GDK_SELECTION_CLIPBOARD);
5992 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
5995 text_view->priv->editable);
5999 gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
6000 GtkClipboard *clipboard,
6003 GtkTextView *text_view = data;
6004 GtkTextViewPrivate *priv;
6006 priv = text_view->priv;
6008 if (priv->scroll_after_paste)
6010 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6011 gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer));
6014 priv->scroll_after_paste = TRUE;
6018 gtk_text_view_toggle_overwrite (GtkTextView *text_view)
6020 GtkTextViewPrivate *priv = text_view->priv;
6022 if (priv->text_window)
6023 text_window_invalidate_cursors (priv->text_window);
6025 priv->overwrite_mode = !priv->overwrite_mode;
6028 gtk_text_layout_set_overwrite_mode (priv->layout,
6029 priv->overwrite_mode && priv->editable);
6031 if (priv->text_window)
6032 text_window_invalidate_cursors (priv->text_window);
6034 gtk_text_view_pend_cursor_blink (text_view);
6036 g_object_notify (G_OBJECT (text_view), "overwrite");
6040 * gtk_text_view_get_overwrite:
6041 * @text_view: a #GtkTextView
6043 * Returns whether the #GtkTextView is in overwrite mode or not.
6045 * Return value: whether @text_view is in overwrite mode or not.
6050 gtk_text_view_get_overwrite (GtkTextView *text_view)
6052 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6054 return text_view->priv->overwrite_mode;
6058 * gtk_text_view_set_overwrite:
6059 * @text_view: a #GtkTextView
6060 * @overwrite: %TRUE to turn on overwrite mode, %FALSE to turn it off
6062 * Changes the #GtkTextView overwrite mode.
6067 gtk_text_view_set_overwrite (GtkTextView *text_view,
6070 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6071 overwrite = overwrite != FALSE;
6073 if (text_view->priv->overwrite_mode != overwrite)
6074 gtk_text_view_toggle_overwrite (text_view);
6078 * gtk_text_view_set_accepts_tab:
6079 * @text_view: A #GtkTextView
6080 * @accepts_tab: %TRUE if pressing the Tab key should insert a tab
6081 * character, %FALSE, if pressing the Tab key should move the
6084 * Sets the behavior of the text widget when the Tab key is pressed.
6085 * If @accepts_tab is %TRUE, a tab character is inserted. If @accepts_tab
6086 * is %FALSE the keyboard focus is moved to the next widget in the focus
6092 gtk_text_view_set_accepts_tab (GtkTextView *text_view,
6093 gboolean accepts_tab)
6095 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6097 accepts_tab = accepts_tab != FALSE;
6099 if (text_view->priv->accepts_tab != accepts_tab)
6101 text_view->priv->accepts_tab = accepts_tab;
6103 g_object_notify (G_OBJECT (text_view), "accepts-tab");
6108 * gtk_text_view_get_accepts_tab:
6109 * @text_view: A #GtkTextView
6111 * Returns whether pressing the Tab key inserts a tab characters.
6112 * gtk_text_view_set_accepts_tab().
6114 * Return value: %TRUE if pressing the Tab key inserts a tab character,
6115 * %FALSE if pressing the Tab key moves the keyboard focus.
6120 gtk_text_view_get_accepts_tab (GtkTextView *text_view)
6122 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6124 return text_view->priv->accepts_tab;
6128 gtk_text_view_compat_move_focus (GtkTextView *text_view,
6129 GtkDirectionType direction_type)
6131 GSignalInvocationHint *hint = g_signal_get_invocation_hint (text_view);
6133 /* as of GTK+ 2.12, the "move-focus" signal has been moved to GtkWidget,
6134 * the evil code below makes sure that both emitting the signal and
6135 * calling the virtual function directly continue to work as expetcted
6138 if (hint->signal_id == g_signal_lookup ("move-focus", GTK_TYPE_WIDGET))
6140 /* if this is a signal emission, chain up */
6144 g_signal_chain_from_overridden_handler (text_view,
6145 direction_type, &retval);
6149 /* otherwise emit the signal, since somebody called the virtual
6153 g_signal_emit_by_name (text_view, "move-focus", direction_type);
6162 gtk_text_view_unselect (GtkTextView *text_view)
6166 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
6167 gtk_text_buffer_get_insert (get_buffer (text_view)));
6169 gtk_text_buffer_move_mark (get_buffer (text_view),
6170 gtk_text_buffer_get_selection_bound (get_buffer (text_view)),
6175 get_iter_at_pointer (GtkTextView *text_view,
6181 GtkTextViewPrivate *priv;
6182 gint xcoord, ycoord;
6183 GdkModifierType state;
6185 priv = text_view->priv;
6187 gdk_window_get_device_position (priv->text_window->bin_window,
6188 device, &xcoord, &ycoord, &state);
6190 gtk_text_layout_get_iter_at_pixel (priv->layout,
6192 xcoord + priv->xoffset,
6193 ycoord + priv->yoffset);
6202 move_mark_to_pointer_and_scroll (GtkTextView *text_view,
6203 const gchar *mark_name,
6206 GtkTextIter newplace;
6209 get_iter_at_pointer (text_view, device, &newplace, NULL, NULL);
6211 mark = gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
6213 /* This may invalidate the layout */
6214 DV(g_print (G_STRLOC": move mark\n"));
6216 gtk_text_buffer_move_mark (get_buffer (text_view),
6220 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6221 gtk_text_view_scroll_mark_onscreen (text_view, mark);
6223 DV (g_print ("first validate idle leaving %s is %d\n",
6224 G_STRLOC, text_view->priv->first_validate_idle));
6228 selection_scan_timeout (gpointer data)
6230 GtkTextView *text_view;
6232 text_view = GTK_TEXT_VIEW (data);
6234 gtk_text_view_scroll_mark_onscreen (text_view,
6235 gtk_text_buffer_get_insert (get_buffer (text_view)));
6237 return TRUE; /* remain installed. */
6240 #define UPPER_OFFSET_ANCHOR 0.8
6241 #define LOWER_OFFSET_ANCHOR 0.2
6244 check_scroll (gdouble offset, GtkAdjustment *adj)
6246 if ((offset > UPPER_OFFSET_ANCHOR &&
6247 adj->value + adj->page_size < adj->upper) ||
6248 (offset < LOWER_OFFSET_ANCHOR &&
6249 adj->value > adj->lower))
6256 drag_scan_timeout (gpointer data)
6258 GtkTextView *text_view;
6259 GtkTextViewPrivate *priv;
6260 GtkTextIter newplace;
6261 gint x, y, width, height;
6262 gdouble pointer_xoffset, pointer_yoffset;
6264 text_view = GTK_TEXT_VIEW (data);
6265 priv = text_view->priv;
6267 get_iter_at_pointer (text_view, priv->dnd_device, &newplace, &x, &y);
6268 gdk_drawable_get_size (priv->text_window->bin_window, &width, &height);
6270 gtk_text_buffer_move_mark (get_buffer (text_view),
6274 pointer_xoffset = (gdouble) x / width;
6275 pointer_yoffset = (gdouble) y / height;
6277 if (check_scroll (pointer_xoffset, priv->hadjustment) ||
6278 check_scroll (pointer_yoffset, priv->vadjustment))
6280 /* do not make offsets surpass lower nor upper anchors, this makes
6281 * scrolling speed relative to the distance of the pointer to the
6282 * anchors when it moves beyond them.
6284 pointer_xoffset = CLAMP (pointer_xoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6285 pointer_yoffset = CLAMP (pointer_yoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6287 gtk_text_view_scroll_to_mark (text_view,
6289 0., TRUE, pointer_xoffset, pointer_yoffset);
6300 } SelectionGranularity;
6303 * Move @start and @end to the boundaries of the selection unit (indicated by
6304 * @granularity) which contained @start initially.
6305 * If the selction unit is SELECT_WORDS and @start is not contained in a word
6306 * the selection is extended to all the white spaces between the end of the
6307 * word preceding @start and the start of the one following.
6310 extend_selection (GtkTextView *text_view,
6311 SelectionGranularity granularity,
6317 if (granularity == SELECT_WORDS)
6319 if (gtk_text_iter_inside_word (start))
6321 if (!gtk_text_iter_starts_word (start))
6322 gtk_text_iter_backward_visible_word_start (start);
6324 if (!gtk_text_iter_ends_word (end))
6326 if (!gtk_text_iter_forward_visible_word_end (end))
6327 gtk_text_iter_forward_to_end (end);
6335 if (gtk_text_iter_backward_visible_word_start (&tmp))
6336 gtk_text_iter_forward_visible_word_end (&tmp);
6338 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (start))
6341 gtk_text_iter_set_line_offset (start, 0);
6344 if (!gtk_text_iter_forward_visible_word_end (&tmp))
6345 gtk_text_iter_forward_to_end (&tmp);
6347 if (gtk_text_iter_ends_word (&tmp))
6348 gtk_text_iter_backward_visible_word_start (&tmp);
6350 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (end))
6353 gtk_text_iter_forward_to_line_end (end);
6356 else if (granularity == SELECT_LINES)
6358 if (gtk_text_view_starts_display_line (text_view, start))
6360 /* If on a display line boundary, we assume the user
6361 * clicked off the end of a line and we therefore select
6362 * the line before the boundary.
6364 gtk_text_view_backward_display_line_start (text_view, start);
6368 /* start isn't on the start of a line, so we move it to the
6369 * start, and move end to the end unless it's already there.
6371 gtk_text_view_backward_display_line_start (text_view, start);
6373 if (!gtk_text_view_starts_display_line (text_view, end))
6374 gtk_text_view_forward_display_line_end (text_view, end);
6382 SelectionGranularity granularity;
6383 GtkTextMark *orig_start;
6384 GtkTextMark *orig_end;
6388 selection_data_free (SelectionData *data)
6390 if (data->orig_start != NULL)
6391 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start),
6393 if (data->orig_end != NULL)
6394 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end),
6400 selection_motion_event_handler (GtkTextView *text_view,
6401 GdkEventMotion *event,
6402 SelectionData *data)
6404 GtkTextViewPrivate *priv;
6406 priv = text_view->priv;
6407 gdk_event_request_motions (event);
6409 if (priv->grab_device != event->device)
6412 if (data->granularity == SELECT_CHARACTERS)
6414 move_mark_to_pointer_and_scroll (text_view, "insert", event->device);
6418 GtkTextIter cursor, start, end;
6419 GtkTextIter orig_start, orig_end;
6420 GtkTextBuffer *buffer;
6422 buffer = get_buffer (text_view);
6424 gtk_text_buffer_get_iter_at_mark (buffer, &orig_start, data->orig_start);
6425 gtk_text_buffer_get_iter_at_mark (buffer, &orig_end, data->orig_end);
6427 get_iter_at_pointer (text_view, event->device, &cursor, NULL, NULL);
6430 extend_selection (text_view, data->granularity, &start, &end);
6432 /* either the selection extends to the front, or end (or not) */
6433 if (gtk_text_iter_compare (&cursor, &orig_start) < 0)
6434 gtk_text_buffer_select_range (buffer, &start, &orig_end);
6436 gtk_text_buffer_select_range (buffer, &end, &orig_start);
6438 gtk_text_view_scroll_mark_onscreen (text_view,
6439 gtk_text_buffer_get_insert (buffer));
6442 /* If we had to scroll offscreen, insert a timeout to do so
6443 * again. Note that in the timeout, even if the mouse doesn't
6444 * move, due to this scroll xoffset/yoffset will have changed
6445 * and we'll need to scroll again.
6447 if (text_view->priv->scroll_timeout != 0) /* reset on every motion event */
6448 g_source_remove (text_view->priv->scroll_timeout);
6450 text_view->priv->scroll_timeout =
6451 gdk_threads_add_timeout (50, selection_scan_timeout, text_view);
6457 gtk_text_view_start_selection_drag (GtkTextView *text_view,
6458 const GtkTextIter *iter,
6459 GdkEventButton *button)
6461 GtkTextViewPrivate *priv;
6462 GtkTextIter cursor, ins, bound;
6463 GtkTextIter orig_start, orig_end;
6464 GtkTextBuffer *buffer;
6465 SelectionData *data;
6467 if (text_view->priv->selection_drag_handler != 0)
6470 priv = text_view->priv;
6471 data = g_new0 (SelectionData, 1);
6473 if (button->type == GDK_2BUTTON_PRESS)
6474 data->granularity = SELECT_WORDS;
6475 else if (button->type == GDK_3BUTTON_PRESS)
6476 data->granularity = SELECT_LINES;
6478 data->granularity = SELECT_CHARACTERS;
6480 priv->grab_device = button->device;
6481 gtk_device_grab_add (GTK_WIDGET (text_view),
6485 buffer = get_buffer (text_view);
6490 extend_selection (text_view, data->granularity, &ins, &bound);
6494 if (button->state & GDK_SHIFT_MASK)
6496 /* Extend selection */
6497 GtkTextIter old_ins, old_bound;
6498 GtkTextIter old_start, old_end;
6500 gtk_text_buffer_get_iter_at_mark (buffer, &old_ins, gtk_text_buffer_get_insert (buffer));
6501 gtk_text_buffer_get_iter_at_mark (buffer, &old_bound, gtk_text_buffer_get_selection_bound (buffer));
6502 old_start = old_ins;
6503 old_end = old_bound;
6504 gtk_text_iter_order (&old_start, &old_end);
6506 /* move the front cursor, if the mouse is in front of the selection. Should the
6507 * cursor however be inside the selection (this happens on tripple click) then we
6508 * move the side which was last moved (current insert mark) */
6509 if (gtk_text_iter_compare (&cursor, &old_start) <= 0 ||
6510 (gtk_text_iter_compare (&cursor, &old_end) < 0 &&
6511 gtk_text_iter_compare (&old_ins, &old_bound) <= 0))
6514 orig_start = old_end;
6526 gtk_text_buffer_select_range (buffer, &ins, &bound);
6528 gtk_text_iter_order (&orig_start, &orig_end);
6529 data->orig_start = gtk_text_buffer_create_mark (buffer, NULL,
6531 data->orig_end = gtk_text_buffer_create_mark (buffer, NULL,
6533 gtk_text_view_check_cursor_blink (text_view);
6535 text_view->priv->selection_drag_handler = g_signal_connect_data (text_view,
6536 "motion-notify-event",
6537 G_CALLBACK (selection_motion_event_handler),
6539 (GClosureNotify) selection_data_free, 0);
6542 /* returns whether we were really dragging */
6544 gtk_text_view_end_selection_drag (GtkTextView *text_view)
6546 GtkTextViewPrivate *priv;
6548 priv = text_view->priv;
6550 if (!priv->grab_device)
6553 if (priv->selection_drag_handler == 0)
6556 g_signal_handler_disconnect (text_view, priv->selection_drag_handler);
6557 priv->selection_drag_handler = 0;
6559 if (priv->scroll_timeout != 0)
6561 g_source_remove (priv->scroll_timeout);
6562 priv->scroll_timeout = 0;
6565 gtk_device_grab_remove (GTK_WIDGET (text_view),
6567 priv->grab_device = NULL;
6577 gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
6578 GtkTextAttributes *values,
6581 values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
6582 values->appearance.fg_color = style->text[GTK_STATE_NORMAL];
6585 pango_font_description_free (values->font);
6587 values->font = pango_font_description_copy (style->font_desc);
6591 gtk_text_view_check_keymap_direction (GtkTextView *text_view)
6593 GtkTextViewPrivate *priv = text_view->priv;
6597 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
6598 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)));
6599 GtkTextDirection new_cursor_dir;
6600 GtkTextDirection new_keyboard_dir;
6601 gboolean split_cursor;
6603 g_object_get (settings,
6604 "gtk-split-cursor", &split_cursor,
6607 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
6608 new_keyboard_dir = GTK_TEXT_DIR_RTL;
6610 new_keyboard_dir = GTK_TEXT_DIR_LTR;
6613 new_cursor_dir = GTK_TEXT_DIR_NONE;
6615 new_cursor_dir = new_keyboard_dir;
6617 gtk_text_layout_set_cursor_direction (priv->layout, new_cursor_dir);
6618 gtk_text_layout_set_keyboard_direction (priv->layout, new_keyboard_dir);
6623 gtk_text_view_ensure_layout (GtkTextView *text_view)
6626 GtkTextViewPrivate *priv;
6628 widget = GTK_WIDGET (text_view);
6629 priv = text_view->priv;
6631 if (priv->layout == NULL)
6633 GtkTextAttributes *style;
6634 PangoContext *ltr_context, *rtl_context;
6637 DV(g_print(G_STRLOC"\n"));
6639 priv->layout = gtk_text_layout_new ();
6641 g_signal_connect (priv->layout,
6643 G_CALLBACK (invalidated_handler),
6646 g_signal_connect (priv->layout,
6648 G_CALLBACK (changed_handler),
6651 g_signal_connect (priv->layout,
6653 G_CALLBACK (gtk_text_view_child_allocated),
6656 if (get_buffer (text_view))
6657 gtk_text_layout_set_buffer (priv->layout, get_buffer (text_view));
6659 if ((gtk_widget_has_focus (widget) && priv->cursor_visible))
6660 gtk_text_view_pend_cursor_blink (text_view);
6662 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
6664 gtk_text_layout_set_overwrite_mode (priv->layout,
6665 priv->overwrite_mode && priv->editable);
6667 ltr_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6668 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
6669 rtl_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6670 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
6672 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
6674 g_object_unref (ltr_context);
6675 g_object_unref (rtl_context);
6677 gtk_text_view_check_keymap_direction (text_view);
6679 style = gtk_text_attributes_new ();
6681 gtk_widget_ensure_style (widget);
6682 gtk_text_view_set_attributes_from_style (text_view,
6683 style, widget->style);
6685 style->pixels_above_lines = priv->pixels_above_lines;
6686 style->pixels_below_lines = priv->pixels_below_lines;
6687 style->pixels_inside_wrap = priv->pixels_inside_wrap;
6688 style->left_margin = priv->left_margin;
6689 style->right_margin = priv->right_margin;
6690 style->indent = priv->indent;
6691 style->tabs = priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
6693 style->wrap_mode = priv->wrap_mode;
6694 style->justification = priv->justify;
6695 style->direction = gtk_widget_get_direction (GTK_WIDGET (text_view));
6697 gtk_text_layout_set_default_style (priv->layout, style);
6699 gtk_text_attributes_unref (style);
6701 /* Set layout for all anchored children */
6703 tmp_list = priv->children;
6704 while (tmp_list != NULL)
6706 GtkTextViewChild *vc = tmp_list->data;
6710 gtk_text_anchored_child_set_layout (vc->widget,
6712 /* vc may now be invalid! */
6715 tmp_list = g_slist_next (tmp_list);
6718 gtk_text_view_invalidate (text_view);
6723 * gtk_text_view_get_default_attributes:
6724 * @text_view: a #GtkTextView
6726 * Obtains a copy of the default text attributes. These are the
6727 * attributes used for text unless a tag overrides them.
6728 * You'd typically pass the default attributes in to
6729 * gtk_text_iter_get_attributes() in order to get the
6730 * attributes in effect at a given text position.
6732 * The return value is a copy owned by the caller of this function,
6733 * and should be freed.
6735 * Return value: a new #GtkTextAttributes
6738 gtk_text_view_get_default_attributes (GtkTextView *text_view)
6740 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
6742 gtk_text_view_ensure_layout (text_view);
6744 return gtk_text_attributes_copy (text_view->priv->layout->default_style);
6748 gtk_text_view_destroy_layout (GtkTextView *text_view)
6750 GtkTextViewPrivate *priv = text_view->priv;
6756 gtk_text_view_remove_validate_idles (text_view);
6758 g_signal_handlers_disconnect_by_func (priv->layout,
6759 invalidated_handler,
6761 g_signal_handlers_disconnect_by_func (priv->layout,
6765 /* Remove layout from all anchored children */
6766 tmp_list = priv->children;
6767 while (tmp_list != NULL)
6769 GtkTextViewChild *vc = tmp_list->data;
6773 gtk_text_anchored_child_set_layout (vc->widget, NULL);
6774 /* vc may now be invalid! */
6777 tmp_list = g_slist_next (tmp_list);
6780 gtk_text_view_stop_cursor_blink (text_view);
6781 gtk_text_view_end_selection_drag (text_view);
6783 g_object_unref (priv->layout);
6784 priv->layout = NULL;
6789 * gtk_text_view_reset_im_context:
6790 * @text_view: a #GtkTextView
6792 * Reset the input method context of the text view if needed.
6794 * This can be necessary in the case where modifying the buffer
6795 * would confuse on-going input method behavior.
6800 gtk_text_view_reset_im_context (GtkTextView *text_view)
6802 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6804 if (text_view->priv->need_im_reset)
6806 text_view->priv->need_im_reset = FALSE;
6807 gtk_im_context_reset (text_view->priv->im_context);
6812 * gtk_text_view_im_context_filter_keypress:
6813 * @text_view: a #GtkTextView
6814 * @event: the key event
6816 * Allow the #GtkTextView input method to internally handle key press
6817 * and release events. If this function returns %TRUE, then no further
6818 * processing should be done for this key event. See
6819 * gtk_im_context_filter_keypress().
6821 * Note that you are expected to call this function from your handler
6822 * when overriding key event handling. This is needed in the case when
6823 * you need to insert your own key handling between the input method
6824 * and the default key event handling of the #GtkTextView.
6828 * gtk_foo_bar_key_press_event (GtkWidget *widget,
6829 * GdkEventKey *event)
6831 * if ((key->keyval == GDK_Return || key->keyval == GDK_KP_Enter))
6833 * if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
6837 * /* Do some stuff */
6839 * return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event);
6843 * Return value: %TRUE if the input method handled the key event.
6848 gtk_text_view_im_context_filter_keypress (GtkTextView *text_view,
6851 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6853 return gtk_im_context_filter_keypress (text_view->priv->im_context, event);
6861 drag_begin_cb (GtkWidget *widget,
6862 GdkDragContext *context,
6865 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6866 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6869 GdkPixmap *pixmap = NULL;
6871 g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
6873 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6874 pixmap = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
6878 gtk_drag_set_icon_pixmap (context,
6879 gdk_drawable_get_colormap (pixmap),
6883 g_object_unref (pixmap);
6887 gtk_drag_set_icon_default (context);
6892 gtk_text_view_start_selection_dnd (GtkTextView *text_view,
6893 const GtkTextIter *iter,
6894 GdkEventMotion *event)
6896 GtkTargetList *target_list;
6898 text_view->priv->drag_start_x = -1;
6899 text_view->priv->drag_start_y = -1;
6900 text_view->priv->pending_place_cursor_button = 0;
6902 target_list = gtk_text_buffer_get_copy_target_list (get_buffer (text_view));
6904 g_signal_connect (text_view, "drag-begin",
6905 G_CALLBACK (drag_begin_cb), NULL);
6906 gtk_drag_begin (GTK_WIDGET (text_view), target_list,
6907 GDK_ACTION_COPY | GDK_ACTION_MOVE,
6908 1, (GdkEvent*)event);
6912 gtk_text_view_drag_begin (GtkWidget *widget,
6913 GdkDragContext *context)
6919 gtk_text_view_drag_end (GtkWidget *widget,
6920 GdkDragContext *context)
6925 gtk_text_view_drag_data_get (GtkWidget *widget,
6926 GdkDragContext *context,
6927 GtkSelectionData *selection_data,
6931 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6932 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6934 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
6936 gtk_selection_data_set (selection_data,
6937 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
6942 else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
6949 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6951 /* Extract the selected text */
6952 str = gtk_text_buffer_serialize (buffer, buffer,
6953 selection_data->target,
6960 gtk_selection_data_set (selection_data,
6961 selection_data->target,
6963 (guchar *) str, len);
6973 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6975 /* Extract the selected text */
6976 str = gtk_text_iter_get_visible_text (&start, &end);
6981 gtk_selection_data_set_text (selection_data, str, -1);
6988 gtk_text_view_drag_data_delete (GtkWidget *widget,
6989 GdkDragContext *context)
6991 gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->priv->buffer,
6992 TRUE, GTK_TEXT_VIEW (widget)->priv->editable);
6996 gtk_text_view_drag_leave (GtkWidget *widget,
6997 GdkDragContext *context,
7000 GtkTextView *text_view;
7001 GtkTextViewPrivate *priv;
7003 text_view = GTK_TEXT_VIEW (widget);
7004 priv = text_view->priv;
7006 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7008 if (priv->dnd_device)
7009 priv->dnd_device = NULL;
7011 if (priv->scroll_timeout != 0)
7012 g_source_remove (priv->scroll_timeout);
7014 priv->scroll_timeout = 0;
7018 gtk_text_view_drag_motion (GtkWidget *widget,
7019 GdkDragContext *context,
7024 GtkTextIter newplace;
7025 GtkTextView *text_view;
7026 GtkTextViewPrivate *priv;
7029 GdkRectangle target_rect;
7032 GdkDragAction suggested_action = 0;
7034 text_view = GTK_TEXT_VIEW (widget);
7035 priv = text_view->priv;
7037 target_rect = priv->text_window->allocation;
7039 if (x < target_rect.x ||
7040 y < target_rect.y ||
7041 x > (target_rect.x + target_rect.width) ||
7042 y > (target_rect.y + target_rect.height))
7043 return FALSE; /* outside the text window, allow parent widgets to handle event */
7045 gtk_text_view_window_to_buffer_coords (text_view,
7046 GTK_TEXT_WINDOW_WIDGET,
7050 gtk_text_layout_get_iter_at_pixel (priv->layout,
7054 target = gtk_drag_dest_find_target (widget, context,
7055 gtk_drag_dest_get_target_list (widget));
7057 if (target == GDK_NONE)
7059 /* can't accept any of the offered targets */
7061 else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7063 gtk_text_iter_compare (&newplace, &start) >= 0 &&
7064 gtk_text_iter_compare (&newplace, &end) <= 0)
7066 /* We're inside the selection. */
7070 if (gtk_text_iter_can_insert (&newplace, priv->editable))
7072 GtkWidget *source_widget;
7074 suggested_action = context->suggested_action;
7076 source_widget = gtk_drag_get_source_widget (context);
7078 if (source_widget == widget)
7080 /* Default to MOVE, unless the user has
7081 * pressed ctrl or alt to affect available actions
7083 if ((context->actions & GDK_ACTION_MOVE) != 0)
7084 suggested_action = GDK_ACTION_MOVE;
7089 /* Can't drop here. */
7093 if (suggested_action != 0)
7095 gtk_text_mark_set_visible (priv->dnd_mark,
7096 priv->cursor_visible);
7098 gdk_drag_status (context, suggested_action, time);
7102 gdk_drag_status (context, 0, time);
7103 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7106 priv->dnd_device = gdk_drag_context_get_device (context);
7108 if (!priv->scroll_timeout)
7109 priv->scroll_timeout =
7110 gdk_threads_add_timeout (100, drag_scan_timeout, text_view);
7112 /* TRUE return means don't propagate the drag motion to parent
7113 * widgets that may also be drop sites.
7119 gtk_text_view_drag_drop (GtkWidget *widget,
7120 GdkDragContext *context,
7125 GtkTextView *text_view;
7126 GtkTextViewPrivate *priv;
7127 GtkTextIter drop_point;
7128 GdkAtom target = GDK_NONE;
7130 text_view = GTK_TEXT_VIEW (widget);
7131 priv = text_view->priv;
7133 if (priv->scroll_timeout != 0)
7134 g_source_remove (priv->scroll_timeout);
7136 priv->scroll_timeout = 0;
7138 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7140 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7144 if (gtk_text_iter_can_insert (&drop_point, priv->editable))
7145 target = gtk_drag_dest_find_target (widget, context, NULL);
7147 if (target != GDK_NONE)
7148 gtk_drag_get_data (widget, context, target, time);
7150 gtk_drag_finish (context, FALSE, FALSE, time);
7156 insert_text_data (GtkTextView *text_view,
7157 GtkTextIter *drop_point,
7158 GtkSelectionData *selection_data)
7162 str = gtk_selection_data_get_text (selection_data);
7166 if (!gtk_text_buffer_insert_interactive (get_buffer (text_view),
7167 drop_point, (gchar *) str, -1,
7168 text_view->priv->editable))
7170 gtk_widget_error_bell (GTK_WIDGET (text_view));
7178 gtk_text_view_drag_data_received (GtkWidget *widget,
7179 GdkDragContext *context,
7182 GtkSelectionData *selection_data,
7186 GtkTextIter drop_point;
7187 GtkTextView *text_view;
7188 GtkTextViewPrivate *priv;
7189 gboolean success = FALSE;
7190 GtkTextBuffer *buffer = NULL;
7192 text_view = GTK_TEXT_VIEW (widget);
7193 priv = text_view->priv;
7195 if (!priv->dnd_mark)
7198 buffer = get_buffer (text_view);
7200 gtk_text_buffer_get_iter_at_mark (buffer,
7204 if (!gtk_text_iter_can_insert (&drop_point, priv->editable))
7209 gtk_text_buffer_begin_user_action (buffer);
7211 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7213 GtkTextBuffer *src_buffer = NULL;
7214 GtkTextIter start, end;
7215 gboolean copy_tags = TRUE;
7217 if (selection_data->length != sizeof (src_buffer))
7220 memcpy (&src_buffer, selection_data->data, sizeof (src_buffer));
7222 if (src_buffer == NULL)
7225 g_return_if_fail (GTK_IS_TEXT_BUFFER (src_buffer));
7227 if (gtk_text_buffer_get_tag_table (src_buffer) !=
7228 gtk_text_buffer_get_tag_table (buffer))
7230 /* try to find a suitable rich text target instead */
7234 GdkAtom target = GDK_NONE;
7238 atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms);
7240 for (list = context->targets; list; list = g_list_next (list))
7244 for (i = 0; i < n_atoms; i++)
7245 if (GUINT_TO_POINTER (atoms[i]) == list->data)
7254 if (target != GDK_NONE)
7256 gtk_drag_get_data (widget, context, target, time);
7257 gtk_text_buffer_end_user_action (buffer);
7262 if (gtk_text_buffer_get_selection_bounds (src_buffer,
7267 gtk_text_buffer_insert_range_interactive (buffer,
7276 str = gtk_text_iter_get_visible_text (&start, &end);
7277 gtk_text_buffer_insert_interactive (buffer,
7278 &drop_point, str, -1,
7284 else if (selection_data->length > 0 &&
7285 info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
7288 GError *error = NULL;
7290 retval = gtk_text_buffer_deserialize (buffer, buffer,
7291 selection_data->target,
7293 (guint8 *) selection_data->data,
7294 selection_data->length,
7299 g_warning ("error pasting: %s\n", error->message);
7300 g_clear_error (&error);
7304 insert_text_data (text_view, &drop_point, selection_data);
7307 gtk_drag_finish (context, success,
7308 success && context->action == GDK_ACTION_MOVE,
7313 gtk_text_buffer_get_iter_at_mark (buffer,
7316 gtk_text_buffer_place_cursor (buffer, &drop_point);
7318 gtk_text_buffer_end_user_action (buffer);
7323 * gtk_text_view_get_hadjustment:
7324 * @text_view: a #GtkTextView
7326 * Gets the horizontal-scrolling #GtkAdjustment.
7328 * Returns: (transfer none): pointer to the horizontal #GtkAdjustment
7333 gtk_text_view_get_hadjustment (GtkTextView *text_view)
7335 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7337 return get_hadjustment (text_view);
7341 * gtk_text_view_get_vadjustment:
7342 * @text_view: a #GtkTextView
7344 * Gets the vertical-scrolling #GtkAdjustment.
7346 * Returns: (transfer none): pointer to the vertical #GtkAdjustment
7351 gtk_text_view_get_vadjustment (GtkTextView *text_view)
7353 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7355 return get_vadjustment (text_view);
7358 static GtkAdjustment*
7359 get_hadjustment (GtkTextView *text_view)
7361 if (text_view->priv->hadjustment == NULL)
7362 gtk_text_view_set_scroll_adjustments (text_view,
7363 NULL, /* forces creation */
7364 text_view->priv->vadjustment);
7366 return text_view->priv->hadjustment;
7369 static GtkAdjustment*
7370 get_vadjustment (GtkTextView *text_view)
7372 if (text_view->priv->vadjustment == NULL)
7373 gtk_text_view_set_scroll_adjustments (text_view,
7374 text_view->priv->hadjustment,
7375 NULL); /* forces creation */
7376 return text_view->priv->vadjustment;
7381 gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
7382 GtkAdjustment *hadj,
7383 GtkAdjustment *vadj)
7385 GtkTextViewPrivate *priv = text_view->priv;
7386 gboolean need_adjust = FALSE;
7389 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7391 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7393 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7395 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7397 if (priv->hadjustment && (priv->hadjustment != hadj))
7399 g_signal_handlers_disconnect_by_func (priv->hadjustment,
7400 gtk_text_view_value_changed,
7402 g_object_unref (priv->hadjustment);
7405 if (priv->vadjustment && (priv->vadjustment != vadj))
7407 g_signal_handlers_disconnect_by_func (priv->vadjustment,
7408 gtk_text_view_value_changed,
7410 g_object_unref (priv->vadjustment);
7413 if (priv->hadjustment != hadj)
7415 priv->hadjustment = hadj;
7416 g_object_ref_sink (priv->hadjustment);
7418 g_signal_connect (priv->hadjustment, "value-changed",
7419 G_CALLBACK (gtk_text_view_value_changed),
7424 if (priv->vadjustment != vadj)
7426 priv->vadjustment = vadj;
7427 g_object_ref_sink (priv->vadjustment);
7429 g_signal_connect (priv->vadjustment, "value-changed",
7430 G_CALLBACK (gtk_text_view_value_changed),
7436 gtk_text_view_value_changed (NULL, text_view);
7439 /* FIXME this adjust_allocation is a big cut-and-paste from
7440 * GtkCList, needs to be some "official" way to do this
7450 /* The window to which widget->window is relative */
7451 #define ALLOCATION_WINDOW(widget) \
7452 (!gtk_widget_get_has_window (widget) ? \
7453 (widget)->window : \
7454 gdk_window_get_parent ((widget)->window))
7457 adjust_allocation_recurse (GtkWidget *widget,
7460 ScrollData *scroll_data = data;
7462 /* Need to really size allocate instead of just poking
7463 * into widget->allocation if the widget is not realized.
7464 * FIXME someone figure out why this was.
7466 if (!gtk_widget_get_realized (widget))
7468 if (gtk_widget_get_visible (widget))
7470 GdkRectangle tmp_rectangle = widget->allocation;
7471 tmp_rectangle.x += scroll_data->dx;
7472 tmp_rectangle.y += scroll_data->dy;
7474 gtk_widget_size_allocate (widget, &tmp_rectangle);
7479 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
7481 widget->allocation.x += scroll_data->dx;
7482 widget->allocation.y += scroll_data->dy;
7484 if (GTK_IS_CONTAINER (widget))
7485 gtk_container_forall (GTK_CONTAINER (widget),
7486 adjust_allocation_recurse,
7493 adjust_allocation (GtkWidget *widget,
7497 ScrollData scroll_data;
7499 if (gtk_widget_get_realized (widget))
7500 scroll_data.window = ALLOCATION_WINDOW (widget);
7502 scroll_data.window = NULL;
7504 scroll_data.dx = dx;
7505 scroll_data.dy = dy;
7507 adjust_allocation_recurse (widget, &scroll_data);
7511 gtk_text_view_value_changed (GtkAdjustment *adj,
7512 GtkTextView *text_view)
7514 GtkTextViewPrivate *priv;
7520 priv = text_view->priv;
7522 /* Note that we oddly call this function with adj == NULL
7526 priv->onscreen_validated = FALSE;
7528 DV(g_print(">Scroll offset changed %s/%g, onscreen_validated = FALSE ("G_STRLOC")\n",
7529 adj == priv->hadjustment ? "hadj" : adj == priv->vadjustment ? "vadj" : "none",
7530 adj ? adj->value : 0.0));
7532 if (adj == priv->hadjustment)
7534 dx = priv->xoffset - (gint)adj->value;
7535 priv->xoffset = adj->value;
7537 /* If the change is due to a size change we need
7538 * to invalidate the entire text window because there might be
7539 * right-aligned or centered text
7541 if (priv->width_changed)
7543 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7544 gdk_window_invalidate_rect (priv->text_window->bin_window, NULL, FALSE);
7546 priv->width_changed = FALSE;
7549 else if (adj == priv->vadjustment)
7551 dy = priv->yoffset - (gint)adj->value;
7552 priv->yoffset = adj->value;
7556 gtk_text_layout_get_line_at_y (priv->layout, &iter, adj->value, &line_top);
7558 gtk_text_buffer_move_mark (get_buffer (text_view), priv->first_para_mark, &iter);
7560 priv->first_para_pixels = adj->value - line_top;
7564 if (dx != 0 || dy != 0)
7568 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7572 if (priv->left_window)
7573 text_window_scroll (priv->left_window, 0, dy);
7574 if (priv->right_window)
7575 text_window_scroll (priv->right_window, 0, dy);
7580 if (priv->top_window)
7581 text_window_scroll (priv->top_window, dx, 0);
7582 if (priv->bottom_window)
7583 text_window_scroll (priv->bottom_window, dx, 0);
7586 /* It looks nicer to scroll the main area last, because
7587 * it takes a while, and making the side areas update
7588 * afterward emphasizes the slowness of scrolling the
7591 text_window_scroll (priv->text_window, dx, dy);
7594 /* Children are now "moved" in the text window, poke
7595 * into widget->allocation for each child
7597 tmp_list = priv->children;
7598 while (tmp_list != NULL)
7600 GtkTextViewChild *child = tmp_list->data;
7603 adjust_allocation (child->widget, dx, dy);
7605 tmp_list = g_slist_next (tmp_list);
7609 /* This could result in invalidation, which would install the
7610 * first_validate_idle, which would validate onscreen;
7611 * but we're going to go ahead and validate here, so
7612 * first_validate_idle shouldn't have anything to do.
7614 gtk_text_view_update_layout_width (text_view);
7616 /* We also update the IM spot location here, since the IM context
7617 * might do something that leads to validation.
7619 gtk_text_view_update_im_spot_location (text_view);
7621 /* note that validation of onscreen could invoke this function
7622 * recursively, by scrolling to maintain first_para, or in response
7623 * to updating the layout width, however there is no problem with
7624 * that, or shouldn't be.
7626 gtk_text_view_validate_onscreen (text_view);
7628 /* process exposes */
7629 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7631 DV (g_print ("Processing updates (%s)\n", G_STRLOC));
7633 if (priv->left_window)
7634 gdk_window_process_updates (priv->left_window->bin_window, TRUE);
7636 if (priv->right_window)
7637 gdk_window_process_updates (priv->right_window->bin_window, TRUE);
7639 if (priv->top_window)
7640 gdk_window_process_updates (priv->top_window->bin_window, TRUE);
7642 if (priv->bottom_window)
7643 gdk_window_process_updates (priv->bottom_window->bin_window, TRUE);
7645 gdk_window_process_updates (priv->text_window->bin_window, TRUE);
7648 /* If this got installed, get rid of it, it's just a waste of time. */
7649 if (priv->first_validate_idle != 0)
7651 g_source_remove (priv->first_validate_idle);
7652 priv->first_validate_idle = 0;
7655 /* Finally we update the IM cursor location again, to ensure any
7656 * changes made by the validation are pushed through.
7658 gtk_text_view_update_im_spot_location (text_view);
7660 DV(g_print(">End scroll offset changed handler ("G_STRLOC")\n"));
7664 gtk_text_view_commit_handler (GtkIMContext *context,
7666 GtkTextView *text_view)
7668 gtk_text_view_commit_text (text_view, str);
7672 gtk_text_view_commit_text (GtkTextView *text_view,
7675 GtkTextViewPrivate *priv;
7676 gboolean had_selection;
7678 priv = text_view->priv;
7680 gtk_text_buffer_begin_user_action (get_buffer (text_view));
7682 had_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7685 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
7688 if (!strcmp (str, "\n"))
7690 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
7693 gtk_widget_error_bell (GTK_WIDGET (text_view));
7698 if (!had_selection && priv->overwrite_mode)
7702 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7704 gtk_text_buffer_get_insert (get_buffer (text_view)));
7705 if (!gtk_text_iter_ends_line (&insert))
7706 gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
7709 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
7712 gtk_widget_error_bell (GTK_WIDGET (text_view));
7716 gtk_text_buffer_end_user_action (get_buffer (text_view));
7718 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
7719 DV(g_print (G_STRLOC": scrolling onscreen\n"));
7720 gtk_text_view_scroll_mark_onscreen (text_view,
7721 gtk_text_buffer_get_insert (get_buffer (text_view)));
7725 gtk_text_view_preedit_changed_handler (GtkIMContext *context,
7726 GtkTextView *text_view)
7728 GtkTextViewPrivate *priv;
7730 PangoAttrList *attrs;
7734 priv = text_view->priv;
7736 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
7737 gtk_text_buffer_get_insert (priv->buffer));
7739 /* Keypress events are passed to input method even if cursor position is
7740 * not editable; so beep here if it's multi-key input sequence, input
7741 * method will be reset in key-press-event handler.
7743 gtk_im_context_get_preedit_string (context, &str, &attrs, &cursor_pos);
7745 if (str && str[0] && !gtk_text_iter_can_insert (&iter, priv->editable))
7747 gtk_widget_error_bell (GTK_WIDGET (text_view));
7751 g_signal_emit (text_view, signals[PREEDIT_CHANGED], 0, str);
7754 gtk_text_layout_set_preedit_string (priv->layout, str, attrs, cursor_pos);
7755 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
7756 gtk_text_view_scroll_mark_onscreen (text_view,
7757 gtk_text_buffer_get_insert (get_buffer (text_view)));
7760 pango_attr_list_unref (attrs);
7765 gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
7766 GtkTextView *text_view)
7773 gtk_text_buffer_get_iter_at_mark (text_view->priv->buffer, &start,
7774 gtk_text_buffer_get_insert (text_view->priv->buffer));
7777 pos = gtk_text_iter_get_line_index (&start);
7778 gtk_text_iter_set_line_offset (&start, 0);
7779 gtk_text_iter_forward_to_line_end (&end);
7781 text = gtk_text_iter_get_slice (&start, &end);
7782 gtk_im_context_set_surrounding (context, text, -1, pos);
7789 gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
7792 GtkTextView *text_view)
7794 GtkTextViewPrivate *priv;
7798 priv = text_view->priv;
7800 gtk_text_buffer_get_iter_at_mark (priv->buffer, &start,
7801 gtk_text_buffer_get_insert (priv->buffer));
7804 gtk_text_iter_forward_chars (&start, offset);
7805 gtk_text_iter_forward_chars (&end, offset + n_chars);
7807 gtk_text_buffer_delete_interactive (priv->buffer, &start, &end,
7814 gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
7815 const GtkTextIter *location,
7819 GtkTextView *text_view = GTK_TEXT_VIEW (data);
7820 gboolean need_reset = FALSE;
7822 if (mark == gtk_text_buffer_get_insert (buffer))
7824 text_view->priv->virtual_cursor_x = -1;
7825 text_view->priv->virtual_cursor_y = -1;
7826 gtk_text_view_update_im_spot_location (text_view);
7829 else if (mark == gtk_text_buffer_get_selection_bound (buffer))
7835 gtk_text_view_reset_im_context (text_view);
7839 gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
7840 const GParamSpec *pspec,
7843 GtkWidget *widget = GTK_WIDGET (data);
7844 GtkTargetList *view_list;
7845 GtkTargetList *buffer_list;
7848 view_list = gtk_drag_dest_get_target_list (widget);
7849 buffer_list = gtk_text_buffer_get_paste_target_list (buffer);
7852 gtk_target_list_ref (view_list);
7854 view_list = gtk_target_list_new (NULL, 0);
7856 list = view_list->list;
7859 GtkTargetPair *pair = list->data;
7861 list = g_list_next (list); /* get next element before removing */
7863 if (pair->info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT &&
7864 pair->info <= GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7866 gtk_target_list_remove (view_list, pair->target);
7870 for (list = buffer_list->list; list; list = g_list_next (list))
7872 GtkTargetPair *pair = list->data;
7874 gtk_target_list_add (view_list, pair->target, pair->flags, pair->info);
7877 gtk_drag_dest_set_target_list (widget, view_list);
7878 gtk_target_list_unref (view_list);
7882 gtk_text_view_get_cursor_location (GtkTextView *text_view,
7887 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7888 gtk_text_buffer_get_insert (get_buffer (text_view)));
7890 gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert, pos, NULL);
7894 gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
7895 GtkTextIter *cursor,
7899 GtkTextViewPrivate *priv;
7903 priv = text_view->priv;
7908 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7909 gtk_text_buffer_get_insert (get_buffer (text_view)));
7911 if ((x && priv->virtual_cursor_x == -1) ||
7912 (y && priv->virtual_cursor_y == -1))
7913 gtk_text_layout_get_cursor_locations (priv->layout, &insert, &pos, NULL);
7917 if (priv->virtual_cursor_x != -1)
7918 *x = priv->virtual_cursor_x;
7925 if (priv->virtual_cursor_x != -1)
7926 *y = priv->virtual_cursor_y;
7928 *y = pos.y + pos.height / 2;
7933 gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
7939 if (!text_view->priv->layout)
7942 if (x == -1 || y == -1)
7943 gtk_text_view_get_cursor_location (text_view, &pos);
7945 text_view->priv->virtual_cursor_x = (x == -1) ? pos.x : x;
7946 text_view->priv->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
7949 /* Quick hack of a popup menu
7952 activate_cb (GtkWidget *menuitem,
7953 GtkTextView *text_view)
7955 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
7956 g_signal_emit_by_name (text_view, signal);
7960 append_action_signal (GtkTextView *text_view,
7962 const gchar *stock_id,
7963 const gchar *signal,
7966 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
7968 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
7969 g_signal_connect (menuitem, "activate",
7970 G_CALLBACK (activate_cb), text_view);
7972 gtk_widget_set_sensitive (menuitem, sensitive);
7974 gtk_widget_show (menuitem);
7975 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
7979 gtk_text_view_select_all (GtkWidget *widget,
7982 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
7983 GtkTextBuffer *buffer;
7984 GtkTextIter start_iter, end_iter, insert;
7986 buffer = text_view->priv->buffer;
7989 gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
7990 gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
7994 gtk_text_buffer_get_iter_at_mark (buffer, &insert,
7995 gtk_text_buffer_get_insert (buffer));
7996 gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &insert);
8001 select_all_cb (GtkWidget *menuitem,
8002 GtkTextView *text_view)
8004 gtk_text_view_select_all (GTK_WIDGET (text_view), TRUE);
8008 delete_cb (GtkTextView *text_view)
8010 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
8011 text_view->priv->editable);
8015 popup_menu_detach (GtkWidget *attach_widget,
8018 GTK_TEXT_VIEW (attach_widget)->priv->popup_menu = NULL;
8022 popup_position_func (GtkMenu *menu,
8028 GtkTextView *text_view;
8030 GdkRectangle cursor_rect;
8031 GdkRectangle onscreen_rect;
8032 gint root_x, root_y;
8037 GdkRectangle monitor;
8039 text_view = GTK_TEXT_VIEW (user_data);
8040 widget = GTK_WIDGET (text_view);
8042 g_return_if_fail (gtk_widget_get_realized (widget));
8044 screen = gtk_widget_get_screen (widget);
8046 gdk_window_get_origin (widget->window, &root_x, &root_y);
8048 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8050 gtk_text_buffer_get_insert (get_buffer (text_view)));
8052 gtk_text_view_get_iter_location (text_view,
8056 gtk_text_view_get_visible_rect (text_view, &onscreen_rect);
8058 gtk_widget_size_request (text_view->priv->popup_menu, &req);
8060 /* can't use rectangle_intersect since cursor rect can have 0 width */
8061 if (cursor_rect.x >= onscreen_rect.x &&
8062 cursor_rect.x < onscreen_rect.x + onscreen_rect.width &&
8063 cursor_rect.y >= onscreen_rect.y &&
8064 cursor_rect.y < onscreen_rect.y + onscreen_rect.height)
8066 gtk_text_view_buffer_to_window_coords (text_view,
8067 GTK_TEXT_WINDOW_WIDGET,
8068 cursor_rect.x, cursor_rect.y,
8069 &cursor_rect.x, &cursor_rect.y);
8071 *x = root_x + cursor_rect.x + cursor_rect.width;
8072 *y = root_y + cursor_rect.y + cursor_rect.height;
8076 /* Just center the menu, since cursor is offscreen. */
8077 *x = root_x + (widget->allocation.width / 2 - req.width / 2);
8078 *y = root_y + (widget->allocation.height / 2 - req.height / 2);
8082 *x = CLAMP (*x, root_x, (root_x + widget->allocation.width));
8083 *y = CLAMP (*y, root_y, (root_y + widget->allocation.height));
8085 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
8086 gtk_menu_set_monitor (menu, monitor_num);
8087 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8089 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
8090 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
8097 GtkTextView *text_view;
8103 range_contains_editable_text (const GtkTextIter *start,
8104 const GtkTextIter *end,
8105 gboolean default_editability)
8107 GtkTextIter iter = *start;
8109 while (gtk_text_iter_compare (&iter, end) < 0)
8111 if (gtk_text_iter_editable (&iter, default_editability))
8114 gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
8121 unichar_chosen_func (const char *text,
8124 GtkTextView *text_view = GTK_TEXT_VIEW (data);
8126 gtk_text_view_commit_text (text_view, text);
8130 popup_targets_received (GtkClipboard *clipboard,
8131 GtkSelectionData *data,
8134 PopupInfo *info = user_data;
8135 GtkTextView *text_view;
8136 GtkTextViewPrivate *priv;
8138 text_view = info->text_view;
8139 priv = text_view->priv;
8141 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
8143 /* We implicitely rely here on the fact that if we are pasting ourself, we'll
8144 * have text targets as well as the private GTK_TEXT_BUFFER_CONTENTS target.
8146 gboolean clipboard_contains_text;
8147 GtkWidget *menuitem;
8149 gboolean have_selection;
8150 gboolean can_insert;
8152 GtkTextIter sel_start, sel_end;
8153 gboolean show_input_method_menu;
8154 gboolean show_unicode_menu;
8156 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8158 if (priv->popup_menu)
8159 gtk_widget_destroy (priv->popup_menu);
8161 priv->popup_menu = gtk_menu_new ();
8163 gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
8164 GTK_WIDGET (text_view),
8167 have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
8168 &sel_start, &sel_end);
8170 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8172 gtk_text_buffer_get_insert (get_buffer (text_view)));
8174 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
8176 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8178 range_contains_editable_text (&sel_start, &sel_end,
8180 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8182 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8183 can_insert && clipboard_contains_text);
8185 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8186 gtk_widget_set_sensitive (menuitem,
8188 range_contains_editable_text (&sel_start, &sel_end,
8190 g_signal_connect_swapped (menuitem, "activate",
8191 G_CALLBACK (delete_cb), text_view);
8192 gtk_widget_show (menuitem);
8193 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8195 menuitem = gtk_separator_menu_item_new ();
8196 gtk_widget_show (menuitem);
8197 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8199 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8200 g_signal_connect (menuitem, "activate",
8201 G_CALLBACK (select_all_cb), text_view);
8202 gtk_widget_show (menuitem);
8203 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8205 g_object_get (gtk_widget_get_settings (GTK_WIDGET (text_view)),
8206 "gtk-show-input-method-menu", &show_input_method_menu,
8207 "gtk-show-unicode-menu", &show_unicode_menu,
8210 if (show_input_method_menu || show_unicode_menu)
8212 menuitem = gtk_separator_menu_item_new ();
8213 gtk_widget_show (menuitem);
8214 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8217 if (show_input_method_menu)
8219 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8220 gtk_widget_show (menuitem);
8221 gtk_widget_set_sensitive (menuitem, can_insert);
8223 submenu = gtk_menu_new ();
8224 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8225 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8227 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (priv->im_context),
8228 GTK_MENU_SHELL (submenu));
8231 if (show_unicode_menu)
8233 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8234 gtk_widget_show (menuitem);
8235 gtk_widget_set_sensitive (menuitem, can_insert);
8237 submenu = gtk_menu_new ();
8238 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8239 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8241 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8242 unichar_chosen_func,
8246 g_signal_emit (text_view,
8247 signals[POPULATE_POPUP],
8252 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8254 info->button, info->time);
8257 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8258 popup_position_func, text_view,
8259 0, gtk_get_current_event_time ());
8260 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->popup_menu), FALSE);
8264 g_object_unref (text_view);
8269 gtk_text_view_do_popup (GtkTextView *text_view,
8270 GdkEventButton *event)
8272 PopupInfo *info = g_new (PopupInfo, 1);
8274 /* In order to know what entries we should make sensitive, we
8275 * ask for the current targets of the clipboard, and when
8276 * we get them, then we actually pop up the menu.
8278 info->text_view = g_object_ref (text_view);
8282 info->button = event->button;
8283 info->time = event->time;
8288 info->time = gtk_get_current_event_time ();
8291 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
8292 GDK_SELECTION_CLIPBOARD),
8293 gdk_atom_intern_static_string ("TARGETS"),
8294 popup_targets_received,
8299 gtk_text_view_popup_menu (GtkWidget *widget)
8301 gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
8305 /* Child GdkWindows */
8308 static GtkTextWindow*
8309 text_window_new (GtkTextWindowType type,
8312 gint height_request)
8316 win = g_new (GtkTextWindow, 1);
8319 win->widget = widget;
8321 win->bin_window = NULL;
8322 win->requisition.width = width_request;
8323 win->requisition.height = height_request;
8324 win->allocation.width = width_request;
8325 win->allocation.height = height_request;
8326 win->allocation.x = 0;
8327 win->allocation.y = 0;
8333 text_window_free (GtkTextWindow *win)
8336 text_window_unrealize (win);
8342 text_window_realize (GtkTextWindow *win,
8345 GdkWindowAttr attributes;
8346 gint attributes_mask;
8349 attributes.window_type = GDK_WINDOW_CHILD;
8350 attributes.x = win->allocation.x;
8351 attributes.y = win->allocation.y;
8352 attributes.width = win->allocation.width;
8353 attributes.height = win->allocation.height;
8354 attributes.wclass = GDK_INPUT_OUTPUT;
8355 attributes.visual = gtk_widget_get_visual (win->widget);
8356 attributes.colormap = gtk_widget_get_colormap (win->widget);
8357 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
8359 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
8361 win->window = gdk_window_new (widget->window,
8365 gdk_window_set_back_pixmap (win->window, NULL, FALSE);
8367 gdk_window_show (win->window);
8368 gdk_window_set_user_data (win->window, win->widget);
8369 gdk_window_lower (win->window);
8373 attributes.width = win->allocation.width;
8374 attributes.height = win->allocation.height;
8375 attributes.event_mask = (GDK_EXPOSURE_MASK |
8377 GDK_KEY_PRESS_MASK |
8378 GDK_BUTTON_PRESS_MASK |
8379 GDK_BUTTON_RELEASE_MASK |
8380 GDK_POINTER_MOTION_MASK |
8381 GDK_POINTER_MOTION_HINT_MASK |
8382 gtk_widget_get_events (win->widget));
8384 win->bin_window = gdk_window_new (win->window,
8388 gdk_window_show (win->bin_window);
8389 gdk_window_set_user_data (win->bin_window, win->widget);
8391 if (win->type == GTK_TEXT_WINDOW_TEXT)
8393 if (gtk_widget_is_sensitive (widget))
8396 cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (widget->window),
8398 gdk_window_set_cursor (win->bin_window, cursor);
8399 gdk_cursor_unref (cursor);
8402 gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->priv->im_context,
8406 gdk_window_set_background (win->bin_window,
8407 &widget->style->base[gtk_widget_get_state (widget)]);
8411 gdk_window_set_background (win->bin_window,
8412 &widget->style->bg[gtk_widget_get_state (widget)]);
8415 g_object_set_qdata (G_OBJECT (win->window),
8416 g_quark_from_static_string ("gtk-text-view-text-window"),
8419 g_object_set_qdata (G_OBJECT (win->bin_window),
8420 g_quark_from_static_string ("gtk-text-view-text-window"),
8425 text_window_unrealize (GtkTextWindow *win)
8427 if (win->type == GTK_TEXT_WINDOW_TEXT)
8429 gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->priv->im_context,
8433 gdk_window_set_user_data (win->window, NULL);
8434 gdk_window_set_user_data (win->bin_window, NULL);
8435 gdk_window_destroy (win->bin_window);
8436 gdk_window_destroy (win->window);
8438 win->bin_window = NULL;
8442 text_window_size_allocate (GtkTextWindow *win,
8445 win->allocation = *rect;
8449 gdk_window_move_resize (win->window,
8451 rect->width, rect->height);
8453 gdk_window_resize (win->bin_window,
8454 rect->width, rect->height);
8459 text_window_scroll (GtkTextWindow *win,
8463 if (dx != 0 || dy != 0)
8465 gdk_window_scroll (win->bin_window, dx, dy);
8470 text_window_invalidate_rect (GtkTextWindow *win,
8473 GdkRectangle window_rect;
8475 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (win->widget),
8482 window_rect.width = rect->width;
8483 window_rect.height = rect->height;
8485 /* Adjust the rect as appropriate */
8489 case GTK_TEXT_WINDOW_TEXT:
8492 case GTK_TEXT_WINDOW_LEFT:
8493 case GTK_TEXT_WINDOW_RIGHT:
8495 window_rect.width = win->allocation.width;
8498 case GTK_TEXT_WINDOW_TOP:
8499 case GTK_TEXT_WINDOW_BOTTOM:
8501 window_rect.height = win->allocation.height;
8505 g_warning ("%s: bug!", G_STRFUNC);
8510 gdk_window_invalidate_rect (win->bin_window, &window_rect, FALSE);
8514 cairo_t *cr = gdk_cairo_create (win->bin_window);
8515 gdk_cairo_rectangle (cr, &window_rect);
8516 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
8524 text_window_invalidate_cursors (GtkTextWindow *win)
8526 GtkTextView *text_view;
8527 GtkTextViewPrivate *priv;
8529 GdkRectangle strong;
8531 gboolean draw_arrow;
8532 gfloat cursor_aspect_ratio;
8536 text_view = GTK_TEXT_VIEW (win->widget);
8537 priv = text_view->priv;
8539 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
8540 gtk_text_buffer_get_insert (priv->buffer));
8542 if (_gtk_text_layout_get_block_cursor (priv->layout, &strong))
8544 text_window_invalidate_rect (win, &strong);
8548 gtk_text_layout_get_cursor_locations (priv->layout, &iter,
8551 /* cursor width calculation as in gtkstyle.c:draw_insertion_cursor(),
8552 * ignoring the text direction be exposing both sides of the cursor
8555 draw_arrow = (strong.x != weak.x || strong.y != weak.y);
8557 gtk_widget_style_get (win->widget,
8558 "cursor-aspect-ratio", &cursor_aspect_ratio,
8561 stem_width = strong.height * cursor_aspect_ratio + 1;
8562 arrow_width = stem_width + 1;
8564 strong.width = stem_width;
8566 /* round up to the next even number */
8570 strong.x -= stem_width / 2;
8571 strong.width += stem_width;
8575 strong.x -= arrow_width;
8576 strong.width += arrow_width * 2;
8579 text_window_invalidate_rect (win, &strong);
8581 if (draw_arrow) /* == have weak */
8583 stem_width = weak.height * cursor_aspect_ratio + 1;
8584 arrow_width = stem_width + 1;
8586 weak.width = stem_width;
8588 /* round up to the next even number */
8592 weak.x -= stem_width / 2;
8593 weak.width += stem_width;
8595 weak.x -= arrow_width;
8596 weak.width += arrow_width * 2;
8598 text_window_invalidate_rect (win, &weak);
8603 text_window_get_width (GtkTextWindow *win)
8605 return win->allocation.width;
8609 text_window_get_height (GtkTextWindow *win)
8611 return win->allocation.height;
8618 * gtk_text_view_get_window:
8619 * @text_view: a #GtkTextView
8620 * @win: window to get
8622 * Retrieves the #GdkWindow corresponding to an area of the text view;
8623 * possible windows include the overall widget window, child windows
8624 * on the left, right, top, bottom, and the window that displays the
8625 * text buffer. Windows are %NULL and nonexistent if their width or
8626 * height is 0, and are nonexistent before the widget has been
8629 * Return value: (transfer none): a #GdkWindow, or %NULL
8632 gtk_text_view_get_window (GtkTextView *text_view,
8633 GtkTextWindowType win)
8635 GtkTextViewPrivate *priv = text_view->priv;
8637 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
8641 case GTK_TEXT_WINDOW_WIDGET:
8642 return GTK_WIDGET (text_view)->window;
8645 case GTK_TEXT_WINDOW_TEXT:
8646 return priv->text_window->bin_window;
8649 case GTK_TEXT_WINDOW_LEFT:
8650 if (priv->left_window)
8651 return priv->left_window->bin_window;
8656 case GTK_TEXT_WINDOW_RIGHT:
8657 if (priv->right_window)
8658 return priv->right_window->bin_window;
8663 case GTK_TEXT_WINDOW_TOP:
8664 if (priv->top_window)
8665 return priv->top_window->bin_window;
8670 case GTK_TEXT_WINDOW_BOTTOM:
8671 if (priv->bottom_window)
8672 return priv->bottom_window->bin_window;
8677 case GTK_TEXT_WINDOW_PRIVATE:
8678 g_warning ("%s: You can't get GTK_TEXT_WINDOW_PRIVATE, it has \"PRIVATE\" in the name because it is private.", G_STRFUNC);
8683 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8688 * gtk_text_view_get_window_type:
8689 * @text_view: a #GtkTextView
8690 * @window: a window type
8692 * Usually used to find out which window an event corresponds to.
8693 * If you connect to an event signal on @text_view, this function
8694 * should be called on <literal>event->window</literal> to
8695 * see which window it was.
8697 * Return value: the window type.
8700 gtk_text_view_get_window_type (GtkTextView *text_view,
8705 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
8706 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8708 if (window == GTK_WIDGET (text_view)->window)
8709 return GTK_TEXT_WINDOW_WIDGET;
8711 win = g_object_get_qdata (G_OBJECT (window),
8712 g_quark_try_string ("gtk-text-view-text-window"));
8718 return GTK_TEXT_WINDOW_PRIVATE;
8723 buffer_to_widget (GtkTextView *text_view,
8729 GtkTextViewPrivate *priv = text_view->priv;
8733 *window_x = buffer_x - priv->xoffset;
8734 *window_x += priv->text_window->allocation.x;
8739 *window_y = buffer_y - priv->yoffset;
8740 *window_y += priv->text_window->allocation.y;
8745 widget_to_text_window (GtkTextWindow *win,
8752 *window_x = widget_x - win->allocation.x;
8755 *window_y = widget_y - win->allocation.y;
8759 buffer_to_text_window (GtkTextView *text_view,
8768 g_warning ("Attempt to convert text buffer coordinates to coordinates "
8769 "for a nonexistent or private child window of GtkTextView");
8773 buffer_to_widget (text_view,
8775 window_x, window_y);
8777 widget_to_text_window (win,
8778 window_x ? *window_x : 0,
8779 window_y ? *window_y : 0,
8785 * gtk_text_view_buffer_to_window_coords:
8786 * @text_view: a #GtkTextView
8787 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8788 * @buffer_x: buffer x coordinate
8789 * @buffer_y: buffer y coordinate
8790 * @window_x: (out) (allow-none): window x coordinate return location or %NULL
8791 * @window_y: (out) (allow-none): window y coordinate return location or %NULL
8793 * Converts coordinate (@buffer_x, @buffer_y) to coordinates for the window
8794 * @win, and stores the result in (@window_x, @window_y).
8796 * Note that you can't convert coordinates for a nonexisting window (see
8797 * gtk_text_view_set_border_window_size()).
8800 gtk_text_view_buffer_to_window_coords (GtkTextView *text_view,
8801 GtkTextWindowType win,
8807 GtkTextViewPrivate *priv = text_view->priv;
8809 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
8813 case GTK_TEXT_WINDOW_WIDGET:
8814 buffer_to_widget (text_view,
8816 window_x, window_y);
8819 case GTK_TEXT_WINDOW_TEXT:
8821 *window_x = buffer_x - priv->xoffset;
8823 *window_y = buffer_y - priv->yoffset;
8826 case GTK_TEXT_WINDOW_LEFT:
8827 buffer_to_text_window (text_view,
8830 window_x, window_y);
8833 case GTK_TEXT_WINDOW_RIGHT:
8834 buffer_to_text_window (text_view,
8837 window_x, window_y);
8840 case GTK_TEXT_WINDOW_TOP:
8841 buffer_to_text_window (text_view,
8844 window_x, window_y);
8847 case GTK_TEXT_WINDOW_BOTTOM:
8848 buffer_to_text_window (text_view,
8849 priv->bottom_window,
8851 window_x, window_y);
8854 case GTK_TEXT_WINDOW_PRIVATE:
8855 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
8859 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8865 widget_to_buffer (GtkTextView *text_view,
8871 GtkTextViewPrivate *priv = text_view->priv;
8875 *buffer_x = widget_x + priv->xoffset;
8876 *buffer_x -= priv->text_window->allocation.x;
8881 *buffer_y = widget_y + priv->yoffset;
8882 *buffer_y -= priv->text_window->allocation.y;
8887 text_window_to_widget (GtkTextWindow *win,
8894 *widget_x = window_x + win->allocation.x;
8897 *widget_y = window_y + win->allocation.y;
8901 text_window_to_buffer (GtkTextView *text_view,
8910 g_warning ("Attempt to convert GtkTextView buffer coordinates into "
8911 "coordinates for a nonexistent child window.");
8915 text_window_to_widget (win,
8921 widget_to_buffer (text_view,
8922 buffer_x ? *buffer_x : 0,
8923 buffer_y ? *buffer_y : 0,
8929 * gtk_text_view_window_to_buffer_coords:
8930 * @text_view: a #GtkTextView
8931 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8932 * @window_x: window x coordinate
8933 * @window_y: window y coordinate
8934 * @buffer_x: (out) (allow-none): buffer x coordinate return location or %NULL
8935 * @buffer_y: (out) (allow-none): buffer y coordinate return location or %NULL
8937 * Converts coordinates on the window identified by @win to buffer
8938 * coordinates, storing the result in (@buffer_x,@buffer_y).
8940 * Note that you can't convert coordinates for a nonexisting window (see
8941 * gtk_text_view_set_border_window_size()).
8944 gtk_text_view_window_to_buffer_coords (GtkTextView *text_view,
8945 GtkTextWindowType win,
8951 GtkTextViewPrivate *priv = text_view->priv;
8953 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
8957 case GTK_TEXT_WINDOW_WIDGET:
8958 widget_to_buffer (text_view,
8960 buffer_x, buffer_y);
8963 case GTK_TEXT_WINDOW_TEXT:
8965 *buffer_x = window_x + priv->xoffset;
8967 *buffer_y = window_y + priv->yoffset;
8970 case GTK_TEXT_WINDOW_LEFT:
8971 text_window_to_buffer (text_view,
8974 buffer_x, buffer_y);
8977 case GTK_TEXT_WINDOW_RIGHT:
8978 text_window_to_buffer (text_view,
8981 buffer_x, buffer_y);
8984 case GTK_TEXT_WINDOW_TOP:
8985 text_window_to_buffer (text_view,
8988 buffer_x, buffer_y);
8991 case GTK_TEXT_WINDOW_BOTTOM:
8992 text_window_to_buffer (text_view,
8993 priv->bottom_window,
8995 buffer_x, buffer_y);
8998 case GTK_TEXT_WINDOW_PRIVATE:
8999 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
9003 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
9009 set_window_width (GtkTextView *text_view,
9011 GtkTextWindowType type,
9012 GtkTextWindow **winp)
9018 text_window_free (*winp);
9020 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9027 *winp = text_window_new (type,
9028 GTK_WIDGET (text_view),
9030 /* if the widget is already realized we need to realize the child manually */
9031 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9032 text_window_realize (*winp, GTK_WIDGET (text_view));
9036 if ((*winp)->requisition.width == width)
9039 (*winp)->requisition.width = width;
9042 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9048 set_window_height (GtkTextView *text_view,
9050 GtkTextWindowType type,
9051 GtkTextWindow **winp)
9057 text_window_free (*winp);
9059 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9066 *winp = text_window_new (type,
9067 GTK_WIDGET (text_view),
9070 /* if the widget is already realized we need to realize the child manually */
9071 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9072 text_window_realize (*winp, GTK_WIDGET (text_view));
9076 if ((*winp)->requisition.height == height)
9079 (*winp)->requisition.height = height;
9082 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9087 * gtk_text_view_set_border_window_size:
9088 * @text_view: a #GtkTextView
9089 * @type: window to affect
9090 * @size: width or height of the window
9092 * Sets the width of %GTK_TEXT_WINDOW_LEFT or %GTK_TEXT_WINDOW_RIGHT,
9093 * or the height of %GTK_TEXT_WINDOW_TOP or %GTK_TEXT_WINDOW_BOTTOM.
9094 * Automatically destroys the corresponding window if the size is set
9095 * to 0, and creates the window if the size is set to non-zero. This
9096 * function can only be used for the "border windows," it doesn't work
9097 * with #GTK_TEXT_WINDOW_WIDGET, #GTK_TEXT_WINDOW_TEXT, or
9098 * #GTK_TEXT_WINDOW_PRIVATE.
9101 gtk_text_view_set_border_window_size (GtkTextView *text_view,
9102 GtkTextWindowType type,
9105 GtkTextViewPrivate *priv = text_view->priv;
9107 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9108 g_return_if_fail (size >= 0);
9112 case GTK_TEXT_WINDOW_LEFT:
9113 set_window_width (text_view, size, GTK_TEXT_WINDOW_LEFT,
9114 &priv->left_window);
9117 case GTK_TEXT_WINDOW_RIGHT:
9118 set_window_width (text_view, size, GTK_TEXT_WINDOW_RIGHT,
9119 &priv->right_window);
9122 case GTK_TEXT_WINDOW_TOP:
9123 set_window_height (text_view, size, GTK_TEXT_WINDOW_TOP,
9127 case GTK_TEXT_WINDOW_BOTTOM:
9128 set_window_height (text_view, size, GTK_TEXT_WINDOW_BOTTOM,
9129 &priv->bottom_window);
9133 g_warning ("Can only set size of left/right/top/bottom border windows with gtk_text_view_set_border_window_size()");
9139 * gtk_text_view_get_border_window_size:
9140 * @text_view: a #GtkTextView
9141 * @type: window to return size from
9143 * Gets the width of the specified border window. See
9144 * gtk_text_view_set_border_window_size().
9146 * Return value: width of window
9149 gtk_text_view_get_border_window_size (GtkTextView *text_view,
9150 GtkTextWindowType type)
9152 GtkTextViewPrivate *priv = text_view->priv;
9154 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
9158 case GTK_TEXT_WINDOW_LEFT:
9159 if (priv->left_window)
9160 return priv->left_window->requisition.width;
9163 case GTK_TEXT_WINDOW_RIGHT:
9164 if (priv->right_window)
9165 return priv->right_window->requisition.width;
9168 case GTK_TEXT_WINDOW_TOP:
9169 if (priv->top_window)
9170 return priv->top_window->requisition.height;
9173 case GTK_TEXT_WINDOW_BOTTOM:
9174 if (priv->bottom_window)
9175 return priv->bottom_window->requisition.height;
9179 g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size()");
9190 static GtkTextViewChild*
9191 text_view_child_new_anchored (GtkWidget *child,
9192 GtkTextChildAnchor *anchor,
9193 GtkTextLayout *layout)
9195 GtkTextViewChild *vc;
9197 vc = g_new (GtkTextViewChild, 1);
9199 vc->type = GTK_TEXT_WINDOW_PRIVATE;
9201 vc->anchor = anchor;
9203 vc->from_top_of_line = 0;
9204 vc->from_left_of_buffer = 0;
9206 g_object_ref (vc->widget);
9207 g_object_ref (vc->anchor);
9209 g_object_set_data (G_OBJECT (child),
9210 I_("gtk-text-view-child"),
9213 gtk_text_child_anchor_register_child (anchor, child, layout);
9218 static GtkTextViewChild*
9219 text_view_child_new_window (GtkWidget *child,
9220 GtkTextWindowType type,
9224 GtkTextViewChild *vc;
9226 vc = g_new (GtkTextViewChild, 1);
9231 vc->from_top_of_line = 0;
9232 vc->from_left_of_buffer = 0;
9234 g_object_ref (vc->widget);
9240 g_object_set_data (G_OBJECT (child),
9241 I_("gtk-text-view-child"),
9248 text_view_child_free (GtkTextViewChild *child)
9250 g_object_set_data (G_OBJECT (child->widget),
9251 I_("gtk-text-view-child"), NULL);
9255 gtk_text_child_anchor_unregister_child (child->anchor,
9257 g_object_unref (child->anchor);
9260 g_object_unref (child->widget);
9266 text_view_child_set_parent_window (GtkTextView *text_view,
9267 GtkTextViewChild *vc)
9270 gtk_widget_set_parent_window (vc->widget,
9271 text_view->priv->text_window->bin_window);
9275 window = gtk_text_view_get_window (text_view,
9277 gtk_widget_set_parent_window (vc->widget, window);
9282 add_child (GtkTextView *text_view,
9283 GtkTextViewChild *vc)
9285 text_view->priv->children = g_slist_prepend (text_view->priv->children,
9288 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9289 text_view_child_set_parent_window (text_view, vc);
9291 gtk_widget_set_parent (vc->widget, GTK_WIDGET (text_view));
9295 * gtk_text_view_add_child_at_anchor:
9296 * @text_view: a #GtkTextView
9297 * @child: a #GtkWidget
9298 * @anchor: a #GtkTextChildAnchor in the #GtkTextBuffer for @text_view
9300 * Adds a child widget in the text buffer, at the given @anchor.
9303 gtk_text_view_add_child_at_anchor (GtkTextView *text_view,
9305 GtkTextChildAnchor *anchor)
9307 GtkTextViewChild *vc;
9309 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9310 g_return_if_fail (GTK_IS_WIDGET (child));
9311 g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
9312 g_return_if_fail (child->parent == NULL);
9314 gtk_text_view_ensure_layout (text_view);
9316 vc = text_view_child_new_anchored (child, anchor,
9317 text_view->priv->layout);
9319 add_child (text_view, vc);
9321 g_assert (vc->widget == child);
9322 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9326 * gtk_text_view_add_child_in_window:
9327 * @text_view: a #GtkTextView
9328 * @child: a #GtkWidget
9329 * @which_window: which window the child should appear in
9330 * @xpos: X position of child in window coordinates
9331 * @ypos: Y position of child in window coordinates
9333 * Adds a child at fixed coordinates in one of the text widget's
9334 * windows. The window must have nonzero size (see
9335 * gtk_text_view_set_border_window_size()). Note that the child
9336 * coordinates are given relative to the #GdkWindow in question, and
9337 * that these coordinates have no sane relationship to scrolling. When
9338 * placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
9339 * irrelevant, the child floats above all scrollable areas. But when
9340 * placing a child in one of the scrollable windows (border windows or
9341 * text window), you'll need to compute the child's correct position
9342 * in buffer coordinates any time scrolling occurs or buffer changes
9343 * occur, and then call gtk_text_view_move_child() to update the
9344 * child's position. Unfortunately there's no good way to detect that
9345 * scrolling has occurred, using the current API; a possible hack
9346 * would be to update all child positions when the scroll adjustments
9347 * change or the text buffer changes. See bug 64518 on
9348 * bugzilla.gnome.org for status of fixing this issue.
9351 gtk_text_view_add_child_in_window (GtkTextView *text_view,
9353 GtkTextWindowType which_window,
9357 GtkTextViewChild *vc;
9359 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9360 g_return_if_fail (GTK_IS_WIDGET (child));
9361 g_return_if_fail (child->parent == NULL);
9363 vc = text_view_child_new_window (child, which_window,
9366 add_child (text_view, vc);
9368 g_assert (vc->widget == child);
9369 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9373 * gtk_text_view_move_child:
9374 * @text_view: a #GtkTextView
9375 * @child: child widget already added to the text view
9376 * @xpos: new X position in window coordinates
9377 * @ypos: new Y position in window coordinates
9379 * Updates the position of a child, as for gtk_text_view_add_child_in_window().
9382 gtk_text_view_move_child (GtkTextView *text_view,
9387 GtkTextViewChild *vc;
9389 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9390 g_return_if_fail (GTK_IS_WIDGET (child));
9391 g_return_if_fail (child->parent == (GtkWidget*) text_view);
9393 vc = g_object_get_data (G_OBJECT (child),
9394 "gtk-text-view-child");
9396 g_assert (vc != NULL);
9398 if (vc->x == xpos &&
9405 if (gtk_widget_get_visible (child) &&
9406 gtk_widget_get_visible (GTK_WIDGET (text_view)))
9407 gtk_widget_queue_resize (child);
9411 /* Iterator operations */
9414 * gtk_text_view_forward_display_line:
9415 * @text_view: a #GtkTextView
9416 * @iter: a #GtkTextIter
9418 * Moves the given @iter forward by one display (wrapped) line.
9419 * A display line is different from a paragraph. Paragraphs are
9420 * separated by newlines or other paragraph separator characters.
9421 * Display lines are created by line-wrapping a paragraph. If
9422 * wrapping is turned off, display lines and paragraphs will be the
9423 * same. Display lines are divided differently for each view, since
9424 * they depend on the view's width; paragraphs are the same in all
9425 * views, since they depend on the contents of the #GtkTextBuffer.
9427 * Return value: %TRUE if @iter was moved and is not on the end iterator
9430 gtk_text_view_forward_display_line (GtkTextView *text_view,
9433 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9434 g_return_val_if_fail (iter != NULL, FALSE);
9436 gtk_text_view_ensure_layout (text_view);
9438 return gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, iter);
9442 * gtk_text_view_backward_display_line:
9443 * @text_view: a #GtkTextView
9444 * @iter: a #GtkTextIter
9446 * Moves the given @iter backward by one display (wrapped) line.
9447 * A display line is different from a paragraph. Paragraphs are
9448 * separated by newlines or other paragraph separator characters.
9449 * Display lines are created by line-wrapping a paragraph. If
9450 * wrapping is turned off, display lines and paragraphs will be the
9451 * same. Display lines are divided differently for each view, since
9452 * they depend on the view's width; paragraphs are the same in all
9453 * views, since they depend on the contents of the #GtkTextBuffer.
9455 * Return value: %TRUE if @iter was moved and is not on the end iterator
9458 gtk_text_view_backward_display_line (GtkTextView *text_view,
9461 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9462 g_return_val_if_fail (iter != NULL, FALSE);
9464 gtk_text_view_ensure_layout (text_view);
9466 return gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, iter);
9470 * gtk_text_view_forward_display_line_end:
9471 * @text_view: a #GtkTextView
9472 * @iter: a #GtkTextIter
9474 * Moves the given @iter forward to the next display line end.
9475 * A display line is different from a paragraph. Paragraphs are
9476 * separated by newlines or other paragraph separator characters.
9477 * Display lines are created by line-wrapping a paragraph. If
9478 * wrapping is turned off, display lines and paragraphs will be the
9479 * same. Display lines are divided differently for each view, since
9480 * they depend on the view's width; paragraphs are the same in all
9481 * views, since they depend on the contents of the #GtkTextBuffer.
9483 * Return value: %TRUE if @iter was moved and is not on the end iterator
9486 gtk_text_view_forward_display_line_end (GtkTextView *text_view,
9489 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9490 g_return_val_if_fail (iter != NULL, FALSE);
9492 gtk_text_view_ensure_layout (text_view);
9494 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, 1);
9498 * gtk_text_view_backward_display_line_start:
9499 * @text_view: a #GtkTextView
9500 * @iter: a #GtkTextIter
9502 * Moves the given @iter backward to the next display line start.
9503 * A display line is different from a paragraph. Paragraphs are
9504 * separated by newlines or other paragraph separator characters.
9505 * Display lines are created by line-wrapping a paragraph. If
9506 * wrapping is turned off, display lines and paragraphs will be the
9507 * same. Display lines are divided differently for each view, since
9508 * they depend on the view's width; paragraphs are the same in all
9509 * views, since they depend on the contents of the #GtkTextBuffer.
9511 * Return value: %TRUE if @iter was moved and is not on the end iterator
9514 gtk_text_view_backward_display_line_start (GtkTextView *text_view,
9517 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9518 g_return_val_if_fail (iter != NULL, FALSE);
9520 gtk_text_view_ensure_layout (text_view);
9522 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, -1);
9526 * gtk_text_view_starts_display_line:
9527 * @text_view: a #GtkTextView
9528 * @iter: a #GtkTextIter
9530 * Determines whether @iter is at the start of a display line.
9531 * See gtk_text_view_forward_display_line() for an explanation of
9532 * display lines vs. paragraphs.
9534 * Return value: %TRUE if @iter begins a wrapped line
9537 gtk_text_view_starts_display_line (GtkTextView *text_view,
9538 const GtkTextIter *iter)
9540 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9541 g_return_val_if_fail (iter != NULL, FALSE);
9543 gtk_text_view_ensure_layout (text_view);
9545 return gtk_text_layout_iter_starts_line (text_view->priv->layout, iter);
9549 * gtk_text_view_move_visually:
9550 * @text_view: a #GtkTextView
9551 * @iter: a #GtkTextIter
9552 * @count: number of characters to move (negative moves left,
9553 * positive moves right)
9555 * Move the iterator a given number of characters visually, treating
9556 * it as the strong cursor position. If @count is positive, then the
9557 * new strong cursor position will be @count positions to the right of
9558 * the old cursor position. If @count is negative then the new strong
9559 * cursor position will be @count positions to the left of the old
9562 * In the presence of bi-directional text, the correspondence
9563 * between logical and visual order will depend on the direction
9564 * of the current run, and there may be jumps when the cursor
9565 * is moved off of the end of a run.
9567 * Return value: %TRUE if @iter moved and is not on the end iterator
9570 gtk_text_view_move_visually (GtkTextView *text_view,
9574 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9575 g_return_val_if_fail (iter != NULL, FALSE);
9577 gtk_text_view_ensure_layout (text_view);
9579 return gtk_text_layout_move_iter_visually (text_view->priv->layout, iter, count);