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