+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* GTK - The GIMP Toolkit
* gtktextview.c Copyright (C) 2000 Red Hat, Inc.
*
#include <config.h>
#include <string.h>
-#include "gtkalias.h"
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
#include "gtkstock.h"
+#include "gtktextbufferrichtext.h"
#include "gtktextdisplay.h"
#include "gtktextview.h"
#include "gtkimmulticontext.h"
#include "gdk/gdkkeysyms.h"
#include "gtkprivate.h"
-#include "gtksizegroup.h" /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
#include "gtktextutil.h"
#include "gtkwindow.h"
+#include "gtkalias.h"
/* How scrolling, validation, exposes, etc. work.
*
#define SPACE_FOR_CURSOR 1
+typedef struct _GtkTextViewPrivate GtkTextViewPrivate;
+
+#define GTK_TEXT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewPrivate))
+
+struct _GtkTextViewPrivate
+{
+ guint blink_time; /* time in msec the cursor has blinked since last user event */
+ guint im_spot_idle;
+};
+
+
struct _GtkTextPendingScroll
{
GtkTextMark *mark;
COPY_CLIPBOARD,
PASTE_CLIPBOARD,
TOGGLE_OVERWRITE,
- MOVE_FOCUS,
MOVE_VIEWPORT,
SELECT_ALL,
+ TOGGLE_CURSOR_VISIBLE,
LAST_SIGNAL
};
LAST_PROP
};
-static void gtk_text_view_init (GtkTextView *text_view);
-static void gtk_text_view_class_init (GtkTextViewClass *klass);
static void gtk_text_view_destroy (GtkObject *object);
static void gtk_text_view_finalize (GObject *object);
static void gtk_text_view_set_property (GObject *object,
static void gtk_text_view_draw_focus (GtkWidget *widget);
static gboolean gtk_text_view_focus (GtkWidget *widget,
GtkDirectionType direction);
+static void gtk_text_view_move_focus (GtkWidget *widget,
+ GtkDirectionType direction_type);
static void gtk_text_view_select_all (GtkWidget *widget,
gboolean select);
static void gtk_text_view_page_horizontally (GtkTextView *text_view,
gint count,
gboolean extend_selection);
-static void gtk_text_view_move_viewport (GtkTextView *text_view,
+static gboolean gtk_text_view_move_viewport (GtkTextView *text_view,
GtkScrollStep step,
gint count);
static void gtk_text_view_set_anchor (GtkTextView *text_view);
-static void gtk_text_view_scroll_pages (GtkTextView *text_view,
+static gboolean gtk_text_view_scroll_pages (GtkTextView *text_view,
gint count,
gboolean extend_selection);
-static void gtk_text_view_scroll_hpages (GtkTextView *text_view,
+static gboolean gtk_text_view_scroll_hpages(GtkTextView *text_view,
gint count,
gboolean extend_selection);
static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
static void gtk_text_view_copy_clipboard (GtkTextView *text_view);
static void gtk_text_view_paste_clipboard (GtkTextView *text_view);
static void gtk_text_view_toggle_overwrite (GtkTextView *text_view);
-static void gtk_text_view_move_focus (GtkTextView *text_view,
+static void gtk_text_view_toggle_cursor_visible (GtkTextView *text_view);
+static void gtk_text_view_compat_move_focus(GtkTextView *text_view,
GtkDirectionType direction_type);
static void gtk_text_view_unselect (GtkTextView *text_view);
static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event);
-static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view,
- GdkEventButton *event);
+static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view);
static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventMotion *event);
static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
+static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
static void gtk_text_view_value_changed (GtkAdjustment *adj,
GtkTextView *view);
const GtkTextIter *location,
GtkTextMark *mark,
gpointer data);
+static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
+ const GParamSpec *pspec,
+ gpointer data);
static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
GdkRectangle *pos);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
gint height_request);
static void text_window_free (GtkTextWindow *win);
static void text_window_realize (GtkTextWindow *win,
- GdkWindow *parent);
+ GtkWidget *widget);
static void text_window_unrealize (GtkTextWindow *win);
static void text_window_size_allocate (GtkTextWindow *win,
GdkRectangle *rect);
gint dy);
static void text_window_invalidate_rect (GtkTextWindow *win,
GdkRectangle *rect);
+static void text_window_invalidate_cursors (GtkTextWindow *win);
static gint text_window_get_width (GtkTextWindow *win);
static gint text_window_get_height (GtkTextWindow *win);
-static GtkTargetEntry target_table[] = {
- { "GTK_TEXT_BUFFER_CONTENTS", GTK_TARGET_SAME_APP, 0 },
-};
-
-static GtkContainerClass *parent_class = NULL;
static guint signals[LAST_SIGNAL] = { 0 };
-GType
-gtk_text_view_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- {
- static const GTypeInfo our_info =
- {
- sizeof (GtkTextViewClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_text_view_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkTextView),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_text_view_init,
- };
-
- our_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTextView",
- &our_info, 0);
- }
-
- return our_type;
-}
+G_DEFINE_TYPE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER)
static void
add_move_binding (GtkBindingSet *binding_set,
GtkMovementStep step,
gint count)
{
- g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
+ g_assert ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move_cursor", 3,
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
- parent_class = g_type_class_peek_parent (klass);
-
/* Default handlers and virtual methods
*/
gobject_class->set_property = gtk_text_view_set_property;
widget_class->motion_notify_event = gtk_text_view_motion_event;
widget_class->expose_event = gtk_text_view_expose_event;
widget_class->focus = gtk_text_view_focus;
-
+
+ /* need to override the base class function via override_class_closure,
+ * because the signal slot is not available in GtkWidgetCLass
+ */
+ g_signal_override_class_closure (g_signal_lookup ("move-focus",
+ GTK_TYPE_WIDGET),
+ GTK_TYPE_TEXT_VIEW,
+ g_cclosure_new (G_CALLBACK (gtk_text_view_move_focus),
+ NULL, NULL));
+
widget_class->drag_begin = gtk_text_view_drag_begin;
widget_class->drag_end = gtk_text_view_drag_end;
widget_class->drag_data_get = gtk_text_view_drag_data_get;
klass->copy_clipboard = gtk_text_view_copy_clipboard;
klass->paste_clipboard = gtk_text_view_paste_clipboard;
klass->toggle_overwrite = gtk_text_view_toggle_overwrite;
- klass->move_focus = gtk_text_view_move_focus;
+ klass->move_focus = gtk_text_view_compat_move_focus;
klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
/*
g_object_class_install_property (gobject_class,
PROP_PIXELS_ABOVE_LINES,
- g_param_spec_int ("pixels_above_lines",
+ g_param_spec_int ("pixels-above-lines",
P_("Pixels Above Lines"),
P_("Pixels of blank space above paragraphs"),
0,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PIXELS_BELOW_LINES,
- g_param_spec_int ("pixels_below_lines",
+ g_param_spec_int ("pixels-below-lines",
P_("Pixels Below Lines"),
P_("Pixels of blank space below paragraphs"),
0,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PIXELS_INSIDE_WRAP,
- g_param_spec_int ("pixels_inside_wrap",
+ g_param_spec_int ("pixels-inside-wrap",
P_("Pixels Inside Wrap"),
P_("Pixels of blank space between wrapped lines in a paragraph"),
0,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_EDITABLE,
P_("Editable"),
P_("Whether the text can be modified by the user"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_WRAP_MODE,
- g_param_spec_enum ("wrap_mode",
+ g_param_spec_enum ("wrap-mode",
P_("Wrap Mode"),
P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
GTK_TYPE_WRAP_MODE,
GTK_WRAP_NONE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_JUSTIFICATION,
P_("Left, right, or center justification"),
GTK_TYPE_JUSTIFICATION,
GTK_JUSTIFY_LEFT,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LEFT_MARGIN,
- g_param_spec_int ("left_margin",
+ g_param_spec_int ("left-margin",
P_("Left Margin"),
P_("Width of the left margin in pixels"),
0,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_RIGHT_MARGIN,
- g_param_spec_int ("right_margin",
+ g_param_spec_int ("right-margin",
P_("Right Margin"),
P_("Width of the right margin in pixels"),
0,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_INDENT,
g_param_spec_int ("indent",
P_("Indent"),
P_("Amount to indent the paragraph, in pixels"),
- 0,
+ G_MININT,
G_MAXINT,
0,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TABS,
P_("Tabs"),
P_("Custom tabs for this text"),
PANGO_TYPE_TAB_ARRAY,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_CURSOR_VISIBLE,
- g_param_spec_boolean ("cursor_visible",
+ g_param_spec_boolean ("cursor-visible",
P_("Cursor Visible"),
P_("If the insertion cursor is shown"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_BUFFER,
P_("Buffer"),
P_("The buffer which is displayed"),
GTK_TYPE_TEXT_BUFFER,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_OVERWRITE,
P_("Overwrite mode"),
P_("Whether entered text overwrites existing contents"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ACCEPTS_TAB,
- g_param_spec_boolean ("accepts_tab",
+ g_param_spec_boolean ("accepts-tab",
P_("Accepts tab"),
P_("Whether Tab will result in a tab character being entered"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/*
* Style properties
P_("Error underline color"),
P_("Color with which to draw error-indication underlines"),
GDK_TYPE_COLOR,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
/*
* Signals
/**
* GtkTextView::move-cursor:
- * @widget: the object which received the signal
+ * @text_view: the object which received the signal
* @step: the granularity of the move, as a #GtkMovementStep
* @count: the number of @step units to move
* @extend_selection: %TRUE if the move should extend the selection
*
- * The ::move-cursor signal is a keybinding signal which gets emitted
- * when the user initiates a cursor movement.
+ * The ::move-cursor signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted when the user initiates a cursor movement.
+ * If the cursor is not visible in @text_view, this signal causes
+ * the viewport to be moved instead.
*
* Applications should not connect to it, but may emit it with
* g_signal_emit_by_name() if they need to control scrolling
* programmatically.
*
+ * The default bindings for this signal come in two variants,
+ * the variant with the Shift modifier extends the selection,
+ * the variant without the Shift modifer does not.
+ * There are too many key combinations to list them all here.
+ * <itemizedlist>
+ * <listitem>Arrow keys move by individual characters/lines</listitem>
+ * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
+ * <listitem>Home/End keys move to the ends of the buffer</listitem>
+ * <listitem>PageUp/PageDown keys move vertically by pages</listitem>
+ * <listitem>Ctrl-PageUp/PageDown keys move horizontally by pages</listitem>
+ * </itemizedlist>
*/
signals[MOVE_CURSOR] =
- g_signal_new ("move_cursor",
+ g_signal_new (I_("move_cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
G_TYPE_INT,
G_TYPE_BOOLEAN);
+ /**
+ * GtkTextView::page-horizontally:
+ * @text_view: the object which received the signal
+ * @count: the number of @step units to move
+ * @extend_selection: %TRUE if the move should extend the selection
+ *
+ * The ::page-horizontally signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which can be bound to key combinations to allow the user
+ * to initiate horizontal cursor movement by pages.
+ *
+ * This signal should not be used anymore, instead use the
+ * #GtkTextview::move-cursor signal with the #GTK_MOVEMENT_HORIZONTAL_PAGES
+ * granularity.
+ */
signals[PAGE_HORIZONTALLY] =
- g_signal_new ("page_horizontally",
+ g_signal_new (I_("page_horizontally"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, page_horizontally),
G_TYPE_INT,
G_TYPE_BOOLEAN);
+ /**
+ * GtkTextView::move-viewport:
+ * @text_view: the object which received the signal
+ * @step: the granularity of the move, as a #GtkMovementStep
+ * @count: the number of @step units to move
+ *
+ * The ::move-viewport signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which can be bound to key combinations to allow the user
+ * to move the viewport, i.e. change what part of the text view
+ * is visible in a containing scrolled window.
+ *
+ * There are no default bindings for this signal.
+ */
signals[MOVE_VIEWPORT] =
- _gtk_binding_signal_new ("move_viewport",
+ _gtk_binding_signal_new (I_("move_viewport"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_CALLBACK (gtk_text_view_move_viewport),
G_TYPE_INT);
signals[SET_ANCHOR] =
- g_signal_new ("set_anchor",
+ g_signal_new (I_("set_anchor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
G_TYPE_NONE, 0);
signals[INSERT_AT_CURSOR] =
- g_signal_new ("insert_at_cursor",
+ g_signal_new (I_("insert_at_cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
G_TYPE_NONE, 1,
G_TYPE_STRING);
+ /**
+ * GtkTextView::delete-from-cursor:
+ * @text_view: the object which received the signal
+ * @type: the granularity of the deletion, as a #GtkDeleteType
+ * @count: the number of @type units to delete
+ *
+ * The ::delete-from-cursor signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted when the user initiates a text deletion.
+ *
+ * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
+ * if there is one, otherwise it deletes the requested number
+ * of characters.
+ *
+ * The default bindings for this signal are
+ * Delete for deleting a character, Ctrl-Delete for
+ * deleting a word and Ctrl-Backspace for deleting a word
+ * backwords.
+ */
signals[DELETE_FROM_CURSOR] =
- g_signal_new ("delete_from_cursor",
+ g_signal_new (I_("delete_from_cursor"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
GTK_TYPE_DELETE_TYPE,
G_TYPE_INT);
+ /**
+ * GtkTextView::backspace:
+ * @text_view: the object which received the signal
+ *
+ * The ::backspace signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted when the user asks for it.
+ *
+ * The default bindings for this signal are
+ * Backspace and Shift-Backspace.
+ */
signals[BACKSPACE] =
- g_signal_new ("backspace",
+ g_signal_new (I_("backspace"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, backspace),
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ /**
+ * GtkTextView::cut-clipboard:
+ * @text_view: the object which received the signal
+ *
+ * The ::cut-clipboard signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to cut the selection to the clipboard.
+ *
+ * The default bindings for this signal are
+ * Ctrl-x and Shift-Delete.
+ */
signals[CUT_CLIPBOARD] =
- g_signal_new ("cut_clipboard",
+ g_signal_new (I_("cut_clipboard"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ /**
+ * GtkTextView::copy-clipboard:
+ * @text_view: the object which received the signal
+ *
+ * The ::copy-clipboard signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to copy the selection to the clipboard.
+ *
+ * The default bindings for this signal are
+ * Ctrl-c and Ctrl-Insert.
+ */
signals[COPY_CLIPBOARD] =
- g_signal_new ("copy_clipboard",
+ g_signal_new (I_("copy_clipboard"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, copy_clipboard),
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ /**
+ * GtkTextView::paste-clipboard:
+ * @text_view: the object which received the signal
+ *
+ * The ::paste-clipboard signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to paste the contents of the clipboard
+ * into the text view.
+ *
+ * The default bindings for this signal are
+ * Ctrl-v and Shift-Insert.
+ */
signals[PASTE_CLIPBOARD] =
- g_signal_new ("paste_clipboard",
+ g_signal_new (I_("paste_clipboard"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, paste_clipboard),
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ /**
+ * GtkTextView::toggle-overwrite:
+ * @text_view: the object which received the signal
+ *
+ * The ::toggle-overwrite signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to change the editability of the text view.
+ *
+ * The default bindings for this signal is Insert.
+ */
signals[TOGGLE_OVERWRITE] =
- g_signal_new ("toggle_overwrite",
+ g_signal_new (I_("toggle_overwrite"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, toggle_overwrite),
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- signals[MOVE_FOCUS] =
- g_signal_new ("move_focus",
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GtkTextViewClass, move_focus),
- NULL, NULL,
- _gtk_marshal_VOID__ENUM,
- G_TYPE_NONE, 1,
- GTK_TYPE_DIRECTION_TYPE);
-
signals[SET_SCROLL_ADJUSTMENTS] =
- g_signal_new ("set_scroll_adjustments",
+ g_signal_new (I_("set_scroll_adjustments"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments),
widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
signals[POPULATE_POPUP] =
- g_signal_new ("populate_popup",
+ g_signal_new (I_("populate_popup"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkTextViewClass, populate_popup),
G_TYPE_NONE, 1,
GTK_TYPE_MENU);
+ /**
+ * GtkTextView::select-all:
+ * @text_view: the object which received the signal
+ * @select: %TRUE to select, %FALSE to unselect
+ *
+ * The ::select-all signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to select or unselect the complete
+ * contents of the text view.
+ *
+ * The default bindings for this signal are Ctrl-a and Ctrl-/
+ * for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
+ */
signals[SELECT_ALL] =
- _gtk_binding_signal_new ("select_all",
+ _gtk_binding_signal_new (I_("select_all"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_CALLBACK (gtk_text_view_select_all),
NULL, NULL,
_gtk_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1,
- G_TYPE_BOOLEAN, TRUE);
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ /**
+ * GtkTextView::toggle-cursor-visible:
+ * @text_view: the object which received the signal
+ *
+ * The ::toggle-cursor-visible signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted to toggle the visibility of the cursor.
+ *
+ * The default binding for this signal is F7.
+ */
+ signals[TOGGLE_CURSOR_VISIBLE] =
+ _gtk_binding_signal_new (I_("toggle_cursor_visible"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (gtk_text_view_toggle_cursor_visible),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
-
/*
* Key bindings
*/
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
- GTK_MOVEMENT_WORDS, 1);
+ GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
"select_all", 1,
G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "select_all", 1,
+ G_TYPE_BOOLEAN, FALSE);
+
/* Deleting text */
gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
"delete_from_cursor", 2,
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
"toggle_overwrite", 0);
+ /* Caret mode */
+ gtk_binding_entry_add_signal (binding_set, GDK_F7, 0,
+ "toggle_cursor_visible", 0);
+
/* Control-tab focus motion */
gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_CONTROL_MASK,
"move_focus", 1,
gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move_focus", 1,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
+
+ g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
}
static void
gtk_text_view_init (GtkTextView *text_view)
{
- GtkWidget *widget;
-
- widget = GTK_WIDGET (text_view);
+ GtkWidget *widget = GTK_WIDGET (text_view);
+ GtkTargetList *target_list;
GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
text_view->tabs = NULL;
text_view->editable = TRUE;
- gtk_drag_dest_set (widget,
- 0,
- target_table, G_N_ELEMENTS (target_table),
+ gtk_drag_dest_set (widget, 0, NULL, 0,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
- gtk_drag_dest_add_text_targets (widget);
+
+ target_list = gtk_target_list_new (NULL, 0);
+ gtk_drag_dest_set_target_list (widget, target_list);
+ gtk_target_list_unref (target_list);
text_view->virtual_cursor_x = -1;
text_view->virtual_cursor_y = -1;
*
* Creates a new #GtkTextView widget displaying the buffer
* @buffer. One buffer can be shared among many widgets.
- * @buffer may be NULL to create a default buffer, in which case
+ * @buffer may be %NULL to create a default buffer, in which case
* this function is equivalent to gtk_text_view_new(). The
* text view adds its own reference count to the buffer; it does not
* take over an existing reference.
* added to @buffer. If you owned a reference to @buffer before passing it
* to this function, you must remove that reference yourself; #GtkTextView
* will not "adopt" it.
- *
**/
void
gtk_text_view_set_buffer (GtkTextView *text_view,
g_signal_handlers_disconnect_by_func (text_view->buffer,
gtk_text_view_mark_set_handler,
text_view);
+ g_signal_handlers_disconnect_by_func (text_view->buffer,
+ gtk_text_view_target_list_notify,
+ text_view);
g_object_unref (text_view->buffer);
text_view->dnd_mark = NULL;
+ text_view->first_para_mark = NULL;
if (GTK_WIDGET_REALIZED (text_view))
{
text_view->first_para_pixels = 0;
g_signal_connect (text_view->buffer, "mark_set",
- G_CALLBACK (gtk_text_view_mark_set_handler), text_view);
+ G_CALLBACK (gtk_text_view_mark_set_handler),
+ text_view);
+ g_signal_connect (text_view->buffer, "notify::paste-target-list",
+ G_CALLBACK (gtk_text_view_target_list_notify),
+ text_view);
+
+ gtk_text_view_target_list_notify (text_view->buffer, NULL, text_view);
if (GTK_WIDGET_REALIZED (text_view))
{
* currently-displayed portion. If you have coordinates from an
* event, you have to convert those to buffer coordinates with
* gtk_text_view_window_to_buffer_coords().
- *
**/
void
gtk_text_view_get_iter_at_location (GtkTextView *text_view,
gtk_text_view_ensure_layout (text_view);
gtk_text_layout_get_iter_at_pixel (text_view->layout,
- iter,
- x,
- y);
+ iter, x, y);
+}
+
+/**
+ * gtk_text_view_get_iter_at_position:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * @trailing: location to store an integer indicating where
+ * in the grapheme the user clicked. It will either be
+ * zero, or the number of characters in the grapheme.
+ * 0 represents the trailing edge of the grapheme.
+ * @x: x position, in buffer coordinates
+ * @y: y position, in buffer coordinates
+ *
+ * Retrieves the iterator pointing to the character at buffer
+ * coordinates @x and @y. Buffer coordinates are coordinates for
+ * the entire buffer, not just the currently-displayed portion.
+ * If you have coordinates from an event, you have to convert
+ * those to buffer coordinates with
+ * gtk_text_view_window_to_buffer_coords().
+ *
+ * Note that this is different from gtk_text_view_get_iter_at_location(),
+ * which returns cursor locations, i.e. positions <emphasis>between</emphasis>
+ * characters.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_text_view_get_iter_at_position (GtkTextView *text_view,
+ GtkTextIter *iter,
+ gint *trailing,
+ gint x,
+ gint y)
+{
+ g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+ g_return_if_fail (iter != NULL);
+
+ gtk_text_view_ensure_layout (text_view);
+
+ gtk_text_layout_get_iter_at_position (text_view->layout,
+ iter, trailing, x, y);
}
/**
* The rectangle position is in buffer coordinates; use
* gtk_text_view_buffer_to_window_coords() to convert these
* coordinates to coordinates for one of the windows in the text view.
- *
**/
void
gtk_text_view_get_iter_location (GtkTextView *text_view,
* Gets the y coordinate of the top of the line containing @iter,
* and the height of the line. The coordinate is a buffer coordinate;
* convert to window coordinates with gtk_text_view_buffer_to_window_coords().
- *
**/
void
gtk_text_view_get_line_yrange (GtkTextView *text_view,
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
* @within_margin: margin as a [0.0,0.5) fraction of screen size
- * @use_align: whether to use alignment arguments (if %FALSE, just get the mark onscreen)
- * @xalign: horizontal alignment of mark within visible area.
+ * @use_align: whether to use alignment arguments (if %FALSE,
+ * just get the mark onscreen)
+ * @xalign: horizontal alignment of mark within visible area
* @yalign: vertical alignment of mark within visible area
*
* Scrolls @text_view so that @iter is on the screen in the position
* indicated by @xalign and @yalign. An alignment of 0.0 indicates
- * left or top, 1.0 indicates right or bottom, 0.5 means center. If @use_align
- * is %FALSE, the text scrolls the minimal distance to get the mark onscreen,
- * possibly not scrolling at all. The effective screen for purposes
- * of this function is reduced by a margin of size @within_margin.
- * NOTE: This function uses the currently-computed height of the
- * lines in the text buffer. Note that line heights are computed
- * in an idle handler; so this function may not have the desired effect
- * if it's called before the height computations. To avoid oddness,
- * consider using gtk_text_view_scroll_to_mark() which saves a point
- * to be scrolled to after line validation.
+ * left or top, 1.0 indicates right or bottom, 0.5 means center.
+ * If @use_align is %FALSE, the text scrolls the minimal distance to
+ * get the mark onscreen, possibly not scrolling at all. The effective
+ * screen for purposes of this function is reduced by a margin of size
+ * @within_margin.
+ *
+ * Note that this function uses the currently-computed height of the
+ * lines in the text buffer. Line heights are computed in an idle
+ * handler; so this function may not have the desired effect if it's
+ * called before the height computations. To avoid oddness, consider
+ * using gtk_text_view_scroll_to_mark() which saves a point to be
+ * scrolled to after line validation.
*
* Return value: %TRUE if scrolling occurred
**/
scroll->use_align,
scroll->xalign,
scroll->yalign);
-
+
free_pending_scroll (scroll);
return retval;
if (text_view->width != width || text_view->height != height)
{
+ if (text_view->width != width)
+ text_view->width_changed = TRUE;
+
text_view->width = width;
text_view->height = height;
gtk_im_context_set_cursor_location (text_view->im_context, &area);
}
+static gboolean
+do_update_im_spot_location (gpointer text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+ priv->im_spot_idle = 0;
+
+ gtk_text_view_update_im_spot_location (text_view);
+ return FALSE;
+}
+
+static void
+queue_update_im_spot_location (GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+
+ /* Use priority a little higher than GTK_TEXT_VIEW_PRIORITY_VALIDATE,
+ * so we don't wait until the entire buffer has been validated. */
+ if (!priv->im_spot_idle)
+ priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
+ do_update_im_spot_location,
+ text_view,
+ NULL);
+}
+
+static void
+flush_update_im_spot_location (GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+
+ if (priv->im_spot_idle)
+ {
+ g_source_remove (priv->im_spot_idle);
+ priv->im_spot_idle = 0;
+ gtk_text_view_update_im_spot_location (text_view);
+ }
+}
+
/**
* gtk_text_view_scroll_to_mark:
* @text_view: a #GtkTextView
* @mark: a #GtkTextMark
* @within_margin: margin as a [0.0,0.5) fraction of screen size
- * @use_align: whether to use alignment arguments (if %FALSE, just get the mark onscreen)
- * @xalign: horizontal alignment of mark within visible area.
+ * @use_align: whether to use alignment arguments (if %FALSE, just
+ * get the mark onscreen)
+ * @xalign: horizontal alignment of mark within visible area
* @yalign: vertical alignment of mark within visible area
*
* Scrolls @text_view so that @mark is on the screen in the position
* indicated by @xalign and @yalign. An alignment of 0.0 indicates
- * left or top, 1.0 indicates right or bottom, 0.5 means center. If @use_align
- * is %FALSE, the text scrolls the minimal distance to get the mark onscreen,
- * possibly not scrolling at all. The effective screen for purposes
- * of this function is reduced by a margin of size @within_margin.
- *
+ * left or top, 1.0 indicates right or bottom, 0.5 means center.
+ * If @use_align is %FALSE, the text scrolls the minimal distance to
+ * get the mark onscreen, possibly not scrolling at all. The effective
+ * screen for purposes of this function is reduced by a margin of size
+ * @within_margin.
**/
void
gtk_text_view_scroll_to_mark (GtkTextView *text_view,
*
* Scrolls @text_view the minimum distance such that @mark is contained
* within the visible area of the widget.
- *
**/
void
gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
}
}
- g_object_notify (G_OBJECT (text_view), "wrap_mode");
+ g_object_notify (G_OBJECT (text_view), "wrap-mode");
}
/**
if (text_view->layout)
{
+ gtk_text_layout_set_overwrite_mode (text_view->layout,
+ text_view->overwrite_mode && text_view->editable);
text_view->layout->default_style->editable = text_view->editable;
gtk_text_layout_default_style_changed (text_view->layout);
}
*
* Sets the default number of blank pixels above paragraphs in @text_view.
* Tags in the buffer for @text_view may override the defaults.
- *
**/
void
gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
gtk_text_layout_default_style_changed (text_view->layout);
}
- g_object_notify (G_OBJECT (text_view), "pixels_above_lines");
+ g_object_notify (G_OBJECT (text_view), "pixels-above-lines");
}
}
* Sets the default number of pixels of blank space
* to put below paragraphs in @text_view. May be overridden
* by tags applied to @text_view's buffer.
- *
**/
void
gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
gtk_text_layout_default_style_changed (text_view->layout);
}
- g_object_notify (G_OBJECT (text_view), "pixels_below_lines");
+ g_object_notify (G_OBJECT (text_view), "pixels-below-lines");
}
}
* Sets the default number of pixels of blank space to leave between
* display/wrapped lines within a paragraph. May be overridden by
* tags in @text_view's buffer.
- *
**/
void
gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
gtk_text_layout_default_style_changed (text_view->layout);
}
- g_object_notify (G_OBJECT (text_view), "pixels_inside_wrap");
+ g_object_notify (G_OBJECT (text_view), "pixels-inside-wrap");
}
}
*
* Sets the default left margin for text in @text_view.
* Tags in the buffer may override the default.
- *
**/
void
gtk_text_view_set_left_margin (GtkTextView *text_view,
gtk_text_layout_default_style_changed (text_view->layout);
}
- g_object_notify (G_OBJECT (text_view), "left_margin");
+ g_object_notify (G_OBJECT (text_view), "left-margin");
}
}
*
* Sets the default right margin for text in the text view.
* Tags in the buffer may override the default.
- *
**/
void
gtk_text_view_set_right_margin (GtkTextView *text_view,
gtk_text_layout_default_style_changed (text_view->layout);
}
- g_object_notify (G_OBJECT (text_view), "right_margin");
+ g_object_notify (G_OBJECT (text_view), "right-margin");
}
}
*
* Sets the default indentation for paragraphs in @text_view.
* Tags in the buffer may override the default.
- *
**/
void
gtk_text_view_set_indent (GtkTextView *text_view,
*
* Sets the default tab stops for paragraphs in @text_view.
* Tags in the buffer may override the default.
- *
**/
void
gtk_text_view_set_tabs (GtkTextView *text_view,
* "standard" (8-space) tabs are used. Free the return value
* with pango_tab_array_free().
*
- * Return value: copy of default tab array, or %NULL if "standard" tabs are used; must be freed with pango_tab_array_free().
+ * Return value: copy of default tab array, or %NULL if "standard"
+ * tabs are used; must be freed with pango_tab_array_free().
**/
PangoTabArray*
gtk_text_view_get_tabs (GtkTextView *text_view)
return text_view->tabs ? pango_tab_array_copy (text_view->tabs) : NULL;
}
+static void
+gtk_text_view_toggle_cursor_visible (GtkTextView *text_view)
+{
+ gtk_text_view_set_cursor_visible (text_view, !text_view->cursor_visible);
+}
+
/**
* gtk_text_view_set_cursor_visible:
* @text_view: a #GtkTextView
* the cursor off.
**/
void
-gtk_text_view_set_cursor_visible (GtkTextView *text_view,
- gboolean setting)
+gtk_text_view_set_cursor_visible (GtkTextView *text_view,
+ gboolean setting)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
}
}
- g_object_notify (G_OBJECT (text_view), "cursor_visible");
+ g_object_notify (G_OBJECT (text_view), "cursor-visible");
}
}
* Return value: whether the insertion mark is visible
**/
gboolean
-gtk_text_view_get_cursor_visible (GtkTextView *text_view)
+gtk_text_view_get_cursor_visible (GtkTextView *text_view)
{
g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
* Moves the cursor to the currently visible region of the
* buffer, it it isn't there already.
*
- * Return value: TRUE if the cursor had to be moved.
+ * Return value: %TRUE if the cursor had to be moved.
**/
gboolean
gtk_text_view_place_cursor_onscreen (GtkTextView *text_view)
g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
if (clamp_iter_onscreen (text_view, &insert))
{
gtk_text_view_destroy (GtkObject *object)
{
GtkTextView *text_view;
- GtkTextLayout *layout;
-
+ GtkTextViewPrivate *priv;
+
text_view = GTK_TEXT_VIEW (object);
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
- layout = text_view->layout;
-
gtk_text_view_remove_validate_idles (text_view);
gtk_text_view_set_buffer (text_view, NULL);
gtk_text_view_destroy_layout (text_view);
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ if (text_view->scroll_timeout)
+ {
+ g_source_remove (text_view->scroll_timeout);
+ text_view->scroll_timeout = 0;
+ }
+
+ if (priv->im_spot_idle)
+ {
+ g_source_remove (priv->im_spot_idle);
+ priv->im_spot_idle = 0;
+ }
+
+ (* GTK_OBJECT_CLASS (gtk_text_view_parent_class)->destroy) (object);
}
static void
text_view = GTK_TEXT_VIEW (object);
- g_return_if_fail (text_view->buffer == NULL);
+ g_assert (text_view->buffer == NULL);
gtk_text_view_destroy_layout (text_view);
gtk_text_view_set_buffer (text_view, NULL);
g_object_unref (text_view->im_context);
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+ (* G_OBJECT_CLASS (gtk_text_view_parent_class)->finalize) (object);
}
static void
text_view = GTK_TEXT_VIEW (widget);
gtk_widget_style_get (widget,
- "interior_focus", &interior_focus,
- "focus_line_width", &focus_width,
+ "interior-focus", &interior_focus,
+ "focus-line-width", &focus_width,
NULL);
if (interior_focus)
{
GtkTextViewChild *child = tmp_list->data;
+ g_assert (child != NULL);
+
if (child->anchor)
{
/* We need to force-validate the regions containing
GtkAllocation allocation;
GtkRequisition child_req;
- g_assert (child != NULL);
-
allocation.x = child->x;
allocation.y = child->y;
*/
gtk_widget_style_get (widget,
- "interior_focus", &interior_focus,
- "focus_line_width", &focus_width,
+ "interior-focus", &interior_focus,
+ "focus-line-width", &focus_width,
NULL);
if (interior_focus)
{
GtkTextView *text_view = data;
- GDK_THREADS_ENTER ();
-
/* Note that some of this code is duplicated at the end of size_allocate,
* keep in sync with that.
*/
gtk_text_view_flush_first_validate (text_view);
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
GtkTextView *text_view = data;
gboolean result = TRUE;
- GDK_THREADS_ENTER ();
-
DV(g_print(G_STRLOC"\n"));
gtk_text_layout_validate (text_view->layout, 2000);
result = FALSE;
}
- GDK_THREADS_LEAVE ();
-
return result;
}
if (!text_view->first_validate_idle)
{
- text_view->first_validate_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
+ text_view->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
DV (g_print (G_STRLOC": adding first validate idle %d\n",
text_view->first_validate_idle));
}
if (!text_view->incremental_validate_idle)
{
- text_view->incremental_validate_idle = g_idle_add_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
+ text_view->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
text_view->incremental_validate_idle));
}
text_window_invalidate_rect (text_view->bottom_window,
&redraw_rect);
- gtk_text_view_update_im_spot_location (text_view);
+ queue_update_im_spot_location (text_view);
}
}
gdk_window_set_background (widget->window,
&widget->style->bg[GTK_WIDGET_STATE (widget)]);
- text_window_realize (text_view->text_window, widget->window);
+ text_window_realize (text_view->text_window, widget);
if (text_view->left_window)
- text_window_realize (text_view->left_window,
- widget->window);
+ text_window_realize (text_view->left_window, widget);
if (text_view->top_window)
- text_window_realize (text_view->top_window,
- widget->window);
+ text_window_realize (text_view->top_window, widget);
if (text_view->right_window)
- text_window_realize (text_view->right_window,
- widget->window);
+ text_window_realize (text_view->right_window, widget);
if (text_view->bottom_window)
- text_window_realize (text_view->bottom_window,
- widget->window);
+ text_window_realize (text_view->bottom_window, widget);
gtk_text_view_ensure_layout (text_view);
gtk_text_view_destroy_layout (text_view);
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ (* GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize) (widget);
}
static void
GtkStyle *previous_style)
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ PangoContext *ltr_context, *rtl_context;
if (GTK_WIDGET_REALIZED (widget))
{
gtk_text_view_set_attributes_from_style (text_view,
text_view->layout->default_style,
widget->style);
- gtk_text_layout_default_style_changed (text_view->layout);
+
+
+ ltr_context = gtk_widget_create_pango_context (widget);
+ pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
+ rtl_context = gtk_widget_create_pango_context (widget);
+ pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
+
+ gtk_text_layout_set_contexts (text_view->layout, ltr_context, rtl_context);
+
+ g_object_unref (ltr_context);
+ g_object_unref (rtl_context);
}
}
if (text_view->layout)
{
text_view->layout->default_style->direction = gtk_widget_get_direction (widget);
+
gtk_text_layout_default_style_changed (text_view->layout);
}
}
GtkStateType previous_state)
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ GdkCursor *cursor;
if (GTK_WIDGET_REALIZED (widget))
{
gtk_text_view_set_background (text_view);
+
+ if (GTK_WIDGET_IS_SENSITIVE (widget))
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
+ else
+ cursor = NULL;
+
+ gdk_window_set_cursor (text_view->text_window->bin_window, cursor);
+
+ if (cursor)
+ gdk_cursor_unref (cursor);
+
+ text_view->mouse_cursor_obscured = FALSE;
}
if (!GTK_WIDGET_IS_SENSITIVE (widget))
gboolean was_grabbed)
{
if (!was_grabbed)
- gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
+ {
+ gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget));
+ gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
+ }
}
GSList *tags;
GSList *tmp;
gboolean retval = FALSE;
- GtkTextView *text_view;
-
- text_view = GTK_TEXT_VIEW (widget);
tags = gtk_text_iter_get_tags (iter);
else if (event->type == GDK_KEY_PRESS ||
event->type == GDK_KEY_RELEASE)
{
- GtkTextMark *insert;
GtkTextIter iter;
- insert = gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert");
-
- gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
return emit_event_on_tags (widget, event, &iter);
}
get_buffer (text_view) == NULL)
return FALSE;
+ /* Make sure input method knows where it is */
+ flush_update_im_spot_location (text_view);
+
insert = gtk_text_buffer_get_insert (get_buffer (text_view));
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
can_insert = gtk_text_iter_can_insert (&iter, text_view->editable);
- if (can_insert &&
- gtk_im_context_filter_keypress (text_view->im_context, event))
+ if (gtk_im_context_filter_keypress (text_view->im_context, event))
{
text_view->need_im_reset = TRUE;
- obscure = TRUE;
+ if (!can_insert)
+ gtk_text_view_reset_im_context (text_view);
+ obscure = can_insert;
retval = TRUE;
}
/* Binding set */
- else if (GTK_WIDGET_CLASS (parent_class)->key_press_event &&
- GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
+ else if (GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_press_event &&
+ GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_press_event (widget, event))
retval = TRUE;
/* use overall editability not can_insert, more predictable for users */
else if (text_view->editable &&
/* this won't actually insert the newline if the cursor isn't
* editable
*/
+ gtk_text_view_reset_im_context (text_view);
gtk_text_view_commit_text (text_view, "\n");
obscure = TRUE;
}
/* Pass through Tab as literal tab, unless Control is held down */
else if ((event->keyval == GDK_Tab ||
- event->keyval == GDK_KP_Tab) &&
+ event->keyval == GDK_KP_Tab ||
+ event->keyval == GDK_ISO_Left_Tab) &&
!(event->state & GDK_CONTROL_MASK))
{
/* If the text widget isn't editable overall, or if the application
*/
if (text_view->accepts_tab && text_view->editable)
{
+ gtk_text_view_reset_im_context (text_view);
gtk_text_view_commit_text (text_view, "\t");
obscure = TRUE;
}
else
- gtk_text_view_move_focus (text_view,
- (event->state & GDK_SHIFT_MASK) ?
- GTK_DIR_TAB_BACKWARD: GTK_DIR_TAB_FORWARD);
+ g_signal_emit_by_name (text_view, "move-focus",
+ (event->state & GDK_SHIFT_MASK) ?
+ GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
retval = TRUE;
}
if (obscure)
gtk_text_view_obscure_mouse_cursor (text_view);
+ gtk_text_view_reset_blink_time (text_view);
gtk_text_view_pend_cursor_blink (text_view);
return retval;
return TRUE;
}
else
- return GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
+ return GTK_WIDGET_CLASS (gtk_text_view_parent_class)->key_release_event (widget, event);
}
static gint
return FALSE;
}
+ gtk_text_view_reset_blink_time (text_view);
+
#if 0
/* debug hack */
if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
{
GtkTextIter iter;
- gtk_text_view_end_selection_drag (text_view, event);
+ gtk_text_view_end_selection_drag (text_view);
gtk_text_layout_get_iter_at_pixel (text_view->layout,
&iter,
text_view->drag_start_y = -1;
}
- if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget), event))
+ if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget)))
return TRUE;
else if (text_view->pending_place_cursor_button == event->button)
{
event->y + text_view->yoffset);
gtk_text_buffer_place_cursor (get_buffer (text_view), &iter);
-
+ gtk_text_view_check_cursor_blink (text_view);
+
text_view->pending_place_cursor_button = 0;
return FALSE;
gtk_widget_queue_draw (widget);
DV(g_print (G_STRLOC": focus_in_event\n"));
-
+
+ gtk_text_view_reset_blink_time (text_view);
+
if (text_view->cursor_visible && text_view->layout)
{
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ gtk_text_view_end_selection_drag (text_view);
+
gtk_widget_queue_draw (widget);
DV(g_print (G_STRLOC": focus_out_event\n"));
if (text_view->cursor_visible && text_view->layout)
{
- gtk_text_layout_set_cursor_visible (text_view->layout, FALSE);
gtk_text_view_check_cursor_blink (text_view);
+ gtk_text_layout_set_cursor_visible (text_view->layout, FALSE);
}
g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
if (event->window == text_view->text_window->bin_window &&
text_view->drag_start_x >= 0)
{
- gint x, y;
+ gint x = event->x;
+ gint y = event->y;
- gdk_window_get_pointer (text_view->text_window->bin_window,
- &x, &y, NULL);
+ gdk_event_request_motions (event);
if (gtk_drag_check_threshold (widget,
text_view->drag_start_x,
if (event->window == widget->window)
gtk_text_view_draw_focus (widget);
- /* Propagate exposes to all children not in the buffer. */
+ /* Propagate exposes to all unanchored children.
+ * Anchored children are handled in gtk_text_view_paint().
+ */
tmp_list = GTK_TEXT_VIEW (widget)->children;
while (tmp_list != NULL)
{
/* propagate_expose checks that event->window matches
* child->window
*/
- if (vc->type != GTK_TEXT_WINDOW_TEXT)
+ if (!vc->anchor)
gtk_container_propagate_expose (GTK_CONTAINER (widget),
vc->widget,
event);
/* We clear the focus if we are in interior focus mode. */
gtk_widget_style_get (widget,
- "interior_focus", &interior_focus,
+ "interior-focus", &interior_focus,
NULL);
if (GTK_WIDGET_DRAWABLE (widget))
gtk_text_view_focus (GtkWidget *widget,
GtkDirectionType direction)
{
- GtkTextView *text_view;
GtkContainer *container;
gboolean result;
- text_view = GTK_TEXT_VIEW (widget);
container = GTK_CONTAINER (widget);
if (!gtk_widget_is_focus (widget) &&
* children to get the focus
*/
GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
- result = GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+ result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
return result;
}
}
+static void
+gtk_text_view_move_focus (GtkWidget *widget,
+ GtkDirectionType direction_type)
+{
+ GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+
+ if (GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus)
+ GTK_TEXT_VIEW_GET_CLASS (text_view)->move_focus (text_view,
+ direction_type);
+}
+
/*
* Container
*/
gtk_text_view_add (GtkContainer *container,
GtkWidget *child)
{
- g_return_if_fail (GTK_IS_TEXT_VIEW (container));
- g_return_if_fail (GTK_IS_WIDGET (child));
-
/* This is pretty random. */
gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container),
child,
GtkTextView *text_view;
GtkTextViewChild *vc;
- g_return_if_fail (GTK_IS_TEXT_VIEW (container));
- g_return_if_fail (GTK_IS_WIDGET (child));
- g_return_if_fail (child->parent == (GtkWidget*) container);
-
text_view = GTK_TEXT_VIEW (container);
vc = NULL;
g_slist_free (copy);
}
-#define CURSOR_ON_MULTIPLIER 0.66
-#define CURSOR_OFF_MULTIPLIER 0.34
-#define CURSOR_PEND_MULTIPLIER 1.0
+#define CURSOR_ON_MULTIPLIER 2
+#define CURSOR_OFF_MULTIPLIER 1
+#define CURSOR_PEND_MULTIPLIER 3
+#define CURSOR_DIVIDER 3
static gboolean
cursor_blinks (GtkTextView *text_view)
#endif
if (gtk_debug_flags & GTK_DEBUG_UPDATES)
return FALSE;
-
+
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
- return blink;
+
+ if (!blink)
+ return FALSE;
+
+ if (text_view->editable)
+ {
+ GtkTextMark *insert;
+ GtkTextIter iter;
+
+ insert = gtk_text_buffer_get_insert (get_buffer (text_view));
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
+
+ if (gtk_text_iter_editable (&iter, text_view->editable))
+ return blink;
+ }
+
+ return FALSE;
}
static gint
return time;
}
+static gint
+get_cursor_blink_timeout (GtkTextView *text_view)
+{
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
+ gint time;
+
+ g_object_get (settings, "gtk-cursor-blink-timeout", &time, NULL);
+
+ return time;
+}
+
+
/*
* Blink!
*/
blink_cb (gpointer data)
{
GtkTextView *text_view;
+ GtkTextViewPrivate *priv;
gboolean visible;
-
- GDK_THREADS_ENTER ();
+ gint blink_timeout;
text_view = GTK_TEXT_VIEW (data);
-
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+
if (!GTK_WIDGET_HAS_FOCUS (text_view))
{
g_warning ("GtkTextView - did not receive focus-out-event. If you\n"
"connect a handler to this signal, it must return\n"
- "FALSE so the entry gets the event as well");
- }
+ "FALSE so the text view gets the event as well");
+
+ gtk_text_view_check_cursor_blink (text_view);
+
+ return FALSE;
+ }
g_assert (text_view->layout);
- g_assert (GTK_WIDGET_HAS_FOCUS (text_view));
g_assert (text_view->cursor_visible);
visible = gtk_text_layout_get_cursor_visible (text_view->layout);
- if (visible)
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER,
- blink_cb,
- text_view);
- else
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER,
+ blink_timeout = get_cursor_blink_timeout (text_view);
+ if (priv->blink_time > 1000 * blink_timeout &&
+ blink_timeout < G_MAXINT/1000)
+ {
+ /* we've blinked enough without the user doing anything, stop blinking */
+ visible = 0;
+ text_view->blink_timeout = 0;
+ }
+ else if (visible)
+ text_view->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
text_view);
-
- gtk_text_layout_set_cursor_visible (text_view->layout,
- !visible);
+ else
+ {
+ text_view->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
+ blink_cb,
+ text_view);
+ priv->blink_time += get_cursor_time (text_view);
+ }
+
+ /* Block changed_handler while changing the layout's cursor visibility
+ * because it would expose the whole paragraph. Instead, we expose
+ * the cursor's area(s) manually below.
+ */
+ g_signal_handlers_block_by_func (text_view->layout,
+ changed_handler,
+ text_view);
+ gtk_text_layout_set_cursor_visible (text_view->layout, !visible);
+ g_signal_handlers_unblock_by_func (text_view->layout,
+ changed_handler,
+ text_view);
- GDK_THREADS_LEAVE ();
+ text_window_invalidate_cursors (text_view->text_window);
/* Remove ourselves */
return FALSE;
{
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER,
+ text_view->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
text_view);
}
}
else
- gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
+ {
+ gtk_text_view_stop_cursor_blink (text_view);
+ gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
+ }
}
else
{
gtk_text_view_stop_cursor_blink (text_view);
+ gtk_text_layout_set_cursor_visible (text_view->layout, FALSE);
}
}
static void
-gtk_text_view_pend_cursor_blink(GtkTextView *text_view)
+gtk_text_view_pend_cursor_blink (GtkTextView *text_view)
{
if (text_view->layout != NULL &&
text_view->cursor_visible &&
GTK_WIDGET_HAS_FOCUS (text_view) &&
cursor_blinks (text_view))
{
- if (text_view->blink_timeout != 0)
- {
- g_source_remove (text_view->blink_timeout);
- text_view->blink_timeout = 0;
- }
-
+ gtk_text_view_stop_cursor_blink (text_view);
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER,
+ text_view->blink_timeout = gdk_threads_add_timeout (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
text_view);
}
}
+static void
+gtk_text_view_reset_blink_time (GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+
+ priv->blink_time = 0;
+}
+
/*
* Key binding handlers
"insert",
new_location);
else
- gtk_text_buffer_place_cursor (get_buffer (text_view),
- new_location);
+ gtk_text_buffer_place_cursor (get_buffer (text_view),
+ new_location);
+ gtk_text_view_check_cursor_blink (text_view);
}
static void
{
GtkTextIter insert;
GtkTextIter newplace;
-
gint cursor_x_pos = 0;
+ GtkDirectionType leave_direction = -1;
if (!text_view->cursor_visible)
{
switch (step)
{
- case GTK_MOVEMENT_LOGICAL_POSITIONS:
case GTK_MOVEMENT_VISUAL_POSITIONS:
+ leave_direction = count > 0 ? GTK_DIR_RIGHT : GTK_DIR_LEFT;
+ /* fall through */
+ case GTK_MOVEMENT_LOGICAL_POSITIONS:
case GTK_MOVEMENT_WORDS:
scroll_step = GTK_SCROLL_HORIZONTAL_STEPS;
break;
scroll_step = GTK_SCROLL_HORIZONTAL_ENDS;
break;
case GTK_MOVEMENT_DISPLAY_LINES:
+ leave_direction = count > 0 ? GTK_DIR_DOWN : GTK_DIR_UP;
+ /* fall through */
case GTK_MOVEMENT_PARAGRAPHS:
case GTK_MOVEMENT_PARAGRAPH_ENDS:
scroll_step = GTK_SCROLL_STEPS;
scroll_step = GTK_SCROLL_PAGES;
break;
}
-
- gtk_text_view_move_viewport (text_view, scroll_step, count);
+
+ if (!gtk_text_view_move_viewport (text_view, scroll_step, count))
+ {
+ if (leave_direction != -1 &&
+ !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
+ leave_direction))
+ {
+ g_signal_emit_by_name (text_view, "move-focus", leave_direction);
+ }
+ }
return;
}
if (step == GTK_MOVEMENT_PAGES)
{
- gtk_text_view_scroll_pages (text_view, count, extend_selection);
+ if (!gtk_text_view_scroll_pages (text_view, count, extend_selection))
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+
+ gtk_text_view_check_cursor_blink (text_view);
gtk_text_view_pend_cursor_blink (text_view);
return;
}
else if (step == GTK_MOVEMENT_HORIZONTAL_PAGES)
{
- gtk_text_view_scroll_hpages (text_view, count, extend_selection);
+ if (!gtk_text_view_scroll_hpages (text_view, count, extend_selection))
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+
+ gtk_text_view_check_cursor_blink (text_view);
gtk_text_view_pend_cursor_blink (text_view);
return;
}
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
newplace = insert;
if (step == GTK_MOVEMENT_DISPLAY_LINES)
else if (count > 0)
{
if (!gtk_text_iter_forward_visible_word_ends (&newplace, count))
- gtk_text_iter_forward_to_end (&newplace);
+ gtk_text_iter_forward_to_line_end (&newplace);
}
break;
case GTK_MOVEMENT_DISPLAY_LINES:
if (count < 0)
- {
- if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
- gtk_text_layout_move_iter_to_x (text_view->layout, &newplace, cursor_x_pos);
- else
- /* we currently do not have a backward_to_start, use offset */
- gtk_text_iter_set_offset (&newplace, 0);
- }
+ {
+ leave_direction = GTK_DIR_UP;
+
+ if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
+ gtk_text_layout_move_iter_to_x (text_view->layout, &newplace, cursor_x_pos);
+ else
+ gtk_text_iter_set_line_offset (&newplace, 0);
+ }
if (count > 0)
- {
- if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
- gtk_text_layout_move_iter_to_x (text_view->layout, &newplace, cursor_x_pos);
- else
- gtk_text_iter_forward_to_end (&newplace);
- }
+ {
+ leave_direction = GTK_DIR_DOWN;
+
+ if (gtk_text_view_move_iter_by_lines (text_view, &newplace, count))
+ gtk_text_layout_move_iter_to_x (text_view->layout, &newplace, cursor_x_pos);
+ else
+ gtk_text_iter_forward_to_line_end (&newplace);
+ }
break;
case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
gtk_text_iter_forward_to_line_end (&newplace);
--count;
}
- gtk_text_iter_forward_lines (&newplace, count);
+ gtk_text_iter_forward_visible_lines (&newplace, count);
gtk_text_iter_forward_to_line_end (&newplace);
}
else if (count < 0)
{
if (gtk_text_iter_get_line_offset (&newplace) > 0)
- {
- gtk_text_iter_set_line_offset (&newplace, 0);
- ++count;
- }
- gtk_text_iter_forward_lines (&newplace, count);
+ gtk_text_iter_set_line_offset (&newplace, 0);
+ gtk_text_iter_forward_visible_lines (&newplace, count);
gtk_text_iter_set_line_offset (&newplace, 0);
}
break;
{
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
if (step == GTK_MOVEMENT_DISPLAY_LINES)
+ gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, -1);
+ }
+ else if (leave_direction != -1)
+ {
+ if (!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
+ leave_direction))
{
- gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, -1);
+ g_signal_emit_by_name (text_view, "move-focus", leave_direction);
}
}
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
+ gtk_text_view_check_cursor_blink (text_view);
gtk_text_view_pend_cursor_blink (text_view);
}
}
-static void
+static gboolean
gtk_text_view_move_viewport (GtkTextView *text_view,
GtkScrollStep step,
gint count)
break;
}
- set_adjustment_clamped (adjustment, adjustment->value + count * increment);
+ return set_adjustment_clamped (adjustment, adjustment->value + count * increment);
}
static void
GtkTextIter insert;
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
}
-static void
+static gboolean
gtk_text_view_scroll_pages (GtkTextView *text_view,
gint count,
gboolean extend_selection)
gdouble oldval;
GtkAdjustment *adj;
gint cursor_x_pos, cursor_y_pos;
+ GtkTextMark *insert_mark;
+ GtkTextIter old_insert;
GtkTextIter new_insert;
GtkTextIter anchor;
gint y0, y1;
- g_return_if_fail (text_view->vadjustment != NULL);
+ g_return_val_if_fail (text_view->vadjustment != NULL, FALSE);
adj = text_view->vadjustment;
+ insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
+
/* Make sure we start from the current cursor position, even
* if it was offscreen, but don't queue more scrolls if we're
* already behind.
if (text_view->pending_scroll)
cancel_pending_scroll (text_view);
else
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
-
-/* Validate the region that will be brought into view by the cursor motion
+ gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
+
+ /* Validate the region that will be brought into view by the cursor motion
*/
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
+ &old_insert, insert_mark);
+
if (count < 0)
{
gtk_text_view_get_first_para_iter (text_view, &anchor);
gtk_text_layout_validate_yrange (text_view->layout, &anchor, y0, y1);
/* FIXME do we need to update the adjustment ranges here? */
+ new_insert = old_insert;
+
if (count < 0 && adj->value <= (adj->lower + 1e-12))
{
/* already at top, just be sure we are at offset 0 */
{
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
- newval = adj->value;
oldval = adj->value;
-
+ newval = adj->value;
+
newval += count * adj->page_increment;
set_adjustment_clamped (adj, newval);
* only guarantees 1 pixel onscreen.
*/
DV(g_print (G_STRLOC": scrolling onscreen\n"));
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
+
+ return !gtk_text_iter_equal (&old_insert, &new_insert);
}
-static void
+static gboolean
gtk_text_view_scroll_hpages (GtkTextView *text_view,
gint count,
gboolean extend_selection)
gdouble oldval;
GtkAdjustment *adj;
gint cursor_x_pos, cursor_y_pos;
+ GtkTextMark *insert_mark;
+ GtkTextIter old_insert;
GtkTextIter new_insert;
gint y, height;
- g_return_if_fail (text_view->hadjustment != NULL);
+ g_return_val_if_fail (text_view->hadjustment != NULL, FALSE);
adj = text_view->hadjustment;
+ insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
+
/* Make sure we start from the current cursor position, even
* if it was offscreen, but don't queue more scrolls if we're
* already behind.
if (text_view->pending_scroll)
cancel_pending_scroll (text_view);
else
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
-
+ gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
+
/* Validate the line that we're moving within.
*/
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
- &new_insert,
- gtk_text_buffer_get_mark (get_buffer (text_view), "insert"));
- gtk_text_layout_get_line_yrange (text_view->layout, &new_insert, &y, &height);
- gtk_text_layout_validate_yrange (text_view->layout, &new_insert, y, y + height);
+ &old_insert, insert_mark);
+
+ gtk_text_layout_get_line_yrange (text_view->layout, &old_insert, &y, &height);
+ gtk_text_layout_validate_yrange (text_view->layout, &old_insert, y, y + height);
/* FIXME do we need to update the adjustment ranges here? */
-
+
+ new_insert = old_insert;
+
if (count < 0 && adj->value <= (adj->lower + 1e-12))
{
/* already at far left, just be sure we are at offset 0 */
else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
{
/* already at far right, just be sure we are at the end */
- gtk_text_iter_forward_to_line_end (&new_insert);
+ if (!gtk_text_iter_ends_line (&new_insert))
+ gtk_text_iter_forward_to_line_end (&new_insert);
move_cursor (text_view, &new_insert, extend_selection);
}
else
{
gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
- newval = adj->value;
oldval = adj->value;
-
+ newval = adj->value;
+
newval += count * adj->page_increment;
set_adjustment_clamped (adj, newval);
* only guarantees 1 pixel onscreen.
*/
DV(g_print (G_STRLOC": scrolling onscreen\n"));
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_view_scroll_mark_onscreen (text_view, insert_mark);
+
+ return !gtk_text_iter_equal (&old_insert, &new_insert);
}
static gboolean
gtk_text_view_insert_at_cursor (GtkTextView *text_view,
const gchar *str)
{
- gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
- text_view->editable);
+ if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
+ text_view->editable))
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
}
static void
return;
}
- gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
- &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
start = insert;
end = insert;
" ", 1,
text_view->editable);
}
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
gtk_text_buffer_end_user_action (get_buffer (text_view));
+ gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view), "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
+ }
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
}
}
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
&insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
if (gtk_text_buffer_backspace (get_buffer (text_view), &insert,
TRUE, text_view->editable))
{
+ gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view), "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
+ }
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
}
}
text_view->editable);
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
}
static void
gtk_text_buffer_copy_clipboard (get_buffer (text_view),
clipboard);
- DV(g_print (G_STRLOC": scrolling onscreen\n"));
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+
+ /* on copy do not scroll, we are already onscreen */
}
static void
text_view->editable);
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
}
static void
gtk_text_view_toggle_overwrite (GtkTextView *text_view)
{
+ if (text_view->text_window)
+ text_window_invalidate_cursors (text_view->text_window);
+
text_view->overwrite_mode = !text_view->overwrite_mode;
+
+ if (text_view->layout)
+ gtk_text_layout_set_overwrite_mode (text_view->layout,
+ text_view->overwrite_mode && text_view->editable);
+
+ if (text_view->text_window)
+ text_window_invalidate_cursors (text_view->text_window);
+
+ gtk_text_view_pend_cursor_blink (text_view);
+
g_object_notify (G_OBJECT (text_view), "overwrite");
}
overwrite = overwrite != FALSE;
if (text_view->overwrite_mode != overwrite)
- {
- text_view->overwrite_mode = overwrite;
-
- g_object_notify (G_OBJECT (text_view), "overwrite");
- }
+ gtk_text_view_toggle_overwrite (text_view);
}
/**
* gtk_text_view_set_accepts_tab:
* @text_view: A #GtkTextView
- * @accepts_tab: %TRUE if pressing the Tab key should insert a tab character, %FALSE, if pressing the Tab key should move the keyboard focus.
+ * @accepts_tab: %TRUE if pressing the Tab key should insert a tab
+ * character, %FALSE, if pressing the Tab key should move the
+ * keyboard focus.
*
- * Sets the behavior of the text widget when the Tab key is pressed. If @accepts_tab
- * is %TRUE a tab character is inserted. If @accepts_tab is %FALSE the keyboard focus
- * is moved to the next widget in the focus chain.
+ * Sets the behavior of the text widget when the Tab key is pressed.
+ * If @accepts_tab is %TRUE, a tab character is inserted. If @accepts_tab
+ * is %FALSE the keyboard focus is moved to the next widget in the focus
+ * chain.
*
* Since: 2.4
**/
{
text_view->accepts_tab = accepts_tab;
- g_object_notify (G_OBJECT (text_view), "accepts_tab");
+ g_object_notify (G_OBJECT (text_view), "accepts-tab");
}
}
* Returns whether pressing the Tab key inserts a tab characters.
* gtk_text_view_set_accepts_tab().
*
- * Return value: %TRUE if pressing the Tab key inserts a tab character, %FALSE if pressing the Tab key moves the keyboard focus.
+ * Return value: %TRUE if pressing the Tab key inserts a tab character,
+ * %FALSE if pressing the Tab key moves the keyboard focus.
*
* Since: 2.4
**/
}
static void
-gtk_text_view_move_focus (GtkTextView *text_view,
- GtkDirectionType direction_type)
+gtk_text_view_compat_move_focus (GtkTextView *text_view,
+ GtkDirectionType direction_type)
{
- GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (text_view));
+ GSignalInvocationHint *hint = g_signal_get_invocation_hint (text_view);
- if (!GTK_WIDGET_TOPLEVEL (toplevel))
- return;
+ /* as of GTK+ 2.12, the "move-focus" signal has been moved to GtkWidget,
+ * the evil code below makes sure that both emitting the signal and
+ * calling the virtual function directly continue to work as expetcted
+ */
+
+ if (hint->signal_id == g_signal_lookup ("move-focus", GTK_TYPE_WIDGET))
+ {
+ /* if this is a signal emission, chain up */
- /* Propagate to toplevel */
- g_signal_emit_by_name (toplevel, "move_focus", direction_type);
+ GValue instance_and_params[2] = { { 0, }, { 0, } };
+ GValue return_value = { 0, };
+
+ g_value_init (&instance_and_params[0], GTK_TYPE_WIDGET);
+ g_value_set_object (&instance_and_params[0], text_view);
+
+ g_value_init (&instance_and_params[1], GTK_TYPE_DIRECTION_TYPE);
+ g_value_set_enum (&instance_and_params[1], direction_type);
+
+ g_value_init (&return_value, G_TYPE_BOOLEAN);
+
+ g_signal_chain_from_overridden (instance_and_params, &return_value);
+
+ g_value_unset (&instance_and_params[0]);
+ g_value_unset (&instance_and_params[1]);
+ g_value_unset (&return_value);
+ }
+ else
+ {
+ /* otherwise emit the signal, since somebody called the virtual
+ * function directly
+ */
+
+ g_signal_emit_by_name (text_view, "move-focus", direction_type);
+ }
}
/*
{
GtkTextIter insert;
- gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
- &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
gtk_text_buffer_move_mark (get_buffer (text_view),
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "selection_bound"),
+ gtk_text_buffer_get_selection_bound (get_buffer (text_view)),
&insert);
}
static void
-move_mark_to_pointer_and_scroll (GtkTextView *text_view,
- const gchar *mark_name)
+get_iter_at_pointer (GtkTextView *text_view,
+ GtkTextIter *iter,
+ gint *x,
+ gint *y)
{
- gint x, y;
+ gint xcoord, ycoord;
GdkModifierType state;
- GtkTextIter newplace;
- /* DV(g_print (G_STRLOC": begin\n")); */
-
gdk_window_get_pointer (text_view->text_window->bin_window,
- &x, &y, &state);
-
- /* DV(g_print (G_STRLOC": get iter at pixel\n"); */
+ &xcoord, &ycoord, &state);
+
gtk_text_layout_get_iter_at_pixel (text_view->layout,
- &newplace,
- x + text_view->xoffset,
- y + text_view->yoffset);
+ iter,
+ xcoord + text_view->xoffset,
+ ycoord + text_view->yoffset);
+ if (x)
+ *x = xcoord;
- {
- GtkTextMark *mark =
- gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
+ if (y)
+ *y = ycoord;
+}
- /* This may invalidate the layout */
- DV(g_print (G_STRLOC": move mark\n"));
- gtk_text_buffer_move_mark (get_buffer (text_view),
- mark,
- &newplace);
+static void
+move_mark_to_pointer_and_scroll (GtkTextView *text_view,
+ const gchar *mark_name)
+{
+ GtkTextIter newplace;
+ GtkTextMark *mark;
- DV(g_print (G_STRLOC": scrolling onscreen\n"));
- gtk_text_view_scroll_mark_onscreen (text_view, mark);
- }
+ get_iter_at_pointer (text_view, &newplace, NULL, NULL);
+
+ mark = gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
+
+ /* This may invalidate the layout */
+ DV(g_print (G_STRLOC": move mark\n"));
+
+ gtk_text_buffer_move_mark (get_buffer (text_view),
+ mark,
+ &newplace);
+
+ DV(g_print (G_STRLOC": scrolling onscreen\n"));
+ gtk_text_view_scroll_mark_onscreen (text_view, mark);
DV (g_print ("first validate idle leaving %s is %d\n",
G_STRLOC, text_view->first_validate_idle));
}
-static gint
+static gboolean
selection_scan_timeout (gpointer data)
{
GtkTextView *text_view;
- GDK_THREADS_ENTER ();
-
text_view = GTK_TEXT_VIEW (data);
DV(g_print (G_STRLOC": calling move_mark_to_pointer_and_scroll\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
- GDK_THREADS_LEAVE ();
-
return TRUE; /* remain installed. */
}
-#define DND_SCROLL_MARGIN 0.20
+#define UPPER_OFFSET_ANCHOR 0.8
+#define LOWER_OFFSET_ANCHOR 0.2
+
+static gboolean
+check_scroll (gdouble offset, GtkAdjustment *adj)
+{
+ if ((offset > UPPER_OFFSET_ANCHOR &&
+ adj->value + adj->page_size < adj->upper) ||
+ (offset < LOWER_OFFSET_ANCHOR &&
+ adj->value > adj->lower))
+ return TRUE;
+
+ return FALSE;
+}
static gint
drag_scan_timeout (gpointer data)
{
GtkTextView *text_view;
- gint x, y;
- GdkModifierType state;
GtkTextIter newplace;
+ gint x, y, width, height;
+ gdouble pointer_xoffset, pointer_yoffset;
- GDK_THREADS_ENTER ();
-
text_view = GTK_TEXT_VIEW (data);
- gdk_window_get_pointer (text_view->text_window->bin_window,
- &x, &y, &state);
-
- gtk_text_layout_get_iter_at_pixel (text_view->layout,
- &newplace,
- x + text_view->xoffset,
- y + text_view->yoffset);
-
+ get_iter_at_pointer (text_view, &newplace, &x, &y);
+ gdk_drawable_get_size (text_view->text_window->bin_window, &width, &height);
+
gtk_text_buffer_move_mark (get_buffer (text_view),
text_view->dnd_mark,
&newplace);
- DV(g_print (G_STRLOC": scrolling onscreen\n"));
- gtk_text_view_scroll_to_mark (text_view,
- text_view->dnd_mark,
- DND_SCROLL_MARGIN, FALSE, 0.0, 0.0);
+ pointer_xoffset = (gdouble) x / width;
+ pointer_yoffset = (gdouble) y / height;
+
+ if (check_scroll (pointer_xoffset, text_view->hadjustment) ||
+ check_scroll (pointer_yoffset, text_view->vadjustment))
+ {
+ /* do not make offsets surpass lower nor upper anchors, this makes
+ * scrolling speed relative to the distance of the pointer to the
+ * anchors when it moves beyond them.
+ */
+ pointer_xoffset = CLAMP (pointer_xoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
+ pointer_yoffset = CLAMP (pointer_yoffset, LOWER_OFFSET_ANCHOR, UPPER_OFFSET_ANCHOR);
+
+ gtk_text_view_scroll_to_mark (text_view,
+ text_view->dnd_mark,
+ 0., TRUE, pointer_xoffset, pointer_yoffset);
+ }
- GDK_THREADS_LEAVE ();
-
return TRUE;
}
/*
* Move @start and @end to the boundaries of the selection unit (indicated by
- * @granularity) which contained @start initially. Return wether @start was
- * contained in a selection unit at all (which may not be the case for words).
+ * @granularity) which contained @start initially.
+ * If the selction unit is SELECT_WORDS and @start is not contained in a word
+ * the selection is extended to all the white spaces between the end of the
+ * word preceding @start and the start of the one following.
*/
-static gboolean
+static void
extend_selection (GtkTextView *text_view,
SelectionGranularity granularity,
GtkTextIter *start,
GtkTextIter *end)
{
- gboolean extend = TRUE;
-
*end = *start;
if (granularity == SELECT_WORDS)
}
}
else
- extend = FALSE;
+ {
+ GtkTextIter tmp;
+
+ tmp = *start;
+ if (gtk_text_iter_backward_visible_word_start (&tmp))
+ gtk_text_iter_forward_visible_word_end (&tmp);
+
+ if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (start))
+ *start = tmp;
+ else
+ gtk_text_iter_set_line_offset (start, 0);
+
+ tmp = *end;
+ if (!gtk_text_iter_forward_visible_word_end (&tmp))
+ gtk_text_iter_forward_to_end (&tmp);
+
+ if (gtk_text_iter_ends_word (&tmp))
+ gtk_text_iter_backward_visible_word_start (&tmp);
+
+ if (gtk_text_iter_get_line (&tmp) == gtk_text_iter_get_line (end))
+ *end = tmp;
+ else
+ gtk_text_iter_forward_to_line_end (end);
+ }
}
else if (granularity == SELECT_LINES)
{
gtk_text_view_forward_display_line_end (text_view, end);
}
}
-
- return extend;
}
+
+typedef struct
+{
+ SelectionGranularity granularity;
+ GtkTextMark *orig_start;
+ GtkTextMark *orig_end;
+} SelectionData;
+
+static void
+selection_data_free (SelectionData *data)
+{
+ if (data->orig_start != NULL)
+ gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start),
+ data->orig_start);
+ if (data->orig_end != NULL)
+ gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end),
+ data->orig_end);
+ g_free (data);
+}
+
static gint
-selection_motion_event_handler (GtkTextView *text_view, GdkEventMotion *event, gpointer data)
+selection_motion_event_handler (GtkTextView *text_view,
+ GdkEventMotion *event,
+ SelectionData *data)
{
- SelectionGranularity granularity = GPOINTER_TO_INT (data);
+ gdk_event_request_motions (event);
- if (granularity == SELECT_CHARACTERS)
+ if (data->granularity == SELECT_CHARACTERS)
{
move_mark_to_pointer_and_scroll (text_view, "insert");
}
else
{
- gint x, y;
- GdkModifierType state;
- GtkTextIter start, end;
- GtkTextIter old_start, old_end;
- GtkTextIter ins, bound;
+ GtkTextIter cursor, start, end;
+ GtkTextIter orig_start, orig_end;
GtkTextBuffer *buffer;
buffer = get_buffer (text_view);
- gdk_window_get_pointer (text_view->text_window->bin_window,
- &x, &y, &state);
-
- gtk_text_layout_get_iter_at_pixel (text_view->layout,
- &start,
- event->x + text_view->xoffset,
- event->y + text_view->yoffset);
-
- if (extend_selection (text_view, granularity, &start, &end))
- {
- /* Extend selection */
- gtk_text_buffer_get_iter_at_mark (buffer,
- &ins,
- gtk_text_buffer_get_insert (buffer));
- gtk_text_buffer_get_iter_at_mark (buffer,
- &bound,
- gtk_text_buffer_get_selection_bound (buffer));
-
- if (gtk_text_iter_compare (&ins, &bound) < 0)
- {
- old_start = ins;
- old_end = bound;
- }
- else
- {
- old_start = bound;
- old_end = ins;
- }
+ gtk_text_buffer_get_iter_at_mark (buffer, &orig_start, data->orig_start);
+ gtk_text_buffer_get_iter_at_mark (buffer, &orig_end, data->orig_end);
- if (gtk_text_iter_compare (&start, &old_start) < 0)
- {
- /* newly selected unit before the current selection */
- ins = start;
- bound = old_end;
- }
- else if (gtk_text_iter_compare (&old_end, &end) < 0)
- {
- /* newly selected unit after the current selection */
- ins = end;
- bound = old_start;
- }
- else if (gtk_text_iter_equal (&ins, &old_start))
- {
- /* newly selected unit inside the current selection
- at the start */
- if (!gtk_text_iter_equal (&ins, &start))
- ins = end;
- }
- else
- {
- /* newly selected unit inside the current selection
- at the end */
- if (!gtk_text_iter_equal (&ins, &end))
- ins = start;
- }
+ get_iter_at_pointer (text_view, &cursor, NULL, NULL);
+
+ start = cursor;
+ extend_selection (text_view, data->granularity, &start, &end);
- gtk_text_buffer_select_range (buffer, &ins, &bound);
- }
+ /* either the selection extends to the front, or end (or not) */
+ if (gtk_text_iter_compare (&cursor, &orig_start) < 0)
+ gtk_text_buffer_select_range (buffer, &start, &orig_end);
+ else
+ gtk_text_buffer_select_range (buffer, &end, &orig_start);
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (buffer,
- "insert"));
+ gtk_text_buffer_get_insert (buffer));
}
-
/* If we had to scroll offscreen, insert a timeout to do so
* again. Note that in the timeout, even if the mouse doesn't
* move, due to this scroll xoffset/yoffset will have changed
g_source_remove (text_view->scroll_timeout);
text_view->scroll_timeout =
- g_timeout_add (50, selection_scan_timeout, text_view);
+ gdk_threads_add_timeout (50, selection_scan_timeout, text_view);
return TRUE;
}
const GtkTextIter *iter,
GdkEventButton *button)
{
- GtkTextIter start, end;
+ GtkTextIter cursor, ins, bound;
+ GtkTextIter orig_start, orig_end;
GtkTextBuffer *buffer;
- SelectionGranularity granularity;
+ SelectionData *data;
- g_return_if_fail (text_view->selection_drag_handler == 0);
+ if (text_view->selection_drag_handler != 0)
+ return;
+
+ data = g_new0 (SelectionData, 1);
if (button->type == GDK_2BUTTON_PRESS)
- granularity = SELECT_WORDS;
+ data->granularity = SELECT_WORDS;
else if (button->type == GDK_3BUTTON_PRESS)
- granularity = SELECT_LINES;
+ data->granularity = SELECT_LINES;
else
- granularity = SELECT_CHARACTERS;
+ data->granularity = SELECT_CHARACTERS;
gtk_grab_add (GTK_WIDGET (text_view));
buffer = get_buffer (text_view);
- start = *iter;
+ cursor = *iter;
+ ins = cursor;
- extend_selection (text_view, granularity, &start, &end);
+ extend_selection (text_view, data->granularity, &ins, &bound);
+ orig_start = ins;
+ orig_end = bound;
if (button->state & GDK_SHIFT_MASK)
{
/* Extend selection */
+ GtkTextIter old_ins, old_bound;
GtkTextIter old_start, old_end;
- gtk_text_buffer_get_selection_bounds (buffer, &old_start, &old_end);
-
- gtk_text_iter_order (&start, &old_start);
- gtk_text_iter_order (&old_end, &end);
+ gtk_text_buffer_get_iter_at_mark (buffer, &old_ins, gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_get_iter_at_mark (buffer, &old_bound, gtk_text_buffer_get_selection_bound (buffer));
+ old_start = old_ins;
+ old_end = old_bound;
+ gtk_text_iter_order (&old_start, &old_end);
- /* Now start is the first of the starts, and end is the
- * last of the ends
- */
+ /* move the front cursor, if the mouse is in front of the selection. Should the
+ * cursor however be inside the selection (this happens on tripple click) then we
+ * move the side which was last moved (current insert mark) */
+ if (gtk_text_iter_compare (&cursor, &old_start) <= 0 ||
+ (gtk_text_iter_compare (&cursor, &old_end) < 0 &&
+ gtk_text_iter_compare (&old_ins, &old_bound) <= 0))
+ {
+ bound = old_end;
+ orig_start = old_end;
+ orig_end = old_end;
+ }
+ else
+ {
+ ins = bound;
+ bound = old_start;
+ orig_end = bound;
+ orig_start = bound;
+ }
}
- gtk_text_buffer_select_range (buffer, &end, &start);
+ gtk_text_buffer_select_range (buffer, &ins, &bound);
+
+ gtk_text_iter_order (&orig_start, &orig_end);
+ data->orig_start = gtk_text_buffer_create_mark (buffer, NULL,
+ &orig_start, TRUE);
+ data->orig_end = gtk_text_buffer_create_mark (buffer, NULL,
+ &orig_end, TRUE);
- text_view->selection_drag_handler = g_signal_connect (text_view,
- "motion_notify_event",
- G_CALLBACK (selection_motion_event_handler),
- GINT_TO_POINTER (granularity));
+ gtk_text_view_check_cursor_blink (text_view);
+
+ text_view->selection_drag_handler = g_signal_connect_data (text_view,
+ "motion_notify_event",
+ G_CALLBACK (selection_motion_event_handler),
+ data,
+ (GClosureNotify) selection_data_free, 0);
}
/* returns whether we were really dragging */
static gboolean
-gtk_text_view_end_selection_drag (GtkTextView *text_view, GdkEventButton *event)
+gtk_text_view_end_selection_drag (GtkTextView *text_view)
{
if (text_view->selection_drag_handler == 0)
return FALSE;
"gtk-split-cursor", &split_cursor,
NULL);
- if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_LTR)
- new_keyboard_dir = GTK_TEXT_DIR_LTR;
+ if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
+ new_keyboard_dir = GTK_TEXT_DIR_RTL;
else
- new_keyboard_dir = GTK_TEXT_DIR_RTL;
+ new_keyboard_dir = GTK_TEXT_DIR_LTR;
if (split_cursor)
new_cursor_dir = GTK_TEXT_DIR_NONE;
else
gtk_text_layout_set_cursor_visible (text_view->layout, FALSE);
+ gtk_text_layout_set_overwrite_mode (text_view->layout,
+ text_view->overwrite_mode && text_view->editable);
+
ltr_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
rtl_context = gtk_widget_create_pango_context (GTK_WIDGET (text_view));
}
gtk_text_view_stop_cursor_blink (text_view);
- gtk_text_view_end_selection_drag (text_view, NULL);
+ gtk_text_view_end_selection_drag (text_view);
g_object_unref (text_view->layout);
text_view->layout = NULL;
* DND feature
*/
+static void
+drag_begin_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer data)
+{
+ GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
+ GtkTextIter start;
+ GtkTextIter end;
+ GdkPixmap *pixmap = NULL;
+
+ g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
+
+ if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
+ pixmap = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
+
+ if (pixmap)
+ {
+ gtk_drag_set_icon_pixmap (context,
+ gdk_drawable_get_colormap (pixmap),
+ pixmap,
+ NULL,
+ -2, -2);
+ g_object_unref (pixmap);
+ }
+ else
+ {
+ gtk_drag_set_icon_default (context);
+ }
+}
+
static void
gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventMotion *event)
{
- GdkDragContext *context;
GtkTargetList *target_list;
text_view->drag_start_x = -1;
text_view->drag_start_y = -1;
text_view->pending_place_cursor_button = 0;
-
- target_list = gtk_target_list_new (target_table,
- G_N_ELEMENTS (target_table));
- gtk_target_list_add_text_targets (target_list, 0);
-
- context = gtk_drag_begin (GTK_WIDGET (text_view), target_list,
- GDK_ACTION_COPY | GDK_ACTION_MOVE,
- 1, (GdkEvent*)event);
- gtk_target_list_unref (target_list);
+ target_list = gtk_text_buffer_get_copy_target_list (get_buffer (text_view));
- gtk_drag_set_icon_default (context);
+ g_signal_connect (text_view, "drag_begin",
+ G_CALLBACK (drag_begin_cb), NULL);
+ gtk_drag_begin (GTK_WIDGET (text_view), target_list,
+ GDK_ACTION_COPY | GDK_ACTION_MOVE,
+ 1, (GdkEvent*)event);
}
static void
gtk_text_view_drag_end (GtkWidget *widget,
GdkDragContext *context)
{
- GtkTextView *text_view;
-
- text_view = GTK_TEXT_VIEW (widget);
}
static void
guint info,
guint time)
{
- GtkTextView *text_view;
-
- text_view = GTK_TEXT_VIEW (widget);
+ GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
- if (selection_data->target == gdk_atom_intern ("GTK_TEXT_BUFFER_CONTENTS", FALSE))
+ if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
{
- GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
-
gtk_selection_data_set (selection_data,
- gdk_atom_intern ("GTK_TEXT_BUFFER_CONTENTS", FALSE),
+ gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
8, /* bytes */
(void*)&buffer,
sizeof (buffer));
}
- else
+ else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
{
- gchar *str;
GtkTextIter start;
GtkTextIter end;
+ guint8 *str = NULL;
+ gsize len;
- str = NULL;
+ if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
+ {
+ /* Extract the selected text */
+ str = gtk_text_buffer_serialize (buffer, buffer,
+ selection_data->target,
+ &start, &end,
+ &len);
+ }
- if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
- &start, &end))
+ if (str)
+ {
+ gtk_selection_data_set (selection_data,
+ selection_data->target,
+ 8, /* bytes */
+ (guchar *) str, len);
+ g_free (str);
+ }
+ }
+ else
+ {
+ GtkTextIter start;
+ GtkTextIter end;
+ gchar *str = NULL;
+
+ if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
{
/* Extract the selected text */
str = gtk_text_iter_get_visible_text (&start, &end);
gtk_text_view_drag_data_delete (GtkWidget *widget,
GdkDragContext *context)
{
- GtkTextView *text_view;
-
- text_view = GTK_TEXT_VIEW (widget);
-
gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->buffer,
TRUE, GTK_TEXT_VIEW (widget)->editable);
}
GtkTextIter end;
GdkRectangle target_rect;
gint bx, by;
+ GdkAtom target;
GdkDragAction suggested_action = 0;
text_view = GTK_TEXT_VIEW (widget);
&newplace,
bx, by);
- if (gtk_drag_dest_find_target (widget, context,
- gtk_drag_dest_get_target_list (widget)) == GDK_NONE)
+ target = gtk_drag_dest_find_target (widget, context,
+ gtk_drag_dest_get_target_list (widget));
+
+ if (target == GDK_NONE)
{
/* can't accept any of the offered targets */
}
else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
- &start, &end) &&
+ &start, &end) &&
gtk_text_iter_compare (&newplace, &start) >= 0 &&
gtk_text_iter_compare (&newplace, &end) <= 0)
{
gtk_text_mark_set_visible (text_view->dnd_mark, FALSE);
}
- gtk_text_buffer_move_mark (get_buffer (text_view),
- text_view->dnd_mark,
- &newplace);
-
- DV(g_print (G_STRLOC": scrolling to mark\n"));
- gtk_text_view_scroll_to_mark (text_view,
- text_view->dnd_mark,
- DND_SCROLL_MARGIN, FALSE, 0.0, 0.0);
-
- if (text_view->scroll_timeout != 0) /* reset on every motion event */
- g_source_remove (text_view->scroll_timeout);
-
- text_view->scroll_timeout =
- g_timeout_add (50, drag_scan_timeout, text_view);
+ if (!text_view->scroll_timeout)
+ text_view->scroll_timeout =
+ gdk_threads_add_timeout (100, drag_scan_timeout, text_view);
/* TRUE return means don't propagate the drag motion to parent
* widgets that may also be drop sites.
GtkTextIter *drop_point,
GtkSelectionData *selection_data)
{
- gchar *str;
+ guchar *str;
str = gtk_selection_data_get_text (selection_data);
if (str)
{
- gtk_text_buffer_insert_interactive (get_buffer (text_view),
- drop_point, str, -1,
- text_view->editable);
+ if (!gtk_text_buffer_insert_interactive (get_buffer (text_view),
+ drop_point, (gchar *) str, -1,
+ text_view->editable))
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
+
g_free (str);
}
}
gtk_text_buffer_begin_user_action (buffer);
- if (selection_data->target == gdk_atom_intern ("GTK_TEXT_BUFFER_CONTENTS", FALSE))
+ if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
{
GtkTextBuffer *src_buffer = NULL;
GtkTextIter start, end;
if (gtk_text_buffer_get_tag_table (src_buffer) !=
gtk_text_buffer_get_tag_table (buffer))
- copy_tags = FALSE;
+ {
+ /* try to find a suitable rich text target instead */
+ GdkAtom *atoms;
+ gint n_atoms;
+ GList *list;
+ GdkAtom target = GDK_NONE;
+
+ copy_tags = FALSE;
+
+ atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms);
+
+ for (list = context->targets; list; list = g_list_next (list))
+ {
+ gint i;
+
+ for (i = 0; i < n_atoms; i++)
+ if (GUINT_TO_POINTER (atoms[i]) == list->data)
+ {
+ target = atoms[i];
+ break;
+ }
+ }
+
+ g_free (atoms);
+
+ if (target != GDK_NONE)
+ {
+ gtk_drag_get_data (widget, context, target, time);
+ gtk_text_buffer_end_user_action (buffer);
+ return;
+ }
+ }
if (gtk_text_buffer_get_selection_bounds (src_buffer,
&start,
}
}
}
+ else if (selection_data->length > 0 &&
+ info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
+ {
+ gboolean retval;
+ GError *error = NULL;
+
+ retval = gtk_text_buffer_deserialize (buffer, buffer,
+ selection_data->target,
+ &drop_point,
+ (guint8 *) selection_data->data,
+ selection_data->length,
+ &error);
+
+ if (!retval)
+ {
+ g_warning ("error pasting: %s\n", error->message);
+ g_clear_error (&error);
+ }
+ }
else
insert_text_data (text_view, &drop_point, selection_data);
-
+
done:
gtk_drag_finish (context, success,
success && context->action == GDK_ACTION_MOVE,
{
gboolean need_adjust = FALSE;
- g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
-
if (hadj)
g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
else
if (text_view->hadjustment != hadj)
{
text_view->hadjustment = hadj;
- g_object_ref (text_view->hadjustment);
- gtk_object_sink (GTK_OBJECT (text_view->hadjustment));
+ g_object_ref_sink (text_view->hadjustment);
g_signal_connect (text_view->hadjustment, "value_changed",
G_CALLBACK (gtk_text_view_value_changed),
if (text_view->vadjustment != vadj)
{
text_view->vadjustment = vadj;
- g_object_ref (text_view->vadjustment);
- gtk_object_sink (GTK_OBJECT (text_view->vadjustment));
+ g_object_ref_sink (text_view->vadjustment);
g_signal_connect (text_view->vadjustment, "value_changed",
G_CALLBACK (gtk_text_view_value_changed),
{
dx = text_view->xoffset - (gint)adj->value;
text_view->xoffset = adj->value;
+
+ /* If the change is due to a size change we need
+ * to invalidate the entire text window because there might be
+ * right-aligned or centered text
+ */
+ if (text_view->width_changed)
+ {
+ if (GTK_WIDGET_REALIZED (text_view))
+ gdk_window_invalidate_rect (text_view->text_window->bin_window, NULL, FALSE);
+
+ text_view->width_changed = FALSE;
+ }
}
else if (adj == text_view->vadjustment)
{
if (!strcmp (str, "\n"))
{
- gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
- text_view->editable);
+ if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
+ text_view->editable))
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
}
else
{
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
&insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
if (!gtk_text_iter_ends_line (&insert))
gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
}
- gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
- text_view->editable);
+
+ if (!gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
+ text_view->editable))
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ }
}
gtk_text_buffer_end_user_action (get_buffer (text_view));
+ gtk_text_view_set_virtual_cursor_pos (text_view, -1, -1);
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
}
static void
gchar *str;
PangoAttrList *attrs;
gint cursor_pos;
+ GtkTextIter iter;
+
+ gtk_text_buffer_get_iter_at_mark (text_view->buffer, &iter,
+ gtk_text_buffer_get_insert (text_view->buffer));
+
+ /* Keypress events are passed to input method even if cursor position is not editable;
+ * so beep here if it's multi-key input sequence, input method will be reset in
+ * key-press-event handler. */
+ if (!gtk_text_iter_can_insert (&iter, text_view->editable))
+ {
+ gtk_widget_error_bell (GTK_WIDGET (text_view));
+ return;
+ }
gtk_im_context_get_preedit_string (context, &str, &attrs, &cursor_pos);
gtk_text_layout_set_preedit_string (text_view->layout, str, attrs, cursor_pos);
pango_attr_list_unref (attrs);
g_free (str);
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ if (GTK_WIDGET_HAS_FOCUS (text_view))
+ gtk_text_view_scroll_mark_onscreen (text_view,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
}
static gboolean
gtk_text_view_reset_im_context (text_view);
}
+static void
+gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
+ const GParamSpec *pspec,
+ gpointer data)
+{
+ GtkWidget *widget = GTK_WIDGET (data);
+ GtkTargetList *view_list;
+ GtkTargetList *buffer_list;
+ GList *list;
+
+ view_list = gtk_drag_dest_get_target_list (widget);
+ buffer_list = gtk_text_buffer_get_paste_target_list (buffer);
+
+ if (view_list)
+ gtk_target_list_ref (view_list);
+ else
+ view_list = gtk_target_list_new (NULL, 0);
+
+ list = view_list->list;
+ while (list)
+ {
+ GtkTargetPair *pair = list->data;
+
+ list = g_list_next (list); /* get next element before removing */
+
+ if (pair->info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT &&
+ pair->info <= GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
+ {
+ gtk_target_list_remove (view_list, pair->target);
+ }
+ }
+
+ for (list = buffer_list->list; list; list = g_list_next (list))
+ {
+ GtkTargetPair *pair = list->data;
+
+ gtk_target_list_add (view_list, pair->target, pair->flags, pair->info);
+ }
+
+ gtk_drag_dest_set_target_list (widget, view_list);
+ gtk_target_list_unref (view_list);
+}
+
static void
gtk_text_view_get_cursor_location (GtkTextView *text_view,
GdkRectangle *pos)
GtkTextIter insert;
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
gtk_text_layout_get_cursor_locations (text_view->layout, &insert, pos, NULL);
}
{
GdkRectangle pos;
+ if (!text_view->layout)
+ return;
+
if (x == -1 || y == -1)
gtk_text_view_get_cursor_location (text_view, &pos);
{
GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
- g_object_set_data (G_OBJECT (menuitem), "gtk-signal", (char *)signal);
+ g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
g_signal_connect (menuitem, "activate",
G_CALLBACK (activate_cb), text_view);
/* We implicitely rely here on the fact that if we are pasting ourself, we'll
* have text targets as well as the private GTK_TEXT_BUFFER_CONTENTS target.
*/
- gboolean clipboard_contains_text = gtk_selection_data_targets_include_text (data);
+ gboolean clipboard_contains_text;
GtkWidget *menuitem;
GtkWidget *submenu;
gboolean have_selection;
gboolean can_insert;
GtkTextIter iter;
GtkTextIter sel_start, sel_end;
+ gboolean show_input_method_menu;
+ gboolean show_unicode_menu;
+ clipboard_contains_text = gtk_selection_data_targets_include_text (data);
+
if (text_view->popup_menu)
gtk_widget_destroy (text_view->popup_menu);
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
- menuitem = gtk_menu_item_new_with_mnemonic (_("Select _All"));
+ menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
g_signal_connect (menuitem, "activate",
G_CALLBACK (select_all_cb), text_view);
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
- menuitem = gtk_separator_menu_item_new ();
- gtk_widget_show (menuitem);
- gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (text_view)),
+ "gtk-show-input-method-menu", &show_input_method_menu,
+ "gtk-show-unicode-menu", &show_unicode_menu,
+ NULL);
- menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
- gtk_widget_show (menuitem);
- gtk_widget_set_sensitive (menuitem, can_insert);
+ if (show_input_method_menu || show_unicode_menu)
+ {
+ menuitem = gtk_separator_menu_item_new ();
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
+ }
- submenu = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
- gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
-
- gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (text_view->im_context),
- GTK_MENU_SHELL (submenu));
+ if (show_input_method_menu)
+ {
+ menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
+ gtk_widget_show (menuitem);
+ gtk_widget_set_sensitive (menuitem, can_insert);
- menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
- gtk_widget_show (menuitem);
- gtk_widget_set_sensitive (menuitem, can_insert);
-
- submenu = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
- gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
+ submenu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+ gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
+
+ gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (text_view->im_context),
+ GTK_MENU_SHELL (submenu));
+ }
- _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
- unichar_chosen_func,
- text_view);
+ if (show_unicode_menu)
+ {
+ menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
+ gtk_widget_show (menuitem);
+ gtk_widget_set_sensitive (menuitem, can_insert);
+ submenu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+ gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
+
+ _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
+ unichar_chosen_func,
+ text_view);
+ }
+
g_signal_emit (text_view,
signals[POPULATE_POPUP],
0,
{
PopupInfo *info = g_new (PopupInfo, 1);
- /* should not need this, see http://bugzilla.gnome.org/show_bug.cgi?id=74620 */
- gtk_text_view_end_selection_drag (text_view, event);
-
/* In order to know what entries we should make sensitive, we
* ask for the current targets of the clipboard, and when
* we get them, then we actually pop up the menu.
gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
GDK_SELECTION_CLIPBOARD),
- gdk_atom_intern ("TARGETS", FALSE),
+ gdk_atom_intern_static_string ("TARGETS"),
popup_targets_received,
info);
}
static void
text_window_realize (GtkTextWindow *win,
- GdkWindow *parent)
+ GtkWidget *widget)
{
GdkWindowAttr attributes;
gint attributes_mask;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
- win->window = gdk_window_new (parent,
+ win->window = gdk_window_new (widget->window,
&attributes,
attributes_mask);
+ gdk_window_set_back_pixmap (win->window, NULL, FALSE);
+
gdk_window_show (win->window);
gdk_window_set_user_data (win->window, win->widget);
+ gdk_window_lower (win->window);
attributes.x = 0;
attributes.y = 0;
if (win->type == GTK_TEXT_WINDOW_TEXT)
{
- /* I-beam cursor */
- cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (parent),
- GDK_XTERM);
- gdk_window_set_cursor (win->bin_window, cursor);
- gdk_cursor_unref (cursor);
-
- gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->im_context,
+ if (GTK_WIDGET_IS_SENSITIVE (widget))
+ {
+ /* I-beam cursor */
+ cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (widget->window),
+ GDK_XTERM);
+ gdk_window_set_cursor (win->bin_window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+
+ gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->im_context,
win->window);
gdk_window_set_background (win->bin_window,
- &win->widget->style->base[GTK_WIDGET_STATE (win->widget)]);
+ &widget->style->base[GTK_WIDGET_STATE (widget)]);
}
else
{
gdk_window_set_background (win->bin_window,
- &win->widget->style->bg[GTK_WIDGET_STATE (win->widget)]);
+ &widget->style->bg[GTK_WIDGET_STATE (widget)]);
}
g_object_set_qdata (G_OBJECT (win->window),
#if 0
{
- GdkColor color = { 0, 65535, 0, 0 };
- GdkGC *gc = gdk_gc_new (win->bin_window);
- gdk_gc_set_rgb_fg_color (gc, &color);
- gdk_draw_rectangle (win->bin_window,
- gc, TRUE, window_rect.x, window_rect.y,
- window_rect.width, window_rect.height);
- g_object_unref (gc);
+ cairo_t *cr = gdk_cairo_create (win->bin_window);
+ gdk_cairo_rectangle (cr, &window_rect);
+ cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
+ cairo_fill (cr);
+ cairo_destroy (cr);
}
#endif
}
+static void
+text_window_invalidate_cursors (GtkTextWindow *win)
+{
+ GtkTextView *text_view = GTK_TEXT_VIEW (win->widget);
+ GtkTextIter iter;
+ GdkRectangle strong;
+ GdkRectangle weak;
+ gboolean draw_arrow;
+ gfloat cursor_aspect_ratio;
+ gint stem_width;
+ gint arrow_width;
+
+ gtk_text_buffer_get_iter_at_mark (text_view->buffer, &iter,
+ gtk_text_buffer_get_insert (text_view->buffer));
+
+ if (_gtk_text_layout_get_block_cursor (text_view->layout, &strong))
+ {
+ text_window_invalidate_rect (win, &strong);
+ return;
+ }
+
+ gtk_text_layout_get_cursor_locations (text_view->layout, &iter,
+ &strong, &weak);
+
+ /* cursor width calculation as in gtkstyle.c:draw_insertion_cursor(),
+ * ignoring the text direction be exposing both sides of the cursor
+ */
+
+ draw_arrow = (strong.x != weak.x || strong.y != weak.y);
+
+ gtk_widget_style_get (win->widget,
+ "cursor-aspect-ratio", &cursor_aspect_ratio,
+ NULL);
+
+ stem_width = strong.height * cursor_aspect_ratio + 1;
+ arrow_width = stem_width + 1;
+
+ strong.width = stem_width;
+
+ /* round up to the next even number */
+ if (stem_width & 1)
+ stem_width++;
+
+ strong.x -= stem_width / 2;
+ strong.width += stem_width;
+
+ if (draw_arrow)
+ {
+ strong.x -= arrow_width;
+ strong.width += arrow_width * 2;
+ }
+
+ text_window_invalidate_rect (win, &strong);
+
+ if (draw_arrow) /* == have weak */
+ {
+ stem_width = weak.height * cursor_aspect_ratio + 1;
+ arrow_width = stem_width + 1;
+
+ weak.width = stem_width;
+
+ /* round up to the next even number */
+ if (stem_width & 1)
+ stem_width++;
+
+ weak.x -= stem_width / 2;
+ weak.width += stem_width;
+
+ weak.x -= arrow_width;
+ weak.width += arrow_width * 2;
+
+ text_window_invalidate_rect (win, &weak);
+ }
+}
+
static gint
text_window_get_width (GtkTextWindow *win)
{
width, 0);
/* if the widget is already realized we need to realize the child manually */
if (GTK_WIDGET_REALIZED (text_view))
- text_window_realize (*winp, GTK_WIDGET (text_view)->window);
+ text_window_realize (*winp, GTK_WIDGET (text_view));
}
else
{
/* if the widget is already realized we need to realize the child manually */
if (GTK_WIDGET_REALIZED (text_view))
- text_window_realize (*winp, GTK_WIDGET (text_view)->window);
+ text_window_realize (*winp, GTK_WIDGET (text_view));
}
else
{
case GTK_TEXT_WINDOW_LEFT:
if (text_view->left_window)
return text_view->left_window->requisition.width;
+ break;
case GTK_TEXT_WINDOW_RIGHT:
if (text_view->right_window)
return text_view->right_window->requisition.width;
+ break;
case GTK_TEXT_WINDOW_TOP:
if (text_view->top_window)
return text_view->top_window->requisition.height;
+ break;
case GTK_TEXT_WINDOW_BOTTOM:
if (text_view->bottom_window)
return text_view->bottom_window->requisition.height;
+ break;
default:
g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size()");
g_object_ref (vc->anchor);
g_object_set_data (G_OBJECT (child),
- "gtk-text-view-child",
+ I_("gtk-text-view-child"),
vc);
gtk_text_child_anchor_register_child (anchor, child, layout);
vc->y = y;
g_object_set_data (G_OBJECT (child),
- "gtk-text-view-child",
+ I_("gtk-text-view-child"),
vc);
return vc;
text_view_child_free (GtkTextViewChild *child)
{
g_object_set_data (G_OBJECT (child->widget),
- "gtk-text-view-child", NULL);
+ I_("gtk-text-view-child"), NULL);
if (child->anchor)
{
* @anchor: a #GtkTextChildAnchor in the #GtkTextBuffer for @text_view
*
* Adds a child widget in the text buffer, at the given @anchor.
- *
**/
void
gtk_text_view_add_child_at_anchor (GtkTextView *text_view,
* @ypos: Y position of child in window coordinates
*
* Adds a child at fixed coordinates in one of the text widget's
- * windows. The window must have nonzero size (see
- * gtk_text_view_set_border_window_size()). Note that the child
+ * windows. The window must have nonzero size (see
+ * gtk_text_view_set_border_window_size()). Note that the child
* coordinates are given relative to the #GdkWindow in question, and
* that these coordinates have no sane relationship to scrolling. When
* placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
* would be to update all child positions when the scroll adjustments
* change or the text buffer changes. See bug 64518 on
* bugzilla.gnome.org for status of fixing this issue.
- *
**/
void
-gtk_text_view_add_child_in_window (GtkTextView *text_view,
- GtkWidget *child,
- GtkTextWindowType which_window,
- gint xpos,
- gint ypos)
+gtk_text_view_add_child_in_window (GtkTextView *text_view,
+ GtkWidget *child,
+ GtkTextWindowType which_window,
+ gint xpos,
+ gint ypos)
{
GtkTextViewChild *vc;
* @ypos: new Y position in window coordinates
*
* Updates the position of a child, as for gtk_text_view_add_child_in_window().
- *
**/
void
-gtk_text_view_move_child (GtkTextView *text_view,
- GtkWidget *child,
- gint xpos,
- gint ypos)
+gtk_text_view_move_child (GtkTextView *text_view,
+ GtkWidget *child,
+ gint xpos,
+ gint ypos)
{
GtkTextViewChild *vc;
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
*
- * Moves the given @iter forward by one display (wrapped) line. A
- * display line is different from a paragraph. Paragraphs are
+ * Moves the given @iter forward by one display (wrapped) line.
+ * A display line is different from a paragraph. Paragraphs are
* separated by newlines or other paragraph separator characters.
- * Display lines are created by line-wrapping a paragraph. If
+ * Display lines are created by line-wrapping a paragraph. If
* wrapping is turned off, display lines and paragraphs will be the
* same. Display lines are divided differently for each view, since
* they depend on the view's width; paragraphs are the same in all
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
*
- * Moves the given @iter backward by one display (wrapped) line. A
- * display line is different from a paragraph. Paragraphs are
+ * Moves the given @iter backward by one display (wrapped) line.
+ * A display line is different from a paragraph. Paragraphs are
* separated by newlines or other paragraph separator characters.
- * Display lines are created by line-wrapping a paragraph. If
+ * Display lines are created by line-wrapping a paragraph. If
* wrapping is turned off, display lines and paragraphs will be the
* same. Display lines are divided differently for each view, since
* they depend on the view's width; paragraphs are the same in all
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
*
- * Moves the given @iter forward to the next display line end. A
- * display line is different from a paragraph. Paragraphs are
+ * Moves the given @iter forward to the next display line end.
+ * A display line is different from a paragraph. Paragraphs are
* separated by newlines or other paragraph separator characters.
- * Display lines are created by line-wrapping a paragraph. If
+ * Display lines are created by line-wrapping a paragraph. If
* wrapping is turned off, display lines and paragraphs will be the
* same. Display lines are divided differently for each view, since
* they depend on the view's width; paragraphs are the same in all
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
*
- * Moves the given @iter backward to the next display line start. A
- * display line is different from a paragraph. Paragraphs are
+ * Moves the given @iter backward to the next display line start.
+ * A display line is different from a paragraph. Paragraphs are
* separated by newlines or other paragraph separator characters.
- * Display lines are created by line-wrapping a paragraph. If
+ * Display lines are created by line-wrapping a paragraph. If
* wrapping is turned off, display lines and paragraphs will be the
* same. Display lines are divided differently for each view, since
* they depend on the view's width; paragraphs are the same in all
* gtk_text_view_move_visually:
* @text_view: a #GtkTextView
* @iter: a #GtkTextIter
- * @count: number of characters to move (negative moves left, positive moves right)
+ * @count: number of characters to move (negative moves left,
+ * positive moves right)
*
* Move the iterator a given number of characters visually, treating
* it as the strong cursor position. If @count is positive, then the
* cursor position will be @count positions to the left of the old
* cursor position.
*
- * In the presence of bidirection text, the correspondence
+ * In the presence of bi-directional text, the correspondence
* between logical and visual order will depend on the direction
* of the current run, and there may be jumps when the cursor
* is moved off of the end of a run.
return gtk_text_layout_move_iter_visually (text_view->layout, iter, count);
}
+
+#define __GTK_TEXT_VIEW_C__
+#include "gtkaliasdef.c"