]> Pileus Git - ~andy/gtk/blob - gtk/gtktext.h
Destroy widgets _after_ propagating unrealize signals through the widget
[~andy/gtk] / gtk / gtktext.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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 #ifndef __GTK_TEXT_H__
20 #define __GTK_TEXT_H__
21
22
23 #include <gdk/gdk.h>
24 #include <gtk/gtkadjustment.h>
25 #include <gtk/gtkeditable.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30
31
32 #define GTK_TYPE_TEXT                  (gtk_text_get_type ())
33 #define GTK_TEXT(obj)                  (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT, GtkText))
34 #define GTK_TEXT_CLASS(klass)          (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT, GtkTextClass))
35 #define GTK_IS_TEXT(obj)               (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT))
36 #define GTK_IS_TEXT_CLASS(klass)       (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT))
37
38 typedef struct _GtkTextFont       GtkTextFont;
39 typedef struct _GtkPropertyMark   GtkPropertyMark;
40 typedef struct _GtkText           GtkText;
41 typedef struct _GtkTextClass      GtkTextClass;
42
43 struct _GtkPropertyMark
44 {
45   /* Position in list. */
46   GList* property;
47
48   /* Offset into that property. */
49   guint offset;
50
51   /* Current index. */
52   guint index;
53 };
54
55 struct _GtkText
56 {
57   GtkEditable editable;
58
59   GdkWindow *text_area;
60
61   GtkAdjustment *hadj;
62   GtkAdjustment *vadj;
63
64   GdkGC *gc;
65
66   GdkPixmap* line_wrap_bitmap;
67   GdkPixmap* line_arrow_bitmap;
68
69                       /* GAPPED TEXT SEGMENT */
70
71   /* The text, a single segment of text a'la emacs, with a gap
72    * where insertion occurs. */
73   union { GdkWChar *wc; guchar  *ch; } text;
74   /* The allocated length of the text segment. */
75   guint text_len;
76   /* The gap position, index into address where a char
77    * should be inserted. */
78   guint gap_position;
79   /* The gap size, s.t. *(text + gap_position + gap_size) is
80    * the first valid character following the gap. */
81   guint gap_size;
82   /* The last character position, index into address where a
83    * character should be appeneded.  Thus, text_end - gap_size
84    * is the length of the actual data. */
85   guint text_end;
86                         /* LINE START CACHE */
87
88   /* A cache of line-start information.  Data is a LineParam*. */
89   GList *line_start_cache;
90   /* Index to the start of the first visible line. */
91   guint first_line_start_index;
92   /* The number of pixels cut off of the top line. */
93   guint first_cut_pixels;
94   /* First visible horizontal pixel. */
95   guint first_onscreen_hor_pixel;
96   /* First visible vertical pixel. */
97   guint first_onscreen_ver_pixel;
98
99                              /* FLAGS */
100
101   /* True iff this buffer is wrapping lines, otherwise it is using a
102    * horizontal scrollbar. */
103   guint line_wrap : 1;
104   guint word_wrap : 1;
105  /* If a fontset is supplied for the widget, use_wchar become true,
106    * and we use GdkWchar as the encoding of text. */
107   guint use_wchar : 1;
108
109   /* Frozen, don't do updates. @@@ fixme */
110   guint freeze_count;
111                         /* TEXT PROPERTIES */
112
113   /* A doubly-linked-list containing TextProperty objects. */
114   GList *text_properties;
115   /* The end of this list. */
116   GList *text_properties_end;
117   /* The first node before or on the point along with its offset to
118    * the point and the buffer's current point.  This is the only
119    * PropertyMark whose index is guaranteed to remain correct
120    * following a buffer insertion or deletion. */
121   GtkPropertyMark point;
122
123                           /* SCRATCH AREA */
124
125   union { GdkWChar *wc; guchar *ch; } scratch_buffer;
126   guint   scratch_buffer_len;
127
128                            /* SCROLLING */
129
130   gint last_ver_value;
131
132                              /* CURSOR */
133
134   gint            cursor_pos_x;       /* Position of cursor. */
135   gint            cursor_pos_y;       /* Baseline of line cursor is drawn on. */
136   GtkPropertyMark cursor_mark;        /* Where it is in the buffer. */
137   GdkWChar        cursor_char;        /* Character to redraw. */
138   gchar           cursor_char_offset; /* Distance from baseline of the font. */
139   gint            cursor_virtual_x;   /* Where it would be if it could be. */
140   gint            cursor_drawn_level; /* How many people have undrawn. */
141
142                           /* Current Line */
143
144   GList *current_line;
145
146                            /* Tab Stops */
147
148   GList *tab_stops;
149   gint default_tab_width;
150
151   GtkTextFont *current_font;    /* Text font for current style */
152
153   /* Timer used for auto-scrolling off ends */
154   gint timer;
155   
156   guint button;                 /* currently pressed mouse button */
157 };
158
159 struct _GtkTextClass
160 {
161   GtkEditableClass parent_class;
162
163   void  (*set_scroll_adjustments)   (GtkText        *text,
164                                      GtkAdjustment  *hadjustment,
165                                      GtkAdjustment  *vadjustment);
166 };
167
168
169 GtkType    gtk_text_get_type        (void);
170 GtkWidget* gtk_text_new             (GtkAdjustment *hadj,
171                                      GtkAdjustment *vadj);
172 void       gtk_text_set_editable    (GtkText       *text,
173                                      gboolean       editable);
174 void       gtk_text_set_word_wrap   (GtkText       *text,
175                                      gint           word_wrap);
176 void       gtk_text_set_line_wrap   (GtkText       *text,
177                                      gint           line_wrap);
178 void       gtk_text_set_adjustments (GtkText       *text,
179                                      GtkAdjustment *hadj,
180                                      GtkAdjustment *vadj);
181 void       gtk_text_set_point       (GtkText       *text,
182                                      guint          index);
183 guint      gtk_text_get_point       (GtkText       *text);
184 guint      gtk_text_get_length      (GtkText       *text);
185 void       gtk_text_freeze          (GtkText       *text);
186 void       gtk_text_thaw            (GtkText       *text);
187 void       gtk_text_insert          (GtkText       *text,
188                                      GdkFont       *font,
189                                      GdkColor      *fore,
190                                      GdkColor      *back,
191                                      const char    *chars,
192                                      gint           length);
193 gint       gtk_text_backward_delete (GtkText       *text,
194                                      guint          nchars);
195 gint       gtk_text_forward_delete  (GtkText       *text,
196                                      guint          nchars);
197
198 #define GTK_TEXT_INDEX(t, index)        (((t)->use_wchar) \
199         ? ((index) < (t)->gap_position ? (t)->text.wc[index] : \
200                                         (t)->text.wc[(index)+(t)->gap_size]) \
201         : ((index) < (t)->gap_position ? (t)->text.ch[index] : \
202                                         (t)->text.ch[(index)+(t)->gap_size]))
203
204 #ifdef __cplusplus
205 }
206 #endif /* __cplusplus */
207
208
209 #endif /* __GTK_TEXT_H__ */