]> Pileus Git - ~andy/gtk/blob - gtk/gtktextsegment.h
0dfd05630dc1099dc9a9112b8c88962327e15bee
[~andy/gtk] / gtk / gtktextsegment.h
1 #ifndef GTK_TEXT_SEGMENT_H
2 #define GTK_TEXT_SEGMENT_H
3
4 #include <gtk/gtktexttag.h>
5 #include <gtk/gtktextiter.h>
6 #include <gtk/gtktextmarkprivate.h>
7 #include <gtk/gtktextchild.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif /* __cplusplus */
12
13 /*
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.
18  */
19
20 /* This header has the segment type, and two specific segments
21    (character and toggle segments) */
22
23 /* Information a BTree stores about a tag. */
24 typedef struct _GtkTextTagInfo GtkTextTagInfo;
25 struct _GtkTextTagInfo {
26   GtkTextTag *tag;
27   GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
28   gint toggle_count;      /* total toggles of this tag below tag_root */
29 };
30
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. */
37 };
38
39
40 /* Class struct for segments */
41
42 /* Split seg at index, returning list of two new segments, and freeing seg */
43 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc)      (GtkTextLineSegment *seg,
44                                                          gint                index);
45
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.
49  */
50 typedef gboolean            (*GtkTextSegDeleteFunc)     (GtkTextLineSegment *seg,
51                                                          GtkTextLine        *line,
52                                                          gboolean            tree_gone);
53
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
57  * the current line.
58  */
59 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc)    (GtkTextLineSegment *seg,
60                                                          GtkTextLine        *line);
61
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...)
65  */
66 typedef void                (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
67                                                          GtkTextLine        *line);
68
69 /* Called to do debug checks on the segment. */
70 typedef void                (*GtkTextSegCheckFunc)      (GtkTextLineSegment *seg,
71                                                          GtkTextLine        *line);
72
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
79                                          * right. */
80   GtkTextSegSplitFunc splitFunc;        /* Procedure to split large segment
81                                          * into two smaller ones. */
82   GtkTextSegDeleteFunc deleteFunc;      /* Procedure to call to delete
83                                          * segment. */
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
89                                          * segments). */
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. */
98
99   GtkTextSegCheckFunc checkFunc;       /* Called during consistency checks
100                                          * to check internal consistency of
101                                          * segment. */
102 };
103
104 /*
105  * The data structure below defines line segments.
106  */
107
108 struct _GtkTextLineSegment {
109   GtkTextLineSegmentClass *type;                /* Pointer to record describing
110                                                  * segment's type. */
111   GtkTextLineSegment *next;                /* Next in list of segments for this
112                                             * line, or NULL for end of list. */
113
114   int char_count;                       /* # of chars of index space occupied */
115   
116   int byte_count;                       /* Size of this segment (# of bytes
117                                          * of index space it occupies). */
118   union {
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 */
125 #if 0
126     GtkTextChild child;                /* child widget */
127 #endif
128   } body;
129 };
130
131
132 GtkTextLineSegment  *gtk_text_line_segment_split(const GtkTextIter *iter);
133
134 GtkTextLineSegment *char_segment_new(const gchar *text, guint len);
135
136 GtkTextLineSegment *char_segment_new_from_two_strings(const gchar *text1, guint len1,
137                                                    const gchar *text2, guint len2);
138
139 GtkTextLineSegment *toggle_segment_new(GtkTextTagInfo *info, gboolean on);
140
141 #ifdef __cplusplus
142 }
143 #endif /* __cplusplus */
144
145 #endif
146
147