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