mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 05:31:07 +00:00
Splitted out the GdkPixbuf to NSImage routine so that it can be used from
2006-12-19 Mikael Hallendal <micke@imendio.com> * gdk/quartz/gdkcursor-quartz.c: Splitted out the GdkPixbuf to NSImage routine so that it can be used from libgtk as well (needed for upcoming GtkStatusIcon support in the Quartz port). * gdk/quartz/gdkevents-quartz.c: Don't assume that all NSWindows are created from GDK, this is not true for the status icon. * gdk/quartz/gdkprivate-quartz.h: * gdk/quartz/gdkquartz.h: Added gdk_quartz_pixbuf_to_ns_image_libgtk_only so that it is available to the status icon code.
This commit is contained in:
parent
0604b0e799
commit
7c92045621
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2006-12-19 Mikael Hallendal <micke@imendio.com>
|
||||
|
||||
* gdk/quartz/gdkcursor-quartz.c: Splitted out the GdkPixbuf to NSImage
|
||||
routine so that it can be used from libgtk as well (needed for
|
||||
upcoming GtkStatusIcon support in the Quartz port).
|
||||
* gdk/quartz/gdkevents-quartz.c: Don't assume that all NSWindows are
|
||||
created from GDK, this is not true for the status icon.
|
||||
* gdk/quartz/gdkprivate-quartz.h:
|
||||
* gdk/quartz/gdkquartz.h: Added
|
||||
gdk_quartz_pixbuf_to_ns_image_libgtk_only so that it is available to
|
||||
the status icon code.
|
||||
|
||||
2006-12-16 Tristan Van Berkom <tvb@gnome.org>
|
||||
|
||||
* gtk/gtkmessagedialog.c: Added return_if_fail (image) to
|
||||
|
@ -184,14 +184,77 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source,
|
||||
return cursor;
|
||||
}
|
||||
|
||||
NSImage *
|
||||
_gdk_quartz_pixbuf_to_ns_image (GdkPixbuf *pixbuf)
|
||||
{
|
||||
NSBitmapImageRep *bitmap_rep;
|
||||
NSImage *image;
|
||||
gboolean has_alpha;
|
||||
|
||||
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
|
||||
|
||||
/* Create a bitmap image rep */
|
||||
bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:gdk_pixbuf_get_width (pixbuf)
|
||||
pixelsHigh:gdk_pixbuf_get_height (pixbuf)
|
||||
bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
|
||||
hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:0 bitsPerPixel:0];
|
||||
|
||||
{
|
||||
/* Add pixel data to bitmap rep */
|
||||
guchar *src, *dst;
|
||||
int src_stride, dst_stride;
|
||||
int x, y;
|
||||
|
||||
src_stride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
dst_stride = [bitmap_rep bytesPerRow];
|
||||
|
||||
for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
|
||||
{
|
||||
src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
|
||||
dst = [bitmap_rep bitmapData] + y * dst_stride;
|
||||
|
||||
for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
|
||||
{
|
||||
if (has_alpha)
|
||||
{
|
||||
guchar red, green, blue, alpha;
|
||||
|
||||
red = *src++;
|
||||
green = *src++;
|
||||
blue = *src++;
|
||||
alpha = *src++;
|
||||
|
||||
*dst++ = (red * alpha) / 255;
|
||||
*dst++ = (green * alpha) / 255;
|
||||
*dst++ = (blue * alpha) / 255;
|
||||
*dst++ = alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image = [[NSImage alloc] init];
|
||||
[image addRepresentation:bitmap_rep];
|
||||
[bitmap_rep release];
|
||||
[image autorelease];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
GdkCursor *
|
||||
gdk_cursor_new_from_pixbuf (GdkDisplay *display,
|
||||
GdkPixbuf *pixbuf,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSBitmapImageRep *bitmap_rep;
|
||||
NSImage *image;
|
||||
NSCursor *nscursor;
|
||||
GdkCursor *cursor;
|
||||
@ -201,67 +264,14 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
|
||||
g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
|
||||
g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
GDK_QUARTZ_ALLOC_POOL;
|
||||
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
|
||||
|
||||
/* Create a bitmap image rep */
|
||||
bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:gdk_pixbuf_get_width (pixbuf)
|
||||
pixelsHigh:gdk_pixbuf_get_height (pixbuf)
|
||||
bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
|
||||
hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:0 bitsPerPixel:0];
|
||||
|
||||
{
|
||||
/* Add pixel data to bitmap rep */
|
||||
guchar *src, *dst;
|
||||
int src_stride, dst_stride;
|
||||
int x, y;
|
||||
|
||||
src_stride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
dst_stride = [bitmap_rep bytesPerRow];
|
||||
|
||||
for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
|
||||
{
|
||||
src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
|
||||
dst = [bitmap_rep bitmapData] + y * dst_stride;
|
||||
|
||||
for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
|
||||
{
|
||||
if (has_alpha)
|
||||
{
|
||||
guchar red, green, blue, alpha;
|
||||
|
||||
red = *src++;
|
||||
green = *src++;
|
||||
blue = *src++;
|
||||
alpha = *src++;
|
||||
|
||||
*dst++ = (red * alpha) / 255;
|
||||
*dst++ = (green * alpha) / 255;
|
||||
*dst++ = (blue * alpha) / 255;
|
||||
*dst++ = alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image = [[NSImage alloc] init];
|
||||
[image addRepresentation:bitmap_rep];
|
||||
[bitmap_rep release];
|
||||
|
||||
image = _gdk_quartz_pixbuf_to_ns_image (pixbuf);
|
||||
nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x, y)];
|
||||
[image release];
|
||||
|
||||
cursor = gdk_quartz_cursor_new_from_nscursor (nscursor, GDK_CURSOR_IS_PIXMAP);
|
||||
[pool release];
|
||||
GDK_QUARTZ_RELEASE_POOL;
|
||||
|
||||
return cursor;
|
||||
}
|
||||
@ -339,3 +349,9 @@ gdk_cursor_get_image (GdkCursor *cursor)
|
||||
/* FIXME: Implement */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSImage *
|
||||
gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
|
||||
{
|
||||
return _gdk_quartz_pixbuf_to_ns_image (pixbuf);
|
||||
}
|
||||
|
@ -1052,7 +1052,11 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
|
||||
|
||||
if (!nswindow)
|
||||
return NULL;
|
||||
|
||||
|
||||
/* Window where not created by GDK so the event should be handled by Quartz */
|
||||
if (![[nswindow contentView] isKindOfClass:[GdkQuartzView class]])
|
||||
return NULL;
|
||||
|
||||
if (event_type == NSMouseMoved ||
|
||||
event_type == NSLeftMouseDragged ||
|
||||
event_type == NSRightMouseDragged ||
|
||||
@ -1160,9 +1164,8 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
|
||||
GdkWindow *mouse_window;
|
||||
|
||||
point = [nsevent locationInWindow];
|
||||
|
||||
toplevel = [(GdkQuartzView *)[nswindow contentView] gdkWindow];
|
||||
|
||||
|
||||
mouse_window = _gdk_quartz_find_child_window_by_point (toplevel, point.x, point.y, x, y);
|
||||
|
||||
synthesize_crossing_events (mouse_window, GDK_CROSSING_NORMAL, nsevent, *x, *y);
|
||||
@ -1567,9 +1570,9 @@ _gdk_events_queue (GdkDisplay *display)
|
||||
{
|
||||
if (current_event)
|
||||
{
|
||||
if (!gdk_event_translate (current_event))
|
||||
if (!gdk_event_translate (current_event))
|
||||
[NSApp sendEvent:current_event];
|
||||
|
||||
|
||||
[current_event release];
|
||||
current_event = NULL;
|
||||
}
|
||||
|
@ -162,4 +162,6 @@ GdkEventMask _gdk_quartz_get_current_event_mask (void);
|
||||
extern GdkWindow *_gdk_quartz_keyboard_grab_window;
|
||||
extern GdkWindow *_gdk_quartz_pointer_grab_window;
|
||||
|
||||
NSImage *_gdk_quartz_pixbuf_to_ns_image (GdkPixbuf *pixbuf);
|
||||
|
||||
#endif /* __GDK_PRIVATE_QUARTZ_H__ */
|
||||
|
@ -9,7 +9,8 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
NSView *gdk_quartz_window_get_nsview (GdkWindow *window);
|
||||
NSView *gdk_quartz_window_get_nsview (GdkWindow *window);
|
||||
NSImage *gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user