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, write to the 16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Boston, MA 02111-1307, USA. 18 */ 19 20 /* 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/. 25 */ 26 27 #ifndef __GTK_TEXT_SEGMENT_H__ 28 #define __GTK_TEXT_SEGMENT_H__ 29 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> 35 36 G_BEGIN_DECLS 37 38 /* 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. 43 */ 44 45 /* This header has the segment type, and two specific segments 46 (character and toggle segments) */ 47 48 /* Information a BTree stores about a tag. */ 49 typedef struct _GtkTextTagInfo GtkTextTagInfo; 50 struct _GtkTextTagInfo { 51 GtkTextTag *tag; 52 GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */ 53 gint toggle_count; /* total toggles of this tag below tag_root */ 54 }; 55 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. */ 62 }; 63 64 65 /* Class struct for segments */ 66 67 /* Split seg at index, returning list of two new segments, and freeing seg */ 68 typedef GtkTextLineSegment* (*GtkTextSegSplitFunc) (GtkTextLineSegment *seg, 69 gint index); 70 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. 74 */ 75 typedef gboolean (*GtkTextSegDeleteFunc) (GtkTextLineSegment *seg, 76 GtkTextLine *line, 77 gboolean tree_gone); 78 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 82 * the current line. 83 */ 84 typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc) (GtkTextLineSegment *seg, 85 GtkTextLine *line); 86 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...) 90 */ 91 typedef void (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg, 92 GtkTextLine *line); 93 94 /* Called to do debug checks on the segment. */ 95 typedef void (*GtkTextSegCheckFunc) (GtkTextLineSegment *seg, 96 GtkTextLine *line); 97 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 104 * right. */ 105 GtkTextSegSplitFunc splitFunc; /* Procedure to split large segment 106 * into two smaller ones. */ 107 GtkTextSegDeleteFunc deleteFunc; /* Procedure to call to delete 108 * segment. */ 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 114 * segments). */ 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. */ 123 124 GtkTextSegCheckFunc checkFunc; /* Called during consistency checks 125 * to check internal consistency of 126 * segment. */ 127 }; 128 129 /* 130 * The data structure below defines line segments. 131 */ 132 133 struct _GtkTextLineSegment { 134 const GtkTextLineSegmentClass *type; /* Pointer to record describing 135 * segment's type. */ 136 GtkTextLineSegment *next; /* Next in list of segments for this 137 * line, or NULL for end of list. */ 138 139 int char_count; /* # of chars of index space occupied */ 140 141 int byte_count; /* Size of this segment (# of bytes 142 * of index space it occupies). */ 143 union { 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 */ 151 } body; 152 }; 153 154 155 GtkTextLineSegment *gtk_text_line_segment_split (const GtkTextIter *iter); 156 157 GtkTextLineSegment *_gtk_char_segment_new (const gchar *text, 158 guint len); 159 GtkTextLineSegment *_gtk_char_segment_new_from_two_strings (const gchar *text1, 160 guint len1, 161 guint chars1, 162 const gchar *text2, 163 guint len2, 164 guint chars2); 165 GtkTextLineSegment *_gtk_toggle_segment_new (GtkTextTagInfo *info, 166 gboolean on); 167 168 169 G_END_DECLS 170 171 #endif 172 173 174