]> Pileus Git - ~andy/gtk/blob - gtk/gtktextsegment.h
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtktextsegment.h
1 /* GTK - The GIMP Toolkit
2  * gtktextsegment.h Copyright (C) 2000 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 /*
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/.
23  */
24
25 #ifndef __GTK_TEXT_SEGMENT_H__
26 #define __GTK_TEXT_SEGMENT_H__
27
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>
33
34 G_BEGIN_DECLS
35
36 /*
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.
41  */
42
43 /* This header has the segment type, and two specific segments
44    (character and toggle segments) */
45
46 /* Information a BTree stores about a tag. */
47 typedef struct _GtkTextTagInfo GtkTextTagInfo;
48 struct _GtkTextTagInfo {
49   GtkTextTag *tag;
50   GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
51   gint toggle_count;      /* total toggles of this tag below tag_root */
52 };
53
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. */
60 };
61
62
63 /* Class struct for segments */
64
65 /* Split seg at index, returning list of two new segments, and freeing seg */
66 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc)      (GtkTextLineSegment *seg,
67                                                          gint                index);
68
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.
72  */
73 typedef gboolean            (*GtkTextSegDeleteFunc)     (GtkTextLineSegment *seg,
74                                                          GtkTextLine        *line,
75                                                          gboolean            tree_gone);
76
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
80  * the current line.
81  */
82 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc)    (GtkTextLineSegment *seg,
83                                                          GtkTextLine        *line);
84
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...)
88  */
89 typedef void                (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
90                                                          GtkTextLine        *line);
91
92 /* Called to do debug checks on the segment. */
93 typedef void                (*GtkTextSegCheckFunc)      (GtkTextLineSegment *seg,
94                                                          GtkTextLine        *line);
95
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
102                                          * right. */
103   GtkTextSegSplitFunc splitFunc;        /* Procedure to split large segment
104                                          * into two smaller ones. */
105   GtkTextSegDeleteFunc deleteFunc;      /* Procedure to call to delete
106                                          * segment. */
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
112                                         * segments). */
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. */
121
122   GtkTextSegCheckFunc checkFunc;       /* Called during consistency checks
123                                         * to check internal consistency of
124                                         * segment. */
125 };
126
127 /*
128  * The data structure below defines line segments.
129  */
130
131 struct _GtkTextLineSegment {
132   const GtkTextLineSegmentClass *type;  /* Pointer to record describing
133                                          * segment's type. */
134   GtkTextLineSegment *next;             /* Next in list of segments for this
135                                          * line, or NULL for end of list. */
136
137   int char_count;                       /* # of chars of index space occupied */
138
139   int byte_count;                       /* Size of this segment (# of bytes
140                                          * of index space it occupies). */
141   union {
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 */
149   } body;
150 };
151
152
153 GtkTextLineSegment  *gtk_text_line_segment_split (const GtkTextIter *iter);
154
155 GtkTextLineSegment *_gtk_char_segment_new                  (const gchar    *text,
156                                                             guint           len);
157 GtkTextLineSegment *_gtk_char_segment_new_from_two_strings (const gchar    *text1,
158                                                             guint           len1,
159                                                             guint           chars1,
160                                                             const gchar    *text2,
161                                                             guint           len2,
162                                                             guint           chars2);
163 GtkTextLineSegment *_gtk_toggle_segment_new                (GtkTextTagInfo *info,
164                                                             gboolean        on);
165
166
167 G_END_DECLS
168
169 #endif
170
171