gtktextsegment.h 7.57 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
2 3 4 5 6 7 8 9 10 11 12 13 14
 * gtktextsegment.h Copyright (C) 2000 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24
 */

/*
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
 */

25 26
#ifndef __GTK_TEXT_SEGMENT_H__
#define __GTK_TEXT_SEGMENT_H__
27

28 29 30 31
#include <gtk/gtktexttag.h>
#include <gtk/gtktextiter.h>
#include <gtk/gtktextmarkprivate.h>
#include <gtk/gtktextchild.h>
32
#include <gtk/gtktextchildprivate.h>
33

34
G_BEGIN_DECLS
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

/*
 * Segments: each line is divided into one or more segments, where each
 * segment is one of several things, such as a group of characters, a
 * tag toggle, a mark, or an embedded widget.  Each segment starts with
 * a standard header followed by a body that varies from type to type.
 */

/* This header has the segment type, and two specific segments
   (character and toggle segments) */

/* Information a BTree stores about a tag. */
typedef struct _GtkTextTagInfo GtkTextTagInfo;
struct _GtkTextTagInfo {
  GtkTextTag *tag;
  GtkTextBTreeNode *tag_root; /* highest-level node containing the tag */
  gint toggle_count;      /* total toggles of this tag below tag_root */
};

/* Body of a segment that toggles a tag on or off */
struct _GtkTextToggleBody {
  GtkTextTagInfo *info;             /* Tag that starts or ends here. */
  gboolean inNodeCounts;             /* TRUE means this toggle has been
                                      * accounted for in node toggle
                                      * counts; FALSE means it hasn't, yet. */
};


/* Class struct for segments */

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/* Split seg at index, returning list of two new segments, and freeing seg */
typedef GtkTextLineSegment* (*GtkTextSegSplitFunc)      (GtkTextLineSegment *seg,
                                                         gint                index);

/* Delete seg which is contained in line; if tree_gone, the tree is being
 * freed in its entirety, which may matter for some reason (?)
 * Return TRUE if the segment is not deleteable, e.g. a mark.
 */
typedef gboolean            (*GtkTextSegDeleteFunc)     (GtkTextLineSegment *seg,
                                                         GtkTextLine        *line,
                                                         gboolean            tree_gone);

/* Called after segment structure of line changes, so segments can
 * cleanup (e.g. merge with adjacent segments). Returns a segment list
 * to replace the original segment list with. The line argument is
 * the current line.
 */
typedef GtkTextLineSegment* (*GtkTextSegCleanupFunc)    (GtkTextLineSegment *seg,
                                                         GtkTextLine        *line);

/* Called when a segment moves from one line to another. CleanupFunc is also
 * 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 90 91 92 93 94
 */
typedef void                (*GtkTextSegLineChangeFunc) (GtkTextLineSegment *seg,
                                                         GtkTextLine        *line);

/* Called to do debug checks on the segment. */
typedef void                (*GtkTextSegCheckFunc)      (GtkTextLineSegment *seg,
                                                         GtkTextLine        *line);
95 96 97 98 99 100 101 102

struct _GtkTextLineSegmentClass {
  char *name;                           /* Name of this kind of segment. */
  gboolean leftGravity;                 /* If a segment has zero size (e.g. a
                                         * mark or tag toggle), does it
                                         * attach to character to its left
                                         * or right?  1 means left, 0 means
                                         * 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 109 110 111 112
                                        * procedure is invoked for all
                                        * segments left in the line to
                                        * perform any cleanup they wish
                                        * (e.g. joining neighboring
                                        * segments). */
113
  GtkTextSegLineChangeFunc lineChangeFunc;
114 115 116 117 118 119 120
  /* Invoked when a segment is about
   * to be moved from its current line
   * to an earlier line because of
   * a deletion.  The line is that
   * for the segment's old line.
   * CleanupFunc will be invoked after
   * the deletion is finished. */
121

122
  GtkTextSegCheckFunc checkFunc;       /* Called during consistency checks
123 124
                                        * to check internal consistency of
                                        * segment. */
125 126 127 128 129 130 131
};

/*
 * The data structure below defines line segments.
 */

struct _GtkTextLineSegment {
Matthias Clasen's avatar
Matthias Clasen committed
132 133 134 135
  const GtkTextLineSegmentClass *type;  /* Pointer to record describing
                                         * segment's type. */
  GtkTextLineSegment *next;             /* Next in list of segments for this
                                         * line, or NULL for end of list. */
136 137

  int char_count;                       /* # of chars of index space occupied */
138

139 140 141 142 143 144 145 146
  int byte_count;                       /* Size of this segment (# of bytes
                                         * of index space it occupies). */
  union {
    char chars[4];                      /* Characters that make up character
                                         * info.  Actual length varies to
                                         * hold as many characters as needed.*/
    GtkTextToggleBody toggle;              /* Information about tag toggle. */
    GtkTextMarkBody mark;              /* Information about mark. */
Havoc Pennington's avatar
Havoc Pennington committed
147
    GtkTextPixbuf pixbuf;              /* Child pixbuf */
148
    GtkTextChildBody child;            /* Child widget */
149 150 151 152
  } body;
};


153
GDK_AVAILABLE_IN_ALL
154
GtkTextLineSegment  *gtk_text_line_segment_split (const GtkTextIter *iter);
155

Havoc Pennington's avatar
Havoc Pennington committed
156 157 158 159
GtkTextLineSegment *_gtk_char_segment_new                  (const gchar    *text,
                                                            guint           len);
GtkTextLineSegment *_gtk_char_segment_new_from_two_strings (const gchar    *text1,
                                                            guint           len1,
160
							    guint           chars1,
Havoc Pennington's avatar
Havoc Pennington committed
161
                                                            const gchar    *text2,
162 163
                                                            guint           len2,
							    guint           chars2);
Havoc Pennington's avatar
Havoc Pennington committed
164 165
GtkTextLineSegment *_gtk_toggle_segment_new                (GtkTextTagInfo *info,
                                                            gboolean        on);
166

167
void                _gtk_toggle_segment_free               (GtkTextLineSegment *seg);
168

169
G_END_DECLS
170 171 172 173

#endif