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 /* This is used to monitor the overall size request
138 * and decide whether we need to queue resizes when
139 * the buffer content changes.
141 * FIXME: This could be done in a simpler way by
142 * consulting the above width/height of the buffer + some
143 * padding values, however all of this request code needs
144 * to be changed to use GtkSizeRequestIface and deserves
147 GtkRequisition cached_size_request;
149 /* The virtual cursor position is normally the same as the
150 * actual (strong) cursor position, except in two circumstances:
152 * a) When the cursor is moved vertically with the keyboard
153 * b) When the text view is scrolled with the keyboard
155 * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
156 * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
158 gint virtual_cursor_x; /* -1 means use actual cursor position */
159 gint virtual_cursor_y; /* -1 means use actual cursor position */
161 GtkTextMark *first_para_mark; /* Mark at the beginning of the first onscreen paragraph */
162 gint first_para_pixels; /* Offset of top of screen in the first onscreen paragraph */
164 GtkTextMark *dnd_mark;
167 guint first_validate_idle; /* Idle to revalidate onscreen portion, runs before resize */
168 guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
170 GtkIMContext *im_context;
171 GtkWidget *popup_menu;
178 GtkTextPendingScroll *pending_scroll;
180 gint pending_place_cursor_button;
182 /* Default style settings */
183 gint pixels_above_lines;
184 gint pixels_below_lines;
185 gint pixels_inside_wrap;
186 GtkWrapMode wrap_mode;
187 GtkJustification justify;
194 guint overwrite_mode : 1;
195 guint cursor_visible : 1;
197 /* if we have reset the IM since the last character entered */
198 guint need_im_reset : 1;
200 guint accepts_tab : 1;
202 guint width_changed : 1;
204 /* debug flag - means that we've validated onscreen since the
205 * last "invalidate" signal from the layout
207 guint onscreen_validated : 1;
209 guint mouse_cursor_obscured : 1;
211 guint scroll_after_paste : 1;
214 struct _GtkTextPendingScroll
217 gdouble within_margin;
225 SET_SCROLL_ADJUSTMENTS,
239 TOGGLE_CURSOR_VISIBLE,
247 PROP_PIXELS_ABOVE_LINES,
248 PROP_PIXELS_BELOW_LINES,
249 PROP_PIXELS_INSIDE_WRAP,
264 static void gtk_text_view_destroy (GtkObject *object);
265 static void gtk_text_view_finalize (GObject *object);
266 static void gtk_text_view_set_property (GObject *object,
270 static void gtk_text_view_get_property (GObject *object,
274 static void gtk_text_view_size_request (GtkWidget *widget,
275 GtkRequisition *requisition);
276 static void gtk_text_view_size_allocate (GtkWidget *widget,
277 GtkAllocation *allocation);
278 static void gtk_text_view_realize (GtkWidget *widget);
279 static void gtk_text_view_unrealize (GtkWidget *widget);
280 static void gtk_text_view_style_set (GtkWidget *widget,
281 GtkStyle *previous_style);
282 static void gtk_text_view_direction_changed (GtkWidget *widget,
283 GtkTextDirection previous_direction);
284 static void gtk_text_view_grab_notify (GtkWidget *widget,
285 gboolean was_grabbed);
286 static void gtk_text_view_state_changed (GtkWidget *widget,
287 GtkStateType previous_state);
289 static gint gtk_text_view_event (GtkWidget *widget,
291 static gint gtk_text_view_key_press_event (GtkWidget *widget,
293 static gint gtk_text_view_key_release_event (GtkWidget *widget,
295 static gint gtk_text_view_button_press_event (GtkWidget *widget,
296 GdkEventButton *event);
297 static gint gtk_text_view_button_release_event (GtkWidget *widget,
298 GdkEventButton *event);
299 static gint gtk_text_view_focus_in_event (GtkWidget *widget,
300 GdkEventFocus *event);
301 static gint gtk_text_view_focus_out_event (GtkWidget *widget,
302 GdkEventFocus *event);
303 static gint gtk_text_view_motion_event (GtkWidget *widget,
304 GdkEventMotion *event);
305 static gint gtk_text_view_expose_event (GtkWidget *widget,
306 GdkEventExpose *expose);
307 static void gtk_text_view_draw_focus (GtkWidget *widget);
308 static gboolean gtk_text_view_focus (GtkWidget *widget,
309 GtkDirectionType direction);
310 static void gtk_text_view_move_focus (GtkWidget *widget,
311 GtkDirectionType direction_type);
312 static void gtk_text_view_select_all (GtkWidget *widget,
316 /* Source side drag signals */
317 static void gtk_text_view_drag_begin (GtkWidget *widget,
318 GdkDragContext *context);
319 static void gtk_text_view_drag_end (GtkWidget *widget,
320 GdkDragContext *context);
321 static void gtk_text_view_drag_data_get (GtkWidget *widget,
322 GdkDragContext *context,
323 GtkSelectionData *selection_data,
326 static void gtk_text_view_drag_data_delete (GtkWidget *widget,
327 GdkDragContext *context);
329 /* Target side drag signals */
330 static void gtk_text_view_drag_leave (GtkWidget *widget,
331 GdkDragContext *context,
333 static gboolean gtk_text_view_drag_motion (GtkWidget *widget,
334 GdkDragContext *context,
338 static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
339 GdkDragContext *context,
343 static void gtk_text_view_drag_data_received (GtkWidget *widget,
344 GdkDragContext *context,
347 GtkSelectionData *selection_data,
351 static void gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
353 GtkAdjustment *vadj);
354 static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
356 static void gtk_text_view_move_cursor (GtkTextView *text_view,
357 GtkMovementStep step,
359 gboolean extend_selection);
360 static gboolean gtk_text_view_move_viewport (GtkTextView *text_view,
363 static void gtk_text_view_set_anchor (GtkTextView *text_view);
364 static gboolean gtk_text_view_scroll_pages (GtkTextView *text_view,
366 gboolean extend_selection);
367 static gboolean gtk_text_view_scroll_hpages(GtkTextView *text_view,
369 gboolean extend_selection);
370 static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
372 static void gtk_text_view_delete_from_cursor (GtkTextView *text_view,
375 static void gtk_text_view_backspace (GtkTextView *text_view);
376 static void gtk_text_view_cut_clipboard (GtkTextView *text_view);
377 static void gtk_text_view_copy_clipboard (GtkTextView *text_view);
378 static void gtk_text_view_paste_clipboard (GtkTextView *text_view);
379 static void gtk_text_view_toggle_overwrite (GtkTextView *text_view);
380 static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view);
381 static void gtk_text_view_compat_move_focus(GtkTextView *text_view,
382 GtkDirectionType direction_type);
383 static void gtk_text_view_unselect (GtkTextView *text_view);
385 static void gtk_text_view_validate_onscreen (GtkTextView *text_view);
386 static void gtk_text_view_get_first_para_iter (GtkTextView *text_view,
388 static void gtk_text_view_update_layout_width (GtkTextView *text_view);
389 static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
390 GtkTextAttributes *values,
392 static void gtk_text_view_ensure_layout (GtkTextView *text_view);
393 static void gtk_text_view_destroy_layout (GtkTextView *text_view);
394 static void gtk_text_view_check_keymap_direction (GtkTextView *text_view);
395 static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
396 const GtkTextIter *iter,
397 GdkEventButton *event);
398 static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view);
399 static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
400 const GtkTextIter *iter,
401 GdkEventMotion *event);
402 static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
403 static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
404 static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
405 static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
407 static void gtk_text_view_value_changed (GtkAdjustment *adj,
409 static void gtk_text_view_commit_handler (GtkIMContext *context,
411 GtkTextView *text_view);
412 static void gtk_text_view_commit_text (GtkTextView *text_view,
414 static void gtk_text_view_preedit_changed_handler (GtkIMContext *context,
415 GtkTextView *text_view);
416 static gboolean gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
417 GtkTextView *text_view);
418 static gboolean gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
421 GtkTextView *text_view);
423 static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
424 const GtkTextIter *location,
427 static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
428 const GParamSpec *pspec,
430 static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
431 GtkClipboard *clipboard,
433 static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
435 static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
439 static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
443 static GtkAdjustment* get_hadjustment (GtkTextView *text_view);
444 static GtkAdjustment* get_vadjustment (GtkTextView *text_view);
446 static void gtk_text_view_do_popup (GtkTextView *text_view,
447 GdkEventButton *event);
449 static void cancel_pending_scroll (GtkTextView *text_view);
450 static void gtk_text_view_queue_scroll (GtkTextView *text_view,
452 gdouble within_margin,
457 static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
458 static void gtk_text_view_update_adjustments (GtkTextView *text_view);
459 static void gtk_text_view_invalidate (GtkTextView *text_view);
460 static void gtk_text_view_flush_first_validate (GtkTextView *text_view);
462 static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
464 /* Container methods */
465 static void gtk_text_view_add (GtkContainer *container,
467 static void gtk_text_view_remove (GtkContainer *container,
469 static void gtk_text_view_forall (GtkContainer *container,
470 gboolean include_internals,
471 GtkCallback callback,
472 gpointer callback_data);
474 /* FIXME probably need the focus methods. */
476 typedef struct _GtkTextViewChild GtkTextViewChild;
478 struct _GtkTextViewChild
482 GtkTextChildAnchor *anchor;
484 gint from_top_of_line;
485 gint from_left_of_buffer;
487 /* These are ignored if anchor != NULL */
488 GtkTextWindowType type;
493 static GtkTextViewChild* text_view_child_new_anchored (GtkWidget *child,
494 GtkTextChildAnchor *anchor,
495 GtkTextLayout *layout);
496 static GtkTextViewChild* text_view_child_new_window (GtkWidget *child,
497 GtkTextWindowType type,
500 static void text_view_child_free (GtkTextViewChild *child);
501 static void text_view_child_set_parent_window (GtkTextView *text_view,
502 GtkTextViewChild *child);
504 struct _GtkTextWindow
506 GtkTextWindowType type;
509 GdkWindow *bin_window;
510 GtkRequisition requisition;
511 GdkRectangle allocation;
514 static GtkTextWindow *text_window_new (GtkTextWindowType type,
517 gint height_request);
518 static void text_window_free (GtkTextWindow *win);
519 static void text_window_realize (GtkTextWindow *win,
521 static void text_window_unrealize (GtkTextWindow *win);
522 static void text_window_size_allocate (GtkTextWindow *win,
524 static void text_window_scroll (GtkTextWindow *win,
527 static void text_window_invalidate_rect (GtkTextWindow *win,
529 static void text_window_invalidate_cursors (GtkTextWindow *win);
531 static gint text_window_get_width (GtkTextWindow *win);
532 static gint text_window_get_height (GtkTextWindow *win);
535 static guint signals[LAST_SIGNAL] = { 0 };
537 G_DEFINE_TYPE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER)
540 add_move_binding (GtkBindingSet *binding_set,
543 GtkMovementStep step,
546 g_assert ((modmask & GDK_SHIFT_MASK) == 0);
548 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
552 G_TYPE_BOOLEAN, FALSE);
554 /* Selection-extending version */
555 gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
559 G_TYPE_BOOLEAN, TRUE);
563 gtk_text_view_class_init (GtkTextViewClass *klass)
565 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
566 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
567 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
568 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
569 GtkBindingSet *binding_set;
571 /* Default handlers and virtual methods
573 gobject_class->set_property = gtk_text_view_set_property;
574 gobject_class->get_property = gtk_text_view_get_property;
576 object_class->destroy = gtk_text_view_destroy;
577 gobject_class->finalize = gtk_text_view_finalize;
579 widget_class->realize = gtk_text_view_realize;
580 widget_class->unrealize = gtk_text_view_unrealize;
581 widget_class->style_set = gtk_text_view_style_set;
582 widget_class->direction_changed = gtk_text_view_direction_changed;
583 widget_class->grab_notify = gtk_text_view_grab_notify;
584 widget_class->state_changed = gtk_text_view_state_changed;
585 widget_class->size_request = gtk_text_view_size_request;
586 widget_class->size_allocate = gtk_text_view_size_allocate;
587 widget_class->event = gtk_text_view_event;
588 widget_class->key_press_event = gtk_text_view_key_press_event;
589 widget_class->key_release_event = gtk_text_view_key_release_event;
590 widget_class->button_press_event = gtk_text_view_button_press_event;
591 widget_class->button_release_event = gtk_text_view_button_release_event;
592 widget_class->focus_in_event = gtk_text_view_focus_in_event;
593 widget_class->focus_out_event = gtk_text_view_focus_out_event;
594 widget_class->motion_notify_event = gtk_text_view_motion_event;
595 widget_class->expose_event = gtk_text_view_expose_event;
596 widget_class->focus = gtk_text_view_focus;
598 /* need to override the base class function via override_class_handler,
599 * because the signal slot is not available in GtkWidgetCLass
601 g_signal_override_class_handler ("move-focus",
603 G_CALLBACK (gtk_text_view_move_focus));
605 widget_class->drag_begin = gtk_text_view_drag_begin;
606 widget_class->drag_end = gtk_text_view_drag_end;
607 widget_class->drag_data_get = gtk_text_view_drag_data_get;
608 widget_class->drag_data_delete = gtk_text_view_drag_data_delete;
610 widget_class->drag_leave = gtk_text_view_drag_leave;
611 widget_class->drag_motion = gtk_text_view_drag_motion;
612 widget_class->drag_drop = gtk_text_view_drag_drop;
613 widget_class->drag_data_received = gtk_text_view_drag_data_received;
615 widget_class->popup_menu = gtk_text_view_popup_menu;
617 container_class->add = gtk_text_view_add;
618 container_class->remove = gtk_text_view_remove;
619 container_class->forall = gtk_text_view_forall;
621 klass->move_cursor = gtk_text_view_move_cursor;
622 klass->set_anchor = gtk_text_view_set_anchor;
623 klass->insert_at_cursor = gtk_text_view_insert_at_cursor;
624 klass->delete_from_cursor = gtk_text_view_delete_from_cursor;
625 klass->backspace = gtk_text_view_backspace;
626 klass->cut_clipboard = gtk_text_view_cut_clipboard;
627 klass->copy_clipboard = gtk_text_view_copy_clipboard;
628 klass->paste_clipboard = gtk_text_view_paste_clipboard;
629 klass->toggle_overwrite = gtk_text_view_toggle_overwrite;
630 klass->move_focus = gtk_text_view_compat_move_focus;
631 klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
637 g_object_class_install_property (gobject_class,
638 PROP_PIXELS_ABOVE_LINES,
639 g_param_spec_int ("pixels-above-lines",
640 P_("Pixels Above Lines"),
641 P_("Pixels of blank space above paragraphs"),
645 GTK_PARAM_READWRITE));
647 g_object_class_install_property (gobject_class,
648 PROP_PIXELS_BELOW_LINES,
649 g_param_spec_int ("pixels-below-lines",
650 P_("Pixels Below Lines"),
651 P_("Pixels of blank space below paragraphs"),
655 GTK_PARAM_READWRITE));
657 g_object_class_install_property (gobject_class,
658 PROP_PIXELS_INSIDE_WRAP,
659 g_param_spec_int ("pixels-inside-wrap",
660 P_("Pixels Inside Wrap"),
661 P_("Pixels of blank space between wrapped lines in a paragraph"),
665 GTK_PARAM_READWRITE));
667 g_object_class_install_property (gobject_class,
669 g_param_spec_boolean ("editable",
671 P_("Whether the text can be modified by the user"),
673 GTK_PARAM_READWRITE));
675 g_object_class_install_property (gobject_class,
677 g_param_spec_enum ("wrap-mode",
679 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
682 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_enum ("justification",
688 P_("Left, right, or center justification"),
689 GTK_TYPE_JUSTIFICATION,
691 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
695 g_param_spec_int ("left-margin",
697 P_("Width of the left margin in pixels"),
701 GTK_PARAM_READWRITE));
703 g_object_class_install_property (gobject_class,
705 g_param_spec_int ("right-margin",
707 P_("Width of the right margin in pixels"),
711 GTK_PARAM_READWRITE));
713 g_object_class_install_property (gobject_class,
715 g_param_spec_int ("indent",
717 P_("Amount to indent the paragraph, in pixels"),
721 GTK_PARAM_READWRITE));
723 g_object_class_install_property (gobject_class,
725 g_param_spec_boxed ("tabs",
727 P_("Custom tabs for this text"),
728 PANGO_TYPE_TAB_ARRAY,
729 GTK_PARAM_READWRITE));
731 g_object_class_install_property (gobject_class,
733 g_param_spec_boolean ("cursor-visible",
734 P_("Cursor Visible"),
735 P_("If the insertion cursor is shown"),
737 GTK_PARAM_READWRITE));
739 g_object_class_install_property (gobject_class,
741 g_param_spec_object ("buffer",
743 P_("The buffer which is displayed"),
744 GTK_TYPE_TEXT_BUFFER,
745 GTK_PARAM_READWRITE));
747 g_object_class_install_property (gobject_class,
749 g_param_spec_boolean ("overwrite",
750 P_("Overwrite mode"),
751 P_("Whether entered text overwrites existing contents"),
753 GTK_PARAM_READWRITE));
755 g_object_class_install_property (gobject_class,
757 g_param_spec_boolean ("accepts-tab",
759 P_("Whether Tab will result in a tab character being entered"),
761 GTK_PARAM_READWRITE));
764 * GtkTextView:im-module:
766 * Which IM (input method) module should be used for this entry.
769 * Setting this to a non-%NULL value overrides the
770 * system-wide IM module setting. See the GtkSettings
771 * #GtkSettings:gtk-im-module property.
775 g_object_class_install_property (gobject_class,
777 g_param_spec_string ("im-module",
779 P_("Which IM module should be used"),
781 GTK_PARAM_READWRITE));
786 gtk_widget_class_install_style_property (widget_class,
787 g_param_spec_boxed ("error-underline-color",
788 P_("Error underline color"),
789 P_("Color with which to draw error-indication underlines"),
791 GTK_PARAM_READABLE));
798 * GtkTextView::move-cursor:
799 * @text_view: the object which received the signal
800 * @step: the granularity of the move, as a #GtkMovementStep
801 * @count: the number of @step units to move
802 * @extend_selection: %TRUE if the move should extend the selection
804 * The ::move-cursor signal is a
805 * <link linkend="keybinding-signals">keybinding signal</link>
806 * which gets emitted when the user initiates a cursor movement.
807 * If the cursor is not visible in @text_view, this signal causes
808 * the viewport to be moved instead.
810 * Applications should not connect to it, but may emit it with
811 * g_signal_emit_by_name() if they need to control the cursor
814 * The default bindings for this signal come in two variants,
815 * the variant with the Shift modifier extends the selection,
816 * the variant without the Shift modifer does not.
817 * There are too many key combinations to list them all here.
819 * <listitem>Arrow keys move by individual characters/lines</listitem>
820 * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
821 * <listitem>Home/End keys move to the ends of the buffer</listitem>
822 * <listitem>PageUp/PageDown keys move vertically by pages</listitem>
823 * <listitem>Ctrl-PageUp/PageDown keys move horizontally by pages</listitem>
826 signals[MOVE_CURSOR] =
827 g_signal_new (I_("move-cursor"),
828 G_OBJECT_CLASS_TYPE (gobject_class),
829 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
830 G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
832 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
834 GTK_TYPE_MOVEMENT_STEP,
839 * GtkTextView::move-viewport:
840 * @text_view: the object which received the signal
841 * @step: the granularity of the move, as a #GtkMovementStep
842 * @count: the number of @step units to move
844 * The ::move-viewport signal is a
845 * <link linkend="keybinding-signals">keybinding signal</link>
846 * which can be bound to key combinations to allow the user
847 * to move the viewport, i.e. change what part of the text view
848 * is visible in a containing scrolled window.
850 * There are no default bindings for this signal.
852 signals[MOVE_VIEWPORT] =
853 g_signal_new_class_handler (I_("move-viewport"),
854 G_OBJECT_CLASS_TYPE (gobject_class),
855 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
856 G_CALLBACK (gtk_text_view_move_viewport),
858 _gtk_marshal_VOID__ENUM_INT,
860 GTK_TYPE_SCROLL_STEP,
864 * GtkTextView::set-anchor:
865 * @text_view: the object which received the signal
867 * The ::set-anchor signal is a
868 * <link linkend="keybinding-signals">keybinding signal</link>
869 * which gets emitted when the user initiates setting the "anchor"
870 * mark. The "anchor" mark gets placed at the same position as the
873 * This signal has no default bindings.
875 signals[SET_ANCHOR] =
876 g_signal_new (I_("set-anchor"),
877 G_OBJECT_CLASS_TYPE (gobject_class),
878 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
879 G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
881 _gtk_marshal_VOID__VOID,
885 * GtkTextView::insert-at-cursor:
886 * @text_view: the object which received the signal
887 * @string: the string to insert
889 * The ::insert-at-cursor signal is a
890 * <link linkend="keybinding-signals">keybinding signal</link>
891 * which gets emitted when the user initiates the insertion of a
892 * fixed string at the cursor.
894 * This signal has no default bindings.
896 signals[INSERT_AT_CURSOR] =
897 g_signal_new (I_("insert-at-cursor"),
898 G_OBJECT_CLASS_TYPE (gobject_class),
899 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
900 G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
902 _gtk_marshal_VOID__STRING,
907 * GtkTextView::delete-from-cursor:
908 * @text_view: the object which received the signal
909 * @type: the granularity of the deletion, as a #GtkDeleteType
910 * @count: the number of @type units to delete
912 * The ::delete-from-cursor signal is a
913 * <link linkend="keybinding-signals">keybinding signal</link>
914 * which gets emitted when the user initiates a text deletion.
916 * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
917 * if there is one, otherwise it deletes the requested number
920 * The default bindings for this signal are
921 * Delete for deleting a character, Ctrl-Delete for
922 * deleting a word and Ctrl-Backspace for deleting a word
925 signals[DELETE_FROM_CURSOR] =
926 g_signal_new (I_("delete-from-cursor"),
927 G_OBJECT_CLASS_TYPE (gobject_class),
928 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
929 G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
931 _gtk_marshal_VOID__ENUM_INT,
933 GTK_TYPE_DELETE_TYPE,
937 * GtkTextView::backspace:
938 * @text_view: the object which received the signal
940 * The ::backspace signal is a
941 * <link linkend="keybinding-signals">keybinding signal</link>
942 * which gets emitted when the user asks for it.
944 * The default bindings for this signal are
945 * Backspace and Shift-Backspace.
948 g_signal_new (I_("backspace"),
949 G_OBJECT_CLASS_TYPE (gobject_class),
950 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
951 G_STRUCT_OFFSET (GtkTextViewClass, backspace),
953 _gtk_marshal_VOID__VOID,
957 * GtkTextView::cut-clipboard:
958 * @text_view: the object which received the signal
960 * The ::cut-clipboard signal is a
961 * <link linkend="keybinding-signals">keybinding signal</link>
962 * which gets emitted to cut the selection to the clipboard.
964 * The default bindings for this signal are
965 * Ctrl-x and Shift-Delete.
967 signals[CUT_CLIPBOARD] =
968 g_signal_new (I_("cut-clipboard"),
969 G_OBJECT_CLASS_TYPE (gobject_class),
970 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
971 G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
973 _gtk_marshal_VOID__VOID,
977 * GtkTextView::copy-clipboard:
978 * @text_view: the object which received the signal
980 * The ::copy-clipboard signal is a
981 * <link linkend="keybinding-signals">keybinding signal</link>
982 * which gets emitted to copy the selection to the clipboard.
984 * The default bindings for this signal are
985 * Ctrl-c and Ctrl-Insert.
987 signals[COPY_CLIPBOARD] =
988 g_signal_new (I_("copy-clipboard"),
989 G_OBJECT_CLASS_TYPE (gobject_class),
990 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
991 G_STRUCT_OFFSET (GtkTextViewClass, copy_clipboard),
993 _gtk_marshal_VOID__VOID,
997 * GtkTextView::paste-clipboard:
998 * @text_view: the object which received the signal
1000 * The ::paste-clipboard signal is a
1001 * <link linkend="keybinding-signals">keybinding signal</link>
1002 * which gets emitted to paste the contents of the clipboard
1003 * into the text view.
1005 * The default bindings for this signal are
1006 * Ctrl-v and Shift-Insert.
1008 signals[PASTE_CLIPBOARD] =
1009 g_signal_new (I_("paste-clipboard"),
1010 G_OBJECT_CLASS_TYPE (gobject_class),
1011 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1012 G_STRUCT_OFFSET (GtkTextViewClass, paste_clipboard),
1014 _gtk_marshal_VOID__VOID,
1018 * GtkTextView::toggle-overwrite:
1019 * @text_view: the object which received the signal
1021 * The ::toggle-overwrite signal is a
1022 * <link linkend="keybinding-signals">keybinding signal</link>
1023 * which gets emitted to toggle the overwrite mode of the text view.
1025 * The default bindings for this signal is Insert.
1027 signals[TOGGLE_OVERWRITE] =
1028 g_signal_new (I_("toggle-overwrite"),
1029 G_OBJECT_CLASS_TYPE (gobject_class),
1030 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1031 G_STRUCT_OFFSET (GtkTextViewClass, toggle_overwrite),
1033 _gtk_marshal_VOID__VOID,
1037 * GtkTextView::set-scroll-adjustments
1038 * @horizontal: the horizontal #GtkAdjustment
1039 * @vertical: the vertical #GtkAdjustment
1041 * Set the scroll adjustments for the text view. Usually scrolled containers
1042 * like #GtkScrolledWindow will emit this signal to connect two instances
1043 * of #GtkScrollbar to the scroll directions of the #GtkTextView.
1045 signals[SET_SCROLL_ADJUSTMENTS] =
1046 g_signal_new (I_("set-scroll-adjustments"),
1047 G_OBJECT_CLASS_TYPE (gobject_class),
1048 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1049 G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments),
1051 _gtk_marshal_VOID__OBJECT_OBJECT,
1053 GTK_TYPE_ADJUSTMENT,
1054 GTK_TYPE_ADJUSTMENT);
1055 widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
1058 * GtkTextView::populate-popup:
1059 * @entry: The text view on which the signal is emitted
1060 * @menu: the menu that is being populated
1062 * The ::populate-popup signal gets emitted before showing the
1063 * context menu of the text view.
1065 * If you need to add items to the context menu, connect
1066 * to this signal and append your menuitems to the @menu.
1068 signals[POPULATE_POPUP] =
1069 g_signal_new (I_("populate-popup"),
1070 G_OBJECT_CLASS_TYPE (gobject_class),
1072 G_STRUCT_OFFSET (GtkTextViewClass, populate_popup),
1074 _gtk_marshal_VOID__OBJECT,
1079 * GtkTextView::select-all:
1080 * @text_view: the object which received the signal
1081 * @select: %TRUE to select, %FALSE to unselect
1083 * The ::select-all signal is a
1084 * <link linkend="keybinding-signals">keybinding signal</link>
1085 * which gets emitted to select or unselect the complete
1086 * contents of the text view.
1088 * The default bindings for this signal are Ctrl-a and Ctrl-/
1089 * for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
1091 signals[SELECT_ALL] =
1092 g_signal_new_class_handler (I_("select-all"),
1093 G_OBJECT_CLASS_TYPE (object_class),
1094 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1095 G_CALLBACK (gtk_text_view_select_all),
1097 _gtk_marshal_VOID__BOOLEAN,
1098 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
1101 * GtkTextView::toggle-cursor-visible:
1102 * @text_view: the object which received the signal
1104 * The ::toggle-cursor-visible signal is a
1105 * <link linkend="keybinding-signals">keybinding signal</link>
1106 * which gets emitted to toggle the visibility of the cursor.
1108 * The default binding for this signal is F7.
1110 signals[TOGGLE_CURSOR_VISIBLE] =
1111 g_signal_new_class_handler (I_("toggle-cursor-visible"),
1112 G_OBJECT_CLASS_TYPE (object_class),
1113 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1114 G_CALLBACK (gtk_text_view_toggle_cursor_visible),
1116 _gtk_marshal_VOID__VOID,
1120 * GtkTextView::preedit-changed:
1121 * @text_view: the object which received the signal
1122 * @preedit: the current preedit string
1124 * If an input method is used, the typed text will not immediately
1125 * be committed to the buffer. So if you are interested in the text,
1126 * connect to this signal.
1128 * This signal is only emitted if the text at the given position
1129 * is actually editable.
1133 signals[PREEDIT_CHANGED] =
1134 g_signal_new_class_handler (I_("preedit-changed"),
1135 G_OBJECT_CLASS_TYPE (object_class),
1136 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1139 _gtk_marshal_VOID__STRING,
1147 binding_set = gtk_binding_set_by_class (klass);
1149 /* Moving the insertion point */
1150 add_move_binding (binding_set, GDK_KEY_Right, 0,
1151 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1153 add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1154 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1156 add_move_binding (binding_set, GDK_KEY_Left, 0,
1157 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1159 add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1160 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1162 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1163 GTK_MOVEMENT_WORDS, 1);
1165 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1166 GTK_MOVEMENT_WORDS, 1);
1168 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1169 GTK_MOVEMENT_WORDS, -1);
1171 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1172 GTK_MOVEMENT_WORDS, -1);
1174 add_move_binding (binding_set, GDK_KEY_Up, 0,
1175 GTK_MOVEMENT_DISPLAY_LINES, -1);
1177 add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1178 GTK_MOVEMENT_DISPLAY_LINES, -1);
1180 add_move_binding (binding_set, GDK_KEY_Down, 0,
1181 GTK_MOVEMENT_DISPLAY_LINES, 1);
1183 add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1184 GTK_MOVEMENT_DISPLAY_LINES, 1);
1186 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK,
1187 GTK_MOVEMENT_PARAGRAPHS, -1);
1189 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK,
1190 GTK_MOVEMENT_PARAGRAPHS, -1);
1192 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK,
1193 GTK_MOVEMENT_PARAGRAPHS, 1);
1195 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK,
1196 GTK_MOVEMENT_PARAGRAPHS, 1);
1198 add_move_binding (binding_set, GDK_KEY_Home, 0,
1199 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1201 add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1202 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
1204 add_move_binding (binding_set, GDK_KEY_End, 0,
1205 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1207 add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1208 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
1210 add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1211 GTK_MOVEMENT_BUFFER_ENDS, -1);
1213 add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1214 GTK_MOVEMENT_BUFFER_ENDS, -1);
1216 add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1217 GTK_MOVEMENT_BUFFER_ENDS, 1);
1219 add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1220 GTK_MOVEMENT_BUFFER_ENDS, 1);
1222 add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1223 GTK_MOVEMENT_PAGES, -1);
1225 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1226 GTK_MOVEMENT_PAGES, -1);
1228 add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1229 GTK_MOVEMENT_PAGES, 1);
1231 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1232 GTK_MOVEMENT_PAGES, 1);
1234 add_move_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
1235 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1237 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK,
1238 GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
1240 add_move_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK,
1241 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1243 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK,
1244 GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
1247 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1249 G_TYPE_BOOLEAN, TRUE);
1251 gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1253 G_TYPE_BOOLEAN, TRUE);
1256 gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1258 G_TYPE_BOOLEAN, FALSE);
1260 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1262 G_TYPE_BOOLEAN, FALSE);
1265 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
1266 "delete-from-cursor", 2,
1267 G_TYPE_ENUM, GTK_DELETE_CHARS,
1270 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
1271 "delete-from-cursor", 2,
1272 G_TYPE_ENUM, GTK_DELETE_CHARS,
1275 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
1278 /* Make this do the same as Backspace, to help with mis-typing */
1279 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
1282 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
1283 "delete-from-cursor", 2,
1284 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1287 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
1288 "delete-from-cursor", 2,
1289 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1292 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
1293 "delete-from-cursor", 2,
1294 G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
1297 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1298 "delete-from-cursor", 2,
1299 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1302 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1303 "delete-from-cursor", 2,
1304 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1307 gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1308 "delete-from-cursor", 2,
1309 G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
1312 /* Cut/copy/paste */
1314 gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
1315 "cut-clipboard", 0);
1316 gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1317 "copy-clipboard", 0);
1318 gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
1319 "paste-clipboard", 0);
1321 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
1322 "cut-clipboard", 0);
1323 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
1324 "copy-clipboard", 0);
1325 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
1326 "paste-clipboard", 0);
1329 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
1330 "toggle-overwrite", 0);
1331 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
1332 "toggle-overwrite", 0);
1335 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F7, 0,
1336 "toggle-cursor-visible", 0);
1338 /* Control-tab focus motion */
1339 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_CONTROL_MASK,
1341 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1342 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
1344 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
1346 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1348 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1349 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1351 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
1353 g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
1357 gtk_text_view_init (GtkTextView *text_view)
1359 GtkWidget *widget = GTK_WIDGET (text_view);
1360 GtkTargetList *target_list;
1361 GtkTextViewPrivate *priv;
1363 text_view->priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
1364 priv = text_view->priv;
1366 gtk_widget_set_can_focus (widget, TRUE);
1368 /* Set up default style */
1369 priv->wrap_mode = GTK_WRAP_NONE;
1370 priv->pixels_above_lines = 0;
1371 priv->pixels_below_lines = 0;
1372 priv->pixels_inside_wrap = 0;
1373 priv->justify = GTK_JUSTIFY_LEFT;
1374 priv->left_margin = 0;
1375 priv->right_margin = 0;
1378 priv->editable = TRUE;
1380 priv->scroll_after_paste = TRUE;
1382 gtk_drag_dest_set (widget, 0, NULL, 0,
1383 GDK_ACTION_COPY | GDK_ACTION_MOVE);
1385 target_list = gtk_target_list_new (NULL, 0);
1386 gtk_drag_dest_set_target_list (widget, target_list);
1387 gtk_target_list_unref (target_list);
1389 priv->virtual_cursor_x = -1;
1390 priv->virtual_cursor_y = -1;
1392 /* This object is completely private. No external entity can gain a reference
1393 * to it; so we create it here and destroy it in finalize ().
1395 priv->im_context = gtk_im_multicontext_new ();
1397 g_signal_connect (priv->im_context, "commit",
1398 G_CALLBACK (gtk_text_view_commit_handler), text_view);
1399 g_signal_connect (priv->im_context, "preedit-changed",
1400 G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
1401 g_signal_connect (priv->im_context, "retrieve-surrounding",
1402 G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
1403 g_signal_connect (priv->im_context, "delete-surrounding",
1404 G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
1406 priv->cursor_visible = TRUE;
1408 priv->accepts_tab = TRUE;
1410 priv->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT,
1413 priv->drag_start_x = -1;
1414 priv->drag_start_y = -1;
1416 priv->pending_place_cursor_button = 0;
1418 /* We handle all our own redrawing */
1419 gtk_widget_set_redraw_on_allocate (widget, FALSE);
1423 * gtk_text_view_new:
1425 * Creates a new #GtkTextView. If you don't call gtk_text_view_set_buffer()
1426 * before using the text view, an empty default buffer will be created
1427 * for you. Get the buffer with gtk_text_view_get_buffer(). If you want
1428 * to specify your own buffer, consider gtk_text_view_new_with_buffer().
1430 * Return value: a new #GtkTextView
1433 gtk_text_view_new (void)
1435 return g_object_new (GTK_TYPE_TEXT_VIEW, NULL);
1439 * gtk_text_view_new_with_buffer:
1440 * @buffer: a #GtkTextBuffer
1442 * Creates a new #GtkTextView widget displaying the buffer
1443 * @buffer. One buffer can be shared among many widgets.
1444 * @buffer may be %NULL to create a default buffer, in which case
1445 * this function is equivalent to gtk_text_view_new(). The
1446 * text view adds its own reference count to the buffer; it does not
1447 * take over an existing reference.
1449 * Return value: a new #GtkTextView.
1452 gtk_text_view_new_with_buffer (GtkTextBuffer *buffer)
1454 GtkTextView *text_view;
1456 text_view = (GtkTextView*)gtk_text_view_new ();
1458 gtk_text_view_set_buffer (text_view, buffer);
1460 return GTK_WIDGET (text_view);
1464 * gtk_text_view_set_buffer:
1465 * @text_view: a #GtkTextView
1466 * @buffer: (allow-none): a #GtkTextBuffer
1468 * Sets @buffer as the buffer being displayed by @text_view. The previous
1469 * buffer displayed by the text view is unreferenced, and a reference is
1470 * added to @buffer. If you owned a reference to @buffer before passing it
1471 * to this function, you must remove that reference yourself; #GtkTextView
1472 * will not "adopt" it.
1475 gtk_text_view_set_buffer (GtkTextView *text_view,
1476 GtkTextBuffer *buffer)
1478 GtkTextViewPrivate *priv;
1480 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1481 g_return_if_fail (buffer == NULL || GTK_IS_TEXT_BUFFER (buffer));
1483 priv = text_view->priv;
1485 if (priv->buffer == buffer)
1488 if (priv->buffer != NULL)
1490 /* Destroy all anchored children */
1494 copy = g_slist_copy (priv->children);
1496 while (tmp_list != NULL)
1498 GtkTextViewChild *vc = tmp_list->data;
1502 gtk_widget_destroy (vc->widget);
1503 /* vc may now be invalid! */
1506 tmp_list = g_slist_next (tmp_list);
1509 g_slist_free (copy);
1511 g_signal_handlers_disconnect_by_func (priv->buffer,
1512 gtk_text_view_mark_set_handler,
1514 g_signal_handlers_disconnect_by_func (priv->buffer,
1515 gtk_text_view_target_list_notify,
1517 g_signal_handlers_disconnect_by_func (priv->buffer,
1518 gtk_text_view_paste_done_handler,
1521 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1523 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1524 GDK_SELECTION_PRIMARY);
1525 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
1529 gtk_text_layout_set_buffer (priv->layout, NULL);
1531 g_object_unref (priv->buffer);
1532 priv->dnd_mark = NULL;
1533 priv->first_para_mark = NULL;
1534 cancel_pending_scroll (text_view);
1537 priv->buffer = buffer;
1540 gtk_text_layout_set_buffer (priv->layout, buffer);
1546 g_object_ref (buffer);
1548 gtk_text_buffer_get_iter_at_offset (priv->buffer, &start, 0);
1550 priv->dnd_mark = gtk_text_buffer_create_mark (priv->buffer,
1554 priv->first_para_mark = gtk_text_buffer_create_mark (priv->buffer,
1558 priv->first_para_pixels = 0;
1561 g_signal_connect (priv->buffer, "mark-set",
1562 G_CALLBACK (gtk_text_view_mark_set_handler),
1564 g_signal_connect (priv->buffer, "notify::paste-target-list",
1565 G_CALLBACK (gtk_text_view_target_list_notify),
1567 g_signal_connect (priv->buffer, "paste-done",
1568 G_CALLBACK (gtk_text_view_paste_done_handler),
1571 gtk_text_view_target_list_notify (priv->buffer, NULL, text_view);
1573 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
1575 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
1576 GDK_SELECTION_PRIMARY);
1577 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
1581 g_object_notify (G_OBJECT (text_view), "buffer");
1583 if (gtk_widget_get_visible (GTK_WIDGET (text_view)))
1584 gtk_widget_queue_draw (GTK_WIDGET (text_view));
1586 DV(g_print ("Invalidating due to set_buffer\n"));
1587 gtk_text_view_invalidate (text_view);
1590 static GtkTextBuffer*
1591 get_buffer (GtkTextView *text_view)
1593 if (text_view->priv->buffer == NULL)
1596 b = gtk_text_buffer_new (NULL);
1597 gtk_text_view_set_buffer (text_view, b);
1601 return text_view->priv->buffer;
1605 * gtk_text_view_get_buffer:
1606 * @text_view: a #GtkTextView
1608 * Returns the #GtkTextBuffer being displayed by this text view.
1609 * The reference count on the buffer is not incremented; the caller
1610 * of this function won't own a new reference.
1612 * Return value: (transfer none): a #GtkTextBuffer
1615 gtk_text_view_get_buffer (GtkTextView *text_view)
1617 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
1619 return get_buffer (text_view);
1623 * gtk_text_view_get_iter_at_location:
1624 * @text_view: a #GtkTextView
1625 * @iter: (out): a #GtkTextIter
1626 * @x: x position, in buffer coordinates
1627 * @y: y position, in buffer coordinates
1629 * Retrieves the iterator at buffer coordinates @x and @y. Buffer
1630 * coordinates are coordinates for the entire buffer, not just the
1631 * currently-displayed portion. If you have coordinates from an
1632 * event, you have to convert those to buffer coordinates with
1633 * gtk_text_view_window_to_buffer_coords().
1636 gtk_text_view_get_iter_at_location (GtkTextView *text_view,
1641 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1642 g_return_if_fail (iter != NULL);
1644 gtk_text_view_ensure_layout (text_view);
1646 gtk_text_layout_get_iter_at_pixel (text_view->priv->layout,
1651 * gtk_text_view_get_iter_at_position:
1652 * @text_view: a #GtkTextView
1653 * @iter: (out): a #GtkTextIter
1654 * @trailing: (out) (allow-none): if non-%NULL, location to store an integer indicating where
1655 * in the grapheme the user clicked. It will either be
1656 * zero, or the number of characters in the grapheme.
1657 * 0 represents the trailing edge of the grapheme.
1658 * @x: x position, in buffer coordinates
1659 * @y: y position, in buffer coordinates
1661 * Retrieves the iterator pointing to the character at buffer
1662 * coordinates @x and @y. Buffer coordinates are coordinates for
1663 * the entire buffer, not just the currently-displayed portion.
1664 * If you have coordinates from an event, you have to convert
1665 * those to buffer coordinates with
1666 * gtk_text_view_window_to_buffer_coords().
1668 * Note that this is different from gtk_text_view_get_iter_at_location(),
1669 * which returns cursor locations, i.e. positions <emphasis>between</emphasis>
1675 gtk_text_view_get_iter_at_position (GtkTextView *text_view,
1681 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1682 g_return_if_fail (iter != NULL);
1684 gtk_text_view_ensure_layout (text_view);
1686 gtk_text_layout_get_iter_at_position (text_view->priv->layout,
1687 iter, trailing, x, y);
1691 * gtk_text_view_get_iter_location:
1692 * @text_view: a #GtkTextView
1693 * @iter: a #GtkTextIter
1694 * @location: (out): bounds of the character at @iter
1696 * Gets a rectangle which roughly contains the character at @iter.
1697 * The rectangle position is in buffer coordinates; use
1698 * gtk_text_view_buffer_to_window_coords() to convert these
1699 * coordinates to coordinates for one of the windows in the text view.
1702 gtk_text_view_get_iter_location (GtkTextView *text_view,
1703 const GtkTextIter *iter,
1704 GdkRectangle *location)
1706 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1707 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1709 gtk_text_view_ensure_layout (text_view);
1711 gtk_text_layout_get_iter_location (text_view->priv->layout, iter, location);
1715 * gtk_text_view_get_line_yrange:
1716 * @text_view: a #GtkTextView
1717 * @iter: a #GtkTextIter
1718 * @y: (out): return location for a y coordinate
1719 * @height: (out): return location for a height
1721 * Gets the y coordinate of the top of the line containing @iter,
1722 * and the height of the line. The coordinate is a buffer coordinate;
1723 * convert to window coordinates with gtk_text_view_buffer_to_window_coords().
1726 gtk_text_view_get_line_yrange (GtkTextView *text_view,
1727 const GtkTextIter *iter,
1731 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1732 g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
1734 gtk_text_view_ensure_layout (text_view);
1736 gtk_text_layout_get_line_yrange (text_view->priv->layout,
1743 * gtk_text_view_get_line_at_y:
1744 * @text_view: a #GtkTextView
1745 * @target_iter: (out): a #GtkTextIter
1746 * @y: a y coordinate
1747 * @line_top: (out): return location for top coordinate of the line
1749 * Gets the #GtkTextIter at the start of the line containing
1750 * the coordinate @y. @y is in buffer coordinates, convert from
1751 * window coordinates with gtk_text_view_window_to_buffer_coords().
1752 * If non-%NULL, @line_top will be filled with the coordinate of the top
1756 gtk_text_view_get_line_at_y (GtkTextView *text_view,
1757 GtkTextIter *target_iter,
1761 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
1763 gtk_text_view_ensure_layout (text_view);
1765 gtk_text_layout_get_line_at_y (text_view->priv->layout,
1772 set_adjustment_clamped (GtkAdjustment *adj, gdouble val)
1774 DV (g_print (" Setting adj to raw value %g\n", val));
1776 /* We don't really want to clamp to upper; we want to clamp to
1777 upper - page_size which is the highest value the scrollbar
1778 will let us reach. */
1779 if (val > (adj->upper - adj->page_size))
1780 val = adj->upper - adj->page_size;
1782 if (val < adj->lower)
1785 if (val != adj->value)
1787 DV (g_print (" Setting adj to clamped value %g\n", val));
1788 gtk_adjustment_set_value (adj, val);
1796 * gtk_text_view_scroll_to_iter:
1797 * @text_view: a #GtkTextView
1798 * @iter: a #GtkTextIter
1799 * @within_margin: margin as a [0.0,0.5) fraction of screen size
1800 * @use_align: whether to use alignment arguments (if %FALSE,
1801 * just get the mark onscreen)
1802 * @xalign: horizontal alignment of mark within visible area
1803 * @yalign: vertical alignment of mark within visible area
1805 * Scrolls @text_view so that @iter is on the screen in the position
1806 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
1807 * left or top, 1.0 indicates right or bottom, 0.5 means center.
1808 * If @use_align is %FALSE, the text scrolls the minimal distance to
1809 * get the mark onscreen, possibly not scrolling at all. The effective
1810 * screen for purposes of this function is reduced by a margin of size
1813 * Note that this function uses the currently-computed height of the
1814 * lines in the text buffer. Line heights are computed in an idle
1815 * handler; so this function may not have the desired effect if it's
1816 * called before the height computations. To avoid oddness, consider
1817 * using gtk_text_view_scroll_to_mark() which saves a point to be
1818 * scrolled to after line validation.
1820 * Return value: %TRUE if scrolling occurred
1823 gtk_text_view_scroll_to_iter (GtkTextView *text_view,
1825 gdouble within_margin,
1831 GdkRectangle screen;
1836 gboolean retval = FALSE;
1838 gint screen_xoffset, screen_yoffset;
1839 gint current_x_scroll, current_y_scroll;
1841 /* FIXME why don't we do the validate-at-scroll-destination thing
1842 * from flush_scroll in this function? I think it wasn't done before
1843 * because changed_handler was screwed up, but I could be wrong.
1846 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
1847 g_return_val_if_fail (iter != NULL, FALSE);
1848 g_return_val_if_fail (within_margin >= 0.0 && within_margin < 0.5, FALSE);
1849 g_return_val_if_fail (xalign >= 0.0 && xalign <= 1.0, FALSE);
1850 g_return_val_if_fail (yalign >= 0.0 && yalign <= 1.0, FALSE);
1852 widget = GTK_WIDGET (text_view);
1854 DV(g_print(G_STRLOC"\n"));
1856 gtk_text_layout_get_iter_location (text_view->priv->layout,
1860 DV (g_print (" target rect %d,%d %d x %d\n", rect.x, rect.y, rect.width, rect.height));
1862 current_x_scroll = text_view->priv->xoffset;
1863 current_y_scroll = text_view->priv->yoffset;
1865 screen.x = current_x_scroll;
1866 screen.y = current_y_scroll;
1867 screen.width = SCREEN_WIDTH (widget);
1868 screen.height = SCREEN_HEIGHT (widget);
1870 screen_xoffset = screen.width * within_margin;
1871 screen_yoffset = screen.height * within_margin;
1873 screen.x += screen_xoffset;
1874 screen.y += screen_yoffset;
1875 screen.width -= screen_xoffset * 2;
1876 screen.height -= screen_yoffset * 2;
1878 /* paranoia check */
1879 if (screen.width < 1)
1881 if (screen.height < 1)
1884 /* The -1 here ensures that we leave enough space to draw the cursor
1885 * when this function is used for horizontal scrolling.
1887 screen_right = screen.x + screen.width - 1;
1888 screen_bottom = screen.y + screen.height;
1890 /* The alignment affects the point in the target character that we
1891 * choose to align. If we're doing right/bottom alignment, we align
1892 * the right/bottom edge of the character the mark is at; if we're
1893 * doing left/top we align the left/top edge of the character; if
1894 * we're doing center alignment we align the center of the
1898 /* Vertical scroll */
1901 scroll_dest = current_y_scroll;
1905 scroll_dest = rect.y + (rect.height * yalign) - (screen.height * yalign);
1907 /* if scroll_dest < screen.y, we move a negative increment (up),
1908 * else a positive increment (down)
1910 scroll_inc = scroll_dest - screen.y + screen_yoffset;
1914 /* move minimum to get onscreen */
1915 if (rect.y < screen.y)
1917 scroll_dest = rect.y;
1918 scroll_inc = scroll_dest - screen.y - screen_yoffset;
1920 else if ((rect.y + rect.height) > screen_bottom)
1922 scroll_dest = rect.y + rect.height;
1923 scroll_inc = scroll_dest - screen_bottom + screen_yoffset;
1927 if (scroll_inc != 0)
1929 retval = set_adjustment_clamped (get_vadjustment (text_view),
1930 current_y_scroll + scroll_inc);
1932 DV (g_print (" vert increment %d\n", scroll_inc));
1935 /* Horizontal scroll */
1938 scroll_dest = current_x_scroll;
1942 scroll_dest = rect.x + (rect.width * xalign) - (screen.width * xalign);
1944 /* if scroll_dest < screen.y, we move a negative increment (left),
1945 * else a positive increment (right)
1947 scroll_inc = scroll_dest - screen.x + screen_xoffset;
1951 /* move minimum to get onscreen */
1952 if (rect.x < screen.x)
1954 scroll_dest = rect.x;
1955 scroll_inc = scroll_dest - screen.x - screen_xoffset;
1957 else if ((rect.x + rect.width) > screen_right)
1959 scroll_dest = rect.x + rect.width;
1960 scroll_inc = scroll_dest - screen_right + screen_xoffset;
1964 if (scroll_inc != 0)
1966 retval = set_adjustment_clamped (get_hadjustment (text_view),
1967 current_x_scroll + scroll_inc);
1969 DV (g_print (" horiz increment %d\n", scroll_inc));
1974 DV(g_print (">Actually scrolled ("G_STRLOC")\n"));
1978 DV(g_print (">Didn't end up scrolling ("G_STRLOC")\n"));
1985 free_pending_scroll (GtkTextPendingScroll *scroll)
1987 if (!gtk_text_mark_get_deleted (scroll->mark))
1988 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (scroll->mark),
1990 g_object_unref (scroll->mark);
1995 cancel_pending_scroll (GtkTextView *text_view)
1997 if (text_view->priv->pending_scroll)
1999 free_pending_scroll (text_view->priv->pending_scroll);
2000 text_view->priv->pending_scroll = NULL;
2005 gtk_text_view_queue_scroll (GtkTextView *text_view,
2007 gdouble within_margin,
2013 GtkTextPendingScroll *scroll;
2015 DV(g_print(G_STRLOC"\n"));
2017 scroll = g_new (GtkTextPendingScroll, 1);
2019 scroll->within_margin = within_margin;
2020 scroll->use_align = use_align;
2021 scroll->xalign = xalign;
2022 scroll->yalign = yalign;
2024 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2026 scroll->mark = gtk_text_buffer_create_mark (get_buffer (text_view),
2029 gtk_text_mark_get_left_gravity (mark));
2031 g_object_ref (scroll->mark);
2033 cancel_pending_scroll (text_view);
2035 text_view->priv->pending_scroll = scroll;
2039 gtk_text_view_flush_scroll (GtkTextView *text_view)
2041 GtkAllocation allocation;
2043 GtkTextPendingScroll *scroll;
2047 widget = GTK_WIDGET (text_view);
2049 DV(g_print(G_STRLOC"\n"));
2051 if (text_view->priv->pending_scroll == NULL)
2053 DV (g_print ("in flush scroll, no pending scroll\n"));
2057 scroll = text_view->priv->pending_scroll;
2059 /* avoid recursion */
2060 text_view->priv->pending_scroll = NULL;
2062 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, scroll->mark);
2064 /* Validate area around the scroll destination, so the adjustment
2065 * can meaningfully point into that area. We must validate
2066 * enough area to be sure that after we scroll, everything onscreen
2067 * is valid; otherwise, validation will maintain the first para
2068 * in one place, but may push the target iter off the bottom of
2071 DV(g_print (">Validating scroll destination ("G_STRLOC")\n"));
2072 gtk_widget_get_allocation (widget, &allocation);
2073 gtk_text_layout_validate_yrange (text_view->priv->layout, &iter,
2074 -(allocation.height * 2),
2075 allocation.height * 2);
2077 DV(g_print (">Done validating scroll destination ("G_STRLOC")\n"));
2079 /* Ensure we have updated width/height */
2080 gtk_text_view_update_adjustments (text_view);
2082 retval = gtk_text_view_scroll_to_iter (text_view,
2084 scroll->within_margin,
2089 free_pending_scroll (scroll);
2095 gtk_text_view_set_adjustment_upper (GtkAdjustment *adj, gdouble upper)
2097 if (upper != adj->upper)
2099 gdouble min = MAX (0.0, upper - adj->page_size);
2100 gboolean value_changed = FALSE;
2104 if (adj->value > min)
2107 value_changed = TRUE;
2110 gtk_adjustment_changed (adj);
2111 DV(g_print(">Changed adj upper to %g ("G_STRLOC")\n", upper));
2115 DV(g_print(">Changed adj value because upper decreased ("G_STRLOC")\n"));
2116 gtk_adjustment_value_changed (adj);
2122 gtk_text_view_update_adjustments (GtkTextView *text_view)
2124 GtkTextViewPrivate *priv;
2125 gint width = 0, height = 0;
2127 DV(g_print(">Updating adjustments ("G_STRLOC")\n"));
2129 priv = text_view->priv;
2132 gtk_text_layout_get_size (priv->layout, &width, &height);
2134 /* Make room for the cursor after the last character in the widest line */
2135 width += SPACE_FOR_CURSOR;
2137 if (priv->width != width || priv->height != height)
2139 if (priv->width != width)
2140 priv->width_changed = TRUE;
2142 priv->width = width;
2143 priv->height = height;
2145 gtk_text_view_set_adjustment_upper (get_hadjustment (text_view),
2146 MAX (SCREEN_WIDTH (text_view), width));
2147 gtk_text_view_set_adjustment_upper (get_vadjustment (text_view),
2148 MAX (SCREEN_HEIGHT (text_view), height));
2150 /* hadj/vadj exist since we called get_hadjustment/get_vadjustment above */
2152 /* Set up the step sizes; we'll say that a page is
2153 our allocation minus one step, and a step is
2154 1/10 of our allocation. */
2155 priv->hadjustment->step_increment =
2156 SCREEN_WIDTH (text_view) / 10.0;
2157 priv->hadjustment->page_increment =
2158 SCREEN_WIDTH (text_view) * 0.9;
2160 priv->vadjustment->step_increment =
2161 SCREEN_HEIGHT (text_view) / 10.0;
2162 priv->vadjustment->page_increment =
2163 SCREEN_HEIGHT (text_view) * 0.9;
2165 gtk_adjustment_changed (get_hadjustment (text_view));
2166 gtk_adjustment_changed (get_vadjustment (text_view));
2171 gtk_text_view_update_layout_width (GtkTextView *text_view)
2173 DV(g_print(">Updating layout width ("G_STRLOC")\n"));
2175 gtk_text_view_ensure_layout (text_view);
2177 gtk_text_layout_set_screen_width (text_view->priv->layout,
2178 MAX (1, SCREEN_WIDTH (text_view) - SPACE_FOR_CURSOR));
2182 gtk_text_view_update_im_spot_location (GtkTextView *text_view)
2186 if (text_view->priv->layout == NULL)
2189 gtk_text_view_get_cursor_location (text_view, &area);
2191 area.x -= text_view->priv->xoffset;
2192 area.y -= text_view->priv->yoffset;
2194 /* Width returned by Pango indicates direction of cursor,
2195 * by it's sign more than the size of cursor.
2199 gtk_im_context_set_cursor_location (text_view->priv->im_context, &area);
2203 do_update_im_spot_location (gpointer text_view)
2205 GtkTextViewPrivate *priv;
2207 priv = GTK_TEXT_VIEW (text_view)->priv;
2208 priv->im_spot_idle = 0;
2210 gtk_text_view_update_im_spot_location (text_view);
2215 queue_update_im_spot_location (GtkTextView *text_view)
2217 GtkTextViewPrivate *priv;
2219 priv = text_view->priv;
2221 /* Use priority a little higher than GTK_TEXT_VIEW_PRIORITY_VALIDATE,
2222 * so we don't wait until the entire buffer has been validated. */
2223 if (!priv->im_spot_idle)
2224 priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
2225 do_update_im_spot_location,
2231 flush_update_im_spot_location (GtkTextView *text_view)
2233 GtkTextViewPrivate *priv;
2235 priv = text_view->priv;
2237 if (priv->im_spot_idle)
2239 g_source_remove (priv->im_spot_idle);
2240 priv->im_spot_idle = 0;
2241 gtk_text_view_update_im_spot_location (text_view);
2246 * gtk_text_view_scroll_to_mark:
2247 * @text_view: a #GtkTextView
2248 * @mark: a #GtkTextMark
2249 * @within_margin: margin as a [0.0,0.5) fraction of screen size
2250 * @use_align: whether to use alignment arguments (if %FALSE, just
2251 * get the mark onscreen)
2252 * @xalign: horizontal alignment of mark within visible area
2253 * @yalign: vertical alignment of mark within visible area
2255 * Scrolls @text_view so that @mark is on the screen in the position
2256 * indicated by @xalign and @yalign. An alignment of 0.0 indicates
2257 * left or top, 1.0 indicates right or bottom, 0.5 means center.
2258 * If @use_align is %FALSE, the text scrolls the minimal distance to
2259 * get the mark onscreen, possibly not scrolling at all. The effective
2260 * screen for purposes of this function is reduced by a margin of size
2264 gtk_text_view_scroll_to_mark (GtkTextView *text_view,
2266 gdouble within_margin,
2271 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2272 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2273 g_return_if_fail (within_margin >= 0.0 && within_margin < 0.5);
2274 g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
2275 g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
2277 /* We need to verify that the buffer contains the mark, otherwise this
2278 * can lead to data structure corruption later on.
2280 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2282 gtk_text_view_queue_scroll (text_view, mark,
2288 /* If no validation is pending, we need to go ahead and force an
2291 if (text_view->priv->layout &&
2292 gtk_text_layout_is_valid (text_view->priv->layout))
2293 gtk_text_view_flush_scroll (text_view);
2297 * gtk_text_view_scroll_mark_onscreen:
2298 * @text_view: a #GtkTextView
2299 * @mark: a mark in the buffer for @text_view
2301 * Scrolls @text_view the minimum distance such that @mark is contained
2302 * within the visible area of the widget.
2305 gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
2308 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2309 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2311 /* We need to verify that the buffer contains the mark, otherwise this
2312 * can lead to data structure corruption later on.
2314 g_return_if_fail (get_buffer (text_view) == gtk_text_mark_get_buffer (mark));
2316 gtk_text_view_scroll_to_mark (text_view, mark, 0.0, FALSE, 0.0, 0.0);
2320 clamp_iter_onscreen (GtkTextView *text_view, GtkTextIter *iter)
2322 GdkRectangle visible_rect;
2323 gtk_text_view_get_visible_rect (text_view, &visible_rect);
2325 return gtk_text_layout_clamp_iter_to_vrange (text_view->priv->layout, iter,
2327 visible_rect.y + visible_rect.height);
2331 * gtk_text_view_move_mark_onscreen:
2332 * @text_view: a #GtkTextView
2333 * @mark: a #GtkTextMark
2335 * Moves a mark within the buffer so that it's
2336 * located within the currently-visible text area.
2338 * Return value: %TRUE if the mark moved (wasn't already onscreen)
2341 gtk_text_view_move_mark_onscreen (GtkTextView *text_view,
2346 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2347 g_return_val_if_fail (mark != NULL, FALSE);
2349 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, mark);
2351 if (clamp_iter_onscreen (text_view, &iter))
2353 gtk_text_buffer_move_mark (get_buffer (text_view), mark, &iter);
2361 * gtk_text_view_get_visible_rect:
2362 * @text_view: a #GtkTextView
2363 * @visible_rect: rectangle to fill
2365 * Fills @visible_rect with the currently-visible
2366 * region of the buffer, in buffer coordinates. Convert to window coordinates
2367 * with gtk_text_view_buffer_to_window_coords().
2370 gtk_text_view_get_visible_rect (GtkTextView *text_view,
2371 GdkRectangle *visible_rect)
2375 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2377 widget = GTK_WIDGET (text_view);
2381 visible_rect->x = text_view->priv->xoffset;
2382 visible_rect->y = text_view->priv->yoffset;
2383 visible_rect->width = SCREEN_WIDTH (widget);
2384 visible_rect->height = SCREEN_HEIGHT (widget);
2386 DV(g_print(" visible rect: %d,%d %d x %d\n",
2389 visible_rect->width,
2390 visible_rect->height));
2395 * gtk_text_view_set_wrap_mode:
2396 * @text_view: a #GtkTextView
2397 * @wrap_mode: a #GtkWrapMode
2399 * Sets the line wrapping for the view.
2402 gtk_text_view_set_wrap_mode (GtkTextView *text_view,
2403 GtkWrapMode wrap_mode)
2405 GtkTextViewPrivate *priv;
2407 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2409 priv = text_view->priv;
2411 if (priv->wrap_mode != wrap_mode)
2413 priv->wrap_mode = wrap_mode;
2417 priv->layout->default_style->wrap_mode = wrap_mode;
2418 gtk_text_layout_default_style_changed (priv->layout);
2422 g_object_notify (G_OBJECT (text_view), "wrap-mode");
2426 * gtk_text_view_get_wrap_mode:
2427 * @text_view: a #GtkTextView
2429 * Gets the line wrapping for the view.
2431 * Return value: the line wrap setting
2434 gtk_text_view_get_wrap_mode (GtkTextView *text_view)
2436 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_WRAP_NONE);
2438 return text_view->priv->wrap_mode;
2442 * gtk_text_view_set_editable:
2443 * @text_view: a #GtkTextView
2444 * @setting: whether it's editable
2446 * Sets the default editability of the #GtkTextView. You can override
2447 * this default setting with tags in the buffer, using the "editable"
2448 * attribute of tags.
2451 gtk_text_view_set_editable (GtkTextView *text_view,
2454 GtkTextViewPrivate *priv;
2456 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2458 priv = text_view->priv;
2459 setting = setting != FALSE;
2461 if (priv->editable != setting)
2465 gtk_text_view_reset_im_context(text_view);
2466 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2467 gtk_im_context_focus_out (priv->im_context);
2470 priv->editable = setting;
2472 if (setting && gtk_widget_has_focus (GTK_WIDGET (text_view)))
2473 gtk_im_context_focus_in (priv->im_context);
2477 gtk_text_layout_set_overwrite_mode (priv->layout,
2478 priv->overwrite_mode && priv->editable);
2479 priv->layout->default_style->editable = priv->editable;
2480 gtk_text_layout_default_style_changed (priv->layout);
2483 g_object_notify (G_OBJECT (text_view), "editable");
2488 * gtk_text_view_get_editable:
2489 * @text_view: a #GtkTextView
2491 * Returns the default editability of the #GtkTextView. Tags in the
2492 * buffer may override this setting for some ranges of text.
2494 * Return value: whether text is editable by default
2497 gtk_text_view_get_editable (GtkTextView *text_view)
2499 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2501 return text_view->priv->editable;
2505 * gtk_text_view_set_pixels_above_lines:
2506 * @text_view: a #GtkTextView
2507 * @pixels_above_lines: pixels above paragraphs
2509 * Sets the default number of blank pixels above paragraphs in @text_view.
2510 * Tags in the buffer for @text_view may override the defaults.
2513 gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
2514 gint pixels_above_lines)
2516 GtkTextViewPrivate *priv;
2518 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2520 priv = text_view->priv;
2522 if (priv->pixels_above_lines != pixels_above_lines)
2524 priv->pixels_above_lines = pixels_above_lines;
2528 priv->layout->default_style->pixels_above_lines = pixels_above_lines;
2529 gtk_text_layout_default_style_changed (priv->layout);
2532 g_object_notify (G_OBJECT (text_view), "pixels-above-lines");
2537 * gtk_text_view_get_pixels_above_lines:
2538 * @text_view: a #GtkTextView
2540 * Gets the default number of pixels to put above paragraphs.
2542 * Return value: default number of pixels above paragraphs
2545 gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
2547 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2549 return text_view->priv->pixels_above_lines;
2553 * gtk_text_view_set_pixels_below_lines:
2554 * @text_view: a #GtkTextView
2555 * @pixels_below_lines: pixels below paragraphs
2557 * Sets the default number of pixels of blank space
2558 * to put below paragraphs in @text_view. May be overridden
2559 * by tags applied to @text_view's buffer.
2562 gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
2563 gint pixels_below_lines)
2565 GtkTextViewPrivate *priv;
2567 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2569 priv = text_view->priv;
2571 if (priv->pixels_below_lines != pixels_below_lines)
2573 priv->pixels_below_lines = pixels_below_lines;
2577 priv->layout->default_style->pixels_below_lines = pixels_below_lines;
2578 gtk_text_layout_default_style_changed (priv->layout);
2581 g_object_notify (G_OBJECT (text_view), "pixels-below-lines");
2586 * gtk_text_view_get_pixels_below_lines:
2587 * @text_view: a #GtkTextView
2589 * Gets the value set by gtk_text_view_set_pixels_below_lines().
2591 * Return value: default number of blank pixels below paragraphs
2594 gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
2596 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2598 return text_view->priv->pixels_below_lines;
2602 * gtk_text_view_set_pixels_inside_wrap:
2603 * @text_view: a #GtkTextView
2604 * @pixels_inside_wrap: default number of pixels between wrapped lines
2606 * Sets the default number of pixels of blank space to leave between
2607 * display/wrapped lines within a paragraph. May be overridden by
2608 * tags in @text_view's buffer.
2611 gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
2612 gint pixels_inside_wrap)
2614 GtkTextViewPrivate *priv;
2616 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2618 priv = text_view->priv;
2620 if (priv->pixels_inside_wrap != pixels_inside_wrap)
2622 priv->pixels_inside_wrap = pixels_inside_wrap;
2626 priv->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
2627 gtk_text_layout_default_style_changed (priv->layout);
2630 g_object_notify (G_OBJECT (text_view), "pixels-inside-wrap");
2635 * gtk_text_view_get_pixels_inside_wrap:
2636 * @text_view: a #GtkTextView
2638 * Gets the value set by gtk_text_view_set_pixels_inside_wrap().
2640 * Return value: default number of pixels of blank space between wrapped lines
2643 gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
2645 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2647 return text_view->priv->pixels_inside_wrap;
2651 * gtk_text_view_set_justification:
2652 * @text_view: a #GtkTextView
2653 * @justification: justification
2655 * Sets the default justification of text in @text_view.
2656 * Tags in the view's buffer may override the default.
2660 gtk_text_view_set_justification (GtkTextView *text_view,
2661 GtkJustification justification)
2663 GtkTextViewPrivate *priv;
2665 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2667 priv = text_view->priv;
2669 if (priv->justify != justification)
2671 priv->justify = justification;
2675 priv->layout->default_style->justification = justification;
2676 gtk_text_layout_default_style_changed (priv->layout);
2679 g_object_notify (G_OBJECT (text_view), "justification");
2684 * gtk_text_view_get_justification:
2685 * @text_view: a #GtkTextView
2687 * Gets the default justification of paragraphs in @text_view.
2688 * Tags in the buffer may override the default.
2690 * Return value: default justification
2693 gtk_text_view_get_justification (GtkTextView *text_view)
2695 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_JUSTIFY_LEFT);
2697 return text_view->priv->justify;
2701 * gtk_text_view_set_left_margin:
2702 * @text_view: a #GtkTextView
2703 * @left_margin: left margin in pixels
2705 * Sets the default left margin for text in @text_view.
2706 * Tags in the buffer may override the default.
2709 gtk_text_view_set_left_margin (GtkTextView *text_view,
2712 GtkTextViewPrivate *priv;
2714 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2716 priv = text_view->priv;
2718 if (priv->left_margin != left_margin)
2720 priv->left_margin = left_margin;
2724 priv->layout->default_style->left_margin = left_margin;
2725 gtk_text_layout_default_style_changed (priv->layout);
2728 g_object_notify (G_OBJECT (text_view), "left-margin");
2733 * gtk_text_view_get_left_margin:
2734 * @text_view: a #GtkTextView
2736 * Gets the default left margin size of paragraphs in the @text_view.
2737 * Tags in the buffer may override the default.
2739 * Return value: left margin in pixels
2742 gtk_text_view_get_left_margin (GtkTextView *text_view)
2744 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2746 return text_view->priv->left_margin;
2750 * gtk_text_view_set_right_margin:
2751 * @text_view: a #GtkTextView
2752 * @right_margin: right margin in pixels
2754 * Sets the default right margin for text in the text view.
2755 * Tags in the buffer may override the default.
2758 gtk_text_view_set_right_margin (GtkTextView *text_view,
2761 GtkTextViewPrivate *priv = text_view->priv;
2763 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2765 if (priv->right_margin != right_margin)
2767 priv->right_margin = right_margin;
2771 priv->layout->default_style->right_margin = right_margin;
2772 gtk_text_layout_default_style_changed (priv->layout);
2775 g_object_notify (G_OBJECT (text_view), "right-margin");
2780 * gtk_text_view_get_right_margin:
2781 * @text_view: a #GtkTextView
2783 * Gets the default right margin for text in @text_view. Tags
2784 * in the buffer may override the default.
2786 * Return value: right margin in pixels
2789 gtk_text_view_get_right_margin (GtkTextView *text_view)
2791 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2793 return text_view->priv->right_margin;
2797 * gtk_text_view_set_indent:
2798 * @text_view: a #GtkTextView
2799 * @indent: indentation in pixels
2801 * Sets the default indentation for paragraphs in @text_view.
2802 * Tags in the buffer may override the default.
2805 gtk_text_view_set_indent (GtkTextView *text_view,
2808 GtkTextViewPrivate *priv;
2810 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2812 priv = text_view->priv;
2814 if (priv->indent != indent)
2816 priv->indent = indent;
2820 priv->layout->default_style->indent = indent;
2821 gtk_text_layout_default_style_changed (priv->layout);
2824 g_object_notify (G_OBJECT (text_view), "indent");
2829 * gtk_text_view_get_indent:
2830 * @text_view: a #GtkTextView
2832 * Gets the default indentation of paragraphs in @text_view.
2833 * Tags in the view's buffer may override the default.
2834 * The indentation may be negative.
2836 * Return value: number of pixels of indentation
2839 gtk_text_view_get_indent (GtkTextView *text_view)
2841 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
2843 return text_view->priv->indent;
2847 * gtk_text_view_set_tabs:
2848 * @text_view: a #GtkTextView
2849 * @tabs: tabs as a #PangoTabArray
2851 * Sets the default tab stops for paragraphs in @text_view.
2852 * Tags in the buffer may override the default.
2855 gtk_text_view_set_tabs (GtkTextView *text_view,
2856 PangoTabArray *tabs)
2858 GtkTextViewPrivate *priv;
2860 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2862 priv = text_view->priv;
2865 pango_tab_array_free (priv->tabs);
2867 priv->tabs = tabs ? pango_tab_array_copy (tabs) : NULL;
2871 /* some unkosher futzing in internal struct details... */
2872 if (priv->layout->default_style->tabs)
2873 pango_tab_array_free (priv->layout->default_style->tabs);
2875 priv->layout->default_style->tabs =
2876 priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
2878 gtk_text_layout_default_style_changed (priv->layout);
2881 g_object_notify (G_OBJECT (text_view), "tabs");
2885 * gtk_text_view_get_tabs:
2886 * @text_view: a #GtkTextView
2888 * Gets the default tabs for @text_view. Tags in the buffer may
2889 * override the defaults. The returned array will be %NULL if
2890 * "standard" (8-space) tabs are used. Free the return value
2891 * with pango_tab_array_free().
2893 * Return value: copy of default tab array, or %NULL if "standard"
2894 * tabs are used; must be freed with pango_tab_array_free().
2897 gtk_text_view_get_tabs (GtkTextView *text_view)
2899 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
2901 return text_view->priv->tabs ? pango_tab_array_copy (text_view->priv->tabs) : NULL;
2905 gtk_text_view_toggle_cursor_visible (GtkTextView *text_view)
2907 gtk_text_view_set_cursor_visible (text_view, !text_view->priv->cursor_visible);
2911 * gtk_text_view_set_cursor_visible:
2912 * @text_view: a #GtkTextView
2913 * @setting: whether to show the insertion cursor
2915 * Toggles whether the insertion point is displayed. A buffer with no editable
2916 * text probably shouldn't have a visible cursor, so you may want to turn
2920 gtk_text_view_set_cursor_visible (GtkTextView *text_view,
2923 GtkTextViewPrivate *priv;
2925 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
2927 priv = text_view->priv;
2928 setting = (setting != FALSE);
2930 if (priv->cursor_visible != setting)
2932 priv->cursor_visible = setting;
2934 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
2938 gtk_text_layout_set_cursor_visible (priv->layout, setting);
2939 gtk_text_view_check_cursor_blink (text_view);
2943 g_object_notify (G_OBJECT (text_view), "cursor-visible");
2948 * gtk_text_view_get_cursor_visible:
2949 * @text_view: a #GtkTextView
2951 * Find out whether the cursor is being displayed.
2953 * Return value: whether the insertion mark is visible
2956 gtk_text_view_get_cursor_visible (GtkTextView *text_view)
2958 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2960 return text_view->priv->cursor_visible;
2965 * gtk_text_view_place_cursor_onscreen:
2966 * @text_view: a #GtkTextView
2968 * Moves the cursor to the currently visible region of the
2969 * buffer, it it isn't there already.
2971 * Return value: %TRUE if the cursor had to be moved.
2974 gtk_text_view_place_cursor_onscreen (GtkTextView *text_view)
2978 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
2980 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
2981 gtk_text_buffer_get_insert (get_buffer (text_view)));
2983 if (clamp_iter_onscreen (text_view, &insert))
2985 gtk_text_buffer_place_cursor (get_buffer (text_view), &insert);
2993 gtk_text_view_remove_validate_idles (GtkTextView *text_view)
2995 GtkTextViewPrivate *priv = text_view->priv;
2997 if (priv->first_validate_idle != 0)
2999 DV (g_print ("Removing first validate idle: %s\n", G_STRLOC));
3000 g_source_remove (priv->first_validate_idle);
3001 priv->first_validate_idle = 0;
3004 if (priv->incremental_validate_idle != 0)
3006 g_source_remove (priv->incremental_validate_idle);
3007 priv->incremental_validate_idle = 0;
3012 gtk_text_view_destroy (GtkObject *object)
3014 GtkTextView *text_view;
3015 GtkTextViewPrivate *priv;
3017 text_view = GTK_TEXT_VIEW (object);
3018 priv = text_view->priv;
3020 gtk_text_view_remove_validate_idles (text_view);
3021 gtk_text_view_set_buffer (text_view, NULL);
3022 gtk_text_view_destroy_layout (text_view);
3024 if (text_view->priv->scroll_timeout)
3026 g_source_remove (text_view->priv->scroll_timeout);
3027 text_view->priv->scroll_timeout = 0;
3030 if (priv->im_spot_idle)
3032 g_source_remove (priv->im_spot_idle);
3033 priv->im_spot_idle = 0;
3036 GTK_OBJECT_CLASS (gtk_text_view_parent_class)->destroy (object);
3040 gtk_text_view_finalize (GObject *object)
3042 GtkTextView *text_view;
3043 GtkTextViewPrivate *priv;
3045 text_view = GTK_TEXT_VIEW (object);
3046 priv = text_view->priv;
3048 g_assert (priv->buffer == NULL);
3050 gtk_text_view_destroy_layout (text_view);
3051 gtk_text_view_set_buffer (text_view, NULL);
3053 cancel_pending_scroll (text_view);
3056 pango_tab_array_free (priv->tabs);
3058 if (priv->hadjustment)
3059 g_object_unref (priv->hadjustment);
3060 if (priv->vadjustment)
3061 g_object_unref (priv->vadjustment);
3063 text_window_free (priv->text_window);
3065 if (priv->left_window)
3066 text_window_free (priv->left_window);
3068 if (priv->top_window)
3069 text_window_free (priv->top_window);
3071 if (priv->right_window)
3072 text_window_free (priv->right_window);
3074 if (priv->bottom_window)
3075 text_window_free (priv->bottom_window);
3077 g_object_unref (priv->im_context);
3079 g_free (priv->im_module);
3081 G_OBJECT_CLASS (gtk_text_view_parent_class)->finalize (object);
3085 gtk_text_view_set_property (GObject *object,
3087 const GValue *value,
3090 GtkTextView *text_view;
3091 GtkTextViewPrivate *priv;
3093 text_view = GTK_TEXT_VIEW (object);
3094 priv = text_view->priv;
3098 case PROP_PIXELS_ABOVE_LINES:
3099 gtk_text_view_set_pixels_above_lines (text_view, g_value_get_int (value));
3102 case PROP_PIXELS_BELOW_LINES:
3103 gtk_text_view_set_pixels_below_lines (text_view, g_value_get_int (value));
3106 case PROP_PIXELS_INSIDE_WRAP:
3107 gtk_text_view_set_pixels_inside_wrap (text_view, g_value_get_int (value));
3111 gtk_text_view_set_editable (text_view, g_value_get_boolean (value));
3114 case PROP_WRAP_MODE:
3115 gtk_text_view_set_wrap_mode (text_view, g_value_get_enum (value));
3118 case PROP_JUSTIFICATION:
3119 gtk_text_view_set_justification (text_view, g_value_get_enum (value));
3122 case PROP_LEFT_MARGIN:
3123 gtk_text_view_set_left_margin (text_view, g_value_get_int (value));
3126 case PROP_RIGHT_MARGIN:
3127 gtk_text_view_set_right_margin (text_view, g_value_get_int (value));
3131 gtk_text_view_set_indent (text_view, g_value_get_int (value));
3135 gtk_text_view_set_tabs (text_view, g_value_get_boxed (value));
3138 case PROP_CURSOR_VISIBLE:
3139 gtk_text_view_set_cursor_visible (text_view, g_value_get_boolean (value));
3142 case PROP_OVERWRITE:
3143 gtk_text_view_set_overwrite (text_view, g_value_get_boolean (value));
3147 gtk_text_view_set_buffer (text_view, GTK_TEXT_BUFFER (g_value_get_object (value)));
3150 case PROP_ACCEPTS_TAB:
3151 gtk_text_view_set_accepts_tab (text_view, g_value_get_boolean (value));
3154 case PROP_IM_MODULE:
3155 g_free (priv->im_module);
3156 priv->im_module = g_value_dup_string (value);
3157 if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
3158 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
3162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3168 gtk_text_view_get_property (GObject *object,
3173 GtkTextView *text_view;
3174 GtkTextViewPrivate *priv;
3176 text_view = GTK_TEXT_VIEW (object);
3177 priv = text_view->priv;
3181 case PROP_PIXELS_ABOVE_LINES:
3182 g_value_set_int (value, priv->pixels_above_lines);
3185 case PROP_PIXELS_BELOW_LINES:
3186 g_value_set_int (value, priv->pixels_below_lines);
3189 case PROP_PIXELS_INSIDE_WRAP:
3190 g_value_set_int (value, priv->pixels_inside_wrap);
3194 g_value_set_boolean (value, priv->editable);
3197 case PROP_WRAP_MODE:
3198 g_value_set_enum (value, priv->wrap_mode);
3201 case PROP_JUSTIFICATION:
3202 g_value_set_enum (value, priv->justify);
3205 case PROP_LEFT_MARGIN:
3206 g_value_set_int (value, priv->left_margin);
3209 case PROP_RIGHT_MARGIN:
3210 g_value_set_int (value, priv->right_margin);
3214 g_value_set_int (value, priv->indent);
3218 g_value_set_boxed (value, priv->tabs);
3221 case PROP_CURSOR_VISIBLE:
3222 g_value_set_boolean (value, priv->cursor_visible);
3226 g_value_set_object (value, get_buffer (text_view));
3229 case PROP_OVERWRITE:
3230 g_value_set_boolean (value, priv->overwrite_mode);
3233 case PROP_ACCEPTS_TAB:
3234 g_value_set_boolean (value, priv->accepts_tab);
3237 case PROP_IM_MODULE:
3238 g_value_set_string (value, priv->im_module);
3242 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3248 gtk_text_view_size_request (GtkWidget *widget,
3249 GtkRequisition *requisition)
3251 GtkTextView *text_view;
3252 GtkTextViewPrivate *priv;
3254 gint focus_edge_width;
3257 gboolean interior_focus;
3259 text_view = GTK_TEXT_VIEW (widget);
3260 priv = text_view->priv;
3262 gtk_widget_style_get (widget,
3263 "interior-focus", &interior_focus,
3264 "focus-line-width", &focus_width,
3268 focus_edge_width = 0;
3270 focus_edge_width = focus_width;
3274 priv->text_window->requisition.width = priv->layout->width;
3275 priv->text_window->requisition.height = priv->layout->height;
3279 priv->text_window->requisition.width = 0;
3280 priv->text_window->requisition.height = 0;
3283 requisition->width = priv->text_window->requisition.width + focus_edge_width * 2;
3284 requisition->height = priv->text_window->requisition.height + focus_edge_width * 2;
3286 if (priv->left_window)
3287 requisition->width += priv->left_window->requisition.width;
3289 if (priv->right_window)
3290 requisition->width += priv->right_window->requisition.width;
3292 if (priv->top_window)
3293 requisition->height += priv->top_window->requisition.height;
3295 if (priv->bottom_window)
3296 requisition->height += priv->bottom_window->requisition.height;
3298 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3299 requisition->width += border_width * 2;
3300 requisition->height += border_width * 2;
3302 tmp_list = priv->children;
3303 while (tmp_list != NULL)
3305 GtkTextViewChild *child = tmp_list->data;
3309 GtkRequisition child_req;
3310 GtkRequisition old_req;
3312 gtk_size_request_get_size (GTK_SIZE_REQUEST (child->widget),
3315 gtk_widget_size_request (child->widget, &child_req);
3317 gtk_size_request_get_size (GTK_SIZE_REQUEST (child->widget),
3320 /* Invalidate layout lines if required */
3322 (old_req.width != child_req.width ||
3323 old_req.height != child_req.height))
3324 gtk_text_child_anchor_queue_resize (child->anchor,
3329 GtkRequisition child_req;
3331 gtk_widget_size_request (child->widget, &child_req);
3334 tmp_list = g_slist_next (tmp_list);
3337 /* Cache the requested size of the text view so we can
3338 * compare it in the changed_handler() */
3339 priv->cached_size_request = *requisition;
3343 gtk_text_view_compute_child_allocation (GtkTextView *text_view,
3344 GtkTextViewChild *vc,
3345 GtkAllocation *allocation)
3351 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3355 gtk_text_layout_get_line_yrange (text_view->priv->layout, &iter,
3358 buffer_y += vc->from_top_of_line;
3360 allocation->x = vc->from_left_of_buffer - text_view->priv->xoffset;
3361 allocation->y = buffer_y - text_view->priv->yoffset;
3363 gtk_size_request_get_size (GTK_SIZE_REQUEST (vc->widget),
3365 allocation->width = req.width;
3366 allocation->height = req.height;
3370 gtk_text_view_update_child_allocation (GtkTextView *text_view,
3371 GtkTextViewChild *vc)
3373 GtkAllocation allocation;
3375 gtk_text_view_compute_child_allocation (text_view, vc, &allocation);
3377 gtk_widget_size_allocate (vc->widget, &allocation);
3380 g_print ("allocation for %p allocated to %d,%d yoffset = %d\n",
3382 vc->widget->allocation.x,
3383 vc->widget->allocation.y,
3384 text_view->priv->yoffset);
3389 gtk_text_view_child_allocated (GtkTextLayout *layout,
3395 GtkTextViewChild *vc = NULL;
3396 GtkTextView *text_view = data;
3398 /* x,y is the position of the child from the top of the line, and
3399 * from the left of the buffer. We have to translate that into text
3400 * window coordinates, then size_allocate the child.
3403 vc = g_object_get_data (G_OBJECT (child),
3404 "gtk-text-view-child");
3406 g_assert (vc != NULL);
3408 DV (g_print ("child allocated at %d,%d\n", x, y));
3410 vc->from_left_of_buffer = x;
3411 vc->from_top_of_line = y;
3413 gtk_text_view_update_child_allocation (text_view, vc);
3417 gtk_text_view_allocate_children (GtkTextView *text_view)
3421 DV(g_print(G_STRLOC"\n"));
3423 tmp_list = text_view->priv->children;
3424 while (tmp_list != NULL)
3426 GtkTextViewChild *child = tmp_list->data;
3428 g_assert (child != NULL);
3432 /* We need to force-validate the regions containing
3435 GtkTextIter child_loc;
3436 gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
3440 /* Since anchored children are only ever allocated from
3441 * gtk_text_layout_get_line_display() we have to make sure
3442 * that the display line caching in the layout doesn't
3443 * get in the way. Invalidating the layout around the anchor
3446 if (GTK_WIDGET_ALLOC_NEEDED (child->widget))
3448 GtkTextIter end = child_loc;
3449 gtk_text_iter_forward_char (&end);
3450 gtk_text_layout_invalidate (text_view->priv->layout, &child_loc, &end);
3453 gtk_text_layout_validate_yrange (text_view->priv->layout,
3459 GtkAllocation allocation;
3460 GtkRequisition child_req;
3462 allocation.x = child->x;
3463 allocation.y = child->y;
3465 gtk_size_request_get_size (GTK_SIZE_REQUEST (child->widget),
3468 allocation.width = child_req.width;
3469 allocation.height = child_req.height;
3471 gtk_widget_size_allocate (child->widget, &allocation);
3474 tmp_list = g_slist_next (tmp_list);
3479 gtk_text_view_size_allocate (GtkWidget *widget,
3480 GtkAllocation *allocation)
3482 GtkAllocation widget_allocation;
3483 GtkTextView *text_view;
3484 GtkTextViewPrivate *priv;
3485 GtkTextIter first_para;
3488 GdkRectangle text_rect;
3489 GdkRectangle left_rect;
3490 GdkRectangle right_rect;
3491 GdkRectangle top_rect;
3492 GdkRectangle bottom_rect;
3493 gint focus_edge_width;
3496 gboolean interior_focus;
3497 gboolean size_changed;
3499 text_view = GTK_TEXT_VIEW (widget);
3500 priv = text_view->priv;
3502 DV(g_print(G_STRLOC"\n"));
3504 gtk_widget_get_allocation (widget, &widget_allocation);
3506 widget_allocation.width != allocation->width ||
3507 widget_allocation.height != allocation->height;
3509 border_width = gtk_container_get_border_width (GTK_CONTAINER (text_view));
3511 gtk_widget_set_allocation (widget, allocation);
3513 if (gtk_widget_get_realized (widget))
3515 gdk_window_move_resize (gtk_widget_get_window (widget),
3516 allocation->x, allocation->y,
3517 allocation->width, allocation->height);
3520 /* distribute width/height among child windows. Ensure all
3521 * windows get at least a 1x1 allocation.
3524 gtk_widget_style_get (widget,
3525 "interior-focus", &interior_focus,
3526 "focus-line-width", &focus_width,
3530 focus_edge_width = 0;
3532 focus_edge_width = focus_width;
3534 width = allocation->width - focus_edge_width * 2 - border_width * 2;
3536 if (priv->left_window)
3537 left_rect.width = priv->left_window->requisition.width;
3539 left_rect.width = 0;
3541 width -= left_rect.width;
3543 if (priv->right_window)
3544 right_rect.width = priv->right_window->requisition.width;
3546 right_rect.width = 0;
3548 width -= right_rect.width;
3550 text_rect.width = MAX (1, width);
3552 top_rect.width = text_rect.width;
3553 bottom_rect.width = text_rect.width;
3556 height = allocation->height - focus_edge_width * 2 - border_width * 2;
3558 if (priv->top_window)
3559 top_rect.height = priv->top_window->requisition.height;
3561 top_rect.height = 0;
3563 height -= top_rect.height;
3565 if (priv->bottom_window)
3566 bottom_rect.height = priv->bottom_window->requisition.height;
3568 bottom_rect.height = 0;
3570 height -= bottom_rect.height;
3572 text_rect.height = MAX (1, height);
3574 left_rect.height = text_rect.height;
3575 right_rect.height = text_rect.height;
3578 left_rect.x = focus_edge_width + border_width;
3579 top_rect.y = focus_edge_width + border_width;
3581 text_rect.x = left_rect.x + left_rect.width;
3582 text_rect.y = top_rect.y + top_rect.height;
3584 left_rect.y = text_rect.y;
3585 right_rect.y = text_rect.y;
3587 top_rect.x = text_rect.x;
3588 bottom_rect.x = text_rect.x;
3590 right_rect.x = text_rect.x + text_rect.width;
3591 bottom_rect.y = text_rect.y + text_rect.height;
3593 text_window_size_allocate (priv->text_window,
3596 if (priv->left_window)
3597 text_window_size_allocate (priv->left_window,
3600 if (priv->right_window)
3601 text_window_size_allocate (priv->right_window,
3604 if (priv->top_window)
3605 text_window_size_allocate (priv->top_window,
3608 if (priv->bottom_window)
3609 text_window_size_allocate (priv->bottom_window,
3612 gtk_text_view_update_layout_width (text_view);
3614 /* Note that this will do some layout validation */
3615 gtk_text_view_allocate_children (text_view);
3617 /* Ensure h/v adj exist */
3618 get_hadjustment (text_view);
3619 get_vadjustment (text_view);
3621 priv->hadjustment->page_size = SCREEN_WIDTH (text_view);
3622 priv->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9;
3623 priv->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1;
3624 priv->hadjustment->lower = 0;
3625 priv->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
3628 if (priv->hadjustment->value > priv->hadjustment->upper - priv->hadjustment->page_size)
3629 gtk_adjustment_set_value (priv->hadjustment, MAX (0, priv->hadjustment->upper - priv->hadjustment->page_size));
3631 gtk_adjustment_changed (priv->hadjustment);
3633 priv->vadjustment->page_size = SCREEN_HEIGHT (text_view);
3634 priv->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9;
3635 priv->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1;
3636 priv->vadjustment->lower = 0;
3637 priv->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
3640 /* Now adjust the value of the adjustment to keep the cursor at the
3641 * same place in the buffer
3643 gtk_text_view_get_first_para_iter (text_view, &first_para);
3644 gtk_text_layout_get_line_yrange (priv->layout, &first_para, &y, NULL);
3646 y += priv->first_para_pixels;
3648 if (y > priv->vadjustment->upper - priv->vadjustment->page_size)
3649 y = MAX (0, priv->vadjustment->upper - priv->vadjustment->page_size);
3651 if (y != priv->yoffset)
3652 gtk_adjustment_set_value (priv->vadjustment, y);
3654 gtk_adjustment_changed (priv->vadjustment);
3656 /* The GTK resize loop processes all the pending exposes right
3657 * after doing the resize stuff, so the idle sizer won't have a
3658 * chance to run. So we do the work here.
3660 gtk_text_view_flush_first_validate (text_view);
3662 /* widget->window doesn't get auto-redrawn as the layout is computed, so has to
3665 if (size_changed && gtk_widget_get_realized (widget))
3666 gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE);
3670 gtk_text_view_get_first_para_iter (GtkTextView *text_view,
3673 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), iter,
3674 text_view->priv->first_para_mark);
3678 gtk_text_view_validate_onscreen (GtkTextView *text_view)
3681 GtkTextViewPrivate *priv;
3683 widget = GTK_WIDGET (text_view);
3684 priv = text_view->priv;
3686 DV(g_print(">Validating onscreen ("G_STRLOC")\n"));
3688 if (SCREEN_HEIGHT (widget) > 0)
3690 GtkTextIter first_para;
3692 /* Be sure we've validated the stuff onscreen; if we
3693 * scrolled, these calls won't have any effect, because
3694 * they were called in the recursive validate_onscreen
3696 gtk_text_view_get_first_para_iter (text_view, &first_para);
3698 gtk_text_layout_validate_yrange (priv->layout,
3701 priv->first_para_pixels +
3702 SCREEN_HEIGHT (widget));
3705 priv->onscreen_validated = TRUE;
3707 DV(g_print(">Done validating onscreen, onscreen_validated = TRUE ("G_STRLOC")\n"));
3709 /* This can have the odd side effect of triggering a scroll, which should
3710 * flip "onscreen_validated" back to FALSE, but should also get us
3711 * back into this function to turn it on again.
3713 gtk_text_view_update_adjustments (text_view);
3715 g_assert (priv->onscreen_validated);
3719 gtk_text_view_flush_first_validate (GtkTextView *text_view)
3721 GtkTextViewPrivate *priv = text_view->priv;
3723 if (priv->first_validate_idle == 0)
3726 /* Do this first, which means that if an "invalidate"
3727 * occurs during any of this process, a new first_validate_callback
3728 * will be installed, and we'll start again.
3730 DV (g_print ("removing first validate in %s\n", G_STRLOC));
3731 g_source_remove (priv->first_validate_idle);
3732 priv->first_validate_idle = 0;
3734 /* be sure we have up-to-date screen size set on the
3737 gtk_text_view_update_layout_width (text_view);
3739 /* Bail out if we invalidated stuff; scrolling right away will just
3740 * confuse the issue.
3742 if (priv->first_validate_idle != 0)
3744 DV(g_print(">Width change forced requeue ("G_STRLOC")\n"));
3748 /* scroll to any marks, if that's pending. This can jump us to
3749 * the validation codepath used for scrolling onscreen, if so we
3750 * bail out. It won't jump if already in that codepath since
3751 * value_changed is not recursive, so also validate if
3754 if (!gtk_text_view_flush_scroll (text_view) ||
3755 !priv->onscreen_validated)
3756 gtk_text_view_validate_onscreen (text_view);
3758 DV(g_print(">Leaving first validate idle ("G_STRLOC")\n"));
3760 g_assert (priv->onscreen_validated);
3765 first_validate_callback (gpointer data)
3767 GtkTextView *text_view = data;
3769 /* Note that some of this code is duplicated at the end of size_allocate,
3770 * keep in sync with that.
3773 DV(g_print(G_STRLOC"\n"));
3775 gtk_text_view_flush_first_validate (text_view);
3781 incremental_validate_callback (gpointer data)
3783 GtkTextView *text_view = data;
3784 gboolean result = TRUE;
3786 DV(g_print(G_STRLOC"\n"));
3788 gtk_text_layout_validate (text_view->priv->layout, 2000);
3790 gtk_text_view_update_adjustments (text_view);
3792 if (gtk_text_layout_is_valid (text_view->priv->layout))
3794 text_view->priv->incremental_validate_idle = 0;
3802 gtk_text_view_invalidate (GtkTextView *text_view)
3804 GtkTextViewPrivate *priv = text_view->priv;
3806 DV (g_print (">Invalidate, onscreen_validated = %d now FALSE ("G_STRLOC")\n",
3807 priv->onscreen_validated));
3809 priv->onscreen_validated = FALSE;
3811 /* We'll invalidate when the layout is created */
3812 if (priv->layout == NULL)
3815 if (!priv->first_validate_idle)
3817 priv->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
3818 DV (g_print (G_STRLOC": adding first validate idle %d\n",
3819 priv->first_validate_idle));
3822 if (!priv->incremental_validate_idle)
3824 priv->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
3825 DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
3826 priv->incremental_validate_idle));
3831 invalidated_handler (GtkTextLayout *layout,
3834 GtkTextView *text_view;
3836 text_view = GTK_TEXT_VIEW (data);
3838 DV (g_print ("Invalidating due to layout invalidate signal\n"));
3839 gtk_text_view_invalidate (text_view);
3843 changed_handler (GtkTextLayout *layout,
3849 GtkTextView *text_view;
3850 GtkTextViewPrivate *priv;
3852 GdkRectangle visible_rect;
3853 GdkRectangle redraw_rect;
3855 text_view = GTK_TEXT_VIEW (data);
3856 priv = text_view->priv;
3857 widget = GTK_WIDGET (data);
3859 DV(g_print(">Lines Validated ("G_STRLOC")\n"));
3861 if (gtk_widget_get_realized (widget))
3863 gtk_text_view_get_visible_rect (text_view, &visible_rect);
3865 redraw_rect.x = visible_rect.x;
3866 redraw_rect.width = visible_rect.width;
3867 redraw_rect.y = start_y;
3869 if (old_height == new_height)
3870 redraw_rect.height = old_height;
3871 else if (start_y + old_height > visible_rect.y)
3872 redraw_rect.height = MAX (0, visible_rect.y + visible_rect.height - start_y);
3874 redraw_rect.height = 0;
3876 if (gdk_rectangle_intersect (&redraw_rect, &visible_rect, &redraw_rect))
3878 /* text_window_invalidate_rect() takes buffer coordinates */
3879 text_window_invalidate_rect (priv->text_window,
3882 DV(g_print(" invalidated rect: %d,%d %d x %d\n",
3886 redraw_rect.height));
3888 if (priv->left_window)
3889 text_window_invalidate_rect (priv->left_window,
3891 if (priv->right_window)
3892 text_window_invalidate_rect (priv->right_window,
3894 if (priv->top_window)
3895 text_window_invalidate_rect (priv->top_window,
3897 if (priv->bottom_window)
3898 text_window_invalidate_rect (priv->bottom_window,
3901 queue_update_im_spot_location (text_view);
3905 if (old_height != new_height)
3907 gboolean yoffset_changed = FALSE;
3909 int new_first_para_top;
3910 int old_first_para_top;
3913 /* If the bottom of the old area was above the top of the
3914 * screen, we need to scroll to keep the current top of the
3915 * screen in place. Remember that first_para_pixels is the
3916 * position of the top of the screen in coordinates relative to
3917 * the first paragraph onscreen.
3919 * In short we are adding the height delta of the portion of the
3920 * changed region above first_para_mark to priv->yoffset.
3922 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &first,
3923 priv->first_para_mark);
3925 gtk_text_layout_get_line_yrange (layout, &first, &new_first_para_top, NULL);
3927 old_first_para_top = priv->yoffset - priv->first_para_pixels;
3929 if (new_first_para_top != old_first_para_top)
3931 priv->yoffset += new_first_para_top - old_first_para_top;
3933 get_vadjustment (text_view)->value = priv->yoffset;
3934 yoffset_changed = TRUE;
3937 if (yoffset_changed)
3939 DV(g_print ("Changing scroll position (%s)\n", G_STRLOC));
3940 gtk_adjustment_value_changed (get_vadjustment (text_view));
3943 /* FIXME be smarter about which anchored widgets we update */
3945 tmp_list = priv->children;
3946 while (tmp_list != NULL)
3948 GtkTextViewChild *child = tmp_list->data;
3951 gtk_text_view_update_child_allocation (text_view, child);
3953 tmp_list = g_slist_next (tmp_list);
3958 GtkRequisition old_req = priv->cached_size_request;
3959 GtkRequisition new_req;
3961 /* Use this instead of gtk_widget_size_request wrapper
3962 * to avoid the optimization which just returns widget->requisition
3963 * if a resize hasn't been queued.
3965 GTK_WIDGET_GET_CLASS (widget)->size_request (widget, &new_req);
3967 if (old_req.width != new_req.width ||
3968 old_req.height != new_req.height)
3970 gtk_widget_queue_resize_no_redraw (widget);
3976 gtk_text_view_realize (GtkWidget *widget)
3978 GtkAllocation allocation;
3979 GtkTextView *text_view;
3980 GtkTextViewPrivate *priv;
3982 GdkWindowAttr attributes;
3983 gint attributes_mask;
3986 text_view = GTK_TEXT_VIEW (widget);
3987 priv = text_view->priv;
3989 gtk_widget_set_realized (widget, TRUE);
3991 gtk_widget_get_allocation (widget, &allocation);
3993 attributes.window_type = GDK_WINDOW_CHILD;
3994 attributes.x = allocation.x;
3995 attributes.y = allocation.y;
3996 attributes.width = allocation.width;
3997 attributes.height = allocation.height;
3998 attributes.wclass = GDK_INPUT_OUTPUT;
3999 attributes.visual = gtk_widget_get_visual (widget);
4000 attributes.colormap = gtk_widget_get_colormap (widget);
4001 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK;
4003 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
4005 window = gdk_window_new (gtk_widget_get_parent_window (widget),
4006 &attributes, attributes_mask);
4007 gtk_widget_set_window (widget, window);
4008 gdk_window_set_user_data (window, widget);
4010 /* must come before text_window_realize calls */
4011 gtk_widget_style_attach (widget);
4013 gdk_window_set_background (window,
4014 >k_widget_get_style (widget)->bg[gtk_widget_get_state (widget)]);
4016 text_window_realize (priv->text_window, widget);
4018 if (priv->left_window)
4019 text_window_realize (priv->left_window, widget);
4021 if (priv->top_window)
4022 text_window_realize (priv->top_window, widget);
4024 if (priv->right_window)
4025 text_window_realize (priv->right_window, widget);
4027 if (priv->bottom_window)
4028 text_window_realize (priv->bottom_window, widget);
4030 gtk_text_view_ensure_layout (text_view);
4034 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4035 GDK_SELECTION_PRIMARY);
4036 gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
4039 tmp_list = priv->children;
4040 while (tmp_list != NULL)
4042 GtkTextViewChild *vc = tmp_list->data;
4044 text_view_child_set_parent_window (text_view, vc);
4046 tmp_list = tmp_list->next;
4049 /* Ensure updating the spot location. */
4050 gtk_text_view_update_im_spot_location (text_view);
4054 gtk_text_view_unrealize (GtkWidget *widget)
4056 GtkTextView *text_view;
4057 GtkTextViewPrivate *priv;
4059 text_view = GTK_TEXT_VIEW (widget);
4060 priv = text_view->priv;
4064 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
4065 GDK_SELECTION_PRIMARY);
4066 gtk_text_buffer_remove_selection_clipboard (priv->buffer, clipboard);
4069 gtk_text_view_remove_validate_idles (text_view);
4071 if (priv->popup_menu)
4073 gtk_widget_destroy (priv->popup_menu);
4074 priv->popup_menu = NULL;
4077 text_window_unrealize (priv->text_window);
4079 if (priv->left_window)
4080 text_window_unrealize (priv->left_window);
4082 if (priv->top_window)
4083 text_window_unrealize (priv->top_window);
4085 if (priv->right_window)
4086 text_window_unrealize (priv->right_window);
4088 if (priv->bottom_window)
4089 text_window_unrealize (priv->bottom_window);
4091 gtk_text_view_destroy_layout (text_view);
4093 GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize (widget);
4097 gtk_text_view_set_background (GtkTextView *text_view)
4102 GtkTextViewPrivate *priv;
4104 widget = GTK_WIDGET (text_view);
4105 priv = text_view->priv;
4107 style = gtk_widget_get_style (widget);
4108 state = gtk_widget_get_state (widget);
4110 gdk_window_set_background (gtk_widget_get_window (widget),
4113 gdk_window_set_background (priv->text_window->bin_window,
4114 &style->base[state]);
4116 if (priv->left_window)
4117 gdk_window_set_background (priv->left_window->bin_window,
4119 if (priv->right_window)
4120 gdk_window_set_background (priv->right_window->bin_window,
4123 if (priv->top_window)
4124 gdk_window_set_background (priv->top_window->bin_window,
4127 if (priv->bottom_window)
4128 gdk_window_set_background (priv->bottom_window->bin_window,
4133 gtk_text_view_style_set (GtkWidget *widget,
4134 GtkStyle *previous_style)
4136 GtkTextView *text_view;
4137 GtkTextViewPrivate *priv;
4138 PangoContext *ltr_context, *rtl_context;
4140 text_view = GTK_TEXT_VIEW (widget);
4141 priv = text_view->priv;
4143 if (gtk_widget_get_realized (widget))
4145 gtk_text_view_set_background (text_view);
4148 if (priv->layout && previous_style)
4150 gtk_text_view_set_attributes_from_style (text_view,
4151 priv->layout->default_style,
4152 gtk_widget_get_style (widget));
4154 ltr_context = gtk_widget_create_pango_context (widget);
4155 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
4156 rtl_context = gtk_widget_create_pango_context (widget);
4157 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
4159 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
4161 g_object_unref (ltr_context);
4162 g_object_unref (rtl_context);
4167 gtk_text_view_direction_changed (GtkWidget *widget,
4168 GtkTextDirection previous_direction)
4170 GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
4174 priv->layout->default_style->direction = gtk_widget_get_direction (widget);
4176 gtk_text_layout_default_style_changed (priv->layout);
4181 gtk_text_view_state_changed (GtkWidget *widget,
4182 GtkStateType previous_state)
4184 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
4187 if (gtk_widget_get_realized (widget))
4189 gtk_text_view_set_background (text_view);
4191 if (gtk_widget_is_sensitive (widget))
4192 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4196 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4199 gdk_cursor_unref (cursor);
4201 text_view->priv->mouse_cursor_obscured = FALSE;
4204 if (!gtk_widget_is_sensitive (widget))
4206 /* Clear any selection */
4207 gtk_text_view_unselect (text_view);
4210 gtk_widget_queue_draw (widget);
4214 set_invisible_cursor (GdkWindow *window)
4216 GdkDisplay *display;
4219 display = gdk_drawable_get_display (window);
4220 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4222 gdk_window_set_cursor (window, cursor);
4224 gdk_cursor_unref (cursor);
4228 gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
4230 if (text_view->priv->mouse_cursor_obscured)
4233 set_invisible_cursor (text_view->priv->text_window->bin_window);
4235 text_view->priv->mouse_cursor_obscured = TRUE;
4239 gtk_text_view_unobscure_mouse_cursor (GtkTextView *text_view)
4241 if (text_view->priv->mouse_cursor_obscured)
4245 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)),
4247 gdk_window_set_cursor (text_view->priv->text_window->bin_window, cursor);
4248 gdk_cursor_unref (cursor);
4249 text_view->priv->mouse_cursor_obscured = FALSE;
4254 gtk_text_view_grab_notify (GtkWidget *widget,
4255 gboolean was_grabbed)
4257 GtkTextViewPrivate *priv;
4259 priv = GTK_TEXT_VIEW (widget)->priv;
4261 if (priv->grab_device &&
4262 gtk_widget_device_is_shadowed (widget, priv->grab_device))
4264 gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget));
4265 gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
4275 get_event_coordinates (GdkEvent *event, gint *x, gint *y)
4278 switch (event->type)
4280 case GDK_MOTION_NOTIFY:
4281 *x = event->motion.x;
4282 *y = event->motion.y;
4286 case GDK_BUTTON_PRESS:
4287 case GDK_2BUTTON_PRESS:
4288 case GDK_3BUTTON_PRESS:
4289 case GDK_BUTTON_RELEASE:
4290 *x = event->button.x;
4291 *y = event->button.y;
4296 case GDK_KEY_RELEASE:
4297 case GDK_ENTER_NOTIFY:
4298 case GDK_LEAVE_NOTIFY:
4299 case GDK_PROPERTY_NOTIFY:
4300 case GDK_SELECTION_CLEAR:
4301 case GDK_SELECTION_REQUEST:
4302 case GDK_SELECTION_NOTIFY:
4303 case GDK_PROXIMITY_IN:
4304 case GDK_PROXIMITY_OUT:
4305 case GDK_DRAG_ENTER:
4306 case GDK_DRAG_LEAVE:
4307 case GDK_DRAG_MOTION:
4308 case GDK_DRAG_STATUS:
4309 case GDK_DROP_START:
4310 case GDK_DROP_FINISHED:
4320 emit_event_on_tags (GtkWidget *widget,
4326 gboolean retval = FALSE;
4328 tags = gtk_text_iter_get_tags (iter);
4333 GtkTextTag *tag = tmp->data;
4335 if (gtk_text_tag_event (tag, G_OBJECT (widget), event, iter))
4341 tmp = g_slist_next (tmp);
4344 g_slist_free (tags);
4350 gtk_text_view_event (GtkWidget *widget, GdkEvent *event)
4352 GtkTextView *text_view;
4353 GtkTextViewPrivate *priv;
4356 text_view = GTK_TEXT_VIEW (widget);
4357 priv = text_view->priv;
4359 if (priv->layout == NULL ||
4360 get_buffer (text_view) == NULL)
4363 if (event->any.window != priv->text_window->bin_window)
4366 if (get_event_coordinates (event, &x, &y))
4373 /* FIXME this is slow and we do it twice per event.
4374 * My favorite solution is to have GtkTextLayout cache
4375 * the last couple lookups.
4377 gtk_text_layout_get_iter_at_pixel (priv->layout,
4381 return emit_event_on_tags (widget, event, &iter);
4383 else if (event->type == GDK_KEY_PRESS ||
4384 event->type == GDK_KEY_RELEASE)
4388 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
4389 gtk_text_buffer_get_insert (get_buffer (text_view)));
4391 return emit_event_on_tags (widget, event, &iter);
4398 gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
4400 GtkTextView *text_view;
4401 GtkTextViewPrivate *priv;
4402 GtkTextMark *insert;
4404 gboolean can_insert;
4405 gboolean retval = FALSE;
4406 gboolean obscure = FALSE;
4408 text_view = GTK_TEXT_VIEW (widget);
4409 priv = text_view->priv;
4411 if (priv->layout == NULL ||
4412 get_buffer (text_view) == NULL)
4415 /* Make sure input method knows where it is */
4416 flush_update_im_spot_location (text_view);
4418 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4419 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4420 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
4421 if (gtk_im_context_filter_keypress (priv->im_context, event))
4423 priv->need_im_reset = TRUE;
4425 gtk_text_view_reset_im_context (text_view);
4426 obscure = can_insert;
4430 else if (GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_press_event (widget, event))
4434 /* use overall editability not can_insert, more predictable for users */
4435 else if (priv->editable &&
4436 (event->keyval == GDK_KEY_Return ||
4437 event->keyval == GDK_KEY_ISO_Enter ||
4438 event->keyval == GDK_KEY_KP_Enter))
4440 /* this won't actually insert the newline if the cursor isn't
4443 gtk_text_view_reset_im_context (text_view);
4444 gtk_text_view_commit_text (text_view, "\n");
4449 /* Pass through Tab as literal tab, unless Control is held down */
4450 else if ((event->keyval == GDK_KEY_Tab ||
4451 event->keyval == GDK_KEY_KP_Tab ||
4452 event->keyval == GDK_KEY_ISO_Left_Tab) &&
4453 !(event->state & GDK_CONTROL_MASK))
4455 /* If the text widget isn't editable overall, or if the application
4456 * has turned off "accepts_tab", move the focus instead
4458 if (priv->accepts_tab && priv->editable)
4460 gtk_text_view_reset_im_context (text_view);
4461 gtk_text_view_commit_text (text_view, "\t");
4465 g_signal_emit_by_name (text_view, "move-focus",
4466 (event->state & GDK_SHIFT_MASK) ?
4467 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
4475 gtk_text_view_obscure_mouse_cursor (text_view);
4477 gtk_text_view_reset_blink_time (text_view);
4478 gtk_text_view_pend_cursor_blink (text_view);
4484 gtk_text_view_key_release_event (GtkWidget *widget, GdkEventKey *event)
4486 GtkTextView *text_view;
4487 GtkTextViewPrivate *priv;
4488 GtkTextMark *insert;
4491 text_view = GTK_TEXT_VIEW (widget);
4492 priv = text_view->priv;
4494 if (priv->layout == NULL || get_buffer (text_view) == NULL)
4497 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
4498 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
4499 if (gtk_text_iter_can_insert (&iter, priv->editable) &&
4500 gtk_im_context_filter_keypress (priv->im_context, event))
4502 priv->need_im_reset = TRUE;
4506 return GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_release_event (widget, event);
4510 gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
4512 GtkTextView *text_view;
4513 GtkTextViewPrivate *priv;
4515 text_view = GTK_TEXT_VIEW (widget);
4516 priv = text_view->priv;
4518 gtk_widget_grab_focus (widget);
4520 if (event->window != priv->text_window->bin_window)
4522 /* Remove selection if any. */
4523 gtk_text_view_unselect (text_view);
4527 gtk_text_view_reset_blink_time (text_view);
4531 if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
4532 _gtk_text_buffer_spew (GTK_TEXT_VIEW (widget)->buffer);
4533 else if (event->button == 3)
4534 gtk_text_layout_spew (GTK_TEXT_VIEW (widget)->layout);
4537 if (event->type == GDK_BUTTON_PRESS)
4539 gtk_text_view_reset_im_context (text_view);
4541 if (event->button == 1)
4543 /* If we're in the selection, start a drag copy/move of the
4544 * selection; otherwise, start creating a new selection.
4547 GtkTextIter start, end;
4549 gtk_text_layout_get_iter_at_pixel (priv->layout,
4551 event->x + priv->xoffset,
4552 event->y + priv->yoffset);
4554 if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
4556 gtk_text_iter_in_range (&iter, &start, &end) &&
4557 !(event->state & GDK_SHIFT_MASK))
4559 priv->drag_start_x = event->x;
4560 priv->drag_start_y = event->y;
4561 priv->pending_place_cursor_button = event->button;
4565 gtk_text_view_start_selection_drag (text_view, &iter, event);
4570 else if (event->button == 2)
4574 /* We do not want to scroll back to the insert iter when we paste
4575 with the middle button */
4576 priv->scroll_after_paste = FALSE;
4578 gtk_text_layout_get_iter_at_pixel (priv->layout,
4580 event->x + priv->xoffset,
4581 event->y + priv->yoffset);
4583 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
4584 gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY),
4589 else if (event->button == 3)
4591 gtk_text_view_do_popup (text_view, event);
4595 else if ((event->type == GDK_2BUTTON_PRESS ||
4596 event->type == GDK_3BUTTON_PRESS) &&
4601 gtk_text_view_end_selection_drag (text_view);
4603 gtk_text_layout_get_iter_at_pixel (priv->layout,
4605 event->x + priv->xoffset,
4606 event->y + priv->yoffset);
4608 gtk_text_view_start_selection_drag (text_view, &iter, event);
4616 gtk_text_view_button_release_event (GtkWidget *widget, GdkEventButton *event)
4618 GtkTextView *text_view;
4619 GtkTextViewPrivate *priv;
4621 text_view = GTK_TEXT_VIEW (widget);
4622 priv = text_view->priv;
4624 if (event->window != priv->text_window->bin_window)
4627 if (event->button == 1)
4629 if (priv->drag_start_x >= 0)
4631 priv->drag_start_x = -1;
4632 priv->drag_start_y = -1;
4635 if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget)))
4637 else if (priv->pending_place_cursor_button == event->button)
4641 /* Unselect everything; we clicked inside selection, but
4642 * didn't move by the drag threshold, so just clear selection
4645 gtk_text_layout_get_iter_at_pixel (priv->layout,
4647 event->x + priv->xoffset,
4648 event->y + priv->yoffset);
4650 gtk_text_buffer_place_cursor (get_buffer (text_view), &iter);
4651 gtk_text_view_check_cursor_blink (text_view);
4653 priv->pending_place_cursor_button = 0;
4663 keymap_direction_changed (GdkKeymap *keymap,
4664 GtkTextView *text_view)
4666 gtk_text_view_check_keymap_direction (text_view);
4670 gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
4672 GtkTextView *text_view;
4673 GtkTextViewPrivate *priv;
4675 text_view = GTK_TEXT_VIEW (widget);
4676 priv = text_view->priv;
4678 gtk_widget_queue_draw (widget);
4680 DV(g_print (G_STRLOC": focus_in_event\n"));
4682 gtk_text_view_reset_blink_time (text_view);
4684 if (priv->cursor_visible && priv->layout)
4686 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
4687 gtk_text_view_check_cursor_blink (text_view);
4690 g_signal_connect (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4691 "direction-changed",
4692 G_CALLBACK (keymap_direction_changed), text_view);
4693 gtk_text_view_check_keymap_direction (text_view);
4697 priv->need_im_reset = TRUE;
4698 gtk_im_context_focus_in (priv->im_context);
4705 gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
4707 GtkTextView *text_view;
4708 GtkTextViewPrivate *priv;
4710 text_view = GTK_TEXT_VIEW (widget);
4711 priv = text_view->priv;
4713 gtk_text_view_end_selection_drag (text_view);
4715 gtk_widget_queue_draw (widget);
4717 DV(g_print (G_STRLOC": focus_out_event\n"));
4719 if (priv->cursor_visible && priv->layout)
4721 gtk_text_view_check_cursor_blink (text_view);
4722 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
4725 g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
4726 keymap_direction_changed,
4731 priv->need_im_reset = TRUE;
4732 gtk_im_context_focus_out (priv->im_context);
4739 gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
4741 GtkTextView *text_view;
4742 GtkTextViewPrivate *priv;
4744 text_view = GTK_TEXT_VIEW (widget);
4745 priv = text_view->priv;
4747 gtk_text_view_unobscure_mouse_cursor (text_view);
4749 if (event->window == priv->text_window->bin_window &&
4750 priv->drag_start_x >= 0)
4755 gdk_event_request_motions (event);
4757 if (gtk_drag_check_threshold (widget,
4763 gint buffer_x, buffer_y;
4765 gtk_text_view_window_to_buffer_coords (text_view,
4766 GTK_TEXT_WINDOW_TEXT,
4772 gtk_text_layout_get_iter_at_pixel (priv->layout,
4774 buffer_x, buffer_y);
4776 gtk_text_view_start_selection_dnd (text_view, &iter, event);
4785 gtk_text_view_paint (GtkWidget *widget,
4787 GdkEventExpose *event)
4789 GtkTextView *text_view;
4790 GtkTextViewPrivate *priv;
4791 GList *child_exposes;
4794 text_view = GTK_TEXT_VIEW (widget);
4795 priv = text_view->priv;
4797 g_return_if_fail (priv->layout != NULL);
4798 g_return_if_fail (priv->xoffset >= 0);
4799 g_return_if_fail (priv->yoffset >= 0);
4801 while (priv->first_validate_idle != 0)
4803 DV (g_print (G_STRLOC": first_validate_idle: %d\n",
4804 priv->first_validate_idle));
4805 gtk_text_view_flush_first_validate (text_view);
4808 if (!priv->onscreen_validated)
4810 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.");
4811 g_assert_not_reached ();
4815 printf ("painting %d,%d %d x %d\n",
4817 area->width, area->height);
4820 child_exposes = NULL;
4821 gtk_text_layout_draw (priv->layout,
4823 priv->text_window->bin_window,
4828 area->width, area->height,
4831 tmp_list = child_exposes;
4832 while (tmp_list != NULL)
4834 GtkWidget *child = tmp_list->data;
4836 gtk_container_propagate_expose (GTK_CONTAINER (text_view),
4840 g_object_unref (child);
4842 tmp_list = tmp_list->next;
4845 g_list_free (child_exposes);
4849 gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
4853 if (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
4854 GTK_TEXT_WINDOW_TEXT))
4856 DV(g_print (">Exposed ("G_STRLOC")\n"));
4857 gtk_text_view_paint (widget, &event->area, event);
4860 if (event->window == gtk_widget_get_window (widget))
4861 gtk_text_view_draw_focus (widget);
4863 /* Propagate exposes to all unanchored children.
4864 * Anchored children are handled in gtk_text_view_paint().
4866 tmp_list = GTK_TEXT_VIEW (widget)->priv->children;
4867 while (tmp_list != NULL)
4869 GtkTextViewChild *vc = tmp_list->data;
4871 /* propagate_expose checks that event->window matches
4875 gtk_container_propagate_expose (GTK_CONTAINER (widget),
4879 tmp_list = tmp_list->next;
4886 gtk_text_view_draw_focus (GtkWidget *widget)
4888 GtkAllocation allocation;
4890 gboolean interior_focus;
4892 /* We clear the focus if we are in interior focus mode. */
4893 gtk_widget_style_get (widget,
4894 "interior-focus", &interior_focus,
4897 if (gtk_widget_is_drawable (widget))
4899 window = gtk_widget_get_window (widget);
4901 if (gtk_widget_has_focus (widget) && !interior_focus)
4903 gtk_widget_get_allocation (widget, &allocation);
4904 gtk_paint_focus (gtk_widget_get_style (widget),
4906 gtk_widget_get_state (widget),
4907 NULL, widget, "textview",
4909 allocation.width, allocation.height);
4913 gdk_window_clear (window);
4919 gtk_text_view_focus (GtkWidget *widget,
4920 GtkDirectionType direction)
4922 GtkContainer *container;
4925 container = GTK_CONTAINER (widget);
4927 if (!gtk_widget_is_focus (widget) &&
4928 gtk_container_get_focus_child (container) == NULL)
4930 gtk_widget_grab_focus (widget);
4936 * Unset CAN_FOCUS flag so that gtk_container_focus() allows
4937 * children to get the focus
4939 gtk_widget_set_can_focus (widget, FALSE);
4940 result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
4941 gtk_widget_set_can_focus (widget, TRUE);
4948 gtk_text_view_move_focus (GtkWidget *widget,
4949 GtkDirectionType direction_type)
4951 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
4953 if (GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus)
4954 GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus (text_view,
4963 gtk_text_view_add (GtkContainer *container,
4966 /* This is pretty random. */
4967 gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container),
4969 GTK_TEXT_WINDOW_WIDGET,
4974 gtk_text_view_remove (GtkContainer *container,
4977 GtkTextView *text_view;
4978 GtkTextViewPrivate *priv;
4979 GtkTextViewChild *vc;
4982 text_view = GTK_TEXT_VIEW (container);
4983 priv = text_view->priv;
4986 iter = priv->children;
4988 while (iter != NULL)
4992 if (vc->widget == child)
4995 iter = g_slist_next (iter);
4998 g_assert (iter != NULL); /* be sure we had the child in the list */
5000 priv->children = g_slist_remove (priv->children, vc);
5002 gtk_widget_unparent (vc->widget);
5004 text_view_child_free (vc);
5008 gtk_text_view_forall (GtkContainer *container,
5009 gboolean include_internals,
5010 GtkCallback callback,
5011 gpointer callback_data)
5014 GtkTextView *text_view;
5017 g_return_if_fail (GTK_IS_TEXT_VIEW (container));
5018 g_return_if_fail (callback != NULL);
5020 text_view = GTK_TEXT_VIEW (container);
5022 copy = g_slist_copy (text_view->priv->children);
5025 while (iter != NULL)
5027 GtkTextViewChild *vc = iter->data;
5029 (* callback) (vc->widget, callback_data);
5031 iter = g_slist_next (iter);
5034 g_slist_free (copy);
5037 #define CURSOR_ON_MULTIPLIER 2
5038 #define CURSOR_OFF_MULTIPLIER 1
5039 #define CURSOR_PEND_MULTIPLIER 3
5040 #define CURSOR_DIVIDER 3
5043 cursor_blinks (GtkTextView *text_view)
5045 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5048 #ifdef DEBUG_VALIDATION_AND_SCROLLING
5051 if (gtk_get_debug_flags () & GTK_DEBUG_UPDATES)
5054 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
5059 if (text_view->priv->editable)
5061 GtkTextMark *insert;
5064 insert = gtk_text_buffer_get_insert (get_buffer (text_view));
5065 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
5067 if (gtk_text_iter_editable (&iter, text_view->priv->editable))
5075 get_cursor_time (GtkTextView *text_view)
5077 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5080 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
5086 get_cursor_blink_timeout (GtkTextView *text_view)
5088 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
5091 g_object_get (settings, "gtk-cursor-blink-timeout", &time, NULL);
5102 blink_cb (gpointer data)
5104 GtkTextView *text_view;
5105 GtkTextViewPrivate *priv;
5109 text_view = GTK_TEXT_VIEW (data);
5110 priv = text_view->priv;
5112 if (!gtk_widget_has_focus (GTK_WIDGET (text_view)))
5114 g_warning ("GtkTextView - did not receive focus-out-event. If you\n"
5115 "connect a handler to this signal, it must return\n"
5116 "FALSE so the text view gets the event as well");
5118 gtk_text_view_check_cursor_blink (text_view);
5123 g_assert (priv->layout);
5124 g_assert (priv->cursor_visible);
5126 visible = gtk_text_layout_get_cursor_visible (priv->layout);
5128 blink_timeout = get_cursor_blink_timeout (text_view);
5129 if (priv->blink_time > 1000 * blink_timeout &&
5130 blink_timeout < G_MAXINT/1000)
5132 /* we've blinked enough without the user doing anything, stop blinking */
5134 priv->blink_timeout = 0;
5137 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5142 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
5145 priv->blink_time += get_cursor_time (text_view);
5148 /* Block changed_handler while changing the layout's cursor visibility
5149 * because it would expose the whole paragraph. Instead, we expose
5150 * the cursor's area(s) manually below.
5152 g_signal_handlers_block_by_func (priv->layout,
5155 gtk_text_layout_set_cursor_visible (priv->layout, !visible);
5156 g_signal_handlers_unblock_by_func (priv->layout,
5160 text_window_invalidate_cursors (priv->text_window);
5162 /* Remove ourselves */
5168 gtk_text_view_stop_cursor_blink (GtkTextView *text_view)
5170 if (text_view->priv->blink_timeout)
5172 g_source_remove (text_view->priv->blink_timeout);
5173 text_view->priv->blink_timeout = 0;
5178 gtk_text_view_check_cursor_blink (GtkTextView *text_view)
5180 GtkTextViewPrivate *priv = text_view->priv;
5182 if (priv->layout != NULL &&
5183 priv->cursor_visible &&
5184 gtk_widget_has_focus (GTK_WIDGET (text_view)))
5186 if (cursor_blinks (text_view))
5188 if (priv->blink_timeout == 0)
5190 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5192 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
5199 gtk_text_view_stop_cursor_blink (text_view);
5200 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5205 gtk_text_view_stop_cursor_blink (text_view);
5206 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
5211 gtk_text_view_pend_cursor_blink (GtkTextView *text_view)
5213 GtkTextViewPrivate *priv = text_view->priv;
5215 if (priv->layout != NULL &&
5216 priv->cursor_visible &&
5217 gtk_widget_has_focus (GTK_WIDGET (text_view)) &&
5218 cursor_blinks (text_view))
5220 gtk_text_view_stop_cursor_blink (text_view);
5221 gtk_text_layout_set_cursor_visible (priv->layout, TRUE);
5223 priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
5230 gtk_text_view_reset_blink_time (GtkTextView *text_view)
5232 GtkTextViewPrivate *priv = text_view->priv;
5234 priv->blink_time = 0;
5239 * Key binding handlers
5243 gtk_text_view_move_iter_by_lines (GtkTextView *text_view,
5244 GtkTextIter *newplace,
5247 gboolean ret = TRUE;
5251 ret = gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, newplace);
5257 ret = gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, newplace);
5265 move_cursor (GtkTextView *text_view,
5266 const GtkTextIter *new_location,
5267 gboolean extend_selection)
5269 if (extend_selection)
5270 gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
5274 gtk_text_buffer_place_cursor (get_buffer (text_view),
5276 gtk_text_view_check_cursor_blink (text_view);
5280 gtk_text_view_move_cursor_internal (GtkTextView *text_view,
5281 GtkMovementStep step,
5283 gboolean extend_selection)
5285 GtkTextViewPrivate *priv;
5287 GtkTextIter newplace;
5288 gboolean cancel_selection = FALSE;
5289 gint cursor_x_pos = 0;
5290 GtkDirectionType leave_direction = -1;
5292 priv = text_view->priv;
5294 if (!priv->cursor_visible)
5296 GtkScrollStep scroll_step;
5300 case GTK_MOVEMENT_VISUAL_POSITIONS:
5301 leave_direction = count > 0 ? GTK_DIR_RIGHT : GTK_DIR_LEFT;
5303 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5304 case GTK_MOVEMENT_WORDS:
5305 scroll_step = GTK_SCROLL_HORIZONTAL_STEPS;
5307 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5308 scroll_step = GTK_SCROLL_HORIZONTAL_ENDS;
5310 case GTK_MOVEMENT_DISPLAY_LINES:
5311 leave_direction = count > 0 ? GTK_DIR_DOWN : GTK_DIR_UP;
5313 case GTK_MOVEMENT_PARAGRAPHS:
5314 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5315 scroll_step = GTK_SCROLL_STEPS;
5317 case GTK_MOVEMENT_PAGES:
5318 scroll_step = GTK_SCROLL_PAGES;
5320 case GTK_MOVEMENT_HORIZONTAL_PAGES:
5321 scroll_step = GTK_SCROLL_HORIZONTAL_PAGES;
5323 case GTK_MOVEMENT_BUFFER_ENDS:
5324 scroll_step = GTK_SCROLL_ENDS;
5327 scroll_step = GTK_SCROLL_PAGES;
5331 if (!gtk_text_view_move_viewport (text_view, scroll_step, count))
5333 if (leave_direction != -1 &&
5334 !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5337 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5344 gtk_text_view_reset_im_context (text_view);
5346 if (step == GTK_MOVEMENT_PAGES)
5348 if (!gtk_text_view_scroll_pages (text_view, count, extend_selection))
5349 gtk_widget_error_bell (GTK_WIDGET (text_view));
5351 gtk_text_view_check_cursor_blink (text_view);
5352 gtk_text_view_pend_cursor_blink (text_view);
5355 else if (step == GTK_MOVEMENT_HORIZONTAL_PAGES)
5357 if (!gtk_text_view_scroll_hpages (text_view, count, extend_selection))
5358 gtk_widget_error_bell (GTK_WIDGET (text_view));
5360 gtk_text_view_check_cursor_blink (text_view);
5361 gtk_text_view_pend_cursor_blink (text_view);
5365 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5366 gtk_text_buffer_get_insert (get_buffer (text_view)));
5368 if (! extend_selection)
5370 GtkTextIter sel_bound;
5372 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
5373 gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
5375 /* if we move forward, assume the cursor is at the end of the selection;
5376 * if we move backward, assume the cursor is at the start
5379 gtk_text_iter_order (&sel_bound, &insert);
5381 gtk_text_iter_order (&insert, &sel_bound);
5383 /* if we actually have a selection, just move *to* the beginning/end
5384 * of the selection and not *from* there on LOGICAL_POSITIONS
5385 * and VISUAL_POSITIONS movement
5387 if (! gtk_text_iter_equal (&sel_bound, &insert))
5388 cancel_selection = TRUE;
5393 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5394 gtk_text_view_get_virtual_cursor_pos (text_view, &insert, &cursor_x_pos, NULL);
5398 case GTK_MOVEMENT_LOGICAL_POSITIONS:
5399 if (! cancel_selection)
5400 gtk_text_iter_forward_visible_cursor_positions (&newplace, count);
5403 case GTK_MOVEMENT_VISUAL_POSITIONS:
5404 if (! cancel_selection)
5405 gtk_text_layout_move_iter_visually (priv->layout,
5409 case GTK_MOVEMENT_WORDS:
5411 gtk_text_iter_backward_visible_word_starts (&newplace, -count);
5414 if (!gtk_text_iter_forward_visible_word_ends (&newplace, count))
5415 gtk_text_iter_forward_to_line_end (&newplace);
5419 case GTK_MOVEMENT_DISPLAY_LINES:
5422 leave_direction = GTK_DIR_UP;
5424 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5425 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5427 gtk_text_iter_set_line_offset (&newplace, 0);
5431 leave_direction = GTK_DIR_DOWN;
5433 if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
5434 gtk_text_layout_move_iter_to_x (priv->layout, &newplace, cursor_x_pos);
5436 gtk_text_iter_forward_to_line_end (&newplace);
5440 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
5442 gtk_text_view_move_iter_by_lines (text_view, &newplace, --count);
5443 else if (count < -1)
5444 gtk_text_view_move_iter_by_lines (text_view, &newplace, ++count);
5447 gtk_text_layout_move_iter_to_line_end (priv->layout, &newplace, count);
5450 case GTK_MOVEMENT_PARAGRAPHS:
5453 if (!gtk_text_iter_ends_line (&newplace))
5455 gtk_text_iter_forward_to_line_end (&newplace);
5458 gtk_text_iter_forward_visible_lines (&newplace, count);
5459 gtk_text_iter_forward_to_line_end (&newplace);
5463 if (gtk_text_iter_get_line_offset (&newplace) > 0)
5464 gtk_text_iter_set_line_offset (&newplace, 0);
5465 gtk_text_iter_forward_visible_lines (&newplace, count);
5466 gtk_text_iter_set_line_offset (&newplace, 0);
5470 case GTK_MOVEMENT_PARAGRAPH_ENDS:
5473 if (!gtk_text_iter_ends_line (&newplace))
5474 gtk_text_iter_forward_to_line_end (&newplace);
5478 gtk_text_iter_set_line_offset (&newplace, 0);
5482 case GTK_MOVEMENT_BUFFER_ENDS:
5484 gtk_text_buffer_get_end_iter (get_buffer (text_view), &newplace);
5486 gtk_text_buffer_get_iter_at_offset (get_buffer (text_view), &newplace, 0);
5493 /* call move_cursor() even if the cursor hasn't moved, since it
5494 cancels the selection
5496 move_cursor (text_view, &newplace, extend_selection);
5498 if (!gtk_text_iter_equal (&insert, &newplace))
5500 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5501 gtk_text_view_scroll_mark_onscreen (text_view,
5502 gtk_text_buffer_get_insert (get_buffer (text_view)));
5504 if (step == GTK_MOVEMENT_DISPLAY_LINES)
5505 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, -1);
5507 else if (leave_direction != -1)
5509 if (!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
5512 g_signal_emit_by_name (text_view, "move-focus", leave_direction);
5515 else if (! cancel_selection)
5517 gtk_widget_error_bell (GTK_WIDGET (text_view));
5520 gtk_text_view_check_cursor_blink (text_view);
5521 gtk_text_view_pend_cursor_blink (text_view);
5525 gtk_text_view_move_cursor (GtkTextView *text_view,
5526 GtkMovementStep step,
5528 gboolean extend_selection)
5530 gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
5534 gtk_text_view_move_viewport (GtkTextView *text_view,
5538 GtkAdjustment *adjustment;
5543 case GTK_SCROLL_STEPS:
5544 case GTK_SCROLL_PAGES:
5545 case GTK_SCROLL_ENDS:
5546 adjustment = get_vadjustment (text_view);
5548 case GTK_SCROLL_HORIZONTAL_STEPS:
5549 case GTK_SCROLL_HORIZONTAL_PAGES:
5550 case GTK_SCROLL_HORIZONTAL_ENDS:
5551 adjustment = get_hadjustment (text_view);
5554 adjustment = get_vadjustment (text_view);
5560 case GTK_SCROLL_STEPS:
5561 case GTK_SCROLL_HORIZONTAL_STEPS:
5562 increment = adjustment->step_increment;
5564 case GTK_SCROLL_PAGES:
5565 case GTK_SCROLL_HORIZONTAL_PAGES:
5566 increment = adjustment->page_increment;
5568 case GTK_SCROLL_ENDS:
5569 case GTK_SCROLL_HORIZONTAL_ENDS:
5570 increment = adjustment->upper - adjustment->lower;
5577 return set_adjustment_clamped (adjustment, adjustment->value + count * increment);
5581 gtk_text_view_set_anchor (GtkTextView *text_view)
5585 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5586 gtk_text_buffer_get_insert (get_buffer (text_view)));
5588 gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
5592 gtk_text_view_scroll_pages (GtkTextView *text_view,
5594 gboolean extend_selection)
5596 GtkTextViewPrivate *priv;
5598 gint cursor_x_pos, cursor_y_pos;
5599 GtkTextMark *insert_mark;
5600 GtkTextIter old_insert;
5601 GtkTextIter new_insert;
5607 priv = text_view->priv;
5609 g_return_val_if_fail (priv->vadjustment != NULL, FALSE);
5611 adj = priv->vadjustment;
5613 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5615 /* Make sure we start from the current cursor position, even
5616 * if it was offscreen, but don't queue more scrolls if we're
5619 if (priv->pending_scroll)
5620 cancel_pending_scroll (text_view);
5622 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5624 /* Validate the region that will be brought into view by the cursor motion
5626 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5627 &old_insert, insert_mark);
5631 gtk_text_view_get_first_para_iter (text_view, &anchor);
5632 y0 = adj->page_size;
5633 y1 = adj->page_size + count * adj->page_increment;
5637 gtk_text_view_get_first_para_iter (text_view, &anchor);
5638 y0 = count * adj->page_increment + adj->page_size;
5642 gtk_text_layout_validate_yrange (priv->layout, &anchor, y0, y1);
5643 /* FIXME do we need to update the adjustment ranges here? */
5645 new_insert = old_insert;
5647 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5649 /* already at top, just be sure we are at offset 0 */
5650 gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
5651 move_cursor (text_view, &new_insert, extend_selection);
5653 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5655 /* already at bottom, just be sure we are at the end */
5656 gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
5657 move_cursor (text_view, &new_insert, extend_selection);
5661 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5663 oldval = adj->value;
5664 newval = adj->value;
5666 newval += count * adj->page_increment;
5668 set_adjustment_clamped (adj, newval);
5669 cursor_y_pos += adj->value - oldval;
5671 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5672 clamp_iter_onscreen (text_view, &new_insert);
5673 move_cursor (text_view, &new_insert, extend_selection);
5675 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5678 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5679 * only guarantees 1 pixel onscreen.
5681 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5682 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5684 return !gtk_text_iter_equal (&old_insert, &new_insert);
5688 gtk_text_view_scroll_hpages (GtkTextView *text_view,
5690 gboolean extend_selection)
5692 GtkTextViewPrivate *priv;
5694 gint cursor_x_pos, cursor_y_pos;
5695 GtkTextMark *insert_mark;
5696 GtkTextIter old_insert;
5697 GtkTextIter new_insert;
5702 priv = text_view->priv;
5704 g_return_val_if_fail (priv->hadjustment != NULL, FALSE);
5706 adj = priv->hadjustment;
5708 insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
5710 /* Make sure we start from the current cursor position, even
5711 * if it was offscreen, but don't queue more scrolls if we're
5714 if (priv->pending_scroll)
5715 cancel_pending_scroll (text_view);
5717 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5719 /* Validate the line that we're moving within.
5721 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5722 &old_insert, insert_mark);
5724 gtk_text_layout_get_line_yrange (priv->layout, &old_insert, &y, &height);
5725 gtk_text_layout_validate_yrange (priv->layout, &old_insert, y, y + height);
5726 /* FIXME do we need to update the adjustment ranges here? */
5728 new_insert = old_insert;
5730 if (count < 0 && adj->value <= (adj->lower + 1e-12))
5732 /* already at far left, just be sure we are at offset 0 */
5733 gtk_text_iter_set_line_offset (&new_insert, 0);
5734 move_cursor (text_view, &new_insert, extend_selection);
5736 else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
5738 /* already at far right, just be sure we are at the end */
5739 if (!gtk_text_iter_ends_line (&new_insert))
5740 gtk_text_iter_forward_to_line_end (&new_insert);
5741 move_cursor (text_view, &new_insert, extend_selection);
5745 gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
5747 oldval = adj->value;
5748 newval = adj->value;
5750 newval += count * adj->page_increment;
5752 set_adjustment_clamped (adj, newval);
5753 cursor_x_pos += adj->value - oldval;
5755 gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
5756 clamp_iter_onscreen (text_view, &new_insert);
5757 move_cursor (text_view, &new_insert, extend_selection);
5759 gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
5762 /* FIXME for lines shorter than the overall widget width, this results in a
5763 * "bounce" effect as we scroll to the right of the widget, then scroll
5764 * back to get the end of the line onscreen.
5765 * http://bugzilla.gnome.org/show_bug.cgi?id=68963
5768 /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
5769 * only guarantees 1 pixel onscreen.
5771 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5772 gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
5774 return !gtk_text_iter_equal (&old_insert, &new_insert);
5778 whitespace (gunichar ch, gpointer user_data)
5780 return (ch == ' ' || ch == '\t');
5784 not_whitespace (gunichar ch, gpointer user_data)
5786 return !whitespace (ch, user_data);
5790 find_whitepace_region (const GtkTextIter *center,
5791 GtkTextIter *start, GtkTextIter *end)
5796 if (gtk_text_iter_backward_find_char (start, not_whitespace, NULL, NULL))
5797 gtk_text_iter_forward_char (start); /* we want the first whitespace... */
5798 if (whitespace (gtk_text_iter_get_char (end), NULL))
5799 gtk_text_iter_forward_find_char (end, not_whitespace, NULL, NULL);
5801 return !gtk_text_iter_equal (start, end);
5805 gtk_text_view_insert_at_cursor (GtkTextView *text_view,
5808 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
5809 text_view->priv->editable))
5811 gtk_widget_error_bell (GTK_WIDGET (text_view));
5816 gtk_text_view_delete_from_cursor (GtkTextView *text_view,
5820 GtkTextViewPrivate *priv;
5824 gboolean leave_one = FALSE;
5826 priv = text_view->priv;
5828 gtk_text_view_reset_im_context (text_view);
5830 if (type == GTK_DELETE_CHARS)
5832 /* Char delete deletes the selection, if one exists */
5833 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5838 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
5839 gtk_text_buffer_get_insert (get_buffer (text_view)));
5846 case GTK_DELETE_CHARS:
5847 gtk_text_iter_forward_cursor_positions (&end, count);
5850 case GTK_DELETE_WORD_ENDS:
5852 gtk_text_iter_forward_word_ends (&end, count);
5854 gtk_text_iter_backward_word_starts (&start, 0 - count);
5857 case GTK_DELETE_WORDS:
5860 case GTK_DELETE_DISPLAY_LINE_ENDS:
5863 case GTK_DELETE_DISPLAY_LINES:
5866 case GTK_DELETE_PARAGRAPH_ENDS:
5869 /* If we're already at a newline, we need to
5870 * simply delete that newline, instead of
5871 * moving to the next one.
5873 if (gtk_text_iter_ends_line (&end))
5875 gtk_text_iter_forward_line (&end);
5881 if (!gtk_text_iter_forward_to_line_end (&end))
5889 if (gtk_text_iter_starts_line (&start))
5891 gtk_text_iter_backward_line (&start);
5892 if (!gtk_text_iter_ends_line (&end))
5893 gtk_text_iter_forward_to_line_end (&start);
5897 gtk_text_iter_set_line_offset (&start, 0);
5901 gtk_text_iter_backward_lines (&start, -count);
5905 case GTK_DELETE_PARAGRAPHS:
5908 gtk_text_iter_set_line_offset (&start, 0);
5909 gtk_text_iter_forward_to_line_end (&end);
5911 /* Do the lines beyond the first. */
5914 gtk_text_iter_forward_to_line_end (&end);
5920 /* FIXME negative count? */
5924 case GTK_DELETE_WHITESPACE:
5926 find_whitepace_region (&insert, &start, &end);
5934 if (!gtk_text_iter_equal (&start, &end))
5936 gtk_text_buffer_begin_user_action (get_buffer (text_view));
5938 if (gtk_text_buffer_delete_interactive (get_buffer (text_view), &start, &end,
5942 gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view),
5948 gtk_widget_error_bell (GTK_WIDGET (text_view));
5951 gtk_text_buffer_end_user_action (get_buffer (text_view));
5952 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5954 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5955 gtk_text_view_scroll_mark_onscreen (text_view,
5956 gtk_text_buffer_get_insert (get_buffer (text_view)));
5960 gtk_widget_error_bell (GTK_WIDGET (text_view));
5965 gtk_text_view_backspace (GtkTextView *text_view)
5967 GtkTextViewPrivate *priv;
5970 priv = text_view->priv;
5972 gtk_text_view_reset_im_context (text_view);
5974 /* Backspace deletes the selection, if one exists */
5975 if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
5979 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
5981 gtk_text_buffer_get_insert (get_buffer (text_view)));
5983 if (gtk_text_buffer_backspace (get_buffer (text_view), &insert,
5984 TRUE, priv->editable))
5986 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
5987 DV(g_print (G_STRLOC": scrolling onscreen\n"));
5988 gtk_text_view_scroll_mark_onscreen (text_view,
5989 gtk_text_buffer_get_insert (get_buffer (text_view)));
5993 gtk_widget_error_bell (GTK_WIDGET (text_view));
5998 gtk_text_view_cut_clipboard (GtkTextView *text_view)
6000 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
6001 GDK_SELECTION_CLIPBOARD);
6003 gtk_text_buffer_cut_clipboard (get_buffer (text_view),
6005 text_view->priv->editable);
6006 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6007 gtk_text_view_scroll_mark_onscreen (text_view,
6008 gtk_text_buffer_get_insert (get_buffer (text_view)));
6012 gtk_text_view_copy_clipboard (GtkTextView *text_view)
6014 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
6015 GDK_SELECTION_CLIPBOARD);
6017 gtk_text_buffer_copy_clipboard (get_buffer (text_view),
6020 /* on copy do not scroll, we are already onscreen */
6024 gtk_text_view_paste_clipboard (GtkTextView *text_view)
6026 GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
6027 GDK_SELECTION_CLIPBOARD);
6029 gtk_text_buffer_paste_clipboard (get_buffer (text_view),
6032 text_view->priv->editable);
6036 gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
6037 GtkClipboard *clipboard,
6040 GtkTextView *text_view = data;
6041 GtkTextViewPrivate *priv;
6043 priv = text_view->priv;
6045 if (priv->scroll_after_paste)
6047 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6048 gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer));
6051 priv->scroll_after_paste = TRUE;
6055 gtk_text_view_toggle_overwrite (GtkTextView *text_view)
6057 GtkTextViewPrivate *priv = text_view->priv;
6059 if (priv->text_window)
6060 text_window_invalidate_cursors (priv->text_window);
6062 priv->overwrite_mode = !priv->overwrite_mode;
6065 gtk_text_layout_set_overwrite_mode (priv->layout,
6066 priv->overwrite_mode && priv->editable);
6068 if (priv->text_window)
6069 text_window_invalidate_cursors (priv->text_window);
6071 gtk_text_view_pend_cursor_blink (text_view);
6073 g_object_notify (G_OBJECT (text_view), "overwrite");
6077 * gtk_text_view_get_overwrite:
6078 * @text_view: a #GtkTextView
6080 * Returns whether the #GtkTextView is in overwrite mode or not.
6082 * Return value: whether @text_view is in overwrite mode or not.
6087 gtk_text_view_get_overwrite (GtkTextView *text_view)
6089 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6091 return text_view->priv->overwrite_mode;
6095 * gtk_text_view_set_overwrite:
6096 * @text_view: a #GtkTextView
6097 * @overwrite: %TRUE to turn on overwrite mode, %FALSE to turn it off
6099 * Changes the #GtkTextView overwrite mode.
6104 gtk_text_view_set_overwrite (GtkTextView *text_view,
6107 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6108 overwrite = overwrite != FALSE;
6110 if (text_view->priv->overwrite_mode != overwrite)
6111 gtk_text_view_toggle_overwrite (text_view);
6115 * gtk_text_view_set_accepts_tab:
6116 * @text_view: A #GtkTextView
6117 * @accepts_tab: %TRUE if pressing the Tab key should insert a tab
6118 * character, %FALSE, if pressing the Tab key should move the
6121 * Sets the behavior of the text widget when the Tab key is pressed.
6122 * If @accepts_tab is %TRUE, a tab character is inserted. If @accepts_tab
6123 * is %FALSE the keyboard focus is moved to the next widget in the focus
6129 gtk_text_view_set_accepts_tab (GtkTextView *text_view,
6130 gboolean accepts_tab)
6132 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6134 accepts_tab = accepts_tab != FALSE;
6136 if (text_view->priv->accepts_tab != accepts_tab)
6138 text_view->priv->accepts_tab = accepts_tab;
6140 g_object_notify (G_OBJECT (text_view), "accepts-tab");
6145 * gtk_text_view_get_accepts_tab:
6146 * @text_view: A #GtkTextView
6148 * Returns whether pressing the Tab key inserts a tab characters.
6149 * gtk_text_view_set_accepts_tab().
6151 * Return value: %TRUE if pressing the Tab key inserts a tab character,
6152 * %FALSE if pressing the Tab key moves the keyboard focus.
6157 gtk_text_view_get_accepts_tab (GtkTextView *text_view)
6159 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6161 return text_view->priv->accepts_tab;
6165 gtk_text_view_compat_move_focus (GtkTextView *text_view,
6166 GtkDirectionType direction_type)
6168 GSignalInvocationHint *hint = g_signal_get_invocation_hint (text_view);
6170 /* as of GTK+ 2.12, the "move-focus" signal has been moved to GtkWidget,
6171 * the evil code below makes sure that both emitting the signal and
6172 * calling the virtual function directly continue to work as expetcted
6175 if (hint->signal_id == g_signal_lookup ("move-focus", GTK_TYPE_WIDGET))
6177 /* if this is a signal emission, chain up */
6181 g_signal_chain_from_overridden_handler (text_view,
6182 direction_type, &retval);
6186 /* otherwise emit the signal, since somebody called the virtual
6190 g_signal_emit_by_name (text_view, "move-focus", direction_type);
6199 gtk_text_view_unselect (GtkTextView *text_view)
6203 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
6204 gtk_text_buffer_get_insert (get_buffer (text_view)));
6206 gtk_text_buffer_move_mark (get_buffer (text_view),
6207 gtk_text_buffer_get_selection_bound (get_buffer (text_view)),
6212 get_iter_at_pointer (GtkTextView *text_view,
6218 GtkTextViewPrivate *priv;
6219 gint xcoord, ycoord;
6220 GdkModifierType state;
6222 priv = text_view->priv;
6224 gdk_window_get_device_position (priv->text_window->bin_window,
6225 device, &xcoord, &ycoord, &state);
6227 gtk_text_layout_get_iter_at_pixel (priv->layout,
6229 xcoord + priv->xoffset,
6230 ycoord + priv->yoffset);
6239 move_mark_to_pointer_and_scroll (GtkTextView *text_view,
6240 const gchar *mark_name,
6243 GtkTextIter newplace;
6246 get_iter_at_pointer (text_view, device, &newplace, NULL, NULL);
6248 mark = gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
6250 /* This may invalidate the layout */
6251 DV(g_print (G_STRLOC": move mark\n"));
6253 gtk_text_buffer_move_mark (get_buffer (text_view),
6257 DV(g_print (G_STRLOC": scrolling onscreen\n"));
6258 gtk_text_view_scroll_mark_onscreen (text_view, mark);
6260 DV (g_print ("first validate idle leaving %s is %d\n",
6261 G_STRLOC, text_view->priv->first_validate_idle));
6265 selection_scan_timeout (gpointer data)
6267 GtkTextView *text_view;
6269 text_view = GTK_TEXT_VIEW (data);
6271 gtk_text_view_scroll_mark_onscreen (text_view,
6272 gtk_text_buffer_get_insert (get_buffer (text_view)));
6274 return TRUE; /* remain installed. */
6277 #define UPPER_OFFSET_ANCHOR 0.8
6278 #define LOWER_OFFSET_ANCHOR 0.2
6281 check_scroll (gdouble offset, GtkAdjustment *adj)
6283 if ((offset > UPPER_OFFSET_ANCHOR &&
6284 adj->value + adj->page_size < adj->upper) ||
6285 (offset < LOWER_OFFSET_ANCHOR &&
6286 adj->value > adj->lower))
6293 drag_scan_timeout (gpointer data)
6295 GtkTextView *text_view;
6296 GtkTextViewPrivate *priv;
6297 GtkTextIter newplace;
6298 gint x, y, width, height;
6299 gdouble pointer_xoffset, pointer_yoffset;
6301 text_view = GTK_TEXT_VIEW (data);
6302 priv = text_view->priv;
6304 get_iter_at_pointer (text_view, priv->dnd_device, &newplace, &x, &y);
6305 gdk_drawable_get_size (priv->text_window->bin_window, &width, &height);
6307 gtk_text_buffer_move_mark (get_buffer (text_view),
6311 pointer_xoffset = (gdouble) x / width;
6312 pointer_yoffset = (gdouble) y / height;
6314 if (check_scroll (pointer_xoffset, priv->hadjustment) ||
6315 check_scroll (pointer_yoffset, priv->vadjustment))
6317 /* do not make offsets surpass lower nor upper anchors, this makes
6318 * scrolling speed relative to the distance of the pointer to the
6319 * anchors when it moves beyond them.
6321 pointer_xoffset = CLAMP (pointer_xoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6322 pointer_yoffset = CLAMP (pointer_yoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
6324 gtk_text_view_scroll_to_mark (text_view,
6326 0., TRUE, pointer_xoffset, pointer_yoffset);
6337 } SelectionGranularity;
6340 * Move @start and @end to the boundaries of the selection unit (indicated by
6341 * @granularity) which contained @start initially.
6342 * If the selction unit is SELECT_WORDS and @start is not contained in a word
6343 * the selection is extended to all the white spaces between the end of the
6344 * word preceding @start and the start of the one following.
6347 extend_selection (GtkTextView *text_view,
6348 SelectionGranularity granularity,
6354 if (granularity == SELECT_WORDS)
6356 if (gtk_text_iter_inside_word (start))
6358 if (!gtk_text_iter_starts_word (start))
6359 gtk_text_iter_backward_visible_word_start (start);
6361 if (!gtk_text_iter_ends_word (end))
6363 if (!gtk_text_iter_forward_visible_word_end (end))
6364 gtk_text_iter_forward_to_end (end);
6372 if (gtk_text_iter_backward_visible_word_start (&tmp))
6373 gtk_text_iter_forward_visible_word_end (&tmp);
6375 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (start))
6378 gtk_text_iter_set_line_offset (start, 0);
6381 if (!gtk_text_iter_forward_visible_word_end (&tmp))
6382 gtk_text_iter_forward_to_end (&tmp);
6384 if (gtk_text_iter_ends_word (&tmp))
6385 gtk_text_iter_backward_visible_word_start (&tmp);
6387 if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (end))
6390 gtk_text_iter_forward_to_line_end (end);
6393 else if (granularity == SELECT_LINES)
6395 if (gtk_text_view_starts_display_line (text_view, start))
6397 /* If on a display line boundary, we assume the user
6398 * clicked off the end of a line and we therefore select
6399 * the line before the boundary.
6401 gtk_text_view_backward_display_line_start (text_view, start);
6405 /* start isn't on the start of a line, so we move it to the
6406 * start, and move end to the end unless it's already there.
6408 gtk_text_view_backward_display_line_start (text_view, start);
6410 if (!gtk_text_view_starts_display_line (text_view, end))
6411 gtk_text_view_forward_display_line_end (text_view, end);
6419 SelectionGranularity granularity;
6420 GtkTextMark *orig_start;
6421 GtkTextMark *orig_end;
6425 selection_data_free (SelectionData *data)
6427 if (data->orig_start != NULL)
6428 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start),
6430 if (data->orig_end != NULL)
6431 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end),
6437 selection_motion_event_handler (GtkTextView *text_view,
6438 GdkEventMotion *event,
6439 SelectionData *data)
6441 GtkTextViewPrivate *priv;
6443 priv = text_view->priv;
6444 gdk_event_request_motions (event);
6446 if (priv->grab_device != event->device)
6449 if (data->granularity == SELECT_CHARACTERS)
6451 move_mark_to_pointer_and_scroll (text_view, "insert", event->device);
6455 GtkTextIter cursor, start, end;
6456 GtkTextIter orig_start, orig_end;
6457 GtkTextBuffer *buffer;
6459 buffer = get_buffer (text_view);
6461 gtk_text_buffer_get_iter_at_mark (buffer, &orig_start, data->orig_start);
6462 gtk_text_buffer_get_iter_at_mark (buffer, &orig_end, data->orig_end);
6464 get_iter_at_pointer (text_view, event->device, &cursor, NULL, NULL);
6467 extend_selection (text_view, data->granularity, &start, &end);
6469 /* either the selection extends to the front, or end (or not) */
6470 if (gtk_text_iter_compare (&cursor, &orig_start) < 0)
6471 gtk_text_buffer_select_range (buffer, &start, &orig_end);
6473 gtk_text_buffer_select_range (buffer, &end, &orig_start);
6475 gtk_text_view_scroll_mark_onscreen (text_view,
6476 gtk_text_buffer_get_insert (buffer));
6479 /* If we had to scroll offscreen, insert a timeout to do so
6480 * again. Note that in the timeout, even if the mouse doesn't
6481 * move, due to this scroll xoffset/yoffset will have changed
6482 * and we'll need to scroll again.
6484 if (text_view->priv->scroll_timeout != 0) /* reset on every motion event */
6485 g_source_remove (text_view->priv->scroll_timeout);
6487 text_view->priv->scroll_timeout =
6488 gdk_threads_add_timeout (50, selection_scan_timeout, text_view);
6494 gtk_text_view_start_selection_drag (GtkTextView *text_view,
6495 const GtkTextIter *iter,
6496 GdkEventButton *button)
6498 GtkTextViewPrivate *priv;
6499 GtkTextIter cursor, ins, bound;
6500 GtkTextIter orig_start, orig_end;
6501 GtkTextBuffer *buffer;
6502 SelectionData *data;
6504 if (text_view->priv->selection_drag_handler != 0)
6507 priv = text_view->priv;
6508 data = g_new0 (SelectionData, 1);
6510 if (button->type == GDK_2BUTTON_PRESS)
6511 data->granularity = SELECT_WORDS;
6512 else if (button->type == GDK_3BUTTON_PRESS)
6513 data->granularity = SELECT_LINES;
6515 data->granularity = SELECT_CHARACTERS;
6517 priv->grab_device = button->device;
6518 gtk_device_grab_add (GTK_WIDGET (text_view),
6522 buffer = get_buffer (text_view);
6527 extend_selection (text_view, data->granularity, &ins, &bound);
6531 if (button->state & GDK_SHIFT_MASK)
6533 /* Extend selection */
6534 GtkTextIter old_ins, old_bound;
6535 GtkTextIter old_start, old_end;
6537 gtk_text_buffer_get_iter_at_mark (buffer, &old_ins, gtk_text_buffer_get_insert (buffer));
6538 gtk_text_buffer_get_iter_at_mark (buffer, &old_bound, gtk_text_buffer_get_selection_bound (buffer));
6539 old_start = old_ins;
6540 old_end = old_bound;
6541 gtk_text_iter_order (&old_start, &old_end);
6543 /* move the front cursor, if the mouse is in front of the selection. Should the
6544 * cursor however be inside the selection (this happens on tripple click) then we
6545 * move the side which was last moved (current insert mark) */
6546 if (gtk_text_iter_compare (&cursor, &old_start) <= 0 ||
6547 (gtk_text_iter_compare (&cursor, &old_end) < 0 &&
6548 gtk_text_iter_compare (&old_ins, &old_bound) <= 0))
6551 orig_start = old_end;
6563 gtk_text_buffer_select_range (buffer, &ins, &bound);
6565 gtk_text_iter_order (&orig_start, &orig_end);
6566 data->orig_start = gtk_text_buffer_create_mark (buffer, NULL,
6568 data->orig_end = gtk_text_buffer_create_mark (buffer, NULL,
6570 gtk_text_view_check_cursor_blink (text_view);
6572 text_view->priv->selection_drag_handler = g_signal_connect_data (text_view,
6573 "motion-notify-event",
6574 G_CALLBACK (selection_motion_event_handler),
6576 (GClosureNotify) selection_data_free, 0);
6579 /* returns whether we were really dragging */
6581 gtk_text_view_end_selection_drag (GtkTextView *text_view)
6583 GtkTextViewPrivate *priv;
6585 priv = text_view->priv;
6587 if (!priv->grab_device)
6590 if (priv->selection_drag_handler == 0)
6593 g_signal_handler_disconnect (text_view, priv->selection_drag_handler);
6594 priv->selection_drag_handler = 0;
6596 if (priv->scroll_timeout != 0)
6598 g_source_remove (priv->scroll_timeout);
6599 priv->scroll_timeout = 0;
6602 gtk_device_grab_remove (GTK_WIDGET (text_view),
6604 priv->grab_device = NULL;
6614 gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
6615 GtkTextAttributes *values,
6618 values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
6619 values->appearance.fg_color = style->text[GTK_STATE_NORMAL];
6622 pango_font_description_free (values->font);
6624 values->font = pango_font_description_copy (style->font_desc);
6628 gtk_text_view_check_keymap_direction (GtkTextView *text_view)
6630 GtkTextViewPrivate *priv = text_view->priv;
6634 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
6635 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)));
6636 GtkTextDirection new_cursor_dir;
6637 GtkTextDirection new_keyboard_dir;
6638 gboolean split_cursor;
6640 g_object_get (settings,
6641 "gtk-split-cursor", &split_cursor,
6644 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
6645 new_keyboard_dir = GTK_TEXT_DIR_RTL;
6647 new_keyboard_dir = GTK_TEXT_DIR_LTR;
6650 new_cursor_dir = GTK_TEXT_DIR_NONE;
6652 new_cursor_dir = new_keyboard_dir;
6654 gtk_text_layout_set_cursor_direction (priv->layout, new_cursor_dir);
6655 gtk_text_layout_set_keyboard_direction (priv->layout, new_keyboard_dir);
6660 gtk_text_view_ensure_layout (GtkTextView *text_view)
6663 GtkTextViewPrivate *priv;
6665 widget = GTK_WIDGET (text_view);
6666 priv = text_view->priv;
6668 if (priv->layout == NULL)
6670 GtkTextAttributes *style;
6671 PangoContext *ltr_context, *rtl_context;
6674 DV(g_print(G_STRLOC"\n"));
6676 priv->layout = gtk_text_layout_new ();
6678 g_signal_connect (priv->layout,
6680 G_CALLBACK (invalidated_handler),
6683 g_signal_connect (priv->layout,
6685 G_CALLBACK (changed_handler),
6688 g_signal_connect (priv->layout,
6690 G_CALLBACK (gtk_text_view_child_allocated),
6693 if (get_buffer (text_view))
6694 gtk_text_layout_set_buffer (priv->layout, get_buffer (text_view));
6696 if ((gtk_widget_has_focus (widget) && priv->cursor_visible))
6697 gtk_text_view_pend_cursor_blink (text_view);
6699 gtk_text_layout_set_cursor_visible (priv->layout, FALSE);
6701 gtk_text_layout_set_overwrite_mode (priv->layout,
6702 priv->overwrite_mode && priv->editable);
6704 ltr_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6705 pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
6706 rtl_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
6707 pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
6709 gtk_text_layout_set_contexts (priv->layout, ltr_context, rtl_context);
6711 g_object_unref (ltr_context);
6712 g_object_unref (rtl_context);
6714 gtk_text_view_check_keymap_direction (text_view);
6716 style = gtk_text_attributes_new ();
6718 gtk_widget_ensure_style (widget);
6719 gtk_text_view_set_attributes_from_style (text_view,
6721 gtk_widget_get_style (widget));
6723 style->pixels_above_lines = priv->pixels_above_lines;
6724 style->pixels_below_lines = priv->pixels_below_lines;
6725 style->pixels_inside_wrap = priv->pixels_inside_wrap;
6726 style->left_margin = priv->left_margin;
6727 style->right_margin = priv->right_margin;
6728 style->indent = priv->indent;
6729 style->tabs = priv->tabs ? pango_tab_array_copy (priv->tabs) : NULL;
6731 style->wrap_mode = priv->wrap_mode;
6732 style->justification = priv->justify;
6733 style->direction = gtk_widget_get_direction (GTK_WIDGET (text_view));
6735 gtk_text_layout_set_default_style (priv->layout, style);
6737 gtk_text_attributes_unref (style);
6739 /* Set layout for all anchored children */
6741 tmp_list = priv->children;
6742 while (tmp_list != NULL)
6744 GtkTextViewChild *vc = tmp_list->data;
6748 gtk_text_anchored_child_set_layout (vc->widget,
6750 /* vc may now be invalid! */
6753 tmp_list = g_slist_next (tmp_list);
6756 gtk_text_view_invalidate (text_view);
6761 * gtk_text_view_get_default_attributes:
6762 * @text_view: a #GtkTextView
6764 * Obtains a copy of the default text attributes. These are the
6765 * attributes used for text unless a tag overrides them.
6766 * You'd typically pass the default attributes in to
6767 * gtk_text_iter_get_attributes() in order to get the
6768 * attributes in effect at a given text position.
6770 * The return value is a copy owned by the caller of this function,
6771 * and should be freed.
6773 * Return value: a new #GtkTextAttributes
6776 gtk_text_view_get_default_attributes (GtkTextView *text_view)
6778 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
6780 gtk_text_view_ensure_layout (text_view);
6782 return gtk_text_attributes_copy (text_view->priv->layout->default_style);
6786 gtk_text_view_destroy_layout (GtkTextView *text_view)
6788 GtkTextViewPrivate *priv = text_view->priv;
6794 gtk_text_view_remove_validate_idles (text_view);
6796 g_signal_handlers_disconnect_by_func (priv->layout,
6797 invalidated_handler,
6799 g_signal_handlers_disconnect_by_func (priv->layout,
6803 /* Remove layout from all anchored children */
6804 tmp_list = priv->children;
6805 while (tmp_list != NULL)
6807 GtkTextViewChild *vc = tmp_list->data;
6811 gtk_text_anchored_child_set_layout (vc->widget, NULL);
6812 /* vc may now be invalid! */
6815 tmp_list = g_slist_next (tmp_list);
6818 gtk_text_view_stop_cursor_blink (text_view);
6819 gtk_text_view_end_selection_drag (text_view);
6821 g_object_unref (priv->layout);
6822 priv->layout = NULL;
6827 * gtk_text_view_reset_im_context:
6828 * @text_view: a #GtkTextView
6830 * Reset the input method context of the text view if needed.
6832 * This can be necessary in the case where modifying the buffer
6833 * would confuse on-going input method behavior.
6838 gtk_text_view_reset_im_context (GtkTextView *text_view)
6840 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
6842 if (text_view->priv->need_im_reset)
6844 text_view->priv->need_im_reset = FALSE;
6845 gtk_im_context_reset (text_view->priv->im_context);
6850 * gtk_text_view_im_context_filter_keypress:
6851 * @text_view: a #GtkTextView
6852 * @event: the key event
6854 * Allow the #GtkTextView input method to internally handle key press
6855 * and release events. If this function returns %TRUE, then no further
6856 * processing should be done for this key event. See
6857 * gtk_im_context_filter_keypress().
6859 * Note that you are expected to call this function from your handler
6860 * when overriding key event handling. This is needed in the case when
6861 * you need to insert your own key handling between the input method
6862 * and the default key event handling of the #GtkTextView.
6866 * gtk_foo_bar_key_press_event (GtkWidget *widget,
6867 * GdkEventKey *event)
6869 * if ((key->keyval == GDK_Return || key->keyval == GDK_KP_Enter))
6871 * if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
6875 * /* Do some stuff */
6877 * return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event);
6881 * Return value: %TRUE if the input method handled the key event.
6886 gtk_text_view_im_context_filter_keypress (GtkTextView *text_view,
6889 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
6891 return gtk_im_context_filter_keypress (text_view->priv->im_context, event);
6899 drag_begin_cb (GtkWidget *widget,
6900 GdkDragContext *context,
6903 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6904 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6907 GdkPixmap *pixmap = NULL;
6909 g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
6911 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6912 pixmap = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
6916 gtk_drag_set_icon_pixmap (context,
6917 gdk_drawable_get_colormap (pixmap),
6921 g_object_unref (pixmap);
6925 gtk_drag_set_icon_default (context);
6930 gtk_text_view_start_selection_dnd (GtkTextView *text_view,
6931 const GtkTextIter *iter,
6932 GdkEventMotion *event)
6934 GtkTargetList *target_list;
6936 text_view->priv->drag_start_x = -1;
6937 text_view->priv->drag_start_y = -1;
6938 text_view->priv->pending_place_cursor_button = 0;
6940 target_list = gtk_text_buffer_get_copy_target_list (get_buffer (text_view));
6942 g_signal_connect (text_view, "drag-begin",
6943 G_CALLBACK (drag_begin_cb), NULL);
6944 gtk_drag_begin (GTK_WIDGET (text_view), target_list,
6945 GDK_ACTION_COPY | GDK_ACTION_MOVE,
6946 1, (GdkEvent*)event);
6950 gtk_text_view_drag_begin (GtkWidget *widget,
6951 GdkDragContext *context)
6957 gtk_text_view_drag_end (GtkWidget *widget,
6958 GdkDragContext *context)
6963 gtk_text_view_drag_data_get (GtkWidget *widget,
6964 GdkDragContext *context,
6965 GtkSelectionData *selection_data,
6969 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
6970 GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
6972 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
6974 gtk_selection_data_set (selection_data,
6975 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
6980 else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
6987 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
6989 /* Extract the selected text */
6990 str = gtk_text_buffer_serialize (buffer, buffer,
6991 selection_data->target,
6998 gtk_selection_data_set (selection_data,
6999 selection_data->target,
7001 (guchar *) str, len);
7011 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
7013 /* Extract the selected text */
7014 str = gtk_text_iter_get_visible_text (&start, &end);
7019 gtk_selection_data_set_text (selection_data, str, -1);
7026 gtk_text_view_drag_data_delete (GtkWidget *widget,
7027 GdkDragContext *context)
7029 gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->priv->buffer,
7030 TRUE, GTK_TEXT_VIEW (widget)->priv->editable);
7034 gtk_text_view_drag_leave (GtkWidget *widget,
7035 GdkDragContext *context,
7038 GtkTextView *text_view;
7039 GtkTextViewPrivate *priv;
7041 text_view = GTK_TEXT_VIEW (widget);
7042 priv = text_view->priv;
7044 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7046 if (priv->dnd_device)
7047 priv->dnd_device = NULL;
7049 if (priv->scroll_timeout != 0)
7050 g_source_remove (priv->scroll_timeout);
7052 priv->scroll_timeout = 0;
7056 gtk_text_view_drag_motion (GtkWidget *widget,
7057 GdkDragContext *context,
7062 GtkTextIter newplace;
7063 GtkTextView *text_view;
7064 GtkTextViewPrivate *priv;
7067 GdkRectangle target_rect;
7070 GdkDragAction suggested_action = 0;
7072 text_view = GTK_TEXT_VIEW (widget);
7073 priv = text_view->priv;
7075 target_rect = priv->text_window->allocation;
7077 if (x < target_rect.x ||
7078 y < target_rect.y ||
7079 x > (target_rect.x + target_rect.width) ||
7080 y > (target_rect.y + target_rect.height))
7081 return FALSE; /* outside the text window, allow parent widgets to handle event */
7083 gtk_text_view_window_to_buffer_coords (text_view,
7084 GTK_TEXT_WINDOW_WIDGET,
7088 gtk_text_layout_get_iter_at_pixel (priv->layout,
7092 target = gtk_drag_dest_find_target (widget, context,
7093 gtk_drag_dest_get_target_list (widget));
7095 if (target == GDK_NONE)
7097 /* can't accept any of the offered targets */
7099 else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7101 gtk_text_iter_compare (&newplace, &start) >= 0 &&
7102 gtk_text_iter_compare (&newplace, &end) <= 0)
7104 /* We're inside the selection. */
7108 if (gtk_text_iter_can_insert (&newplace, priv->editable))
7110 GtkWidget *source_widget;
7112 suggested_action = context->suggested_action;
7114 source_widget = gtk_drag_get_source_widget (context);
7116 if (source_widget == widget)
7118 /* Default to MOVE, unless the user has
7119 * pressed ctrl or alt to affect available actions
7121 if ((context->actions & GDK_ACTION_MOVE) != 0)
7122 suggested_action = GDK_ACTION_MOVE;
7127 /* Can't drop here. */
7131 if (suggested_action != 0)
7133 gtk_text_mark_set_visible (priv->dnd_mark,
7134 priv->cursor_visible);
7136 gdk_drag_status (context, suggested_action, time);
7140 gdk_drag_status (context, 0, time);
7141 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7144 priv->dnd_device = gdk_drag_context_get_device (context);
7146 if (!priv->scroll_timeout)
7147 priv->scroll_timeout =
7148 gdk_threads_add_timeout (100, drag_scan_timeout, text_view);
7150 /* TRUE return means don't propagate the drag motion to parent
7151 * widgets that may also be drop sites.
7157 gtk_text_view_drag_drop (GtkWidget *widget,
7158 GdkDragContext *context,
7163 GtkTextView *text_view;
7164 GtkTextViewPrivate *priv;
7165 GtkTextIter drop_point;
7166 GdkAtom target = GDK_NONE;
7168 text_view = GTK_TEXT_VIEW (widget);
7169 priv = text_view->priv;
7171 if (priv->scroll_timeout != 0)
7172 g_source_remove (priv->scroll_timeout);
7174 priv->scroll_timeout = 0;
7176 gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
7178 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7182 if (gtk_text_iter_can_insert (&drop_point, priv->editable))
7183 target = gtk_drag_dest_find_target (widget, context, NULL);
7185 if (target != GDK_NONE)
7186 gtk_drag_get_data (widget, context, target, time);
7188 gtk_drag_finish (context, FALSE, FALSE, time);
7194 insert_text_data (GtkTextView *text_view,
7195 GtkTextIter *drop_point,
7196 GtkSelectionData *selection_data)
7200 str = gtk_selection_data_get_text (selection_data);
7204 if (!gtk_text_buffer_insert_interactive (get_buffer (text_view),
7205 drop_point, (gchar *) str, -1,
7206 text_view->priv->editable))
7208 gtk_widget_error_bell (GTK_WIDGET (text_view));
7216 gtk_text_view_drag_data_received (GtkWidget *widget,
7217 GdkDragContext *context,
7220 GtkSelectionData *selection_data,
7224 GtkTextIter drop_point;
7225 GtkTextView *text_view;
7226 GtkTextViewPrivate *priv;
7227 gboolean success = FALSE;
7228 GtkTextBuffer *buffer = NULL;
7230 text_view = GTK_TEXT_VIEW (widget);
7231 priv = text_view->priv;
7233 if (!priv->dnd_mark)
7236 buffer = get_buffer (text_view);
7238 gtk_text_buffer_get_iter_at_mark (buffer,
7242 if (!gtk_text_iter_can_insert (&drop_point, priv->editable))
7247 gtk_text_buffer_begin_user_action (buffer);
7249 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7251 GtkTextBuffer *src_buffer = NULL;
7252 GtkTextIter start, end;
7253 gboolean copy_tags = TRUE;
7255 if (selection_data->length != sizeof (src_buffer))
7258 memcpy (&src_buffer, selection_data->data, sizeof (src_buffer));
7260 if (src_buffer == NULL)
7263 g_return_if_fail (GTK_IS_TEXT_BUFFER (src_buffer));
7265 if (gtk_text_buffer_get_tag_table (src_buffer) !=
7266 gtk_text_buffer_get_tag_table (buffer))
7268 /* try to find a suitable rich text target instead */
7272 GdkAtom target = GDK_NONE;
7276 atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms);
7278 for (list = context->targets; list; list = g_list_next (list))
7282 for (i = 0; i < n_atoms; i++)
7283 if (GUINT_TO_POINTER (atoms[i]) == list->data)
7292 if (target != GDK_NONE)
7294 gtk_drag_get_data (widget, context, target, time);
7295 gtk_text_buffer_end_user_action (buffer);
7300 if (gtk_text_buffer_get_selection_bounds (src_buffer,
7305 gtk_text_buffer_insert_range_interactive (buffer,
7314 str = gtk_text_iter_get_visible_text (&start, &end);
7315 gtk_text_buffer_insert_interactive (buffer,
7316 &drop_point, str, -1,
7322 else if (selection_data->length > 0 &&
7323 info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
7326 GError *error = NULL;
7328 retval = gtk_text_buffer_deserialize (buffer, buffer,
7329 selection_data->target,
7331 (guint8 *) selection_data->data,
7332 selection_data->length,
7337 g_warning ("error pasting: %s\n", error->message);
7338 g_clear_error (&error);
7342 insert_text_data (text_view, &drop_point, selection_data);
7345 gtk_drag_finish (context, success,
7346 success && context->action == GDK_ACTION_MOVE,
7351 gtk_text_buffer_get_iter_at_mark (buffer,
7354 gtk_text_buffer_place_cursor (buffer, &drop_point);
7356 gtk_text_buffer_end_user_action (buffer);
7361 * gtk_text_view_get_hadjustment:
7362 * @text_view: a #GtkTextView
7364 * Gets the horizontal-scrolling #GtkAdjustment.
7366 * Returns: (transfer none): pointer to the horizontal #GtkAdjustment
7371 gtk_text_view_get_hadjustment (GtkTextView *text_view)
7373 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7375 return get_hadjustment (text_view);
7379 * gtk_text_view_get_vadjustment:
7380 * @text_view: a #GtkTextView
7382 * Gets the vertical-scrolling #GtkAdjustment.
7384 * Returns: (transfer none): pointer to the vertical #GtkAdjustment
7389 gtk_text_view_get_vadjustment (GtkTextView *text_view)
7391 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
7393 return get_vadjustment (text_view);
7396 static GtkAdjustment*
7397 get_hadjustment (GtkTextView *text_view)
7399 if (text_view->priv->hadjustment == NULL)
7400 gtk_text_view_set_scroll_adjustments (text_view,
7401 NULL, /* forces creation */
7402 text_view->priv->vadjustment);
7404 return text_view->priv->hadjustment;
7407 static GtkAdjustment*
7408 get_vadjustment (GtkTextView *text_view)
7410 if (text_view->priv->vadjustment == NULL)
7411 gtk_text_view_set_scroll_adjustments (text_view,
7412 text_view->priv->hadjustment,
7413 NULL); /* forces creation */
7414 return text_view->priv->vadjustment;
7419 gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
7420 GtkAdjustment *hadj,
7421 GtkAdjustment *vadj)
7423 GtkTextViewPrivate *priv = text_view->priv;
7424 gboolean need_adjust = FALSE;
7427 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7429 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7431 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7433 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7435 if (priv->hadjustment && (priv->hadjustment != hadj))
7437 g_signal_handlers_disconnect_by_func (priv->hadjustment,
7438 gtk_text_view_value_changed,
7440 g_object_unref (priv->hadjustment);
7443 if (priv->vadjustment && (priv->vadjustment != vadj))
7445 g_signal_handlers_disconnect_by_func (priv->vadjustment,
7446 gtk_text_view_value_changed,
7448 g_object_unref (priv->vadjustment);
7451 if (priv->hadjustment != hadj)
7453 priv->hadjustment = hadj;
7454 g_object_ref_sink (priv->hadjustment);
7456 g_signal_connect (priv->hadjustment, "value-changed",
7457 G_CALLBACK (gtk_text_view_value_changed),
7462 if (priv->vadjustment != vadj)
7464 priv->vadjustment = vadj;
7465 g_object_ref_sink (priv->vadjustment);
7467 g_signal_connect (priv->vadjustment, "value-changed",
7468 G_CALLBACK (gtk_text_view_value_changed),
7474 gtk_text_view_value_changed (NULL, text_view);
7477 /* FIXME this adjust_allocation is a big cut-and-paste from
7478 * GtkCList, needs to be some "official" way to do this
7488 /* The window to which widget->window is relative */
7489 #define ALLOCATION_WINDOW(widget) \
7490 (!gtk_widget_get_has_window (widget) ? \
7491 gtk_widget_get_window (widget) : \
7492 gdk_window_get_parent (gtk_widget_get_window (widget)))
7495 adjust_allocation_recurse (GtkWidget *widget,
7498 GtkAllocation allocation;
7499 ScrollData *scroll_data = data;
7501 /* Need to really size allocate instead of just poking
7502 * into widget->allocation if the widget is not realized.
7503 * FIXME someone figure out why this was.
7505 if (!gtk_widget_get_realized (widget))
7507 if (gtk_widget_get_visible (widget))
7509 GdkRectangle tmp_rectangle;
7511 tmp_rectangle = allocation;
7512 tmp_rectangle.x += scroll_data->dx;
7513 tmp_rectangle.y += scroll_data->dy;
7515 gtk_widget_size_allocate (widget, &tmp_rectangle);
7520 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
7522 allocation.x += scroll_data->dx;
7523 allocation.y += scroll_data->dy;
7524 gtk_widget_set_allocation (widget, &allocation);
7526 if (GTK_IS_CONTAINER (widget))
7527 gtk_container_forall (GTK_CONTAINER (widget),
7528 adjust_allocation_recurse,
7535 adjust_allocation (GtkWidget *widget,
7539 ScrollData scroll_data;
7541 if (gtk_widget_get_realized (widget))
7542 scroll_data.window = ALLOCATION_WINDOW (widget);
7544 scroll_data.window = NULL;
7546 scroll_data.dx = dx;
7547 scroll_data.dy = dy;
7549 adjust_allocation_recurse (widget, &scroll_data);
7553 gtk_text_view_value_changed (GtkAdjustment *adj,
7554 GtkTextView *text_view)
7556 GtkTextViewPrivate *priv;
7562 priv = text_view->priv;
7564 /* Note that we oddly call this function with adj == NULL
7568 priv->onscreen_validated = FALSE;
7570 DV(g_print(">Scroll offset changed %s/%g, onscreen_validated = FALSE ("G_STRLOC")\n",
7571 adj == priv->hadjustment ? "hadj" : adj == priv->vadjustment ? "vadj" : "none",
7572 adj ? adj->value : 0.0));
7574 if (adj == priv->hadjustment)
7576 dx = priv->xoffset - (gint)adj->value;
7577 priv->xoffset = adj->value;
7579 /* If the change is due to a size change we need
7580 * to invalidate the entire text window because there might be
7581 * right-aligned or centered text
7583 if (priv->width_changed)
7585 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7586 gdk_window_invalidate_rect (priv->text_window->bin_window, NULL, FALSE);
7588 priv->width_changed = FALSE;
7591 else if (adj == priv->vadjustment)
7593 dy = priv->yoffset - (gint)adj->value;
7594 priv->yoffset = adj->value;
7598 gtk_text_layout_get_line_at_y (priv->layout, &iter, adj->value, &line_top);
7600 gtk_text_buffer_move_mark (get_buffer (text_view), priv->first_para_mark, &iter);
7602 priv->first_para_pixels = adj->value - line_top;
7606 if (dx != 0 || dy != 0)
7610 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7614 if (priv->left_window)
7615 text_window_scroll (priv->left_window, 0, dy);
7616 if (priv->right_window)
7617 text_window_scroll (priv->right_window, 0, dy);
7622 if (priv->top_window)
7623 text_window_scroll (priv->top_window, dx, 0);
7624 if (priv->bottom_window)
7625 text_window_scroll (priv->bottom_window, dx, 0);
7628 /* It looks nicer to scroll the main area last, because
7629 * it takes a while, and making the side areas update
7630 * afterward emphasizes the slowness of scrolling the
7633 text_window_scroll (priv->text_window, dx, dy);
7636 /* Children are now "moved" in the text window, poke
7637 * into widget->allocation for each child
7639 tmp_list = priv->children;
7640 while (tmp_list != NULL)
7642 GtkTextViewChild *child = tmp_list->data;
7645 adjust_allocation (child->widget, dx, dy);
7647 tmp_list = g_slist_next (tmp_list);
7651 /* This could result in invalidation, which would install the
7652 * first_validate_idle, which would validate onscreen;
7653 * but we're going to go ahead and validate here, so
7654 * first_validate_idle shouldn't have anything to do.
7656 gtk_text_view_update_layout_width (text_view);
7658 /* We also update the IM spot location here, since the IM context
7659 * might do something that leads to validation.
7661 gtk_text_view_update_im_spot_location (text_view);
7663 /* note that validation of onscreen could invoke this function
7664 * recursively, by scrolling to maintain first_para, or in response
7665 * to updating the layout width, however there is no problem with
7666 * that, or shouldn't be.
7668 gtk_text_view_validate_onscreen (text_view);
7670 /* process exposes */
7671 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
7673 DV (g_print ("Processing updates (%s)\n", G_STRLOC));
7675 if (priv->left_window)
7676 gdk_window_process_updates (priv->left_window->bin_window, TRUE);
7678 if (priv->right_window)
7679 gdk_window_process_updates (priv->right_window->bin_window, TRUE);
7681 if (priv->top_window)
7682 gdk_window_process_updates (priv->top_window->bin_window, TRUE);
7684 if (priv->bottom_window)
7685 gdk_window_process_updates (priv->bottom_window->bin_window, TRUE);
7687 gdk_window_process_updates (priv->text_window->bin_window, TRUE);
7690 /* If this got installed, get rid of it, it's just a waste of time. */
7691 if (priv->first_validate_idle != 0)
7693 g_source_remove (priv->first_validate_idle);
7694 priv->first_validate_idle = 0;
7697 /* Finally we update the IM cursor location again, to ensure any
7698 * changes made by the validation are pushed through.
7700 gtk_text_view_update_im_spot_location (text_view);
7702 DV(g_print(">End scroll offset changed handler ("G_STRLOC")\n"));
7706 gtk_text_view_commit_handler (GtkIMContext *context,
7708 GtkTextView *text_view)
7710 gtk_text_view_commit_text (text_view, str);
7714 gtk_text_view_commit_text (GtkTextView *text_view,
7717 GtkTextViewPrivate *priv;
7718 gboolean had_selection;
7720 priv = text_view->priv;
7722 gtk_text_buffer_begin_user_action (get_buffer (text_view));
7724 had_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
7727 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
7730 if (!strcmp (str, "\n"))
7732 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
7735 gtk_widget_error_bell (GTK_WIDGET (text_view));
7740 if (!had_selection && priv->overwrite_mode)
7744 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
7746 gtk_text_buffer_get_insert (get_buffer (text_view)));
7747 if (!gtk_text_iter_ends_line (&insert))
7748 gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
7751 if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
7754 gtk_widget_error_bell (GTK_WIDGET (text_view));
7758 gtk_text_buffer_end_user_action (get_buffer (text_view));
7760 gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
7761 DV(g_print (G_STRLOC": scrolling onscreen\n"));
7762 gtk_text_view_scroll_mark_onscreen (text_view,
7763 gtk_text_buffer_get_insert (get_buffer (text_view)));
7767 gtk_text_view_preedit_changed_handler (GtkIMContext *context,
7768 GtkTextView *text_view)
7770 GtkTextViewPrivate *priv;
7772 PangoAttrList *attrs;
7776 priv = text_view->priv;
7778 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
7779 gtk_text_buffer_get_insert (priv->buffer));
7781 /* Keypress events are passed to input method even if cursor position is
7782 * not editable; so beep here if it's multi-key input sequence, input
7783 * method will be reset in key-press-event handler.
7785 gtk_im_context_get_preedit_string (context, &str, &attrs, &cursor_pos);
7787 if (str && str[0] && !gtk_text_iter_can_insert (&iter, priv->editable))
7789 gtk_widget_error_bell (GTK_WIDGET (text_view));
7793 g_signal_emit (text_view, signals[PREEDIT_CHANGED], 0, str);
7796 gtk_text_layout_set_preedit_string (priv->layout, str, attrs, cursor_pos);
7797 if (gtk_widget_has_focus (GTK_WIDGET (text_view)))
7798 gtk_text_view_scroll_mark_onscreen (text_view,
7799 gtk_text_buffer_get_insert (get_buffer (text_view)));
7802 pango_attr_list_unref (attrs);
7807 gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
7808 GtkTextView *text_view)
7815 gtk_text_buffer_get_iter_at_mark (text_view->priv->buffer, &start,
7816 gtk_text_buffer_get_insert (text_view->priv->buffer));
7819 pos = gtk_text_iter_get_line_index (&start);
7820 gtk_text_iter_set_line_offset (&start, 0);
7821 gtk_text_iter_forward_to_line_end (&end);
7823 text = gtk_text_iter_get_slice (&start, &end);
7824 gtk_im_context_set_surrounding (context, text, -1, pos);
7831 gtk_text_view_delete_surrounding_handler (GtkIMContext *context,
7834 GtkTextView *text_view)
7836 GtkTextViewPrivate *priv;
7840 priv = text_view->priv;
7842 gtk_text_buffer_get_iter_at_mark (priv->buffer, &start,
7843 gtk_text_buffer_get_insert (priv->buffer));
7846 gtk_text_iter_forward_chars (&start, offset);
7847 gtk_text_iter_forward_chars (&end, offset + n_chars);
7849 gtk_text_buffer_delete_interactive (priv->buffer, &start, &end,
7856 gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
7857 const GtkTextIter *location,
7861 GtkTextView *text_view = GTK_TEXT_VIEW (data);
7862 gboolean need_reset = FALSE;
7864 if (mark == gtk_text_buffer_get_insert (buffer))
7866 text_view->priv->virtual_cursor_x = -1;
7867 text_view->priv->virtual_cursor_y = -1;
7868 gtk_text_view_update_im_spot_location (text_view);
7871 else if (mark == gtk_text_buffer_get_selection_bound (buffer))
7877 gtk_text_view_reset_im_context (text_view);
7881 gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
7882 const GParamSpec *pspec,
7885 GtkWidget *widget = GTK_WIDGET (data);
7886 GtkTargetList *view_list;
7887 GtkTargetList *buffer_list;
7890 view_list = gtk_drag_dest_get_target_list (widget);
7891 buffer_list = gtk_text_buffer_get_paste_target_list (buffer);
7894 gtk_target_list_ref (view_list);
7896 view_list = gtk_target_list_new (NULL, 0);
7898 list = view_list->list;
7901 GtkTargetPair *pair = list->data;
7903 list = g_list_next (list); /* get next element before removing */
7905 if (pair->info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT &&
7906 pair->info <= GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
7908 gtk_target_list_remove (view_list, pair->target);
7912 for (list = buffer_list->list; list; list = g_list_next (list))
7914 GtkTargetPair *pair = list->data;
7916 gtk_target_list_add (view_list, pair->target, pair->flags, pair->info);
7919 gtk_drag_dest_set_target_list (widget, view_list);
7920 gtk_target_list_unref (view_list);
7924 gtk_text_view_get_cursor_location (GtkTextView *text_view,
7929 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7930 gtk_text_buffer_get_insert (get_buffer (text_view)));
7932 gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert, pos, NULL);
7936 gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
7937 GtkTextIter *cursor,
7941 GtkTextViewPrivate *priv;
7945 priv = text_view->priv;
7950 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
7951 gtk_text_buffer_get_insert (get_buffer (text_view)));
7953 if ((x && priv->virtual_cursor_x == -1) ||
7954 (y && priv->virtual_cursor_y == -1))
7955 gtk_text_layout_get_cursor_locations (priv->layout, &insert, &pos, NULL);
7959 if (priv->virtual_cursor_x != -1)
7960 *x = priv->virtual_cursor_x;
7967 if (priv->virtual_cursor_x != -1)
7968 *y = priv->virtual_cursor_y;
7970 *y = pos.y + pos.height / 2;
7975 gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
7981 if (!text_view->priv->layout)
7984 if (x == -1 || y == -1)
7985 gtk_text_view_get_cursor_location (text_view, &pos);
7987 text_view->priv->virtual_cursor_x = (x == -1) ? pos.x : x;
7988 text_view->priv->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
7991 /* Quick hack of a popup menu
7994 activate_cb (GtkWidget *menuitem,
7995 GtkTextView *text_view)
7997 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
7998 g_signal_emit_by_name (text_view, signal);
8002 append_action_signal (GtkTextView *text_view,
8004 const gchar *stock_id,
8005 const gchar *signal,
8008 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8010 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8011 g_signal_connect (menuitem, "activate",
8012 G_CALLBACK (activate_cb), text_view);
8014 gtk_widget_set_sensitive (menuitem, sensitive);
8016 gtk_widget_show (menuitem);
8017 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8021 gtk_text_view_select_all (GtkWidget *widget,
8024 GtkTextView *text_view = GTK_TEXT_VIEW (widget);
8025 GtkTextBuffer *buffer;
8026 GtkTextIter start_iter, end_iter, insert;
8028 buffer = text_view->priv->buffer;
8031 gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
8032 gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
8036 gtk_text_buffer_get_iter_at_mark (buffer, &insert,
8037 gtk_text_buffer_get_insert (buffer));
8038 gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &insert);
8043 select_all_cb (GtkWidget *menuitem,
8044 GtkTextView *text_view)
8046 gtk_text_view_select_all (GTK_WIDGET (text_view), TRUE);
8050 delete_cb (GtkTextView *text_view)
8052 gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
8053 text_view->priv->editable);
8057 popup_menu_detach (GtkWidget *attach_widget,
8060 GTK_TEXT_VIEW (attach_widget)->priv->popup_menu = NULL;
8064 popup_position_func (GtkMenu *menu,
8070 GtkAllocation allocation;
8071 GtkTextView *text_view;
8073 GdkRectangle cursor_rect;
8074 GdkRectangle onscreen_rect;
8075 gint root_x, root_y;
8080 GdkRectangle monitor;
8082 text_view = GTK_TEXT_VIEW (user_data);
8083 widget = GTK_WIDGET (text_view);
8085 g_return_if_fail (gtk_widget_get_realized (widget));
8087 screen = gtk_widget_get_screen (widget);
8089 gdk_window_get_origin (gtk_widget_get_window (widget),
8092 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8094 gtk_text_buffer_get_insert (get_buffer (text_view)));
8096 gtk_text_view_get_iter_location (text_view,
8100 gtk_text_view_get_visible_rect (text_view, &onscreen_rect);
8102 gtk_widget_size_request (text_view->priv->popup_menu, &req);
8104 gtk_widget_get_allocation (widget, &allocation);
8106 /* can't use rectangle_intersect since cursor rect can have 0 width */
8107 if (cursor_rect.x >= onscreen_rect.x &&
8108 cursor_rect.x < onscreen_rect.x + onscreen_rect.width &&
8109 cursor_rect.y >= onscreen_rect.y &&
8110 cursor_rect.y < onscreen_rect.y + onscreen_rect.height)
8112 gtk_text_view_buffer_to_window_coords (text_view,
8113 GTK_TEXT_WINDOW_WIDGET,
8114 cursor_rect.x, cursor_rect.y,
8115 &cursor_rect.x, &cursor_rect.y);
8117 *x = root_x + cursor_rect.x + cursor_rect.width;
8118 *y = root_y + cursor_rect.y + cursor_rect.height;
8122 /* Just center the menu, since cursor is offscreen. */
8123 *x = root_x + (allocation.width / 2 - req.width / 2);
8124 *y = root_y + (allocation.height / 2 - req.height / 2);
8128 *x = CLAMP (*x, root_x, (root_x + allocation.width));
8129 *y = CLAMP (*y, root_y, (root_y + allocation.height));
8131 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
8132 gtk_menu_set_monitor (menu, monitor_num);
8133 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8135 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
8136 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
8143 GtkTextView *text_view;
8149 range_contains_editable_text (const GtkTextIter *start,
8150 const GtkTextIter *end,
8151 gboolean default_editability)
8153 GtkTextIter iter = *start;
8155 while (gtk_text_iter_compare (&iter, end) < 0)
8157 if (gtk_text_iter_editable (&iter, default_editability))
8160 gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
8167 unichar_chosen_func (const char *text,
8170 GtkTextView *text_view = GTK_TEXT_VIEW (data);
8172 gtk_text_view_commit_text (text_view, text);
8176 popup_targets_received (GtkClipboard *clipboard,
8177 GtkSelectionData *data,
8180 PopupInfo *info = user_data;
8181 GtkTextView *text_view;
8182 GtkTextViewPrivate *priv;
8184 text_view = info->text_view;
8185 priv = text_view->priv;
8187 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
8189 /* We implicitely rely here on the fact that if we are pasting ourself, we'll
8190 * have text targets as well as the private GTK_TEXT_BUFFER_CONTENTS target.
8192 gboolean clipboard_contains_text;
8193 GtkWidget *menuitem;
8195 gboolean have_selection;
8196 gboolean can_insert;
8198 GtkTextIter sel_start, sel_end;
8199 gboolean show_input_method_menu;
8200 gboolean show_unicode_menu;
8202 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8204 if (priv->popup_menu)
8205 gtk_widget_destroy (priv->popup_menu);
8207 priv->popup_menu = gtk_menu_new ();
8209 gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
8210 GTK_WIDGET (text_view),
8213 have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
8214 &sel_start, &sel_end);
8216 gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
8218 gtk_text_buffer_get_insert (get_buffer (text_view)));
8220 can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
8222 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8224 range_contains_editable_text (&sel_start, &sel_end,
8226 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8228 append_action_signal (text_view, priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8229 can_insert && clipboard_contains_text);
8231 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8232 gtk_widget_set_sensitive (menuitem,
8234 range_contains_editable_text (&sel_start, &sel_end,
8236 g_signal_connect_swapped (menuitem, "activate",
8237 G_CALLBACK (delete_cb), text_view);
8238 gtk_widget_show (menuitem);
8239 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8241 menuitem = gtk_separator_menu_item_new ();
8242 gtk_widget_show (menuitem);
8243 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8245 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8246 g_signal_connect (menuitem, "activate",
8247 G_CALLBACK (select_all_cb), text_view);
8248 gtk_widget_show (menuitem);
8249 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8251 g_object_get (gtk_widget_get_settings (GTK_WIDGET (text_view)),
8252 "gtk-show-input-method-menu", &show_input_method_menu,
8253 "gtk-show-unicode-menu", &show_unicode_menu,
8256 if (show_input_method_menu || show_unicode_menu)
8258 menuitem = gtk_separator_menu_item_new ();
8259 gtk_widget_show (menuitem);
8260 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8263 if (show_input_method_menu)
8265 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8266 gtk_widget_show (menuitem);
8267 gtk_widget_set_sensitive (menuitem, can_insert);
8269 submenu = gtk_menu_new ();
8270 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8271 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8273 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (priv->im_context),
8274 GTK_MENU_SHELL (submenu));
8277 if (show_unicode_menu)
8279 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8280 gtk_widget_show (menuitem);
8281 gtk_widget_set_sensitive (menuitem, can_insert);
8283 submenu = gtk_menu_new ();
8284 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8285 gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
8287 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8288 unichar_chosen_func,
8292 g_signal_emit (text_view,
8293 signals[POPULATE_POPUP],
8298 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8300 info->button, info->time);
8303 gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
8304 popup_position_func, text_view,
8305 0, gtk_get_current_event_time ());
8306 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->popup_menu), FALSE);
8310 g_object_unref (text_view);
8315 gtk_text_view_do_popup (GtkTextView *text_view,
8316 GdkEventButton *event)
8318 PopupInfo *info = g_new (PopupInfo, 1);
8320 /* In order to know what entries we should make sensitive, we
8321 * ask for the current targets of the clipboard, and when
8322 * we get them, then we actually pop up the menu.
8324 info->text_view = g_object_ref (text_view);
8328 info->button = event->button;
8329 info->time = event->time;
8334 info->time = gtk_get_current_event_time ();
8337 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
8338 GDK_SELECTION_CLIPBOARD),
8339 gdk_atom_intern_static_string ("TARGETS"),
8340 popup_targets_received,
8345 gtk_text_view_popup_menu (GtkWidget *widget)
8347 gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
8351 /* Child GdkWindows */
8354 static GtkTextWindow*
8355 text_window_new (GtkTextWindowType type,
8358 gint height_request)
8362 win = g_new (GtkTextWindow, 1);
8365 win->widget = widget;
8367 win->bin_window = NULL;
8368 win->requisition.width = width_request;
8369 win->requisition.height = height_request;
8370 win->allocation.width = width_request;
8371 win->allocation.height = height_request;
8372 win->allocation.x = 0;
8373 win->allocation.y = 0;
8379 text_window_free (GtkTextWindow *win)
8382 text_window_unrealize (win);
8388 text_window_realize (GtkTextWindow *win,
8392 GdkWindowAttr attributes;
8393 gint attributes_mask;
8396 attributes.window_type = GDK_WINDOW_CHILD;
8397 attributes.x = win->allocation.x;
8398 attributes.y = win->allocation.y;
8399 attributes.width = win->allocation.width;
8400 attributes.height = win->allocation.height;
8401 attributes.wclass = GDK_INPUT_OUTPUT;
8402 attributes.visual = gtk_widget_get_visual (win->widget);
8403 attributes.colormap = gtk_widget_get_colormap (win->widget);
8404 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
8406 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
8408 window = gtk_widget_get_window (widget);
8410 win->window = gdk_window_new (window,
8411 &attributes, attributes_mask);
8413 gdk_window_set_back_pixmap (win->window, NULL, FALSE);
8415 gdk_window_show (win->window);
8416 gdk_window_set_user_data (win->window, win->widget);
8417 gdk_window_lower (win->window);
8421 attributes.width = win->allocation.width;
8422 attributes.height = win->allocation.height;
8423 attributes.event_mask = (GDK_EXPOSURE_MASK |
8425 GDK_KEY_PRESS_MASK |
8426 GDK_BUTTON_PRESS_MASK |
8427 GDK_BUTTON_RELEASE_MASK |
8428 GDK_POINTER_MOTION_MASK |
8429 GDK_POINTER_MOTION_HINT_MASK |
8430 gtk_widget_get_events (win->widget));
8432 win->bin_window = gdk_window_new (win->window,
8436 gdk_window_show (win->bin_window);
8437 gdk_window_set_user_data (win->bin_window, win->widget);
8439 if (win->type == GTK_TEXT_WINDOW_TEXT)
8441 if (gtk_widget_is_sensitive (widget))
8444 cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (window),
8446 gdk_window_set_cursor (win->bin_window, cursor);
8447 gdk_cursor_unref (cursor);
8450 gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->priv->im_context,
8454 gdk_window_set_background (win->bin_window,
8455 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
8459 gdk_window_set_background (win->bin_window,
8460 >k_widget_get_style (widget)->bg[gtk_widget_get_state (widget)]);
8463 g_object_set_qdata (G_OBJECT (win->window),
8464 g_quark_from_static_string ("gtk-text-view-text-window"),
8467 g_object_set_qdata (G_OBJECT (win->bin_window),
8468 g_quark_from_static_string ("gtk-text-view-text-window"),
8473 text_window_unrealize (GtkTextWindow *win)
8475 if (win->type == GTK_TEXT_WINDOW_TEXT)
8477 gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->priv->im_context,
8481 gdk_window_set_user_data (win->window, NULL);
8482 gdk_window_set_user_data (win->bin_window, NULL);
8483 gdk_window_destroy (win->bin_window);
8484 gdk_window_destroy (win->window);
8486 win->bin_window = NULL;
8490 text_window_size_allocate (GtkTextWindow *win,
8493 win->allocation = *rect;
8497 gdk_window_move_resize (win->window,
8499 rect->width, rect->height);
8501 gdk_window_resize (win->bin_window,
8502 rect->width, rect->height);
8507 text_window_scroll (GtkTextWindow *win,
8511 if (dx != 0 || dy != 0)
8513 gdk_window_scroll (win->bin_window, dx, dy);
8518 text_window_invalidate_rect (GtkTextWindow *win,
8521 GdkRectangle window_rect;
8523 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (win->widget),
8530 window_rect.width = rect->width;
8531 window_rect.height = rect->height;
8533 /* Adjust the rect as appropriate */
8537 case GTK_TEXT_WINDOW_TEXT:
8540 case GTK_TEXT_WINDOW_LEFT:
8541 case GTK_TEXT_WINDOW_RIGHT:
8543 window_rect.width = win->allocation.width;
8546 case GTK_TEXT_WINDOW_TOP:
8547 case GTK_TEXT_WINDOW_BOTTOM:
8549 window_rect.height = win->allocation.height;
8553 g_warning ("%s: bug!", G_STRFUNC);
8558 gdk_window_invalidate_rect (win->bin_window, &window_rect, FALSE);
8562 cairo_t *cr = gdk_cairo_create (win->bin_window);
8563 gdk_cairo_rectangle (cr, &window_rect);
8564 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
8572 text_window_invalidate_cursors (GtkTextWindow *win)
8574 GtkTextView *text_view;
8575 GtkTextViewPrivate *priv;
8577 GdkRectangle strong;
8579 gboolean draw_arrow;
8580 gfloat cursor_aspect_ratio;
8584 text_view = GTK_TEXT_VIEW (win->widget);
8585 priv = text_view->priv;
8587 gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter,
8588 gtk_text_buffer_get_insert (priv->buffer));
8590 if (_gtk_text_layout_get_block_cursor (priv->layout, &strong))
8592 text_window_invalidate_rect (win, &strong);
8596 gtk_text_layout_get_cursor_locations (priv->layout, &iter,
8599 /* cursor width calculation as in gtkstyle.c:draw_insertion_cursor(),
8600 * ignoring the text direction be exposing both sides of the cursor
8603 draw_arrow = (strong.x != weak.x || strong.y != weak.y);
8605 gtk_widget_style_get (win->widget,
8606 "cursor-aspect-ratio", &cursor_aspect_ratio,
8609 stem_width = strong.height * cursor_aspect_ratio + 1;
8610 arrow_width = stem_width + 1;
8612 strong.width = stem_width;
8614 /* round up to the next even number */
8618 strong.x -= stem_width / 2;
8619 strong.width += stem_width;
8623 strong.x -= arrow_width;
8624 strong.width += arrow_width * 2;
8627 text_window_invalidate_rect (win, &strong);
8629 if (draw_arrow) /* == have weak */
8631 stem_width = weak.height * cursor_aspect_ratio + 1;
8632 arrow_width = stem_width + 1;
8634 weak.width = stem_width;
8636 /* round up to the next even number */
8640 weak.x -= stem_width / 2;
8641 weak.width += stem_width;
8643 weak.x -= arrow_width;
8644 weak.width += arrow_width * 2;
8646 text_window_invalidate_rect (win, &weak);
8651 text_window_get_width (GtkTextWindow *win)
8653 return win->allocation.width;
8657 text_window_get_height (GtkTextWindow *win)
8659 return win->allocation.height;
8666 * gtk_text_view_get_window:
8667 * @text_view: a #GtkTextView
8668 * @win: window to get
8670 * Retrieves the #GdkWindow corresponding to an area of the text view;
8671 * possible windows include the overall widget window, child windows
8672 * on the left, right, top, bottom, and the window that displays the
8673 * text buffer. Windows are %NULL and nonexistent if their width or
8674 * height is 0, and are nonexistent before the widget has been
8677 * Return value: (transfer none): a #GdkWindow, or %NULL
8680 gtk_text_view_get_window (GtkTextView *text_view,
8681 GtkTextWindowType win)
8683 GtkTextViewPrivate *priv = text_view->priv;
8685 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
8689 case GTK_TEXT_WINDOW_WIDGET:
8690 return gtk_widget_get_window (GTK_WIDGET (text_view));
8693 case GTK_TEXT_WINDOW_TEXT:
8694 return priv->text_window->bin_window;
8697 case GTK_TEXT_WINDOW_LEFT:
8698 if (priv->left_window)
8699 return priv->left_window->bin_window;
8704 case GTK_TEXT_WINDOW_RIGHT:
8705 if (priv->right_window)
8706 return priv->right_window->bin_window;
8711 case GTK_TEXT_WINDOW_TOP:
8712 if (priv->top_window)
8713 return priv->top_window->bin_window;
8718 case GTK_TEXT_WINDOW_BOTTOM:
8719 if (priv->bottom_window)
8720 return priv->bottom_window->bin_window;
8725 case GTK_TEXT_WINDOW_PRIVATE:
8726 g_warning ("%s: You can't get GTK_TEXT_WINDOW_PRIVATE, it has \"PRIVATE\" in the name because it is private.", G_STRFUNC);
8731 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8736 * gtk_text_view_get_window_type:
8737 * @text_view: a #GtkTextView
8738 * @window: a window type
8740 * Usually used to find out which window an event corresponds to.
8741 * If you connect to an event signal on @text_view, this function
8742 * should be called on <literal>event->window</literal> to
8743 * see which window it was.
8745 * Return value: the window type.
8748 gtk_text_view_get_window_type (GtkTextView *text_view,
8753 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
8754 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
8756 if (window == gtk_widget_get_window (GTK_WIDGET (text_view)))
8757 return GTK_TEXT_WINDOW_WIDGET;
8759 win = g_object_get_qdata (G_OBJECT (window),
8760 g_quark_try_string ("gtk-text-view-text-window"));
8766 return GTK_TEXT_WINDOW_PRIVATE;
8771 buffer_to_widget (GtkTextView *text_view,
8777 GtkTextViewPrivate *priv = text_view->priv;
8781 *window_x = buffer_x - priv->xoffset;
8782 *window_x += priv->text_window->allocation.x;
8787 *window_y = buffer_y - priv->yoffset;
8788 *window_y += priv->text_window->allocation.y;
8793 widget_to_text_window (GtkTextWindow *win,
8800 *window_x = widget_x - win->allocation.x;
8803 *window_y = widget_y - win->allocation.y;
8807 buffer_to_text_window (GtkTextView *text_view,
8816 g_warning ("Attempt to convert text buffer coordinates to coordinates "
8817 "for a nonexistent or private child window of GtkTextView");
8821 buffer_to_widget (text_view,
8823 window_x, window_y);
8825 widget_to_text_window (win,
8826 window_x ? *window_x : 0,
8827 window_y ? *window_y : 0,
8833 * gtk_text_view_buffer_to_window_coords:
8834 * @text_view: a #GtkTextView
8835 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8836 * @buffer_x: buffer x coordinate
8837 * @buffer_y: buffer y coordinate
8838 * @window_x: (out) (allow-none): window x coordinate return location or %NULL
8839 * @window_y: (out) (allow-none): window y coordinate return location or %NULL
8841 * Converts coordinate (@buffer_x, @buffer_y) to coordinates for the window
8842 * @win, and stores the result in (@window_x, @window_y).
8844 * Note that you can't convert coordinates for a nonexisting window (see
8845 * gtk_text_view_set_border_window_size()).
8848 gtk_text_view_buffer_to_window_coords (GtkTextView *text_view,
8849 GtkTextWindowType win,
8855 GtkTextViewPrivate *priv = text_view->priv;
8857 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
8861 case GTK_TEXT_WINDOW_WIDGET:
8862 buffer_to_widget (text_view,
8864 window_x, window_y);
8867 case GTK_TEXT_WINDOW_TEXT:
8869 *window_x = buffer_x - priv->xoffset;
8871 *window_y = buffer_y - priv->yoffset;
8874 case GTK_TEXT_WINDOW_LEFT:
8875 buffer_to_text_window (text_view,
8878 window_x, window_y);
8881 case GTK_TEXT_WINDOW_RIGHT:
8882 buffer_to_text_window (text_view,
8885 window_x, window_y);
8888 case GTK_TEXT_WINDOW_TOP:
8889 buffer_to_text_window (text_view,
8892 window_x, window_y);
8895 case GTK_TEXT_WINDOW_BOTTOM:
8896 buffer_to_text_window (text_view,
8897 priv->bottom_window,
8899 window_x, window_y);
8902 case GTK_TEXT_WINDOW_PRIVATE:
8903 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
8907 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
8913 widget_to_buffer (GtkTextView *text_view,
8919 GtkTextViewPrivate *priv = text_view->priv;
8923 *buffer_x = widget_x + priv->xoffset;
8924 *buffer_x -= priv->text_window->allocation.x;
8929 *buffer_y = widget_y + priv->yoffset;
8930 *buffer_y -= priv->text_window->allocation.y;
8935 text_window_to_widget (GtkTextWindow *win,
8942 *widget_x = window_x + win->allocation.x;
8945 *widget_y = window_y + win->allocation.y;
8949 text_window_to_buffer (GtkTextView *text_view,
8958 g_warning ("Attempt to convert GtkTextView buffer coordinates into "
8959 "coordinates for a nonexistent child window.");
8963 text_window_to_widget (win,
8969 widget_to_buffer (text_view,
8970 buffer_x ? *buffer_x : 0,
8971 buffer_y ? *buffer_y : 0,
8977 * gtk_text_view_window_to_buffer_coords:
8978 * @text_view: a #GtkTextView
8979 * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
8980 * @window_x: window x coordinate
8981 * @window_y: window y coordinate
8982 * @buffer_x: (out) (allow-none): buffer x coordinate return location or %NULL
8983 * @buffer_y: (out) (allow-none): buffer y coordinate return location or %NULL
8985 * Converts coordinates on the window identified by @win to buffer
8986 * coordinates, storing the result in (@buffer_x,@buffer_y).
8988 * Note that you can't convert coordinates for a nonexisting window (see
8989 * gtk_text_view_set_border_window_size()).
8992 gtk_text_view_window_to_buffer_coords (GtkTextView *text_view,
8993 GtkTextWindowType win,
8999 GtkTextViewPrivate *priv = text_view->priv;
9001 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9005 case GTK_TEXT_WINDOW_WIDGET:
9006 widget_to_buffer (text_view,
9008 buffer_x, buffer_y);
9011 case GTK_TEXT_WINDOW_TEXT:
9013 *buffer_x = window_x + priv->xoffset;
9015 *buffer_y = window_y + priv->yoffset;
9018 case GTK_TEXT_WINDOW_LEFT:
9019 text_window_to_buffer (text_view,
9022 buffer_x, buffer_y);
9025 case GTK_TEXT_WINDOW_RIGHT:
9026 text_window_to_buffer (text_view,
9029 buffer_x, buffer_y);
9032 case GTK_TEXT_WINDOW_TOP:
9033 text_window_to_buffer (text_view,
9036 buffer_x, buffer_y);
9039 case GTK_TEXT_WINDOW_BOTTOM:
9040 text_window_to_buffer (text_view,
9041 priv->bottom_window,
9043 buffer_x, buffer_y);
9046 case GTK_TEXT_WINDOW_PRIVATE:
9047 g_warning ("%s: can't get coords for private windows", G_STRFUNC);
9051 g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
9057 set_window_width (GtkTextView *text_view,
9059 GtkTextWindowType type,
9060 GtkTextWindow **winp)
9066 text_window_free (*winp);
9068 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9075 *winp = text_window_new (type,
9076 GTK_WIDGET (text_view),
9078 /* if the widget is already realized we need to realize the child manually */
9079 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9080 text_window_realize (*winp, GTK_WIDGET (text_view));
9084 if ((*winp)->requisition.width == width)
9087 (*winp)->requisition.width = width;
9090 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9096 set_window_height (GtkTextView *text_view,
9098 GtkTextWindowType type,
9099 GtkTextWindow **winp)
9105 text_window_free (*winp);
9107 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9114 *winp = text_window_new (type,
9115 GTK_WIDGET (text_view),
9118 /* if the widget is already realized we need to realize the child manually */
9119 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9120 text_window_realize (*winp, GTK_WIDGET (text_view));
9124 if ((*winp)->requisition.height == height)
9127 (*winp)->requisition.height = height;
9130 gtk_widget_queue_resize (GTK_WIDGET (text_view));
9135 * gtk_text_view_set_border_window_size:
9136 * @text_view: a #GtkTextView
9137 * @type: window to affect
9138 * @size: width or height of the window
9140 * Sets the width of %GTK_TEXT_WINDOW_LEFT or %GTK_TEXT_WINDOW_RIGHT,
9141 * or the height of %GTK_TEXT_WINDOW_TOP or %GTK_TEXT_WINDOW_BOTTOM.
9142 * Automatically destroys the corresponding window if the size is set
9143 * to 0, and creates the window if the size is set to non-zero. This
9144 * function can only be used for the "border windows," it doesn't work
9145 * with #GTK_TEXT_WINDOW_WIDGET, #GTK_TEXT_WINDOW_TEXT, or
9146 * #GTK_TEXT_WINDOW_PRIVATE.
9149 gtk_text_view_set_border_window_size (GtkTextView *text_view,
9150 GtkTextWindowType type,
9153 GtkTextViewPrivate *priv = text_view->priv;
9155 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9156 g_return_if_fail (size >= 0);
9160 case GTK_TEXT_WINDOW_LEFT:
9161 set_window_width (text_view, size, GTK_TEXT_WINDOW_LEFT,
9162 &priv->left_window);
9165 case GTK_TEXT_WINDOW_RIGHT:
9166 set_window_width (text_view, size, GTK_TEXT_WINDOW_RIGHT,
9167 &priv->right_window);
9170 case GTK_TEXT_WINDOW_TOP:
9171 set_window_height (text_view, size, GTK_TEXT_WINDOW_TOP,
9175 case GTK_TEXT_WINDOW_BOTTOM:
9176 set_window_height (text_view, size, GTK_TEXT_WINDOW_BOTTOM,
9177 &priv->bottom_window);
9181 g_warning ("Can only set size of left/right/top/bottom border windows with gtk_text_view_set_border_window_size()");
9187 * gtk_text_view_get_border_window_size:
9188 * @text_view: a #GtkTextView
9189 * @type: window to return size from
9191 * Gets the width of the specified border window. See
9192 * gtk_text_view_set_border_window_size().
9194 * Return value: width of window
9197 gtk_text_view_get_border_window_size (GtkTextView *text_view,
9198 GtkTextWindowType type)
9200 GtkTextViewPrivate *priv = text_view->priv;
9202 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
9206 case GTK_TEXT_WINDOW_LEFT:
9207 if (priv->left_window)
9208 return priv->left_window->requisition.width;
9211 case GTK_TEXT_WINDOW_RIGHT:
9212 if (priv->right_window)
9213 return priv->right_window->requisition.width;
9216 case GTK_TEXT_WINDOW_TOP:
9217 if (priv->top_window)
9218 return priv->top_window->requisition.height;
9221 case GTK_TEXT_WINDOW_BOTTOM:
9222 if (priv->bottom_window)
9223 return priv->bottom_window->requisition.height;
9227 g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size()");
9238 static GtkTextViewChild*
9239 text_view_child_new_anchored (GtkWidget *child,
9240 GtkTextChildAnchor *anchor,
9241 GtkTextLayout *layout)
9243 GtkTextViewChild *vc;
9245 vc = g_new (GtkTextViewChild, 1);
9247 vc->type = GTK_TEXT_WINDOW_PRIVATE;
9249 vc->anchor = anchor;
9251 vc->from_top_of_line = 0;
9252 vc->from_left_of_buffer = 0;
9254 g_object_ref (vc->widget);
9255 g_object_ref (vc->anchor);
9257 g_object_set_data (G_OBJECT (child),
9258 I_("gtk-text-view-child"),
9261 gtk_text_child_anchor_register_child (anchor, child, layout);
9266 static GtkTextViewChild*
9267 text_view_child_new_window (GtkWidget *child,
9268 GtkTextWindowType type,
9272 GtkTextViewChild *vc;
9274 vc = g_new (GtkTextViewChild, 1);
9279 vc->from_top_of_line = 0;
9280 vc->from_left_of_buffer = 0;
9282 g_object_ref (vc->widget);
9288 g_object_set_data (G_OBJECT (child),
9289 I_("gtk-text-view-child"),
9296 text_view_child_free (GtkTextViewChild *child)
9298 g_object_set_data (G_OBJECT (child->widget),
9299 I_("gtk-text-view-child"), NULL);
9303 gtk_text_child_anchor_unregister_child (child->anchor,
9305 g_object_unref (child->anchor);
9308 g_object_unref (child->widget);
9314 text_view_child_set_parent_window (GtkTextView *text_view,
9315 GtkTextViewChild *vc)
9318 gtk_widget_set_parent_window (vc->widget,
9319 text_view->priv->text_window->bin_window);
9323 window = gtk_text_view_get_window (text_view,
9325 gtk_widget_set_parent_window (vc->widget, window);
9330 add_child (GtkTextView *text_view,
9331 GtkTextViewChild *vc)
9333 text_view->priv->children = g_slist_prepend (text_view->priv->children,
9336 if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
9337 text_view_child_set_parent_window (text_view, vc);
9339 gtk_widget_set_parent (vc->widget, GTK_WIDGET (text_view));
9343 * gtk_text_view_add_child_at_anchor:
9344 * @text_view: a #GtkTextView
9345 * @child: a #GtkWidget
9346 * @anchor: a #GtkTextChildAnchor in the #GtkTextBuffer for @text_view
9348 * Adds a child widget in the text buffer, at the given @anchor.
9351 gtk_text_view_add_child_at_anchor (GtkTextView *text_view,
9353 GtkTextChildAnchor *anchor)
9355 GtkTextViewChild *vc;
9357 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9358 g_return_if_fail (GTK_IS_WIDGET (child));
9359 g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
9360 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
9362 gtk_text_view_ensure_layout (text_view);
9364 vc = text_view_child_new_anchored (child, anchor,
9365 text_view->priv->layout);
9367 add_child (text_view, vc);
9369 g_assert (vc->widget == child);
9370 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9374 * gtk_text_view_add_child_in_window:
9375 * @text_view: a #GtkTextView
9376 * @child: a #GtkWidget
9377 * @which_window: which window the child should appear in
9378 * @xpos: X position of child in window coordinates
9379 * @ypos: Y position of child in window coordinates
9381 * Adds a child at fixed coordinates in one of the text widget's
9382 * windows. The window must have nonzero size (see
9383 * gtk_text_view_set_border_window_size()). Note that the child
9384 * coordinates are given relative to the #GdkWindow in question, and
9385 * that these coordinates have no sane relationship to scrolling. When
9386 * placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
9387 * irrelevant, the child floats above all scrollable areas. But when
9388 * placing a child in one of the scrollable windows (border windows or
9389 * text window), you'll need to compute the child's correct position
9390 * in buffer coordinates any time scrolling occurs or buffer changes
9391 * occur, and then call gtk_text_view_move_child() to update the
9392 * child's position. Unfortunately there's no good way to detect that
9393 * scrolling has occurred, using the current API; a possible hack
9394 * would be to update all child positions when the scroll adjustments
9395 * change or the text buffer changes. See bug 64518 on
9396 * bugzilla.gnome.org for status of fixing this issue.
9399 gtk_text_view_add_child_in_window (GtkTextView *text_view,
9401 GtkTextWindowType which_window,
9405 GtkTextViewChild *vc;
9407 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9408 g_return_if_fail (GTK_IS_WIDGET (child));
9409 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
9411 vc = text_view_child_new_window (child, which_window,
9414 add_child (text_view, vc);
9416 g_assert (vc->widget == child);
9417 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9421 * gtk_text_view_move_child:
9422 * @text_view: a #GtkTextView
9423 * @child: child widget already added to the text view
9424 * @xpos: new X position in window coordinates
9425 * @ypos: new Y position in window coordinates
9427 * Updates the position of a child, as for gtk_text_view_add_child_in_window().
9430 gtk_text_view_move_child (GtkTextView *text_view,
9435 GtkTextViewChild *vc;
9437 g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
9438 g_return_if_fail (GTK_IS_WIDGET (child));
9439 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
9441 vc = g_object_get_data (G_OBJECT (child),
9442 "gtk-text-view-child");
9444 g_assert (vc != NULL);
9446 if (vc->x == xpos &&
9453 if (gtk_widget_get_visible (child) &&
9454 gtk_widget_get_visible (GTK_WIDGET (text_view)))
9455 gtk_widget_queue_resize (child);
9459 /* Iterator operations */
9462 * gtk_text_view_forward_display_line:
9463 * @text_view: a #GtkTextView
9464 * @iter: a #GtkTextIter
9466 * Moves the given @iter forward by one display (wrapped) line.
9467 * A display line is different from a paragraph. Paragraphs are
9468 * separated by newlines or other paragraph separator characters.
9469 * Display lines are created by line-wrapping a paragraph. If
9470 * wrapping is turned off, display lines and paragraphs will be the
9471 * same. Display lines are divided differently for each view, since
9472 * they depend on the view's width; paragraphs are the same in all
9473 * views, since they depend on the contents of the #GtkTextBuffer.
9475 * Return value: %TRUE if @iter was moved and is not on the end iterator
9478 gtk_text_view_forward_display_line (GtkTextView *text_view,
9481 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9482 g_return_val_if_fail (iter != NULL, FALSE);
9484 gtk_text_view_ensure_layout (text_view);
9486 return gtk_text_layout_move_iter_to_next_line (text_view->priv->layout, iter);
9490 * gtk_text_view_backward_display_line:
9491 * @text_view: a #GtkTextView
9492 * @iter: a #GtkTextIter
9494 * Moves the given @iter backward by one display (wrapped) line.
9495 * A display line is different from a paragraph. Paragraphs are
9496 * separated by newlines or other paragraph separator characters.
9497 * Display lines are created by line-wrapping a paragraph. If
9498 * wrapping is turned off, display lines and paragraphs will be the
9499 * same. Display lines are divided differently for each view, since
9500 * they depend on the view's width; paragraphs are the same in all
9501 * views, since they depend on the contents of the #GtkTextBuffer.
9503 * Return value: %TRUE if @iter was moved and is not on the end iterator
9506 gtk_text_view_backward_display_line (GtkTextView *text_view,
9509 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9510 g_return_val_if_fail (iter != NULL, FALSE);
9512 gtk_text_view_ensure_layout (text_view);
9514 return gtk_text_layout_move_iter_to_previous_line (text_view->priv->layout, iter);
9518 * gtk_text_view_forward_display_line_end:
9519 * @text_view: a #GtkTextView
9520 * @iter: a #GtkTextIter
9522 * Moves the given @iter forward to the next display line end.
9523 * A display line is different from a paragraph. Paragraphs are
9524 * separated by newlines or other paragraph separator characters.
9525 * Display lines are created by line-wrapping a paragraph. If
9526 * wrapping is turned off, display lines and paragraphs will be the
9527 * same. Display lines are divided differently for each view, since
9528 * they depend on the view's width; paragraphs are the same in all
9529 * views, since they depend on the contents of the #GtkTextBuffer.
9531 * Return value: %TRUE if @iter was moved and is not on the end iterator
9534 gtk_text_view_forward_display_line_end (GtkTextView *text_view,
9537 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9538 g_return_val_if_fail (iter != NULL, FALSE);
9540 gtk_text_view_ensure_layout (text_view);
9542 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, 1);
9546 * gtk_text_view_backward_display_line_start:
9547 * @text_view: a #GtkTextView
9548 * @iter: a #GtkTextIter
9550 * Moves the given @iter backward to the next display line start.
9551 * A display line is different from a paragraph. Paragraphs are
9552 * separated by newlines or other paragraph separator characters.
9553 * Display lines are created by line-wrapping a paragraph. If
9554 * wrapping is turned off, display lines and paragraphs will be the
9555 * same. Display lines are divided differently for each view, since
9556 * they depend on the view's width; paragraphs are the same in all
9557 * views, since they depend on the contents of the #GtkTextBuffer.
9559 * Return value: %TRUE if @iter was moved and is not on the end iterator
9562 gtk_text_view_backward_display_line_start (GtkTextView *text_view,
9565 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9566 g_return_val_if_fail (iter != NULL, FALSE);
9568 gtk_text_view_ensure_layout (text_view);
9570 return gtk_text_layout_move_iter_to_line_end (text_view->priv->layout, iter, -1);
9574 * gtk_text_view_starts_display_line:
9575 * @text_view: a #GtkTextView
9576 * @iter: a #GtkTextIter
9578 * Determines whether @iter is at the start of a display line.
9579 * See gtk_text_view_forward_display_line() for an explanation of
9580 * display lines vs. paragraphs.
9582 * Return value: %TRUE if @iter begins a wrapped line
9585 gtk_text_view_starts_display_line (GtkTextView *text_view,
9586 const GtkTextIter *iter)
9588 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9589 g_return_val_if_fail (iter != NULL, FALSE);
9591 gtk_text_view_ensure_layout (text_view);
9593 return gtk_text_layout_iter_starts_line (text_view->priv->layout, iter);
9597 * gtk_text_view_move_visually:
9598 * @text_view: a #GtkTextView
9599 * @iter: a #GtkTextIter
9600 * @count: number of characters to move (negative moves left,
9601 * positive moves right)
9603 * Move the iterator a given number of characters visually, treating
9604 * it as the strong cursor position. If @count is positive, then the
9605 * new strong cursor position will be @count positions to the right of
9606 * the old cursor position. If @count is negative then the new strong
9607 * cursor position will be @count positions to the left of the old
9610 * In the presence of bi-directional text, the correspondence
9611 * between logical and visual order will depend on the direction
9612 * of the current run, and there may be jumps when the cursor
9613 * is moved off of the end of a run.
9615 * Return value: %TRUE if @iter moved and is not on the end iterator
9618 gtk_text_view_move_visually (GtkTextView *text_view,
9622 g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
9623 g_return_val_if_fail (iter != NULL, FALSE);
9625 gtk_text_view_ensure_layout (text_view);
9627 return gtk_text_layout_move_iter_visually (text_view->priv->layout, iter, count);