summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXInit.c
diff options
context:
space:
mode:
authordas <das>2006-05-12 18:17:48 (GMT)
committerdas <das>2006-05-12 18:17:48 (GMT)
commit114d3cd57863e0f50a373996e6c9004963a35f4a (patch)
treecd23015b14a776e288d49f24dec1f6c29be75a35 /macosx/tkMacOSXInit.c
parent1eaf61f1bb88dff80fda08fde5ac5adcecbe5af6 (diff)
downloadtk-114d3cd57863e0f50a373996e6c9004963a35f4a.zip
tk-114d3cd57863e0f50a373996e6c9004963a35f4a.tar.gz
tk-114d3cd57863e0f50a373996e6c9004963a35f4a.tar.bz2
* generic/tkCanvWind.c (DisplayWinItem, WinItemRequestProc): ensure
canvas window items are unmapped when canvas is unmapped. [Bug 940117] * macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn): empty clip region of unmapped windows to prevent any drawing into them or into their children from becoming visible. [Bug 940117] * macosx/tkMacOSXInt.h: revert Jim's attempt of 2005-03-14 to * macosx/tkMacOSXSubwindows.c: fix Bug 940117 as it disables Map/Unmap event propagation to children. [Bug 1480105] * macosx/tkMacOSXDraw.c (TkPutImage): handle tkPictureIsOpen flag, fixes incorrect positioning of images with complex alpha on native buttons; actual alpha blending is still broken in this situation. [Bug 1155596] * macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent): * macosx/tkMacOSXMenus.c (TkMacOSXInitMenus): workaround carbon bug with key shortcut for 'Preferences' app menu item. [Bug 1481503] * macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only check for HICommand menu item shortcuts in the application menu. * macosx/tkMacOSXInt.h: initialize keyboard layout setup in * macosx/tkMacOSXInit.c: TkpInit() rather than during handling of * macosx/tkMacOSXKeyEvent.c: first key down event. * macosx/tkMacOSXDraw.c: add optional debug code to flash clip * macosx/tkMacOSXSubwindows.c: regions during update or draw.
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r--macosx/tkMacOSXInit.c408
1 files changed, 205 insertions, 203 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index 269dce0..e12a56e 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -6,11 +6,12 @@
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
+ * Copyright (c) 2005-2006 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.
*
- * RCS: @(#) $Id: tkMacOSXInit.c,v 1.20 2006/04/11 10:19:51 das Exp $
+ * RCS: @(#) $Id: tkMacOSXInit.c,v 1.21 2006/05/12 18:17:48 das Exp $
*/
#include "tkMacOSXInt.h"
@@ -88,7 +89,7 @@ Tcl_Encoding TkMacOSXCarbonEncoding = NULL;
/*
* If the App is in an App package, then we want to add the Scripts
- * directory to the auto_path.
+ * directory to the auto_path.
*/
static char scriptPath[PATH_MAX + 1] = "";
@@ -98,7 +99,7 @@ static char scriptPath[PATH_MAX + 1] = "";
* TkpInit --
*
* Performs Mac-specific interpreter initialization related to the
- * tk_library variable.
+ * tk_library variable.
*
* Results:
* Returns a standard Tcl result. Leaves an error message or result
@@ -130,16 +131,17 @@ TkpInit(interp)
char *encodingStr = NULL;
int i;
- tkMacOSXInitialized = true;
+ tkMacOSXInitialized = true;
+
+ TkMacOSXInitAppleEvents(interp);
+ TkMacOSXInitCarbonEvents(interp);
+ TkMacOSXInitMenus(interp);
+ TkMacOSXUseAntialiasedText(interp, -1);
+ TkMacOSXInitCGDrawing(interp, TRUE, 3);
+ TkMacOSXInitKeyboard(interp);
- TkMacOSXInitAppleEvents(interp);
- TkMacOSXInitCarbonEvents(interp);
- TkMacOSXInitMenus(interp);
- TkMacOSXUseAntialiasedText(interp, -1);
- TkMacOSXInitCGDrawing(interp, TRUE, 3);
-
encoding = CFStringGetSystemEncoding();
-
+
for (i = 0; scriptMap[i].strKey != NULL; i++) {
if (scriptMap[i].numKey == encoding) {
encodingStr = scriptMap[i].strKey;
@@ -149,178 +151,178 @@ TkpInit(interp)
if (encodingStr == NULL) {
encodingStr = "macRoman";
}
-
+
TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr);
if (TkMacOSXCarbonEncoding == NULL) {
TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL);
}
-
- /*
- * When Tk is in a framework, force tcl_findLibrary to look in the
- * framework scripts directory.
- * FIXME: Should we come up with a more generic way of doing this?
- */
-
+
+ /*
+ * When Tk is in a framework, force tcl_findLibrary to look in the
+ * framework scripts directory.
+ * FIXME: Should we come up with a more generic way of doing this?
+ */
+
#ifdef TK_FRAMEWORK
- if (Tcl_MacOSXOpenVersionedBundleResources(interp,
- "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
+ if (Tcl_MacOSXOpenVersionedBundleResources(interp,
+ "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
#endif
- {
- /* Tk.framework not found, check if resource file is open */
- Handle rsrc = Get1NamedResource('CURS', "\phand");
- if (rsrc) {
- ReleaseResource(rsrc);
- } else {
+ {
+ /* Tk.framework not found, check if resource file is open */
+ Handle rsrc = Get1NamedResource('CURS', "\phand");
+ if (rsrc) {
+ ReleaseResource(rsrc);
+ } else {
#ifndef __LP64__
- const struct mach_header *image;
- char *data = NULL;
- uint32_t size;
- int fd = -1;
- char fileName[L_tmpnam + 15];
- uint32_t i, n;
-
- /* Get resource data from __tk_rsrc section of tk library file */
- n = _dyld_image_count();
- for (i = 0; i < n; i++) {
- image = _dyld_get_image_header(i);
- if (image) {
- data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
- if (data) {
- data += _dyld_get_image_vmaddr_slide(i);
- break;
- }
- }
- }
- while (data) {
- OSStatus err;
- FSRef ref;
- SInt16 refNum;
-
- /* Write resource data to temporary file and open it */
- strcpy(fileName, P_tmpdir);
- if (fileName[strlen(fileName) - 1] != '/') {
- strcat(fileName, "/");
- }
- strcat(fileName, "tkMacOSX_XXXXXX");
- fd = mkstemp(fileName);
- if (fd == -1) break;
- fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (write(fd, data, size) == -1) break;
- err = FSPathMakeRef((unsigned char*)fileName, &ref, NULL);
- if (err != noErr) break;
- err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum);
+ const struct mach_header *image;
+ char *data = NULL;
+ uint32_t size;
+ int fd = -1;
+ char fileName[L_tmpnam + 15];
+ uint32_t i, n;
+
+ /* Get resource data from __tk_rsrc section of tk library file */
+ n = _dyld_image_count();
+ for (i = 0; i < n; i++) {
+ image = _dyld_get_image_header(i);
+ if (image) {
+ data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
+ if (data) {
+ data += _dyld_get_image_vmaddr_slide(i);
+ break;
+ }
+ }
+ }
+ while (data) {
+ OSStatus err;
+ FSRef ref;
+ SInt16 refNum;
+
+ /* Write resource data to temporary file and open it */
+ strcpy(fileName, P_tmpdir);
+ if (fileName[strlen(fileName) - 1] != '/') {
+ strcat(fileName, "/");
+ }
+ strcat(fileName, "tkMacOSX_XXXXXX");
+ fd = mkstemp(fileName);
+ if (fd == -1) break;
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+ if (write(fd, data, size) == -1) break;
+ err = FSPathMakeRef((unsigned char*)fileName, &ref, NULL);
+ if (err != noErr) break;
+ err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum);
#ifdef TK_MAC_DEBUG
- if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
+ if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
#endif
- break;
- }
- if (fd != -1) {
- unlink(fileName);
- close(fd);
- }
+ break;
+ }
+ if (fd != -1) {
+ unlink(fileName);
+ close(fd);
+ }
#endif /* __LP64__ */
- }
- }
-
- /*
- * If we don't have a TTY and stdin is a special character file of length 0,
- * (e.g. /dev/null, which is what Finder sets when double clicking Wish)
- * then use the Tk based console interpreter.
- */
-
- /* REMOVE ME: Close stdin & stdout for remote debugging otherwise we
- * will fight with gdb for stdin & stdout
- */
-
- if (getenv ("XCNOSTDIN") != NULL) {
- close (0);
- close (1);
- }
-
- if (!isatty(0)) {
- struct stat st;
- if (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0)) {
- Tk_InitConsoleChannels(interp);
- Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
- Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
- Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
- /* Only show the console if we don't have a startup script */
- if (Tcl_GetStartupScript(NULL) == NULL) {
- Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
- }
- if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
- }
- }
+ }
+ }
+
+ /*
+ * If we don't have a TTY and stdin is a special character file of length 0,
+ * (e.g. /dev/null, which is what Finder sets when double clicking Wish)
+ * then use the Tk based console interpreter.
+ */
+
+ /* REMOVE ME: Close stdin & stdout for remote debugging otherwise we
+ * will fight with gdb for stdin & stdout
+ */
+
+ if (getenv ("XCNOSTDIN") != NULL) {
+ close (0);
+ close (1);
+ }
+
+ if (!isatty(0)) {
+ struct stat st;
+ if (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0)) {
+ Tk_InitConsoleChannels(interp);
+ Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
+ Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
+ Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
+ /* Only show the console if we don't have a startup script */
+ if (Tcl_GetStartupScript(NULL) == NULL) {
+ Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
+ }
+ if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ }
+ }
#if MAC_OSX_TK_USE_CPS_SPI
- /*
- * If we are loaded into an executable that is not a bundled application,
- * the window server does not let us come to the foreground.
- * For such an executable, we attempt to use an undocumented SPI to
- * notify the window server that we are now a full GUI application.
- */
- {
- /* Check whether we are a bundled executable: */
- int bundledExecutable = 0;
- CFBundleRef bundleRef = CFBundleGetMainBundle();
- CFURLRef bundleUrl = NULL;
- if (bundleRef) {
- bundleUrl = CFBundleCopyBundleURL(bundleRef);
- }
- if (bundleUrl) {
- /*
- * A bundled executable is two levels down from its main bundle
- * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas
- * an unbundled executable's main bundle directory is just
- * the directory containing the executable.
- * So to check whether we are bundled, we delete the last three
- * path components of the executable's url and compare the
- * resulting url with the main bundle url.
- */
- int j = 3;
- CFURLRef url = CFBundleCopyExecutableURL(bundleRef);
- while (url && j--) {
- CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, url);
- CFRelease(url);
- url = parent;
- }
- if (url) {
- bundledExecutable = CFEqual(bundleUrl, url);
- CFRelease(url);
- }
- CFRelease(bundleUrl);
- }
-
- /* If we are not a bundled executable, attempt to use the CPS SPI: */
- if (!bundledExecutable) {
- /*
- * Load the CPS SPI symbol dynamically, so that we don't break
- * if it every disappears or changes its name.
- */
- TkMacOSXInitNamedSymbol(CoreGraphics, OSErr, \
- CPSEnableForegroundOperation, ProcessSerialNumberPtr);
- if (CPSEnableForegroundOperation) {
- ProcessSerialNumber psn = { 0, kCurrentProcess };
- /*
- * Let the window server know that we are a foregroundable app
- */
- CPSEnableForegroundOperation(&psn);
- }
- }
- }
+ /*
+ * If we are loaded into an executable that is not a bundled application,
+ * the window server does not let us come to the foreground.
+ * For such an executable, we attempt to use an undocumented SPI to
+ * notify the window server that we are now a full GUI application.
+ */
+ {
+ /* Check whether we are a bundled executable: */
+ int bundledExecutable = 0;
+ CFBundleRef bundleRef = CFBundleGetMainBundle();
+ CFURLRef bundleUrl = NULL;
+ if (bundleRef) {
+ bundleUrl = CFBundleCopyBundleURL(bundleRef);
+ }
+ if (bundleUrl) {
+ /*
+ * A bundled executable is two levels down from its main bundle
+ * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas
+ * an unbundled executable's main bundle directory is just
+ * the directory containing the executable.
+ * So to check whether we are bundled, we delete the last three
+ * path components of the executable's url and compare the
+ * resulting url with the main bundle url.
+ */
+ int j = 3;
+ CFURLRef url = CFBundleCopyExecutableURL(bundleRef);
+ while (url && j--) {
+ CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, url);
+ CFRelease(url);
+ url = parent;
+ }
+ if (url) {
+ bundledExecutable = CFEqual(bundleUrl, url);
+ CFRelease(url);
+ }
+ CFRelease(bundleUrl);
+ }
+
+ /* If we are not a bundled executable, attempt to use the CPS SPI: */
+ if (!bundledExecutable) {
+ /*
+ * Load the CPS SPI symbol dynamically, so that we don't break
+ * if it every disappears or changes its name.
+ */
+ TkMacOSXInitNamedSymbol(CoreGraphics, OSErr, \
+ CPSEnableForegroundOperation, ProcessSerialNumberPtr);
+ if (CPSEnableForegroundOperation) {
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
+ /*
+ * Let the window server know that we are a foregroundable app
+ */
+ CPSEnableForegroundOperation(&psn);
+ }
+ }
+ }
#endif /* MAC_OSX_TK_USE_CPS_SPI */
}
if (tkLibPath[0] != '\0') {
- Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
+ Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
}
if (scriptPath[0] != '\0') {
- Tcl_SetVar(interp, "auto_path", scriptPath,
- TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
+ Tcl_SetVar(interp, "auto_path", scriptPath,
+ TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
}
-
+
return Tcl_Eval(interp, initScript);
}
@@ -351,12 +353,12 @@ TkpGetAppName(interp, namePtr)
name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
if ((name == NULL) || (*name == 0)) {
- name = "tk";
+ name = "tk";
} else {
- p = strrchr(name, '/');
- if (p != NULL) {
- name = p+1;
- }
+ p = strrchr(name, '/');
+ if (p != NULL) {
+ name = p+1;
+ }
}
Tcl_DStringAppend(namePtr, name, -1);
}
@@ -385,10 +387,10 @@ TkpDisplayWarning(msg, title)
{
Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
if (errChannel) {
- Tcl_WriteChars(errChannel, title, -1);
- Tcl_WriteChars(errChannel, ": ", 2);
- Tcl_WriteChars(errChannel, msg, -1);
- Tcl_WriteChars(errChannel, "\n", 1);
+ Tcl_WriteChars(errChannel, title, -1);
+ Tcl_WriteChars(errChannel, ": ", 2);
+ Tcl_WriteChars(errChannel, msg, -1);
+ Tcl_WriteChars(errChannel, "\n", 1);
}
}
@@ -404,7 +406,7 @@ TkpDisplayWarning(msg, title)
* Scripts folder to the auto_path. If we don't find the startup
* script, we just bag it, assuming the user is starting up some
* other way.
- *
+ *
* Results:
* None.
*
@@ -418,33 +420,33 @@ MODULE_SCOPE void
TkMacOSXDefaultStartupScript(void)
{
CFBundleRef bundleRef;
-
+
bundleRef = CFBundleGetMainBundle();
-
+
if (bundleRef != NULL) {
- CFURLRef appMainURL;
- appMainURL = CFBundleCopyResourceURL(bundleRef,
- CFSTR("AppMain"),
- CFSTR("tcl"),
- CFSTR("Scripts"));
-
- if (appMainURL != NULL) {
- CFURLRef scriptFldrURL;
- char startupScript[PATH_MAX + 1];
-
- if (CFURLGetFileSystemRepresentation (appMainURL, true,
- (unsigned char*) startupScript, PATH_MAX)) {
- Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, -1), NULL);
- scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(
- NULL, appMainURL);
- if (scriptFldrURL != NULL) {
- CFURLGetFileSystemRepresentation(scriptFldrURL,
- true, (unsigned char*) scriptPath, PATH_MAX);
- CFRelease(scriptFldrURL);
- }
- }
- CFRelease(appMainURL);
- }
+ CFURLRef appMainURL;
+ appMainURL = CFBundleCopyResourceURL(bundleRef,
+ CFSTR("AppMain"),
+ CFSTR("tcl"),
+ CFSTR("Scripts"));
+
+ if (appMainURL != NULL) {
+ CFURLRef scriptFldrURL;
+ char startupScript[PATH_MAX + 1];
+
+ if (CFURLGetFileSystemRepresentation (appMainURL, true,
+ (unsigned char*) startupScript, PATH_MAX)) {
+ Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, -1), NULL);
+ scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(
+ NULL, appMainURL);
+ if (scriptFldrURL != NULL) {
+ CFURLGetFileSystemRepresentation(scriptFldrURL,
+ true, (unsigned char*) scriptPath, PATH_MAX);
+ CFRelease(scriptFldrURL);
+ }
+ }
+ CFRelease(appMainURL);
+ }
}
}
@@ -478,13 +480,13 @@ TkMacOSXGetNamedSymbol(const char* module, const char* symbol)
nsSymbol = NSLookupAndBindSymbolWithHint(symbol, module);
}
} else {
- if(NSIsSymbolNameDefined(symbol)) {
- nsSymbol = NSLookupAndBindSymbol(symbol);
- }
+ if(NSIsSymbolNameDefined(symbol)) {
+ nsSymbol = NSLookupAndBindSymbol(symbol);
+ }
}
if(nsSymbol) {
return NSAddressOfSymbol(nsSymbol);
} else {
- return NULL;
+ return NULL;
}
}