Debian Codegraph @

gdk/quartz/gdkutils-quartz.c

raw
1 /* gdkutils-quartz.c
2 *
3 * Copyright (C) 2005 Imendio AB
4 * Copyright (C) 2010 Kristian Rietveld <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21
22 #include <gdk/gdk.h>
23 #include <gdkinternals.h>
24
25 #include "gdkquartz-gtk-only.h"
26 #include "gdkquartz-cocoa-access.h"
27 #include <gdkquartzutils.h>
28
29 NSImage *
30 gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
31 {
32 NSBitmapImageRep *bitmap_rep;
33 NSImage *image;
34 gboolean has_alpha;
35
36 has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
37
38 /* Create a bitmap image rep */
39 bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
40 pixelsWide:gdk_pixbuf_get_width (pixbuf)
41 pixelsHigh:gdk_pixbuf_get_height (pixbuf)
42 bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
43 hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
44 bytesPerRow:0 bitsPerPixel:0];
45
46 {
47 /* Add pixel data to bitmap rep */
48 guchar *src, *dst;
49 int src_stride, dst_stride;
50 int x, y;
51
52 src_stride = gdk_pixbuf_get_rowstride (pixbuf);
53 dst_stride = [bitmap_rep bytesPerRow];
54
55 for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
56 {
57 src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
58 dst = [bitmap_rep bitmapData] + y * dst_stride;
59
60 for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
61 {
62 if (has_alpha)
63 {
64 guchar red, green, blue, alpha;
65
66 red = *src++;
67 green = *src++;
68 blue = *src++;
69 alpha = *src++;
70
71 *dst++ = (red * alpha) / 255;
72 *dst++ = (green * alpha) / 255;
73 *dst++ = (blue * alpha) / 255;
74 *dst++ = alpha;
75 }
76 else
77 {
78 *dst++ = *src++;
79 *dst++ = *src++;
80 *dst++ = *src++;
81 }
82 }
83 }
84 }
85
86 image = [[NSImage alloc] init];
87 [image addRepresentation:bitmap_rep];
88 [bitmap_rep release];
89 [image autorelease];
90
91 return image;
92 }
93
94 NSEvent *
95 gdk_quartz_event_get_nsevent (GdkEvent *event)
96 {
97 /* FIXME: If the event here is unallocated, we crash. */
98 return ((GdkEventPrivate *) event)->windowing_data;
99 }
100
101 /*
102 * Code for key code conversion
103 *
104 * Copyright (C) 2009 Paul Davis
105 */
106 gunichar
107 gdk_quartz_get_key_equivalent (guint key)
108 {
109 if (key >= GDK_KEY_A && key <= GDK_KEY_Z)
110 return key + (GDK_KEY_a - GDK_KEY_A);
111
112 if (key >= GDK_KEY_space && key <= GDK_KEY_asciitilde)
113 return key;
114
115 switch (key)
116 {
117 case GDK_KEY_BackSpace:
118 return NSBackspaceCharacter;
119 case GDK_KEY_Delete:
120 return NSDeleteFunctionKey;
121 case GDK_KEY_Pause:
122 return NSPauseFunctionKey;
123 case GDK_KEY_Scroll_Lock:
124 return NSScrollLockFunctionKey;
125 case GDK_KEY_Sys_Req:
126 return NSSysReqFunctionKey;
127 case GDK_KEY_Home:
128 return NSHomeFunctionKey;
129 case GDK_KEY_Left:
130 case GDK_KEY_leftarrow:
131 return NSLeftArrowFunctionKey;
132 case GDK_KEY_Up:
133 case GDK_KEY_uparrow:
134 return NSUpArrowFunctionKey;
135 case GDK_KEY_Right:
136 case GDK_KEY_rightarrow:
137 return NSRightArrowFunctionKey;
138 case GDK_KEY_Down:
139 case GDK_KEY_downarrow:
140 return NSDownArrowFunctionKey;
141 case GDK_KEY_Page_Up:
142 return NSPageUpFunctionKey;
143 case GDK_KEY_Page_Down:
144 return NSPageDownFunctionKey;
145 case GDK_KEY_End:
146 return NSEndFunctionKey;
147 case GDK_KEY_Begin:
148 return NSBeginFunctionKey;
149 case GDK_KEY_Select:
150 return NSSelectFunctionKey;
151 case GDK_KEY_Print:
152 return NSPrintFunctionKey;
153 case GDK_KEY_Execute:
154 return NSExecuteFunctionKey;
155 case GDK_KEY_Insert:
156 return NSInsertFunctionKey;
157 case GDK_KEY_Undo:
158 return NSUndoFunctionKey;
159 case GDK_KEY_Redo:
160 return NSRedoFunctionKey;
161 case GDK_KEY_Menu:
162 return NSMenuFunctionKey;
163 case GDK_KEY_Find:
164 return NSFindFunctionKey;
165 case GDK_KEY_Help:
166 return NSHelpFunctionKey;
167 case GDK_KEY_Break:
168 return NSBreakFunctionKey;
169 case GDK_KEY_Mode_switch:
170 return NSModeSwitchFunctionKey;
171 case GDK_KEY_F1:
172 return NSF1FunctionKey;
173 case GDK_KEY_F2:
174 return NSF2FunctionKey;
175 case GDK_KEY_F3:
176 return NSF3FunctionKey;
177 case GDK_KEY_F4:
178 return NSF4FunctionKey;
179 case GDK_KEY_F5:
180 return NSF5FunctionKey;
181 case GDK_KEY_F6:
182 return NSF6FunctionKey;
183 case GDK_KEY_F7:
184 return NSF7FunctionKey;
185 case GDK_KEY_F8:
186 return NSF8FunctionKey;
187 case GDK_KEY_F9:
188 return NSF9FunctionKey;
189 case GDK_KEY_F10:
190 return NSF10FunctionKey;
191 case GDK_KEY_F11:
192 return NSF11FunctionKey;
193 case GDK_KEY_F12:
194 return NSF12FunctionKey;
195 case GDK_KEY_F13:
196 return NSF13FunctionKey;
197 case GDK_KEY_F14:
198 return NSF14FunctionKey;
199 case GDK_KEY_F15:
200 return NSF15FunctionKey;
201 case GDK_KEY_F16:
202 return NSF16FunctionKey;
203 case GDK_KEY_F17:
204 return NSF17FunctionKey;
205 case GDK_KEY_F18:
206 return NSF18FunctionKey;
207 case GDK_KEY_F19:
208 return NSF19FunctionKey;
209 case GDK_KEY_F20:
210 return NSF20FunctionKey;
211 case GDK_KEY_F21:
212 return NSF21FunctionKey;
213 case GDK_KEY_F22:
214 return NSF22FunctionKey;
215 case GDK_KEY_F23:
216 return NSF23FunctionKey;
217 case GDK_KEY_F24:
218 return NSF24FunctionKey;
219 case GDK_KEY_F25:
220 return NSF25FunctionKey;
221 case GDK_KEY_F26:
222 return NSF26FunctionKey;
223 case GDK_KEY_F27:
224 return NSF27FunctionKey;
225 case GDK_KEY_F28:
226 return NSF28FunctionKey;
227 case GDK_KEY_F29:
228 return NSF29FunctionKey;
229 case GDK_KEY_F30:
230 return NSF30FunctionKey;
231 case GDK_KEY_F31:
232 return NSF31FunctionKey;
233 case GDK_KEY_F32:
234 return NSF32FunctionKey;
235 case GDK_KEY_F33:
236 return NSF33FunctionKey;
237 case GDK_KEY_F34:
238 return NSF34FunctionKey;
239 case GDK_KEY_F35:
240 return NSF35FunctionKey;
241 default:
242 break;
243 }
244
245 return '\0';
246 }