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