]> Pileus Git - ~andy/gtk/blob - gtk/gtktextview.h
880cff302eaea872075b10fdec27de4a9afb413b
[~andy/gtk] / gtk / gtktextview.h
1 /* GTK - The GIMP Toolkit
2  * gtktextview.h Copyright (C) 2000 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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-2000.  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_TEXT_VIEW_H
28 #define GTK_TEXT_VIEW_H
29
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkimcontext.h>
32 #include <gtk/gtktextbuffer.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37
38 #define GTK_TYPE_TEXT_VIEW             (gtk_text_view_get_type ())
39 #define GTK_TEXT_VIEW(obj)             (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_VIEW, GtkTextView))
40 #define GTK_TEXT_VIEW_CLASS(klass)     (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
41 #define GTK_IS_TEXT_VIEW(obj)          (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_VIEW))
42 #define GTK_IS_TEXT_VIEW_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_VIEW))
43 #define GTK_TEXT_VIEW_GET_CLASS(obj)   (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
44
45 typedef enum
46 {
47   GTK_TEXT_WINDOW_PRIVATE,
48   GTK_TEXT_WINDOW_WIDGET,
49   GTK_TEXT_WINDOW_TEXT,
50   GTK_TEXT_WINDOW_LEFT,
51   GTK_TEXT_WINDOW_RIGHT,
52   GTK_TEXT_WINDOW_TOP,
53   GTK_TEXT_WINDOW_BOTTOM
54 } GtkTextWindowType;
55
56 typedef struct _GtkTextView GtkTextView;
57 typedef struct _GtkTextViewClass GtkTextViewClass;
58
59 /* Internal private type. */
60 typedef struct _GtkTextWindow GtkTextWindow;
61
62 struct _GtkTextView
63 {
64   GtkContainer parent_instance;
65
66   struct _GtkTextLayout *layout;
67   GtkTextBuffer *buffer;
68
69   guint selection_drag_handler;
70   guint selection_drag_scan_timeout;
71   gint scrolling_accel_factor;
72
73   /* Default style settings */
74   gint pixels_above_lines;
75   gint pixels_below_lines;
76   gint pixels_inside_wrap;
77   GtkWrapMode wrap_mode;  
78   GtkJustification justify;
79   gint left_margin;
80   gint right_margin;
81   gint indent;
82   PangoTabArray *tabs;
83   guint editable : 1;
84
85   
86   
87   guint overwrite_mode : 1;
88   guint cursor_visible : 1;
89   guint  need_im_reset : 1;     /* If we have reset the IM since the last character entered */
90
91   GtkTextWindow *text_window;
92   GtkTextWindow *left_window;
93   GtkTextWindow *right_window;
94   GtkTextWindow *top_window;
95   GtkTextWindow *bottom_window;
96
97   GtkAdjustment *hadjustment;
98   GtkAdjustment *vadjustment;
99
100   gint xoffset;                 /* Offsets between widget coordinates and buffer coordinates */
101   gint yoffset;
102   gint width;                   /* Width and height of the buffer */
103   gint height;
104
105   /* The virtual cursor position is normally the same as the
106    * actual (strong) cursor position, except in two circumstances:
107    *
108    * a) When the cursor is moved vertically with the keyboard
109    * b) When the text view is scrolled with the keyboard
110    *
111    * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
112    * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
113    */
114   gint virtual_cursor_x;           /* -1 means use actual cursor position */
115   gint virtual_cursor_y;           /* -1 means use actual cursor position */
116
117   GtkTextMark *first_para_mark;    /* Mark at the beginning of the first onscreen paragraph */
118   gint first_para_pixels;          /* Offset of top of screen in the first onscreen paragraph */
119
120   GtkTextMark *dnd_mark;
121   guint blink_timeout;
122   guint preblink_timeout;
123
124   guint first_validate_idle;            /* Idle to revalidate onscreen portion, runs before resize */
125   guint incremental_validate_idle;      /* Idle to revalidate offscreen portions, runs after redraw */
126
127   GtkIMContext *im_context;
128   GtkWidget *popup_menu;
129
130   gint drag_start_x;
131   gint drag_start_y;
132
133   GSList *children;
134 };
135
136 struct _GtkTextViewClass
137 {
138   GtkContainerClass parent_class;
139
140   /* These are all RUN_ACTION signals for keybindings */
141
142   /* move insertion point */
143   void (* move_cursor) (GtkTextView    *text_view,
144                         GtkMovementStep step,
145                         gint            count,
146                         gboolean        extend_selection);
147   /* move the "anchor" (what Emacs calls the mark) to the cursor position */
148   void (* set_anchor)  (GtkTextView    *text_view);
149
150   /* Edits */
151   void (* insert_at_cursor)      (GtkTextView *text_view,
152                                   const gchar *str);
153   void (* delete_from_cursor)    (GtkTextView  *text_view,
154                                   GtkDeleteType type,
155                                   gint          count);
156
157   /* cut copy paste */
158   void (* cut_clipboard)   (GtkTextView *text_view);
159   void (* copy_clipboard)  (GtkTextView *text_view);
160   void (* paste_clipboard) (GtkTextView *text_view);
161   /* overwrite */
162   void (* toggle_overwrite) (GtkTextView *text_view);
163   void (* set_scroll_adjustments)   (GtkTextView    *text_view,
164                                      GtkAdjustment  *hadjustment,
165                                      GtkAdjustment  *vadjustment);
166 };
167
168 GtkType        gtk_text_view_get_type              (void) G_GNUC_CONST;
169 GtkWidget *    gtk_text_view_new                   (void);
170 GtkWidget *    gtk_text_view_new_with_buffer       (GtkTextBuffer *buffer);
171 void           gtk_text_view_set_buffer            (GtkTextView   *text_view,
172                                                     GtkTextBuffer *buffer);
173 GtkTextBuffer *gtk_text_view_get_buffer            (GtkTextView   *text_view);
174 gboolean       gtk_text_view_scroll_to_mark        (GtkTextView   *text_view,
175                                                     GtkTextMark   *mark,
176                                                     gint           mark_within_margin);
177 gboolean       gtk_text_view_move_mark_onscreen    (GtkTextView   *text_view,
178                                                     GtkTextMark   *mark);
179 gboolean       gtk_text_view_place_cursor_onscreen (GtkTextView   *text_view);
180
181 void           gtk_text_view_get_visible_rect      (GtkTextView   *text_view,
182                                                     GdkRectangle  *visible_rect);
183 void           gtk_text_view_set_cursor_visible    (GtkTextView   *text_view,
184                                                     gboolean       setting);
185 gboolean       gtk_text_view_get_cursor_visible    (GtkTextView   *text_view);
186
187 void           gtk_text_view_get_iter_location     (GtkTextView   *text_view,
188                                                     const GtkTextIter *iter,
189                                                     GdkRectangle  *location);
190 void           gtk_text_view_get_iter_at_location  (GtkTextView   *text_view,
191                                                     GtkTextIter   *iter,
192                                                     gint           x,
193                                                     gint           y);
194 void           gtk_text_view_get_line_yrange       (GtkTextView       *text_view,
195                                                     const GtkTextIter *iter,
196                                                     gint              *y,
197                                                     gint              *height);
198
199 void           gtk_text_view_get_line_at_y         (GtkTextView       *text_view,
200                                                     GtkTextIter       *target_iter,
201                                                     gint               y,
202                                                     gint              *line_top);
203
204 void gtk_text_view_buffer_to_window_coords (GtkTextView       *text_view,
205                                             GtkTextWindowType  win,
206                                             gint               buffer_x,
207                                             gint               buffer_y,
208                                             gint              *window_x,
209                                             gint              *window_y);
210 void gtk_text_view_window_to_buffer_coords (GtkTextView       *text_view,
211                                             GtkTextWindowType  win,
212                                             gint               window_x,
213                                             gint               window_y,
214                                             gint              *buffer_x,
215                                             gint              *buffer_y);
216
217 GdkWindow*        gtk_text_view_get_window      (GtkTextView       *text_view,
218                                                  GtkTextWindowType  win);
219 GtkTextWindowType gtk_text_view_get_window_type (GtkTextView       *text_view,
220                                                  GdkWindow         *window);
221
222 void gtk_text_view_set_border_window_size (GtkTextView       *text_view,
223                                            GtkTextWindowType  type,
224                                            gint               size);
225 void gtk_text_view_set_text_window_size   (GtkTextView       *text_view,
226                                            gint               width,
227                                            gint               height);
228
229
230 /* Adding child widgets */
231 void gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
232                                         GtkWidget            *child,
233                                         GtkTextChildAnchor   *anchor);
234
235 void gtk_text_view_add_child_in_window (GtkTextView          *text_view,
236                                         GtkWidget            *child,
237                                         GtkTextWindowType     which_window,
238                                         /* window coordinates */
239                                         gint                  xpos,
240                                         gint                  ypos);
241
242 void gtk_text_view_move_child          (GtkTextView          *text_view,
243                                         GtkWidget            *child,
244                                         /* window coordinates */
245                                         gint                  xpos,
246                                         gint                  ypos);
247
248 /* Default style settings (fallbacks if no tag affects the property) */
249
250 void             gtk_text_view_set_wrap_mode          (GtkTextView      *text_view,
251                                                        GtkWrapMode       wrap_mode);
252 GtkWrapMode      gtk_text_view_get_wrap_mode          (GtkTextView      *text_view);
253 void             gtk_text_view_set_editable           (GtkTextView      *text_view,
254                                                        gboolean          setting);
255 gboolean         gtk_text_view_get_editable           (GtkTextView      *text_view);
256 void             gtk_text_view_set_pixels_above_lines (GtkTextView      *text_view,
257                                                        gint              pixels_above_lines);
258 gint             gtk_text_view_get_pixels_above_lines (GtkTextView      *text_view);
259 void             gtk_text_view_set_pixels_below_lines (GtkTextView      *text_view,
260                                                        gint              pixels_below_lines);
261 gint             gtk_text_view_get_pixels_below_lines (GtkTextView      *text_view);
262 void             gtk_text_view_set_pixels_inside_wrap (GtkTextView      *text_view,
263                                                        gint              pixels_inside_wrap);
264 gint             gtk_text_view_get_pixels_inside_wrap (GtkTextView      *text_view);
265 void             gtk_text_view_set_justification      (GtkTextView      *text_view,
266                                                        GtkJustification  justification);
267 GtkJustification gtk_text_view_get_justification      (GtkTextView      *text_view);
268 void             gtk_text_view_set_left_margin        (GtkTextView      *text_view,
269                                                        gint              left_margin);
270 gint             gtk_text_view_get_left_margin        (GtkTextView      *text_view);
271 void             gtk_text_view_set_right_margin       (GtkTextView      *text_view,
272                                                        gint              right_margin);
273 gint             gtk_text_view_get_right_margin       (GtkTextView      *text_view);
274 void             gtk_text_view_set_indent             (GtkTextView      *text_view,
275                                                        gint              indent);
276 gint             gtk_text_view_get_indent             (GtkTextView      *text_view);
277 void             gtk_text_view_set_tabs               (GtkTextView      *text_view,
278                                                        PangoTabArray    *tabs);
279 PangoTabArray*   gtk_text_view_get_tabs               (GtkTextView      *text_view);
280                                        
281
282
283 #ifdef __cplusplus
284 }
285 #endif /* __cplusplus */
286
287 #endif /* GTK_TEXT_VIEW_H */