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