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 (C) 1997 Martin Jones (mjones@kde.org) |
---|
5 | Copyright (C) 1997 Torben Weis (weis@kde.org) |
---|
6 | Copyright (C) 1999, 2000 Helix Code, Inc. |
---|
7 | |
---|
8 | This library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public |
---|
10 | License as published by the Free Software Foundation; either |
---|
11 | version 2 of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | This library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public License |
---|
19 | along with this library; see the file COPYING.LIB. If not, write to |
---|
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _HTMLENGINE_H_ |
---|
25 | #define _HTMLENGINE_H_ |
---|
26 | |
---|
27 | #include <glib-object.h> |
---|
28 | #include <gdk/gdktypes.h> |
---|
29 | #include <gtk/gtkwidget.h> |
---|
30 | #include "gtkhtml-types.h" |
---|
31 | |
---|
32 | #include "htmltypes.h" |
---|
33 | #include "htmlenums.h" |
---|
34 | #include "htmlcursor.h" |
---|
35 | |
---|
36 | |
---|
37 | #define HTML_TYPE_ENGINE (html_engine_get_type ()) |
---|
38 | #define HTML_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HTML_TYPE_ENGINE, HTMLEngine)) |
---|
39 | #define HTML_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HTML_TYPE_ENGINE, HTMLEngineClass)) |
---|
40 | #define HTML_IS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HTML_TYPE_ENGINE)) |
---|
41 | #define HTML_IS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HTML_TYPE_ENGINE)) |
---|
42 | |
---|
43 | |
---|
44 | /* FIXME extreme hideous ugliness in the following lines. */ |
---|
45 | |
---|
46 | #define LEFT_BORDER 10 |
---|
47 | #define RIGHT_BORDER 10 |
---|
48 | #define TOP_BORDER 10 |
---|
49 | #define BOTTOM_BORDER 10 |
---|
50 | |
---|
51 | /* FIXME this needs splitting. */ |
---|
52 | |
---|
53 | struct _HTMLEngine { |
---|
54 | GObject parent; |
---|
55 | HTMLDrawQueue *draw_queue; |
---|
56 | |
---|
57 | HTMLPainter *painter; |
---|
58 | |
---|
59 | HTMLSettings *settings; |
---|
60 | HTMLSettings *defaultSettings; |
---|
61 | |
---|
62 | HTMLUndo *undo; |
---|
63 | |
---|
64 | GdkWindow *window; |
---|
65 | GdkGC *invert_gc; |
---|
66 | |
---|
67 | gboolean editable; |
---|
68 | gboolean caret_mode; |
---|
69 | |
---|
70 | HTMLObject *clipboard; |
---|
71 | guint clipboard_len; |
---|
72 | GList *clipboard_stack; |
---|
73 | |
---|
74 | HTMLObject *primary; |
---|
75 | guint primary_len; |
---|
76 | |
---|
77 | /* Freeze counter. When greater than zero, we never trigger relayouts |
---|
78 | nor repaints. When going from nonzero to zero, we relayout and |
---|
79 | repaint everything. */ |
---|
80 | guint freeze_count; |
---|
81 | guint thaw_idle_id; |
---|
82 | gint block_redraw; |
---|
83 | gboolean need_redraw; |
---|
84 | GSList *pending_expose; |
---|
85 | |
---|
86 | gboolean parsing; |
---|
87 | HTMLTokenizer *ht; |
---|
88 | HTMLStringTokenizer *st; |
---|
89 | HTMLObject *clue; /* the document root */ |
---|
90 | |
---|
91 | HTMLObject *flow; |
---|
92 | |
---|
93 | gint leftBorder; |
---|
94 | gint rightBorder; |
---|
95 | gint topBorder; |
---|
96 | gint bottomBorder; |
---|
97 | |
---|
98 | /* Current indentation level. */ |
---|
99 | guint indent_level; |
---|
100 | |
---|
101 | /* For the widget */ |
---|
102 | gint width; |
---|
103 | gint height; |
---|
104 | |
---|
105 | /* Number of tokens parsed in the current time-slice */ |
---|
106 | gint parseCount; |
---|
107 | gint granularity; |
---|
108 | |
---|
109 | /* Offsets */ |
---|
110 | gint x_offset, y_offset; |
---|
111 | |
---|
112 | gboolean inTitle; |
---|
113 | gboolean inPre; |
---|
114 | gboolean inOption; |
---|
115 | gboolean inTextArea; |
---|
116 | gboolean eat_space; |
---|
117 | gboolean allow_frameset; |
---|
118 | gboolean newPage; |
---|
119 | gboolean begin; |
---|
120 | |
---|
121 | HTMLStack *span_stack; |
---|
122 | HTMLStack *clueflow_style_stack; /* Clueflow style stack, elements are HTMLClueFlowStyles. */ |
---|
123 | HTMLStack *frame_stack; |
---|
124 | HTMLStack *body_stack; |
---|
125 | HTMLStack *table_stack; |
---|
126 | |
---|
127 | gchar *url; |
---|
128 | gchar *target; |
---|
129 | |
---|
130 | /* timer id to schedule paint events */ |
---|
131 | guint updateTimer; |
---|
132 | |
---|
133 | /* timer id for parsing routine */ |
---|
134 | guint timerId; |
---|
135 | |
---|
136 | guint redraw_idle_id; |
---|
137 | |
---|
138 | /* FIXME: replace with a `gchar *'? */ |
---|
139 | GString *title; |
---|
140 | |
---|
141 | gboolean writing; |
---|
142 | |
---|
143 | /* The background pixmap, an HTMLImagePointer */ |
---|
144 | gpointer bgPixmapPtr; |
---|
145 | |
---|
146 | /* Stack of lists currently active */ |
---|
147 | HTMLStack *listStack; |
---|
148 | |
---|
149 | /* Stack of embedded "object"'s */ |
---|
150 | HTMLStack *embeddedStack; |
---|
151 | |
---|
152 | /* The associated widget. */ |
---|
153 | GtkHTML *widget; |
---|
154 | |
---|
155 | gpointer image_factory; |
---|
156 | |
---|
157 | /* |
---|
158 | * This list holds strings which are displayed in the view, |
---|
159 | * but are not actually contained in the HTML source. |
---|
160 | * e.g. The numbers in an ordered list. |
---|
161 | * FIXME? |
---|
162 | */ |
---|
163 | GList *tempStrings; |
---|
164 | |
---|
165 | HTMLMap *map; |
---|
166 | HTMLForm *form; |
---|
167 | HTMLSelect *formSelect; |
---|
168 | HTMLTextArea *formTextArea; |
---|
169 | GList *formList; |
---|
170 | GString *formText; |
---|
171 | |
---|
172 | /* This is TRUE if we cannot insert a paragraph break (which is just an |
---|
173 | extra empty line). It's set to FALSE as soon as some element is |
---|
174 | added to a flow. The purpose is to avoid having paragraph breaks to |
---|
175 | be inserted in sequence, or after elements that have some vspace of |
---|
176 | their own. */ |
---|
177 | gboolean avoid_para; |
---|
178 | |
---|
179 | /* Whether we have the keyboard focus. */ |
---|
180 | guint have_focus : 1; |
---|
181 | |
---|
182 | HTMLInterval *selection; |
---|
183 | gboolean selected_in; |
---|
184 | |
---|
185 | /* --- */ |
---|
186 | |
---|
187 | /* Editing stuff. -- FIXME it should be in a separate object. */ |
---|
188 | |
---|
189 | /* The current position of the cursor. */ |
---|
190 | HTMLCursor *cursor; |
---|
191 | |
---|
192 | /* If no region is active, this is NULL. Otherwise, this is |
---|
193 | one extreme of the selected region. The other extreme is |
---|
194 | always the cursor. */ |
---|
195 | HTMLCursor *mark; |
---|
196 | |
---|
197 | /* Hide counter for the cursor. When greater than zero, it |
---|
198 | means the cursor is invisible. */ |
---|
199 | gint cursor_hide_count; |
---|
200 | |
---|
201 | /* Timer ID for cursor blink. */ |
---|
202 | gint blinking_timer_id; |
---|
203 | |
---|
204 | /* Blinking status (visible/invisible). */ |
---|
205 | gboolean blinking_status; |
---|
206 | |
---|
207 | /* Font style for insertion. If HTML_FONT_STYLE_DEFAULT, use that of |
---|
208 | the text we are in. */ |
---|
209 | GtkHTMLFontStyle insertion_font_style; |
---|
210 | HTMLColor *insertion_color; |
---|
211 | gchar *insertion_url; |
---|
212 | gchar *insertion_target; |
---|
213 | |
---|
214 | /* if we are doing shift selection - Shift + some event (arrows, mouse motion, ...) */ |
---|
215 | gboolean shift_selection; |
---|
216 | |
---|
217 | /* This object is used to update the keyboard selection in the |
---|
218 | idle loop. */ |
---|
219 | HTMLEngineEditSelectionUpdater *selection_updater; |
---|
220 | |
---|
221 | /* keeps selection between operation, which are changing selection |
---|
222 | and need restore it after done */ |
---|
223 | GList *selection_stack; |
---|
224 | |
---|
225 | /* search & replace */ |
---|
226 | HTMLSearch *search_info; |
---|
227 | HTMLReplace *replace_info; |
---|
228 | |
---|
229 | /* id-to-object mapping */ |
---|
230 | GHashTable *id_table; |
---|
231 | |
---|
232 | /* table contains data, which are set to objects by type during parse time */ |
---|
233 | GHashTable *class_data; |
---|
234 | |
---|
235 | /* table of maps */ |
---|
236 | GHashTable *map_table; |
---|
237 | |
---|
238 | gdouble min_split_index; |
---|
239 | |
---|
240 | gboolean need_spell_check; |
---|
241 | gint block_events; |
---|
242 | gchar *language; |
---|
243 | |
---|
244 | GSList *cursor_position_stack; |
---|
245 | gboolean selection_mode; |
---|
246 | gint block_selection; |
---|
247 | |
---|
248 | HTMLCursorRectangle cursor_cell; |
---|
249 | HTMLCursorRectangle cursor_table; |
---|
250 | HTMLCursorRectangle cursor_image; |
---|
251 | |
---|
252 | GList *cut_and_paste_stack; |
---|
253 | |
---|
254 | gboolean block; |
---|
255 | gboolean block_images; |
---|
256 | gint opened_streams; |
---|
257 | gboolean stopped; |
---|
258 | gboolean keep_scroll; |
---|
259 | |
---|
260 | HTMLObject *focus_object; |
---|
261 | gint focus_object_offset; |
---|
262 | |
---|
263 | gboolean save_data; |
---|
264 | gint saved_step_count; |
---|
265 | |
---|
266 | gboolean expose; |
---|
267 | gboolean need_update; |
---|
268 | |
---|
269 | HTMLObject *parser_clue; /* the root of the currently parsed block */ |
---|
270 | }; |
---|
271 | |
---|
272 | /* must be forward referenced *sigh* */ |
---|
273 | struct _HTMLEmbedded; |
---|
274 | |
---|
275 | struct _HTMLEngineClass { |
---|
276 | GObjectClass parent_class; |
---|
277 | |
---|
278 | void (* title_changed) (HTMLEngine *engine); |
---|
279 | void (* set_base) (HTMLEngine *engine, const gchar *base); |
---|
280 | void (* set_base_target) (HTMLEngine *engine, const gchar *base_target); |
---|
281 | void (* load_done) (HTMLEngine *engine); |
---|
282 | void (* url_requested) (HTMLEngine *engine, const char *url, GtkHTMLStream *handle); |
---|
283 | void (* draw_pending) (HTMLEngine *engine); |
---|
284 | void (* redirect) (HTMLEngine *engine, const char *url, int delay); |
---|
285 | void (* submit) (HTMLEngine *engine, const gchar *method, const gchar *action, const gchar *encoding); |
---|
286 | gboolean (* object_requested) (HTMLEngine *engine, GtkHTMLEmbedded *); |
---|
287 | }; |
---|
288 | |
---|
289 | |
---|
290 | /* Object construction. */ |
---|
291 | GType html_engine_get_type (void); |
---|
292 | HTMLEngine *html_engine_new (GtkWidget *); |
---|
293 | void html_engine_realize (HTMLEngine *engine, |
---|
294 | GdkWindow *window); |
---|
295 | void html_engine_unrealize (HTMLEngine *engine); |
---|
296 | |
---|
297 | void html_engine_saved (HTMLEngine *e); |
---|
298 | gboolean html_engine_is_saved (HTMLEngine *e); |
---|
299 | |
---|
300 | /* Editability control. */ |
---|
301 | void html_engine_set_editable (HTMLEngine *e, |
---|
302 | gboolean editable); |
---|
303 | gboolean html_engine_get_editable (HTMLEngine *e); |
---|
304 | |
---|
305 | /* Focus. */ |
---|
306 | void html_engine_set_focus (HTMLEngine *engine, |
---|
307 | gboolean have_focus); |
---|
308 | |
---|
309 | /* Tokenizer. */ |
---|
310 | void html_engine_set_tokenizer (HTMLEngine *engine, |
---|
311 | HTMLTokenizer *tok); |
---|
312 | |
---|
313 | /* Parsing control. */ |
---|
314 | GtkHTMLStream *html_engine_begin (HTMLEngine *p, |
---|
315 | char *content_type); |
---|
316 | void html_engine_parse (HTMLEngine *p); |
---|
317 | void html_engine_stop_parser (HTMLEngine *e); |
---|
318 | void html_engine_stop (HTMLEngine *e); |
---|
319 | void html_engine_flush (HTMLEngine *e); |
---|
320 | |
---|
321 | /* Rendering control. */ |
---|
322 | gint html_engine_calc_min_width (HTMLEngine *e); |
---|
323 | gboolean html_engine_calc_size (HTMLEngine *e, |
---|
324 | GList **changed_objs); |
---|
325 | gint html_engine_get_doc_height (HTMLEngine *p); |
---|
326 | gint html_engine_get_doc_width (HTMLEngine *e); |
---|
327 | gint html_engine_get_max_width (HTMLEngine *e); |
---|
328 | gint html_engine_get_max_height (HTMLEngine *e); |
---|
329 | void html_engine_draw (HTMLEngine *e, |
---|
330 | gint x, |
---|
331 | gint y, |
---|
332 | gint width, |
---|
333 | gint height); |
---|
334 | void html_engine_expose (HTMLEngine *e, |
---|
335 | GdkEventExpose *event); |
---|
336 | void html_engine_draw_background (HTMLEngine *e, |
---|
337 | gint x, |
---|
338 | gint y, |
---|
339 | gint width, |
---|
340 | gint height); |
---|
341 | |
---|
342 | /* Scrolling. */ |
---|
343 | void html_engine_schedule_update (HTMLEngine *e); |
---|
344 | void html_engine_schedule_redraw (HTMLEngine *e); |
---|
345 | void html_engine_block_redraw (HTMLEngine *e); |
---|
346 | void html_engine_unblock_redraw (HTMLEngine *e); |
---|
347 | gboolean html_engine_make_cursor_visible (HTMLEngine *e); |
---|
348 | gboolean html_engine_goto_anchor (HTMLEngine *e, |
---|
349 | const gchar *anchor); |
---|
350 | |
---|
351 | /* Draw/clear queue. */ |
---|
352 | void html_engine_flush_draw_queue (HTMLEngine *e); |
---|
353 | void html_engine_queue_draw (HTMLEngine *e, |
---|
354 | HTMLObject *o); |
---|
355 | void html_engine_queue_clear (HTMLEngine *e, |
---|
356 | gint x, |
---|
357 | gint y, |
---|
358 | guint width, |
---|
359 | guint height); |
---|
360 | |
---|
361 | void html_engine_set_painter (HTMLEngine *e, |
---|
362 | HTMLPainter *painter); |
---|
363 | |
---|
364 | /* Getting objects through pointer positions. */ |
---|
365 | HTMLObject *html_engine_get_object_at (HTMLEngine *e, |
---|
366 | gint x, |
---|
367 | gint y, |
---|
368 | guint *offset_return, |
---|
369 | gboolean for_cursor); |
---|
370 | HTMLPoint *html_engine_get_point_at (HTMLEngine *e, |
---|
371 | gint x, |
---|
372 | gint y, |
---|
373 | gboolean for_cursor); |
---|
374 | const gchar *html_engine_get_link_at (HTMLEngine *e, |
---|
375 | gint x, |
---|
376 | gint y); |
---|
377 | |
---|
378 | /* Form support. */ |
---|
379 | void html_engine_form_submitted (HTMLEngine *engine, |
---|
380 | const gchar *method, |
---|
381 | const gchar *action, |
---|
382 | const gchar *encoding); |
---|
383 | |
---|
384 | /* Misc. (FIXME: Should die?) */ |
---|
385 | gchar *html_engine_canonicalize_url (HTMLEngine *e, |
---|
386 | const char *in_url); |
---|
387 | |
---|
388 | /* Cursor */ |
---|
389 | HTMLCursor *html_engine_get_cursor (HTMLEngine *e); |
---|
390 | void html_engine_normalize_cursor (HTMLEngine *e); |
---|
391 | |
---|
392 | /* Freezing/thawing. */ |
---|
393 | gboolean html_engine_frozen (HTMLEngine *engine); |
---|
394 | void html_engine_freeze (HTMLEngine *engine); |
---|
395 | void html_engine_thaw (HTMLEngine *engine); |
---|
396 | |
---|
397 | /* Creating an empty document. */ |
---|
398 | void html_engine_load_empty (HTMLEngine *engine); |
---|
399 | |
---|
400 | /* Search & Replace */ |
---|
401 | |
---|
402 | void html_engine_replace (HTMLEngine *e, |
---|
403 | const gchar *text, |
---|
404 | const gchar *rep_text, |
---|
405 | gboolean case_sensitive, |
---|
406 | gboolean forward, |
---|
407 | gboolean regular, |
---|
408 | void (*ask)(HTMLEngine *, gpointer), gpointer ask_data); |
---|
409 | gboolean html_engine_replace_do (HTMLEngine *e, HTMLReplaceQueryAnswer answer); |
---|
410 | gint html_engine_replaced (void); |
---|
411 | |
---|
412 | /* Magic links */ |
---|
413 | void html_engine_init_magic_links (void); |
---|
414 | |
---|
415 | /* spell checking */ |
---|
416 | void html_engine_spell_check (HTMLEngine *e); |
---|
417 | void html_engine_clear_spell_check (HTMLEngine *e); |
---|
418 | gchar *html_engine_get_spell_word (HTMLEngine *e); |
---|
419 | gboolean html_engine_spell_word_is_valid (HTMLEngine *e); |
---|
420 | void html_engine_replace_spell_word_with (HTMLEngine *e, |
---|
421 | const gchar *word); |
---|
422 | void html_engine_set_language (HTMLEngine *e, |
---|
423 | const gchar *language); |
---|
424 | const gchar *html_engine_get_language (HTMLEngine *e); |
---|
425 | |
---|
426 | /* view size - for image size specified in percent */ |
---|
427 | gint html_engine_get_view_width (HTMLEngine *e); |
---|
428 | gint html_engine_get_view_height (HTMLEngine *e); |
---|
429 | |
---|
430 | /* id support */ |
---|
431 | void html_engine_add_object_with_id (HTMLEngine *e, |
---|
432 | const gchar *id, |
---|
433 | HTMLObject *obj); |
---|
434 | HTMLObject *html_engine_get_object_by_id (HTMLEngine *e, |
---|
435 | const gchar *id); |
---|
436 | |
---|
437 | HTMLEngine *html_engine_get_top_html_engine (HTMLEngine *e); |
---|
438 | void html_engine_thaw_idle_flush (HTMLEngine *e); |
---|
439 | |
---|
440 | /* class data */ |
---|
441 | const gchar *html_engine_get_class_data (HTMLEngine *e, |
---|
442 | const gchar *class_name, |
---|
443 | const gchar *key); |
---|
444 | GHashTable *html_engine_get_class_table (HTMLEngine *e, |
---|
445 | const gchar *class_name); |
---|
446 | void html_engine_set_class_data (HTMLEngine *e, |
---|
447 | const gchar *class_name, |
---|
448 | const gchar *key, |
---|
449 | const gchar *value); |
---|
450 | void html_engine_clear_class_data (HTMLEngine *e, |
---|
451 | const gchar *class_name, |
---|
452 | const gchar *key); |
---|
453 | void html_engine_clear_all_class_data (HTMLEngine *e); |
---|
454 | gboolean html_engine_intersection (HTMLEngine *e, |
---|
455 | gint *x1, |
---|
456 | gint *y1, |
---|
457 | gint *x2, |
---|
458 | gint *y2); |
---|
459 | void html_engine_add_expose (HTMLEngine *e, |
---|
460 | gint x, |
---|
461 | gint y, |
---|
462 | gint width, |
---|
463 | gint height, |
---|
464 | gboolean expose); |
---|
465 | void html_engine_redraw_selection (HTMLEngine *e); |
---|
466 | |
---|
467 | gboolean html_engine_focus (HTMLEngine *e, |
---|
468 | GtkDirectionType dir); |
---|
469 | HTMLObject *html_engine_get_focus_object (HTMLEngine *e, |
---|
470 | gint *offset); |
---|
471 | void html_engine_set_focus_object (HTMLEngine *e, |
---|
472 | HTMLObject *o, |
---|
473 | gint offset); |
---|
474 | void html_engine_update_focus_if_necessary (HTMLEngine *e, |
---|
475 | HTMLObject *o, |
---|
476 | gint offset); |
---|
477 | |
---|
478 | HTMLMap *html_engine_get_map (HTMLEngine *e, |
---|
479 | const gchar *name); |
---|
480 | |
---|
481 | gboolean html_engine_selection_contains_object_type (HTMLEngine *e, |
---|
482 | HTMLType obj_type); |
---|
483 | gboolean html_engine_selection_contains_link (HTMLEngine *e); |
---|
484 | |
---|
485 | gint html_engine_get_left_border (HTMLEngine *e); |
---|
486 | gint html_engine_get_right_border (HTMLEngine *e); |
---|
487 | gint html_engine_get_top_border (HTMLEngine *e); |
---|
488 | gint html_engine_get_bottom_border (HTMLEngine *e); |
---|
489 | |
---|
490 | HTMLImageFactory *html_engine_get_image_factory (HTMLEngine *e); |
---|
491 | void html_engine_opened_streams_increment (HTMLEngine *e); |
---|
492 | void html_engine_opened_streams_decrement (HTMLEngine *e); |
---|
493 | void html_engine_opened_streams_set (HTMLEngine *e, int value); |
---|
494 | |
---|
495 | void html_engine_refresh_fonts (HTMLEngine *e); |
---|
496 | |
---|
497 | #endif /* _HTMLENGINE_H_ */ |
---|