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/.
31 /* Needed for SEEK_END in SunOS */
37 #include "gdkpixmap-x11.h"
38 #include "gdkprivate-x11.h"
50 GdkColormap *colormap;
54 static void gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
58 static void gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *pixmap);
59 static void gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass);
60 static void gdk_pixmap_impl_x11_finalize (GObject *object);
62 static gpointer parent_class = NULL;
65 gdk_pixmap_impl_x11_get_type (void)
67 static GType object_type = 0;
71 static const GTypeInfo object_info =
73 sizeof (GdkPixmapImplX11Class),
75 (GBaseFinalizeFunc) NULL,
76 (GClassInitFunc) gdk_pixmap_impl_x11_class_init,
77 NULL, /* class_finalize */
78 NULL, /* class_data */
79 sizeof (GdkPixmapImplX11),
81 (GInstanceInitFunc) gdk_pixmap_impl_x11_init,
84 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
94 _gdk_pixmap_impl_get_type (void)
96 return gdk_pixmap_impl_x11_get_type ();
100 gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *impl)
107 gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass)
109 GObjectClass *object_class = G_OBJECT_CLASS (klass);
110 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
112 parent_class = g_type_class_peek_parent (klass);
114 object_class->finalize = gdk_pixmap_impl_x11_finalize;
116 drawable_class->get_size = gdk_pixmap_impl_x11_get_size;
120 gdk_pixmap_impl_x11_finalize (GObject *object)
122 GdkPixmapImplX11 *impl = GDK_PIXMAP_IMPL_X11 (object);
123 GdkPixmap *wrapper = GDK_PIXMAP (GDK_DRAWABLE_IMPL_X11 (impl)->wrapper);
127 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
129 if (draw_impl->picture)
130 XRenderFreePicture (draw_impl->xdisplay, draw_impl->picture);
132 #endif /* HAVE_XFT */
134 if (!impl->is_foreign)
135 XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
137 gdk_xid_table_remove (GDK_PIXMAP_XID (wrapper));
139 G_OBJECT_CLASS (parent_class)->finalize (object);
143 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
148 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
150 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
154 gdk_pixmap_new (GdkWindow *window,
160 GdkDrawableImplX11 *draw_impl;
161 GdkPixmapImplX11 *pix_impl;
165 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
166 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
167 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
170 window = _gdk_parent_root;
172 if (GDK_WINDOW_DESTROYED (window))
175 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
177 depth = window_depth;
179 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
180 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
181 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
182 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
184 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
185 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
186 GDK_WINDOW_XID (window),
187 width, height, depth);
189 pix_impl->is_foreign = FALSE;
190 pix_impl->width = width;
191 pix_impl->height = height;
192 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
194 if (depth == window_depth)
196 cmap = gdk_drawable_get_colormap (window);
198 gdk_drawable_set_colormap (pixmap, cmap);
201 gdk_xid_table_insert (&draw_impl->xid, pixmap);
207 gdk_bitmap_create_from_data (GdkWindow *window,
213 GdkDrawableImplX11 *draw_impl;
214 GdkPixmapImplX11 *pix_impl;
216 g_return_val_if_fail (data != NULL, NULL);
217 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
218 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
221 window = _gdk_parent_root;
223 if (GDK_WINDOW_DESTROYED (window))
226 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
227 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
228 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
229 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
231 pix_impl->is_foreign = FALSE;
232 pix_impl->width = width;
233 pix_impl->height = height;
234 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
236 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
237 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
238 GDK_WINDOW_XID (window),
239 (char *)data, width, height);
241 gdk_xid_table_insert (&draw_impl->xid, pixmap);
247 gdk_pixmap_create_from_data (GdkWindow *window,
256 GdkDrawableImplX11 *draw_impl;
257 GdkPixmapImplX11 *pix_impl;
259 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
260 g_return_val_if_fail (data != NULL, NULL);
261 g_return_val_if_fail (fg != NULL, NULL);
262 g_return_val_if_fail (bg != NULL, NULL);
263 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
264 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
267 window = _gdk_parent_root;
269 if (GDK_WINDOW_DESTROYED (window))
273 depth = gdk_drawable_get_visual (window)->depth;
275 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
276 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
277 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
278 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
280 pix_impl->is_foreign = FALSE;
281 pix_impl->width = width;
282 pix_impl->height = height;
283 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
285 draw_impl->xdisplay = GDK_DRAWABLE_XDISPLAY (window);
286 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
287 GDK_WINDOW_XID (window),
288 (char *)data, width, height,
289 fg->pixel, bg->pixel, depth);
291 gdk_xid_table_insert (&draw_impl->xid, pixmap);
297 * gdk_pixmap_foreign_new:
298 * @anid: a native pixmap handle.
300 * Wraps a native window in a #GdkPixmap.
301 * This may fail if the pixmap has been destroyed.
303 * For example in the X backend, a native pixmap handle is an Xlib
306 * Return value: the newly-created #GdkPixmap wrapper for the
307 * native pixmap or %NULL if the pixmap has been destroyed.
310 gdk_pixmap_foreign_new (GdkNativeWindow anid)
313 GdkDrawableImplX11 *draw_impl;
314 GdkPixmapImplX11 *pix_impl;
318 unsigned int w_ret, h_ret, bw_ret, depth_ret;
320 /* check to make sure we were passed something at
321 least a little sane */
322 g_return_val_if_fail((anid != 0), NULL);
324 /* set the pixmap to the passed in value */
327 /* get information about the Pixmap to fill in the structure for
329 if (!XGetGeometry(GDK_DISPLAY(),
330 xpixmap, &root_return,
331 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
334 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
335 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
336 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
337 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
340 draw_impl->xdisplay = GDK_DISPLAY ();
341 draw_impl->xid = xpixmap;
343 pix_impl->is_foreign = TRUE;
344 pix_impl->width = w_ret;
345 pix_impl->height = h_ret;
346 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
348 gdk_xid_table_insert(&draw_impl->xid, pixmap);
355 * @anid: a native pixmap handle.
357 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
359 * For example in the X backend, a native pixmap handle is an Xlib
362 * Return value: the #GdkWindow wrapper for the native window,
363 * or %NULL if there is none.
366 gdk_pixmap_lookup (GdkNativeWindow anid)
368 return (GdkPixmap*) gdk_xid_table_lookup (anid);