1 #ifndef GTK_TEXT_SEGMENT_H
2 #define GTK_TEXT_SEGMENT_H
4 #include <gtk/gtktexttag.h>
5 #include <gtk/gtktextiter.h>
6 #include <gtk/gtktextmarkprivate.h>
7 #include <gtk/gtktextchild.h>
11 #endif /* __cplusplus */
14 * Segments: each line is divided into one or more segments, where each
15 * segment is one of several things, such as a group of characters, a
16 * tag toggle, a mark, or an embedded widget. Each segment starts with
17 * a standard header followed by a body that varies from type to type.
20 /* This header has the segment type, and two specific segments
21 (character and toggle segments) */
23 /* Information a BTree stores about a tag. */
24 typedef struct _GtkTextTagInfo GtkTextTagInfo;
25 struct _GtkTextTagInfo {
27 GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
28 gint toggle_count; /* total toggles of this tag below tag_root */
31 /* Body of a segment that toggles a tag on or off */
32 struct _GtkTextToggleBody {
33 GtkTextTagInfo *info; /* Tag that starts or ends here. */
34 gboolean inNodeCounts; /* TRUE means this toggle has been
35 * accounted for in node toggle
36 * counts; FALSE means it hasn't, yet. */
40 /* Class struct for segments */
42 /* Split seg at index, returning list of two new segments, and freeing seg */
43 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc) (GtkTextLineSegment *seg,
46 /* Delete seg which is contained in line; if tree_gone, the tree is being
47 * freed in its entirety, which may matter for some reason (?)
48 * Return TRUE if the segment is not deleteable, e.g. a mark.
50 typedef gboolean (*GtkTextSegDeleteFunc) (GtkTextLineSegment *seg,
54 /* Called after segment structure of line changes, so segments can
55 * cleanup (e.g. merge with adjacent segments). Returns a segment list
56 * to replace the original segment list with. The line argument is
59 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc) (GtkTextLineSegment *seg,
62 /* Called when a segment moves from one line to another. CleanupFunc is also
63 * called in that case, so many segments just use CleanupFunc, I'm not sure
64 * what's up with that (this function may not be needed...)
66 typedef void (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
69 /* Called to do debug checks on the segment. */
70 typedef void (*GtkTextSegCheckFunc) (GtkTextLineSegment *seg,
73 struct _GtkTextLineSegmentClass {
74 char *name; /* Name of this kind of segment. */
75 gboolean leftGravity; /* If a segment has zero size (e.g. a
76 * mark or tag toggle), does it
77 * attach to character to its left
78 * or right? 1 means left, 0 means
80 GtkTextSegSplitFunc splitFunc; /* Procedure to split large segment
81 * into two smaller ones. */
82 GtkTextSegDeleteFunc deleteFunc; /* Procedure to call to delete
84 GtkTextSegCleanupFunc cleanupFunc; /* After any change to a line, this
85 * procedure is invoked for all
86 * segments left in the line to
87 * perform any cleanup they wish
88 * (e.g. joining neighboring
90 GtkTextSegLineChangeFunc lineChangeFunc;
91 /* Invoked when a segment is about
92 * to be moved from its current line
93 * to an earlier line because of
94 * a deletion. The line is that
95 * for the segment's old line.
96 * CleanupFunc will be invoked after
97 * the deletion is finished. */
99 GtkTextSegCheckFunc checkFunc; /* Called during consistency checks
100 * to check internal consistency of
105 * The data structure below defines line segments.
108 struct _GtkTextLineSegment {
109 GtkTextLineSegmentClass *type; /* Pointer to record describing
111 GtkTextLineSegment *next; /* Next in list of segments for this
112 * line, or NULL for end of list. */
114 int char_count; /* # of chars of index space occupied */
116 int byte_count; /* Size of this segment (# of bytes
117 * of index space it occupies). */
119 char chars[4]; /* Characters that make up character
120 * info. Actual length varies to
121 * hold as many characters as needed.*/
122 GtkTextToggleBody toggle; /* Information about tag toggle. */
123 GtkTextMarkBody mark; /* Information about mark. */
124 GtkTextPixbuf pixbuf; /* Child pixbuf */
126 GtkTextChild child; /* child widget */
132 GtkTextLineSegment *gtk_text_line_segment_split(const GtkTextIter *iter);
134 GtkTextLineSegment *char_segment_new(const gchar *text, guint len);
136 GtkTextLineSegment *char_segment_new_from_two_strings(const gchar *text1, guint len1,
137 const gchar *text2, guint len2);
139 GtkTextLineSegment *toggle_segment_new(GtkTextTagInfo *info, gboolean on);
143 #endif /* __cplusplus */