]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkimage-quartz.c
Add escape to the list of special keys, to get the escape key working.
[~andy/gtk] / gdk / quartz / gdkimage-quartz.c
1 /* gdkimage-quartz.c
2  *
3  * Copyright (C) 2005 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22
23 #include "gdk.h"
24 #include "gdkimage.h"
25 #include "gdkprivate-quartz.h"
26
27 static GObjectClass *parent_class;
28
29 GdkImage *
30 _gdk_quartz_copy_to_image (GdkDrawable *drawable,
31                            GdkImage    *image,
32                            gint         src_x,
33                            gint         src_y,
34                            gint         dest_x,
35                            gint         dest_y,
36                            gint         width,
37                            gint         height)
38 {
39   /* FIXME: Implement */
40   return NULL;
41 }
42
43 static void
44 gdk_image_finalize (GObject *object)
45 {
46   GdkImage *image = GDK_IMAGE (object);
47
48   g_free (image->mem);
49
50   G_OBJECT_CLASS (parent_class)->finalize (object);
51 }
52
53 static void
54 gdk_image_class_init (GdkImageClass *klass)
55 {
56   GObjectClass *object_class = G_OBJECT_CLASS (klass);
57
58   parent_class = g_type_class_peek_parent (klass);
59   
60   object_class->finalize = gdk_image_finalize;
61 }
62
63 GType
64 gdk_image_get_type (void)
65 {
66   static GType object_type = 0;
67
68   if (!object_type)
69     {
70       static const GTypeInfo object_info =
71       {
72         sizeof (GdkImageClass),
73         (GBaseInitFunc) NULL,
74         (GBaseFinalizeFunc) NULL,
75         (GClassInitFunc) gdk_image_class_init,
76         NULL,           /* class_finalize */
77         NULL,           /* class_data */
78         sizeof (GdkImage),
79         0,              /* n_preallocs */
80         (GInstanceInitFunc) NULL,
81       };
82       
83       object_type = g_type_register_static (G_TYPE_OBJECT,
84                                             "GdkImage",
85                                             &object_info,
86                                             0);
87     }
88   
89   return object_type;
90 }
91
92 GdkImage *
93 gdk_image_new_bitmap (GdkVisual *visual, gpointer data, gint width, gint height)
94 {
95   /* We don't implement this function because it's broken, deprecated and 
96    * tricky to implement. */
97   g_warning ("This function is unimplemented");
98
99   return NULL;
100 }
101
102 GdkImage*
103 _gdk_image_new_for_depth (GdkScreen    *screen,
104                           GdkImageType  type,
105                           GdkVisual    *visual,
106                           gint          width,
107                           gint          height,
108                           gint          depth)
109 {
110   GdkImage *image;
111
112   if (visual)
113     depth = visual->depth;
114
115   g_assert (depth == 24 || depth == 32);
116
117   image = g_object_new (gdk_image_get_type (), NULL);
118   image->type = type;
119   image->visual = visual;
120   image->width = width;
121   image->height = height;
122   image->depth = depth;
123
124   image->byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ? GDK_LSB_FIRST : GDK_MSB_FIRST;
125
126   /* We only support images with bpp 4 */
127   image->bpp = 4;
128   image->bpl = image->width * image->bpp;
129   image->bits_per_pixel = image->bpp * 8;
130   
131   image->mem = g_malloc (image->bpl * image->height);
132   memset (image->mem, 0x00, image->bpl * image->height);
133
134   return image;
135 }
136
137 guint32
138 gdk_image_get_pixel (GdkImage *image,
139                      gint x,
140                      gint y)
141 {
142   guchar *ptr;
143
144   g_return_val_if_fail (image != NULL, 0);
145   g_return_val_if_fail (x >= 0 && x < image->width, 0);
146   g_return_val_if_fail (y >= 0 && y < image->height, 0);
147
148   ptr = image->mem + y * image->bpl + x * image->bpp;
149
150   return *(guint32 *)ptr;
151 }
152
153 void
154 gdk_image_put_pixel (GdkImage *image,
155                      gint x,
156                      gint y,
157                      guint32 pixel)
158 {
159   guchar *ptr;
160
161   ptr = image->mem + y * image->bpl + x * image->bpp;
162
163   *(guint32 *)ptr = pixel;
164 }
165
166 gint
167 _gdk_windowing_get_bits_for_depth (GdkDisplay *display,
168                                    gint        depth)
169 {
170   if (depth == 24 || depth == 32)
171     return 32;
172   else
173     g_assert_not_reached ();
174
175   return 0;
176 }