static void nruler_make_pixmap(Nruler *ruler, GtkWidget *widget, GtkWidget *parent) { gint width; gint height; GtkAllocation allocation, parent_allocation; if (! gtk_widget_is_drawable(widget)) { return; } gtk_widget_get_allocation(widget, &allocation); gtk_widget_get_allocation(parent, &parent_allocation); if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) { ruler->length = parent_allocation.width; ruler->size = allocation.height; ruler->ofst = (parent_allocation.width - allocation.width) / 2; } else { ruler->length = parent_allocation.height; ruler->size = allocation.width; ruler->ofst = (parent_allocation.height - allocation.height) / 2; } if (ruler->backing_store) { #if GTK_CHECK_VERSION(3, 0, 0) width = cairo_image_surface_get_width(ruler->backing_store); height = cairo_image_surface_get_height(ruler->backing_store); #elif GTK_CHECK_VERSION(2, 24, 0) gdk_pixmap_get_size(ruler->backing_store, &width, &height); #else gdk_drawable_get_size(ruler->backing_store, &width, &height); #endif if ((width == allocation.width) && (height == allocation.height)) { return; } #if GTK_CHECK_VERSION(3, 0, 0) cairo_surface_destroy(ruler->backing_store); #else g_object_unref(ruler->backing_store); #endif } #if GTK_CHECK_VERSION(3, 0, 0) ruler->backing_store = cairo_image_surface_create(CAIRO_FORMAT_RGB24, allocation.width, allocation.height); #else ruler->backing_store = gdk_pixmap_new(gtk_widget_get_window(widget), allocation.width, allocation.height, -1); #endif ruler->save_l = 0; ruler->save_u = 0; }
PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); GtkWidget* viewContainer = gtk_widget_get_parent(GTK_WIDGET(view)); gint width, height; #ifdef GTK_API_VERSION_2 GdkPixmap* pixmap = gtk_widget_get_snapshot(viewContainer, 0); gdk_pixmap_get_size(pixmap, &width, &height); #else width = gtk_widget_get_allocated_width(viewContainer); height = gtk_widget_get_allocated_height(viewContainer); #endif cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t* context = cairo_create(imageSurface); #ifdef GTK_API_VERSION_2 gdk_cairo_set_source_pixmap(context, pixmap, 0, 0); cairo_paint(context); g_object_unref(pixmap); #else gtk_widget_draw(viewContainer, context); #endif if (drawSelectionRect) { cairo_rectangle_int_t rectangle; DumpRenderTreeSupportGtk::rectangleForSelection(mainFrame, &rectangle); cairo_set_line_width(context, 1.0); cairo_rectangle(context, rectangle.x, rectangle.y, rectangle.width, rectangle.height); cairo_set_source_rgba(context, 1.0, 0.0, 0.0, 1.0); cairo_stroke(context); } return BitmapContext::createByAdoptingBitmapAndContext(0, context); }
static gboolean gtk_mirror_bin_expose (GtkWidget *widget, GdkEventExpose *event) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gint width, height; if (gtk_widget_is_drawable (widget)) { if (event->window == gtk_widget_get_window (widget)) { GdkPixmap *pixmap; cairo_t *cr; cairo_matrix_t matrix; cairo_pattern_t *mask; if (bin->child && gtk_widget_get_visible (bin->child)) { pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window); gdk_pixmap_get_size (pixmap, &width, &height); cr = gdk_cairo_create (gtk_widget_get_window (widget)); cairo_save (cr); cairo_rectangle (cr, 0, 0, width, height); cairo_clip (cr); /* paint the offscreen child */ gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0); cairo_paint (cr); cairo_restore (cr); cairo_matrix_init (&matrix, 1.0, 0.0, 0.3, 1.0, 0.0, 0.0); cairo_matrix_scale (&matrix, 1.0, -1.0); cairo_matrix_translate (&matrix, -10, - 3 * height - 10); cairo_transform (cr, &matrix); cairo_rectangle (cr, 0, height, width, height); cairo_clip (cr); gdk_cairo_set_source_pixmap (cr, pixmap, 0, height); /* create linear gradient as mask-pattern to fade out the source */ mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height); cairo_pattern_add_color_stop_rgba (mask, 0.0, 0.0, 0.0, 0.0, 0.0); cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.01); cairo_pattern_add_color_stop_rgba (mask, 0.5, 0.0, 0.0, 0.0, 0.25); cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.5); cairo_pattern_add_color_stop_rgba (mask, 1.0, 0.0, 0.0, 0.0, 1.0); /* paint the reflection */ cairo_mask (cr, mask); cairo_pattern_destroy (mask); cairo_destroy (cr); } } else if (event->window == bin->offscreen_window) { gtk_paint_flat_box (gtk_widget_get_style (widget), event->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, &event->area, widget, "blah", 0, 0, -1, -1); if (bin->child) gtk_container_propagate_expose (GTK_CONTAINER (widget), bin->child, event); } } return FALSE; }