]> Pileus Git - ~andy/gtk/blob - gdk/gdkpixmap.c
gdk: Remove gdk_windowing_create_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
33
34 static void   gdk_pixmap_real_get_size  (GdkDrawable     *drawable,
35                                          gint            *width,
36                                          gint            *height);
37
38 static cairo_surface_t *gdk_pixmap_ref_cairo_surface (GdkDrawable *drawable);
39 static cairo_surface_t *gdk_pixmap_create_cairo_surface (GdkDrawable *drawable,
40                                                          int width,
41                                                          int height);
42
43 static GdkVisual*   gdk_pixmap_real_get_visual   (GdkDrawable *drawable);
44 static gint         gdk_pixmap_real_get_depth    (GdkDrawable *drawable);
45 static void         gdk_pixmap_real_set_colormap (GdkDrawable *drawable,
46                                                   GdkColormap *cmap);
47 static GdkColormap* gdk_pixmap_real_get_colormap (GdkDrawable *drawable);
48 static GdkScreen*   gdk_pixmap_real_get_screen   (GdkDrawable *drawable);
49
50 static void gdk_pixmap_init       (GdkPixmapObject      *pixmap);
51 static void gdk_pixmap_class_init (GdkPixmapObjectClass *klass);
52 static void gdk_pixmap_finalize   (GObject              *object);
53
54 static gpointer parent_class = NULL;
55
56 GType
57 gdk_pixmap_get_type (void)
58 {
59   static GType object_type = 0;
60
61   if (!object_type)
62     object_type = g_type_register_static_simple (GDK_TYPE_DRAWABLE,
63                                                  "GdkPixmap",
64                                                  sizeof (GdkPixmapObjectClass),
65                                                  (GClassInitFunc) gdk_pixmap_class_init,
66                                                  sizeof (GdkPixmapObject),
67                                                  (GInstanceInitFunc) gdk_pixmap_init,
68                                                  0);
69   
70   return object_type;
71 }
72
73 static void
74 gdk_pixmap_init (GdkPixmapObject *pixmap)
75 {
76   /* 0-initialization is good for all other fields. */
77   pixmap->impl = g_object_new (_gdk_pixmap_impl_get_type (), NULL);
78 }
79
80 static void
81 gdk_pixmap_class_init (GdkPixmapObjectClass *klass)
82 {
83   GObjectClass *object_class = G_OBJECT_CLASS (klass);
84   GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
85   
86   parent_class = g_type_class_peek_parent (klass);
87
88   object_class->finalize = gdk_pixmap_finalize;
89
90   drawable_class->get_depth = gdk_pixmap_real_get_depth;
91   drawable_class->get_screen = gdk_pixmap_real_get_screen;
92   drawable_class->get_size = gdk_pixmap_real_get_size;
93   drawable_class->set_colormap = gdk_pixmap_real_set_colormap;
94   drawable_class->get_colormap = gdk_pixmap_real_get_colormap;
95   drawable_class->get_visual = gdk_pixmap_real_get_visual;
96   drawable_class->ref_cairo_surface = gdk_pixmap_ref_cairo_surface;
97   drawable_class->create_cairo_surface = gdk_pixmap_create_cairo_surface;
98 }
99
100 static void
101 gdk_pixmap_finalize (GObject *object)
102 {
103   GdkPixmapObject *obj = (GdkPixmapObject *) object;
104
105   g_object_unref (obj->impl);
106   obj->impl = NULL;
107   
108   G_OBJECT_CLASS (parent_class)->finalize (object);
109 }
110
111 GdkPixmap *
112 gdk_pixmap_new (GdkDrawable *drawable,
113                 gint         width,
114                 gint         height,
115                 gint         depth)
116 {
117   GdkDrawable *source_drawable;
118
119   if (drawable)
120     source_drawable = _gdk_drawable_get_source_drawable (drawable);
121   else
122     source_drawable = NULL;
123   return _gdk_pixmap_new (source_drawable, width, height, depth);
124 }
125
126 static void
127 gdk_pixmap_real_get_size (GdkDrawable *drawable,
128                           gint *width,
129                           gint *height)
130 {
131   g_return_if_fail (GDK_IS_PIXMAP (drawable));
132
133   gdk_drawable_get_size (GDK_DRAWABLE (((GdkPixmapObject*)drawable)->impl),
134                          width, height);
135 }
136
137 static GdkVisual*
138 gdk_pixmap_real_get_visual (GdkDrawable *drawable)
139 {
140   GdkColormap *colormap;
141
142   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), NULL);
143
144   colormap = gdk_drawable_get_colormap (drawable);
145   return colormap ? gdk_colormap_get_visual (colormap) : NULL;
146 }
147
148 static gint
149 gdk_pixmap_real_get_depth (GdkDrawable *drawable)
150 {
151   gint depth;
152   
153   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), 0);
154
155   depth = GDK_PIXMAP_OBJECT (drawable)->depth;
156
157   return depth;
158 }
159
160 static void
161 gdk_pixmap_real_set_colormap (GdkDrawable *drawable,
162                               GdkColormap *cmap)
163 {
164   g_return_if_fail (GDK_IS_PIXMAP (drawable));  
165   
166   gdk_drawable_set_colormap (((GdkPixmapObject*)drawable)->impl, cmap);
167 }
168
169 static GdkColormap*
170 gdk_pixmap_real_get_colormap (GdkDrawable *drawable)
171 {
172   g_return_val_if_fail (GDK_IS_PIXMAP (drawable), NULL);
173   
174   return gdk_drawable_get_colormap (((GdkPixmapObject*)drawable)->impl);
175 }
176
177 static cairo_surface_t *
178 gdk_pixmap_ref_cairo_surface (GdkDrawable *drawable)
179 {
180   return _gdk_drawable_ref_cairo_surface (((GdkPixmapObject*)drawable)->impl);
181 }
182
183 static cairo_surface_t *
184 gdk_pixmap_create_cairo_surface (GdkDrawable *drawable,
185                                  int width,
186                                  int height)
187 {
188   return _gdk_drawable_create_cairo_surface (GDK_PIXMAP_OBJECT(drawable)->impl,
189                                              width, height);
190 }
191
192 static GdkScreen*
193 gdk_pixmap_real_get_screen (GdkDrawable *drawable)
194 {
195     return gdk_drawable_get_screen (GDK_PIXMAP_OBJECT (drawable)->impl);
196 }