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#if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
31#error "Only <gtk/gtk.h> can be included directly."
32#endif
33
34#include <gtk/gtkcontainer.h>
35#include <gtk/gtkimcontext.h>
36#include <gtk/gtktextbuffer.h>
37#include <gtk/gtkmenu.h>
38
39G_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
48typedef 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
61typedef struct _GtkTextView GtkTextView;
62typedef struct _GtkTextViewClass GtkTextViewClass;
63
64/* Internal private types. */
65typedef struct _GtkTextWindow GtkTextWindow;
66typedef struct _GtkTextPendingScroll GtkTextPendingScroll;
67
68struct _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
155struct _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
217GType gtk_text_view_get_type (void) G_GNUC_CONST;
218GtkWidget * gtk_text_view_new (void);
219GtkWidget * gtk_text_view_new_with_buffer (GtkTextBuffer *buffer);
220void gtk_text_view_set_buffer (GtkTextView *text_view,
221 GtkTextBuffer *buffer);
222GtkTextBuffer *gtk_text_view_get_buffer (GtkTextView *text_view);
223gboolean 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);
229void 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);
235void gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
236 GtkTextMark *mark);
237gboolean gtk_text_view_move_mark_onscreen (GtkTextView *text_view,
238 GtkTextMark *mark);
239gboolean gtk_text_view_place_cursor_onscreen (GtkTextView *text_view);
240
241void gtk_text_view_get_visible_rect (GtkTextView *text_view,
242 GdkRectangle *visible_rect);
243void gtk_text_view_set_cursor_visible (GtkTextView *text_view,
244 gboolean setting);
245gboolean gtk_text_view_get_cursor_visible (GtkTextView *text_view);
246
247void gtk_text_view_get_iter_location (GtkTextView *text_view,
248 const GtkTextIter *iter,
249 GdkRectangle *location);
250void gtk_text_view_get_iter_at_location (GtkTextView *text_view,
251 GtkTextIter *iter,
252 gint x,
253 gint y);
254void gtk_text_view_get_iter_at_position (GtkTextView *text_view,
255 GtkTextIter *iter,
256 gint *trailing,
257 gint x,
258 gint y);
259void gtk_text_view_get_line_yrange (GtkTextView *text_view,
260 const GtkTextIter *iter,
261 gint *y,
262 gint *height);
263
264void gtk_text_view_get_line_at_y (GtkTextView *text_view,
265 GtkTextIter *target_iter,
266 gint y,
267 gint *line_top);
268
269void 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);
275void 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
282GtkAdjustment* gtk_text_view_get_hadjustment (GtkTextView *text_view);
283GtkAdjustment* gtk_text_view_get_vadjustment (GtkTextView *text_view);
284
285GdkWindow* gtk_text_view_get_window (GtkTextView *text_view,
286 GtkTextWindowType win);
287GtkTextWindowType gtk_text_view_get_window_type (GtkTextView *text_view,
288 GdkWindow *window);
289
290void gtk_text_view_set_border_window_size (GtkTextView *text_view,
291 GtkTextWindowType type,
292 gint size);
293gint gtk_text_view_get_border_window_size (GtkTextView *text_view,
294 GtkTextWindowType type);
295
296gboolean gtk_text_view_forward_display_line (GtkTextView *text_view,
297 GtkTextIter *iter);
298gboolean gtk_text_view_backward_display_line (GtkTextView *text_view,
299 GtkTextIter *iter);
300gboolean gtk_text_view_forward_display_line_end (GtkTextView *text_view,
301 GtkTextIter *iter);
302gboolean gtk_text_view_backward_display_line_start (GtkTextView *text_view,
303 GtkTextIter *iter);
304gboolean gtk_text_view_starts_display_line (GtkTextView *text_view,
305 const GtkTextIter *iter);
306gboolean gtk_text_view_move_visually (GtkTextView *text_view,
307 GtkTextIter *iter,
308 gint count);
309
310gboolean gtk_text_view_im_context_filter_keypress (GtkTextView *text_view,
311 GdkEventKey *event);
312void gtk_text_view_reset_im_context (GtkTextView *text_view);
313
314/* Adding child widgets */
315void gtk_text_view_add_child_at_anchor (GtkTextView *text_view,
316 GtkWidget *child,
317 GtkTextChildAnchor *anchor);
318
319void gtk_text_view_add_child_in_window (GtkTextView *text_view,
320 GtkWidget *child,
321 GtkTextWindowType which_window,
322 /* window coordinates */
323 gint xpos,
324 gint ypos);
325
326void gtk_text_view_move_child (GtkTextView *text_view,
327 GtkWidget *child,
328 /* window coordinates */
329 gint xpos,
330 gint ypos);
331
332/* Default style settings (fallbacks if no tag affects the property) */
333
334void gtk_text_view_set_wrap_mode (GtkTextView *text_view,
335 GtkWrapMode wrap_mode);
336GtkWrapMode gtk_text_view_get_wrap_mode (GtkTextView *text_view);
337void gtk_text_view_set_editable (GtkTextView *text_view,
338 gboolean setting);
339gboolean gtk_text_view_get_editable (GtkTextView *text_view);
340void gtk_text_view_set_overwrite (GtkTextView *text_view,
341 gboolean overwrite);
342gboolean gtk_text_view_get_overwrite (GtkTextView *text_view);
343void gtk_text_view_set_accepts_tab (GtkTextView *text_view,
344 gboolean accepts_tab);
345gboolean gtk_text_view_get_accepts_tab (GtkTextView *text_view);
346void gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
347 gint pixels_above_lines);
348gint gtk_text_view_get_pixels_above_lines (GtkTextView *text_view);
349void gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
350 gint pixels_below_lines);
351gint gtk_text_view_get_pixels_below_lines (GtkTextView *text_view);
352void gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
353 gint pixels_inside_wrap);
354gint gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view);
355void gtk_text_view_set_justification (GtkTextView *text_view,
356 GtkJustification justification);
357GtkJustification gtk_text_view_get_justification (GtkTextView *text_view);
358void gtk_text_view_set_left_margin (GtkTextView *text_view,
359 gint left_margin);
360gint gtk_text_view_get_left_margin (GtkTextView *text_view);
361void gtk_text_view_set_right_margin (GtkTextView *text_view,
362 gint right_margin);
363gint gtk_text_view_get_right_margin (GtkTextView *text_view);
364void gtk_text_view_set_indent (GtkTextView *text_view,
365 gint indent);
366gint gtk_text_view_get_indent (GtkTextView *text_view);
367void gtk_text_view_set_tabs (GtkTextView *text_view,
368 PangoTabArray *tabs);
369PangoTabArray* gtk_text_view_get_tabs (GtkTextView *text_view);
370
371/* note that the return value of this changes with the theme */
372GtkTextAttributes* gtk_text_view_get_default_attributes (GtkTextView *text_view);
373
374G_END_DECLS
375
376#endif /* __GTK_TEXT_VIEW_H__ */
377