static GType gtk_mirror_bin_child_type (GtkContainer *container) { GtkMirrorBin *bin = GTK_MIRROR_BIN (container); if (bin->child) return G_TYPE_NONE; return GTK_TYPE_WIDGET; }
static void gtk_mirror_bin_unrealize (GtkWidget *widget) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gdk_window_set_user_data (bin->offscreen_window, NULL); gdk_window_destroy (bin->offscreen_window); bin->offscreen_window = NULL; GTK_WIDGET_CLASS (gtk_mirror_bin_parent_class)->unrealize (widget); }
static void gtk_mirror_bin_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) { GtkMirrorBin *bin = GTK_MIRROR_BIN (container); g_return_if_fail (callback != NULL); if (bin->child) (*callback) (bin->child, callback_data); }
static void gtk_mirror_bin_add (GtkContainer *container, GtkWidget *widget) { GtkMirrorBin *bin = GTK_MIRROR_BIN (container); if (!bin->child) { gtk_widget_set_parent_window (widget, bin->offscreen_window); gtk_widget_set_parent (widget, GTK_WIDGET (bin)); bin->child = widget; } else g_warning ("GtkMirrorBin cannot have more than one child\n"); }
static void gtk_mirror_bin_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); GtkRequisition child_requisition; child_requisition.width = 0; child_requisition.height = 0; if (bin->child && gtk_widget_get_visible (bin->child)) gtk_widget_size_request (bin->child, &child_requisition); requisition->width = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.width + 10; requisition->height = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.height * 2 + 10; }
static void gtk_mirror_bin_remove (GtkContainer *container, GtkWidget *widget) { GtkMirrorBin *bin = GTK_MIRROR_BIN (container); gboolean was_visible; was_visible = gtk_widget_get_visible (widget); if (bin->child == widget) { gtk_widget_unparent (widget); bin->child = NULL; if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container))) gtk_widget_queue_resize (GTK_WIDGET (container)); } }
static void gtk_mirror_bin_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gint border_width; gint w, h; gtk_widget_set_allocation (widget, allocation); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); w = allocation->width - border_width * 2; h = allocation->height - border_width * 2; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (gtk_widget_get_window (widget), allocation->x + border_width, allocation->y + border_width, w, h); if (bin->child && gtk_widget_get_visible (bin->child)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (bin->child, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.height = child_requisition.height; child_allocation.width = child_requisition.width; if (gtk_widget_get_realized (widget)) gdk_window_move_resize (bin->offscreen_window, allocation->x + border_width, allocation->y + border_width, child_allocation.width, child_allocation.height); gtk_widget_size_allocate (bin->child, &child_allocation); } }
static void gtk_mirror_bin_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); gint border_width; gint w, h; widget->allocation = *allocation; border_width = GTK_CONTAINER (widget)->border_width; w = allocation->width - border_width * 2; h = allocation->height - border_width * 2; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, allocation->x + border_width, allocation->y + border_width, w, h); if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { GtkRequisition child_requisition; GtkAllocation child_allocation; gtk_widget_get_child_requisition (bin->child, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.height = child_requisition.height; child_allocation.width = child_requisition.width; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (bin->offscreen_window, allocation->x + border_width, allocation->y + border_width, child_allocation.width, child_allocation.height); gtk_widget_size_allocate (bin->child, &child_allocation); } }
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 == widget->window) { 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_drawable_get_size (pixmap, &width, &height); cr = gdk_cairo_create (widget->window); 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 (widget->style, 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; }
static void gtk_mirror_bin_realize (GtkWidget *widget) { GtkMirrorBin *bin = GTK_MIRROR_BIN (widget); GdkWindowAttr attributes; gint attributes_mask; gint border_width; GtkRequisition child_requisition; gtk_widget_set_realized (widget, TRUE); border_width = GTK_CONTAINER (widget)->border_width; attributes.x = widget->allocation.x + border_width; attributes.y = widget->allocation.y + border_width; attributes.width = widget->allocation.width - 2 * border_width; attributes.height = widget->allocation.height - 2 * border_width; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes.wclass = GDK_INPUT_OUTPUT; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, widget); g_signal_connect (widget->window, "pick-embedded-child", G_CALLBACK (pick_offscreen_child), bin); attributes.window_type = GDK_WINDOW_OFFSCREEN; child_requisition.width = child_requisition.height = 0; if (bin->child && gtk_widget_get_visible (bin->child)) { attributes.width = bin->child->allocation.width; attributes.height = bin->child->allocation.height; } bin->offscreen_window = gdk_window_new (gtk_widget_get_root_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (bin->offscreen_window, widget); if (bin->child) gtk_widget_set_parent_window (bin->child, bin->offscreen_window); gdk_offscreen_window_set_embedder (bin->offscreen_window, widget->window); g_signal_connect (bin->offscreen_window, "to-embedder", G_CALLBACK (offscreen_window_to_parent), bin); g_signal_connect (bin->offscreen_window, "from-embedder", G_CALLBACK (offscreen_window_from_parent), bin); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, bin->offscreen_window, GTK_STATE_NORMAL); gdk_window_show (bin->offscreen_window); }