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