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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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-1999. 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 XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
125 gdk_xid_table_remove (GDK_PIXMAP_XID (wrapper));
127 G_OBJECT_CLASS (parent_class)->finalize (object);
131 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
136 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
138 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
142 gdk_pixmap_new (GdkWindow *window,
148 GdkDrawableImplX11 *draw_impl;
149 GdkPixmapImplX11 *pix_impl;
151 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
152 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
153 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
156 window = gdk_parent_root;
158 if (GDK_WINDOW_DESTROYED (window))
162 depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
164 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
165 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
166 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
167 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
169 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
170 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
171 GDK_WINDOW_XID (window),
172 width, height, depth);
174 pix_impl->width = width;
175 pix_impl->height = height;
176 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
178 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
184 gdk_bitmap_create_from_data (GdkWindow *window,
190 GdkDrawableImplX11 *draw_impl;
191 GdkPixmapImplX11 *pix_impl;
193 g_return_val_if_fail (data != NULL, NULL);
194 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
195 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
198 window = gdk_parent_root;
200 if (GDK_WINDOW_DESTROYED (window))
203 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
204 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
205 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
206 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
208 pix_impl->width = width;
209 pix_impl->height = height;
210 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
212 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
213 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
214 GDK_WINDOW_XID (window),
215 (char *)data, width, height);
217 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
223 gdk_pixmap_create_from_data (GdkWindow *window,
232 GdkDrawableImplX11 *draw_impl;
233 GdkPixmapImplX11 *pix_impl;
235 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
236 g_return_val_if_fail (data != NULL, NULL);
237 g_return_val_if_fail (fg != NULL, NULL);
238 g_return_val_if_fail (bg != NULL, NULL);
239 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
240 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
243 window = gdk_parent_root;
245 if (GDK_WINDOW_DESTROYED (window))
249 depth = gdk_drawable_get_visual (window)->depth;
251 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
252 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
253 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
254 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
256 pix_impl->width = width;
257 pix_impl->height = height;
258 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
260 draw_impl->xdisplay = GDK_DRAWABLE_XDISPLAY (window);
261 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
262 GDK_WINDOW_XID (window),
263 (char *)data, width, height,
264 fg->pixel, bg->pixel, depth);
266 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
272 gdk_pixmap_foreign_new (GdkNativeWindow anid)
275 GdkDrawableImplX11 *draw_impl;
276 GdkPixmapImplX11 *pix_impl;
279 unsigned int x_ret, y_ret, w_ret, h_ret, bw_ret, depth_ret;
281 /* check to make sure we were passed something at
282 least a little sane */
283 g_return_val_if_fail((anid != 0), NULL);
285 /* set the pixmap to the passed in value */
288 /* get information about the Pixmap to fill in the structure for
290 if (!XGetGeometry(GDK_DISPLAY(),
291 xpixmap, &root_return,
292 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
295 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
296 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
297 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
298 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
301 draw_impl->xdisplay = GDK_DISPLAY ();
302 draw_impl->xid = xpixmap;
304 pix_impl->width = w_ret;
305 pix_impl->height = h_ret;
306 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
308 gdk_xid_table_insert(&GDK_PIXMAP_XID (pixmap), pixmap);