Commit ca8a8358 authored by Benjamin Otte's avatar Benjamin Otte

API: Remove gtk_widget_get_snapshot()

It will be replaced with gtk_widget_draw().
parent 99c82af2
......@@ -4899,7 +4899,6 @@ gtk_widget_set_tooltip_window
gtk_widget_get_has_tooltip
gtk_widget_set_has_tooltip
gtk_widget_trigger_tooltip_query
gtk_widget_get_snapshot
gtk_widget_get_window
gtk_widget_get_allocation
gtk_widget_set_allocation
......
......@@ -4245,7 +4245,6 @@ gtk_widget_get_screen
gtk_widget_get_sensitive
gtk_widget_get_settings
gtk_widget_get_size_request
gtk_widget_get_snapshot
gtk_widget_get_state
gtk_widget_get_style
gtk_widget_get_tooltip_markup
......
......@@ -31,11 +31,9 @@
*
* GtkOffscreenWindow is strictly intended to be used for obtaining
* snapshots of widgets that are not part of a normal widget hierarchy.
* It differs from gtk_widget_get_snapshot() in that the widget you
* want to get a snapshot of need not be displayed on the user's screen
* as a part of a widget hierarchy. However, since GtkOffscreenWindow
* is a toplevel widget you cannot obtain snapshots of a full window
* with it since you cannot pack a toplevel widget in another toplevel.
* Since #GtkOffscreenWindow is a toplevel widget you cannot obtain
* snapshots of a full window with it since you cannot pack a toplevel
* widget in another toplevel.
*
* The idea is to take a widget and manually set the state of it,
* add it to a GtkOffscreenWindow and then retrieve the snapshot
......@@ -259,9 +257,7 @@ gtk_offscreen_window_init (GtkOffscreenWindow *window)
* gtk_offscreen_window_new:
*
* Creates a toplevel container widget that is used to retrieve
* snapshots of widgets without showing them on the screen. For
* widgets that are on the screen and part of a normal widget
* hierarchy, gtk_widget_get_snapshot() can be used instead.
* snapshots of widgets without showing them on the screen.
*
* Return value: A pointer to a #GtkWidget
*
......
......@@ -10143,232 +10143,6 @@ gtk_widget_reset_shapes (GtkWidget *widget)
gtk_reset_shapes_recurse (widget, priv->window);
}
static void
expose_window (GdkWindow *window)
{
GdkEvent event;
GList *l, *children;
gpointer user_data;
gboolean is_double_buffered;
gdk_window_get_user_data (window, &user_data);
if (user_data)
is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
else
is_double_buffered = FALSE;
event.expose.type = GDK_EXPOSE;
event.expose.window = g_object_ref (window);
event.expose.send_event = FALSE;
event.expose.count = 0;
event.expose.area.x = 0;
event.expose.area.y = 0;
gdk_drawable_get_size (GDK_DRAWABLE (window),
&event.expose.area.width,
&event.expose.area.height);
event.expose.region = cairo_region_create_rectangle (&event.expose.area);
/* If this is not double buffered, force a double buffer so that
redirection works. */
if (!is_double_buffered)
gdk_window_begin_paint_region (window, event.expose.region);
gtk_main_do_event (&event);
if (!is_double_buffered)
gdk_window_end_paint (window);
children = gdk_window_peek_children (window);
for (l = children; l != NULL; l = l->next)
{
GdkWindow *child = l->data;
/* Don't expose input-only windows */
if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
expose_window (l->data);
}
g_object_unref (window);
}
/**
* gtk_widget_get_snapshot:
* @widget: a #GtkWidget
* @clip_rect: (allow-none): a #GdkRectangle or %NULL
*
* Create a #GdkPixmap of the contents of the widget and its children.
*
* Works even if the widget is obscured. The depth and visual of the
* resulting pixmap is dependent on the widget being snapshot and likely
* differs from those of a target widget displaying the pixmap.
* The function gdk_pixbuf_get_from_drawable() can be used to convert
* the pixmap to a visual independant representation.
*
* The snapshot area used by this function is the @widget's allocation plus
* any extra space occupied by additional windows belonging to this widget
* (such as the arrows of a spin button).
* Thus, the resulting snapshot pixmap is possibly larger than the allocation.
*
* If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
* match the specified clip_rect. The (x,y) coordinates of @clip_rect are
* interpreted widget relative. If width or height of @clip_rect are 0 or
* negative, the width or height of the resulting pixmap will be shrunken
* by the respective amount.
* For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
* chop off 5 pixels at each side of the snapshot pixmap.
* If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
* coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
* can be used to preserve the auto-grown snapshot area and use @clip_rect
* as a pure output parameter.
*
* The returned pixmap can be %NULL, if the resulting @clip_area was empty.
*
* Return value: #GdkPixmap snapshot of the widget
*
* Since: 2.14
**/
GdkPixmap*
gtk_widget_get_snapshot (GtkWidget *widget,
GdkRectangle *clip_rect)
{
GtkWidgetPrivate *priv;
int x, y, width, height;
GdkWindow *parent_window = NULL;
GdkPixmap *pixmap;
GList *windows = NULL, *list;
priv = widget->priv;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (!gtk_widget_get_visible (widget))
return NULL;
/* the widget (and parent_window) must be realized to be drawable */
if (priv->parent && !gtk_widget_get_realized (priv->parent))
gtk_widget_realize (priv->parent);
if (!gtk_widget_get_realized (widget))
gtk_widget_realize (widget);
/* determine snapshot rectangle */
x = priv->allocation.x;
y = priv->allocation.y;
width = priv->allocation.width;
height = priv->allocation.height;
if (priv->parent && gtk_widget_get_has_window (widget))
{
/* grow snapshot rectangle to cover all widget windows */
parent_window = gtk_widget_get_parent_window (widget);
for (list = gdk_window_peek_children (parent_window); list; list = list->next)
{
GdkWindow *subwin = list->data;
gpointer windata;
int wx, wy, ww, wh;
gdk_window_get_user_data (subwin, &windata);
if (windata != widget)
continue;
windows = g_list_prepend (windows, subwin);
gdk_window_get_position (subwin, &wx, &wy);
gdk_drawable_get_size (subwin, &ww, &wh);
/* grow snapshot rectangle by extra widget sub window */
if (wx < x)
{
width += x - wx;
x = wx;
}
if (wy < y)
{
height += y - wy;
y = wy;
}
if (x + width < wx + ww)
width += wx + ww - (x + width);
if (y + height < wy + wh)
height += wy + wh - (y + height);
}
}
else if (!priv->parent)
x = y = 0; /* toplevel */
/* at this point, (x,y,width,height) is the parent_window relative
* snapshot area covering all of widget's windows.
*/
/* shrink snapshot size by clip_rectangle */
if (clip_rect)
{
GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
clip.x = clip.x < 0 ? x : clip.x;
clip.y = clip.y < 0 ? y : clip.y;
clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
if (priv->parent)
{
/* offset clip_rect, so it's parent_window relative */
if (clip_rect->x >= 0)
clip.x += priv->allocation.x;
if (clip_rect->y >= 0)
clip.y += priv->allocation.y;
}
if (!gdk_rectangle_intersect (&snap, &clip, &snap))
{
g_list_free (windows);
clip_rect->width = clip_rect->height = 0;
return NULL; /* empty snapshot area */
}
x = snap.x;
y = snap.y;
width = snap.width;
height = snap.height;
}
/* render snapshot */
pixmap = gdk_pixmap_new (priv->window, width, height, gdk_drawable_get_depth (priv->window));
for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
{
GdkWindow *subwin = list->data;
int wx, wy;
if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
continue; /* Input only window */
gdk_window_get_position (subwin, &wx, &wy);
gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
MAX (0, wx - x), MAX (0, wy - y), width, height);
expose_window (subwin);
}
if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == priv->window */
{
gdk_window_redirect_to_drawable (priv->window, pixmap, x, y, 0, 0, width, height);
expose_window (priv->window);
}
for (list = windows; list; list = list->next)
gdk_window_remove_redirection (list->data);
if (!windows) /* NO_WINDOW || toplevel */
gdk_window_remove_redirection (priv->window);
g_list_free (windows);
/* return pixmap and snapshot rectangle coordinates */
if (clip_rect)
{
clip_rect->x = x;
clip_rect->y = y;
clip_rect->width = width;
clip_rect->height = height;
if (priv->parent)
{
/* offset clip_rect from parent_window so it's widget relative */
clip_rect->x -= priv->allocation.x;
clip_rect->y -= priv->allocation.y;
}
if (0)
g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
G_OBJECT_TYPE_NAME (widget),
clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
}
return pixmap;
}
/* style properties
*/
......
......@@ -741,8 +741,6 @@ GdkWindow * gtk_widget_get_root_window (GtkWidget *widget);
GtkSettings* gtk_widget_get_settings (GtkWidget *widget);
GtkClipboard *gtk_widget_get_clipboard (GtkWidget *widget,
GdkAtom selection);
GdkPixmap * gtk_widget_get_snapshot (GtkWidget *widget,
GdkRectangle *clip_rect);
/* Multidevice support */
gboolean gtk_widget_get_support_multidevice (GtkWidget *widget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment