]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkutils-quartz.c
x11: Clean up xsettings header
[~andy/gtk] / gdk / quartz / gdkutils-quartz.c
1 /* gdkutils-quartz.c
2  *
3  * Copyright (C) 2005 Imendio AB
4  * Copyright (C) 2010  Kristian Rietveld  <kris@gtk.org>
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 <AppKit/AppKit.h>
23
24 #include <gdkquartzutils.h>
25 #include "gdkprivate-quartz.h"
26
27 NSImage *
28 gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
29 {
30   NSBitmapImageRep  *bitmap_rep;
31   NSImage           *image;
32   gboolean           has_alpha;
33   
34   has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
35   
36   /* Create a bitmap image rep */
37   bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL 
38                                          pixelsWide:gdk_pixbuf_get_width (pixbuf)
39                                          pixelsHigh:gdk_pixbuf_get_height (pixbuf)
40                                          bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
41                                          hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
42                                          bytesPerRow:0 bitsPerPixel:0];
43         
44   {
45     /* Add pixel data to bitmap rep */
46     guchar *src, *dst;
47     int src_stride, dst_stride;
48     int x, y;
49                 
50     src_stride = gdk_pixbuf_get_rowstride (pixbuf);
51     dst_stride = [bitmap_rep bytesPerRow];
52                 
53     for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++) 
54       {
55         src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
56         dst = [bitmap_rep bitmapData] + y * dst_stride;
57         
58         for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
59           {
60             if (has_alpha)
61               {
62                 guchar red, green, blue, alpha;
63                 
64                 red = *src++;
65                 green = *src++;
66                 blue = *src++;
67                 alpha = *src++;
68                 
69                 *dst++ = (red * alpha) / 255;
70                 *dst++ = (green * alpha) / 255;
71                 *dst++ = (blue * alpha) / 255;
72                 *dst++ = alpha;
73               }
74             else
75              {
76                *dst++ = *src++;
77                *dst++ = *src++;
78                *dst++ = *src++;
79              }
80           }
81       } 
82   }
83         
84   image = [[NSImage alloc] init];
85   [image addRepresentation:bitmap_rep];
86   [bitmap_rep release];
87   [image autorelease];
88         
89   return image;
90 }
91
92 NSEvent *
93 gdk_quartz_event_get_nsevent (GdkEvent *event)
94 {
95   /* FIXME: If the event here is unallocated, we crash. */
96   return ((GdkEventPrivate *) event)->windowing_data;
97 }