]> Pileus Git - ~andy/gtk/blob - gtk/gtktextview.h
8af1a9e7f12308feef4d310f55378da02ccd69ed
[~andy/gtk] / gtk / gtktextview.h
1 #ifndef GTK_TEXT_VIEW_H
2 #define GTK_TEXT_VIEW_H
3
4 #include <gtk/gtkcontainer.h>
5 #include <gtk/gtkimcontext.h>
6 #include <gtk/gtktextbuffer.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif /* __cplusplus */
11
12 typedef enum {
13   GTK_TEXT_MOVEMENT_CHAR,       /* move by forw/back chars */
14   GTK_TEXT_MOVEMENT_POSITIONS,  /* move by left/right chars */
15   GTK_TEXT_MOVEMENT_WORD,       /* move by forward/back words */
16   GTK_TEXT_MOVEMENT_LINE,       /* move up/down lines (wrapped lines) */
17   GTK_TEXT_MOVEMENT_PARAGRAPH,  /* move up/down paragraphs (newline-ended lines) */
18   GTK_TEXT_MOVEMENT_PARAGRAPH_ENDS,   /* move to either end of a paragraph */
19   GTK_TEXT_MOVEMENT_BUFFER_ENDS       /* move to ends of the buffer */
20 } GtkTextViewMovementStep;
21
22 typedef enum {
23   GTK_TEXT_SCROLL_TO_TOP,
24   GTK_TEXT_SCROLL_TO_BOTTOM,
25   GTK_TEXT_SCROLL_PAGE_DOWN,
26   GTK_TEXT_SCROLL_PAGE_UP
27 } GtkTextViewScrollType;
28
29 typedef enum {
30   GTK_TEXT_DELETE_CHAR,
31   GTK_TEXT_DELETE_HALF_WORD, /* delete only the portion of the word to the
32                                  left/right of cursor if we're in the middle
33                                  of a word */
34   GTK_TEXT_DELETE_WHOLE_WORD,
35   GTK_TEXT_DELETE_HALF_LINE,
36   GTK_TEXT_DELETE_WHOLE_LINE,
37   GTK_TEXT_DELETE_HALF_PARAGRAPH,  /* like C-k in Emacs (or its reverse) */
38   GTK_TEXT_DELETE_WHOLE_PARAGRAPH, /* C-k in pico, kill whole line */
39   GTK_TEXT_DELETE_WHITESPACE,      /* M-\ in Emacs */
40   GTK_TEXT_DELETE_WHITESPACE_LEAVE_ONE /* M-space in Emacs */
41 } GtkTextViewDeleteType;
42
43 #define GTK_TYPE_TEXT_VIEW             (gtk_text_view_get_type())
44 #define GTK_TEXT_VIEW(obj)             (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_VIEW, GtkTextView))
45 #define GTK_TEXT_VIEW_CLASS(klass)     (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
46 #define GTK_IS_TEXT_VIEW(obj)          (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_VIEW))
47 #define GTK_IS_TEXT_VIEW_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_VIEW))
48 #define GTK_TEXT_VIEW_GET_CLASS(obj)   (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewClass))
49
50 typedef struct _GtkTextView GtkTextView;
51 typedef struct _GtkTextViewClass GtkTextViewClass;
52
53 struct _GtkTextView {
54   GtkContainer parent_instance;
55
56   struct _GtkTextLayout *layout;
57   GtkTextBuffer *buffer;
58
59   guint selection_drag_handler;
60   guint selection_drag_scan_timeout;
61   gint scrolling_accel_factor;
62
63   gboolean overwrite_mode;
64
65   GtkWrapMode wrap_mode;        /* Default wrap mode */
66
67   GdkWindow *bin_window;
68   GtkAdjustment *hadjustment;
69   GtkAdjustment *vadjustment;
70
71   gint xoffset;                 /* Offsets between widget coordinates and buffer coordinates */
72   gint yoffset;
73   gint width;                   /* Width and height of the buffer */
74   gint height;
75   
76   /* The virtual cursor position is normally the same as the
77    * actual (strong) cursor position, except in two circumstances:
78    *
79    * a) When the cursor is moved vertically with the keyboard
80    * b) When the text view is scrolled with the keyboard
81    *
82    * In case a), virtual_cursor_x is preserved, but not virtual_cursor_y
83    * In case b), both virtual_cursor_x and virtual_cursor_y are preserved.
84    */
85   gint virtual_cursor_x;           /* -1 means use actual cursor position */
86   gint virtual_cursor_y;           /* -1 means use actual cursor position */
87   
88   GtkTextMark *first_para_mark;    /* Mark at the beginning of the first onscreen paragraph */
89   gint first_para_pixels;          /* Offset of top of screen in the first onscreen paragraph */
90
91   GtkTextMark *dnd_mark;
92   guint blink_timeout;
93
94   guint first_validate_idle;            /* Idle to revalidate onscreen portion, runs before resize */
95   guint incremental_validate_idle;      /* Idle to revalidate offscreen portions, runs after redraw */
96
97   GtkIMContext *im_context;
98 };
99
100 struct _GtkTextViewClass {
101   GtkContainerClass parent_class;
102
103   /* These are all RUN_ACTION signals for keybindings */
104
105   /* move insertion point */
106   void (* move_insert) (GtkTextView *text_view, GtkTextViewMovementStep step, gint count, gboolean extend_selection);
107   /* move the "anchor" (what Emacs calls the mark) to the cursor position */
108   void (* set_anchor)  (GtkTextView *text_view);
109   /* Scroll */
110   void (* scroll_text) (GtkTextView *text_view, GtkTextViewScrollType type);
111   /* Deletions */
112   void (* delete_text) (GtkTextView *text_view, GtkTextViewDeleteType type, gint count);
113   /* cut copy paste */
114   void (* cut_text)    (GtkTextView *text_view);
115   void (* copy_text)    (GtkTextView *text_view);
116   void (* paste_text)    (GtkTextView *text_view);
117   /* overwrite */
118   void (* toggle_overwrite) (GtkTextView *text_view);
119   void  (*set_scroll_adjustments)   (GtkTextView    *text_view,
120                                      GtkAdjustment  *hadjustment,
121                                      GtkAdjustment  *vadjustment);
122 };
123
124 GtkType        gtk_text_view_get_type              (void);
125 GtkWidget *    gtk_text_view_new                   (void);
126 GtkWidget *    gtk_text_view_new_with_buffer       (GtkTextBuffer *buffer);
127 void           gtk_text_view_set_buffer            (GtkTextView   *text_view,
128                                                     GtkTextBuffer *buffer);
129 GtkTextBuffer *gtk_text_view_get_buffer            (GtkTextView   *text_view);
130 void           gtk_text_view_get_iter_at_pixel     (GtkTextView   *text_view,
131                                                     GtkTextIter   *iter,
132                                                     gint           x,
133                                                     gint           y);
134 gboolean       gtk_text_view_scroll_to_mark        (GtkTextView   *text_view,
135                                                     GtkTextMark   *mark,
136                                                     gint           mark_within_margin);
137 gboolean       gtk_text_view_move_mark_onscreen    (GtkTextView   *text_view,
138                                                     GtkTextMark   *mark);
139 gboolean       gtk_text_view_place_cursor_onscreen (GtkTextView   *text_view);
140
141 void           gtk_text_view_get_visible_rect      (GtkTextView   *text_view,
142                                                     GdkRectangle  *visible_rect);
143 void           gtk_text_view_set_wrap_mode         (GtkTextView   *text_view,
144                                                     GtkWrapMode    wrap_mode);
145 GtkWrapMode    gtk_text_view_get_wrap_mode         (GtkTextView   *text_view);
146
147 #ifdef __cplusplus
148 }
149 #endif /* __cplusplus */
150
151 #endif /* GTK_TEXT_VIEW_H */