1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include <pango/pangocairo.h>
30 #include <gdk-pixbuf/gdk-pixbuf.h>
32 #include "gdkdrawable.h"
33 #include "gdkinternals.h"
34 #include "gdkwindow.h"
35 #include "gdkscreen.h"
36 #include "gdkpixbuf.h"
39 static cairo_region_t * gdk_drawable_real_get_visible_region (GdkDrawable *drawable);
42 G_DEFINE_ABSTRACT_TYPE (GdkDrawable, gdk_drawable, G_TYPE_OBJECT)
45 gdk_drawable_class_init (GdkDrawableClass *klass)
47 /* Default implementation for clip and visible region is the same */
48 klass->get_clip_region = gdk_drawable_real_get_visible_region;
49 klass->get_visible_region = gdk_drawable_real_get_visible_region;
53 gdk_drawable_init (GdkDrawable *drawable)
57 /* Manipulation of drawables
61 * gdk_drawable_get_size:
62 * @drawable: a #GdkDrawable
63 * @width: (out) (allow-none): location to store drawable's width, or %NULL
64 * @height: (out) (allow-none): location to store drawable's height, or %NULL
66 * Fills *@width and *@height with the size of @drawable.
67 * @width or @height can be %NULL if you only want the other one.
69 * On the X11 platform, if @drawable is a #GdkWindow, the returned
70 * size is the size reported in the most-recently-processed configure
71 * event, rather than the current size on the X server.
75 gdk_drawable_get_size (GdkDrawable *drawable,
79 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
81 GDK_DRAWABLE_GET_CLASS (drawable)->get_size (drawable, width, height);
85 * gdk_drawable_get_visual:
86 * @drawable: a #GdkDrawable
88 * Gets the #GdkVisual describing the pixel format of @drawable.
90 * Return value: a #GdkVisual
93 gdk_drawable_get_visual (GdkDrawable *drawable)
95 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
97 return GDK_DRAWABLE_GET_CLASS (drawable)->get_visual (drawable);
101 * gdk_drawable_get_depth:
102 * @drawable: a #GdkDrawable
104 * Obtains the bit depth of the drawable, that is, the number of bits
105 * that make up a pixel in the drawable's visual. Examples are 8 bits
106 * per pixel, 24 bits per pixel, etc.
108 * Return value: number of bits per pixel
111 gdk_drawable_get_depth (GdkDrawable *drawable)
113 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), 0);
115 return GDK_DRAWABLE_GET_CLASS (drawable)->get_depth (drawable);
118 * gdk_drawable_get_screen:
119 * @drawable: a #GdkDrawable
121 * Gets the #GdkScreen associated with a #GdkDrawable.
123 * Return value: the #GdkScreen associated with @drawable
128 gdk_drawable_get_screen(GdkDrawable *drawable)
130 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
132 return GDK_DRAWABLE_GET_CLASS (drawable)->get_screen (drawable);
136 * gdk_drawable_get_display:
137 * @drawable: a #GdkDrawable
139 * Gets the #GdkDisplay associated with a #GdkDrawable.
141 * Return value: the #GdkDisplay associated with @drawable
146 gdk_drawable_get_display (GdkDrawable *drawable)
148 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
150 return gdk_screen_get_display (gdk_drawable_get_screen (drawable));
154 * gdk_drawable_set_colormap:
155 * @drawable: a #GdkDrawable
156 * @colormap: a #GdkColormap
158 * Sets the colormap associated with @drawable. Normally this will
159 * happen automatically when the drawable is created; you only need to
160 * use this function if the drawable-creating function did not have a
161 * way to determine the colormap, and you then use drawable operations
162 * that require a colormap. The colormap for all drawables and
163 * graphics contexts you intend to use together should match.
166 gdk_drawable_set_colormap (GdkDrawable *drawable,
169 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
170 g_return_if_fail (cmap == NULL || gdk_drawable_get_depth (drawable)
171 == cmap->visual->depth);
173 GDK_DRAWABLE_GET_CLASS (drawable)->set_colormap (drawable, cmap);
177 * gdk_drawable_get_colormap:
178 * @drawable: a #GdkDrawable
180 * Gets the colormap for @drawable, if one is set; returns
183 * Return value: the colormap, or %NULL
186 gdk_drawable_get_colormap (GdkDrawable *drawable)
188 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
190 return GDK_DRAWABLE_GET_CLASS (drawable)->get_colormap (drawable);
194 * gdk_drawable_get_clip_region:
195 * @drawable: a #GdkDrawable
197 * Computes the region of a drawable that potentially can be written
198 * to by drawing primitives. This region will not take into account
199 * the clip region for the GC, and may also not take into account
200 * other factors such as if the window is obscured by other windows,
201 * but no area outside of this region will be affected by drawing
204 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
208 gdk_drawable_get_clip_region (GdkDrawable *drawable)
210 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
212 return GDK_DRAWABLE_GET_CLASS (drawable)->get_clip_region (drawable);
216 * gdk_drawable_get_visible_region:
217 * @drawable: a #GdkDrawable
219 * Computes the region of a drawable that is potentially visible.
220 * This does not necessarily take into account if the window is
221 * obscured by other windows, but no area outside of this region
224 * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
228 gdk_drawable_get_visible_region (GdkDrawable *drawable)
230 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
232 return GDK_DRAWABLE_GET_CLASS (drawable)->get_visible_region (drawable);
235 static cairo_region_t *
236 gdk_drawable_real_get_visible_region (GdkDrawable *drawable)
243 gdk_drawable_get_size (drawable, &rect.width, &rect.height);
245 return cairo_region_create_rectangle (&rect);
249 * _gdk_drawable_ref_cairo_surface:
250 * @drawable: a #GdkDrawable
252 * Obtains a #cairo_surface_t for the given drawable. If a
253 * #cairo_surface_t for the drawable already exists, it will be
254 * referenced, otherwise a new surface will be created.
256 * Return value: a newly referenced #cairo_surface_t that points
257 * to @drawable. Unref with cairo_surface_destroy()
260 _gdk_drawable_ref_cairo_surface (GdkDrawable *drawable)
262 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
264 return GDK_DRAWABLE_GET_CLASS (drawable)->ref_cairo_surface (drawable);
267 /************************************************************************/
270 * _gdk_drawable_get_source_drawable:
271 * @drawable: a #GdkDrawable
273 * Returns a drawable for the passed @drawable that is guaranteed to be
274 * usable to create a pixmap (e.g.: not an offscreen window).
279 _gdk_drawable_get_source_drawable (GdkDrawable *drawable)
281 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
283 if (GDK_DRAWABLE_GET_CLASS (drawable)->get_source_drawable)
284 return GDK_DRAWABLE_GET_CLASS (drawable)->get_source_drawable (drawable);
290 _gdk_drawable_create_cairo_surface (GdkDrawable *drawable,
294 return GDK_DRAWABLE_GET_CLASS (drawable)->create_cairo_surface (drawable,