*/
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
-#include "gtksignal.h"
+#include <config.h>
+#include "gtkalias.h"
#include "gtkmarshalers.h"
#include "gtktextlayout.h"
#include "gtktextbtree.h"
#include <stdlib.h>
#include <string.h>
+#define GTK_TEXT_LAYOUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutPrivate))
+
+typedef struct _GtkTextLayoutPrivate GtkTextLayoutPrivate;
+
+struct _GtkTextLayoutPrivate
+{
+ /* Cache the line that the cursor is positioned on, as the keyboard
+ direction only influences the direction of the cursor line.
+ */
+ GtkTextLine *cursor_line;
+};
+
static GtkTextLineData *gtk_text_layout_real_wrap (GtkTextLayout *layout,
GtkTextLine *line,
/* may be NULL */
static void gtk_text_layout_real_free_line_data (GtkTextLayout *layout,
GtkTextLine *line,
GtkTextLineData *line_data);
+static void gtk_text_layout_emit_changed (GtkTextLayout *layout,
+ gint y,
+ gint old_height,
+ gint new_height);
static void gtk_text_layout_invalidate_all (GtkTextLayout *layout);
static PangoAttribute *gtk_text_attr_appearance_new (const GtkTextAppearance *appearance);
+static void gtk_text_layout_mark_set_handler (GtkTextBuffer *buffer,
+ const GtkTextIter *location,
+ GtkTextMark *mark,
+ gpointer data);
+static void gtk_text_layout_buffer_insert_text (GtkTextBuffer *textbuffer,
+ GtkTextIter *iter,
+ gchar *str,
+ gint len,
+ gpointer data);
+static void gtk_text_layout_buffer_delete_range (GtkTextBuffer *textbuffer,
+ GtkTextIter *start,
+ GtkTextIter *end,
+ gpointer data);
+
+static void gtk_text_layout_update_cursor_line (GtkTextLayout *layout);
+
enum {
INVALIDATED,
CHANGED,
LAST_ARG
};
+#define PIXEL_BOUND(d) (((d) + PANGO_SCALE - 1) / PANGO_SCALE)
+
static void gtk_text_layout_init (GtkTextLayout *text_layout);
static void gtk_text_layout_class_init (GtkTextLayoutClass *klass);
static void gtk_text_layout_finalize (GObject *object);
(GInstanceInitFunc) gtk_text_layout_init
};
- our_type = g_type_register_static (G_TYPE_OBJECT,
- "GtkTextLayout",
- &our_info,
- 0);
+ our_type = g_type_register_static (G_TYPE_OBJECT, "GtkTextLayout",
+ &our_info, 0);
}
return our_type;
G_STRUCT_OFFSET (GtkTextLayoutClass, invalidated),
NULL, NULL,
_gtk_marshal_VOID__VOID,
- GTK_TYPE_NONE,
+ G_TYPE_NONE,
0);
signals[CHANGED] =
G_STRUCT_OFFSET (GtkTextLayoutClass, changed),
NULL, NULL,
_gtk_marshal_VOID__INT_INT_INT,
- GTK_TYPE_NONE,
+ G_TYPE_NONE,
3,
- GTK_TYPE_INT,
- GTK_TYPE_INT,
- GTK_TYPE_INT);
+ G_TYPE_INT,
+ G_TYPE_INT,
+ G_TYPE_INT);
signals[ALLOCATE_CHILD] =
g_signal_new ("allocate_child",
G_STRUCT_OFFSET (GtkTextLayoutClass, allocate_child),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_INT_INT,
- GTK_TYPE_NONE,
+ G_TYPE_NONE,
3,
GTK_TYPE_OBJECT,
- GTK_TYPE_INT,
- GTK_TYPE_INT);
+ G_TYPE_INT,
+ G_TYPE_INT);
+
+ g_type_class_add_private (object_class, sizeof (GtkTextLayoutPrivate));
}
static void
GtkTextLayout*
gtk_text_layout_new (void)
{
- return GTK_TEXT_LAYOUT (g_object_new (gtk_text_layout_get_type (), NULL));
+ return g_object_new (GTK_TYPE_TEXT_LAYOUT, NULL);
}
static void
if (layout->ltr_context)
{
- g_object_unref (G_OBJECT (layout->ltr_context));
+ g_object_unref (layout->ltr_context);
layout->ltr_context = NULL;
}
if (layout->rtl_context)
{
- g_object_unref (G_OBJECT (layout->rtl_context));
+ g_object_unref (layout->rtl_context);
layout->rtl_context = NULL;
}
+ if (layout->one_display_cache)
+ {
+ GtkTextLineDisplay *tmp_display = layout->one_display_cache;
+ layout->one_display_cache = NULL;
+ gtk_text_layout_free_line_display (layout, tmp_display);
+ }
+
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
_gtk_text_btree_remove_view (_gtk_text_buffer_get_btree (layout->buffer),
layout);
- g_object_unref (G_OBJECT (layout->buffer));
+ g_signal_handlers_disconnect_by_func (layout->buffer,
+ G_CALLBACK (gtk_text_layout_mark_set_handler),
+ layout);
+ g_signal_handlers_disconnect_by_func (layout->buffer,
+ G_CALLBACK (gtk_text_layout_buffer_insert_text),
+ layout);
+ g_signal_handlers_disconnect_by_func (layout->buffer,
+ G_CALLBACK (gtk_text_layout_buffer_delete_range),
+ layout);
+
+ g_object_unref (layout->buffer);
layout->buffer = NULL;
}
{
layout->buffer = buffer;
- g_object_ref (G_OBJECT (buffer));
+ g_object_ref (buffer);
_gtk_text_btree_add_view (_gtk_text_buffer_get_btree (buffer), layout);
+
+ /* Bind to all signals that move the insert mark. */
+ g_signal_connect_after (layout->buffer, "mark_set",
+ G_CALLBACK (gtk_text_layout_mark_set_handler), layout);
+ g_signal_connect_after (layout->buffer, "insert_text",
+ G_CALLBACK (gtk_text_layout_buffer_insert_text), layout);
+ g_signal_connect_after (layout->buffer, "delete_range",
+ G_CALLBACK (gtk_text_layout_buffer_delete_range), layout);
+
+ gtk_text_layout_update_cursor_line (layout);
}
}
g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
if (layout->ltr_context)
- g_object_unref (G_OBJECT (ltr_context));
+ g_object_unref (ltr_context);
layout->ltr_context = ltr_context;
- g_object_ref (G_OBJECT (ltr_context));
+ g_object_ref (ltr_context);
if (layout->rtl_context)
- g_object_unref (G_OBJECT (rtl_context));
+ g_object_unref (rtl_context);
layout->rtl_context = rtl_context;
- g_object_ref (G_OBJECT (rtl_context));
+ g_object_ref (rtl_context);
DV (g_print ("invalidating all due to new pango contexts (%s)\n", G_STRLOC));
gtk_text_layout_invalidate_all (layout);
}
}
+/**
+ * gtk_text_layout_set_keyboard_direction:
+ * @keyboard_dir: the current direction of the keyboard.
+ *
+ * Sets the keyboard direction; this is used as for the bidirectional
+ * base direction for the line with the cursor if the line contains
+ * only neutral characters.
+ **/
+void
+gtk_text_layout_set_keyboard_direction (GtkTextLayout *layout,
+ GtkTextDirection keyboard_dir)
+{
+ if (keyboard_dir != layout->keyboard_direction)
+ {
+ layout->keyboard_direction = keyboard_dir;
+ gtk_text_layout_invalidate_cursor_line (layout);
+ }
+}
+
/**
* gtk_text_layout_get_buffer:
* @layout: a #GtkTextLayout
gtk_text_buffer_get_mark (layout->buffer, "insert"));
gtk_text_layout_get_line_yrange (layout, &iter, &y, &height);
- gtk_text_layout_changed (layout, y, height, height);
+ gtk_text_layout_emit_changed (layout, y, height, height);
gtk_text_layout_invalidate_cache (layout, _gtk_text_iter_get_text_line (&iter));
}
static void
gtk_text_layout_invalidated (GtkTextLayout *layout)
{
- g_signal_emit (G_OBJECT (layout), signals[INVALIDATED], 0);
+ g_signal_emit (layout, signals[INVALIDATED], 0);
+}
+
+static void
+gtk_text_layout_emit_changed (GtkTextLayout *layout,
+ gint y,
+ gint old_height,
+ gint new_height)
+{
+ g_signal_emit (layout, signals[CHANGED], 0, y, old_height, new_height);
}
void
gint old_height,
gint new_height)
{
- g_signal_emit (G_OBJECT (layout), signals[CHANGED], 0,
- y, old_height, new_height);
+ /* Check if the range intersects our cached line display,
+ * and invalidate the cached line if so.
+ */
+ if (layout->one_display_cache)
+ {
+ GtkTextLine *line = layout->one_display_cache->line;
+ gint cache_y = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
+ line, layout);
+ gint cache_height = layout->one_display_cache->height;
+
+ if (cache_y + cache_height > y && cache_y < y + old_height)
+ gtk_text_layout_invalidate_cache (layout, line);
+ }
+
+ gtk_text_layout_emit_changed (layout, y, old_height, new_height);
}
void
static void
gtk_text_layout_invalidate_cursor_line (GtkTextLayout *layout)
{
- GtkTextIter iter;
- GtkTextLine *line;
+ GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
GtkTextLineData *line_data;
- gtk_text_buffer_get_iter_at_mark (layout->buffer, &iter,
- gtk_text_buffer_get_mark (layout->buffer, "insert"));
-
- line = _gtk_text_iter_get_text_line (&iter);
- line_data = _gtk_text_line_get_data (line, layout);
+ if (priv->cursor_line == NULL)
+ return;
+
+ line_data = _gtk_text_line_get_data (priv->cursor_line, layout);
if (line_data)
{
- gtk_text_layout_invalidate_cache (layout, line);
- _gtk_text_line_invalidate_wrap (line, line_data);
+ gtk_text_layout_invalidate_cache (layout, priv->cursor_line);
+ _gtk_text_line_invalidate_wrap (priv->cursor_line, line_data);
gtk_text_layout_invalidated (layout);
}
}
+static void
+gtk_text_layout_update_cursor_line(GtkTextLayout *layout)
+{
+ GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
+ GtkTextIter iter;
+
+ gtk_text_buffer_get_iter_at_mark (layout->buffer, &iter,
+ gtk_text_buffer_get_mark (layout->buffer, "insert"));
+
+ priv->cursor_line = _gtk_text_iter_get_text_line (&iter);
+}
+
static void
gtk_text_layout_real_invalidate (GtkTextLayout *layout,
const GtkTextIter *start,
g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
g_return_if_fail (layout->wrap_loop_count == 0);
+ /* Because we may be invalidating a mark, it's entirely possible
+ * that gtk_text_iter_equal (start, end) in which case we
+ * should still invalidate the line they are both on. i.e.
+ * we always invalidate the line with "start" even
+ * if there's an empty range.
+ */
+
#if 0
gtk_text_view_index_spew (start_index, "invalidate start");
gtk_text_view_index_spew (end_index, "invalidate end");
{
GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout);
- if (line_data &&
- (line != last_line || !gtk_text_iter_starts_line (end)))
- {
- gtk_text_layout_invalidate_cache (layout, line);
- _gtk_text_line_invalidate_wrap (line, line_data);
- }
+ gtk_text_layout_invalidate_cache (layout, line);
+
+ if (line_data)
+ _gtk_text_line_invalidate_wrap (line, line_data);
if (line == last_line)
break;
GtkTextLine *line,
GtkTextLineData *line_data)
{
- if (layout->one_display_cache && line == layout->one_display_cache->line)
- {
- GtkTextLineDisplay *tmp_display = layout->one_display_cache;
- layout->one_display_cache = NULL;
- gtk_text_layout_free_line_display (layout, tmp_display);
- }
+ gtk_text_layout_invalidate_cache (layout, line);
g_free (line_data);
}
* @layout: a #GtkTextLayout
* @anchor: iter pointing into a line that will be used as the
* coordinate origin
- * @y0: offset from the top of the line pointed to by @anchor at
- * which to begin validation. (The offset here is in pixels
- * after validation.)
- * @y1: offset from the top of the line pointed to by @anchor at
- * which to end validation. (The offset here is in pixels
- * after validation.)
+ * @y0_: offset from the top of the line pointed to by @anchor at
+ * which to begin validation. (The offset here is in pixels
+ * after validation.)
+ * @y1_: offset from the top of the line pointed to by @anchor at
+ * which to end validation. (The offset here is in pixels
+ * after validation.)
*
* Ensure that a region of a #GtkTextLayout is valid. The ::changed
* signal will be emitted if any lines are validated.
/* Validate backwards from the anchor line to y0
*/
line = _gtk_text_iter_get_text_line (anchor);
+ line = _gtk_text_line_previous (line);
seen = 0;
while (line && seen < -y0)
{
delta_height += line_data->height - old_height;
first_line = line;
- first_line_y = -seen;
+ first_line_y = -seen - line_data->height;
if (!last_line)
{
last_line = line;
- last_line_y = -seen + line_data->height;
+ last_line_y = -seen;
}
}
line_top = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
first_line, layout);
- gtk_text_layout_changed (layout,
- line_top,
- last_line_y - first_line_y - delta_height,
- last_line_y - first_line_y);
+ gtk_text_layout_emit_changed (layout,
+ line_top,
+ last_line_y - first_line_y - delta_height,
+ last_line_y - first_line_y);
}
}
max_pixels -= new_height;
update_layout_size (layout);
- gtk_text_layout_changed (layout, y, old_height, new_height);
+ gtk_text_layout_emit_changed (layout, y, old_height, new_height);
}
}
GtkTextLineSegment *seg;
int bytes = 0;
- /* If we have a cached style, then we know it does actually apply
- * and we can just see if it is invisible.
+ /* Check if the first char is visible, if so we are partially visible.
+ * Note that we have to check this since we don't know the current
+ * invisible/noninvisible toggle state; this function can use the whole btree
+ * to get it right.
*/
- if (layout->one_style_cache &&
- !layout->one_style_cache->invisible)
+ _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
+ iter, line, 0);
+
+ if (!_gtk_text_btree_char_is_invisible (iter))
return FALSE;
- /* Without the cache, we check if the first char is visible, if so
- * we are partially visible. Note that we have to check this since
- * we don't know the current invisible/noninvisible toggle state; this
- * function can use the whole btree to get it right.
- */
- else
- {
- _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
- iter, line, 0);
-
- if (!_gtk_text_btree_char_is_invisible (iter))
- return FALSE;
- }
bytes = 0;
seg = line->segments;
static void
set_para_values (GtkTextLayout *layout,
- GtkTextAttributes *style,
+ PangoDirection base_dir,
+ GtkTextAttributes *style,
GtkTextLineDisplay *display)
{
PangoAlignment pango_align = PANGO_ALIGN_LEFT;
int layout_width;
- display->direction = style->direction;
+ switch (base_dir)
+ {
+ /* If no base direction was found, then use the style direction */
+ case PANGO_DIRECTION_NEUTRAL :
+ display->direction = style->direction;
- if (display->direction == GTK_TEXT_DIR_LTR)
- display->layout = pango_layout_new (layout->ltr_context);
- else
+ /* Override the base direction */
+ if (display->direction == GTK_TEXT_DIR_RTL)
+ base_dir = PANGO_DIRECTION_RTL;
+ else
+ base_dir = PANGO_DIRECTION_LTR;
+
+ break;
+ case PANGO_DIRECTION_RTL :
+ display->direction = GTK_TEXT_DIR_RTL;
+ break;
+ default:
+ display->direction = GTK_TEXT_DIR_LTR;
+ break;
+ }
+
+ if (display->direction == GTK_TEXT_DIR_RTL)
display->layout = pango_layout_new (layout->rtl_context);
+ else
+ display->layout = pango_layout_new (layout->ltr_context);
switch (style->justification)
{
case GTK_JUSTIFY_LEFT:
- pango_align = (style->direction == GTK_TEXT_DIR_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
+ pango_align = (base_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
break;
case GTK_JUSTIFY_RIGHT:
- pango_align = (style->direction == GTK_TEXT_DIR_LTR) ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
+ pango_align = (base_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
break;
case GTK_JUSTIFY_CENTER:
pango_align = PANGO_ALIGN_CENTER;
pango_layout_set_wrap (display->layout, PANGO_WRAP_WORD);
break;
+ case GTK_WRAP_WORD_CHAR:
+ layout_width = layout->screen_width - display->left_margin - display->right_margin;
+ pango_layout_set_width (display->layout, layout_width * PANGO_SCALE);
+ pango_layout_set_wrap (display->layout, PANGO_WRAP_WORD_CHAR);
+ break;
+
case GTK_WRAP_NONE:
break;
}
-
+
display->total_width = MAX (layout->screen_width, layout->width) - display->left_margin - display->right_margin;
}
GtkTextAppearance *appearance = &((GtkTextAttrAppearance *)attr)->appearance;
if (appearance->bg_stipple)
- gdk_drawable_unref (appearance->bg_stipple);
+ g_object_unref (appearance->bg_stipple);
if (appearance->fg_stipple)
- gdk_drawable_unref (appearance->fg_stipple);
+ g_object_unref (appearance->fg_stipple);
g_free (attr);
}
result->appearance = *appearance;
if (appearance->bg_stipple)
- gdk_drawable_ref (appearance->bg_stipple);
+ g_object_ref (appearance->bg_stipple);
if (appearance->fg_stipple)
- gdk_drawable_ref (appearance->fg_stipple);
+ g_object_ref (appearance->fg_stipple);
return (PangoAttribute *)result;
}
pango_attr_list_insert (attrs, attr);
}
+ if (appearance->strikethrough)
+ {
+ attr = pango_attr_strikethrough_new (appearance->strikethrough);
+
+ attr->start_index = start;
+ attr->end_index = start + byte_count;
+
+ pango_attr_list_insert (attrs, attr);
+ }
+
if (appearance->rise != 0)
{
attr = pango_attr_rise_new (appearance->rise);
logical_rect.width = width * PANGO_SCALE;
logical_rect.height = height * PANGO_SCALE;
- attr = pango_attr_shape_new (&logical_rect, &logical_rect);
+ attr = pango_attr_shape_new_with_data (&logical_rect, &logical_rect,
+ pixbuf->pixbuf, NULL, NULL);
attr->start_index = start;
attr->end_index = start + seg->byte_count;
pango_attr_list_insert (attrs, attr);
GtkTextChildAnchor *anchor;
gint width, height;
GSList *tmp_list;
+ GtkWidget *widget;
width = 1;
height = 1;
width = req.width;
height = req.height;
- display->shaped_objects =
- g_slist_append (display->shaped_objects, child);
+ widget = child;
break;
}
width = 30;
height = 20;
- display->shaped_objects =
- g_slist_append (display->shaped_objects, NULL);
+ widget = NULL;
}
+
+ display->shaped_objects = g_slist_append (display->shaped_objects, widget);
logical_rect.x = 0;
logical_rect.y = -height * PANGO_SCALE;
logical_rect.width = width * PANGO_SCALE;
logical_rect.height = height * PANGO_SCALE;
- attr = pango_attr_shape_new (&logical_rect, &logical_rect);
+ attr = pango_attr_shape_new_with_data (&logical_rect, &logical_rect,
+ widget, NULL, NULL);
attr->start_index = start;
attr->end_index = start + seg->byte_count;
pango_attr_list_insert (attrs, attr);
NULL,
&extents);
- g_signal_emit (G_OBJECT (text_layout),
+ g_signal_emit (text_layout,
signals[ALLOCATE_CHILD],
0,
shaped_object,
if (end == G_MAXINT)
end = layout->preedit_len;
+ if (end == start)
+ continue;
+
pango_attr_iterator_get_font (iter, font_desc, &language, &extra_attrs);
tmp_list = extra_attrs;
GtkTextLine *line,
gboolean size_only)
{
+ GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
GtkTextLineDisplay *display;
GtkTextLineSegment *seg;
GtkTextIter iter;
GSList *cursor_segs = NULL;
GSList *tmp_list1, *tmp_list2;
gboolean saw_widget = FALSE;
+ PangoDirection base_dir;
g_return_val_if_fail (line != NULL, NULL);
if (totally_invisible_line (layout, line, &iter))
return display;
+ /* Find the bidi base direction */
+ base_dir = line->dir_propagated_forward;
+ if (base_dir == PANGO_DIRECTION_NEUTRAL)
+ base_dir = line->dir_propagated_back;
+
+ if (line == priv->cursor_line &&
+ line->dir_strong == PANGO_DIRECTION_NEUTRAL)
+ {
+ base_dir = (layout->keyboard_direction == GTK_TEXT_DIR_LTR) ?
+ PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
+ }
+
/* Allocate space for flat text for buffer
*/
text_allocated = _gtk_text_line_byte_count (line);
*/
if (!para_values_set)
{
- set_para_values (layout, style, display);
+ set_para_values (layout, base_dir, style, display);
para_values_set = TRUE;
}
if (!para_values_set)
{
style = get_style (layout, &iter);
- set_para_values (layout, style, display);
+ set_para_values (layout, base_dir, style, display);
release_style (layout, style);
}
pango_layout_get_extents (display->layout, NULL, &extents);
- display->width = PANGO_PIXELS (extents.width) + display->left_margin + display->right_margin;
+ display->width = PIXEL_BOUND (extents.width) + display->left_margin + display->right_margin;
display->height += PANGO_PIXELS (extents.height);
+
+ /* If we aren't wrapping, we need to do the alignment of each
+ * paragraph ourselves.
+ */
+ if (pango_layout_get_width (display->layout) < 0)
+ {
+ gint excess = display->total_width - display->width;
+
+ switch (pango_layout_get_alignment (display->layout))
+ {
+ case PANGO_ALIGN_LEFT:
+ break;
+ case PANGO_ALIGN_CENTER:
+ display->x_offset += excess / 2;
+ break;
+ case PANGO_ALIGN_RIGHT:
+ display->x_offset += excess;
+ break;
+ }
+ }
/* Free this if we aren't in a loop */
if (layout->wrap_loop_count == 0)
if (display != layout->one_display_cache)
{
if (display->layout)
- g_object_unref (G_OBJECT (display->layout));
+ g_object_unref (display->layout);
if (display->cursors)
{
index = gtk_text_iter_get_visible_line_index (iter);
- if (index >= display->insert_index)
- index += layout->preedit_len;
+ if (layout->preedit_len > 0 && display->insert_index >= 0)
+ {
+ if (index >= display->insert_index)
+ index += layout->preedit_len;
+ }
return index;
}
g_return_if_fail (!_gtk_text_line_is_last (display->line,
_gtk_text_buffer_get_btree (layout->buffer)));
- if (index >= display->insert_index + layout->preedit_len)
- index -= layout->preedit_len;
- else if (index > display->insert_index)
+ if (layout->preedit_len > 0 && display->insert_index >= 0)
{
- index = display->insert_index;
- trailing = 0;
+ if (index >= display->insert_index + layout->preedit_len)
+ index -= layout->preedit_len;
+ else if (index > display->insert_index)
+ {
+ index = display->insert_index;
+ trailing = 0;
+ }
}
_gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
void
gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
- GtkTextIter *target_iter,
- gint x, gint y)
+ GtkTextIter *target_iter,
+ gint x,
+ gint y)
+{
+ gint trailing;
+
+ gtk_text_layout_get_iter_at_position (layout, target_iter, &trailing, x, y);
+
+ gtk_text_iter_forward_chars (target_iter, trailing);
+}
+
+void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
+ GtkTextIter *target_iter,
+ gint *trailing,
+ gint x,
+ gint y)
{
GtkTextLine *line;
- gint byte_index, trailing;
+ gint byte_index;
gint line_top;
GtkTextLineDisplay *display;
if (y > display->height - display->top_margin - display->bottom_margin)
{
byte_index = _gtk_text_line_byte_count (line);
- trailing = 0;
+ *trailing = 0;
}
else
{
* x-direction.
*/
pango_layout_xy_to_index (display->layout, x * PANGO_SCALE, y * PANGO_SCALE,
- &byte_index, &trailing);
+ &byte_index, trailing);
}
- line_display_index_to_iter (layout, display, target_iter, byte_index, trailing);
+ line_display_index_to_iter (layout, display, target_iter, byte_index, 0);
gtk_text_layout_free_line_display (layout, display);
}
+
/**
- * gtk_text_layout_get_cursor_locations
+ * gtk_text_layout_get_cursor_locations:
* @layout: a #GtkTextLayout
* @iter: a #GtkTextIter
* @strong_pos: location to store the strong cursor position (may be %NULL)
* @weak_pos: location to store the weak cursor position (may be %NULL)
*
- * Given an iterator within a text laout, determine the positions that of the
+ * Given an iterator within a text layout, determine the positions of the
* strong and weak cursors if the insertion point is at that
* iterator. The position of each cursor is stored as a zero-width
* rectangle. The strong cursor location is the location where
GtkTextLineDisplay *display;
gint line_top;
gint index;
+ GtkTextIter insert_iter;
PangoRectangle pango_strong_pos;
PangoRectangle pango_weak_pos;
line_top = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
line, layout);
+ gtk_text_buffer_get_iter_at_mark (layout->buffer, &insert_iter,
+ gtk_text_buffer_get_mark (layout->buffer,
+ "insert"));
+
+ if (gtk_text_iter_equal (iter, &insert_iter))
+ index += layout->preedit_cursor - layout->preedit_len;
+
pango_layout_get_cursor_pos (display->layout, index,
strong_pos ? &pango_strong_pos : NULL,
weak_pos ? &pango_weak_pos : NULL);
{
line_byte = layout_line->start_index + layout_line->length;
}
-
+
if (line_byte < layout_line->length || !tmp_list->next) /* first line of paragraph */
{
GtkTextLine *prev_line;
prev_line = _gtk_text_line_previous (line);
+
+ /* first line of the whole buffer, do not move the iter and return FALSE */
+ if (prev_line == NULL)
+ goto out;
+
while (prev_line)
{
gtk_text_layout_free_line_display (layout, display);
prev_line = _gtk_text_line_previous (prev_line);
}
-
- if (prev_line == NULL)
- line_display_index_to_iter (layout, display, iter, 0, 0);
}
else
{
line = _gtk_text_line_next_excluding_last (line);
}
+ if (!found_after)
+ gtk_text_buffer_get_end_iter (layout->buffer, iter);
+
return
!gtk_text_iter_equal (iter, &orig) &&
!gtk_text_iter_is_end (iter);
layout->height, layout->screen_width);
#endif
}
+
+/* Catch all situations that move the insertion point.
+ */
+static void
+gtk_text_layout_mark_set_handler (GtkTextBuffer *buffer,
+ const GtkTextIter *location,
+ GtkTextMark *mark,
+ gpointer data)
+{
+ GtkTextLayout *layout = GTK_TEXT_LAYOUT (data);
+
+ if (mark == gtk_text_buffer_get_insert (buffer))
+ gtk_text_layout_update_cursor_line (layout);
+}
+
+static void
+gtk_text_layout_buffer_insert_text (GtkTextBuffer *textbuffer,
+ GtkTextIter *iter,
+ gchar *str,
+ gint len,
+ gpointer data)
+{
+ GtkTextLayout *layout = GTK_TEXT_LAYOUT (data);
+
+ gtk_text_layout_update_cursor_line (layout);
+}
+
+static void
+gtk_text_layout_buffer_delete_range (GtkTextBuffer *textbuffer,
+ GtkTextIter *start,
+ GtkTextIter *end,
+ gpointer data)
+{
+ GtkTextLayout *layout = GTK_TEXT_LAYOUT (data);
+
+ gtk_text_layout_update_cursor_line (layout);
+}