]> Pileus Git - ~andy/gtk/blob - gtk/gtktextview.h
Documentation updates. Updates.
[~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)             (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_VIEW, GtkTextView))
41 #define GTK_TEXT_VIEW_CLASS(klass)     (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
42 #define GTK_IS_TEXT_VIEW(obj)          (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_VIEW))
43 #define GTK_IS_TEXT_VIEW_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_VIEW))
44 #define GTK_TEXT_VIEW_GET_CLASS(obj)   (GTK_CHECK_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   guint  need_im_reset : 1;     /* If we have reset the IM since the last character entered */
93   /* just selected a word or line via double/triple click */
94   guint just_selected_element : 1;
95   
96   /* debug flag - means that we've validated onscreen since the
97    * last "invalidate" signal from the layout
98    */
99   guint onscreen_validated : 1;
100   
101   GtkTextWindow *text_window;
102   GtkTextWindow *left_window;
103   GtkTextWindow *right_window;
104   GtkTextWindow *top_window;
105   GtkTextWindow *bottom_window;
106
107   GtkAdjustment *hadjustment;
108   GtkAdjustment *vadjustment;
109
110   gint xoffset;                 /* Offsets between widget coordinates and buffer coordinates */
111   gint yoffset;
112   gint width;                   /* Width and height of the buffer */
113   gint height;
114
115   /* The virtual cursor position is normally the same as the
116    * actual (strong) cursor position, except in two circumstances:
117    *
118    * a) When the cursor is moved vertically with the keyboard
119    * b) When the text view is scrolled with the keyboard
120    *
121    * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
122    * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
123    */
124   gint virtual_cursor_x;           /* -1 means use actual cursor position */
125   gint virtual_cursor_y;           /* -1 means use actual cursor position */
126
127   GtkTextMark *first_para_mark;    /* Mark at the beginning of the first onscreen paragraph */
128   gint first_para_pixels;          /* Offset of top of screen in the first onscreen paragraph */
129
130   GtkTextMark *dnd_mark;
131   guint blink_timeout;
132
133   guint first_validate_idle;            /* Idle to revalidate onscreen portion, runs before resize */
134   guint incremental_validate_idle;      /* Idle to revalidate offscreen portions, runs after redraw */
135
136   GtkIMContext *im_context;
137   GtkWidget *popup_menu;
138
139   gint drag_start_x;
140   gint drag_start_y;
141
142   GSList *children;
143
144   GtkTextPendingScroll *pending_scroll;
145   GdkGC *cursor_gc;
146
147   gint pending_place_cursor_button;
148 };
149
150 struct _GtkTextViewClass
151 {
152   GtkContainerClass parent_class;
153
154   void (* set_scroll_adjustments)   (GtkTextView    *text_view,
155                                      GtkAdjustment  *hadjustment,
156                                      GtkAdjustment  *vadjustment);
157
158   void (* populate_popup)           (GtkTextView    *text_view,
159                                      GtkMenu        *menu);
160   
161   /* These are all RUN_ACTION signals for keybindings */
162
163   /* move insertion point */
164   void (* move_cursor) (GtkTextView    *text_view,
165                         GtkMovementStep step,
166                         gint            count,
167                         gboolean        extend_selection);
168   /* move the "anchor" (what Emacs calls the mark) to the cursor position */
169   void (* set_anchor)  (GtkTextView    *text_view);
170
171   /* Edits */
172   void (* insert_at_cursor)      (GtkTextView *text_view,
173                                   const gchar *str);
174   void (* delete_from_cursor)    (GtkTextView  *text_view,
175                                   GtkDeleteType type,
176                                   gint          count);
177
178   /* cut copy paste */
179   void (* cut_clipboard)   (GtkTextView *text_view);
180   void (* copy_clipboard)  (GtkTextView *text_view);
181   void (* paste_clipboard) (GtkTextView *text_view);
182   /* overwrite */
183   void (* toggle_overwrite) (GtkTextView *text_view);
184 };
185
186 GtkType        gtk_text_view_get_type              (void) G_GNUC_CONST;
187 GtkWidget *    gtk_text_view_new                   (void);
188 GtkWidget *    gtk_text_view_new_with_buffer       (GtkTextBuffer *buffer);
189 void           gtk_text_view_set_buffer            (GtkTextView   *text_view,
190                                                     GtkTextBuffer *buffer);
191 GtkTextBuffer *gtk_text_view_get_buffer            (GtkTextView   *text_view);
192 gboolean       gtk_text_view_scroll_to_iter        (GtkTextView   *text_view,
193                                                     GtkTextIter   *iter,
194                                                     gdouble        within_margin,
195                                                     gboolean       use_align,
196                                                     gdouble        xalign,
197                                                     gdouble        yalign);
198 void           gtk_text_view_scroll_to_mark        (GtkTextView   *text_view,
199                                                     GtkTextMark   *mark,
200                                                     gdouble        within_margin,
201                                                     gboolean       use_align,
202                                                     gdouble        xalign,
203                                                     gdouble        yalign);
204 void           gtk_text_view_scroll_mark_onscreen  (GtkTextView   *text_view,
205                                                     GtkTextMark   *mark);
206 gboolean       gtk_text_view_move_mark_onscreen    (GtkTextView   *text_view,
207                                                     GtkTextMark   *mark);
208 gboolean       gtk_text_view_place_cursor_onscreen (GtkTextView   *text_view);
209
210 void           gtk_text_view_get_visible_rect      (GtkTextView   *text_view,
211                                                     GdkRectangle  *visible_rect);
212 void           gtk_text_view_set_cursor_visible    (GtkTextView   *text_view,
213                                                     gboolean       setting);
214 gboolean       gtk_text_view_get_cursor_visible    (GtkTextView   *text_view);
215
216 void           gtk_text_view_get_iter_location     (GtkTextView   *text_view,
217                                                     const GtkTextIter *iter,
218                                                     GdkRectangle  *location);
219 void           gtk_text_view_get_iter_at_location  (GtkTextView   *text_view,
220                                                     GtkTextIter   *iter,
221                                                     gint           x,
222                                                     gint           y);
223 void           gtk_text_view_get_line_yrange       (GtkTextView       *text_view,
224                                                     const GtkTextIter *iter,
225                                                     gint              *y,
226                                                     gint              *height);
227
228 void           gtk_text_view_get_line_at_y         (GtkTextView       *text_view,
229                                                     GtkTextIter       *target_iter,
230                                                     gint               y,
231                                                     gint              *line_top);
232
233 void gtk_text_view_buffer_to_window_coords (GtkTextView       *text_view,
234                                             GtkTextWindowType  win,
235                                             gint               buffer_x,
236                                             gint               buffer_y,
237                                             gint              *window_x,
238                                             gint              *window_y);
239 void gtk_text_view_window_to_buffer_coords (GtkTextView       *text_view,
240                                             GtkTextWindowType  win,
241                                             gint               window_x,
242                                             gint               window_y,
243                                             gint              *buffer_x,
244                                             gint              *buffer_y);
245
246 GdkWindow*        gtk_text_view_get_window      (GtkTextView       *text_view,
247                                                  GtkTextWindowType  win);
248 GtkTextWindowType gtk_text_view_get_window_type (GtkTextView       *text_view,
249                                                  GdkWindow         *window);
250
251 void gtk_text_view_set_border_window_size (GtkTextView       *text_view,
252                                            GtkTextWindowType  type,
253                                            gint               size);
254 gint gtk_text_view_get_border_window_size (GtkTextView       *text_view,
255                                            GtkTextWindowType  type);
256
257 gboolean gtk_text_view_forward_display_line           (GtkTextView       *text_view,
258                                                        GtkTextIter       *iter);
259 gboolean gtk_text_view_backward_display_line          (GtkTextView       *text_view,
260                                                        GtkTextIter       *iter);
261 gboolean gtk_text_view_forward_display_line_end       (GtkTextView       *text_view,
262                                                        GtkTextIter       *iter);
263 gboolean gtk_text_view_backward_display_line_start    (GtkTextView       *text_view,
264                                                        GtkTextIter       *iter);
265 gboolean gtk_text_view_starts_display_line            (GtkTextView       *text_view,
266                                                        const GtkTextIter *iter);
267 gboolean gtk_text_view_move_visually                  (GtkTextView       *text_view,
268                                                        GtkTextIter       *iter,
269                                                        gint               count);
270
271 /* Adding child widgets */
272 void gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
273                                         GtkWidget            *child,
274                                         GtkTextChildAnchor   *anchor);
275
276 void gtk_text_view_add_child_in_window (GtkTextView          *text_view,
277                                         GtkWidget            *child,
278                                         GtkTextWindowType     which_window,
279                                         /* window coordinates */
280                                         gint                  xpos,
281                                         gint                  ypos);
282
283 void gtk_text_view_move_child          (GtkTextView          *text_view,
284                                         GtkWidget            *child,
285                                         /* window coordinates */
286                                         gint                  xpos,
287                                         gint                  ypos);
288
289 /* Default style settings (fallbacks if no tag affects the property) */
290
291 void             gtk_text_view_set_wrap_mode          (GtkTextView      *text_view,
292                                                        GtkWrapMode       wrap_mode);
293 GtkWrapMode      gtk_text_view_get_wrap_mode          (GtkTextView      *text_view);
294 void             gtk_text_view_set_editable           (GtkTextView      *text_view,
295                                                        gboolean          setting);
296 gboolean         gtk_text_view_get_editable           (GtkTextView      *text_view);
297 void             gtk_text_view_set_pixels_above_lines (GtkTextView      *text_view,
298                                                        gint              pixels_above_lines);
299 gint             gtk_text_view_get_pixels_above_lines (GtkTextView      *text_view);
300 void             gtk_text_view_set_pixels_below_lines (GtkTextView      *text_view,
301                                                        gint              pixels_below_lines);
302 gint             gtk_text_view_get_pixels_below_lines (GtkTextView      *text_view);
303 void             gtk_text_view_set_pixels_inside_wrap (GtkTextView      *text_view,
304                                                        gint              pixels_inside_wrap);
305 gint             gtk_text_view_get_pixels_inside_wrap (GtkTextView      *text_view);
306 void             gtk_text_view_set_justification      (GtkTextView      *text_view,
307                                                        GtkJustification  justification);
308 GtkJustification gtk_text_view_get_justification      (GtkTextView      *text_view);
309 void             gtk_text_view_set_left_margin        (GtkTextView      *text_view,
310                                                        gint              left_margin);
311 gint             gtk_text_view_get_left_margin        (GtkTextView      *text_view);
312 void             gtk_text_view_set_right_margin       (GtkTextView      *text_view,
313                                                        gint              right_margin);
314 gint             gtk_text_view_get_right_margin       (GtkTextView      *text_view);
315 void             gtk_text_view_set_indent             (GtkTextView      *text_view,
316                                                        gint              indent);
317 gint             gtk_text_view_get_indent             (GtkTextView      *text_view);
318 void             gtk_text_view_set_tabs               (GtkTextView      *text_view,
319                                                        PangoTabArray    *tabs);
320 PangoTabArray*   gtk_text_view_get_tabs               (GtkTextView      *text_view);
321
322 /* note that the return value of this changes with the theme */
323 GtkTextAttributes* gtk_text_view_get_default_attributes (GtkTextView    *text_view);
324
325 #ifdef __cplusplus
326 }
327 #endif /* __cplusplus */
328
329 #endif /* GTK_TEXT_VIEW_H */