static void set_format (GtkHTML *html, gboolean format_html) { HTMLGdkPainter *p, *old_p; gtk_widget_ensure_style (GTK_WIDGET (html)); if (!plain_painter) { gdk_painter = HTML_GDK_PAINTER (html->engine->painter); plain_painter = HTML_GDK_PAINTER (html_plain_painter_new (GTK_WIDGET (html), TRUE)); g_object_ref (G_OBJECT (gdk_painter)); } if (format_html) { p = gdk_painter; old_p = plain_painter; } else { p = plain_painter; old_p = gdk_painter; } if (html->engine->painter != (HTMLPainter *) p) { html_gdk_painter_unrealize (old_p); if (html->engine->window) html_gdk_painter_realize (p, html->engine->window); html_font_manager_set_default (&HTML_PAINTER (p)->font_manager, HTML_PAINTER (old_p)->font_manager.variable.face, HTML_PAINTER (old_p)->font_manager.fixed.face, HTML_PAINTER (old_p)->font_manager.var_size, HTML_PAINTER (old_p)->font_manager.var_points, HTML_PAINTER (old_p)->font_manager.fix_size, HTML_PAINTER (old_p)->font_manager.fix_points); html_engine_set_painter (html->engine, HTML_PAINTER (p)); html_engine_schedule_redraw (html->engine); } }
void html_engine_draw_cursor_in_area (HTMLEngine *engine, gint x, gint y, gint width, gint height) { HTMLObject *obj; guint offset; gint x1, y1, x2, y2, sc_x, sc_y; GdkRectangle pos; GtkAdjustment *hadj, *vadj; if ((engine->editable || engine->caret_mode) && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) { html_engine_draw_table_cursor (engine); html_engine_draw_cell_cursor (engine); html_engine_draw_image_cursor (engine); } if (!cursor_enabled || engine->cursor_hide_count > 0 || !(engine->editable || engine->caret_mode) || engine->thaw_idle_id) return; obj = engine->cursor->object; if (obj == NULL || engine->window == NULL) return; offset = engine->cursor->offset; if (width < 0 || height < 0) { width = html_engine_get_doc_width (engine); height = html_engine_get_doc_height (engine); x = 0; y = 0; } html_object_get_cursor (obj, engine->painter, offset, &x1, &y1, &x2, &y2); while (obj) { if (html_object_is_frame (obj)) { x1 -= HTML_EMBEDDED (obj)->abs_x; x2 -= HTML_EMBEDDED (obj)->abs_x; y1 -= HTML_EMBEDDED (obj)->abs_y; y2 -= HTML_EMBEDDED (obj)->abs_y; break; } obj = obj->parent; } /* get scroll offset */ hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (engine->widget)); vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (engine->widget)); sc_x = (gint) gtk_adjustment_get_value (hadj); sc_y = (gint) gtk_adjustment_get_value (vadj); pos.x = x1 - sc_x; pos.y = y1 - sc_y; pos.width = x2 - x1; pos.height = y2 - y1; gtk_im_context_set_cursor_location (GTK_HTML (engine->widget)->priv->im_context, &pos); if (clip_cursor (engine, x, y, width, height, &x1, &y1, &x2, &y2)) { cairo_t *cr; gboolean using_painter_cr; using_painter_cr = engine->painter && HTML_IS_GDK_PAINTER (engine->painter) && HTML_GDK_PAINTER (engine->painter)->cr != NULL; if (using_painter_cr) { HTMLGdkPainter *gdk_painter = HTML_GDK_PAINTER (engine->painter); cr = gdk_painter->cr; cairo_save (cr); x1 -= gdk_painter->x1; y1 -= gdk_painter->y1; x2 -= gdk_painter->x1; y2 -= gdk_painter->y1; } else { cr = gdk_cairo_create (engine->window); } cairo_set_source_rgb (cr, 1, 1, 1); cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); cairo_move_to (cr, x1 + 0.5, y1 + 0.5); cairo_line_to (cr, x2 + 0.5, y2 - 0.5); cairo_set_line_width (cr, 1); cairo_stroke (cr); if (using_painter_cr) cairo_restore (cr); else cairo_destroy (cr); } }