summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXXStubs.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2012-09-12 03:05:29 (GMT)
committerKevin Walzer <kw@codebykevin.com>2012-09-12 03:05:29 (GMT)
commit4d00df90e7901e55bc22ae2b9589a9c005f6d9f7 (patch)
tree531b9edd57ee78802a71cb6c0fd09a0367f59211 /macosx/tkMacOSXXStubs.c
parent799666382d309825a9bd5d7205fd05662a742391 (diff)
downloadtk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.zip
tk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.tar.gz
tk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.tar.bz2
Review branch for merge of Tk-Cocoa into Tk 8.5 main branch
Diffstat (limited to 'macosx/tkMacOSXXStubs.c')
-rw-r--r--macosx/tkMacOSXXStubs.c422
1 files changed, 242 insertions, 180 deletions
diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c
index 6788bfd..761416a 100644
--- a/macosx/tkMacOSXXStubs.c
+++ b/macosx/tkMacOSXXStubs.c
@@ -7,17 +7,20 @@
* 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.
+ *
+ * RCS: @(#) $Id$
*/
#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 +34,9 @@
#define ROOT_ID 10
+CGFloat tkMacOSXZeroScreenHeight = 0;
+CGFloat tkMacOSXZeroScreenTop = 0;
+
/*
* Declarations of static variables used in this file.
*/
@@ -54,13 +60,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 +84,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 +135,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) {
@@ -166,11 +167,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
@@ -205,6 +218,7 @@ TkpOpenDisplay(
bzero(gMacDisplay, sizeof(TkDisplay));
gMacDisplay->display = display;
+ [pool drain];
return gMacDisplay;
}
@@ -272,7 +286,7 @@ TkClipCleanup(
* needed.
*/
- TkSuspendClipboard();
+ [NSApp tkProvidePasteboard:dispPtr];
if (dispPtr->clipWindow != NULL) {
Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
@@ -432,14 +446,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 +485,7 @@ XBell(
Display* display,
int percent)
{
- SysBeep(percent);
+ NSBeep();
return Success;
}
@@ -653,7 +664,8 @@ XGetWindowProperty(
}
void
-XRefreshKeyboardMapping( XMappingEvent* x)
+XRefreshKeyboardMapping(
+ XMappingEvent *x)
{
/* used by tkXEvent.c */
Debugger();
@@ -718,7 +730,7 @@ XSetClipRectangles(
while (n--) {
XRectangle rect = *rectangles;
-
+
rect.x += clip_x_origin;
rect.y += clip_y_origin;
TkUnionRectWithRegion(&rect, clipRgn, clipRgn);
@@ -755,17 +767,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
+
/*
*----------------------------------------------------------------------
*
@@ -841,7 +856,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;
@@ -876,37 +891,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
@@ -914,14 +937,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;
}
@@ -979,38 +1002,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.
*
@@ -1024,64 +1066,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
/*
*----------------------------------------------------------------------
@@ -1104,24 +1135,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)
{
@@ -1129,7 +1160,7 @@ XSetWindowBackgroundPixmap(
void
XSetWindowBorder(
- Display* display,
+ Display *display,
Window w,
unsigned long border_pixel)
{
@@ -1137,7 +1168,7 @@ XSetWindowBorder(
void
XSetWindowBorderPixmap(
- Display* display,
+ Display *display,
Window w,
Pixmap border_pixmap)
{
@@ -1145,7 +1176,7 @@ XSetWindowBorderPixmap(
void
XSetWindowBorderWidth(
- Display* display,
+ Display *display,
Window w,
unsigned int width)
{
@@ -1153,7 +1184,7 @@ XSetWindowBorderWidth(
void
XSetWindowColormap(
- Display* display,
+ Display *display,
Window w,
Colormap colormap)
{
@@ -1162,24 +1193,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;
@@ -1202,10 +1234,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')) {
@@ -1306,5 +1338,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: c
+ * c-basic-offset: 4
+ * fill-column: 79
+ * coding: utf-8
+ * End:
+ */