diff options
Diffstat (limited to 'macosx/tkMacOSXXStubs.c')
-rw-r--r-- | macosx/tkMacOSXXStubs.c | 465 |
1 files changed, 249 insertions, 216 deletions
diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c index a09501b..37384eb 100644 --- a/macosx/tkMacOSXXStubs.c +++ b/macosx/tkMacOSXXStubs.c @@ -7,17 +7,18 @@ * eventually be moved into other files. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net> * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMacOSXEvent.h" #include <IOKit/IOKitLib.h> +#include <IOKit/hidsystem/IOHIDShared.h> /* * Because this file is still under major development Debugger statements are @@ -31,6 +32,9 @@ #define ROOT_ID 10 +CGFloat tkMacOSXZeroScreenHeight = 0; +CGFloat tkMacOSXZeroScreenTop = 0; + /* * Declarations of static variables used in this file. */ @@ -54,13 +58,8 @@ static int DefaultErrorHandler(Display *display, static int DestroyImage(XImage *image); static unsigned long ImageGetPixel(XImage *image, int x, int y); -static int PutPixel(XImage *image, int x, int y, +static int ImagePutPixel(XImage *image, int x, int y, unsigned long pixel); -#if 0 -static XImage * SubImage(XImage *image, int x, int y, - unsigned int width, unsigned int height); -static int AddPixel(XImage *image, long value); -#endif /* *---------------------------------------------------------------------- @@ -83,38 +82,35 @@ void TkMacOSXDisplayChanged( Display *display) { - GDHandle graphicsDevice; Screen *screen; - Rect bounds = {0, 0, 0, 0}, *maxBounds; + NSArray *nsScreens; + if (display == NULL || display->screens == NULL) { return; } screen = display->screens; - graphicsDevice = GetMainDevice(); - screen->root_depth = (*(*graphicsDevice)->gdPMap)->cmpSize * - (*(*graphicsDevice)->gdPMap)->cmpCount; - screen->height = (*graphicsDevice)->gdRect.bottom - - (*graphicsDevice)->gdRect.top; - screen->width = (*graphicsDevice)->gdRect.right - - (*graphicsDevice)->gdRect.left; - - screen->mwidth = (screen->width * 254 + 360) / 720; - screen->mheight = (screen->height * 254 + 360) / 720; - - maxBounds = (Rect *) screen->ext_data; - *maxBounds = bounds; - graphicsDevice = GetDeviceList(); - while (graphicsDevice) { - OSStatus err; - - err = ChkErr(GetAvailableWindowPositioningBounds, graphicsDevice, - &bounds); - if (err == noErr) { - UnionRect(&bounds, maxBounds, maxBounds); + nsScreens = [NSScreen screens]; + if (nsScreens && [nsScreens count]) { + NSScreen *s = [nsScreens objectAtIndex:0]; + NSRect bounds = [s frame], visible = [s visibleFrame]; + NSRect maxBounds = NSZeroRect; + + tkMacOSXZeroScreenHeight = bounds.size.height; + tkMacOSXZeroScreenTop = tkMacOSXZeroScreenHeight - + (visible.origin.y + visible.size.height); + + screen->root_depth = NSBitsPerPixelFromDepth([s depth]); + screen->width = bounds.size.width; + screen->height = bounds.size.height; + screen->mwidth = (bounds.size.width * 254 + 360) / 720; + screen->mheight = (bounds.size.height * 254 + 360) / 720; + + for (s in nsScreens) { + maxBounds = NSUnionRect(maxBounds, [s visibleFrame]); } - graphicsDevice = GetNextDevice(graphicsDevice); + *((NSRect *)screen->ext_data) = maxBounds; } } @@ -137,12 +133,15 @@ TkMacOSXDisplayChanged( TkDisplay * TkpOpenDisplay( - CONST char *display_name) + const char *display_name) { Display *display; Screen *screen; int fd = 0; - static Rect maxBounds = {0, 0, 0, 0}; + static NSRect maxBounds = {{0, 0}, {0, 0}}; + static char vendor[25] = ""; + NSArray *cgVers; + NSAutoreleasePool *pool; if (gMacDisplay != NULL) { if (strcmp(gMacDisplay->display->display_name, display_name) == 0) { @@ -152,8 +151,8 @@ TkpOpenDisplay( } } - display = (Display *) ckalloc(sizeof(Display)); - screen = (Screen *) ckalloc(sizeof(Screen)); + display = ckalloc(sizeof(Display)); + screen = ckalloc(sizeof(Screen)); bzero(display, sizeof(Display)); bzero(screen, sizeof(Screen)); @@ -166,11 +165,23 @@ TkpOpenDisplay( display->default_screen = 0; display->display_name = (char *) macScreenName; - Gestalt(gestaltQuickdrawVersion, (long *) &display->proto_minor_version); - display->proto_major_version = 10; - display->proto_minor_version -= gestaltMacOSXQD; - display->vendor = "Apple"; - Gestalt(gestaltSystemVersion, (long *) &display->release); + pool = [NSAutoreleasePool new]; + cgVers = [[[NSBundle bundleWithIdentifier:@"com.apple.CoreGraphics"] + objectForInfoDictionaryKey:@"CFBundleShortVersionString"] + componentsSeparatedByString:@"."]; + if ([cgVers count] >= 2) { + display->proto_major_version = [[cgVers objectAtIndex:1] integerValue]; + } + if ([cgVers count] >= 3) { + display->proto_minor_version = [[cgVers objectAtIndex:2] integerValue]; + } + if (!vendor[0]) { + snprintf(vendor, sizeof(vendor), "Apple AppKit %s %g", + ([NSGarbageCollector defaultCollector] ? "GC" : "RR"), + NSAppKitVersionNumber); + } + display->vendor = vendor; + Gestalt(gestaltSystemVersion, (SInt32 *) &display->release); /* * These screen bits never change @@ -181,7 +192,7 @@ TkpOpenDisplay( screen->white_pixel = 0x00FFFFFF | PIXEL_MAGIC << 24; screen->ext_data = (XExtData *) &maxBounds; - screen->root_visual = (Visual *) ckalloc(sizeof(Visual)); + screen->root_visual = ckalloc(sizeof(Visual)); screen->root_visual->visualid = 0; screen->root_visual->class = TrueColor; screen->root_visual->red_mask = 0x00FF0000; @@ -196,7 +207,7 @@ TkpOpenDisplay( TkMacOSXDisplayChanged(display); - gMacDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay)); + gMacDisplay = ckalloc(sizeof(TkDisplay)); /* * This is the quickest way to make sure that all the *Init flags get @@ -205,6 +216,7 @@ TkpOpenDisplay( bzero(gMacDisplay, sizeof(TkDisplay)); gMacDisplay->display = display; + [pool drain]; return gMacDisplay; } @@ -237,11 +249,11 @@ TkpCloseDisplay( gMacDisplay = NULL; if (display->screens != NULL) { if (display->screens->root_visual != NULL) { - ckfree((char *) display->screens->root_visual); + ckfree(display->screens->root_visual); } - ckfree((char *) display->screens); + ckfree(display->screens); } - ckfree((char *) display); + ckfree(display); } /* @@ -272,7 +284,7 @@ TkClipCleanup( * needed. */ - TkSuspendClipboard(); + [NSApp tkProvidePasteboard:dispPtr]; if (dispPtr->clipWindow != NULL) { Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom, @@ -321,33 +333,6 @@ MacXIdAlloc( /* *---------------------------------------------------------------------- * - * TkpWindowWasRecentlyDeleted -- - * - * Tries to determine whether the given window was recently deleted. - * Called from the generic code error handler to attempt to deal with - * async BadWindow errors under some circumstances. - * - * Results: - * Always 0, we do not keep this information on the Mac, so we do not - * know whether the window was destroyed. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -int -TkpWindowWasRecentlyDeleted( - Window win, - TkDisplay *dispPtr) -{ - return 0; -} - -/* - *---------------------------------------------------------------------- - * * DefaultErrorHandler -- * * This procedure is the default X error handler. Tk uses it's own error @@ -432,14 +417,11 @@ XGetGeometry( *border_width_return = winPtr->changes.border_width; *depth_return = Tk_Depth(winPtr); } else { - Rect boundsRect; - CGrafPtr destPort = TkMacOSXGetDrawablePort(d); - - GetPortBounds(destPort, &boundsRect); - *x_return = boundsRect.left; - *y_return = boundsRect.top; - *width_return = boundsRect.right - boundsRect.left; - *height_return = boundsRect.bottom - boundsRect.top; + CGSize size = ((MacDrawable *) d)->size; + *x_return = 0; + *y_return = 0; + *width_return = size.width; + *height_return = size.height; *border_width_return = 0; *depth_return = 32; } @@ -474,7 +456,7 @@ XBell( Display* display, int percent) { - SysBeep(percent); + NSBeep(); } #if 0 @@ -651,7 +633,8 @@ XGetWindowProperty( } void -XRefreshKeyboardMapping( XMappingEvent* x) +XRefreshKeyboardMapping( + XMappingEvent *x) { /* used by tkXEvent.c */ Debugger(); @@ -716,7 +699,7 @@ XSetClipRectangles( while (n--) { XRectangle rect = *rectangles; - + rect.x += clip_x_origin; rect.y += clip_y_origin; TkUnionRectWithRegion(&rect, clipRgn, clipRgn); @@ -753,17 +736,20 @@ TkGetServerInfo( Tk_Window tkwin) /* Token for window; this selects a particular * display and server. */ { - char buffer[8 + TCL_INTEGER_SPACE * 2]; - char buffer2[TCL_INTEGER_SPACE]; + char buffer[5 + TCL_INTEGER_SPACE * 2]; + char buffer2[11 + TCL_INTEGER_SPACE]; - sprintf(buffer, "QD%dR%x ", ProtocolVersion(Tk_Display(tkwin)), + snprintf(buffer, sizeof(buffer), "CG%d.%d ", + ProtocolVersion(Tk_Display(tkwin)), ProtocolRevision(Tk_Display(tkwin))); - sprintf(buffer2, " %x", VendorRelease(Tk_Display(tkwin))); + snprintf(buffer2, sizeof(buffer2), " Mac OS X %x", + VendorRelease(Tk_Display(tkwin))); Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)), buffer2, NULL); } #pragma mark XImage handling + /* *---------------------------------------------------------------------- * @@ -796,7 +782,7 @@ XCreateImage( XImage *ximage; display->request++; - ximage = (XImage *) ckalloc(sizeof(XImage)); + ximage = ckalloc(sizeof(XImage)); ximage->height = height; ximage->width = width; @@ -839,7 +825,7 @@ XCreateImage( ximage->f.create_image = NULL; ximage->f.destroy_image = DestroyImage; ximage->f.get_pixel = ImageGetPixel; - ximage->f.put_pixel = PutPixel; + ximage->f.put_pixel = ImagePutPixel; ximage->f.sub_image = NULL; ximage->f.add_pixel = NULL; @@ -874,37 +860,45 @@ XGetImage( unsigned long plane_mask, int format) { + MacDrawable *macDraw = (MacDrawable *) d; XImage * imagePtr = NULL; Pixmap pixmap = (Pixmap) NULL; - Tk_Window win = (Tk_Window) ((MacDrawable *) d)->winPtr; + Tk_Window win = (Tk_Window) macDraw->winPtr; GC gc; + char * data = NULL; int depth = 32; int offset = 0; - int bitmap_pad = 32; + int bitmap_pad = 0; int bytes_per_line = 0; - if (TkMacOSXGetDrawablePort(d)) { - if (format == ZPixmap) { - if (width > 0 && height > 0) { - /* - * Tk_GetPixmap fails for zero width or height. - */ + if (format == ZPixmap) { + if (width > 0 && height > 0) { + /* + * Tk_GetPixmap fails for zero width or height. + */ - pixmap = Tk_GetPixmap(display, d, width, height, depth); - } - if (win) { - XGCValues values; + pixmap = Tk_GetPixmap(display, d, width, height, depth); + } + if (win) { + XGCValues values; - gc = Tk_GetGC(win, 0, &values); - } else { - gc = XCreateGC(display, pixmap, 0, NULL); - } - if (pixmap) { - XCopyArea(display, d, pixmap, gc, x, y, width, height, 0, 0); + gc = Tk_GetGC(win, 0, &values); + } else { + gc = XCreateGC(display, pixmap, 0, NULL); + } + if (pixmap) { + CGContextRef context; + + XCopyArea(display, d, pixmap, gc, x, y, width, height, 0, 0); + context = ((MacDrawable *) pixmap)->context; + if (context) { + data = CGBitmapContextGetData(context); + bytes_per_line = CGBitmapContextGetBytesPerRow(context); } + } + if (data) { imagePtr = XCreateImage(display, NULL, depth, format, offset, - (char *) TkMacOSXGetDrawablePort(pixmap), - width, height, bitmap_pad, bytes_per_line); + data, width, height, bitmap_pad, bytes_per_line); /* * Track Pixmap underlying the XImage in the unused obdata field @@ -912,14 +906,14 @@ XGetImage( */ imagePtr->obdata = (XPointer) pixmap; - if (!win) { - XFreeGC(display, gc); - } - } else { - TkpDisplayWarning( - "XGetImage: only ZPixmap types are implemented", - "XGetImage Failure"); + } else if (pixmap) { + Tk_FreePixmap(display, pixmap); } + if (!win) { + XFreeGC(display, gc); + } + } else { + TkMacOSXDbgMsg("Invalid image format"); } return imagePtr; } @@ -950,7 +944,7 @@ DestroyImage( } else if (image->data) { ckfree(image->data); } - ckfree((char*) image); + ckfree(image); } return 0; } @@ -977,38 +971,57 @@ ImageGetPixel( int x, int y) { - CGrafPtr destPort, savePort; - Boolean portChanged; - RGBColor cPix; - unsigned long r, g, b, c; - - destPort = (CGrafPtr) image->data; - portChanged = QDSwapPort(destPort, &savePort); - GetCPixel(x, y, &cPix); - if (image->obdata) { - /* - * Image from XGetImage, 16 bit color values. - */ - - r = (cPix . red) >> 8; - g = (cPix . green) >> 8; - b = (cPix . blue) >> 8; - } else { - r = cPix . red; - g = cPix . green; - b = cPix . blue; - } - c = (r<<16)|(g<<8)|(b); - if (portChanged) { - QDSwapPort(savePort, NULL); + unsigned char r = 0, g = 0, b = 0; + + if (image && image->data) { + unsigned char *srcPtr = ((unsigned char*) image->data) + + (y * image->bytes_per_line) + + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); + + switch (image->bits_per_pixel) { + case 32: { + r = (*((unsigned int*) srcPtr) >> 16) & 0xff; + g = (*((unsigned int*) srcPtr) >> 8) & 0xff; + b = (*((unsigned int*) srcPtr) ) & 0xff; + /*if (image->byte_order == LSBFirst) { + r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0]; + } else { + r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; + }*/ + break; + } + case 16: + r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; + g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; + b = (*((unsigned short*) srcPtr) << 3) & 0xf8; + break; + case 8: + r = (*srcPtr << 2) & 0xc0; + g = (*srcPtr << 4) & 0xc0; + b = (*srcPtr << 6) & 0xc0; + r |= r >> 2 | r >> 4 | r >> 6; + g |= g >> 2 | g >> 4 | g >> 6; + b |= b >> 2 | b >> 4 | b >> 6; + break; + case 4: { + unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); + r = (c & 0x04) ? 0xff : 0; + g = (c & 0x02) ? 0xff : 0; + b = (c & 0x01) ? 0xff : 0; + break; + } + case 1: + r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; + break; + } } - return c; + return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b; } /* *---------------------------------------------------------------------- * - * PutPixel -- + * ImagePutPixel -- * * Set a single pixel in an image. * @@ -1022,64 +1035,53 @@ ImageGetPixel( */ static int -PutPixel( +ImagePutPixel( XImage *image, int x, int y, unsigned long pixel) { - CGrafPtr destPort, savePort; - Boolean portChanged; - RGBColor cPix; - unsigned long r, g, b; - - destPort = (CGrafPtr)image->data; - portChanged = QDSwapPort(destPort, &savePort); - r = (pixel & image->red_mask)>>16; - g = (pixel & image->green_mask)>>8; - b = (pixel & image->blue_mask); - if (image->obdata) { - /* - * Image from XGetImage, 16 bit color values. - */ - - cPix.red = r << 8; - cPix.green = g << 8; - cPix.blue = b << 8; - } else { - cPix.red = r; - cPix.green = g; - cPix.blue = b; - } - SetCPixel(x, y, &cPix); - if (portChanged) { - QDSwapPort(savePort, NULL); + if (image && image->data) { + unsigned char r = ((pixel & image->red_mask) >> 16) & 0xff; + unsigned char g = ((pixel & image->green_mask) >> 8) & 0xff; + unsigned char b = ((pixel & image->blue_mask) ) & 0xff; + unsigned char *dstPtr = ((unsigned char*) image->data) + + (y * image->bytes_per_line) + + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); + + switch (image->bits_per_pixel) { + case 32: + *((unsigned int*) dstPtr) = (0xff << 24) | (r << 16) | + (g << 8) | b; + /*if (image->byte_order == LSBFirst) { + dstPtr[3] = 0xff; dstPtr[2] = r; dstPtr[1] = g; dstPtr[0] = b; + } else { + dstPtr[0] = 0xff; dstPtr[1] = r; dstPtr[2] = g; dstPtr[3] = b; + }*/ + break; + case 16: + *((unsigned short*) dstPtr) = ((r & 0xf8) << 7) | + ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + break; + case 8: + *dstPtr = ((r & 0xc0) >> 2) | ((g & 0xc0) >> 4) | + ((b & 0xc0) >> 6); + break; + case 4: { + unsigned char c = ((r & 0x80) >> 5) | ((g & 0x80) >> 6) | + ((b & 0x80) >> 7); + *dstPtr = (x % 2) ? ((*dstPtr & 0xf0) | (c & 0x0f)) : + ((*dstPtr & 0x0f) | ((c << 4) & 0xf0)); + break; + } + case 1: + *dstPtr = ((r|g|b) & 0x80) ? (*dstPtr | (0x80 >> (x % 8))) : + (*dstPtr & ~(0x80 >> (x % 8))); + break; + } } return 0; } - -#if 0 -static XImage * -SubImage( - XImage *image, - int x, - int y, - unsigned int width, - unsigned int height) -{ - Debugger(); - return NULL; -} - -static int -AddPixel( - XImage *image, - long value) -{ - Debugger(); - return 0; -} -#endif /* *---------------------------------------------------------------------- @@ -1102,24 +1104,24 @@ AddPixel( void XChangeWindowAttributes( - Display* display, + Display *display, Window w, unsigned long value_mask, - XSetWindowAttributes* attributes) + XSetWindowAttributes *attributes) { } void XSetWindowBackground( - Display *display, - Window window, - unsigned long value) + Display *display, + Window window, + unsigned long value) { } void XSetWindowBackgroundPixmap( - Display* display, + Display *display, Window w, Pixmap background_pixmap) { @@ -1127,7 +1129,7 @@ XSetWindowBackgroundPixmap( void XSetWindowBorder( - Display* display, + Display *display, Window w, unsigned long border_pixel) { @@ -1135,7 +1137,7 @@ XSetWindowBorder( void XSetWindowBorderPixmap( - Display* display, + Display *display, Window w, Pixmap border_pixmap) { @@ -1143,7 +1145,7 @@ XSetWindowBorderPixmap( void XSetWindowBorderWidth( - Display* display, + Display *display, Window w, unsigned int width) { @@ -1151,7 +1153,7 @@ XSetWindowBorderWidth( void XSetWindowColormap( - Display* display, + Display *display, Window w, Colormap colormap) { @@ -1160,24 +1162,25 @@ XSetWindowColormap( Status XStringListToTextProperty( - char** list, + char **list, int count, - XTextProperty* text_prop_return) + XTextProperty *text_prop_return) { Debugger(); return (Status) 0; } + void XSetWMClientMachine( - Display* display, + Display *display, Window w, - XTextProperty* text_prop) + XTextProperty *text_prop) { Debugger(); } + XIC -XCreateIC( - void) +XCreateIC(void) { Debugger(); return (XIC) 0; @@ -1200,10 +1203,10 @@ XCreateIC( *---------------------------------------------------------------------- */ -CONST char * +const char * TkGetDefaultScreenName( Tcl_Interp *interp, /* Not used. */ - CONST char *screenName) /* If NULL, use default string. */ + const char *screenName) /* If NULL, use default string. */ { #if 0 if ((screenName == NULL) || (screenName[0] == '\0')) { @@ -1304,5 +1307,35 @@ void Tk_ResetUserInactiveTime( Display *dpy) { - UpdateSystemActivity(UsrActivity); + IOGPoint loc; + kern_return_t kr; + NXEvent nullEvent = {NX_NULLEVENT, {0, 0}, 0, -1, 0}; + enum { kNULLEventPostThrottle = 10 }; + static io_connect_t io_connection = MACH_PORT_NULL; + + if (io_connection == MACH_PORT_NULL) { + io_service_t service = IOServiceGetMatchingService( + kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)); + + if (service == MACH_PORT_NULL) { + return; + } + kr = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, + &io_connection); + IOObjectRelease(service); + if (kr != KERN_SUCCESS) { + return; + } + } + kr = IOHIDPostEvent(io_connection, NX_NULLEVENT, loc, &nullEvent.data, + FALSE, 0, FALSE); } + +/* + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ |