*/
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
-#include <config.h>
+#include "config.h"
#include "gtktextbtree.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "gtktexttag.h"
+#include "gtktexttagprivate.h"
#include "gtktexttagtable.h"
#include "gtktextlayout.h"
#include "gtktextiterprivate.h"
#include "gtkdebug.h"
#include "gtktextmarkprivate.h"
-#include "gtkalias.h"
/*
* Types
int level; /* Level of this node in the B-tree.
* 0 refers to the bottom of the tree
* (children are lines, not nodes). */
+ int num_lines; /* Total number of lines (leaves) in
+ * the subtree rooted here. */
+ int num_chars; /* Number of chars below here */
+ int num_children; /* Number of children of this node. */
union { /* First in linked list of children. */
struct _GtkTextBTreeNode *node; /* Used if level > 0. */
GtkTextLine *line; /* Used if level == 0. */
} children;
- int num_children; /* Number of children of this node. */
- int num_lines; /* Total number of lines (leaves) in
- * the subtree rooted here. */
- int num_chars; /* Number of chars below here */
NodeData *node_data;
};
gpointer view_id);
static GtkTextBTreeNode *gtk_text_btree_node_new (void);
+#if 0
static void gtk_text_btree_node_invalidate_downward (GtkTextBTreeNode *node);
+#endif
static void gtk_text_btree_node_invalidate_upward (GtkTextBTreeNode *node,
gpointer view_id);
static NodeData * gtk_text_btree_node_check_valid (GtkTextBTreeNode *node,
static void redisplay_region (GtkTextBTree *tree,
const GtkTextIter *start,
- const GtkTextIter *end);
+ const GtkTextIter *end,
+ gboolean cursors_only);
/* Inline thingies */
g_object_ref (tree->table);
tree->tag_changed_handler = g_signal_connect (tree->table,
- "tag_changed",
+ "tag-changed",
G_CALLBACK (tag_changed_cb),
tree);
*/
line = _gtk_text_line_previous (line);
_gtk_text_btree_get_iter_at_line (tree, &end_propagate, line, 0);
- _gtk_text_btree_invalidate_region (tree, end, &end_propagate);
+ _gtk_text_btree_invalidate_region (tree, end, &end_propagate, FALSE);
}
/* Sweep backward */
if (line && line->dir_propagated_forward == PANGO_DIRECTION_NEUTRAL)
{
_gtk_text_btree_get_iter_at_line (tree, &start_propagate, line, 0);
- _gtk_text_btree_invalidate_region(tree, &start_propagate, start);
+ _gtk_text_btree_invalidate_region (tree, &start_propagate, start, FALSE);
}
}
}
GtkTextBTree *tree;
GtkTextLine *start_line;
GtkTextLine *end_line;
+ GtkTextLine *line;
GtkTextLine *deleted_lines = NULL; /* List of lines we've deleted */
gint start_byte_offset;
tree = _gtk_text_iter_get_btree (start);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
/* Broadcast the need for redisplay before we break the iterators */
DV (g_print ("invalidating due to deleting some text (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (tree, start, end);
+ _gtk_text_btree_invalidate_region (tree, start, end, FALSE);
/* Save the byte offset so we can reset the iterators */
start_byte_offset = gtk_text_iter_get_line_index (start);
start_line->segments = seg;
}
else if (prev_seg->next &&
+ prev_seg->next != last_seg &&
seg->type == >k_text_toggle_off_type &&
prev_seg->next->type == >k_text_toggle_on_type &&
seg->body.toggle.info == prev_seg->next->body.toggle.info)
view = tree->views;
while (view)
{
- GtkTextLine *line;
GtkTextLineData *ld;
gint deleted_width = 0;
deleted_height += ld->height;
}
- if (!view->next)
- gtk_text_line_destroy (tree, line);
-
line = next_line;
}
view = view->next;
}
+ line = deleted_lines;
+ while (line)
+ {
+ GtkTextLine *next_line = line->next;
+
+ gtk_text_line_destroy (tree, line);
+
+ line = next_line;
+ }
+
/* avoid dangling pointer */
deleted_lines = NULL;
chars_changed (tree);
segments_changed (tree);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
/* Re-initialize our iterators */
gtk_text_iter_forward_chars (&end, char_count_delta);
DV (g_print ("invalidating due to inserting some text (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (tree,
- &start, &end);
+ _gtk_text_btree_invalidate_region (tree, &start, &end, FALSE);
/* Convenience for the user */
gtk_text_iter_forward_char (iter); /* skip forward past the segment */
DV (g_print ("invalidating due to inserting pixbuf/widget (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (tree, &start, iter);
+ _gtk_text_btree_invalidate_region (tree, &start, iter, FALSE);
}
void
{
gint current_y = 0;
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
if (node->level == 0)
void
_gtk_text_btree_invalidate_region (GtkTextBTree *tree,
const GtkTextIter *start,
- const GtkTextIter *end)
+ const GtkTextIter *end,
+ gboolean cursors_only)
{
BTreeView *view;
while (view != NULL)
{
- gtk_text_layout_invalidate (view->layout, start, end);
+ if (cursors_only)
+ gtk_text_layout_invalidate_cursors (view->layout, start, end);
+ else
+ gtk_text_layout_invalidate (view->layout, start, end);
view = view->next;
}
if (_gtk_text_tag_affects_size (tag))
{
DV (g_print ("invalidating due to size-affecting tag (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (tree, start, end);
+ _gtk_text_btree_invalidate_region (tree, start, end, FALSE);
}
else if (_gtk_text_tag_affects_nonsize_appearance (tag))
{
/* We only need to queue a redraw, not a relayout */
- redisplay_region (tree, start, end);
+ redisplay_region (tree, start, end, FALSE);
}
/* We don't need to do anything if the tag doesn't affect display */
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
g_return_if_fail (_gtk_text_iter_get_btree (start_orig) ==
_gtk_text_iter_get_btree (end_orig));
- g_return_if_fail (tag->table == _gtk_text_iter_get_btree (start_orig)->table);
+ g_return_if_fail (tag->priv->table == _gtk_text_iter_get_btree (start_orig)->table);
#if 0
printf ("%s tag %s from %d to %d\n",
queue_tag_redisplay (tree, tag, &start, &end);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
}
return line;
}
+/* It returns an array sorted by tags priority, ready to pass to
+ * _gtk_text_attributes_fill_from_tags() */
GtkTextTag**
_gtk_text_btree_get_tags (const GtkTextIter *iter,
gint *num_tags)
g_free (tagInfo.tags);
return NULL;
}
+
+ /* Sort tags in ascending order of priority */
+ _gtk_text_tag_array_sort (tagInfo.tags, dst);
+
return tagInfo.tags;
}
if (copy)
{
g_string_append_len (string,
- gtk_text_unknown_char_utf8,
- 3);
+ _gtk_text_unknown_char_utf8,
+ GTK_TEXT_UNKNOWN_CHAR_UTF8_LEN);
}
}
|| (seg->type == >k_text_toggle_off_type))
{
tag = seg->body.toggle.info->tag;
- if (tag->invisible_set && tag->values->invisible)
+ if (tag->priv->invisible_set)
{
- tags[tag->priority] = tag;
- tagCnts[tag->priority]++;
+ tags[tag->priv->priority] = tag;
+ tagCnts[tag->priv->priority]++;
}
}
}
|| (seg->type == >k_text_toggle_off_type))
{
tag = seg->body.toggle.info->tag;
- if (tag->invisible_set && tag->values->invisible)
+ if (tag->priv->invisible_set)
{
- tags[tag->priority] = tag;
- tagCnts[tag->priority]++;
+ tags[tag->priv->priority] = tag;
+ tagCnts[tag->priv->priority]++;
}
}
}
if (summary->toggle_count & 1)
{
tag = summary->info->tag;
- if (tag->invisible_set && tag->values->invisible)
+ if (tag->priv->invisible_set)
{
- tags[tag->priority] = tag;
- tagCnts[tag->priority] += summary->toggle_count;
+ tags[tag->priv->priority] = tag;
+ tagCnts[tag->priv->priority] += summary->toggle_count;
}
}
}
}
#endif
#endif
- invisible = tags[i]->values->invisible;
+ invisible = tags[i]->priv->values->invisible;
break;
}
}
static void
redisplay_region (GtkTextBTree *tree,
const GtkTextIter *start,
- const GtkTextIter *end)
+ const GtkTextIter *end,
+ gboolean cursors_only)
{
BTreeView *view;
GtkTextLine *start_line, *end_line;
if (ld)
end_y += ld->height;
- gtk_text_layout_changed (view->layout, start_y,
- end_y - start_y,
- end_y - start_y);
+ if (cursors_only)
+ gtk_text_layout_cursors_changed (view->layout, start_y,
+ end_y - start_y,
+ end_y - start_y);
+ else
+ gtk_text_layout_changed (view->layout, start_y,
+ end_y - start_y,
+ end_y - start_y);
view = view->next;
}
{
GtkTextIter iter;
GtkTextIter end;
+ gboolean cursor_only;
_gtk_text_btree_get_iter_at_mark (mark->body.mark.tree,
&iter,
gtk_text_iter_forward_char (&end);
DV (g_print ("invalidating due to moving visible mark (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (mark->body.mark.tree,
- &iter, &end);
+ cursor_only = mark == mark->body.mark.tree->insert_mark->segment;
+ _gtk_text_btree_invalidate_region (mark->body.mark.tree, &iter, &end, cursor_only);
}
static void
GtkTextLineSegment *mark,
GtkTextIter *iter)
{
- if (gtk_text_iter_get_line (iter) ==
- _gtk_text_btree_line_count (tree))
+ if (gtk_text_iter_get_line (iter) == _gtk_text_btree_line_count (tree))
gtk_text_iter_backward_char (iter);
}
g_return_val_if_fail (_gtk_text_iter_get_btree (where) == tree, NULL);
if (existing_mark)
- mark = existing_mark->segment;
+ {
+ if (gtk_text_mark_get_buffer (existing_mark) != NULL)
+ mark = existing_mark->segment;
+ else
+ mark = NULL;
+ }
else if (name != NULL)
mark = g_hash_table_lookup (tree->mark_table,
name);
iter = *where;
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_iter_check (&iter);
if (mark != NULL)
_gtk_text_btree_get_iter_at_mark (tree, &old_pos,
mark->body.mark.obj);
- redisplay_region (tree, &old_pos, where);
+ redisplay_region (tree, &old_pos, where, TRUE);
}
/*
}
else
{
- mark = _gtk_mark_segment_new (tree,
- left_gravity,
- name);
+ if (existing_mark)
+ g_object_ref (existing_mark);
+ else
+ existing_mark = gtk_text_mark_new (name, left_gravity);
+
+ mark = existing_mark->segment;
+ _gtk_mark_segment_set_tree (mark, tree);
mark->body.mark.line = _gtk_text_iter_get_text_line (&iter);
mark);
}
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_iter_check (&iter);
/* Link mark into new location */
redisplay_mark_if_visible (mark);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_iter_check (&iter);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
return mark;
const GtkTextIter *ins,
const GtkTextIter *bound)
{
- GtkTextIter start, end;
+ GtkTextIter old_ins, old_bound;
- if (_gtk_text_btree_get_selection_bounds (tree, &start, &end))
- redisplay_region (tree, &start, &end);
+ _gtk_text_btree_get_iter_at_mark (tree, &old_ins,
+ tree->insert_mark);
+ _gtk_text_btree_get_iter_at_mark (tree, &old_bound,
+ tree->selection_bound_mark);
- /* Move insert AND selection_bound before we redisplay */
- real_set_mark (tree, tree->insert_mark,
- "insert", FALSE, ins, TRUE, FALSE);
- real_set_mark (tree, tree->selection_bound_mark,
- "selection_bound", FALSE, bound, TRUE, FALSE);
+ /* Check if it's no-op since gtk_text_buffer_place_cursor()
+ * also calls this, and this will redraw the cursor line. */
+ if (!gtk_text_iter_equal (&old_ins, ins) ||
+ !gtk_text_iter_equal (&old_bound, bound))
+ {
+ redisplay_region (tree, &old_ins, &old_bound, TRUE);
+
+ /* Move insert AND selection_bound before we redisplay */
+ real_set_mark (tree, tree->insert_mark,
+ "insert", FALSE, ins, TRUE, FALSE);
+ real_set_mark (tree, tree->selection_bound_mark,
+ "selection_bound", FALSE, bound, TRUE, FALSE);
- redisplay_region (tree, ins, bound);
+ redisplay_region (tree, ins, bound, TRUE);
+ }
}
return segment == tree->selection_bound_mark;
}
+GtkTextMark *
+_gtk_text_btree_get_insert (GtkTextBTree *tree)
+{
+ return tree->insert_mark;
+}
+
+GtkTextMark *
+_gtk_text_btree_get_selection_bound (GtkTextBTree *tree)
+{
+ return tree->selection_bound_mark;
+}
+
GtkTextMark*
_gtk_text_btree_get_mark_by_name (GtkTextBTree *tree,
const gchar *name)
{
seg->body.mark.visible = setting;
- redisplay_mark (seg);
+ if (seg->body.mark.tree)
+ redisplay_mark (seg);
}
}
{
if (tree->end_iter_line_stamp != tree->chars_changed_stamp)
{
- int n_lines;
- int real_line;
-
- /* n_lines is without the magic line at the end */
- n_lines = _gtk_text_btree_line_count (tree);
-
- g_assert (n_lines >= 1);
+ gint real_line;
+
+ /* n_lines is without the magic line at the end */
+ g_assert (_gtk_text_btree_line_count (tree) >= 1);
tree->end_iter_line = _gtk_text_btree_get_line_no_last (tree, -1, &real_line);
while (offset >= seg->byte_count)
{
- g_assert (seg != NULL); /* means an invalid byte index */
offset -= seg->byte_count;
seg = seg->next;
+ g_assert (seg != NULL); /* means an invalid byte index */
}
if (seg_offset)
while (offset >= seg->char_count)
{
- g_assert (seg != NULL); /* means an invalid char index */
offset -= seg->char_count;
seg = seg->next;
+ g_assert (seg != NULL); /* means an invalid char index */
}
if (seg_offset)
while (offset > 0 && offset >= seg->byte_count)
{
- g_assert (seg != NULL); /* means an invalid byte index */
offset -= seg->byte_count;
seg = seg->next;
+ g_assert (seg != NULL); /* means an invalid byte index */
}
if (seg_offset)
while (offset > 0 && offset >= seg->char_count)
{
- g_assert (seg != NULL); /* means an invalid byte index */
offset -= seg->char_count;
seg = seg->next;
+ g_assert (seg != NULL); /* means an invalid byte index */
}
if (seg_offset)
while (byte_offset >= seg->byte_count) /* while (we need to go farther than
the next segment) */
{
- g_assert (seg != NULL); /* our byte_index was bogus if this happens */
-
byte_offset -= seg->byte_count;
char_offset += seg->char_count;
-
seg = seg->next;
+ g_assert (seg != NULL); /* our byte_index was bogus if this happens */
}
g_assert (seg != NULL);
g_return_val_if_fail (line != NULL, NULL);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
if (tag == NULL)
g_return_val_if_fail (line != NULL, NULL);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
if (tag == NULL)
{
GtkTextLine *line;
- line = g_new0(GtkTextLine, 1);
+ line = g_slice_new0 (GtkTextLine);
line->dir_strong = PANGO_DIRECTION_NEUTRAL;
line->dir_propagated_forward = PANGO_DIRECTION_NEUTRAL;
line->dir_propagated_back = PANGO_DIRECTION_NEUTRAL;
ld = next;
}
- g_free (line);
+ g_slice_free (GtkTextLine, line);
}
static void
{
GtkTextBTreeNode *node;
- node = g_new (GtkTextBTreeNode, 1);
+ node = g_slice_new (GtkTextBTreeNode);
node->node_data = NULL;
}
/* Add node and all children to the damage region. */
+#if 0
static void
gtk_text_btree_node_invalidate_downward (GtkTextBTreeNode *node)
{
}
}
}
+#endif
static void
gtk_text_btree_node_invalidate_upward (GtkTextBTreeNode *node, gpointer view_id)
if (new_height)
*new_height = state.new_height;
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
return TRUE;
summary_list_destroy (node->summary);
node_data_list_destroy (node->node_data);
- g_free (node);
+ g_slice_free (GtkTextBTreeNode, node);
}
static NodeData*
/* Must be a last toggle if there was a first one. */
_gtk_text_btree_get_iter_at_last_toggle (tree, &end, tag);
DV (g_print ("invalidating due to tag change (%s)\n", G_STRLOC));
- _gtk_text_btree_invalidate_region (tree,
- &start, &end);
+ _gtk_text_btree_invalidate_region (tree, &start, &end, FALSE);
}
}
gtk_text_btree_rebalance (tree, node);
}
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
}
cleanup_line (line);
segments_changed (tree);
- if (gtk_debug_flags & GTK_DEBUG_TEXT)
+ if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
}
break;
}
g_error ("gtk_text_btree_node_check_consistency: GtkTextBTreeNode tag \"%s\" not %s",
- summary->info->tag->name,
+ summary->info->tag->priv->name,
"present in parent summaries");
}
if (summary->info == summary2->info)
if (summary->info->toggle_count == summary->toggle_count)
{
g_error ("gtk_text_btree_node_check_consistency: found unpruned root for \"%s\"",
- summary->info->tag->name);
+ summary->info->tag->priv->name);
}
toggle_count = 0;
if (node->level == 0)
if (summary2->info == summary->info)
{
g_error ("gtk_text_btree_node_check_consistency: duplicated GtkTextBTreeNode tag: %s",
- summary->info->tag->name);
+ summary->info->tag->priv->name);
}
}
}
if (info->toggle_count != 0)
{
g_error ("_gtk_text_btree_check found \"%s\" with toggles (%d) but no root",
- tag->name, info->toggle_count);
+ tag->priv->name, info->toggle_count);
}
continue; /* no ranges for the tag */
}
else if (info->toggle_count == 0)
{
g_error ("_gtk_text_btree_check found root for \"%s\" with no toggles",
- tag->name);
+ tag->priv->name);
}
else if (info->toggle_count & 1)
{
g_error ("_gtk_text_btree_check found odd toggle count for \"%s\" (%d)",
- tag->name, info->toggle_count);
+ tag->priv->name, info->toggle_count);
}
for (summary = node->summary; summary != NULL;
summary = summary->next)
}
else
{
- GtkTextLineSegmentClass * last = NULL;
+ const GtkTextLineSegmentClass *last = NULL;
for (line = node->children.line ; line != NULL ;
line = line->next)
if (count != info->toggle_count)
{
g_error ("_gtk_text_btree_check toggle_count (%d) wrong for \"%s\" should be (%d)",
- info->toggle_count, tag->name, count);
+ info->toggle_count, tag->priv->name, count);
}
}
}
info = list->data;
printf (" tag `%s': root at %p, toggle count %d\n",
- info->tag->name, info->tag_root, info->toggle_count);
+ info->tag->priv->name, info->tag_root, info->toggle_count);
list = g_slist_next (list);
}
seg->type == >k_text_toggle_off_type)
{
printf ("%s tag `%s' %s\n",
- spaces, seg->body.toggle.info->tag->name,
+ spaces, seg->body.toggle.info->tag->priv->name,
seg->type == >k_text_toggle_off_type ? "off" : "on");
}
while (s)
{
printf ("%s %d toggles of `%s' below this node\n",
- spaces, s->toggle_count, s->info->tag->name);
+ spaces, s->toggle_count, s->info->tag->priv->name);
s = s->next;
}
seg->type == >k_text_toggle_off_type)
{
printf (" tag `%s' priority %d\n",
- seg->body.toggle.info->tag->name,
- seg->body.toggle.info->tag->priority);
+ seg->body.toggle.info->tag->priv->name,
+ seg->body.toggle.info->tag->priv->priority);
}
}
-
-#define __GTK_TEXT_BTREE_C__
-#include "gtkaliasdef.c"