[gtkhtml/gtk3: 16/38] Fix drawing with gtk3
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkhtml/gtk3: 16/38] Fix drawing with gtk3
- Date: Thu, 13 Jan 2011 01:22:40 +0000 (UTC)
commit 88be3a816be457985875230b769cb7465a6635d2
Author: Milan Crha <mcrha redhat com>
Date: Fri Dec 17 17:54:13 2010 +0100
Fix drawing with gtk3
components/editor/gtkhtml-color-swatch.c | 22 +++-----
gtkhtml/gtkhtml-private.h | 3 +
gtkhtml/gtkhtml.c | 95 +++++++++++++-----------------
gtkhtml/htmlengine.c | 27 ++++-----
gtkhtml/htmlengine.h | 7 +--
5 files changed, 66 insertions(+), 88 deletions(-)
---
diff --git a/components/editor/gtkhtml-color-swatch.c b/components/editor/gtkhtml-color-swatch.c
index 7100ebb..0c6d75c 100644
--- a/components/editor/gtkhtml-color-swatch.c
+++ b/components/editor/gtkhtml-color-swatch.c
@@ -43,29 +43,23 @@ struct _GtkhtmlColorSwatchPrivate {
static gpointer parent_class;
static gboolean
-color_swatch_expose_cb (GtkWidget *drawing_area,
- GdkEventExpose *event)
+color_swatch_draw_cb (GtkWidget *drawing_area, cairo_t *cr)
{
GtkStyle *style;
- GdkWindow *window;
GdkColor *color;
- cairo_t *cr;
+ GdkRectangle rect;
style = gtk_widget_get_style (drawing_area);
- window = gtk_widget_get_window (drawing_area);
-
- if (window == NULL)
+ if (!style)
return FALSE;
- cr = gdk_cairo_create (window);
-
color = &style->bg[GTK_STATE_NORMAL];
+
+ gdk_cairo_get_clip_rectangle (cr, &rect);
gdk_cairo_set_source_color (cr, color);
- gdk_cairo_rectangle (cr, &event->area);
+ gdk_cairo_rectangle (cr, &rect);
cairo_fill (cr);
- cairo_destroy (cr);
-
return FALSE;
}
@@ -235,8 +229,8 @@ color_swatch_init (GtkhtmlColorSwatch *swatch)
gtk_widget_show (widget);
g_signal_connect (
- widget, "expose-event",
- G_CALLBACK (color_swatch_expose_cb), swatch);
+ widget, "draw",
+ G_CALLBACK (color_swatch_draw_cb), swatch);
}
GType
diff --git a/gtkhtml/gtkhtml-private.h b/gtkhtml/gtkhtml-private.h
index 5e23390..4d3edbb 100644
--- a/gtkhtml/gtkhtml-private.h
+++ b/gtkhtml/gtkhtml-private.h
@@ -80,6 +80,9 @@ struct _GtkHTMLPrivate {
gchar *caret_first_focus_anchor;
gboolean is_first_focus;
+
+ GtkAdjustment *hadjustment;
+ GtkAdjustment *vadjustment;
};
void gtk_html_private_calc_scrollbars (GtkHTML *html,
diff --git a/gtkhtml/gtkhtml.c b/gtkhtml/gtkhtml.c
index cb59516..fad8c85 100644
--- a/gtkhtml/gtkhtml.c
+++ b/gtkhtml/gtkhtml.c
@@ -577,20 +577,11 @@ static void
vertical_scroll_cb (GtkAdjustment *adjustment, gpointer data)
{
GtkHTML *html = GTK_HTML (data);
- gdouble page_increment;
- gdouble value;
-
- value = gtk_adjustment_get_value (adjustment);
- page_increment = gtk_adjustment_get_page_increment (adjustment);
- /* check if adjustment is valid, it's changed in
- Layout::size_allocate and we can't do anything about it,
- because it uses private fields we cannot access, so we have
- to use it*/
- if (html->engine->keep_scroll || html->engine->height != page_increment)
+ if (html->engine->keep_scroll)
return;
- html->engine->y_offset = (gint) value;
+ html->engine->y_offset = (gint) gtk_adjustment_get_value (adjustment);
scroll_update_mouse (GTK_WIDGET (data));
}
@@ -598,20 +589,11 @@ static void
horizontal_scroll_cb (GtkAdjustment *adjustment, gpointer data)
{
GtkHTML *html = GTK_HTML (data);
- gdouble page_increment;
- gdouble value;
-
- value = gtk_adjustment_get_value (adjustment);
- page_increment = gtk_adjustment_get_page_increment (adjustment);
- /* check if adjustment is valid, it's changed in
- Layout::size_allocate and we can't do anything about it,
- because it uses private fields we cannot access, so we have
- to use it*/
- if (html->engine->keep_scroll || html->engine->width != page_increment)
+ if (html->engine->keep_scroll)
return;
- html->engine->x_offset = (gint) value;
+ html->engine->x_offset = (gint) gtk_adjustment_get_value (adjustment);
scroll_update_mouse (GTK_WIDGET (data));
}
@@ -621,19 +603,27 @@ hadjustment_notify_cb (GtkHTML *html)
GtkScrollable *scrollable;
GtkAdjustment *hadjustment;
+ if (!html->priv)
+ return;
+
scrollable = GTK_SCROLLABLE (html);
hadjustment = gtk_scrollable_get_hadjustment (scrollable);
- if (html->hadj_connection > 0)
+ if (html->hadj_connection > 0) {
g_signal_handler_disconnect (
- hadjustment, html->hadj_connection);
+ html->priv->hadjustment, html->hadj_connection);
+ g_object_unref (html->priv->hadjustment);
+ }
- if (hadjustment != NULL)
+ if (hadjustment != NULL) {
html->hadj_connection = g_signal_connect (
hadjustment, "value_changed",
G_CALLBACK (horizontal_scroll_cb), html);
- else
+ html->priv->hadjustment = g_object_ref (hadjustment);
+ } else {
html->hadj_connection = 0;
+ html->priv->hadjustment = NULL;
+ }
}
static void
@@ -642,19 +632,27 @@ vadjustment_notify_cb (GtkHTML *html)
GtkScrollable *scrollable;
GtkAdjustment *vadjustment;
+ if (!html->priv)
+ return;
+
scrollable = GTK_SCROLLABLE (html);
vadjustment = gtk_scrollable_get_vadjustment (scrollable);
- if (html->vadj_connection != 0)
+ if (html->vadj_connection != 0) {
g_signal_handler_disconnect (
- vadjustment, html->vadj_connection);
+ html->priv->vadjustment, html->vadj_connection);
+ g_object_unref (html->priv->vadjustment);
+ }
- if (vadjustment != NULL)
+ if (vadjustment != NULL) {
html->vadj_connection = g_signal_connect (
vadjustment, "value_changed",
G_CALLBACK (vertical_scroll_cb), html);
- else
+ html->priv->vadjustment = g_object_ref (vadjustment);
+ } else {
html->vadj_connection = 0;
+ html->priv->vadjustment = NULL;
+ }
}
@@ -793,10 +791,16 @@ dispose (GObject *object)
html->ibeam_cursor = NULL;
}
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (html), NULL);
- gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (html), NULL);
-
if (html->priv) {
+ gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (html), NULL);
+ gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (html), NULL);
+
+ hadjustment_notify_cb (html);
+ vadjustment_notify_cb (html);
+
+ g_signal_handlers_disconnect_by_func (html, hadjustment_notify_cb, NULL);
+ g_signal_handlers_disconnect_by_func (html, vadjustment_notify_cb, NULL);
+
if (html->priv->idle_handler_id != 0) {
g_source_remove (html->priv->idle_handler_id);
html->priv->idle_handler_id = 0;
@@ -1244,13 +1248,12 @@ unrealize (GtkWidget *widget)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
}
-#if GTK_CHECK_VERSION(2,91,0)
static gboolean
draw (GtkWidget *widget, cairo_t *cr)
{
/* printf ("draw x: %d y: %d\n", GTK_HTML (widget)->engine->x_offset, GTK_HTML (widget)->engine->y_offset); */
- html_engine_expose (GTK_HTML (widget)->engine, cr);
+ html_engine_draw_cb (GTK_HTML (widget)->engine, cr);
if (GTK_WIDGET_CLASS (parent_class)->draw)
(* GTK_WIDGET_CLASS (parent_class)->draw) (widget, cr);
@@ -1258,21 +1261,6 @@ draw (GtkWidget *widget, cairo_t *cr)
return FALSE;
}
-#else
-static gboolean
-expose (GtkWidget *widget, GdkEventExpose *event)
-{
- /* printf ("expose x: %d y: %d\n", GTK_HTML (widget)->engine->x_offset, GTK_HTML (widget)->engine->y_offset); */
-
- html_engine_expose (GTK_HTML (widget)->engine, event);
-
- if (GTK_WIDGET_CLASS (parent_class)->expose_event)
- (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
- /* printf ("expose END\n"); */
-
- return FALSE;
-}
-#endif
static void
gtk_html_get_preferred_height (GtkWidget *widget, gint *minimum_height, gint *natural_height)
@@ -3226,11 +3214,7 @@ gtk_html_class_init (GtkHTMLClass *klass)
widget_class->style_set = style_set;
widget_class->key_press_event = key_press_event;
widget_class->key_release_event = key_release_event;
-#if GTK_CHECK_VERSION(2,91,0)
widget_class->draw = draw;
-#else
- widget_class->expose_event = expose;
-#endif
widget_class->get_preferred_width = gtk_html_get_preferred_width;
widget_class->get_preferred_height = gtk_html_get_preferred_height;
widget_class->size_allocate = size_allocate;
@@ -3546,6 +3530,9 @@ gtk_html_init (GtkHTML* html)
html->priv->caret_first_focus_anchor = NULL;
html->priv->is_first_focus = TRUE;
+ html->priv->hadjustment = NULL;
+ html->priv->vadjustment = NULL;
+
/* IM Context */
html->priv->im_context = gtk_im_multicontext_new ();
html->priv->need_im_reset = FALSE;
diff --git a/gtkhtml/htmlengine.c b/gtkhtml/htmlengine.c
index 37cd422..b44e092 100644
--- a/gtkhtml/htmlengine.c
+++ b/gtkhtml/htmlengine.c
@@ -5128,28 +5128,27 @@ html_engine_draw_real (HTMLEngine *e, gint x, gint y, gint width, gint height, g
e->expose = FALSE;
}
-#if GTK_CHECK_VERSION(2,91,0)
void
-html_engine_expose (HTMLEngine *e, cairo_t *cr)
+html_engine_draw_cb (HTMLEngine *e, cairo_t *cr)
{
GdkRectangle rect;
+ GdkWindow *bin_window;
gdk_cairo_get_clip_rectangle (cr, &rect);
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (e->widget));
+ if (bin_window) {
+ gdk_window_get_position (bin_window, &e->x_offset, &e->y_offset);
+
+ e->x_offset = ABS (e->x_offset);
+ e->y_offset = ABS (e->y_offset);
+ }
+
if (html_engine_frozen (e))
- html_engine_add_expose (e, rect.x, rect.y, rect.width, rect.height, TRUE);
- else
- html_engine_draw_real (e, rect.x, rect.y, rect.width, rect.height, TRUE);
-}
-#else
-void
-html_engine_expose (HTMLEngine *e, GdkEventExpose *event)
-{
- if (html_engine_frozen (e))
- html_engine_add_expose (e, event->area.x, event->area.y, event->area.width, event->area.height, TRUE);
+ html_engine_add_expose (e, e->x_offset + rect.x, e->y_offset + rect.y, rect.width, rect.height, TRUE);
else
- html_engine_draw_real (e, event->area.x, event->area.y, event->area.width, event->area.height, TRUE);
+ html_engine_draw_real (e, e->x_offset + rect.x, e->y_offset + rect.y, rect.width, rect.height, TRUE);
}
-#endif
void
html_engine_draw (HTMLEngine *e, gint x, gint y, gint width, gint height)
diff --git a/gtkhtml/htmlengine.h b/gtkhtml/htmlengine.h
index d3425df..23691fb 100644
--- a/gtkhtml/htmlengine.h
+++ b/gtkhtml/htmlengine.h
@@ -335,13 +335,8 @@ void html_engine_draw (HTMLEngine *e,
gint y,
gint width,
gint height);
-#if GTK_CHECK_VERSION(2,91,0)
-void html_engine_expose (HTMLEngine *e,
+void html_engine_draw_cb (HTMLEngine *e,
cairo_t *cr);
-#else
-void html_engine_expose (HTMLEngine *e,
- GdkEventExpose *event);
-#endif
void html_engine_draw_background (HTMLEngine *e,
gint x,
gint y,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]