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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #ifndef __GTK_TEXT_SEGMENT_H__
28 #define __GTK_TEXT_SEGMENT_H__
30 #include <gtk/gtktexttag.h>
31 #include <gtk/gtktextiter.h>
32 #include <gtk/gtktextmarkprivate.h>
33 #include <gtk/gtktextchild.h>
34 #include <gtk/gtktextchildprivate.h>
39 * Segments: each line is divided into one or more segments, where each
40 * segment is one of several things, such as a group of characters, a
41 * tag toggle, a mark, or an embedded widget. Each segment starts with
42 * a standard header followed by a body that varies from type to type.
45 /* This header has the segment type, and two specific segments
46 (character and toggle segments) */
48 /* Information a BTree stores about a tag. */
49 typedef struct _GtkTextTagInfo GtkTextTagInfo;
50 struct _GtkTextTagInfo {
52 GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
53 gint toggle_count; /* total toggles of this tag below tag_root */
56 /* Body of a segment that toggles a tag on or off */
57 struct _GtkTextToggleBody {
58 GtkTextTagInfo *info; /* Tag that starts or ends here. */
59 gboolean inNodeCounts; /* TRUE means this toggle has been
60 * accounted for in node toggle
61 * counts; FALSE means it hasn't, yet. */
65 /* Class struct for segments */
67 /* Split seg at index, returning list of two new segments, and freeing seg */
68 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc) (GtkTextLineSegment *seg,
71 /* Delete seg which is contained in line; if tree_gone, the tree is being
72 * freed in its entirety, which may matter for some reason (?)
73 * Return TRUE if the segment is not deleteable, e.g. a mark.
75 typedef gboolean (*GtkTextSegDeleteFunc) (GtkTextLineSegment *seg,
79 /* Called after segment structure of line changes, so segments can
80 * cleanup (e.g. merge with adjacent segments). Returns a segment list
81 * to replace the original segment list with. The line argument is
84 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc) (GtkTextLineSegment *seg,
87 /* Called when a segment moves from one line to another. CleanupFunc is also
88 * called in that case, so many segments just use CleanupFunc, I'm not sure
89 * what's up with that (this function may not be needed...)
91 typedef void (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
94 /* Called to do debug checks on the segment. */
95 typedef void (*GtkTextSegCheckFunc) (GtkTextLineSegment *seg,
98 struct _GtkTextLineSegmentClass {
99 char *name; /* Name of this kind of segment. */
100 gboolean leftGravity; /* If a segment has zero size (e.g. a
101 * mark or tag toggle), does it
102 * attach to character to its left
103 * or right? 1 means left, 0 means
105 GtkTextSegSplitFunc splitFunc; /* Procedure to split large segment
106 * into two smaller ones. */
107 GtkTextSegDeleteFunc deleteFunc; /* Procedure to call to delete
109 GtkTextSegCleanupFunc cleanupFunc; /* After any change to a line, this
110 * procedure is invoked for all
111 * segments left in the line to
112 * perform any cleanup they wish
113 * (e.g. joining neighboring
115 GtkTextSegLineChangeFunc lineChangeFunc;
116 /* Invoked when a segment is about
117 * to be moved from its current line
118 * to an earlier line because of
119 * a deletion. The line is that
120 * for the segment's old line.
121 * CleanupFunc will be invoked after
122 * the deletion is finished. */
124 GtkTextSegCheckFunc checkFunc; /* Called during consistency checks
125 * to check internal consistency of
130 * The data structure below defines line segments.
133 struct _GtkTextLineSegment {
134 const GtkTextLineSegmentClass *type; /* Pointer to record describing
136 GtkTextLineSegment *next; /* Next in list of segments for this
137 * line, or NULL for end of list. */
139 int char_count; /* # of chars of index space occupied */
141 int byte_count; /* Size of this segment (# of bytes
142 * of index space it occupies). */
144 char chars[4]; /* Characters that make up character
145 * info. Actual length varies to
146 * hold as many characters as needed.*/
147 GtkTextToggleBody toggle; /* Information about tag toggle. */
148 GtkTextMarkBody mark; /* Information about mark. */
149 GtkTextPixbuf pixbuf; /* Child pixbuf */
150 GtkTextChildBody child; /* Child widget */
155 GtkTextLineSegment *gtk_text_line_segment_split (const GtkTextIter *iter);
157 GtkTextLineSegment *_gtk_char_segment_new (const gchar *text,
159 GtkTextLineSegment *_gtk_char_segment_new_from_two_strings (const gchar *text1,
165 GtkTextLineSegment *_gtk_toggle_segment_new (GtkTextTagInfo *info,