comparison pidgin/gtkwebview.h @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents b8cbd52e26b1
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
1 /**
2 * @file gtkwebview.h Wrapper over the Gtk WebKitWebView component
3 * @ingroup pidgin
4 */
5
6 /* pidgin
7 *
8 * Pidgin is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 *
26 */
27
28 #ifndef _PIDGIN_WEBVIEW_H_
29 #define _PIDGIN_WEBVIEW_H_
30
31 #include <glib.h>
32 #include <gtk/gtk.h>
33 #include <webkit/webkit.h>
34
35 #define GTK_TYPE_WEBVIEW (gtk_webview_get_type())
36 #define GTK_WEBVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_WEBVIEW, GtkWebView))
37 #define GTK_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_WEBVIEW, GtkWebViewClass))
38 #define GTK_IS_WEBVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_WEBVIEW))
39 #define GTK_IS_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_WEBVIEW))
40 #define GTK_WEBVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_WEBVIEW, GtkWebViewClass))
41
42 typedef enum {
43 GTK_WEBVIEW_BOLD = 1 << 0,
44 GTK_WEBVIEW_ITALIC = 1 << 1,
45 GTK_WEBVIEW_UNDERLINE = 1 << 2,
46 GTK_WEBVIEW_GROW = 1 << 3,
47 GTK_WEBVIEW_SHRINK = 1 << 4,
48 GTK_WEBVIEW_FACE = 1 << 5,
49 GTK_WEBVIEW_FORECOLOR = 1 << 6,
50 GTK_WEBVIEW_BACKCOLOR = 1 << 7,
51 GTK_WEBVIEW_LINK = 1 << 8,
52 GTK_WEBVIEW_IMAGE = 1 << 9,
53 GTK_WEBVIEW_SMILEY = 1 << 10,
54 GTK_WEBVIEW_LINKDESC = 1 << 11,
55 GTK_WEBVIEW_STRIKE = 1 << 12,
56 /** Show custom smileys when appropriate. */
57 GTK_WEBVIEW_CUSTOM_SMILEY = 1 << 13,
58 GTK_WEBVIEW_ALL = -1
59 } GtkWebViewButtons;
60
61 typedef struct _GtkWebView GtkWebView;
62 typedef struct _GtkWebViewClass GtkWebViewClass;
63
64 struct _GtkWebView
65 {
66 WebKitWebView parent;
67 };
68
69 struct _GtkWebViewClass
70 {
71 WebKitWebViewClass parent;
72
73 void (*buttons_update)(GtkWebView *, GtkWebViewButtons);
74 void (*toggle_format)(GtkWebView *, GtkWebViewButtons);
75 void (*clear_format)(GtkWebView *);
76 void (*update_format)(GtkWebView *);
77 };
78
79 G_BEGIN_DECLS
80
81 /**
82 * Returns the GType for a GtkWebView widget
83 *
84 * @return The GType for GtkWebView widget
85 */
86 GType gtk_webview_get_type(void);
87
88 /**
89 * Create a new GtkWebView object
90 *
91 * @return A GtkWidget corresponding to the GtkWebView object
92 */
93 GtkWidget *gtk_webview_new(void);
94
95 /**
96 * TODO WEBKIT: Right now this just tests whether an append has been called
97 * since the last clear or since the Widget was created. So it does not
98 * test for load_string's called in between.
99 *
100 * @param webview The GtkWebView object
101 *
102 * @return gboolean indicating whether the webview is empty
103 */
104 gboolean gtk_webview_is_empty(GtkWebView *webview);
105
106 /**
107 * A very basic routine to append html, which can be considered
108 * equivalent to a "document.write" using JavaScript.
109 *
110 * @param webview The GtkWebView object
111 * @param markup The html markup to append
112 */
113 void gtk_webview_append_html(GtkWebView *webview, const char *markup);
114
115 /**
116 * Rather than use webkit_webview_load_string, this routine
117 * parses and displays the \<img id=?\> tags that make use of the
118 * Pidgin imgstore.
119 *
120 * @param webview The GtkWebView object
121 * @param html The HTML content to load
122 */
123 void gtk_webview_load_html_string(GtkWebView *webview, const char *html);
124
125 /**
126 * Execute the JavaScript only after the webkit_webview_load_string
127 * loads completely. We also guarantee that the scripts are executed
128 * in the order they are called here. This is useful to avoid race
129 * conditions when calling JS functions immediately after opening the
130 * page.
131 *
132 * @param webview The GtkWebView object
133 * @param script The script to execute
134 */
135 void gtk_webview_safe_execute_script(GtkWebView *webview, const char *script);
136
137 /**
138 * A convenience routine to quote a string for use as a JavaScript
139 * string. For instance, "hello 'world'" becomes "'hello \\'world\\''"
140 *
141 * @param str The string to escape and quote
142 *
143 * @return The quoted string
144 */
145 char *gtk_webview_quote_js_string(const char *str);
146
147 /**
148 * Set the vertical adjustment for the GtkWebView.
149 *
150 * @param webview The GtkWebView object
151 * @param vadj The GtkAdjustment that control the webview
152 */
153 void gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj);
154
155 /**
156 * Scrolls the Webview to the end of its contents.
157 *
158 * @param webview The GtkWebView object
159 * @param smooth A boolean indicating if smooth scrolling should be used
160 */
161 void gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth);
162
163 /**
164 * Scrolls a GtkWebView up by one page.
165 *
166 * @param webview The GtkWebView.
167 */
168 void gtk_webview_page_up(GtkWebView *webview);
169
170 /**
171 * Scrolls a GtkWebView down by one page.
172 *
173 * @param webview The GtkWebView.
174 */
175 void gtk_webview_page_down(GtkWebView *webview);
176
177 /**
178 * Enables or disables editing in a GtkWebView.
179 *
180 * @param webview The GtkWebView
181 * @param editable @c TRUE to make the widget editable, or @c FALSE otherwise.
182 */
183 void gtk_webview_set_editable(GtkWebView *webview, gboolean editable);
184
185 /**
186 * Setup formatting for a GtkWebView depending on the flags specified.
187 *
188 * @param webview The GtkWebView.
189 * @param flags The connection flags describing the allowed formatting.
190 */
191 void gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags);
192
193 /**
194 * Enables or disables whole buffer formatting only (wbfo) in a GtkWebView.
195 * In this mode formatting options to the buffer take effect for the entire
196 * buffer instead of specific text.
197 *
198 * @param webview The GtkWebView
199 * @param wbfo @c TRUE to enable the mode, or @c FALSE otherwise.
200 */
201 void gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview,
202 gboolean wbfo);
203
204 /**
205 * Indicates which formatting functions to enable and disable in a GtkWebView.
206 *
207 * @param webview The GtkWebView
208 * @param buttons A GtkWebViewButtons bitmask indicating which functions to use
209 */
210 void gtk_webview_set_format_functions(GtkWebView *webview,
211 GtkWebViewButtons buttons);
212
213 /**
214 * Returns which formatting functions are enabled in a GtkWebView.
215 *
216 * @param webview The GtkWebView
217 *
218 * @return A GtkWebViewButtons bitmask indicating which functions to are enabled
219 */
220 GtkWebViewButtons gtk_webview_get_format_functions(GtkWebView *webview);
221
222 /**
223 * Sets each boolean to @c TRUE or @c FALSE to indicate if that formatting
224 * option is enabled at the current position in a GtkWebView.
225 *
226 * @param webview The GtkWebView
227 * @param bold The boolean to set for bold or @c NULL.
228 * @param italic The boolean to set for italic or @c NULL.
229 * @param underline The boolean to set for underline or @c NULL.
230 * @param strikethrough The boolean to set for strikethrough or @c NULL.
231 */
232 void gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
233 gboolean *italic, gboolean *underline,
234 gboolean *strike);
235
236 /**
237 * Returns a string containing the selected font face at the current position
238 * in a GtkWebView.
239 *
240 * @param webview The GtkWebView
241 *
242 * @return A string containing the font face or @c NULL if none is set.
243 */
244 char *gtk_webview_get_current_fontface(GtkWebView *webview);
245
246 /**
247 * Returns a string containing the selected foreground color at the current
248 * position in a GtkWebView.
249 *
250 * @param webview The GtkWebView
251 *
252 * @return A string containing the foreground color or @c NULL if none is set.
253 */
254 char *gtk_webview_get_current_forecolor(GtkWebView *webview);
255
256 /**
257 * Returns a string containing the selected font background color at the current
258 * position in a GtkWebView.
259 *
260 * @param webview The GtkWebView
261 *
262 * @return A string containing the background color or @c NULL if none is set.
263 */
264 char *gtk_webview_get_current_backcolor(GtkWebView *webview);
265
266 /**
267 * Returns a integer containing the selected HTML font size at the current
268 * position in a GtkWebView.
269 *
270 * @param webview The GtkWebView
271 *
272 * @return The HTML font size.
273 */
274 gint gtk_webview_get_current_fontsize(GtkWebView *webview);
275
276 /**
277 * Checks whether a GtkWebView is marked as editable.
278 *
279 * @param webview The GtkWebView
280 *
281 * @return @c TRUE if the IM/HTML is editable, or @c FALSE otherwise.
282 */
283 gboolean gtk_webview_get_editable(GtkWebView *webview);
284
285 /**
286 * Clear all the formatting on a GtkWebView.
287 *
288 * @param webview The GtkWebView
289 */
290 void gtk_webview_clear_formatting(GtkWebView *webview);
291
292 /**
293 * Toggles bold at the cursor location or selection in a GtkWebView.
294 *
295 * @param webview The GtkWebView
296 */
297 void gtk_webview_toggle_bold(GtkWebView *webview);
298
299 /**
300 * Toggles italic at the cursor location or selection in a GtkWebView.
301 *
302 * @param webview The GtkWebView
303 */
304 void gtk_webview_toggle_italic(GtkWebView *webview);
305
306 /**
307 * Toggles underline at the cursor location or selection in a GtkWebView.
308 *
309 * @param webview The GtkWebView
310 */
311 void gtk_webview_toggle_underline(GtkWebView *webview);
312
313 /**
314 * Toggles strikethrough at the cursor location or selection in a GtkWebView.
315 *
316 * @param webview The GtkWebView
317 */
318 void gtk_webview_toggle_strike(GtkWebView *webview);
319
320 /**
321 * Toggles a foreground color at the current location or selection in a
322 * GtkWebView.
323 *
324 * @param webview The GtkWebView
325 * @param color The HTML-style color, or @c NULL or "" to clear the color.
326 *
327 * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
328 */
329 gboolean gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color);
330
331 /**
332 * Toggles a background color at the current location or selection in a
333 * GtkWebView.
334 *
335 * @param webview The GtkWebView
336 * @param color The HTML-style color, or @c NULL or "" to clear the color.
337 *
338 * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
339 */
340 gboolean gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color);
341
342 /**
343 * Toggles a font face at the current location or selection in a GtkWebView.
344 *
345 * @param webview The GtkWebView
346 * @param face The font face name, or @c NULL or "" to clear the font.
347 *
348 * @return @c TRUE if a font name was set, or @c FALSE if it was cleared.
349 */
350 gboolean gtk_webview_toggle_fontface(GtkWebView *webview, const char *face);
351
352 /**
353 * Sets the font size at the current location or selection in a GtkWebView.
354 *
355 * @param webview The GtkWebView
356 * @param size The HTML font size to use.
357 */
358 void gtk_webview_font_set_size(GtkWebView *webview, gint size);
359
360 /**
361 * Decreases the font size by 1 at the current location or selection in a
362 * GtkWebView.
363 *
364 * @param webview The GtkWebView
365 */
366 void gtk_webview_font_shrink(GtkWebView *webview);
367
368 /**
369 * Increases the font size by 1 at the current location or selection in a
370 * GtkWebView.
371 *
372 * @param webview The GtkWebView
373 */
374 void gtk_webview_font_grow(GtkWebView *webview);
375
376 G_END_DECLS
377
378 #endif /* _PIDGIN_WEBVIEW_H_ */
379