0.8.6claws107
[claws.git] / src / gtk / gtkstext.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
20 /*
21  * Modified by the GTK+ Team and others 1997-1999.  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 /*
28  * Modified by the Sylpheed Team and others 2001-2002.
29  */
30
31 #ifndef __GTK_STEXT_H__
32 #define __GTK_STEXT_H__
33
34 #ifdef HAVE_CONFIG_H
35 #  include "config.h"
36 #endif
37
38 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
39 #  include <wchar.h>
40 #  include <wctype.h>
41 #endif
42
43 #include <gdk/gdk.h>
44 #include <gtk/gtkadjustment.h>
45 #include <gtk/gtkeditable.h>
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif /* __cplusplus */
50
51
52 #define GTK_TYPE_STEXT                  (gtk_stext_get_type ())
53 #define GTK_STEXT(obj)                  (GTK_CHECK_CAST ((obj), GTK_TYPE_STEXT, GtkSText))
54 #define GTK_STEXT_CLASS(klass)          (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_STEXT, GtkSTextClass))
55 #define GTK_IS_STEXT(obj)               (GTK_CHECK_TYPE ((obj), GTK_TYPE_STEXT))
56 #define GTK_IS_STEXT_CLASS(klass)       (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_STEXT))
57
58 typedef struct _GtkSTextFont       GtkSTextFont;
59 typedef struct _GtkSPropertyMark   GtkSPropertyMark;
60 typedef struct _GtkSText           GtkSText;
61 typedef struct _GtkSTextClass      GtkSTextClass;
62
63 typedef enum
64 {
65   GTK_STEXT_CURSOR_LINE,
66   GTK_STEXT_CURSOR_BLOCK
67 } GtkSTextCursorType;
68
69 struct _GtkSPropertyMark
70 {
71   /* Position in list. */
72   GList* property;
73
74   /* Offset into that property. */
75   guint offset;
76
77   /* Current index. */
78   guint index;
79 };
80
81 struct _GtkSText
82 {
83   GtkEditable editable;
84
85   GdkWindow *text_area;
86
87   GtkAdjustment *hadj;
88   GtkAdjustment *vadj;
89
90   GdkGC *gc;
91
92   GdkPixmap* line_wrap_bitmap;
93   GdkPixmap* line_arrow_bitmap;
94
95                       /* GAPPED TEXT SEGMENT */
96
97   /* The text, a single segment of text a'la emacs, with a gap
98    * where insertion occurs. */
99   union { GdkWChar *wc; guchar  *ch; } text;
100   /* The allocated length of the text segment. */
101   guint text_len;
102   /* The gap position, index into address where a char
103    * should be inserted. */
104   guint gap_position;
105   /* The gap size, s.t. *(text + gap_position + gap_size) is
106    * the first valid character following the gap. */
107   guint gap_size;
108   /* The last character position, index into address where a
109    * character should be appeneded.  Thus, text_end - gap_size
110    * is the length of the actual data. */
111   guint text_end;
112                         /* LINE START CACHE */
113
114   /* A cache of line-start information.  Data is a LineParam*. */
115   GList *line_start_cache;
116   /* Index to the start of the first visible line. */
117   guint first_line_start_index;
118   /* The number of pixels cut off of the top line. */
119   guint first_cut_pixels;
120   /* First visible horizontal pixel. */
121   guint first_onscreen_hor_pixel;
122   /* First visible vertical pixel. */
123   guint first_onscreen_ver_pixel;
124
125                              /* FLAGS */
126
127   /* True iff this buffer is wrapping lines, otherwise it is using a
128    * horizontal scrollbar. */
129   guint line_wrap : 1;
130   guint word_wrap : 1;
131  /* If a fontset is supplied for the widget, use_wchar become true,
132    * and we use GdkWchar as the encoding of text. */
133   guint use_wchar : 1;
134
135   /* Frozen, don't do updates. @@@ fixme */
136   guint freeze_count;
137                         /* TEXT PROPERTIES */
138
139   /* A doubly-linked-list containing TextProperty objects. */
140   GList *text_properties;
141   /* The end of this list. */
142   GList *text_properties_end;
143   /* The first node before or on the point along with its offset to
144    * the point and the buffer's current point.  This is the only
145    * PropertyMark whose index is guaranteed to remain correct
146    * following a buffer insertion or deletion. */
147   GtkSPropertyMark point;
148
149                           /* SCRATCH AREA */
150
151   union { GdkWChar *wc; guchar *ch; } scratch_buffer;
152   guint   scratch_buffer_len;
153
154                            /* SCROLLING */
155
156   gint last_ver_value;
157
158                              /* CURSOR */
159
160   gint             cursor_pos_x;       /* Position of cursor. */
161   gint             cursor_pos_y;       /* Baseline of line cursor is drawn on. */
162   GtkSPropertyMark cursor_mark;        /* Where it is in the buffer. */
163   GdkWChar         cursor_char;        /* Character to redraw. */
164   gchar            cursor_char_offset; /* Distance from baseline of the font. */
165   gint             cursor_virtual_x;   /* Where it would be if it could be. */
166   gint             cursor_drawn_level; /* How many people have undrawn. */
167
168                           /* Current Line */
169
170   GList *current_line;
171
172                            /* Tab Stops */
173
174   GList *tab_stops;
175   gint default_tab_width;
176
177   GtkSTextFont *current_font;   /* Text font for current style */
178
179   /* Timer used for auto-scrolling off ends */
180   gint timer;
181   
182   guint button;                 /* currently pressed mouse button */
183   GdkGC *bg_gc;                 /* gc for drawing background pixmap */
184
185   /* SYLPHEED:
186    * properties added for different cursor
187    */
188    gboolean cursor_visible;             /* whether cursor is visible */
189    gboolean cursor_timer_on;            /* blinking enabled */
190    guint cursor_off_ms;                 /* cursor off time */
191    guint cursor_on_ms;                  /* cursor on time */
192    gboolean cursor_state_on;            /* state */
193    guint32 cursor_timer_id;             /* blinking timer */
194    guint32 cursor_idle_time_timer_id;   /* timer id */
195
196    GtkSTextCursorType cursor_type;
197
198    /* SYLPHEED:
199     * properties added for rmargin 
200         */
201    gint         wrap_rmargin;                                   /* right margin */
202
203    /* SYLPHEED:
204     * properties added for persist column position when
205         * using up and down key */
206    gint         persist_column;         
207 };
208
209 struct _GtkSTextClass
210 {
211   GtkEditableClass parent_class;
212
213   void  (*set_scroll_adjustments)   (GtkSText       *text,
214                                      GtkAdjustment  *hadjustment,
215                                      GtkAdjustment  *vadjustment);
216 };
217
218
219 GtkType    gtk_stext_get_type        (void);
220 GtkWidget* gtk_stext_new             (GtkAdjustment *hadj,
221                                       GtkAdjustment *vadj);
222 void       gtk_stext_set_editable    (GtkSText      *text,
223                                       gboolean       editable);
224 void       gtk_stext_set_word_wrap   (GtkSText      *text,
225                                       gint           word_wrap);
226 void       gtk_stext_set_line_wrap   (GtkSText      *text,
227                                       gint           line_wrap);
228 void       gtk_stext_set_adjustments (GtkSText      *text,
229                                       GtkAdjustment *hadj,
230                                       GtkAdjustment *vadj);
231 void       gtk_stext_set_point       (GtkSText      *text,
232                                       guint          index);
233 guint      gtk_stext_get_point       (GtkSText      *text);
234 guint      gtk_stext_get_length      (GtkSText      *text);
235 void       gtk_stext_freeze          (GtkSText      *text);
236 void       gtk_stext_thaw            (GtkSText      *text);
237 void       gtk_stext_insert          (GtkSText      *text,
238                                       GdkFont       *font,
239                                       GdkColor      *fore,
240                                       GdkColor      *back,
241                                       const char    *chars,
242                                       gint           length);
243 gint       gtk_stext_backward_delete (GtkSText      *text,
244                                       guint          nchars);
245 gint       gtk_stext_forward_delete  (GtkSText      *text,
246                                       guint          nchars);
247
248 /* SYLPHEED
249  */
250 void       gtk_stext_set_blink       (GtkSText           *text,
251                                       gboolean            blinking_on);
252 void       gtk_stext_set_cursor_type (GtkSText           *text,
253                                       GtkSTextCursorType  cursor_type);
254 void       gtk_stext_compact_buffer     (GtkSText *text);
255
256 /* these are normally not exported! */
257 void gtk_stext_move_forward_character    (GtkSText          *text);
258 void gtk_stext_move_backward_character   (GtkSText          *text);
259 void gtk_stext_move_forward_word         (GtkSText          *text);
260 void gtk_stext_move_backward_word        (GtkSText          *text);
261 void gtk_stext_move_beginning_of_line    (GtkSText          *text);
262 void gtk_stext_move_end_of_line          (GtkSText          *text);
263 void gtk_stext_move_next_line            (GtkSText          *text);
264 void gtk_stext_move_previous_line        (GtkSText          *text);
265 void gtk_stext_delete_forward_character  (GtkSText          *text);
266 void gtk_stext_delete_backward_character (GtkSText          *text);
267 void gtk_stext_delete_forward_word       (GtkSText          *text);
268 void gtk_stext_delete_backward_word      (GtkSText          *text);
269 void gtk_stext_delete_line               (GtkSText          *text);
270 void gtk_stext_delete_to_line_end        (GtkSText          *text);
271
272
273 /* Set the rmargin for the stext. if rmargin is 0, then reset to old 
274  * behaviour */
275 void       gtk_stext_set_wrap_rmargin (GtkSText *text, gint rmargin);
276
277 /* gtk stext functions */
278 gboolean gtk_stext_match_string         (GtkSText       *text,
279                                          gint            pos,
280                                          wchar_t        *wcs,
281                                          gint            len,
282                                          gboolean        case_sens);
283 guint gtk_stext_str_compare_n           (GtkSText       *text,
284                                          guint           pos1,
285                                          guint           pos2,
286                                          guint           len,
287                                          guint           text_len);
288 guint gtk_stext_str_compare             (GtkSText       *text,
289                                          guint           start_pos,
290                                          guint           text_len,
291                                          const gchar    *str);
292 gboolean gtk_stext_is_uri_string        (GtkSText       *text,
293                                          guint           start_pos,
294                                          guint           text_len);
295 void gtk_stext_clear                    (GtkSText       *text);
296
297
298
299 #define GTK_STEXT_INDEX(t, index)       (((t)->use_wchar) \
300         ? ((index) < (t)->gap_position ? (t)->text.wc[index] : \
301                                         (t)->text.wc[(index)+(t)->gap_size]) \
302         : ((index) < (t)->gap_position ? (t)->text.ch[index] : \
303                                         (t)->text.ch[(index)+(t)->gap_size]))
304
305 #ifdef __cplusplus
306 }
307 #endif /* __cplusplus */
308
309
310 #endif /* __GTK_STEXT_H__ */