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