head	1.41;
access;
symbols
	core-8-5-9:1.34.2.3
	core-8-5-8:1.34.2.3
	macosx-cocoa-merge:1.40
	macosx-cocoa-premerge:1.39
	macosx-carbon-freeze:1.39
	core-8-5-7:1.34.2.2
	core-8-5-6:1.34.2.2
	core-8-6-b1:1.38
	core-8-6-a3:1.36
	core-8-5-5:1.34.2.2
	core-8-6-a2:1.36
	core-8-5-4:1.34.2.2
	core-8-5-3:1.34.2.2
	core-8-6-a1:1.36
	core-8-4-19:1.3.2.25
	core-8-5-branch:1.34.0.2
	core-8-5-2:1.34
	core-8-4-18:1.3.2.25
	core-8-5-1:1.34
	core-8-4-17:1.3.2.25
	core-8-5-0:1.34
	core-8-5-b3:1.33
	core-8-5-b2:1.33
	core-8-4-16:1.3.2.24
	core-8-5-b1:1.33
	core-stablilizer-merge:1.32
	core-stabilizer-branch:1.28.0.2
	core-stabilizer-merge:1.34.2.2
	core-8-4-15:1.3.2.21
	core-8-5-a6:1.28
	core-8-5-a5:1.24
	core-8-4-14:1.3.2.19
	core-8-5-a4:1.20
	core-8-4-13:1.3.2.14
	core-8-4-12:1.3.2.11
	core-8-4-11:1.3.2.8
	core-8-5-a3:1.13
	core-8-4-10:1.3.2.8
	core-8-4-9-branch:1.3.2.3.0.2
	core-8-5-a2:1.6
	core-8-4-9:1.3.2.3
	core-8-4-8:1.3.2.3
	core-8-4-7:1.3.2.2
	core-8-5-a1:1.5
	core-8-4-6:1.3.2.1
	core-8-4-5:1.3.2.1
	mistachkin-dev-branch:1.4.0.2
	core-8-4-4:1.3.2.1
	core-8-4-3:1.3.2.1
	core-8-4-branch:1.3.0.2
	core-8-4-2:1.3
	core-8-4-1:1.3
	core-8-4-0:1.2
	macosx-8-4-merge-2002-08-31-trunk:1.2
	macosx-8-4-premerge-2002-08-31-branch:1.1.2.8
	macosx-8-4-merge-2002-08-30-branch:1.1.2.7
	macosx-8-4-merge-2002-08-20-branch:1.1.2.6
	macosx-premerge-6-9-02:1.1.2.4
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@ * @;


1.41
date	2009.07.06.20.29.21;	author dkf;	state Exp;
branches;
next	1.40;

1.40
date	2009.06.29.14.35.01;	author das;	state Exp;
branches;
next	1.39;

1.39
date	2009.05.06.16.36.24;	author das;	state Exp;
branches;
next	1.38;

1.38
date	2008.12.15.16.17.18;	author dgp;	state Exp;
branches;
next	1.37;

1.37
date	2008.12.09.23.53.37;	author das;	state Exp;
branches;
next	1.36;

1.36
date	2008.06.19.00.13.02;	author das;	state Exp;
branches;
next	1.35;

1.35
date	2008.04.27.22.39.12;	author dkf;	state Exp;
branches;
next	1.34;

1.34
date	2007.12.13.15.27.09;	author dgp;	state Exp;
branches
	1.34.2.1;
next	1.33;

1.33
date	2007.09.06.19.33.56;	author dgp;	state Exp;
branches;
next	1.32;

1.32
date	2007.06.29.03.20.01;	author das;	state Exp;
branches;
next	1.31;

1.31
date	2007.06.09.17.09.40;	author das;	state Exp;
branches;
next	1.30;

1.30
date	2007.06.06.09.55.52;	author das;	state Exp;
branches;
next	1.29;

1.29
date	2007.06.04.09.27.33;	author das;	state Exp;
branches;
next	1.28;

1.28
date	2007.04.23.21.24.33;	author das;	state Exp;
branches
	1.28.2.1;
next	1.27;

1.27
date	2007.04.21.19.06.38;	author hobbs;	state Exp;
branches;
next	1.26;

1.26
date	2007.04.13.14.51.18;	author dkf;	state Exp;
branches;
next	1.25;

1.25
date	2006.11.24.19.03.50;	author hobbs;	state Exp;
branches;
next	1.24;

1.24
date	2006.10.16.15.35.28;	author das;	state Exp;
branches;
next	1.23;

1.23
date	2006.08.18.07.47.10;	author das;	state Exp;
branches;
next	1.22;

1.22
date	2006.07.20.06.24.16;	author das;	state Exp;
branches;
next	1.21;

1.21
date	2006.05.12.18.17.48;	author das;	state Exp;
branches;
next	1.20;

1.20
date	2006.04.11.10.19.51;	author das;	state Exp;
branches;
next	1.19;

1.19
date	2006.03.24.14.58.01;	author das;	state Exp;
branches;
next	1.18;

1.18
date	2006.01.10.05.37.51;	author das;	state Exp;
branches;
next	1.17;

1.17
date	2005.12.08.07.50.14;	author das;	state Exp;
branches;
next	1.16;

1.16
date	2005.11.27.02.36.15;	author das;	state Exp;
branches;
next	1.15;

1.15
date	2005.09.10.14.53.20;	author das;	state Exp;
branches;
next	1.14;

1.14
date	2005.08.09.07.39.21;	author das;	state Exp;
branches;
next	1.13;

1.13
date	2005.05.29.07.00.26;	author das;	state Exp;
branches;
next	1.12;

1.12
date	2005.05.26.11.19.01;	author das;	state Exp;
branches;
next	1.11;

1.11
date	2005.05.24.02.32.15;	author das;	state Exp;
branches;
next	1.10;

1.10
date	2005.05.23.20.24.59;	author das;	state Exp;
branches;
next	1.9;

1.9
date	2005.05.14.20.48.15;	author das;	state Exp;
branches;
next	1.8;

1.8
date	2005.03.09.19.40.52;	author wolfsuit;	state Exp;
branches;
next	1.7;

1.7
date	2005.01.25.06.54.18;	author das;	state Exp;
branches;
next	1.6;

1.6
date	2004.11.11.01.24.32;	author das;	state Exp;
branches;
next	1.5;

1.5
date	2004.02.16.00.19.42;	author wolfsuit;	state Exp;
branches;
next	1.4;

1.4
date	2003.05.13.08.40.58;	author das;	state Exp;
branches;
next	1.3;

1.3
date	2002.10.16.19.44.05;	author das;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2002.08.31.06.12.30;	author das;	state Exp;
branches;
next	1.1;

1.1
date	2001.10.15.09.22.00;	author wolfsuit;	state dead;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2001.10.15.09.22.00;	author wolfsuit;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.11.11.17.54.40;	author wolfsuit;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2002.01.22.01.28.18;	author wolfsuit;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2002.02.05.02.25.17;	author wolfsuit;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2002.07.18.23.45.18;	author vincentdarley;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2002.07.19.09.22.34;	author vincentdarley;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2002.08.21.12.28.56;	author das;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2002.08.30.18.18.16;	author das;	state Exp;
branches;
next	;

1.3.2.1
date	2003.05.13.08.41.48;	author das;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	2004.07.25.01.57.41;	author wolfsuit;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2004.11.11.01.26.43;	author das;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2005.01.25.06.54.58;	author das;	state Exp;
branches;
next	1.3.2.5;

1.3.2.5
date	2005.05.14.20.53.31;	author das;	state Exp;
branches;
next	1.3.2.6;

1.3.2.6
date	2005.05.24.04.21.32;	author das;	state Exp;
branches;
next	1.3.2.7;

1.3.2.7
date	2005.05.26.11.20.09;	author das;	state Exp;
branches;
next	1.3.2.8;

1.3.2.8
date	2005.05.29.07.00.47;	author das;	state Exp;
branches;
next	1.3.2.9;

1.3.2.9
date	2005.08.09.07.40.00;	author das;	state Exp;
branches;
next	1.3.2.10;

1.3.2.10
date	2005.09.10.14.54.17;	author das;	state Exp;
branches;
next	1.3.2.11;

1.3.2.11
date	2005.11.27.02.36.46;	author das;	state Exp;
branches;
next	1.3.2.12;

1.3.2.12
date	2005.12.08.07.50.30;	author das;	state Exp;
branches;
next	1.3.2.13;

1.3.2.13
date	2006.01.10.05.38.20;	author das;	state Exp;
branches;
next	1.3.2.14;

1.3.2.14
date	2006.03.28.02.44.13;	author das;	state Exp;
branches;
next	1.3.2.15;

1.3.2.15
date	2006.04.28.06.02.59;	author das;	state Exp;
branches;
next	1.3.2.16;

1.3.2.16
date	2006.05.12.18.17.55;	author das;	state Exp;
branches;
next	1.3.2.17;

1.3.2.17
date	2006.07.20.06.26.45;	author das;	state Exp;
branches;
next	1.3.2.18;

1.3.2.18
date	2006.08.18.07.47.25;	author das;	state Exp;
branches;
next	1.3.2.19;

1.3.2.19
date	2006.10.16.15.35.51;	author das;	state Exp;
branches;
next	1.3.2.20;

1.3.2.20
date	2006.11.24.19.04.07;	author hobbs;	state Exp;
branches;
next	1.3.2.21;

1.3.2.21
date	2007.04.29.02.26.49;	author das;	state Exp;
branches;
next	1.3.2.22;

1.3.2.22
date	2007.06.06.09.56.54;	author das;	state Exp;
branches;
next	1.3.2.23;

1.3.2.23
date	2007.06.09.17.10.21;	author das;	state Exp;
branches;
next	1.3.2.24;

1.3.2.24
date	2007.06.29.03.22.02;	author das;	state Exp;
branches;
next	1.3.2.25;

1.3.2.25
date	2007.11.09.06.26.55;	author das;	state Exp;
branches;
next	;

1.28.2.1
date	2007.06.04.15.19.00;	author dgp;	state Exp;
branches;
next	1.28.2.2;

1.28.2.2
date	2007.06.12.16.22.42;	author dgp;	state Exp;
branches;
next	1.28.2.3;

1.28.2.3
date	2007.07.01.17.31.33;	author dgp;	state Exp;
branches;
next	1.28.2.4;

1.28.2.4
date	2007.09.07.01.25.37;	author dgp;	state Exp;
branches;
next	1.28.2.5;

1.28.2.5
date	2008.06.25.16.46.08;	author dgp;	state Exp;
branches;
next	;

1.34.2.1
date	2008.05.03.21.09.16;	author das;	state Exp;
branches;
next	1.34.2.2;

1.34.2.2
date	2008.06.19.00.13.10;	author das;	state Exp;
branches;
next	1.34.2.3;

1.34.2.3
date	2009.05.06.16.36.28;	author das;	state Exp;
branches;
next	;


desc
@@


1.41
log
@More marking of files as Objective-C.
@
text
@/*
 * tkMacOSXInit.c --
 *
 *	This file contains Mac OS X -specific interpreter initialization
 *	functions.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * 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.
 *
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.40 2009/06/29 14:35:01 das Exp $
 */

#include "tkMacOSXPrivate.h"

#include <sys/stat.h>
#include <sys/utsname.h>
#include <dlfcn.h>
#include <objc/objc-auto.h>

static char tkLibPath[PATH_MAX + 1] = "";

/*
 * If the App is in an App package, then we want to add the Scripts directory
 * to the auto_path.
 */

static char scriptPath[PATH_MAX + 1] = "";

int tkMacOSXGCEnabled = 0;
long tkMacOSXMacOSXVersion = 0;

#pragma mark TKApplication(TKInit)

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#define NSTextInputContextKeyboardSelectionDidChangeNotification @@"NSTextInputContextKeyboardSelectionDidChangeNotification"
static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
    [[NSNotificationCenter defaultCenter] postNotificationName:NSTextInputContextKeyboardSelectionDidChangeNotification object:nil userInfo:nil];
}
#endif

@@interface TKApplication(TKKeyboard)
- (void) keyboardChanged: (NSNotification *) notification;
@@end

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
#define TKApplication_NSApplicationDelegate <NSApplicationDelegate>
#else
#define TKApplication_NSApplicationDelegate
#endif
@@interface TKApplication(TKWindowEvent) TKApplication_NSApplicationDelegate
- (void) _setupWindowNotifications;
@@end

@@interface TKApplication(TKScrlbr)
- (void) _setupScrollBarNotifications;
@@end

@@interface TKApplication(TKMenus)
- (void) _setupMenus;
@@end

@@implementation TKApplication
@@end

@@implementation TKApplication(TKInit)
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
- (void) _postedNotification: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
}
#endif

- (void) _setupApplicationNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
#define observe(n, s) \
	[nc addObserver:self selector:@@selector(s) name:(n) object:nil]
    observe(NSApplicationDidBecomeActiveNotification, applicationActivate:);
    observe(NSApplicationDidResignActiveNotification, applicationDeactivate:);
    observe(NSApplicationDidUnhideNotification, applicationShowHide:);
    observe(NSApplicationDidHideNotification, applicationShowHide:);
    observe(NSApplicationDidChangeScreenParametersNotification, displayChanged:);
    observe(NSTextInputContextKeyboardSelectionDidChangeNotification, keyboardChanged:);
#undef observe
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
    CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &keyboardChanged, kTISNotifySelectedKeyboardInputSourceChanged, NULL, CFNotificationSuspensionBehaviorCoalesce);
#endif
}

- (void) _setupEventLoop
{
    _running = 1;
    if (!_appFlags._hasBeenRun) {
        _appFlags._hasBeenRun = YES;
	[self finishLaunching];
    }
    [self setWindowsNeedUpdate:YES];
}

- (void) _setup: (Tcl_Interp *) interp
{
    _eventInterp = interp;
    _defaultMainMenu = nil;
    [self _setupMenus];
    [self setDelegate:self];
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    [[NSNotificationCenter defaultCenter] addObserver:self
	    selector:@@selector(_postedNotification:) name:nil object:nil];
#endif
    [self _setupWindowNotifications];
    [self _setupScrollBarNotifications];
    [self _setupApplicationNotifications];
}

- (NSString *) tkFrameworkImagePath: (NSString *) image
{
    NSString *path = nil;

    if (tkLibPath[0] != '\0') {
	path = [[NSBundle bundleWithPath:[[NSString stringWithUTF8String:
		tkLibPath] stringByAppendingString:@@"/../.."]]
		pathForImageResource:image];
    }
    if (!path) {
	const char *tk_library = Tcl_GetVar2(_eventInterp, "tk_library", NULL,
		TCL_GLOBAL_ONLY);

	if (tk_library) {
	    NSFileManager *fm = [NSFileManager defaultManager];

	    path = [[NSString stringWithUTF8String:tk_library]
		    stringByAppendingFormat:@@"/%@@", image];
	    if (![fm isReadableFileAtPath:path]) {
		path = [[NSString stringWithUTF8String:tk_library]
			stringByAppendingFormat:@@"/../macosx/%@@", image];
		if (![fm isReadableFileAtPath:path]) {
		    path = nil;
		}
	    }
	}
    }
#ifdef TK_MAC_DEBUG
    if (!path && getenv("TK_SRCROOT")) {
	path = [[NSString stringWithUTF8String:getenv("TK_SRCROOT")]
		stringByAppendingFormat:@@"/macosx/%@@", image];
	if (![[NSFileManager defaultManager] isReadableFileAtPath:path]) {
	    path = nil;
	}
    }
#endif
    return path;
}
@@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * DoWindowActivate --
 *
 *	Idle handler that sets the application icon to the generic Tk icon.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
SetApplicationIcon(
    ClientData clientData)
{
    NSString *path = [NSApp tkFrameworkImagePath:@@"Tk.icns"];
    if (path) {
	NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
	if (image) {
	    [NSApp setApplicationIconImage:image];
	    [image release];
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpInit --
 *
 *	Performs Mac-specific interpreter initialization related to the
 *	tk_library variable.
 *
 * Results:
 *	Returns a standard Tcl result. Leaves an error message or result in
 *	the interp's result.
 *
 * Side effects:
 *	Sets "tk_library" Tcl variable, runs "tk.tcl" script.
 *
 *----------------------------------------------------------------------
 */

int
TkpInit(
    Tcl_Interp *interp)
{
    static int initialized = 0;

    /*
     * Since it is possible for TkInit to be called multiple times and we
     * don't want to do the following initialization multiple times we protect
     * against doing it more than once.
     */

    if (!initialized) {
	int bundledExecutable = 0;
	CFBundleRef bundleRef;
	CFURLRef bundleUrl = NULL;
	struct utsname name;
	struct stat st;

	initialized = 1;

	/*
	 * Initialize/check OS version variable for runtime checks.
	 */

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
#   error Mac OS X 10.5 required
#endif

	if (!uname(&name)) {
	    tkMacOSXMacOSXVersion = (strtod(name.release, NULL) + 96) * 10;
	}
	if (tkMacOSXMacOSXVersion &&
		tkMacOSXMacOSXVersion/10 < MAC_OS_X_VERSION_MIN_REQUIRED/10) {
	    Tcl_Panic("Mac OS X 10.%d or later required !",
		    (MAC_OS_X_VERSION_MIN_REQUIRED/10)-100);
	}

#ifdef TK_FRAMEWORK
	/*
	 * 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?
	 */

	if (Tcl_MacOSXOpenVersionedBundleResources(interp,
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 0, PATH_MAX,
		tkLibPath) != TCL_OK) {
	    TkMacOSXDbgMsg("Tcl_MacOSXOpenVersionedBundleResources failed");
	}
#endif

	static NSAutoreleasePool *pool = nil;
	if (!pool) {
	    pool = [NSAutoreleasePool new];
	}
	tkMacOSXGCEnabled = ([NSGarbageCollector defaultCollector] != nil);
	[[NSUserDefaults standardUserDefaults] registerDefaults:
		[NSDictionary dictionaryWithObjectsAndKeys:
		[NSNumber numberWithBool:YES],
		@@"_NSCanWrapButtonTitles",
		[NSNumber numberWithInt:-1],
		@@"NSStringDrawingTypesetterBehavior",
		nil]];
	[TKApplication sharedApplication];
	[NSApp _setup:interp];

	/* Check whether we are a bundled executable: */
	bundleRef = CFBundleGetMainBundle();
	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 (!bundledExecutable) {
	    /*
	     * 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, notify the window server
	     * that we are now a full GUI application.
	     */

	    OSStatus err = procNotFound;
	    ProcessSerialNumber psn = { 0, kCurrentProcess };

	    err = ChkErr(TransformProcessType, &psn,
		    kProcessTransformToForegroundApplication);

	    /*
	     * Set application icon to generic Tk icon, do it at idle time
	     * instead of now to ensure tk_library is setup.
	     */

	    Tcl_DoWhenIdle(SetApplicationIcon, NULL);
	}

	[NSApp _setupEventLoop];
	TkMacOSXInitAppleEvents(interp);
	TkMacOSXUseAntialiasedText(interp, -1);
	TkMacOSXInitCGDrawing(interp, TRUE, 0);
	[pool drain];
	pool = [NSAutoreleasePool new];

	/*
	 * FIXME: Close stdin & stdout for remote debugging otherwise we will
	 * fight with gdb for stdin & stdout
	 */

	if (getenv("XCNOSTDIN") != NULL) {
	    close(0);
	    close(1);
	}

	/*
	 * 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.
	 */

	if (getenv("TK_CONSOLE") ||
		(!isatty(0) && (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
	     * and tcl_interactive hasn't been set already.
	     */

	    if (Tcl_GetStartupScript(NULL) == NULL) {
		const char *intvar = Tcl_GetVar(interp,
			"tcl_interactive", TCL_GLOBAL_ONLY);

		if (intvar == NULL) {
		    Tcl_SetVar(interp, "tcl_interactive", "1",
			    TCL_GLOBAL_ONLY);
		}
	    }
	    if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
		return TCL_ERROR;
	    }
	}
    }

    Tk_MacOSXSetupTkNotifier();

    if (tkLibPath[0] != '\0') {
	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_CreateObjCommand(interp, "::tk::mac::standardAboutPanel",
	    TkMacOSXStandardAboutPanelObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap",
	    TkMacOSXIconBitmapObjCmd, NULL, NULL);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetAppName --
 *
 *	Retrieves the name of the current application from a platform specific
 *	location. For Unix, the application name is the tail of the path
 *	contained in the tcl variable argv0.
 *
 * Results:
 *	Returns the application name in the given Tcl_DString.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpGetAppName(
    Tcl_Interp *interp,
    Tcl_DString *namePtr)	/* A previously initialized Tcl_DString. */
{
    const char *p, *name;

    name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
    if ((name == NULL) || (*name == 0)) {
	name = "tk";
    } else {
	p = strrchr(name, '/');
	if (p != NULL) {
	    name = p+1;
	}
    }
    Tcl_DStringAppend(namePtr, name, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayWarning --
 *
 *	This routines is called from Tk_Main to display warning messages that
 *	occur during startup.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Generates messages on stdout.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayWarning(
    const char *msg,		/* Message to be displayed. */
    const char *title)		/* Title of warning. */
{
    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);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDefaultStartupScript --
 *
 *	On MacOS X, we look for a file in the Resources/Scripts directory
 *	called AppMain.tcl and if found, we set argv[1] to that, so that the
 *	rest of the code will find it, and add the 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.
 *
 * Side effects:
 *	Tcl_SetStartupScript() called when AppMain.tcl found.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void
TkMacOSXDefaultStartupScript(void)
{
    CFBundleRef bundleRef;

    bundleRef = CFBundleGetMainBundle();

    if (bundleRef != NULL) {
	CFURLRef 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);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNamedSymbol --
 *
 *	Dynamically acquire address of a named symbol from a loaded dynamic
 *	library, so that we can use API that may not be available on all OS
 *	versions.
 *
 * Results:
 *	Address of given symbol or NULL if unavailable.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void*
TkMacOSXGetNamedSymbol(
    const char* module,
    const char* symbol)
{
    void *addr = dlsym(RTLD_NEXT, symbol);
    if (!addr) {
	(void) dlerror(); /* Clear dlfcn error state */
    }
    return addr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetStringObjFromCFString --
 *
 *	Get a string object from a CFString as efficiently as possible.
 *
 * Results:
 *	New string object or NULL if conversion failed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE Tcl_Obj*
TkMacOSXGetStringObjFromCFString(
    CFStringRef str)
{
    Tcl_Obj *obj = NULL;
    const char *c = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);

    if (c) {
	obj = Tcl_NewStringObj(c, -1);
    } else {
	CFRange all = CFRangeMake(0, CFStringGetLength(str));
	CFIndex len;

	if (CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, NULL,
		0, &len) > 0 && len < INT_MAX) {
	    obj = Tcl_NewObj();
	    Tcl_SetObjLength(obj, len);
	    CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false,
		    (UInt8*) obj->bytes, len, NULL);
	}
    }
    return obj;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.40
log
@Merge of TkAqua Cocoa port
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.39 2009/05/06 16:36:24 das Exp $
d46 1
a46 1
- (void)keyboardChanged:(NSNotification *)notification;
d55 1
a55 1
- (void)_setupWindowNotifications;
d59 1
a59 1
- (void)_setupScrollBarNotifications;
d63 1
a63 1
- (void)_setupMenus;
d71 2
a72 1
- (void)_postedNotification:(NSNotification *)notification {
d76 3
a78 1
- (void)_setupApplicationNotifications {
d80 2
a81 1
#define observe(n, s) [nc addObserver:self selector:@@selector(s) name:(n) object:nil]
d93 3
a95 1
- (void)_setupEventLoop {
d103 3
a105 1
- (void)_setup:(Tcl_Interp *)interp {
d118 3
a120 1
- (NSString *)tkFrameworkImagePath:(NSString*)image {
d122 1
d131 1
d134 1
d593 1
a593 1
 * mode: c
@


1.39
log
@avoid panic for CFStrings longer than INT_MAX
@
text
@d8 2
a9 2
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2005-2008 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.38 2008/12/15 16:17:18 dgp Exp $
d21 4
a24 2
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
d27 2
a28 3
 * Define the following to 0 to not attempt to use an undocumented SPI to
 * notify the window server that an unbundled executable is a full GUI
 * application after loading Tk.
d31 1
a31 3
#ifndef MAC_OSX_TK_USE_CPS_SPI
#define MAC_OSX_TK_USE_CPS_SPI 1
#endif
d33 2
a34 6
/*
 * The following structures are used to map the script/language codes of a
 * font to the name that should be passed to Tcl_GetEncoding() to obtain the
 * encoding for that font. The set of numeric constants is fixed and defined
 * by Apple.
 */
d36 1
a36 40
typedef struct Map {
    CFStringEncoding numKey;
    const char *strKey;
} Map;

static Map scriptMap[] = {
    {smRoman,		"macRoman"},
    {smJapanese,	"macJapan"},
    {smTradChinese,	"macChinese"},
    {smKorean,		"macKorean"},
    {smArabic,		"macArabic"},
    {smHebrew,		"macHebrew"},
    {smGreek,		"macGreek"},
    {smCyrillic,	"macCyrillic"},
    {smRSymbol,		"macRSymbol"},
    {smDevanagari,	"macDevanagari"},
    {smGurmukhi,	"macGurmukhi"},
    {smGujarati,	"macGujarati"},
    {smOriya,		"macOriya"},
    {smBengali,		"macBengali"},
    {smTamil,		"macTamil"},
    {smTelugu,		"macTelugu"},
    {smKannada,		"macKannada"},
    {smMalayalam,	"macMalayalam"},
    {smSinhalese,	"macSinhalese"},
    {smBurmese,		"macBurmese"},
    {smKhmer,		"macKhmer"},
    {smThai,		"macThailand"},
    {smLaotian,		"macLaos"},
    {smGeorgian,	"macGeorgia"},
    {smArmenian,	"macArmenia"},
    {smSimpChinese,	"macSimpChinese"},
    {smTibetan,		"macTIbet"},
    {smMongolian,	"macMongolia"},
    {smGeez,		"macEthiopia"},
    {smEastEurRoman,	"macCentEuro"},
    {smVietnamese,	"macVietnam"},
    {smExtArabic,	"macSindhi"},
    {0,			NULL}
};
d38 6
a43 1
Tcl_Encoding TkMacOSXCarbonEncoding = NULL;
d45 103
d149 13
a161 2
 * If the App is in an App package, then we want to add the Scripts directory
 * to the auto_path.
d164 13
a176 3
static char scriptPath[PATH_MAX + 1] = "";

float tkMacOSXToolboxVersionNumber = 0;
a199 1
    static char tkLibPath[PATH_MAX + 1];
a201 2
    Tk_MacOSXSetupTkNotifier();

a211 3
	CFStringEncoding encoding;
	const char *encodingStr = NULL;
	int i;
a212 1
	long osVersion = 0;
d216 1
a216 1
	
d220 5
a224 1
	
d226 1
a226 1
	    osVersion = strtol(name.release, NULL, 10) - 4;
d228 2
a229 1
	if (osVersion && osVersion < (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10) {
d231 1
a231 1
		    (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
a232 15
	TK_IF_MAC_OS_X_API (3, &kHIToolboxVersionNumber,
	    tkMacOSXToolboxVersionNumber = kHIToolboxVersionNumber;
	) TK_ELSE_MAC_OS_X (3,
	    if (osVersion > 5) {
		tkMacOSXToolboxVersionNumber = INFINITY;
	    } else if (osVersion >= 3) {
		static const float tbVersions[3] = {
		    kHIToolboxVersionNumber10_3,
		    kHIToolboxVersionNumber10_4,
		    kHIToolboxVersionNumber10_5,
		};

		tkMacOSXToolboxVersionNumber = tbVersions[osVersion-3];
	    }
	) TK_ENDIF
d234 1
a240 1
#ifdef TK_FRAMEWORK
d242 4
a245 2
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX,
		tkLibPath) != TCL_OK)
a246 63
	{
	    /* 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 dylib 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", (void *) &size);
			if (data) {
			    data += _dyld_get_image_vmaddr_slide(i);
			    break;
			}
		    }
		}
		while (data) {
		    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;
		    }
		    if(ChkErr(FSPathMakeRef, (unsigned char *) fileName, &ref,
			    NULL) != noErr) {
			break;
		    }
		    ChkErr(FSOpenResourceFile, &ref, 0, NULL, fsRdPerm,
			    &refNum);
		    break;
		}
		if (fd != -1) {
		    unlink(fileName);
		    close(fd);
		}
#endif /* __LP64__ */
	    }
	}
d248 14
a261 6
	/*
	 * 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, notify the window server that
	 * we are now a full GUI application.
	 */
d296 7
a302 4
	/*
	 * If we are not a bundled executable, notify the window server that
	 * we are a foregroundable app.
	 */
a303 1
	if (!bundledExecutable) {
d307 9
a315 20
	    TK_IF_MAC_OS_X_API (3, TransformProcessType,
		err = ChkErr(TransformProcessType, &psn,
			kProcessTransformToForegroundApplication);
	    ) TK_ENDIF
#if MAC_OSX_TK_USE_CPS_SPI
	    if (err != noErr) {
		/*
		 * When building or running on 10.2 or when the above fails,
		 * attempt to use undocumented CPS SPI to notify the window
		 * server. Load the SPI symbol dynamically, so that we don't
		 * break if it ever disappears or changes its name.
		 */

		TkMacOSXInitNamedSymbol(CoreGraphics, OSStatus,
			CPSEnableForegroundOperation, ProcessSerialNumberPtr);
		if (CPSEnableForegroundOperation) {
		    ChkErr(CPSEnableForegroundOperation, &psn);
		}
	    }
#endif /* MAC_OSX_TK_USE_CPS_SPI */
d318 1
a319 2
	TkMacOSXInitCarbonEvents(interp);
	TkMacOSXInitMenus(interp);
d322 2
a323 18
	TkMacOSXInitKeyboard(interp);

	encoding = CFStringGetSystemEncoding();

	for (i = 0; scriptMap[i].strKey != NULL; i++) {
	    if (scriptMap[i].numKey == encoding) {
		encodingStr = scriptMap[i].strKey;
		break;
	    }
	}
	if (encodingStr == NULL) {
	    encodingStr = "macRoman";
	}

	TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, encodingStr);
	if (TkMacOSXCarbonEncoding == NULL) {
	    TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, NULL);
	}
d369 2
d379 5
d515 1
a515 2
 *	versions. If module is non-NULL and not the empty string, use twolevel
 *	namespace lookup.
d531 3
a533 14
    NSSymbol nsSymbol = NULL;

    if (module && *module) {
	if (NSIsSymbolNameDefinedWithHint(symbol, module)) {
	    nsSymbol = NSLookupAndBindSymbolWithHint(symbol, module);
	}
    } else {
	if (NSIsSymbolNameDefined(symbol)) {
	    nsSymbol = NSLookupAndBindSymbol(symbol);
	}
    }

    if (!nsSymbol) {
	return NULL;
d535 1
a535 1
    return NSAddressOfSymbol(nsSymbol);
@


1.38
log
@        TIP #338 IMPLEMENTATION

        * doc/Tk_Main.c:        Removed the last two '#include "tclInt.h"'.
        * generic/tkMain.c:     Tk is now limited to Tcl's public interface.
        * macosx/tkMacOSXInit.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.37 2008/12/09 23:53:37 das Exp $
d584 1
a584 1
		0, &len) > 0) {
@


1.37
log
@	* macosx/tkMacOSXInit.c (TkpInit):	unconditionally show Tk console
						if TK_CONSOLE env var is set.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.36 2008/06/19 00:13:02 das Exp $
a18 2
#include "tclInt.h" /* for Tcl_GetStartupScript() & Tcl_SetStartupScript() */

@


1.36
log
@	* macosx/tkMacOSXInit.c:	add helper to efficiently convert from
	* macosx/tkMacOSXPrivate.h:	CFString to Tcl_Obj.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.35 2008/04/27 22:39:12 dkf Exp $
d137 1
d354 7
a360 2
	if (!isatty(0)) {
	    struct stat st;
d362 4
a365 10
	    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
		 * and tcl_interactive hasn't been set already.
		 */
d367 7
a373 11
		if (Tcl_GetStartupScript(NULL) == NULL) {
		    const char *intvar = Tcl_GetVar(interp,
			    "tcl_interactive", TCL_GLOBAL_ONLY);

		    if (intvar == NULL) {
			Tcl_SetVar(interp, "tcl_interactive", "1",
				TCL_GLOBAL_ONLY);
		    }
		}
		if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
		    return TCL_ERROR;
d375 3
@


1.35
log
@Get rid of pre-C89-isms (esp. CONST vs const).
@
text
@d9 1
a9 1
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.34 2007/12/13 15:27:09 dgp Exp $
d556 49
@


1.34
log
@merge stable branch onto HEAD
@
text
@d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28.2.4 2007/09/07 01:25:37 dgp Exp $
d27 3
a29 3
 * Define the following to 0 to not attempt to use an undocumented SPI
 * to notify the window server that an unbundled executable is a full
 * GUI application after loading Tk.
d31 1
d38 3
a40 3
 * font to the name that should be passed to Tcl_GetEncoding() to obtain
 * the encoding for that font. The set of numeric constants is fixed and
 * defined by Apple.
d87 2
a88 2
 * If the App is in an App package, then we want to add the Scripts
 * directory to the auto_path.
d90 1
a93 1

d104 2
a105 2
 *	Returns a standard Tcl result. Leaves an error message or result
 *	in the interp's result.
d123 3
a125 3
     * Since it is possible for TkInit to be called multiple times
     * and we don't want to do the following initialization multiple times
     * we protect against doing it more than once.
d134 1
a134 1
	int  i;
d149 1
a149 1
		(MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
d178 1
a178 1
	    {
d198 1
a198 1
					"__tk_rsrc", (void*)&size);
d226 1
a226 1
		    if(ChkErr(FSPathMakeRef, (unsigned char*)fileName, &ref,
d264 1
d267 1
d269 3
a271 2
		CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL,
			url);
d282 5
a286 2
	/* If we are not a bundled executable, notify the window server that
	 * we are a foregroundable app. */
d303 1
d338 2
a339 2
	 * FIXME: Close stdin & stdout for remote debugging otherwise we
	 * will fight with gdb for stdin & stdout
d400 3
a402 3
 *	Retrieves the name of the current application from a platform
 *	specific location. For Unix, the application name is the tail
 *	of the path contained in the tcl variable argv0.
d437 2
a438 2
 *	This routines is called from Tk_Main to display warning
 *	messages that occur during startup.
d451 2
a452 2
    CONST char *msg,		/* Message to be displayed. */
    CONST char *title)		/* Title of warning. */
d455 1
d469 5
a473 7
 *
 *	On MacOS X, we look for a file in the Resources/Scripts
 *	directory called AppMain.tcl and if found, we set argv[1] to
 *	that, so that the rest of the code will find it, and add the
 *	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.
d492 2
a493 5
	CFURLRef appMainURL;
	appMainURL = CFBundleCopyResourceURL(bundleRef,
		CFSTR("AppMain"),
		CFSTR("tcl"),
		CFSTR("Scripts"));
d500 4
a503 4
		    (unsigned char*) startupScript, PATH_MAX)) {
		Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, -1), NULL);
		scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(
			NULL, appMainURL);
d505 2
a506 2
		    CFURLGetFileSystemRepresentation(scriptFldrURL,
			    true, (unsigned char*) scriptPath, PATH_MAX);
d520 3
a522 5
 *
 *	Dynamically acquire address of a named symbol from a loaded
 *	dynamic library, so that we can use API that may not be
 *	available on all OS versions.
 *	If module is non-NULL and not the empty string, use twolevel
d540 1
d542 1
a542 1
	if(NSIsSymbolNameDefinedWithHint(symbol, module)) {
d546 1
a546 1
	if(NSIsSymbolNameDefined(symbol)) {
d550 2
a551 3
    if (nsSymbol) {
	return NSAddressOfSymbol(nsSymbol);
    } else {
d554 1
@


1.34.2.1
log
@sync with dkf's 2008-04-27 whitespace&formatting changes on HEAD, to ease branch maintenance.
@
text
@d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.34 2007/12/13 15:27:09 dgp Exp $
d27 3
a29 3
 * Define the following to 0 to not attempt to use an undocumented SPI to
 * notify the window server that an unbundled executable is a full GUI
 * application after loading Tk.
a30 1

d37 3
a39 3
 * font to the name that should be passed to Tcl_GetEncoding() to obtain the
 * encoding for that font. The set of numeric constants is fixed and defined
 * by Apple.
d86 2
a87 2
 * If the App is in an App package, then we want to add the Scripts directory
 * to the auto_path.
a88 1

d92 1
d103 2
a104 2
 *	Returns a standard Tcl result. Leaves an error message or result in
 *	the interp's result.
d122 3
a124 3
     * Since it is possible for TkInit to be called multiple times and we
     * don't want to do the following initialization multiple times we protect
     * against doing it more than once.
d133 1
a133 1
	int i;
d148 1
a148 1
		    (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
d177 1
a177 1
	{
d197 1
a197 1
				"__tk_rsrc", (void *) &size);
d225 1
a225 1
		    if(ChkErr(FSPathMakeRef, (unsigned char *) fileName, &ref,
a262 1

a264 1

d266 2
a267 3
		CFURLRef parent =
			CFURLCreateCopyDeletingLastPathComponent(NULL, url);

d278 2
a279 5
	/*
	 * If we are not a bundled executable, notify the window server that
	 * we are a foregroundable app.
	 */

a295 1

d330 2
a331 2
	 * FIXME: Close stdin & stdout for remote debugging otherwise we will
	 * fight with gdb for stdin & stdout
d392 3
a394 3
 *	Retrieves the name of the current application from a platform specific
 *	location. For Unix, the application name is the tail of the path
 *	contained in the tcl variable argv0.
d429 2
a430 2
 *	This routines is called from Tk_Main to display warning messages that
 *	occur during startup.
a446 1

d460 7
a466 5
 *	On MacOS X, we look for a file in the Resources/Scripts directory
 *	called AppMain.tcl and if found, we set argv[1] to that, so that the
 *	rest of the code will find it, and add the 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.
d485 5
a489 2
	CFURLRef appMainURL = CFBundleCopyResourceURL(bundleRef,
		CFSTR("AppMain"), CFSTR("tcl"), CFSTR("Scripts"));
d496 4
a499 4
		    (unsigned char *) startupScript, PATH_MAX)) {
		Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL);
		scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL,
			appMainURL);
d501 2
a502 2
		    CFURLGetFileSystemRepresentation(scriptFldrURL, true,
			    (unsigned char *) scriptPath, PATH_MAX);
d516 5
a520 3
 *	Dynamically acquire address of a named symbol from a loaded dynamic
 *	library, so that we can use API that may not be available on all OS
 *	versions. If module is non-NULL and not the empty string, use twolevel
a537 1

d539 1
a539 1
	if (NSIsSymbolNameDefinedWithHint(symbol, module)) {
d543 1
a543 1
	if (NSIsSymbolNameDefined(symbol)) {
d547 3
a549 2

    if (!nsSymbol) {
a551 1
    return NSAddressOfSymbol(nsSymbol);
@


1.34.2.2
log
@	* macosx/tkMacOSXInit.c:	add helper to efficiently convert from
	* macosx/tkMacOSXPrivate.h:	CFString to Tcl_Obj.
@
text
@d9 1
a9 1
 * Copyright (c) 2005-2008 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.34.2.1 2008/05/03 21:09:16 das Exp $
a555 49

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetStringObjFromCFString --
 *
 *	Get a string object from a CFString as efficiently as possible.
 *
 * Results:
 *	New string object or NULL if conversion failed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE Tcl_Obj*
TkMacOSXGetStringObjFromCFString(
    CFStringRef str)
{
    Tcl_Obj *obj = NULL;
    const char *c = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);

    if (c) {
	obj = Tcl_NewStringObj(c, -1);
    } else {
	CFRange all = CFRangeMake(0, CFStringGetLength(str));
	CFIndex len;

	if (CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, NULL,
		0, &len) > 0) {
	    obj = Tcl_NewObj();
	    Tcl_SetObjLength(obj, len);
	    CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false,
		    (UInt8*) obj->bytes, len, NULL);
	}
    }
    return obj;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.34.2.3
log
@avoid panic for CFStrings longer than INT_MAX
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.34.2.2 2008/06/19 00:13:10 das Exp $
d587 1
a587 1
		0, &len) > 0 && len < INT_MAX) {
@


1.33
log
@        * generic/tkWindow.c (Initialize):      Moved common Tk initialization
        * generic/tkInitScript.h (removed):     script out of tkInitScript.h
        * macosx/tkMacOSXInit.c:        and multiple TkpInit() routines and
        * unix/Makefile.in:     into the common Initialize() routine in
        * unix/tkUnixInit.c:    generic code.  Also removed constraint on
        * win/tkWinInit.c:      ability to define a custom [tkInit] before
        calling Tk_Init().  Until now the custom [tkInit] had to be a proc.
        Now it can be any command.  Removal of tkInitScript.h also fixes
        [Bug 1656283].
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.32 2007/06/29 03:20:01 das Exp $
@


1.32
log
@	* macosx/tkMacOSXScrlbr.c: correct int <-> dobule conversion issues
	that could lead to Carbon getting confused about scrollbar thumb size.

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage) use
	TkMacOSX{Setup,Restore}DrawingContext() to setup/restore clip & colors.
	(TkMacOSXSetupDrawingContext, TkMacOSXRestoreDrawingContext): add save
	and restore of QD port clip region; factor out clip region code common
	to CG and QD branches; check for port and context validity; handle
	tkPictureIsOpen flag during QD port setup.
	(TkScrollWindow): remove unnecessary scroll region manipulation

	* macosx/tkMacOSXDraw.c:	remove second global QD temp region
	* macosx/tkMacOSXInt.h:		(no longer necessary) and rename
	* macosx/tkMacOSXRegion.c:	remaining global QD temp region.
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXDraw.c:	make useCGDrawing variable MODULE_SCOPE
	* macosx/tkMacOSXFont.c:	and respect it for ATSUI font drawing.

	* macosx/tkMacOSXButton.c:	reduce reliance on current QD port
	* macosx/tkMacOSXColor.c:	setting and remove unnecessary
	* macosx/tkMacOSXDebug.c:	references to a drawable's QD port,
	* macosx/tkMacOSXDebug.h:	notably replace GetWindowFromPort(
	* macosx/tkMacOSXDialog.c:	TkMacOSXGetDrawablePort()) idiom by new
	* macosx/tkMacOSXDraw.c:	TkMacOSXDrawableWindow() and change
	* macosx/tkMacOSXKeyEvent.c:	TkMacOSXSetColorInPort() to take a port
	* macosx/tkMacOSXMenu.c:	argument.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:			factor out macros, declarations
	* macosx/tkMacOSXPrivate.h (new):	and prototypes that are purely
	internal and private to the 'macosx' sources into a new internal header
	file that does _not_ get installed into Tk.framework/PrivateHeaders.

	* macosx/tkMacOSXButton.c:		#include new tkMacOSXPrivate.h
	* macosx/tkMacOSXCarbonEvents.c:	instead of tkMacOSXInt.h.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* macosx/ttkMacOSXTheme.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.31 2007/06/09 17:09:40 das Exp $
a26 6
 * The Init script (common to Windows and Unix platforms) is
 * defined in tkInitScript.h
 */
#include "tkInitScript.h"

/*
d384 1
a384 1
    return Tcl_EvalEx(interp, initScript, -1, TCL_EVAL_GLOBAL);
@


1.31
log
@	* macosx/tkMacOSXColor.c: fix issues with TK_{IF,ELSE,ENDIF} macros;
	* macosx/tkMacOSXDraw.c:  implement Jaguar equivalent of unavailable
	* macosx/tkMacOSXEntry.c: kHIToolboxVersion global; panic at startup
	* macosx/tkMacOSXEvent.c: if MAC_OS_X_VERSION_MIN_REQUIRED constraint
	* macosx/tkMacOSXInit.c:  is not satisfied.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage)
	(TkMacOSXSetupDrawingContext): factor out common code and standardize
	setup/restore of port, context and clipping; formatting cleanup.

	* macosx/tkMacOSXWindowEvent.c:	add error checking.
	* macosx/tkMacOSXMenu.c:	fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	formatting cleanup.
	* macosx/tkMacOSXRegion.c:	fix typos.
	* macosx/tkMacOSXScale.c:

	* macosx/tkMacOSXXStubs.c (Tk_GetUserInactiveTime): remove superfluous
							    CFRetain/CFRelease.

	* macosx/Wish-Release.xcconfig: disable tktest release build stripping.

	* macosx/Wish.xcodeproj/project.pbxproj: add new Tclsh-Info.plist.in.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.30 2007/06/06 09:55:52 das Exp $
d17 1
a17 1
#include "tkMacOSXInt.h"
@


1.30
log
@	* macosx/tkMacOSXMouseEvent.c (GenerateMouseWheelEvent): enable
	processing of mousewheel events in background windows.

	* macosx/tkMacOSXScrlbr.c: modernize checks for active/front window.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXColor.c: factor out verbose #ifdef checks of
	* macosx/tkMacOSXDraw.c:  MAC_OS_X_VERSION_{MAX_ALLOWED,MIN_REQUIRED}
	* macosx/tkMacOSXEntry.c: and runtime checks of kHIToolboxVersion into
	* macosx/tkMacOSXEvent.c: new TK_{IF,ELSE,ENDIF}_MAC_OS_X macros.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c:  factor out clip clearing in QD ports;
	* macosx/tkMacOSXEntry.c: formatting cleanup.

	* macosx/Wish.xcodeproj/project.pbxproj: add settings for Fix&Continue.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.29 2007/06/04 09:27:33 das Exp $
d22 1
d97 2
d123 1
a123 1
    static int tkMacOSXInitialized = 0;
d133 1
a133 1
    if (!tkMacOSXInitialized) {
d140 2
d143 28
a170 1
	tkMacOSXInitialized = 1;
d293 1
a293 1
	    ) TK_ENDIF_MAC_OS_X
@


1.29
log
@	* macosx/tkMacOSXInit.c:	comment formatting fix for Xcode 3.0.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28 2007/04/23 21:24:33 das Exp $
d258 1
a258 6
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
	    if (1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
		    && TransformProcessType != NULL
#endif
	    ) {
d261 1
a261 2
	    }
#endif
@


1.28
log
@	* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
	* macosx/tkMacOSXEvent.c:	 handler for all kEventClassWindow and
	* macosx/tkMacOSXEvent.h:	 kEventClassMouse events;
	* macosx/tkMacOSXNotify.c:	 move all remaining events except for
	* macosx/tkMacOSXWindowEvent.c:	 kEventClassKeyboard from dispatcher to
	application event handler; pass event handler callRef downstream; fix
	debug event tracing; process all tcl event types in carbon event timer;
	delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark
	enter/exit of event tracking loop during which all tcl events but only
	carbon update events should be processed by the timer (replaces various
	calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent()
	to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to
	tkMacOSXCarbonEvents.c and modify it to dequeue only update events
	during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize
	the various ways in use to run the tcl event loop; add handling of
	kEventClassAppearance events (for ScrollBarVariantChanged event).

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXTrackingLoop() around
	* macosx/tkMacOSXEvent.c:	blocking API that puts up modal dialogs
	* macosx/tkMacOSXMenu.c:	or when entering/exiting menu/control
	* macosx/tkMacOSXMouseEvent.c:	tracking, window dragging and other
	* macosx/tkMacOSXScale.c:	mouse tracking loops.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXRunTclEventLoop()
	* macosx/tkMacOSXScale.c:	instead of Tcl_DoOneEvent(),
	* macosx/tkMacOSXScrlbr.c:	Tcl_ServiceAll(), TclServiceIdle()
	* macosx/tkMacOSXWindowEvent.c:	and Tcl_GlobalEval("update idletasks").

	* macosx/tkMacOSXColor.c: make available as Tk system colors all
	* macosx/tkMacOSXPort.h:  appearance manager brushes, text colors and
	backgrounds with new and legacy names, as well as the fully transparent
	color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to
	directly set an X pixel color value in the current QD port resp. the
	given CG context without requiring passage through rgb representation
	(lossy for most system colors); modernize/remove Classic-era code;
	replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct().

	* macosx/tkMacOSXButton.c:	use new TkMacOSXSetColorInPort()
	* macosx/tkMacOSXDraw.c:	instead of setting rgb color directly
	* macosx/tkMacOSXMenubutton.c:	to allow for non-rgb system colors.

	* macosx/tkMacOSXCursor.c: implement "none" cursor as on other
	platforms [Patch 1615427]; add all missing appearance manager cursors.

	* macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua
	L&F; use standard system color names; use new 'menu' system font;
	correct default scrollbar width.

	* macosx/tkMacOSXDraw.c:	standardize initialization, use and
	* macosx/tkMacOSXInt.h:		emptying of various static temp rgns
	* macosx/tkMacOSXRegion.c:	onto two global RgnHandles; in debug
	* macosx/tkMacOSXSubwindows.c:	builds, verify emptiness of these temp
	* macosx/tkMacOSXWindowEvent.c:	rgns before use.

	* macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to
	* macosx/tkMacOSXInt.h:  abstract common setup & teardown of drawing
	environment (for both CG and QD); save/restore QD theme drawing state;
	handle GC clip region; add TkpClipDrawableToRect() to allow clipped
	drawing into drawable regardless of GC used; use new system color
	"systemWindowHeaderBackground" to setup background in themed toplevels;
	correct implementation of TkMacOSXMakeStippleMap().

	* macosx/tkMacOSXEntry.c:  use new TkMacOSXSetupDrawingContext() and
	* macosx/tkMacOSXFont.c:   TkMacOSXRestoreDrawingContext() instead of
	* macosx/ttkMacOSXTheme.c: various setup/teardown procs like
	TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(),
	TkMacOSXSetUpGraphicsPort() etc.

	* macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields
	* macosx/tkMacOSXInt.h:   to MacDrawable struct.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al.
	use the sheet version of NavServices dialogs; ensure native parent win
	exists before using StandardSheet API for tk_messageBox [Bug 1677611];
	force sheets to behave like app-modal dialogs via WindowModality() API;
	use more modern ColorPicker API.

	* macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year.

	* macosx/tkMacOSXEntry.c:  take xOff/yOff of MacDrawable into account
	* macosx/ttkMacOSXTheme.c: when computing locations/bounds to ensure
	correct posititioning when not drawing into intermediate pixmap.

	* macosx/tkMacOSXFont.c: use appearance manager API to map system font
	* macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for
	menu item text drawing from MDEF; always draw with CG; remove QD
	dependent stippling algorithm; move most header declarations into the
	source file (as they were not used anywhere else).

	* macosx/tkMacOSXMenu.c:		 large-scale rewrite of custom
	* macosx/tkMacOSXMenu.r (removed):	 MDEF and related code that
	* macosx/Wish.xcode/project.pbxproj:	 restores many longtime-MIA
	* macosx/Wish.xcodeproj/project.pbxproj: features to working order
	* unix/Makefile.in:			 (e.g. images, custom colors &
	fonts in menus etc); implement compound menu items; use Appearance Mgr
	and ThemeText APIs to mimic native MDEF as closely as possible when
	default "menu" system font is used; remove now obsolete SICN drawing
	code and resources.

	* macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events
	* macosx/tkMacOSXEvent.c:	 in order to support <<MenuSelect>> in
	* macosx/tkMacOSXMenu.c:	 the menubar and in menus that are not
	* macosx/tkMacOSXMenus.c:	 using the custom MDEF [Bug 1620826];
	fix early and missing clearing of current Tk active menu entry; fix
	extraneous sending of <<MenuSelect>> during active menu entry clearing.

	* macosx/tkMacOSXMouseEvent.c: add support for async window dragging by
	the window server; set the corresponding window attribute by default.

	* macosx/tkMacOSXMouseEvent.c: rationalized handling order of
	non-mousedown events; add TkMacOSXModifierState() to retrieve the
	current key modifiers in carbon format.

	* macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve
	scrollbar component metrics; add awareness of multiple possibilites for
	scrollbar arrow position in aqua and handle user changes to arrow
	position pref; handle difference in metrics of small & large scrollbar
	variants; handle aqua "jump to here" scrollbar behaviour; correct
	computation of scroll view size and position; enforce min scrollbar
	height to avoid scrollbar component overlap; erase scrollbar area
	outside of standard width; remove broken auto-adjust code; account for
	window class when leaving space for grow box; remove code to manually
	draw grow box; use modern API for thumb scroll proc; replace
	HiliteControl() by modern API; replace control mgr constants with
	appearance mgr equivalents.

	* macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of
	SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix
	for [Bug 940117] made them dependent on mapping state; remove unneeded
	calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port;
	use native-endian pixmap on intel; remove obsolete pixmap pix locking.

	* macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of
	kEventAppAvailableWindowBoundsChanged events sent per transaction;
	handle kEventWindowBoundsChanged event to support live window resizing
	and centralized sending of location/size changed ConfigureNotify
	events; ensure HIGrowBox is redrawn after bounds change; constrain
	window after dragging to ensure titlebar is not inacessible
	offscreen or under dock/menubar; handle kEventWindowGetRegion and
	kEventWindowDrawContent for transparent windows to mark resp. paint
	content region as transparent; handle kEventWindowConstrain for
	fullscreen windows to ensure bounds match new screen size; enter/exit
	fullscreen UIMode upon activation/deactivation of fullscreen window.

	* macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window
	* macosx/tkMacOSXWm.h: attributes for toplevels by default; implement
	new [wm attributes] -topmost, -transparent and -fullscreen; refactor
	WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus
	factored proc to set proxy icon from [wm iconbitmap]; dynamically
	determine default values for toplevel min and max sizes (similar to
	tkWinWm.c impl): min sizes depend on window class & attributes to
	ensure visibility of all titlebar widgets and grow box, max sizes
	depend on maximal window bounds for all active displays; factor out
	code that puts into effect changes to master or override_redirect; use
	RepositionWindow() API to determine staggered initial window bounds;
	correct resize limit calculations, handle gridding and use modern
	resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify
	after resize or zoom (now handled by BoundsChanged handler); correct
	composite carbon window attribute handling, remove currently unusable
	attributes and add new attributes in [tk::unsupported::MacWindowStyle];
	ensure validity of window class and attributes before use; apply
	changes to window class when handling carbon window attribute changes
	(if HIWindowChangeClass() API available); add debug build warning
	message when deprecated window style is used instead of window class;
	use transparent HIGrowBox for resizable windows; avoid unnecessary
	calls to window structure width API; use tcl time API in TkpGetMS();
	add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and
	menubar hidden; restrict wmTracing output to debug builds; remove
	unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD
	port; workaround GetWindowStructureWidths() Carbon bug (bogus results
	for never-mapped floating windows).

	* macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window
	bounds field to Screen record (in ext_data), computed as the union of
	available window positioning bounds of all graphics devices (displays).

	* macosx/tkMacOSXBitmap.c: fix macRoman encoding leak.
	* macosx/tkMacOSXCursor.c:

	* macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static
	* macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes.

	* macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of
	* macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld().
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS
	* macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c: remove obsolete and now incorrect
	* macosx/tkMacOSXInt.h:  tkMenuCascadeRgn clipping code.
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval()
	* macosx/tkMacOSXScrlbr.c:   by Tcl_EvalEx().
	* macosx/tkMacOSXInit.c:

	* macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps.

	* macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support.

	* macosx/tkMacOSXMenus.c: remove now useless call to
	TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman
	literar chars to allow file to be edited as utf-8.

	* macosx/tkMacOSXScale.c: replace TrackControl() by modern
	* macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new
	TkMacOSXModifierState()).

	* macosx/tkMacOSXInt.h:		move all constant #defines needed to
	* macosx/tkMacOSXColor.c:	support building on older OS X releases
	* macosx/tkMacOSXEvent.h:	to a central location in tkMacOSXInt.h.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/ttkMacOSXTheme.c:

	* macosx/tkMacOSXInt.h:		 add ChkErr() macro to factor out
	* macosx/tkMacOSXButton.c:	 Carbon OSStatus return value checking
	* macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour
	* macosx/tkMacOSXClipboard.c:	 out debug message output; use these
	* macosx/tkMacOSXColor.c:	 macros to replace #ifdef TK_MAC_DEBUG
	* macosx/tkMacOSXCursor.c:	 blocks & direct printing to stderr,
	* macosx/tkMacOSXDebug.c:	 and to do additional OSStatus return
	* macosx/tkMacOSXDialog.c:	 checking, and to standardize OSStatus
	* macosx/tkMacOSXDraw.c:	 usage.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXSend.c:	remove duplicate/unused declarations
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXDebug.c:	const fixes.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/Wish-Info.plist.in: add tcl document extensions/mime types and
	LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys.

	* macosx/Wish-Common.xcconfig: add Wish's Info.plist as __info_plist
	section to tktest; enable more warnings.

	* macosx/Wish.xcodeproj/project.pbxproj: add 'DebugMemCompile' build
	configuration that calls configure with --enable-symbols=all; disable
	configure check for __attribute__((__visibility__("hidden"))) in Debug
	configuration to restore availability of ZeroLink.

	* macosx/Wish-Common.xcconfig:	fix whitespace.
	* macosx/Wish-Debug.xcconfig:
	* macosx/Wish-Release.xcconfig:
	* macosx/tkMacOSXAETE.r:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursors.r:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXSend.c:
	* macosx/ttkMacOSXTheme.c:
	* macosx/tkMacOSXXCursors.r:
	* macosx/README:

	* macosx/GNUmakefile:		fix/add copyright and license refs.
	* macosx/Tk-Info.plist.in:
	* macosx/Wish-Info.plist.in:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/project.pbxproj:
	* macosx/tkMacOSX.h:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.27 2007/04/21 19:06:38 hobbs Exp $
d310 1
a310 1
	 * REMOVE ME: Close stdin & stdout for remote debugging otherwise we
@


1.28.2.1
log
@merge updates from HEAD
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28 2007/04/23 21:24:33 das Exp $
d310 1
a310 1
	 * FIXME: Close stdin & stdout for remote debugging otherwise we
@


1.28.2.2
log
@merge updates from HEAD
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28.2.1 2007/06/04 15:19:00 dgp Exp $
a21 1
#include <sys/utsname.h>
a95 2
float tkMacOSXToolboxVersionNumber = 0;

d120 1
a120 1
    static int initialized = 0;
d130 1
a130 1
    if (!initialized) {
a136 27
	struct utsname name;
	long osVersion = 0;

	initialized = 1;
	
	/*
	 * Initialize/check OS version variable for runtime checks.
	 */
	
	if (!uname(&name)) {
	    osVersion = strtol(name.release, NULL, 10) - 4;
	}
	if (osVersion && osVersion < (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10) {
	    Tcl_Panic("Mac OS X 10.%d or later required !",
		(MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
	}
	TK_IF_MAC_OS_X_API (3, &kHIToolboxVersionNumber,
	    tkMacOSXToolboxVersionNumber = kHIToolboxVersionNumber;
	) TK_ELSE_MAC_OS_X (3,
	    if (osVersion > 5) {
		tkMacOSXToolboxVersionNumber = INFINITY;
	    } else if (osVersion >= 3) {
		static const float tbVersions[3] = {
		    kHIToolboxVersionNumber10_3,
		    kHIToolboxVersionNumber10_4,
		    kHIToolboxVersionNumber10_5,
		};
d138 1
a138 3
		tkMacOSXToolboxVersionNumber = tbVersions[osVersion-3];
	    }
	) TK_ENDIF
d258 6
a263 1
	    TK_IF_MAC_OS_X_API (3, TransformProcessType,
d266 2
a267 1
	    ) TK_ENDIF
@


1.28.2.3
log
@merge updates from HEAD
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id$
d17 1
a17 1
#include "tkMacOSXPrivate.h"
@


1.28.2.4
log
@merge updates from HEAD
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28.2.3 2007/07/01 17:31:33 dgp Exp $
d27 6
d390 1
a390 1
    return TCL_OK;
@


1.28.2.5
log
@merge updates from 8.5 branch
@
text
@d9 1
a9 1
 * Copyright (c) 2005-2008 Daniel A. Steffen <das@@users.sourceforge.net>
d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.28.2.4 2007/09/07 01:25:37 dgp Exp $
d27 3
a29 3
 * Define the following to 0 to not attempt to use an undocumented SPI to
 * notify the window server that an unbundled executable is a full GUI
 * application after loading Tk.
a30 1

d37 3
a39 3
 * font to the name that should be passed to Tcl_GetEncoding() to obtain the
 * encoding for that font. The set of numeric constants is fixed and defined
 * by Apple.
d86 2
a87 2
 * If the App is in an App package, then we want to add the Scripts directory
 * to the auto_path.
a88 1

d92 1
d103 2
a104 2
 *	Returns a standard Tcl result. Leaves an error message or result in
 *	the interp's result.
d122 3
a124 3
     * Since it is possible for TkInit to be called multiple times and we
     * don't want to do the following initialization multiple times we protect
     * against doing it more than once.
d133 1
a133 1
	int i;
d148 1
a148 1
		    (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
d177 1
a177 1
	{
d197 1
a197 1
				"__tk_rsrc", (void *) &size);
d225 1
a225 1
		    if(ChkErr(FSPathMakeRef, (unsigned char *) fileName, &ref,
a262 1

a264 1

d266 2
a267 3
		CFURLRef parent =
			CFURLCreateCopyDeletingLastPathComponent(NULL, url);

d278 2
a279 5
	/*
	 * If we are not a bundled executable, notify the window server that
	 * we are a foregroundable app.
	 */

a295 1

d330 2
a331 2
	 * FIXME: Close stdin & stdout for remote debugging otherwise we will
	 * fight with gdb for stdin & stdout
d392 3
a394 3
 *	Retrieves the name of the current application from a platform specific
 *	location. For Unix, the application name is the tail of the path
 *	contained in the tcl variable argv0.
d429 2
a430 2
 *	This routines is called from Tk_Main to display warning messages that
 *	occur during startup.
a446 1

d460 7
a466 5
 *	On MacOS X, we look for a file in the Resources/Scripts directory
 *	called AppMain.tcl and if found, we set argv[1] to that, so that the
 *	rest of the code will find it, and add the 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.
d485 5
a489 2
	CFURLRef appMainURL = CFBundleCopyResourceURL(bundleRef,
		CFSTR("AppMain"), CFSTR("tcl"), CFSTR("Scripts"));
d496 4
a499 4
		    (unsigned char *) startupScript, PATH_MAX)) {
		Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL);
		scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL,
			appMainURL);
d501 2
a502 2
		    CFURLGetFileSystemRepresentation(scriptFldrURL, true,
			    (unsigned char *) scriptPath, PATH_MAX);
d516 5
a520 3
 *	Dynamically acquire address of a named symbol from a loaded dynamic
 *	library, so that we can use API that may not be available on all OS
 *	versions. If module is non-NULL and not the empty string, use twolevel
a537 1

d539 1
a539 1
	if (NSIsSymbolNameDefinedWithHint(symbol, module)) {
d543 1
a543 1
	if (NSIsSymbolNameDefined(symbol)) {
d547 3
a549 2

    if (!nsSymbol) {
a551 41
    return NSAddressOfSymbol(nsSymbol);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetStringObjFromCFString --
 *
 *	Get a string object from a CFString as efficiently as possible.
 *
 * Results:
 *	New string object or NULL if conversion failed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE Tcl_Obj*
TkMacOSXGetStringObjFromCFString(
    CFStringRef str)
{
    Tcl_Obj *obj = NULL;
    const char *c = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);

    if (c) {
	obj = Tcl_NewStringObj(c, -1);
    } else {
	CFRange all = CFRangeMake(0, CFStringGetLength(str));
	CFIndex len;

	if (CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, NULL,
		0, &len) > 0) {
	    obj = Tcl_NewObj();
	    Tcl_SetObjLength(obj, len);
	    CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false,
		    (UInt8*) obj->bytes, len, NULL);
	}
    }
    return obj;
a552 9

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.27
log
@	* macosx/tkMacOSXBitmap.c, macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c, macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXCursor.c, macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c, macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c, macosx/tkMacOSXInit.c, macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c, macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c, macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c, macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c: Revert of commits from 2007-04-13 which
	broke the OS X build.
@
text
@d1 1
a1 1
/* 
d4 2
a5 2
 *        This file contains Mac OS X -specific interpreter initialization
 *        functions.
d9 1
a9 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.25 2006/11/24 19:03:50 hobbs Exp $
d43 1
a43 1
 * the encoding for that font.  The set of numeric constants is fixed and
d49 1
a49 1
    char *strKey;
d85 1
a85 1
    {0, 		NULL}
d96 1
d102 2
a103 2
 *        Performs Mac-specific interpreter initialization related to the
 *        tk_library variable.
d106 2
a107 2
 *        Returns a standard Tcl result.  Leaves an error message or result
 *        in the interp's result.
d110 1
a110 1
 *        Sets "tk_library" Tcl variable, runs "tk.tcl" script.
d116 2
a117 2
TkpInit(interp)
    Tcl_Interp *interp;
d120 1
a120 1
    static int tkMacOSXInitialized = false;
d124 1
a124 1
    /* 
d126 1
a126 1
     * and we don't want to do the initialization multiple times
d130 4
a133 1
    if (tkMacOSXInitialized == false) {
d135 1
a135 1
	char *encodingStr = NULL;
d138 1
a138 25
	tkMacOSXInitialized = true;

	TkMacOSXInitAppleEvents(interp);
	TkMacOSXInitCarbonEvents(interp);
	TkMacOSXInitMenus(interp);
	TkMacOSXUseAntialiasedText(interp, -1);
	TkMacOSXInitCGDrawing(interp, TRUE, 0);
	TkMacOSXInitKeyboard(interp);

	encoding = CFStringGetSystemEncoding();

	for (i = 0; scriptMap[i].strKey != NULL; i++) {
	    if (scriptMap[i].numKey == encoding) {
		encodingStr = scriptMap[i].strKey;
		break;
	    }
	}
	if (encodingStr == NULL) {
	    encodingStr = "macRoman";
	}

	TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr);
	if (TkMacOSXCarbonEncoding == NULL) {
	    TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL);
	}
d141 1
a141 1
	 * When Tk is in a framework, force tcl_findLibrary to look in the 
d148 2
a149 1
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
d165 1
a165 1
		/* Get resource data from __tk_rsrc section of tk library file */
d170 2
a171 1
			data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
a178 1
		    OSStatus err;
d182 4
a185 1
		    /* Write resource data to temporary file and open it */
d192 3
a194 1
		    if (fd == -1) break;
d196 9
a204 7
		    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);
#endif
d215 97
a311 2
	/* REMOVE ME: Close stdin & stdout for remote debugging otherwise we
	 * will fight with gdb for stdin & stdout 
d314 3
a316 3
	if (getenv ("XCNOSTDIN") != NULL) {
	    close (0);
	    close (1);
d327 1
d333 1
d338 1
d340 3
a342 2
		    CONST char *intvar =
			Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY);
a352 67

	/*
	 * 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, 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, notify the window server that
	     * we are a foregroundable app. */
	    if (!bundledExecutable) {
		OSStatus err = procNotFound;
		ProcessSerialNumber psn = { 0, kCurrentProcess };
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
		if (TransformProcessType != NULL) {
		    err = TransformProcessType(&psn,
			    kProcessTransformToForegroundApplication);
		}
#endif
#if MAC_OSX_TK_USE_CPS_SPI
		if (err != noErr) {
		    /*
		     * When building or running on 10.2 or when the above fails,
		     * attempt to use undocumented CPS SPI to notify the window
		     * server. Load the SPI symbol dynamically, so that we don't
		     * break if it ever disappears or changes its name.
		     */
		    TkMacOSXInitNamedSymbol(CoreGraphics, OSErr,
			    CPSEnableForegroundOperation, ProcessSerialNumberPtr);
		    if (CPSEnableForegroundOperation) {
			CPSEnableForegroundOperation(&psn);
		    }
		}
#endif /* MAC_OSX_TK_USE_CPS_SPI */
	    }
	}
d364 1
a364 1
    return Tcl_Eval(interp, initScript);
d372 3
a374 3
 *        Retrieves the name of the current application from a platform
 *        specific location.  For Unix, the application name is the tail
 *        of the path contained in the tcl variable argv0.
d377 1
a377 1
 *        Returns the application name in the given Tcl_DString.
d380 1
a380 1
 *        None.
d386 3
a388 3
TkpGetAppName(interp, namePtr)
    Tcl_Interp *interp;
    Tcl_DString *namePtr;        /* A previously initialized Tcl_DString. */
d390 1
a390 1
    CONST char *p, *name;
d409 2
a410 2
 *        This routines is called from Tk_Main to display warning
 *        messages that occur during startup.
d413 1
a413 1
 *        None.
d416 1
a416 1
 *        Generates messages on stdout.
d422 3
a424 3
TkpDisplayWarning(msg, title)
    CONST char *msg;                  /* Message to be displayed. */
    CONST char *title;                /* Title of warning. */
d441 6
a446 6
 *        On MacOS X, we look for a file in the Resources/Scripts
 *        directory called AppMain.tcl and if found, we set argv[1] to
 *        that, so that the rest of the code will find it, and add the
 *        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.
d449 1
a449 1
 *        None.
d452 1
a452 1
 *        Tcl_SetStartupScript() called when AppMain.tcl found.
d466 3
a468 3
	appMainURL = CFBundleCopyResourceURL(bundleRef, 
		CFSTR("AppMain"), 
		CFSTR("tcl"), 
d481 1
a481 1
		    CFURLGetFileSystemRepresentation(scriptFldrURL, 
d497 6
a502 6
 *        Dynamically acquire address of a named symbol from a loaded
 *        dynamic library, so that we can use API that may not be
 *        available on all OS versions.
 *        If module is non-NULL and not the empty string, use twolevel
 *        namespace lookup.
 *       
d504 1
a504 1
 *        Address of given symbol or NULL if unavailable.
d507 1
a507 1
 *        None.
d513 3
a515 1
TkMacOSXGetNamedSymbol(const char* module, const char* symbol)
d527 1
a527 1
    if(nsSymbol) {
@


1.26
log
@Reduce the #ifdef count a lot by adding debug-print macros
@
text
@d201 1
a201 4
		    /*
		     * Write resource data to temporary file and open it.
		     */

d208 1
a208 3
		    if (fd == -1) {
			break;
		    }
d210 1
a210 3
		    if (write(fd, data, size) == -1) {
			break;
		    }
d212 1
a212 3
		    if (err != noErr) {
			break;
		    }
d214 3
a216 1
		    LOG_ON_ERROR(FSOpenResourceFile);
d228 2
a229 1
	 * will fight with gdb for stdin & stdout */
d231 3
a233 3
	if (getenv("XCNOSTDIN") != NULL) {
	    close(0);
	    close(1);
a243 1

a248 1

d250 2
a251 2
		 * Only show the console if we don't have a startup script and
		 * tcl_interactive hasn't been set already.
a252 1

d254 2
a255 3
		    CONST char *intvar = Tcl_GetVar(interp,
			    "tcl_interactive", TCL_GLOBAL_ONLY);

@


1.25
log
@	* macosx/tkMacOSXInit.c (TkpInit): only set tcl_interactive 1 if
	it isn't already defined.  Allows embedders to set it to 0 to
	prevent the console appearing on OS X. [Bug 1487701]
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.24 2006/10/16 15:35:28 das Exp $
d201 4
a204 1
		    /* Write resource data to temporary file and open it */
d211 3
a213 1
		    if (fd == -1) break;
d215 3
a217 1
		    if (write(fd, data, size) == -1) break;
d219 3
a221 1
		    if (err != noErr) break;
d223 1
a223 3
#ifdef TK_MAC_DEBUG
		    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
#endif
d235 1
a235 2
	 * will fight with gdb for stdin & stdout 
	 */
d237 3
a239 3
	if (getenv ("XCNOSTDIN") != NULL) {
	    close (0);
	    close (1);
d250 1
d256 1
d258 2
a259 2
		 * Only show the console if we don't have a startup script
		 * and tcl_interactive hasn't been set already.
d261 1
d263 3
a265 2
		    CONST char *intvar =
			Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY);
@


1.24
log
@	* changes: updates for 8.5a5 release.

	* macosx/tkMacOSXDraw.c: fix numerous issues in CG and QD drawing procs
	so that they now match X11 drawing much more closely [Bug 1558051];
	use Tiger ellipse drawing API when available; fix comments & whitespace.

	* macosx/tkMacOSXInit.c: set default linewidth limit for CG
	antialiasing to 0 as thin horizontal/vertical lines look good now.

	* generic/tkCanvLine.c (ConfigureLine):     on TkAqua, pass outline
	* generic/tkCanvPoly.c (ConfigurePolygon):  linewidth in gc even for
	* generic/tkRectOval.c (ConfigureRectOval): fills (as it controls AA).
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.23 2006/08/18 07:47:10 das Exp $
a226 6
	/*
	 * 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.
	 */

d236 6
d249 4
a252 1
		/* Only show the console if we don't have a startup script */
d254 6
a259 1
		    Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
d268 4
a271 4
	 * 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, notify the window server that we are now a
	 * full GUI application.
@


1.23
log
@	* unix/tcl.m4 (Darwin): add support for --enable-64bit on x86_64, for
	universal builds including x86_64, for 64-bit CoreFoundation on Leopard
	and for use of -mmacosx-version-min instead of MACOSX_DEPLOYMENT_TARGET.
	* unix/configure.in (Darwin): remove 64-bit arch flags from CFLAGS for
	combined 32-bit and 64-bit universal builds, as neither TkAqua nor TkX11
	can be built for 64-bit at present.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/Wish.xcodeproj/project.pbxproj: switch native release targets
	to use DWARF with dSYM, Xcode 3.0 changes.
	* macosx/README: updates for x86_64 and Xcode 2.3.

	* macosx/tkMacOSXInit.c (TkpInit): when available, use public
	TransformProcessType() API instead of CPSEnableForegroundOperation() SPI
	to notify the window server that we are a GUI application.

	* macosx/tkMacOSXWm.c (WmAttrGetTitlePath): use HIWindow API on >=Tiger.

	* macosx/tkMacOSXMouseEvent.c (GenerateToolbarButtonEvent):
	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent): bzero XVirtualEvent structure
	before use to ensure all fields are initialized. [Bug 1542205]
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.22 2006/07/20 06:24:16 das Exp $
d140 1
a140 1
	TkMacOSXInitCGDrawing(interp, TRUE, 3);
@


1.22
log
@	* generic/tkImgGIF.c (ReadImage):
	* macosx/tkMacOSXCursor.c (TkMacOSXCursor):
	* macosx/tkMacOSXDebug.c (TkMacOSXGetNamedDebugSymbol):
	* macosx/tkMacOSXInit.c (Map):
	* xlib/xgc.c (XCreateGC): fix signed-with-unsigned comparison and other
	warnings from gcc4 -Wextra.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.21 2006/05/12 18:17:48 das Exp $
d258 1
a258 1
#if MAC_OSX_TK_USE_CPS_SPI
d262 2
a263 2
	 * For such an executable, we attempt to use an undocumented SPI to
	 * notify the window server that we are now a full GUI application.
d297 2
a298 1
	    /* If we are not a bundled executable, attempt to use the CPS SPI: */
d300 10
a309 8
		/*
		 * 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 };
d311 4
a314 1
		     * Let the window server know that we are a foregroundable app
d316 5
a320 1
		    CPSEnableForegroundOperation(&psn);
d322 1
a324 1
#endif /* MAC_OSX_TK_USE_CPS_SPI */
@


1.21
log
@	* 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.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.20 2006/04/11 10:19:51 das Exp $
d48 1
a48 1
    int numKey;
@


1.20
log
@	* macosx/tkMacOSXFont.c: remove #ifdef'd text measuring codepaths now
	* macosx/tkMacOSXInit.c: known to be incorrect, cleanup obsolete text
	* macosx/README:         antialiasing control code, document ATSUI
	                         text antialiasing changes.
@
text
@d9 1
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.19 2006/03/24 14:58:01 das Exp $
d92 1
a92 1
 * directory to the auto_path.      
d102 1
a102 1
 *      tk_library variable.
d134 8
a141 1
    	tkMacOSXInitialized = true;
a142 6
        TkMacOSXInitAppleEvents(interp);
        TkMacOSXInitCarbonEvents(interp);
        TkMacOSXInitMenus(interp);
        TkMacOSXUseAntialiasedText(interp, -1);
        TkMacOSXInitCGDrawing(interp, TRUE, 3);
	
d144 1
a144 1
	
d154 1
a154 1
	
d159 7
a165 7
        
        /*
         * 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?
         */
         
d167 2
a168 2
        if (Tcl_MacOSXOpenVersionedBundleResources(interp, 
                "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
d170 6
a175 6
            {
            /* Tk.framework not found, check if resource file is open */
            Handle rsrc = Get1NamedResource('CURS', "\phand");
            if (rsrc) {
                ReleaseResource(rsrc);
            } else {
d177 37
a213 37
                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);
d215 1
a215 1
                    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
d217 6
a222 6
                    break;
                }
                if (fd != -1) {
                    unlink(fileName);
                    close(fd);
                }
d224 34
a257 34
            }
        }
                 
        /*
         * 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;
                }
            }
        }
d259 55
a313 55
        /*
         * 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);
                }
            }
        }
d318 1
a318 1
        Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
d322 2
a323 2
        Tcl_SetVar(interp, "auto_path", scriptPath,
                TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
d325 1
a325 1
    
d356 1
a356 1
        name = "tk";
d358 4
a361 4
        p = strrchr(name, '/');
        if (p != NULL) {
            name = p+1;
        }
d390 4
a393 4
        Tcl_WriteChars(errChannel, title, -1);
        Tcl_WriteChars(errChannel, ": ", 2);
        Tcl_WriteChars(errChannel, msg, -1);
        Tcl_WriteChars(errChannel, "\n", 1);
d409 1
a409 1
 *       
d423 1
a423 1
    
d425 1
a425 1
    
d427 23
a449 23
        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);
        }
d483 3
a485 3
        if(NSIsSymbolNameDefined(symbol)) {
            nsSymbol = NSLookupAndBindSymbol(symbol);
        }
d490 1
a490 1
        return NULL;
@


1.19
log
@	* generic/tkTextDisp.c:   moved #ifdef MAC_OSX_TK code added by
	* macosx/tkMacOSXColor.c: Patch #638966 into platform specific
	* macosx/tkMacOSXInt.h:   files.

	* macosx/tkMacOSX.h:             cleaned up & rationalized order of
	* macosx/tkMacOSXBitmap.c:       #includes of tk and carbon headers.
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.18 2006/01/10 05:37:51 das Exp $
d138 1
a138 1
        TkMacOSXUseAntialiasedText(interp, TRUE);
@


1.18
log
@	* macosx/tkMacOSXDebug.c: add TkMacOSXGetNamedDebugSymbol() function
	* macosx/tkMacOSXDebug.h: that finds unexported symbols in loaded
	libraries by manually walking their symbol table; only to be used for
	debugging purposes, may break unexpectedly in the future. Needed to get
	access to private_extern internal debugging functions in HIToolbox.

	* macosx/tkMacOSXCarbonEvents.c: fix debug event tracing on Tiger.
	* macosx/tkMacOSXMenu.c: add debug menu printing during reconfigure.
	* macosx/tkMacOSXInit.c: conditionalize 64bit-unsafe dyld code.
	* macosx/GNUmakefile: add 'wish8.x' symlink to SYMROOT.

	* macosx/Wish.xcode/project.pbxproj:     fix copy to tktest resource
	* macosx/Wish.xcodeproj/project.pbxproj: fork when zerolinked.

	* macosx/Wish.xcode/default.pbxuser:     add widget demo as argument to
	* macosx/Wish.xcodeproj/default.pbxuser: executables (on by default).

	* unix/configure:    add caching, use AC_CACHE_CHECK instead of
	* unix/configure.in: AC_CACHE_VAL where possible, consistent message
	* unix/tcl.m4:       quoting, sync relevant tclconfig/tcl.m4 changes and
	gratuitous formatting differences, fix SC_CONFIG_MANPAGES with default
	argument, Darwin improvements to SC_LOAD_*CONFIG.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.17 2005/12/08 07:50:14 das Exp $
a15 1
#include "tkInt.h"
d17 1
d19 1
@


1.17
log
@        * macosx/tkMacOSXDraw.c:   remove inclusion of tclInt.h and use of tcl
        * macosx/tkMacOSXFont.c:   internals wherever possible in tk/macosx, the
        * macosx/tkMacOSXInit.c:   only remaining tcl internals in TkAqua are
        * macosx/tkMacOSXNotify.c: TclServiceIdle() in tkMacOSXScrlbr.c and
        * macosx/tkMacOSXScrlbr.c: Tcl_Get/SetStartupScript() in tkMacOSXInit.c
	                           [Bug 1336531].
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.16 2005/11/27 02:36:15 das Exp $
d173 1
d179 1
a179 1
                int i, n;
d220 1
@


1.16
log
@	* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
	add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
	configure (flag can't be present twice, so can't be in both CFLAGS and
	LDFLAGS during configure), don't use -prebind when deploying on 10.4,
	define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
	(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
	autoconf macros. Sync with tcl/unix/tcl.m4.

	* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
	formatting/ordering differences with tcl/unix/configure.in.

	* unix/Makefile.in: add CFLAGS to wish/tktest link to make executable
	linking the same as during configure (needed to avoid loosing any linker
	relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS).
	Avoid concurrent linking of wish and compiling of tkTestInit.o during
	parallel make, fix dependencies and flags for building tkMacOSXInit.o
	(checkstubs, checkexports): dependency and Darwin fixes
	(dist): add new macosx files.

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessEvent):
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	* macosx/tkMacOSXCarbonEvents.c: install standard application event
	handler, add & call functions to start and stop carbon even timer that
	runs the tcl event loop periodically during a nested carbon event loop
	in the toolbox (e.g. during menutracking) to ensure tcl timers etc
	continue to fire, register app event handler for menu tracking and HI
	command carbon events, move menu event handling to new handlers for
	those carbon events, no longer register for/handle appleevent carbon
	event (now dealt with by standard application event handler), event
	debugging code dynamically acquires carbon event debugging functions to
	allow use on Tiger where they are no longer exported from HIToolbox.

	* macosx/tkMacOSXFont.c (TkMacOSXUseAntialiasedText):
	* macosx/tkMacOSXKeyEvent.c (GetKeyboardLayout):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: abstract common code to dynamically acquire
	address of a named symbol (from a loaded dynamic library) into new
	function TkMacOSXGetNamedSymbol() and macro TkMacOSXInitNamedSymbol.

	* macosx/tkMacOSXMenu.c (TkpNewMenu):
	* macosx/tkMacOSXMenubutton.c (MenuButtonInitControl):
	* macosx/tkMacOSXMenus.c (TkMacOSXHandleMenuSelect): switch to  modern
	utf8 aware menu manager API, remove obsolete code, add error handling.

	* macosx/tkMacOSXMouseEvent.c: define OSX 10.3 or later only constants
	if necessary to allow compilation on OSX 10.2

	* macosx/tkMacOSXWm.c (UpdateSizeHints): remove code that is never
	executed.

	* xlib/xgc.c (XCreateGC): sync with core-8-4-branch change.

	* generic/tk.h: add/correct location of version numbers in macosx files.

	* generic/tkInt.h: clarify fat compile comment.

	* macosx/Wish.pbproj/default.pbxuser (new file):
	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/default.pbxuser (new file):
	* macosx/Wish.xcodeproj/project.pbxproj (new file): new/updated projects
	for Xcode 2.2 on 10.4, Xcode 1.5 on 10.3 & ProjectBuilder on 10.2, with
	native tktest targets and support for universal (fat) compiles.

	* macosx/Tk-Info.plist (removed):
	* macosx/Wish-Info.plist (removed):
	* macosx/buildTkConfig.tcl (removed): remove obsolete build files.

	* macosx/README: clarification/cleanup, document new Xcode projects and
	universal (fat) builds via CFLAGS (i.e. ppc and i386 at the same time).

	* unix/Makefile.in:
	* unix/aclocal.m4:
	* unix/configure.in:
	* macosx/configure.ac (new file): add support for inclusion of
	unix/configure.in by macosx/configure.ac, allows generation of a config
	headers enabled configure script in macosx (required by Xcode projects).

	* macosx/GNUmakefile: rename from Makefile to avoid overwriting by
	configure run in tk/macosx, add support for reusing configure cache,
	build target fixes.

	* generic/tk3d.h:
	* generic/tkButton.h:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h:
	* generic/tkColor.h:
	* generic/tkEntry.h:
	* generic/tkFileFilter.h:
	* generic/tkFont.c:
	* generic/tkFont.h:
	* generic/tkImage.c:
	* generic/tkImgPhoto.c:
	* generic/tkInt.h:
	* generic/tkMenu.c:
	* generic/tkMenu.h:
	* generic/tkMenubutton.h:
	* generic/tkScale.h:
	* generic/tkScrollbar.h:
	* generic/tkSelect.h:
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* generic/tkText.h:
	* generic/tkUndo.h:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixMenu.c:
	* xlib/xgc.c: ensure externally visible symbols not contained in stubs
	table are declared as MODULE_SCOPE (or as static if not used outside of
	own source file), #ifdef out a few Xlib and aqua functions that are
	never called. These changes allow 'make checkstubs' to complete without
	error on Darwin with gcc 4.

	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXPort.h:
	* win/tkWinTest.c:
	* generic/tkInt.decls: add functions needed by tktest to internal stubs
	table, correct signature of TkMacOSXHandleMenuSelect, add XSync to aqua
	Xlib stubs.

	* unix/tkUnixSend.c:
	* generic/tkText.c:
	* generic/tkTest.c: #ifdef unix only declarations.
	(TestmetricsCmd): unify win and mac implementation.
	(TestsendCmd): move to tkUnixSend.c to avoid access to global var.
	(TesttextCmd): move to tkText.c to avoid having to put all the internal
	text functions it uses into the stubs table.

	* generic/tkTextDisp.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXXStubs.c: fix gcc 4 warnings.

	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXScrlbr.c: sync with core-8-4-branch.

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure:
	* unix/tkConfig.h.in: regen.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.15 2005/09/10 14:53:20 das Exp $
d18 1
a18 1
#include "tclInt.h"
@


1.15
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): check if
	process is in front on MouseDown, otherwise request process activation
	from BringWindowForward() via new isFrontProcess param.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents): register our
	event handler on the dispatcher target for all carbon events of interest
	to TkAqua; this replaces event processing directly from the event queue
	and thus allows to capture events that are syntesized by Carbon and sent
	directly to the dispatcher and not to the event queue.

	* macosx/tkMacOSXEvent.c: remove TkMacOSXCountAndProcessMacEvents(),
	rename ReceiveAndProcessEvent() to TkMacOSXReceiveAndProcessEvent().
	(TkMacOSXReceiveAndProcessEvent): remove tk event processing before
	sending events to the dispatcher, all events of interest are now
	processed in our dispatcher target event handler.

	* macosx/tkMacOSXNotify.c (CarbonEventsCheckProc): dispatch events
	directly via TkMacOSXReceiveAndProcessEvent(), but dispatch no more than
	four carbon events at one time to avoid starving other event sources.

	* macosx/tkMacOSXEvent.c: formatting cleanup, move XSync() to XStubs,
	* macosx/tkMacOSXEvent.h: removed obsolete kEventClassWish handling.
	* macosx/tkMacOSXXStubs.c

	* macosx/tkMacOSXEvent.h: declare macosx internal procs as MODULE_SCOPE.
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXButton.c: conditionalize all debug message printing to
	* macosx/tkMacOSXCursor.c: stderr via TK_MAC_DEBUG define.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* unix/configure.in: define TK_MAC_DEBUG on aqua when symbols enabled.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* library/listbox.tcl: synced aqua MouseWheel bindings with
	* library/scrlbar.tcl: core-8-4-branch.
	* library/text.tcl:

	* xlib/xcolors.c: fixed warning
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.14 2005/08/09 07:39:21 das Exp $
d173 1
a173 1
                struct mach_header *image;
d175 1
a175 1
                unsigned long size;
d207 1
a207 1
                    err = FSPathMakeRef(fileName, &ref, NULL);
d298 3
a300 11
                OSErr (*cpsEnableForegroundOperation)(ProcessSerialNumberPtr) = NULL;
                NSSymbol nsSymbol;
                if(NSIsSymbolNameDefinedWithHint(
                        "_CPSEnableForegroundOperation", "CoreGraphics")) {
                    nsSymbol = NSLookupAndBindSymbolWithHint(
                        "_CPSEnableForegroundOperation", "CoreGraphics");
                    if(nsSymbol) {
                        cpsEnableForegroundOperation = NSAddressOfSymbol(nsSymbol);
                    }
                }
                if (cpsEnableForegroundOperation) {
d305 1
a305 1
                    cpsEnableForegroundOperation(&psn);
d447 41
@


1.14
log
@	* macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon
	events sent directly to application event target via the general
	TkMacOSXProcessEvent() in the same way as events posted to the event
	loop. Moved existing app event handlers to tkMacOSXWindowEvent.c.
	(TkMacOSXInitCarbonEvents): register our application event handler for
	kEventWindowExpanded events to deal with uncollapsing from the dock.

	* macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added
	* macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for
	                          use by app event handler.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve
	current window, partCode, modifiers and local cursor position from
	carbon mouse event if possible. Use new static GenerateButtonEvent()
	taking a MouseEventData struct instead of TkGenerateButtonEvent() to
	avoid recomputing already known values. Move process activation on
	MouseDown into BringWindowForward() to allow clicking on window titlebar
	widgets without activating process. Move code dealing with clicks in
	window titelbar into separate function HandleWindowTitlebarMouseDown()
	to avoid code duplication. Avoid repeated calls to TkMacOSXGetXWindow()
	by storing result in MouseEventData struct.
	(TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier
	state from currently processed carbon event (to avoid unnecessary IPC
	with the window server), otherwise use modern carbon API to get this
	info instead of Button() and GetKeys(); only retrieve info caller asks
	for (via non-NULL ptr passed to XQueryPointer).
	(ButtonModifiers2State): new static function converting carbon button
	and modifier state into tk state, allows detection of more than 3 mouse
	buttons (tk supports up to 5) and of NumLock and Fn modifier keys
	(NumLock is mapped to Mod3 and Fn to Mod4).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent): handle
	kEventWindowExpanded event to deal with window uncollapsing from the
	dock by generating tk Map event, handle kEventAppHidden and
	kEventAppShown events (moved here from tkMacOSXCarbonEvents.c).

	* macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when
	it is not iconified to avoid window flashing on collapse.

	* macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle().
	(TkMacOSXZoomToplevel): remove call to TrackBox(), now done in
	HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c.
	(TkpWmSetState): avoid window flashing on collapse by unmapping after
	calling CollapseWindow(); only uncollapse window if it is collapsed.

	* generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature.
	* generic/tkIntPlatDecls.h:

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call
	GetMenuItemCommandID() on KeyDown or KeyRepeat events.

	* macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to
	obsolete AppendResMenu() API.

	* macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive
	* macosx/tkMacOSXMenu.c:     GetMouse() and TkMacOSXButtonKeyState()
	* macosx/tkMacOSXMenus.c:    APIs by calls to XQueryPointer()
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:   replaced use of FrontNonFloatingWindow()
	* macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as
	* macosx/tkMacOSXMenu.c:     recommended by Carbon docs.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c: fixed warnings
	* macosx/tkMacOSXTest.c:

	* macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.h:

	* macosx/tkMacOSXInt.h: declare macosx internal procs as MODULE_SCOPE.
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXWindowEvent.c

	* library/bgerror.tcl: sync with core-8-4-branch changes of 2005-07-28.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXMouseEvent.c:

	* generic/tkFrame.c:   sync with core-8-4-branch changes of 2005-07-27.
	* generic/tkIntDecls.h:
	* generic/tkStubInit.c:
	* generic/tkFrame.c:
	* win/tkWinDraw.c:
	* unix/tkUnixDraw.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXButton.c: sync with core-8-4-branch.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXScale.c:

	* library/demos/menu.tcl: removed errant '}'.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.13 2005/05/29 07:00:26 das Exp $
d210 1
d212 1
@


1.13
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: fixed warnings.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.12 2005/05/26 11:19:01 das Exp $
d420 1
a420 1
void
@


1.12
log
@	* macosx/tkMacOSXInit.c (TkpInit): fixed resource file extraction
	from __tk_rsrc section to work with non-prebound .dylib and .bundle.

	* macosx/Makefile: corrected EMBEDDED_BUILD check, use separate tcl
	and tk version vars to properly support tk/x11 framework version
	overriding, rewrite tkConfig.sh when overriding tk version, corrected
	Wish.app symlink in tk build dir.

	* unix/configure.in: corrected framework finalization to softlink
	stub library to Versions/8.x subdir instead of Versions/Current.
	* unix/configure: autoconf-2.59
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.11 2005/05/24 02:32:15 das Exp $
d210 1
a210 1
                    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %d\n",err);
@


1.11
log
@fix for non-framework TkAqua build
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.10 2005/05/23 20:24:59 das Exp $
d178 1
d181 1
a181 7
#ifdef HAVE__DYLD_GET_IMAGE_HEADER_CONTAINING_ADDRESS
                image = _dyld_get_image_header_containing_address((unsigned long)&TkpInit);
                if (image) {
                    data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
                }
#else
                int i, n = _dyld_image_count();
d186 4
a190 1
                    if (data) break;
a191 1
#endif
d210 1
@


1.10
log
@	* macosx/Makefile:
	* macosx/README:
	* macosx/Tk-Info.plist.in (new file):
	* macosx/Wish-Info.plist.in (new file):
	* unix/Makefile.in:
	* unix/configure.in:
	* unix/tcl.m4:
	* unix/tkUnixInit.c:  moved all Darwin framework and TkAqua build
	support from macosx/Wish.pbproj and macosx/Makefile into the standard
	unix configure/make buildsystem, the project and macosx/Makefile are
	no longer required to build Tk.framework and/or TkAqua. TkAqua is now
	enabled by the --enable-aqua configure option, and static and
	non-framework builds of TkAqua are now available via the standard
	configure switches. Tk/X11 can also be built as a framework. The
	macosx/Makefile now wraps the unix buildsystem and no longer uses the
	projects, embedded builds are still only available via this Makefile,
	but for other builds it is not longer required (but its current
	functionality is still available for backwards compatibility). The
	projects currently do not call through to the Makefile to build
	(unlike Tcl.pbproj) so project builds may differ from makefile builds.
	Due to issues with spaces in pathnames, 'Wish Shell.app' has been
	renamed to 'Wish.app', the macosx/Makefile installs backwards
	compatibility symlinks for the old name.
	* macosx/tkMacOSXInit.c (TkpInit): added support for Tk resource file
	in non-framework and static builds: the resource file is copied into a
	__tk_rsrc MachO segment of the library or executable at link time and
	extracted into a temporary location at initialization.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in (new file): autoheader-2.59
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.9 2005/05/14 20:48:15 das Exp $
d163 1
d165 3
a167 1
                "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK) {
@


1.9
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: introduction of new tcl notifier based on
	CFRunLoop allows replacement of the custom TkAqua notifier by a
	standard tcl event source. Removes requirement of threaded tcl core
	for TkAqua, allows to stub-link TkAqua against Tcl by removing use of
	the unstubbed TclInitNotifier & TclFinalizeNotifier. [Tcl Patch 1202052]

	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.pbproj/project.pbxproj: stub-link TkAqua: build with
	USE_TCL_STUBS and link against libtclstub instead of Tcl.framework,
	unexport libtclstub symbols from Tk to avoid duplicate symbol warnings
	when linking with both Tcl and Tk, fixes for gcc4.0 warnings.

	* macosx/Wish.xcode/project.pbxproj: sync with Wish.pbproj changes
	since 2004-11-19.
	NOTE: to use this project, need to uncomment the tclConfig.h settings
	at the top of tcl/unix/configure.in, autoconf and rebuild tcl !

	* macosx/tkMacOSXBitmap.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c: fixed gcc 4.0 warnings.

	* unix/tcl.m4: sync with tcl
	* unix/configure: autoconf-2.59
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.8 2005/03/09 19:40:52 wolfsuit Exp $
d21 1
d163 55
a217 2
        Tcl_MacOSXOpenVersionedBundleResources(interp, 
                "com.tcltk.tklibrary", TK_VERSION, 1, 1024, tkLibPath);
@


1.8
log
@Add a hack to work around some issues with remote debugging with Xcode.  Xcode requires
that stdin & stdout be closed or you won't be able to interrupt the running program.  So
I added a check for XCNOSTDIN environment variable in the startup, and I force them
closed if it is set.  With that, remote debugging works pretty well.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.7 2005/01/25 06:54:18 das Exp $
d82 1
a82 1
    {NULL,		NULL}
d118 2
a132 1
        Tk_MacOSXSetupTkNotifier();
d384 1
a384 1
                    startupScript, PATH_MAX)) {
d390 1
a390 1
                            true, scriptPath, PATH_MAX);
@


1.7
log
@	* macosx/tkMacOSXInit.c (TkpInit): set tcl_interactive to 1 to show
	console at startup instead of directly calling [console show].

	* unix/tcl.m4 (Darwin): fixed bug with static build linking to
	dynamic library in /usr/lib etc instead of linking to static library
	earlier in search path. [Tcl Bug 956908]
	Removed obsolete references to Rhapsody.
	* unix/configure: autoconf-2.57
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.6 2004/11/11 01:24:32 das Exp $
d170 9
@


1.6
log
@	* generic/tkMain.c:
	* macosx/tkMacOSXAppInit.c (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: changes to make TkAqua dynamically loadable,
	enabling [package require Tk] from tclsh. Startup code from
	tkMacOSXAppInit.c moved into tkMacOSXInit.c, added code that
	notifies the window server that an unbundled executable is a full
	GUI application after loading Tk. [Patch 1035348]

	* doc/wm.n: documented [wm attributes] on Mac OS X. [Bug 606665]
	* macosx/tkMacOSXWm.c: implemented TIP 222 [wm attributes -alpha] on
	Mac OS X. [Patch 892194]
	WmIconbitmapCmd: adopted FSRef changes from [wm atttrs -titlepath].

	* macosx/tkMacOSXSubwindows.c: synced spacing/formatting with
	core-8-4-branch.

	* generic/tkRectOval.c:
	* macosx/README:
	* macosx/tkMacOSXDefault.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXWm.c: forward port from core-8-4-branch of Jim's
	and my changes for CG drawing and [wm attributes] (corresponds to
	8.4 changes dating from 09-18, 07-27, 07-24).

	* macosx/tkMacOSXMouseEvent.c: endianness fixes.

	* macosx/Wish.pbproj/project.pbxproj: corrected path to html help
	inside framework.

	* macosx/Makefile: prevent parallel make from building several
	targets at the same time.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.5 2004/02/16 00:19:42 wolfsuit Exp $
d177 6
a182 5
                if (Tk_CreateConsoleWindow(interp) == TCL_OK) {
                    /* Only show the console if we don't have a startup script */
                    if (Tcl_GetStartupScript(NULL) == NULL) {
                        Tcl_Eval(interp, "console show");
                    }
@


1.5
log
@Fix a bug in tk_getOpenFile - files with no types are rejected when they would
pass in Mac OS Classic.
Add the tkMacOSXCarbonEvents.c - just a skeleton right now.
A bunch of formatting nits fixed.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d18 3
d29 9
d87 5
d115 2
a116 4
    char tkLibPath[1024];
    int result;
    static int menusInitialized = false;
    static int carbonEncodingInitialized = false;
d120 1
a120 1
     * and we don't want to do the menu initialization multiple times
d124 7
a130 2
    if (menusInitialized == false) {
    	menusInitialized = true;
d136 1
a136 6
    }
 
    if (carbonEncodingInitialized == false) {
	CFStringEncoding encoding;
	char *encodingStr = NULL;
	int  i;
d154 96
d251 2
a252 11
    
    /*
     * 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?
     */
     
    result = Tcl_MacOSXOpenVersionedBundleResources(interp, 
    	    "com.tcltk.tklibrary", TK_VERSION, 1, 1024, tkLibPath);
     
    if (result != TCL_ERROR) {
d255 5
d331 56
@


1.4
log
@	* macosx/tkMacOSXInit.c (TkpInit): use new versioned bundle
	resource API to get tk runtime library for TK_VERSION. [Bug 736774]
@
text
@d2 1
a2 1
 * tkUnixInit.c --
d4 1
a4 1
 *        This file contains Unix-specific interpreter initialization
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3 2002/10/16 19:44:05 das Exp $
d113 1
@


1.3
log
@	* macosx/Wish.pbproj/project.pbxproj: added TEXT document
	type to plist so that files can be dragged onto Wish Shell.

	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXFont.c: added private proc
	TkMacOSXUseAntialiasedText() to enable/disable quickdraw
	text antialiasing where available, default is enabled.
	Added a linked boolean ::tk::mac::antialiasedtext with
	write trace to allow control of antialiasing from tcl.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.2 2002/08/31 06:12:30 das Exp $
d146 2
a147 2
    result = Tcl_MacOSXOpenBundleResources(interp, "com.tcltk.tklibrary", 
                1, 1024, tkLibPath);
@


1.3.2.1
log
@	* macosx/tkMacOSXInit.c (TkpInit): use new versioned bundle
	resource API to get tk runtime library for TK_VERSION. [Bug 736774]
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3 2002/10/16 19:44:05 das Exp $
d146 2
a147 2
    result = Tcl_MacOSXOpenVersionedBundleResources(interp, 
    	    "com.tcltk.tklibrary", TK_VERSION, 1, 1024, tkLibPath);
@


1.3.2.2
log
@Finish the implementation of the CG version of the X Drawing layer.
Add support for returning values for the wm attributes commands, and
use FSRef's rather than FSSpec's.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
a114 1
        TkMacOSXInitCGDrawing(interp, TRUE, 3);
@


1.3.2.3
log
@	* generic/tkMain.c:
	* macosx/tkMacOSXAppInit.c (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: changes to make TkAqua dynamically loadable,
	enabling [package require Tk] from tclsh. Startup code from
	tkMacOSXAppInit.c moved into tkMacOSXInit.c, added code that
	notifies the window server that an unbundled executable is a full
	GUI application after loading Tk. [Patch 1035348]

	* doc/wm.n: documented [wm attributes] on Mac OS X. [Bug 606665]
	* macosx/tkMacOSXWm.c: implemented TIP 222 [wm attributes -alpha] on
	Mac OS X. [Patch 892194]
	WmIconbitmapCmd: adopted FSRef changes from [wm atttrs -titlepath].

	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c: synced spacing/formatting with HEAD.

	* macosx/tkMacOSXMouseEvent.c: endianness fixes.

	* macosx/Wish.pbproj/project.pbxproj: corrected path to html help
	inside framework.

	* macosx/Makefile: prevent parallel make from building several
	targets at the same time.
	Ensure that xcodebuild will use Wish.pbproj project even if a .xcode
	project is also present.
@
text
@d2 1
a2 1
 * tkMacOSXInit.c --
d4 1
a4 1
 *        This file contains Mac OS X -specific interpreter initialization
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.2 2004/07/25 01:57:41 wolfsuit Exp $
a17 3
#include "tclInt.h"
#include <sys/stat.h>
#include <mach-o/dyld.h>
a25 9
 * Define the following to 0 to not attempt to use an undocumented SPI
 * to notify the window server that an unbundled executable is a full
 * GUI application after loading Tk.
 */
#ifndef MAC_OSX_TK_USE_CPS_SPI
#define MAC_OSX_TK_USE_CPS_SPI 1
#endif

/*
a74 5
/*
 * If the App is in an App package, then we want to add the Scripts
 * directory to the auto_path.      
 */
static char scriptPath[PATH_MAX + 1] = "";
d98 4
a101 2
    static char tkLibPath[PATH_MAX + 1];
    static int tkMacOSXInitialized = false;
d105 1
a105 1
     * and we don't want to do the initialization multiple times
d109 2
a110 7
    if (tkMacOSXInitialized == false) {
	CFStringEncoding encoding;
	char *encodingStr = NULL;
	int  i;

    	tkMacOSXInitialized = true;

d116 6
d139 1
a139 15
        
        /*
         * 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?
         */
         
        Tcl_MacOSXOpenVersionedBundleResources(interp, 
                "com.tcltk.tklibrary", TK_VERSION, 1, 1024, tkLibPath);
                 
        /*
         * 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.
         */
d141 10
a150 83
        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));
                if (Tk_CreateConsoleWindow(interp) == TCL_OK) {
                    /* Only show the console if we don't have a startup script */
                    if (TclGetStartupScriptPath() == NULL) {
                        Tcl_Eval(interp, "console show");
                    }
                }
            }
        }
#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.
                 */
                OSErr (*cpsEnableForegroundOperation)(ProcessSerialNumberPtr) = NULL;
                NSSymbol nsSymbol;
                if(NSIsSymbolNameDefinedWithHint(
                        "_CPSEnableForegroundOperation", "CoreGraphics")) {
                    nsSymbol = NSLookupAndBindSymbolWithHint(
                        "_CPSEnableForegroundOperation", "CoreGraphics");
                    if(nsSymbol) {
                        cpsEnableForegroundOperation = NSAddressOfSymbol(nsSymbol);
                    }
                }
                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') {
a152 5

    if (scriptPath[0] != '\0') {
        Tcl_SetVar(interp, "auto_path", scriptPath,
                TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
    }
a223 56

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDefaultStartupScript --
 *
 *
 *        On MacOS X, we look for a file in the Resources/Scripts
 *        directory called AppMain.tcl and if found, we set argv[1] to
 *        that, so that the rest of the code will find it, and add the
 *        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.
 *
 * Side effects:
 *        TclSetStartupScriptFileName() called when AppMain.tcl found.
 *
 *----------------------------------------------------------------------
 */

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,
                    startupScript, PATH_MAX)) {
                TclSetStartupScriptFileName(startupScript);
                scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(
                        NULL, appMainURL);
                if (scriptFldrURL != NULL) {
                    CFURLGetFileSystemRepresentation(scriptFldrURL, 
                            true, scriptPath, PATH_MAX);
                    CFRelease(scriptFldrURL);
                }
            }
            CFRelease(appMainURL);
        }
    }
}
@


1.3.2.4
log
@	* macosx/tkMacOSXInit.c (TkpInit): set tcl_interactive to 1 to show
	console at startup instead of directly calling [console show].

	* unix/tcl.m4 (Darwin): fixed bug with static build linking to
	dynamic library in /usr/lib etc instead of linking to static library
	earlier in search path. [Tcl Bug 956908]
	Removed obsolete references to Rhapsody.
	* unix/configure: autoconf-2.13
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.3 2004/11/11 01:26:43 das Exp $
d176 5
a180 6
                /* Only show the console if we don't have a startup script */
                if (TclGetStartupScriptFileName() == NULL) {
                    Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
                }
                if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
                    return TCL_ERROR;
@


1.3.2.5
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: introduction of new tcl notifier based on
	CFRunLoop allows replacement of the custom TkAqua notifier by a
	standard tcl event source. Removes requirement of threaded tcl core
	for TkAqua, allows to stub-link TkAqua against Tcl by removing use of
	the unstubbed TclInitNotifier & TclFinalizeNotifier. [Tcl Patch 1202052]

	* macosx/Wish.pbproj/project.pbxproj: stub-link TkAqua: build with
	USE_TCL_STUBS and link against libtclstub instead of Tcl.framework,
	unexport libtclstub symbols from Tk to avoid duplicate symbol warnings
	when linking with both Tcl and Tk, fixes for gcc4.0 warnings.

	* macosx/tkMacOSXBitmap.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c: fixed gcc 4.0 warnings.

	* unix/tcl.m4: sync with tcl
	* unix/configure: autoconf-2.13
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.4 2005/01/25 06:54:58 das Exp $
d82 1
a82 1
    {0, 		NULL}
a117 2
    Tk_MacOSXSetupTkNotifier();

d131 1
d373 1
a373 1
                    (unsigned char*) startupScript, PATH_MAX)) {
d379 1
a379 1
                            true, (unsigned char*) scriptPath, PATH_MAX);
@


1.3.2.6
log
@	* macosx/Makefile:
	* macosx/README:
	* macosx/Tk-Info.plist.in (new file):
	* macosx/Wish-Info.plist.in (new file):
	* unix/Makefile.in:
	* unix/configure.in:
	* unix/tcl.m4:
	* unix/tkUnixInit.c:  moved all Darwin framework and TkAqua build
	support from macosx/Wish.pbproj and macosx/Makefile into the standard
	unix configure/make buildsystem, the project and macosx/Makefile are
	no longer required to build Tk.framework and/or TkAqua. TkAqua is now
	enabled by the --enable-aqua configure option, and static and
	non-framework builds of TkAqua are now available via the standard
	configure switches. Tk/X11 can also be built as a framework. The
	macosx/Makefile now wraps the unix buildsystem and no longer uses the
	projects, embedded builds are still only available via this Makefile,
	but for other builds it is not longer required (but its current
	functionality is still available for backwards compatibility). The
	projects currently do not call through to the Makefile to build
	(unlike Tcl.pbproj) so project builds may differ from makefile builds.
	Due to issues with spaces in pathnames, 'Wish Shell.app' has been
	renamed to 'Wish.app', the macosx/Makefile installs backwards
	compatibility symlinks for the old name.
	* macosx/tkMacOSXInit.c (TkpInit): added support for Tk resource file
	in non-framework and static builds: the resource file is copied into a
	__tk_rsrc MachO segment of the library or executable at link time and
	extracted into a temporary location at initialization.
	* unix/configure: autoconf-2.13
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.5 2005/05/14 20:53:31 das Exp $
a20 1
#include <mach-o/getsect.h>
d161 2
a162 58
#ifdef TK_FRAMEWORK
        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 {
                struct mach_header *image;
                char *data = NULL;
                unsigned long size;
                int fd = -1;
                char fileName[L_tmpnam + 15];

                /* Get resource data from __tk_rsrc section of tk library file */
#ifdef HAVE__DYLD_GET_IMAGE_HEADER_CONTAINING_ADDRESS
                image = _dyld_get_image_header_containing_address((unsigned long)&TkpInit);
                if (image) {
                    data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
                }
#else
                int i, 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) break;
                }
#endif
                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(fileName, &ref, NULL);
                    if (err != noErr) break;
                    err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum);
                    break;
                }
                if (fd != -1) {
                    unlink(fileName);
                    close(fd);
                }
            }
        }
@


1.3.2.7
log
@	* macosx/tkMacOSXInit.c (TkpInit): fixed resource file extraction
	from __tk_rsrc section to work with non-prebound .dylib and .bundle.

	* macosx/Makefile: corrected EMBEDDED_BUILD check, use separate tcl
	and tk version vars to properly support tk/x11 framework version
	overriding, rewrite tkConfig.sh when overriding tk version, corrected
	Wish.app symlink in tk build dir.

	* unix/configure.in: corrected framework finalization to softlink
	stub library to Versions/8.x subdir instead of Versions/Current.
	* unix/configure: autoconf-2.13
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.6 2005/05/24 04:21:32 das Exp $
a176 1
                int i, n;
d179 7
a185 1
                n = _dyld_image_count();
a189 4
                        if (data) {
                            data += _dyld_get_image_vmaddr_slide(i);
                            break;
                        }
d191 1
d193 1
a211 1
                    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %d\n",err);
@


1.3.2.8
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: fixed warnings.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.7 2005/05/26 11:20:09 das Exp $
d209 1
a209 1
                    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
@


1.3.2.9
log
@	* macosx/tkMacOSXCarbonEvents.c (new): moved carbon events code into
	* macosx/tkMacOSXHLEvents.c:           new file like on HEAD,
	* macosx/tkMacOSXInit.c (TkpInit):     initialize carbon event handlers
	* macosx/tkMacOSXInt.h:                in TkpInit(), add new source
	* unix/Makefile.in:                    file to Makefile.in.

	* macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon
	events sent directly to application event target via the general
	TkMacOSXProcessEvent() in the same way as events posted to the event
	loop. Moved existing app event handlers to tkMacOSXWindowEvent.c.
	(TkMacOSXInitCarbonEvents): register our application event handler for
	kEventWindowExpanded events to deal with uncollapsing from the dock.

	* macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added
	* macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for
	                          use by app event handler.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve
	current window, partCode, modifiers and local cursor position from
	carbon mouse event if possible. Use new static GenerateButtonEvent()
	taking a MouseEventData struct instead of TkGenerateButtonEvent() to
	avoid recomputing already known values. Move process activation on
	MouseDown into BringWindowForward() to allow clicking on window titlebar
	widgets without activating process. Move code dealing with clicks in
	window titelbar into separate function HandleWindowTitlebarMouseDown()
	to avoid code duplication. Avoid repeated calls to TkMacOSXGetXWindow()
	by storing result in MouseEventData struct.
	(TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier
	state from currently processed carbon event (to avoid unnecessary IPC
	with the window server), otherwise use modern carbon API to get this
	info instead of Button() and GetKeys(); only retrieve info caller asks
	for (via non-NULL ptr passed to XQueryPointer).
	(ButtonModifiers2State): new static function converting carbon button
	and modifier state into tk state, allows detection of more than 3 mouse
	buttons (tk supports up to 5) and of NumLock and Fn modifier keys
	(NumLock is mapped to Mod3 and Fn to Mod4).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent): handle
	kEventWindowExpanded event to deal with window uncollapsing from the
	dock by generating tk Map event, handle kEventAppHidden and
	kEventAppShown events (moved here from tkMacOSXCarbonEvents.c).

	* macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when
	it is not iconified to avoid window flashing on collapse.

	* macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle().
	(TkMacOSXZoomToplevel): remove call to TrackBox(), now done in
	HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c.
	(TkpWmSetState): avoid window flashing on collapse by unmapping after
	calling CollapseWindow(); only uncollapse window if it is collapsed.

	* generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature.
	* generic/tkIntPlatDecls.h:

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call
	GetMenuItemCommandID() on KeyDown or KeyRepeat events.

	* macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to
	obsolete AppendResMenu() API.

	* macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive
	* macosx/tkMacOSXMenu.c:     GetMouse() and TkMacOSXButtonKeyState()
	* macosx/tkMacOSXMenus.c:    APIs by calls to XQueryPointer()
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:   replaced use of FrontNonFloatingWindow()
	* macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as
	* macosx/tkMacOSXMenu.c:     recommended by Carbon docs.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c: fixed warnings
	* macosx/tkMacOSXTest.c:

	* macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.h:

	* macosx/tkMacOSXEmbed.c: replaced all uses of panic() with Tcl_Panic()
	* macosx/tkMacOSXFont.c:  (sync with HEAD).
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXInt.h:      sync with HEAD changes of 2005-03-14.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tclets.r (removed): sync with HEAD.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXPort.h:

	* library/demos/menu.tcl: removed errant '}'.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.8 2005/05/29 07:00:47 das Exp $
a134 1
        TkMacOSXInitCarbonEvents(interp);
@


1.3.2.10
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): check if
	process is in front on MouseDown, otherwise request process activation
	from BringWindowForward() via new isFrontProcess param.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents): register our
	event handler on the dispatcher target for all carbon events of interest
	to TkAqua; this replaces event processing directly from the event queue
	and thus allows to capture events that are syntesized by Carbon and sent
	directly to the dispatcher and not to the event queue.

	* macosx/tkMacOSXEvent.c: remove TkMacOSXCountAndProcessMacEvents(),
	rename ReceiveAndProcessEvent() to TkMacOSXReceiveAndProcessEvent().
	(TkMacOSXReceiveAndProcessEvent): remove tk event processing before
	sending events to the dispatcher, all events of interest are now
	processed in our dispatcher target event handler.

	* macosx/tkMacOSXNotify.c (CarbonEventsCheckProc): dispatch events
	directly via TkMacOSXReceiveAndProcessEvent(), but dispatch no more than
	four carbon events at one time to avoid starving other event sources.

	* macosx/tkMacOSXEvent.c: formatting cleanup, move XSync() to XStubs,
	* macosx/tkMacOSXEvent.h: removed obsolete kEventClassWish handling.
	* macosx/tkMacOSXXStubs.c

	* macosx/tkMacOSXButton.c: conditionalize all debug message printing to
	* macosx/tkMacOSXCursor.c: stderr via TK_MAC_DEBUG define.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* unix/configure.in: define TK_MAC_DEBUG on aqua when symbols enabled.
	* unix/configure: autoconf-2.13

	* library/listbox.tcl: corrected comments.
	* library/text.tcl:

	* xlib/xcolors.c: fixed warning
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.9 2005/08/09 07:40:00 das Exp $
a209 1
#ifdef TK_MAC_DEBUG
a210 1
#endif
@


1.3.2.11
log
@	* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
	add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
	configure (flag can't be present twice, so can't be in both CFLAGS and
	LDFLAGS during configure), don't use -prebind when deploying on 10.4,
	define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
	(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
	autoconf macros. Sync with tk/unix/tcl.m4, sync whitespace with HEAD.

	* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
	formatting/ordering differences with tcl/unix/configure.in.

	* unix/Makefile.in: add CFLAGS to wish/tktest link to make executable
	linking the same as during configure (needed to avoid loosing any linker
	relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS).
	Avoid concurrent linking of wish and compiling of tkTestInit.o during
	parallel make, fix dependencies and flags for building tkMacOSXInit.o
	(checkstubs, checkexports): dependency and Darwin fixes

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessEvent):
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	* macosx/tkMacOSXCarbonEvents.c: install standard application event
	handler, add & call functions to start and stop carbon even timer that
	runs the tcl event loop periodically during a nested carbon event loop
	in the toolbox (e.g. during menutracking) to ensure tcl timers etc
	continue to fire, register app event handler for menu tracking and HI
	command carbon events, move menu event handling to new handlers for
	those carbon events, no longer register for/handle appleevent carbon
	event (now dealt with by standard application event handler), event
	debugging code dynamically acquires carbon event debugging functions to
	allow use on Tiger where they are no longer exported from HIToolbox.

	* macosx/tkMacOSXFont.c (TkMacOSXUseAntialiasedText):
	* macosx/tkMacOSXKeyEvent.c (GetKeyboardLayout):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: abstract common code to dynamically acquire
	address of a named symbol (from a loaded dynamic library) into new
	function TkMacOSXGetNamedSymbol() and macro TkMacOSXInitNamedSymbol.

	* macosx/tkMacOSXMenu.c (TkpNewMenu):
	* macosx/tkMacOSXMenubutton.c (MenuButtonInitControl):
	* macosx/tkMacOSXMenus.c (TkMacOSXHandleMenuSelect): switch to  modern
	utf8 aware menu manager API, remove obsolete code, add error handling.

	* macosx/tkMacOSXMouseEvent.c: define OSX 10.3 or later only constants
	if necessary to allow compilation on OSX 10.2

	* macosx/tkMacOSXWm.c (UpdateSizeHints): remove code that is never
	executed.

	* generic/tk.h: add/correct location of version numbers in macosx files.

	* generic/tkInt.h: clarify fat compile comment.

	* macosx/Wish.pbproj/default.pbxuser (new file):
	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj: sync with HEAD.

	* macosx/buildTkConfig.tcl (removed): remove obsolete build files.

	* macosx/README: clarification/cleanup, sync with HEAD, document
	universal (fat) builds via CFLAGS (i.e. ppc and i386 at the same time).

	* macosx/Makefile: add support for reusing configure cache, build target
	fixes.

	* generic/tkMenu.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXXStubs.c:
	* macosx/tkMacOSXSubwindows.c:
	* xlib/xgc.c: declare functions and globals used only in own file as
	static, #ifdef out a few Xlib and aqua functions that are never called
	(sync with HEAD).

	* macosx/tkMacOSXPort.h:
	* generic/tkInt.decls: correct signature of TkMacOSXHandleMenuSelect,
	add XSync to aqua Xlib stubs.

	* generic/tkTest.c: #ifdef unix only declarations.
	(TestmetricsCmd): unify win and mac implementation.

	* generic/tkTextDisp.c:
	* generic/tkTextBTree.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXXStubs.c: fix gcc 4 warnings.

	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXTest.c: sync with HEAD.

	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure: regen.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.10 2005/09/10 14:54:17 das Exp $
d173 1
a173 1
                const struct mach_header *image;
d175 1
a175 1
                uint32_t size;
d207 1
a207 1
                    err = FSPathMakeRef((unsigned char*)fileName, &ref, NULL);
d289 11
a299 3
                TkMacOSXInitNamedSymbol(CoreGraphics, OSErr, \
                        CPSEnableForegroundOperation, ProcessSerialNumberPtr);
                if (CPSEnableForegroundOperation) {
d304 1
a304 1
                    CPSEnableForegroundOperation(&psn);
a445 41

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNamedSymbol --
 *
 *
 *        Dynamically acquire address of a named symbol from a loaded
 *        dynamic library, so that we can use API that may not be
 *        available on all OS versions.
 *        If module is non-NULL and not the empty string, use twolevel
 *        namespace lookup.
 *       
 * Results:
 *        Address of given symbol or NULL if unavailable.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void*
TkMacOSXGetNamedSymbol(const char* module, const char* symbol)
{
    NSSymbol nsSymbol = NULL;
    if (module && *module) {
	if(NSIsSymbolNameDefinedWithHint(symbol, module)) {
	    nsSymbol = NSLookupAndBindSymbolWithHint(symbol, module);
	}
    } else {
        if(NSIsSymbolNameDefined(symbol)) {
            nsSymbol = NSLookupAndBindSymbol(symbol);
        }
    }
    if(nsSymbol) {
	return NSAddressOfSymbol(nsSymbol);
    } else {
        return NULL;
    }
}
@


1.3.2.12
log
@        * macosx/tkMacOSXDraw.c:   remove inclusion of tclInt.h and use of tcl
        * macosx/tkMacOSXFont.c:   internals wherever possible in tk/macosx, the
        * macosx/tkMacOSXInit.c:   only remaining tcl internals in TkAqua are
        * macosx/tkMacOSXNotify.c: TclServiceIdle() in tkMacOSXScrlbr.c and
        * macosx/tkMacOSXScrlbr.c: Tcl_Get/SetStartupScript() in tkMacOSXInit.c
	                           [Bug 1336531].
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.11 2005/11/27 02:36:46 das Exp $
d18 1
a18 1
#include "tclInt.h" /* for TclGetStartupScript() & TclSetStartupScript() */
@


1.3.2.13
log
@	* macosx/tkMacOSXDraw.c: re-added inclusion of tclInt.h to allow access
	* macosx/tkMacOSXFont.c: to 8.4-internal Tcl_CreateNamespace().

	* macosx/tkMacOSXDebug.c: add TkMacOSXGetNamedDebugSymbol() function
	* macosx/tkMacOSXDebug.h: that finds unexported symbols in loaded
	libraries by manually walking their symbol table; only to be used for
	debugging purposes, may break unexpectedly in the future. Needed to get
	access to private_extern internal debugging functions in HIToolbox.

	* macosx/tkMacOSXCarbonEvents.c: fix debug event tracing on Tiger.
	* macosx/tkMacOSXMenu.c: add debug menu printing during reconfigure.
	* macosx/tkMacOSXInit.c: conditionalize 64bit-unsafe dyld code.
	* macosx/Makefile: add 'wish8.x' symlink to SYMROOT.

	* unix/configure:    add caching, use AC_CACHE_CHECK instead of
	* unix/configure.in: AC_CACHE_VAL where possible, consistent message
	* unix/tcl.m4:       quoting, sync relevant tclconfig/tcl.m4 changes and
	gratuitous formatting differences, fix SC_CONFIG_MANPAGES with default
	argument, Darwin improvements to SC_LOAD_*CONFIG.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.12 2005/12/08 07:50:30 das Exp $
a172 1
#ifndef __LP64__
d178 1
a178 1
                uint32_t i, n;
a218 1
#endif /* __LP64__ */
@


1.3.2.14
log
@	* macosx/tkMacOSX.h:             Cleaned up & rationalized order of
	* macosx/tkMacOSXBitmap.c:       #includes of tk and carbon headers;
	* macosx/tkMacOSXButton.c:       sync whitespace, comments & minor
	* macosx/tkMacOSXCarbonEvents.c: changes with HEAD.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXFont.h (new file):
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.13 2006/01/10 05:38:20 das Exp $
d16 1
a17 1

a18 1

@


1.3.2.15
log
@	* macosx/tkMacOSXWm.c (TkWmMapWindow, InitialWindowBounds): fix use of
	potentially stale window position in initial configure event on first
	map of a window. [Bug 1476443]
	(TkMacOSXWindowOffset): use modern GetWindowStructureWidths API.

	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMouseEvent.c (TkGenerateButtonEventForXPointer): new
	internal function to generate button events for current pointer
	directly, without requiring prior call to XQueryPointer().

	* macosx/tkMacOSXMouseEvent.c (XQueryPointer): implement return of
	window-local pointer position.

	* macosx/tkMacOSXInt.h:      use improvements above to avoid calls to
	* macosx/tkMacOSXKeyEvent.c: GlobalToLocal() when the current port might
	* macosx/tkMacOSXMenu.c:     not be set correctly. May fix [Bug 1243318]
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:

	* tkAboutDlg.r: update copyright.

	* macosx/tkMacOSXCarbonEvents.c: sync with HEAD
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.14 2006/03/28 02:44:13 das Exp $
d408 1
a408 1
MODULE_SCOPE void
@


1.3.2.16
log
@	* 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.
@
text
@a8 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.15 2006/04/28 06:02:59 das Exp $
d91 1
a91 1
 * directory to the auto_path.
d101 1
a101 1
 *        tk_library variable.
d133 1
a133 8
	tkMacOSXInitialized = true;

	TkMacOSXInitAppleEvents(interp);
	TkMacOSXInitCarbonEvents(interp);
	TkMacOSXInitMenus(interp);
	TkMacOSXUseAntialiasedText(interp, TRUE);
	TkMacOSXInitCGDrawing(interp, TRUE, 3);
	TkMacOSXInitKeyboard(interp);
d135 6
d142 1
a142 1

d152 1
a152 1

d157 7
a163 7

	/*
	 * 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?
	 */

d165 2
a166 2
	if (Tcl_MacOSXOpenVersionedBundleResources(interp,
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
d168 6
a173 6
	    {
	    /* Tk.framework not found, check if resource file is open */
	    Handle rsrc = Get1NamedResource('CURS', "\phand");
	    if (rsrc) {
		ReleaseResource(rsrc);
	    } else {
d175 37
a211 37
		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);
d213 1
a213 1
		    if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
d215 6
a220 6
		    break;
		}
		if (fd != -1) {
		    unlink(fileName);
		    close(fd);
		}
d222 25
a246 25
	    }
	}

	/*
	 * 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.
	 */

	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 (TclGetStartupScriptFileName() == NULL) {
		    Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
		}
		if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
		    return TCL_ERROR;
		}
	    }
	}
d248 55
a302 55
	/*
	 * 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);
		}
	    }
	}
d307 1
a307 1
	Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
d311 2
a312 2
	Tcl_SetVar(interp, "auto_path", scriptPath,
		TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
d314 1
a314 1

d345 1
a345 1
	name = "tk";
d347 4
a350 4
	p = strrchr(name, '/');
	if (p != NULL) {
	    name = p+1;
	}
d379 4
a382 4
	Tcl_WriteChars(errChannel, title, -1);
	Tcl_WriteChars(errChannel, ": ", 2);
	Tcl_WriteChars(errChannel, msg, -1);
	Tcl_WriteChars(errChannel, "\n", 1);
d398 1
a398 1
 *
d412 1
a412 1

d414 1
a414 1

d416 23
a438 23
	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)) {
		TclSetStartupScriptFileName(startupScript);
		scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(
			NULL, appMainURL);
		if (scriptFldrURL != NULL) {
		    CFURLGetFileSystemRepresentation(scriptFldrURL, 
			    true, (unsigned char*) scriptPath, PATH_MAX);
		    CFRelease(scriptFldrURL);
		}
	    }
	    CFRelease(appMainURL);
	}
d472 3
a474 3
	if(NSIsSymbolNameDefined(symbol)) {
	    nsSymbol = NSLookupAndBindSymbol(symbol);
	}
d479 1
a479 1
	return NULL;
@


1.3.2.17
log
@	* macosx/tkMacOSXCursor.c (TkMacOSXCursor):
	* macosx/tkMacOSXDebug.c (TkMacOSXGetNamedDebugSymbol):
	* macosx/tkMacOSXInit.c (Map): fix signed-with-unsigned comparison and
	other warnings from gcc4 -Wextra.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.16 2006/05/12 18:17:55 das Exp $
d48 1
a48 1
    CFStringEncoding numKey;
@


1.3.2.18
log
@	* unix/tcl.m4 (Darwin): add support for --enable-64bit on x86_64, for
	universal builds including x86_64, for 64-bit CoreFoundation on Leopard
	and for use of -mmacosx-version-min instead of MACOSX_DEPLOYMENT_TARGET.
	* unix/configure.in (Darwin): remove 64-bit arch flags from CFLAGS for
	combined 32-bit and 64-bit universal builds, as neither TkAqua nor TkX11
	can be built for 64-bit at present.
	* unix/configure: autoconf-2.13

	* macosx/README: updates for x86_64 support in Tcl.

	* macosx/tkMacOSXInit.c (TkpInit): when available, use public
	TransformProcessType() API instead of CPSEnableForegroundOperation() SPI
	to notify the window server that we are a GUI application.

	* macosx/tkMacOSXWm.c (WmAttrGetTitlePath): use HIWindow API on >=Tiger.

	* macosx/tkMacOSXMouseEvent.c (GenerateToolbarButtonEvent):
	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent): bzero XVirtualEvent structure
	before use to ensure all fields are initialized. [Bug 1542205]
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.17 2006/07/20 06:26:45 das Exp $
d249 1
a249 1

d253 2
a254 2
	 * For such an executable, notify the window server that we are now a
	 * full GUI application.
d288 1
a288 2
	    /* If we are not a bundled executable, notify the window server that
	     * we are a foregroundable app. */
d290 8
a297 10
		OSStatus err = procNotFound;
		ProcessSerialNumber psn = { 0, kCurrentProcess };
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
		if (TransformProcessType != NULL) {
		    err = TransformProcessType(&psn,
			    kProcessTransformToForegroundApplication);
		}
#endif
#if MAC_OSX_TK_USE_CPS_SPI
		if (err != noErr) {
d299 1
a299 4
		     * When building or running on 10.2 or when the above fails,
		     * attempt to use undocumented CPS SPI to notify the window
		     * server. Load the SPI symbol dynamically, so that we don't
		     * break if it ever disappears or changes its name.
d301 1
a301 5
		    TkMacOSXInitNamedSymbol(CoreGraphics, OSErr,
			    CPSEnableForegroundOperation, ProcessSerialNumberPtr);
		    if (CPSEnableForegroundOperation) {
			CPSEnableForegroundOperation(&psn);
		    }
a302 1
#endif /* MAC_OSX_TK_USE_CPS_SPI */
d305 1
@


1.3.2.19
log
@	* changes: updates for 8.4.14 release.

	* macosx/tkMacOSXDraw.c: fix numerous issues in CG and QD drawing procs
	so that they now match X11 drawing much more closely [Bug 1558051];
	use Tiger ellipse drawing API when available; fix comments & whitespace.

	* macosx/tkMacOSXInit.c: set default linewidth limit for CG
	antialiasing to 0 as thin horizontal/vertical lines look good now.

	* generic/tkCanvLine.c (ConfigureLine):     on TkAqua, pass outline
	* generic/tkCanvPoly.c (ConfigurePolygon):  linewidth in gc even for
	* generic/tkRectOval.c (ConfigureRectOval): fills (as it controls AA).
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.18 2006/08/18 07:47:25 das Exp $
d19 1
a19 1
#include "tclInt.h" /* for Tcl{G,S}etStartupScriptFileName() */
d140 1
a140 1
	TkMacOSXInitCGDrawing(interp, TRUE, 0);
@


1.3.2.20
log
@	* macosx/tkMacOSXInit.c (TkpInit): only set tcl_interactive 1 if
	it isn't already defined.  Allows embedders to set it to 0 to
	prevent the console appearing on OS X. [Bug 1487701]
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.19 2006/10/16 15:35:51 das Exp $
d228 3
a230 3
	 * 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.
d240 1
a240 4
		/*
		 * Only show the console if we don't have a startup script
		 * and tcl_interactive hasn't been set already.
		 */
d242 1
a242 6
		    CONST char *intvar =
			Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY);
		    if (intvar == NULL) {
			Tcl_SetVar(interp, "tcl_interactive", "1",
				TCL_GLOBAL_ONLY);
		    }
d251 4
a254 4
	 * 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, notify the window server that
	 * we are now a full GUI application.
d288 2
a289 2
	    /* If we are not a bundled executable, notify the window server
	     * that we are a foregroundable app. */
d302 4
a305 5
		     * When building or running on 10.2 or when the above
		     * fails, attempt to use undocumented CPS SPI to notify
		     * the window server. Load the SPI symbol dynamically, so
		     * that we don't break if it ever disappears or changes
		     * its name.
d327 1
a327 1
    return Tcl_EvalEx(interp, initScript, -1, TCL_EVAL_GLOBAL);
d465 1
a465 1
 *
d488 1
a488 1
    if (nsSymbol) {
@


1.3.2.21
log
@	* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
	* macosx/tkMacOSXEvent.c:	 handler for all kEventClassWindow and
	* macosx/tkMacOSXEvent.h:	 kEventClassMouse events; move all
	* macosx/tkMacOSXNotify.c:	 remaining events except for
	* macosx/tkMacOSXWindowEvent.c:	 kEventClassKeyboard from dispatcher to
	application event handler; pass event handler callRef downstream; fix
	debug event tracing; process all tcl event types in carbon event timer;
	delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark
	enter/exit of event tracking loop during which all tcl events but only
	carbon update events should be processed by the timer (replaces various
	calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent()
	to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to
	tkMacOSXCarbonEvents.c and modify it to dequeue only update events
	during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize
	the various ways in use to run the tcl event loop; add handling of
	kEventClassAppearance events (for ScrollBarVariantChanged event).

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXTrackingLoop() around
	* macosx/tkMacOSXEvent.c:	blocking API that puts up modal dialogs
	* macosx/tkMacOSXMenu.c:	or when entering/exiting menu/control
	* macosx/tkMacOSXMouseEvent.c:	tracking, window dragging and other
	* macosx/tkMacOSXScale.c:	mouse tracking loops.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXRunTclEventLoop()
	* macosx/tkMacOSXScale.c:	instead of Tcl_DoOneEvent(),
	* macosx/tkMacOSXScrlbr.c:	Tcl_ServiceAll(), TclServiceIdle()
	* macosx/tkMacOSXWindowEvent.c:	and Tcl_GlobalEval("update idletasks").

	* macosx/tkMacOSXColor.c: make available as Tk system colors all
	* macosx/tkMacOSXPort.h:  appearance manager brushes, text colors and
	backgrounds with new and legacy names, as well as the fully transparent
	color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to
	directly set an X pixel color value in the current QD port resp. the
	given CG context without requiring passage through rgb representation
	(lossy for most system colors); modernize/remove Classic-era code;
	replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct().

	* macosx/tkMacOSXButton.c:	use new TkMacOSXSetColorInPort()
	* macosx/tkMacOSXDraw.c:	instead of setting rgb color directly
	* macosx/tkMacOSXMenubutton.c:	to allow for non-rgb system colors.

	* macosx/tkMacOSXCursor.c: implement "none" cursor as on other
	platforms [Patch 1615427]; add all missing appearance manager cursors.

	* macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua
	L&F; use standard system color names; use new 'menu' system font;
	correct default scrollbar width.

	* macosx/tkMacOSXDraw.c:	standardize initialization, use and
	* macosx/tkMacOSXInt.h:		emptying of various static temp rgns
	* macosx/tkMacOSXRegion.c:	onto two global RgnHandles; in debug
	* macosx/tkMacOSXSubwindows.c:	builds, verify emptiness of these temp
	* macosx/tkMacOSXWindowEvent.c:	rgns before use.

	* macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to
	* macosx/tkMacOSXInt.h:  abstract common setup & teardown of drawing
	environment (for both CG and QD); save/restore QD theme drawing state;
	handle GC clip region; add TkpClipDrawableToRect() to allow clipped
	drawing into drawable regardless of GC used; use new system color
	"systemWindowHeaderBackground" to setup background in themed toplevels;
	correct implementation of TkMacOSXMakeStippleMap().

	* macosx/tkMacOSXEntry.c: use new TkMacOSXSetupDrawingContext() and
	* macosx/tkMacOSXFont.c:  TkMacOSXRestoreDrawingContext() instead of
	various setup/teardown procs like TkMacOSX{SetUp,Release}CGContext(),
	TkMacOSXQuarz{Start,End}Draw(), TkMacOSXSetUpGraphicsPort() etc.

	* macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields
	* macosx/tkMacOSXInt.h:   to MacDrawable struct.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al.
	use the sheet version of NavServices dialogs; ensure native parent win
	exists before using StandardSheet API for tk_messageBox [Bug 1677611];
	force sheets to behave like app-modal dialogs via WindowModality() API;
	use more modern ColorPicker API.

	* macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year.

	* macosx/tkMacOSXEntry.c:  take xOff/yOff of MacDrawable into account
	when computing locations/bounds to ensure correct posititioning when
	not drawing into intermediate pixmap.

	* macosx/tkMacOSXFont.c: use appearance manager API to map system font
	* macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for
	menu item text drawing from MDEF; disable broken QD stippling.

	* macosx/tkMacOSXMenu.c:		large-scale rewrite of custom
	* macosx/tkMacOSXMenu.r (removed):	MDEF and related code that
	* unix/Makefile.in:			restores many longtime-MIA
	features to working order (e.g. images, custom colors & fonts in menus
	etc); implement compound menu items; use Appearance Mgr and ThemeText
	APIs to mimic native MDEF as closely as possible when default "menu"
	system font is used; remove now obsolete SICN drawing code and
	resources.

	* macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events
	* macosx/tkMacOSXEvent.c:	 in order to support <<MenuSelect>> in
	* macosx/tkMacOSXMenu.c:	 the menubar and in menus that are not
	* macosx/tkMacOSXMenus.c:	 using the custom MDEF [Bug 1620826];
	fix early and missing clearing of current Tk active menu entry; fix
	extraneous sending of <<MenuSelect>> during active menu entry clearing.

	* macosx/tkMacOSXMouseEvent.c: add support for async window dragging by
	the window server; set the corresponding window attribute by default.

	* macosx/tkMacOSXMouseEvent.c: rationalized handling order of
	non-mousedown events; add TkMacOSXModifierState() to retrieve the
	current key modifiers in carbon format.

	* macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve
	scrollbar component metrics; add awareness of multiple possibilites for
	scrollbar arrow position in aqua and handle user changes to arrow
	position pref; handle difference in metrics of small & large scrollbar
	variants; handle aqua "jump to here" scrollbar behaviour; correct
	computation of scroll view size and position; enforce min scrollbar
	height to avoid scrollbar component overlap; erase scrollbar area
	outside of standard width; remove broken auto-adjust code; account for
	window class when leaving space for grow box; remove code to manually
	draw grow box; use modern API for thumb scroll proc; replace
	HiliteControl() by modern API; replace control mgr constants with
	appearance mgr equivalents.

	* macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of
	SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix
	for [Bug 940117] made them dependent on mapping state; remove unneeded
	calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port;
	use native-endian pixmap on intel; remove obsolete pixmap pix locking.

	* macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of
	kEventAppAvailableWindowBoundsChanged events sent per transaction;
	handle kEventWindowBoundsChanged event to support live window resizing
	and centralized sending of location/size changed ConfigureNotify
	events; ensure HIGrowBox is redrawn after bounds change; constrain
	window after dragging to ensure titlebar is not inacessible
	offscreen or under dock/menubar; handle kEventWindowGetRegion and
	kEventWindowDrawContent for transparent windows to mark resp. paint
	content region as transparent; handle kEventWindowConstrain for
	fullscreen windows to ensure bounds match new screen size; enter/exit
	fullscreen UIMode upon activation/deactivation of fullscreen window.

	* macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window
	* macosx/tkMacOSXWm.h: attributes for toplevels by default; implement
	new [wm attributes] -topmost, -transparent and -fullscreen; refactor
	WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus
	factored proc to set proxy icon from [wm iconbitmap]; dynamically
	determine default values for toplevel min and max sizes (similar to
	tkWinWm.c impl): min sizes depend on window class & attributes to
	ensure visibility of all titlebar widgets and grow box, max sizes
	depend on maximal window bounds for all active displays; factor out
	code that puts into effect changes to master or override_redirect; use
	RepositionWindow() API to determine staggered initial window bounds;
	correct resize limit calculations, handle gridding and use modern
	resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify
	after resize or zoom (now handled by BoundsChanged handler); correct
	composite carbon window attribute handling, remove currently unusable
	attributes and add new attributes in [tk::unsupported::MacWindowStyle];
	ensure validity of window class and attributes before use; apply
	changes to window class when handling carbon window attribute changes
	(if HIWindowChangeClass() API available); add debug build warning
	message when deprecated window style is used instead of window class;
	use transparent HIGrowBox for resizable windows; avoid unnecessary
	calls to window structure width API; use tcl time API in TkpGetMS();
	add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and
	menubar hidden; restrict wmTracing output to debug builds; remove
	unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD
	port; workaround GetWindowStructureWidths() Carbon bug (bogus results
	for never-mapped floating windows).

	* macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window
	bounds field to Screen record (in ext_data), computed as the union of
	available window positioning bounds of all graphics devices (displays).

	* macosx/tkMacOSXBitmap.c: fix macRoman encoding leak.
	* macosx/tkMacOSXCursor.c:

	* macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static
	* macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes.

	* macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of
	* macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld().
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS
	* macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c: remove obsolete and now incorrect
	* macosx/tkMacOSXInt.h:  tkMenuCascadeRgn clipping code.
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval()
	* macosx/tkMacOSXScrlbr.c:   by Tcl_EvalEx().
	* macosx/tkMacOSXInit.c:

	* macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps.

	* macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support.

	* macosx/tkMacOSXMenus.c: remove now useless call to
	TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman
	literar chars to allow file to be edited as utf-8.

	* macosx/tkMacOSXScale.c: replace TrackControl() by modern
	* macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new
	TkMacOSXModifierState()).

	* macosx/tkMacOSXInt.h:		move all constant #defines needed to
	* macosx/tkMacOSXColor.c:	support building on older OS X releases
	* macosx/tkMacOSXEvent.h:	to a central location in tkMacOSXInt.h.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:		 add ChkErr() macro to factor out
	* macosx/tkMacOSXButton.c:	 Carbon OSStatus return value checking
	* macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour
	* macosx/tkMacOSXClipboard.c:	 out debug message output; use these
	* macosx/tkMacOSXColor.c:	 macros to replace #ifdef TK_MAC_DEBUG
	* macosx/tkMacOSXCursor.c:	 blocks & direct printing to stderr,
	* macosx/tkMacOSXDebug.c:	 and to do additional OSStatus return
	* macosx/tkMacOSXDialog.c:	 checking, and to standardize OSStatus
	* macosx/tkMacOSXDraw.c:	 usage.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXSend.c:	remove duplicate/unused declarations.
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXDebug.c:	const fixes.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/Wish-Info.plist.in: add tcl document extensions/mime types and
	LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys.

	* macosx/tkMacOSXAETE.r:	fix whitespace.
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursors.r:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXXCursors.r:
	* macosx/README:

	* macosx/Makefile:		fix/add copyright and license refs.
	* macosx/Tk-Info.plist.in:
	* macosx/Wish-Info.plist.in:
	* macosx/tkMacOSX.h:
@
text
@d1 1
a1 1
/*
d4 2
a5 2
 *	This file contains Mac OS X -specific interpreter initialization
 *	functions.
d9 1
a9 1
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.20 2006/11/24 19:04:07 hobbs Exp $
d43 1
a43 1
 * the encoding for that font. The set of numeric constants is fixed and
d49 1
a49 1
    const char *strKey;
d85 1
a85 1
    {0,			NULL}
a95 1

d101 2
a102 2
 *	Performs Mac-specific interpreter initialization related to the
 *	tk_library variable.
d105 2
a106 2
 *	Returns a standard Tcl result. Leaves an error message or result
 *	in the interp's result.
d109 1
a109 1
 *	Sets "tk_library" Tcl variable, runs "tk.tcl" script.
d115 2
a116 2
TkpInit(
    Tcl_Interp *interp)
d119 1
a119 1
    static int tkMacOSXInitialized = 0;
d123 1
a123 1
    /*
d125 1
a125 1
     * and we don't want to do the following initialization multiple times
d129 1
a129 4
    if (!tkMacOSXInitialized) {
	int bundledExecutable = 0;
	CFBundleRef bundleRef;
	CFURLRef bundleUrl = NULL;
d131 1
a131 1
	const char *encodingStr = NULL;
d134 25
a158 1
	tkMacOSXInitialized = 1;
d161 1
a161 1
	 * When Tk is in a framework, force tcl_findLibrary to look in the
d168 1
a168 2
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX,
		tkLibPath) != TCL_OK)
d184 1
a184 1
		/* Get resource data from __tk_rsrc section of tk dylib file*/
d189 1
a189 2
			data = getsectdatafromheader(image, SEG_TEXT,
					"__tk_rsrc", (void*)&size);
d197 1
d201 1
a201 4
		    /*
		     * Write resource data to temporary file and open it.
		     */

d208 1
a208 3
		    if (fd == -1) {
			break;
		    }
d210 7
a216 9
		    if (write(fd, data, size) == -1) {
			break;
		    }
		    if(ChkErr(FSPathMakeRef, (unsigned char*)fileName, &ref,
			    NULL) != noErr) {
			break;
		    }
		    ChkErr(FSOpenResourceFile, &ref, 0, NULL, fsRdPerm,
			    &refNum);
a227 94
	 * 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, notify the window server that
	 * we are now a full GUI application.
	 */

	/* Check whether we are a bundled executable: */
	bundleRef = CFBundleGetMainBundle();
	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, notify the window server that
	 * we are a foregroundable app. */
	if (!bundledExecutable) {
	    OSStatus err = procNotFound;
	    ProcessSerialNumber psn = { 0, kCurrentProcess };

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
	    if (1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
		    && TransformProcessType != NULL
#endif
	    ) {
		err = ChkErr(TransformProcessType, &psn,
			kProcessTransformToForegroundApplication);
	    }
#endif
#if MAC_OSX_TK_USE_CPS_SPI
	    if (err != noErr) {
		/*
		 * When building or running on 10.2 or when the above fails,
		 * attempt to use undocumented CPS SPI to notify the window
		 * server. Load the SPI symbol dynamically, so that we don't
		 * break if it ever disappears or changes its name.
		 */
		TkMacOSXInitNamedSymbol(CoreGraphics, OSStatus,
			CPSEnableForegroundOperation, ProcessSerialNumberPtr);
		if (CPSEnableForegroundOperation) {
		    ChkErr(CPSEnableForegroundOperation, &psn);
		}
	    }
#endif /* MAC_OSX_TK_USE_CPS_SPI */
	}

	TkMacOSXInitAppleEvents(interp);
	TkMacOSXInitCarbonEvents(interp);
	TkMacOSXInitMenus(interp);
	TkMacOSXUseAntialiasedText(interp, TRUE);
	TkMacOSXInitCGDrawing(interp, TRUE, 0);
	TkMacOSXInitKeyboard(interp);

	encoding = CFStringGetSystemEncoding();

	for (i = 0; scriptMap[i].strKey != NULL; i++) {
	    if (scriptMap[i].numKey == encoding) {
		encodingStr = scriptMap[i].strKey;
		break;
	    }
	}
	if (encodingStr == NULL) {
	    encodingStr = "macRoman";
	}

	TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, encodingStr);
	if (TkMacOSXCarbonEncoding == NULL) {
	    TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, NULL);
	}

	/*
a234 1

a239 1

a243 1

d245 2
a246 3
		    const char *intvar = Tcl_GetVar(interp,
			    "tcl_interactive", TCL_GLOBAL_ONLY);

d257 68
d344 3
a346 3
 *	Retrieves the name of the current application from a platform
 *	specific location. For Unix, the application name is the tail
 *	of the path contained in the tcl variable argv0.
d349 1
a349 1
 *	Returns the application name in the given Tcl_DString.
d352 1
a352 1
 *	None.
d358 3
a360 3
TkpGetAppName(
    Tcl_Interp *interp,
    Tcl_DString *namePtr)	/* A previously initialized Tcl_DString. */
d362 1
a362 1
    const char *p, *name;
d381 2
a382 2
 *	This routines is called from Tk_Main to display warning
 *	messages that occur during startup.
d385 1
a385 1
 *	None.
d388 1
a388 1
 *	Generates messages on stdout.
d394 3
a396 3
TkpDisplayWarning(
    CONST char *msg,		/* Message to be displayed. */
    CONST char *title)		/* Title of warning. */
d413 6
a418 6
 *	On MacOS X, we look for a file in the Resources/Scripts
 *	directory called AppMain.tcl and if found, we set argv[1] to
 *	that, so that the rest of the code will find it, and add the
 *	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.
d421 1
a421 1
 *	None.
d424 1
a424 1
 *	TclSetStartupScriptFileName() called when AppMain.tcl found.
d438 3
a440 3
	appMainURL = CFBundleCopyResourceURL(bundleRef,
		CFSTR("AppMain"),
		CFSTR("tcl"),
d453 1
a453 1
		    CFURLGetFileSystemRepresentation(scriptFldrURL,
d469 5
a473 5
 *	Dynamically acquire address of a named symbol from a loaded
 *	dynamic library, so that we can use API that may not be
 *	available on all OS versions.
 *	If module is non-NULL and not the empty string, use twolevel
 *	namespace lookup.
d476 1
a476 1
 *	Address of given symbol or NULL if unavailable.
d479 1
a479 1
 *	None.
d485 1
a485 3
TkMacOSXGetNamedSymbol(
    const char* module,
    const char* symbol)
@


1.3.2.22
log
@	* macosx/tkMacOSXMouseEvent.c (GenerateMouseWheelEvent): enable
	processing of mousewheel events in background windows.

	* macosx/tkMacOSXScrlbr.c: modernize checks for active/front window.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXColor.c: factor out verbose #ifdef checks of
	* macosx/tkMacOSXDraw.c:  MAC_OS_X_VERSION_{MAX_ALLOWED,MIN_REQUIRED}
	* macosx/tkMacOSXEntry.c: and runtime checks of kHIToolboxVersion into
	* macosx/tkMacOSXEvent.c: new TK_{IF,ELSE,ENDIF}_MAC_OS_X macros.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c:  factor out clip clearing in QD ports;
	* macosx/tkMacOSXEntry.c: formatting cleanup.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.21 2007/04/29 02:26:49 das Exp $
d258 6
a263 1
	    TK_IF_MAC_OS_X_API (3, TransformProcessType,
d266 2
a267 1
	    ) TK_ENDIF_MAC_OS_X
@


1.3.2.23
log
@	* macosx/tkMacOSXColor.c: fix issues with TK_{IF,ELSE,ENDIF} macros;
	* macosx/tkMacOSXDraw.c:  implement Jaguar equivalent of unavailable
	* macosx/tkMacOSXEntry.c: kHIToolboxVersion global; panic at startup
	* macosx/tkMacOSXEvent.c: if MAC_OS_X_VERSION_MIN_REQUIRED constraint
	* macosx/tkMacOSXInit.c:  is not satisfied.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage)
	(TkMacOSXSetupDrawingContext): factor out common code and standardize
	setup/restore of port, context and clipping; formatting cleanup.

	* macosx/tkMacOSXWindowEvent.c:	add error checking.
	* macosx/tkMacOSXMenu.c:	fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	formatting cleanup.
	* macosx/tkMacOSXRegion.c:	fix typos.
	* macosx/tkMacOSXScale.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.22 2007/06/06 09:56:54 das Exp $
a21 1
#include <sys/utsname.h>
a95 2
float tkMacOSXToolboxVersionNumber = 0;

d120 1
a120 1
    static int initialized = 0;
d130 1
a130 1
    if (!initialized) {
a136 2
	struct utsname name;
	long osVersion = 0;
d138 1
a138 28
	initialized = 1;
	
	/*
	 * Initialize/check OS version variable for runtime checks.
	 */
	
	if (!uname(&name)) {
	    osVersion = strtol(name.release, NULL, 10) - 4;
	}
	if (osVersion && osVersion < (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10) {
	    Tcl_Panic("Mac OS X 10.%d or later required !",
		(MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10);
	}
	TK_IF_MAC_OS_X_API (3, &kHIToolboxVersionNumber,
	    tkMacOSXToolboxVersionNumber = kHIToolboxVersionNumber;
	) TK_ELSE_MAC_OS_X (3,
	    if (osVersion > 5) {
		tkMacOSXToolboxVersionNumber = INFINITY;
	    } else if (osVersion >= 3) {
		static const float tbVersions[3] = {
		    kHIToolboxVersionNumber10_3,
		    kHIToolboxVersionNumber10_4,
		    kHIToolboxVersionNumber10_5,
		};

		tkMacOSXToolboxVersionNumber = tbVersions[osVersion-3];
	    }
	) TK_ENDIF
d261 1
a261 1
	    ) TK_ENDIF
@


1.3.2.24
log
@	* macosx/tkMacOSXScrlbr.c: correct int <-> dobule conversion issues
	that could lead to Carbon getting confused about scrollbar thumb size.

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage) use
	TkMacOSX{Setup,Restore}DrawingContext() to setup/restore clip & colors.
	(TkMacOSXSetupDrawingContext, TkMacOSXRestoreDrawingContext): add save
	and restore of QD port clip region; factor out clip region code common
	to CG and QD branches; check for port and context validity; handle
	tkPictureIsOpen flag during QD port setup.
	(TkScrollWindow): remove unnecessary scroll region manipulation

	* macosx/tkMacOSXDraw.c:	remove second global QD temp region
	* macosx/tkMacOSXInt.h:		(no longer necessary) and rename
	* macosx/tkMacOSXRegion.c:	remaining global QD temp region.
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXDraw.c:	make useCGDrawing variable MODULE_SCOPE
	* macosx/tkMacOSXFont.c:	and sync formatting with HEAD.

	* macosx/tkMacOSXButton.c:	reduce reliance on current QD port
	* macosx/tkMacOSXColor.c:	setting and remove unnecessary
	* macosx/tkMacOSXDebug.c:	references to a drawable's QD port,
	* macosx/tkMacOSXDebug.h:	notably replace GetWindowFromPort(
	* macosx/tkMacOSXDialog.c:	TkMacOSXGetDrawablePort()) idiom by new
	* macosx/tkMacOSXDraw.c:	TkMacOSXDrawableWindow() and change
	* macosx/tkMacOSXKeyEvent.c:	TkMacOSXSetColorInPort() to take a port
	* macosx/tkMacOSXMenu.c:	argument.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:			factor out macros, declarations
	* macosx/tkMacOSXPrivate.h (new):	and prototypes that are purely
	internal and private to the 'macosx' sources into a new internal header
	file that does _not_ get installed into Tk.framework/PrivateHeaders.

	* macosx/tkMacOSXButton.c:		#include new tkMacOSXPrivate.h
	* macosx/tkMacOSXCarbonEvents.c:	instead of tkMacOSXInt.h.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.23 2007/06/09 17:10:21 das Exp $
d17 1
a17 1
#include "tkMacOSXPrivate.h"
@


1.3.2.25
log
@	Backport from HEAD of Aqua changes from 2007-10-12 to 2007-11-09
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.3.2.24 2007/06/29 03:22:02 das Exp $
a334 12
#if 0
	/*
	 * FIXME: Close stdin & stdout for remote debugging otherwise we
	 * will fight with gdb for stdin & stdout
	 */

	if (getenv("XCNOSTDIN") != NULL) {
	    close(0);
	    close(1);
	}
#endif

@


1.2
log
@	*** macosx-8-4-branch merged into the mainline [tcl patch #602770] ***

	* generic/tk.decls:
	* generic/tkInt.decls: added new "aqua" specific entries to the
	stubs tables. Changed all "unix" entries to "x11" to allow us to
	distinguish and build both "aqua" on MacOSX and "x11" on MacOSX.

	* generic/tk.h: added a #ifnded RESOURCE_INCLUDED so that tk.h can
	be passed to the resource compiler.

	* generic/tkCmds.c (Tk_TkObjCmd): added [tk windowingsystem]
	subcommand: returns "x11" when running on X11, "win32" on Windows,
	"classic" on MacOS9 and "aqua" on MacOSX Aqua (i.e. Carbon)

	* generic/tkFont.c (TkFontGetFirstTextLayout): new private function
	returning the first chunk of a Tk_TextLayout, i.e. until the first
	font change on the first line (or the whole first line if there is
	no such font change).

	* generic/tkMain.c: made Tcl_ThreadDataKey static

	* library/demos/puzzle.tcl: fixed button metrics for aqua

	* tests/cursor.test: check for presence of arrow cursor instead of
	heart cursor

	* xlib/xcolors.c: changed xColors static initialization to more
	standard C

	* macosx/Wish.pbproj/jingham.pbxuser (new):
	* macosx/Wish.pbproj/project.pbxproj (new): project for Apple's
	ProjectBuilder IDE.

	* macosx/Makefile (new): simple makefile for building the project
	from the command line via the ProjectBuilder tool 'pbxbuild'.

	* macosx/tkMacOSXAppInit.c (new): macosx specific AppInit looking
	for a AppMain.tcl file in its bundled Resources/Scripts folder. If
	present, argv[1] is set to that file and the Scripts folder is
	added to the auto_path. This allows tk apps to embed scripts within
	their bundle directory structure.

	* macosx/tkMacOSXInit.c (new): macosx adapted version of
	tkUnixInit.c: we initialize & cache the Carbon native encoding
	(e.g. 'macRoman') and try to find the tk script library files
	inside Tk packaged as a framework.

	* macosx/tkMacOSXNotify.c (new): new macosx specific merged
	Carbon/select-based notifier.

	* macosx/tkMacOSXEvent.c (new):
	* macosx/tkMacOSXEvent.h (new):
	* macosx/tkMacOSXKeyEvent.c (new):
	* macosx/tkMacOSXMouseEvent.c (new):
	* macosx/tkMacOSXWindowEvent.c (new): new macosx specific event
	handling functionality.

	* macosx/tkMacOSX.h (new):
	* macosx/tkMacOSXBitmap.c (new):
	* macosx/tkMacOSXButton.c (new):
	* macosx/tkMacOSXClipboard.c (new):
	* macosx/tkMacOSXColor.c (new):
	* macosx/tkMacOSXConfig.c (new):
	* macosx/tkMacOSXCursor.c (new):
	* macosx/tkMacOSXDefault.h (new):
	* macosx/tkMacOSXDialog.c (new):
	* macosx/tkMacOSXDraw.c (new):
	* macosx/tkMacOSXEmbed.c (new):
	* macosx/tkMacOSXFont.c (new):
	* macosx/tkMacOSXHLEvents.c (new):
	* macosx/tkMacOSXInt.h (new):
	* macosx/tkMacOSXKeyboard.c (new):
	* macosx/tkMacOSXMenu.c (new):
	* macosx/tkMacOSXMenubutton.c (new):
	* macosx/tkMacOSXMenus.c (new):
	* macosx/tkMacOSXPort.h (new):
	* macosx/tkMacOSXRegion.c (new):
	* macosx/tkMacOSXScale.c (new):
	* macosx/tkMacOSXScrlbr.c (new):
	* macosx/tkMacOSXSubwindows.c (new):
	* macosx/tkMacOSXTest.c (new):
	* macosx/tkMacOSXUtil.c (new):
	* macosx/tkMacOSXUtil.h (new):
	* macosx/tkMacOSXWm.c (new):
	* macosx/tkMacOSXWm.h (new):
	* macosx/tkMacOSXXStubs.c (new): macosx ports of classic mac Tk
	implementation in tk/mac.

	* macosx/tkMacOSXSend.c (new): only send to local interp
	implemented currently.

	* macosx/tkMacOSXDebug.h (new):
	* macosx/tkMacOSXDebug.c (new): new macosx specific functions for
	debugging MacOS events, regions, etc.

	* macosx/tkAboutDlg.r (new):
	* macosx/tkMacOSXApplication.r (new):
	* macosx/tkMacOSXCursors.r (new):
	* macosx/tkMacOSXLibrary.r (new):
	* macosx/tkMacOSXMenu.r (new):
	* macosx/tkMacOSXResource.r (new):
	* macosx/tkMacOSXXCursors.r (new):
	* macosx/tclets.r (new): sources for Rez resource compiler.

	* macosx/Wish.icns (new): Wish application icon.

	* generic/tk.h:
	* generic/default.h:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkGrab.c:
	* generic/tkPointer.c:
	* generic/tkPort.h:
	* generic/tkSelect.c:
	* generic/tkStubLib.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkWindow.c:
	* unix/tkUnix3d.c:
	* xlib/xgc.c:
	* xlib/X11/X.h:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h: added #includes and #ifdefs for macosx

	* library/bgerror.tcl:
	* library/button.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/widget: check [tk windowingsystem] instead of
	and/or in addition to $tcl_platform(platform).

	* generic/tkInt.h:
	* mac/tkMacBitmap.c:
	* mac/tkMacWm.c: added missing CONSTification

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: regen
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d75 1
a75 1

d114 1
@


1.1
log
@file tkMacOSXInit.c was initially added on branch macosx-8-4-branch.
@
text
@d1 221
@


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 211
/* 
 * tkUnixInit.c --
 *
 *        This file contains Unix-specific interpreter initialization
 *        functions.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001, Apple Computer, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id$
 */

#include "tkInt.h"
#include "tkMacOSXInt.h"

/*
 * The Init script (common to Windows and Unix platforms) is
 * defined in tkInitScript.h
 */
#include "tkInitScript.h"


/*
 *----------------------------------------------------------------------
 *
 * TkpInit --
 *
 *        Performs Mac-specific interpreter initialization related to the
 *      tk_library variable.
 *
 * Results:
 *        Returns a standard Tcl result.  Leaves an error message or result
 *        in the interp's result.
 *
 * Side effects:
 *        Sets "tk_library" Tcl variable, runs "tk.tcl" script.
 *
 *----------------------------------------------------------------------
 */

int
TkpInit(interp)
    Tcl_Interp *interp;
{
    char tkLibPath[1024];
    int result;
    
    Tcl_SetVar2(interp, "tcl_platform", "windowingsystem", "aqua", TCL_GLOBAL_ONLY);
    
    /*
     * 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?
     */
     
    result = Tk_MacOSXOpenBundleResources(interp, "com.tcltk.tklibrary", 
                tkLibPath, 1024, 1);
     
    if (result != TCL_ERROR) {
        Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
        Tcl_SetVar(interp, "auto_path", tkLibPath, 
            TCL_GLOBAL_ONLY | TCL_LIST_ELEMENT | TCL_APPEND_VALUE);
    }
    
    return Tcl_Eval(interp, initScript);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetAppName --
 *
 *        Retrieves the name of the current application from a platform
 *        specific location.  For Unix, the application name is the tail
 *        of the path contained in the tcl variable argv0.
 *
 * Results:
 *        Returns the application name in the given Tcl_DString.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

void
TkpGetAppName(interp, namePtr)
    Tcl_Interp *interp;
    Tcl_DString *namePtr;        /* A previously initialized Tcl_DString. */
{
    char *p, *name;

    name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
    if ((name == NULL) || (*name == 0)) {
        name = "tk";
    } else {
        p = strrchr(name, '/');
        if (p != NULL) {
            name = p+1;
        }
    }
    Tcl_DStringAppend(namePtr, name, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayWarning --
 *
 *        This routines is called from Tk_Main to display warning
 *        messages that occur during startup.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Generates messages on stdout.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayWarning(msg, title)
    char *msg;                  /* Message to be displayed. */
    char *title;                /* Title of warning. */
{
    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);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXOpenBundleResources --
 *
 *	Given the bundle name for a shared library, this routine
 *	sets libraryVarName to the Resources/Scripts directory 
 *	in the framework package.  If hasResourceFile is
 *	true, it will also open the main resource file for the bundle.
 *
 *      FIXME: This should probably be in Tcl, but the resource stuff
 *      isn't in Darwin, and I haven't figured out how to sort out Darwin,
 *      the Unix side of Tcl, and the MacOS X side of Tcl.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	libraryVariableName may be set, and the resource file opened.
 *
 *----------------------------------------------------------------------
 */

int
Tk_MacOSXOpenBundleResources(Tcl_Interp *interp,
        char *bundleName,
        char *libraryPath,
        int maxPathLen,
        int hasResourceFile)
{
    CFBundleRef bundleRef;
    CFStringRef bundleNameRef;
    
    libraryPath[0] = '\0';
    
    bundleNameRef = CFStringCreateWithCString(NULL, 
            bundleName, kCFStringEncodingUTF8);
            
    bundleRef = CFBundleGetBundleWithIdentifier(bundleNameRef);
    CFRelease(bundleNameRef);
    
    if (bundleRef == 0) {
        return TCL_ERROR;
    } else {
        CFURLRef libURL;
        
        if (hasResourceFile) {
            short refNum;
            refNum = CFBundleOpenBundleResourceMap(bundleRef);
        }
        
	libURL = CFBundleCopyResourceURL(bundleRef, 
	        CFSTR("Scripts"), 
		NULL, 
		NULL);
        
        if (libURL != NULL) {
            /* 
             * FIXME: This is a quick fix, it is probably not right 
             * for internationalization. 
             */
            
            if (CFURLGetFileSystemRepresentation (libURL, true,
                    libraryPath, maxPathLen)) {
            }
            CFRelease(libURL);
        } else {
            return TCL_ERROR;
        }
    }
    
    return TCL_OK;
}
@


1.1.2.2
log
@Move the bundle routines over to Tcl, and use them from there.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.1.2.1 2001/10/15 09:22:00 wolfsuit Exp $
d59 2
a60 2
    result = Tcl_MacOSXOpenBundleResources(interp, "com.tcltk.tklibrary", 
                1, 1024, tkLibPath);
d137 75
a211 1
}@


1.1.2.3
log
@        * macosx/tkMacOSXInit.c (TkpInit): Move ALL the MacOS X specific
        initialization code into TkpInit so extension writers don't have
        to do anything special to initialize Tk.

This is patch #495549
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d50 2
a51 15
    static int menusInitialized = false;

    /* Since it is possible for TkInit to be called multiple times
     * and we don't want to do the menu initialization multiple times
     * we protect against doing it more than once.
     */

    if (menusInitialized == false) {
    	menusInitialized = true;
        Tk_MacOSXSetupTkNotifier();
        TkMacOSXInitAppleEvents(interp);
        TkMacOSXInitMenus(interp);
    }
    Tcl_SetVar2(interp, "tcl_platform", "windowingsystem", 
            "aqua", TCL_GLOBAL_ONLY);
d137 1
a137 1
}
@


1.1.2.4
log
@Merge with current TOT
Added support for the wm stackorder command
Fixed crash when selecting Menu items in the Application menu that we didn't
put there.
Added first bits of the use of CG for low-level drawing.  The line-drawing works,
the rest doesn't yet.  You have to set the file static useCGDrawing to 1 and
rebuild to activate this code.
@
text
@d140 2
a141 2
    CONST char *msg;                  /* Message to be displayed. */
    CONST char *title;                /* Title of warning. */
@


1.1.2.5
log
@encodings, events
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.1.2.4 2002/02/05 02:25:17 wolfsuit Exp $
a24 2
Tcl_Encoding macRomanEncoding = NULL;

a51 4
    if (macRomanEncoding == NULL) {
	macRomanEncoding = Tcl_GetEncoding(NULL, "macRoman");
    }
    
@


1.1.2.6
log
@Jim's patch for encodings
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXInit.c,v 1.1.2.5 2002/07/18 23:45:18 vincentdarley Exp $
d25 1
a25 49
/*
 * The following structures are used to map the script/language codes of a
 * font to the name that should be passed to Tcl_GetEncoding() to obtain
 * the encoding for that font.  The set of numeric constants is fixed and
 * defined by Apple.
 */

typedef struct Map {
    int numKey;
    char *strKey;
} Map;

static Map scriptMap[] = {
    {smRoman,		"macRoman"},
    {smJapanese,	"macJapan"},
    {smTradChinese,	"macChinese"},
    {smKorean,		"macKorean"},
    {smArabic,		"macArabic"},
    {smHebrew,		"macHebrew"},
    {smGreek,		"macGreek"},
    {smCyrillic,	"macCyrillic"},
    {smRSymbol,		"macRSymbol"},
    {smDevanagari,	"macDevanagari"},
    {smGurmukhi,	"macGurmukhi"},
    {smGujarati,	"macGujarati"},
    {smOriya,		"macOriya"},
    {smBengali,		"macBengali"},
    {smTamil,		"macTamil"},
    {smTelugu,		"macTelugu"},
    {smKannada,		"macKannada"},
    {smMalayalam,	"macMalayalam"},
    {smSinhalese,	"macSinhalese"},
    {smBurmese,		"macBurmese"},
    {smKhmer,		"macKhmer"},
    {smThai,		"macThailand"},
    {smLaotian,		"macLaos"},
    {smGeorgian,	"macGeorgia"},
    {smArmenian,	"macArmenia"},
    {smSimpChinese,	"macSimpChinese"},
    {smTibetan,		"macTIbet"},
    {smMongolian,	"macMongolia"},
    {smGeez,		"macEthiopia"},
    {smEastEurRoman,	"macCentEuro"},
    {smVietnamese,	"macVietnam"},
    {smExtArabic,	"macSindhi"},
    {NULL,		NULL}
};

Tcl_Encoding TkMacOSXCarbonEncoding = NULL;
a52 1
    static int carbonEncodingInitialized = false;
d54 5
a58 2
    /* 
     * Since it is possible for TkInit to be called multiple times
a68 24
 
    if (carbonEncodingInitialized == false) {
	CFStringEncoding encoding;
	char *encodingStr = NULL;
	int  i;
	
	encoding = CFStringGetSystemEncoding();
	
	for (i = 0; scriptMap[i].strKey != NULL; i++) {
	    if (scriptMap[i].numKey == encoding) {
		encodingStr = scriptMap[i].strKey;
		break;
	    }
	}
	if (encodingStr == NULL) {
	    encodingStr = "macRoman";
	}
	
	TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr);
	if (TkMacOSXCarbonEncoding == NULL) {
	    TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL);
	}
    }
    
@


1.1.2.7
log
@whitespace & other cleanup
wish startup code cleanup induced by new support in tcl for standard MacOSX tcl package locations
renamed Tk_GetFirstTextLayout to private TkFontGetFirstTextLayout
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d153 2
d183 1
a183 1
    CONST char *p, *name;
@


1.1.2.8
log
@various project cleanups & enhancements
added macosx/Makefile to facilitate building from cli
added [tk windowingsystem] and removed $::tcl_plaform(windowingsystem)
changed all runtime library references to the above
removed duplicate entries in tk.decls & tkInt.decls
CONSTification and other small changes in macosx/ to remove compiler warnings
@
text
@d139 3
@


