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 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;
153 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
154 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
155 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
158 window = gdk_parent_root;
160 if (GDK_WINDOW_DESTROYED (window))
164 depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
166 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
167 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
168 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
169 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
171 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
172 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
173 GDK_WINDOW_XID (window),
174 width, height, depth);
176 pix_impl->is_foreign = FALSE;
177 pix_impl->width = width;
178 pix_impl->height = height;
179 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
181 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
187 gdk_bitmap_create_from_data (GdkWindow *window,
193 GdkDrawableImplX11 *draw_impl;
194 GdkPixmapImplX11 *pix_impl;
196 g_return_val_if_fail (data != NULL, NULL);
197 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
198 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
201 window = gdk_parent_root;
203 if (GDK_WINDOW_DESTROYED (window))
206 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
207 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
208 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
209 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
211 pix_impl->is_foreign = FALSE;
212 pix_impl->width = width;
213 pix_impl->height = height;
214 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
216 draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (window);
217 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
218 GDK_WINDOW_XID (window),
219 (char *)data, width, height);
221 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
227 gdk_pixmap_create_from_data (GdkWindow *window,
236 GdkDrawableImplX11 *draw_impl;
237 GdkPixmapImplX11 *pix_impl;
239 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
240 g_return_val_if_fail (data != NULL, NULL);
241 g_return_val_if_fail (fg != NULL, NULL);
242 g_return_val_if_fail (bg != NULL, NULL);
243 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
244 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
247 window = gdk_parent_root;
249 if (GDK_WINDOW_DESTROYED (window))
253 depth = gdk_drawable_get_visual (window)->depth;
255 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
256 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
257 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
258 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
260 pix_impl->is_foreign = FALSE;
261 pix_impl->width = width;
262 pix_impl->height = height;
263 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
265 draw_impl->xdisplay = GDK_DRAWABLE_XDISPLAY (window);
266 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
267 GDK_WINDOW_XID (window),
268 (char *)data, width, height,
269 fg->pixel, bg->pixel, depth);
271 gdk_xid_table_insert (&GDK_PIXMAP_XID (pixmap), pixmap);
277 gdk_pixmap_foreign_new (GdkNativeWindow anid)
280 GdkDrawableImplX11 *draw_impl;
281 GdkPixmapImplX11 *pix_impl;
284 unsigned int x_ret, y_ret, w_ret, h_ret, bw_ret, depth_ret;
286 /* check to make sure we were passed something at
287 least a little sane */
288 g_return_val_if_fail((anid != 0), NULL);
290 /* set the pixmap to the passed in value */
293 /* get information about the Pixmap to fill in the structure for
295 if (!XGetGeometry(GDK_DISPLAY(),
296 xpixmap, &root_return,
297 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
300 pixmap = GDK_PIXMAP (g_type_create_instance (gdk_pixmap_get_type ()));
301 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
302 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
303 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
306 draw_impl->xdisplay = GDK_DISPLAY ();
307 draw_impl->xid = xpixmap;
309 pix_impl->is_foreign = TRUE;
310 pix_impl->width = w_ret;
311 pix_impl->height = h_ret;
312 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
314 gdk_xid_table_insert(&GDK_PIXMAP_XID (pixmap), pixmap);