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);
125 if (!impl->is_foreign)
126 XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
128 gdk_xid_table_remove (GDK_PIXMAP_XID (wrapper));
130 G_OBJECT_CLASS (parent_class)->finalize (object);
134 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
139 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
141 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
145 gdk_pixmap_new (GdkWindow *window,
151 GdkDrawableImplX11 *draw_impl;
152 GdkPixmapImplX11 *pix_impl;
156 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
157 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
158 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
161 window = _gdk_parent_root;
163 if (GDK_WINDOW_DESTROYED (window))
166 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
168 depth = window_depth;
170 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
171 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
172 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
173 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
175 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
176 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
177 GDK_WINDOW_XID (window),
178 width, height, depth);
180 pix_impl->is_foreign = FALSE;
181 pix_impl->width = width;
182 pix_impl->height = height;
183 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
185 if (depth == window_depth)
187 cmap = gdk_drawable_get_colormap (window);
189 gdk_drawable_set_colormap (pixmap, cmap);
192 gdk_xid_table_insert (&draw_impl->xid, pixmap);
198 gdk_bitmap_create_from_data (GdkWindow *window,
204 GdkDrawableImplX11 *draw_impl;
205 GdkPixmapImplX11 *pix_impl;
207 g_return_val_if_fail (data != NULL, NULL);
208 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
209 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
212 window = _gdk_parent_root;
214 if (GDK_WINDOW_DESTROYED (window))
217 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
218 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
219 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
220 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
222 pix_impl->is_foreign = FALSE;
223 pix_impl->width = width;
224 pix_impl->height = height;
225 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
227 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
228 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
229 GDK_WINDOW_XID (window),
230 (char *)data, width, height);
232 gdk_xid_table_insert (&draw_impl->xid, pixmap);
238 gdk_pixmap_create_from_data (GdkWindow *window,
247 GdkDrawableImplX11 *draw_impl;
248 GdkPixmapImplX11 *pix_impl;
250 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
251 g_return_val_if_fail (data != NULL, NULL);
252 g_return_val_if_fail (fg != NULL, NULL);
253 g_return_val_if_fail (bg != NULL, NULL);
254 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
255 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
258 window = _gdk_parent_root;
260 if (GDK_WINDOW_DESTROYED (window))
264 depth = gdk_drawable_get_visual (window)->depth;
266 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
267 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
268 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
269 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
271 pix_impl->is_foreign = FALSE;
272 pix_impl->width = width;
273 pix_impl->height = height;
274 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
276 draw_impl->xdisplay = GDK_DRAWABLE_XDISPLAY (window);
277 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
278 GDK_WINDOW_XID (window),
279 (char *)data, width, height,
280 fg->pixel, bg->pixel, depth);
282 gdk_xid_table_insert (&draw_impl->xid, pixmap);
288 * gdk_pixmap_foreign_new:
289 * @anid: an X window ID for a pixmap
291 * Creates a #GdkPixmap for the Xlib pixmap ID @anid.
292 * If the Xlib pixmap is destroyed while creating
293 * the #GdkPixmap, this function returns %NULL.
295 * Return value: a new #GdkPixmap
298 gdk_pixmap_foreign_new (GdkNativeWindow anid)
301 GdkDrawableImplX11 *draw_impl;
302 GdkPixmapImplX11 *pix_impl;
305 unsigned int x_ret, y_ret, w_ret, h_ret, bw_ret, depth_ret;
307 /* check to make sure we were passed something at
308 least a little sane */
309 g_return_val_if_fail((anid != 0), NULL);
311 /* set the pixmap to the passed in value */
314 /* get information about the Pixmap to fill in the structure for
316 if (!XGetGeometry(GDK_DISPLAY(),
317 xpixmap, &root_return,
318 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
321 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
322 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
323 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
324 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
327 draw_impl->xdisplay = GDK_DISPLAY ();
328 draw_impl->xid = xpixmap;
330 pix_impl->is_foreign = TRUE;
331 pix_impl->width = w_ret;
332 pix_impl->height = h_ret;
333 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
335 gdk_xid_table_insert(&draw_impl->xid, pixmap);