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