]> Pileus Git - ~andy/gtk/blob - gtk/gtktextview.h
5fe62bac9afecd1e1f20031cbfc029f3190ef532
[~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 #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
28 #error "Only <gtk/gtk.h> can be included directly."
29 #endif
30
31 #ifndef __GTK_TEXT_VIEW_H__
32 #define __GTK_TEXT_VIEW_H__
33
34 #include <gtk/gtkcontainer.h>
35 #include <gtk/gtkimcontext.h>
36 #include <gtk/gtktextbuffer.h>
37 #include <gtk/gtkmenu.h>
38
39 G_BEGIN_DECLS
40
41 #define GTK_TYPE_TEXT_VIEW             (gtk_text_view_get_type ())
42 #define GTK_TEXT_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_VIEW, GtkTextView))
43 #define GTK_TEXT_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
44 #define GTK_IS_TEXT_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_VIEW))
45 #define GTK_IS_TEXT_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_VIEW))
46 #define GTK_TEXT_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
47
48 typedef enum
49 {
50   GTK_TEXT_WINDOW_PRIVATE,
51   GTK_TEXT_WINDOW_WIDGET,
52   GTK_TEXT_WINDOW_TEXT,
53   GTK_TEXT_WINDOW_LEFT,
54   GTK_TEXT_WINDOW_RIGHT,
55   GTK_TEXT_WINDOW_TOP,
56   GTK_TEXT_WINDOW_BOTTOM
57 } GtkTextWindowType;
58
59 #define GTK_TEXT_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
60
61 typedef struct _GtkTextView GtkTextView;
62 typedef struct _GtkTextViewClass GtkTextViewClass;
63
64 /* Internal private types. */
65 typedef struct _GtkTextWindow GtkTextWindow;
66 typedef struct _GtkTextPendingScroll GtkTextPendingScroll;
67
68 struct _GtkTextView
69 {
70   GtkContainer parent_instance;
71
72   struct _GtkTextLayout *GSEAL (layout);
73   GtkTextBuffer *GSEAL (buffer);
74
75   guint GSEAL (selection_drag_handler);
76   guint GSEAL (scroll_timeout);
77
78   /* Default style settings */
79   gint GSEAL (pixels_above_lines);
80   gint GSEAL (pixels_below_lines);
81   gint GSEAL (pixels_inside_wrap);
82   GtkWrapMode GSEAL (wrap_mode);
83   GtkJustification GSEAL (justify);
84   gint GSEAL (left_margin);
85   gint GSEAL (right_margin);
86   gint GSEAL (indent);
87   PangoTabArray *GSEAL (tabs);
88   guint GSEAL (editable) : 1;
89
90   guint GSEAL (overwrite_mode) : 1;
91   guint GSEAL (cursor_visible) : 1;
92
93   /* if we have reset the IM since the last character entered */  
94   guint GSEAL (need_im_reset) : 1;
95
96   guint GSEAL (accepts_tab) : 1;
97
98   guint GSEAL (width_changed) : 1;
99
100   /* debug flag - means that we've validated onscreen since the
101    * last "invalidate" signal from the layout
102    */
103   guint GSEAL (onscreen_validated) : 1;
104
105   guint GSEAL (mouse_cursor_obscured) : 1;
106
107   GtkTextWindow *GSEAL (text_window);
108   GtkTextWindow *GSEAL (left_window);
109   GtkTextWindow *GSEAL (right_window);
110   GtkTextWindow *GSEAL (top_window);
111   GtkTextWindow *GSEAL (bottom_window);
112
113   GtkAdjustment *GSEAL (hadjustment);
114   GtkAdjustment *GSEAL (vadjustment);
115
116   gint GSEAL (xoffset);         /* Offsets between widget coordinates and buffer coordinates */
117   gint GSEAL (yoffset);
118   gint GSEAL (width);           /* Width and height of the buffer */
119   gint GSEAL (height);
120
121   /* The virtual cursor position is normally the same as the
122    * actual (strong) cursor position, except in two circumstances:
123    *
124    * a) When the cursor is moved vertically with the keyboard
125    * b) When the text view is scrolled with the keyboard
126    *
127    * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
128    * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
129    */
130   gint GSEAL (virtual_cursor_x);   /* -1 means use actual cursor position */
131   gint GSEAL (virtual_cursor_y);   /* -1 means use actual cursor position */
132
133   GtkTextMark *GSEAL (first_para_mark); /* Mark at the beginning of the first onscreen paragraph */
134   gint GSEAL (first_para_pixels);       /* Offset of top of screen in the first onscreen paragraph */
135
136   GtkTextMark *GSEAL (dnd_mark);
137   guint GSEAL (blink_timeout);
138
139   guint GSEAL (first_validate_idle);        /* Idle to revalidate onscreen portion, runs before resize */
140   guint GSEAL (incremental_validate_idle);  /* Idle to revalidate offscreen portions, runs after redraw */
141
142   GtkIMContext *GSEAL (im_context);
143   GtkWidget *GSEAL (popup_menu);
144
145   gint GSEAL (drag_start_x);
146   gint GSEAL (drag_start_y);
147
148   GSList *GSEAL (children);
149
150   GtkTextPendingScroll *GSEAL (pending_scroll);
151
152   gint GSEAL (pending_place_cursor_button);
153 };
154
155 struct _GtkTextViewClass
156 {
157   GtkContainerClass parent_class;
158
159   void (* set_scroll_adjustments)   (GtkTextView    *text_view,
160                                      GtkAdjustment  *hadjustment,
161                                      GtkAdjustment  *vadjustment);
162
163   void (* populate_popup)           (GtkTextView    *text_view,
164                                      GtkMenu        *menu);
165
166   /* These are all RUN_ACTION signals for keybindings */
167
168   /* move insertion point */
169   void (* move_cursor) (GtkTextView    *text_view,
170                         GtkMovementStep step,
171                         gint            count,
172                         gboolean        extend_selection);
173
174   /* FIXME should be deprecated in favor of adding GTK_MOVEMENT_HORIZONTAL_PAGES
175    * or something in GTK 2.2, was put in to avoid adding enum values during
176    * the freeze.
177    */
178   void (* page_horizontally) (GtkTextView *text_view,
179                               gint         count,
180                               gboolean     extend_selection);
181
182   /* move the "anchor" (what Emacs calls the mark) to the cursor position */
183   void (* set_anchor)  (GtkTextView    *text_view);
184
185   /* Edits */
186   void (* insert_at_cursor)      (GtkTextView *text_view,
187                                   const gchar *str);
188   void (* delete_from_cursor)    (GtkTextView  *text_view,
189                                   GtkDeleteType type,
190                                   gint          count);
191   void (* backspace)             (GtkTextView *text_view);
192
193   /* cut copy paste */
194   void (* cut_clipboard)   (GtkTextView *text_view);
195   void (* copy_clipboard)  (GtkTextView *text_view);
196   void (* paste_clipboard) (GtkTextView *text_view);
197   /* overwrite */
198   void (* toggle_overwrite) (GtkTextView *text_view);
199
200   /* as of GTK+ 2.12 the "move-focus" signal has been moved to GtkWidget,
201    * so this is merley a virtual function now. Overriding it in subclasses
202    * continues to work though.
203    */
204   void (* move_focus)       (GtkTextView     *text_view,
205                              GtkDirectionType direction);
206
207   /* Padding for future expansion */
208   void (*_gtk_reserved1) (void);
209   void (*_gtk_reserved2) (void);
210   void (*_gtk_reserved3) (void);
211   void (*_gtk_reserved4) (void);
212   void (*_gtk_reserved5) (void);
213   void (*_gtk_reserved6) (void);
214   void (*_gtk_reserved7) (void);
215 };
216
217 GType          gtk_text_view_get_type              (void) G_GNUC_CONST;
218 GtkWidget *    gtk_text_view_new                   (void);
219 GtkWidget *    gtk_text_view_new_with_buffer       (GtkTextBuffer *buffer);
220 void           gtk_text_view_set_buffer            (GtkTextView   *text_view,
221                                                     GtkTextBuffer *buffer);
222 GtkTextBuffer *gtk_text_view_get_buffer            (GtkTextView   *text_view);
223 gboolean       gtk_text_view_scroll_to_iter        (GtkTextView   *text_view,
224                                                     GtkTextIter   *iter,
225                                                     gdouble        within_margin,
226                                                     gboolean       use_align,
227                                                     gdouble        xalign,
228                                                     gdouble        yalign);
229 void           gtk_text_view_scroll_to_mark        (GtkTextView   *text_view,
230                                                     GtkTextMark   *mark,
231                                                     gdouble        within_margin,
232                                                     gboolean       use_align,
233                                                     gdouble        xalign,
234                                                     gdouble        yalign);
235 void           gtk_text_view_scroll_mark_onscreen  (GtkTextView   *text_view,
236                                                     GtkTextMark   *mark);
237 gboolean       gtk_text_view_move_mark_onscreen    (GtkTextView   *text_view,
238                                                     GtkTextMark   *mark);
239 gboolean       gtk_text_view_place_cursor_onscreen (GtkTextView   *text_view);
240
241 void           gtk_text_view_get_visible_rect      (GtkTextView   *text_view,
242                                                     GdkRectangle  *visible_rect);
243 void           gtk_text_view_set_cursor_visible    (GtkTextView   *text_view,
244                                                     gboolean       setting);
245 gboolean       gtk_text_view_get_cursor_visible    (GtkTextView   *text_view);
246
247 void           gtk_text_view_get_iter_location     (GtkTextView   *text_view,
248                                                     const GtkTextIter *iter,
249                                                     GdkRectangle  *location);
250 void           gtk_text_view_get_iter_at_location  (GtkTextView   *text_view,
251                                                     GtkTextIter   *iter,
252                                                     gint           x,
253                                                     gint           y);
254 void           gtk_text_view_get_iter_at_position  (GtkTextView   *text_view,
255                                                     GtkTextIter   *iter,
256                                                     gint          *trailing,
257                                                     gint           x,
258                                                     gint           y);
259 void           gtk_text_view_get_line_yrange       (GtkTextView       *text_view,
260                                                     const GtkTextIter *iter,
261                                                     gint              *y,
262                                                     gint              *height);
263
264 void           gtk_text_view_get_line_at_y         (GtkTextView       *text_view,
265                                                     GtkTextIter       *target_iter,
266                                                     gint               y,
267                                                     gint              *line_top);
268
269 void gtk_text_view_buffer_to_window_coords (GtkTextView       *text_view,
270                                             GtkTextWindowType  win,
271                                             gint               buffer_x,
272                                             gint               buffer_y,
273                                             gint              *window_x,
274                                             gint              *window_y);
275 void gtk_text_view_window_to_buffer_coords (GtkTextView       *text_view,
276                                             GtkTextWindowType  win,
277                                             gint               window_x,
278                                             gint               window_y,
279                                             gint              *buffer_x,
280                                             gint              *buffer_y);
281
282 GtkAdjustment* gtk_text_view_get_hadjustment (GtkTextView *text_view);
283 GtkAdjustment* gtk_text_view_get_vadjustment (GtkTextView *text_view);
284
285 GdkWindow*        gtk_text_view_get_window      (GtkTextView       *text_view,
286                                                  GtkTextWindowType  win);
287 GtkTextWindowType gtk_text_view_get_window_type (GtkTextView       *text_view,
288                                                  GdkWindow         *window);
289
290 void gtk_text_view_set_border_window_size (GtkTextView       *text_view,
291                                            GtkTextWindowType  type,
292                                            gint               size);
293 gint gtk_text_view_get_border_window_size (GtkTextView       *text_view,
294                                            GtkTextWindowType  type);
295
296 gboolean gtk_text_view_forward_display_line           (GtkTextView       *text_view,
297                                                        GtkTextIter       *iter);
298 gboolean gtk_text_view_backward_display_line          (GtkTextView       *text_view,
299                                                        GtkTextIter       *iter);
300 gboolean gtk_text_view_forward_display_line_end       (GtkTextView       *text_view,
301                                                        GtkTextIter       *iter);
302 gboolean gtk_text_view_backward_display_line_start    (GtkTextView       *text_view,
303                                                        GtkTextIter       *iter);
304 gboolean gtk_text_view_starts_display_line            (GtkTextView       *text_view,
305                                                        const GtkTextIter *iter);
306 gboolean gtk_text_view_move_visually                  (GtkTextView       *text_view,
307                                                        GtkTextIter       *iter,
308                                                        gint               count);
309
310 /* Adding child widgets */
311 void gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
312                                         GtkWidget            *child,
313                                         GtkTextChildAnchor   *anchor);
314
315 void gtk_text_view_add_child_in_window (GtkTextView          *text_view,
316                                         GtkWidget            *child,
317                                         GtkTextWindowType     which_window,
318                                         /* window coordinates */
319                                         gint                  xpos,
320                                         gint                  ypos);
321
322 void gtk_text_view_move_child          (GtkTextView          *text_view,
323                                         GtkWidget            *child,
324                                         /* window coordinates */
325                                         gint                  xpos,
326                                         gint                  ypos);
327
328 /* Default style settings (fallbacks if no tag affects the property) */
329
330 void             gtk_text_view_set_wrap_mode          (GtkTextView      *text_view,
331                                                        GtkWrapMode       wrap_mode);
332 GtkWrapMode      gtk_text_view_get_wrap_mode          (GtkTextView      *text_view);
333 void             gtk_text_view_set_editable           (GtkTextView      *text_view,
334                                                        gboolean          setting);
335 gboolean         gtk_text_view_get_editable           (GtkTextView      *text_view);
336 void             gtk_text_view_set_overwrite          (GtkTextView      *text_view,
337                                                        gboolean          overwrite);
338 gboolean         gtk_text_view_get_overwrite          (GtkTextView      *text_view);
339 void             gtk_text_view_set_accepts_tab        (GtkTextView      *text_view,
340                                                        gboolean          accepts_tab);
341 gboolean         gtk_text_view_get_accepts_tab        (GtkTextView      *text_view);
342 void             gtk_text_view_set_pixels_above_lines (GtkTextView      *text_view,
343                                                        gint              pixels_above_lines);
344 gint             gtk_text_view_get_pixels_above_lines (GtkTextView      *text_view);
345 void             gtk_text_view_set_pixels_below_lines (GtkTextView      *text_view,
346                                                        gint              pixels_below_lines);
347 gint             gtk_text_view_get_pixels_below_lines (GtkTextView      *text_view);
348 void             gtk_text_view_set_pixels_inside_wrap (GtkTextView      *text_view,
349                                                        gint              pixels_inside_wrap);
350 gint             gtk_text_view_get_pixels_inside_wrap (GtkTextView      *text_view);
351 void             gtk_text_view_set_justification      (GtkTextView      *text_view,
352                                                        GtkJustification  justification);
353 GtkJustification gtk_text_view_get_justification      (GtkTextView      *text_view);
354 void             gtk_text_view_set_left_margin        (GtkTextView      *text_view,
355                                                        gint              left_margin);
356 gint             gtk_text_view_get_left_margin        (GtkTextView      *text_view);
357 void             gtk_text_view_set_right_margin       (GtkTextView      *text_view,
358                                                        gint              right_margin);
359 gint             gtk_text_view_get_right_margin       (GtkTextView      *text_view);
360 void             gtk_text_view_set_indent             (GtkTextView      *text_view,
361                                                        gint              indent);
362 gint             gtk_text_view_get_indent             (GtkTextView      *text_view);
363 void             gtk_text_view_set_tabs               (GtkTextView      *text_view,
364                                                        PangoTabArray    *tabs);
365 PangoTabArray*   gtk_text_view_get_tabs               (GtkTextView      *text_view);
366
367 /* note that the return value of this changes with the theme */
368 GtkTextAttributes* gtk_text_view_get_default_attributes (GtkTextView    *text_view);
369
370 G_END_DECLS
371
372 #endif /* __GTK_TEXT_VIEW_H__ */