1 /* GTK - The GIMP Toolkit
2 * gtktextsegment.h Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25 #ifndef __GTK_TEXT_SEGMENT_H__
26 #define __GTK_TEXT_SEGMENT_H__
28 #include <gtk/gtktexttag.h>
29 #include <gtk/gtktextiter.h>
30 #include <gtk/gtktextmarkprivate.h>
31 #include <gtk/gtktextchild.h>
32 #include <gtk/gtktextchildprivate.h>
37 * Segments: each line is divided into one or more segments, where each
38 * segment is one of several things, such as a group of characters, a
39 * tag toggle, a mark, or an embedded widget. Each segment starts with
40 * a standard header followed by a body that varies from type to type.
43 /* This header has the segment type, and two specific segments
44 (character and toggle segments) */
46 /* Information a BTree stores about a tag. */
47 typedef struct _GtkTextTagInfo GtkTextTagInfo;
48 struct _GtkTextTagInfo {
50 GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
51 gint toggle_count; /* total toggles of this tag below tag_root */
54 /* Body of a segment that toggles a tag on or off */
55 struct _GtkTextToggleBody {
56 GtkTextTagInfo *info; /* Tag that starts or ends here. */
57 gboolean inNodeCounts; /* TRUE means this toggle has been
58 * accounted for in node toggle
59 * counts; FALSE means it hasn't, yet. */
63 /* Class struct for segments */
65 /* Split seg at index, returning list of two new segments, and freeing seg */
66 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc) (GtkTextLineSegment *seg,
69 /* Delete seg which is contained in line; if tree_gone, the tree is being
70 * freed in its entirety, which may matter for some reason (?)
71 * Return TRUE if the segment is not deleteable, e.g. a mark.
73 typedef gboolean (*GtkTextSegDeleteFunc) (GtkTextLineSegment *seg,
77 /* Called after segment structure of line changes, so segments can
78 * cleanup (e.g. merge with adjacent segments). Returns a segment list
79 * to replace the original segment list with. The line argument is
82 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc) (GtkTextLineSegment *seg,
85 /* Called when a segment moves from one line to another. CleanupFunc is also
86 * called in that case, so many segments just use CleanupFunc, I'm not sure
87 * what's up with that (this function may not be needed...)
89 typedef void (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
92 /* Called to do debug checks on the segment. */
93 typedef void (*GtkTextSegCheckFunc) (GtkTextLineSegment *seg,
96 struct _GtkTextLineSegmentClass {
97 char *name; /* Name of this kind of segment. */
98 gboolean leftGravity; /* If a segment has zero size (e.g. a
99 * mark or tag toggle), does it
100 * attach to character to its left
101 * or right? 1 means left, 0 means
103 GtkTextSegSplitFunc splitFunc; /* Procedure to split large segment
104 * into two smaller ones. */
105 GtkTextSegDeleteFunc deleteFunc; /* Procedure to call to delete
107 GtkTextSegCleanupFunc cleanupFunc; /* After any change to a line, this
108 * procedure is invoked for all
109 * segments left in the line to
110 * perform any cleanup they wish
111 * (e.g. joining neighboring
113 GtkTextSegLineChangeFunc lineChangeFunc;
114 /* Invoked when a segment is about
115 * to be moved from its current line
116 * to an earlier line because of
117 * a deletion. The line is that
118 * for the segment's old line.
119 * CleanupFunc will be invoked after
120 * the deletion is finished. */
122 GtkTextSegCheckFunc checkFunc; /* Called during consistency checks
123 * to check internal consistency of
128 * The data structure below defines line segments.
131 struct _GtkTextLineSegment {
132 const GtkTextLineSegmentClass *type; /* Pointer to record describing
134 GtkTextLineSegment *next; /* Next in list of segments for this
135 * line, or NULL for end of list. */
137 int char_count; /* # of chars of index space occupied */
139 int byte_count; /* Size of this segment (# of bytes
140 * of index space it occupies). */
142 char chars[4]; /* Characters that make up character
143 * info. Actual length varies to
144 * hold as many characters as needed.*/
145 GtkTextToggleBody toggle; /* Information about tag toggle. */
146 GtkTextMarkBody mark; /* Information about mark. */
147 GtkTextPixbuf pixbuf; /* Child pixbuf */
148 GtkTextChildBody child; /* Child widget */
153 GtkTextLineSegment *gtk_text_line_segment_split (const GtkTextIter *iter);
155 GtkTextLineSegment *_gtk_char_segment_new (const gchar *text,
157 GtkTextLineSegment *_gtk_char_segment_new_from_two_strings (const gchar *text1,
163 GtkTextLineSegment *_gtk_toggle_segment_new (GtkTextTagInfo *info,