]> Pileus Git - ~andy/gtk/blob - gdk/gdkpixmap.c
Switch set_cairo_target() virtual function to ref_cairo_surface()
[~andy/gtk] / gdk / gdkpixmap.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include <config.h>
28 #include "gdkpixmap.h"
29 #include "gdkinternals.h"
30 #include "gdkpixbuf.h"
31 #include "gdkscreen.h"
32 #include "gdkalias.h"
33
34 static GdkGC *gdk_pixmap_create_gc      (GdkDrawable     *drawable,
35                                          GdkGCValues     *values,
36                                          GdkGCValuesMask  mask);
37 static void   gdk_pixmap_draw_rectangle (GdkDrawable     *drawable,
38                                          GdkGC           *gc,
39                                          gboolean         filled,
40                                          gint             x,
41                                          gint             y,
42                                          gint             width,
43                                          gint             height);
44 static void   gdk_pixmap_draw_arc       (GdkDrawable     *drawable,
45                                          GdkGC           *gc,
46                                          gboolean         filled,
47                                          gint             x,
48                                          gint             y,
49                                          gint             width,
50                                          gint             height,
51                                          gint             angle1,
52                                          gint             angle2);
53 static void   gdk_pixmap_draw_polygon   (GdkDrawable     *drawable,
54                                          GdkGC           *gc,
55                                          gboolean         filled,
56                                          GdkPoint        *points,
57                                          gint             npoints);
58 static void   gdk_pixmap_draw_text      (GdkDrawable     *drawable,
59                                          GdkFont         *font,
60                                          GdkGC           *gc,
61                                          gint             x,
62                                          gint             y,
63                                          const gchar     *text,
64                                          gint             text_length);
65 static void   gdk_pixmap_draw_text_wc   (GdkDrawable     *drawable,
66                                          GdkFont         *font,
67                                          GdkGC           *gc,
68                                          gint             x,
69                                          gint             y,
70                                          const GdkWChar  *text,
71                                          gint             text_length);
72 static void   gdk_pixmap_draw_drawable  (GdkDrawable     *drawable,
73                                          GdkGC           *gc,
74                                          GdkPixmap       *src,
75                                          gint             xsrc,
76                                          gint             ysrc,
77                                          gint             xdest,
78                                          gint             ydest,
79                                          gint             width,
80                                          gint             height);
81 static void   gdk_pixmap_draw_points    (GdkDrawable     *drawable,
82                                          GdkGC           *gc,
83                                          GdkPoint        *points,
84                                          gint             npoints);
85 static void   gdk_pixmap_draw_segments  (GdkDrawable     *drawable,
86                                          GdkGC           *gc,
87                                          GdkSegment      *segs,
88                                          gint             nsegs);
89 static void   gdk_pixmap_draw_lines     (GdkDrawable     *drawable,
90                                          GdkGC           *gc,
91                                          GdkPoint        *points,
92                                          gint             npoints);
93
94 static void gdk_pixmap_draw_glyphs             (GdkDrawable      *drawable,
95                                                 GdkGC            *gc,
96                                                 PangoFont        *font,
97                                                 gint              x,
98                                                 gint              y,
99                                                 PangoGlyphString *glyphs);
100 static void gdk_pixmap_draw_glyphs_transformed (GdkDrawable      *drawable,
101                                                 GdkGC            *gc,
102                                                 PangoMatrix      *matrix,
103                                                 PangoFont        *font,
104                                                 gint              x,
105                                                 gint              y,
106                                                 PangoGlyphString *glyphs);
107
108 static void   gdk_pixmap_draw_image     (GdkDrawable     *drawable,
109                                          GdkGC           *gc,
110                                          GdkImage        *image,
111                                          gint             xsrc,
112                                          gint             ysrc,
113                                          gint             xdest,
114                                          gint             ydest,
115                                          gint             width,
116                                          gint             height);
117 static void   gdk_pixmap_draw_pixbuf    (GdkDrawable     *drawable,
118                                          GdkGC           *gc,
119                                          GdkPixbuf       *pixbuf,
120                                          gint             src_x,
121                                          gint             src_y,
122                                          gint             dest_x,
123                                          gint             dest_y,
124                                          gint             width,
125                                          gint             height,
126                                          GdkRgbDither     dither,
127                                          gint             x_dither,
128                                          gint             y_dither);
129 static void  gdk_pixmap_draw_trapezoids (GdkDrawable     *drawable,
130                                          GdkGC           *gc,
131                                          GdkTrapezoid    *trapezoids,
132                                          gint             n_trapezoids);
133
134 static void   gdk_pixmap_real_get_size  (GdkDrawable     *drawable,
135                                          gint            *width,
136                                          gint            *height);
137
138 static GdkImage* gdk_pixmap_copy_to_image (GdkDrawable *drawable,
139                                            GdkImage    *image,
140                                            gint         src_x,
141                                            gint         src_y,
142                                            gint         dest_x,
143                                            gint         dest_y,
144                                            gint         width,
145                                            gint         height);
146
147 static cairo_surface_t *gdk_pixmap_ref_cairo_surface (GdkDrawable *drawable);
148
149 static GdkVisual*   gdk_pixmap_real_get_visual   (GdkDrawable *drawable);
150 static gint         gdk_pixmap_real_get_depth    (GdkDrawable *drawable);
151 static void         gdk_pixmap_real_set_colormap (GdkDrawable *drawable,
152                                                   GdkColormap *cmap);
153 static GdkColormap* gdk_pixmap_real_get_colormap (GdkDrawable *drawable);
154 static GdkScreen*   gdk_pixmap_real_get_screen   (GdkDrawable *drawable);
155
156 static void gdk_pixmap_init       (GdkPixmapObject      *pixmap);
157 static void gdk_pixmap_class_init (GdkPixmapObjectClass *klass);
158 static void gdk_pixmap_finalize   (GObject              *object);
159
160 static gpointer parent_class = NULL;
161
162 GType
163 gdk_pixmap_get_type (void)
164 {
165   static GType object_type = 0;
166
167   if (!object_type)
168     {
169       static const GTypeInfo object_info =
170       {
171         sizeof (GdkPixmapObjectClass),
172         (GBaseInitFunc) NULL,
173         (GBaseFinalizeFunc) NULL,
174         (GClassInitFunc) gdk_pixmap_class_init,
175         NULL,           /* class_finalize */
176         NULL,           /* class_data */
177         sizeof (GdkPixmapObject),
178         0,              /* n_preallocs */
179         (GInstanceInitFunc) gdk_pixmap_init,
180       };
181       
182       object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
183                                             "GdkPixmap",
184                                             &object_info, 0);
185     }
186   
187   return object_type;
188 }
189
190 static void
191 gdk_pixmap_init (GdkPixmapObject *pixmap)
192 {
193   /* 0-initialization is good for all other fields. */
194   pixmap->impl = g_object_new (_gdk_pixmap_impl_get_type (), NULL);
195 }
196
197 static void
198 gdk_pixmap_class_init (GdkPixmapObjectClass *klass)
199 {
200   GObjectClass *object_class = G_OBJECT_CLASS (klass);
201   GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
202   
203   parent_class = g_type_class_peek_parent (klass);
204
205   object_class->finalize = gdk_pixmap_finalize;
206
207   drawable_class->create_gc = gdk_pixmap_create_gc;
208   drawable_class->draw_rectangle = gdk_pixmap_draw_rectangle;
209   drawable_class->draw_arc = gdk_pixmap_draw_arc;
210   drawable_class->draw_polygon = gdk_pixmap_draw_polygon;
211   drawable_class->draw_text = gdk_pixmap_draw_text;
212   drawable_class->draw_text_wc = gdk_pixmap_draw_text_wc;
213   drawable_class->draw_drawable = gdk_pixmap_draw_drawable;
214   drawable_class->draw_points = gdk_pixmap_draw_points;
215   drawable_class->draw_segments = gdk_pixmap_draw_segments;
216   drawable_class->draw_lines = gdk_pixmap_draw_lines;
217   drawable_class->draw_glyphs = gdk_pixmap_draw_glyphs;
218   drawable_class->draw_glyphs_transformed = gdk_pixmap_draw_glyphs_transformed;
219   drawable_class->draw_image = gdk_pixmap_draw_image;
220   drawable_class->draw_pixbuf = gdk_pixmap_draw_pixbuf;
221   drawable_class->draw_trapezoids = gdk_pixmap_draw_trapezoids;
222   drawable_class->get_depth = gdk_pixmap_real_get_depth;
223   drawable_class->get_screen = gdk_pixmap_real_get_screen;
224   drawable_class->get_size = gdk_pixmap_real_get_size;
225   drawable_class->set_colormap = gdk_pixmap_real_set_colormap;
226   drawable_class->get_colormap = gdk_pixmap_real_get_colormap;
227   drawable_class->get_visual = gdk_pixmap_real_get_visual;
228   drawable_class->_copy_to_image = gdk_pixmap_copy_to_image;
229   drawable_class->ref_cairo_surface = gdk_pixmap_ref_cairo_surface;
230 }
231
232 static void
233 gdk_pixmap_finalize (GObject *object)
234 {
235   GdkPixmapObject *obj = (GdkPixmapObject *) object;
236
237   g_object_unref (obj->impl);
238   obj->impl = NULL;
239   
240   G_OBJECT_CLASS (parent_class)->finalize (object);
241 }
242
243 static GdkGC *
244 gdk_pixmap_create_gc (GdkDrawable     *drawable,
245                       GdkGCValues     *values,
246                       GdkGCValuesMask  mask)
247 {
248   return gdk_gc_new_with_values (((GdkPixmapObject *) drawable)->impl,
249                                  values, mask);
250 }
251
252 static void
253 gdk_pixmap_draw_rectangle (GdkDrawable *drawable,
254                            GdkGC       *gc,
255                            gboolean     filled,
256                            gint         x,
257                            gint         y,
258                            gint         width,
259                            gint         height)
260 {
261   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
262
263   gdk_draw_rectangle (private->impl, gc, filled,
264                       x, y, width, height);
265 }
266
267 static void
268 gdk_pixmap_draw_arc (GdkDrawable *drawable,
269                      GdkGC       *gc,
270                      gboolean     filled,
271                      gint         x,
272                      gint         y,
273                      gint         width,
274                      gint         height,
275                      gint         angle1,
276                      gint         angle2)
277 {
278   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
279
280   gdk_draw_arc (private->impl, gc, filled,
281                 x, y,
282                 width, height, angle1, angle2);
283 }
284
285 static void
286 gdk_pixmap_draw_polygon (GdkDrawable *drawable,
287                          GdkGC       *gc,
288                          gboolean     filled,
289                          GdkPoint    *points,
290                          gint         npoints)
291 {
292   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
293
294   gdk_draw_polygon (private->impl, gc, filled, points, npoints);
295 }
296
297 static void
298 gdk_pixmap_draw_text (GdkDrawable *drawable,
299                       GdkFont     *font,
300                       GdkGC       *gc,
301                       gint         x,
302                       gint         y,
303                       const gchar *text,
304                       gint         text_length)
305 {
306   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
307
308   gdk_draw_text (private->impl, font, gc,
309                  x, y, text, text_length);
310 }
311
312 static void
313 gdk_pixmap_draw_text_wc (GdkDrawable    *drawable,
314                          GdkFont        *font,
315                          GdkGC          *gc,
316                          gint            x,
317                          gint            y,
318                          const GdkWChar *text,
319                          gint            text_length)
320 {
321   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
322
323   gdk_draw_text_wc (private->impl, font, gc,
324                     x, y, text, text_length);
325 }
326
327 static void
328 gdk_pixmap_draw_drawable (GdkDrawable *drawable,
329                           GdkGC       *gc,
330                           GdkPixmap   *src,
331                           gint         xsrc,
332                           gint         ysrc,
333                           gint         xdest,
334                           gint         ydest,
335                           gint         width,
336                           gint         height)
337 {
338   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
339
340   gdk_draw_drawable (private->impl, gc, src, xsrc, ysrc,
341                      xdest, ydest,
342                      width, height);
343 }
344
345 static void
346 gdk_pixmap_draw_points (GdkDrawable *drawable,
347                         GdkGC       *gc,
348                         GdkPoint    *points,
349                         gint         npoints)
350 {
351   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
352
353   gdk_draw_points (private->impl, gc, points, npoints);
354 }
355
356 static void
357 gdk_pixmap_draw_segments (GdkDrawable *drawable,
358                           GdkGC       *gc,
359                           GdkSegment  *segs,
360                           gint         nsegs)
361 {
362   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
363
364   gdk_draw_segments (private->impl, gc, segs, nsegs);
365 }
366
367 static void
368 gdk_pixmap_draw_lines (GdkDrawable *drawable,
369                        GdkGC       *gc,
370                        GdkPoint    *points,
371                        gint         npoints)
372 {
373   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
374
375   gdk_draw_lines (private->impl, gc, points, npoints);
376 }
377
378 static void
379 gdk_pixmap_draw_glyphs (GdkDrawable      *drawable,
380                         GdkGC            *gc,
381                         PangoFont        *font,
382                         gint              x,
383                         gint              y,
384                         PangoGlyphString *glyphs)
385 {
386   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
387
388   gdk_draw_glyphs (private->impl, gc, font, x, y, glyphs);
389 }
390
391 static void
392 gdk_pixmap_draw_glyphs_transformed (GdkDrawable      *drawable,
393                                     GdkGC            *gc,
394                                     PangoMatrix      *matrix,
395                                     PangoFont        *font,
396                                     gint              x,
397                                     gint              y,
398                                     PangoGlyphString *glyphs)
399 {
400   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
401
402   gdk_draw_glyphs_transformed (private->impl, gc, matrix, font, x, y, glyphs);
403 }
404
405 static void
406 gdk_pixmap_draw_image (GdkDrawable     *drawable,
407                        GdkGC           *gc,
408                        GdkImage        *image,
409                        gint             xsrc,
410                        gint             ysrc,
411                        gint             xdest,
412                        gint             ydest,
413                        gint             width,
414                        gint             height)
415 {
416   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
417
418   gdk_draw_image (private->impl, gc, image, xsrc, ysrc, xdest, ydest,
419                   width, height);
420 }
421
422 static void
423 gdk_pixmap_draw_pixbuf (GdkDrawable     *drawable,
424                         GdkGC           *gc,
425                         GdkPixbuf       *pixbuf,
426                         gint             src_x,
427                         gint             src_y,
428                         gint             dest_x,
429                         gint             dest_y,
430                         gint             width,
431                         gint             height,
432                         GdkRgbDither     dither,
433                         gint             x_dither,
434                         gint             y_dither)
435 {
436   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
437
438   gdk_draw_pixbuf (private->impl, gc, pixbuf,
439                    src_x, src_y, dest_x, dest_y, width, height,
440                    dither, x_dither, y_dither);
441 }
442
443 static void
444 gdk_pixmap_draw_trapezoids (GdkDrawable     *drawable,
445                             GdkGC           *gc,
446                             GdkTrapezoid    *trapezoids,
447                             gint             n_trapezoids)
448 {
449   GdkPixmapObject *private = (GdkPixmapObject *)drawable;
450
451   gdk_draw_trapezoids (private->impl, gc, trapezoids, n_trapezoids);
452 }
453
454 static void
455 gdk_pixmap_real_get_size (GdkDrawable *drawable,
456                           gint *width,
457                           gint *height)
458 {
459   g_return_if_fail (GDK_IS_PIXMAP (drawable));
460
461   gdk_drawable_get_size (GDK_DRAWABLE (((GdkPixmapObject*)drawable)->impl),
462                          width, height);
463 }
464
465 static GdkVisual*
466 gdk_pixmap_real_get_visual (GdkDrawable *drawable)
467 {
468   GdkColormap *colormap;
469
470   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), NULL);
471
472   colormap = gdk_drawable_get_colormap (drawable);
473   return colormap ? gdk_colormap_get_visual (colormap) : NULL;
474 }
475
476 static gint
477 gdk_pixmap_real_get_depth (GdkDrawable *drawable)
478 {
479   gint depth;
480   
481   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), 0);
482
483   depth = GDK_PIXMAP_OBJECT (drawable)->depth;
484
485   return depth;
486 }
487
488 static void
489 gdk_pixmap_real_set_colormap (GdkDrawable *drawable,
490                               GdkColormap *cmap)
491 {
492   g_return_if_fail (GDK_IS_PIXMAP (drawable));  
493   
494   gdk_drawable_set_colormap (((GdkPixmapObject*)drawable)->impl, cmap);
495 }
496
497 static GdkColormap*
498 gdk_pixmap_real_get_colormap (GdkDrawable *drawable)
499 {
500   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), NULL);
501   
502   return gdk_drawable_get_colormap (((GdkPixmapObject*)drawable)->impl);
503 }
504
505 static GdkImage*
506 gdk_pixmap_copy_to_image (GdkDrawable     *drawable,
507                           GdkImage        *image,
508                           gint             src_x,
509                           gint             src_y,
510                           gint             dest_x,
511                           gint             dest_y,
512                           gint             width,
513                           gint             height)
514 {
515   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), NULL);
516   
517   return gdk_drawable_copy_to_image (((GdkPixmapObject*)drawable)->impl,
518                                      image,
519                                      src_x, src_y, dest_x, dest_y,
520                                      width, height);
521 }
522
523 static cairo_surface_t *
524 gdk_pixmap_ref_cairo_surface (GdkDrawable *drawable)
525 {
526   return _gdk_drawable_ref_cairo_surface (((GdkPixmapObject*)drawable)->impl);
527 }
528
529 static GdkBitmap *
530 make_solid_mask (GdkScreen *screen, gint width, gint height)
531 {
532   GdkBitmap *bitmap;
533   GdkGC *gc;
534   GdkGCValues gc_values;
535   
536   bitmap = gdk_pixmap_new (gdk_screen_get_root_window (screen),
537                            width, height, 1);
538
539   gc_values.foreground.pixel = 1;
540   gc = gdk_gc_new_with_values (bitmap, &gc_values, GDK_GC_FOREGROUND);
541   
542   gdk_draw_rectangle (bitmap, gc, TRUE, 0, 0, width, height);
543   
544   g_object_unref (gc);
545   
546   return bitmap;
547 }
548
549 #define PACKED_COLOR(c) ((((c)->red   & 0xff00)  << 8) |   \
550                           ((c)->green & 0xff00)        |   \
551                           ((c)->blue             >> 8))
552
553 static GdkPixmap *
554 gdk_pixmap_colormap_new_from_pixbuf (GdkColormap    *colormap,
555                                      GdkBitmap     **mask,
556                                      const GdkColor *transparent_color,
557                                      GdkPixbuf      *pixbuf)
558 {
559   GdkPixmap *pixmap;
560   GdkPixbuf *render_pixbuf;
561   GdkGC *tmp_gc;
562   GdkScreen *screen = gdk_colormap_get_screen (colormap);
563   
564   pixmap = gdk_pixmap_new (gdk_screen_get_root_window (screen),
565                            gdk_pixbuf_get_width (pixbuf),
566                            gdk_pixbuf_get_height (pixbuf),
567                            gdk_colormap_get_visual (colormap)->depth);
568   gdk_drawable_set_colormap (pixmap, colormap);
569   
570   if (transparent_color)
571     {
572       guint32 packed_color = PACKED_COLOR (transparent_color);
573       render_pixbuf = gdk_pixbuf_composite_color_simple (pixbuf,
574                                                          gdk_pixbuf_get_width (pixbuf),
575                                                          gdk_pixbuf_get_height (pixbuf),
576                                                          GDK_INTERP_NEAREST,
577                                                          255, 16, packed_color, packed_color);
578     }
579   else
580     render_pixbuf = pixbuf;
581
582   tmp_gc = _gdk_drawable_get_scratch_gc (pixmap, FALSE);
583   gdk_draw_pixbuf (pixmap, tmp_gc, render_pixbuf, 0, 0, 0, 0,
584                    gdk_pixbuf_get_width (render_pixbuf),
585                    gdk_pixbuf_get_height (render_pixbuf),
586                    GDK_RGB_DITHER_NORMAL, 0, 0);
587
588   if (render_pixbuf != pixbuf)
589     g_object_unref (render_pixbuf);
590
591   if (mask)
592     gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf, colormap, NULL, mask, 128);
593
594   if (mask && !*mask)
595     *mask = make_solid_mask (screen,
596                              gdk_pixbuf_get_width (pixbuf),
597                              gdk_pixbuf_get_height (pixbuf));
598
599   return pixmap;
600 }
601
602 GdkPixmap*
603 gdk_pixmap_colormap_create_from_xpm (GdkDrawable    *drawable,
604                                      GdkColormap    *colormap,
605                                      GdkBitmap     **mask,
606                                      const GdkColor *transparent_color,
607                                      const gchar    *filename)
608 {
609   GdkPixbuf *pixbuf;
610   GdkPixmap *pixmap;
611
612   g_return_val_if_fail (drawable != NULL || colormap != NULL, NULL);
613   g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
614   g_return_val_if_fail (colormap == NULL || GDK_IS_COLORMAP (colormap), NULL);
615
616   if (colormap == NULL)
617     colormap = gdk_drawable_get_colormap (drawable);
618   
619   pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
620   if (!pixbuf)
621     return NULL;
622
623   pixmap = gdk_pixmap_colormap_new_from_pixbuf (colormap, mask, transparent_color, pixbuf);
624
625   g_object_unref (pixbuf);
626   
627   return pixmap;
628 }
629
630 GdkPixmap*
631 gdk_pixmap_create_from_xpm (GdkDrawable    *drawable,
632                             GdkBitmap     **mask,
633                             const GdkColor *transparent_color,
634                             const gchar    *filename)
635 {
636   return gdk_pixmap_colormap_create_from_xpm (drawable, NULL, mask,
637                                               transparent_color, filename);
638 }
639
640 GdkPixmap*
641 gdk_pixmap_colormap_create_from_xpm_d (GdkDrawable    *drawable,
642                                        GdkColormap    *colormap,
643                                        GdkBitmap     **mask,
644                                        const GdkColor *transparent_color,
645                                        gchar         **data)
646 {
647   GdkPixbuf *pixbuf;
648   GdkPixmap *pixmap;
649
650   g_return_val_if_fail (drawable != NULL || colormap != NULL, NULL);
651   g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
652   g_return_val_if_fail (colormap == NULL || GDK_IS_COLORMAP (colormap), NULL);
653
654   if (colormap == NULL)
655     colormap = gdk_drawable_get_colormap (drawable);
656   
657   pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)data);
658   if (!pixbuf)
659     return NULL;
660
661   pixmap = gdk_pixmap_colormap_new_from_pixbuf (colormap, mask, transparent_color, pixbuf);
662
663   g_object_unref (pixbuf);
664
665   return pixmap;
666 }
667
668 GdkPixmap*
669 gdk_pixmap_create_from_xpm_d (GdkDrawable    *drawable,
670                               GdkBitmap     **mask,
671                               const GdkColor *transparent_color,
672                               gchar         **data)
673 {
674   return gdk_pixmap_colormap_create_from_xpm_d (drawable, NULL, mask,
675                                                 transparent_color, data);
676 }
677
678 static GdkScreen*
679 gdk_pixmap_real_get_screen (GdkDrawable *drawable)
680 {
681     return gdk_drawable_get_screen (GDK_PIXMAP_OBJECT (drawable)->impl);
682 }
683
684 #define __GDK_PIXMAP_C__
685 #include "gdkaliasdef.c"