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