#include "gtktextview.h"
#include "gtkimmulticontext.h"
#include "gdk/gdkkeysyms.h"
+#include "gtksizegroup.h" /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
#include "gtktextutil.h"
+#include "gtkwindow.h"
#include <string.h>
/* How scrolling, validation, exposes, etc. work.
*
*/
-#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window)
-#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window)
-
#if 0
#define DEBUG_VALIDATION_AND_SCROLLING
#endif
#define DV(x)
#endif
+#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window)
+#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window)
+
struct _GtkTextPendingScroll
{
GtkTextMark *mark;
SET_SCROLL_ADJUSTMENTS,
POPULATE_POPUP,
MOVE_CURSOR,
+ PAGE_HORIZONTALLY,
SET_ANCHOR,
INSERT_AT_CURSOR,
DELETE_FROM_CURSOR,
COPY_CLIPBOARD,
PASTE_CLIPBOARD,
TOGGLE_OVERWRITE,
+ MOVE_FOCUS,
LAST_SIGNAL
};
GdkEventExpose *expose);
static void gtk_text_view_draw_focus (GtkWidget *widget);
static void gtk_text_view_grab_focus (GtkWidget *widget);
+static gboolean gtk_text_view_focus (GtkWidget *widget,
+ GtkDirectionType direction);
+
/* Source side drag signals */
static void gtk_text_view_drag_begin (GtkWidget *widget,
static void gtk_text_view_set_scroll_adjustments (GtkTextView *text_view,
GtkAdjustment *hadj,
GtkAdjustment *vadj);
-static void gtk_text_view_popup_menu (GtkWidget *widget);
-
-static void gtk_text_view_move_cursor (GtkTextView *text_view,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection);
+static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
+
+static void gtk_text_view_move_cursor (GtkTextView *text_view,
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection);
+static void gtk_text_view_page_horizontally (GtkTextView *text_view,
+ gint count,
+ gboolean extend_selection);
static void gtk_text_view_set_anchor (GtkTextView *text_view);
static void gtk_text_view_scroll_pages (GtkTextView *text_view,
gint count);
+static void gtk_text_view_scroll_hpages (GtkTextView *text_view,
+ gint count);
static void gtk_text_view_insert_at_cursor (GtkTextView *text_view,
const gchar *str);
static void gtk_text_view_delete_from_cursor (GtkTextView *text_view,
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,
+ GtkDirectionType direction_type);
static void gtk_text_view_unselect (GtkTextView *text_view);
static void gtk_text_view_validate_onscreen (GtkTextView *text_view);
gdouble xalign,
gdouble yalign);
-static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
-static void gtk_text_view_update_adjustments (GtkTextView *text_view);
-static void gtk_text_view_invalidate (GtkTextView *text_view);
+static gboolean gtk_text_view_flush_scroll (GtkTextView *text_view);
+static void gtk_text_view_update_adjustments (GtkTextView *text_view);
+static void gtk_text_view_invalidate (GtkTextView *text_view);
+static void gtk_text_view_flush_first_validate (GtkTextView *text_view);
static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
GtkWidget *child);
static void gtk_text_view_forall (GtkContainer *container,
gboolean include_internals,
- GtkCallback callback,
+ GtkCallback callback,
gpointer callback_data);
/* FIXME probably need the focus methods. */
{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
{ "TEXT", 0, TARGET_TEXT },
- { "text/plain", 0, TARGET_STRING },
{ "STRING", 0, TARGET_STRING }
};
widget_class->motion_notify_event = gtk_text_view_motion_event;
widget_class->expose_event = gtk_text_view_expose_event;
widget_class->grab_focus = gtk_text_view_grab_focus;
+ widget_class->focus = gtk_text_view_focus;
widget_class->drag_begin = gtk_text_view_drag_begin;
widget_class->drag_end = gtk_text_view_drag_end;
container_class->forall = gtk_text_view_forall;
klass->move_cursor = gtk_text_view_move_cursor;
+ klass->page_horizontally = gtk_text_view_page_horizontally;
klass->set_anchor = gtk_text_view_set_anchor;
klass->insert_at_cursor = gtk_text_view_insert_at_cursor;
klass->delete_from_cursor = gtk_text_view_delete_from_cursor;
klass->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->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
/*
G_PARAM_READWRITE));
- /*
- * Style properties
- */
-
- gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boxed ("cursor_color",
- _("Cursor color"),
- _("Color with which to draw insertion cursor"),
- GDK_TYPE_COLOR,
- G_PARAM_READABLE));
-
-
/*
* Signals
*/
_gtk_marshal_VOID__ENUM_INT_BOOLEAN,
GTK_TYPE_NONE, 3, GTK_TYPE_MOVEMENT_STEP, GTK_TYPE_INT, GTK_TYPE_BOOL);
+ signals[PAGE_HORIZONTALLY] =
+ gtk_signal_new ("page_horizontally",
+ GTK_RUN_LAST | GTK_RUN_ACTION,
+ GTK_CLASS_TYPE (object_class),
+ GTK_SIGNAL_OFFSET (GtkTextViewClass, page_horizontally),
+ _gtk_marshal_VOID__INT_BOOLEAN,
+ GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_BOOL);
+
signals[SET_ANCHOR] =
gtk_signal_new ("set_anchor",
GTK_RUN_LAST | GTK_RUN_ACTION,
_gtk_marshal_VOID__VOID,
GTK_TYPE_NONE, 0);
+ signals[MOVE_FOCUS] =
+ gtk_signal_new ("move_focus",
+ GTK_RUN_LAST | GTK_RUN_ACTION,
+ GTK_CLASS_TYPE (object_class),
+ GTK_SIGNAL_OFFSET (GtkTextViewClass, move_focus),
+ _gtk_marshal_VOID__ENUM,
+ GTK_TYPE_NONE, 1, GTK_TYPE_DIRECTION_TYPE);
+
signals[SET_SCROLL_ADJUSTMENTS] =
gtk_signal_new ("set_scroll_adjustments",
GTK_RUN_LAST,
*/
binding_set = gtk_binding_set_by_class (klass);
-
+
/* Moving the insertion point */
add_move_binding (binding_set, GDK_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
- add_move_binding (binding_set, GDK_f, GDK_CONTROL_MASK,
- GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
-
- add_move_binding (binding_set, GDK_b, GDK_CONTROL_MASK,
- GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
-
add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
- /* Eventually we want to move by display lines, not paragraphs */
add_move_binding (binding_set, GDK_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
add_move_binding (binding_set, GDK_KP_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
- add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
- GTK_MOVEMENT_DISPLAY_LINES, -1);
-
- add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
- GTK_MOVEMENT_DISPLAY_LINES, 1);
-
add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, -1);
add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, 1);
- add_move_binding (binding_set, GDK_a, GDK_CONTROL_MASK,
- GTK_MOVEMENT_PARAGRAPH_ENDS, -1);
-
- add_move_binding (binding_set, GDK_e, GDK_CONTROL_MASK,
- GTK_MOVEMENT_PARAGRAPH_ENDS, 1);
-
- add_move_binding (binding_set, GDK_f, GDK_MOD1_MASK,
- GTK_MOVEMENT_WORDS, 1);
-
- add_move_binding (binding_set, GDK_b, GDK_MOD1_MASK,
- GTK_MOVEMENT_WORDS, -1);
-
add_move_binding (binding_set, GDK_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KP_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
+
+ /* Select all
+ */
+ gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+ "move_cursor", 3,
+ GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
+ GTK_TYPE_INT, -1,
+ GTK_TYPE_BOOL, FALSE);
+ gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+ "move_cursor", 3,
+ GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
+ GTK_TYPE_INT, 1,
+ GTK_TYPE_BOOL, TRUE);
+
- /* Setting the cut/paste/copy anchor */
- gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
- "set_anchor", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
- "set_anchor", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_CONTROL_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, -1,
+ GTK_TYPE_BOOL, FALSE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, -1,
+ GTK_TYPE_BOOL, TRUE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, GDK_CONTROL_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, -1,
+ GTK_TYPE_BOOL, FALSE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, -1,
+ GTK_TYPE_BOOL, TRUE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_CONTROL_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, 1,
+ GTK_TYPE_BOOL, FALSE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, 1,
+ GTK_TYPE_BOOL, TRUE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, GDK_CONTROL_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, 1,
+ GTK_TYPE_BOOL, FALSE);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "page_horizontally", 2,
+ GTK_TYPE_INT, 1,
+ GTK_TYPE_BOOL, TRUE);
/* Deleting text */
gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
GTK_TYPE_ENUM, GTK_DELETE_CHARS,
GTK_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_CONTROL_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_CHARS,
- GTK_TYPE_INT, 1);
-
gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
"delete_from_cursor", 2,
GTK_TYPE_ENUM, GTK_DELETE_CHARS,
GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
GTK_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_MOD1_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
- GTK_TYPE_INT, 1);
-
gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
"delete_from_cursor", 2,
GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
GTK_TYPE_INT, -1);
- gtk_binding_entry_add_signal (binding_set, GDK_k, GDK_CONTROL_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
- GTK_TYPE_INT, 1);
-
- gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPHS,
- GTK_TYPE_INT, 1);
-
- gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
- GTK_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
- GTK_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
- "insert_at_cursor", 1,
- GTK_TYPE_STRING, " ");
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
- "insert_at_cursor", 1,
- GTK_TYPE_STRING, " ");
-
- gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_MOD1_MASK,
- "delete_from_cursor", 2,
- GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
- GTK_TYPE_INT, 1);
-
/* Cut/copy/paste */
gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
"cut_clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK,
- "cut_clipboard", 0);
-
gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
"copy_clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
"paste_clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_y, GDK_CONTROL_MASK,
- "paste_clipboard", 0);
-
/* Overwrite */
gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
"toggle_overwrite", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
"toggle_overwrite", 0);
+
+ /* Control-tab focus motion */
+ gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_CONTROL_MASK,
+ "move_focus", 1,
+ GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_CONTROL_MASK,
+ "move_focus", 1,
+ GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "move_focus", 1,
+ GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
+ 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);
}
static void
if (GTK_WIDGET_VISIBLE (text_view))
gtk_widget_queue_draw (GTK_WIDGET (text_view));
-
+
+ DV(g_print ("Invalidating due to set_buffer\n"));
gtk_text_view_invalidate (text_view);
}
GtkTextIter iter;
GtkTextPendingScroll *scroll;
gboolean retval;
+ GtkWidget *widget;
+
+ widget = GTK_WIDGET (text_view);
DV(g_print(G_STRLOC"\n"));
if (text_view->pending_scroll == NULL)
- return FALSE;
+ {
+ DV (g_print ("in flush scroll, no pending scroll\n"));
+ return FALSE;
+ }
scroll = text_view->pending_scroll;
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, scroll->mark);
- /* Validate arbitrary area around the scroll destination, so the adjustment
- * can meaningfully point into that area
+ /* Validate area around the scroll destination, so the adjustment
+ * can meaningfully point into that area. We must validate
+ * enough area to be sure that after we scroll, everything onscreen
+ * is valid; otherwise, validation will maintain the first para
+ * in one place, but may push the target iter off the bottom of
+ * the screen.
*/
DV(g_print (">Validating scroll destination ("G_STRLOC")\n"));
- gtk_text_layout_validate_yrange (text_view->layout, &iter, -300, 300);
+ gtk_text_layout_validate_yrange (text_view->layout, &iter,
+ - (widget->allocation.height * 2),
+ widget->allocation.height * 2);
DV(g_print (">Done validating scroll destination ("G_STRLOC")\n"));
gtk_text_view_flush_scroll (text_view);
}
+/**
+ * gtk_text_view_scroll_mark_onscreen:
+ * @text_view: a #GtkTextView
+ * @mark: a mark in the buffer for @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,
GtkTextMark *mark)
gboolean setting)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+ setting = setting != FALSE;
if (text_view->editable != setting)
{
text_view->layout->default_style->editable = text_view->editable;
gtk_text_layout_default_style_changed (text_view->layout);
}
- }
- g_object_notify (G_OBJECT (text_view), "editable");
+ g_object_notify (G_OBJECT (text_view), "editable");
+ }
}
/**
return text_view->editable;
}
+/**
+ * gtk_text_view_set_pixels_above_lines:
+ * @text_view: a #GtkTextView
+ * @pixels_above_lines: pixels above paragraphs
+ *
+ * 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,
gint pixels_above_lines)
text_view->layout->default_style->pixels_above_lines = pixels_above_lines;
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");
+ }
}
+/**
+ * gtk_text_view_get_pixels_above_lines:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default number of pixels to put above paragraphs.
+ *
+ * Return value: default number of pixels above paragraphs
+ **/
gint
gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
{
return text_view->pixels_above_lines;
}
+/**
+ * gtk_text_view_set_pixels_below_lines:
+ * @text_view: a #GtkTextView
+ * @pixels_below_lines: pixels below paragraphs
+ *
+ * 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,
gint pixels_below_lines)
text_view->layout->default_style->pixels_below_lines = pixels_below_lines;
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");
+ }
}
+/**
+ * gtk_text_view_get_pixels_below_lines:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the value set by gtk_text_view_set_pixels_below_lines().
+ *
+ * Return value: default number of blank pixels below paragraphs
+ **/
gint
gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
{
return text_view->pixels_below_lines;
}
+/**
+ * gtk_text_view_set_pixels_inside_wrap:
+ * @text_view: a #GtkTextView
+ * @pixels_inside_wrap: default number of pixels between wrapped 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,
gint pixels_inside_wrap)
text_view->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
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");
}
+/**
+ * gtk_text_view_get_pixels_inside_wrap:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the value set by gtk_text_view_set_pixels_inside_wrap().
+ *
+ * Return value: default number of pixels of blank space between wrapped lines
+ **/
gint
gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
{
return text_view->pixels_inside_wrap;
}
+/**
+ * gtk_text_view_set_justification:
+ * @text_view: a #GtkTextView
+ * @justification: justification
+ *
+ * Sets the default justification of text in @text_view.
+ * Tags in the view's buffer may override the default.
+ *
+ **/
void
gtk_text_view_set_justification (GtkTextView *text_view,
- GtkJustification justify)
+ GtkJustification justification)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
- if (text_view->justify != justify)
+ if (text_view->justify != justification)
{
- text_view->justify = justify;
+ text_view->justify = justification;
if (text_view->layout)
{
- text_view->layout->default_style->justification = justify;
+ text_view->layout->default_style->justification = justification;
gtk_text_layout_default_style_changed (text_view->layout);
}
- }
- g_object_notify (G_OBJECT (text_view), "justification");
+ g_object_notify (G_OBJECT (text_view), "justification");
+ }
}
+/**
+ * gtk_text_view_get_justification:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default justification of paragraphs in @text_view.
+ * Tags in the buffer may override the default.
+ *
+ * Return value: default justification
+ **/
GtkJustification
gtk_text_view_get_justification (GtkTextView *text_view)
{
return text_view->justify;
}
+/**
+ * gtk_text_view_set_left_margin:
+ * @text_view: a #GtkTextView
+ * @left_margin: left margin in pixels
+ *
+ * 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,
gint left_margin)
text_view->layout->default_style->left_margin = left_margin;
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");
+ }
}
+/**
+ * gtk_text_view_get_left_margin:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default left margin size of paragraphs in the @text_view.
+ * Tags in the buffer may override the default.
+ *
+ * Return value: left margin in pixels
+ **/
gint
gtk_text_view_get_left_margin (GtkTextView *text_view)
{
return text_view->left_margin;
}
+/**
+ * gtk_text_view_set_right_margin:
+ * @text_view: a #GtkTextView
+ * @right_margin: right margin in pixels
+ *
+ * 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,
gint right_margin)
text_view->layout->default_style->right_margin = right_margin;
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");
+ }
}
+/**
+ * gtk_text_view_get_right_margin:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default right margin for text in @text_view. Tags
+ * in the buffer may override the default.
+ *
+ * Return value: right margin in pixels
+ **/
gint
gtk_text_view_get_right_margin (GtkTextView *text_view)
{
return text_view->right_margin;
}
+/**
+ * gtk_text_view_set_indent:
+ * @text_view: a #GtkTextView
+ * @indent: indentation in pixels
+ *
+ * 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,
gint indent)
text_view->layout->default_style->indent = indent;
gtk_text_layout_default_style_changed (text_view->layout);
}
+
+ g_object_notify (G_OBJECT (text_view), "indent");
}
- g_object_notify (G_OBJECT (text_view), "indent");
}
+/**
+ * gtk_text_view_get_indent:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default indentation of paragraphs in @text_view.
+ * Tags in the view's buffer may override the default.
+ * The indentation may be negative.
+ *
+ * Return value: number of pixels of indentation
+ **/
gint
gtk_text_view_get_indent (GtkTextView *text_view)
{
return text_view->indent;
}
+/**
+ * gtk_text_view_set_tabs:
+ * @text_view: a #GtkTextView
+ * @tabs: tabs as a #PangoTabArray
+ *
+ * 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,
PangoTabArray *tabs)
g_object_notify (G_OBJECT (text_view), "tabs");
}
+/**
+ * gtk_text_view_get_tabs:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the default tabs for @text_view. Tags in the buffer may
+ * override the defaults. The returned array will be %NULL if
+ * "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().
+ **/
PangoTabArray*
gtk_text_view_get_tabs (GtkTextView *text_view)
{
gtk_text_view_check_cursor_blink (text_view);
}
}
- }
- g_object_notify (G_OBJECT (text_view), "cursor_visible");
+ g_object_notify (G_OBJECT (text_view), "cursor_visible");
+ }
}
/**
{
if (text_view->first_validate_idle != 0)
{
+ DV (g_print ("Removing first validate idle: %s\n", G_STRLOC));
g_source_remove (text_view->first_validate_idle);
text_view->first_validate_idle = 0;
}
break;
case PROP_TABS:
- gtk_text_view_set_tabs (text_view, g_value_get_object (value));
+ gtk_text_view_set_tabs (text_view, g_value_get_boxed (value));
break;
case PROP_CURSOR_VISIBLE:
break;
case PROP_TABS:
- g_value_set_object (value, gtk_text_view_get_tabs (text_view));
+ g_value_set_boxed (value, text_view->tabs);
break;
case PROP_CURSOR_VISIBLE:
}
text_view->hadjustment->page_size = SCREEN_WIDTH (text_view);
- text_view->hadjustment->page_increment = SCREEN_WIDTH (text_view) / 2;
+ text_view->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9;
+ text_view->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1;
text_view->hadjustment->lower = 0;
text_view->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
text_view->width);
gtk_signal_emit_by_name (GTK_OBJECT (text_view->hadjustment), "changed");
text_view->vadjustment->page_size = SCREEN_HEIGHT (text_view);
- text_view->vadjustment->page_increment = SCREEN_HEIGHT (text_view) / 2;
+ text_view->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9;
+ text_view->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1;
text_view->vadjustment->lower = 0;
text_view->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
text_view->height);
if (yoffset_changed)
gtk_adjustment_value_changed (vadj);
- if (text_view->first_validate_idle != 0)
- {
- /* The GTK resize loop processes all the pending exposes right
- * after doing the resize stuff, so the idle sizer won't have a
- * chance to run. So we do the work here.
- */
-
- g_source_remove (text_view->first_validate_idle);
- text_view->first_validate_idle = 0;
-
- if (!gtk_text_view_flush_scroll (text_view))
- gtk_text_view_validate_onscreen (text_view);
- }
+ /* The GTK resize loop processes all the pending exposes right
+ * after doing the resize stuff, so the idle sizer won't have a
+ * chance to run. So we do the work here.
+ */
+ gtk_text_view_flush_first_validate (text_view);
/* widget->window doesn't get auto-redrawn as the layout is computed, so has to
* be invalidated
g_assert (text_view->onscreen_validated);
}
-static gboolean
-first_validate_callback (gpointer data)
+static void
+gtk_text_view_flush_first_validate (GtkTextView *text_view)
{
- 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.
- */
-
- DV(g_print(G_STRLOC"\n"));
+ if (text_view->first_validate_idle == 0)
+ return;
/* Do this first, which means that if an "invalidate"
* occurs during any of this process, a new first_validate_callback
* will be installed, and we'll start again.
*/
+ DV (g_print ("removing first validate in %s\n", G_STRLOC));
+ g_source_remove (text_view->first_validate_idle);
text_view->first_validate_idle = 0;
/* be sure we have up-to-date screen size set on the
DV(g_print(">Leaving first validate idle ("G_STRLOC")\n"));
g_assert (text_view->onscreen_validated);
-
}
+}
+
+static gboolean
+first_validate_callback (gpointer data)
+{
+ 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.
+ */
+
+ DV(g_print(G_STRLOC"\n"));
+
+ gtk_text_view_flush_first_validate (text_view);
GDK_THREADS_LEAVE ();
static void
gtk_text_view_invalidate (GtkTextView *text_view)
-{
+{
+ DV (g_print (">Invalidate, onscreen_validated = %d now FALSE ("G_STRLOC")\n",
+ text_view->onscreen_validated));
+
text_view->onscreen_validated = FALSE;
- DV(g_print(">Invalidate, onscreen_validated = FALSE ("G_STRLOC")\n"));
-
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 = GTK_TEXT_VIEW (data);
+ DV (g_print ("Invalidating due to layout invalidate signal\n"));
gtk_text_view_invalidate (text_view);
}
}
if (yoffset_changed)
- gtk_adjustment_value_changed (get_vadjustment (text_view));
+ {
+ DV(g_print ("Changing scroll position (%s)\n", G_STRLOC));
+ gtk_adjustment_value_changed (get_vadjustment (text_view));
+ }
/* FIXME be smarter about which anchored widgets we update */
if (old_req.width != new_req.width ||
old_req.height != new_req.height)
- gtk_widget_queue_resize (widget);
+ {
+ /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
+ _gtk_size_group_queue_resize (widget);
+ }
}
}
if (text_view->cursor_gc)
gdk_gc_unref (text_view->cursor_gc);
- gtk_widget_style_get (GTK_WIDGET (text_view), "cursor_color", &cursor_color, NULL);
+ gtk_widget_style_get (GTK_WIDGET (text_view), "cursor-color", &cursor_color, NULL);
if (!cursor_color)
cursor_color = &red;
}
}
+
+static void
+set_invisible_cursor (GdkWindow *window)
+{
+ GdkBitmap *empty_bitmap;
+ GdkCursor *cursor;
+ GdkColor useless;
+ char invisible_cursor_bits[] = { 0x0 };
+
+ useless.red = useless.green = useless.blue = 0;
+ useless.pixel = 0;
+
+ empty_bitmap = gdk_bitmap_create_from_data (window,
+ invisible_cursor_bits,
+ 1, 1);
+
+ cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
+ empty_bitmap,
+ &useless,
+ &useless, 0, 0);
+
+ gdk_window_set_cursor (window, cursor);
+
+ gdk_cursor_unref (cursor);
+
+ g_object_unref (empty_bitmap);
+}
+
+static void
+gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
+{
+ if (text_view->mouse_cursor_obscured)
+ return;
+
+ set_invisible_cursor (text_view->text_window->bin_window);
+
+ text_view->mouse_cursor_obscured = TRUE;
+}
+
/*
* Events
*/
gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
{
gboolean retval = FALSE;
+ gboolean obscure = FALSE;
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GtkTextMark *insert;
GtkTextIter iter;
gtk_im_context_filter_keypress (text_view->im_context, event))
{
text_view->need_im_reset = TRUE;
+ obscure = TRUE;
retval = TRUE;
}
else if (GTK_WIDGET_CLASS (parent_class)->key_press_event &&
event->keyval == GDK_KP_Enter)
{
gtk_text_view_commit_text (text_view, "\n");
+
+ obscure = TRUE;
retval = 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_ISO_Left_Tab) &&
+ event->keyval == GDK_KP_Tab) &&
!(event->state & GDK_CONTROL_MASK))
{
- gtk_text_view_commit_text (text_view, "\t");
+ /* If the text isn't editable, move the focus instead */
+ if (text_view->editable)
+ {
+ 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);
+
retval = TRUE;
}
else
retval = FALSE;
+ if (obscure)
+ gtk_text_view_obscure_mouse_cursor (text_view);
+
gtk_text_view_pend_cursor_blink (text_view);
return retval;
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
gtk_widget_queue_draw (widget);
DV(g_print (G_STRLOC": focus_in_event\n"));
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
gtk_widget_queue_draw (widget);
DV(g_print (G_STRLOC": focus_out_event\n"));
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ if (text_view->mouse_cursor_obscured)
+ {
+ GdkCursor *cursor;
+
+ cursor = gdk_cursor_new (GDK_XTERM);
+ gdk_window_set_cursor (text_view->text_window->bin_window, cursor);
+ gdk_cursor_unref (cursor);
+ text_view->mouse_cursor_obscured = FALSE;
+ }
+
if (event->window == text_view->text_window->bin_window &&
text_view->drag_start_x >= 0)
{
GtkTextView *text_view;
GList *child_exposes;
GList *tmp_list;
+ GdkRegion *updates;
text_view = GTK_TEXT_VIEW (widget);
g_return_if_fail (text_view->layout != NULL);
g_return_if_fail (text_view->xoffset >= 0);
g_return_if_fail (text_view->yoffset >= 0);
-
- DV (g_print (G_STRLOC": first_validate_idle: %d\n",
- text_view->first_validate_idle));
+
+ while (text_view->first_validate_idle != 0)
+ {
+ DV (g_print (G_STRLOC": first_validate_idle: %d\n",
+ text_view->first_validate_idle));
+ gtk_text_view_flush_first_validate (text_view);
+ }
+
+ /* More regions could have become invalid in the above loop */
+ updates = gdk_window_get_update_area (text_view->text_window->bin_window);
+ if (updates)
+ {
+ GdkRectangle rect;
+
+ gdk_region_get_clipbox (updates, &rect);
+
+ gdk_rectangle_union (area, &rect, area);
+
+ gdk_region_destroy (updates);
+ }
if (!text_view->onscreen_validated)
{
- g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen - this is a known bug, no need to report.");
+ g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen - may be a text widget bug.");
G_BREAKPOINT ();
}
static gint
gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
-{
+{
+ GSList *tmp_list;
+
if (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
GTK_TEXT_WINDOW_TEXT))
{
if (event->window == widget->window)
gtk_text_view_draw_focus (widget);
+ /* Propagate exposes to all children not in the buffer. */
+ tmp_list = GTK_TEXT_VIEW (widget)->children;
+ while (tmp_list != NULL)
+ {
+ GtkTextViewChild *vc = tmp_list->data;
+
+ /* propagate_expose checks that event->window matches
+ * child->window
+ */
+ if (vc->type != GTK_TEXT_WINDOW_TEXT)
+ gtk_container_propagate_expose (GTK_CONTAINER (widget),
+ vc->widget,
+ event);
+
+ tmp_list = tmp_list->next;
+ }
+
return FALSE;
}
"insert"));
}
+static gboolean
+gtk_text_view_focus (GtkWidget *widget,
+ GtkDirectionType direction)
+{
+ GtkTextView *text_view;
+ GtkContainer *container;
+
+ text_view = GTK_TEXT_VIEW (widget);
+ container = GTK_CONTAINER (widget);
+
+ return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+}
+
/*
* Container
*/
}
}
+/* FIXME when we are unfrozen and can change GtkMovementStep,
+ * fix this
+ */
+#define PAGE_HORIZONTALLY_HACK_VALUE 57
+
static void
-gtk_text_view_move_cursor (GtkTextView *text_view,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection)
+gtk_text_view_move_cursor_internal (GtkTextView *text_view,
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection)
{
GtkTextIter insert;
GtkTextIter newplace;
gtk_text_view_pend_cursor_blink (text_view);
return;
}
+ else if (step == PAGE_HORIZONTALLY_HACK_VALUE)
+ {
+ gtk_text_view_scroll_hpages (text_view, count);
+ 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),
break;
case GTK_MOVEMENT_PARAGRAPHS:
- gtk_text_iter_forward_lines (&newplace, count);
- gtk_text_iter_set_line_offset (&newplace, 0);
+ if (count > 0)
+ {
+ if (!gtk_text_iter_ends_line (&newplace))
+ {
+ gtk_text_iter_forward_to_line_end (&newplace);
+ --count;
+ }
+ }
+ else if (count < 0)
+ {
+ if (gtk_text_iter_get_line_offset (&newplace) > 0)
+ {
+ gtk_text_iter_set_line_offset (&newplace, 0);
+ ++count;
+ }
+ }
+
+ if (count != 0)
+ {
+ gtk_text_iter_forward_lines (&newplace, count);
+ gtk_text_iter_set_line_offset (&newplace, 0);
+ }
break;
case GTK_MOVEMENT_PARAGRAPH_ENDS:
else if (count < 0)
gtk_text_buffer_get_iter_at_offset (get_buffer (text_view), &newplace, 0);
break;
-
+
default:
break;
}
gtk_text_view_pend_cursor_blink (text_view);
}
+static void
+gtk_text_view_move_cursor (GtkTextView *text_view,
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection)
+{
+ gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
+}
+
+static void
+gtk_text_view_page_horizontally (GtkTextView *text_view,
+ gint count,
+ gboolean extend_selection)
+{
+ gtk_text_view_move_cursor_internal (text_view, PAGE_HORIZONTALLY_HACK_VALUE,
+ count, extend_selection);
+}
+
static void
gtk_text_view_set_anchor (GtkTextView *text_view)
{
gint count)
{
gdouble newval;
+ gdouble oldval;
GtkAdjustment *adj;
gint cursor_x_pos, cursor_y_pos;
GtkTextIter new_insert;
gtk_text_layout_validate_yrange (text_view->layout, &anchor, y0, y1);
/* FIXME do we need to update the adjustment ranges here? */
+
+ if (count < 0 && adj->value <= (adj->lower + 1e-12))
+ {
+ /* already at top, just be sure we are at offset 0 */
+ gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ }
+ else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
+ {
+ /* already at bottom, just be sure we are at the end */
+ gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ }
+ else
+ {
+ gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+
+ newval = adj->value;
+ oldval = adj->value;
- gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+ newval += count * adj->page_increment;
- newval = adj->value;
+ set_adjustment_clamped (adj, newval);
+ cursor_y_pos += adj->value - oldval;
- newval += count * adj->page_increment;
+ gtk_text_layout_get_iter_at_pixel (text_view->layout, &new_insert, cursor_x_pos, cursor_y_pos);
+ clamp_iter_onscreen (text_view, &new_insert);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
- cursor_y_pos += newval - adj->value;
- set_adjustment_clamped (adj, newval);
+ gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+ }
+
+ /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
+ * 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"));
+}
+
+static void
+gtk_text_view_scroll_hpages (GtkTextView *text_view,
+ gint count)
+{
+ gdouble newval;
+ gdouble oldval;
+ GtkAdjustment *adj;
+ gint cursor_x_pos, cursor_y_pos;
+ GtkTextIter new_insert;
+ gint y, height;
+
+ g_return_if_fail (text_view->hadjustment != NULL);
+
+ adj = text_view->hadjustment;
+
+ /* 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);
+ /* FIXME do we need to update the adjustment ranges here? */
+
+ if (count < 0 && adj->value <= (adj->lower + 1e-12))
+ {
+ /* already at far left, just be sure we are at offset 0 */
+ gtk_text_iter_set_line_offset (&new_insert, 0);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ }
+ 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);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ }
+ else
+ {
+ gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+
+ newval = adj->value;
+ oldval = adj->value;
+
+ newval += count * adj->page_increment;
- gtk_text_layout_get_iter_at_pixel (text_view->layout, &new_insert, cursor_x_pos, cursor_y_pos);
- clamp_iter_onscreen (text_view, &new_insert);
- gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ set_adjustment_clamped (adj, newval);
+ cursor_x_pos += adj->value - oldval;
- gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+ gtk_text_layout_get_iter_at_pixel (text_view->layout, &new_insert, cursor_x_pos, cursor_y_pos);
+ clamp_iter_onscreen (text_view, &new_insert);
+ gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+ gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+ }
+
+ /* FIXME for lines shorter than the overall widget width, this results in a
+ * "bounce" effect as we scroll to the right of the widget, then scroll
+ * back to get the end of the line onscreen.
+ * http://bugzilla.gnome.org/show_bug.cgi?id=68963
+ */
+
/* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
* only guarantees 1 pixel onscreen.
*/
text_view->overwrite_mode = !text_view->overwrite_mode;
}
+static void
+gtk_text_view_move_focus (GtkTextView *text_view,
+ GtkDirectionType direction_type)
+{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (text_view));
+
+ if (!GTK_WIDGET_TOPLEVEL (toplevel))
+ return;
+
+ /* Propagate to toplevel */
+ g_signal_emit_by_name (G_OBJECT (toplevel), "move_focus", direction_type);
+}
+
/*
* Selections
*/
GtkTextMark *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,
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
* Obtains a copy of the default text attributes. These are the
* attributes used for text unless a tag overrides them.
* You'd typically pass the default attributes in to
- * gtk_text_tag_get_attributes() in order to get the
+ * gtk_text_iter_get_attributes() in order to get the
* attributes in effect at a given text position.
*
* The return value is a copy owned by the caller of this function,
/* process exposes */
if (GTK_WIDGET_REALIZED (text_view))
{
+ DV (g_print ("Processing updates (%s)\n", G_STRLOC));
+
if (text_view->left_window)
gdk_window_process_updates (text_view->left_window->bin_window, TRUE);
NULL, NULL,
info->button, info->time);
else
- gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
- popup_position_func, text_view,
- 0, gtk_get_current_event_time ());
+ {
+ gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
+ popup_position_func, text_view,
+ 0, gtk_get_current_event_time ());
+ _gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu));
+ }
}
g_object_unref (text_view);
info);
}
-static void
+static gboolean
gtk_text_view_popup_menu (GtkWidget *widget)
{
gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
+ return TRUE;
}
/* Child GdkWindows */
/* I-beam cursor */
cursor = gdk_cursor_new (GDK_XTERM);
gdk_window_set_cursor (win->bin_window, cursor);
- gdk_cursor_destroy (cursor);
+ gdk_cursor_unref (cursor);
gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->im_context,
win->window);
return NULL;
break;
- default:
- g_warning ("%s: Unknown GtkTextWindowType", G_STRLOC);
+ case GTK_TEXT_WINDOW_PRIVATE:
+ g_warning ("%s: You can't get GTK_TEXT_WINDOW_PRIVATE, it has \"PRIVATE\" in the name because it is private.", G_GNUC_FUNCTION);
return NULL;
break;
}
+
+ g_warning ("%s: Unknown GtkTextWindowType", G_GNUC_FUNCTION);
+ return NULL;
}
/**
gint buffer_y,
gint *window_x,
gint *window_y)
-{
- gint focus_edge_width;
- gboolean interior_focus;
- gint focus_width;
-
- gtk_widget_style_get (GTK_WIDGET (text_view),
- "interior_focus", &interior_focus,
- "focus_line_width", &focus_width,
- NULL);
-
- if (interior_focus)
- focus_edge_width = 0;
- else
- focus_edge_width = focus_width;
-
+{
if (window_x)
{
- *window_x = buffer_x - text_view->xoffset + focus_edge_width;
- if (text_view->left_window)
- *window_x += text_view->left_window->allocation.width;
+ *window_x = buffer_x - text_view->xoffset;
+ *window_x += text_view->text_window->allocation.x;
}
if (window_y)
{
- *window_y = buffer_y - text_view->yoffset + focus_edge_width;
- if (text_view->top_window)
- *window_y += text_view->top_window->allocation.height;
+ *window_y = buffer_y - text_view->yoffset;
+ *window_y += text_view->text_window->allocation.y;
}
}
gtk_widget_set_parent (vc->widget, GTK_WIDGET (text_view));
}
+/**
+ * gtk_text_view_add_child_at_anchor:
+ * @text_view: a #GtkTextView
+ * @child: a #GtkWidget
+ * @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,
GtkWidget *child,
/* Iterator operations */
+/**
+ * gtk_text_view_forward_display_line:
+ * @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
+ * separated by newlines or other paragraph separator characters.
+ * 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
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ *
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
gboolean
gtk_text_view_forward_display_line (GtkTextView *text_view,
GtkTextIter *iter)
return gtk_text_layout_move_iter_to_next_line (text_view->layout, iter);
}
+/**
+ * gtk_text_view_backward_display_line:
+ * @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
+ * separated by newlines or other paragraph separator characters.
+ * 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
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ *
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
gboolean
gtk_text_view_backward_display_line (GtkTextView *text_view,
GtkTextIter *iter)
return gtk_text_layout_move_iter_to_previous_line (text_view->layout, iter);
}
+/**
+ * gtk_text_view_forward_display_line_end:
+ * @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
+ * separated by newlines or other paragraph separator characters.
+ * 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
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ *
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
gboolean
gtk_text_view_forward_display_line_end (GtkTextView *text_view,
GtkTextIter *iter)
return gtk_text_layout_move_iter_to_line_end (text_view->layout, iter, 1);
}
+/**
+ * gtk_text_view_backward_display_line_start:
+ * @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
+ * separated by newlines or other paragraph separator characters.
+ * 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
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ *
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
gboolean
gtk_text_view_backward_display_line_start (GtkTextView *text_view,
GtkTextIter *iter)
return gtk_text_layout_move_iter_to_line_end (text_view->layout, iter, -1);
}
+/**
+ * gtk_text_view_starts_display_line:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ *
+ * Determines whether @iter is at the start of a display line.
+ * See gtk_text_view_forward_display_line() for an explanation of
+ * display lines vs. paragraphs.
+ *
+ * Return value: %TRUE if @iter begins a wrapped line
+ **/
gboolean
gtk_text_view_starts_display_line (GtkTextView *text_view,
const GtkTextIter *iter)
return gtk_text_layout_iter_starts_line (text_view->layout, iter);
}
+/**
+ * gtk_text_view_move_visually:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * @count: number of lines to move
+ *
+ * Moves @iter up or down by @count display (wrapped) lines.
+ * See gtk_text_view_forward_display_line() for an explanation of
+ * display lines vs. paragraphs.
+ *
+ * Return value: %TRUE if @iter moved and is not on the end iterator
+ **/
gboolean
gtk_text_view_move_visually (GtkTextView *text_view,
GtkTextIter *iter,