1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*  This file is part of the GtkHTML library.
3  *
4  *  Copyright 1999, 2000 Helix Code, Inc.
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public License
17  *  along with this library; see the file COPYING.LIB.  If not, write to
18  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef _GTKHTML_H_
23 #define _GTKHTML_H_
24 
25 #include <sys/types.h>
26 
27 #include "gtkhtml-types.h"
28 #include "gtkhtml-enums.h"
29 #include <gtk/gtk.h>
30 
31 /* FIXME we should remove html dep */
32 #include "htmltypes.h"
33 
34 #define GTK_TYPE_HTML                  (gtk_html_get_type ())
35 #define GTK_HTML(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_HTML, GtkHTML))
36 #define GTK_HTML_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_HTML, GtkHTMLClass))
37 #define GTK_IS_HTML(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_HTML))
38 #define GTK_IS_HTML_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HTML))
39 
40 struct _GtkHTML {
41 	GtkLayout layout;
42 
43 	GtkWidget            *iframe_parent;
44 	HTMLObject           *frame;
45 	GtkHTMLEditorAPI     *editor_api;
46 	gpointer              editor_data;
47 	HTMLEngine           *engine;
48 
49 	/* The URL of the link over which the pointer currently is.  NULL if
50 	 * the pointer is not over a link.  */
51 	gchar *pointer_url;
52 
53 	/* The cursors we use within the widget.  */
54 	GdkCursor *hand_cursor;
55 	GdkCursor *ibeam_cursor;
56 
57 	gint selection_x1, selection_y1;
58 
59 	guint in_selection : 1;
60 	guint in_selection_drag : 1;
61 
62 	guint debug : 1;
63 	guint allow_selection : 1;
64 
65 	guint hadj_connection;
66 	guint vadj_connection;
67 
68 	gboolean binding_handled;
69 	GtkHTMLPrivate *priv;
70 };
71 
72 struct _GtkHTMLClass {
73 	GtkLayoutClass parent_class;
74 
75         void (* title_changed)   (GtkHTML *html, const gchar *new_title);
76         void (* url_requested)   (GtkHTML *html, const gchar *url, GtkHTMLStream *handle);
77         void (* load_done)       (GtkHTML *html);
78         void (* link_clicked)    (GtkHTML *html, const gchar *url);
79 	void (* set_base)        (GtkHTML *html, const gchar *base_url);
80 	void (* set_base_target) (GtkHTML *html, const gchar *base_url);
81 
82 	void (* on_url)		 (GtkHTML *html, const gchar *url);
83 	void (* redirect)        (GtkHTML *html, const gchar *url, gint delay);
84 	void (* submit)          (GtkHTML *html, const gchar *method, const gchar *url, const gchar *encoding);
85 	gboolean (* object_requested)(GtkHTML *html, GtkHTMLEmbedded *);
86 
87 	void (* current_paragraph_style_changed) (GtkHTML *html, GtkHTMLParagraphStyle new_style);
88 	void (* current_paragraph_alignment_changed) (GtkHTML *html, GtkHTMLParagraphAlignment new_alignment);
89 	void (* current_paragraph_indentation_changed) (GtkHTML *html, guint new_indentation);
90 	void (* insertion_font_style_changed) (GtkHTML *html, GtkHTMLFontStyle style);
91 	void (* insertion_color_changed) (GtkHTML *html, GdkColor *color);
92 
93         void (* size_changed)       (GtkHTML *html);
94 	void (* iframe_created)     (GtkHTML *html, GtkHTML *iframe);
95 
96 	/* keybindings signals */
97 	void     (* scroll)               (GtkHTML *html, GtkOrientation orientation, GtkScrollType scroll_type,
98 					   gfloat position);
99 	void     (* cursor_move)          (GtkHTML *html, GtkDirectionType dir_type, GtkHTMLCursorSkipType skip);
100 	gboolean (* command)              (GtkHTML *html, GtkHTMLCommandType com_type);
101 	void (* cursor_changed)       (GtkHTML *html);
102 	void (* object_inserted)       (GtkHTML *html, gint pos, gint len);
103 	void (* object_delete)        (GtkHTML *html, gint pos, gint len);
104 
105 	/* properties */
106 	GtkHTMLClassProperties *properties;
107 	GtkBindingSet *emacs_bindings;
108 	gboolean use_emacs_bindings;
109 };
110 
111 struct _GtkHTMLEditorAPI
112 {
113 	/* spell checking methods */
114 	gboolean  (* check_word)              (GtkHTML *html, const gchar *word, gpointer data);
115 	void      (* suggestion_request)      (GtkHTML *html, gpointer data);
116 	void      (* add_to_session)          (GtkHTML *html, const gchar *word, gpointer data);
117 	void      (* add_to_personal)         (GtkHTML *html, const gchar *word, const gchar *language, gpointer data);
118 
119 	/* unhandled commands */
120 	gboolean  (* command)                 (GtkHTML *html, GtkHTMLCommandType com_type, gpointer data);
121 
122 	GValue  * (* event)                   (GtkHTML *html, GtkHTMLEditorEventType event_type, GValue *args, gpointer data);
123 
124 	/* input line */
125 	GtkWidget * (* create_input_line)     (GtkHTML *html, gpointer data);
126 
127 	/* spell checking methods */
128 	void      (* set_language)            (GtkHTML *html, const gchar *language, gpointer data);
129 };
130 
131 /* Creation.  */
132 GType                    gtk_html_get_type                      (void);
133 void                       gtk_html_construct                     (GtkHTML                   *html);
134 GtkWidget                 *gtk_html_new                           (void);
135 void                       gtk_html_set_editor_api                (GtkHTML                   *html,
136 								   GtkHTMLEditorAPI          *api,
137 								   gpointer                   data);
138 
139 /* parent iframe setting */
140 gint                       gtk_html_set_iframe_parent             (GtkHTML                   *html,
141 								   GtkWidget                 *parent,
142 								   HTMLObject                *frame);
143 GtkHTML                   *gtk_html_get_top_html                  (GtkHTML                   *html);
144 
145 /* Debugging.  */
146 void                       gtk_html_enable_debug                  (GtkHTML                   *html,
147 								   gboolean                   debug);
148 
149 /* Behavior.  */
150 void                       gtk_html_allow_selection               (GtkHTML                   *html,
151 								   gboolean                   allow);
152 void                       gtk_html_select_word                   (GtkHTML                   *html);
153 void                       gtk_html_select_line                   (GtkHTML                   *html);
154 void                       gtk_html_select_paragraph              (GtkHTML                   *html);
155 void                       gtk_html_select_paragraph_extended     (GtkHTML                   *html);
156 void                       gtk_html_select_all                    (GtkHTML                   *html);
157 void                       gtk_html_unselect_all                  (GtkHTML                   *html);
158 /* Loading.  */
159 GtkHTMLStream             *gtk_html_begin                         (GtkHTML                   *html);
160 GtkHTMLStream             *gtk_html_begin_full                    (GtkHTML                   *html,
161 								   gchar                      *target_frame,
162 								   const gchar                *content_type,
163 								   GtkHTMLBeginFlags         flags);
164 
165 void                       gtk_html_write                         (GtkHTML                   *html,
166 								   GtkHTMLStream             *handle,
167 								   const gchar               *buffer,
168 								   gsize                     size);
169 void                       gtk_html_end                           (GtkHTML                   *html,
170 								   GtkHTMLStream             *handle,
171 								   GtkHTMLStreamStatus        status);
172 void                       gtk_html_flush                         (GtkHTML                   *html);
173 void                       gtk_html_stop                          (GtkHTML                   *html);
174 void                       gtk_html_load_from_string              (GtkHTML                   *html,
175 								   const gchar               *str,
176 								   gint                       len);
177 
178 /* Saving.  */
179 gboolean                   gtk_html_export                        (GtkHTML                   *html,
180 								   const gchar                *type,
181 								   GtkHTMLSaveReceiverFn      receiver,
182 								   gpointer                   data);
183 gchar *                     gtk_html_get_selection_html            (GtkHTML                   *html,
184 								   gint                       *len);
185 gchar *                     gtk_html_get_selection_plain_text      (GtkHTML                   *html,
186 								   gint                       *len);
187 
188 /* Editable support.  */
189 void                       gtk_html_set_editable                  (GtkHTML                   *html,
190 								   gboolean                   editable);
191 gboolean                   gtk_html_get_editable                  (const GtkHTML             *html);
192 void                       gtk_html_set_inline_spelling           (GtkHTML                   *html,
193 								   gboolean                   inline_spell);
194 gboolean                   gtk_html_get_inline_spelling           (const GtkHTML             *html);
195 void                       gtk_html_set_magic_links               (GtkHTML                   *html,
196 								   gboolean                   magic_links);
197 gboolean                   gtk_html_get_magic_links               (const GtkHTML             *html);
198 void                       gtk_html_set_magic_smileys             (GtkHTML                   *html,
199 								   gboolean                   magic_smileys);
200 gboolean                   gtk_html_get_magic_smileys             (const GtkHTML             *html);
201 
202 /* Caret Mode */
203 void                       gtk_html_set_caret_mode                (GtkHTML                   *html,
204 								   gboolean                   caret_mode);
205 gboolean                   gtk_html_get_caret_mode                (const GtkHTML             *html);
206 
207 void			   gtk_html_set_caret_first_focus_anchor  (GtkHTML		     *html,
208 								   const gchar                *name);
209 
210 /* Animated Images */
211 void                       gtk_html_set_animate                   (GtkHTML                   *html,
212 								   gboolean                   animate);
213 gboolean                   gtk_html_get_animate                   (const GtkHTML             *html);
214 
215 /* Printing support.  */
216 void			   gtk_html_print_page_with_header_footer (GtkHTML		     *html,
217 								   GtkPrintContext	     *context,
218 								   gdouble		      header_height,
219 								   gdouble		      footer_height,
220 								   GtkHTMLPrintCallback       header_print,
221 								   GtkHTMLPrintCallback       footer_print,
222 								   gpointer		      user_data);
223 void			   gtk_html_print_page			   (GtkHTML		      *html,
224 								    GtkPrintContext	      *context);
225 gint			   gtk_html_print_page_get_pages_num	  (GtkHTML		      *html,
226 								   GtkPrintContext            *context,
227 								   gdouble		       header_height,
228 								   gdouble                     footer_height);
229 GtkPrintOperationResult	   gtk_html_print_operation_run		  (GtkHTML                    *html,
230 								   GtkPrintOperation          *operation,
231 								   GtkPrintOperationAction     action,
232 								   GtkWindow                  *parent,
233 								   GtkHTMLPrintCalcHeight      calc_header_height,
234 								   GtkHTMLPrintCalcHeight      calc_footer_height,
235 								   GtkHTMLPrintDrawFunc        draw_header,
236 								   GtkHTMLPrintDrawFunc        draw_footer,
237 								   gpointer                    user_data,
238 								   GError                    **error);
239 
240 /* Title.  */
241 const gchar               *gtk_html_get_title                     (GtkHTML                   *html);
242 void                       gtk_html_set_title                     (GtkHTML                   *html, const gchar *title);
243 
244 /* Anchors.  */
245 gboolean                   gtk_html_jump_to_anchor                (GtkHTML                   *html,
246 								   const gchar               *anchor);
247 
248 
249 /* Editing functions.  */
250 GtkHTMLParagraphStyle      gtk_html_get_paragraph_style           (GtkHTML                   *html);
251 void                       gtk_html_set_paragraph_style           (GtkHTML                   *html,
252 								   GtkHTMLParagraphStyle      style);
253 void                       gtk_html_set_indent                    (GtkHTML                   *html,
254 								   GByteArray                *levels);
255 void                       gtk_html_indent_push_level             (GtkHTML                   *html,
256 								   HTMLListType               level_type);
257 void                       gtk_html_indent_pop_level              (GtkHTML                   *html);
258 guint                      gtk_html_get_paragraph_indentation     (GtkHTML                   *html);
259 void                       gtk_html_set_font_style                (GtkHTML                   *html,
260 								   GtkHTMLFontStyle           and_mask,
261 								   GtkHTMLFontStyle           or_mask);
262 void                       gtk_html_set_color                     (GtkHTML                   *html,
263 								   HTMLColor                 *color);
264 void                       gtk_html_toggle_font_style             (GtkHTML                   *html,
265 								   GtkHTMLFontStyle           style);
266 GtkHTMLParagraphAlignment  gtk_html_get_paragraph_alignment       (GtkHTML                   *html);
267 void                       gtk_html_set_paragraph_alignment       (GtkHTML                   *html,
268 								   GtkHTMLParagraphAlignment  alignment);
269 void                       gtk_html_cut                           (GtkHTML                   *html);
270 void                       gtk_html_copy                          (GtkHTML                   *html);
271 void                       gtk_html_paste                         (GtkHTML                   *html,
272 								   gboolean                   as_cite);
273 void                       gtk_html_undo                          (GtkHTML                   *html);
274 void                       gtk_html_redo                          (GtkHTML                   *html);
275 void                       gtk_html_insert_html                   (GtkHTML                   *html,
276 								   const gchar               *html_src);
277 void                       gtk_html_insert_gtk_html               (GtkHTML                   *html,
278 								   GtkHTML                   *to_be_destroyed);
279 void                       gtk_html_append_html                   (GtkHTML                   *html,
280 								   const gchar               *html_src);
281 
282 /* misc utils */
283 gpointer                   gtk_html_get_object_by_id              (GtkHTML                   *html,
284 								   const gchar               *id);
285 const gchar *               gtk_html_get_object_id_at              (GtkHTML                   *html,
286 								   gint                        x,
287 								   gint                        y);
288 gboolean                   gtk_html_command                       (GtkHTML                   *html,
289 								   const gchar               *command_name);
290 gboolean                   gtk_html_edit_make_cursor_visible      (GtkHTML                   *html);
291 
292 void                       gtk_html_set_magnification             (GtkHTML                   *html,
293 								   gdouble                    magnification);
294 void                       gtk_html_zoom_in                       (GtkHTML                   *html);
295 void                       gtk_html_zoom_out                      (GtkHTML                   *html);
296 void                       gtk_html_zoom_reset                    (GtkHTML                   *html);
297 void                       gtk_html_update_styles                 (GtkHTML                   *html);
298 void                       gtk_html_set_allow_frameset            (GtkHTML                   *html,
299 								   gboolean                   allow);
300 gboolean                   gtk_html_get_allow_frameset            (GtkHTML                   *html);
301 void                       gtk_html_set_base                      (GtkHTML                   *html,
302 								   const gchar                *url);
303 const gchar                *gtk_html_get_base                      (GtkHTML                   *html);
304 gchar                      *gtk_html_get_url_base_relative         (GtkHTML                   *html,
305 								   const gchar                *url);
306 gchar                      *gtk_html_get_url_object_relative       (GtkHTML                   *html,
307 								   HTMLObject                *o,
308 								   const gchar                *url);
309 void                       gtk_html_images_ref                    (GtkHTML                   *html);
310 void                       gtk_html_images_unref                  (GtkHTML                   *html);
311 void                       gtk_html_image_ref                     (GtkHTML                   *html,
312 								   const gchar               *url);
313 void                       gtk_html_image_unref                   (GtkHTML                   *html,
314 								   const gchar               *url);
315 void                       gtk_html_image_preload                 (GtkHTML                   *html,
316 								   const gchar               *url);
317 void                       gtk_html_set_blocking                  (GtkHTML                   *html,
318 								   gboolean                   block);
319 void                       gtk_html_set_images_blocking           (GtkHTML                   *html,
320 								   gboolean                   block);
321 gboolean                   gtk_html_has_undo                      (GtkHTML                   *html);
322 void                       gtk_html_drop_undo                     (GtkHTML                   *html);
323 gchar *                     gtk_html_get_url_at                    (GtkHTML                   *html,
324 								   gint                        x,
325 								   gint                        y);
326 gchar *                     gtk_html_get_cursor_url                (GtkHTML                   *html);
327 
328 gchar *                     gtk_html_get_image_src_at              (GtkHTML                   *html,
329 								   gint                        x,
330 								   gint                        y);
331 gchar *                     gtk_html_get_cursor_image_src          (GtkHTML                   *html);
332 GdkPixbufAnimation *        gtk_html_get_image_at		   (GtkHTML                   *html,
333 								    gint		      x,
334 								    gint		      y);
335 
336 void                       gtk_html_set_tokenizer                 (GtkHTML                   *html,
337 								   HTMLTokenizer             *tokenizer);
338 
339 gboolean		   gtk_html_get_cursor_pos		  (GtkHTML *html, gint *position, gint *offset);
340 
341 /* DEPRECATED */
342 #if 1
343 gboolean                   gtk_html_build_with_gconf              (void);
344 const gchar *               gtk_html_get_default_content_type              (GtkHTML                   *html);
345 void                       gtk_html_set_default_content_type              (GtkHTML                   *html,
346 								   const gchar                     *content_type);
347 void			   gtk_html_set_default_engine		  (GtkHTML *html,
348 								   gboolean enginetype);
349 gboolean		   gtk_html_get_default_engine		  (GtkHTML *html);
350 GtkWidget                 *gtk_html_new_from_string               (const gchar               *Astr,
351 								   gint                       len);
352 void                       gtk_html_load_empty                    (GtkHTML                   *html);
353 gboolean                   gtk_html_save                          (GtkHTML                   *html,
354 								   GtkHTMLSaveReceiverFn      receiver,
355 								   gpointer                   data);
356 GtkHTMLStream             *gtk_html_begin_content                 (GtkHTML                   *html,
357 								   const gchar               *content_type);
358 void                       gtk_html_drag_dest_set                 (GtkHTML                   *html);
359 
360 #endif
361 
362 #endif /* _GTKHTML_H_ */
363