]> Pileus Git - ~andy/gtk/blob - gtk/gtktextsegment.h
text_window_* weren't static and should have been. Start work on child
[~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 #include <gtk/gtktextchildprivate.h>
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif /* __cplusplus */
13
14 /*
15  * Segments: each line is divided into one or more segments, where each
16  * segment is one of several things, such as a group of characters, a
17  * tag toggle, a mark, or an embedded widget.  Each segment starts with
18  * a standard header followed by a body that varies from type to type.
19  */
20
21 /* This header has the segment type, and two specific segments
22    (character and toggle segments) */
23
24 /* Information a BTree stores about a tag. */
25 typedef struct _GtkTextTagInfo GtkTextTagInfo;
26 struct _GtkTextTagInfo {
27   GtkTextTag *tag;
28   GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
29   gint toggle_count;      /* total toggles of this tag below tag_root */
30 };
31
32 /* Body of a segment that toggles a tag on or off */
33 struct _GtkTextToggleBody {
34   GtkTextTagInfo *info;             /* Tag that starts or ends here. */
35   gboolean inNodeCounts;             /* TRUE means this toggle has been
36                                       * accounted for in node toggle
37                                       * counts; FALSE means it hasn't, yet. */
38 };
39
40
41 /* Class struct for segments */
42
43 /* Split seg at index, returning list of two new segments, and freeing seg */
44 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc)      (GtkTextLineSegment *seg,
45                                                          gint                index);
46
47 /* Delete seg which is contained in line; if tree_gone, the tree is being
48  * freed in its entirety, which may matter for some reason (?)
49  * Return TRUE if the segment is not deleteable, e.g. a mark.
50  */
51 typedef gboolean            (*GtkTextSegDeleteFunc)     (GtkTextLineSegment *seg,
52                                                          GtkTextLine        *line,
53                                                          gboolean            tree_gone);
54
55 /* Called after segment structure of line changes, so segments can
56  * cleanup (e.g. merge with adjacent segments). Returns a segment list
57  * to replace the original segment list with. The line argument is
58  * the current line.
59  */
60 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc)    (GtkTextLineSegment *seg,
61                                                          GtkTextLine        *line);
62
63 /* Called when a segment moves from one line to another. CleanupFunc is also
64  * called in that case, so many segments just use CleanupFunc, I'm not sure
65  * what's up with that (this function may not be needed...)
66  */
67 typedef void                (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
68                                                          GtkTextLine        *line);
69
70 /* Called to do debug checks on the segment. */
71 typedef void                (*GtkTextSegCheckFunc)      (GtkTextLineSegment *seg,
72                                                          GtkTextLine        *line);
73
74 struct _GtkTextLineSegmentClass {
75   char *name;                           /* Name of this kind of segment. */
76   gboolean leftGravity;                 /* If a segment has zero size (e.g. a
77                                          * mark or tag toggle), does it
78                                          * attach to character to its left
79                                          * or right?  1 means left, 0 means
80                                          * right. */
81   GtkTextSegSplitFunc splitFunc;        /* Procedure to split large segment
82                                          * into two smaller ones. */
83   GtkTextSegDeleteFunc deleteFunc;      /* Procedure to call to delete
84                                          * segment. */
85   GtkTextSegCleanupFunc cleanupFunc;   /* After any change to a line, this
86                                          * procedure is invoked for all
87                                          * segments left in the line to
88                                          * perform any cleanup they wish
89                                          * (e.g. joining neighboring
90                                          * segments). */
91   GtkTextSegLineChangeFunc lineChangeFunc;
92                                          /* Invoked when a segment is about
93                                           * to be moved from its current line
94                                           * to an earlier line because of
95                                           * a deletion.  The line is that
96                                           * for the segment's old line.
97                                           * CleanupFunc will be invoked after
98                                           * the deletion is finished. */
99
100   GtkTextSegCheckFunc checkFunc;       /* Called during consistency checks
101                                          * to check internal consistency of
102                                          * segment. */
103 };
104
105 /*
106  * The data structure below defines line segments.
107  */
108
109 struct _GtkTextLineSegment {
110   GtkTextLineSegmentClass *type;                /* Pointer to record describing
111                                                  * segment's type. */
112   GtkTextLineSegment *next;                /* Next in list of segments for this
113                                             * line, or NULL for end of list. */
114
115   int char_count;                       /* # of chars of index space occupied */
116   
117   int byte_count;                       /* Size of this segment (# of bytes
118                                          * of index space it occupies). */
119   union {
120     char chars[4];                      /* Characters that make up character
121                                          * info.  Actual length varies to
122                                          * hold as many characters as needed.*/
123     GtkTextToggleBody toggle;              /* Information about tag toggle. */
124     GtkTextMarkBody mark;              /* Information about mark. */
125     GtkTextPixbuf pixbuf;              /* Child pixbuf */
126     GtkTextChildBody child;            /* Child widget */
127   } body;
128 };
129
130
131 GtkTextLineSegment  *gtk_text_line_segment_split (const GtkTextIter *iter);
132
133 GtkTextLineSegment *char_segment_new                  (const gchar    *text,
134                                                        guint           len);
135 GtkTextLineSegment *char_segment_new_from_two_strings (const gchar    *text1,
136                                                        guint           len1,
137                                                        const gchar    *text2,
138                                                        guint           len2);
139 GtkTextLineSegment *toggle_segment_new                (GtkTextTagInfo *info,
140                                                        gboolean        on);
141
142
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146
147 #endif
148
149