head	1.12;
access;
symbols
	core-8-5-9:1.7.4.1
	core-8-5-8:1.7.4.1
	macosx-cocoa-merge:1.10
	macosx-cocoa-premerge:1.9
	macosx-carbon-freeze:1.9
	core-8-5-7:1.7.4.1
	core-8-5-6:1.7.4.1
	core-8-6-b1:1.8
	core-8-6-a3:1.8
	core-8-5-5:1.7.4.1
	core-8-6-a2:1.8
	core-8-5-4:1.7.4.1
	core-8-5-3:1.7.4.1
	core-8-6-a1:1.8
	core-8-4-19:1.2.2.3
	core-8-5-branch:1.7.0.4
	core-8-5-2:1.7
	core-8-4-18:1.2.2.3
	core-8-5-1:1.7
	core-8-4-17:1.2.2.3
	core-8-5-0:1.7
	core-8-5-b3:1.7
	core-8-5-b2:1.7
	core-8-4-16:1.2.2.3
	core-8-5-b1:1.7
	core-stablilizer-merge:1.7
	core-stabilizer-branch:1.7.0.2
	core-stabilizer-merge:1.7.4.1
	core-8-4-15:1.2.2.3
	core-8-5-a6:1.7
	core-8-5-a5:1.4
	core-8-4-14:1.2.2.2
	core-8-5-a4:1.4
	core-8-4-13:1.2.2.2
	core-8-4-12:1.2.2.1
	core-8-4-11:1.2.2.1
	core-8-5-a3:1.3
	core-8-4-10:1.2.2.1
	core-8-4-9-branch:1.2.0.6
	core-8-5-a2:1.2
	core-8-4-9:1.2
	core-8-4-8:1.2
	core-8-4-7:1.2
	core-8-5-a1:1.2
	core-8-4-6:1.2
	core-8-4-5:1.2
	mistachkin-dev-branch:1.2.0.4
	core-8-4-4:1.2
	core-8-4-3:1.2
	core-8-4-branch:1.2.0.2
	core-8-4-2:1.2
	core-8-4-1:1.2
	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.2
	macosx-8-4-merge-2002-08-30-branch:1.1.2.1
	macosx-8-4-merge-2002-08-20-branch:1.1.2.1
	macosx-premerge-6-9-02:1.1.2.1
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@ * @;


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

1.11
date	2009.07.06.20.29.21;	author dkf;	state Exp;
branches;
next	1.10;

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

1.9
date	2009.02.27.23.23.36;	author nijtmans;	state Exp;
branches;
next	1.8;

1.8
date	2008.04.27.22.39.12;	author dkf;	state Exp;
branches;
next	1.7;

1.7
date	2007.04.23.21.24.32;	author das;	state Exp;
branches
	1.7.2.1
	1.7.4.1;
next	1.6;

1.6
date	2007.04.21.19.06.37;	author hobbs;	state Exp;
branches;
next	1.5;

1.5
date	2007.04.13.14.51.17;	author dkf;	state Exp;
branches;
next	1.4;

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

1.3
date	2005.05.14.20.48.14;	author das;	state Exp;
branches;
next	1.2;

1.2
date	2002.08.31.06.12.29;	author das;	state Exp;
branches
	1.2.2.1;
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	2002.08.30.18.18.16;	author das;	state Exp;
branches;
next	;

1.2.2.1
date	2005.05.14.20.53.31;	author das;	state Exp;
branches;
next	1.2.2.2;

1.2.2.2
date	2006.03.28.02.44.12;	author das;	state Exp;
branches;
next	1.2.2.3;

1.2.2.3
date	2007.04.29.02.26.47;	author das;	state Exp;
branches;
next	;

1.7.2.1
date	2008.06.25.16.46.07;	author dgp;	state Exp;
branches;
next	;

1.7.4.1
date	2008.05.03.21.09.16;	author das;	state Exp;
branches;
next	;


desc
@@


1.12
log
@	* macosx/tkMacOSXBitmap.c:	Fix tk::mac::iconBitmap crash due to
					off-by-one ckalloc error. [Bug 2821318]
@
text
@/*
 * tkMacOSXBitmap.c --
 *
 *	This file handles the implementation of native bitmaps.
 *
 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-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: tkMacOSXBitmap.c,v 1.11 2009/07/06 20:29:21 dkf Exp $
 */

#include "tkMacOSXPrivate.h"

/*
 * This structure holds information about native bitmaps.
 */

typedef struct {
    const char *name;		/* Name of icon. */
    OSType iconType;		/* OSType of icon. */
} BuiltInIcon;

/*
 * This array mapps a string name to the supported builtin icons
 * on the Macintosh.
 */

static BuiltInIcon builtInIcons[] = {
    {"document",	kGenericDocumentIcon},
    {"stationery",	kGenericStationeryIcon},
    {"edition",		kGenericEditionFileIcon},
    {"application",	kGenericApplicationIcon},
    {"accessory",	kGenericDeskAccessoryIcon},
    {"folder",		kGenericFolderIcon},
    {"pfolder",		kPrivateFolderIcon},
    {"trash",		kTrashIcon},
    {"floppy",		kGenericFloppyIcon},
    {"ramdisk",		kGenericRAMDiskIcon},
    {"cdrom",		kGenericCDROMIcon},
    {"preferences",	kGenericPreferencesIcon},
    {"querydoc",	kGenericQueryDocumentIcon},
    {"stop",		kAlertStopIcon},
    {"note",		kAlertNoteIcon},
    {"caution",		kAlertCautionIcon},
    {NULL}
};

#define builtInIconSize 32

static Tcl_HashTable iconBitmapTable = {};
typedef struct {
    int kind, width, height;
    char *value;
} IconBitmap;

static const char *const iconBitmapOptionStrings[] = {
    "-file", "-fileType", "-osType", "-systemType", "-namedImage",
    "-imageFile", NULL
};
enum iconBitmapOptions {
    ICON_FILE, ICON_FILETYPE, ICON_OSTYPE, ICON_SYSTEMTYPE, ICON_NAMEDIMAGE,
    ICON_IMAGEFILE,
};


/*
 *----------------------------------------------------------------------
 *
 * TkpDefineNativeBitmaps --
 *
 *	Add native bitmaps.
 *
 * Results:
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
 *
 * Side effects:
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
 *
 *----------------------------------------------------------------------
 */

void
TkpDefineNativeBitmaps(void)
{
    Tcl_HashTable *tablePtr = TkGetBitmapPredefTable();
    BuiltInIcon *builtInPtr;

    for (builtInPtr = builtInIcons; builtInPtr->name != NULL; builtInPtr++) {
	Tcl_HashEntry *predefHashPtr;
	Tk_Uid name;
	int isNew;

	name = Tk_GetUid(builtInPtr->name);
	predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew);
	if (isNew) {
	    TkPredefBitmap *predefPtr = (TkPredefBitmap *)
		    ckalloc(sizeof(TkPredefBitmap));
	    predefPtr->source = UINT2PTR(builtInPtr->iconType);
	    predefPtr->width = builtInIconSize;
	    predefPtr->height = builtInIconSize;
	    predefPtr->native = 1;
	    Tcl_SetHashValue(predefHashPtr, predefPtr);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GetBitmapForIcon --
 *
 * Results:
 *	Bitmap for the given IconRef.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Pixmap
GetBitmapForIcon(
    Display *display,
    IconRef icon,
    CGSize size)
{
    TkMacOSXDrawingContext dc;
    Pixmap pixmap;

    pixmap = Tk_GetPixmap(display, None, size.width, size.height, 0);
    if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
	if (dc.context) {
	    const CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
		    .tx = 0, .ty = size.height };
	    const CGRect r = { .origin = { .x = 0, .y = 0 }, .size = size };

	    CGContextConcatCTM(dc.context, t);
	    PlotIconRefInContext(dc.context, &r, kAlignAbsoluteCenter,
		    kTransformNone, NULL, kPlotIconRefNormalFlags, icon);
	}
	TkMacOSXRestoreDrawingContext(&dc);
    }
    return pixmap;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateNativeBitmap --
 *
 *	Create native bitmap.
 *
 * Results:
 *	Native bitmap.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Pixmap
TkpCreateNativeBitmap(
    Display *display,
    const void *source)		/* Info about the icon to build. */
{
    Pixmap pixmap;
    IconRef icon;
    OSErr err;

    err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
	    PTR2UINT(source), &icon);
    if (err == noErr) {
	pixmap = GetBitmapForIcon(display, icon, CGSizeMake(builtInIconSize,
		builtInIconSize));
	ReleaseIconRef(icon);
    } else {
	pixmap = Tk_GetPixmap(display, None, builtInIconSize,
		builtInIconSize, 0);
    }
    return pixmap;
}

/*
 *----------------------------------------------------------------------
 *
 * OSTypeFromString --
 *
 *	Helper to convert string to OSType.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	t is set to OSType if conversion successful.
 *
 *----------------------------------------------------------------------
 */

static int
OSTypeFromString(const char *s, OSType *t) {
    int result = TCL_ERROR;
    Tcl_DString ds;
    Tcl_Encoding encoding = Tcl_GetEncoding(NULL, "macRoman");

    Tcl_UtfToExternalDString(encoding, s, -1, &ds);
    if (Tcl_DStringLength(&ds) <= 4) {
	char string[4] = {};
	memcpy(string, Tcl_DStringValue(&ds), (size_t) Tcl_DStringLength(&ds));
	*t = (OSType) string[0] << 24 | (OSType) string[1] << 16 |
	     (OSType) string[2] <<  8 | (OSType) string[3];
	result = TCL_OK;
    }
    Tcl_DStringFree(&ds);
    Tcl_FreeEncoding(encoding);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetNativeAppBitmap --
 *
 *	Get a named native bitmap.
 *
 *	Attemps to interpret the given name in order as:
 *	    - name defined by ::tk::mac::iconBitmap
 *	    - NSImage named image name
 *	    - NSImage url string
 *	    - 4-char OSType of IconServices icon
 *
 * Results:
 *	Native bitmap or None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Pixmap
TkpGetNativeAppBitmap(
    Display *display,		/* The display. */
    const char *name,		/* The name of the bitmap. */
    int *width,			/* The width & height of the bitmap. */
    int *height)
{
    Tcl_HashEntry *hPtr;
    Pixmap pixmap = None;
    NSString *string;
    NSImage *image = nil;
    NSSize size = { .width = builtInIconSize, .height = builtInIconSize };

    if (iconBitmapTable.buckets &&
	    (hPtr = Tcl_FindHashEntry(&iconBitmapTable, name))) {
	OSType type;
	IconBitmap *iconBitmap = Tcl_GetHashValue(hPtr);
	name = NULL;
	size = NSMakeSize(iconBitmap->width, iconBitmap->height);
	switch (iconBitmap->kind) {
	case ICON_FILE:
	    string = [[NSString stringWithUTF8String:iconBitmap->value]
		    stringByExpandingTildeInPath];
	    image = [[NSWorkspace sharedWorkspace] iconForFile:string];
	    break;
	case ICON_FILETYPE:
	    string = [NSString stringWithUTF8String:iconBitmap->value];
	    image = [[NSWorkspace sharedWorkspace] iconForFileType:string];
	    break;
	case ICON_OSTYPE:
	    if (OSTypeFromString(iconBitmap->value, &type) == TCL_OK) {
		string = NSFileTypeForHFSTypeCode(type);
		image = [[NSWorkspace sharedWorkspace] iconForFileType:string];
	    }
	    break;
	case ICON_SYSTEMTYPE:
	    name = iconBitmap->value;
	    break;
	case ICON_NAMEDIMAGE:
	    string = [NSString stringWithUTF8String:iconBitmap->value];
	    image = [NSImage imageNamed:string];
	    break;
	case ICON_IMAGEFILE:
	    string = [[NSString stringWithUTF8String:iconBitmap->value]
		    stringByExpandingTildeInPath];
	    image = [[[NSImage alloc] initWithContentsOfFile:string]
		    autorelease];
	    break;
	}
	if (image) {
	    [image setSize:size];
	}
    } else {
	string = [NSString stringWithUTF8String:name];
	image = [NSImage imageNamed:string];
	if (!image) {
	    NSURL *url = [NSURL URLWithString:string];
	    if (url) {
		image = [[[NSImage alloc] initWithContentsOfURL:url]
			autorelease];
	    }
	}
	if (image) {
	    size = [image size];
	}
    }
    if (image) {
	TkMacOSXDrawingContext dc;
	int depth = 0;

#ifdef MAC_OSX_TK_TODO
	for (NSImageRep *r in [image representations]) {
	    NSInteger bitsPerSample = [r bitsPerSample];
	    if (bitsPerSample && bitsPerSample > depth) {
		depth = bitsPerSample;
	    };
	}
	if (depth == 1) {
	    /* TODO: convert BW NSImage to CGImageMask */
	}
#endif
	pixmap = Tk_GetPixmap(display, None, size.width, size.height, depth);
	*width = size.width;
	*height = size.height;
	if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
	    if (dc.context) {
		CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
			.tx = 0, .ty = size.height};

		CGContextConcatCTM(dc.context, t);
		[NSGraphicsContext saveGraphicsState];
		[NSGraphicsContext setCurrentContext:[NSGraphicsContext
			graphicsContextWithGraphicsPort:dc.context flipped:NO]];
		[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
			operation:NSCompositeCopy fraction:1.0];
		[NSGraphicsContext restoreGraphicsState];
	    }
	    TkMacOSXRestoreDrawingContext(&dc);
	}
    } else if (name) {
	OSType iconType;
	if (OSTypeFromString(name, &iconType) == TCL_OK) {
	    IconRef icon;
	    OSErr err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
		    iconType, &icon);
	    if (err == noErr) {
		pixmap = GetBitmapForIcon(display, icon, NSSizeToCGSize(size));
		*width = size.width;
		*height = size.height;
		ReleaseIconRef(icon);
	    }
	}
    }
    return pixmap;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXIconBitmapObjCmd --
 *
 *	Implements the ::tk::mac::iconBitmap command.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	none
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXIconBitmapObjCmd(
    ClientData clientData,	/* Unused. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tcl_HashEntry *hPtr;
    int i = 1, len, isNew, result = TCL_ERROR;
    const char *name, *value;
    IconBitmap ib, *iconBitmap;

    if (objc != 6) {
	Tcl_WrongNumArgs(interp, 1, objv, "name width height "
		"-file|-fileType|-osType|-systemType|-namedImage|-imageFile "
		"value");
	goto end;
    }
    name = Tcl_GetStringFromObj(objv[i++], &len);
    if (!len) {
	Tcl_AppendResult(interp, "empty bitmap name", NULL);
	goto end;
    }
    if (Tcl_GetIntFromObj(interp, objv[i++], &ib.width) != TCL_OK) {
	goto end;
    }
    if (Tcl_GetIntFromObj(interp, objv[i++], &ib.height) != TCL_OK) {
	goto end;
    }
    if (Tcl_GetIndexFromObj(interp, objv[i++], iconBitmapOptionStrings,
	    "kind", TCL_EXACT, &ib.kind) != TCL_OK) {
	goto end;
    }
    value = Tcl_GetStringFromObj(objv[i++], &len);
    if (!len) {
	Tcl_AppendResult(interp, "empty bitmap value", NULL);
	goto end;
    }
#if 0
    if ((kind == ICON_TYPE || kind == ICON_SYSTEM)) {
	Tcl_DString ds;
 	Tcl_Encoding encoding = Tcl_GetEncoding(NULL, "macRoman");
	Tcl_UtfToExternalDString(encoding, value, -1, &ds);
	len = Tcl_DStringLength(&ds);
	Tcl_DStringFree(&ds);
	Tcl_FreeEncoding(encoding);
	if (len > 4) {
	    Tcl_AppendResult(interp, "invalid bitmap value", NULL);
	    goto end;
	}
    }
#endif
    ib.value = ckalloc(len + 1);
    strcpy(ib.value, value);
    if (!iconBitmapTable.buckets) {
	Tcl_InitHashTable(&iconBitmapTable, TCL_STRING_KEYS);
    }
    hPtr = Tcl_CreateHashEntry(&iconBitmapTable, name, &isNew);
    if (!isNew) {
	iconBitmap = Tcl_GetHashValue(hPtr);
	ckfree(iconBitmap->value);
    } else {
	iconBitmap = (IconBitmap *) ckalloc(sizeof(IconBitmap));
	Tcl_SetHashValue(hPtr, iconBitmap);
    }
    *iconBitmap = ib;
    result = TCL_OK;
end:
    return result;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.11
log
@More marking of files as Objective-C.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.10 2009/06/29 14:35:01 das Exp $
d431 1
a431 1
    ib.value = ckalloc(len);
@


1.10
log
@Merge of TkAqua Cocoa port
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.9 2009/02/27 23:23:36 nijtmans Exp $
d452 1
a452 1
 * mode: c
@


1.9
log
@[Feature Request 2636558] Tk_DefineBitmap
and Tk_GetBitmapFromData signature problem
@
text
@d7 2
a8 2
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2006-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.8 2008/04/27 22:39:12 dkf Exp $
d16 1
a16 18
#include "tkMacOSXInt.h"

/*
 * Depending on the resource type there are different ways to
 * draw native icons.
 */
#define TYPE1	0		/* Family icon suite. */
#define TYPE2	1		/* ICON resource. */
#define TYPE3	2		/* cicn resource. */

/*
 * This data structure describes the id and type of a given icon.
 * It is used as the source for native icons.
 */
typedef struct {
    int id;			/* Resource Id for Icon. */
    long int type;		/* Type of icon. */
} NativeIcon;
d24 1
a24 3
    long int type;		/* Type of icon. */
    int id;			/* Id of icon. */
    int size;			/* Size of icon. */
d33 17
a49 17
    {"document",	TYPE1,	kGenericDocumentIconResource,		32},
    {"stationery",	TYPE1,	kGenericStationeryIconResource,		32},
    {"edition",		TYPE1,	kGenericEditionFileIconResource,	32},
    {"application",	TYPE1,	kGenericApplicationIconResource,	32},
    {"accessory",	TYPE1,	kGenericDeskAccessoryIconResource,	32},
    {"folder",		TYPE1,	kGenericFolderIconResource,		32},
    {"pfolder",		TYPE1,	kPrivateFolderIconResource,		32},
    {"trash",		TYPE1,	kTrashIconResource,			32},
    {"floppy",		TYPE1,	kFloppyIconResource,			32},
    {"ramdisk",		TYPE1,	kGenericRAMDiskIconResource,		32},
    {"cdrom",		TYPE1,	kGenericCDROMIconResource,		32},
    {"preferences",	TYPE1,	kGenericPreferencesIconResource,	32},
    {"querydoc",	TYPE1,	kGenericQueryDocumentIconResource,	32},
    {"stop",		TYPE2,	kStopIcon,				32},
    {"note",		TYPE2,	kNoteIcon,				32},
    {"caution",		TYPE2,	kCautionIcon,				32},
    {NULL,		0,	0,					0}
d51 18
d96 1
a96 1
	const char * name;
d104 3
a106 8
	    NativeIcon *nativeIconPtr = (NativeIcon *)
		    ckalloc(sizeof(NativeIcon));

	    nativeIconPtr->id = builtInPtr->id;
	    nativeIconPtr->type = builtInPtr->type;
	    predefPtr->source = nativeIconPtr;
	    predefPtr->width = builtInPtr->size;
	    predefPtr->height = builtInPtr->size;
d116 39
d157 1
a157 1
 *	Add native bitmaps.
d160 1
a160 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
d163 1
a163 2
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
d173 13
a185 27
    Pixmap pix;
    Rect destRect;
    CGrafPtr savePort;
    Boolean portChanged;
    const NativeIcon *nativeIconPtr;

    pix = Tk_GetPixmap(display, None, 32, 32, 0);
    portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort);

    nativeIconPtr = (const NativeIcon *) source;
    SetRect(&destRect, 0, 0, 32, 32);
    if (nativeIconPtr->type == TYPE1) {
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};

	RGBForeColor(&white);
	PaintRect(&destRect);
	PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
    } else if (nativeIconPtr->type == TYPE2) {
	Handle icon = GetIcon(nativeIconPtr->id);

	if (icon != NULL) {
	    RGBColor black = {0, 0, 0};

	    RGBForeColor(&black);
	    PlotIcon(&destRect, icon);
	    ReleaseResource(icon);
	}
d187 18
d206 13
a218 2
    if (portChanged) {
	QDSwapPort(savePort, NULL);
d220 3
a222 1
    return pix;
d230 7
a236 1
 *	Add native bitmaps.
d239 1
a239 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
d242 1
a242 2
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
d254 45
a298 22
    Pixmap pix;
    CGrafPtr savePort;
    Boolean portChanged;
    Rect destRect;
    Handle resource;
    int type = -1, destWrote;
    Str255 nativeName;
    Tcl_Encoding encoding;

    /*
     * macRoman is the encoding that the resource fork uses.
     */

    encoding = Tcl_GetEncoding(NULL, "macRoman");
    Tcl_UtfToExternal(NULL, encoding, name, strlen(name), 0, NULL,
	    (char *) &nativeName[1], 255, NULL, &destWrote, NULL);
    nativeName[0] = destWrote;
    Tcl_FreeEncoding(encoding);

    resource = GetNamedResource('cicn', nativeName);
    if (resource != NULL) {
	type = TYPE3;
d300 11
a310 3
	resource = GetNamedResource('ICON', nativeName);
	if (resource != NULL) {
	    type = TYPE2;
d313 65
d379 32
a410 2
    if (resource == NULL) {
	return (Pixmap) NULL;
d412 23
a434 30

    pix = Tk_GetPixmap(display, None, 32, 32, 0);
    portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort);

    SetRect(&destRect, 0, 0, 32, 32);
    if (type == TYPE2) {
	RGBColor black = {0, 0, 0};

	RGBForeColor(&black);
	PlotIcon(&destRect, resource);
	ReleaseResource(resource);
    } else if (type == TYPE3) {
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
	short id;
	ResType theType;
	Str255 dummy;

	/*
	 * We need to first paint the background white. Also, for some reason
	 * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to
	 * work - so we use GetResInfo to get the id.
	 */

	RGBForeColor(&white);
	PaintRect(&destRect);
	GetResInfo(resource, &id, &theType, dummy);
	ReleaseResource(resource);
	resource = (Handle) GetCIcon(id);
	PlotCIcon(&destRect, (CIconHandle) resource);
	DisposeCIcon((CIconHandle) resource);
d436 7
a442 5

    *width = 32;
    *height = 32;
    if (portChanged) {
	QDSwapPort(savePort, NULL);
d444 4
a447 1
    return pix;
d449 9
@


1.8
log
@Get rid of pre-C89-isms (esp. CONST vs const).
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.7 2007/04/23 21:24:32 das Exp $
d110 1
a110 1
	    predefPtr->source = (char *) nativeIconPtr;
d140 1
a140 1
    const char *source)		/* Info about the icon to build. */
@


1.7
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
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.6 2007/04/21 19:06:37 hobbs Exp $
d140 1
a140 1
    CONST char *source)		/* Info about the icon to build. */
d198 1
a198 1
    CONST char *name,		/* The name of the bitmap. */
d252 3
a254 3
	 * We need to first paint the background white. Also, for
	 * some reason we *must* use GetCIcon instead of GetNamedResource
	 * for PlotCIcon to work - so we use GetResInfo to get the id.
@


1.7.2.1
log
@merge updates from 8.5 branch
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.7 2007/04/23 21:24:32 das Exp $
d252 3
a254 3
	 * We need to first paint the background white. Also, for some reason
	 * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to
	 * work - so we use GetResInfo to get the id.
@


1.7.4.1
log
@sync with dkf's 2008-04-27 whitespace&formatting changes on HEAD, to ease branch maintenance.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.7 2007/04/23 21:24:32 das Exp $
d252 3
a254 3
	 * We need to first paint the background white. Also, for some reason
	 * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to
	 * work - so we use GetResInfo to get the id.
@


1.6
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 1
a4 1
 *        This file handles the implementation of native bitmaps.
d8 1
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.4 2006/03/24 14:58:01 das Exp $
d22 3
a24 3
#define TYPE1        0        /* Family icon suite. */
#define TYPE2        1        /* ICON resource. */
#define TYPE3        2        /* cicn resource. */
d31 2
a32 2
    int id;                /* Resource Id for Icon. */
    long int type;        /* Type of icon. */
d40 4
a43 4
    char *name;                        /* Name of icon. */
    long int type;                /* Type of icon. */
    int id;                        /* Id of icon. */
    int size;                        /* Size of icon. */
d52 17
a68 17
    {"document",        TYPE1,        kGenericDocumentIconResource,           32},
    {"stationery",      TYPE1,        kGenericStationeryIconResource,         32},
    {"edition",         TYPE1,        kGenericEditionFileIconResource,        32},
    {"application",     TYPE1,        kGenericApplicationIconResource,        32},
    {"accessory",       TYPE1,        kGenericDeskAccessoryIconResource,      32},
    {"folder",          TYPE1,        kGenericFolderIconResource,             32},
    {"pfolder",         TYPE1,        kPrivateFolderIconResource,             32},
    {"trash",           TYPE1,        kTrashIconResource,                     32},
    {"floppy",          TYPE1,        kFloppyIconResource,                    32},
    {"ramdisk",         TYPE1,        kGenericRAMDiskIconResource,            32},
    {"cdrom",           TYPE1,        kGenericCDROMIconResource,              32},
    {"preferences",     TYPE1,        kGenericPreferencesIconResource,        32},
    {"querydoc",        TYPE1,        kGenericQueryDocumentIconResource,      32},
    {"stop",            TYPE2,        kStopIcon,                              32},
    {"note",            TYPE2,        kNoteIcon,                              32},
    {"caution",         TYPE2,        kCautionIcon,                           32},
    {(char *) NULL,        0,        0,                                        0}
d76 1
a76 1
 *        Add native bitmaps.
d79 2
a80 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d83 2
a84 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d90 1
a90 1
TkpDefineNativeBitmaps()
d92 1
a92 4
    int new;
    Tcl_HashEntry *predefHashPtr;
    TkPredefBitmap *predefPtr;
    CONST char * name;
d94 1
a94 3
    NativeIcon *nativeIconPtr;
    Tcl_HashTable *tablePtr;
    
d96 20
a115 15
        name = Tk_GetUid(builtInPtr->name);
        tablePtr = TkGetBitmapPredefTable();
        predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &new);
        if (!new) {
            continue;
        }
        predefPtr = (TkPredefBitmap *) ckalloc(sizeof(TkPredefBitmap));
        nativeIconPtr = (NativeIcon *) ckalloc(sizeof(NativeIcon));
        nativeIconPtr->id = builtInPtr->id;
        nativeIconPtr->type = builtInPtr->type;
        predefPtr->source = (char *) nativeIconPtr;
        predefPtr->width = builtInPtr->size;
        predefPtr->height = builtInPtr->size;
        predefPtr->native = 1;
        Tcl_SetHashValue(predefHashPtr, predefPtr);
d124 1
a124 1
 *        Add native bitmaps.
d127 2
a128 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d131 2
a132 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d140 1
a140 1
    CONST char * source)                /* Info about the icon to build. */
a142 1
    GWorldPtr destPort;
d144 4
a147 5
    Handle icon;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    NativeIcon *nativeIconPtr;
    
d149 1
a149 4
    destPort = TkMacOSXGetDrawablePort(pix);

    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
d151 1
a151 1
    nativeIconPtr = (NativeIcon *) source;
d154 1
a154 1
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
d156 3
a158 3
        RGBForeColor(&white);
        PaintRect(&destRect);
        PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
d160 9
a168 8
        icon = GetIcon(nativeIconPtr->id);
        if (icon != NULL) {
            RGBColor black = {0, 0, 0};
        
            RGBForeColor(&black);
            PlotIcon(&destRect, icon);
            ReleaseResource(icon);
        }
d171 3
a173 1
    SetGWorld(saveWorld, saveDevice);
d182 1
a182 1
 *        Add native bitmaps.
d185 2
a186 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d189 2
a190 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d197 3
a199 3
    Display *display,        /* The display. */
    CONST char *name,        /* The name of the bitmap. */
    int *width,                /* The width & height of the bitmap. */
d203 2
a204 3
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
d209 2
a210 1
    
d215 3
a217 4
    Tcl_UtfToExternal(NULL, Tcl_GetEncoding(NULL, "macRoman"), name,
            strlen(name), 0, NULL, 
            (char *) &nativeName[1],
            255, NULL, &destWrote, NULL); /* Internalize native */
d219 1
d223 1
a223 1
        type = TYPE3;
d225 4
a228 4
        resource = GetNamedResource('ICON', nativeName);
        if (resource != NULL) {
            type = TYPE2;
        }
d230 1
a230 1
    
d232 1
a232 1
        return (Pixmap) NULL;
d234 1
a234 1
    
d236 1
a236 1
    destPort = TkMacOSXGetDrawablePort(pix);
a237 3
    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    
d240 5
a244 5
        RGBColor black = {0, 0, 0};
        
        RGBForeColor(&black);
        PlotIcon(&destRect, resource);
        ReleaseResource(resource);
d246 18
a263 17
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
        short id;
        ResType theType;
        Str255 dummy;
        
        /*
         * We need to first paint the background white.  Also, for
         * some reason we *must* use GetCIcon instead of GetNamedResource
         * for PlotCIcon to work - so we use GetResInfo to get the id.
         */
        RGBForeColor(&white);
        PaintRect(&destRect);
        GetResInfo(resource, &id, &theType, dummy);
        ReleaseResource(resource);
        resource = (Handle) GetCIcon(id);
        PlotCIcon(&destRect, (CIconHandle) resource);
        DisposeCIcon((CIconHandle) resource);
d265 1
a265 1
    
d268 3
a270 1
    SetGWorld(saveWorld, saveDevice);
@


1.5
log
@Reduce the #ifdef count a lot by adding debug-print macros
@
text
@d1 1
a1 1
/*
d4 1
a4 1
 *	This file handles the implementation of native bitmaps.
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d18 2
a19 2
 * Depending on the resource type there are different ways to draw native
 * icons.
d21 3
a23 4

#define TYPE1	0		/* Family icon suite. */
#define TYPE2	1		/* ICON resource. */
#define TYPE3	2		/* cicn resource. */
d26 2
a27 2
 * This data structure describes the id and type of a given icon. It is used
 * as the source for native icons.
a28 1

d30 2
a31 2
    int id;			/* Resource Id for Icon. */
    long int type;		/* Type of icon. */
d39 4
a42 4
    char *name;			/* Name of icon. */
    long int type;		/* Type of icon. */
    int id;			/* Id of icon. */
    int size;			/* Size of icon. */
d46 2
a47 2
 * This array mapps a string name to the supported builtin icons on the
 * Macintosh.
d51 17
a67 17
    {"document",	TYPE1,	kGenericDocumentIconResource,		32},
    {"stationery",	TYPE1,	kGenericStationeryIconResource,		32},
    {"edition",		TYPE1,	kGenericEditionFileIconResource,	32},
    {"application",	TYPE1,	kGenericApplicationIconResource,	32},
    {"accessory",	TYPE1,	kGenericDeskAccessoryIconResource,	32},
    {"folder",		TYPE1,	kGenericFolderIconResource,		32},
    {"pfolder",		TYPE1,	kPrivateFolderIconResource,		32},
    {"trash",		TYPE1,	kTrashIconResource,			32},
    {"floppy",		TYPE1,	kFloppyIconResource,			32},
    {"ramdisk",		TYPE1,	kGenericRAMDiskIconResource,		32},
    {"cdrom",		TYPE1,	kGenericCDROMIconResource,		32},
    {"preferences",	TYPE1,	kGenericPreferencesIconResource,	32},
    {"querydoc",	TYPE1,	kGenericQueryDocumentIconResource,	32},
    {"stop",		TYPE2,	kStopIcon,				32},
    {"note",		TYPE2,	kNoteIcon,				32},
    {"caution",		TYPE2,	kCautionIcon,				32},
    {(char *) NULL,	0,	0,					0}
d75 1
a75 1
 *	Add native bitmaps.
d78 2
a79 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is returned
 *	and a message is left in the interp's result.
d82 2
a83 2
 *	"Name" is entered into the bitmap table and may be used from here on
 *	to refer to the given bitmap.
d89 1
a89 1
TkpDefineNativeBitmaps(void)
d91 4
a94 1
    Tcl_HashTable *tablePtr = TkGetBitmapPredefTable();
d96 19
a114 22

    for (builtInPtr=builtInIcons ; builtInPtr->name!=NULL ; builtInPtr++) {
	Tcl_HashEntry *predefHashPtr;
	CONST char *name;
	int isNew;

	name = Tk_GetUid(builtInPtr->name);
	predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew);
	if (isNew) {
	    TkPredefBitmap *predefPtr = (TkPredefBitmap *)
		    ckalloc(sizeof(TkPredefBitmap));
	    NativeIcon *nativeIconPtr = (NativeIcon *)
		    ckalloc(sizeof(NativeIcon));

	    nativeIconPtr->id = builtInPtr->id;
	    nativeIconPtr->type = builtInPtr->type;
	    predefPtr->source = (char *) nativeIconPtr;
	    predefPtr->width = builtInPtr->size;
	    predefPtr->height = builtInPtr->size;
	    predefPtr->native = 1;
	    Tcl_SetHashValue(predefHashPtr, predefPtr);
	}
d123 1
a123 1
 *	Add native bitmaps.
d126 2
a127 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is returned
 *	and a message is left in the interp's result.
d130 2
a131 2
 *	"Name" is entered into the bitmap table and may be used from here on
 *	to refer to the given bitmap.
d139 1
a139 1
    CONST char *source)		/* Info about the icon to build. */
d144 1
d148 1
a148 1

d158 1
a158 1
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
d160 3
a162 3
	RGBForeColor(&white);
	PaintRect(&destRect);
	PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
d164 8
a171 9
	Handle icon = GetIcon(nativeIconPtr->id);

	if (icon != NULL) {
	    RGBColor black = {0, 0, 0};

	    RGBForeColor(&black);
	    PlotIcon(&destRect, icon);
	    ReleaseResource(icon);
	}
d183 1
a183 1
 *	Add native bitmaps.
d186 2
a187 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is returned
 *	and a message is left in the interp's result.
d190 2
a191 2
 *	"Name" is entered into the bitmap table and may be used from here on
 *	to refer to the given bitmap.
d198 3
a200 3
    Display *display,		/* The display. */
    CONST char *name,		/* The name of the bitmap. */
    int *width,			/* The width & height of the bitmap. */
d211 1
a211 1

d217 3
a219 2
	    strlen(name), 0, NULL, (char *) &nativeName[1], 255, NULL,
	    &destWrote, NULL); /* Internalize native */
d224 1
a224 1
	type = TYPE3;
d226 4
a229 4
	resource = GetNamedResource('ICON', nativeName);
	if (resource != NULL) {
	    type = TYPE2;
	}
d231 1
a231 1

d233 1
a233 1
	return (Pixmap) NULL;
d235 1
a235 1

d241 1
a241 1

d244 5
a248 5
	RGBColor black = {0, 0, 0};

	RGBForeColor(&black);
	PlotIcon(&destRect, resource);
	ReleaseResource(resource);
d250 17
a266 18
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
	short id;
	ResType theType;
	Str255 dummy;

	/*
	 * We need to first paint the background white. Also, for some reason
	 * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to
	 * work - so we use GetResInfo to get the id.
	 */

	RGBForeColor(&white);
	PaintRect(&destRect);
	GetResInfo(resource, &id, &theType, dummy);
	ReleaseResource(resource);
	resource = (Handle) GetCIcon(id);
	PlotCIcon(&destRect, (CIconHandle) resource);
	DisposeCIcon((CIconHandle) resource);
d268 1
a268 1

a273 8

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.4
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
@d1 1
a1 1
/* 
d4 1
a4 1
 *        This file handles the implementation of native bitmaps.
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.3 2005/05/14 20:48:14 das Exp $
d18 2
a19 2
 * Depending on the resource type there are different ways to
 * draw native icons.
d21 4
a24 3
#define TYPE1        0        /* Family icon suite. */
#define TYPE2        1        /* ICON resource. */
#define TYPE3        2        /* cicn resource. */
d27 2
a28 2
 * This data structure describes the id and type of a given icon.
 * It is used as the source for native icons.
d30 1
d32 2
a33 2
    int id;                /* Resource Id for Icon. */
    long int type;        /* Type of icon. */
d41 4
a44 4
    char *name;                        /* Name of icon. */
    long int type;                /* Type of icon. */
    int id;                        /* Id of icon. */
    int size;                        /* Size of icon. */
d48 2
a49 2
 * This array mapps a string name to the supported builtin icons
 * on the Macintosh.
d53 17
a69 17
    {"document",        TYPE1,        kGenericDocumentIconResource,           32},
    {"stationery",      TYPE1,        kGenericStationeryIconResource,         32},
    {"edition",         TYPE1,        kGenericEditionFileIconResource,        32},
    {"application",     TYPE1,        kGenericApplicationIconResource,        32},
    {"accessory",       TYPE1,        kGenericDeskAccessoryIconResource,      32},
    {"folder",          TYPE1,        kGenericFolderIconResource,             32},
    {"pfolder",         TYPE1,        kPrivateFolderIconResource,             32},
    {"trash",           TYPE1,        kTrashIconResource,                     32},
    {"floppy",          TYPE1,        kFloppyIconResource,                    32},
    {"ramdisk",         TYPE1,        kGenericRAMDiskIconResource,            32},
    {"cdrom",           TYPE1,        kGenericCDROMIconResource,              32},
    {"preferences",     TYPE1,        kGenericPreferencesIconResource,        32},
    {"querydoc",        TYPE1,        kGenericQueryDocumentIconResource,      32},
    {"stop",            TYPE2,        kStopIcon,                              32},
    {"note",            TYPE2,        kNoteIcon,                              32},
    {"caution",         TYPE2,        kCautionIcon,                           32},
    {(char *) NULL,        0,        0,                                        0}
d77 1
a77 1
 *        Add native bitmaps.
d80 2
a81 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d84 2
a85 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d91 1
a91 1
TkpDefineNativeBitmaps()
d93 1
a93 4
    int new;
    Tcl_HashEntry *predefHashPtr;
    TkPredefBitmap *predefPtr;
    CONST char * name;
d95 22
a116 19
    NativeIcon *nativeIconPtr;
    Tcl_HashTable *tablePtr;
    
    for (builtInPtr = builtInIcons; builtInPtr->name != NULL; builtInPtr++) {
        name = Tk_GetUid(builtInPtr->name);
        tablePtr = TkGetBitmapPredefTable();
        predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &new);
        if (!new) {
            continue;
        }
        predefPtr = (TkPredefBitmap *) ckalloc(sizeof(TkPredefBitmap));
        nativeIconPtr = (NativeIcon *) ckalloc(sizeof(NativeIcon));
        nativeIconPtr->id = builtInPtr->id;
        nativeIconPtr->type = builtInPtr->type;
        predefPtr->source = (char *) nativeIconPtr;
        predefPtr->width = builtInPtr->size;
        predefPtr->height = builtInPtr->size;
        predefPtr->native = 1;
        Tcl_SetHashValue(predefHashPtr, predefPtr);
d125 1
a125 1
 *        Add native bitmaps.
d128 2
a129 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d132 2
a133 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d141 1
a141 1
    CONST char * source)                /* Info about the icon to build. */
a145 1
    Handle icon;
d149 1
a149 1
    
d159 1
a159 1
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
d161 3
a163 3
        RGBForeColor(&white);
        PaintRect(&destRect);
        PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
d165 9
a173 8
        icon = GetIcon(nativeIconPtr->id);
        if (icon != NULL) {
            RGBColor black = {0, 0, 0};
        
            RGBForeColor(&black);
            PlotIcon(&destRect, icon);
            ReleaseResource(icon);
        }
d185 1
a185 1
 *        Add native bitmaps.
d188 2
a189 2
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
d192 2
a193 2
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
d200 3
a202 3
    Display *display,        /* The display. */
    CONST char *name,        /* The name of the bitmap. */
    int *width,                /* The width & height of the bitmap. */
d213 1
a213 1
    
d219 2
a220 3
            strlen(name), 0, NULL, 
            (char *) &nativeName[1],
            255, NULL, &destWrote, NULL); /* Internalize native */
d225 1
a225 1
        type = TYPE3;
d227 4
a230 4
        resource = GetNamedResource('ICON', nativeName);
        if (resource != NULL) {
            type = TYPE2;
        }
d232 1
a232 1
    
d234 1
a234 1
        return (Pixmap) NULL;
d236 1
a236 1
    
d242 1
a242 1
    
d245 5
a249 5
        RGBColor black = {0, 0, 0};
        
        RGBForeColor(&black);
        PlotIcon(&destRect, resource);
        ReleaseResource(resource);
d251 18
a268 17
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
        short id;
        ResType theType;
        Str255 dummy;
        
        /*
         * We need to first paint the background white.  Also, for
         * some reason we *must* use GetCIcon instead of GetNamedResource
         * for PlotCIcon to work - so we use GetResInfo to get the id.
         */
        RGBForeColor(&white);
        PaintRect(&destRect);
        GetResInfo(resource, &id, &theType, dummy);
        ReleaseResource(resource);
        resource = (Handle) GetCIcon(id);
        PlotCIcon(&destRect, (CIconHandle) resource);
        DisposeCIcon((CIconHandle) resource);
d270 1
a270 1
    
d276 8
@


1.3
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.2 2002/08/31 06:12:29 das Exp $
a14 2
#include "tkPort.h"
#include "tk.h"
a16 8
#include <Carbon/Carbon.h>
/*
#include <Icons.h>
#include <Dialogs.h>
#include <Resources.h>
#include <Strings.h>
*/

@


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
@d12 1
a12 1
 * RCS: @@(#) $Id$
d243 1
a243 1
        return NULL;
@


1.2.2.1
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.2 2002/08/31 06:12:29 das Exp $
d243 1
a243 1
        return (Pixmap) NULL;
@


1.2.2.2
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.2.2.1 2005/05/14 20:53:31 das Exp $
d15 2
d19 8
@


1.2.2.3
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 1
a4 1
 *	This file handles the implementation of native bitmaps.
a7 1
 * Copyright (c) 2006-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXBitmap.c,v 1.2.2.2 2006/03/28 02:44:12 das Exp $
d21 3
a23 3
#define TYPE1	0		/* Family icon suite. */
#define TYPE2	1		/* ICON resource. */
#define TYPE3	2		/* cicn resource. */
d30 2
a31 2
    int id;			/* Resource Id for Icon. */
    long int type;		/* Type of icon. */
d39 4
a42 4
    const char *name;		/* Name of icon. */
    long int type;		/* Type of icon. */
    int id;			/* Id of icon. */
    int size;			/* Size of icon. */
d51 17
a67 17
    {"document",	TYPE1,	kGenericDocumentIconResource,		32},
    {"stationery",	TYPE1,	kGenericStationeryIconResource,		32},
    {"edition",		TYPE1,	kGenericEditionFileIconResource,	32},
    {"application",	TYPE1,	kGenericApplicationIconResource,	32},
    {"accessory",	TYPE1,	kGenericDeskAccessoryIconResource,	32},
    {"folder",		TYPE1,	kGenericFolderIconResource,		32},
    {"pfolder",		TYPE1,	kPrivateFolderIconResource,		32},
    {"trash",		TYPE1,	kTrashIconResource,			32},
    {"floppy",		TYPE1,	kFloppyIconResource,			32},
    {"ramdisk",		TYPE1,	kGenericRAMDiskIconResource,		32},
    {"cdrom",		TYPE1,	kGenericCDROMIconResource,		32},
    {"preferences",	TYPE1,	kGenericPreferencesIconResource,	32},
    {"querydoc",	TYPE1,	kGenericQueryDocumentIconResource,	32},
    {"stop",		TYPE2,	kStopIcon,				32},
    {"note",		TYPE2,	kNoteIcon,				32},
    {"caution",		TYPE2,	kCautionIcon,				32},
    {NULL,		0,	0,					0}
d75 1
a75 1
 *	Add native bitmaps.
d78 2
a79 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
d82 2
a83 2
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
d89 1
a89 1
TkpDefineNativeBitmaps(void)
d91 4
a94 1
    Tcl_HashTable *tablePtr = TkGetBitmapPredefTable();
d96 3
a98 1

d100 15
a114 20
	Tcl_HashEntry *predefHashPtr;
	const char * name;
	int isNew;

	name = Tk_GetUid(builtInPtr->name);
	predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew);
	if (isNew) {
	    TkPredefBitmap *predefPtr = (TkPredefBitmap *)
		    ckalloc(sizeof(TkPredefBitmap));
	    NativeIcon *nativeIconPtr = (NativeIcon *)
		    ckalloc(sizeof(NativeIcon));

	    nativeIconPtr->id = builtInPtr->id;
	    nativeIconPtr->type = builtInPtr->type;
	    predefPtr->source = (char *) nativeIconPtr;
	    predefPtr->width = builtInPtr->size;
	    predefPtr->height = builtInPtr->size;
	    predefPtr->native = 1;
	    Tcl_SetHashValue(predefHashPtr, predefPtr);
	}
d123 1
a123 1
 *	Add native bitmaps.
d126 2
a127 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
d130 2
a131 2
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
d139 1
a139 1
    CONST char *source)		/* Info about the icon to build. */
d142 1
d144 7
a150 3
    CGrafPtr savePort;
    Boolean portChanged;
    const NativeIcon *nativeIconPtr;
d152 2
a153 2
    pix = Tk_GetPixmap(display, None, 32, 32, 0);
    portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort);
d155 1
a155 1
    nativeIconPtr = (const NativeIcon *) source;
d158 1
a158 1
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
d160 3
a162 3
	RGBForeColor(&white);
	PaintRect(&destRect);
	PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
d164 8
a171 9
	Handle icon = GetIcon(nativeIconPtr->id);

	if (icon != NULL) {
	    RGBColor black = {0, 0, 0};

	    RGBForeColor(&black);
	    PlotIcon(&destRect, icon);
	    ReleaseResource(icon);
	}
d174 1
a174 3
    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }
d183 1
a183 1
 *	Add native bitmaps.
d186 2
a187 2
 *	A standard Tcl result. If an error occurs then TCL_ERROR is
 *	returned and a message is left in the interp's result.
d190 2
a191 2
 *	"Name" is entered into the bitmap table and may be used from
 *	here on to refer to the given bitmap.
d198 3
a200 3
    Display *display,		/* The display. */
    CONST char *name,		/* The name of the bitmap. */
    int *width,			/* The width & height of the bitmap. */
d204 3
a206 2
    CGrafPtr savePort;
    Boolean portChanged;
d211 1
a211 2
    Tcl_Encoding encoding;

d216 4
a219 3
    encoding = Tcl_GetEncoding(NULL, "macRoman");
    Tcl_UtfToExternal(NULL, encoding, name, strlen(name), 0, NULL,
	    (char *) &nativeName[1], 255, NULL, &destWrote, NULL);
a220 1
    Tcl_FreeEncoding(encoding);
d224 1
a224 1
	type = TYPE3;
d226 4
a229 4
	resource = GetNamedResource('ICON', nativeName);
	if (resource != NULL) {
	    type = TYPE2;
	}
d231 1
a231 1

d233 1
a233 1
	return (Pixmap) NULL;
d235 1
a235 1

d237 1
a237 1
    portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort);
d239 3
d244 5
a248 5
	RGBColor black = {0, 0, 0};

	RGBForeColor(&black);
	PlotIcon(&destRect, resource);
	ReleaseResource(resource);
d250 17
a266 18
	RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
	short id;
	ResType theType;
	Str255 dummy;

	/*
	 * We need to first paint the background white. Also, for
	 * some reason we *must* use GetCIcon instead of GetNamedResource
	 * for PlotCIcon to work - so we use GetResInfo to get the id.
	 */

	RGBForeColor(&white);
	PaintRect(&destRect);
	GetResInfo(resource, &id, &theType, dummy);
	ReleaseResource(resource);
	resource = (Handle) GetCIcon(id);
	PlotCIcon(&destRect, (CIconHandle) resource);
	DisposeCIcon((CIconHandle) resource);
d268 1
a268 1

d271 1
a271 3
    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }
@


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


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 283
/* 
 * tkMacOSXBitmap.c --
 *
 *        This file handles the implementation of native bitmaps.
 *
 * Copyright (c) 1996-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 "tkPort.h"
#include "tk.h"
#include "tkMacOSXInt.h"

#include <Carbon/Carbon.h>
/*
#include <Icons.h>
#include <Dialogs.h>
#include <Resources.h>
#include <Strings.h>
*/

/*
 * Depending on the resource type there are different ways to
 * draw native icons.
 */
#define TYPE1        0        /* Family icon suite. */
#define TYPE2        1        /* ICON resource. */
#define TYPE3        2        /* cicn resource. */

/*
 * This data structure describes the id and type of a given icon.
 * It is used as the source for native icons.
 */
typedef struct {
    int id;                /* Resource Id for Icon. */
    long int type;        /* Type of icon. */
} NativeIcon;

/*
 * This structure holds information about native bitmaps.
 */

typedef struct {
    char *name;                        /* Name of icon. */
    long int type;                /* Type of icon. */
    int id;                        /* Id of icon. */
    int size;                        /* Size of icon. */
} BuiltInIcon;

/*
 * This array mapps a string name to the supported builtin icons
 * on the Macintosh.
 */

static BuiltInIcon builtInIcons[] = {
    {"document",        TYPE1,        kGenericDocumentIconResource,           32},
    {"stationery",      TYPE1,        kGenericStationeryIconResource,         32},
    {"edition",         TYPE1,        kGenericEditionFileIconResource,        32},
    {"application",     TYPE1,        kGenericApplicationIconResource,        32},
    {"accessory",       TYPE1,        kGenericDeskAccessoryIconResource,      32},
    {"folder",          TYPE1,        kGenericFolderIconResource,             32},
    {"pfolder",         TYPE1,        kPrivateFolderIconResource,             32},
    {"trash",           TYPE1,        kTrashIconResource,                     32},
    {"floppy",          TYPE1,        kFloppyIconResource,                    32},
    {"ramdisk",         TYPE1,        kGenericRAMDiskIconResource,            32},
    {"cdrom",           TYPE1,        kGenericCDROMIconResource,              32},
    {"preferences",     TYPE1,        kGenericPreferencesIconResource,        32},
    {"querydoc",        TYPE1,        kGenericQueryDocumentIconResource,      32},
    {"stop",            TYPE2,        kStopIcon,                              32},
    {"note",            TYPE2,        kNoteIcon,                              32},
    {"caution",         TYPE2,        kCautionIcon,                           32},
    {(char *) NULL,        0,        0,                                        0}
};

/*
 *----------------------------------------------------------------------
 *
 * TkpDefineNativeBitmaps --
 *
 *        Add native bitmaps.
 *
 * Results:
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
 *
 * Side effects:
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
 *
 *----------------------------------------------------------------------
 */

void
TkpDefineNativeBitmaps()
{
    int new;
    Tcl_HashEntry *predefHashPtr;
    TkPredefBitmap *predefPtr;
    char * name;
    BuiltInIcon *builtInPtr;
    NativeIcon *nativeIconPtr;
    Tcl_HashTable *tablePtr;
    
    for (builtInPtr = builtInIcons; builtInPtr->name != NULL; builtInPtr++) {
        name = Tk_GetUid(builtInPtr->name);
        tablePtr = TkGetBitmapPredefTable();
        predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &new);
        if (!new) {
            continue;
        }
        predefPtr = (TkPredefBitmap *) ckalloc(sizeof(TkPredefBitmap));
        nativeIconPtr = (NativeIcon *) ckalloc(sizeof(NativeIcon));
        nativeIconPtr->id = builtInPtr->id;
        nativeIconPtr->type = builtInPtr->type;
        predefPtr->source = (char *) nativeIconPtr;
        predefPtr->width = builtInPtr->size;
        predefPtr->height = builtInPtr->size;
        predefPtr->native = 1;
        Tcl_SetHashValue(predefHashPtr, predefPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateNativeBitmap --
 *
 *        Add native bitmaps.
 *
 * Results:
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
 *
 * Side effects:
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
 *
 *----------------------------------------------------------------------
 */

Pixmap
TkpCreateNativeBitmap(
    Display *display,
    char * source)                /* Info about the icon to build. */
{
    Pixmap pix;
    GWorldPtr destPort;
    Rect destRect;
    Handle icon;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    NativeIcon *nativeIconPtr;
    
    pix = Tk_GetPixmap(display, None, 32, 32, 0);
    destPort = TkMacOSXGetDrawablePort(pix);

    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);

    nativeIconPtr = (NativeIcon *) source;
    SetRect(&destRect, 0, 0, 32, 32);
    if (nativeIconPtr->type == TYPE1) {
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};

        RGBForeColor(&white);
        PaintRect(&destRect);
        PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
    } else if (nativeIconPtr->type == TYPE2) {
        icon = GetIcon(nativeIconPtr->id);
        if (icon != NULL) {
            RGBColor black = {0, 0, 0};
        
            RGBForeColor(&black);
            PlotIcon(&destRect, icon);
            ReleaseResource(icon);
        }
    }

    SetGWorld(saveWorld, saveDevice);
    return pix;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetNativeAppBitmap --
 *
 *        Add native bitmaps.
 *
 * Results:
 *        A standard Tcl result.  If an error occurs then TCL_ERROR is
 *        returned and a message is left in the interp's result.
 *
 * Side effects:
 *        "Name" is entered into the bitmap table and may be used from
 *        here on to refer to the given bitmap.
 *
 *----------------------------------------------------------------------
 */

Pixmap
TkpGetNativeAppBitmap(
    Display *display,        /* The display. */
    CONST char *name,        /* The name of the bitmap. */
    int *width,                /* The width & height of the bitmap. */
    int *height)
{
    Pixmap pix;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    Rect destRect;
    Handle resource;
    int type, destWrote;
    Str255 nativeName;
    
    /*
     * macRoman is the encoding that the resource fork uses.
     */

    Tcl_UtfToExternal(NULL, Tcl_GetEncoding(NULL, "macRoman"), name,
            strlen(name), 0, NULL, 
            (char *) &nativeName[1],
            255, NULL, &destWrote, NULL); /* Internalize native */
    nativeName[0] = destWrote;

    resource = GetNamedResource('cicn', nativeName);
    if (resource != NULL) {
        type = TYPE3;
    } else {
        resource = GetNamedResource('ICON', nativeName);
        if (resource != NULL) {
            type = TYPE2;
        }
    }
    
    if (resource == NULL) {
        return NULL;
    }
    
    pix = Tk_GetPixmap(display, None, 32, 32, 0);
    destPort = TkMacOSXGetDrawablePort(pix);

    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    
    SetRect(&destRect, 0, 0, 32, 32);
    if (type == TYPE2) {
        RGBColor black = {0, 0, 0};
        
        RGBForeColor(&black);
        PlotIcon(&destRect, resource);
        ReleaseResource(resource);
    } else if (type == TYPE3) {
        RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
        short id;
        ResType theType;
        Str255 dummy;
        
        /*
         * We need to first paint the background white.  Also, for
         * some reason we *must* use GetCIcon instead of GetNamedResource
         * for PlotCIcon to work - so we use GetResInfo to get the id.
         */
        RGBForeColor(&white);
        PaintRect(&destRect);
        GetResInfo(resource, &id, &theType, dummy);
        ReleaseResource(resource);
        resource = (Handle) GetCIcon(id);
        PlotCIcon(&destRect, (CIconHandle) resource);
        DisposeCIcon((CIconHandle) resource);
    }
    
    *width = 32;
    *height = 32;
    SetGWorld(saveWorld, saveDevice);
    return pix;
}
@


1.1.2.2
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
@d104 1
a104 1
    CONST char * name;
d149 1
a149 1
    CONST char * source)                /* Info about the icon to build. */
d219 1
a219 1
    int type = -1, destWrote;
@


