gtktext.h 6.95 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * 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/. 
 */

27 28
#ifdef GTK_ENABLE_BROKEN

Elliot Lee's avatar
Elliot Lee committed
29 30 31 32 33 34
#ifndef __GTK_TEXT_H__
#define __GTK_TEXT_H__


#include <gdk/gdk.h>
#include <gtk/gtkadjustment.h>
Owen Taylor's avatar
Owen Taylor committed
35
#include <gtk/gtkoldeditable.h>
Elliot Lee's avatar
Elliot Lee committed
36

37
G_BEGIN_DECLS
Elliot Lee's avatar
Elliot Lee committed
38

39 40 41 42 43
#define GTK_TYPE_TEXT                  (gtk_text_get_type ())
#define GTK_TEXT(obj)                  (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT, GtkText))
#define GTK_TEXT_CLASS(klass)          (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT, GtkTextClass))
#define GTK_IS_TEXT(obj)               (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT))
#define GTK_IS_TEXT_CLASS(klass)       (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT))
Tim Janik's avatar
Tim Janik committed
44 45
#define GTK_TEXT_GET_CLASS(obj)        (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT, GtkTextClass))

Elliot Lee's avatar
Elliot Lee committed
46

47
typedef struct _GtkTextFont       GtkTextFont;
Elliot Lee's avatar
Elliot Lee committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
typedef struct _GtkPropertyMark   GtkPropertyMark;
typedef struct _GtkText           GtkText;
typedef struct _GtkTextClass      GtkTextClass;

struct _GtkPropertyMark
{
  /* Position in list. */
  GList* property;

  /* Offset into that property. */
  guint offset;

  /* Current index. */
  guint index;
};

struct _GtkText
{
Owen Taylor's avatar
Owen Taylor committed
66
  GtkOldEditable old_editable;
Elliot Lee's avatar
Elliot Lee committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

  GdkWindow *text_area;

  GtkAdjustment *hadj;
  GtkAdjustment *vadj;

  GdkGC *gc;

  GdkPixmap* line_wrap_bitmap;
  GdkPixmap* line_arrow_bitmap;

		      /* GAPPED TEXT SEGMENT */

  /* The text, a single segment of text a'la emacs, with a gap
   * where insertion occurs. */
82
  union { GdkWChar *wc; guchar  *ch; } text;
Elliot Lee's avatar
Elliot Lee committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  /* The allocated length of the text segment. */
  guint text_len;
  /* The gap position, index into address where a char
   * should be inserted. */
  guint gap_position;
  /* The gap size, s.t. *(text + gap_position + gap_size) is
   * the first valid character following the gap. */
  guint gap_size;
  /* The last character position, index into address where a
   * character should be appeneded.  Thus, text_end - gap_size
   * is the length of the actual data. */
  guint text_end;
			/* LINE START CACHE */

  /* A cache of line-start information.  Data is a LineParam*. */
  GList *line_start_cache;
  /* Index to the start of the first visible line. */
  guint first_line_start_index;
  /* The number of pixels cut off of the top line. */
  guint first_cut_pixels;
  /* First visible horizontal pixel. */
  guint first_onscreen_hor_pixel;
  /* First visible vertical pixel. */
106
  guint first_onscreen_ver_pixel;
Elliot Lee's avatar
Elliot Lee committed
107 108 109 110 111 112

			     /* FLAGS */

  /* True iff this buffer is wrapping lines, otherwise it is using a
   * horizontal scrollbar. */
  guint line_wrap : 1;
113
  guint word_wrap : 1;
114 115 116
 /* If a fontset is supplied for the widget, use_wchar become true,
   * and we use GdkWchar as the encoding of text. */
  guint use_wchar : 1;
Elliot Lee's avatar
Elliot Lee committed
117

118 119
  /* Frozen, don't do updates. @@@ fixme */
  guint freeze_count;
Elliot Lee's avatar
Elliot Lee committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133
			/* TEXT PROPERTIES */

  /* A doubly-linked-list containing TextProperty objects. */
  GList *text_properties;
  /* The end of this list. */
  GList *text_properties_end;
  /* The first node before or on the point along with its offset to
   * the point and the buffer's current point.  This is the only
   * PropertyMark whose index is guaranteed to remain correct
   * following a buffer insertion or deletion. */
  GtkPropertyMark point;

			  /* SCRATCH AREA */

134
  union { GdkWChar *wc; guchar *ch; } scratch_buffer;
Elliot Lee's avatar
Elliot Lee committed
135 136 137 138 139 140 141 142 143 144 145
  guint   scratch_buffer_len;

			   /* SCROLLING */

  gint last_ver_value;

			     /* CURSOR */

  gint            cursor_pos_x;       /* Position of cursor. */
  gint            cursor_pos_y;       /* Baseline of line cursor is drawn on. */
  GtkPropertyMark cursor_mark;        /* Where it is in the buffer. */
146
  GdkWChar        cursor_char;        /* Character to redraw. */
Elliot Lee's avatar
Elliot Lee committed
147 148 149 150 151 152 153 154 155 156 157 158 159
  gchar           cursor_char_offset; /* Distance from baseline of the font. */
  gint            cursor_virtual_x;   /* Where it would be if it could be. */
  gint            cursor_drawn_level; /* How many people have undrawn. */

			  /* Current Line */

  GList *current_line;

			   /* Tab Stops */

  GList *tab_stops;
  gint default_tab_width;

160 161
  GtkTextFont *current_font;	/* Text font for current style */

162
  /* Timer used for auto-scrolling off ends */
Owen Taylor's avatar
Owen Taylor committed
163 164 165
  gint timer;
  
  guint button;			/* currently pressed mouse button */
166
  GdkGC *bg_gc;			/* gc for drawing background pixmap */
Elliot Lee's avatar
Elliot Lee committed
167 168 169 170
};

struct _GtkTextClass
{
Owen Taylor's avatar
Owen Taylor committed
171
  GtkOldEditableClass parent_class;
172

173 174 175
  void  (*set_scroll_adjustments)   (GtkText	    *text,
				     GtkAdjustment  *hadjustment,
				     GtkAdjustment  *vadjustment);
Elliot Lee's avatar
Elliot Lee committed
176 177 178
};


Elliot Lee's avatar
Elliot Lee committed
179
GtkType    gtk_text_get_type        (void) G_GNUC_CONST;
Elliot Lee's avatar
Elliot Lee committed
180 181 182
GtkWidget* gtk_text_new             (GtkAdjustment *hadj,
				     GtkAdjustment *vadj);
void       gtk_text_set_editable    (GtkText       *text,
183
				     gboolean       editable);
184
void       gtk_text_set_word_wrap   (GtkText       *text,
185
				     gboolean       word_wrap);
186
void       gtk_text_set_line_wrap   (GtkText       *text,
187
				     gboolean       line_wrap);
Elliot Lee's avatar
Elliot Lee committed
188 189 190 191 192 193 194 195 196
void       gtk_text_set_adjustments (GtkText       *text,
				     GtkAdjustment *hadj,
				     GtkAdjustment *vadj);
void       gtk_text_set_point       (GtkText       *text,
				     guint          index);
guint      gtk_text_get_point       (GtkText       *text);
guint      gtk_text_get_length      (GtkText       *text);
void       gtk_text_freeze          (GtkText       *text);
void       gtk_text_thaw            (GtkText       *text);
197 198 199 200 201 202
void       gtk_text_insert          (GtkText        *text,
				     GdkFont        *font,
				     const GdkColor *fore,
				     const GdkColor *back,
				     const char     *chars,
				     gint            length);
203
gboolean   gtk_text_backward_delete (GtkText       *text,
Elliot Lee's avatar
Elliot Lee committed
204
				     guint          nchars);
205
gboolean   gtk_text_forward_delete  (GtkText       *text,
Elliot Lee's avatar
Elliot Lee committed
206 207
				     guint          nchars);

208 209 210 211 212
#define GTK_TEXT_INDEX(t, index)	(((t)->use_wchar) \
	? ((index) < (t)->gap_position ? (t)->text.wc[index] : \
					(t)->text.wc[(index)+(t)->gap_size]) \
	: ((index) < (t)->gap_position ? (t)->text.ch[index] : \
					(t)->text.ch[(index)+(t)->gap_size]))
Elliot Lee's avatar
Elliot Lee committed
213

214
G_END_DECLS
Elliot Lee's avatar
Elliot Lee committed
215 216

#endif /* __GTK_TEXT_H__ */
217 218

#endif /* GTK_ENABLE_BROKEN */