1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
2  *  gtksourceview.h
3  *
4  *  Copyright (C) 2001 - Mikael Hermansson <tyan@linux.se> and
5  *  Chris Phelps <chicane@reninet.com>
6  *
7  *  Copyright (C) 2003 - Gustavo Giráldez and Paolo Maggi
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU Library General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU Library General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Library General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef __GTK_SOURCE_VIEW_H__
25 #define __GTK_SOURCE_VIEW_H__
26 
27 #include <gtk/gtk.h>
28 
29 #include <gtksourceview/gtksourcebuffer.h>
30 #include <gtksourceview/gtksourcecompletion.h>
31 #include <gtksourceview/gtksourcegutter.h>
32 
33 G_BEGIN_DECLS
34 
35 #define GTK_TYPE_SOURCE_VIEW             (gtk_source_view_get_type ())
36 #define GTK_SOURCE_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_VIEW, GtkSourceView))
37 #define GTK_SOURCE_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SOURCE_VIEW, GtkSourceViewClass))
38 #define GTK_IS_SOURCE_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_VIEW))
39 #define GTK_IS_SOURCE_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SOURCE_VIEW))
40 #define GTK_SOURCE_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SOURCE_VIEW, GtkSourceViewClass))
41 
42 /**
43  * GtkSourceViewGutterPosition:
44  * @GTK_SOURCE_VIEW_GUTTER_POSITION_LINES: the gutter position of the lines
45  * renderer
46  * @GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS: the gutter position of the marks
47  * renderer
48  **/
49 typedef enum
50 {
51 	GTK_SOURCE_VIEW_GUTTER_POSITION_LINES = -30,
52 	GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS = -20
53 } GtkSourceViewGutterPosition;
54 
55 typedef struct _GtkSourceView GtkSourceView;
56 typedef struct _GtkSourceViewClass GtkSourceViewClass;
57 
58 typedef struct _GtkSourceViewPrivate GtkSourceViewPrivate;
59 
60 struct _GtkSourceView
61 {
62 	GtkTextView           parent;
63 
64 	GtkSourceViewPrivate *priv;
65 };
66 
67 struct _GtkSourceViewClass
68 {
69 	GtkTextViewClass parent_class;
70 
71 	void (*undo) (GtkSourceView *view);
72 	void (*redo) (GtkSourceView *view);
73 	void (*line_mark_activated) (GtkSourceView *view,
74 	                             GtkTextIter   *iter,
75 	                             GdkEvent      *event);
76 	void (*show_completion) (GtkSourceView *view);
77 	void (*move_lines) (GtkSourceView *view,
78 	                    gboolean       copy,
79 	                    gint           step);
80 
81 	/* Padding for future expansion */
82 	void (*_gtk_source_reserved1) (void);
83 };
84 
85 /**
86  * GtkSourceSmartHomeEndType:
87  * @GTK_SOURCE_SMART_HOME_END_DISABLED: smart-home-end disabled.
88  * @GTK_SOURCE_SMART_HOME_END_BEFORE: move to the first/last
89  * non-whitespace character on the first press of the HOME/END keys and
90  * to the beginning/end of the line on the second press.
91  * @GTK_SOURCE_SMART_HOME_END_AFTER: move to the beginning/end of the
92  * line on the first press of the HOME/END keys and to the first/last
93  * non-whitespace character on the second press.
94  * @GTK_SOURCE_SMART_HOME_END_ALWAYS: always move to the first/last
95  * non-whitespace character when the HOME/END keys are pressed.
96  **/
97 typedef enum
98 {
99 	GTK_SOURCE_SMART_HOME_END_DISABLED,
100 	GTK_SOURCE_SMART_HOME_END_BEFORE,
101 	GTK_SOURCE_SMART_HOME_END_AFTER,
102 	GTK_SOURCE_SMART_HOME_END_ALWAYS
103 } GtkSourceSmartHomeEndType;
104 
105 /**
106  * GtkSourceDrawSpacesFlags:
107  * @GTK_SOURCE_DRAW_SPACES_SPACE: whether the space character should be drawn.
108  * @GTK_SOURCE_DRAW_SPACES_TAB: whether the tab character should be drawn.
109  * @GTK_SOURCE_DRAW_SPACES_NEWLINE: whether the line breaks should be drawn.
110  * @GTK_SOURCE_DRAW_SPACES_NBSP: whether the non-breaking whitespaces should be drawn.
111  * @GTK_SOURCE_DRAW_SPACES_LEADING: whether leading whitespaces should be drawn.
112  * @GTK_SOURCE_DRAW_SPACES_TEXT: whether whitespaces inside text should be drawn.
113  * @GTK_SOURCE_DRAW_SPACES_TRAILING: whether trailing whitespaces should be drawn.
114  * @GTK_SOURCE_DRAW_SPACES_ALL: wheter all kind of spaces should be drawn.
115  *
116  * GtkSourceDrawSpacesFlags determine what kind of spaces whould be drawn. If none
117  * of GTK_SOURCE_DRAW_SPACES_LEADING, GTK_SOURCE_DRAW_SPACES_TEXT or
118  * GTK_SOURCE_DRAW_SPACES_TRAILING is specified, whitespaces at any position in
119  * the line will be drawn (i.e. it has the same effect as specifying all of them).
120  */
121 typedef enum
122 {
123 	GTK_SOURCE_DRAW_SPACES_SPACE      = 1 << 0,
124 	GTK_SOURCE_DRAW_SPACES_TAB        = 1 << 1,
125 	GTK_SOURCE_DRAW_SPACES_NEWLINE    = 1 << 2,
126 	GTK_SOURCE_DRAW_SPACES_NBSP       = 1 << 3,
127 	GTK_SOURCE_DRAW_SPACES_LEADING    = 1 << 4,
128 	GTK_SOURCE_DRAW_SPACES_TEXT       = 1 << 5,
129 	GTK_SOURCE_DRAW_SPACES_TRAILING   = 1 << 6,
130 	GTK_SOURCE_DRAW_SPACES_ALL        = (GTK_SOURCE_DRAW_SPACES_SPACE   | \
131 	                                     GTK_SOURCE_DRAW_SPACES_TAB     | \
132 	                                     GTK_SOURCE_DRAW_SPACES_NEWLINE | \
133 	                                     GTK_SOURCE_DRAW_SPACES_NBSP | \
134 	                                     GTK_SOURCE_DRAW_SPACES_LEADING | \
135 	                                     GTK_SOURCE_DRAW_SPACES_TEXT | \
136 	                                     GTK_SOURCE_DRAW_SPACES_TRAILING)
137 } GtkSourceDrawSpacesFlags;
138 
139 
140 GType		 gtk_source_view_get_type 		(void) G_GNUC_CONST;
141 
142 /* Constructors */
143 GtkWidget 	*gtk_source_view_new 			(void);
144 GtkWidget 	*gtk_source_view_new_with_buffer	(GtkSourceBuffer *buffer);
145 
146 /* Properties */
147 void 		 gtk_source_view_set_show_line_numbers 	(GtkSourceView   *view,
148 							 gboolean         show);
149 gboolean 	 gtk_source_view_get_show_line_numbers 	(GtkSourceView   *view);
150 
151 void 		 gtk_source_view_set_tab_width          (GtkSourceView   *view,
152 							 guint            width);
153 guint            gtk_source_view_get_tab_width          (GtkSourceView   *view);
154 
155 void		 gtk_source_view_set_indent_width 	(GtkSourceView   *view,
156 							 gint             width);
157 gint		 gtk_source_view_get_indent_width	(GtkSourceView   *view);
158 
159 void		 gtk_source_view_set_auto_indent 	(GtkSourceView   *view,
160 							 gboolean         enable);
161 gboolean	 gtk_source_view_get_auto_indent 	(GtkSourceView   *view);
162 
163 void		 gtk_source_view_set_insert_spaces_instead_of_tabs
164 							(GtkSourceView   *view,
165 							 gboolean         enable);
166 gboolean	 gtk_source_view_get_insert_spaces_instead_of_tabs
167 							(GtkSourceView   *view);
168 
169 void		 gtk_source_view_set_indent_on_tab 	(GtkSourceView   *view,
170 							 gboolean         enable);
171 gboolean	 gtk_source_view_get_indent_on_tab 	(GtkSourceView   *view);
172 
173 void		 gtk_source_view_set_highlight_current_line
174 							(GtkSourceView   *view,
175 							 gboolean         show);
176 gboolean 	 gtk_source_view_get_highlight_current_line
177 							(GtkSourceView   *view);
178 
179 void		 gtk_source_view_set_show_right_margin 	(GtkSourceView   *view,
180 							 gboolean         show);
181 gboolean 	 gtk_source_view_get_show_right_margin 	(GtkSourceView   *view);
182 
183 void		 gtk_source_view_set_right_margin_position
184 					 		(GtkSourceView   *view,
185 							 guint            pos);
186 guint		 gtk_source_view_get_right_margin_position
187 					 		(GtkSourceView   *view);
188 
189 void 		 gtk_source_view_set_show_line_marks    (GtkSourceView   *view,
190 							 gboolean         show);
191 gboolean	 gtk_source_view_get_show_line_marks    (GtkSourceView   *view);
192 
193 #ifndef GTKSOURCEVIEW_DISABLE_DEPRECATED
194 void		 gtk_source_view_set_mark_category_pixbuf
195 							(GtkSourceView   *view,
196 							const gchar      *category,
197 							GdkPixbuf        *pixbuf) G_GNUC_DEPRECATED;
198 #endif
199 
200 void             gtk_source_view_set_mark_category_icon_from_pixbuf
201 							(GtkSourceView   *view,
202 							 const gchar     *category,
203 							 GdkPixbuf       *pixbuf);
204 
205 void             gtk_source_view_set_mark_category_icon_from_stock
206 							(GtkSourceView   *view,
207 							 const gchar     *category,
208 							 const gchar     *stock_id);
209 
210 void             gtk_source_view_set_mark_category_icon_from_icon_name
211 							(GtkSourceView   *view,
212 							 const gchar     *category,
213 							 const gchar     *name);
214 
215 #ifndef GTKSOURCEVIEW_DISABLE_DEPRECATED
216 GdkPixbuf	*gtk_source_view_get_mark_category_pixbuf
217 							(GtkSourceView   *view,
218 				       			 const gchar     *category) G_GNUC_DEPRECATED;
219 #endif
220 
221 void             gtk_source_view_set_mark_category_background
222 							(GtkSourceView   *view,
223 							 const gchar     *category,
224 							 const GdkColor  *color);
225 gboolean         gtk_source_view_get_mark_category_background
226 							(GtkSourceView   *view,
227 							 const gchar     *category,
228 							 GdkColor        *dest);
229 
230 /**
231  * GtkSourceViewMarkTooltipFunc:
232  * @mark: the #GtkSourceMark
233  * @user_data: user data pointer which was passed to gtk_source_view_set_mark_category_tooltip_func()
234  *
235  * Function type for setting up a tooltip for #GtkSourceMark.
236  * Returns: a newly-allocated string that is going to be shown as tooltip text.
237  */
238 typedef gchar *  (*GtkSourceViewMarkTooltipFunc)	(GtkSourceMark	*mark,
239 							 gpointer	 user_data);
240 void             gtk_source_view_set_mark_category_tooltip_func
241 							(GtkSourceView   *view,
242 							 const gchar     *category,
243 							 GtkSourceViewMarkTooltipFunc func,
244 							 gpointer	  user_data,
245 							 GDestroyNotify   user_data_notify);
246 void		 gtk_source_view_set_mark_category_tooltip_markup_func
247 							(GtkSourceView   *view,
248 							const gchar     *category,
249 							GtkSourceViewMarkTooltipFunc markup_func,
250 							gpointer         user_data,
251 							GDestroyNotify   user_data_notify);
252 
253 void             gtk_source_view_set_mark_category_priority
254 							(GtkSourceView   *view,
255 							 const gchar     *category,
256 							 gint priority);
257 gint		 gtk_source_view_get_mark_category_priority
258 							(GtkSourceView   *view,
259 				       			 const gchar     *category);
260 
261 void		 gtk_source_view_set_smart_home_end	(GtkSourceView             *view,
262 							 GtkSourceSmartHomeEndType  smart_he);
263 GtkSourceSmartHomeEndType
264 		 gtk_source_view_get_smart_home_end	(GtkSourceView   *view);
265 
266 void		 gtk_source_view_set_draw_spaces	(GtkSourceView   *view,
267 							 GtkSourceDrawSpacesFlags flags);
268 GtkSourceDrawSpacesFlags
269 		gtk_source_view_get_draw_spaces		(GtkSourceView   *view);
270 
271 GtkSourceCompletion *
272 		gtk_source_view_get_completion		(GtkSourceView   *view);
273 
274 GtkSourceGutter *gtk_source_view_get_gutter		(GtkSourceView     *view,
275                                                          GtkTextWindowType  window_type);
276 
277 G_END_DECLS
278 #endif				/* end of SOURCE_VIEW_H__ */
279