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 */
35 #include <gdk/gdkpixmap.h>
36 #include "gdkpixmap-x11.h"
37 #include "gdkprivate-x11.h"
49 GdkColormap *colormap;
53 static void gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
57 static void gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *pixmap);
58 static void gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass);
59 static void gdk_pixmap_impl_x11_finalize (GObject *object);
61 static gpointer parent_class = NULL;
64 gdk_pixmap_impl_x11_get_type (void)
66 static GType object_type = 0;
70 static const GTypeInfo object_info =
72 sizeof (GdkPixmapImplX11Class),
74 (GBaseFinalizeFunc) NULL,
75 (GClassInitFunc) gdk_pixmap_impl_x11_class_init,
76 NULL, /* class_finalize */
77 NULL, /* class_data */
78 sizeof (GdkPixmapImplX11),
80 (GInstanceInitFunc) gdk_pixmap_impl_x11_init,
83 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
93 _gdk_pixmap_impl_get_type (void)
95 return gdk_pixmap_impl_x11_get_type ();
99 gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *impl)
106 gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass)
108 GObjectClass *object_class = G_OBJECT_CLASS (klass);
109 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
111 parent_class = g_type_class_peek_parent (klass);
113 object_class->finalize = gdk_pixmap_impl_x11_finalize;
115 drawable_class->get_size = gdk_pixmap_impl_x11_get_size;
119 gdk_pixmap_impl_x11_finalize (GObject *object)
121 GdkPixmapImplX11 *impl = GDK_PIXMAP_IMPL_X11 (object);
122 GdkPixmap *wrapper = GDK_PIXMAP (GDK_DRAWABLE_IMPL_X11 (impl)->wrapper);
124 if (!impl->is_foreign)
125 XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
127 gdk_xid_table_remove (GDK_PIXMAP_XID (wrapper));
129 G_OBJECT_CLASS (parent_class)->finalize (object);
133 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
138 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
140 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
144 gdk_pixmap_new (GdkWindow *window,
150 GdkDrawableImplX11 *draw_impl;
151 GdkPixmapImplX11 *pix_impl;
154 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
155 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
156 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
159 window = gdk_parent_root;
161 if (GDK_WINDOW_DESTROYED (window))
165 depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
167 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
168 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
169 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
170 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
172 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
173 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
174 GDK_WINDOW_XID (window),
175 width, height, depth);
177 pix_impl->is_foreign = FALSE;
178 pix_impl->width = width;
179 pix_impl->height = height;
180 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
184 cmap = gdk_drawable_get_colormap (window);
186 gdk_drawable_set_colormap (pixmap, cmap);
189 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
195 gdk_bitmap_create_from_data (GdkWindow *window,
201 GdkDrawableImplX11 *draw_impl;
202 GdkPixmapImplX11 *pix_impl;
204 g_return_val_if_fail (data != NULL, NULL);
205 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
206 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
209 window = gdk_parent_root;
211 if (GDK_WINDOW_DESTROYED (window))
214 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
215 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
216 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
217 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
219 pix_impl->is_foreign = FALSE;
220 pix_impl->width = width;
221 pix_impl->height = height;
222 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
224 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
225 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
226 GDK_WINDOW_XID (window),
227 (char *)data, width, height);
229 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
235 gdk_pixmap_create_from_data (GdkWindow *window,
244 GdkDrawableImplX11 *draw_impl;
245 GdkPixmapImplX11 *pix_impl;
247 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
248 g_return_val_if_fail (data != NULL, NULL);
249 g_return_val_if_fail (fg != NULL, NULL);
250 g_return_val_if_fail (bg != NULL, NULL);
251 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
252 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
255 window = gdk_parent_root;
257 if (GDK_WINDOW_DESTROYED (window))
261 depth = gdk_drawable_get_visual (window)->depth;
263 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
264 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
265 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
266 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
268 pix_impl->is_foreign = FALSE;
269 pix_impl->width = width;
270 pix_impl->height = height;
271 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
273 draw_impl->xdisplay = GDK_DRAWABLE_XDISPLAY (window);
274 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
275 GDK_WINDOW_XID (window),
276 (char *)data, width, height,
277 fg->pixel, bg->pixel, depth);
279 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
285 gdk_pixmap_foreign_new (GdkNativeWindow anid)
288 GdkDrawableImplX11 *draw_impl;
289 GdkPixmapImplX11 *pix_impl;
292 unsigned int x_ret, y_ret, w_ret, h_ret, bw_ret, depth_ret;
294 /* check to make sure we were passed something at
295 least a little sane */
296 g_return_val_if_fail((anid != 0), NULL);
298 /* set the pixmap to the passed in value */
301 /* get information about the Pixmap to fill in the structure for
303 if (!XGetGeometry(GDK_DISPLAY(),
304 xpixmap, &root_return,
305 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
308 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
309 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
310 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
311 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
314 draw_impl->xdisplay = GDK_DISPLAY ();
315 draw_impl->xid = xpixmap;
317 pix_impl->is_foreign = TRUE;
318 pix_impl->width = w_ret;
319 pix_impl->height = h_ret;
320 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
322 gdk_xid_table_insert(&GDK_PIXMAP_XID (pixmap), pixmap);