From e82c5be653d77de73a1d0e5eb7e83f4de193a6f7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 17 Sep 2011 14:58:42 +0000 Subject: remove deprecated GDK usage except for in libsexy svn path=/trunk/netsurf/; revision=12803 --- gtk/Makefile.target | 10 ++++--- gtk/font_pango.c | 34 +++------------------- gtk/plotters.c | 81 +++++++++++++++++++---------------------------------- gtk/plotters.h | 3 -- gtk/scaffolding.c | 9 ++---- gtk/thumbnail.c | 7 +---- gtk/treeview.c | 10 +------ gtk/window.c | 6 ---- 8 files changed, 44 insertions(+), 116 deletions(-) diff --git a/gtk/Makefile.target b/gtk/Makefile.target index 41f08d074..29d0a85c7 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -29,11 +29,13 @@ $(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp,WebP (libwebp))) GTKDEPFLAGS := -DG_DISABLE_SINGLE_INCLUDES \ -DG_DISABLE_DEPRECATED \ -DGTK_DISABLE_SINGLE_INCLUDES \ - -DPANGO_DISABLE_DEPRECATED \ - -DGDK_PIXBUF_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ -DGTK_DISABLE_DEPRECATED \ - -DGTK_MULTIHEAD_SAFE + -DGTK_MULTIHEAD_SAFE \ + -DPANGO_DISABLE_DEPRECATED \ + -DGDK_PIXBUF_DISABLE_DEPRECATED + +# libsexy currently means we cannot enable this +# -DGDK_DISABLE_DEPRECATED GTKCFLAGS := -std=c99 -Dgtk -Dnsgtk \ $(GTKDEPFLAGS) \ diff --git a/gtk/font_pango.c b/gtk/font_pango.c index f2277a096..99da51561 100644 --- a/gtk/font_pango.c +++ b/gtk/font_pango.c @@ -36,9 +36,6 @@ #include "utils/log.h" #include "desktop/options.h" -/* Until we can consider the descenders etc, we need to not render using cairo */ -#undef CAIRO_VERSION - static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width); @@ -241,18 +238,6 @@ bool nsfont_paint(int x, int y, const char *string, size_t length, PangoLayout *layout; PangoLayoutLine *line; gint size; -#ifdef CAIRO_VERSION - int width, height; -#else - PangoContext *context; - GdkColor colour = { 0, - ((fstyle->foreground & 0xff) << 8) | - (fstyle->foreground & 0xff), - (fstyle->foreground & 0xff00) | - (fstyle->foreground & 0xff00 >> 8), - ((fstyle->foreground & 0xff0000) >> 8) | - (fstyle->foreground & 0xff0000 >> 16) }; -#endif if (length == 0) return true; @@ -264,27 +249,16 @@ bool nsfont_paint(int x, int y, const char *string, size_t length, else pango_font_description_set_size(desc, size); -#ifdef CAIRO_VERSION layout = pango_cairo_create_layout(current_cr); -#else - nsfont_pango_check(); - context = nsfont_pango_context; - layout = nsfont_pango_layout; -#endif pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, string, length); line = pango_layout_get_line(layout, 0); -#ifdef CAIRO_VERSION - cairo_move_to(current_cr, x, y); - nsgtk_set_colour(c); - pango_cairo_show_layout_line(current_cr, layout, line); -#else - gdk_draw_layout_line_with_colors(current_drawable, current_gc, - x, y, line, &colour, 0); - -#endif + cairo_move_to(current_cr, x, y + 0.5); + nsgtk_set_colour(fstyle->foreground); + pango_cairo_show_layout_line(current_cr, line); + pango_font_description_free(desc); return true; diff --git a/gtk/plotters.c b/gtk/plotters.c index 0041b728c..0469b8dfb 100644 --- a/gtk/plotters.c +++ b/gtk/plotters.c @@ -41,13 +41,8 @@ #include "gtk/options.h" #include "gtk/bitmap.h" -#ifndef CAIRO_VERSION -#error "nsgtk requires cairo" -#endif - GtkWidget *current_widget; GdkDrawable *current_drawable; -GdkGC *current_gc; cairo_t *current_cr; static GdkRectangle cliprect; @@ -57,44 +52,11 @@ struct plotter_table plot; /** Set cairo context colour to nsgtk colour. */ void nsgtk_set_colour(colour c) { - int r, g, b; - GdkColor colour; - - r = c & 0xff; - g = (c & 0xff00) >> 8; - b = (c & 0xff0000) >> 16; - - colour.red = r | (r << 8); - colour.green = g | (g << 8); - colour.blue = b | (b << 8); - colour.pixel = (r << 16) | (g << 8) | b; - - gdk_colormap_alloc_color(gdk_colormap_get_system(), &colour, true, true); - gdk_gc_set_foreground(current_gc, &colour); - - cairo_set_source_rgba(current_cr, r / 255.0, - g / 255.0, b / 255.0, 1.0); -} - -/** Plot a caret. - * - * @note It is assumed that the plotters have been set up. - */ -void nsgtk_plot_caret(int x, int y, int h) -{ - GdkColor colour; - - colour.red = 0; - colour.green = 0; - colour.blue = 0; - colour.pixel = 0; - gdk_colormap_alloc_color(gdk_colormap_get_system(), - &colour, true, true); - gdk_gc_set_foreground(current_gc, &colour); - - gdk_draw_line(current_drawable, current_gc, - x, y, - x, y + h - 1); + cairo_set_source_rgba(current_cr, + (c & 0xff) / 255.0, + ((c & 0xff00) >> 8) / 255.0, + ((c & 0xff0000) >> 16) / 255.0, + 1.0); } /** Set cairo context to solid plot operation. */ @@ -130,7 +92,6 @@ static bool nsgtk_plot_clip(const struct rect *clip) cliprect.y = clip->y0; cliprect.width = clip->x1 - clip->x0; cliprect.height = clip->y1 - clip->y0; - gdk_gc_set_clip_rectangle(current_gc, &cliprect); return true; } @@ -192,9 +153,9 @@ static bool nsgtk_plot_disc(int x, int y, int radius, const plot_style_t *style) return true; } -static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style) +static bool +nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style) { - nsgtk_set_colour(style->stroke_colour); switch (style->stroke_type) { @@ -232,6 +193,22 @@ static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t * return true; } +/** Plot a caret. + * + * @note It is assumed that the plotters have been set up. + */ +void nsgtk_plot_caret(int x, int y, int h) +{ + nsgtk_set_solid(); /* solid line */ + nsgtk_set_colour(0); /* black */ + cairo_set_line_width(current_cr, 1); /* thin line */ + + /* core expects horizontal and vertical lines to be on pixels, not + * between pixels */ + cairo_move_to(current_cr, x + 0.5, y); + cairo_line_to(current_cr, x + 0.5, y + h - 1); + cairo_stroke(current_cr); +} static bool nsgtk_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { @@ -367,9 +344,9 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height, gdk_pixbuf_get_height(pixbuf) == height) { /* Bitmap is not scaled */ /* Plot the bitmap */ - gdk_draw_pixbuf(current_drawable, current_gc, pixbuf, - dsrcx, dsrcy, x, y, dwidth, dheight, - GDK_RGB_DITHER_MAX, 0, 0); + gdk_cairo_set_source_pixbuf(current_cr, pixbuf, x - dsrcx, y -dsrcy); + cairo_rectangle(current_cr, x , y , dwidth, dheight); + cairo_fill(current_cr); } else { /* Bitmap is scaled */ @@ -391,9 +368,9 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height, return false; /* Plot the scaled bitmap */ - gdk_draw_pixbuf(current_drawable, current_gc, scaled, - 0, 0, x, y, dwidth, dheight, - GDK_RGB_DITHER_MAX, 0, 0); + gdk_cairo_set_source_pixbuf(current_cr, scaled, x, y); + cairo_rectangle(current_cr, x , y , dwidth, dheight); + cairo_fill(current_cr); g_object_unref(scaled); } diff --git a/gtk/plotters.h b/gtk/plotters.h index d4cf51426..55ad71b5a 100644 --- a/gtk/plotters.h +++ b/gtk/plotters.h @@ -32,10 +32,7 @@ extern const struct plotter_table nsgtk_plotters; /* make sure this is NULL if no redraw is in progress */ extern GtkWidget *current_widget; extern GdkDrawable *current_drawable; -extern GdkGC *current_gc; -#ifdef CAIRO_VERSION extern cairo_t *current_cr; -#endif void nsgtk_set_colour(colour c); void nsgtk_plot_caret(int x, int y, int h); diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 07b5c4166..fd076616f 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -1514,10 +1514,8 @@ static gboolean nsgtk_history_expose_event(GtkWidget *widget, current_widget = widget; current_drawable = widget->window; - current_gc = gdk_gc_new(current_drawable); -#ifdef CAIRO_VERSION + current_cr = gdk_cairo_create(current_drawable); -#endif clip.x0 = event->area.x; clip.y0 = event->area.y; @@ -1528,10 +1526,9 @@ static gboolean nsgtk_history_expose_event(GtkWidget *widget, history_redraw(bw->history, &ctx); current_widget = NULL; - g_object_unref(current_gc); -#ifdef CAIRO_VERSION + cairo_destroy(current_cr); -#endif + return FALSE; } diff --git a/gtk/thumbnail.c b/gtk/thumbnail.c index c70c06546..da8afd1dd 100644 --- a/gtk/thumbnail.c +++ b/gtk/thumbnail.c @@ -102,10 +102,7 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, /* set to plot to pixmap */ current_drawable = pixmap; - current_gc = gdk_gc_new(current_drawable); -#ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); -#endif /* render the content */ thumbnail_redraw(content, cwidth, cheight, &ctx); @@ -129,10 +126,8 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, bitmap_modified(bitmap); - g_object_unref(current_gc); -#ifdef CAIRO_VERSION cairo_destroy(current_cr); -#endif + g_object_unref(pixmap); g_object_unref(big); diff --git a/gtk/treeview.c b/gtk/treeview.c index aec06f32f..8582ce6a8 100644 --- a/gtk/treeview.c +++ b/gtk/treeview.c @@ -182,25 +182,17 @@ gboolean nsgtk_tree_window_expose_event(GtkWidget *widget, current_widget = widget; current_drawable = widget->window; - current_gc = gdk_gc_new(current_drawable); -#ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); -#endif + current_widget = widget; current_drawable = widget->window; - current_gc = gdk_gc_new(current_drawable); -#ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); -#endif tree_set_redraw(tree, true); tree_draw(tree, 0, 0, x, y, width, height, &ctx); current_widget = NULL; - g_object_unref(current_gc); -#ifdef CAIRO_VERSION cairo_destroy(current_cr); -#endif return FALSE; } diff --git a/gtk/window.c b/gtk/window.c index 29e5e7099..4c85afa6a 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -159,10 +159,7 @@ static gboolean nsgtk_window_expose_event(GtkWidget *widget, current_widget = (GtkWidget *)g->layout; current_drawable = g->layout->bin_window; - current_gc = gdk_gc_new(current_drawable); -#ifdef CAIRO_VERSION current_cr = gdk_cairo_create(current_drawable); -#endif clip.x0 = event->area.x; clip.y0 = event->area.y; @@ -175,10 +172,7 @@ static gboolean nsgtk_window_expose_event(GtkWidget *widget, nsgtk_plot_caret(g->caretx, g->carety, g->careth); current_widget = NULL; - g_object_unref(current_gc); -#ifdef CAIRO_VERSION cairo_destroy(current_cr); -#endif return FALSE; } -- cgit v1.2.3