summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--macosx/tkMacOSXBitmap.c270
-rw-r--r--macosx/tkMacOSXButton.c1969
-rw-r--r--macosx/tkMacOSXCarbonEvents.c399
-rw-r--r--macosx/tkMacOSXClipboard.c343
-rw-r--r--macosx/tkMacOSXCursor.c8
-rw-r--r--macosx/tkMacOSXDialog.c1013
-rw-r--r--macosx/tkMacOSXDraw.c800
-rw-r--r--macosx/tkMacOSXEvent.c235
-rw-r--r--macosx/tkMacOSXFont.c2364
-rw-r--r--macosx/tkMacOSXInit.c44
-rw-r--r--macosx/tkMacOSXInt.h180
-rw-r--r--macosx/tkMacOSXKeyEvent.c1418
-rw-r--r--macosx/tkMacOSXMenu.c3954
-rw-r--r--macosx/tkMacOSXMenubutton.c977
-rw-r--r--macosx/tkMacOSXMouseEvent.c22
-rw-r--r--macosx/tkMacOSXScale.c308
-rw-r--r--macosx/tkMacOSXWindowEvent.c62
-rw-r--r--macosx/tkMacOSXWm.c1408
19 files changed, 8137 insertions, 7650 deletions
diff --git a/ChangeLog b/ChangeLog
index b9dcbef..eadbd9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-04-21 Jeff Hobbs <jeffh@ActiveState.com>
+
+ * 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.
+
2007-04-17 Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
* generic/tkFont.c, generic/tkListbox.c, unix/tkUnixSelect.c:
diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c
index 9735d98..dc05bc8 100644
--- a/macosx/tkMacOSXBitmap.c
+++ b/macosx/tkMacOSXBitmap.c
@@ -1,36 +1,34 @@
-/*
+/*
* tkMacOSXBitmap.c --
*
- * This file handles the implementation of native bitmaps.
+ * 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.
+ * 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.5 2007/04/13 14:51:17 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXBitmap.c,v 1.6 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
/*
- * Depending on the resource type there are different ways to draw native
- * icons.
+ * 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. */
+#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.
+ * 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. */
+ int id; /* Resource Id for Icon. */
+ long int type; /* Type of icon. */
} NativeIcon;
/*
@@ -38,35 +36,35 @@ typedef struct {
*/
typedef struct {
- char *name; /* Name of icon. */
- long int type; /* Type of icon. */
- int id; /* Id of icon. */
- int size; /* Size of icon. */
+ 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.
+ * 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}
+ {"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}
};
/*
@@ -74,46 +72,46 @@ static BuiltInIcon builtInIcons[] = {
*
* TkpDefineNativeBitmaps --
*
- * Add native bitmaps.
+ * 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.
+ * 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.
+ * "Name" is entered into the bitmap table and may be used from
+ * here on to refer to the given bitmap.
*
*----------------------------------------------------------------------
*/
void
-TkpDefineNativeBitmaps(void)
+TkpDefineNativeBitmaps()
{
- Tcl_HashTable *tablePtr = TkGetBitmapPredefTable();
+ int new;
+ Tcl_HashEntry *predefHashPtr;
+ TkPredefBitmap *predefPtr;
+ CONST char * name;
BuiltInIcon *builtInPtr;
-
- 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);
- }
+ 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);
}
}
@@ -122,15 +120,15 @@ TkpDefineNativeBitmaps(void)
*
* TkpCreateNativeBitmap --
*
- * Add native bitmaps.
+ * 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.
+ * 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.
+ * "Name" is entered into the bitmap table and may be used from
+ * here on to refer to the given bitmap.
*
*----------------------------------------------------------------------
*/
@@ -138,15 +136,16 @@ TkpDefineNativeBitmaps(void)
Pixmap
TkpCreateNativeBitmap(
Display *display,
- CONST char *source) /* Info about the icon to build. */
+ CONST 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);
@@ -156,21 +155,20 @@ TkpCreateNativeBitmap(
nativeIconPtr = (NativeIcon *) source;
SetRect(&destRect, 0, 0, 32, 32);
if (nativeIconPtr->type == TYPE1) {
- RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
+ RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
- RGBForeColor(&white);
- PaintRect(&destRect);
- PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id);
+ 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);
- }
+ icon = GetIcon(nativeIconPtr->id);
+ if (icon != NULL) {
+ RGBColor black = {0, 0, 0};
+
+ RGBForeColor(&black);
+ PlotIcon(&destRect, icon);
+ ReleaseResource(icon);
+ }
}
SetGWorld(saveWorld, saveDevice);
@@ -182,24 +180,24 @@ TkpCreateNativeBitmap(
*
* TkpGetNativeAppBitmap --
*
- * Add native bitmaps.
+ * 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.
+ * 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.
+ * "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. */
+ Display *display, /* The display. */
+ CONST char *name, /* The name of the bitmap. */
+ int *width, /* The width & height of the bitmap. */
int *height)
{
Pixmap pix;
@@ -210,74 +208,66 @@ TkpGetNativeAppBitmap(
Handle resource;
int type = -1, 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 */
+ 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;
+ type = TYPE3;
} else {
- resource = GetNamedResource('ICON', nativeName);
- if (resource != NULL) {
- type = TYPE2;
- }
+ resource = GetNamedResource('ICON', nativeName);
+ if (resource != NULL) {
+ type = TYPE2;
+ }
}
-
+
if (resource == NULL) {
- return (Pixmap) NULL;
+ return (Pixmap) 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);
+ 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);
+ 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;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index 1fc95aa..84addc5 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -1,16 +1,16 @@
-/*
+/*
* tkMacOSXButton.c --
*
- * This file implements the Macintosh specific portion of the button
- * widgets.
+ * This file implements the Macintosh specific portion of the
+ * button widgets.
*
* Copyright (c) 1996-1997 by 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.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXButton.c,v 1.21 2007/04/13 14:51:17 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXButton.c,v 1.22 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -23,7 +23,6 @@
/*
* Default insets for controls
*/
-
#define DEF_INSET_LEFT 2
#define DEF_INSET_RIGHT 2
#define DEF_INSET_TOP 2
@@ -38,7 +37,7 @@
#define DRAW_CUSTOM 2 /* Make our own button drawing. */
#define DRAW_BEVEL 3
-/*
+/*
* Declaration of Mac specific button structure.
*/
@@ -47,77 +46,75 @@ typedef struct {
SInt16 minValue;
SInt16 maxValue;
SInt16 procID;
- int isBevel;
+ int isBevel;
} MacControlParams;
typedef struct {
int drawType;
Tk_3DBorder border;
int relief;
- int offset; /* 0 means this is a normal widget. 1 means it
- * is an image button, so we offset the image
- * to make the button appear to move up and
- * down as the relief changes. */
- GC gc;
+ int offset; /* 0 means this is a normal widget. 1 means
+ * it is an image button, so we offset the
+ * image to make the button appear to move
+ * up and down as the relief changes. */
+ GC gc;
int hasImageOrBitmap;
} DrawParams;
+
typedef struct {
- TkButton info; /* Generic button info */
- int id;
- int usingControl;
- int useTkText;
- int flags; /* Initialisation status */
- MacControlParams params;
- WindowRef windowRef;
- RGBColor userPaneBackground;
- ControlRef userPane; /* Carbon control */
- ControlRef control; /* Carbon control */
- Str255 controlTitle;
- ControlFontStyleRec fontStyle;
- /*
- * The following are used to store the image content for beveled buttons -
- * i.e. buttons with images.
+ TkButton info; /* generic button info */
+ int id;
+ int usingControl;
+ int useTkText;
+ int flags; /* initialisation status */
+ MacControlParams params;
+ WindowRef windowRef;
+ RGBColor userPaneBackground;
+ ControlRef userPane; /* Carbon control */
+ ControlRef control; /* Carbon control */
+ Str255 controlTitle;
+ ControlFontStyleRec fontStyle;
+ /*
+ * the following are used to store the image content for
+ * beveled buttons - i.e. buttons with images.
*/
- CCTabHandle tabHandle;
+ CCTabHandle tabHandle;
ControlButtonContentInfo bevelButtonContent;
- OpenCPicParams picParams;
- Pixmap picPixmap;
+ OpenCPicParams picParams;
+ Pixmap picPixmap;
} MacButton;
/*
* Forward declarations for procedures defined later in this file:
*/
-static OSErr SetUserPaneDrawProc(ControlRef control,
- ControlUserPaneDrawProcPtr upp);
-static OSErr SetUserPaneSetUpSpecialBackgroundProc(
- ControlRef control,
- ControlUserPaneBackgroundProcPtr upp);
-static void UserPaneDraw(ControlRef control, ControlPartCode cpc);
-static void UserPaneBackgroundProc(ControlHandle,
- ControlBackgroundPtr info);
-
-static void ButtonEventProc(ClientData clientData,
- XEvent *eventPtr);
-static int UpdateControlColors(MacButton *mbPtr);
-static void TkMacOSXComputeControlParams(TkButton *butPtr,
- MacControlParams *paramsPtr);
-static int TkMacOSXComputeDrawParams(TkButton *butPtr,
- DrawParams *dpPtr);
-static void TkMacOSXDrawControl(MacButton *butPtr,
- GWorldPtr destPort, GC gc, Pixmap pixmap);
-static void SetupBevelButton(MacButton *butPtr,
- ControlRef controlHandle, GWorldPtr destPort,
- GC gc, Pixmap pixmap);
+
+static OSErr SetUserPaneDrawProc(ControlRef control,
+ ControlUserPaneDrawProcPtr upp);
+static OSErr SetUserPaneSetUpSpecialBackgroundProc(ControlRef control,
+ ControlUserPaneBackgroundProcPtr upp);
+static void UserPaneDraw(ControlRef control, ControlPartCode cpc);
+static void UserPaneBackgroundProc(ControlHandle,
+ ControlBackgroundPtr info);
+
+static void ButtonEventProc _ANSI_ARGS_(( ClientData clientData, XEvent *eventPtr));
+static int UpdateControlColors _ANSI_ARGS_((MacButton *mbPtr ));
+static void TkMacOSXComputeControlParams _ANSI_ARGS_((TkButton * butPtr, MacControlParams * paramsPtr));
+static int TkMacOSXComputeDrawParams _ANSI_ARGS_((TkButton * butPtr, DrawParams * dpPtr));
+static void TkMacOSXDrawControl _ANSI_ARGS_((MacButton *butPtr,
+ GWorldPtr destPort, GC gc, Pixmap pixmap));
+static void SetupBevelButton _ANSI_ARGS_((MacButton *butPtr,
+ ControlRef controlHandle,
+ GWorldPtr destPort, GC gc, Pixmap pixmap));
/*
* The class procedure table for the button widgets.
*/
-Tk_ClassProcs tkpButtonProcs = {
- sizeof(Tk_ClassProcs), /* size */
- TkButtonWorldChanged, /* worldChangedProc */
+Tk_ClassProcs tkpButtonProcs = {
+ sizeof(Tk_ClassProcs), /* size */
+ TkButtonWorldChanged, /* worldChangedProc */
};
static int bCount;
@@ -129,13 +126,13 @@ int tkPictureIsOpen;
*
* TkpCreateButton --
*
- * Allocate a new TkButton structure.
+ * Allocate a new TkButton structure.
*
* Results:
- * Returns a newly allocated TkButton structure.
+ * Returns a newly allocated TkButton structure.
*
* Side effects:
- * Registers an event handler for the widget.
+ * Registers an event handler for the widget.
*
*----------------------------------------------------------------------
*/
@@ -144,10 +141,10 @@ TkButton *
TkpCreateButton(
Tk_Window tkwin)
{
- MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
-
+ MacButton *macButtonPtr;
+ macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
Tk_CreateEventHandler(tkwin, ActivateMask,
- ButtonEventProc, (ClientData) macButtonPtr);
+ ButtonEventProc, (ClientData) macButtonPtr);
macButtonPtr->id = bCount++;
macButtonPtr->usingControl = 0;
macButtonPtr->flags = 0;
@@ -168,7 +165,6 @@ TkpCreateButton(
macButtonPtr->bevelButtonContent.contentType = kControlContentPictHandle;
bzero(&macButtonPtr->params, sizeof(macButtonPtr->params));
bzero(&macButtonPtr->fontStyle,sizeof(macButtonPtr->fontStyle));
-
return (TkButton *)macButtonPtr;
}
@@ -177,298 +173,309 @@ TkpCreateButton(
*
* TkpDisplayButton --
*
- * This procedure is invoked to display a button widget. It is normally
- * invoked as an idle handler.
+ * This procedure is invoked to display a button widget. It is
+ * normally invoked as an idle handler.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Commands are output to X to display the button in its current mode.
- * The REDRAW_PENDING flag is cleared.
+ * Commands are output to X to display the button in its
+ * current mode. The REDRAW_PENDING flag is cleared.
*
*----------------------------------------------------------------------
*/
void
TkpDisplayButton(
- ClientData clientData) /* Information about widget. */
+ ClientData clientData) /* Information about widget. */
{
MacButton *macButtonPtr = (MacButton *)clientData;
- TkButton *butPtr = (TkButton *) clientData;
- Tk_Window tkwin = butPtr->tkwin;
+ TkButton *butPtr = (TkButton *) clientData;
+ Tk_Window tkwin = butPtr->tkwin;
+ int width, height, fullWidth, fullHeight;
+ int textXOffset, textYOffset;
+ int haveImage = 0, haveText = 0;
GWorldPtr destPort;
+ int borderWidth;
Pixmap pixmap;
- int width, height, fullWidth, fullHeight, textXOffset, textYOffset;
- int borderWidth, wasUsingControl;
- int haveImage = 0, haveText = 0, imageWidth = 0, imageHeight = 0;
- int imageXOffset = 0, imageYOffset = 0;
- /* Image information that will be used to
- * restrict disabled pixmap as well. */
- DrawParams drawParams, *dpPtr = &drawParams;
+ int wasUsingControl;
+ int imageWidth = 0, imageHeight = 0;
+ int imageXOffset = 0, imageYOffset = 0; /* image information that will
+ * be used to restrict disabled
+ * pixmap as well */
+ DrawParams drawParams, * dpPtr = &drawParams;
butPtr->flags &= ~REDRAW_PENDING;
if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
- return;
+ return;
}
pixmap = (Pixmap) Tk_WindowId(tkwin);
wasUsingControl = macButtonPtr->usingControl;
if (TkMacOSXComputeDrawParams(butPtr, &drawParams) ) {
- macButtonPtr->usingControl = 1;
- if (butPtr->type == TYPE_BUTTON) {
- macButtonPtr->useTkText = 0;
- } else {
- macButtonPtr->useTkText = 1;
- }
+ macButtonPtr->usingControl = 1;
+ if (butPtr->type == TYPE_BUTTON) {
+ macButtonPtr->useTkText = 0;
+ } else {
+ macButtonPtr->useTkText = 1;
+ }
} else {
- macButtonPtr->usingControl = 0;
- macButtonPtr->useTkText = 1;
+ macButtonPtr->usingControl = 0;
+ macButtonPtr->useTkText = 1;
}
-
- /*
- * Set up clipping region. Make sure the we are using the port for this
- * button, or we will set the wrong window's clip.
+
+ /*
+ * set up clipping region. Make sure the we are using the port
+ * for this button, or we will set the wrong window's clip.
*/
-
+
destPort = TkMacOSXGetDrawablePort(pixmap);
SetGWorld(destPort, NULL);
TkMacOSXSetUpClippingRgn(pixmap);
+
/*
- * See the comment in UpdateControlColors as to why we use the
+ * See the comment in UpdateControlColors as to why we use the
* highlightbackground for the border of Macintosh buttons.
*/
if (macButtonPtr->useTkText) {
- if (butPtr->type == TYPE_BUTTON) {
- Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
- Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
- } else {
- Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
- Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
- }
+ if (butPtr->type == TYPE_BUTTON) {
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
+ } else {
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
+ }
}
/*
* Draw the native portion of the buttons. Start by creating the control
- * if it doesn't already exist. Then configure the Macintosh control from
- * the Tk info. Finally, we call Draw1Control to draw to the screen.
+ * if it doesn't already exist. Then configure the Macintosh control from
+ * the Tk info. Finally, we call Draw1Control to draw to the screen.
*/
if (macButtonPtr->usingControl) {
- borderWidth = 0;
- TkMacOSXDrawControl(macButtonPtr, destPort, dpPtr->gc, pixmap);
- } else if (wasUsingControl && macButtonPtr->userPane) {
- DisposeControl(macButtonPtr->userPane);
- macButtonPtr->userPane = NULL;
- macButtonPtr->control = NULL;
- macButtonPtr->flags = 0;
+ borderWidth = 0;
+ TkMacOSXDrawControl(macButtonPtr, destPort, dpPtr->gc, pixmap);
+ } else {
+ if (wasUsingControl && macButtonPtr->userPane) {
+ DisposeControl(macButtonPtr->userPane);
+ macButtonPtr->userPane = NULL;
+ macButtonPtr->control = NULL;
+ macButtonPtr->flags = 0;
+ }
}
if ((dpPtr->drawType == DRAW_CUSTOM) || (dpPtr->drawType == DRAW_LABEL)) {
- borderWidth = butPtr->borderWidth;
+ borderWidth = butPtr->borderWidth;
}
/*
- * Display image or bitmap or text for button. This has already been done
- * under Appearance with the Bevel button types.
+ * Display image or bitmap or text for button. This has
+ * already been done under Appearance with the Bevel
+ * button types.
*/
if (dpPtr->drawType == DRAW_BEVEL) {
- goto applyStipple;
- }
-
- if (butPtr->image != None) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- haveImage = 1;
- } else if (butPtr->bitmap != None) {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- haveImage = 1;
- }
- imageWidth = width;
- imageHeight = height;
-
- haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
- if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
- int x, y;
-
- textXOffset = 0;
- textYOffset = 0;
- fullWidth = 0;
- fullHeight = 0;
-
- switch ((enum compound) butPtr->compound) {
- case COMPOUND_TOP:
- case COMPOUND_BOTTOM:
- /*
- * Image is above or below text.
- */
-
- if (butPtr->compound == COMPOUND_TOP) {
- textYOffset = height + butPtr->padY;
- } else {
- imageYOffset = butPtr->textHeight + butPtr->padY;
- }
- fullHeight = height + butPtr->textHeight + butPtr->padY;
- fullWidth = (width>butPtr->textWidth ? width : butPtr->textWidth);
- textXOffset = (fullWidth - butPtr->textWidth)/2;
- imageXOffset = (fullWidth - width)/2;
- break;
-
- case COMPOUND_LEFT:
- case COMPOUND_RIGHT:
- /*
- * Image is left or right of text.
- */
-
- if (butPtr->compound == COMPOUND_LEFT) {
- textXOffset = width + butPtr->padX;
- } else {
- imageXOffset = butPtr->textWidth + butPtr->padX;
- }
- fullWidth = butPtr->textWidth + butPtr->padX + width;
- fullHeight = (height > butPtr->textHeight ? height :
- butPtr->textHeight);
- textYOffset = (fullHeight - butPtr->textHeight)/2;
- imageYOffset = (fullHeight - height)/2;
- break;
-
- case COMPOUND_CENTER:
- /*
- * Image and text are superimposed.
- */
-
- fullWidth = (width>butPtr->textWidth ? width : butPtr->textWidth);
- fullHeight = (height > butPtr->textHeight ? height :
- butPtr->textHeight);
- textXOffset = (fullWidth - butPtr->textWidth)/2;
- imageXOffset = (fullWidth - width)/2;
- textYOffset = (fullHeight - butPtr->textHeight)/2;
- imageYOffset = (fullHeight - height)/2;
- break;
-
- case COMPOUND_NONE:
- break;
- }
-
- TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
- butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y);
-
- x += butPtr->indicatorSpace;
-
- x += dpPtr->offset;
- y += dpPtr->offset;
- if (dpPtr->relief == TK_RELIEF_RAISED) {
- x -= dpPtr->offset;
- y -= dpPtr->offset;
- } else if (dpPtr->relief == TK_RELIEF_SUNKEN) {
- x += dpPtr->offset;
- y += dpPtr->offset;
- }
- imageXOffset += x;
- imageYOffset += y;
- if (butPtr->image != NULL) {
- if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
- Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
- pixmap, imageXOffset, imageYOffset);
- } else if ((butPtr->tristateImage != NULL) &&
- (butPtr->flags & TRISTATED)) {
- Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height,
- pixmap, imageXOffset, imageYOffset);
- } else {
- Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap,
- imageXOffset, imageYOffset);
- }
- } else {
- XSetClipOrigin(butPtr->display, dpPtr->gc, imageXOffset,
- imageYOffset);
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
- 0, 0, (unsigned int) width, (unsigned int) height,
- imageXOffset, imageYOffset, 1);
- XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
- }
-
- if (macButtonPtr->useTkText) {
- Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
- butPtr->textLayout, x + textXOffset, y + textYOffset,
- 0, -1);
- Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
- butPtr->textLayout, x + textXOffset, y + textYOffset,
- butPtr->underline);
- }
- y += fullHeight/2;
- } else if (haveImage) {
- int x = 0, y;
-
- TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
- butPtr->indicatorSpace + width, height, &x, &y);
- x += butPtr->indicatorSpace;
-
- x += dpPtr->offset;
- y += dpPtr->offset;
- if (dpPtr->relief == TK_RELIEF_RAISED) {
- x -= dpPtr->offset;
- y -= dpPtr->offset;
- } else if (dpPtr->relief == TK_RELIEF_SUNKEN) {
- x += dpPtr->offset;
- y += dpPtr->offset;
- }
- imageXOffset += x;
- imageYOffset += y;
- if (butPtr->image != NULL) {
- if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
- Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
- pixmap, imageXOffset, imageYOffset);
- } else if ((butPtr->tristateImage != NULL) &&
- (butPtr->flags & TRISTATED)) {
- Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height,
- pixmap, imageXOffset, imageYOffset);
- } else {
- Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap,
+ /* Empty Body */
+ } else {
+ if (butPtr->image != None) {
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
+ } else if (butPtr->bitmap != None) {
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
+ }
+ imageWidth = width;
+ imageHeight = height;
+
+ haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
+ if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
+ int x;
+ int y;
+ textXOffset = 0;
+ textYOffset = 0;
+ fullWidth = 0;
+ fullHeight = 0;
+
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM: {
+ /* Image is above or below text */
+ if (butPtr->compound == COMPOUND_TOP) {
+ textYOffset = height + butPtr->padY;
+ } else {
+ imageYOffset = butPtr->textHeight + butPtr->padY;
+ }
+ fullHeight = height + butPtr->textHeight + butPtr->padY;
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ break;
+ }
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT: {
+ /*
+ * Image is left or right of text
+ */
+
+ if (butPtr->compound == COMPOUND_LEFT) {
+ textXOffset = width + butPtr->padX;
+ } else {
+ imageXOffset = butPtr->textWidth + butPtr->padX;
+ }
+ fullWidth = butPtr->textWidth + butPtr->padX + width;
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_CENTER: {
+ /*
+ * Image and text are superimposed
+ */
+
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_NONE: {break;}
+ }
+
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
+ butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y);
+
+ x += butPtr->indicatorSpace;
+
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ if (dpPtr->relief == TK_RELIEF_RAISED) {
+ x -= dpPtr->offset;
+ y -= dpPtr->offset;
+ } else if (dpPtr->relief == TK_RELIEF_SUNKEN) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ }
+ imageXOffset += x;
+ imageYOffset += y;
+ if (butPtr->image != NULL) {
+ if ((butPtr->selectImage != NULL) &&
+ (butPtr->flags & SELECTED)) {
+ Tk_RedrawImage(butPtr->selectImage, 0, 0,
+ width, height, pixmap, imageXOffset, imageYOffset);
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0,
+ width, height, pixmap, imageXOffset, imageYOffset);
+ } else {
+ Tk_RedrawImage(butPtr->image, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ }
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc,
imageXOffset, imageYOffset);
- }
- } else {
- XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
- 0, 0, (unsigned) width, (unsigned) height, x, y, 1);
- XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
- }
- y += height/2;
- } else if (macButtonPtr->useTkText) {
- int x = 0, y;
-
- TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
- butPtr->indicatorSpace + butPtr->textWidth,
- butPtr->textHeight, &x, &y);
- x += butPtr->indicatorSpace;
- Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
- butPtr->textLayout, x, y, 0, -1);
+ XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width, (unsigned int) height,
+ imageXOffset, imageYOffset, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+
+ if (macButtonPtr->useTkText) {
+ Tk_DrawTextLayout(butPtr->display, pixmap,
+ dpPtr->gc, butPtr->textLayout,
+ x + textXOffset, y + textYOffset, 0, -1);
+ Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout,
+ x + textXOffset, y + textYOffset,
+ butPtr->underline);
+ }
+ y += fullHeight/2;
+ } else {
+ if (haveImage) {
+ int x = 0;
+ int y;
+
+ TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
+ butPtr->indicatorSpace + width, height, &x, &y);
+ x += butPtr->indicatorSpace;
+
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ if (dpPtr->relief == TK_RELIEF_RAISED) {
+ x -= dpPtr->offset;
+ y -= dpPtr->offset;
+ } else if (dpPtr->relief == TK_RELIEF_SUNKEN) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ }
+ imageXOffset += x;
+ imageYOffset += y;
+ if (butPtr->image != NULL) {
+ if ((butPtr->selectImage != NULL) &&
+ (butPtr->flags & SELECTED)) {
+ Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ } else {
+ Tk_RedrawImage(butPtr->image, 0, 0, width, height,
+ pixmap, imageXOffset, imageYOffset);
+ }
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
+ XCopyPlane(butPtr->display, butPtr->bitmap,
+ pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width,
+ (unsigned int) height, x, y, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+ y += height/2;
+ } else if (macButtonPtr->useTkText) {
+ int x = 0;
+ int y;
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX,
+ butPtr->padY,
+ butPtr->indicatorSpace + butPtr->textWidth,
+ butPtr->textHeight, &x, &y);
+ x += butPtr->indicatorSpace;
+ Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout, x, y, 0, -1);
+ }
+ }
}
/*
* If the button is disabled with a stipple rather than a special
- * foreground color, generate the stippled effect. If the widget is
- * selected and we use a different background color when selected, must
- * temporarily modify the GC so the stippling is the right color.
+ * foreground color, generate the stippled effect. If the widget
+ * is selected and we use a different background color when selected,
+ * must temporarily modify the GC so the stippling is the right color.
*/
- applyStipple:
if (macButtonPtr->useTkText) {
- if ((butPtr->state == STATE_DISABLED)
- && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
- if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
+ if ((butPtr->state == STATE_DISABLED)
+ && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
+ if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
&& (butPtr->selectBorder != NULL)) {
- XSetForeground(butPtr->display, butPtr->stippleGC,
+ XSetForeground(butPtr->display, butPtr->stippleGC,
Tk_3DBorderColor(butPtr->selectBorder)->pixel);
- }
-
+ }
/*
* Stipple the whole button if no disabledFg was specified,
* otherwise restrict stippling only to displayed image
*/
-
if (butPtr->disabledFg == NULL) {
XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC,
0, 0, (unsigned) Tk_Width(tkwin),
@@ -478,25 +485,24 @@ TkpDisplayButton(
imageXOffset, imageYOffset,
(unsigned) imageWidth, (unsigned) imageHeight);
}
- if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
+ if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
&& (butPtr->selectBorder != NULL)) {
XSetForeground(butPtr->display, butPtr->stippleGC,
Tk_3DBorderColor(butPtr->normalBorder)->pixel);
}
- }
-
- /*
- * Draw the border and traversal highlight last. This way, if the
- * button's contents overflow they'll be covered up by the border.
- */
-
- if (dpPtr->relief != TK_RELIEF_FLAT) {
- int inset = butPtr->highlightWidth;
-
- Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
- Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
- butPtr->borderWidth, dpPtr->relief);
- }
+ }
+
+ /*
+ * Draw the border and traversal highlight last. This way, if the
+ * button's contents overflow they'll be covered up by the border.
+ */
+
+ if (dpPtr->relief != TK_RELIEF_FLAT) {
+ int inset = butPtr->highlightWidth;
+ Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
+ Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
+ butPtr->borderWidth, dpPtr->relief);
+ }
}
}
@@ -505,228 +511,236 @@ TkpDisplayButton(
*
* TkpComputeButtonGeometry --
*
- * After changes in a button's text or bitmap, this procedure recomputes
- * the button's geometry and passes this information along to the
- * geometry manager for the window.
+ * After changes in a button's text or bitmap, this procedure
+ * recomputes the button's geometry and passes this information
+ * along to the geometry manager for the window.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The button's window may change size.
+ * The button's window may change size.
*
*----------------------------------------------------------------------
*/
void
TkpComputeButtonGeometry(
- TkButton *butPtr) /* Button whose geometry may have changed. */
+ TkButton *butPtr) /* Button whose geometry may have changed. */
{
int width, height, avgWidth, haveImage = 0, haveText = 0;
- int xInset, yInset, txtWidth, txtHeight;
+ int xInset, yInset;
+ int txtWidth, txtHeight;
Tk_FontMetrics fm;
DrawParams drawParams;
/*
* First figure out the size of the contents of the button.
*/
-
+
width = 0;
height = 0;
txtWidth = 0;
txtHeight = 0;
avgWidth = 0;
+
butPtr->indicatorSpace = 0;
if (butPtr->image != NULL) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- haveImage = 1;
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
} else if (butPtr->bitmap != None) {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- haveImage = 1;
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
}
if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
- Tk_FreeTextLayout(butPtr->textLayout);
- butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
- Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
- butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
-
- txtWidth = butPtr->textWidth;
- txtHeight = butPtr->textHeight;
- avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
- Tk_GetFontMetrics(butPtr->tkfont, &fm);
- haveText = (txtWidth != 0 && txtHeight != 0);
+ Tk_FreeTextLayout(butPtr->textLayout);
+ butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
+ Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
+ butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
+
+ txtWidth = butPtr->textWidth;
+ txtHeight = butPtr->textHeight;
+ avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
+ Tk_GetFontMetrics(butPtr->tkfont, &fm);
+ haveText = (txtWidth != 0 && txtHeight != 0);
}
/*
- * If the button is compound (ie, it shows both an image and text), the
- * new geometry is a combination of the image and text geometry. We only
- * honor the compound bit if the button has both text and an image,
- * because otherwise it is not really a compound button.
+ * If the button is compound (ie, it shows both an image and text),
+ * the new geometry is a combination of the image and text geometry.
+ * We only honor the compound bit if the button has both text and an
+ * image, because otherwise it is not really a compound button.
*/
if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
- switch ((enum compound) butPtr->compound) {
- case COMPOUND_TOP:
- case COMPOUND_BOTTOM:
- /*
- * Image is above or below text.
- */
-
- height += txtHeight + butPtr->padY;
- width = (width > txtWidth ? width : txtWidth);
- break;
- case COMPOUND_LEFT:
- case COMPOUND_RIGHT:
- /*
- * Image is left or right of text.
- */
-
- width += txtWidth + butPtr->padX;
- height = (height > txtHeight ? height : txtHeight);
- break;
- case COMPOUND_CENTER:
- /*
- * Image and text are superimposed.
- */
-
- width = (width > txtWidth ? width : txtWidth);
- height = (height > txtHeight ? height : txtHeight);
- break;
- case COMPOUND_NONE:
- break;
- }
- if (butPtr->width > 0) {
- width = butPtr->width;
- }
- if (butPtr->height > 0) {
- height = butPtr->height;
- }
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM: {
+ /*
+ * Image is above or below text
+ */
+
+ height += txtHeight + butPtr->padY;
+ width = (width > txtWidth ? width : txtWidth);
+ break;
+ }
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT: {
+ /*
+ * Image is left or right of text
+ */
+
+ width += txtWidth + butPtr->padX;
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ }
+ case COMPOUND_CENTER: {
+ /*
+ * Image and text are superimposed
+ */
+
+ width = (width > txtWidth ? width : txtWidth);
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ }
+ case COMPOUND_NONE: {break;}
+ }
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+
+ if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
+ butPtr->indicatorSpace = height;
+ if (butPtr->type == TYPE_CHECK_BUTTON) {
+ butPtr->indicatorDiameter = (65 * height)/100;
+ } else {
+ butPtr->indicatorDiameter = (75 * height)/100;
+ }
+ }
+
+ width += 2 * butPtr->padX;
+ height += 2 * butPtr->padY;
- if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
- butPtr->indicatorSpace = height;
- if (butPtr->type == TYPE_CHECK_BUTTON) {
- butPtr->indicatorDiameter = (65 * height)/100;
- } else {
- butPtr->indicatorDiameter = (75 * height)/100;
- }
- }
-
- width += 2 * butPtr->padX;
- height += 2 * butPtr->padY;
- } else if (haveImage) {
- if (butPtr->width > 0) {
- width = butPtr->width;
- }
- if (butPtr->height > 0) {
- height = butPtr->height;
- }
- if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
- butPtr->indicatorSpace = height;
- if (butPtr->type == TYPE_CHECK_BUTTON) {
- butPtr->indicatorDiameter = (65 * height)/100;
- } else {
- butPtr->indicatorDiameter = (75 * height)/100;
- }
- }
} else {
- width = txtWidth;
- height = txtHeight;
- if (butPtr->width > 0) {
- width = butPtr->width * avgWidth;
- }
- if (butPtr->height > 0) {
- height = butPtr->height * fm.linespace;
- }
- if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
- butPtr->indicatorDiameter = fm.linespace;
- if (butPtr->type == TYPE_CHECK_BUTTON) {
- butPtr->indicatorDiameter =
- (80 * butPtr->indicatorDiameter)/100;
- }
- butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
- }
+ if (haveImage) {
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+ if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
+ butPtr->indicatorSpace = height;
+ if (butPtr->type == TYPE_CHECK_BUTTON) {
+ butPtr->indicatorDiameter = (65 * height)/100;
+ } else {
+ butPtr->indicatorDiameter = (75 * height)/100;
+ }
+ }
+ } else {
+ width = txtWidth;
+ height = txtHeight;
+ if (butPtr->width > 0) {
+ width = butPtr->width * avgWidth;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height * fm.linespace;
+ }
+ if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
+ butPtr->indicatorDiameter = fm.linespace;
+ if (butPtr->type == TYPE_CHECK_BUTTON) {
+ butPtr->indicatorDiameter =
+ (80 * butPtr->indicatorDiameter)/100;
+ }
+ butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
+ }
+ }
}
/*
* Now figure out the size of the border decorations for the button.
*/
-
+
if (butPtr->highlightWidth < 0) {
- butPtr->highlightWidth = 0;
+ butPtr->highlightWidth = 0;
}
-
+
/*
- * The width and height calculation for Appearance buttons with images &
- * non-Appearance buttons with images is different. In the latter case, we
- * add the borderwidth to the inset, since we are going to stamp a 3-D
- * border over the image. In the former, we add it to the height,
+ * The width and height calculation for Appearance buttons with images &
+ * non-Appearance buttons with images is different. In the latter case,
+ * we add the borderwidth to the inset, since we are going to stamp a
+ * 3-D border over the image. In the former, we add it to the height,
* directly, since Appearance will draw the border as part of our control.
*
* When issuing the geometry request, add extra space for the indicator,
- * if any, and for the border and padding, plus if this is an image two
+ * if any, and for the border and padding, plus if this is an image two
* extra pixels so the display can be offset by 1 pixel in either
* direction for the raised or lowered effect.
*
* The highlight width corresponds to the default ring on the Macintosh.
* As such, the highlight width is only added if the button is the default
- * button. The actual width of the default ring is one less than the
- * highlight width as there is also one pixel of spacing. Appearance
- * buttons with images do not have a highlight ring, because the Bevel
- * button type does not support one.
+ * button. The actual width of the default ring is one less than the
+ * highlight width as there is also one pixel of spacing.
+ * Appearance buttons with images do not have a highlight ring, because the
+ * Bevel button type does not support one.
*/
if ((butPtr->image == None) && (butPtr->bitmap == None)) {
- width += 2*butPtr->padX;
- height += 2*butPtr->padY;
+ width += 2*butPtr->padX;
+ height += 2*butPtr->padY;
}
-
+
if ((butPtr->type == TYPE_BUTTON)) {
- if ((butPtr->image == None) && (butPtr->bitmap == None)) {
- butPtr->inset = 0;
- if (butPtr->defaultState != STATE_DISABLED) {
- butPtr->inset += butPtr->highlightWidth;
- }
- } else {
- butPtr->inset = 0;
- width += (2 * butPtr->borderWidth + 4);
- height += (2 * butPtr->borderWidth + 4);
- }
- } else if (butPtr->type == TYPE_LABEL) {
- butPtr->inset = butPtr->borderWidth;
- } else if (butPtr->indicatorOn) {
- butPtr->inset = 0;
+ if ((butPtr->image == None) && (butPtr->bitmap == None)) {
+ butPtr->inset = 0;
+ if (butPtr->defaultState != STATE_DISABLED) {
+ butPtr->inset += butPtr->highlightWidth;
+ }
+ } else {
+ butPtr->inset = 0;
+ width += (2 * butPtr->borderWidth + 4);
+ height += (2 * butPtr->borderWidth + 4);
+ }
+ } else if ((butPtr->type != TYPE_LABEL)) {
+ if (butPtr->indicatorOn) {
+ butPtr->inset = 0;
+ } else {
+ /*
+ * Under Appearance, the Checkbutton or radiobutton with an image
+ * is represented by a BevelButton with the Sticky defProc...
+ * So we must set its height in the same way as the Button
+ * with an image or bitmap.
+ */
+
+ if ( (butPtr->image != None) || (butPtr->bitmap != None)) {
+ int border;
+ butPtr->inset = 0;
+ if ( butPtr->borderWidth <= 2 ) {
+ border = 6;
+ } else {
+ border = 2 * butPtr->borderWidth + 2;
+ }
+ width += border;
+ height += border;
+ } else {
+ butPtr->inset = butPtr->borderWidth;
+ }
+ }
} else {
- /*
- * Under Appearance, the Checkbutton or radiobutton with an image is
- * represented by a BevelButton with the Sticky defProc... So we must
- * set its height in the same way as the Button with an image or
- * bitmap.
- */
-
- if ((butPtr->image != None) || (butPtr->bitmap != None)) {
- int border;
-
- butPtr->inset = 0;
- if (butPtr->borderWidth <= 2) {
- border = 6;
- } else {
- border = 2 * butPtr->borderWidth + 2;
- }
- width += border;
- height += border;
- } else {
- butPtr->inset = butPtr->borderWidth;
- }
+ butPtr->inset = butPtr->borderWidth;
}
if (TkMacOSXComputeDrawParams(butPtr,&drawParams)) {
- xInset = butPtr->indicatorSpace + DEF_INSET_LEFT + DEF_INSET_RIGHT;
- yInset = DEF_INSET_TOP + DEF_INSET_BOTTOM;
+ xInset = butPtr->indicatorSpace + DEF_INSET_LEFT + DEF_INSET_RIGHT;
+ yInset = DEF_INSET_TOP + DEF_INSET_BOTTOM;
} else {
- xInset = butPtr->indicatorSpace+butPtr->inset*2;
- yInset = butPtr->inset*2;
+ xInset = butPtr->indicatorSpace+butPtr->inset*2;
+ yInset = butPtr->inset*2;
}
Tk_GeometryRequest(butPtr->tkwin, width + xInset, height + yInset);
Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
@@ -737,13 +751,13 @@ TkpComputeButtonGeometry(
*
* TkpDestroyButton --
*
- * Free data structures associated with the button control.
+ * Free data structures associated with the button control.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Restores the default control state.
+ * Restores the default control state.
*
*----------------------------------------------------------------------
*/
@@ -752,11 +766,10 @@ void
TkpDestroyButton(
TkButton *butPtr)
{
- MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */
-
+ MacButton *mbPtr = ( MacButton *) butPtr; /* Mac button. */
if (mbPtr->userPane) {
- DisposeControl(mbPtr->userPane);
- mbPtr->userPane = NULL;
+ DisposeControl(mbPtr->userPane);
+ mbPtr->userPane = NULL;
}
}
@@ -765,220 +778,246 @@ TkpDestroyButton(
*
* TkMacOSXInitControl --
*
- * This procedure initialises a Carbon control.
+ * This procedure initialises a Carbon control
*
* Results:
- * 0 on success, 1 on failure.
+ * 0 on success, 1 on failure.
*
* Side effects:
- * A background pane control and the control itself is created. The
- * contol is embedded in the background control. The background control
- * is embedded in the root control of the containing window. The creation
- * parameters for the control are also computed.
+ * A background pane control and the control itself is created
+ * The contol is embedded in the background control
+ * The background control is embedded in the root control
+ * of the containing window
+ * The creation parameters for the control are also computed
*
*----------------------------------------------------------------------
*/
static int
-TkMacOSXInitControl(
- MacButton *mbPtr, /* Mac button. */
- GWorldPtr destPort,
- GC gc,
- Pixmap pixmap,
- Rect *paneRect,
- Rect *cntrRect)
+TkMacOSXInitControl (
+ MacButton *mbPtr, /* Mac button. */
+ GWorldPtr destPort,
+ GC gc,
+ Pixmap pixmap,
+ Rect *paneRect,
+ Rect *cntrRect
+)
{
- OSErr status;
- TkButton *butPtr = (TkButton *) mbPtr;
+ OSErr status;
+ TkButton * butPtr = ( TkButton * )mbPtr;
ControlRef rootControl;
- SInt16 procID, initialValue, minValue, maxValue;
- Boolean initiallyVisible;
- SInt32 controlReference;
+ SInt16 procID;
+ Boolean initiallyVisible;
+ SInt16 initialValue;
+ SInt16 minValue;
+ SInt16 maxValue;
+ SInt32 controlReference;
rootControl = TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin));
- mbPtr->windowRef = GetWindowFromPort(
- TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
+ mbPtr->windowRef
+ = GetWindowFromPort(TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
- /*
- * Set up the user pane.
+ /*
+ * Set up the user pane
*/
initiallyVisible = false;
- initialValue = kControlSupportsEmbedding|kControlHasSpecialBackground;
- minValue = 0;
- maxValue = 1;
- procID = kControlUserPaneProc;
+ initialValue = kControlSupportsEmbedding|kControlHasSpecialBackground;
+ minValue = 0;
+ maxValue = 1;
+ procID = kControlUserPaneProc;
controlReference = (SInt32)mbPtr;
- mbPtr->userPane = NewControl(mbPtr->windowRef, paneRect, "\p",
- initiallyVisible, initialValue, minValue, maxValue, procID,
- controlReference);
-
+ mbPtr->userPane = NewControl(mbPtr->windowRef,
+ paneRect, "\p",
+ initiallyVisible,
+ initialValue,
+ minValue,
+ maxValue,
+ procID,
+ controlReference );
+
if (!mbPtr->userPane) {
- LOG_MSG("Failed to create user pane control");
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Failed to create user pane control\n");
+#endif
+ return 1;
}
-
+
if ((status = EmbedControl(mbPtr->userPane,rootControl)) != noErr) {
- LOG_MSG("Failed to embed user pane control %d", status);
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Failed to embed user pane control %d\n", status);
+#endif
+ return 1;
}
-
+
SetUserPaneSetUpSpecialBackgroundProc(mbPtr->userPane,
- UserPaneBackgroundProc);
+ UserPaneBackgroundProc);
SetUserPaneDrawProc(mbPtr->userPane,UserPaneDraw);
initiallyVisible = false;
TkMacOSXComputeControlParams(butPtr,&mbPtr->params);
- mbPtr->control = NewControl(mbPtr->windowRef, cntrRect, "\p",
- initiallyVisible, mbPtr->params.initialValue,
- mbPtr->params.minValue, mbPtr->params.maxValue,
- mbPtr->params.procID, controlReference);
-
+ mbPtr->control = NewControl(mbPtr->windowRef,
+ cntrRect, "\p",
+ initiallyVisible,
+ mbPtr->params.initialValue,
+ mbPtr->params.minValue,
+ mbPtr->params.maxValue,
+ mbPtr->params.procID,
+ controlReference );
+
if (!mbPtr->control) {
- LOG_MSG("failed to create control of type %d", procID);
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"failed to create control of type %d\n",procID);
+#endif
+ return 1;
}
-
- if (EmbedControl(mbPtr->control,mbPtr->userPane) != noErr) {
- LOG_MSG("failed to embed control of type %d", procID);
- return 1;
+
+ if (EmbedControl(mbPtr->control,mbPtr->userPane) != noErr ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"failed to embed control of type %d\n",procID);
+#endif
+ return 1;
}
-
+
mbPtr->flags |= (1 + 2);
return 0;
}
-
+
/*
*--------------------------------------------------------------
*
* TkMacOSXDrawControl --
*
- * This function draws the tk button using Mac controls. In addition,
- * this code may apply custom colors passed in the TkButton.
+ * This function draws the tk button using Mac controls
+ * In addition, this code may apply custom colors passed
+ * in the TkButton.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The control is created, or reinitialised as needed.
+ * The control is created, or reinitialised as needed
+ *
*
*--------------------------------------------------------------
*/
static void
TkMacOSXDrawControl(
- MacButton *mbPtr, /* Mac button. */
- GWorldPtr destPort, /* Off screen GWorld. */
- GC gc, /* The GC we are drawing into - needed for the
- * bevel button */
- Pixmap pixmap) /* The pixmap we are drawing into - needed for
- * the bevel button */
+ MacButton *mbPtr, /* Mac button. */
+ GWorldPtr destPort, /* Off screen GWorld. */
+ GC gc, /* The GC we are drawing into - needed for
+ * the bevel button */
+ Pixmap pixmap) /* The pixmap we are drawing into - needed
+ * for the bevel button */
+
{
- TkButton *butPtr = (TkButton *) mbPtr;
- int err;
- TkWindow *winPtr;
- Rect paneRect, cntrRect;
-
- winPtr = (TkWindow *) butPtr->tkwin;
-
- paneRect.left = winPtr->privatePtr->xOff;
- paneRect.top = winPtr->privatePtr->yOff;
- paneRect.right = paneRect.left + Tk_Width(butPtr->tkwin);
+ TkButton * butPtr = ( TkButton *)mbPtr;
+ int err;
+ TkWindow * winPtr;
+ Rect paneRect;
+ Rect cntrRect;
+
+ winPtr = (TkWindow *)butPtr->tkwin;
+
+ paneRect.left = winPtr->privatePtr->xOff;
+ paneRect.top = winPtr->privatePtr->yOff;
+ paneRect.right = paneRect.left + Tk_Width(butPtr->tkwin);
paneRect.bottom = paneRect.top + Tk_Height(butPtr->tkwin);
cntrRect = paneRect;
/*
- cntrRect.left += butPtr->inset;
- cntrRect.top += butPtr->inset;
- cntrRect.right -= butPtr->inset;
+ cntrRect.left += butPtr->inset;
+ cntrRect.top += butPtr->inset;
+ cntrRect.right -= butPtr->inset;
cntrRect.bottom -= butPtr->inset;
*/
- cntrRect.left += DEF_INSET_LEFT;
- cntrRect.top += DEF_INSET_TOP;
- cntrRect.right -= DEF_INSET_RIGHT;
+ cntrRect.left += DEF_INSET_LEFT;
+ cntrRect.top += DEF_INSET_TOP;
+ cntrRect.right -= DEF_INSET_RIGHT;
cntrRect.bottom -= DEF_INSET_BOTTOM;
- /*
- * The control has been previously initialised. It may need to be
- * re-initialised.
+ /*
+ * The control has been previously initialised
+ * It may need to be re-initialised
*/
-
+
if (mbPtr->flags) {
- MacControlParams params;
-
- TkMacOSXComputeControlParams(butPtr, &params);
- if (bcmp(&params, &mbPtr->params, sizeof(params))) {
- /*
- * The type of control has changed. Clean it up and clear the
- * flag.
- */
-
- if (mbPtr->userPane) {
- DisposeControl(mbPtr->userPane);
- mbPtr->userPane = NULL;
- mbPtr->control = NULL;
- }
- mbPtr->flags = 0;
- }
+ MacControlParams params;
+ TkMacOSXComputeControlParams(butPtr, &params);
+ if (bcmp(&params, &mbPtr->params, sizeof(params))) {
+ /*
+ * the type of control has changed
+ * Clean it up and clear the flag
+ */
+
+ if (mbPtr->userPane) {
+ DisposeControl(mbPtr->userPane);
+ mbPtr->userPane = NULL;
+ mbPtr->control = NULL;
+ }
+ mbPtr->flags = 0;
+ }
}
if (!(mbPtr->flags & 1)) {
- if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap,
- &paneRect, &cntrRect)) {
- return;
- }
+ if (TkMacOSXInitControl(mbPtr, destPort, gc,
+ pixmap, &paneRect, &cntrRect) ) {
+ return;
+ }
}
SetControlBounds(mbPtr->userPane, &paneRect);
SetControlBounds(mbPtr->control, &cntrRect);
if (!mbPtr->useTkText) {
- Str255 controlTitle;
- ControlFontStyleRec fontStyle;
- Tk_Font font;
- int len;
-
- if (((mbPtr->info.image == NULL) && (mbPtr->info.bitmap == None))
- || (mbPtr->info.compound != COMPOUND_NONE)) {
- len = TkFontGetFirstTextLayout(butPtr->textLayout,
- &font, (char*) controlTitle);
- controlTitle[len] = 0;
- } else {
- len = 0;
- controlTitle[0] = 0;
- }
- if (bcmp(mbPtr->controlTitle, controlTitle, len+1)) {
- CFStringRef cf = CFStringCreateWithCString(NULL,
- (char*) controlTitle, kCFStringEncodingUTF8);
-
- if (cf != NULL) {
- SetControlTitleWithCFString(mbPtr->control, cf);
- CFRelease(cf);
- }
- bcopy(controlTitle, mbPtr->controlTitle, len+1);
- }
- if (len) {
- TkMacOSXInitControlFontStyle(font, &fontStyle);
- if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) {
- if (SetControlFontStyle(mbPtr->control, &fontStyle) != noErr) {
- LOG_MSG("SetControlFontStyle failed");
- }
- bcopy(&fontStyle, &mbPtr->fontStyle, sizeof(fontStyle));
- }
- }
+ Str255 controlTitle;
+ ControlFontStyleRec fontStyle;
+ Tk_Font font;
+ int len;
+
+ if (((mbPtr->info.image == NULL) && (mbPtr->info.bitmap == None))
+ || (mbPtr->info.compound != COMPOUND_NONE)) {
+ len = TkFontGetFirstTextLayout(butPtr->textLayout,
+ &font, (char*) controlTitle);
+ controlTitle[len] = 0;
+ } else {
+ len = 0;
+ controlTitle[0] = 0;
+ }
+ if (bcmp(mbPtr->controlTitle, controlTitle, len+1)) {
+ CFStringRef cf;
+ cf = CFStringCreateWithCString(NULL,
+ (char*) controlTitle, kCFStringEncodingUTF8);
+ if (cf != NULL) {
+ SetControlTitleWithCFString(mbPtr->control, cf);
+ CFRelease(cf);
+ }
+ bcopy(controlTitle, mbPtr->controlTitle, len+1);
+ }
+ if (len) {
+ TkMacOSXInitControlFontStyle(font, &fontStyle);
+ if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) {
+ if (SetControlFontStyle(mbPtr->control, &fontStyle) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetControlFontStyle failed\n");
+#endif
+ }
+ bcopy(&fontStyle, &mbPtr->fontStyle,
+ sizeof(fontStyle));
+ }
+ }
}
if (mbPtr->params.isBevel) {
- /*
- * Initialiase the image/button parameters.
- */
-
- SetupBevelButton(mbPtr, mbPtr->control, destPort, gc, pixmap);
+ /* Initialiase the image/button parameters */
+ SetupBevelButton(mbPtr, mbPtr->control, destPort,
+ gc, pixmap);
}
if (butPtr->flags & SELECTED) {
- SetControlValue(mbPtr->control, 1);
+ SetControlValue(mbPtr->control, 1);
} else if (butPtr->flags & TRISTATED) {
- SetControlValue(mbPtr->control, 2);
+ SetControlValue(mbPtr->control, 2);
} else {
- SetControlValue(mbPtr->control, 0);
+ SetControlValue(mbPtr->control, 0);
}
if (!Tk_MacOSXIsAppInFront() || butPtr->state == STATE_DISABLED) {
@@ -988,7 +1027,6 @@ TkMacOSXDrawControl(
* Use NoPart for normal and to ensure correct direct transition from
* disabled to active -state. [Bug 706446]
*/
-
HiliteControl(mbPtr->control, kControlNoPart);
if (butPtr->state == STATE_ACTIVE) {
@@ -996,15 +1034,15 @@ TkMacOSXDrawControl(
HiliteControl(mbPtr->control, kControlButtonPart);
} else {
switch (butPtr->type) {
- case TYPE_BUTTON:
- HiliteControl(mbPtr->control, kControlButtonPart);
- break;
- case TYPE_RADIO_BUTTON:
- HiliteControl(mbPtr->control, kControlRadioButtonPart);
- break;
- case TYPE_CHECK_BUTTON:
- HiliteControl(mbPtr->control, kControlCheckBoxPart);
- break;
+ case TYPE_BUTTON:
+ HiliteControl(mbPtr->control, kControlButtonPart);
+ break;
+ case TYPE_RADIO_BUTTON:
+ HiliteControl(mbPtr->control, kControlRadioButtonPart);
+ break;
+ case TYPE_CHECK_BUTTON:
+ HiliteControl(mbPtr->control, kControlCheckBoxPart);
+ break;
}
}
}
@@ -1012,30 +1050,30 @@ TkMacOSXDrawControl(
UpdateControlColors(mbPtr);
if (butPtr->type == TYPE_BUTTON) {
- Boolean isDefault;
-
- if (butPtr->defaultState == STATE_ACTIVE) {
- isDefault = true;
- } else {
- isDefault = false;
- }
- if (SetControlData(mbPtr->control, kControlNoPart,
- kControlPushButtonDefaultTag,
- sizeof(isDefault), (Ptr) &isDefault) != noErr) {
- }
+ Boolean isDefault;
+
+ if (butPtr->defaultState == STATE_ACTIVE) {
+ isDefault = true;
+ } else {
+ isDefault = false;
+ }
+ if ((err=SetControlData(mbPtr->control, kControlNoPart,
+ kControlPushButtonDefaultTag,
+ sizeof(isDefault), (Ptr) &isDefault)) != noErr) {
+ }
}
if (mbPtr->flags&2) {
- ShowControl(mbPtr->userPane);
- ShowControl(mbPtr->control);
- mbPtr->flags ^= 2;
+ ShowControl(mbPtr->userPane);
+ ShowControl(mbPtr->control);
+ mbPtr->flags ^= 2;
} else {
- SetControlVisibility(mbPtr->control, true, true);
- Draw1Control(mbPtr->userPane);
+ SetControlVisibility(mbPtr->control, true, true);
+ Draw1Control(mbPtr->userPane);
}
if (mbPtr->params.isBevel) {
- KillPicture(mbPtr->bevelButtonContent.u.picture);
+ KillPicture(mbPtr->bevelButtonContent.u.picture);
}
}
@@ -1044,131 +1082,150 @@ TkMacOSXDrawControl(
*
* SetupBevelButton --
*
- * Sets up the Bevel Button with image by copying the source image onto
- * the PicHandle for the button.
+ * Sets up the Bevel Button with image by copying the
+ * source image onto the PicHandle for the button.
*
* Results:
- * None
+ * None
*
* Side effects:
- * The image or bitmap for the button is copied over to a picture.
+ * The image or bitmap for the button is copied over to a picture.
*
*--------------------------------------------------------------
*/
-
void
SetupBevelButton(
- MacButton *mbPtr, /* Mac button. */
- ControlRef controlHandle, /* The control to set this picture to */
- GWorldPtr destPort, /* Off screen GWorld. */
- GC gc, /* The GC we are drawing into - needed for the
- * bevel button */
- Pixmap pixmap) /* The pixmap we are drawing into - needed for
- * the bevel button */
+ MacButton *mbPtr, /* Mac button. */
+ ControlRef controlHandle, /* The control to set this picture to */
+ GWorldPtr destPort, /* Off screen GWorld. */
+ GC gc, /* The GC we are drawing into - needed for
+ * the bevel button */
+ Pixmap pixmap /* The pixmap we are drawing into - needed
+ for the bevel button */
+ )
{
- int err, height, width;
- TkButton *butPtr = (TkButton *) mbPtr;
+ int err;
+ TkButton *butPtr = ( TkButton *)mbPtr;
+ int height, width;
ControlButtonGraphicAlignment theAlignment;
-
+
SetPort(destPort);
if (butPtr->image != None) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
+ Tk_SizeOfImage(butPtr->image,
+ &width, &height);
} else {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap,
+ &width, &height);
}
-
+
if ((butPtr->width > 0) && (butPtr->width < width)) {
- width = butPtr->width;
+ width = butPtr->width;
}
if ((butPtr->height > 0) && (butPtr->height < height)) {
- height = butPtr->height;
+ height = butPtr->height;
}
mbPtr->picParams.srcRect.right = width;
mbPtr->picParams.srcRect.bottom = height;
- /*
- * Set the flag to circumvent clipping and bounds problems with OS 10.0.4
+ /*
+ * Set the flag to circumvent clipping and bounds problems with OS 10.0.4
*/
-
- mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams);
- if (!mbPtr->bevelButtonContent.u.picture) {
- LOG_MSG("OpenCPicture failed");
+
+ if (!(mbPtr->bevelButtonContent.u.picture
+ = OpenCPicture(&mbPtr->picParams)) ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"OpenCPicture failed\n");
+#endif
}
tkPictureIsOpen = 1;
-
+
/*
- * TO DO - There is one case where XCopyPlane calls CopyDeepMask, which
- * does not get recorded in the picture. So the bitmap code will fail in
- * that case.
+ * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
+ * which does not get recorded in the picture. So the bitmap code
+ * will fail in that case.
*/
-
+
if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
- Tk_RedrawImage(butPtr->selectImage, 0,0, width, height, pixmap, 0,0);
- } else if ((butPtr->tristateImage!=NULL) && (butPtr->flags & TRISTATED)) {
- Tk_RedrawImage(butPtr->tristateImage, 0,0, width,height, pixmap, 0,0);
+ Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
+ pixmap, 0, 0);
+ } else if ((butPtr->tristateImage != NULL) && (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height,
+ pixmap, 0, 0);
} else if (butPtr->image != NULL) {
- Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0);
- } else {
- XSetClipOrigin(butPtr->display, gc, 0, 0);
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
- (unsigned int) width, (unsigned int) height, 0, 0, 1);
+ Tk_RedrawImage(butPtr->image, 0, 0, width,
+ height, pixmap, 0, 0);
+ } else {
+ XSetClipOrigin(butPtr->display, gc, 0, 0);
+ XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
+ (unsigned int) width, (unsigned int) height, 0, 0, 1);
}
-
+
ClosePicture();
tkPictureIsOpen = 0;
-
- err = SetControlData(controlHandle, kControlButtonPart,
- kControlBevelButtonContentTag,
- sizeof(ControlButtonContentInfo),
- (char *) &mbPtr->bevelButtonContent);
- LOG_ON_ERROR(SetControlData_BevelButtonContent);
-
+
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
+ kControlBevelButtonContentTag,
+ sizeof(ControlButtonContentInfo),
+ (char *) &mbPtr->bevelButtonContent)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,
+ "SetControlData BevelButtonContent failed, %d\n", err );
+#endif
+ }
+
if (butPtr->anchor == TK_ANCHOR_N) {
- theAlignment = kControlBevelButtonAlignTop;
- } else if (butPtr->anchor == TK_ANCHOR_NE) {
- theAlignment = kControlBevelButtonAlignTopRight;
- } else if (butPtr->anchor == TK_ANCHOR_E) {
- theAlignment = kControlBevelButtonAlignRight;
+ theAlignment = kControlBevelButtonAlignTop;
+ } else if (butPtr->anchor == TK_ANCHOR_NE) {
+ theAlignment = kControlBevelButtonAlignTopRight;
+ } else if (butPtr->anchor == TK_ANCHOR_E) {
+ theAlignment = kControlBevelButtonAlignRight;
} else if (butPtr->anchor == TK_ANCHOR_SE) {
- theAlignment = kControlBevelButtonAlignBottomRight;
+ theAlignment = kControlBevelButtonAlignBottomRight;
} else if (butPtr->anchor == TK_ANCHOR_S) {
- theAlignment = kControlBevelButtonAlignBottom;
+ theAlignment = kControlBevelButtonAlignBottom;
} else if (butPtr->anchor == TK_ANCHOR_SW) {
- theAlignment = kControlBevelButtonAlignBottomLeft;
+ theAlignment = kControlBevelButtonAlignBottomLeft;
} else if (butPtr->anchor == TK_ANCHOR_W) {
- theAlignment = kControlBevelButtonAlignLeft;
+ theAlignment = kControlBevelButtonAlignLeft;
} else if (butPtr->anchor == TK_ANCHOR_NW) {
- theAlignment = kControlBevelButtonAlignTopLeft;
+ theAlignment = kControlBevelButtonAlignTopLeft;
} else if (butPtr->anchor == TK_ANCHOR_CENTER) {
- theAlignment = kControlBevelButtonAlignCenter;
+ theAlignment = kControlBevelButtonAlignCenter;
}
- err = SetControlData(controlHandle, kControlButtonPart,
- kControlBevelButtonGraphicAlignTag,
- sizeof(ControlButtonGraphicAlignment),
- (char *) &theAlignment);
- LOG_ON_ERROR(SetControlData_BevelButtonGraphicAlign);
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
+ kControlBevelButtonGraphicAlignTag,
+ sizeof(ControlButtonGraphicAlignment),
+ (char *) &theAlignment)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,
+ "SetControlData BevelButtonGraphicAlign failed, %d\n", err );
+#endif
+ }
if (butPtr->compound != COMPOUND_NONE) {
- ControlButtonTextPlacement thePlacement =
- kControlBevelButtonPlaceNormally;
-
- if (butPtr->compound == COMPOUND_TOP) {
- thePlacement = kControlBevelButtonPlaceBelowGraphic;
- } else if (butPtr->compound == COMPOUND_BOTTOM) {
- thePlacement = kControlBevelButtonPlaceAboveGraphic;
- } else if (butPtr->compound == COMPOUND_LEFT) {
- thePlacement = kControlBevelButtonPlaceToRightOfGraphic;
- } else if (butPtr->compound == COMPOUND_RIGHT) {
- thePlacement = kControlBevelButtonPlaceToLeftOfGraphic;
- }
- err = SetControlData(controlHandle, kControlButtonPart,
- kControlBevelButtonTextPlaceTag,
- sizeof(ControlButtonTextPlacement),
- (char *) &thePlacement);
- LOG_ON_ERROR(SetControlData_BevelButtonTextPlace);
+ ControlButtonTextPlacement thePlacement = \
+ kControlBevelButtonPlaceNormally;
+ if (butPtr->compound == COMPOUND_TOP) {
+ thePlacement = kControlBevelButtonPlaceBelowGraphic;
+ } else if (butPtr->compound == COMPOUND_BOTTOM) {
+ thePlacement = kControlBevelButtonPlaceAboveGraphic;
+ } else if (butPtr->compound == COMPOUND_LEFT) {
+ thePlacement = kControlBevelButtonPlaceToRightOfGraphic;
+ } else if (butPtr->compound == COMPOUND_RIGHT) {
+ thePlacement = kControlBevelButtonPlaceToLeftOfGraphic;
+ }
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
+ kControlBevelButtonTextPlaceTag,
+ sizeof(ControlButtonTextPlacement),
+ (char *) &thePlacement)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,
+ "SetControlData BevelButtonTextPlace failed, %d\n", err );
+#endif
+ }
}
}
@@ -1177,30 +1234,28 @@ SetupBevelButton(
*
* SetUserPaneDrawProc --
*
- * Utility function to add a UserPaneDrawProc to a userPane control. From
- * MoreControls code from Apple DTS.
+ * Utility function to add a UserPaneDrawProc
+ * to a userPane control. From MoreControls code
+ * from Apple DTS.
*
* Results:
- * MacOS system error.
+ * MacOS system error.
*
* Side effects:
- * The user pane gets a new UserPaneDrawProc.
+ * The user pane gets a new UserPaneDrawProc.
*
*--------------------------------------------------------------
*/
-
-OSErr
-SetUserPaneDrawProc(
+OSErr SetUserPaneDrawProc (
ControlRef control,
ControlUserPaneDrawProcPtr upp)
{
ControlUserPaneDrawUPP myControlUserPaneDrawUPP;
-
- myControlUserPaneDrawUPP = NewControlUserPaneDrawUPP(upp);
- return SetControlData(control, kControlNoPart,
- kControlUserPaneDrawProcTag,
- sizeof(myControlUserPaneDrawUPP),
- (Ptr) &myControlUserPaneDrawUPP);
+ myControlUserPaneDrawUPP = NewControlUserPaneDrawUPP(upp);
+ return SetControlData (control,
+ kControlNoPart, kControlUserPaneDrawProcTag,
+ sizeof(myControlUserPaneDrawUPP),
+ (Ptr) &myControlUserPaneDrawUPP);
}
/*
@@ -1208,29 +1263,28 @@ SetUserPaneDrawProc(
*
* SetUserPaneSetUpSpecialBackgroundProc --
*
- * Utility function to add a UserPaneBackgroundProc to a userPane control
+ * Utility function to add a UserPaneBackgroundProc
+ * to a userPane control
*
* Results:
- * MacOS system error.
+ * MacOS system error.
*
* Side effects:
- * The user pane gets a new UserPaneBackgroundProc.
+ * The user pane gets a new UserPaneBackgroundProc.
*
*--------------------------------------------------------------
*/
-
OSErr
SetUserPaneSetUpSpecialBackgroundProc(
- ControlRef control,
+ ControlRef control,
ControlUserPaneBackgroundProcPtr upp)
{
ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP;
-
myControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP(upp);
- return SetControlData(control, kControlNoPart,
- kControlUserPaneBackgroundProcTag,
- sizeof(myControlUserPaneBackgroundUPP),
- (Ptr) &myControlUserPaneBackgroundUPP);
+ return SetControlData (control, kControlNoPart,
+ kControlUserPaneBackgroundProcTag,
+ sizeof(myControlUserPaneBackgroundUPP),
+ (Ptr) &myControlUserPaneBackgroundUPP);
}
/*
@@ -1238,29 +1292,28 @@ SetUserPaneSetUpSpecialBackgroundProc(
*
* UserPaneDraw --
*
- * This function draws the background of the user pane that will lie
- * under checkboxes and radiobuttons.
+ * This function draws the background of the user pane that will
+ * lie under checkboxes and radiobuttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The user pane gets updated to the current color.
+ * The user pane gets updated to the current color.
*
*--------------------------------------------------------------
*/
-
void
UserPaneDraw(
ControlRef control,
ControlPartCode cpc)
{
- MacButton *mbPtr = (MacButton *) GetControlReference(control);
Rect contrlRect;
-
+ MacButton * mbPtr;
+ mbPtr = ( MacButton *)GetControlReference(control);
GetControlBounds(control,&contrlRect);
- RGBBackColor(&mbPtr->userPaneBackground);
- EraseRect(&contrlRect);
+ RGBBackColor (&mbPtr->userPaneBackground);
+ EraseRect (&contrlRect);
}
/*
@@ -1268,14 +1321,14 @@ UserPaneDraw(
*
* UserPaneBackgroundProc --
*
- * This function sets up the background of the user pane that will lie
- * under checkboxes and radiobuttons.
+ * This function sets up the background of the user pane that will
+ * lie under checkboxes and radiobuttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The user pane background gets set to the current color.
+ * The user pane background gets set to the current color.
*
*--------------------------------------------------------------
*/
@@ -1285,10 +1338,10 @@ UserPaneBackgroundProc(
ControlHandle control,
ControlBackgroundPtr info)
{
- MacButton *mbPtr = (MacButton *) GetControlReference(control);
-
+ MacButton * mbPtr;
+ mbPtr = ( MacButton *)GetControlReference(control);
if (info->colorDevice) {
- RGBBackColor(&mbPtr->userPaneBackground);
+ RGBBackColor (&mbPtr->userPaneBackground);
}
}
@@ -1297,83 +1350,82 @@ UserPaneBackgroundProc(
*
* UpdateControlColors --
*
- * This function will review the colors used to display a Macintosh
- * button. If any non-standard colors are used we create a custom palette
- * for the button, populate with the colors for the button and install
- * the palette.
+ * This function will review the colors used to display
+ * a Macintosh button. If any non-standard colors are
+ * used we create a custom palette for the button, populate
+ * with the colors for the button and install the palette.
*
- * Under Appearance, we just set the pointer that will be used by the
- * UserPaneDrawProc.
+ * Under Appearance, we just set the pointer that will be
+ * used by the UserPaneDrawProc.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The Macintosh control may get a custom palette installed.
+ * The Macintosh control may get a custom palette installed.
*
*--------------------------------------------------------------
*/
static int
-UpdateControlColors(
- MacButton *mbPtr)
+UpdateControlColors(MacButton * mbPtr)
{
XColor *xcolor;
- TkButton *butPtr = (TkButton *) mbPtr;
-
+ TkButton * butPtr = ( TkButton * )mbPtr;
+
/*
- * Under Appearance we cannot change the background of the button itself.
- * However, the color we are setting is the color of the containing
- * userPane. This will be the color that peeks around the rounded corners
- * of the button. We make this the highlightbackground rather than the
- * background, because if you color the background of a frame containing a
- * button, you usually also color the highlightbackground as well, or you
- * will get a thin grey ring around the button.
+ * Under Appearance we cannot change the background of the
+ * button itself. However, the color we are setting is the color
+ * of the containing userPane. This will be the color that peeks
+ * around the rounded corners of the button.
+ * We make this the highlightbackground rather than the background,
+ * because if you color the background of a frame containing a
+ * button, you usually also color the highlightbackground as well,
+ * or you will get a thin grey ring around the button.
*/
-
+
if (butPtr->type == TYPE_BUTTON) {
- xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
+ xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
} else {
- xcolor = Tk_3DBorderColor(butPtr->normalBorder);
+ xcolor = Tk_3DBorderColor(butPtr->normalBorder);
}
TkSetMacColor(xcolor->pixel, &mbPtr->userPaneBackground);
-
+
return false;
-}
-
+}
/*
*--------------------------------------------------------------
*
* ButtonEventProc --
*
- * This procedure is invoked by the Tk dispatcher for various events on
- * buttons.
+ * This procedure is invoked by the Tk dispatcher for various
+ * events on buttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * When it gets exposed, it is redisplayed.
+ * When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
ButtonEventProc(
- ClientData clientData, /* Information about window. */
- XEvent *eventPtr) /* Information about event. */
+ ClientData clientData, /* Information about window. */
+ XEvent *eventPtr) /* Information about event. */
{
TkButton *buttonPtr = (TkButton *) clientData;
-
if (eventPtr->type == ActivateNotify
- || eventPtr->type == DeactivateNotify) {
- if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
- return;
- }
- if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
- Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
- buttonPtr->flags |= REDRAW_PENDING;
- }
+ || eventPtr->type == DeactivateNotify) {
+ if ((buttonPtr->tkwin == NULL)
+ || (!Tk_IsMapped(buttonPtr->tkwin))) {
+ return;
+ }
+ if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
+ Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
+ buttonPtr->flags |= REDRAW_PENDING;
+ }
}
}
@@ -1382,221 +1434,216 @@ ButtonEventProc(
*
* TkMacOSXComputeControlParams --
*
- * This procedure computes the various parameters used when creating a
- * Carbon control (NewControl). These are determined by the various Tk
- * button parameters
+ * This procedure computes the various parameters used
+ * when creating a Carbon control (NewControl)
+ * These are determined by the various tk button parameters
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Sets the control initialisation parameters
+ * Sets the control initialisation parameters
*
*----------------------------------------------------------------------
*/
static void
-TkMacOSXComputeControlParams(
- TkButton *butPtr,
- MacControlParams *paramsPtr)
+TkMacOSXComputeControlParams(TkButton * butPtr, MacControlParams * paramsPtr )
{
paramsPtr->isBevel = 0;
-
- /*
- * Determine ProcID based on button type and dimensions.
+
+ /*
+ * Determine ProcID based on button type and dimensions
*/
-
+
switch (butPtr->type) {
- case TYPE_BUTTON:
- if ((butPtr->image == None) && (butPtr->bitmap == None)) {
- paramsPtr->initialValue = 1;
- paramsPtr->minValue = 0;
- paramsPtr->maxValue = 1;
- paramsPtr->procID = kControlPushButtonProc;
- } else {
- paramsPtr->initialValue = 0;
- paramsPtr->minValue = kControlBehaviorOffsetContents
- | kControlContentPictHandle;
- paramsPtr->maxValue = 1;
- if (butPtr->borderWidth <= 2) {
- paramsPtr->procID = kControlBevelButtonSmallBevelProc;
- } else if (butPtr->borderWidth == 3) {
- paramsPtr->procID = kControlBevelButtonNormalBevelProc;
- } else {
- paramsPtr->procID = kControlBevelButtonLargeBevelProc;
- }
- paramsPtr->isBevel = 1;
- }
- break;
- case TYPE_RADIO_BUTTON:
- if (((butPtr->image == None) && (butPtr->bitmap == None))
- || (butPtr->indicatorOn)) {
- paramsPtr->initialValue = 1;
- paramsPtr->minValue = 0;
- paramsPtr->maxValue = 2;
- paramsPtr->procID = kControlRadioButtonProc;
- } else {
- paramsPtr->initialValue = 0;
- paramsPtr->minValue = kControlBehaviorOffsetContents |
- kControlBehaviorSticky | kControlContentPictHandle;
- paramsPtr->maxValue = 2;
- if (butPtr->borderWidth <= 2) {
- paramsPtr->procID = kControlBevelButtonSmallBevelProc;
- } else if (butPtr->borderWidth == 3) {
- paramsPtr->procID = kControlBevelButtonNormalBevelProc;
- } else {
- paramsPtr->procID = kControlBevelButtonLargeBevelProc;
- }
- paramsPtr->isBevel = 1;
- }
- break;
- case TYPE_CHECK_BUTTON:
- if (((butPtr->image == None) && (butPtr->bitmap == None))
- || (butPtr->indicatorOn)) {
- paramsPtr->initialValue = 1;
- paramsPtr->minValue = 0;
- paramsPtr->maxValue = 2;
- paramsPtr->procID = kControlCheckBoxProc;
- } else {
- paramsPtr->initialValue = 0;
- paramsPtr->minValue = kControlBehaviorOffsetContents |
- kControlBehaviorSticky | kControlContentPictHandle;
- paramsPtr->maxValue = 2;
- if (butPtr->borderWidth <= 2) {
- paramsPtr->procID = kControlBevelButtonSmallBevelProc;
- } else if (butPtr->borderWidth == 3) {
- paramsPtr->procID = kControlBevelButtonNormalBevelProc;
- } else {
- paramsPtr->procID = kControlBevelButtonLargeBevelProc;
- }
- paramsPtr->isBevel = 1;
- }
- break;
+ case TYPE_BUTTON:
+ if ((butPtr->image == None) && (butPtr->bitmap == None)) {
+ paramsPtr->initialValue = 1;
+ paramsPtr->minValue = 0;
+ paramsPtr->maxValue = 1;
+ paramsPtr->procID = kControlPushButtonProc;
+ } else {
+ paramsPtr->initialValue = 0;
+ paramsPtr->minValue = kControlBehaviorOffsetContents
+ | kControlContentPictHandle;
+ paramsPtr->maxValue = 1;
+ if (butPtr->borderWidth <= 2) {
+ paramsPtr->procID = kControlBevelButtonSmallBevelProc;
+ } else if (butPtr->borderWidth == 3) {
+ paramsPtr->procID = kControlBevelButtonNormalBevelProc;
+ } else {
+ paramsPtr->procID = kControlBevelButtonLargeBevelProc;
+ }
+ paramsPtr->isBevel = 1;
+ }
+ break;
+ case TYPE_RADIO_BUTTON:
+ if (((butPtr->image == None) && (butPtr->bitmap == None))
+ || (butPtr->indicatorOn)) {
+ paramsPtr->initialValue = 1;
+ paramsPtr->minValue = 0;
+ paramsPtr->maxValue = 2;
+ paramsPtr->procID = kControlRadioButtonProc;
+ } else {
+ paramsPtr->initialValue = 0;
+ paramsPtr->minValue = kControlBehaviorOffsetContents|
+ kControlBehaviorSticky|
+ kControlContentPictHandle;
+ paramsPtr->maxValue = 2;
+ if (butPtr->borderWidth <= 2) {
+ paramsPtr->procID = kControlBevelButtonSmallBevelProc;
+ } else if (butPtr->borderWidth == 3) {
+ paramsPtr->procID = kControlBevelButtonNormalBevelProc;
+ } else {
+ paramsPtr->procID = kControlBevelButtonLargeBevelProc;
+ }
+ paramsPtr->isBevel = 1;
+ }
+ break;
+ case TYPE_CHECK_BUTTON:
+ if (((butPtr->image == None)
+ && (butPtr->bitmap == None))
+ || (butPtr->indicatorOn)) {
+ paramsPtr->initialValue = 1;
+ paramsPtr->minValue = 0;
+ paramsPtr->maxValue = 2;
+ paramsPtr->procID = kControlCheckBoxProc;
+ } else {
+ paramsPtr->initialValue = 0;
+ paramsPtr->minValue = kControlBehaviorOffsetContents
+ | kControlBehaviorSticky
+ | kControlContentPictHandle;
+ paramsPtr->maxValue = 2;
+ if (butPtr->borderWidth <= 2) {
+ paramsPtr->procID = kControlBevelButtonSmallBevelProc;
+ } else if (butPtr->borderWidth == 3) {
+ paramsPtr->procID = kControlBevelButtonNormalBevelProc;
+ } else {
+ paramsPtr->procID = kControlBevelButtonLargeBevelProc;
+ }
+ paramsPtr->isBevel = 1;
+ }
+ break;
}
-}
-
+}
/*
*----------------------------------------------------------------------
*
* TkMacOSXComputeDrawParams --
*
- * This procedure computes the various parameters used when drawing a
- * button. These are determined by the various Tk button parameters.
+ * This procedure computes the various parameters used
+ * when drawing a button
+ * These are determined by the various tk button parameters
*
* Results:
- * 1 if control will be used, 0 otherwise.
+ * 1 if control will be used, 0 otherwise.
*
* Side effects:
- * Sets the button draw parameters
+ * Sets the button draw parameters
*
*----------------------------------------------------------------------
*/
static int
-TkMacOSXComputeDrawParams(
- TkButton *butPtr,
- DrawParams *dpPtr)
+TkMacOSXComputeDrawParams(TkButton * butPtr, DrawParams * dpPtr)
{
- dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
- || (butPtr->bitmap != None));
- dpPtr->offset = (butPtr->type == TYPE_BUTTON)
- && dpPtr->hasImageOrBitmap;
+ dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
+ || (butPtr->bitmap != None));
+ dpPtr->offset = (butPtr->type == TYPE_BUTTON)
+ && dpPtr->hasImageOrBitmap;
dpPtr->border = butPtr->normalBorder;
- if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
- dpPtr->gc = butPtr->disabledGC;
- } else if ((butPtr->type==TYPE_BUTTON) && (butPtr->state==STATE_ACTIVE)) {
- dpPtr->gc = butPtr->activeTextGC;
- dpPtr->border = butPtr->activeBorder;
+ if ((butPtr->state == STATE_DISABLED)
+ && (butPtr->disabledFg != NULL)) {
+ dpPtr->gc = butPtr->disabledGC;
+ } else if ((butPtr->type == TYPE_BUTTON)
+ && (butPtr->state == STATE_ACTIVE)) {
+ dpPtr->gc = butPtr->activeTextGC;
+ dpPtr->border = butPtr->activeBorder;
} else {
- dpPtr->gc = butPtr->normalTextGC;
+ dpPtr->gc = butPtr->normalTextGC;
}
- if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
- && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
- dpPtr->border = butPtr->selectBorder;
+ if ((butPtr->flags & SELECTED)
+ && (butPtr->state != STATE_ACTIVE)
+ && (butPtr->selectBorder != NULL)
+ && !butPtr->indicatorOn) {
+ dpPtr->border = butPtr->selectBorder;
}
-
+
/*
- * Override the relief specified for the button if this is a checkbutton
- * or radiobutton and there's no indicator. However, don't do this in the
- * presence of Appearance, since then the bevel button will take care of
- * the relief.
+ * Override the relief specified for the button if this is a
+ * checkbutton or radiobutton and there's no indicator.
+ * However, don't do this in the presence of Appearance, since
+ * then the bevel button will take care of the relief.
*/
dpPtr->relief = butPtr->relief;
if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
- if (!dpPtr->hasImageOrBitmap) {
- dpPtr->relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
- : TK_RELIEF_RAISED;
- }
+ if (!dpPtr->hasImageOrBitmap) {
+ dpPtr->relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
+ : TK_RELIEF_RAISED;
+ }
}
/*
* Determine the draw type
*/
-
if (butPtr->type == TYPE_LABEL) {
- dpPtr->drawType = DRAW_LABEL;
+ dpPtr->drawType = DRAW_LABEL;
} else if (butPtr->type == TYPE_BUTTON) {
- if (!dpPtr->hasImageOrBitmap) {
- dpPtr->drawType = DRAW_CONTROL;
- } else if (butPtr->image != None) {
- dpPtr->drawType = DRAW_BEVEL;
- } else {
- /*
- * TO DO - The current way the we draw bitmaps (XCopyPlane) uses
- * CopyDeepMask in this one case. The Picture recording does not
- * record this call, and so we can't use the Appearance bevel
- * button here. The only case that would exercise this is if you
- * use a bitmap, with -data & -mask specified. We should probably
- * draw the appearance button and overprint the image in this
- * case. This just punts and draws the old-style, ugly, button.
- */
-
- if (dpPtr->gc->clip_mask == 0) {
- dpPtr->drawType = DRAW_BEVEL;
- } else {
- TkpClipMask *clipPtr = (TkpClipMask *) dpPtr->gc->clip_mask;
-
- if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
- (clipPtr->value.pixmap != butPtr->bitmap)) {
- dpPtr->drawType = DRAW_CUSTOM;
- } else {
- dpPtr->drawType = DRAW_BEVEL;
- }
- }
- }
- } else if (butPtr->indicatorOn) {
- dpPtr->drawType = DRAW_CONTROL;
- } else if (dpPtr->hasImageOrBitmap) {
- if (dpPtr->gc->clip_mask == 0) {
- dpPtr->drawType = DRAW_BEVEL;
- } else {
- TkpClipMask *clipPtr = (TkpClipMask*) dpPtr->gc->clip_mask;
-
- if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
- (clipPtr->value.pixmap != butPtr->bitmap)) {
- dpPtr->drawType = DRAW_CUSTOM;
- } else {
- dpPtr->drawType = DRAW_BEVEL;
- }
- }
+ if (!dpPtr->hasImageOrBitmap) {
+ dpPtr->drawType = DRAW_CONTROL;
+ } else if (butPtr->image != None) {
+ dpPtr->drawType = DRAW_BEVEL;
+ } else {
+ /*
+ * TO DO - The current way the we draw bitmaps (XCopyPlane)
+ * uses CopyDeepMask in this one case. The Picture recording
+ * does not record this call, and so we can't use the
+ * Appearance bevel button here. The only case that would
+ * exercise this is if you use a bitmap, with
+ * -data & -mask specified. We should probably draw the
+ * appearance button and overprint the image in this case.
+ * This just punts and draws the old-style, ugly, button.
+ */
+
+ if (dpPtr->gc->clip_mask == 0) {
+ dpPtr->drawType = DRAW_BEVEL;
+ } else {
+ TkpClipMask *clipPtr = (TkpClipMask*) dpPtr->gc->clip_mask;
+ if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
+ (clipPtr->value.pixmap != butPtr->bitmap)) {
+ dpPtr->drawType = DRAW_CUSTOM;
+ } else {
+ dpPtr->drawType = DRAW_BEVEL;
+ }
+ }
+ }
} else {
- dpPtr->drawType = DRAW_CUSTOM;
+ if (butPtr->indicatorOn) {
+ dpPtr->drawType = DRAW_CONTROL;
+ } else if (dpPtr->hasImageOrBitmap) {
+ if (dpPtr->gc->clip_mask == 0) {
+ dpPtr->drawType = DRAW_BEVEL;
+ } else {
+ TkpClipMask *clipPtr = (TkpClipMask*) dpPtr->gc->clip_mask;
+ if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
+ (clipPtr->value.pixmap != butPtr->bitmap)) {
+ dpPtr->drawType = DRAW_CUSTOM;
+ } else {
+ dpPtr->drawType = DRAW_BEVEL;
+ }
+ }
+ } else {
+ dpPtr->drawType = DRAW_CUSTOM;
+ }
}
if ((dpPtr->drawType == DRAW_CONTROL) || (dpPtr->drawType == DRAW_BEVEL)) {
- return 1;
+ return 1;
} else {
- return 0;
+ return 0;
}
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXCarbonEvents.c b/macosx/tkMacOSXCarbonEvents.c
index 81706ba..18c519e 100644
--- a/macosx/tkMacOSXCarbonEvents.c
+++ b/macosx/tkMacOSXCarbonEvents.c
@@ -1,13 +1,14 @@
/*
* tkMacOSXCarbonEvents.c --
*
- * This file implements functions that register for and handle various
- * Carbon Events and Timers. Most carbon events of interest to TkAqua are
- * processed in a handler registered on the dispatcher event target so
- * that we get first crack at them before HIToolbox dispatchers/processes
- * them further. As some events are sent directly to the focus or app
- * event target and not dispatched normally, we also register a handler
- * on the application event target.
+ * This file implements functions that register for and handle
+ * various Carbon Events and Timers. Most carbon events of interest
+ * to TkAqua are processed in a handler registered on the dispatcher
+ * event target so that we get first crack at them before HIToolbox
+ * dispatchers/processes them further.
+ * As some events are sent directly to the focus or app event target
+ * and not dispatched normally, we also register a handler on the
+ * application event target.
*
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2005 Daniel A. Steffen <das@users.sourceforge.net>
@@ -15,45 +16,51 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * The following terms apply to all files originating from Apple
- * Computer, Inc. ("Apple") and associated with the software unless
- * explicitly disclaimed in individual files.
- *
- * Apple hereby grants permission to use, copy, modify, distribute, and
- * license this software and its documentation for any purpose, provided
- * that existing copyright notices are retained in all copies and that
- * this notice is included verbatim in any distributions. No written
- * agreement, license, or royalty fee is required for any of the
- * authorized uses. Modifications to this software may be copyrighted by
- * their authors and need not follow the licensing terms described here,
- * provided that the new terms are clearly indicated on the first page of
- * each file where they apply.
- *
- * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE SOFTWARE
- * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
- * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS
- * DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF APPLE OR THE
- * AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. APPLE,
- * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
- * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
- * APPLE,THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
- * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- *
- * GOVERNMENT USE: If you are acquiring this software on behalf of the
- * U.S. government, the Government shall have only "Restricted Rights" in
- * the software and related documentation as defined in the Federal
- * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
- * acquiring the software on behalf of the Department of Defense, the
- * software shall be classified as "Commercial Computer Software" and the
- * Government shall have only "Restricted Rights" as defined in Clause
- * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
- * authors grant the U.S. Government and others acting in its behalf
- * permission to use and distribute the software in accordance with the
- * terms specified in this license.
- *
- * RCS: @(#) $Id: tkMacOSXCarbonEvents.c,v 1.14 2007/04/13 14:51:17 dkf Exp $
+ * The following terms apply to all files originating from Apple
+ * Computer, Inc. ("Apple") and associated with the software
+ * unless explicitly disclaimed in individual files.
+ *
+ *
+ * Apple hereby grants permission to use, copy, modify,
+ * distribute, and license this software and its documentation
+ * for any purpose, provided that existing copyright notices are
+ * retained in all copies and that this notice is included
+ * verbatim in any distributions. No written agreement, license,
+ * or royalty fee is required for any of the authorized
+ * uses. Modifications to this software may be copyrighted by
+ * their authors and need not follow the licensing terms
+ * described here, provided that the new terms are clearly
+ * indicated on the first page of each file where they apply.
+ *
+ *
+ * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
+ * SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
+ * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
+ * THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
+ * EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE. APPLE, THE AUTHORS AND
+ * DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS
+ * SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
+ * AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * GOVERNMENT USE: If you are acquiring this software on behalf
+ * of the U.S. government, the Government shall have only
+ * "Restricted Rights" in the software and related documentation
+ * as defined in the Federal Acquisition Regulations (FARs) in
+ * Clause 52.227.19 (c) (2). If you are acquiring the software
+ * on behalf of the Department of Defense, the software shall be
+ * classified as "Commercial Computer Software" and the
+ * Government shall have only "Restricted Rights" as defined in
+ * Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
+ * foregoing, the authors grant the U.S. Government and others
+ * acting in its behalf permission to use and distribute the
+ * software in accordance with the terms specified in this
+ * license.
+ *
+ * RCS: @(#) $Id: tkMacOSXCarbonEvents.c,v 1.15 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -66,51 +73,44 @@
#endif
*/
-/*
- * Declarations of functions used only in this file:
- */
-
-static OSStatus CarbonEventHandlerProc(EventHandlerCallRef callRef,
- EventRef event, void *userData);
-static OSStatus InstallStandardApplicationEventHandler(void);
-static void ExitRaelEventHandlerProc(EventHandlerCallRef,
- EventRef, void *) __attribute__ ((__noreturn__));
-static void CarbonTimerProc(EventLoopTimerRef timer,
- void *userData);
-
-/*
- * Static data used by several functions in this file:
- */
+/* Declarations of functions used only in this file */
+static OSStatus CarbonEventHandlerProc(EventHandlerCallRef callRef,
+ EventRef event, void *userData);
+static OSStatus InstallStandardApplicationEventHandler();
+static void ExitRaelEventHandlerProc (EventHandlerCallRef, EventRef, void*)
+ __attribute__ ((__noreturn__));
+static void CarbonTimerProc(EventLoopTimerRef timer, void *userData);
+/* Static data used by several functions in this file */
static jmp_buf exitRaelJmpBuf;
static EventLoopTimerRef carbonTimer = NULL;
static int carbonTimerEnabled = 0;
-
+
/*
*----------------------------------------------------------------------
*
* CarbonEventHandlerProc --
*
- * This procedure is the handler for all registered CarbonEvents.
+ * This procedure is the handler for all registered CarbonEvents.
*
* Results:
- * OS status code.
+ * OS status code.
*
* Side effects:
- * Dispatches CarbonEvents.
+ * Dispatches CarbonEvents.
*
*----------------------------------------------------------------------
*/
static OSStatus
-CarbonEventHandlerProc(
- EventHandlerCallRef callRef,
- EventRef event,
- void *userData)
+CarbonEventHandlerProc (
+ EventHandlerCallRef callRef,
+ EventRef event,
+ void *userData)
{
- OSStatus result = eventNotHandledErr;
- TkMacOSXEvent macEvent;
- MacEventStatus eventStatus;
+ OSStatus result = eventNotHandledErr;
+ TkMacOSXEvent macEvent;
+ MacEventStatus eventStatus;
macEvent.eventRef = event;
macEvent.eClass = GetEventClass(macEvent.eventRef);
@@ -123,14 +123,11 @@ CarbonEventHandlerProc(
if (macEvent.eKind != kEventMouseMoved &&
macEvent.eKind != kEventMouseDragged) {
TkMacOSXCarbonEventToAscii(event, buf);
- LOG_MSG("CarbonEventHandlerProc started handling %s", buf);
+ fprintf(stderr, "CarbonEventHandlerProc started handling %s\n", buf);
TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _DebugPrintEvent,
EventRef inEvent);
if (_DebugPrintEvent) {
- /*
- * Carbon-internal event debugging (c.f. Technote 2124)
- */
-
+ /* Carbon-internal event debugging (c.f. Technote 2124) */
_DebugPrintEvent(event);
}
}
@@ -144,7 +141,8 @@ CarbonEventHandlerProc(
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS)
if (macEvent.eKind != kEventMouseMoved &&
macEvent.eKind != kEventMouseDragged) {
- LOG_MSG("CarbonEventHandlerProc finished handling %s: %s handled",
+ fprintf(stderr,
+ "CarbonEventHandlerProc finished handling %s: %s handled\n",
buf, eventStatus.stopProcessing ? " " : "not");
}
#endif /* TK_MAC_DEBUG_CARBON_EVENTS */
@@ -156,71 +154,81 @@ CarbonEventHandlerProc(
*
* TkMacOSXInitCarbonEvents --
*
- * This procedure initializes all CarbonEvent handlers.
+ * This procedure initializes all CarbonEvent handlers.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Handlers for Carbon Events are registered.
+ * Handlers for Carbon Events are registered.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE void
-TkMacOSXInitCarbonEvents(
- Tcl_Interp *interp)
+TkMacOSXInitCarbonEvents (
+ Tcl_Interp *interp)
{
OSStatus err;
const EventTypeSpec dispatcherEventTypes[] = {
- {kEventClassMouse, kEventMouseDown},
- {kEventClassMouse, kEventMouseUp},
- {kEventClassMouse, kEventMouseMoved},
- {kEventClassMouse, kEventMouseDragged},
- {kEventClassMouse, kEventMouseWheelMoved},
- {kEventClassWindow, kEventWindowUpdate},
- {kEventClassWindow, kEventWindowActivated},
- {kEventClassWindow, kEventWindowDeactivated},
- {kEventClassKeyboard, kEventRawKeyDown},
- {kEventClassKeyboard, kEventRawKeyRepeat},
- {kEventClassKeyboard, kEventRawKeyUp},
- {kEventClassKeyboard, kEventRawKeyModifiersChanged},
- {kEventClassKeyboard, kEventRawKeyRepeat},
- {kEventClassApplication, kEventAppActivated},
- {kEventClassApplication, kEventAppDeactivated},
- {kEventClassApplication, kEventAppQuit},
+ {kEventClassMouse, kEventMouseDown},
+ {kEventClassMouse, kEventMouseUp},
+ {kEventClassMouse, kEventMouseMoved},
+ {kEventClassMouse, kEventMouseDragged},
+ {kEventClassMouse, kEventMouseWheelMoved},
+ {kEventClassWindow, kEventWindowUpdate},
+ {kEventClassWindow, kEventWindowActivated},
+ {kEventClassWindow, kEventWindowDeactivated},
+ {kEventClassKeyboard, kEventRawKeyDown},
+ {kEventClassKeyboard, kEventRawKeyRepeat},
+ {kEventClassKeyboard, kEventRawKeyUp},
+ {kEventClassKeyboard, kEventRawKeyModifiersChanged},
+ {kEventClassKeyboard, kEventRawKeyRepeat},
+ {kEventClassApplication, kEventAppActivated},
+ {kEventClassApplication, kEventAppDeactivated},
+ {kEventClassApplication, kEventAppQuit},
};
const EventTypeSpec applicationEventTypes[] = {
- {kEventClassMenu, kEventMenuBeginTracking},
- {kEventClassMenu, kEventMenuEndTracking},
- {kEventClassCommand, kEventCommandProcess},
- {kEventClassCommand, kEventCommandUpdateStatus},
- {kEventClassMouse, kEventMouseWheelMoved},
- {kEventClassWindow, kEventWindowExpanded},
- {kEventClassApplication, kEventAppHidden},
- {kEventClassApplication, kEventAppShown},
- {kEventClassApplication, kEventAppAvailableWindowBoundsChanged},
+ {kEventClassMenu, kEventMenuBeginTracking},
+ {kEventClassMenu, kEventMenuEndTracking},
+ {kEventClassCommand, kEventCommandProcess},
+ {kEventClassCommand, kEventCommandUpdateStatus},
+ {kEventClassMouse, kEventMouseWheelMoved},
+ {kEventClassWindow, kEventWindowExpanded},
+ {kEventClassApplication, kEventAppHidden},
+ {kEventClassApplication, kEventAppShown},
+ {kEventClassApplication, kEventAppAvailableWindowBoundsChanged},
};
EventHandlerUPP handler = NewEventHandlerUPP(CarbonEventHandlerProc);
err = InstallStandardApplicationEventHandler();
- LOG_ON_ERROR(InstallStandardApplicationEventHandler);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "InstallStandardApplicationEventHandler failed, %d\n",
+ (int) err);
+#endif
+ }
err = InstallEventHandler(GetEventDispatcherTarget(), handler,
GetEventTypeCount(dispatcherEventTypes), dispatcherEventTypes,
(void *) interp, NULL);
- LOG_ON_ERROR(InstallEventHandler);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "InstallEventHandler failed, %d\n", (int) err);
+#endif
+ }
err = InstallEventHandler(GetApplicationEventTarget(), handler,
GetEventTypeCount(applicationEventTypes), applicationEventTypes,
(void *) interp, NULL);
- LOG_ON_ERROR(InstallEventHandler);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "InstallEventHandler failed, %d\n", (int) err);
+#endif
+ }
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS)
TkMacOSXInitNamedDebugSymbol(HIToolbox, void, TraceEventByName, char*);
if (TraceEventByName) {
- /*
- * Carbon-internal event debugging (c.f. Technote 2124)
- */
-
+ /* Carbon-internal event debugging (c.f. Technote 2124) */
TraceEventByName("kEventMouseDown");
TraceEventByName("kEventMouseUp");
TraceEventByName("kEventMouseWheelMoved");
@@ -253,38 +261,34 @@ TkMacOSXInitCarbonEvents(
*
* InstallStandardApplicationEventHandler --
*
- * This procedure installs the carbon standard application event handler.
+ * This procedure installs the carbon standard application event
+ * handler.
*
* Results:
- * OS status code.
+ * OS status code.
*
* Side effects:
- * Standard handlers for application Carbon Events are registered.
+ * Standard handlers for application Carbon Events are registered.
*
*----------------------------------------------------------------------
*/
static OSStatus
-InstallStandardApplicationEventHandler(void)
+InstallStandardApplicationEventHandler()
{
- /*
- * This is a hack to workaround missing Carbon API to install the standard
- * application event handler (InstallStandardEventHandler() does not work
- * on the application target). The only way to install the standard app
- * handler is to call RunApplicationEventLoop(), but since we are running
- * our own event loop, we'll immediately need to break out of RAEL again:
- * we do this via longjmp out of the ExitRaelEventHandlerProc event
- * handler called first off from RAEL by posting a high priority dummy
- * event. This workaround is derived from a similar approach in Technical
- * Q&A 1061.
- */
-
- enum {
- kExitRaelEvent = 'ExiT'
- };
- const EventTypeSpec exitRaelEventType = {
- kExitRaelEvent, kExitRaelEvent
- };
+ /*
+ * This is a hack to workaround missing Carbon API to install the standard
+ * application event handler (InstallStandardEventHandler() does not work
+ * on the application target). The only way to install the standard app
+ * handler is to call RunApplicationEventLoop(), but since we are running
+ * our own event loop, we'll immediately need to break out of RAEL again:
+ * we do this via longjmp out of the ExitRaelEventHandlerProc event handler
+ * called first off from RAEL by posting a high priority dummy event.
+ * This workaround is derived from a similar approach in Technical Q&A 1061.
+ */
+ enum { kExitRaelEvent = 'ExiT' };
+ const EventTypeSpec exitRaelEventType =
+ { kExitRaelEvent, kExitRaelEvent};
EventHandlerUPP exitRaelEventHandler;
EventHandlerRef exitRaelEventHandlerRef = NULL;
EventRef exitRaelEvent = NULL;
@@ -298,7 +302,7 @@ InstallStandardApplicationEventHandler(void)
&exitRaelEventHandlerRef);
}
if (err == noErr) {
- err = CreateEvent(NULL, kExitRaelEvent, kExitRaelEvent,
+ err = CreateEvent(NULL, kExitRaelEvent, kExitRaelEvent,
GetCurrentEventTime(), kEventAttributeNone, &exitRaelEvent);
}
if (err == noErr) {
@@ -308,11 +312,7 @@ InstallStandardApplicationEventHandler(void)
if (err == noErr) {
if (!setjmp(exitRaelJmpBuf)) {
RunApplicationEventLoop();
-
- /*
- * This point should never be reached!
- */
-
+ /* This point should never be reached ! */
Tcl_Panic("RunApplicationEventLoop exited !");
}
}
@@ -333,24 +333,23 @@ InstallStandardApplicationEventHandler(void)
*
* ExitRaelEventHandlerProc --
*
- * This procedure is the dummy event handler used to break out of RAEL
- * via longjmp(), it is called as the first ever event handler in RAEL by
- * posting a high priority dummy event.
+ * This procedure is the dummy event handler used to break out of
+ * RAEL via longjmp, it is called as the first ever event handler
+ * in RAEL by posting a high priority dummy event.
*
* Results:
- * None. Never returns!
+ * None. Never returns !
*
* Side effects:
- * longjmp()s back to InstallStandardApplicationEventHandler().
+ * longjmp back to InstallStandardApplicationEventHandler().
*
*----------------------------------------------------------------------
*/
static void
-ExitRaelEventHandlerProc(
- EventHandlerCallRef callRef,
- EventRef event,
- void *userData)
+ExitRaelEventHandlerProc (
+ EventHandlerCallRef callRef,
+ EventRef event, void *userData)
{
longjmp(exitRaelJmpBuf, 1);
}
@@ -360,36 +359,33 @@ ExitRaelEventHandlerProc(
*
* CarbonTimerProc --
*
- * This procedure is the carbon timer handler that runs the tcl event
- * loop periodically. It does not process TCL_WINDOW_EVENTS to avoid
- * reentry issues with Carbon, nor TCL_IDLE_EVENTS since it is only
- * intended to be called during short periods of busy time such as during
- * menu tracking.
+ * This procedure is the carbon timer handler that runs the tcl
+ * event loop periodically. It does not process TCL_WINDOW_EVENTS
+ * to avoid reentry issues with Carbon, nor TCL_IDLE_EVENTS since
+ * it is only intended to be called during short periods of busy
+ * time such as during menu tracking.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Runs the Tcl event loop.
+ * Runs the Tcl event loop.
*
*----------------------------------------------------------------------
*/
static void
-CarbonTimerProc(
- EventLoopTimerRef timer,
- void *userData)
+CarbonTimerProc (
+ EventLoopTimerRef timer,
+ void *userData)
{
- if (carbonTimerEnabled) {
- /*
- * Avoid starving main event loop: process at most 4 events.
- */
-
+ if(carbonTimerEnabled) {
+ /* Avoid starving main event loop: process at most 4 events. */
int i = 4;
- while (--i && Tcl_DoOneEvent(
+ while(--i && Tcl_DoOneEvent(
TCL_FILE_EVENTS|TCL_TIMER_EVENTS|TCL_DONT_WAIT)) {
-#ifdef TK_MAC_DEBUG_CARBON_EVENTS
- LOG_MSG("Processed tcl event from carbon timer");
+#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS)
+ fprintf(stderr, "Processed tcl event from carbon timer\n");
#endif /* TK_MAC_DEBUG_CARBON_EVENTS */
}
}
@@ -400,75 +396,80 @@ CarbonTimerProc(
*
* TkMacOSXStartTclEventLoopCarbonTimer --
*
- * This procedure installs (if necessary) and starts a carbon event timer
- * that runs the tcl event loop periodically. It should be called
- * whenever a nested carbon event loop is run by HIToolbox (e.g. during
- * menutracking) to ensure that non-window non-idle tcl events are
- * processed.
+ * This procedure installs (if necessary) and starts a carbon
+ * event timer that runs the tcl event loop periodically.
+ * It should be called whenever a nested carbon event loop is
+ * run by HIToolbox (e.g. during menutracking) to ensure that
+ * non-window non-idle tcl events are processed.
*
* Results:
- * OS status code.
+ * OS status code.
*
* Side effects:
- * Carbon event timer is installed and started.
+ * Carbon event timer is installed and started.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE OSStatus
-TkMacOSXStartTclEventLoopCarbonTimer(void)
+TkMacOSXStartTclEventLoopCarbonTimer()
{
OSStatus err;
- if (!carbonTimer) {
+ if(!carbonTimer) {
EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(CarbonTimerProc);
-
err = InstallEventLoopTimer(GetMainEventLoop(), kEventDurationNoWait,
5 * kEventDurationMillisecond, timerUPP, NULL, &carbonTimer);
- LOG_ON_ERROR(InstallEventLoopTimer);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "InstallEventLoopTimer failed, %d\n", (int) err);
+#endif
+ }
} else {
err = SetEventLoopTimerNextFireTime(carbonTimer, kEventDurationNoWait);
- LOG_ON_ERROR(SetEventLoopTimerNextFireTime);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "SetEventLoopTimerNextFireTime failed, %d\n",
+ (int) err);
+#endif
+ }
}
carbonTimerEnabled = 1;
return err;
}
-
+
/*
*----------------------------------------------------------------------
*
* TkMacOSXStopTclEventLoopCarbonTimer --
*
- * This procedure stops the carbon event timer started by
- * TkMacOSXStartTclEventLoopCarbonTimer().
+ * This procedure stops the carbon event timer started by
+ * TkMacOSXStartTclEventLoopCarbonTimer().
*
* Results:
- * OS status code.
+ * OS status code.
*
* Side effects:
- * Carbon event timer is stopped.
+ * Carbon event timer is stopped.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE OSStatus
-TkMacOSXStopTclEventLoopCarbonTimer(void)
+TkMacOSXStopTclEventLoopCarbonTimer()
{
OSStatus err = noErr;
- if (carbonTimer) {
- err = SetEventLoopTimerNextFireTime(carbonTimer,
- kEventDurationForever);
- LOG_ON_ERROR(SetEventLoopTimerNextFireTime);
+ if(carbonTimer) {
+ err = SetEventLoopTimerNextFireTime(carbonTimer, kEventDurationForever);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "SetEventLoopTimerNextFireTime failed, %d\n",
+ (int) err);
+#endif
+ }
}
carbonTimerEnabled = 0;
return err;
}
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c
index b4008c6..fb83d02 100644
--- a/macosx/tkMacOSXClipboard.c
+++ b/macosx/tkMacOSXClipboard.c
@@ -1,15 +1,15 @@
/*
* tkMacOSXClipboard.c --
*
- * This file manages the clipboard for the Tk toolkit.
+ * This file manages the clipboard for the Tk toolkit.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.8 2007/04/13 14:51:17 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.9 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -21,58 +21,59 @@
*
* TkSelGetSelection --
*
- * Retrieve the specified selection from another process. For now, only
- * fetching XA_STRING from CLIPBOARD is supported. Eventually other types
- * should be allowed.
- *
+ * Retrieve the specified selection from another process. For
+ * now, only fetching XA_STRING from CLIPBOARD is supported.
+ * Eventually other types should be allowed.
+ *
* Results:
- * The return value is a standard Tcl return value. If an error occurs
- * (such as no selection exists) then an error message is left in the
- * interp's result.
+ * The return value is a standard Tcl return value.
+ * If an error occurs (such as no selection exists)
+ * then an error message is left in the interp's result.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
int
TkSelGetSelection(
- Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
- Tk_Window tkwin, /* Window on whose behalf to retrieve the
- * selection (determines display from which to
- * retrieve). */
- Atom selection, /* Selection to retrieve. */
- Atom target, /* Desired form in which selection is to be
- * returned. */
- Tk_GetSelProc *proc, /* Procedure to call to process the selection,
- * once it has been retrieved. */
- ClientData clientData) /* Arbitrary value to pass to proc. */
+ Tcl_Interp *interp, /* Interpreter to use for reporting
+ * errors. */
+ Tk_Window tkwin, /* Window on whose behalf to retrieve
+ * the selection (determines display
+ * from which to retrieve). */
+ Atom selection, /* Selection to retrieve. */
+ Atom target, /* Desired form in which selection
+ * is to be returned. */
+ Tk_GetSelProc *proc, /* Procedure to call to process the
+ * selection, once it has been retrieved. */
+ ClientData clientData) /* Arbitrary value to pass to proc. */
{
- int result, err;
+ int result;
+ int err;
long length;
ScrapRef scrapRef;
- char *buf;
+ char * buf;
if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
- && (target == XA_STRING)) {
- /*
- * Get the scrap from the Macintosh global clipboard.
- */
-
- err = GetCurrentScrap(&scrapRef);
- if (err != noErr) {
- Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
- " GetCurrentScrap failed.", NULL);
- return TCL_ERROR;
- }
+ && (target == XA_STRING)) {
+ /*
+ * Get the scrap from the Macintosh global clipboard.
+ */
+
+ err = GetCurrentScrap(&scrapRef);
+ if (err != noErr) {
+ Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
+ " GetCurrentScrap failed.", (char *) NULL);
+ return TCL_ERROR;
+ }
/*
* Try UNICODE first
*/
-
- err = GetScrapFlavorSize(scrapRef, kScrapFlavorTypeUnicode, &length);
- if (err == noErr && length > 0) {
+ err = GetScrapFlavorSize(scrapRef, kScrapFlavorTypeUnicode, &length);
+ if (err == noErr && length > 0) {
Tcl_DString ds;
char *data;
@@ -97,49 +98,49 @@ TkSelGetSelection(
}
}
- err = GetScrapFlavorSize(scrapRef, 'TEXT', &length);
- if (err != noErr) {
- Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
- " GetScrapFlavorSize failed.", NULL);
- return TCL_ERROR;
- }
- if (length > 0) {
- Tcl_DString encodedText;
- char *data;
-
- buf = (char *) ckalloc(length + 1);
+ err = GetScrapFlavorSize(scrapRef, 'TEXT', &length);
+ if (err != noErr) {
+ Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
+ " GetScrapFlavorSize failed.", (char *) NULL);
+ return TCL_ERROR;
+ }
+ if (length > 0) {
+ Tcl_DString encodedText;
+ char *data;
+
+ buf = (char *) ckalloc(length + 1);
buf[length] = 0;
err = GetScrapFlavorData(scrapRef, 'TEXT', &length, buf);
- if (err != noErr) {
- Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
- " GetScrapFlavorData failed.", (char *) NULL);
- return TCL_ERROR;
- }
-
- /*
- * Tcl expects '\n' not '\r' as the line break character.
- */
-
- for (data = buf; *data != '\0'; data++) {
- if (*data == '\r') {
- *data = '\n';
- }
- }
-
- Tcl_ExternalToUtfDString(TkMacOSXCarbonEncoding, buf, length,
- &encodedText);
- result = (*proc)(clientData, interp,
- Tcl_DStringValue(&encodedText));
- Tcl_DStringFree(&encodedText);
-
- ckfree(buf);
- return result;
- }
+ if (err != noErr) {
+ Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
+ " GetScrapFlavorData failed.", (char *) NULL);
+ return TCL_ERROR;
+ }
+
+ /*
+ * Tcl expects '\n' not '\r' as the line break character.
+ */
+
+ for (data = buf; *data != '\0'; data++) {
+ if (*data == '\r') {
+ *data = '\n';
+ }
+ }
+
+ Tcl_ExternalToUtfDString(TkMacOSXCarbonEncoding, buf, length,
+ &encodedText);
+ result = (*proc)(clientData, interp,
+ Tcl_DStringValue(&encodedText));
+ Tcl_DStringFree(&encodedText);
+
+ ckfree(buf);
+ return result;
+ }
}
-
+
Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
- " selection doesn't exist or form \"",
- Tk_GetAtomName(tkwin, target), "\" not defined", NULL);
+ " selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
+ "\" not defined", (char *) NULL);
return TCL_ERROR;
}
@@ -148,46 +149,48 @@ TkSelGetSelection(
*
* TkSetSelectionOwner --
*
- * This function claims ownership of the specified selection. If the
- * selection is CLIPBOARD, then we empty the system clipboard.
+ * This function claims ownership of the specified selection.
+ * If the selection is CLIPBOARD, then we empty the system
+ * clipboard.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
void
XSetSelectionOwner(
- Display *display, /* X Display. */
- Atom selection, /* What selection to own. */
- Window owner, /* Window to be the owner. */
- Time time) /* The current time? */
+ Display* display, /* X Display. */
+ Atom selection, /* What selection to own. */
+ Window owner, /* Window to be the owner. */
+ Time time) /* The current time? */
{
Tk_Window tkwin;
TkDisplay *dispPtr;
/*
- * This is a gross hack because the Tk_InternAtom interface is broken. It
- * expects a Tk_Window, even though it only needs a Tk_Display.
+ * This is a gross hack because the Tk_InternAtom interface is broken.
+ * It expects a Tk_Window, even though it only needs a Tk_Display.
*/
tkwin = (Tk_Window) TkGetMainInfoList()->winPtr;
if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) {
- /*
- * Only claim and empty the clipboard if we aren't already the owner
- * of the clipboard.
- */
- dispPtr = TkGetMainInfoList()->winPtr->dispPtr;
- if (dispPtr->clipboardActive) {
- return;
- }
- ClearCurrentScrap();
+ /*
+ * Only claim and empty the clipboard if we aren't already the
+ * owner of the clipboard.
+ */
+
+ dispPtr = TkGetMainInfoList()->winPtr->dispPtr;
+ if (dispPtr->clipboardActive) {
+ return;
+ }
+ ClearCurrentScrap();
}
}
@@ -196,23 +199,23 @@ XSetSelectionOwner(
*
* TkSelUpdateClipboard --
*
- * This function is called to force the clipboard to be updated after new
- * data is added. On the Mac we don't need to do anything.
+ * This function is called to force the clipboard to be updated
+ * after new data is added. On the Mac we don't need to do
+ * anything.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
void
TkSelUpdateClipboard(
- TkWindow *winPtr, /* Window associated with clipboard. */
- TkClipboardTarget *targetPtr)
- /* Info about the content. */
+ TkWindow *winPtr, /* Window associated with clipboard. */
+ TkClipboardTarget *targetPtr) /* Info about the content. */
{
}
@@ -221,25 +224,28 @@ TkSelUpdateClipboard(
*
* TkSelEventProc --
*
- * This procedure is invoked whenever a selection-related event occurs.
+ * This procedure is invoked whenever a selection-related
+ * event occurs.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Lots: depends on the type of event.
+ * Lots: depends on the type of event.
*
*--------------------------------------------------------------
*/
void
TkSelEventProc(
- Tk_Window tkwin, /* Window for which event was targeted. */
- register XEvent *eventPtr) /* X event: either SelectionClear,
- * SelectionRequest, or SelectionNotify. */
+ Tk_Window tkwin, /* Window for which event was
+ * targeted. */
+ register XEvent *eventPtr) /* X event: either SelectionClear,
+ * SelectionRequest, or
+ * SelectionNotify. */
{
if (eventPtr->type == SelectionClear) {
- TkSelClearSelection(tkwin, eventPtr);
+ TkSelClearSelection(tkwin, eventPtr);
}
}
@@ -248,21 +254,22 @@ TkSelEventProc(
*
* TkSelPropProc --
*
- * This procedure is invoked when property-change events occur on windows
- * not known to the toolkit. This is a stub function under Windows.
+ * This procedure is invoked when property-change events
+ * occur on windows not known to the toolkit. This is a stub
+ * function under Windows.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
void
TkSelPropProc(
- register XEvent *eventPtr) /* X PropertyChange event. */
+ register XEvent *eventPtr) /* X PropertyChange event. */
{
}
@@ -271,20 +278,20 @@ TkSelPropProc(
*
* TkSuspendClipboard --
*
- * Handle clipboard conversion as required by the suppend event. This
- * function is also called on exit.
+ * Handle clipboard conversion as required by the suppend event.
+ * This function is also called on exit.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The local scrap is moved to the global scrap.
+ * The local scrap is moved to the global scrap.
*
*----------------------------------------------------------------------
*/
void
-TkSuspendClipboard(void)
+TkSuspendClipboard()
{
TkClipboardTarget *targetPtr;
TkClipboardBuffer *cbPtr;
@@ -295,50 +302,50 @@ TkSuspendClipboard(void)
dispPtr = TkGetDisplayList();
if ((dispPtr == NULL) || !dispPtr->clipboardActive) {
- return;
+ return;
}
for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
- targetPtr = targetPtr->nextPtr) {
- if (targetPtr->type == XA_STRING) {
- break;
- }
+ targetPtr = targetPtr->nextPtr) {
+ if (targetPtr->type == XA_STRING)
+ break;
}
if (targetPtr != NULL) {
- Tcl_DString encodedText, unicodedText;
-
- length = 0;
- for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
- cbPtr = cbPtr->nextPtr) {
- length += cbPtr->length;
- }
-
- buffer = ckalloc(length);
- buffPtr = buffer;
- for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
- cbPtr = cbPtr->nextPtr) {
- for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
- p < endPtr; p++) {
- if (*p == '\n') {
- *buffPtr++ = '\r';
- } else {
- *buffPtr++ = *p;
- }
- }
- }
-
- ClearCurrentScrap();
- GetCurrentScrap(&scrapRef);
- Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer, length,
- &encodedText);
- PutScrapFlavor(scrapRef, 'TEXT', 0, Tcl_DStringLength(&encodedText),
- Tcl_DStringValue(&encodedText));
- Tcl_DStringFree(&encodedText);
+ Tcl_DString encodedText;
+ Tcl_DString unicodedText;
+
+ length = 0;
+ for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
+ cbPtr = cbPtr->nextPtr) {
+ length += cbPtr->length;
+ }
+
+ buffer = ckalloc(length);
+ buffPtr = buffer;
+ for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
+ cbPtr = cbPtr->nextPtr) {
+ for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
+ p < endPtr; p++) {
+ if (*p == '\n') {
+ *buffPtr++ = '\r';
+ } else {
+ *buffPtr++ = *p;
+ }
+ }
+ }
+
+ ClearCurrentScrap();
+ GetCurrentScrap(&scrapRef);
+ Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer,
+ length, &encodedText);
+ PutScrapFlavor(scrapRef, 'TEXT', 0,
+ Tcl_DStringLength(&encodedText),
+ Tcl_DStringValue(&encodedText) );
+ Tcl_DStringFree(&encodedText);
/*
- * Also put unicode data on scrap.
+ * Also put unicode data on scrap
*/
-
Tcl_DStringInit(&unicodedText);
Tcl_UtfToUniCharDString(buffer, length, &unicodedText);
PutScrapFlavor(scrapRef, kScrapFlavorTypeUnicode, 0,
@@ -346,26 +353,20 @@ TkSuspendClipboard(void)
Tcl_DStringValue(&unicodedText));
Tcl_DStringFree(&unicodedText);
- ckfree(buffer);
+ ckfree(buffer);
}
/*
- * The system now owns the scrap. We tell Tk that it has lost the
- * selection so that it will look for it the next time it needs it.
- * (Window list NULL if quiting.)
+ * The system now owns the scrap. We tell Tk that it has
+ * lost the selection so that it will look for it the next time
+ * it needs it. (Window list NULL if quiting.)
*/
if (TkGetMainInfoList() != NULL) {
- Tk_ClearSelection((Tk_Window) TkGetMainInfoList()->winPtr,
- Tk_InternAtom((Tk_Window) TkGetMainInfoList()->winPtr,
- "CLIPBOARD"));
+ Tk_ClearSelection((Tk_Window) TkGetMainInfoList()->winPtr,
+ Tk_InternAtom((Tk_Window) TkGetMainInfoList()->winPtr,
+ "CLIPBOARD"));
}
+
+ return;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXCursor.c b/macosx/tkMacOSXCursor.c
index 175af6a..571f5b6 100644
--- a/macosx/tkMacOSXCursor.c
+++ b/macosx/tkMacOSXCursor.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXCursor.c,v 1.9 2007/04/13 14:51:17 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXCursor.c,v 1.10 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -358,7 +358,7 @@ TkMacOSXInstallCursor(
CCrsrHandle ccursor;
CursHandle cursor;
static unsigned int cursorStep = 0;
-
+
gResizeOverride = resizeOverride;
if (resizeOverride) {
@@ -366,7 +366,9 @@ TkMacOSXInstallCursor(
if (cursor) {
SetCursor(*cursor);
} else {
- LOG_MSG("Resize cursor failed, %d", ResError());
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Resize cursor failed, %d\n", ResError());
+#endif
}
} else if (macCursorPtr == NULL) {
SetThemeCursor(kThemeArrowCursor);
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 4b41cb5..2db0ca5 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -6,10 +6,10 @@
* 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.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.22 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.23 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -25,7 +25,6 @@
/*
* The following are ID's for resources that are defined in tkMacOSXResource.r
*/
-
#define OPEN_BOX 130
#define OPEN_POPUP 131
#define OPEN_MENU 132
@@ -44,45 +43,46 @@
* The following structure is used in the GetFileName() function. It stored
* information about the file dialog and the file filters.
*/
-
typedef struct _OpenFileData {
FileFilterList fl; /* List of file filters. */
SInt16 curType; /* The filetype currently being listed. */
short popupItem; /* Item number of the popup in the dialog. */
- int usePopup; /* True if we show the popup menu (this is an
- * open operation and the -filetypes option is
- * set). */
+ int usePopup; /* True if we show the popup menu (this is
+ * an open operation and the -filetypes
+ * option is set). */
} OpenFileData;
+
/*
- * The following structure is used in the tk_messageBox implementation.
+ * The following structure is used in the tk_messageBox
+ * implementation.
*/
-
typedef struct {
- WindowRef windowRef;
- int buttonIndex;
+ WindowRef windowRef;
+ int buttonIndex;
} CallbackUserData;
+
static OSStatus AlertHandler(EventHandlerCallRef callRef,
EventRef eventRef, void *userData);
-static Boolean MatchOneType(StringPtr fileNamePtr, OSType fileType,
+static Boolean MatchOneType(StringPtr fileNamePtr, OSType fileType,
OpenFileData *myofdPtr, FileFilter *filterPtr);
-static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info,
+static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info,
NavCallBackUserData callBackUD,
NavFilterModes filterMode);
-static pascal void OpenEventProc(NavEventCallbackMessage callBackSelector,
+static pascal void OpenEventProc(NavEventCallbackMessage callBackSelector,
NavCBRecPtr callBackParms,
NavCallBackUserData callBackUD);
-static void InitFileDialogs(void);
-static int NavServicesGetFile(Tcl_Interp *interp,
- OpenFileData *ofd, AEDesc *initialDescPtr,
+static void InitFileDialogs();
+static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd,
+ AEDesc *initialDescPtr,
char *initialFile, AEDescList *selectDescPtr,
- CFStringRef title, CFStringRef message,
- int multiple, int isOpen);
-static int HandleInitialDirectory(Tcl_Interp *interp,
- char *initialFile, char *initialDir,
- FSRef *dirRef, AEDescList *selectDescPtr,
- AEDesc *dirDescPtr);
+ CFStringRef title, CFStringRef message, int multiple, int isOpen);
+static int HandleInitialDirectory (Tcl_Interp *interp,
+ char *initialFile, char *initialDir,
+ FSRef *dirRef,
+ AEDescList *selectDescPtr,
+ AEDesc *dirDescPtr);
/*
* Have we initialized the file dialog subsystem
@@ -97,14 +97,16 @@ static int fileDlgInited = 0;
static NavObjectFilterUPP openFileFilterUPP;
static NavEventUPP openFileEventUPP;
+
/*
*----------------------------------------------------------------------
*
* Tk_ChooseColorObjCmd --
*
- * This procedure implements the color dialog box for the Mac platform.
- * See the user documentation for details on what it does.
+ * This procedure implements the color dialog box for the Mac
+ * platform. See the user documentation for details on what it
+ * does.
*
* Results:
* A standard Tcl result.
@@ -117,10 +119,10 @@ static NavEventUPP openFileEventUPP;
int
Tk_ChooseColorObjCmd(
- ClientData clientData, /* Main window associated with interpreter. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+ ClientData clientData, /* Main window associated with interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
Tk_Window parent;
char *title;
@@ -129,17 +131,17 @@ Tk_ChooseColorObjCmd(
static int inited = 0;
static RGBColor in;
static CONST char *optionStrings[] = {
- "-initialcolor", "-parent", "-title", NULL
+ "-initialcolor", "-parent", "-title", NULL
};
enum options {
- COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
+ COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
};
if (inited == 0) {
- /*
- * 'in' stores the last color picked. The next time the color dialog
- * pops up, the last color will remain in the dialog.
- */
+ /*
+ * 'in' stores the last color picked. The next time the color dialog
+ * pops up, the last color will remain in the dialog.
+ */
in.red = 0xffff;
in.green = 0xffff;
@@ -152,44 +154,46 @@ Tk_ChooseColorObjCmd(
picked = 0;
for (i = 1; i < objc; i += 2) {
- int index;
- char *option, *value;
+ int index;
+ char *option, *value;
if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option",
TCL_EXACT, &index) != TCL_OK) {
return TCL_ERROR;
}
if (i + 1 == objc) {
- option = Tcl_GetString(objv[i]);
+ option = Tcl_GetStringFromObj(objv[i], NULL);
Tcl_AppendResult(interp, "value for \"", option, "\" missing",
- NULL);
+ (char *) NULL);
return TCL_ERROR;
}
value = Tcl_GetStringFromObj(objv[i + 1], NULL);
switch ((enum options) index) {
- case COLOR_INITIAL: {
- XColor *colorPtr;
+ case COLOR_INITIAL: {
+ XColor *colorPtr;
- colorPtr = Tk_GetColor(interp, parent, value);
- if (colorPtr == NULL) {
- return TCL_ERROR;
+ colorPtr = Tk_GetColor(interp, parent, value);
+ if (colorPtr == NULL) {
+ return TCL_ERROR;
+ }
+ in.red = colorPtr->red;
+ in.green = colorPtr->green;
+ in.blue = colorPtr->blue;
+ Tk_FreeColor(colorPtr);
+ break;
}
- in.red = colorPtr->red;
- in.green = colorPtr->green;
- in.blue = colorPtr->blue;
- Tk_FreeColor(colorPtr);
- break;
- }
- case COLOR_PARENT:
- parent = Tk_NameToWindow(interp, value, parent);
- if (parent == NULL) {
- return TCL_ERROR;
+ case COLOR_PARENT: {
+ parent = Tk_NameToWindow(interp, value, parent);
+ if (parent == NULL) {
+ return TCL_ERROR;
+ }
+ break;
+ }
+ case COLOR_TITLE: {
+ title = value;
+ break;
}
- break;
- case COLOR_TITLE:
- title = value;
- break;
}
}
@@ -209,13 +213,13 @@ Tk_ChooseColorObjCmd(
/* This doesn't seem to actually set the title! */
Tcl_UtfToExternal(NULL, NULL, title, -1, 0, NULL,
- StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL);
+ StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL);
StrLength(cpinfo.prompt) = (unsigned char) dstWrote;
if ((PickColor(&cpinfo) == noErr) && (cpinfo.newColorChosen != 0)) {
- in.red = cpinfo.theColor.color.rgb.red;
- in.green = cpinfo.theColor.color.rgb.green;
- in.blue = cpinfo.theColor.color.rgb.blue;
+ in.red = cpinfo.theColor.color.rgb.red;
+ in.green = cpinfo.theColor.color.rgb.green;
+ in.blue = cpinfo.theColor.color.rgb.blue;
picked = 1;
}
@@ -235,24 +239,24 @@ Tk_ChooseColorObjCmd(
*
* Tk_GetOpenFileObjCmd --
*
- * This procedure implements the "open file" dialog box for the Mac
- * platform. See the user documentation for details on what it does.
+ * This procedure implements the "open file" dialog box for the
+ * Mac platform. See the user documentation for details on what
+ * it does.
*
* Results:
- * A standard Tcl result.
+ * A standard Tcl result.
*
* Side effects:
- * See user documentation.
- *
+ * See user documentation.
*----------------------------------------------------------------------
*/
int
Tk_GetOpenFileObjCmd(
- ClientData clientData, /* Main window associated with interpreter. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+ ClientData clientData, /* Main window associated with interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int i, result, multiple;
OpenFileData ofd;
@@ -264,12 +268,16 @@ Tk_GetOpenFileObjCmd(
AEDescList selectDesc = {typeNull, NULL};
char *initialFile = NULL, *initialDir = NULL;
static CONST char *openOptionStrings[] = {
- "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
- "-message", "-multiple", "-parent", "-title", NULL
+ "-defaultextension", "-filetypes",
+ "-initialdir", "-initialfile",
+ "-message", "-multiple",
+ "-parent", "-title", NULL
};
enum openOptions {
- OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE,
- OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE
+ OPEN_DEFAULT, OPEN_FILETYPES,
+ OPEN_INITDIR, OPEN_INITFILE,
+ OPEN_MESSAGE, OPEN_MULTIPLE,
+ OPEN_PARENT, OPEN_TITLE
};
if (!fileDlgInited) {
@@ -284,9 +292,9 @@ Tk_GetOpenFileObjCmd(
TkInitFileFilters(&ofd.fl);
- ofd.curType = 0;
- ofd.popupItem = OPEN_POPUP_ITEM;
- ofd.usePopup = 1;
+ ofd.curType = 0;
+ ofd.popupItem = OPEN_POPUP_ITEM;
+ ofd.usePopup = 1;
for (i = 1; i < objc; i += 2) {
char *choice;
@@ -307,57 +315,55 @@ Tk_GetOpenFileObjCmd(
}
switch (index) {
- case OPEN_DEFAULT:
- break;
- case OPEN_FILETYPES:
- if (TkGetFileFilters(interp, &ofd.fl, objv[i + 1], 0) != TCL_OK) {
- result = TCL_ERROR;
- goto end;
- }
- break;
- case OPEN_INITDIR:
- initialDir = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- /* empty strings should be like no selection given */
- if (choiceLen == 0) {
- initialDir = NULL;
- }
- break;
- case OPEN_INITFILE:
- initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL);
- /* empty strings should be like no selection given */
- if (choiceLen == 0) {
- initialFile = NULL;
- }
- break;
- case OPEN_MESSAGE:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- message = CFStringCreateWithBytes(NULL, (unsigned char*) choice,
- choiceLen, kCFStringEncodingUTF8, false);
- break;
- case OPEN_MULTIPLE:
- if (Tcl_GetBooleanFromObj(interp, objv[i+1], &multiple)!=TCL_OK) {
- result = TCL_ERROR;
- goto end;
- }
- break;
- case OPEN_PARENT:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- parent = Tk_NameToWindow(interp, choice, parent);
- if (parent == NULL) {
- result = TCL_ERROR;
- goto end;
- }
- break;
- case OPEN_TITLE:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- title = CFStringCreateWithBytes(NULL, (unsigned char*) choice,
- choiceLen, kCFStringEncodingUTF8, false);
- break;
+ case OPEN_DEFAULT:
+ break;
+ case OPEN_FILETYPES:
+ if (TkGetFileFilters(interp, &ofd.fl, objv[i + 1], 0)
+ != TCL_OK) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ break;
+ case OPEN_INITDIR:
+ initialDir = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ /* empty strings should be like no selection given */
+ if (choiceLen == 0) { initialDir = NULL; }
+ break;
+ case OPEN_INITFILE:
+ initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL);
+ /* empty strings should be like no selection given */
+ if (choiceLen == 0) { initialFile = NULL; }
+ break;
+ case OPEN_MESSAGE:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
+ break;
+ case OPEN_MULTIPLE:
+ if (Tcl_GetBooleanFromObj(interp, objv[i + 1], &multiple)
+ != TCL_OK) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ break;
+ case OPEN_PARENT:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ parent = Tk_NameToWindow(interp, choice, parent);
+ if (parent == NULL) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ break;
+ case OPEN_TITLE:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
+ break;
}
}
if (HandleInitialDirectory(interp, initialFile, initialDir, &dirRef,
- &selectDesc, &initialDesc) != TCL_OK) {
+ &selectDesc, &initialDesc) != TCL_OK) {
result = TCL_ERROR;
goto end;
}
@@ -368,7 +374,7 @@ Tk_GetOpenFileObjCmd(
result = NavServicesGetFile(interp, &ofd, initialPtr,
NULL, &selectDesc, title, message, multiple, OPEN_FILE);
- end:
+ end:
TkFreeFileFilters(&ofd.fl);
AEDisposeDesc(&initialDesc);
AEDisposeDesc(&selectDesc);
@@ -414,12 +420,12 @@ Tk_GetSaveFileObjCmd(
CFStringRef title, message;
OpenFileData ofd;
static CONST char *saveOptionStrings[] = {
- "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
- "-message", "-parent", "-title", NULL
+ "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
+ "-message", "-parent", "-title", NULL
};
enum saveOptions {
- SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE,
- SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE
+ SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE,
+ SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE
};
if (!fileDlgInited) {
@@ -432,59 +438,59 @@ Tk_GetSaveFileObjCmd(
message = NULL;
for (i = 1; i < objc; i += 2) {
- char *choice, *string;
+ char *choice;
int index, choiceLen;
+ char *string;
if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option",
TCL_EXACT, &index) != TCL_OK) {
return TCL_ERROR;
}
if (i + 1 == objc) {
- string = Tcl_GetString(objv[i]);
+ string = Tcl_GetStringFromObj(objv[i], NULL);
Tcl_AppendResult(interp, "value for \"", string, "\" missing",
- NULL);
+ (char *) NULL);
return TCL_ERROR;
}
switch (index) {
- case SAVE_DEFAULT:
- break;
- case SAVE_FILETYPES:
- /* Currently unimplemented - what would we do here anyway? */
- break;
- case SAVE_INITDIR:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- /* empty strings should be like no selection given */
- if (choiceLen && HandleInitialDirectory(interp, NULL, choice,
- &dirRef, NULL, &initialDesc) != TCL_OK) {
- result = TCL_ERROR;
- goto end;
- }
- break;
- case SAVE_INITFILE:
- initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- /* empty strings should be like no selection given */
- if (choiceLen == 0) {
- initialFile = NULL;
- }
- break;
- case SAVE_MESSAGE:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- message = CFStringCreateWithBytes(NULL, (unsigned char*) choice,
- choiceLen, kCFStringEncodingUTF8, false);
- break;
- case SAVE_PARENT:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- parent = Tk_NameToWindow(interp, choice, parent);
- if (parent == NULL) {
- result = TCL_ERROR;
- goto end;
- }
- break;
- case SAVE_TITLE:
- choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- title = CFStringCreateWithBytes(NULL, (unsigned char*) choice,
- choiceLen, kCFStringEncodingUTF8, false);
- break;
+ case SAVE_DEFAULT:
+ break;
+ case SAVE_FILETYPES:
+ /* Currently unimplemented - what would we do here anyway? */
+ break;
+ case SAVE_INITDIR:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ /* empty strings should be like no selection given */
+ if (choiceLen &&
+ HandleInitialDirectory(interp, NULL, choice, &dirRef,
+ NULL, &initialDesc) != TCL_OK) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ break;
+ case SAVE_INITFILE:
+ initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ /* empty strings should be like no selection given */
+ if (choiceLen == 0) { initialFile = NULL; }
+ break;
+ case SAVE_MESSAGE:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
+ break;
+ case SAVE_PARENT:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ parent = Tk_NameToWindow(interp, choice, parent);
+ if (parent == NULL) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ break;
+ case SAVE_TITLE:
+ choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
+ title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
+ break;
}
}
@@ -495,9 +501,10 @@ Tk_GetSaveFileObjCmd(
initialPtr = &initialDesc;
}
result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL,
- title, message, false, SAVE_FILE);
+ title, message, false, SAVE_FILE);
+
+ end:
- end:
AEDisposeDesc(&initialDesc);
if (title != NULL) {
CFRelease(title);
@@ -514,26 +521,26 @@ Tk_GetSaveFileObjCmd(
*
* Tk_ChooseDirectoryObjCmd --
*
- * This procedure implements the "tk_chooseDirectory" dialog box for the
- * Windows platform. See the user documentation for details on what it
- * does.
+ * This procedure implements the "tk_chooseDirectory" dialog box
+ * for the Windows platform. See the user documentation for details
+ * on what it does.
*
* Results:
- * See user documentation.
+ * See user documentation.
*
* Side effects:
- * A modal dialog window is created. Tcl_SetServiceMode() is called to
- * allow background events to be processed
+ * A modal dialog window is created. Tcl_SetServiceMode() is
+ * called to allow background events to be processed
*
*----------------------------------------------------------------------
*/
int
-Tk_ChooseDirectoryObjCmd(
- ClientData clientData, /* Main window associated with interpreter. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
+ ClientData clientData; /* Main window associated with interpreter. */
+ Tcl_Interp *interp; /* Current interpreter. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj *CONST objv[]; /* Argument objects. */
{
int i, result;
Tk_Window parent;
@@ -589,8 +596,8 @@ Tk_ChooseDirectoryObjCmd(
break;
case CHOOSE_MESSAGE:
choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- message = CFStringCreateWithBytes(NULL, (unsigned char*)choice,
- choiceLen, kCFStringEncodingUTF8, false);
+ message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
break;
case CHOOSE_PARENT:
choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
@@ -602,8 +609,8 @@ Tk_ChooseDirectoryObjCmd(
break;
case CHOOSE_TITLE:
choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen);
- title = CFStringCreateWithBytes(NULL, (unsigned char*) choice,
- choiceLen, kCFStringEncodingUTF8, false);
+ title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen,
+ kCFStringEncodingUTF8, false);
break;
}
}
@@ -628,7 +635,7 @@ Tk_ChooseDirectoryObjCmd(
return result;
}
-
+
int
HandleInitialDirectory (
Tcl_Interp *interp,
@@ -695,21 +702,21 @@ HandleInitialDirectory (
AEDisposeDesc(&fileDesc);
}
- end:
+end:
if (dirName != NULL) {
Tcl_DStringFree(&ds);
}
return result;
}
-
+
static void
-InitFileDialogs(void)
+InitFileDialogs()
{
fileDlgInited = 1;
openFileFilterUPP = NewNavObjectFilterUPP(OpenFileFilterProc);
openFileEventUPP = NewNavEventUPP(OpenEventProc);
}
-
+
static int
NavServicesGetFile(
Tcl_Interp *interp,
@@ -731,13 +738,13 @@ NavServicesGetFile(
int result;
err = NavGetDefaultDialogCreationOptions(&diagOptions);
- if (err != noErr) {
+ if (err!=noErr) {
return TCL_ERROR;
}
diagOptions.location.h = -1;
diagOptions.location.v = -1;
diagOptions.optionFlags = kNavDontAutoTranslate
- + kNavDontAddTranslateItems;
+ + kNavDontAddTranslateItems;
if (multiple) {
diagOptions.optionFlags += kNavAllowMultipleFiles;
}
@@ -757,8 +764,8 @@ NavServicesGetFile(
int index = 0;
ofdPtr->curType = 0;
- menuItemNames = (CFStringRef *)
- ckalloc(ofdPtr->fl.numFilters * sizeof(CFStringRef));
+ menuItemNames = (CFStringRef *)ckalloc(ofdPtr->fl.numFilters
+ * sizeof(CFStringRef));
for (filterPtr = ofdPtr->fl.filters; filterPtr != NULL;
filterPtr = filterPtr->next, index++) {
@@ -773,14 +780,13 @@ NavServicesGetFile(
}
/*
- * This is required to allow App packages to be selectable in the file
- * dialogs...
+ * This is required to allow App packages to be selectable in the
+ * file dialogs...
*/
diagOptions.optionFlags += kNavSupportPackages;
- diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish",
- kCFStringEncodingUTF8);
+ diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish", kCFStringEncodingUTF8);
diagOptions.message = message;
diagOptions.windowTitle = title;
if (initialFile) {
@@ -795,25 +801,42 @@ NavServicesGetFile(
diagOptions.preferenceKey = 0;
/*
- * Now process the selection list. We have to use the popupExtension to
- * fill the menu.
+ * Now process the selection list. We have to use the popupExtension
+ * to fill the menu.
*/
if (isOpen == OPEN_FILE) {
- err = NavCreateGetFileDialog(&diagOptions, NULL, openFileEventUPP,
- NULL, openFileFilterUPP, ofdPtr, &dialogRef);
- LOG_ON_ERROR(NavCreateGetFileDialog);
+ err = NavCreateGetFileDialog(&diagOptions,
+ NULL,
+ openFileEventUPP,
+ NULL,
+ openFileFilterUPP,
+ ofdPtr,
+ &dialogRef);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"NavCreateGetFileDialog failed, %d\n", err);
+#endif
+ dialogRef = NULL;
+ }
} else if (isOpen == SAVE_FILE) {
err = NavCreatePutFileDialog(&diagOptions, 'TEXT', 'WIsH',
openFileEventUPP, NULL, &dialogRef);
- LOG_ON_ERROR(NavCreatePutFileDialog);
+ if (err!=noErr){
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"NavCreatePutFileDialog failed, %d\n", err);
+#endif
+ dialogRef = NULL;
+ }
} else if (isOpen == CHOOSE_FOLDER) {
err = NavCreateChooseFolderDialog(&diagOptions, openFileEventUPP,
openFileFilterUPP, NULL, &dialogRef);
- LOG_ON_ERROR(NavCreateChooseFolderDialog);
- }
- if (err != noErr) {
- dialogRef = NULL;
+ if (err!=noErr){
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"NavCreateChooseFolderDialog failed, %d\n", err);
+#endif
+ dialogRef = NULL;
+ }
}
if (dialogRef) {
@@ -825,11 +848,16 @@ NavServicesGetFile(
NavCustomControl(dialogRef, kNavCtlSetSelection, selectDescPtr);
}
- err = NavDialogRun(dialogRef);
- LOG_ON_ERROR(NavDialogRun);
- if (err == noErr) {
- err = NavDialogGetReply(dialogRef, &theReply);
- LOG_ON_ERROR(NavDialogGetReply);
+ if ((err = NavDialogRun(dialogRef)) != noErr){
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"NavDialogRun failed, %d\n", err);
+#endif
+ } else {
+ if ((err = NavDialogGetReply(dialogRef, &theReply)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"NavGetReply failed, %d\n", err);
+#endif
+ }
}
}
@@ -850,57 +878,68 @@ NavServicesGetFile(
if (theReply.validRecord && err == noErr) {
AEDesc resultDesc;
long count;
- FSRef fsRef;
- char pathPtr[1024];
- int pathValid = 0;
-
+ FSRef fsRef;
+ char pathPtr[1024];
+ int pathValid = 0;
err = AECountItems(&theReply.selection, &count);
if (err == noErr) {
long i;
-
for (i = 1; i <= count; i++) {
- err = AEGetNthDesc(&theReply.selection, i, typeFSRef, NULL,
- &resultDesc);
+ err = AEGetNthDesc(&theReply.selection,
+ i, typeFSRef, NULL, &resultDesc);
pathValid = 0;
- if (err != noErr) {
- continue;
- }
- err = AEGetDescData(&resultDesc, &fsRef, sizeof(fsRef));
- LOG_ON_ERROR(AEGetDescData);
if (err == noErr) {
- err = FSRefMakePath(&fsRef, (unsigned char*) pathPtr,
- 1024);
- LOG_ON_ERROR(FSRefMakePath);
- if (err == noErr) {
- if (isOpen == SAVE_FILE) {
- CFStringRef saveNameRef;
- char saveName[1024];
-
- saveNameRef = NavDialogGetSaveFileName(dialogRef);
- if (!saveNameRef) {
- LOG_MSG("NavDialogGetSaveFileName failed");
- } else if (!CFStringGetCString(saveNameRef,
- saveName, 1024, kCFStringEncodingUTF8)) {
- LOG_MSG("CFStringGetCString failed");
- } else if (strlen(pathPtr)+strlen(saveName)<1023){
- strcat(pathPtr, "/");
- strcat(pathPtr, saveName);
- goto pathValid;
- } else {
- LOG_MSG("Path name too long");
- }
- }
+ if ((err = AEGetDescData(&resultDesc, &fsRef, sizeof(fsRef)))
+ != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"AEGetDescData failed %d\n", err);
+#endif
} else {
- pathValid:
- if (multiple) {
- Tcl_ListObjAppendElement(interp, theResult,
- Tcl_NewStringObj(pathPtr, -1));
+ if ((err = FSRefMakePath(&fsRef, (unsigned char*) pathPtr, 1024))) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"FSRefMakePath failed, %d\n", err);
+#endif
} else {
- Tcl_SetStringObj(theResult, pathPtr, -1);
+ if (isOpen == SAVE_FILE) {
+ CFStringRef saveNameRef;
+ char saveName [1024];
+ if ((saveNameRef = NavDialogGetSaveFileName(dialogRef))) {
+ if (CFStringGetCString(saveNameRef, saveName,
+ 1024, kCFStringEncodingUTF8)) {
+ if (strlen(pathPtr) + strlen(saveName) < 1023) {
+ strcat(pathPtr, "/");
+ strcat(pathPtr, saveName);
+ pathValid = 1;
+ } else {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "Path name too long\n");
+#endif
+ }
+ } else {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "CFStringGetCString failed\n");
+#endif
+ }
+ } else {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "NavDialogGetSaveFileName failed\n");
+#endif
+ }
+ } else {
+ pathValid = 1;
+ }
+ if (pathValid) {
+ if (multiple) {
+ Tcl_ListObjAppendElement(interp, theResult,
+ Tcl_NewStringObj(pathPtr, -1));
+ } else {
+ Tcl_SetStringObj(theResult, pathPtr, -1);
+ }
+ }
}
}
+ AEDisposeDesc(&resultDesc);
}
- AEDisposeDesc(&resultDesc);
}
}
err = NavDisposeReply(&theReply);
@@ -929,14 +968,12 @@ NavServicesGetFile(
if (diagOptions.clientName) {
CFRelease(diagOptions.clientName);
}
-
/*
* dispose of the CFArray diagOptions.popupExtension
*/
if (menuItemNames) {
int i;
-
for (i = 0;i < ofdPtr->fl.numFilters; i++) {
CFRelease(menuItemNames[i]);
}
@@ -948,11 +985,10 @@ NavServicesGetFile(
return result;
}
-
+
static pascal Boolean
OpenFileFilterProc(
- AEDesc *theItem,
- void *info,
+ AEDesc* theItem, void* info,
NavCallBackUserData callBackUD,
NavFilterModes filterMode)
{
@@ -960,86 +996,94 @@ OpenFileFilterProc(
if (!ofdPtr || !ofdPtr->usePopup) {
return true;
- }
-
- if (ofdPtr->fl.numFilters == 0) {
- return true;
- }
-
- if ((theItem->descriptorType == typeFSS)
- || (theItem->descriptorType = typeFSRef)) {
- NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info;
- char fileName[256];
- int result, i, len;
- OSType fileType;
- StringPtr fileNamePtr;
- Tcl_DString fileNameDString;
- FileFilter *filterPtr;
-
- if (!theInfo->isFolder) {
- fileType = theInfo->fileAndFolder.fileInfo.finderInfo.fdType;
- Tcl_DStringInit(&fileNameDString);
-
- if (theItem->descriptorType == typeFSS) {
- fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name);
- len = fileNamePtr[0];
- strncpy(fileName, (char*) fileNamePtr + 1, len);
- fileName[len] = '\0';
- fileNamePtr = (unsigned char*) fileName;
- } else if ((theItem->descriptorType = typeFSRef)) {
- OSStatus err;
- FSRef *theRef = (FSRef *) *theItem->dataHandle;
- HFSUniStr255 uniFileName;
-
- err = FSGetCatalogInfo(theRef, kFSCatInfoNone, NULL,
- &uniFileName, NULL, NULL);
+ } else {
+ if (ofdPtr->fl.numFilters == 0) {
+ return true;
+ } else {
+ if ((theItem->descriptorType == typeFSS)
+ || (theItem->descriptorType = typeFSRef)) {
+ NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info;
+ char fileName[256];
+ int result;
+
+ if (!theInfo->isFolder) {
+ OSType fileType;
+ StringPtr fileNamePtr;
+ Tcl_DString fileNameDString;
+ int i;
+ FileFilter *filterPtr;
+
+ fileType =
+ theInfo->fileAndFolder.fileInfo.finderInfo.fdType;
+ Tcl_DStringInit (&fileNameDString);
+
+ if (theItem->descriptorType == typeFSS) {
+ int len;
+ fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name);
+ len = fileNamePtr[0];
+ strncpy(fileName, (char*) fileNamePtr + 1, len);
+ fileName[len] = '\0';
+ fileNamePtr = (unsigned char*) fileName;
+
+ } else if ((theItem->descriptorType = typeFSRef)) {
+ OSStatus err;
+ FSRef *theRef = (FSRef *) *theItem->dataHandle;
+ HFSUniStr255 uniFileName;
+ err = FSGetCatalogInfo (theRef, kFSCatInfoNone, NULL,
+ &uniFileName, NULL, NULL);
+
+ if (err == noErr) {
+ Tcl_UniCharToUtfDString (
+ (Tcl_UniChar *) uniFileName.unicode,
+ uniFileName.length,
+ &fileNameDString);
+ fileNamePtr = (unsigned char*) Tcl_DStringValue(&fileNameDString);
+ } else {
+ fileNamePtr = NULL;
+ }
+ }
+ if (ofdPtr->usePopup) {
+ i = ofdPtr->curType;
+ for (filterPtr = ofdPtr->fl.filters;
+ filterPtr && i > 0; i--) {
+ filterPtr = filterPtr->next;
+ }
+ if (filterPtr) {
+ result = MatchOneType(fileNamePtr, fileType,
+ ofdPtr, filterPtr);
+ } else {
+ result = false;
+ }
+ } else {
+ /*
+ * We are not using the popup menu. In this case, the
+ * file is considered matched if it matches any of
+ * the file filters.
+ */
+
+ result = UNMATCHED;
+ for (filterPtr = ofdPtr->fl.filters; filterPtr;
+ filterPtr = filterPtr->next) {
+ if (MatchOneType(fileNamePtr, fileType,
+ ofdPtr, filterPtr) == MATCHED) {
+ result = MATCHED;
+ break;
+ }
+ }
+ }
- if (err == noErr) {
- Tcl_UniCharToUtfDString(
- (Tcl_UniChar *) uniFileName.unicode,
- uniFileName.length, &fileNameDString);
- fileNamePtr = (unsigned char *)
- Tcl_DStringValue(&fileNameDString);
+ Tcl_DStringFree (&fileNameDString);
+ return (result == MATCHED);
} else {
- fileNamePtr = NULL;
+ return true;
}
}
- if (ofdPtr->usePopup) {
- i = ofdPtr->curType;
- for (filterPtr=ofdPtr->fl.filters ; filterPtr && i>0 ; i--) {
- filterPtr = filterPtr->next;
- }
- if (filterPtr) {
- result = MatchOneType(fileNamePtr, fileType, ofdPtr,
- filterPtr);
- } else {
- result = UNMATCHED;
- }
- } else {
- /*
- * We are not using the popup menu. In this case, the file is
- * considered matched if it matches any of the file filters.
- */
-
- result = UNMATCHED;
- for (filterPtr = ofdPtr->fl.filters; filterPtr;
- filterPtr = filterPtr->next) {
- if (MatchOneType(fileNamePtr, fileType,
- ofdPtr, filterPtr) == MATCHED) {
- result = MATCHED;
- break;
- }
- }
- }
-
- Tcl_DStringFree(&fileNameDString);
- return (result == MATCHED);
}
- }
- return true;
+ return true;
+ }
}
-
+
pascal void
OpenEventProc(
NavEventCallbackMessage callBackSelector,
@@ -1053,12 +1097,12 @@ OpenEventProc(
|kNavCBCancel|kNavCBAdjustPreview);
if (callBackSelector == kNavCBPopupMenuSelect) {
- chosenItem = (NavMenuItemSpec *)
- callBackParams->eventData.eventDataParms.param;
+ chosenItem = (NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param;
ofd->curType = chosenItem->menuType;
} else if (callBackSelector == kNavCBAdjustRect
|| (callBackSelector & otherEvent) != 0) {
- while (Tcl_DoOneEvent(TCL_IDLE_EVENTS | TCL_DONT_WAIT
+ while (Tcl_DoOneEvent(TCL_IDLE_EVENTS
+ | TCL_DONT_WAIT
| TCL_WINDOW_EVENTS)) {
/* Empty Body */
}
@@ -1070,52 +1114,51 @@ OpenEventProc(
*
* MatchOneType --
*
- * Match a file with one file type in the list of file types.
+ * Match a file with one file type in the list of file types.
*
* Results:
- * Returns MATCHED if the file matches with the file type; returns
- * UNMATCHED otherwise.
+ * Returns MATCHED if the file matches with the file type; returns
+ * UNMATCHED otherwise.
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
static Boolean
MatchOneType(
- StringPtr fileNamePtr, /* Name of the file */
- OSType fileType, /* Type of the file, 0 means there was no
- * specified type. */
- OpenFileData *ofdPtr, /* Information about this file dialog */
- FileFilter *filterPtr) /* Match the file described by pb against this
- * filter */
+ StringPtr fileNamePtr, /* Name of the file */
+ OSType fileType, /* Type of the file, 0 means there was no specified type. */
+ OpenFileData * ofdPtr, /* Information about this file dialog */
+ FileFilter * filterPtr) /* Match the file described by pb against
+ * this filter */
{
- FileFilterClause *clausePtr;
+ FileFilterClause * clausePtr;
/*
- * A file matches with a file type if it matches with at least one clause
- * of the type.
+ * A file matches with a file type if it matches with at least one
+ * clause of the type.
*
- * If the clause has both glob patterns and ostypes, the file must match
- * with at least one pattern AND at least one ostype.
+ * If the clause has both glob patterns and ostypes, the file must
+ * match with at least one pattern AND at least one ostype.
*
* If the clause has glob patterns only, the file must match with at least
* one pattern.
*
- * If the clause has mac types only, the file must match with at least one
- * mac type.
+ * If the clause has mac types only, the file must match with at least
+ * one mac type.
*
- * If the clause has neither glob patterns nor mac types, it's considered
- * an error.
+ * If the clause has neither glob patterns nor mac types, it's
+ * considered an error.
*/
for (clausePtr = filterPtr->clauses; clausePtr;
clausePtr = clausePtr->next) {
- int macMatched = 0;
+ int macMatched = 0;
int globMatched = 0;
- GlobPattern *globPtr;
- MacFileType *mfPtr;
+ GlobPattern * globPtr;
+ MacFileType * mfPtr;
if (clausePtr->patterns == NULL) {
globMatched = 1;
@@ -1153,10 +1196,10 @@ MatchOneType(
goto glob_unmatched;
}
- glob_unmatched:
+ glob_unmatched:
continue;
- glob_matched:
+ glob_matched:
globMatched = 1;
break;
}
@@ -1169,12 +1212,13 @@ MatchOneType(
}
/*
- * On Mac OS X, it is not uncommon for files to have NO file type.
- * But folks with Tcl code on Classic MacOS pretty much assume that a
- * generic file will have type TEXT. So if we were strict about
- * matching types when the source file had NO type set, they would
- * have to add another rule always with no fileType. To avoid that, we
- * pass the macMatch side of the test if no fileType is set.
+ * On Mac OS X, it is not uncommon for files to have NO
+ * file type. But folks with Tcl code on Classic MacOS pretty
+ * much assume that a generic file will have type TEXT. So
+ * if we were strict about matching types when the source file
+ * had NO type set, they would have to add another rule always
+ * with no fileType. To avoid that, we pass the macMatch side
+ * of the test if no fileType is set.
*/
if (globMatched && (macMatched || (fileType == 0))) {
@@ -1184,26 +1228,26 @@ MatchOneType(
return UNMATCHED;
}
-
+
/*
*----------------------------------------------------------------------
*
* TkAboutDlg --
*
- * Displays the default Tk About box. This code uses Macintosh resources
- * to define the content of the About Box.
+ * Displays the default Tk About box. This code uses Macintosh
+ * resources to define the content of the About Box.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
void
-TkAboutDlg(void)
+TkAboutDlg()
{
DialogPtr aboutDlog;
WindowRef windowRef;
@@ -1228,83 +1272,95 @@ TkAboutDlg(void)
return;
}
-
+
/*
*----------------------------------------------------------------------
*
* Tk_MessageBoxObjCmd --
*
- * Implements the tk_messageBox in native Mac OS X style.
+ * Implements the tk_messageBox in native Mac OS X style.
*
* Results:
- * A standard Tcl result.
+ * A standard Tcl result.
*
* Side effects:
- * none
+ * none
*
*----------------------------------------------------------------------
*/
int
Tk_MessageBoxObjCmd(
- ClientData clientData, /* Main window associated with interpreter. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+ ClientData clientData, /* Main window associated with interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
- Tk_Window tkwin = (Tk_Window) clientData;
+ Tk_Window tkwin = (Tk_Window) clientData;
AlertStdCFStringAlertParamRec paramCFStringRec;
- AlertType alertType;
- DialogRef dialogRef;
- CFStringRef messageTextCF = NULL;
- CFStringRef finemessageTextCF = NULL;
- OSErr osError;
- SInt16 itemHit;
- Boolean haveDefaultOption = false, haveParentOption = false;
- char *str;
- int defaultButtonIndex;
- int defaultNativeButtonIndex; /* 1, 2, 3: right to left. */
- int index, typeIndex, i;
- int indexDefaultOption = 0;
- int result = TCL_OK;
+ AlertType alertType;
+ DialogRef dialogRef;
+ CFStringRef messageTextCF = NULL;
+ CFStringRef finemessageTextCF = NULL;
+ OSErr osError;
+ SInt16 itemHit;
+ Boolean haveDefaultOption = false;
+ Boolean haveParentOption = false;
+ char *str;
+ int index;
+ int defaultButtonIndex;
+ int defaultNativeButtonIndex; /* 1, 2, 3: right to left. */
+ int typeIndex;
+ int i;
+ int indexDefaultOption = 0;
+ int result = TCL_OK;
static CONST char *movableAlertStrings[] = {
- "-default", "-detail", "-icon", "-message", "-parent", "-title",
- "-type", NULL
+ "-default", "-detail", "-icon",
+ "-message", "-parent",
+ "-title", "-type",
+ (char *)NULL
};
static CONST char *movableTypeStrings[] = {
- "abortretryignore", "ok", "okcancel", "retrycancel", "yesno",
- "yesnocancel", NULL
+ "abortretryignore", "ok",
+ "okcancel", "retrycancel",
+ "yesno", "yesnocancel",
+ (char *)NULL
};
static CONST char *movableButtonStrings[] = {
- "abort", "retry", "ignore", "ok", "cancel", "yes", "no", NULL
+ "abort", "retry", "ignore",
+ "ok", "cancel", "yes", "no",
+ (char *)NULL
};
static CONST char *movableIconStrings[] = {
- "error", "info", "question", "warning", NULL
+ "error", "info", "question", "warning",
+ (char *)NULL
};
enum movableAlertOptions {
- ALERT_DEFAULT, ALERT_DETAIL, ALERT_ICON, ALERT_MESSAGE, ALERT_PARENT,
+ ALERT_DEFAULT, ALERT_DETAIL, ALERT_ICON,
+ ALERT_MESSAGE, ALERT_PARENT,
ALERT_TITLE, ALERT_TYPE
};
enum movableTypeOptions {
- TYPE_ABORTRETRYIGNORE, TYPE_OK, TYPE_OKCANCEL, TYPE_RETRYCANCEL,
+ TYPE_ABORTRETRYIGNORE, TYPE_OK,
+ TYPE_OKCANCEL, TYPE_RETRYCANCEL,
TYPE_YESNO, TYPE_YESNOCANCEL
};
enum movableButtonOptions {
- TEXT_ABORT, TEXT_RETRY, TEXT_IGNORE, TEXT_OK, TEXT_CANCEL, TEXT_YES,
- TEXT_NO
+ TEXT_ABORT, TEXT_RETRY, TEXT_IGNORE,
+ TEXT_OK, TEXT_CANCEL, TEXT_YES, TEXT_NO
};
enum movableIconOptions {
ICON_ERROR, ICON_INFO, ICON_QUESTION, ICON_WARNING
};
/*
- * Need to map from 'movableButtonStrings' and its corresponding integer
- * index, to the native button index, which is 1, 2, 3, from right to
- * left. This is necessary to do for each separate '-type' of button sets.
+ * Need to map from 'movableButtonStrings' and its corresponding integer index,
+ * to the native button index, which is 1, 2, 3, from right to left.
+ * This is necessary to do for each separate '-type' of button sets.
*/
- short buttonIndexAndTypeToNativeButtonIndex[][7] = {
+ short buttonIndexAndTypeToNativeButtonIndex[][7] = {
/* abort retry ignore ok cancel yes no */
{1, 2, 3, 0, 0, 0, 0}, /* abortretryignore */
{0, 0, 0, 1, 0, 0, 0}, /* ok */
@@ -1319,7 +1375,7 @@ Tk_MessageBoxObjCmd(
* descriptive button text string index.
*/
- short nativeButtonIndexAndTypeToButtonIndex[][4] = {
+ short nativeButtonIndexAndTypeToButtonIndex[][4] = {
{-1, 0, 1, 2}, /* abortretryignore */
{-1, 3, 0, 0}, /* ok */
{-1, 3, 4, 0}, /* okcancel */
@@ -1331,77 +1387,76 @@ Tk_MessageBoxObjCmd(
alertType = kAlertPlainAlert;
typeIndex = TYPE_OK;
- GetStandardAlertDefaultParams(&paramCFStringRec,
- kStdCFStringAlertVersionOne);
+ GetStandardAlertDefaultParams(&paramCFStringRec, kStdCFStringAlertVersionOne);
paramCFStringRec.movable = true;
paramCFStringRec.helpButton = false;
paramCFStringRec.defaultButton = kAlertStdAlertOKButton;
paramCFStringRec.cancelButton = kAlertStdAlertCancelButton;
for (i = 1; i < objc; i += 2) {
- int iconIndex;
- char *string;
+ int iconIndex;
+ char *string;
if (Tcl_GetIndexFromObj(interp, objv[i], movableAlertStrings, "option",
- TCL_EXACT, &index) != TCL_OK) {
+ TCL_EXACT, &index) != TCL_OK) {
result = TCL_ERROR;
goto end;
}
if (i + 1 == objc) {
string = Tcl_GetStringFromObj(objv[i], NULL);
Tcl_AppendResult(interp, "value for \"", string, "\" missing",
- NULL);
+ (char *) NULL);
result = TCL_ERROR;
goto end;
}
switch (index) {
- case ALERT_DEFAULT:
+
+ case ALERT_DEFAULT:
+
/*
- * Need to postpone processing of this option until we are sure to
- * know the '-type' as well.
+ * Need to postpone processing of this option until we are
+ * sure to know the '-type' as well.
*/
haveDefaultOption = true;
indexDefaultOption = i;
break;
- case ALERT_DETAIL:
+ case ALERT_DETAIL:
str = Tcl_GetStringFromObj(objv[i + 1], NULL);
- finemessageTextCF = CFStringCreateWithCString(NULL, str,
- kCFStringEncodingUTF8);
+ finemessageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8);
break;
- case ALERT_ICON:
- /* not sure about UTF translation here... */
+ case ALERT_ICON:
+ /* not sure about UTF translation here... */
if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableIconStrings,
- "value", TCL_EXACT, &iconIndex) != TCL_OK) {
+ "value", TCL_EXACT, &iconIndex) != TCL_OK) {
result = TCL_ERROR;
goto end;
}
switch (iconIndex) {
- case ICON_ERROR:
+ case ICON_ERROR:
alertType = kAlertStopAlert;
break;
- case ICON_INFO:
+ case ICON_INFO:
alertType = kAlertNoteAlert;
break;
- case ICON_QUESTION:
+ case ICON_QUESTION:
alertType = kAlertCautionAlert;
break;
- case ICON_WARNING:
+ case ICON_WARNING:
alertType = kAlertCautionAlert;
break;
}
break;
- case ALERT_MESSAGE:
+ case ALERT_MESSAGE:
str = Tcl_GetStringFromObj(objv[i + 1], NULL);
- messageTextCF = CFStringCreateWithCString(NULL, str,
- kCFStringEncodingUTF8);
+ messageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8);
break;
- case ALERT_PARENT:
+ case ALERT_PARENT:
str = Tcl_GetStringFromObj(objv[i + 1], NULL);
tkwin = Tk_NameToWindow(interp, str, tkwin);
if (tkwin == NULL) {
@@ -1411,39 +1466,39 @@ Tk_MessageBoxObjCmd(
haveParentOption = true;
break;
- case ALERT_TITLE:
+ case ALERT_TITLE:
break;
- case ALERT_TYPE:
- /* not sure about UTF translation here... */
+ case ALERT_TYPE:
+ /* not sure about UTF translation here... */
if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableTypeStrings,
- "value", TCL_EXACT, &typeIndex) != TCL_OK) {
+ "value", TCL_EXACT, &typeIndex) != TCL_OK) {
result = TCL_ERROR;
goto end;
}
switch (typeIndex) {
- case TYPE_ABORTRETRYIGNORE:
+ case TYPE_ABORTRETRYIGNORE:
paramCFStringRec.defaultText = CFSTR("Abort");
paramCFStringRec.cancelText = CFSTR("Retry");
paramCFStringRec.otherText = CFSTR("Ignore");
paramCFStringRec.cancelButton = kAlertStdAlertOtherButton;
break;
- case TYPE_OK:
+ case TYPE_OK:
paramCFStringRec.defaultText = CFSTR("OK");
break;
- case TYPE_OKCANCEL:
+ case TYPE_OKCANCEL:
paramCFStringRec.defaultText = CFSTR("OK");
paramCFStringRec.cancelText = CFSTR("Cancel");
break;
- case TYPE_RETRYCANCEL:
+ case TYPE_RETRYCANCEL:
paramCFStringRec.defaultText = CFSTR("Retry");
paramCFStringRec.cancelText = CFSTR("Cancel");
break;
- case TYPE_YESNO:
+ case TYPE_YESNO:
paramCFStringRec.defaultText = CFSTR("Yes");
paramCFStringRec.cancelText = CFSTR("No");
break;
- case TYPE_YESNOCANCEL:
+ case TYPE_YESNOCANCEL:
paramCFStringRec.defaultText = CFSTR("Yes");
paramCFStringRec.cancelText = CFSTR("No");
paramCFStringRec.otherText = CFSTR("Cancel");
@@ -1457,27 +1512,25 @@ Tk_MessageBoxObjCmd(
if (haveDefaultOption) {
/*
- * Any '-default' option needs to know the '-type' option, which is
- * why we do this here.
+ * Any '-default' option needs to know the '-type' option, which is why
+ * we do this here.
*/
str = Tcl_GetStringFromObj(objv[indexDefaultOption + 1], NULL);
if (Tcl_GetIndexFromObj(interp, objv[indexDefaultOption + 1],
- movableButtonStrings, "value", TCL_EXACT,
- &defaultButtonIndex) != TCL_OK) {
+ movableButtonStrings, "value", TCL_EXACT,
+ &defaultButtonIndex) != TCL_OK) {
result = TCL_ERROR;
goto end;
}
- /*
- * Need to map from "ok" etc. to 1, 2, 3, right to left.
- */
+ /* Need to map from "ok" etc. to 1, 2, 3, right to left. */
defaultNativeButtonIndex =
buttonIndexAndTypeToNativeButtonIndex[typeIndex][defaultButtonIndex];
if (defaultNativeButtonIndex == 0) {
Tcl_SetObjResult(interp,
- Tcl_NewStringObj("Illegal default option", -1));
+ Tcl_NewStringObj("Illegal default option", -1));
result = TCL_ERROR;
goto end;
}
@@ -1489,11 +1542,11 @@ Tk_MessageBoxObjCmd(
SetThemeCursor(kThemeArrowCursor);
if (haveParentOption) {
- TkWindow *winPtr;
- WindowRef windowRef;
- EventTargetRef notifyTarget;
- EventHandlerUPP handler;
- CallbackUserData data;
+ TkWindow *winPtr;
+ WindowRef windowRef;
+ EventTargetRef notifyTarget;
+ EventHandlerUPP handler;
+ CallbackUserData data;
const EventTypeSpec kEvents[] = {
{kEventClassCommand, kEventProcessCommand}
};
@@ -1505,12 +1558,12 @@ Tk_MessageBoxObjCmd(
*/
windowRef = GetWindowFromPort(
- TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)));
+ TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)));
notifyTarget = GetWindowEventTarget(windowRef);
osError = CreateStandardSheet(alertType, messageTextCF,
- finemessageTextCF, &paramCFStringRec, notifyTarget,
- &dialogRef);
- if (osError != noErr) {
+ finemessageTextCF, &paramCFStringRec,
+ notifyTarget, &dialogRef);
+ if(osError != noErr) {
result = TCL_ERROR;
goto end;
}
@@ -1518,7 +1571,8 @@ Tk_MessageBoxObjCmd(
data.buttonIndex = 1;
handler = NewEventHandlerUPP(AlertHandler);
InstallEventHandler(notifyTarget, handler,
- GetEventTypeCount(kEvents), kEvents, &data, NULL);
+ GetEventTypeCount(kEvents),
+ kEvents, &data, NULL);
osError = ShowSheetWindow(GetDialogWindow(dialogRef), windowRef);
if(osError != noErr) {
result = TCL_ERROR;
@@ -1533,8 +1587,8 @@ Tk_MessageBoxObjCmd(
DisposeEventHandlerUPP(handler);
} else {
osError = CreateStandardAlert(alertType, messageTextCF,
- finemessageTextCF, &paramCFStringRec, &dialogRef);
- if (osError != noErr) {
+ finemessageTextCF, &paramCFStringRec, &dialogRef);
+ if(osError != noErr) {
result = TCL_ERROR;
goto end;
}
@@ -1544,8 +1598,8 @@ Tk_MessageBoxObjCmd(
goto end;
}
}
- if (osError == noErr) {
- int ind;
+ if(osError == noErr) {
+ int ind;
/*
* Map 'itemHit' (1, 2, 3) to descriptive text string.
@@ -1553,12 +1607,12 @@ Tk_MessageBoxObjCmd(
ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit];
Tcl_SetObjResult(interp,
- Tcl_NewStringObj(movableButtonStrings[ind], -1));
+ Tcl_NewStringObj(movableButtonStrings[ind], -1));
} else {
result = TCL_ERROR;
}
- end:
+ end:
if (finemessageTextCF != NULL) {
CFRelease(finemessageTextCF);
}
@@ -1567,7 +1621,7 @@ Tk_MessageBoxObjCmd(
}
return result;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -1585,27 +1639,24 @@ Tk_MessageBoxObjCmd(
*/
static OSStatus
-AlertHandler(
- EventHandlerCallRef callRef,
- EventRef eventRef,
- void *userData)
+AlertHandler(EventHandlerCallRef callRef, EventRef eventRef, void *userData)
{
- OSStatus result = eventNotHandledErr;
- HICommand cmd;
- CallbackUserData *dataPtr = (CallbackUserData *) userData;
+ OSStatus result = eventNotHandledErr;
+ HICommand cmd;
+ CallbackUserData *dataPtr = (CallbackUserData *) userData;
GetEventParameter(eventRef, kEventParamDirectObject, typeHICommand,
- NULL, sizeof(cmd), NULL, &cmd);
+ NULL, sizeof(cmd), NULL, &cmd);
switch (cmd.commandID) {
- case kHICommandOK:
+ case kHICommandOK:
dataPtr->buttonIndex = 1;
result = noErr;
break;
- case kHICommandCancel:
+ case kHICommandCancel:
dataPtr->buttonIndex = 2;
result = noErr;
break;
- case kHICommandOther:
+ case kHICommandOther:
dataPtr->buttonIndex = 3;
result = noErr;
break;
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index f4b8600..8ecb7d9 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -1,17 +1,18 @@
-/*
+/*
* tkMacOSXDraw.c --
*
- * This file contains functions that perform drawing to Xlib windows.
- * Most of the functions simple emulate Xlib functions.
+ * This file contains functions that perform drawing to
+ * Xlib windows. Most of the functions simple emulate
+ * Xlib functions.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2006 Daniel A. Steffen <das@users.sourceforge.net>
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.19 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.20 2007/04/21 19:06:37 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -23,17 +24,15 @@
#endif
*/
-#define RGBFLOATRED(c) ((c).red / 65535.0)
+#define RGBFLOATRED(c) ((c).red / 65535.0)
#define RGBFLOATGREEN(c) ((c).green / 65535.0)
-#define RGBFLOATBLUE(c) ((c).blue / 65535.0)
-#define radians(d) ((d) * (M_PI/180.0))
+#define RGBFLOATBLUE(c) ((c).blue / 65535.0)
+#define radians(d) ((d) * (M_PI/180.0))
/*
- * Non-antialiased CG drawing looks better and more like X11 drawing when
- * using very fine lines, so decrease all linewidths by the following
- * constant.
+ * Non-antialiased CG drawing looks better and more like X11 drawing when using
+ * very fine lines, so decrease all linewidths by the following constant.
*/
-
#define NON_AA_CG_OFFSET .999
/*
@@ -54,35 +53,33 @@ static int useThemedFrame = 0;
/*
* Prototypes for functions used only in this file.
*/
-
-static unsigned char InvertByte(unsigned char data);
-static void TkMacOSXSetUpCGContext(MacDrawable *macWin,
- CGrafPtr destPort, GC gc,
- CGContextRef *contextPtr);
-static void TkMacOSXReleaseCGContext(MacDrawable *macWin,
- CGrafPtr destPort, CGContextRef *context);
+static unsigned char InvertByte(unsigned char data);
+static void TkMacOSXSetUpCGContext(MacDrawable *macWin, CGrafPtr destPort,
+ GC gc, CGContextRef *contextPtr);
+static void TkMacOSXReleaseCGContext(MacDrawable *macWin, CGrafPtr destPort,
+ CGContextRef *context);
/*
*----------------------------------------------------------------------
*
* TkMacOSXInitCGDrawing --
*
- * Initializes link vars that control CG drawing.
+ * Initializes link vars that control CG drawing.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE int
-TkMacOSXInitCGDrawing(
- Tcl_Interp *interp,
- int enable,
- int limit)
+TkMacOSXInitCGDrawing(interp, enable, limit)
+ Tcl_Interp *interp;
+ int enable;
+ int limit;
{
static Boolean initialized = FALSE;
@@ -107,13 +104,12 @@ TkMacOSXInitCGDrawing(
/*
* Piggy-back the themed drawing var init here.
*/
-
if (Tcl_LinkVar(interp, "::tk::mac::useThemedToplevel",
- (char *) &useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
+ (char *) &useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
Tcl_ResetResult(interp);
}
if (Tcl_LinkVar(interp, "::tk::mac::useThemedFrame",
- (char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
+ (char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
Tcl_ResetResult(interp);
}
}
@@ -125,35 +121,36 @@ TkMacOSXInitCGDrawing(
*
* XCopyArea --
*
- * Copies data from one drawable to another using block transfer
- * routines.
+ * Copies data from one drawable to another using block transfer
+ * routines.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Data is moved from a window or bitmap to a second window or bitmap.
+ * Data is moved from a window or bitmap to a second window or
+ * bitmap.
*
*----------------------------------------------------------------------
*/
void
XCopyArea(
- Display *display, /* Display. */
- Drawable src, /* Source drawable. */
- Drawable dst, /* Destination drawable. */
- GC gc, /* GC to use. */
- int src_x, /* X & Y, width & height */
- int src_y, /* define the source rectangle */
- unsigned int width, /* the will be copied. */
+ Display* display, /* Display. */
+ Drawable src, /* Source drawable. */
+ Drawable dst, /* Destination drawable. */
+ GC gc, /* GC to use. */
+ int src_x, /* X & Y, width & height */
+ int src_y, /* define the source rectangle */
+ unsigned int width, /* the will be copied. */
unsigned int height,
- int dest_x, /* Dest X & Y on dest rect. */
+ int dest_x, /* Dest X & Y on dest rect. */
int dest_y)
{
Rect srcRect, dstRect;
- Rect *srcPtr, *dstPtr;
- const BitMap *srcBit;
- const BitMap *dstBit;
+ Rect * srcPtr, * dstPtr;
+ const BitMap * srcBit;
+ const BitMap * dstBit;
MacDrawable *srcDraw = (MacDrawable *) src;
MacDrawable *dstDraw = (MacDrawable *) dst;
CGrafPtr srcPort, dstPort;
@@ -198,20 +195,20 @@ XCopyArea(
(short) (dstDraw->yOff + dest_y + height));
}
TkMacOSXSetUpClippingRgn(dst);
-
/*
- * We will change the clip rgn in this routine, so we need to be able to
- * restore it when we exit.
+ * We will change the clip rgn in this routine, so we need to
+ * be able to restore it when we exit.
*/
GetClip(tmpRgn2);
if (tkPictureIsOpen) {
/*
- * When rendering into a picture, after a call to "OpenCPicture" the
- * clipping is seriously WRONG and also INCONSISTENT with the clipping
- * for single plane bitmaps. To circumvent this problem, we clip to
- * the whole window In this case, would have also clipped to the
- * srcRect ClipRect(&srcRect);
+ * When rendering into a picture, after a call to "OpenCPicture"
+ * the clipping is seriously WRONG and also INCONSISTENT with the
+ * clipping for single plane bitmaps.
+ * To circumvent this problem, we clip to the whole window
+ * In this case, would have also clipped to the srcRect
+ * ClipRect(&srcRect);
*/
GetPortBounds(dstPort,&clpRect);
@@ -219,12 +216,11 @@ XCopyArea(
ClipRect(&clpRect);
}
if (!gc->clip_mask) {
- /* do nothing */
} else if (((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) {
RgnHandle clipRgn = (RgnHandle)
((TkpClipMask*)gc->clip_mask)->value.region;
- int xOffset = 0, yOffset = 0;
+ int xOffset = 0, yOffset = 0;
if (tmpRgn == NULL) {
tmpRgn = NewRgn();
}
@@ -256,33 +252,39 @@ XCopyArea(
*
* XCopyPlane --
*
- * Copies a bitmap from a source drawable to a destination drawable. The
- * plane argument specifies which bit plane of the source contains the
- * bitmap. Note that this implementation ignores the gc->function.
+ * Copies a bitmap from a source drawable to a destination
+ * drawable. The plane argument specifies which bit plane of
+ * the source contains the bitmap. Note that this implementation
+ * ignores the gc->function.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Changes the destination drawable.
+ * Changes the destination drawable.
*
*----------------------------------------------------------------------
*/
void
XCopyPlane(
- Display *display, /* Display. */
- Drawable src, /* Source drawable. */
- Drawable dst, /* Destination drawable. */
- GC gc, /* The GC to use. */
- int src_x, int src_y, /* X, Y, width & height define the source
- * rect. */
- unsigned int width, unsigned int height,
- int dest_x, int dest_y, /* X & Y on dest where we will copy. */
- unsigned long plane) /* Which plane to copy. */
+ Display* display, /* Display. */
+ Drawable src, /* Source drawable. */
+ Drawable dst, /* Destination drawable. */
+ GC gc, /* The GC to use. */
+ int src_x, /* X, Y, width & height */
+ int src_y, /* define the source rect. */
+ unsigned int width,
+ unsigned int height,
+ int dest_x, /* X & Y on dest where we will copy. */
+ int dest_y,
+ unsigned long plane) /* Which plane to copy. */
{
- Rect srcRect, dstRect, *srcPtr, *dstPtr;
- const BitMap *srcBit, *dstBit, *mskBit;
+ Rect srcRect, dstRect;
+ Rect * srcPtr, * dstPtr;
+ const BitMap * srcBit;
+ const BitMap * dstBit;
+ const BitMap * mskBit;
MacDrawable *srcDraw = (MacDrawable *) src;
MacDrawable *dstDraw = (MacDrawable *) dst;
GWorldPtr srcPort, dstPort, mskPort;
@@ -309,10 +311,10 @@ XCopyPlane(
srcPtr = &srcRect;
if (tkPictureIsOpen) {
/*
- * When rendering into a picture, after a call to "OpenCPicture" the
- * clipping is seriously WRONG and also INCONSISTENT with the clipping
- * for color bitmaps. To circumvent this problem, we clip to the whole
- * window.
+ * When rendering into a picture, after a call to "OpenCPicture"
+ * the clipping is seriously WRONG and also INCONSISTENT with the
+ * clipping for color bitmaps.
+ * To circumvent this problem, we clip to the whole window
*/
Rect clpRect;
@@ -346,8 +348,8 @@ XCopyPlane(
if (clipPtr->value.pixmap == src) {
PixMapHandle pm;
/*
- * Case 2: transparent bitmaps. If it's color we ignore the
- * forecolor.
+ * Case 2: transparent bitmaps. If it's color we ignore
+ * the forecolor.
*/
pm = GetPortPixMap(srcPort);
@@ -365,8 +367,8 @@ XCopyPlane(
tmode = srcCopy;
mskPort = TkMacOSXGetDrawablePort(clipPtr->value.pixmap);
mskBit = GetPortBitMapForCopyBits(mskPort);
- CopyDeepMask(srcBit, mskBit, dstBit, srcPtr, srcPtr, dstPtr,
- tmode, NULL);
+ CopyDeepMask(srcBit, mskBit, dstBit,
+ srcPtr, srcPtr, dstPtr, tmode, NULL);
}
}
@@ -378,14 +380,14 @@ XCopyPlane(
*
* TkPutImage --
*
- * Copies a subimage from an in-memory image to a rectangle of the
- * specified drawable.
+ * Copies a subimage from an in-memory image to a rectangle of
+ * of the specified drawable.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws the image on the specified drawable.
+ * Draws the image on the specified drawable.
*
*----------------------------------------------------------------------
*/
@@ -428,14 +430,13 @@ TkPutImage(
SetRect(srcPtr, src_x, src_y, src_x + width, src_y + height);
if (tkPictureIsOpen) {
/*
- * When rendering into a picture, after a call to "OpenCPicture" the
- * clipping is seriously WRONG and also INCONSISTENT with the clipping
- * for single plane bitmaps. To circumvent this problem, we clip to
- * the whole window.
+ * When rendering into a picture, after a call to "OpenCPicture"
+ * the clipping is seriously WRONG and also INCONSISTENT with the
+ * clipping for single plane bitmaps.
+ * To circumvent this problem, we clip to the whole window
*/
Rect clpRect;
-
GetPortBounds(destPort,&clpRect);
ClipRect(&clpRect);
destPtr = srcPtr;
@@ -446,19 +447,14 @@ TkPutImage(
}
if (image->obdata) {
- /*
- * Image from XGetImage, copy from containing GWorld directly.
- */
-
+ /* Image from XGetImage, copy from containing GWorld directly */
GWorldPtr srcPort = TkMacOSXGetDrawablePort((Drawable)image->obdata);
-
CopyBits(GetPortBitMapForCopyBits(srcPort),
destBits, srcPtr, destPtr, srcCopy, NULL);
} else if (image->depth == 1) {
/*
* BW image
*/
-
const int maxRowBytes = 0x3ffe;
BitMap bitmap;
int odd;
@@ -491,7 +487,7 @@ TkPutImage(
oldPtr = dataPtr;
odd = sliceRowBytes % 2;
if (!newData) {
- newData = ckalloc(image->height * (sliceRowBytes+odd));
+ newData = (char *) ckalloc(image->height * (sliceRowBytes+odd));
}
newPtr = newData;
for (i = 0; i < image->height; i++) {
@@ -516,7 +512,6 @@ TkPutImage(
/*
* Color image
*/
-
const int maxRowBytes = 0x3ffc;
PixMap pixmap;
@@ -524,7 +519,7 @@ TkPutImage(
pixmap.bounds.top = 0;
pixmap.bounds.bottom = (short) image->height;
pixmap.pixelType = RGBDirect;
- pixmap.pmVersion = baseAddr32; /* 32bit clean */
+ pixmap.pmVersion = baseAddr32; /* 32bit clean */
pixmap.packType = 0;
pixmap.packSize = 0;
pixmap.hRes = 0x00480000;
@@ -594,23 +589,23 @@ TkPutImage(
*
* XDrawLines --
*
- * Draw connected lines.
+ * Draw connected lines.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Renders a series of connected lines.
+ * Renders a series of connected lines.
*
*----------------------------------------------------------------------
*/
void
XDrawLines(
- Display *display, /* Display. */
+ Display* display, /* Display. */
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
- XPoint *points, /* Array of points. */
+ XPoint* points, /* Array of points. */
int npoints, /* Number of points. */
int mode) /* Line drawing mode. */
{
@@ -659,19 +654,15 @@ XDrawLines(
TkMacOSXSetUpGraphicsPort(gc, destPort);
ShowPen();
PenPixPat(gPenPat);
-
- /*
- * This is broken for fat lines, it is not possible to correctly
- * imitate X11 drawing of oblique fat lines with QD line drawing, we
- * should draw a filled polygon instead.
- */
-
+ /* This is broken for fat lines, it is not possible to correctly
+ * imitate X11 drawing of oblique fat lines with QD line drawing,
+ * we should draw a filled polygon instead. */
MoveTo((short) (macWin->xOff + points[0].x + o),
- (short) (macWin->yOff + points[0].y + o));
+ (short) (macWin->yOff + points[0].y + o));
for (i = 1; i < npoints; i++) {
if (mode == CoordModeOrigin) {
LineTo((short) (macWin->xOff + points[i].x + o),
- (short) (macWin->yOff + points[i].y + o));
+ (short) (macWin->yOff + points[i].y + o));
} else {
Line((short) points[i].x, (short) points[i].y);
}
@@ -687,24 +678,23 @@ XDrawLines(
*
* XDrawSegments --
*
- * Draw unconnected lines.
+ * Draw unconnected lines.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Renders a series of unconnected lines.
+ * Renders a series of unconnected lines.
*
*----------------------------------------------------------------------
*/
-void
-XDrawSegments(
+void XDrawSegments(
Display *display,
- Drawable d,
+ Drawable d,
GC gc,
XSegment *segments,
- int nsegments)
+ int nsegments)
{
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
@@ -740,18 +730,14 @@ XDrawSegments(
TkMacOSXSetUpGraphicsPort(gc, destPort);
ShowPen();
PenPixPat(gPenPat);
-
- /*
- * This is broken for fat lines, it is not possible to correctly
- * imitate X11 drawing of oblique fat lines with QD line drawing, we
- * should draw a filled polygon instead.
- */
-
+ /* This is broken for fat lines, it is not possible to correctly
+ * imitate X11 drawing of oblique fat lines with QD line drawing,
+ * we should draw a filled polygon instead. */
for (i = 0; i < nsegments; i++) {
MoveTo((short) (macWin->xOff + segments[i].x1 + o),
- (short) (macWin->yOff + segments[i].y1 + o));
+ (short) (macWin->yOff + segments[i].y1 + o));
LineTo((short) (macWin->xOff + segments[i].x2 + o),
- (short) (macWin->yOff + segments[i].y2 + o));
+ (short) (macWin->yOff + segments[i].y2 + o));
}
HidePen();
}
@@ -764,13 +750,13 @@ XDrawSegments(
*
* XFillPolygon --
*
- * Draws a filled polygon.
+ * Draws a filled polygon.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws a filled polygon on the specified drawable.
+ * Draws a filled polygon on the specified drawable.
*
*----------------------------------------------------------------------
*/
@@ -827,11 +813,11 @@ XFillPolygon(
PenNormal();
polygon = OpenPoly();
MoveTo((short) (macWin->xOff + points[0].x),
- (short) (macWin->yOff + points[0].y));
+ (short) (macWin->yOff + points[0].y));
for (i = 1; i < npoints; i++) {
if (mode == CoordModeOrigin) {
LineTo((short) (macWin->xOff + points[i].x),
- (short) (macWin->yOff + points[i].y));
+ (short) (macWin->yOff + points[i].y));
} else {
Line((short) points[i].x, (short) points[i].y);
}
@@ -849,24 +835,25 @@ XFillPolygon(
*
* XDrawRectangle --
*
- * Draws a rectangle.
+ * Draws a rectangle.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws a rectangle on the specified drawable.
+ * Draws a rectangle on the specified drawable.
*
*----------------------------------------------------------------------
*/
void
XDrawRectangle(
- Display *display, /* Display. */
- Drawable d, /* Draw on this. */
- GC gc, /* Use this GC. */
- int x, int y, /* Upper left corner. */
- unsigned int width, /* Width & height of rect. */
+ Display* display, /* Display. */
+ Drawable d, /* Draw on this. */
+ GC gc, /* Use this GC. */
+ int x, /* Upper left corner. */
+ int y,
+ unsigned int width, /* Width & height of rect. */
unsigned int height)
{
MacDrawable *macWin = (MacDrawable *) d;
@@ -904,10 +891,10 @@ XDrawRectangle(
TkMacOSXSetUpGraphicsPort(gc, destPort);
ShowPen();
PenPixPat(gPenPat);
- theRect.left = (short) (macWin->xOff + x + o);
- theRect.top = (short) (macWin->yOff + y + o);
- theRect.right = (short) (theRect.left + width + lw);
- theRect.bottom = (short) (theRect.top + height + lw);
+ theRect.left = (short) (macWin->xOff + x + o);
+ theRect.top = (short) (macWin->yOff + y + o);
+ theRect.right = (short) (theRect.left + width + lw);
+ theRect.bottom = (short) (theRect.top + height + lw);
FrameRect(&theRect);
HidePen();
}
@@ -921,26 +908,27 @@ XDrawRectangle(
*
* XDrawRectangles --
*
- * Draws the outlines of the specified rectangles as if a five-point
- * PolyLine protocol request were specified for each rectangle:
+ * Draws the outlines of the specified rectangles as if a
+ * five-point PolyLine protocol request were specified for each
+ * rectangle:
*
- * [x,y] [x+width,y] [x+width,y+height] [x,y+height]
- * [x,y]
+ * [x,y] [x+width,y] [x+width,y+height] [x,y+height]
+ * [x,y]
*
- * For the specified rectangles, these functions do not draw a pixel more
- * than once. XDrawRectangles draws the rectangles in the order listed in
- * the array. If rectangles intersect, the intersecting pixels are drawn
- * multiple times. Draws a rectangle.
+ * For the specified rectangles, these functions do not draw a
+ * pixel more than once. XDrawRectangles draws the rectangles in
+ * the order listed in the array. If rectangles intersect, the
+ * intersecting pixels are drawn multiple times. Draws a
+ * rectangle.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws rectangles on the specified drawable.
+ * Draws rectangles on the specified drawable.
*
*----------------------------------------------------------------------
*/
-
void
XDrawRectangles(
Display *display,
@@ -987,10 +975,10 @@ XDrawRectangles(
ShowPen();
PenPixPat(gPenPat);
for (i = 0, rectPtr = rectArr; i < nRects;i++, rectPtr++) {
- theRect.left = (short) (macWin->xOff + rectPtr->x + o);
- theRect.top = (short) (macWin->yOff + rectPtr->y + o);
- theRect.right = (short) (theRect.left + rectPtr->width + lw);
- theRect.bottom = (short) (theRect.top + rectPtr->height + lw);
+ theRect.left = (short) (macWin->xOff + rectPtr->x + o);
+ theRect.top = (short) (macWin->yOff + rectPtr->y + o);
+ theRect.right = (short) (theRect.left + rectPtr->width + lw);
+ theRect.bottom = (short) (theRect.top + rectPtr->height + lw);
FrameRect(&theRect);
}
HidePen();
@@ -1005,24 +993,23 @@ XDrawRectangles(
*
* XFillRectangles --
*
- * Fill multiple rectangular areas in the given drawable.
+ * Fill multiple rectangular areas in the given drawable.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws onto the specified drawable.
+ * Draws onto the specified drawable.
*
*----------------------------------------------------------------------
*/
-
void
XFillRectangles(
- Display* display, /* Display. */
- Drawable d, /* Draw on this. */
- GC gc, /* Use this GC. */
- XRectangle *rectangles, /* Rectangle array. */
- int n_rectangles) /* Number of rectangles. */
+ Display* display, /* Display. */
+ Drawable d, /* Draw on this. */
+ GC gc, /* Use this GC. */
+ XRectangle *rectangles, /* Rectangle array. */
+ int n_rectangles) /* Number of rectangles. */
{
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
@@ -1046,7 +1033,8 @@ XFillRectangles(
if (rectPtr->width == 0 || rectPtr->height == 0) {
continue;
}
- rect = CGRectMake(macWin->xOff + rectPtr->x,
+ rect = CGRectMake(
+ macWin->xOff + rectPtr->x,
macWin->yOff + rectPtr->y,
rectPtr->width, rectPtr->height);
CGContextFillRect(outContext, rect);
@@ -1057,10 +1045,10 @@ XFillRectangles(
TkMacOSXSetUpGraphicsPort(gc, destPort);
for (i = 0, rectPtr = rectangles; i < n_rectangles; i++, rectPtr++) {
- theRect.left = (short) (macWin->xOff + rectPtr->x);
- theRect.top = (short) (macWin->yOff + rectPtr->y);
- theRect.right = (short) (theRect.left + rectPtr->width);
- theRect.bottom = (short) (theRect.top + rectPtr->height);
+ theRect.left = (short) (macWin->xOff + rectPtr->x);
+ theRect.top = (short) (macWin->yOff + rectPtr->y);
+ theRect.right = (short) (theRect.left + rectPtr->width);
+ theRect.bottom = (short) (theRect.top + rectPtr->height);
FillCRect(&theRect, gPenPat);
}
}
@@ -1073,27 +1061,28 @@ XFillRectangles(
*
* XDrawArc --
*
- * Draw an arc.
+ * Draw an arc.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws an arc on the specified drawable.
+ * Draws an arc on the specified drawable.
*
*----------------------------------------------------------------------
*/
void
XDrawArc(
- Display* display, /* Display. */
- Drawable d, /* Draw on this. */
- GC gc, /* Use this GC. */
- int x, int y, /* Upper left of bounding rect. */
- unsigned int width, /* Width & height. */
+ Display* display, /* Display. */
+ Drawable d, /* Draw on this. */
+ GC gc, /* Use this GC. */
+ int x, /* Upper left of */
+ int y, /* bounding rect. */
+ unsigned int width, /* Width & height. */
unsigned int height,
- int angle1, /* Staring angle of arc. */
- int angle2) /* Extent of arc. */
+ int angle1, /* Staring angle of arc. */
+ int angle2) /* Extent of arc. */
{
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
@@ -1153,11 +1142,11 @@ XDrawArc(
TkMacOSXSetUpGraphicsPort(gc, destPort);
ShowPen();
PenPixPat(gPenPat);
- theRect.left = (short) (macWin->xOff + x + o);
- theRect.top = (short) (macWin->yOff + y + o);
- theRect.right = (short) (theRect.left + width + lw);
+ theRect.left = (short) (macWin->xOff + x + o);
+ theRect.top = (short) (macWin->yOff + y + o);
+ theRect.right = (short) (theRect.left + width + lw);
theRect.bottom = (short) (theRect.top + height + lw);
- start = (short) (90 - (angle1/64));
+ start = (short) (90 - (angle1/64));
extent = (short) (-(angle2/64));
FrameArc(&theRect, start, extent);
HidePen();
@@ -1172,23 +1161,23 @@ XDrawArc(
*
* XDrawArcs --
*
- * Draws multiple circular or elliptical arcs. Each arc is specified by a
- * rectangle and two angles. The center of the circle or ellipse is the
- * center of the rectangle, and the major and minor axes are specified by
- * the width and height. Positive angles indicate counterclock- wise
- * motion, and negative angles indicate clockwise motion. If the
- * magnitude of angle2 is greater than 360 degrees, XDrawArcs truncates
- * it to 360 degrees.
+ * Draws multiple circular or elliptical arcs. Each arc is
+ * specified by a rectangle and two angles. The center of the
+ * circle or ellipse is the center of the rect- angle, and the
+ * major and minor axes are specified by the width and height.
+ * Positive angles indicate counterclock- wise motion, and
+ * negative angles indicate clockwise motion. If the magnitude
+ * of angle2 is greater than 360 degrees, XDrawArcs truncates it
+ * to 360 degrees.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws an arc for each array element on the specified drawable.
+ * Draws an arc for each array element on the specified drawable.
*
*----------------------------------------------------------------------
*/
-
void
XDrawArcs(
Display *display,
@@ -1197,11 +1186,12 @@ XDrawArcs(
XArc *arcArr,
int nArcs)
{
+
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
GDHandle saveDevice;
GWorldPtr destPort;
- XArc *arcPtr;
+ XArc * arcPtr;
int i, lw = gc->line_width;
destPort = TkMacOSXGetDrawablePort(d);
@@ -1221,7 +1211,8 @@ XDrawArcs(
|| arcPtr->angle2 == 0) {
continue;
}
- rect = CGRectMake(macWin->xOff + arcPtr->x + o,
+ rect = CGRectMake(
+ macWin->xOff + arcPtr->x + o,
macWin->yOff + arcPtr->y + o,
arcPtr->width, arcPtr->height);
@@ -1235,13 +1226,13 @@ XDrawArcs(
CGMutablePathRef p = CGPathCreateMutable();
CGAffineTransform t = CGAffineTransformIdentity;
CGPoint c = CGPointMake(CGRectGetMidX(rect),
- CGRectGetMidY(rect));
+ CGRectGetMidY(rect));
float w = CGRectGetWidth(rect);
if (arcPtr->width != arcPtr->height) {
t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w);
c = CGPointApplyAffineTransform(c,
- CGAffineTransformInvert(t));
+ CGAffineTransformInvert(t));
}
CGPathAddArc(p, &t, c.x, c.y, w/2,
radians(-arcPtr->angle1/64.0),
@@ -1262,11 +1253,11 @@ XDrawArcs(
ShowPen();
PenPixPat(gPenPat);
for (i = 0, arcPtr = arcArr;i < nArcs;i++, arcPtr++) {
- theRect.left = (short) (macWin->xOff + arcPtr->x + o);
- theRect.top = (short) (macWin->yOff + arcPtr->y + o);
- theRect.right = (short) (theRect.left + arcPtr->width + lw);
+ theRect.left = (short) (macWin->xOff + arcPtr->x + o);
+ theRect.top = (short) (macWin->yOff + arcPtr->y + o);
+ theRect.right = (short) (theRect.left + arcPtr->width + lw);
theRect.bottom = (short) (theRect.top + arcPtr->height + lw);
- start = (short) (90 - (arcPtr->angle1/64));
+ start = (short) (90 - (arcPtr->angle1/64));
extent = (short) (-(arcPtr->angle2/64));
FrameArc(&theRect, start, extent);
}
@@ -1282,27 +1273,28 @@ XDrawArcs(
*
* XFillArc --
*
- * Draw a filled arc.
+ * Draw a filled arc.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws a filled arc on the specified drawable.
+ * Draws a filled arc on the specified drawable.
*
*----------------------------------------------------------------------
*/
void
XFillArc(
- Display* display, /* Display. */
- Drawable d, /* Draw on this. */
- GC gc, /* Use this GC. */
- int x, int y, /* Upper left of bounding rect. */
- unsigned int width, /* Width & height. */
+ Display* display, /* Display. */
+ Drawable d, /* Draw on this. */
+ GC gc, /* Use this GC. */
+ int x, /* Upper left of */
+ int y, /* bounding rect. */
+ unsigned int width, /* Width & height. */
unsigned int height,
- int angle1, /* Staring angle of arc. */
- int angle2) /* Extent of arc. */
+ int angle1, /* Staring angle of arc. */
+ int angle2) /* Extent of arc. */
{
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
@@ -1330,7 +1322,9 @@ XFillArc(
u += NON_AA_CG_OFFSET;
}
TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext);
- rect = CGRectMake(macWin->xOff + x + o, macWin->yOff + y + o,
+ rect = CGRectMake(
+ macWin->xOff + x + o,
+ macWin->yOff + y + o,
width - u, height - u);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
@@ -1370,9 +1364,9 @@ XFillArc(
double vertex[2], center1[2], center2[2];
TkMacOSXSetUpGraphicsPort(gc, destPort);
- theRect.left = (short) (macWin->xOff + x + o);
- theRect.top = (short) (macWin->yOff + y + o);
- theRect.right = (short) (theRect.left + width + lw);
+ theRect.left = (short) (macWin->xOff + x + o);
+ theRect.top = (short) (macWin->yOff + y + o);
+ theRect.right = (short) (theRect.left + width + lw);
theRect.bottom = (short) (theRect.top + height + lw);
start = (short) (90 - (angle1/64));
extent = (short) (-(angle2/64));
@@ -1394,7 +1388,7 @@ XFillArc(
polygon = OpenPoly();
MoveTo((short) ((theRect.left + theRect.right)/2),
- (short) ((theRect.top + theRect.bottom)/2));
+ (short) ((theRect.top + theRect.bottom)/2));
LineTo((short) (center1[0] + .5), (short) (center1[1] + .5));
LineTo((short) (center2[0] + .5), (short) (center2[1] + .5));
ClosePoly();
@@ -1419,17 +1413,16 @@ XFillArc(
*
* XFillArcs --
*
- * Draw a filled arc.
+ * Draw a filled arc.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Draws a filled arc for each array element on the specified drawable.
+ * Draws a filled arc for each array element on the specified drawable.
*
*----------------------------------------------------------------------
*/
-
void
XFillArcs(
Display *display,
@@ -1442,7 +1435,7 @@ XFillArcs(
CGrafPtr saveWorld;
GDHandle saveDevice;
GWorldPtr destPort;
- XArc *arcPtr;
+ XArc * arcPtr;
int i, lw = gc->line_width;
destPort = TkMacOSXGetDrawablePort(d);
@@ -1466,7 +1459,8 @@ XFillArcs(
|| arcPtr->angle2 == 0) {
continue;
}
- rect = CGRectMake(macWin->xOff + arcPtr->x + o,
+ rect = CGRectMake(
+ macWin->xOff + arcPtr->x + o,
macWin->yOff + arcPtr->y + o,
arcPtr->width - u, arcPtr->height - u);
@@ -1480,13 +1474,13 @@ XFillArcs(
CGMutablePathRef p = CGPathCreateMutable();
CGAffineTransform t = CGAffineTransformIdentity;
CGPoint c = CGPointMake(CGRectGetMidX(rect),
- CGRectGetMidY(rect));
+ CGRectGetMidY(rect));
float w = CGRectGetWidth(rect);
if (arcPtr->width != arcPtr->height) {
t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w);
c = CGPointApplyAffineTransform(c,
- CGAffineTransformInvert(t));
+ CGAffineTransformInvert(t));
}
if (gc->arc_mode == ArcPieSlice) {
CGPathMoveToPoint(p, &t, c.x, c.y);
@@ -1513,9 +1507,9 @@ XFillArcs(
TkMacOSXSetUpGraphicsPort(gc, destPort);
for (i = 0, arcPtr = arcArr;i<nArcs;i++, arcPtr++) {
- theRect.left = (short) (macWin->xOff + arcPtr->x + o);
- theRect.top = (short) (macWin->yOff + arcPtr->y + o);
- theRect.right = (short) (theRect.left + arcPtr->width + lw);
+ theRect.left = (short) (macWin->xOff + arcPtr->x + o);
+ theRect.top = (short) (macWin->yOff + arcPtr->y + o);
+ theRect.right = (short) (theRect.left + arcPtr->width + lw);
theRect.bottom = (short) (theRect.top + arcPtr->height + lw);
start = (short) (90 - (arcPtr->angle1/64));
extent = (short) (- (arcPtr->angle2/64));
@@ -1538,7 +1532,7 @@ XFillArcs(
polygon = OpenPoly();
MoveTo((short) ((theRect.left + theRect.right)/2),
- (short) ((theRect.top + theRect.bottom)/2));
+ (short) ((theRect.top + theRect.bottom)/2));
LineTo((short) (center1[0] + .5), (short) (center1[1] + .5));
LineTo((short) (center2[0] + .5), (short) (center2[1] + .5));
ClosePoly();
@@ -1567,10 +1561,8 @@ XFillArcs(
*
*----------------------------------------------------------------------
*/
-
long
-XMaxRequestSize(
- Display *display)
+XMaxRequestSize(Display *display)
{
return (SHRT_MAX / 4);
}
@@ -1581,28 +1573,31 @@ XMaxRequestSize(
*
* TkScrollWindow --
*
- * Scroll a rectangle of the specified window and accumulate a damage
- * region.
+ * Scroll a rectangle of the specified window and accumulate
+ * a damage region.
*
* Results:
- * Returns 0 if the scroll genereated no additional damage. Otherwise,
- * sets the region that needs to be repainted after scrolling and returns
- * 1.
+ * Returns 0 if the scroll genereated no additional damage.
+ * Otherwise, sets the region that needs to be repainted after
+ * scrolling and returns 1.
*
* Side effects:
- * Scrolls the bits in the window.
+ * Scrolls the bits in the window.
*
*----------------------------------------------------------------------
*/
int
TkScrollWindow(
- Tk_Window tkwin, /* The window to be scrolled. */
- GC gc, /* GC for window to be scrolled. */
- int x, int y, /* Position rectangle to be scrolled. */
- int width, int height,
- int dx, int dy, /* Distance rectangle should be moved. */
- TkRegion damageRgn) /* Region to accumulate damage in. */
+ Tk_Window tkwin, /* The window to be scrolled. */
+ GC gc, /* GC for window to be scrolled. */
+ int x, /* Position rectangle to be scrolled. */
+ int y,
+ int width,
+ int height,
+ int dx, /* Distance rectangle should be moved. */
+ int dy,
+ TkRegion damageRgn) /* Region to accumulate damage in. */
{
MacDrawable *destDraw = (MacDrawable *) Tk_WindowId(tkwin);
RgnHandle rgn = (RgnHandle) damageRgn;
@@ -1618,12 +1613,13 @@ TkScrollWindow(
TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
/*
- * Due to the implementation below the behavior may be differnt than X in
- * certain cases that should never occur in Tk. The scrollRect is the
- * source rect extended by the offset (the union of the source rect and
- * the offset rect). Everything in the extended scrollRect is scrolled. On
- * X, it's possible to "skip" over an area if the offset makes the source
- * and destination rects disjoint and non-aligned.
+ * Due to the implementation below the behavior may be differnt
+ * than X in certain cases that should never occur in Tk. The
+ * scrollRect is the source rect extended by the offset (the union
+ * of the source rect and the offset rect). Everything
+ * in the extended scrollRect is scrolled. On X, it's possible
+ * to "skip" over an area if the offset makes the source and
+ * destination rects disjoint and non-aligned.
*/
SetRect(&srcRect, (short) (destDraw->xOff + x),
@@ -1643,10 +1639,9 @@ TkScrollWindow(
}
/*
- * Adjust clip region so that we don't copy any windows that may overlap
- * us.
+ * Adjust clip region so that we don't copy any windows
+ * that may overlap us.
*/
-
visRgn = NewRgn();
clipRgn = NewRgn();
RectRgn(rgn, &srcRect);
@@ -1659,14 +1654,14 @@ TkScrollWindow(
SetEmptyRgn(rgn);
/*
- * When a menu is up, the Mac does not expect drawing to occur and does
- * not clip out the menu. We have to do it ourselves. This is pretty
- * gross.
+ * When a menu is up, the Mac does not expect drawing to occur and
+ * does not clip out the menu. We have to do it ourselves. This
+ * is pretty gross.
*/
if (tkUseMenuCascadeRgn == 1) {
- Point scratch = {0, 0};
- MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(tkwin);
+ Point scratch = {0, 0};
+ MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(tkwin);
LocalToGlobal(&scratch);
CopyRgn(tkMenuCascadeRgn, rgn);
@@ -1683,14 +1678,17 @@ TkScrollWindow(
DisposeRgn(clipRgn);
DisposeRgn(visRgn);
-
/*
- * Fortunantly, the region returned by ScrollRect is symanticlly the same
- * as what we need to return in this function. If the region is empty we
- * return zero to denote that no damage was created.
+ * Fortunantly, the region returned by ScrollRect is symanticlly
+ * the same as what we need to return in this function. If the
+ * region is empty we return zero to denote that no damage was
+ * created.
*/
-
- return !EmptyRgn(rgn);
+ if (EmptyRgn(rgn)) {
+ return 0;
+ } else {
+ return 1;
+ }
}
/*
@@ -1698,13 +1696,13 @@ TkScrollWindow(
*
* TkMacOSXSetUpGraphicsPort --
*
- * Set up the graphics port from the given GC.
+ * Set up the graphics port from the given GC.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The current port is adjusted.
+ * The current port is adjusted.
*
*----------------------------------------------------------------------
*/
@@ -1712,7 +1710,7 @@ TkScrollWindow(
void
TkMacOSXSetUpGraphicsPort(
GC gc,
- GWorldPtr destPort) /* GC to apply to current port. */
+ GWorldPtr destPort) /* GC to apply to current port. */
{
RGBColor macColor;
@@ -1721,15 +1719,12 @@ TkMacOSXSetUpGraphicsPort(
}
if (TkSetMacColor(gc->foreground, &macColor) == true) {
- /*
- * TODO: cache RGBPats for preformace - measure gains...
- */
-
+ /* TODO: cache RGBPats for preformace - measure gains... */
MakeRGBPat(gPenPat, &macColor);
}
PenNormal();
- if (gc->function == GXxor) {
+ if(gc->function == GXxor) {
PenMode(patXor);
}
if (gc->line_width > 1) {
@@ -1737,26 +1732,26 @@ TkMacOSXSetUpGraphicsPort(
}
if (gc->line_style != LineSolid) {
/*
- * Here the dash pattern should be set in the drawing environment, but
- * I don't know how to do that for the Mac.
+ * Here the dash pattern should be set in the drawing,
+ * environment, but I don't know how to do that for the Mac.
*
- * p[] is an array of unsigned chars containing the dash list. A '\0'
- * indicates the end of this list.
+ * p[] is an array of unsigned chars containing the dash list.
+ * A '\0' indicates the end of this list.
*
- * Someone knows how to implement this? If you have a more complete
- * implementation of SetUpGraphicsPort() for the Mac (or for Windows),
- * please let me know.
+ * Someone knows how to implement this? If you have a more
+ * complete implementation of SetUpGraphicsPort() for
+ * the Mac (or for Windows), please let me know.
*
- * Jan Nijtmans
- * CMG Arnhem, B.V.
- * email: j.nijtmans@chello.nl (private)
- * jan.nijtmans@cmg.nl (work)
- * url: http://purl.oclc.org/net/nijtmans/
+ * Jan Nijtmans
+ * CMG Arnhem, B.V.
+ * email: j.nijtmans@chello.nl (private)
+ * jan.nijtmans@cmg.nl (work)
+ * url: http://purl.oclc.org/net/nijtmans/
*
* FIXME:
- * This is not possible with QuickDraw line drawing. As of Tk 8.4.7 we
- * have a complete set of drawing routines using CG, so there is no
- * reason to support this here.
+ * This is not possible with QuickDraw line drawing. As of
+ * Tk 8.4.7 we have a complete set of drawing routines using
+ * CG, so there is no reason to support this here.
*/
}
}
@@ -1766,13 +1761,13 @@ TkMacOSXSetUpGraphicsPort(
*
* TkMacOSXSetUpCGContext --
*
- * Set up a CGContext for the given graphics port.
+ * Set up a CGContext for the given graphics port.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
@@ -1796,13 +1791,13 @@ TkMacOSXSetUpCGContext(
outContext = *contextPtr;
/*
- * Now clip the CG Context to the port. Note, we have already set up the
- * port with our clip region, so we can just get the clip back out of
- * there. If we use the macWin->clipRgn directly at this point, we get
- * some odd drawing effects.
+ * Now clip the CG Context to the port. Note, we have already
+ * set up the port with our clip region, so we can just get
+ * the clip back out of there. If we use the macWin->clipRgn
+ * directly at this point, we get some odd drawing effects.
*
- * We also have to intersect our clip region with the port visible region
- * so we don't overwrite the window decoration.
+ * We also have to intersect our clip region with the port
+ * visible region so we don't overwrite the window decoration.
*/
if (!clipRgn) {
@@ -1818,8 +1813,8 @@ TkMacOSXSetUpCGContext(
SetEmptyRgn(clipRgn);
/*
- * Note: You have to call SyncCGContextOriginWithPort AFTER all the clip
- * region manipulations.
+ * Note: You have to call SyncCGContextOriginWithPort
+ * AFTER all the clip region manipulations.
*/
SyncCGContextOriginWithPort(outContext, destPort);
@@ -1828,32 +1823,28 @@ TkMacOSXSetUpCGContext(
boundsRect.bottom - boundsRect.top);
CGContextConcatCTM(outContext, coordsTransform);
- /*
- * Now offset the CTM to the subwindow offset.
- */
+ /* Now offset the CTM to the subwindow offset */
if (TkSetMacColor(gc->foreground, &macColor) == true) {
- CGContextSetRGBFillColor(outContext, RGBFLOATRED(macColor),
- RGBFLOATGREEN(macColor), RGBFLOATBLUE(macColor), 1);
- CGContextSetRGBStrokeColor(outContext, RGBFLOATRED(macColor),
- RGBFLOATGREEN(macColor), RGBFLOATBLUE(macColor), 1);
+ CGContextSetRGBFillColor(outContext,
+ RGBFLOATRED(macColor),
+ RGBFLOATGREEN(macColor),
+ RGBFLOATBLUE(macColor),
+ 1);
+ CGContextSetRGBStrokeColor(outContext,
+ RGBFLOATRED(macColor),
+ RGBFLOATGREEN(macColor),
+ RGBFLOATBLUE(macColor),
+ 1);
}
- if (gc->function == GXxor) {
- /* empty */
+ if(gc->function == GXxor) {
}
w = gc->line_width;
-
- /*
- * When should we antialias?
- */
-
+ /* When should we antialias? */
if (notAA(gc->line_width)) {
- /*
- * Make non-antialiased CG drawing look more like X11.
- */
-
+ /* Make non-antialiased CG drawing look more like X11 */
w -= (gc->line_width ? NON_AA_CG_OFFSET : 0);
CGContextSetShouldAntialias(outContext, 0);
} else {
@@ -1876,7 +1867,7 @@ TkMacOSXSetUpCGContext(
if (gc->cap_style == CapButt) {
/*
- * What about CapNotLast, CapProjecting?
+ * What about CapNotLast, CapProjecting?
*/
CGContextSetLineCap(outContext, kCGLineCapButt);
@@ -1900,22 +1891,22 @@ TkMacOSXSetUpCGContext(
*
* TkMacOSXReleaseCGContext --
*
- * Release the CGContext for the given graphics port.
+ * Release the CGContext for the given graphics port.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
static void
TkMacOSXReleaseCGContext(
- MacDrawable *macWin,
- CGrafPtr destPort,
- CGContextRef *outContext)
+ MacDrawable *macWin,
+ CGrafPtr destPort,
+ CGContextRef *outContext)
{
CGContextSynchronize(*outContext);
QDEndCGContext(destPort, outContext);
@@ -1926,21 +1917,21 @@ TkMacOSXReleaseCGContext(
*
* TkMacOSXSetUpClippingRgn --
*
- * Set up the clipping region so that drawing only occurs on the
- * specified X subwindow.
+ * Set up the clipping region so that drawing only occurs on the
+ * specified X subwindow.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The clipping region in the current port is changed.
+ * The clipping region in the current port is changed.
*
*----------------------------------------------------------------------
*/
void
TkMacOSXSetUpClippingRgn(
- Drawable drawable) /* Drawable to update. */
+ Drawable drawable) /* Drawable to update. */
{
MacDrawable *macDraw = (MacDrawable *) drawable;
@@ -1951,44 +1942,40 @@ TkMacOSXSetUpClippingRgn(
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_DRAWING)
TkMacOSXInitNamedDebugSymbol(HIToolbox, int, QDDebugFlashRegion,
- CGrafPtr port, RgnHandle region);
+ CGrafPtr port, RgnHandle region);
if (QDDebugFlashRegion) {
CGrafPtr grafPtr = TkMacOSXGetDrawablePort(drawable);
-
- /*
- * Carbon-internal region flashing SPI (c.f. Technote 2124)
- */
-
+ /* Carbon-internal region flashing SPI (c.f. Technote 2124) */
QDDebugFlashRegion(grafPtr, macDraw->clipRgn);
}
#endif /* TK_MAC_DEBUG_DRAWING */
/*
* When a menu is up, the Mac does not expect drawing to occur and
- * does not clip out the menu. We have to do it ourselves. This is
- * pretty gross.
+ * does not clip out the menu. We have to do it ourselves. This
+ * is pretty gross.
*/
if (macDraw->clipRgn != NULL) {
if (tkUseMenuCascadeRgn == 1) {
- Point scratch = {0, 0};
- GDHandle saveDevice;
- GWorldPtr saveWorld;
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(TkMacOSXGetDrawablePort(drawable), NULL);
- LocalToGlobal(&scratch);
- SetGWorld(saveWorld, saveDevice);
- if (tmpRgn == NULL) {
- tmpRgn = NewRgn();
- }
- CopyRgn(tkMenuCascadeRgn, tmpRgn);
- OffsetRgn(tmpRgn, -scratch.h, -scratch.v);
- DiffRgn(macDraw->clipRgn, tmpRgn, tmpRgn);
- SetClip(tmpRgn);
- macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU;
+ Point scratch = {0, 0};
+ GDHandle saveDevice;
+ GWorldPtr saveWorld;
+
+ GetGWorld(&saveWorld, &saveDevice);
+ SetGWorld(TkMacOSXGetDrawablePort(drawable), NULL);
+ LocalToGlobal(&scratch);
+ SetGWorld(saveWorld, saveDevice);
+ if (tmpRgn == NULL) {
+ tmpRgn = NewRgn();
+ }
+ CopyRgn(tkMenuCascadeRgn, tmpRgn);
+ OffsetRgn(tmpRgn, -scratch.h, -scratch.v);
+ DiffRgn(macDraw->clipRgn, tmpRgn, tmpRgn);
+ SetClip(tmpRgn);
+ macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU;
} else {
- SetClip(macDraw->clipRgn);
+ SetClip(macDraw->clipRgn);
}
}
}
@@ -1999,29 +1986,31 @@ TkMacOSXSetUpClippingRgn(
*
* TkMacOSXMakeStippleMap --
*
- * Given a drawable and a stipple pattern this function draws the pattern
- * repeatedly over the drawable. The drawable can then be used as a mask
- * for bit-bliting a stipple pattern over an object.
+ * Given a drawable and a stipple pattern this function draws the
+ * pattern repeatedly over the drawable. The drawable can then
+ * be used as a mask for bit-bliting a stipple pattern over an
+ * object.
*
* Results:
- * A BitMap data structure.
+ * A BitMap data structure.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
BitMapPtr
TkMacOSXMakeStippleMap(
- Drawable drawable, /* Window to apply stipple. */
- Drawable stipple) /* The stipple pattern. */
+ Drawable drawable, /* Window to apply stipple. */
+ Drawable stipple) /* The stipple pattern. */
{
GWorldPtr destPort;
BitMapPtr bitmapPtr;
- Rect portRect;
- int width, height, stippleHeight, stippleWidth, i, j;
- char *data;
+ Rect portRect;
+ int width, height, stippleHeight, stippleWidth;
+ int i, j;
+ char * data;
Rect bounds;
destPort = TkMacOSXGetDrawablePort(drawable);
@@ -2050,7 +2039,7 @@ TkMacOSXMakeStippleMap(
bounds.bottom = i + stippleHeight;
CopyBits(GetPortBitMapForCopyBits(destPort), bitmapPtr,
- &portRect, &bounds, srcCopy, NULL);
+ &portRect, &bounds, srcCopy, NULL);
}
}
return bitmapPtr;
@@ -2061,20 +2050,20 @@ TkMacOSXMakeStippleMap(
*
* InvertByte --
*
- * This function reverses the bits in the passed in Byte of data.
+ * This function reverses the bits in the passed in Byte of data.
*
* Results:
- * The incoming byte in reverse bit order.
+ * The incoming byte in reverse bit order.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
static unsigned char
InvertByte(
- unsigned char data) /* Byte of data. */
+ unsigned char data) /* Byte of data. */
{
unsigned char i;
unsigned char mask = 1, result = 0;
@@ -2093,32 +2082,32 @@ InvertByte(
*
* TkpDrawHighlightBorder --
*
- * This procedure draws a rectangular ring around the outside of a widget
- * to indicate that it has received the input focus.
+ * This procedure draws a rectangular ring around the outside of
+ * a widget to indicate that it has received the input focus.
*
- * On the Macintosh, this puts a 1 pixel border in the bgGC color between
- * the widget and the focus ring, except in the case where highlightWidth
- * is 1, in which case the border is left out.
+ * On the Macintosh, this puts a 1 pixel border in the bgGC color
+ * between the widget and the focus ring, except in the case where
+ * highlightWidth is 1, in which case the border is left out.
*
- * For proper Mac L&F, use highlightWidth of 3.
+ * For proper Mac L&F, use highlightWidth of 3.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * A rectangle "width" pixels wide is drawn in "drawable", corresponding
- * to the outer area of "tkwin".
+ * A rectangle "width" pixels wide is drawn in "drawable",
+ * corresponding to the outer area of "tkwin".
*
*----------------------------------------------------------------------
*/
void
TkpDrawHighlightBorder (
- Tk_Window tkwin,
- GC fgGC,
- GC bgGC,
- int highlightWidth,
- Drawable drawable)
+ Tk_Window tkwin,
+ GC fgGC,
+ GC bgGC,
+ int highlightWidth,
+ Drawable drawable)
{
if (highlightWidth == 1) {
TkDrawInsetFocusHighlight (tkwin, fgGC, highlightWidth, drawable, 0);
@@ -2136,8 +2125,8 @@ TkpDrawHighlightBorder (
*
* TkpDrawFrame --
*
- * This procedure draws the rectangular frame area. If the user has
- * request themeing, it draws with a the background theme.
+ * This procedure draws the rectangular frame area. If the user
+ * has request themeing, it draws with a the background theme.
*
* Results:
* None.
@@ -2149,20 +2138,15 @@ TkpDrawHighlightBorder (
*/
void
-TkpDrawFrame(
- Tk_Window tkwin,
- Tk_3DBorder border,
- int highlightWidth,
- int borderWidth,
- int relief)
+TkpDrawFrame (Tk_Window tkwin, Tk_3DBorder border,
+ int highlightWidth, int borderWidth, int relief)
{
if (useThemedToplevel && Tk_IsTopLevel(tkwin)) {
/*
- * Currently only support themed toplevels, until we can better factor
- * this to handle individual windows (blanket theming of frames will
- * work for very few UIs).
+ * Currently only support themed toplevels, until we can better
+ * factor this to handle individual windows (blanket theming of
+ * frames will work for very few UIs).
*/
-
Rect bounds;
Point origin;
CGrafPtr saveWorld;
@@ -2191,21 +2175,15 @@ TkpDrawFrame(
EraseRect(&bounds);
SetGWorld(saveWorld, saveDevice);
- XCopyArea(display, pixmap, Tk_WindowId(tkwin), gc, 0, 0, bounds.right,
- bounds.bottom, 0, 0);
+ XCopyArea(display, pixmap, Tk_WindowId(tkwin),
+ gc, 0, 0, bounds.right, bounds.bottom, 0, 0);
Tk_FreePixmap(display, pixmap);
Tk_FreeGC(display, gc);
} else {
- Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, highlightWidth,
- highlightWidth, Tk_Width(tkwin) - 2 * highlightWidth,
- Tk_Height(tkwin) - 2 * highlightWidth, borderWidth, relief);
+ Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
+ border, highlightWidth, highlightWidth,
+ Tk_Width(tkwin) - 2 * highlightWidth,
+ Tk_Height(tkwin) - 2 * highlightWidth,
+ borderWidth, relief);
}
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c
index dd90d6e..b94606e 100644
--- a/macosx/tkMacOSXEvent.c
+++ b/macosx/tkMacOSXEvent.c
@@ -1,4 +1,4 @@
-/*
+/*
* tkMacOSXEvent.c --
*
* This file contains the basic Mac OS X Event handling routines.
@@ -7,23 +7,23 @@
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2005-2006 Daniel A. Steffen <das@users.sourceforge.net>
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.13 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.14 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
-
+
/*
*----------------------------------------------------------------------
*
* TkMacOSXFlushWindows --
*
- * This routine flushes all the Carbon windows of the application. It is
- * called by the setup procedure for the Tcl/Carbon event source.
+ * This routine flushes all the Carbon windows of the application. It
+ * is called by the setup procedure for the Tcl/Carbon event source.
*
* Results:
* None.
@@ -35,10 +35,10 @@
*/
MODULE_SCOPE void
-TkMacOSXFlushWindows(void)
+TkMacOSXFlushWindows ()
{
WindowRef wRef = GetWindowList();
-
+
while (wRef) {
CGrafPtr portPtr = GetWindowPort(wRef);
if (QDIsPortBuffered(portPtr)) {
@@ -48,61 +48,62 @@ TkMacOSXFlushWindows(void)
}
}
-/*
+/*
*----------------------------------------------------------------------
- *
+ *
* TkMacOSXProcessEvent --
- *
+ *
* This dispatches a filtered Carbon event to the appropriate handler
*
* Note on MacEventStatus.stopProcessing: Please be conservative in the
- * individual handlers and don't assume the event is fully handled unless
- * you *really* need to ensure that other handlers don't see the event
- * anymore. Some OS manager or library might be interested in events even
- * after they are already handled on the Tk level.
+ * individual handlers and don't assume the event is fully handled
+ * unless you *really* need to ensure that other handlers don't see the
+ * event anymore. Some OS manager or library might be interested in
+ * events even after they are already handled on the Tk level.
*
- * Results:
+ * Results:
* 0 on success
* -1 on failure
*
* Side effects:
* Converts a Carbon event to a Tk event
- *
+ *
*----------------------------------------------------------------------
*/
-MODULE_SCOPE int
-TkMacOSXProcessEvent(
- TkMacOSXEvent *eventPtr,
- MacEventStatus *statusPtr)
+MODULE_SCOPE int
+TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
{
switch (eventPtr->eClass) {
- case kEventClassMouse:
- TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
- break;
- case kEventClassWindow:
- TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
- break;
- case kEventClassKeyboard:
- TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
- break;
- case kEventClassApplication:
- TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
- break;
- case kEventClassMenu:
- TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
- break;
- case kEventClassCommand:
- TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
- break;
- default: {
- char buf[256];
-
- LOG_MSG("Unrecognised event : %s\n",
- TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
- break;
- }
- }
+ case kEventClassMouse:
+ TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassWindow:
+ TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassKeyboard:
+ TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassApplication:
+ TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassMenu:
+ TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassCommand:
+ TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
+ break;
+ default:
+#ifdef TK_MAC_DEBUG
+ {
+ char buf [256];
+ fprintf(stderr,
+ "Unrecognised event : %s\n",
+ TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
+ }
+#endif
+ break;
+ }
return 0;
}
@@ -111,8 +112,8 @@ TkMacOSXProcessEvent(
*
* TkMacOSXProcessMenuEvent --
*
- * This routine processes the event in eventPtr, and generates the
- * appropriate Tk events from it.
+ * This routine processes the event in eventPtr, and
+ * generates the appropriate Tk events from it.
*
* Results:
* True if event(s) are generated - false otherwise.
@@ -124,37 +125,37 @@ TkMacOSXProcessEvent(
*/
MODULE_SCOPE int
-TkMacOSXProcessMenuEvent(
- TkMacOSXEvent *eventPtr,
- MacEventStatus *statusPtr)
+TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
- int menuContext;
- OSStatus status;
+ int menuContext;
+ OSStatus status;
switch (eventPtr->eKind) {
- case kEventMenuBeginTracking:
- case kEventMenuEndTracking:
- break;
- default:
- return 0;
- break;
+ case kEventMenuBeginTracking:
+ case kEventMenuEndTracking:
+ break;
+ default:
+ return 0;
+ break;
}
- status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext,
- typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext);
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamMenuContext,
+ typeUInt32, NULL,
+ sizeof(menuContext), NULL,
+ &menuContext);
if (status == noErr && (menuContext & kMenuContextMenuBar)) {
static int oldMode = TCL_SERVICE_ALL;
-
if (eventPtr->eKind == kEventMenuBeginTracking) {
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
TkMacOSXClearMenubarActive();
-
+
/*
* Handle -postcommand
*/
-
+
TkMacOSXPreprocessMenu();
} else {
- Tcl_SetServiceMode(oldMode);
+ Tcl_SetServiceMode(oldMode);
}
}
return 0;
@@ -165,8 +166,8 @@ TkMacOSXProcessMenuEvent(
*
* TkMacOSXProcessCommandEvent --
*
- * This routine processes the event in eventPtr, and generates the
- * appropriate Tk events from it.
+ * This routine processes the event in eventPtr, and
+ * generates the appropriate Tk events from it.
*
* Results:
* True if event(s) are generated - false otherwise.
@@ -178,29 +179,32 @@ TkMacOSXProcessMenuEvent(
*/
MODULE_SCOPE int
-TkMacOSXProcessCommandEvent(
- TkMacOSXEvent *eventPtr,
- MacEventStatus *statusPtr)
+TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
- HICommand command;
- int menuContext;
- OSStatus status;
+ HICommand command;
+ int menuContext;
+ OSStatus status;
switch (eventPtr->eKind) {
- case kEventCommandProcess:
- case kEventCommandUpdateStatus:
- break;
- default:
- return 0;
- break;
+ case kEventCommandProcess:
+ case kEventCommandUpdateStatus:
+ break;
+ default:
+ return 0;
+ break;
}
- status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject,
- typeHICommand, NULL, sizeof(command), NULL, &command);
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamDirectObject,
+ typeHICommand, NULL,
+ sizeof(command), NULL,
+ &command);
if (status == noErr && (command.attributes & kHICommandFromMenu)) {
if (eventPtr->eKind == kEventCommandProcess) {
- status = GetEventParameter(eventPtr->eventRef,
- kEventParamMenuContext, typeUInt32, NULL,
- sizeof(menuContext), NULL, &menuContext);
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamMenuContext,
+ typeUInt32, NULL,
+ sizeof(menuContext), NULL,
+ &menuContext);
if (status == noErr && (menuContext & kMenuContextMenuBar) &&
(menuContext & kMenuContextMenuBarTracking)) {
TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
@@ -208,26 +212,26 @@ TkMacOSXProcessCommandEvent(
GetCurrentEventKeyModifiers() & optionKey);
return 1;
}
- } else if (command.commandID == kHICommandPreferences
- && eventPtr->interp) {
+ } else {
Tcl_CmdInfo dummy;
-
- if (Tcl_GetCommandInfo(eventPtr->interp,
- "::tk::mac::ShowPreferences", &dummy)) {
- if (!IsMenuItemEnabled(command.menu.menuRef,
- command.menu.menuItemIndex)) {
- EnableMenuItem(command.menu.menuRef,
- command.menu.menuItemIndex);
- }
- } else {
- if (IsMenuItemEnabled(command.menu.menuRef,
- command.menu.menuItemIndex)) {
- DisableMenuItem(command.menu.menuRef,
- command.menu.menuItemIndex);
+ if (command.commandID == kHICommandPreferences && eventPtr->interp) {
+ if (Tcl_GetCommandInfo(eventPtr->interp,
+ "::tk::mac::ShowPreferences", &dummy)) {
+ if (!IsMenuItemEnabled(command.menu.menuRef,
+ command.menu.menuItemIndex)) {
+ EnableMenuItem(command.menu.menuRef,
+ command.menu.menuItemIndex);
+ }
+ } else {
+ if (IsMenuItemEnabled(command.menu.menuRef,
+ command.menu.menuItemIndex)) {
+ DisableMenuItem(command.menu.menuRef,
+ command.menu.menuItemIndex);
+ }
}
+ statusPtr->stopProcessing = 1;
+ return 1;
}
- statusPtr->stopProcessing = 1;
- return 1;
}
}
return 0;
@@ -252,17 +256,17 @@ TkMacOSXProcessCommandEvent(
*/
MODULE_SCOPE OSStatus
-TkMacOSXReceiveAndProcessEvent(void)
+TkMacOSXReceiveAndProcessEvent()
{
static EventTargetRef targetRef = NULL;
EventRef eventRef;
OSStatus err;
/*
- * This is a poll, since we have already counted the events coming into
- * this routine, and are guaranteed to have one waiting.
+ * This is a poll, since we have already counted the events coming
+ * into this routine, and are guaranteed to have one waiting.
*/
-
+
err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef);
if (err == noErr) {
if (!targetRef) {
@@ -273,10 +277,11 @@ TkMacOSXReceiveAndProcessEvent(void)
TkMacOSXStopTclEventLoopCarbonTimer();
#ifdef TK_MAC_DEBUG
if (err != noErr && err != eventLoopTimedOutErr
- && err != eventNotHandledErr) {
- char buf[256];
-
- ERR_MSG("RCNE SendEventToEventTarget (%s) failed, %d",
+ && err != eventNotHandledErr
+ ) {
+ char buf [256];
+ fprintf(stderr,
+ "RCNE SendEventToEventTarget (%s) failed, %d\n",
TkMacOSXCarbonEventToAscii(eventRef, buf), (int)err);
}
#endif
@@ -284,11 +289,3 @@ TkMacOSXReceiveAndProcessEvent(void)
}
return err;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 00e88ac..2f81ae5 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -1,8 +1,8 @@
/*
* tkMacOSXFont.c --
*
- * Contains the Macintosh implementation of the platform-independant font
- * package interface. This version uses ATSU instead of Quickdraw.
+ * Contains the Macintosh implementation of the platform-independant
+ * font package interface. This version uses ATSU instead of Quickdraw.
*
* Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de
*
@@ -16,6 +16,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
+ *
* Todos:
*
* - Get away from Font Manager and Quickdraw functions as much as possible,
@@ -25,16 +26,16 @@
* instead of just assuming that they are the same.
*
* - Get a second font register going for fonts that are not assigned to a
- * font family by the OS. On my system I have 27 fonts of that type, Hebrew,
- * Arabic and Hindi fonts that actually come with the system.
+ * font family by the OS. On my system I have 27 fonts of that type,
+ * Hebrew, Arabic and Hindi fonts that actually come with the system.
* FMGetFontFamilyInstanceFromFont() returns -981 (kFMInvalidFontFamilyErr)
- * for these and they are not listed when enumerating families, but they are
- * when enumerating fonts directly. The problem that the OS sees may be that
- * at least some of them do not contain any Latin characters. Note that such
- * fonts can not be used for controls, because controls definitely require a
- * family id (this assertion needs testing).
+ * for these and they are not listed when enumerating families, but they
+ * are when enumerating fonts directly. The problem that the OS sees may
+ * be that at least some of them do not contain any Latin characters. Note
+ * that such fonts can not be used for controls, because controls
+ * definitely require a family id (this assertion needs testing).
*
- * RCS: @(#) $Id: tkMacOSXFont.c,v 1.22 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXFont.c,v 1.23 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -45,47 +46,40 @@
#define TK_MAC_DEBUG_FONTS
#endif
*/
-#ifdef TK_MAC_DEBUG_FONTS
-#define FDBG DBG_MSG
-#else
-#define LOG_ON_ERR(...) /* nothing */
-#define FDBG(...) /* nothing */
-#endif
/* Define macros only available on Mac OS X 10.3 or later */
#ifndef FixedToInt
-#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
+#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
#endif
#ifndef IntToFixed
-#define IntToFixed(a) ((Fixed)(a) << 16)
+#define IntToFixed(a) ((Fixed)(a) << 16)
#endif
/*
- * Problem: The sum of two parts is not the same as the whole. In particular
+ * Problem: The sum of two parts is not the same as the whole. In particular
* the width of two separately measured strings will usually be larger than
- * the width of them pasted together. Tk has a design bug here, because it
- * generally assumes that this kind of arithmetic works. To workaround this,
- * #define TK_MAC_COALESCE_LINE to 1 below, we then avoid lines that tremble
- * and shiver while the cursor passes through them by undercutting the system
- * and behind the scenes pasting strings together that look like they are on
- * the same line and adjacent and that are drawn with the same font. To do
- * this we need some global data.
+ * the width of them pasted together. Tk has a design bug here, because it
+ * generally assumes that this kind of arithmetic works.
+ * To workaround this, #define TK_MAC_COALESCE_LINE to 1 below, we then avoid
+ * lines that tremble and shiver while the cursor passes through them by
+ * undercutting the system and behind the scenes pasting strings together that
+ * look like they are on the same line and adjacent and that are drawn with
+ * the same font. To do this we need some global data.
*/
-
#define TK_MAC_COALESCE_LINE 0
typedef TkMacOSXFont MacFont;
typedef TkMacOSXFontDrawingContext DrawingContext;
/*
- * Information about font families, initialized at startup time. Font families
- * are described by a mapping from UTF-8 names to MacOS font family IDs. The
- * whole list is kept as the sorted array "familyList", allocated with
- * ckrealloc().
+ * Information about font families, initialized at startup time. Font
+ * families are described by a mapping from UTF-8 names to MacOS font family
+ * IDs. The whole list is kept as the sorted array "familyList", allocated
+ * with ckrealloc().
*
* Note: This would have been easier, if we could just have used Tcl hash
- * arrays. Unfortunately there seems to be no pre-packaged non-case-sensitive
- * version of that available.
+ * arrays. Unfortunately there seems to be no pre-packaged
+ * non-case-sensitive version of that available.
*/
typedef struct {
@@ -95,42 +89,43 @@ typedef struct {
static MacFontFamily * familyList = NULL;
static int
- familyListNextFree = 0, /* The next free slot in familyList. */
- familyListMaxValid = 0, /* The top of the sorted area. */
- familyListSize = 0; /* The size of the whole array. */
+ familyListNextFree = 0, /* The next free slot in familyList. */
+ familyListMaxValid = 0, /* The top of the sorted area. */
+ familyListSize = 0; /* The size of the whole array. */
/*
* A simple one-shot sub-allocator for fast and efficient allocation of
- * strings. Used by the familyList array for the names. These strings are only
- * allocated once at startup and never freed. If you ever need to
+ * strings. Used by the familyList array for the names. These strings are
+ * only allocated once at startup and never freed. If you ever need to
* re-initialize this, you can just ckfree() all the StringBlocks in the list
* and start over.
*/
-#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) ==
- * 1024. */
+#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) ==
+ * 1024. */
typedef struct StringBlock {
- struct StringBlock *next; /* Starting from "stringMemory" these
- * blocks form a linked list. */
- int nextFree; /* Top of the used area in the
- * "strings" member. */
- char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */
+ struct StringBlock * next; /* Starting from "stringMemory" these
+ * blocks form a linked list. */
+ int nextFree; /* Top of the used area in the
+ * "strings" member. */
+ char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */
} StringBlock;
-static StringBlock *stringMemory = NULL;
+static StringBlock * stringMemory = NULL;
+
#if TK_MAC_COALESCE_LINE
-static Tcl_DString currentLine; /* The current line as seen so far. This
- * contains a Tcl_UniChar DString. */
+static Tcl_DString currentLine; /* The current line as seen so far. This
+ * contains a Tcl_UniChar DString. */
static int
- currentY = -1, /* The Y position (row in pixels) of the
- * current line. */
- currentLeft = -1, /* The left edge (pixels) of the current
- * line. */
- currentRight = -1; /* The right edge (pixels) of the current
- * line. */
-static const MacFont *currentFontPtr = NULL;
- /* The font of the current line. */
+ currentY = -1, /* The Y position (row in pixels) of the
+ * current line. */
+ currentLeft = -1, /* The left edge (pixels) of the current
+ * line. */
+ currentRight = -1; /* The right edge (pixels) of the current
+ * line. */
+static const MacFont * currentFontPtr = NULL;
+ /* The font of the current line. */
#endif /* TK_MAC_COALESCE_LINE */
static int antialiasedTextEnabled;
@@ -140,7 +135,7 @@ static int antialiasedTextEnabled;
*/
#define SYSTEMFONT_NAME "system"
-#define APPLFONT_NAME "application"
+#define APPLFONT_NAME "application"
/*
* Procedures used only in this file.
@@ -150,88 +145,104 @@ static int antialiasedTextEnabled;
* The actual workers.
*/
-static void MacFontDrawText(const MacFont *fontPtr,
- const char * source, int numBytes, int rangeStart,
- int rangeLength, int x, int y);
-static int MeasureStringWidth(const MacFont *fontPtr,
- int start, int end);
+static void MacFontDrawText(
+ const MacFont * fontPtr,
+ const char * source, int numBytes,
+ int rangeStart, int rangeLength,
+ int x, int y);
+static int MeasureStringWidth(
+ const MacFont * fontPtr,
+ int start, int end);
+
#if TK_MAC_COALESCE_LINE
-static const Tcl_UniChar* UpdateLineBuffer(const MacFont * fontPtr,
- const DrawingContext *drawingContextPtr,
- const char *source, int numBytes, int x, int y,
- int *offset);
+static const Tcl_UniChar * UpdateLineBuffer(
+ const MacFont * fontPtr,
+ const DrawingContext * drawingContextPtr,
+ const char * source, int numBytes,
+ int x, int y,
+ int * offset);
#endif /* TK_MAC_COALESCE_LINE */
/*
* Initialization and setup of a font data structure.
*/
-static void InitFont(Tk_Window tkwin, FMFontFamily familyId,
- const char * familyName, int size, int qdStyle,
- MacFont * fontPtr);
-static void InitATSUObjects(FMFontFamily familyId, short qdsize,
- short qdStyle, ATSUFontID * fontIdPtr,
- ATSUTextLayout *layoutPtr, ATSUStyle *stylePtr);
-static void InitATSUStyle(ATSUFontID fontId, short ptSize,
- short qdStyle, ATSUStyle style);
-static void SetFontFeatures(ATSUFontID fontId, int fixed,
- ATSUStyle style);
-static void AdjustFontHeight(MacFont *fontPtr);
-static void InitATSULayout(const DrawingContext*drawingContextPtr,
- ATSUTextLayout layout, int fixed);
-static void ReleaseFont(MacFont *fontPtr);
+static void InitFont(
+ Tk_Window tkwin,
+ FMFontFamily familyId, const char * familyName,
+ int size, int qdStyle, MacFont * fontPtr);
+static void InitATSUObjects(
+ FMFontFamily familyId,
+ short qdsize, short qdStyle,
+ ATSUFontID * fontIdPtr,
+ ATSUTextLayout * layoutPtr, ATSUStyle * stylePtr);
+static void InitATSUStyle(
+ ATSUFontID fontId, short ptSize, short qdStyle,
+ ATSUStyle style);
+static void SetFontFeatures(
+ ATSUFontID fontId, int fixed,
+ ATSUStyle style);
+static void AdjustFontHeight(
+ MacFont * fontPtr);
+static void InitATSULayout(
+ const DrawingContext * drawingContextPtr,
+ ATSUTextLayout layout, int fixed);
+static void ReleaseFont(
+ MacFont * fontPtr);
/*
* Finding fonts by name.
*/
-static const MacFontFamily* FindFontFamilyOrAlias(const char *name);
-static const MacFontFamily* FindFontFamilyOrAliasOrFallback(const char*name);
+static const MacFontFamily * FindFontFamilyOrAlias(
+ const char * name);
+static const MacFontFamily * FindFontFamilyOrAliasOrFallback(
+ const char * name);
/*
* Doing interesting things with font families and fonts.
*/
-static void InitFontFamilies(void);
-static OSStatus GetFontFamilyName(FMFontFamily fontFamily, char *name,
- int numBytes);
+static void InitFontFamilies(void);
+static OSStatus GetFontFamilyName(
+ FMFontFamily fontFamily, char * name, int numBytes);
/*
* Accessor functions and internal utilities for the font family list.
*/
-static const MacFontFamily * AddFontFamily(const char *name,
- FMFontFamily familyId);
+static const MacFontFamily * AddFontFamily(
+ const char * name, FMFontFamily familyId);
static const MacFontFamily * FindFontFamily(const char * name);
-static Tcl_Obj * EnumFontFamilies(void);
+static Tcl_Obj * EnumFontFamilies(void);
+
+static OSStatus FontFamilyEnumCallback(ATSFontFamilyRef family, void *refCon);
+static void SortFontFamilies(void);
+static int CompareFontFamilies(const void * vp1, const void * vp2);
+static const char * AddString(const char * in);
-static OSStatus FontFamilyEnumCallback(ATSFontFamilyRef family,
- void *refCon);
-static void SortFontFamilies(void);
-static int CompareFontFamilies(const void *vp1, const void *vp2);
-static const char * AddString(const char *in);
/*
*-------------------------------------------------------------------------
*
* TkpFontPkgInit --
*
- * This procedure is called when an application is created. It
- * initializes all the structures that are used by the platform-dependant
- * code on a per application basis.
+ * This procedure is called when an application is created. It
+ * initializes all the structures that are used by the
+ * platform-dependant code on a per application basis.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Initialization of variables local to this file.
+ * Initialization of variables local to this file.
*
*-------------------------------------------------------------------------
*/
void
TkpFontPkgInit(
- TkMainInfo *mainPtr) /* The application being created. */
+ TkMainInfo * mainPtr) /* The application being created. */
{
InitFontFamilies();
@@ -239,7 +250,10 @@ TkpFontPkgInit(
Tcl_DStringInit(&currentLine);
#endif
- FDBG("tkMacOSXFont.c (ATSU version) intialized (" __TIME__ ")");
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "tkMacOSXFont.c (ATSU version) intialized "
+ "(" __TIME__ ")\n");
+#endif
}
/*
@@ -247,41 +261,41 @@ TkpFontPkgInit(
*
* TkpGetNativeFont --
*
- * Map a platform-specific native font name to a TkFont.
+ * Map a platform-specific native font name to a TkFont.
*
* Results:
- * The return value is a pointer to a TkFont that represents the native
- * font. If a native font by the given name could not be found, the
- * return value is NULL.
+ * The return value is a pointer to a TkFont that represents the
+ * native font. If a native font by the given name could not be
+ * found, the return value is NULL.
*
- * Every call to this procedure returns a new TkFont structure, even if
- * the name has already been seen before. The caller should call
- * TkpDeleteFont() when the font is no longer needed.
+ * Every call to this procedure returns a new TkFont structure, even
+ * if the name has already been seen before. The caller should call
+ * TkpDeleteFont() when the font is no longer needed.
*
- * The caller is responsible for initializing the memory associated with
- * the generic TkFont when this function returns and releasing the
- * contents of the generics TkFont before calling TkpDeleteFont().
+ * The caller is responsible for initializing the memory associated
+ * with the generic TkFont when this function returns and releasing
+ * the contents of the generics TkFont before calling TkpDeleteFont().
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
TkFont *
TkpGetNativeFont(
- Tk_Window tkwin, /* For display where font will be used. */
- const char * name) /* Platform-specific font name. */
+ Tk_Window tkwin, /* For display where font will be used. */
+ const char * name) /* Platform-specific font name. */
{
FMFontFamily familyId;
MacFont * fontPtr;
if (strcmp(name, SYSTEMFONT_NAME) == 0) {
- familyId = GetSysFont();
+ familyId = GetSysFont();
} else if (strcmp(name, APPLFONT_NAME) == 0) {
- familyId = GetAppFont();
+ familyId = GetAppFont();
} else {
- return NULL;
+ return NULL;
}
fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
@@ -295,74 +309,74 @@ TkpGetNativeFont(
*
* TkpGetFontFromAttributes --
*
- * Given a desired set of attributes for a font, find a font with the
- * closest matching attributes.
+ * Given a desired set of attributes for a font, find a font with the
+ * closest matching attributes.
*
* Results:
- * The return value is a pointer to a TkFont that represents the font
- * with the desired attributes. If a font with the desired attributes
- * could not be constructed, some other font will be substituted
- * automatically.
+ * The return value is a pointer to a TkFont that represents the font
+ * with the desired attributes. If a font with the desired attributes
+ * could not be constructed, some other font will be substituted
+ * automatically.
*
- * Every call to this procedure returns a new TkFont structure, even if
- * the specified attributes have already been seen before. The caller
- * should call TkpDeleteFont() to free the platform-specific data when
- * the font is no longer needed.
+ * Every call to this procedure returns a new TkFont structure, even
+ * if the specified attributes have already been seen before. The
+ * caller should call TkpDeleteFont() to free the platform- specific
+ * data when the font is no longer needed.
*
- * The caller is responsible for initializing the memory associated with
- * the generic TkFont when this function returns and releasing the
- * contents of the generic TkFont before calling TkpDeleteFont().
+ * The caller is responsible for initializing the memory associated
+ * with the generic TkFont when this function returns and releasing
+ * the contents of the generic TkFont before calling TkpDeleteFont().
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
TkFont *
TkpGetFontFromAttributes(
- TkFont *tkFontPtr, /* If non-NULL, store the information in this
- * existing TkFont structure, rather than
- * allocating a new structure to hold the
- * font; the existing contents of the font
- * will be released. If NULL, a new TkFont
- * structure is allocated. */
- Tk_Window tkwin, /* For display where font will be used. */
- const TkFontAttributes *faPtr)
- /* Set of attributes to match. */
+ TkFont * tkFontPtr, /* If non-NULL, store the information in this
+ * existing TkFont structure, rather than
+ * allocating a new structure to hold the font;
+ * the existing contents of the font will be
+ * released. If NULL, a new TkFont structure is
+ * allocated. */
+ Tk_Window tkwin, /* For display where font will be used. */
+ const TkFontAttributes * faPtr)
+ /* Set of attributes to match. */
{
short qdStyle;
FMFontFamily familyId;
- const char *name;
- const MacFontFamily *familyPtr;
- MacFont *fontPtr;
+ const char * name;
+ const MacFontFamily * familyPtr;
+ MacFont * fontPtr;
familyId = GetAppFont();
name = NULL;
qdStyle = 0;
if (faPtr->family != NULL) {
- familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family);
- if (familyPtr != NULL) {
- name = familyPtr->name;
- familyId = familyPtr->familyId;
- }
+ familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family);
+ if (familyPtr != NULL) {
+ name = familyPtr->name;
+ familyId = familyPtr->familyId;
+ }
}
if (faPtr->weight != TK_FW_NORMAL) {
- qdStyle |= bold;
+ qdStyle |= bold;
}
if (faPtr->slant != TK_FS_ROMAN) {
- qdStyle |= italic;
+ qdStyle |= italic;
}
if (faPtr->underline) {
- qdStyle |= underline;
+ qdStyle |= underline;
}
if (tkFontPtr == NULL) {
- fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
+ fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
} else {
- fontPtr = (MacFont *) tkFontPtr;
- ReleaseFont(fontPtr);
+ fontPtr = (MacFont *) tkFontPtr;
+ ReleaseFont(fontPtr);
}
InitFont(tkwin, familyId, name, faPtr->size, qdStyle, fontPtr);
@@ -374,23 +388,23 @@ TkpGetFontFromAttributes(
*
* TkpDeleteFont --
*
- * Called to release a font allocated by TkpGetNativeFont() or
- * TkpGetFontFromAttributes(). The caller should have already released
- * the fields of the TkFont that are used exclusively by the generic
- * TkFont code.
+ * Called to release a font allocated by TkpGetNativeFont() or
+ * TkpGetFontFromAttributes(). The caller should have already
+ * released the fields of the TkFont that are used exclusively by the
+ * generic TkFont code.
*
* Results:
- * TkFont is deallocated.
+ * TkFont is deallocated.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
void
TkpDeleteFont(
- TkFont *tkFontPtr) /* Token of font to be deleted. */
+ TkFont * tkFontPtr) /* Token of font to be deleted. */
{
ReleaseFont((MacFont *) tkFontPtr);
}
@@ -400,23 +414,23 @@ TkpDeleteFont(
*
* TkpGetFontFamilies --
*
- * Return information about the font families that are available on the
- * display of the given window.
+ * Return information about the font families that are available on
+ * the display of the given window.
*
* Results:
- * Modifies interp's result object to hold a list of all the available
- * font families.
+ * Modifies interp's result object to hold a list of all the available
+ * font families.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
void
TkpGetFontFamilies(
- Tcl_Interp *interp, /* Interp to hold result. */
- Tk_Window tkwin) /* For display to query. */
+ Tcl_Interp * interp, /* Interp to hold result. */
+ Tk_Window tkwin) /* For display to query. */
{
Tcl_SetObjResult(interp,EnumFontFamilies());
}
@@ -426,30 +440,28 @@ TkpGetFontFamilies(
*
* TkpGetSubFonts --
*
- * A function used by the testing package for querying the actual screen
- * fonts that make up a font object.
+ * A function used by the testing package for querying the actual
+ * screen fonts that make up a font object.
*
* Results:
- * Modifies interp's result object to hold a list containing the names of
- * the screen fonts that make up the given font object.
+ * Modifies interp's result object to hold a list containing the names
+ * of the screen fonts that make up the given font object.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
void
TkpGetSubFonts(
- Tcl_Interp *interp, /* Interp to hold result. */
- Tk_Font tkfont) /* Font object to query. */
+ Tcl_Interp * interp, /* Interp to hold result. */
+ Tk_Font tkfont) /* Font object to query. */
{
- /*
- * We don't know much about our fallback fonts, ATSU does all that for us.
- * We could use ATSUMatchFont to implement this function. But as the
- * information is only used for testing, such an effort seems not very
- * useful.
- */
+ /* We don't know much about our fallback fonts, ATSU does all that for
+ * us. We could use ATSUMatchFont to implement this function. But as
+ * the information is only used for testing, such an effort seems not
+ * very useful. */
}
/*
@@ -457,24 +469,24 @@ TkpGetSubFonts(
*
* TkpGetFontAttrsForChar --
*
- * Retrieve the font attributes of the actual font used to render a given
- * character.
+ * Retrieve the font attributes of the actual font used to render a
+ * given character.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The font attributes are stored in *faPtr.
+ * The font attributes are stored in *faPtr.
*
*----------------------------------------------------------------------
*/
void
TkpGetFontAttrsForChar(
- Tk_Window tkwin, /* Window on the font's display */
- Tk_Font tkfont, /* Font to query */
- Tcl_UniChar c, /* Character of interest */
- TkFontAttributes* faPtr) /* Output: Font attributes */
+ Tk_Window tkwin, /* Window on the font's display */
+ Tk_Font tkfont, /* Font to query */
+ Tcl_UniChar c, /* Character of interest */
+ TkFontAttributes* faPtr) /* Output: Font attributes */
{
TkMacOSXFont* fontPtr = (TkMacOSXFont*) tkfont;
UniChar uchar = c;
@@ -485,8 +497,8 @@ TkpGetFontAttrsForChar(
UniCharCount changedLength;
/*
- * Most of the attributes are just copied from the base font. This assumes
- * that all fonts can have all attributes.
+ * Most of the attributes are just copied from the base font. This
+ * assumes that all fonts can have all attributes.
*/
*faPtr = fontPtr->font.fa;
@@ -503,46 +515,57 @@ TkpGetFontAttrsForChar(
TkMacOSXLayoutSetString(fontPtr, &drawingContext, &uchar, 1);
fontId = fontPtr->atsuFontId;
- err = ATSUMatchFontsToText(fontPtr->atsuLayout, 0, 1,
- &fontId, &changedOffset, &changedLength);
+ err = ATSUMatchFontsToText(
+ fontPtr->atsuLayout, 0, 1,
+ &fontId, &changedOffset, &changedLength);
#ifdef TK_MAC_DEBUG_FONTS
if (err != kATSUFontsMatched && err != noErr) {
- FDBG("TkpGetFontAttrsForChar: Can't match \\u%04X", (unsigned) c);
+ fprintf(stderr, "TkpGetFontAttrsForChar: "
+ "Can't match \\u%04X\n",
+ (unsigned) c);
}
#endif
if (err == kATSUFontsMatched) {
- /*
- * A fallback was used and the actual font is in fontId. Determine the
- * name.
- */
-
- FMFontFamily fontFamilyId;
- FMFontStyle fontStyle;
- int i;
-
- err = FMGetFontFamilyInstanceFromFont(fontId, &fontFamilyId,
- &fontStyle);
- LOG_ON_ERR(FMGetFontFamilyInstanceFromFont);
-
- if (err == noErr) {
- /*
- * Find the canonical name in our global list.
- */
-
- for (i=0; i<familyListMaxValid; ++i) {
- if (fontFamilyId == familyList[i].familyId) {
- faPtr->family = familyList[i].name;
- break;
- }
- }
+
+ /*
+ * A fallback was used and the actual font is in fontId. Determine
+ * the name.
+ */
+
+ FMFontFamily fontFamilyId;
+ FMFontStyle fontStyle;
+ int i;
+
+ err = FMGetFontFamilyInstanceFromFont(
+ fontId, &fontFamilyId, &fontStyle);
#ifdef TK_MAC_DEBUG_FONTS
- if (i >= familyListMaxValid) {
- FDBG("TkpGetFontAttrsForChar: Can't find font %d for \\u%04X",
- (int) fontFamilyId, (unsigned) c);
- }
+ if (err != noErr) {
+ fprintf(stderr, "FMGetFontFamilyInstanceFromFont: Error %d\n",
+ (int) err);
+ }
#endif
- }
+
+ if (err == noErr) {
+
+ /*
+ * Find the canonical name in our global list.
+ */
+
+ for (i=0; i<familyListMaxValid; ++i) {
+ if (fontFamilyId == familyList[i].familyId) {
+ faPtr->family = familyList[i].name;
+ break;
+ }
+ }
+#ifdef TK_MAC_DEBUG_FONTS
+ if (i >= familyListMaxValid) {
+ fprintf(stderr, "TkpGetFontAttrsForChar: "
+ "Can't find font %d for \\u%04X\n",
+ (int) fontFamilyId, (unsigned) c);
+ }
+#endif
+ }
}
#if TK_MAC_USE_QUARZ
@@ -553,124 +576,133 @@ TkpGetFontAttrsForChar(
/*
*---------------------------------------------------------------------------
*
- * Tk_MeasureChars --
+ * Tk_MeasureChars --
*
- * Determine the number of characters from the string that will fit in
- * the given horizontal span. The measurement is done under the
- * assumption that Tk_DrawChars() will be used to actually display the
- * characters.
+ * Determine the number of characters from the string that will fit in
+ * the given horizontal span. The measurement is done under the
+ * assumption that Tk_DrawChars() will be used to actually display the
+ * characters.
*
- * With ATSUI we need the line context to do this right, so we have the
- * actual implementation in TkpMeasureCharsInContext().
+ * With ATSUI we need the line context to do this right, so we have the
+ * actual implementation in TkpMeasureCharsInContext().
*
* Results:
- * The return value is the number of bytes from source that fit into the
- * span that extends from 0 to maxLength. *lengthPtr is filled with the
- * x-coordinate of the right edge of the last character that did fit.
+ *
+ * The return value is the number of bytes from source that fit into the
+ * span that extends from 0 to maxLength. *lengthPtr is filled with the
+ * x-coordinate of the right edge of the last character that did fit.
*
* Side effects:
- * None.
+ *
+ * None.
*
* Todo:
- * Effects of the "flags" parameter are untested.
+ *
+ * Effects of the "flags" parameter are untested.
*
*---------------------------------------------------------------------------
*/
int
Tk_MeasureChars(
- Tk_Font tkfont, /* Font in which characters will be drawn. */
- const char *source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. */
- int numBytes, /* Maximum number of bytes to consider from
- * source string. */
- int maxLength, /* If >= 0, maxLength specifies the longest
- * permissible line length; don't consider any
- * character that would cross this x-position.
- * If < 0, then line length is unbounded and
- * the flags argument is ignored. */
- int flags, /* Various flag bits OR-ed together:
- * TK_PARTIAL_OK means include the last char
- * which only partially fit on this line.
- * TK_WHOLE_WORDS means stop on a word
- * boundary, if possible. TK_AT_LEAST_ONE
- * means return at least one character even if
- * no characters fit. */
- int *lengthPtr) /* Filled with x-location just after the
- * terminating character. */
+ Tk_Font tkfont, /* Font in which characters will be drawn. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. */
+ int numBytes, /* Maximum number of bytes to consider from
+ * source string. */
+ int maxLength, /* If >= 0, maxLength specifies the longest
+ * permissible line length; don't consider any
+ * character that would cross this x-position.
+ * If < 0, then line length is unbounded and the
+ * flags argument is ignored. */
+ int flags, /* Various flag bits OR-ed together:
+ * TK_PARTIAL_OK means include the last char
+ * which only partially fit on this line.
+ * TK_WHOLE_WORDS means stop on a word boundary,
+ * if possible. TK_AT_LEAST_ONE means return at
+ * least one character even if no characters
+ * fit. */
+ int * lengthPtr) /* Filled with x-location just after the
+ * terminating character. */
{
- return TkpMeasureCharsInContext(tkfont, source, numBytes, 0, numBytes,
- maxLength, flags, lengthPtr);
+ return TkpMeasureCharsInContext(
+ tkfont, source, numBytes, 0, numBytes, maxLength, flags, lengthPtr);
}
/*
*---------------------------------------------------------------------------
*
- * TkpMeasureCharsInContext --
+ * TkpMeasureCharsInContext --
*
- * Determine the number of bytes from the string that will fit in the
- * given horizontal span. The measurement is done under the assumption
- * that TkpDrawCharsInContext() will be used to actually display the
- * characters.
+ * Determine the number of bytes from the string that will fit in the
+ * given horizontal span. The measurement is done under the assumption
+ * that TkpDrawCharsInContext() will be used to actually display the
+ * characters.
*
- * This one is almost the same as Tk_MeasureChars(), but with access to
- * all the characters on the line for context.
+ * This one is almost the same as Tk_MeasureChars(), but with access to
+ * all the characters on the line for context.
*
* Results:
- * The return value is the number of bytes from source that fit into the
- * span that extends from 0 to maxLength. *lengthPtr is filled with the
- * x-coordinate of the right edge of the last character that did fit.
+ * The return value is the number of bytes from source that
+ * fit into the span that extends from 0 to maxLength. *lengthPtr is
+ * filled with the x-coordinate of the right edge of the last
+ * character that did fit.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
int
TkpMeasureCharsInContext(
- Tk_Font tkfont, /* Font in which characters will be drawn. */
- const char * source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. */
- int numBytes, /* Maximum number of bytes to consider from
- * source string in all. */
- int rangeStart, /* Index of first byte to measure. */
- int rangeLength, /* Length of range to measure in bytes. */
- int maxLength, /* If >= 0, maxLength specifies the longest
- * permissible line length; don't consider any
- * character that would cross this x-position.
- * If < 0, then line length is unbounded and
- * the flags argument is ignored. */
- int flags, /* Various flag bits OR-ed together:
- * TK_PARTIAL_OK means include the last char
- * which only partially fits on this line.
- * TK_WHOLE_WORDS means stop on a word
- * boundary, if possible. TK_AT_LEAST_ONE
- * means return at least one character (or at
- * least the first partial word in case
- * TK_WHOLE_WORDS is also set) even if no
- * characters (words) fit. TK_ISOLATE_END
- * means that the last character should not be
- * considered in context with the rest of the
- * string (used for breaking lines). */
- int *lengthPtr) /* Filled with x-location just after the
- * terminating character. */
+ Tk_Font tkfont, /* Font in which characters will be drawn. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. */
+ int numBytes, /* Maximum number of bytes to consider from
+ * source string in all. */
+ int rangeStart, /* Index of first byte to measure. */
+ int rangeLength, /* Length of range to measure in bytes. */
+ int maxLength, /* If >= 0, maxLength specifies the longest
+ * permissible line length; don't consider any
+ * character that would cross this x-position.
+ * If < 0, then line length is unbounded and the
+ * flags argument is ignored. */
+ int flags, /* Various flag bits OR-ed together:
+ * TK_PARTIAL_OK means include the last char
+ * which only partially fits on this line.
+ * TK_WHOLE_WORDS means stop on a word boundary,
+ * if possible.
+ * TK_AT_LEAST_ONE means return at least one
+ * character (or at least the first partial word
+ * in case TK_WHOLE_WORDS is also set) even if no
+ * characters (words) fit.
+ * TK_ISOLATE_END means that the last character
+ * should not be considered in context with the
+ * rest of the string (used for breaking
+ * lines). */
+ int * lengthPtr) /* Filled with x-location just after the
+ * terminating character. */
{
- const MacFont *fontPtr = (const MacFont *) tkfont;
- int curX = -1, curByte = 0;
- UniChar *uchars;
+ const MacFont * fontPtr = (const MacFont *) tkfont;
+ int curX = -1;
+ int curByte = 0;
+ UniChar * uchars;
int ulen, urstart, urlen, urend;
Tcl_DString ucharBuffer;
DrawingContext drawingContext;
+
/*
* Sanity checks.
*/
if ((rangeStart < 0) || ((rangeStart+rangeLength) > numBytes)) {
- FDBG("MeasureChars: bad parameters");
- *lengthPtr = 0;
- return 0;
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "MeasureChars: bad parameters\n");
+#endif
+ *lengthPtr = 0;
+ return 0;
}
/*
@@ -679,11 +711,13 @@ TkpMeasureCharsInContext(
if (rangeLength == 0 || (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) {
#ifdef TK_MAC_DEBUG_FONTS
- fflush(stdout);
+ fflush(stdout);
+ fprintf(stderr, "measure: '%.*s', empty\n",
+ rangeLength, source+rangeStart);
+ fflush(stderr);
#endif
- FDBG("measure: '%.*s', empty", rangeLength, source+rangeStart);
- *lengthPtr = 0;
- return 0;
+ *lengthPtr = 0;
+ return 0;
}
#if TK_MAC_USE_QUARZ
@@ -700,217 +734,242 @@ TkpMeasureCharsInContext(
urend = urstart + urlen;
if (maxLength < 0) {
- curX = MeasureStringWidth(fontPtr, urstart, urend);
- curByte = rangeLength;
+
+ curX = MeasureStringWidth(fontPtr, urstart, urend);
+ curByte = rangeLength;
+
} else {
- UniCharArrayOffset offset = 0;
- OSStatus err;
-
- /*
- * Have some upper limit on the size actually used.
- */
-
- if (maxLength > 32767) {
- maxLength = 32767;
- }
-
- offset = urstart;
- err = noErr;
-
- if (maxLength > 1) {
- /*
- * Let the system do some work by calculating a line break.
- *
- * Somehow ATSUBreakLine seems to assume that it needs at least
- * one pixel padding. So we add one to the limit. Note also that
- * ATSUBreakLine sometimes runs into an endless loop when the
- * third parameter is equal or less than IntToFixed(2), so we need
- * at least IntToFixed(3) (at least that's the current state of my
- * knowledge).
- */
-
- err = ATSUBreakLine(fontPtr->atsuLayout, urstart,
- IntToFixed(maxLength+1), false, /* !iUseAsSoftLineBreak */
- &offset);
-
- /*
- * There is no way to signal an error from this routine, so we use
- * predefined offset=urstart and otherwise ignore the possibility.
- */
+
+ UniCharArrayOffset offset = 0;
+ OSStatus err;
+
+ /*
+ * Have some upper limit on the size actually used.
+ */
+
+ if (maxLength > 32767) {
+ maxLength = 32767;
+ }
+
+ offset = urstart;
+ err = noErr;
+
+ if (maxLength > 1) {
+
+ /*
+ * Let the system do some work by calculating a line break.
+ *
+ * Somehow ATSUBreakLine seems to assume that it needs at least
+ * one pixel padding. So we add one to the limit. Note also
+ * that ATSUBreakLine sometimes runs into an endless loop when
+ * the third parameter is equal or less than IntToFixed(2), so we
+ * need at least IntToFixed(3) (at least that's the current state
+ * of my knowledge).
+ */
+
+ err = ATSUBreakLine(
+ fontPtr->atsuLayout,
+ urstart,
+ IntToFixed(maxLength+1),
+ false, /* !iUseAsSoftLineBreak */
+ &offset);
+
+ /*
+ * There is no way to signal an error from this routine, so we
+ * use predefined offset=urstart and otherwise ignore the
+ * possibility.
+ */
#ifdef TK_MAC_DEBUG_FONTS
- if ((err != noErr) && (err != kATSULineBreakInWord)) {
- FDBG("ATSUBreakLine(): Error %d for '%.*s'",
- (int) err, rangeLength, source+rangeStart);
- }
+ if ((err != noErr) && (err != kATSULineBreakInWord)) {
+ fprintf(stderr, "ATSUBreakLine(): Error %d for '%.*s'\n",
+ (int) err, rangeLength, source+rangeStart);
+ }
#endif
- FDBG("measure: '%.*s', break offset=%d, errcode=%d",
- rangeLength, source+rangeStart, (int) offset, (int) err);
-
- /*
- * ATSUBreakLine includes the whitespace that separates words, but
- * we don't want that. Besides, ATSUBreakLine thinks that spaces
- * don't occupy pixels at the end of the break, which is also
- * something we like to decide for ourself.
- */
-
- while ((offset > (UniCharArrayOffset)urstart)
- && (uchars[offset-1] == ' ')) {
- offset--;
- }
-
- /*
- * Fix up left-overs for the TK_WHOLE_WORDS case.
- */
-
- if (flags & TK_WHOLE_WORDS) {
- if (flags & TK_AT_LEAST_ONE) {
- /*
- * If we are the the start of the range, we need to look
- * forward. If we are not at the end of a word, we must be
- * in the middle of the first word, so we also look
- * forward.
- */
-
- if ((offset == (UniCharArrayOffset)urstart)
- || (uchars[offset] != ' ')) {
- while ((offset < (UniCharArrayOffset)urend)
- && (uchars[offset] != ' ')) {
- offset++;
- }
- }
- } else {
- /*
- * If we are not at the end of a word, we need to look
- * backward.
- */
-
- if ((offset != (UniCharArrayOffset)urend)
- && (uchars[offset] != ' ')) {
- while ((offset > (UniCharArrayOffset)urstart)
- && (uchars[offset-1] != ' ')) {
- offset--;
- }
- while ((offset > (UniCharArrayOffset)urstart)
- && (uchars[offset-1] == ' ')) {
- offset--;
- }
- }
- }
- }
- }
-
- if (offset > (UniCharArrayOffset)urend) {
- offset = urend;
- }
-
- /*
- * If "flags" says that we don't actually want a word break, we need
- * to find the next character break ourself, as ATSUBreakLine() will
- * only give us word breaks. Do a simple linear search.
- */
-
- if ((err != kATSULineBreakInWord)
- && !(flags & TK_WHOLE_WORDS)
- && (offset <= (UniCharArrayOffset)urend)) {
- UniCharArrayOffset lastOffset = offset;
- UniCharArrayOffset nextoffset;
- int lastX = -1;
- int wantonemorechar = -1; /* undecided */
-
- while (offset <= (UniCharArrayOffset)urend) {
- if (flags & TK_ISOLATE_END) {
- TkMacOSXLayoutSetString(fontPtr, &drawingContext,
- uchars, offset);
- }
- curX = MeasureStringWidth(fontPtr, urstart, offset);
-
- FDBG("measure: '%.*s', try until=%d, width=%d",
- rangeLength, source+rangeStart, (int) offset, curX);
-
- if (curX > maxLength) {
- /*
- * Even if we are over the limit, we may want another
- * character in some situations. Than we keep looking for
- * one more character.
- */
-
- if (wantonemorechar == -1) {
- wantonemorechar =
- ((flags & TK_AT_LEAST_ONE)
- && (lastOffset == (UniCharArrayOffset)urstart))
- || ((flags & TK_PARTIAL_OK)
- && (lastX != maxLength));
- if (!wantonemorechar) {
- break;
- }
- lastX = curX;
- }
-
- /*
- * There may belong combining marks to this character.
- * Wait for a new curX to collect them all.
- */
-
- if (lastX != curX) {
- break;
- }
- }
-
- /*
- * Save this position, so we can come back to it.
- */
-
- lastX = curX;
- lastOffset = offset;
-
- /*
- * Increment offset by one character, taking combining marks
- * into account.
- */
-
- if (offset >= (UniCharArrayOffset)urend) {
- break;
- }
- nextoffset = 0;
- if (flags & TK_ISOLATE_END) {
- TkMacOSXLayoutSetString(fontPtr, &drawingContext,
- uchars, ulen);
- }
- err = ATSUNextCursorPosition(fontPtr->atsuLayout, offset,
- kATSUByCluster, &nextoffset);
- if (err != noErr) {
- FDBG("ATSUNextCursorPosition(): Error %d", (int) err);
- break;
- }
- if (nextoffset <= offset) {
- FDBG("ATSUNextCursorPosition(): Can't move further "
- "(shouldn't happen, bad data?)");
- break;
- }
-
- offset = nextoffset;
- }
-
- /*
- * We have overshot one character, so backup one position.
- */
-
- curX = lastX;
- offset = lastOffset;
- }
-
- if (curX < 0) {
- if (flags & TK_ISOLATE_END) {
- TkMacOSXLayoutSetString(fontPtr, &drawingContext,
- uchars, offset);
- }
- curX = MeasureStringWidth(fontPtr, urstart, offset);
- }
-
- curByte = Tcl_UtfAtIndex(source, offset) - source;
- curByte -= rangeStart;
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "measure: '%.*s', break offset=%d, errcode=%d\n",
+ rangeLength, source+rangeStart, (int) offset, (int) err);
+#endif
+
+ /*
+ * ATSUBreakLine includes the whitespace that separates words,
+ * but we don't want that. Besides, ATSUBreakLine thinks that
+ * spaces don't occupy pixels at the end of the break, which is
+ * also something we like to decide for ourself.
+ */
+
+ while ((offset > (UniCharArrayOffset)urstart) && (uchars[offset-1] == ' ')) {
+ offset--;
+ }
+
+ /*
+ * Fix up left-overs for the TK_WHOLE_WORDS case.
+ */
+
+ if (flags & TK_WHOLE_WORDS) {
+ if(flags & TK_AT_LEAST_ONE) {
+
+ /*
+ * If we are the the start of the range, we need to look
+ * forward. If we are not at the end of a word, we must
+ * be in the middle of the first word, so we also look
+ * forward.
+ */
+
+ if ((offset == (UniCharArrayOffset)urstart) || (uchars[offset] != ' ')) {
+ while ((offset < (UniCharArrayOffset)urend)
+ && (uchars[offset] != ' ')) {
+ offset++;
+ }
+ }
+ } else {
+
+ /*
+ * If we are not at the end of a word, we need to look
+ * backward.
+ */
+
+ if ((offset != (UniCharArrayOffset)urend) && (uchars[offset] != ' ')) {
+ while ((offset > (UniCharArrayOffset)urstart)
+ && (uchars[offset-1] != ' ')) {
+ offset--;
+ }
+ while ((offset > (UniCharArrayOffset)urstart)
+ && (uchars[offset-1] == ' ')) {
+ offset--;
+ }
+ }
+ }
+ }
+ }
+
+ if (offset > (UniCharArrayOffset)urend) {
+ offset = urend;
+ }
+
+ /*
+ * If "flags" says that we don't actually want a word break, we need
+ * to find the next character break ourself, as ATSUBreakLine() will
+ * only give us word breaks. Do a simple linear search.
+ */
+
+ if ((err != kATSULineBreakInWord)
+ && !(flags & TK_WHOLE_WORDS)
+ && (offset <= (UniCharArrayOffset)urend)) {
+
+ UniCharArrayOffset lastOffset = offset;
+ UniCharArrayOffset nextoffset;
+ int lastX = -1;
+ int wantonemorechar = -1; /* undecided */
+
+ while (offset <= (UniCharArrayOffset)urend) {
+
+ if (flags & TK_ISOLATE_END) {
+ TkMacOSXLayoutSetString(fontPtr, &drawingContext,
+ uchars, offset);
+ }
+ curX = MeasureStringWidth(fontPtr, urstart, offset);
+
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "measure: '%.*s', try until=%d, width=%d\n",
+ rangeLength, source+rangeStart, (int) offset, curX);
+#endif
+
+ if (curX > maxLength) {
+
+ /*
+ * Even if we are over the limit, we may want another
+ * character in some situations. Than we keep looking
+ * for one more character.
+ */
+
+ if (wantonemorechar == -1) {
+ wantonemorechar =
+ ((flags & TK_AT_LEAST_ONE)
+ && (lastOffset == (UniCharArrayOffset)urstart))
+ ||
+ ((flags & TK_PARTIAL_OK)
+ && (lastX != maxLength))
+ ;
+ if (!wantonemorechar) {
+ break;
+ }
+ lastX = curX;
+ }
+
+ /*
+ * There may belong combining marks to this character.
+ * Wait for a new curX to collect them all.
+ */
+
+ if (lastX != curX) {
+ break;
+ }
+ }
+
+ /*
+ * Save this position, so we can come back to it.
+ */
+
+ lastX = curX;
+ lastOffset = offset;
+
+ /*
+ * Increment offset by one character, taking combining marks
+ * into account.
+ */
+
+ if (offset >= (UniCharArrayOffset)urend) {
+ break;
+ }
+ nextoffset = 0;
+ if (flags & TK_ISOLATE_END) {
+ TkMacOSXLayoutSetString(fontPtr, &drawingContext,
+ uchars, ulen);
+ }
+ err = ATSUNextCursorPosition(
+ fontPtr->atsuLayout,
+ offset,
+ kATSUByCluster,
+ &nextoffset);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "ATSUNextCursorPosition(): "
+ "Error %d\n", (int) err);
+#endif
+ break;
+ }
+ if (nextoffset <= offset) {
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "ATSUNextCursorPosition(): "
+ "Can't move further "
+ "(shouldn't happen, bad data?)\n");
+#endif
+ break;
+ }
+
+ offset = nextoffset;
+ }
+
+ /*
+ * We have overshot one character, so backup one position.
+ */
+
+ curX = lastX;
+ offset = lastOffset;
+ }
+
+ if (curX < 0) {
+ if (flags & TK_ISOLATE_END) {
+ TkMacOSXLayoutSetString(fontPtr, &drawingContext,
+ uchars, offset);
+ }
+ curX = MeasureStringWidth(fontPtr, urstart, offset);
+ }
+
+ curByte = Tcl_UtfAtIndex(source, offset) - source;
+ curByte -= rangeStart;
}
Tcl_DStringFree(&ucharBuffer);
@@ -921,12 +980,13 @@ TkpMeasureCharsInContext(
#ifdef TK_MAC_DEBUG_FONTS
fflush(stdout);
- FDBG("measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, flags=%s%s%s%s",
- rangeLength, source+rangeStart, maxLength, curX, curByte,
- flags & TK_PARTIAL_OK ? "partialOk " : "",
- flags & TK_WHOLE_WORDS ? "wholeWords " : "",
- flags & TK_AT_LEAST_ONE ? "atLeastOne " : "",
- flags & TK_ISOLATE_END ? "isolateEnd " : "");
+ fprintf(stderr, "measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, "
+ "flags=%s%s%s%s\n",
+ rangeLength, source+rangeStart, maxLength, curX, curByte,
+ flags & TK_PARTIAL_OK ? "partialOk " : "",
+ flags & TK_WHOLE_WORDS ? "wholeWords " : "",
+ flags & TK_AT_LEAST_ONE ? "atLeastOne " : "",
+ flags & TK_ISOLATE_END ? "isolateEnd " : "");
fflush(stderr);
#endif
@@ -939,40 +999,42 @@ TkpMeasureCharsInContext(
*
* Tk_DrawChars --
*
- * Draw a string of characters on the screen.
+ * Draw a string of characters on the screen.
*
- * With ATSUI we need the line context to do this right, so we have the
- * actual implementation in TkpDrawCharsInContext().
+ * With ATSUI we need the line context to do this right, so we have the
+ * actual implementation in TkpDrawCharsInContext().
*
* Results:
- * None.
+ *
+ * None.
*
* Side effects:
- * Information gets drawn on the screen.
+ *
+ * Information gets drawn on the screen.
*
*---------------------------------------------------------------------------
*/
void
Tk_DrawChars(
- Display *display, /* Display on which to draw. */
- Drawable drawable, /* Window or pixmap in which to draw. */
- GC gc, /* Graphics context for drawing characters. */
- Tk_Font tkfont, /* Font in which characters will be drawn; must
- * be the same as font used in GC. */
- const char *source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. All Tk meta-characters
- * (tabs, control characters, and newlines)
- * should be stripped out of the string that
- * is passed to this function. If they are not
- * stripped out, they will be displayed as
- * regular printing characters. */
- int numBytes, /* Number of bytes in string. */
- int x, int y) /* Coordinates at which to place origin of the
- * string when drawing. */
+ Display * display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context for drawing characters. */
+ Tk_Font tkfont, /* Font in which characters will be drawn; must
+ * be the same as font used in GC. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. All Tk meta-characters
+ * (tabs, control characters, and newlines)
+ * should be stripped out of the string that is
+ * passed to this function. If they are not
+ * stripped out, they will be displayed as
+ * regular printing characters. */
+ int numBytes, /* Number of bytes in string. */
+ int x, int y) /* Coordinates at which to place origin of the
+ * string when drawing. */
{
TkpDrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
- 0, numBytes, x, y);
+ 0, numBytes, x, y);
}
@@ -981,45 +1043,46 @@ Tk_DrawChars(
*
* TkpDrawCharsInContext --
*
- * Draw a string of characters on the screen like Tk_DrawChars(), with
- * access to all the characters on the line for context.
+ * Draw a string of characters on the screen like Tk_DrawChars(), with
+ * access to all the characters on the line for context.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Information gets drawn on the screen.
+ * Information gets drawn on the screen.
*
* Todo:
- * We could try to implement a correct stipple algorithm.
*
- * The fiddling with QD GraphPorts can be replaced with just working with
- * the Quarz CGContext (see TkMacOSXQuarzStartDraw()), once we decide to
- * stick to Quarz and really forget about QD drawing in here.
+ * We could try to implement a correct stipple algorithm.
+ *
+ * The fiddling with QD GraphPorts can be replaced with just working
+ * with the Quarz CGContext (see TkMacOSXQuarzStartDraw()), once we
+ * decide to stick to Quarz and really forget about QD drawing in here.
*
*---------------------------------------------------------------------------
*/
void
TkpDrawCharsInContext(
- Display *display, /* Display on which to draw. */
- Drawable drawable, /* Window or pixmap in which to draw. */
- GC gc, /* Graphics context for drawing characters. */
- Tk_Font tkfont, /* Font in which characters will be drawn; must
- * be the same as font used in GC. */
- const char * source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. All Tk meta-characters
- * (tabs, control characters, and newlines)
- * should be stripped out of the string that
- * is passed to this function. If they are not
- * stripped out, they will be displayed as
- * regular printing characters. */
- int numBytes, /* Number of bytes in string. */
- int rangeStart, /* Index of first byte to draw. */
- int rangeLength, /* Length of range to draw in bytes. */
- int x, int y) /* Coordinates at which to place origin of the
- * whole (not just the range) string when
- * drawing. */
+ Display * display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context for drawing characters. */
+ Tk_Font tkfont, /* Font in which characters will be drawn; must
+ * be the same as font used in GC. */
+ const char * source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. All Tk meta-characters
+ * (tabs, control characters, and newlines)
+ * should be stripped out of the string that is
+ * passed to this function. If they are not
+ * stripped out, they will be displayed as
+ * regular printing characters. */
+ int numBytes, /* Number of bytes in string. */
+ int rangeStart, /* Index of first byte to draw. */
+ int rangeLength, /* Length of range to draw in bytes. */
+ int x, int y) /* Coordinates at which to place origin of the
+ * whole (not just the range) string when
+ * drawing. */
{
const MacFont * fontPtr;
MacDrawable * macWin;
@@ -1044,52 +1107,54 @@ TkpDrawCharsInContext(
GetForeColor(&origColor);
if ((gc->fill_style == FillStippled
- || gc->fill_style == FillOpaqueStippled)
- && gc->stipple != None) {
- Pixmap pixmap;
- GWorldPtr bufferPort;
- Pattern white;
-
- stippleMap = TkMacOSXMakeStippleMap(drawable, gc->stipple);
-
- pixmap = Tk_GetPixmap(display, drawable,
- stippleMap->bounds.right, stippleMap->bounds.bottom, 0);
-
- bufferPort = TkMacOSXGetDrawablePort(pixmap);
- SetGWorld(bufferPort, NULL);
-
- if (TkSetMacColor(gc->foreground, &macColor)) {
- RGBForeColor(&macColor);
- }
- GetQDGlobalsWhite(&white);
- ShowPen();
- FillRect(&stippleMap->bounds, &white);
- MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength,
- 0, 0);
- HidePen();
-
- SetGWorld(destPort, NULL);
-
- CopyDeepMask(GetPortBitMapForCopyBits(bufferPort), stippleMap,
- GetPortBitMapForCopyBits(destPort), &stippleMap->bounds,
- &stippleMap->bounds, &portRect, srcOr, NULL);
-
- /*
- * TODO: this doesn't work quite right - it does a blend. You can't
- * draw white text when you have a stipple.
- */
-
- Tk_FreePixmap(display, pixmap);
- ckfree(stippleMap->baseAddr);
- ckfree((char *)stippleMap);
+ || gc->fill_style == FillOpaqueStippled)
+ && gc->stipple != None) {
+
+ Pixmap pixmap;
+ GWorldPtr bufferPort;
+ Pattern white;
+
+ stippleMap = TkMacOSXMakeStippleMap(drawable, gc->stipple);
+
+ pixmap = Tk_GetPixmap(display, drawable,
+ stippleMap->bounds.right, stippleMap->bounds.bottom, 0);
+
+ bufferPort = TkMacOSXGetDrawablePort(pixmap);
+ SetGWorld(bufferPort, NULL);
+
+ if (TkSetMacColor(gc->foreground, &macColor)) {
+ RGBForeColor(&macColor);
+ }
+ GetQDGlobalsWhite(&white);
+ ShowPen();
+ FillRect(&stippleMap->bounds, &white);
+ MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength,
+ 0, 0);
+ HidePen();
+
+ SetGWorld(destPort, NULL);
+
+ CopyDeepMask(GetPortBitMapForCopyBits(bufferPort), stippleMap,
+ GetPortBitMapForCopyBits(destPort), &stippleMap->bounds,
+ &stippleMap->bounds, &portRect,
+ srcOr, NULL);
+
+ /*
+ * TODO: this doesn't work quite right - it does a blend. you can't
+ * draw white text when you have a stipple.
+ */
+
+ Tk_FreePixmap(display, pixmap);
+ ckfree(stippleMap->baseAddr);
+ ckfree((char *)stippleMap);
} else {
- if (TkSetMacColor(gc->foreground, &macColor)) {
- RGBForeColor(&macColor);
- }
- ShowPen();
- MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength,
- macWin->xOff + x, macWin->yOff + y);
- HidePen();
+ if (TkSetMacColor(gc->foreground, &macColor)) {
+ RGBForeColor(&macColor);
+ }
+ ShowPen();
+ MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength,
+ macWin->xOff + x, macWin->yOff + y);
+ HidePen();
}
RGBForeColor(&origColor);
@@ -1106,31 +1171,34 @@ TkpDrawCharsInContext(
*
* TkMacOSXQuarzStartDraw --
*
- * Setup a Quarz CGContext from the current QD GraphPort for use in
- * drawing or measuring.
+ * Setup a Quarz CGContext from the current QD GraphPort for use in
+ * drawing or measuring.
*
* Results:
- * A CGContext is allocated, configured and returned in
- * drawingContextPtr. Also drawingContextPtr->portRect is filled in.
+ *
+ * A CGContext is allocated, configured and returned in
+ * drawingContextPtr. Also drawingContextPtr->portRect is filled in.
*
* Side effects:
- * None.
+ *
+ * None.
*
* Assumptions:
- * The current QD GraphPort contains all the data necessary. This is
- * clearly the case for the actual drawing, but not so clear for
- * measuring. OTOH for measuring the specific parameters are not really
- * interesting and the GraphPort is not changed either. The availability
- * of a CGContext may be important for the measuring process though.
+ *
+ * The current QD GraphPort contains all the data necessary. This is
+ * clearly the case for the actual drawing, but not so clear for
+ * measuring. OTOH for measuring the specific parameters are not really
+ * interesting and the GraphPort is not changed either. The
+ * availability of a CGContext may be important for the measuring
+ * process though.
*
*-------------------------------------------------------------------------
*/
void
TkMacOSXQuarzStartDraw(
- DrawingContext *drawingContextPtr)
- /* Quarz context data filled in by this
- * function. */
+ DrawingContext * drawingContextPtr) /* Quarz context data filled in
+ * by this function. */
{
GDHandle currentDevice;
CGrafPtr destPort;
@@ -1145,47 +1213,53 @@ TkMacOSXQuarzStartDraw(
err = QDBeginCGContext(destPort, &outContext);
if (err == noErr && outContext) {
- /*
- * Now clip the CG Context to the port. We also have to intersect our
- * clip region with the port visible region so we don't overwrite the
- * window decoration.
- */
-
- if (!clipRgn) {
- clipRgn = NewRgn();
- }
-
- GetPortBounds(destPort, &boundsRect);
-
- RectRgn(clipRgn, &boundsRect);
- SectRegionWithPortClipRegion(destPort, clipRgn);
- SectRegionWithPortVisibleRegion(destPort, clipRgn);
- ClipCGContextToRegion(outContext, &boundsRect, clipRgn);
- SetEmptyRgn(clipRgn);
-
- /*
- * Note: You have to call SyncCGContextOriginWithPort AFTER all the
- * clip region manipulations.
- */
-
- SyncCGContextOriginWithPort(outContext, destPort);
-
- /*
- * Scale the color values, as QD uses UInt16 with the range
- * [0..2^16-1] while Quarz uses float with [0..1]. NB: Only
- * CGContextSetRGBFillColor() seems to be actually used by ATSU.
- */
-
- GetForeColor(&macColor);
- CGContextSetRGBFillColor(outContext, RGBFLOATRED(macColor),
- RGBFLOATGREEN(macColor), RGBFLOATBLUE(macColor), 1.0f);
+ /*
+ * Now clip the CG Context to the port. We also have to intersect our clip
+ * region with the port visible region so we don't overwrite the window
+ * decoration.
+ */
+
+ if (!clipRgn) {
+ clipRgn = NewRgn();
+ }
+
+ GetPortBounds(destPort, &boundsRect);
+
+ RectRgn(clipRgn, &boundsRect);
+ SectRegionWithPortClipRegion(destPort, clipRgn);
+ SectRegionWithPortVisibleRegion(destPort, clipRgn);
+ ClipCGContextToRegion(outContext, &boundsRect, clipRgn);
+ SetEmptyRgn(clipRgn);
+
+ /*
+ * Note: You have to call SyncCGContextOriginWithPort
+ * AFTER all the clip region manipulations.
+ */
+
+ SyncCGContextOriginWithPort(outContext, destPort);
+
+ /*
+ * Scale the color values, as QD uses UInt16 with the range [0..2^16-1]
+ * while Quarz uses float with [0..1]. NB: Only
+ * CGContextSetRGBFillColor() seems to be actually used by ATSU.
+ */
+
+ GetForeColor(&macColor);
+ CGContextSetRGBFillColor(outContext,
+ RGBFLOATRED(macColor),
+ RGBFLOATGREEN(macColor),
+ RGBFLOATBLUE(macColor),
+ 1.0f);
+ #ifdef TK_MAC_DEBUG_FONTS
} else {
- FDBG("QDBeginCGContext(): Error %d", (int) err);
+ fprintf(stderr, "QDBeginCGContext(): Error %d\n", (int) err);
+ #endif
}
drawingContextPtr->graphPort = destPort;
drawingContextPtr->cgContext = outContext;
drawingContextPtr->portRect = boundsRect;
+
}
/*
@@ -1193,16 +1267,16 @@ TkMacOSXQuarzStartDraw(
*
* TkMacOSXQuarzEndDraw --
*
- * Free the Quarz CGContext in drawingContextPtr.
+ * Free the Quarz CGContext in drawingContextPtr.
*
* Results:
*
- * The CGContext is de-allocated. drawingContextPtr->cgContext will be
- * invalid after this.
+ * The CGContext is de-allocated. drawingContextPtr->cgContext will be
+ * invalid after this.
*
* Side effects:
*
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
@@ -1213,8 +1287,8 @@ TkMacOSXQuarzEndDraw(
{
if (drawingContextPtr->cgContext) {
QDEndCGContext(
- drawingContextPtr->graphPort,
- &drawingContextPtr->cgContext);
+ drawingContextPtr->graphPort,
+ &drawingContextPtr->cgContext);
}
}
#endif /* TK_MAC_USE_QUARZ */
@@ -1224,28 +1298,28 @@ TkMacOSXQuarzEndDraw(
*
* MacFontDrawText --
*
- * Helper function for Tk_DrawChars. Draws characters, using the screen
- * font in fontPtr to draw multilingual characters.
+ * Helper function for Tk_DrawChars. Draws characters, using the
+ * screen font in fontPtr to draw multilingual characters.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Information gets drawn on the screen.
+ * Information gets drawn on the screen.
*
*-------------------------------------------------------------------------
*/
static void
MacFontDrawText(
- const MacFont *fontPtr, /* Contains font to use when drawing
- * following string. */
- const char *source, /* Potentially multilingual UTF-8 string. */
- int numBytes, /* Length of string in bytes. */
- int rangeStart, /* Index of first byte to draw. */
- int rangeLength, /* Length of range to draw in bytes. */
- int x, int y) /* Coordinates at which to place origin of
- * string when drawing. */
+ const MacFont * fontPtr, /* Contains font to use when drawing
+ * following string. */
+ const char * source, /* Potentially multilingual UTF-8 string. */
+ int numBytes, /* Length of string in bytes. */
+ int rangeStart, /* Index of first byte to draw. */
+ int rangeLength, /* Length of range to draw in bytes. */
+ int x, int y) /* Coordinates at which to place origin of
+ * string when drawing. */
{
Fixed fx, fy;
int ulen, urstart, urlen;
@@ -1258,11 +1332,12 @@ MacFontDrawText(
Tcl_DString runString;
#endif
+
#if TK_MAC_USE_QUARZ
TkMacOSXQuarzStartDraw(&drawingContext);
/*
- * Turn the y coordinate upside-down for Quarz drawing. We would have
+ * Turn the y coordinate upside-down for Quarz drawing. We would have
* liked to just use a CTM transform in the CGContext, but than we get
* upside-down text, so doing it that way gets more painfull than to just
* hack around the problem right here.
@@ -1274,9 +1349,10 @@ MacFontDrawText(
fy = IntToFixed(y);
#endif
+
#if TK_MAC_COALESCE_LINE
- UpdateLineBuffer(fontPtr, &drawingContext, source, numBytes, x, y,
- &lineOffset);
+ UpdateLineBuffer(
+ fontPtr, &drawingContext, source, numBytes, x, y, &lineOffset);
fx = IntToFixed(currentLeft);
@@ -1296,8 +1372,15 @@ MacFontDrawText(
urstart = Tcl_NumUtfChars(source, rangeStart);
urlen = Tcl_NumUtfChars(source+rangeStart,rangeLength);
- err = ATSUDrawText(fontPtr->atsuLayout, lineOffset+urstart, urlen, fx,fy);
- LOG_ON_ERR(ATSUDrawText);
+ err = ATSUDrawText(
+ fontPtr->atsuLayout,
+ lineOffset+urstart, urlen,
+ fx, fy);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUDrawText(): Error %d\n", (int) err);
+ }
+#endif
#if !TK_MAC_COALESCE_LINE
Tcl_DStringFree(&runString);
@@ -1307,42 +1390,46 @@ MacFontDrawText(
TkMacOSXQuarzEndDraw(&drawingContext);
#endif
}
+
/*
*---------------------------------------------------------------------------
*
* MeasureStringWidth --
*
- * Low-level measuring of strings.
+ * Low-level measuring of strings.
*
* Results:
- * The width of the string in pixels.
+ *
+ * The width of the string in pixels.
*
* Side effects:
- * None.
+ *
+ * None.
*
* Assumptions:
- * fontPtr->atsuLayout is setup with the actual string data to measure.
+ *
+ * fontPtr->atsuLayout is setup with the actual string data to measure.
*
*---------------------------------------------------------------------------
*/
static int
MeasureStringWidth(
- const MacFont *fontPtr, /* Contains font, ATSU layout and string data
- * to measure. */
- int start, int end) /* Start and end positions to measure in that
- * string. */
+ const MacFont * fontPtr, /* Contains font, ATSU layout and string data
+ * to measure. */
+ int start, int end) /* Start and end positions to measure in that
+ * string. */
{
/*
* This implementation of measuring via ATSUGetGlyphBounds() does not
* quite conform with the specification given for [font measure]:
*
- * The return value is the total width in pixels of text, not
- * including the extra pixels used by highly exagerrated characters
- * such as cursive "f".
+ * The return value is the total width in pixels of text, not
+ * including the extra pixels used by highly exagerrated characters
+ * such as cursive "f".
*
- * Instead the result of ATSUGetGlyphBounds() *does* include these "extra
- * pixels".
+ * Instead the result of ATSUGetGlyphBounds() *does* include these
+ * "extra pixels".
*/
ATSTrapezoid bounds;
@@ -1350,19 +1437,23 @@ MeasureStringWidth(
OSStatus err;
if (end <= start) {
- return 0;
+ return 0;
}
bounds.upperRight.x = bounds.upperLeft.x = 0;
- err = ATSUGetGlyphBounds(fontPtr->atsuLayout, 0, 0, start, end-start,
- kATSUseFractionalOrigins, 1, &bounds, &numBounds);
+ err = ATSUGetGlyphBounds(
+ fontPtr->atsuLayout,
+ 0, 0,
+ start, end-start,
+ kATSUseFractionalOrigins,
+ 1, &bounds, &numBounds);
#ifdef TK_MAC_DEBUG_FONTS
if (err != noErr) {
- FDBG("ATSUGetGlyphBounds(): Error %d", (int) err);
+ fprintf(stderr, "ATSUGetGlyphBounds(): Error %d\n", (int) err);
} else if (numBounds < 1) {
- FDBG("ATSUGetGlyphBounds(): No output");
+ fprintf(stderr, "ATSUGetGlyphBounds(): No output\n");
} else if (numBounds > 1) {
- FDBG("ATSUGetGlyphBounds(): More output");
+ fprintf(stderr, "ATSUGetGlyphBounds(): More output\n");
}
#endif
@@ -1375,50 +1466,52 @@ MeasureStringWidth(
*
* UpdateLineBuffer --
*
- * See the general dicussion of TK_MAC_COALESCE_LINE on the header pages.
- * This function maintains the data for this feature.
+ * See the general dicussion of TK_MAC_COALESCE_LINE on the header
+ * pages. This function maintains the data for this feature.
*
* Results:
- * The Tcl_UniChar string of the whole line as seen so far.
+ *
+ * The Tcl_UniChar string of the whole line as seen so far.
*
* Side effects:
- * "*offset" is filled with the index of the first new character in
- * "currentLine". The globals currentLine, currentY, currentLeft,
- * currentRight and currentFontPtr are updated as necessary.
*
- * The currentLine string is set as the current text in
- * fontPtr->atsuLayout (see TkMacOSXLayoutSetString()).
+ * "*offset" is filled with the index of the first new character in
+ * "currentLine". The globals currentLine, currentY, currentLeft,
+ * currentRight and currentFontPtr are updated as necessary.
+ *
+ * The currentLine string is set as the current text in
+ * fontPtr->atsuLayout (see TkMacOSXLayoutSetString()).
*
*-------------------------------------------------------------------------
*/
static const Tcl_UniChar *
UpdateLineBuffer(
- const MacFont *fontPtr, /* The font to be used for the new piece of
- * text. */
- const DrawingContext *drawingContextPtr,
- /* The Quarz drawing parameters. Needed for
- * measuring the new piece. */
- const char *source, /* A new piece of line to be added. */
- int numBytes, /* Length of the new piece. */
- int x, int y, /* Position of the new piece in the window. */
- int *offset) /* Filled with the offset of the new piece in
- * currentLine. */
+ const MacFont * fontPtr,/* The font to be used for the new piece of
+ * text. */
+ const DrawingContext * drawingContextPtr,
+ /* The Quarz drawing parameters. Needed for
+ * measuring the new piece. */
+ const char * source, /* A new piece of line to be added. */
+ int numBytes, /* Length of the new piece. */
+ int x, int y, /* Position of the new piece in the window. */
+ int * offset) /* Filled with the offset of the new piece in
+ * currentLine. */
{
const Tcl_UniChar * uchars;
int ulen;
if (y != currentY
- || x < currentRight-1 || x > currentRight+2
- || currentFontPtr != fontPtr) {
- Tcl_DStringFree(&currentLine);
- Tcl_DStringInit(&currentLine);
- currentY = y;
- currentLeft = x;
- currentFontPtr = fontPtr;
- *offset = 0;
+ || x < currentRight-1 || x > currentRight+2
+ || currentFontPtr != fontPtr) {
+ Tcl_DStringFree(&currentLine);
+ Tcl_DStringInit(&currentLine);
+ currentY = y;
+ currentLeft = x;
+ currentFontPtr = fontPtr;
+ *offset = 0;
} else {
- *offset = Tcl_DStringLength(&currentLine) / 2;
+ *offset = Tcl_DStringLength(&currentLine) / 2;
}
Tcl_UtfToUniCharDString(source, numBytes, &currentLine);
@@ -1436,33 +1529,33 @@ UpdateLineBuffer(
*
* InitFont --
*
- * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes().
- * Initializes the memory for a MacFont that wraps the platform-specific
- * data.
+ * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes().
+ * Initializes the memory for a MacFont that wraps the
+ * platform-specific data.
*
- * The caller is responsible for initializing the fields of the TkFont
- * that are used exclusively by the generic TkFont code, and for
- * releasing those fields before calling TkpDeleteFont().
+ * The caller is responsible for initializing the fields of the TkFont
+ * that are used exclusively by the generic TkFont code, and for
+ * releasing those fields before calling TkpDeleteFont().
*
* Results:
- * Fills the MacFont structure.
+ * Fills the MacFont structure.
*
* Side effects:
- * Memory allocated.
+ * Memory allocated.
*
*---------------------------------------------------------------------------
*/
static void
InitFont(
- Tk_Window tkwin, /* For display where font will be used. */
- FMFontFamily familyId, /* The font family to initialize for. */
- const char * familyName, /* The font family name, if known. Otherwise
- * this can be NULL. */
- int size, /* Point size for the font. */
- int qdStyle, /* QuickDraw style bits. */
- MacFont * fontPtr) /* Filled with information constructed from the
- * above arguments. */
+ Tk_Window tkwin, /* For display where font will be used. */
+ FMFontFamily familyId, /* The font family to initialize for. */
+ const char * familyName,/* The font family name, if known. Otherwise
+ * this can be NULL. */
+ int size, /* Point size for the font. */
+ int qdStyle, /* QuickDraw style bits. */
+ MacFont * fontPtr) /* Filled with information constructed from the
+ * above arguments. */
{
OSStatus err;
FontInfo fi;
@@ -1472,31 +1565,38 @@ InitFont(
int periodWidth, wWidth;
if (size == 0) {
- size = GetDefFontSize();
+ size = GetDefFontSize();
}
points = (short) TkFontGetPoints(tkwin, size);
err = FetchFontInfo(familyId, points, qdStyle, &fi);
- LOG_ON_ERR(FetchFontInfo);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "FetchFontInfo(): Error %d\n", (int) err);
+ }
+#endif
if (familyName == NULL) {
- char name[256] = "";
- const MacFontFamily * familyPtr;
-
- err = GetFontFamilyName(familyId, name, sizeof(name));
- if (err == noErr) {
- /*
- * We find the canonical font name, so we can avoid unnecessary
- * memory management.
- */
-
- familyPtr = FindFontFamily(name);
- if (familyPtr != NULL) {
- familyName = familyPtr->name;
- } else {
- FDBG("Font family '%s': Not found", name);
- }
- }
+ char name[256] = "";
+ const MacFontFamily * familyPtr;
+
+ err = GetFontFamilyName(familyId, name, sizeof(name));
+ if (err == noErr) {
+
+ /*
+ * We find the canonical font name, so we can avoid unnecessary
+ * memory management.
+ */
+
+ familyPtr = FindFontFamily(name);
+ if (familyPtr != NULL) {
+ familyName = familyPtr->name;
+ } else {
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "Font family '%s': Not found\n", name);
+#endif
+ }
+ }
}
fontPtr->font.fid = (Font) fontPtr;
@@ -1512,11 +1612,11 @@ InitFont(
fmPtr = &fontPtr->font.fm;
/*
- * Note: Macs measure the line height as ascent + descent + leading.
- * Leading as a separate entity does not exist in X11 and Tk. We add it to
- * the ascent at the moment, because adding it to the descent, as the Mac
- * docs would indicate, would change the position of self-drawn
- * underlines.
+ * Note: Macs measure the line height as ascent + descent +
+ * leading. Leading as a separate entity does not exist in X11
+ * and Tk. We add it to the ascent at the moment, because adding
+ * it to the descent, as the Mac docs would indicate, would change
+ * the position of self-drawn underlines.
*/
fmPtr->ascent = fi.ascent + fi.leading;
@@ -1527,8 +1627,9 @@ InitFont(
fontPtr->qdSize = points;
fontPtr->qdStyle = (short) qdStyle;
- InitATSUObjects(familyId, points, qdStyle,
- &fontPtr->atsuFontId, &fontPtr->atsuLayout, &fontPtr->atsuStyle);
+ InitATSUObjects(
+ familyId, points, qdStyle,
+ &fontPtr->atsuFontId, &fontPtr->atsuLayout, &fontPtr->atsuStyle);
Tk_MeasureChars((Tk_Font)fontPtr, ".", 1, -1, 0, &periodWidth);
Tk_MeasureChars((Tk_Font)fontPtr, "W", 1, -1, 0, &wWidth);
@@ -1544,28 +1645,29 @@ InitFont(
*
* InitATSUObjects --
*
- * Helper for InitFont(). Initializes the ATSU data handles for a
- * MacFont.
+ * Helper for InitFont(). Initializes the ATSU data handles for a
+ * MacFont.
*
* Results:
- * Sets up all we know and can do at this point in time in fontIdPtr,
- * layoutPtr and stylePtr.
+ *
+ * Sets up all we know and can do at this point in time in fontIdPtr,
+ * layoutPtr and stylePtr.
*
* Side effects:
- * Allocates data structures inside of ATSU.
+ *
+ * Allocates data structures inside of ATSU.
*
*---------------------------------------------------------------------------
*/
static void
InitATSUObjects(
- FMFontFamily familyId, /* The font family to use. */
- short ptSize, short qdStyles,
- /* The additional font parameters. */
- ATSUFontID *fontIdPtr, /* Filled with the font id. */
- ATSUTextLayout *layoutPtr, /* Filled with the ATSU layout handle. */
- ATSUStyle *stylePtr) /* Filled with the ATSU style handle,
- * configured with all parameters. */
+ FMFontFamily familyId, /* The font family to use. */
+ short ptSize, short qdStyles, /* The additional font parameters. */
+ ATSUFontID * fontIdPtr, /* Filled with the font id. */
+ ATSUTextLayout * layoutPtr, /* Filled with the ATSU layout handle. */
+ ATSUStyle * stylePtr) /* Filled with the ATSU style handle,
+ * configured with all parameters. */
{
OSStatus err;
FMFontStyle stylesDone, stylesLeft;
@@ -1582,13 +1684,18 @@ InitATSUObjects(
* Generate a font id from family id and QD style bits.
*/
- err = FMGetFontFromFontFamilyInstance(familyId, qdStyles, fontIdPtr,
- &stylesDone);
- LOG_ON_ERR(FMGetFontFromFontFamilyInstance);
+ err = FMGetFontFromFontFamilyInstance(
+ familyId, qdStyles, fontIdPtr, &stylesDone);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "FMGetFontFromFontFamilyInstance(): Error %d\n",
+ (int) err);
+ }
+#endif
/*
- * We see what style bits are left and tell ATSU to synthesize what's left
- * like QD does it.
+ * We see what style bits are left and tell ATSU to synthesize what's
+ * left like QD does it.
*/
stylesLeft = qdStyles & ~(unsigned)stylesDone;
@@ -1598,16 +1705,24 @@ InitATSUObjects(
*/
err = ATSUCreateStyle(stylePtr);
- LOG_ON_ERR(ATSUCreateStyle);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUCreateStyle(): Error %d\n", (int) err);
+ }
+#endif
InitATSUStyle(*fontIdPtr, ptSize, stylesLeft, *stylePtr);
/*
- * Create the layout. Note: We can't set the layout attributes here,
+ * Create the layout. Note: We can't set the layout attributes here,
* because the text and the style must be set first.
*/
err = ATSUCreateTextLayout(layoutPtr);
- LOG_ON_ERR(ATSUCreateTextLayout);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUCreateTextLayout(): Error %d\n", (int) err);
+ }
+#endif
/*InitATSULayout(*layoutPtr);*/
}
@@ -1616,24 +1731,25 @@ InitATSUObjects(
*
* InitATSUStyle --
*
- * Helper for InitATSUObjects(). Initializes the ATSU style for a
- * MacFont.
+ * Helper for InitATSUObjects(). Initializes the ATSU style for a
+ * MacFont.
*
* Results:
- * Sets up all parameters needed for an ATSU style.
+ *
+ * Sets up all parameters needed for an ATSU style.
*
* Side effects:
- * Allocates data structures for the style inside of ATSU.
+ *
+ * Allocates data structures for the style inside of ATSU.
*
*---------------------------------------------------------------------------
*/
static void
InitATSUStyle(
- ATSUFontID fontId, /* The font id to use. */
- short ptSize, short qdStyles,
- /* Additional font parameters. */
- ATSUStyle style) /* The style handle to configure. */
+ ATSUFontID fontId, /* The font id to use. */
+ short ptSize, short qdStyles, /* Additional font parameters. */
+ ATSUStyle style) /* The style handle to configure. */
{
/*
* Attributes for the style.
@@ -1641,59 +1757,69 @@ InitATSUStyle(
Fixed fsize = IntToFixed(ptSize);
Boolean
- isBold = (qdStyles&bold) != 0,
- isUnderline = (qdStyles&underline) != 0,
- isItalic = (qdStyles&italic) != 0;
+ isBold = (qdStyles&bold) != 0,
+ isUnderline = (qdStyles&underline) != 0,
+ isItalic = (qdStyles&italic) != 0;
ATSStyleRenderingOptions options =
- antialiasedTextEnabled == -1 ? kATSStyleNoOptions :
- antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing :
- kATSStyleApplyAntiAliasing;
+ antialiasedTextEnabled == -1 ? kATSStyleNoOptions :
+ antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing :
+ kATSStyleApplyAntiAliasing;
static const ATSUAttributeTag styleTags[] = {
- kATSUFontTag, kATSUSizeTag,
- kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag,
- kATSUStyleRenderingOptionsTag,
+ kATSUFontTag, kATSUSizeTag,
+ kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag,
+ kATSUStyleRenderingOptionsTag,
};
static const ByteCount styleSizes[] = {
- sizeof(ATSUFontID), sizeof(Fixed),
- sizeof(Boolean), sizeof(Boolean), sizeof(Boolean),
- sizeof(ATSStyleRenderingOptions),
+ sizeof(ATSUFontID), sizeof(Fixed),
+ sizeof(Boolean), sizeof(Boolean), sizeof(Boolean),
+ sizeof(ATSStyleRenderingOptions),
};
const ATSUAttributeValuePtr styleValues[] = {
- &fontId, &fsize,
- &isBold, &isItalic, &isUnderline,
- &options,
+ &fontId, &fsize,
+ &isBold, &isItalic, &isUnderline,
+ &options,
};
- OSStatus err = ATSUSetAttributes(style,
- sizeof(styleTags)/sizeof(styleTags[0]),
- styleTags, styleSizes, styleValues);
- LOG_ON_ERR(ATSUSetAttributes);
+ OSStatus err;
+
+ err = ATSUSetAttributes(
+ style,
+ sizeof(styleTags)/sizeof(styleTags[0]),
+ styleTags, styleSizes, styleValues);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetAttributes(): Error %d\n", (int) err);
+ }
+#endif
}
+
/*
*---------------------------------------------------------------------------
*
* SetFontFeatures --
*
- * Helper for InitFont(). Request specific font features of the ATSU
- * style object for a MacFont.
+ * Helper for InitFont(). Request specific font features of the ATSU
+ * style object for a MacFont.
*
* Results:
- * None.
+ *
+ * None.
*
* Side effects:
- * Specific font features are enabled on the ATSU style object.
+ *
+ * Specific font features are enabled on the ATSU style object.
*
*---------------------------------------------------------------------------
*/
static void
SetFontFeatures(
- ATSUFontID fontId, /* The font id to use. */
- int fixed, /* Is this a fixed font? */
- ATSUStyle style) /* The style handle to configure. */
+ ATSUFontID fontId, /* The font id to use. */
+ int fixed, /* Is this a fixed font? */
+ ATSUStyle style) /* The style handle to configure. */
{
/*
* Don't use the standard latin ligatures, if this is determined to be a
@@ -1701,19 +1827,24 @@ SetFontFeatures(
*/
static const ATSUFontFeatureType fixed_featureTypes[] = {
- kLigaturesType, kLigaturesType
+ kLigaturesType, kLigaturesType
};
static const ATSUFontFeatureSelector fixed_featureSelectors[] = {
- kCommonLigaturesOffSelector, kRareLigaturesOffSelector
+ kCommonLigaturesOffSelector, kRareLigaturesOffSelector
};
OSStatus err;
if (fixed) {
- err = ATSUSetFontFeatures(style,
- sizeof(fixed_featureTypes)/sizeof(fixed_featureTypes[0]),
- fixed_featureTypes, fixed_featureSelectors);
- LOG_ON_ERR(ATSUSetFontFeatures);
+ err = ATSUSetFontFeatures(
+ style,
+ sizeof(fixed_featureTypes)/sizeof(fixed_featureTypes[0]),
+ fixed_featureTypes, fixed_featureSelectors);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetFontFeatures(): Error %d\n", (int) err);
+ }
+#endif
}
}
@@ -1722,15 +1853,17 @@ SetFontFeatures(
*
* AdjustFontHeight --
*
- * Helper for InitFont(). Check font height against some real world
- * examples.
+ * Helper for InitFont(). Check font height against some real world
+ * examples.
*
* Results:
- * None.
+ *
+ * None.
*
* Side effects:
- * The metrics in fontPtr->font.fm are adjusted so that typical combined
- * characters fit into ascent+descent.
+ *
+ * The metrics in fontPtr->font.fm are adjusted so that typical combined
+ * characters fit into ascent+descent.
*
*---------------------------------------------------------------------------
*/
@@ -1742,7 +1875,7 @@ AdjustFontHeight(
/*
* The standard values for ascent, descent and leading as determined in
* InitFont do not take composition into account, they are designed for
- * plain ASCII characters. This code measures the actual size of some
+ * plain ASCII characters. This code measures the actual size of some
* typical composed characters from the Latin-1 range and corrects these
* factors, especially the ascent.
*
@@ -1750,18 +1883,20 @@ AdjustFontHeight(
* than requested.
*
* An alternative would be to instruct ATSU to shrink oversized combined
- * characters. I think I have seen that feature somewhere, but I can't
+ * characters. I think I have seen that feature somewhere, but I can't
* find it now [BR].
*/
static const UniChar chars[]
- /* Auml, Aacute, Acirc, Atilde, Ccedilla */
- = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7};
+ /* Auml, Aacute, Acirc, Atilde, Ccedilla */
+ = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7};
static const int charslen = sizeof(chars) / sizeof(chars[0]);
+
DrawingContext drawingContext;
Rect size;
OSStatus err;
+
#if TK_MAC_USE_QUARZ
TkMacOSXQuarzStartDraw(&drawingContext);
#endif
@@ -1769,90 +1904,100 @@ AdjustFontHeight(
TkMacOSXLayoutSetString(fontPtr, &drawingContext, chars, charslen);
size.top = size.bottom = 0;
- err = ATSUMeasureTextImage(fontPtr->atsuLayout, 0, charslen, 0, 0, &size);
+ err = ATSUMeasureTextImage(
+ fontPtr->atsuLayout,
+ 0, charslen,
+ 0, 0,
+ &size);
#if TK_MAC_USE_QUARZ
TkMacOSXQuarzEndDraw(&drawingContext);
#endif
if (err != noErr) {
- FDBG("ATSUMeasureTextImage(): Error %d", (int) err);
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "ATSUMeasureTextImage(): Error %d\n", (int) err);
+#endif
} else {
- TkFontMetrics * fmPtr = &fontPtr->font.fm;
- int ascent = -size.top;
- int descent = size.bottom;
-
- if (ascent > fmPtr->ascent) {
- fmPtr->ascent = ascent;
- }
- if (descent > fmPtr->descent) {
- fmPtr->descent = descent;
- }
+ TkFontMetrics * fmPtr = &fontPtr->font.fm;
+ int ascent = -size.top;
+ int descent = size.bottom;
+
+ if (ascent > fmPtr->ascent) {
+ fmPtr->ascent = ascent;
+ }
+ if (descent > fmPtr->descent) {
+ fmPtr->descent = descent;
+ }
}
}
+
/*
*---------------------------------------------------------------------------
*
* InitATSULayout --
*
- * Helper for TkMacOSXLayoutSetString(). Initializes the ATSU layout
- * object for a MacFont and a specific string.
+ * Helper for TkMacOSXLayoutSetString(). Initializes the ATSU layout
+ * object for a MacFont and a specific string.
*
* Results:
- * Sets up all parameters needed for an ATSU layout object.
+ *
+ * Sets up all parameters needed for an ATSU layout object.
*
* Side effects:
- * Allocates data structures for the layout object inside of ATSU.
+ *
+ * Allocates data structures for the layout object inside of ATSU.
*
* Assumptions:
- * The actual string data and style information is already set by
- * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see
- * TkMacOSXLayoutSetString()).
+ *
+ * The actual string data and style information is already set by
+ * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see
+ * TkMacOSXLayoutSetString()).
*
*---------------------------------------------------------------------------
*/
static void
InitATSULayout(
- const DrawingContext *drawingContextPtr,
- /* Specifies the CGContext to use. */
- ATSUTextLayout layout, /* The layout object to configure. */
- int fixed) /* Is this a fixed font? */
+ const DrawingContext * drawingContextPtr,
+ /* Specifies the CGContext to use. */
+ ATSUTextLayout layout, /* The layout object to configure. */
+ int fixed) /* Is this a fixed font? */
{
/*
* Attributes for the layout.
*/
ATSLineLayoutOptions layoutOptions =
- 0
+ 0
#if TK_MAC_COALESCE_LINE
/*
* Options to use unconditionally, when we try to do coalescing in here.
*/
- | kATSLineDisableAllLayoutOperations
- | kATSLineFractDisable
- | kATSLineUseDeviceMetrics
+ | kATSLineDisableAllLayoutOperations
+ | kATSLineFractDisable
+ | kATSLineUseDeviceMetrics
#endif
- ;
+ ;
static const ATSUAttributeTag layoutTags[] = {
#if TK_MAC_USE_QUARZ
- kATSUCGContextTag,
+ kATSUCGContextTag,
#endif
- kATSULineLayoutOptionsTag,
+ kATSULineLayoutOptionsTag,
};
static const ByteCount layoutSizes[] = {
#if TK_MAC_USE_QUARZ
- sizeof(CGContextRef),
+ sizeof(CGContextRef),
#endif
- sizeof(ATSLineLayoutOptions),
+ sizeof(ATSLineLayoutOptions),
};
const ATSUAttributeValuePtr layoutValues[] = {
#if TK_MAC_USE_QUARZ
- (void*)&drawingContextPtr->cgContext,
+ (void*)&drawingContextPtr->cgContext,
#endif
- &layoutOptions,
+ &layoutOptions,
};
OSStatus err;
@@ -1862,16 +2007,29 @@ InitATSULayout(
*/
if (fixed) {
- layoutOptions |= kATSLineFractDisable | kATSLineUseDeviceMetrics;
+ layoutOptions |=
+ kATSLineFractDisable
+ | kATSLineUseDeviceMetrics
+ ;
}
- err = ATSUSetLayoutControls(layout,
- sizeof(layoutTags)/sizeof(layoutTags[0]),
- layoutTags, layoutSizes, layoutValues);
- LOG_ON_ERR(ATSUSetLayoutControls);
+ err = ATSUSetLayoutControls(
+ layout,
+ sizeof(layoutTags)/sizeof(layoutTags[0]),
+ layoutTags, layoutSizes, layoutValues);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetLayoutControls(): Error %d\n", (int) err);
+ }
+#endif
err = ATSUSetTransientFontMatching(layout, true);
- LOG_ON_ERR(ATSUSetTransientFontMatching);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetTransientFontMatching(): Error %d\n",
+ (int) err);
+ }
+#endif
}
/*
@@ -1879,68 +2037,83 @@ InitATSULayout(
*
* TkMacOSXLayoutSetString --
*
- * Setup the MacFont for a specific string.
+ * Setup the MacFont for a specific string.
*
* Results:
- * Sets up all parameters so that ATSU can work with the objects in
- * MacFont.
+ *
+ * Sets up all parameters so that ATSU can work with the objects in
+ * MacFont.
*
* Side effects:
- * Sets parameters on the layout object fontPtr->atsuLayout.
+ *
+ * Sets parameters on the layout object fontPtr->atsuLayout.
*
*---------------------------------------------------------------------------
*/
void
TkMacOSXLayoutSetString(
- const MacFont *fontPtr, /* The fontPtr to configure. */
+ const MacFont * fontPtr, /* The fontPtr to configure. */
const DrawingContext * drawingContextPtr,
- /* For the CGContext to be used.*/
- const UniChar *uchars, int ulen)
- /* The UniChar string to set into
- * fontPtr->atsuLayout. */
+ /* For the CGContext to be used.*/
+ const UniChar * uchars, int ulen) /* The UniChar string to set into
+ * fontPtr->atsuLayout. */
{
OSStatus err;
- err = ATSUSetTextPointerLocation(fontPtr->atsuLayout,
- uchars, kATSUFromTextBeginning, ulen, ulen);
- LOG_ON_ERR(ATSUSetTextPointerLocation);
+ err = ATSUSetTextPointerLocation(
+ fontPtr->atsuLayout,
+ uchars, kATSUFromTextBeginning, ulen,
+ ulen);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetTextPointerLocation(): Error %d\n", (int) err);
+ }
+#endif
/*
* Styles can only be set after the text is set.
*/
- err = ATSUSetRunStyle(fontPtr->atsuLayout, fontPtr->atsuStyle,
- kATSUFromTextBeginning, kATSUToTextEnd);
- LOG_ON_ERR(ATSUSetRunStyle);
+ err = ATSUSetRunStyle(
+ fontPtr->atsuLayout, fontPtr->atsuStyle,
+ kATSUFromTextBeginning, kATSUToTextEnd);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSUSetRunStyle(): Error %d\n", (int) err);
+ }
+#endif
/*
* Layout attributes can only be set after the styles are set.
*/
- InitATSULayout(drawingContextPtr, fontPtr->atsuLayout,
- fontPtr->font.fm.fixed);
+ InitATSULayout(
+ drawingContextPtr, fontPtr->atsuLayout,
+ fontPtr->font.fm.fixed);
}
+
/*
*-------------------------------------------------------------------------
*
* ReleaseFont --
*
- * Called to release the Macintosh-specific contents of a TkFont. The
- * caller is responsible for freeing the memory used by the font itself.
+ * Called to release the Macintosh-specific contents of a TkFont. The
+ * caller is responsible for freeing the memory used by the font
+ * itself.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Memory is freed.
+ * Memory is freed.
*
*---------------------------------------------------------------------------
*/
static void
ReleaseFont(
- MacFont *fontPtr) /* The font to delete. */
+ MacFont * fontPtr) /* The font to delete. */
{
ATSUDisposeTextLayout(fontPtr->atsuLayout);
ATSUDisposeStyle(fontPtr->atsuStyle);
@@ -1951,40 +2124,40 @@ ReleaseFont(
*
* FindFontFamilyOrAlias, FindFontFamilyOrAliasOrFallback --
*
- * Determine if any physical screen font exists on the system with the
- * given family name. If the family exists, then it should be possible to
- * construct some physical screen font with that family name.
+ * Determine if any physical screen font exists on the system with The
+ * given family name. If the family exists, then it should be possible
+ * to construct some physical screen font with that family name.
*
- * FindFontFamilyOrAlias also considers font aliases as determined by
- * TkFontGetAliasList().
+ * FindFontFamilyOrAlias also considers font aliases as determined by
+ * TkFontGetAliasList().
*
- * FindFontFamilyOrAliasOrFallback also considers font aliases as
- * determined by TkFontGetFallbacks().
+ * FindFontFamilyOrAliasOrFallback also considers font aliases as
+ * determined by TkFontGetFallbacks().
*
- * The overall algorithm to get the closest font to the one requested is
- * this:
+ * The overall algorithm to get the closest font to the one requested is
+ * this:
*
- * try fontname
- * try all aliases for fontname
- * foreach fallback for fontname
- * try the fallback
- * try all aliases for the fallback
+ * try fontname
+ * try all aliases for fontname
+ * foreach fallback for fontname
+ * try the fallback
+ * try all aliases for the fallback
*
* Results:
*
- * The return value is NULL if the specified font family does not exist,
- * a valid MacFontFamily* otherwise.
+ * The return value is NULL if the specified font family does not exist,
+ * a valid MacFontFamily* otherwise.
*
* Side effects:
*
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
static const MacFontFamily *
FindFontFamilyOrAlias(
- const char * name) /* Name or alias name of the font to find. */
+ const char * name) /* Name or alias name of the font to find. */
{
const MacFontFamily * familyPtr;
char ** aliases;
@@ -1992,24 +2165,24 @@ FindFontFamilyOrAlias(
familyPtr = FindFontFamily(name);
if (familyPtr != NULL) {
- return familyPtr;
+ return familyPtr;
}
aliases = TkFontGetAliasList(name);
if (aliases != NULL) {
- for (i = 0; aliases[i] != NULL; i++) {
- familyPtr = FindFontFamily(aliases[i]);
- if (familyPtr != NULL) {
- return familyPtr;
- }
- }
+ for (i = 0; aliases[i] != NULL; i++) {
+ familyPtr = FindFontFamily(aliases[i]);
+ if (familyPtr != NULL) {
+ return familyPtr;
+ }
+ }
}
return NULL;
}
-
+
static const MacFontFamily *
FindFontFamilyOrAliasOrFallback(
- const char * name) /* Name or alias name of the font to find. */
+ const char * name) /* Name or alias name of the font to find. */
{
const MacFontFamily * familyPtr;
const char * fallback;
@@ -2018,34 +2191,38 @@ FindFontFamilyOrAliasOrFallback(
familyPtr = FindFontFamilyOrAlias(name);
if (familyPtr != NULL) {
- return familyPtr;
+ return familyPtr;
}
fallbacks = TkFontGetFallbacks();
for (i = 0; fallbacks[i] != NULL; i++) {
- for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
- if (strcasecmp(name, fallback) == 0) {
- for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
- familyPtr = FindFontFamilyOrAlias(fallback);
- if (familyPtr != NULL) {
- return familyPtr;
- }
- }
- }
- break; /* benny: This "break" is a carry-over from
- * tkMacOSXFont.c, but what is actually its purpose
- * ???? */
- }
+ for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
+ if (strcasecmp(name, fallback) == 0) {
+ for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
+ familyPtr = FindFontFamilyOrAlias(fallback);
+ if (familyPtr != NULL) {
+ return familyPtr;
+ }
+ }
+ }
+ break; /* benny: This "break" is a carry-over from
+ * tkMacOSXFont.c, but what is actually its purpose
+ * ???? */
+ }
}
+
/*
- * FIXME: We would have liked to recover by re-enumerating fonts. But that
- * doesn't work, because Carbon seems to cache the inital list of fonts.
- * Fonts newly installed don't show up with
- * FMCreateFontFamilyIterator()/FMGetNextFontFamily() without a restart of
- * the app. Similar problem with fonts removed.
+ * FIXME: We would have liked to recover by re-enumerating fonts. But
+ * that doesn't work, because Carbon seems to cache the inital list of
+ * fonts. Fonts newly installed don't show up with
+ * FMCreateFontFamilyIterator()/FMGetNextFontFamily() without a restart
+ * of the app. Similar problem with fonts removed.
*/
- FDBG("Font family '%s': Not found", name);
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "Font family '%s': Not found\n", name);
+#endif
+
return NULL;
}
@@ -2054,16 +2231,16 @@ FindFontFamilyOrAliasOrFallback(
*
* InitFontFamilies --
*
- * Helper to TkpFontPkgInit. Use the Font Manager to fill in the
- * familyList global array.
+ * Helper to TkpFontPkgInit. Use the Font Manager to fill in the
+ * familyList global array.
*
* Results:
*
- * None.
+ * None.
*
* Side effects:
*
- * Allocates memory.
+ * Allocates memory.
*
*-------------------------------------------------------------------------
*/
@@ -2078,11 +2255,15 @@ InitFontFamilies(void)
*/
if (familyListNextFree > 0) {
- return;
+ return;
}
err = ATSFontFamilyApplyFunction(FontFamilyEnumCallback,NULL);
- LOG_ON_ERR(ATSFontFamilyApplyFunction);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "ATSFontFamilyApplyFunction(): Error %d\n", (int) err);
+ }
+#endif
AddFontFamily(APPLFONT_NAME, GetAppFont());
AddFontFamily(SYSTEMFONT_NAME, GetSysFont());
@@ -2092,7 +2273,7 @@ InitFontFamilies(void)
static OSStatus
FontFamilyEnumCallback(
- ATSFontFamilyRef family,
+ ATSFontFamilyRef family,
void *refCon)
{
OSStatus err;
@@ -2102,7 +2283,7 @@ FontFamilyEnumCallback(
err = GetFontFamilyName(family, name, sizeof(name));
if (err == noErr) {
- AddFontFamily(name, family);
+ AddFontFamily(name, family);
}
return noErr;
@@ -2114,28 +2295,28 @@ FontFamilyEnumCallback(
*
* GetFontFamilyName --
*
- * Use the Font Manager to get the name of a given FMFontfamily. This
- * currently gets the standard, non-localized QuickDraw name. Other names
- * would be possible, see docs for ATSUFindFontName for a selection. The
- * MacOSX font selector seems to use the localized family name given by
- * ATSUFindFontName(kFontFamilyName), but that API doesn't give us a name
- * at all for some fonts.
+ * Use the Font Manager to get the name of a given FMFontfamily. This
+ * currently gets the standard, non-localized QuickDraw name. Other
+ * names would be possible, see docs for ATSUFindFontName for a
+ * selection. The MacOSX font selector seems to use the localized
+ * family name given by ATSUFindFontName(kFontFamilyName), but that API
+ * doesn't give us a name at all for some fonts.
*
* Results:
- * An OS error code, noErr on success. name is filled with the resulting
- * name.
+ * An OS error code, noErr on success. name is filled with the
+ * resulting name.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
static OSStatus
GetFontFamilyName(
- FMFontFamily fontFamily, /* The font family for which to find the
- * name. */
- char * name, int numBytes) /* Filled with the result. */
+ FMFontFamily fontFamily, /* The font family for which to find the
+ * name. */
+ char * name, int numBytes) /* Filled with the result. */
{
OSStatus err;
Str255 nativeName;
@@ -2147,9 +2328,11 @@ GetFontFamilyName(
name[0] = 0;
err = FMGetFontFamilyName(fontFamily, nativeName);
- LOG_ON_ERR(FMGetFontFamilyName);
if (err != noErr) {
- return err;
+#ifdef TK_MAC_DEBUG_FONTS
+ fprintf(stderr, "FMGetFontFamilyName(): Error %d\n", (int) err);
+#endif
+ return err;
}
/*
@@ -2159,26 +2342,35 @@ GetFontFamilyName(
encoding = kTextEncodingMacRoman;
err = FMGetFontFamilyTextEncoding(fontFamily, &encoding);
- LOG_ON_ERR(FMGetFontFamilyTextEncoding);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "FMGetFontFamilyTextEncoding(): Error %d\n", (int) err);
+ }
+#endif
nameencoding = encoding;
err = RevertTextEncodingToScriptInfo(encoding, &nameencoding, NULL, NULL);
- LOG_ON_ERR(RevertTextEncodingToScriptInfo);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (err != noErr) {
+ fprintf(stderr, "RevertTextEncodingToScriptInfo(): Error %d\n",
+ (int) err);
+ }
+#endif
/*
- * Note: We could use Tcl facilities to do the re-encoding here. We'd have
- * to maintain tables to map OS encoding codes to Tcl encoding names like
- * tkMacOSXFont.c did. Using native re-encoding directly instead is a lot
- * easier and future-proof than that. There is one snag, though: I have
- * seen CFStringGetCString() crash with invalid encoding ids. But than if
- * that happens it would be a bug in FMGetFontFamilyTextEncoding() or
- * RevertTextEncodingToScriptInfo().
+ * Note: We could use Tcl facilities to do the re-encoding here. We'd
+ * have to maintain tables to map OS encoding codes to Tcl encoding names
+ * like tkMacOSXFont.c did. Using native re-encoding directly instead is
+ * a lot easier and future-proof than that. There is one snag, though: I
+ * have seen CFStringGetCString() crash with invalid encoding ids. But
+ * than if that happens it would be a bug in
+ * FMGetFontFamilyTextEncoding() or RevertTextEncodingToScriptInfo().
*/
cfString = CFStringCreateWithPascalStringNoCopy(
- NULL, nativeName, nameencoding, kCFAllocatorNull);
+ NULL, nativeName, nameencoding, kCFAllocatorNull);
CFStringGetCString(
- cfString, name, numBytes, kCFStringEncodingUTF8);
+ cfString, name, numBytes, kCFStringEncodingUTF8);
CFRelease(cfString);
return noErr;
@@ -2189,39 +2381,41 @@ GetFontFamilyName(
*
* FindFontFamily --
*
- * Find the font family with the given name in the global familyList.
- * Uses bsearch() for convenient access. Comparision is done
- * non-case-sensitively with CompareFontFamilies() which see.
+ * Find the font family with the given name in the global familyList.
+ * Uses bsearch() for convenient access. Comparision is done
+ * non-case-sensitively with CompareFontFamilies() which see.
*
* Results:
*
- * MacFontFamily: A pair of family id and the actual name registered for
- * the font.
+ * MacFontFamily: A pair of family id and the actual name registered for
+ * the font.
*
* Side effects:
*
- * None.
+ * None.
*
* Assumption:
*
- * Requires the familyList array to be sorted.
+ * Requires the familyList array to be sorted.
*
*-------------------------------------------------------------------------
*/
static const MacFontFamily *
FindFontFamily(
- const char *name) /* The family name. Note: Names are compared
- * non-case-sensitive. */
+ const char * name) /* The family name. Note: Names are compared
+ * non-case-sensitive. */
{
const MacFontFamily key = {name,-1};
if(familyListMaxValid <= 0) {
- return NULL;
+ return NULL;
}
- return bsearch(&key, familyList, familyListMaxValid, sizeof(*familyList),
- CompareFontFamilies);
+ return bsearch(
+ &key,
+ familyList, familyListMaxValid, sizeof(*familyList),
+ CompareFontFamilies);
}
/*
@@ -2229,13 +2423,15 @@ FindFontFamily(
*
* EnumFontFamilies --
*
- * Create a Tcl list with the registered names in the global familyList.
+ * Create a Tcl list with the registered names in the global familyList.
*
* Results:
- * A Tcl list of names.
+ *
+ * A Tcl list of names.
*
* Side effects:
- * None.
+ *
+ * None.
*
*-------------------------------------------------------------------------
*/
@@ -2248,8 +2444,8 @@ EnumFontFamilies(void)
tclList = Tcl_NewListObj(0, NULL);
for (i=0; i<familyListMaxValid; ++i) {
- Tcl_ListObjAppendElement(NULL, tclList,
- Tcl_NewStringObj(familyList[i].name, -1));
+ Tcl_ListObjAppendElement(
+ NULL, tclList, Tcl_NewStringObj(familyList[i].name, -1));
}
return tclList;
@@ -2260,32 +2456,33 @@ EnumFontFamilies(void)
*
* AddFontFamily --
*
- * Register a font family in familyList. Until SortFontFamilies() is
- * called, this is not actually available for FindFontFamily().
+ * Register a font family in familyList. Until SortFontFamilies() is
+ * called, this is not actually available for FindFontFamily().
*
* Results:
*
- * MacFontFamily: The new pair of family id and the actual name
- * registered for the font.
+ * MacFontFamily: The new pair of family id and the actual name
+ * registered for the font.
*
* Side effects:
*
- * New entry in familyList and familyListNextFree updated.
+ * New entry in familyList and familyListNextFree updated.
*
*-------------------------------------------------------------------------
*/
static const MacFontFamily *
AddFontFamily(
- const char *name, /* Font family name to register. */
- FMFontFamily familyId) /* Font family id to register. */
+ const char * name, /* Font family name to register. */
+ FMFontFamily familyId) /* Font family id to register. */
{
MacFontFamily * familyPtr;
if (familyListNextFree >= familyListSize) {
- familyListSize += 100;
- familyList = (MacFontFamily *) ckrealloc((void*) familyList,
- familyListSize * sizeof(*familyList));
+ familyListSize += 100;
+ familyList = (MacFontFamily *) ckrealloc(
+ (void*) familyList,
+ familyListSize * sizeof(*familyList));
}
familyPtr = familyList + familyListNextFree;
@@ -2302,18 +2499,18 @@ AddFontFamily(
*
* SortFontFamilies --
*
- * Sort the entries in familyList. Only after calling SortFontFamilies(),
- * the new families registered with AddFontFamily() are actually
- * available for FindFontFamily(), because FindFontFamily() requires the
- * array to be sorted.
+ * Sort the entries in familyList. Only after calling
+ * SortFontFamilies(), the new families registered with AddFontFamily()
+ * are actually available for FindFontFamily(), because FindFontFamily()
+ * requires the array to be sorted.
*
* Results:
*
- * None.
+ * None.
*
* Side effects:
*
- * familyList is sorted and familyListMaxValid is updated.
+ * familyList is sorted and familyListMaxValid is updated.
*
*-------------------------------------------------------------------------
*/
@@ -2322,8 +2519,8 @@ static void
SortFontFamilies(void)
{
if (familyListNextFree > 0) {
- qsort(familyList, familyListNextFree, sizeof(*familyList),
- CompareFontFamilies);
+ qsort( familyList, familyListNextFree, sizeof(*familyList),
+ CompareFontFamilies);
}
familyListMaxValid = familyListNextFree;
}
@@ -2333,19 +2530,21 @@ SortFontFamilies(void)
*
* CompareFontFamilies --
*
- * Comparison function used by SortFontFamilies() and FindFontFamily().
+ * Comparison function used by SortFontFamilies() and FindFontFamily().
*
* Results:
- * Result as required to generate a stable sort order for bsearch() and
- * qsort(). The ordering is not case-sensitive as far as
- * Tcl_UtfNcasecmp() (which see) can provide that.
*
- * Note: It would be faster to compare first the length and the actual
- * strings only as a tie-breaker, but than the ordering wouldn't look so
- * pretty in [font families] ;-).
+ * Result as required to generate a stable sort order for bsearch() and
+ * qsort(). The ordering is not case-sensitive as far as
+ * Tcl_UtfNcasecmp() (which see) can provide that.
+ *
+ * Note: It would be faster to compare first the length and the actual
+ * strings only as a tie-breaker, but than the ordering wouldn't look so
+ * pretty in [font families] ;-).
*
* Side effects:
- * None.
+ *
+ * None.
*
*-------------------------------------------------------------------------
*/
@@ -2357,7 +2556,9 @@ CompareFontFamilies(
{
const char * name1;
const char * name2;
- int len1, len2, diff;
+ int len1;
+ int len2;
+ int diff;
name1 = ((const MacFontFamily *) vp1)->name;
name2 = ((const MacFontFamily *) vp2)->name;
@@ -2375,39 +2576,43 @@ CompareFontFamilies(
*
* AddString --
*
- * Helper for AddFontFamily(). Allocates a string in the one-shot
- * allocator.
+ * Helper for AddFontFamily(). Allocates a string in the one-shot
+ * allocator.
*
* Results:
- * A duplicated string in the one-shot allocator.
+ *
+ * A duplicated string in the one-shot allocator.
*
* Side effects:
- * May allocate a new memory block.
+ *
+ * May allocate a new memory block.
*
*-------------------------------------------------------------------------
*/
static const char *
AddString(
- const char *in) /* String to add, zero-terminated. */
+ const char * in) /* String to add, zero-terminated. */
{
int len;
- char *result;
-
+ char * result;
+
len = strlen(in) +1;
if (stringMemory == NULL
- || (stringMemory->nextFree+len) > STRING_BLOCK_MAX) {
- StringBlock * newblock = (StringBlock *) ckalloc(sizeof(StringBlock));
- newblock->next = stringMemory;
- newblock->nextFree = 0;
- stringMemory = newblock;
+ || (stringMemory->nextFree+len) > STRING_BLOCK_MAX ) {
+ StringBlock * newblock =
+ (StringBlock *) ckalloc(sizeof(StringBlock));
+ newblock->next = stringMemory;
+ newblock->nextFree = 0;
+ stringMemory = newblock;
}
result = stringMemory->strings + stringMemory->nextFree;
stringMemory->nextFree += len;
memcpy(result, in, len);
+
return result;
}
@@ -2416,29 +2621,29 @@ AddString(
*
* TkMacOSXIsCharacterMissing --
*
- * Given a tkFont and a character determine whether the character has a
- * glyph defined in the font or not.
+ * Given a tkFont and a character determine whether the character has
+ * a glyph defined in the font or not.
*
* Results:
- * Returns a 1 if the character is missing, a 0 if it is not.
+ * Returns a 1 if the character is missing, a 0 if it is not.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
int
TkMacOSXIsCharacterMissing(
- Tk_Font tkfont, /* The font we are looking in. */
- unsigned int searchChar) /* The character we are looking for. */
+ Tk_Font tkfont, /* The font we are looking in. */
+ unsigned int searchChar) /* The character we are looking for. */
{
/* Background: This function is private and only used in
* tkMacOSXMenu.c:FindMarkCharacter().
*
- * We could use ATSUMatchFont() to implement. We'd have to change the
- * definition of the encoding of the parameter searchChar from MacRoman to
- * UniChar for that.
+ * We could use ATSUMatchFont() to implement. We'd have to change the
+ * definition of the encoding of the parameter searchChar from MacRoman
+ * to UniChar for that.
*
* The system uses font fallback for controls, so we don't really need
* this. */
@@ -2451,27 +2656,30 @@ TkMacOSXIsCharacterMissing(
*
* TkMacOSXInitControlFontStyle --
*
- * This procedure sets up the appropriate ControlFontStyleRec
- * for a Mac control.
+ * This procedure sets up the appropriate ControlFontStyleRec
+ * for a Mac control.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
void
TkMacOSXInitControlFontStyle(
- Tk_Font tkfont, /* Tk font object to use for the control. */
- ControlFontStylePtr fsPtr) /* The style object to configure. */
+ Tk_Font tkfont, /* Tk font object to use for the control. */
+ ControlFontStylePtr fsPtr) /* The style object to configure. */
{
- const MacFont * fontPtr = (MacFont *) tkfont;
-
- fsPtr->flags = kControlUseFontMask |
- kControlUseSizeMask | kControlUseFaceMask | kControlUseJustMask;
+ const MacFont * fontPtr;
+ fontPtr = (MacFont *) tkfont;
+ fsPtr->flags =
+ kControlUseFontMask|
+ kControlUseSizeMask|
+ kControlUseFaceMask|
+ kControlUseJustMask;
fsPtr->font = fontPtr->qdFont;
fsPtr->size = fontPtr->qdSize;
fsPtr->style = fontPtr->qdStyle;
@@ -2483,53 +2691,47 @@ TkMacOSXInitControlFontStyle(
*
* TkMacOSXUseAntialiasedText --
*
- * Enables or disables application-wide use of antialiased text (where
- * available). Sets up a linked Tcl global variable to allow disabling of
- * antialiased text from tcl. The possible values for this variable are:
+ * Enables or disables application-wide use of antialiased text (where
+ * available). Sets up a linked Tcl global variable to allow
+ * disabling of antialiased text from tcl.
+ * The possible values for this variable are:
*
- * -1 - Use system default as configurable in "System Preferences" ->
- * "General".
- * 0 - Unconditionally disable antialiasing.
- * 1 - Unconditionally enable antialiasing.
+ * -1 - Use system default as configurable in "System Preferences" ->
+ * "General".
+ * 0 - Unconditionally disable antialiasing.
+ * 1 - Unconditionally enable antialiasing.
*
* Results:
*
- * TCL_OK.
+ * TCL_OK.
*
* Side effects:
*
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE int
TkMacOSXUseAntialiasedText(
- Tcl_Interp * interp, /* The Tcl interpreter to receive the variable .*/
- int enable) /* Initial value. */
+ Tcl_Interp * interp, /* The Tcl interpreter to receive the
+ * variable .*/
+ int enable) /* Initial value. */
{
static Boolean initialized = FALSE;
- if (!initialized) {
- initialized = TRUE;
-
- if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
- Tcl_ResetResult(interp);
- }
- if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
- (char *) &antialiasedTextEnabled,
- TCL_LINK_INT) != TCL_OK) {
- Tcl_ResetResult(interp);
- }
+ if(!initialized) {
+ initialized = TRUE;
+
+ if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
+ Tcl_ResetResult(interp);
+ }
+ if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
+ (char *) &antialiasedTextEnabled,
+ TCL_LINK_INT) != TCL_OK) {
+ Tcl_ResetResult(interp);
+ }
}
antialiasedTextEnabled = enable;
return TCL_OK;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index 6059708..cde0be8 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXInit.c,v 1.26 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXInit.c,v 1.27 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -198,29 +198,22 @@ TkpInit(interp)
FSRef ref;
SInt16 refNum;
- /*
- * Write resource data to temporary file and open it.
- */
-
+ /* Write resource data to temporary file and open it */
strcpy(fileName, P_tmpdir);
if (fileName[strlen(fileName) - 1] != '/') {
strcat(fileName, "/");
}
strcat(fileName, "tkMacOSX_XXXXXX");
fd = mkstemp(fileName);
- if (fd == -1) {
- break;
- }
+ if (fd == -1) break;
fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (write(fd, data, size) == -1) {
- break;
- }
+ if (write(fd, data, size) == -1) break;
err = FSPathMakeRef((unsigned char*)fileName, &ref, NULL);
- if (err != noErr) {
- break;
- }
+ if (err != noErr) break;
err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum);
- LOG_ON_ERROR(FSOpenResourceFile);
+#ifdef TK_MAC_DEBUG
+ if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err);
+#endif
break;
}
if (fd != -1) {
@@ -232,11 +225,12 @@ TkpInit(interp)
}
/* REMOVE ME: Close stdin & stdout for remote debugging otherwise we
- * will fight with gdb for stdin & stdout */
+ * will fight with gdb for stdin & stdout
+ */
- if (getenv("XCNOSTDIN") != NULL) {
- close(0);
- close(1);
+ if (getenv ("XCNOSTDIN") != NULL) {
+ close (0);
+ close (1);
}
/*
@@ -247,22 +241,18 @@ TkpInit(interp)
if (!isatty(0)) {
struct stat st;
-
if (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0)) {
Tk_InitConsoleChannels(interp);
Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
-
/*
- * Only show the console if we don't have a startup script and
- * tcl_interactive hasn't been set already.
+ * Only show the console if we don't have a startup script
+ * and tcl_interactive hasn't been set already.
*/
-
if (Tcl_GetStartupScript(NULL) == NULL) {
- CONST char *intvar = Tcl_GetVar(interp,
- "tcl_interactive", TCL_GLOBAL_ONLY);
-
+ CONST char *intvar =
+ Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY);
if (intvar == NULL) {
Tcl_SetVar(interp, "tcl_interactive", "1",
TCL_GLOBAL_ONLY);
diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h
index 289f47b..9ff9069 100644
--- a/macosx/tkMacOSXInt.h
+++ b/macosx/tkMacOSXInt.h
@@ -6,10 +6,10 @@
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXInt.h,v 1.21 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXInt.h,v 1.22 2007/04/21 19:06:38 hobbs Exp $
*/
#ifndef _TKMACINT
@@ -32,63 +32,64 @@
#endif
struct TkWindowPrivate {
- TkWindow *winPtr; /* Ptr to tk window or NULL if Pixmap */
- CGrafPtr grafPtr;
+ TkWindow *winPtr; /* Ptr to tk window or NULL if Pixmap */
+ CGrafPtr grafPtr;
ControlRef rootControl;
- int xOff; /* X offset from toplevel window */
- int yOff; /* Y offset from toplevel window */
+ int xOff; /* X offset from toplevel window */
+ int yOff; /* Y offset from toplevel window */
RgnHandle clipRgn; /* Visible region of window */
RgnHandle aboveClipRgn; /* Visible region of window & it's children */
int referenceCount; /* Don't delete toplevel until children are
* gone. */
- struct TkWindowPrivate *toplevel;
- /* Pointer to the toplevel datastruct. */
+ struct TkWindowPrivate *toplevel; /* Pointer to the toplevel
+ * datastruct. */
int flags; /* Various state see defines below. */
};
typedef struct TkWindowPrivate MacDrawable;
/*
- * This list is used to keep track of toplevel windows that have a Mac window
- * attached. This is useful for several things, not the least of which is
- * maintaining floating windows.
+ * This list is used to keep track of toplevel windows that have a Mac
+ * window attached. This is useful for several things, not the least
+ * of which is maintaining floating windows.
*/
typedef struct TkMacOSXWindowList {
- struct TkMacOSXWindowList *nextPtr;
- /* The next window in the list. */
- TkWindow *winPtr; /* This window */
+ struct TkMacOSXWindowList *nextPtr; /* The next window in the list. */
+ TkWindow *winPtr; /* This window */
} TkMacOSXWindowList;
/*
* Defines use for the flags field of the MacDrawable data structure.
*/
-
+
#define TK_SCROLLBAR_GROW 1
#define TK_CLIP_INVALID 2
#define TK_HOST_EXISTS 4
#define TK_DRAWN_UNDER_MENU 8
/*
- * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags. This is
- * defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the TkWindow
- * structure for the window, but in the MacWin. This way we can still tell
- * what the correct port is after the TKWindow structure has been freed. This
- * actually happens when you bind destroy of a toplevel to Destroy of a child.
+ * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags
+ * This is defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the
+ * TkWindow structure for the window, but in the MacWin. This way we can
+ * still tell what the correct port is after the TKWindow structure has been
+ * freed. This actually happens when you bind destroy of a toplevel to
+ * Destroy of a child.
*/
/*
- * This structure is for handling Netscape-type in process embedding where Tk
- * does not control the top-level. It contains various functions that are
- * needed by Mac specific routines, like TkMacOSXGetDrawablePort. The
- * definitions of the function types are in tkMacOSX.h.
+ * This structure is for handling Netscape-type in process
+ * embedding where Tk does not control the top-level. It contains
+ * various functions that are needed by Mac specific routines, like
+ * TkMacOSXGetDrawablePort. The definitions of the function types
+ * are in tkMacOSX.h.
*/
typedef struct {
- Tk_MacOSXEmbedRegisterWinProc *registerWinProc;
- Tk_MacOSXEmbedGetGrafPortProc *getPortProc;
- Tk_MacOSXEmbedMakeContainerExistProc *containerExistProc;
- Tk_MacOSXEmbedGetClipProc *getClipProc;
- Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc;
+ Tk_MacOSXEmbedRegisterWinProc *registerWinProc;
+ Tk_MacOSXEmbedGetGrafPortProc *getPortProc;
+ Tk_MacOSXEmbedMakeContainerExistProc *containerExistProc;
+ Tk_MacOSXEmbedGetClipProc *getClipProc;
+ Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc;
} TkMacOSXEmbedHandler;
MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler;
@@ -96,7 +97,7 @@ MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler;
/*
* Defines used for TkMacOSXInvalidateWindow
*/
-
+
#define TK_WINDOW_ONLY 0
#define TK_PARENT_WINDOW 1
@@ -119,104 +120,65 @@ MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler;
* Defines for tkTextDisp.c
*/
-#define TK_LAYOUT_WITH_BASE_CHUNKS 1
-#define TK_DRAW_IN_CONTEXT 1
+#define TK_LAYOUT_WITH_BASE_CHUNKS 1
+#define TK_DRAW_IN_CONTEXT 1
/*
- * Variables shared among various Mac Tk modules but are not exported to the
- * outside world.
+ * Variables shared among various Mac Tk modules but are not
+ * exported to the outside world.
*/
/*
* Globals shared among Macintosh Tk
*/
-MODULE_SCOPE MenuHandle tkCurrentAppleMenu;
- /* Handle to current Apple Menu */
-MODULE_SCOPE MenuHandle tkAppleMenu;
- /* Handle to default Apple Menu */
-MODULE_SCOPE MenuHandle tkFileMenu;
- /* Handles to menus */
-MODULE_SCOPE MenuHandle tkEditMenu;
- /* Handles to menus */
-MODULE_SCOPE RgnHandle tkMenuCascadeRgn;
- /* A region to clip with. */
-MODULE_SCOPE int tkUseMenuCascadeRgn;
- /* If this is 1, clipping code should
- * intersect tkMenuCascadeRgn before drawing
- * occurs. tkMenuCascadeRgn will only be valid
- * when the value of this variable is 1. */
-MODULE_SCOPE int tkPictureIsOpen;
- /* If this is 1, we are drawing to a picture
- * The clipping should then be done relative
- * to the bounds of the picture rather than
- * the window. As of OS X.0.4, something is
- * seriously wrong: The clipping bounds only
- * seem to work if the top,left values are 0,0
- * The destination rectangle for CopyBits
- * should also have top,left values of 0,0 */
+MODULE_SCOPE MenuHandle tkCurrentAppleMenu; /* Handle to current Apple Menu */
+MODULE_SCOPE MenuHandle tkAppleMenu; /* Handle to default Apple Menu */
+MODULE_SCOPE MenuHandle tkFileMenu; /* Handles to menus */
+MODULE_SCOPE MenuHandle tkEditMenu; /* Handles to menus */
+MODULE_SCOPE RgnHandle tkMenuCascadeRgn;/* A region to clip with. */
+MODULE_SCOPE int tkUseMenuCascadeRgn; /* If this is 1, clipping code
+ * should intersect tkMenuCascadeRgn
+ * before drawing occurs.
+ * tkMenuCascadeRgn will only
+ * be valid when the value of this
+ * variable is 1. */
+MODULE_SCOPE int tkPictureIsOpen; /* If this is 1, we are drawing to a
+ * picture The clipping should then be
+ * done relative to the bounds of the
+ * picture rather than the window. As
+ * of OS X.0.4, something is seriously
+ * wrong: The clipping bounds only
+ * seem to work if the top,left values
+ * are 0,0 The destination rectangle
+ * for CopyBits should also have
+ * top,left values of 0,0
+ */
MODULE_SCOPE TkMacOSXWindowList *tkMacOSXWindowListPtr;
- /* The list of toplevels */
+ /* The list of toplevels */
MODULE_SCOPE Tcl_Encoding TkMacOSXCarbonEncoding;
-MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
-MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
- int enable);
-MODULE_SCOPE void TkMacOSXInitCarbonEvents(Tcl_Interp *interp);
-MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
- int antiAlias);
-MODULE_SCOPE void TkMacOSXInitKeyboard(Tcl_Interp *interp);
-MODULE_SCOPE void TkMacOSXDefaultStartupScript(void);
-MODULE_SCOPE int TkMacOSXGenerateFocusEvent(Window window,
- int activeFlag);
+MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
+MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp, int enable);
+MODULE_SCOPE void TkMacOSXInitCarbonEvents(Tcl_Interp *interp);
+MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable, int antiAlias);
+MODULE_SCOPE void TkMacOSXInitKeyboard(Tcl_Interp *interp);
+MODULE_SCOPE void TkMacOSXDefaultStartupScript(void);
+MODULE_SCOPE int TkMacOSXGenerateFocusEvent( Window window, int activeFlag);
MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr);
-MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
-MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
-MODULE_SCOPE int TkMacOSXCompareColors(unsigned long c1,
- unsigned long c2);
-MODULE_SCOPE void * TkMacOSXGetNamedSymbol(const char *module,
- const char *symbol);
-
-/*
- * Macro to abstract common use of TkMacOSXGetNamedSymbol to initialize named
- * symbols.
- */
+MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
+MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
+MODULE_SCOPE int TkMacOSXCompareColors(unsigned long c1, unsigned long c2);
+MODULE_SCOPE void* TkMacOSXGetNamedSymbol(const char* module, const char* symbol);
+/* Macro to abstract common use of TkMacOSXGetNamedSymbol to initialize named symbols */
#define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \
static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \
if (symbol == (void*)(-1L)) { \
symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), STRINGIFY(_##symbol));\
}
-/*
- * Macro to make handling failed events a little bit less verbose. Assumes
- * that error values are always in the (local) variable 'err'.
- */
-
-#ifdef TK_MAC_DEBUG
-#define LOG_MSG(msg, ...) fprintf(stderr, msg "\n", __VA_ARGS__)
-#define LOG_ON_ERROR(msg) \
- if (err != noErr) { \
- fprintf(stderr, ##msg " failed, %d\n", (int) err); \
- }
-#else
-#define LOG_MSG(msg, ...) /* do nothing */
-#define LOG_ON_ERROR(msg) /* do nothing */
-#endif
-
-/*
- * Include the stubbed internal platform-specific API.
- */
-
#include "tkIntPlatDecls.h"
#endif /* _TKMACINT */
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c
index 27d6c7b..08d61a4 100644
--- a/macosx/tkMacOSXKeyEvent.c
+++ b/macosx/tkMacOSXKeyEvent.c
@@ -1,8 +1,8 @@
/*
* tkMacOSXKeyEvent.c --
*
- * This file implements functions that decode & handle keyboard events
- * on MacOS X.
+ * This file implements functions that decode & handle keyboard events
+ * on MacOS X.
*
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2006 Daniel A. Steffen <das@users.sourceforge.net>
@@ -10,49 +10,51 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * The following terms apply to all files originating from Apple
- * Computer, Inc. ("Apple") and associated with the software
- * unless explicitly disclaimed in individual files.
- *
- * Apple hereby grants permission to use, copy, modify,
- * distribute, and license this software and its documentation
- * for any purpose, provided that existing copyright notices are
- * retained in all copies and that this notice is included
- * verbatim in any distributions. No written agreement, license,
- * or royalty fee is required for any of the authorized
- * uses. Modifications to this software may be copyrighted by
- * their authors and need not follow the licensing terms
- * described here, provided that the new terms are clearly
- * indicated on the first page of each file where they apply.
- *
- * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
- * SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
- * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
- * THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
- * EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE. APPLE, THE AUTHORS AND
- * DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS
- * SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
- * AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
- * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- *
- * GOVERNMENT USE: If you are acquiring this software on behalf
- * of the U.S. government, the Government shall have only
- * "Restricted Rights" in the software and related documentation
- * as defined in the Federal Acquisition Regulations (FARs) in
- * Clause 52.227.19 (c) (2). If you are acquiring the software
- * on behalf of the Department of Defense, the software shall be
- * classified as "Commercial Computer Software" and the
- * Government shall have only "Restricted Rights" as defined in
- * Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
- * foregoing, the authors grant the U.S. Government and others
- * acting in its behalf permission to use and distribute the
- * software in accordance with the terms specified in this
- * license.
- *
- * RCS: @(#) $Id: tkMacOSXKeyEvent.c,v 1.19 2007/04/13 14:51:18 dkf Exp $
+ * The following terms apply to all files originating from Apple
+ * Computer, Inc. ("Apple") and associated with the software
+ * unless explicitly disclaimed in individual files.
+ *
+ *
+ * Apple hereby grants permission to use, copy, modify,
+ * distribute, and license this software and its documentation
+ * for any purpose, provided that existing copyright notices are
+ * retained in all copies and that this notice is included
+ * verbatim in any distributions. No written agreement, license,
+ * or royalty fee is required for any of the authorized
+ * uses. Modifications to this software may be copyrighted by
+ * their authors and need not follow the licensing terms
+ * described here, provided that the new terms are clearly
+ * indicated on the first page of each file where they apply.
+ *
+ *
+ * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
+ * SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
+ * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
+ * THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
+ * EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE. APPLE, THE AUTHORS AND
+ * DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS
+ * SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
+ * AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * GOVERNMENT USE: If you are acquiring this software on behalf
+ * of the U.S. government, the Government shall have only
+ * "Restricted Rights" in the software and related documentation
+ * as defined in the Federal Acquisition Regulations (FARs) in
+ * Clause 52.227.19 (c) (2). If you are acquiring the software
+ * on behalf of the Department of Defense, the software shall be
+ * classified as "Commercial Computer Software" and the
+ * Government shall have only "Restricted Rights" as defined in
+ * Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
+ * foregoing, the authors grant the U.S. Government and others
+ * acting in its behalf permission to use and distribute the
+ * software in accordance with the terms specified in this
+ * license.
+ *
+ * RCS: @(#) $Id: tkMacOSXKeyEvent.c,v 1.20 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -63,225 +65,252 @@
#define TK_MAC_DEBUG_KEYBOARD
#endif
*/
-#ifdef TK_MAC_DEBUG_KEYBOARD
-#define KDBG DBG_MSG
-#else
-#define KDBG(...) /* nothing */
-#endif
typedef struct {
- WindowRef whichWindow;
- int global_x, global_y;
- int local_x, local_y;
+ WindowRef whichWindow;
+ int global_x, global_y;
+ int local_x, local_y;
unsigned int state;
unsigned char ch;
- UInt32 keyCode;
- UInt32 keyModifiers;
- UInt32 message;
+ UInt32 keyCode;
+ UInt32 keyModifiers;
+ UInt32 message;
} KeyEventData;
-static Tk_Window gGrabWinPtr = NULL;
- /* Current grab window, NULL if no grab. */
-static Tk_Window gKeyboardWinPtr = NULL;
- /* Current keyboard grab window. */
-static UInt32 deadKeyStateUp = 0;
- /* The deadkey state for the current sequence
- * of keyup events or 0 if not in a deadkey
- * sequence */
-static UInt32 deadKeyStateDown = 0;
- /* Ditto for keydown */
+static Tk_Window gGrabWinPtr = NULL; /* Current grab window,
+ * NULL if no grab. */
+static Tk_Window gKeyboardWinPtr = NULL; /* Current keyboard grab window. */
+
+static UInt32 deadKeyStateUp = 0; /* The deadkey state for the current
+ * sequence of keyup events or 0 if
+ * not in a deadkey sequence */
+static UInt32 deadKeyStateDown = 0; /* Ditto for keydown */
/*
* Declarations for functions used only in this file.
*/
-
-static int InitKeyData(KeyEventData *keyEventDataPtr);
-static int InitKeyEvent(XEvent *eventPtr, KeyEventData *e,
- UInt32 savedKeyCode, UInt32 savedModifiers);
-static int GenerateKeyEvent(UInt32 eKind, KeyEventData *e,
- UInt32 savedKeyCode, UInt32 savedModifiers,
- const UniChar *chars, int numChars);
-static int GetKeyboardLayout(Ptr *resourcePtr,
- TextEncoding *encodingPtr);
-static TextEncoding GetKCHREncoding(ScriptCode script, SInt32 layoutid);
-static int KeycodeToUnicodeViaUnicodeResource(UniChar *uniChars,
- int maxChars, Ptr uchr, EventKind eKind,
- UInt32 keycode, UInt32 modifiers,
- UInt32 *deadKeyStatePtr);
-static int KeycodeToUnicodeViaKCHRResource(UniChar *uniChars,
- int maxChars, Ptr kchr, TextEncoding encoding,
- EventKind eKind, UInt32 keycode, UInt32 modifiers,
- UInt32 *deadKeyStatePtr);
+
+static int InitKeyData(
+ KeyEventData * keyEventDataPtr);
+
+static int InitKeyEvent(
+ XEvent * eventPtr,
+ KeyEventData * e,
+ UInt32 savedKeyCode,
+ UInt32 savedModifiers);
+
+static int GenerateKeyEvent (
+ UInt32 eKind,
+ KeyEventData * e,
+ UInt32 savedKeyCode,
+ UInt32 savedModifiers,
+ const UniChar * chars, int numChars);
+
+static int GetKeyboardLayout (
+ Ptr * resourcePtr, TextEncoding * encodingPtr);
+static TextEncoding GetKCHREncoding(
+ ScriptCode script, SInt32 layoutid);
+
+static int KeycodeToUnicodeViaUnicodeResource(
+ UniChar * uniChars, int maxChars,
+ Ptr uchr,
+ EventKind eKind,
+ UInt32 keycode, UInt32 modifiers,
+ UInt32 * deadKeyStatePtr);
+
+static int KeycodeToUnicodeViaKCHRResource(
+ UniChar * uniChars, int maxChars,
+ Ptr kchr, TextEncoding encoding,
+ EventKind eKind,
+ UInt32 keycode, UInt32 modifiers,
+ UInt32 * deadKeyStatePtr);
/*
*----------------------------------------------------------------------
*
* TkMacOSXProcessKeyboardEvent --
*
- * This routine processes the event in eventPtr, and generates the
- * appropriate Tk events from it.
+ * This routine processes the event in eventPtr, and
+ * generates the appropriate Tk events from it.
*
* Results:
- * True if event(s) are generated - false otherwise.
+ * True if event(s) are generated - false otherwise.
*
* Side effects:
- * Additional events may be place on the Tk event queue.
+ * Additional events may be place on the Tk event queue.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE int
TkMacOSXProcessKeyboardEvent(
- TkMacOSXEvent *eventPtr,
- MacEventStatus *statusPtr)
+ TkMacOSXEvent * eventPtr,
+ MacEventStatus * statusPtr)
{
static UInt32 savedKeyCode = 0;
static UInt32 savedModifiers = 0;
static UniChar savedChar = 0;
- OSStatus status;
+ OSStatus status;
KeyEventData keyEventData;
- MenuRef menuRef;
+ MenuRef menuRef;
MenuItemIndex menuItemIndex;
int eventGenerated;
UniChar uniChars[5]; /* make this larger, if needed */
UInt32 uniCharsLen = 0;
if (!InitKeyData(&keyEventData)) {
- statusPtr->err = 1;
- return false;
+ statusPtr->err = 1;
+ return false;
}
-
+
/*
* Because of the way that Tk operates, we can't in general funnel menu
- * accelerators through IsMenuKeyEvent. Tk treats accelerators as mere
+ * accelerators through IsMenuKeyEvent. Tk treats accelerators as mere
* decoration, and the user has to install bindings to get them to fire.
*
- * However, the only way to trigger the Hide & Hide Others functions is by
- * invoking the Menu command for Hide. So there is no nice way to provide
- * a Tk command to hide the app which would be available for a binding. So
- * I am going to hijack Command-H and Command-Shift-H here, and run the
- * menu commands. Since the HI Guidelines explicitly reserve these for
- * Hide, this isn't such a bad thing. Also, if you do rebind Command-H to
- * another menu item, Hide will lose its binding.
- *
- * Note that I don't really do anything at this point, I just mark
- * stopProcessing as 0 and return, and then the RecieveAndProcessEvent
- * code will dispatch the event to the default handler.
+ * However, the only way to trigger the Hide & Hide Others functions
+ * is by invoking the Menu command for Hide. So there is no nice way to
+ * provide a Tk command to hide the app which would be available for a
+ * binding. So I am going to hijack Command-H and Command-Shift-H
+ * here, and run the menu commands. Since the HI Guidelines explicitly
+ * reserve these for Hide, this isn't such a bad thing. Also, if you do
+ * rebind Command-H to another menu item, Hide will lose its binding.
+ *
+ * Note that I don't really do anything at this point,
+ * I just mark stopProcessing as 0 and return, and then the
+ * RecieveAndProcessEvent code will dispatch the event to the default
+ * handler.
*/
- if ((eventPtr->eKind == kEventRawKeyDown
+ if ((eventPtr->eKind == kEventRawKeyDown
|| eventPtr->eKind == kEventRawKeyRepeat)
- && IsMenuKeyEvent(tkCurrentAppleMenu, eventPtr->eventRef,
+ && IsMenuKeyEvent(tkCurrentAppleMenu, eventPtr->eventRef,
kMenuEventQueryOnly, &menuRef, &menuItemIndex)) {
MenuCommand menuCmd;
GetMenuItemCommandID (menuRef, menuItemIndex, &menuCmd);
switch (menuCmd) {
- case kHICommandHide:
- case kHICommandHideOthers:
- case kHICommandShowAll:
- case kHICommandPreferences:
- case kHICommandQuit:
- statusPtr->stopProcessing = 0;
- return 0; /* TODO: may not be on event on queue. */
- break;
- default:
- break;
+ case kHICommandHide:
+ case kHICommandHideOthers:
+ case kHICommandShowAll:
+ case kHICommandPreferences:
+ case kHICommandQuit:
+ statusPtr->stopProcessing = 0;
+ return 0; /* TODO: may not be on event on queue. */
+ break;
+ default:
+ break;
}
}
- status = GetEventParameter(eventPtr->eventRef,
- kEventParamKeyMacCharCodes, typeChar, NULL,
- sizeof(keyEventData.ch), NULL, &keyEventData.ch);
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamKeyMacCharCodes,
+ typeChar, NULL,
+ sizeof(keyEventData.ch), NULL,
+ &keyEventData.ch);
if (status != noErr) {
- LOG_MSG("Failed to retrieve KeyMacCharCodes");
- statusPtr->err = 1;
- return false;
- }
- status = GetEventParameter(eventPtr->eventRef, kEventParamKeyCode,
- typeUInt32, NULL, sizeof(keyEventData.keyCode), NULL,
- &keyEventData.keyCode);
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr, "Failed to retrieve KeyMacCharCodes\n");
+#endif
+ statusPtr->err = 1;
+ return false;
+ }
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamKeyCode,
+ typeUInt32, NULL,
+ sizeof(keyEventData.keyCode), NULL,
+ &keyEventData.keyCode);
if (status != noErr) {
- LOG_MSG("Failed to retrieve KeyCode");
- statusPtr->err = 1;
- return false;
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr, "Failed to retrieve KeyCode\n");
+#endif
+ statusPtr->err = 1;
+ return false;
}
- status = GetEventParameter(eventPtr->eventRef, kEventParamKeyModifiers,
- typeUInt32, NULL, sizeof(keyEventData.keyModifiers), NULL,
- &keyEventData.keyModifiers);
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamKeyModifiers,
+ typeUInt32, NULL,
+ sizeof(keyEventData.keyModifiers), NULL,
+ &keyEventData.keyModifiers);
if (status != noErr) {
- LOG_MSG("Failed to retrieve KeyModifiers");
- statusPtr->err = 1;
- return false;
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr, "Failed to retrieve KeyModifiers\n");
+#endif
+ statusPtr->err = 1;
+ return false;
}
switch (eventPtr->eKind) {
- case kEventRawKeyUp:
- case kEventRawKeyDown:
- case kEventRawKeyRepeat: {
- UInt32 *deadKeyStatePtr;
-
- if (kEventRawKeyDown == eventPtr->eKind) {
- deadKeyStatePtr = &deadKeyStateDown;
- } else {
- deadKeyStatePtr = &deadKeyStateUp;
- }
-
- uniCharsLen = TkMacOSXKeycodeToUnicode(uniChars,
- sizeof(uniChars)/sizeof(*uniChars), eventPtr->eKind,
- keyEventData.keyCode, keyEventData.keyModifiers,
- deadKeyStatePtr);
- }
+ case kEventRawKeyUp:
+ case kEventRawKeyDown:
+ case kEventRawKeyRepeat:
+ {
+ UInt32 *deadKeyStatePtr;
+
+ if (kEventRawKeyDown == eventPtr->eKind) {
+ deadKeyStatePtr = &deadKeyStateDown;
+ } else {
+ deadKeyStatePtr = &deadKeyStateUp;
+ }
+
+ uniCharsLen = TkMacOSXKeycodeToUnicode(
+ uniChars, sizeof(uniChars)/sizeof(*uniChars),
+ eventPtr->eKind,
+ keyEventData.keyCode, keyEventData.keyModifiers,
+ deadKeyStatePtr);
+ }
}
if (kEventRawKeyUp == eventPtr->eKind) {
- /*
- * For some reason the deadkey processing for KeyUp doesn't work
- * sometimes, so we fudge and use the last detected KeyDown.
- */
-
- if ((0 == uniCharsLen) && (0 != savedChar)) {
- uniChars[0] = savedChar;
- uniCharsLen = 1;
- }
-
- /*
- * Suppress keyup events while we have a deadkey sequence on keydown.
- * We still *do* want to collect deadkey state in this situation if
- * the system provides it, that's why we do this only after
- * TkMacOSXKeycodeToUnicode().
- */
-
- if (0 != deadKeyStateDown) {
- uniCharsLen = 0;
- }
+ /*
+ * For some reason the deadkey processing for KeyUp doesn't work
+ * sometimes, so we fudge and use the last detected KeyDown.
+ */
+
+ if((0 == uniCharsLen) && (0 != savedChar)) {
+ uniChars[0] = savedChar;
+ uniCharsLen = 1;
+ }
+
+ /*
+ * Suppress keyup events while we have a deadkey sequence on keydown.
+ * We still *do* want to collect deadkey state in this situation if
+ * the system provides it, that's why we do this only after
+ * TkMacOSXKeycodeToUnicode().
+ */
+
+ if (0 != deadKeyStateDown) {
+ uniCharsLen = 0;
+ }
}
keyEventData.message = keyEventData.ch|(keyEventData.keyCode << 8);
- eventGenerated = GenerateKeyEvent(eventPtr->eKind, &keyEventData,
- savedKeyCode, savedModifiers, uniChars, uniCharsLen);
+ eventGenerated = GenerateKeyEvent(
+ eventPtr->eKind, &keyEventData,
+ savedKeyCode, savedModifiers,
+ uniChars, uniCharsLen);
savedModifiers = keyEventData.keyModifiers;
if ((kEventRawKeyDown == eventPtr->eKind) && (uniCharsLen > 0)) {
- savedChar = uniChars[0];
+ savedChar = uniChars[0];
} else {
- savedChar = 0;
+ savedChar = 0;
}
-
+
statusPtr->stopProcessing = 1;
if (eventGenerated == 0) {
- savedKeyCode = keyEventData.message;
- return false;
+ savedKeyCode = keyEventData.message;
+ return false;
} else if (eventGenerated == -1) {
- savedKeyCode = 0;
- statusPtr->stopProcessing = 0;
- return false;
+ savedKeyCode = 0;
+ statusPtr->stopProcessing = 0;
+ return false;
} else {
- savedKeyCode = 0;
- return true;
+ savedKeyCode = 0;
+ return true;
}
}
@@ -290,102 +319,107 @@ TkMacOSXProcessKeyboardEvent(
*
* GenerateKeyEvent --
*
- * Given Macintosh keyUp, keyDown & autoKey events (in their "raw" form)
- * and a list of unicode characters this function generates the
- * appropriate X key events.
+ * Given Macintosh keyUp, keyDown & autoKey events (in their "raw"
+ * form) and a list of unicode characters this function generates the
+ * appropriate X key events.
*
- * Parameter eKind is a raw keyboard event. e contains the data sent with
- * the event. savedKeyCode and savedModifiers contain the values from the
- * last event that came before (see TkMacOSXProcessKeyboardEvent()).
- * chars/numChars has the Unicode characters for which we want to create
- * events.
+ * Parameter eKind is a raw keyboard event. e contains the data sent
+ * with the event. savedKeyCode and savedModifiers contain the values
+ * from the last event that came before (see
+ * TkMacOSXProcessKeyboardEvent()). chars/numChars has the Unicode
+ * characters for which we want to create events.
*
* Results:
- * 1 if an event was generated, -1 for any error.
+ * 1 if an event was generated, -1 for any error.
*
* Side effects:
- * Additional events may be place on the Tk event queue.
+ * Additional events may be place on the Tk event queue.
*
*----------------------------------------------------------------------
*/
static int
GenerateKeyEvent(
- UInt32 eKind,
- KeyEventData * e,
- UInt32 savedKeyCode,
- UInt32 savedModifiers,
- const UniChar * chars,
- int numChars)
+ UInt32 eKind,
+ KeyEventData * e,
+ UInt32 savedKeyCode,
+ UInt32 savedModifiers,
+ const UniChar * chars, int numChars)
{
XEvent event;
int i;
-
+
if (-1 == InitKeyEvent(&event, e, savedKeyCode, savedModifiers)) {
- return -1;
+ return -1;
}
if (kEventRawKeyModifiersChanged == eKind) {
- if (savedModifiers > e->keyModifiers) {
- event.xany.type = KeyRelease;
- } else {
- event.xany.type = KeyPress;
- }
-
- /*
- * Use special '-1' to signify a special keycode to our
- * platform specific code in tkMacOSXKeyboard.c. This is
- * rather like what happens on Windows.
- */
-
- event.xany.send_event = -1;
- /*
- * Set keycode (which was zero) to the changed modifier
- */
-
- event.xkey.keycode = (e->keyModifiers ^ savedModifiers);
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ if (savedModifiers > e->keyModifiers) {
+ event.xany.type = KeyRelease;
+ } else {
+ event.xany.type = KeyPress;
+ }
+
+ /*
+ * Use special '-1' to signify a special keycode to our
+ * platform specific code in tkMacOSXKeyboard.c. This is
+ * rather like what happens on Windows.
+ */
+
+ event.xany.send_event = -1;
+
+ /*
+ * Set keycode (which was zero) to the changed modifier
+ */
+
+ event.xkey.keycode = (e->keyModifiers ^ savedModifiers);
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
} else {
- for (i = 0; i < numChars; ++i) {
- /*
- * Encode one char in the trans_chars array that was already
- * introduced for MS Windows. Don't encode the string, if it is a
- * control character but was not generated with a real control
- * modifier. Such control characters get generated by KeyTrans()
- * for special keys, but we rather want to identify those by their
- * KeySyms.
- */
-
- event.xkey.trans_chars[0] = 0;
- if ((controlKey & e->keyModifiers) || (chars[i] >= ' ')) {
- int done;
- done = Tcl_UniCharToUtf(chars[i],event.xkey.trans_chars);
- event.xkey.trans_chars[done] = 0;
- }
-
- switch(eKind) {
- case kEventRawKeyDown:
- event.xany.type = KeyPress;
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- break;
- case kEventRawKeyUp:
- event.xany.type = KeyRelease;
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- break;
- case kEventRawKeyRepeat:
- event.xany.type = KeyRelease;
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- event.xany.type = KeyPress;
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- break;
- default:
- LOG_MSG("GenerateKeyEvent(): Invalid parameter eKind %d",
- (int) eKind);
- return -1;
- }
- }
+
+ for (i = 0; i < numChars; ++i) {
+
+ /*
+ * Encode one char in the trans_chars array that was already
+ * introduced for MS Windows. Don't encode the string, if it is
+ * a control character but was not generated with a real control
+ * modifier. Such control characters get generated by KeyTrans()
+ * for special keys, but we rather want to identify those by
+ * their KeySyms.
+ */
+
+ event.xkey.trans_chars[0] = 0;
+ if ((controlKey & e->keyModifiers) || (chars[i] >= ' ')) {
+ int done;
+ done = Tcl_UniCharToUtf(chars[i],event.xkey.trans_chars);
+ event.xkey.trans_chars[done] = 0;
+ }
+
+ switch(eKind) {
+ case kEventRawKeyDown:
+ event.xany.type = KeyPress;
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ break;
+ case kEventRawKeyUp:
+ event.xany.type = KeyRelease;
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ break;
+ case kEventRawKeyRepeat:
+ event.xany.type = KeyRelease;
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ event.xany.type = KeyPress;
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ break;
+ default:
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr,
+ "GenerateKeyEvent(): Invalid parameter eKind %d\n",
+ (int) eKind);
+#endif
+ return -1;
+ }
+ }
}
return 1;
@@ -396,33 +430,33 @@ GenerateKeyEvent(
*
* InitKeyData --
*
- * This routine initializes a KeyEventData structure by asking the OS and
- * Tk for all the global information needed here.
+ * This routine initializes a KeyEventData structure by asking the OS
+ * and Tk for all the global information needed here.
*
* Results:
- * True if the current front window can be found in Tk data structures -
- * false otherwise.
+ * True if the current front window can be found in Tk data structures
+ * - false otherwise.
*
* Side Effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
-
-static int
-InitKeyData(
- KeyEventData *keyEventDataPtr)
+static int
+InitKeyData(KeyEventData * keyEventDataPtr)
{
- memset(keyEventDataPtr, 0, sizeof(*keyEventDataPtr));
+ memset (keyEventDataPtr, 0, sizeof(*keyEventDataPtr));
keyEventDataPtr->whichWindow = ActiveNonFloatingWindow();
if (keyEventDataPtr->whichWindow == NULL) {
- return false;
+ return false;
}
XQueryPointer(NULL, None, NULL, NULL,
- &keyEventDataPtr->global_x, &keyEventDataPtr->global_y,
- &keyEventDataPtr->local_x, &keyEventDataPtr->local_y,
- &keyEventDataPtr->state);
+ &keyEventDataPtr->global_x,
+ &keyEventDataPtr->global_y,
+ &keyEventDataPtr->local_x,
+ &keyEventDataPtr->local_y,
+ &keyEventDataPtr->state);
return true;
}
@@ -432,70 +466,75 @@ InitKeyData(
*
* InitKeyEvent --
*
- * Initialize an XEvent structure by asking Tk for global information.
- * Also uses a KeyEventData structure and other current state.
+ * Initialize an XEvent structure by asking Tk for global information.
+ * Also uses a KeyEventData structure and other current state.
*
* Results:
- * 1 on success, -1 for any error.
+ * 1 on success, -1 for any error.
*
* Side effects:
- * Additional events may be place on the Tk event queue.
+ * Additional events may be place on the Tk event queue.
*
*----------------------------------------------------------------------
*/
-/*
- * We have a general problem here. How do we handle 'Option-char' keypresses?
- * The problem is that we might want to bind to some of these (e.g. Cmd-Opt-d
- * is 'uncomment' in Alpha). OTOH Option-d actually produces a real character
- * on MacOS, namely a mathematical delta.
+/*
+ * We have a general problem here. How do we handle 'Option-char'
+ * keypresses? The problem is that we might want to bind to some of these
+ * (e.g. Cmd-Opt-d is 'uncomment' in Alpha). OTOH Option-d actually produces
+ * a real character on MacOS, namely a mathematical delta.
*
* The current behaviour is that a binding goes by the combinations of
- * modifiers and base keysym, that is Option-d. The string value of the event
- * is the mathematical delta character, so if no binding calls [break], the
- * text widget will insert that character.
+ * modifiers and base keysym, that is Option-d. The string value of the
+ * event is the mathematical delta character, so if no binding calls
+ * [break], the text widget will insert that character.
*
- * Note that this is similar to control combinations on all platforms. They
+ * Note that this is similar to control combinations on all platforms. They
* also generate events that have the base character as keysym and a real
- * control character as character value. So Ctrl+C gets us the keysym XK_C,
+ * control character as character value. So Ctrl+C gets us the keysym XK_C,
* the modifier Control (so you can bind <Control-C>) and a string value as
* "\u0003".
- *
+ *
* For a different solutions we may want for the event to contain keysyms for
- * *both* the 'Opt-d' side of things and the mathematical delta. Then a
+ * *both* the 'Opt-d' side of things and the mathematical delta. Then a
* binding on Opt-d will trigger, but a binding on mathematical delta would
- * also trigger. This would require changes in the core, though.
+ * also trigger. This would require changes in the core, though.
*/
static int
InitKeyEvent(
- XEvent * eventPtr,
- KeyEventData * e,
- UInt32 savedKeyCode,
- UInt32 savedModifiers)
+ XEvent * eventPtr,
+ KeyEventData * e,
+ UInt32 savedKeyCode,
+ UInt32 savedModifiers)
{
Window window;
Tk_Window tkwin;
TkDisplay *dispPtr;
-
+
/*
- * The focus must be in the FrontWindow on the Macintosh. We then query Tk
- * to determine the exact Tk window that owns the focus.
+ * The focus must be in the FrontWindow on the Macintosh.
+ * We then query Tk to determine the exact Tk window
+ * that owns the focus.
*/
window = TkMacOSXGetXWindow(e->whichWindow);
dispPtr = TkGetDisplayList();
tkwin = Tk_IdToWindow(dispPtr->display, window);
-
+
if (tkwin == NULL) {
- LOG_MSG("tkwin == NULL, %d", __LINE__);
- return -1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"tkwin == NULL, %d\n", __LINE__);
+#endif
+ return -1;
}
-
+
tkwin = (Tk_Window) ((TkWindow *) tkwin)->dispPtr->focusPtr;
if (tkwin == NULL) {
- LOG_MSG("tkwin == NULL, %d", __LINE__);
- return -1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"tkwin == NULL, %d\n", __LINE__);
+#endif
+ return -1;
}
eventPtr->xany.send_event = false;
@@ -512,15 +551,17 @@ InitKeyEvent(
eventPtr->xkey.state = e->state;
eventPtr->xkey.trans_chars[0] = 0;
- Tk_TopCoordsToWindow(tkwin, e->local_x, e->local_y,
- &eventPtr->xkey.x, &eventPtr->xkey.y);
+ Tk_TopCoordsToWindow(
+ tkwin, e->local_x, e->local_y,
+ &eventPtr->xkey.x, &eventPtr->xkey.y);
eventPtr->xkey.keycode = e->ch |
- ((savedKeyCode & charCodeMask) << 8) |
- ((e->message&keyCodeMask) << 8);
+ ((savedKeyCode & charCodeMask) << 8) |
+ ((e->message&keyCodeMask) << 8);
return 1;
}
+
/*
* If we have old headers, we need to define these types and constants
@@ -542,27 +583,25 @@ InitKeyEvent(
*
* GetKeyboardLayout --
*
- * Queries the OS for a pointer to a keyboard resource.
+ * Queries the OS for a pointer to a keyboard resource.
*
- * This function works with the keyboard layout switch menu. It uses
- * Keyboard Layout Services, where available.
+ * This function works with the keyboard layout switch menu. It uses
+ * Keyboard Layout Services, where available.
*
* Results:
- * 1 if there is returned a Unicode 'uchr' resource in *resourcePtr, 0 if
- * it is a classic 'KCHR' resource. A pointer to the actual resource data
- * goes into *resourcePtr. If the resource is a 'KCHR' resource, the
- * corresponding Mac encoding goes into *encodingPtr.
+ * 1 if there is returned a Unicode 'uchr' resource in *resourcePtr, 0
+ * if it is a classic 'KCHR' resource. A pointer to the actual resource
+ * data goes into *resourcePtr. If the resource is a 'KCHR' resource,
+ * the corresponding Mac encoding goes into *encodingPtr.
*
* Side effects:
- * Sets some internal static variables.
+ * Sets some internal static variables.
*
*----------------------------------------------------------------------
*/
static int
-GetKeyboardLayout(
- Ptr *resourcePtr,
- TextEncoding *encodingPtr)
+GetKeyboardLayout (Ptr * resourcePtr, TextEncoding * encodingPtr)
{
static KeyboardLayoutRef lastLayout = NULL;
static SInt32 lastLayoutId;
@@ -583,260 +622,279 @@ GetKeyboardLayout(
currentKeyScript = GetScriptManagerVariable(smKeyScript);
TkMacOSXInitNamedSymbol(HIToolbox, OSStatus, KLGetCurrentKeyboardLayout,
- KeyboardLayoutRef*);
+ KeyboardLayoutRef*);
TkMacOSXInitNamedSymbol(HIToolbox, OSStatus, KLGetKeyboardLayoutProperty,
- KeyboardLayoutRef, KeyboardLayoutPropertyTag, const void**);
+ KeyboardLayoutRef, KeyboardLayoutPropertyTag, const void**);
if (KLGetCurrentKeyboardLayout && KLGetKeyboardLayoutProperty) {
- /*
- * Use the Keyboard Layout Services (these functions only exist since
- * 10.2).
- */
-
- KLGetCurrentKeyboardLayout(&currentLayout);
-
- if (currentLayout != NULL) {
- /*
- * The layout pointer could in theory be the same for different
- * layouts, only the id gives us the information that the keyboard
- * has actually changed. OTOH the layout object can also change
- * and it could still be the same layoutid.
- */
-
- KLGetKeyboardLayoutProperty(currentLayout, kKLIdentifier,
- (const void**)&currentLayoutId);
-
- if ((lastLayout != currentLayout)
- || (lastLayoutId != currentLayoutId)) {
- KDBG("GetKeyboardLayout(): Use KLS");
- hasLayoutChanged = true;
-
- /*
- * Reinitialize all relevant variables.
- */
-
- lastLayout = currentLayout;
- lastLayoutId = currentLayoutId;
- uchr = NULL;
- KCHR = NULL;
-
- if ((KLGetKeyboardLayoutProperty(currentLayout, kKLuchrData,
- (const void**)&uchr) == noErr) && (uchr != NULL)) {
- /* done */
- } else if ((KLGetKeyboardLayoutProperty(currentLayout,
- kKLKCHRData, (const void**)&KCHR) == noErr)
- && (KCHR != NULL)) {
- /* done */
- }
- }
- }
+
+ /*
+ * Use the Keyboard Layout Services (these functions only exist since
+ * 10.2).
+ */
+
+ KLGetCurrentKeyboardLayout(&currentLayout);
+
+ if (currentLayout != NULL) {
+
+ /*
+ * The layout pointer could in theory be the same for different
+ * layouts, only the id gives us the information that the
+ * keyboard has actually changed. OTOH the layout object can
+ * also change and it could still be the same layoutid.
+ */
+
+ KLGetKeyboardLayoutProperty(currentLayout, kKLIdentifier,
+ (const void**)&currentLayoutId);
+
+ if ((lastLayout != currentLayout)
+ || (lastLayoutId != currentLayoutId)) {
+
+#ifdef TK_MAC_DEBUG_KEYBOARD
+ fprintf (stderr, "GetKeyboardLayout(): Use KLS\n");
+#endif
+
+ hasLayoutChanged = true;
+
+ /*
+ * Reinitialize all relevant variables.
+ */
+
+ lastLayout = currentLayout;
+ lastLayoutId = currentLayoutId;
+ uchr = NULL;
+ KCHR = NULL;
+
+ if ((KLGetKeyboardLayoutProperty(currentLayout,
+ kKLuchrData, (const void**)&uchr)
+ == noErr)
+ && (uchr != NULL)) {
+ /* done */
+ } else if ((KLGetKeyboardLayoutProperty(currentLayout,
+ kKLKCHRData, (const void**)&KCHR)
+ == noErr)
+ && (KCHR != NULL)) {
+ /* done */
+ }
+ }
+ }
+
} else {
- /*
- * Use the classic approach as shown in Apple code samples, loading
- * the keyboard resources directly. This is broken for 10.3 and
- * possibly already in 10.2.
- */
-
- currentLayoutId = GetScriptVariable(currentKeyScript,smScriptKeys);
-
- if ((lastLayout == NULL) || (lastLayoutId != currentLayoutId)) {
- KDBG("GetKeyboardLayout(): Use GetResource()");
-
- hasLayoutChanged = true;
-
- /*
- * Reinitialize all relevant variables.
- */
-
- lastLayout = (KeyboardLayoutRef)-1;
- lastLayoutId = currentLayoutId;
- uchr = NULL;
- KCHR = NULL;
-
- /*
- * Get the new layout resource in the classic way.
- */
-
- if (handle != NULL) {
- HUnlock(handle);
- }
-
- if ((handle = GetResource('uchr',currentLayoutId)) != NULL) {
- HLock(handle);
- uchr = *handle;
- } else if ((handle = GetResource('KCHR',currentLayoutId)) != NULL) {
- HLock(handle);
- KCHR = *handle;
- }
- }
+
+ /*
+ * Use the classic approach as shown in Apple code samples, loading
+ * the keyboard resources directly. This is broken for 10.3 and
+ * possibly already in 10.2.
+ */
+
+ currentLayoutId = GetScriptVariable(currentKeyScript,smScriptKeys);
+
+ if ((lastLayout == NULL) || (lastLayoutId != currentLayoutId)) {
+
+#ifdef TK_MAC_DEBUG_KEYBOARD
+ fprintf (stderr, "GetKeyboardLayout(): Use GetResource()\n");
+#endif
+
+ hasLayoutChanged = true;
+
+ /*
+ * Reinitialize all relevant variables.
+ */
+
+ lastLayout = (KeyboardLayoutRef)-1;
+ lastLayoutId = currentLayoutId;
+ uchr = NULL;
+ KCHR = NULL;
+
+ /*
+ * Get the new layout resource in the classic way.
+ */
+
+ if (handle != NULL) {
+ HUnlock(handle);
+ }
+
+ if ((handle = GetResource('uchr',currentLayoutId)) != NULL) {
+ HLock(handle);
+ uchr = *handle;
+ } else if ((handle = GetResource('KCHR',currentLayoutId)) != NULL) {
+ HLock(handle);
+ KCHR = *handle;
+ }
+ }
}
if (hasLayoutChanged) {
+
#ifdef TK_MAC_DEBUG_KEYBOARD
- if (KCHR != NULL) {
- KDBG("GetKeyboardLayout(): New 'KCHR' layout %d",
- (int) (short) currentLayoutId);
- } else if (uchr != NULL) {
- KDBG("GetKeyboardLayout(): New 'uchr' layout %d",
- (int) (short) currentLayoutId);
- } else {
- KDBG("GetKeyboardLayout(): Use cached layout "
- "(should have been %d)", (int) (short) currentLayoutId);
- }
+ if (KCHR != NULL) {
+ fprintf (stderr, "GetKeyboardLayout(): New 'KCHR' layout %d\n",
+ (int) (short) currentLayoutId);
+ } else if (uchr != NULL) {
+ fprintf (stderr, "GetKeyboardLayout(): New 'uchr' layout %d\n",
+ (int) (short) currentLayoutId);
+ } else {
+ fprintf (stderr, "GetKeyboardLayout(): Use cached layout "
+ "(should have been %d)\n",
+ (int) (short) currentLayoutId);
+ }
#endif
- deadKeyStateUp = deadKeyStateDown = 0;
-
- /*
- * If we did get a new 'KCHR', compute its encoding and put it into
- * lastEncoding.
- *
- * If we didn't get a new 'KCHR' and if we have no 'uchr' either, get
- * some 'KCHR' from the OS cache and leave lastEncoding at its
- * current value. This should better not happen, it doesn't really
- * work.
- */
-
- if (KCHR != NULL) {
- lastEncoding = GetKCHREncoding(currentKeyScript, currentLayoutId);
- KDBG("GetKeyboardLayout(): New 'KCHR' encoding %lu (%lu + 0x%lX)",
- lastEncoding, lastEncoding & 0xFFFFL,
- lastEncoding & ~0xFFFFL);
- } else if (uchr == NULL) {
- KCHR = (Ptr) GetScriptManagerVariable(smKCHRCache);
- }
+ deadKeyStateUp = deadKeyStateDown = 0;
+
+ /*
+ * If we did get a new 'KCHR', compute its encoding and put it into
+ * lastEncoding.
+ *
+ * If we didn't get a new 'KCHR' and if we have no 'uchr' either, get
+ * some 'KCHR' from the OS cache and leave lastEncoding at its
+ * current value. This should better not happen, it doesn't really
+ * work.
+ */
+
+ if (KCHR != NULL) {
+ lastEncoding = GetKCHREncoding(currentKeyScript, currentLayoutId);
+#ifdef TK_MAC_DEBUG_KEYBOARD
+ fprintf (stderr, "GetKeyboardLayout(): New 'KCHR' encoding %lu "
+ "(%lu + 0x%lX)\n",
+ lastEncoding, lastEncoding & 0xFFFFL,
+ lastEncoding & ~0xFFFFL);
+#endif
+ } else if (uchr == NULL) {
+ KCHR = (Ptr) GetScriptManagerVariable(smKCHRCache);
+ }
}
if (uchr != NULL) {
- *resourcePtr = uchr;
- return 1;
+ *resourcePtr = uchr;
+ return 1;
} else {
- *resourcePtr = KCHR;
- *encodingPtr = lastEncoding;
- return 0;
+ *resourcePtr = KCHR;
+ *encodingPtr = lastEncoding;
+ return 0;
}
}
+
/*
*----------------------------------------------------------------------
*
* GetKCHREncoding --
*
- * Upgrade a WorldScript code to a TEC encoding based on the keyboard
- * layout id.
+ * Upgrade a WorldScript code to a TEC encoding based on the keyboard
+ * layout id.
*
* Results:
- * The TEC code that corresponds best to the combination of WorldScript
- * code and 'KCHR' id.
+ * The TEC code that corresponds best to the combination of WorldScript
+ * code and 'KCHR' id.
*
* Side effects:
- * None.
+ * None.
*
* Rationale and Notes:
- * WorldScript codes are sometimes not unique encodings. E.g. Icelandic
- * uses script smRoman (0), but the actual encoding is
- * kTextEncodingMacIcelandic (37). ftp://ftp.unicode.org/Public
- * /MAPPINGS/VENDORS/APPLE/README.TXT has a good summary of these
- * variants. So we need to upgrade the script to an encoding with
- * GetTextEncodingFromScriptInfo().
+ * WorldScript codes are sometimes not unique encodings. E.g. Icelandic
+ * uses script smRoman (0), but the actual encoding is
+ * kTextEncodingMacIcelandic (37). ftp://ftp.unicode.org/Public
+ * /MAPPINGS/VENDORS/APPLE/README.TXT has a good summary of these
+ * variants. So we need to upgrade the script to an encoding with
+ * GetTextEncodingFromScriptInfo().
*
- * 'KCHR' ids are usually region codes (see the comments in Script.h).
- * Where they are not, we get a paramErr from the OS function and have
- * appropriate fallbacks.
+ * 'KCHR' ids are usually region codes (see the comments in Script.h).
+ * Where they are not, we get a paramErr from the OS function and have
+ * appropriate fallbacks.
*
*----------------------------------------------------------------------
*/
static TextEncoding
-GetKCHREncoding(
- ScriptCode script,
- SInt32 layoutid)
+GetKCHREncoding(ScriptCode script, SInt32 layoutid)
{
RegionCode region = layoutid;
TextEncoding encoding = script;
if (GetTextEncodingFromScriptInfo(script, kTextLanguageDontCare, region,
- &encoding) == noErr) {
- return encoding;
+ &encoding) == noErr) {
+ return encoding;
}
/*
- * GetTextEncodingFromScriptInfo() doesn't know about more exotic layouts.
- * This provides a fallback for good measure. In an ideal world, exotic
- * layouts would always provide a 'uchr' resource anyway, so we wouldn't
- * need this.
+ * GetTextEncodingFromScriptInfo() doesn't know about more exotic
+ * layouts. This provides a fallback for good measure. In an ideal
+ * world, exotic layouts would always provide a 'uchr' resource anyway,
+ * so we wouldn't need this.
*
- * We can add more keyboard layouts, if we get actual complaints. Farsi or
- * other Celtic/Gaelic layouts would be candidates.
+ * We can add more keyboard layouts, if we get actual complaints. Farsi
+ * or other Celtic/Gaelic layouts would be candidates.
*/
switch (layoutid) {
- /*
- * Icelandic and Faroese (planned). These layouts are sold by Apple
- * Iceland for legacy applications.
- */
-
- case 1800: case 1821:
- return kTextEncodingMacIcelandic;
-
- /*
- * Irish and Welsh. These layouts are mentioned in <Script.h>.
- *
- * FIXME: This may have to be kTextEncodingMacGaelic instead, but I
- * can't locate layouts of this type for testing.
- */
-
- case 581: case 779:
- return kTextEncodingMacCeltic;
- }
+ /*
+ * Icelandic and Faroese (planned). These layouts are sold by Apple
+ * Iceland for legacy applications.
+ */
+
+ case 1800: case 1821:
+ return kTextEncodingMacIcelandic;
+
+ /*
+ * Irish and Welsh. These layouts are mentioned in <Script.h>.
+ *
+ * FIXME: This may have to be kTextEncodingMacGaelic instead, but I
+ * can't locate layouts of this type for testing.
+ */
+
+ case 581: case 779:
+ return kTextEncodingMacCeltic;
+ }
+
/*
- * The valid script codes are also the valid default encoding codes, so if
- * nothing else helps, fall back on those.
+ * The valid script codes are also the valid default encoding codes, so
+ * if nothing else helps, fall back on those.
*/
return script;
}
+
/*
*----------------------------------------------------------------------
*
* KeycodeToUnicodeViaUnicodeResource --
*
- * Given MacOS key event data this function generates the Unicode
- * characters. It does this using a 'uchr' and the UCKeyTranslate API.
+ * Given MacOS key event data this function generates the Unicode
+ * characters. It does this using a 'uchr' and the UCKeyTranslate
+ * API.
*
- * The parameter deadKeyStatePtr can be NULL, if no deadkey handling is
- * needed.
+ * The parameter deadKeyStatePtr can be NULL, if no deadkey handling
+ * is needed.
*
- * Tested and known to work with US, Hebrew, Greek and Russian layouts as
- * well as "Unicode Hex Input".
+ * Tested and known to work with US, Hebrew, Greek and Russian layouts
+ * as well as "Unicode Hex Input".
*
* Results:
- * The number of characters generated if any, 0 if we are waiting for
- * another byte of a dead-key sequence. Fills in the uniChars array with
- * a Unicode string.
+ * The number of characters generated if any, 0 if we are waiting for
+ * another byte of a dead-key sequence. Fills in the uniChars array
+ * with a Unicode string.
*
* Side Effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
static int
KeycodeToUnicodeViaUnicodeResource(
- UniChar *uniChars,
- int maxChars,
- Ptr uchr,
- EventKind eKind,
- UInt32 keycode,
- UInt32 modifiers,
- UInt32 *deadKeyStatePtr)
+ UniChar * uniChars, int maxChars,
+ Ptr uchr,
+ EventKind eKind,
+ UInt32 keycode, UInt32 modifiers,
+ UInt32 * deadKeyStatePtr)
{
int action;
unsigned long keyboardType;
OptionBits options = 0;
UInt32 dummy_state;
- UniCharCount actuallength;
+ UniCharCount actuallength;
OSStatus status;
keycode &= 0xFF;
@@ -844,242 +902,260 @@ KeycodeToUnicodeViaUnicodeResource(
keyboardType = LMGetKbdType();
if (NULL==deadKeyStatePtr) {
- options = kUCKeyTranslateNoDeadKeysMask;
- dummy_state = 0;
- deadKeyStatePtr = &dummy_state;
+ options = kUCKeyTranslateNoDeadKeysMask;
+ dummy_state = 0;
+ deadKeyStatePtr = &dummy_state;
}
- switch(eKind) {
- case kEventRawKeyDown:
- action = kUCKeyActionDown;
- break;
- case kEventRawKeyUp:
- action = kUCKeyActionUp;
- break;
- case kEventRawKeyRepeat:
- action = kUCKeyActionAutoKey;
- break;
- default:
- LOG_MSG("KeycodeToUnicodeViaUnicodeResource(): "
- "Invalid parameter eKind %d", (int) eKind);
- return 0;
+ switch(eKind) {
+ case kEventRawKeyDown:
+ action = kUCKeyActionDown;
+ break;
+ case kEventRawKeyUp:
+ action = kUCKeyActionUp;
+ break;
+ case kEventRawKeyRepeat:
+ action = kUCKeyActionAutoKey;
+ break;
+ default:
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr,
+ "KeycodeToUnicodeViaUnicodeResource(): "
+ "Invalid parameter eKind %d\n",
+ (int) eKind);
+#endif
+ return 0;
}
- status = UCKeyTranslate((const UCKeyboardLayout *) uchr, keycode, action,
- modifiers, keyboardType, options, deadKeyStatePtr, maxChars,
- &actuallength, uniChars);
+ status = UCKeyTranslate(
+ (const UCKeyboardLayout *) uchr,
+ keycode, action, modifiers, keyboardType,
+ options, deadKeyStatePtr,
+ maxChars, &actuallength, uniChars);
if ((0 == actuallength) && (0 != *deadKeyStatePtr)) {
- /*
- * More data later
- */
-
- return 0;
+ /*
+ * More data later
+ */
+
+ return 0;
}
-
+
/*
* some IMEs leave residue :-(
*/
-
- *deadKeyStatePtr = 0;
+
+ *deadKeyStatePtr = 0;
if (noErr != status) {
- LOG_MSG("UCKeyTranslate failed: %d", (int) status);
- actuallength = 0;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"UCKeyTranslate failed: %d", (int) status);
+#endif
+ actuallength = 0;
}
return actuallength;
}
+
/*
*----------------------------------------------------------------------
*
* KeycodeToUnicodeViaKCHRResource --
*
- * Given MacOS key event data this function generates the Unicode
- * characters. It does this using a 'KCHR' and the KeyTranslate API.
+ * Given MacOS key event data this function generates the Unicode
+ * characters. It does this using a 'KCHR' and the KeyTranslate API.
*
- * The parameter deadKeyStatePtr can be NULL, if no deadkey handling is
- * needed.
+ * The parameter deadKeyStatePtr can be NULL, if no deadkey handling
+ * is needed.
*
* Results:
- * The number of characters generated if any, 0 if we are waiting for
- * another byte of a dead-key sequence. Fills in the uniChars array with
- * a Unicode string.
+ * The number of characters generated if any, 0 if we are waiting for
+ * another byte of a dead-key sequence. Fills in the uniChars array
+ * with a Unicode string.
*
* Side Effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
static int
KeycodeToUnicodeViaKCHRResource(
- UniChar *uniChars,
- int maxChars,
- Ptr kchr,
- TextEncoding encoding,
- EventKind eKind,
- UInt32 keycode,
- UInt32 modifiers,
- UInt32 *deadKeyStatePtr)
+ UniChar * uniChars, int maxChars,
+ Ptr kchr, TextEncoding encoding,
+ EventKind eKind,
+ UInt32 keycode, UInt32 modifiers,
+ UInt32 * deadKeyStatePtr)
{
UInt32 result;
char macBuff[3];
- char *macStr;
+ char * macStr;
int macStrLen;
UInt32 dummy_state = 0;
+
if (NULL == deadKeyStatePtr) {
- deadKeyStatePtr = &dummy_state;
+ deadKeyStatePtr = &dummy_state;
}
keycode |= modifiers;
result = KeyTranslate(kchr, keycode, deadKeyStatePtr);
if ((0 == result) && (0 != dummy_state)) {
- /*
- * 'dummy_state' gets only filled if the caller did not want deadkey
- * processing (deadKeyStatePtr was NULL originally), but we still
- * have a deadkey. We just push the keycode for the space bar to get
- * the real key value.
- */
-
- result = KeyTranslate(kchr, 0x31, deadKeyStatePtr);
- *deadKeyStatePtr = 0;
+ /*
+ * 'dummy_state' gets only filled if the caller did not want deadkey
+ * processing (deadKeyStatePtr was NULL originally), but we still
+ * have a deadkey. We just push the keycode for the space bar to get
+ * the real key value.
+ */
+
+ result = KeyTranslate(kchr, 0x31, deadKeyStatePtr);
+ *deadKeyStatePtr = 0;
}
if ((0 == result) && (0 != *deadKeyStatePtr)) {
- /*
- * More data later
- */
-
- return 0;
+ /*
+ * More data later
+ */
+
+ return 0;
}
macBuff[0] = (char) (result >> 16);
- macBuff[1] = (char) result;
+ macBuff[1] = (char) result;
macBuff[2] = 0;
if (0 != macBuff[0]) {
- /*
- * If the first byte is valid, the second is too
- */
-
- macStr = macBuff;
- macStrLen = 2;
+ /*
+ * If the first byte is valid, the second is too
+ */
+
+ macStr = macBuff;
+ macStrLen = 2;
} else if (0 != macBuff[1]) {
- /*
- * Only the second is valid
- */
-
- macStr = macBuff+1;
- macStrLen = 1;
+ /*
+ * Only the second is valid
+ */
+
+ macStr = macBuff+1;
+ macStrLen = 1;
} else {
- /*
- * No valid bytes at all -- shouldn't happen
- */
-
- macStr = NULL;
- macStrLen = 0;
+ /*
+ * No valid bytes at all -- shouldn't happen
+ */
+
+ macStr = NULL;
+ macStrLen = 0;
}
if (macStrLen <= 0) {
- return 0;
+ return 0;
} else {
- /*
- * Use the CFString conversion routines. This is the easiest and most
- * compatible way to get from an 8-bit string and a MacOS script code
- * to a Unicode string.
- *
- * FIXME: The system ships with an Irish 'KCHR' but without the
- * corresponding macCeltic encoding, which triggers the error below.
- * Tcl doesn't have the macCeltic encoding either right now, so until
- * we get that, we can just as well stick to this code. The right fix
- * would be to use the Tcl encodings and add macCeltic and probably
- * others there. Suitable Unicode data files for the missing encodings
- * are available from www.evertype.com.
- */
-
- CFStringRef cfString;
- int uniStrLen;
-
- cfString = CFStringCreateWithCStringNoCopy(NULL, macStr, encoding,
- kCFAllocatorNull);
- if (cfString == NULL) {
- LOG_MSG("CFString: Can't convert with encoding %d",
- (int) encoding);
- return 0;
- }
- uniStrLen = CFStringGetLength(cfString);
- if (uniStrLen > maxChars) {
- uniStrLen = maxChars;
- }
- CFStringGetCharacters(cfString, CFRangeMake(0,uniStrLen), uniChars);
- CFRelease(cfString);
+ /*
+ * Use the CFString conversion routines. This is the easiest and
+ * most compatible way to get from an 8-bit string and a MacOS script
+ * code to a Unicode string.
+ *
+ * FIXME: The system ships with an Irish 'KCHR' but without the
+ * corresponding macCeltic encoding, which triggers the error below.
+ * Tcl doesn't have the macCeltic encoding either right now, so until
+ * we get that, we can just as well stick to this code. The right
+ * fix would be to use the Tcl encodings and add macCeltic and
+ * probably others there. Suitable Unicode data files for the
+ * missing encodings are available from www.evertype.com.
+ */
+
+ CFStringRef cfString;
+ int uniStrLen;
+
+ cfString = CFStringCreateWithCStringNoCopy(
+ NULL, macStr, encoding, kCFAllocatorNull);
+ if (cfString == NULL) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "CFString: Can't convert with encoding %d\n",
+ (int) encoding);
+#endif
+ return 0;
+ }
+
+ uniStrLen = CFStringGetLength(cfString);
+ if (uniStrLen > maxChars) {
+ uniStrLen = maxChars;
+ }
+ CFStringGetCharacters(cfString, CFRangeMake(0,uniStrLen), uniChars);
+ CFRelease(cfString);
- return uniStrLen;
+ return uniStrLen;
}
}
+
/*
*----------------------------------------------------------------------
*
* TkMacOSXKeycodeToUnicode --
*
- * Given MacOS key event data this function generates the Unicode
- * characters. It does this using OS resources and APIs.
+ * Given MacOS key event data this function generates the Unicode
+ * characters. It does this using OS resources and APIs.
*
- * The parameter deadKeyStatePtr can be NULL, if no deadkey handling is
- * needed.
+ * The parameter deadKeyStatePtr can be NULL, if no deadkey handling
+ * is needed.
*
- * This function is called from XKeycodeToKeysym() in tkMacOSKeyboard.c.
+ * This function is called from XKeycodeToKeysym() in
+ * tkMacOSKeyboard.c.
*
* Results:
- * The number of characters generated if any, 0 if we are waiting for
- * another byte of a dead-key sequence. Fills in the uniChars array with
- * a Unicode string.
+ * The number of characters generated if any, 0 if we are waiting for
+ * another byte of a dead-key sequence. Fills in the uniChars array
+ * with a Unicode string.
*
* Side Effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE int
TkMacOSXKeycodeToUnicode(
- UniChar *uniChars,
- int maxChars,
- EventKind eKind,
- UInt32 keycode,
- UInt32 modifiers,
- UInt32 *deadKeyStatePtr)
+ UniChar * uniChars, int maxChars,
+ EventKind eKind,
+ UInt32 keycode, UInt32 modifiers,
+ UInt32 * deadKeyStatePtr)
{
Ptr resource = NULL;
TextEncoding encoding;
+ int len;
+
- if (GetKeyboardLayout(&resource, &encoding)) {
- return KeycodeToUnicodeViaUnicodeResource(uniChars, maxChars,
- resource, eKind, keycode, modifiers, deadKeyStatePtr);
+ if (GetKeyboardLayout(&resource,&encoding)) {
+ len = KeycodeToUnicodeViaUnicodeResource(
+ uniChars, maxChars, resource, eKind,
+ keycode, modifiers, deadKeyStatePtr);
} else {
- return KeycodeToUnicodeViaKCHRResource(uniChars, maxChars, resource,
- encoding, eKind, keycode, modifiers, deadKeyStatePtr);
+ len = KeycodeToUnicodeViaKCHRResource(
+ uniChars, maxChars, resource, encoding, eKind,
+ keycode, modifiers, deadKeyStatePtr);
}
+
+ return len;
}
+
+
/*
*----------------------------------------------------------------------
*
* XGrabKeyboard --
*
- * Simulates a keyboard grab by setting the focus.
+ * Simulates a keyboard grab by setting the focus.
*
* Results:
- * Always returns GrabSuccess.
+ * Always returns GrabSuccess.
*
* Side effects:
- * Sets the keyboard focus to the specified window.
+ * Sets the keyboard focus to the specified window.
*
*----------------------------------------------------------------------
*/
@@ -1102,13 +1178,13 @@ XGrabKeyboard(
*
* XUngrabKeyboard --
*
- * Releases the simulated keyboard grab.
+ * Releases the simulated keyboard grab.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Sets the keyboard focus back to the value before the grab.
+ * Sets the keyboard focus back to the value before the grab.
*
*----------------------------------------------------------------------
*/
@@ -1127,14 +1203,13 @@ XUngrabKeyboard(
* TkMacOSXGetCapture --
*
* Results:
- * Returns the current grab window
+ * Returns the current grab window
* Side effects:
- * None.
+ * None.
*
*/
-
Tk_Window
-TkMacOSXGetCapture(void)
+TkMacOSXGetCapture()
{
return gGrabWinPtr;
}
@@ -1144,25 +1219,26 @@ TkMacOSXGetCapture(void)
*
* TkpSetCapture --
*
- * This function captures the mouse so that all future events will be
- * reported to this window, even if the mouse is outside the window. If
- * the specified window is NULL, then the mouse is released.
+ * This function captures the mouse so that all future events
+ * will be reported to this window, even if the mouse is outside
+ * the window. If the specified window is NULL, then the mouse
+ * is released.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Sets the capture flag and captures the mouse.
+ * Sets the capture flag and captures the mouse.
*
*----------------------------------------------------------------------
*/
void
TkpSetCapture(
- TkWindow *winPtr) /* Capture window, or NULL. */
+ TkWindow *winPtr) /* Capture window, or NULL. */
{
while ((winPtr != NULL) && !Tk_IsTopLevel(winPtr)) {
- winPtr = winPtr->parentPtr;
+ winPtr = winPtr->parentPtr;
}
gGrabWinPtr = (Tk_Window) winPtr;
}
@@ -1172,25 +1248,25 @@ TkpSetCapture(
*
* Tk_SetCaretPos --
*
- * This enables correct placement of the XIM caret. This is called by
- * widgets to indicate their cursor placement, and the caret location is
- * used by TkpGetString to place the XIM caret.
+ * This enables correct placement of the XIM caret. This is called
+ * by widgets to indicate their cursor placement, and the caret
+ * location is used by TkpGetString to place the XIM caret.
*
* Results:
- * None
+ * None
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
void
-Tk_SetCaretPos(
- Tk_Window tkwin,
- int x,
- int y,
- int height)
+Tk_SetCaretPos(tkwin, x, y, height)
+ Tk_Window tkwin;
+ int x;
+ int y;
+ int height;
{
}
@@ -1199,31 +1275,23 @@ Tk_SetCaretPos(
*
* TkMacOSXInitKeyboard --
*
- * This procedure initializes the keyboard layout.
+ * This procedure initializes the keyboard layout.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
MODULE_SCOPE void
-TkMacOSXInitKeyboard(
- Tcl_Interp *interp)
+TkMacOSXInitKeyboard (
+ Tcl_Interp *interp)
{
Ptr resource;
TextEncoding encoding;
-
- GetKeyboardLayout(&resource, &encoding);
+
+ GetKeyboardLayout(&resource,&encoding);
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index f4d1acf..0d80798 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.c
@@ -1,4 +1,4 @@
-/*
+/*
* tkMacOSXMenu.c --
*
* This module implements the Mac-platform specific features of menus.
@@ -7,10 +7,10 @@
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2005-2006 Daniel A. Steffen <das@users.sourceforge.net>
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.35 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.36 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -36,9 +36,10 @@
typedef struct MacMenu {
MenuRef menuHdl; /* The Menu Manager data structure. */
Rect menuRect; /* The rectangle as calculated in the
- * MDEF. This is used to figure out the
- * clipping rgn before we push the
- * <<MenuSelect>> virtual binding through. */
+ * MDEF. This is used to figure ou the
+ * clipping rgn before we push
+ * the <<MenuSelect>> virtual binding
+ * through. */
} MacMenu;
typedef struct MenuEntryUserData {
@@ -104,14 +105,15 @@ typedef struct MenuEntryUserData {
*/
typedef struct EntryGeometry {
- int accelTextStart; /* Offset into the accel string where the text
- * starts. Everything before this is modifier
- * key descriptions. */
+ int accelTextStart; /* Offset into the accel string where
+ * the text starts. Everything before
+ * this is modifier key descriptions.
+ */
int modifierWidth; /* Width of modifier symbols. */
- int accelTextWidth; /* Width of the text after the modifier
+ int accelTextWidth; /* Width of the text after the modifier
* keys. */
- int nonAccelMargin; /* The width of the margin for entries without
- * accelerators. */
+ int nonAccelMargin; /* The width of the margin for entries
+ * without accelerators. */
} EntryGeometry;
/*
@@ -144,14 +146,15 @@ typedef struct TopLevelMenubarList {
#define MENU_HELP_MENU MENU_PLATFORM_FLAG2
#define MENU_RECONFIGURE_PENDING MENU_PLATFORM_FLAG3
-#define CASCADE_CMD (0x1b) /* The special command char for cascade
- * menus. */
+#define CASCADE_CMD (0x1b)
+ /* The special command char for cascade
+ * menus. */
#define MENUBAR_REDRAW_PENDING 1
#define SCREEN_MARGIN 5
static int gNoTkMenus = 0; /* This is used by Tk_MacOSXTurnOffMenus as the
- * flag that Tk is not to draw any menus. */
-
+ * flag that Tk is not to draw any menus. */
+
RgnHandle tkMenuCascadeRgn = NULL;
/* The region to clip drawing to when the
* MDEF is up. */
@@ -180,7 +183,7 @@ static char *currentMenuBarName;
static Tk_Window currentMenuBarOwner;
/* Which window owns the current menu bar. */
static char elipsisString[TCL_UTF_MAX + 1];
- /* The UTF representation of the elipsis (...)
+ /* The UTF representation of the elipsis (...)
* character. */
static int inPostMenu; /* We cannot be re-entrant like X
* windows. */
@@ -194,7 +197,7 @@ static MacDrawable macMDEFDrawable;
static int MDEFScrollFlag = 0; /* Used so that popups don't scroll too soon. */
static int menuBarFlags; /* Used for whether the menu bar needs
* redrawing or not. */
-
+
static struct TearoffSelect {
TkMenu *menuPtr; /* The menu that is torn off */
Point point; /* The point to place the new menu */
@@ -203,8 +206,8 @@ static struct TearoffSelect {
} tearoffStruct;
struct MenuCommandHandlerData { /* This is the ClientData we pass to */
- TkMenu *menuPtr; /* Tcl_DoWhenIdle to move handling */
- int index; /* menu commands to the event loop. */
+ TkMenu *menuPtr; /* Tcl_DoWhenIdle to move handling */
+ int index; /* menu commands to the event loop. */
};
static RgnHandle totalMenuRgn = NULL;
@@ -215,7 +218,7 @@ static RgnHandle utilRgn = NULL;/* Used when creating the region that is to
static TopLevelMenubarList *windowListPtr;
/* A list of windows that have menubars set. */
-static MenuItemDrawingUPP tkThemeMenuItemDrawingUPP;
+static MenuItemDrawingUPP tkThemeMenuItemDrawingUPP;
/* Points to the UPP for theme Item drawing. */
static Tcl_Obj *useMDEFVar;
@@ -225,94 +228,125 @@ MenuRef tkCurrentAppleMenu = NULL;
* Forward declarations for procedures defined later in this file:
*/
-MODULE_SCOPE int TkMacOSXGetNewMenuID(Tcl_Interp *interp,
- TkMenu *menuInstPtr, int cascade,
- short *menuIDPtr);
-MODULE_SCOPE void TkMacOSXFreeMenuID(short menuID);
-
-static void CompleteIdlers(TkMenu *menuPtr);
-static void DrawMenuBarWhenIdle(ClientData clientData);
-static void DrawMenuBackground(Rect *menuRectPtr, Drawable d,
- ThemeMenuType type);
-static void DrawMenuEntryAccelerator(TkMenu *menuPtr,
- TkMenuEntry *mePtr, Drawable d, GC gc,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- Tk_3DBorder activeBorder, int x, int y, int width,
- int height, int drawArrow);
-static void DrawMenuEntryBackground(TkMenu *menuPtr,
- TkMenuEntry *mePtr, Drawable d,
- Tk_3DBorder activeBorder, Tk_3DBorder bgBorder,
- int x, int y, int width, int heigth);
-static void DrawMenuEntryIndicator(TkMenu *menuPtr,
- TkMenuEntry *mePtr, Drawable d, GC gc,
- GC indicatorGC, Tk_Font tkfont,
- CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height);
-static void DrawMenuEntryLabel(TkMenu *menuPtr,TkMenuEntry *mePtr,
- Drawable d, GC gc, Tk_Font tkfont,
- CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height);
-static void DrawMenuSeparator(TkMenu *menuPtr, TkMenuEntry *mePtr,
- Drawable d, GC gc, Tk_Font tkfont,
+MODULE_SCOPE int TkMacOSXGetNewMenuID _ANSI_ARGS_((Tcl_Interp *interp,
+ TkMenu *menuInstPtr,
+ int cascade,
+ short *menuIDPtr));
+MODULE_SCOPE void TkMacOSXFreeMenuID _ANSI_ARGS_((short menuID));
+
+static void CompleteIdlers _ANSI_ARGS_((TkMenu *menuPtr));
+static void DrawMenuBarWhenIdle _ANSI_ARGS_((
+ ClientData clientData));
+static void DrawMenuBackground _ANSI_ARGS_((
+ Rect *menuRectPtr, Drawable d, ThemeMenuType type));
+static void DrawMenuEntryAccelerator _ANSI_ARGS_((
+ TkMenu *menuPtr, TkMenuEntry *mePtr,
+ Drawable d, GC gc, Tk_Font tkfont,
+ CONST Tk_FontMetrics *fmPtr,
+ Tk_3DBorder activeBorder, int x, int y,
+ int width, int height, int drawArrow));
+static void DrawMenuEntryBackground _ANSI_ARGS_((
+ TkMenu *menuPtr, TkMenuEntry *mePtr,
+ Drawable d, Tk_3DBorder activeBorder,
+ Tk_3DBorder bgBorder, int x, int y,
+ int width, int heigth));
+static void DrawMenuEntryIndicator _ANSI_ARGS_((
+ TkMenu *menuPtr, TkMenuEntry *mePtr,
+ Drawable d, GC gc, GC indicatorGC,
+ Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height);
-static void DrawTearoffEntry(TkMenu *menuPtr, TkMenuEntry *mePtr,
- Drawable d, GC gc, Tk_Font tkfont,
+ int width, int height));
+static void DrawMenuEntryLabel _ANSI_ARGS_((
+ TkMenu * menuPtr, TkMenuEntry *mePtr, Drawable d,
+ GC gc, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height);
-static void EventuallyInvokeMenu(ClientData data);
-static void GetEntryText(TkMenuEntry *mePtr,
- Tcl_DString *dStringPtr);
-static void GetMenuAccelGeometry(TkMenu *menuPtr,
+ int width, int height));
+static void DrawMenuSeparator _ANSI_ARGS_((TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height));
+static void DrawTearoffEntry _ANSI_ARGS_((TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height));
+static void EventuallyInvokeMenu (ClientData data);
+static void GetEntryText _ANSI_ARGS_((TkMenuEntry *mePtr,
+ Tcl_DString *dStringPtr));
+static void GetMenuAccelGeometry _ANSI_ARGS_((TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int *modWidthPtr,
- int *textWidthPtr, int *heightPtr);
-static void GetMenuLabelGeometry(TkMenuEntry *mePtr,
+ int *textWidthPtr, int *heightPtr));
+static void GetMenuLabelGeometry _ANSI_ARGS_((TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr);
-static void GetMenuIndicatorGeometry(TkMenu *menuPtr,
- TkMenuEntry *mePtr, Tk_Font tkfont,
- CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr);
-static void GetMenuSeparatorGeometry(
+ int *widthPtr, int *heightPtr));
+static void GetMenuIndicatorGeometry _ANSI_ARGS_((
+ TkMenu *menuPtr, TkMenuEntry *mePtr,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int *widthPtr, int *heightPtr));
+static void GetMenuSeparatorGeometry _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr);
-static void GetTearoffEntryGeometry(TkMenu *menuPtr,
+ int *widthPtr, int *heightPtr));
+static void GetTearoffEntryGeometry _ANSI_ARGS_((TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int *widthPtr,
- int *heightPtr);
-static char FindMarkCharacter(TkMenuEntry *mePtr);
-static void InvalidateMDEFRgns(void);
-static void MenuDefProc(short message, MenuHandle menu,
- Rect *menuRectPtr, Point hitPt, short *whichItem);
-static void HandleMenuHiliteMsg(MenuRef menu, Rect *menuRectPtr,
- Point hitPt, SInt16 *whichItem, TkMenu *menuPtr);
-static void HandleMenuDrawMsg(MenuRef menu, Rect *menuRectPtr,
- Point hitPt, SInt16 *whichItem, TkMenu *menuPtr);
-static void HandleMenuFindItemsMsg(MenuRef menu, Rect *menuRectPtr,
- Point hitPt, SInt16 *whichItem, TkMenu *menuPtr);
-static void HandleMenuPopUpMsg(MenuRef menu, Rect *menuRectPtr,
- Point hitPt, SInt16 *whichItem, TkMenu *menuPtr);
-static void HandleMenuCalcItemMsg(MenuRef menu, Rect *menuRectPtr,
- Point hitPt, SInt16 *whichItem, TkMenu *menuPtr);
-static void MenuSelectEvent(TkMenu *menuPtr);
-static void ReconfigureIndividualMenu(TkMenu *menuPtr,
- MenuHandle macMenuHdl, int base);
-static void ReconfigureMacintoshMenu(ClientData clientData);
-static void RecursivelyClearActiveMenu(TkMenu *menuPtr);
-static void RecursivelyDeleteMenu(TkMenu *menuPtr);
-static void RecursivelyInsertMenu(TkMenu *menuPtr);
-static void SetDefaultMenubar(void);
-static int SetMenuCascade(TkMenu *menuPtr);
-static void mySetMenuTitle(MenuHandle menuHdl, Tcl_Obj *titlePtr);
-static void AppearanceEntryDrawWrapper(TkMenuEntry *mePtr,
- Rect *menuRectPtr, MenuTrackingData *mtdPtr,
+ int *heightPtr));
+static char FindMarkCharacter _ANSI_ARGS_((TkMenuEntry *mePtr));
+static void InvalidateMDEFRgns _ANSI_ARGS_((void));
+
+static void MenuDefProc _ANSI_ARGS_((short message,
+ MenuHandle menu, Rect *menuRectPtr,
+ Point hitPt, short *whichItem ));
+static void HandleMenuHiliteMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr);
+static void HandleMenuDrawMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr);
+static void HandleMenuFindItemsMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr);
+static void HandleMenuPopUpMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr);
+static void HandleMenuCalcItemMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr);
+
+static void MenuSelectEvent _ANSI_ARGS_((TkMenu *menuPtr));
+static void ReconfigureIndividualMenu _ANSI_ARGS_((
+ TkMenu *menuPtr, MenuHandle macMenuHdl,
+ int base));
+static void ReconfigureMacintoshMenu _ANSI_ARGS_ ((
+ ClientData clientData));
+static void RecursivelyClearActiveMenu _ANSI_ARGS_((
+ TkMenu *menuPtr));
+static void RecursivelyDeleteMenu _ANSI_ARGS_((
+ TkMenu *menuPtr));
+static void RecursivelyInsertMenu _ANSI_ARGS_((
+ TkMenu *menuPtr));
+static void SetDefaultMenubar _ANSI_ARGS_((void));
+static int SetMenuCascade _ANSI_ARGS_((TkMenu *menuPtr));
+static void mySetMenuTitle _ANSI_ARGS_((MenuHandle menuHdl,
+ Tcl_Obj *titlePtr));
+static void AppearanceEntryDrawWrapper _ANSI_ARGS_((TkMenuEntry *mePtr,
+ Rect * menuRectPtr, MenuTrackingData *mtdPtr,
Drawable d, Tk_FontMetrics *fmPtr, Tk_Font tkfont,
- int x, int y, int width, int height);
-static pascal void ThemeMenuItemDrawingProc(const Rect *inBounds,
- SInt16 inDepth, Boolean inIsColorDevice,
- SInt32 inUserData);
+ int x, int y, int width, int height));
+static pascal void ThemeMenuItemDrawingProc _ANSI_ARGS_ ((const Rect *inBounds,
+ SInt16 inDepth, Boolean inIsColorDevice,
+ SInt32 inUserData));
+
/*
*----------------------------------------------------------------------
@@ -341,15 +375,16 @@ TkMacOSXUseMenuID(
Tcl_HashEntry *commandEntryPtr;
int newEntry;
int iMacID = macID; /* Do this to remove compiler warning */
-
+
TkMenuInit();
commandEntryPtr = Tcl_CreateHashEntry(&commandTable, (char *) iMacID,
- &newEntry);
- if (!newEntry) {
- return TCL_ERROR;
+ &newEntry);
+ if (newEntry == 1) {
+ Tcl_SetHashValue(commandEntryPtr, NULL);
+ return TCL_OK;
+ } else {
+ return TCL_ERROR;
}
- Tcl_SetHashValue(commandEntryPtr, NULL);
- return TCL_OK;
}
/*
@@ -357,27 +392,27 @@ TkMacOSXUseMenuID(
*
* TkMacOSXGetNewMenuID --
*
- * Allocates a new menu id and marks it in use. Each menu on the mac must
- * be designated by a unique id, which is a short. In addition, some ids
- * are reserved by the system. Since Tk uses mostly dynamic menus, we
- * must allocate and free these ids on the fly. We use the id as a key
- * into a hash table; if there is no hash entry, we know that we can use
- * the id.
+ * Allocates a new menu id and marks it in use. Each menu on the
+ * mac must be designated by a unique id, which is a short. In
+ * addition, some ids are reserved by the system. Since Tk uses
+ * mostly dynamic menus, we must allocate and free these ids on
+ * the fly. We use the id as a key into a hash table; if there
+ * is no hash entry, we know that we can use the id.
*
- * Carbon allows a much larger number of menus than the old APIs. I
- * believe this is 32768, but am not sure. This code just uses 2000 as
- * the upper limit. Unfortunately Tk leaks menus when cloning, under some
- * circumstances (see bug on sourceforge).
+ * Carbon allows a much larger number of menus than the old APIs.
+ * I believe this is 32768, but am not sure. This code just uses
+ * 2000 as the upper limit. Unfortunately tk leaks menus when
+ * cloning, under some circumstances (see bug on sourceforge).
*
* Results:
- * Returns TCL_OK if succesful; TCL_ERROR if there are no more ids of the
- * appropriate type to allocate. menuIDPtr contains the new id if
- * succesful.
+ * Returns TCL_OK if succesful; TCL_ERROR if there are no more
+ * ids of the appropriate type to allocate. menuIDPtr contains
+ * the new id if succesful.
*
* Side effects:
- * An entry is created for the menu in the command hash table, and the
- * hash entry is stored in the appropriate field in the menu data
- * structure.
+ * An entry is created for the menu in the command hash table,
+ * and the hash entry is stored in the appropriate field in the
+ * menu data structure.
*
*----------------------------------------------------------------------
*/
@@ -386,7 +421,7 @@ int
Tcl_Interp *interp, /* Used for error reporting */
TkMenu *menuPtr, /* The menu we are working with */
int cascade, /* 0 if we are working with a normal menu;
- * 1 if we are working with a cascade */
+ 1 if we are working with a cascade */
short *menuIDPtr) /* The resulting id */
{
int found = 0;
@@ -395,27 +430,25 @@ int
short returnID = *menuIDPtr;
/*
- * The following code relies on shorts and unsigned chars wrapping when
- * the highest value is incremented. Also, the values between 236 and 255
- * inclusive are reserved for DA's by the Mac OS.
+ * The following code relies on shorts and unsigned chars wrapping
+ * when the highest value is incremented. Also, the values between
+ * 236 and 255 inclusive are reserved for DA's by the Mac OS.
*/
-
+
if (!cascade) {
short curID = lastMenuID + 1;
-
- if (curID == 236) {
+ if (curID == 236) {
curID = 256;
}
while (curID != lastMenuID) {
- int iCurID = curID;
-
+ int iCurID = curID;
commandEntryPtr = Tcl_CreateHashEntry(&commandTable,
(char *) iCurID, &newEntry);
if (newEntry == 1) {
- found = 1;
- lastMenuID = returnID = curID;
- break;
+ found = 1;
+ lastMenuID = returnID = curID;
+ break;
}
curID++;
if (curID == 236) {
@@ -423,19 +456,19 @@ int
}
}
} else {
+
/*
- * Cascade ids must be between 0 and 235 only, so they must be dealt
- * with separately.
+ * Cascade ids must be between 0 and 235 only, so they must be
+ * dealt with separately.
*/
-
+
short curID = lastCascadeID + 1;
- if (curID == 2000) {
+ if (curID == 2000) {
curID = 0;
}
-
+
while (curID != lastCascadeID) {
- int iCurID = curID;
-
+ int iCurID = curID;
commandEntryPtr = Tcl_CreateHashEntry(&commandTable,
(char *) iCurID, &newEntry);
if (newEntry == 1) {
@@ -450,15 +483,16 @@ int
}
}
- if (!found) {
+ if (found) {
+ Tcl_SetHashValue(commandEntryPtr, (char *) menuPtr);
+ *menuIDPtr = returnID;
+ return TCL_OK;
+ } else {
Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "No more menus can be allocated.", NULL);
+ Tcl_AppendResult(interp, "No more menus can be allocated.",
+ (char *) NULL);
return TCL_ERROR;
}
-
- Tcl_SetHashValue(commandEntryPtr, (char *) menuPtr);
- *menuIDPtr = returnID;
- return TCL_OK;
}
/*
@@ -483,7 +517,7 @@ TkMacOSXFreeMenuID(
{
Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&commandTable,
(char *) ((int)menuID));
-
+
if (entryPtr != NULL) {
Tcl_DeleteHashEntry(entryPtr);
}
@@ -507,8 +541,8 @@ TkMacOSXFreeMenuID(
* Returns a standard TCL error.
*
* Side effects:
- * Allocates a Macintosh menu handle and puts in the platformData field
- * of the menuPtr.
+ * Allocates a Macintosh menu handle and puts in the platformData
+ * field of the menuPtr.
*
*----------------------------------------------------------------------
*/
@@ -526,45 +560,49 @@ TkpNewMenu(
int error = TCL_OK;
OSStatus err;
CFStringRef cfStr;
-
+
error = TkMacOSXGetNewMenuID(menuPtr->interp, menuPtr, 0, &menuID);
if (error != TCL_OK) {
return error;
}
err = CreateNewMenu(menuID, kMenuAttrDoNotUseUserCommandKeys, &macMenuHdl);
if (err != noErr) {
- Tcl_AppendResult(menuPtr->interp, "CreateNewMenu failed.", NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(menuPtr->interp, "CreateNewMenu failed.",
+ (char *) NULL);
+ return TCL_ERROR;
}
cfStr = CFStringCreateWithCString(NULL, Tk_PathName(menuPtr->tkwin),
- kCFStringEncodingUTF8);
+ kCFStringEncodingUTF8);
if (!cfStr) {
- Tcl_AppendResult(menuPtr->interp, "CFStringCreateWithCString failed.",
- NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(menuPtr->interp, "CFStringCreateWithCString failed.",
+ (char *) NULL);
+ return TCL_ERROR;
}
err = SetMenuTitleWithCFString(macMenuHdl, cfStr);
CFRelease(cfStr);
if (err != noErr) {
- Tcl_AppendResult(menuPtr->interp, "SetMenuTitleWithCFString failed.",
- NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(menuPtr->interp, "SetMenuTitleWithCFString failed.",
+ (char *) NULL);
+ return TCL_ERROR;
}
-
+
/*
- * Check whether we want to use the custom mdef or not. For now the
- * default is to use it unless the variable is explicitly set to no.
+ * Check whether we want to use the custom mdef or not. For now
+ * the default is to use it unless the variable is explicitly
+ * set to no.
*/
-
- useMDEFObjPtr = Tcl_ObjGetVar2(menuPtr->interp, useMDEFVar, NULL,
- TCL_GLOBAL_ONLY);
- if (useMDEFObjPtr == NULL ||
- Tcl_GetBooleanFromObj(NULL, useMDEFObjPtr, &useMDEF) == TCL_ERROR
- || useMDEF) {
- menuDefSpec.defType = kMenuDefProcPtr;
- menuDefSpec.u.defProc = MenuDefProc;
- err = SetMenuDefinition(macMenuHdl, &menuDefSpec);
- LOG_ON_ERROR(SetMenuDefinition);
+
+ useMDEFObjPtr = Tcl_ObjGetVar2(menuPtr->interp, useMDEFVar, NULL, TCL_GLOBAL_ONLY);
+ if (useMDEFObjPtr == NULL
+ || Tcl_GetBooleanFromObj(NULL, useMDEFObjPtr, &useMDEF) == TCL_ERROR
+ || useMDEF) {
+ menuDefSpec.defType = kMenuDefProcPtr;
+ menuDefSpec.u.defProc = MenuDefProc;
+ if ((err = SetMenuDefinition(macMenuHdl, &menuDefSpec)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr, "SetMenuDefinition failed %d\n", (int) err);
+#endif
+ }
}
menuPtr->platformData = (TkMenuPlatformData) ckalloc(sizeof(MacMenu));
((MacMenu *) menuPtr->platformData)->menuHdl = macMenuHdl;
@@ -573,7 +611,7 @@ TkpNewMenu(
if ((currentMenuBarInterp == menuPtr->interp)
&& (currentMenuBarName != NULL)) {
Tk_Window parentWin = Tk_Parent(menuPtr->tkwin);
-
+
if (strcmp(currentMenuBarName, Tk_PathName(parentWin)) == 0) {
if ((strcmp(Tk_PathName(menuPtr->tkwin)
+ strlen(Tk_PathName(parentWin)), ".apple") == 0)
@@ -583,10 +621,10 @@ TkpNewMenu(
Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL);
menuBarFlags |= MENUBAR_REDRAW_PENDING;
}
- }
+ }
}
}
-
+
menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr);
return TCL_OK;
@@ -620,12 +658,12 @@ TkpDestroyMenu(
}
if (GetMenuID(macMenuHdl) == currentHelpMenuID) {
MenuRef helpMenuHdl;
- MenuItemIndex helpIndex;
-
- if ((HMGetHelpMenu(&helpMenuHdl,&helpIndex) == noErr)
+ MenuItemIndex helpIndex;
+
+ if ((HMGetHelpMenu(&helpMenuHdl,&helpIndex) == noErr)
&& (helpMenuHdl != NULL)) {
int i, count = CountMenuItems(helpMenuHdl);
-
+
for (i = helpIndex; i <= count; i++) {
DeleteMenuItem(helpMenuHdl, helpIndex);
}
@@ -633,12 +671,12 @@ TkpDestroyMenu(
currentHelpMenuID = 0;
}
if (menuPtr->platformData != NULL) {
- MenuID menuID = GetMenuID(macMenuHdl);
-
- DeleteMenu(menuID);
- TkMacOSXFreeMenuID(menuID);
- DisposeMenu(macMenuHdl);
- ckfree((char *) menuPtr->platformData);
+ MenuID menuID;
+ menuID = GetMenuID(macMenuHdl);
+ DeleteMenu(menuID);
+ TkMacOSXFreeMenuID(menuID);
+ DisposeMenu(macMenuHdl);
+ ckfree((char *) menuPtr->platformData);
menuPtr->platformData = NULL;
}
}
@@ -668,7 +706,6 @@ SetMenuCascade(
MenuHandle macMenuHdl = ((MacMenu *) menuPtr->platformData)->menuHdl;
MenuID newMenuID, menuID = GetMenuID(macMenuHdl);
int error = TCL_OK;
-
if (menuID >= 256) {
error = TkMacOSXGetNewMenuID(menuPtr->interp, menuPtr, 1, &newMenuID);
if (error == TCL_OK) {
@@ -697,12 +734,13 @@ SetMenuCascade(
void
TkpDestroyMenuEntry(
- TkMenuEntry *mePtr) /* The common structure for the menu entry. */
+ TkMenuEntry *mePtr) /* The common structure for the menu
+ * entry. */
{
- TkMenu *menuPtr = mePtr->menuPtr;
-
+ TkMenu *menuPtr = mePtr->menuPtr;
+
ckfree((char *) mePtr->platformEntryData);
- if ((menuPtr->platformData != NULL)
+ if ((menuPtr->platformData != NULL)
&& !(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) {
menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr);
@@ -715,9 +753,9 @@ TkpDestroyMenuEntry(
* GetEntryText --
*
* Given a menu entry, gives back the text that should go in it.
- * Separators should be done by the caller, as they have to be handled
- * specially. This is primarily used to do a substitution between "..."
- * and the ellipsis character which looks nicer.
+ * Separators should be done by the caller, as they have to be
+ * handled specially. This is primarily used to do a substitution
+ * between "..." and the ellipsis character which looks nicer.
*
* Results:
* itemText points to the new text for the item.
@@ -731,8 +769,8 @@ TkpDestroyMenuEntry(
static void
GetEntryText(
TkMenuEntry *mePtr, /* A pointer to the menu entry. */
- Tcl_DString *dStringPtr) /* The DString to put the text into. This will
- * be initialized by this routine. */
+ Tcl_DString *dStringPtr) /* The DString to put the text into. This
+ * will be initialized by this routine. */
{
Tcl_DStringInit(dStringPtr);
if (mePtr->type == TEAROFF_ENTRY) {
@@ -775,12 +813,12 @@ GetEntryText(
*
* FindMarkCharacter --
*
- * Finds the Macintosh mark character based on the font of the item. We
- * calculate a good mark character based on the font that this item is
- * rendered in.
+ * Finds the Macintosh mark character based on the font of the
+ * item. We calculate a good mark character based on the font
+ * that this item is rendered in.
*
- * We try the following special mac characters. If none of them are
- * present, just use the check mark.
+ * We try the following special mac characters. If none of them
+ * are present, just use the check mark.
* '' - Check mark character (\022)
* 'Â¥' - Mac Bullet character (\245)
* '' - Filled diamond (\023)
@@ -808,7 +846,7 @@ FindMarkCharacter(
tkfont = Tk_GetFontFromObj(mePtr->menuPtr->tkwin,
(mePtr->fontPtr == NULL) ? mePtr->menuPtr->fontPtr
: mePtr->fontPtr);
-
+
if (!TkMacOSXIsCharacterMissing(tkfont, '\022')) {
markChar = '\022'; /* Check mark */
} else if (!TkMacOSXIsCharacterMissing(tkfont, '\245')) {
@@ -833,8 +871,8 @@ FindMarkCharacter(
* SetMenuTitle --
*
* Sets title of menu so that the text displays correctly in menubar.
- * This code directly manipulates menu handle data. This code was
- * originally part of an ancient Apple Developer Response mail.
+ * This code directly manipulates menu handle data. This code
+ * was originally part of an ancient Apple Developer Response mail.
*
* Results:
* None.
@@ -849,20 +887,18 @@ FindMarkCharacter(
static void
mySetMenuTitle(
MenuRef menuHdl, /* The menu we are setting the title of. */
- Tcl_Obj *titlePtr) /* The C string to set the title to. */
+ Tcl_Obj *titlePtr) /* The C string to set the title to. */
{
- char *title = (titlePtr == NULL) ? "" : Tcl_GetString(titlePtr);
- CFStringRef cf = CFStringCreateWithCString(NULL, title,
- kCFStringEncodingUTF8);
+ char *title = (titlePtr == NULL) ? ""
+ : Tcl_GetStringFromObj(titlePtr, NULL);
+ CFStringRef cf = CFStringCreateWithCString(NULL,
+ title, kCFStringEncodingUTF8);
SetMenuTitleWithCFString(menuHdl, cf);
CFRelease(cf);
}
-
-static int
-ParseAccelerators(
- char **accelStringPtr)
-{
+
+static int ParseAccelerators(char **accelStringPtr) {
char *accelString = *accelStringPtr;
int flags = 0;
while (1) {
@@ -918,91 +954,95 @@ ParseAccelerators(
* Processes configurations for menu entries.
*
* Results:
- * Returns standard TCL result. If TCL_ERROR is returned, then the
- * interp's result contains an error message.
+ * Returns standard TCL result. If TCL_ERROR is returned, then
+ * the interp's result contains an error message.
*
* Side effects:
- * Configuration information get set for mePtr; old resources get freed,
- * if any need it.
+ * Configuration information get set for mePtr; old resources
+ * get freed, if any need it.
*
*----------------------------------------------------------------------
*/
int
TkpConfigureMenuEntry(
- TkMenuEntry *mePtr) /* Information about menu entry; may or may
- * not already have values for some fields. */
+ TkMenuEntry *mePtr) /* Information about menu entry; may
+ * or may not already have values for
+ * some fields. */
{
TkMenu *menuPtr = mePtr->menuPtr;
-#if 0 /* Unused */
+#if 0 /* Unused */
int index = mePtr->index;
MenuHandle macMenuHdl = ((MacMenu *) menuPtr->platformData)->menuHdl;
MenuHandle helpMenuHdl = NULL;
#endif
/*
- * Cascade menus have to have menu IDs of less than 256. So we need to
- * change the child menu if this has been configured for a cascade item.
+ * Cascade menus have to have menu IDs of less than 256. So
+ * we need to change the child menu if this has been configured
+ * for a cascade item.
*/
-
+
if (mePtr->type == CASCADE_ENTRY) {
if ((mePtr->childMenuRefPtr != NULL)
&& (mePtr->childMenuRefPtr->menuPtr != NULL)) {
MenuHandle childMenuHdl = ((MacMenu *) mePtr
->childMenuRefPtr->menuPtr->platformData)->menuHdl;
-
+
if (childMenuHdl != NULL) {
int error = SetMenuCascade(mePtr->childMenuRefPtr->menuPtr);
-
+
if (error != TCL_OK) {
return error;
}
-
+
if (menuPtr->menuType == MENUBAR) {
mySetMenuTitle(childMenuHdl, mePtr->labelPtr);
}
}
}
}
-
+
/*
- * We need to parse the accelerator string. If it has the strings for
- * Command, Control, Shift or Option, we need to flag it so we can draw
- * the symbols for it. We also need to precalcuate the position of the
- * first real character we are drawing.
+ * We need to parse the accelerator string. If it has the strings
+ * for Command, Control, Shift or Option, we need to flag it
+ * so we can draw the symbols for it. We also need to precalcuate
+ * the position of the first real character we are drawing.
*/
-
+
if (0 == mePtr->accelLength) {
((EntryGeometry *)mePtr->platformEntryData)->accelTextStart = -1;
} else {
char *accelString = (mePtr->accelPtr == NULL) ? ""
- : Tcl_GetString(mePtr->accelPtr);
+ : Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
char *accel = accelString;
mePtr->entryFlags &= ~ENTRY_ACCEL_MASK;
-
+
mePtr->entryFlags |= ParseAccelerators(&accelString);
-
- ((EntryGeometry *)mePtr->platformEntryData)->accelTextStart
+
+ ((EntryGeometry *)mePtr->platformEntryData)->accelTextStart
= ((long) accelString - (long) accel);
}
-
+
if (!(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) {
menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr);
}
-
+
return TCL_OK;
}
+
/*
*----------------------------------------------------------------------
*
* ReconfigureIndividualMenu --
*
- * This routine redoes the guts of the menu. It works from a base item
- * and offset, so that a regular menu will just have all of its items
- * added, but the help menu will have all of its items appended after the
- * apple-defined items.
+ * This routine redoes the guts of the menu. It works from
+ * a base item and offset, so that a regular menu will
+ * just have all of its items added, but the help menu will
+ * have all of its items appended after the apple-defined
+ * items.
*
* Results:
* None.
@@ -1016,12 +1056,14 @@ TkpConfigureMenuEntry(
static void
ReconfigureIndividualMenu(
TkMenu *menuPtr, /* The menu we are affecting. */
- MenuHandle macMenuHdl, /* The macintosh menu we are affecting. Will
- * not necessarily be menuPtr->platformData
- * because this could be the help menu. */
+ MenuHandle macMenuHdl, /* The macintosh menu we are affecting.
+ * Will not necessarily be
+ * menuPtr->platformData because this could
+ * be the help menu. */
int base) /* The last index that we do not want
- * touched. 0 for normal menus; # of system
- * help menu items * for help menus. */
+ * touched. 0 for normal menus;
+ * # of system help menu items
+ * for help menus. */
{
int count;
int index;
@@ -1030,17 +1072,17 @@ ReconfigureIndividualMenu(
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_MENUS)
/* Carbon-internal menu debugging (c.f. Technote 2124) */
- TkMacOSXInitNamedDebugSymbol(HIToolbox,void,DebugPrintMenu,MenuRef menu);
+ TkMacOSXInitNamedDebugSymbol(HIToolbox, void, DebugPrintMenu, MenuRef menu);
if (DebugPrintMenu) {
- DebugPrintMenu(macMenuHdl);
+ DebugPrintMenu(macMenuHdl);
}
#endif
for (mePtr = menuPtr->menuRefPtr->parentEntryPtr; mePtr != NULL;
mePtr = mePtr->nextCascadePtr) {
char *name = (mePtr->namePtr == NULL) ? ""
- : Tcl_GetString(mePtr->namePtr);
-
+ : Tcl_GetStringFromObj(mePtr->namePtr, NULL);
+
if (strcmp(Tk_PathName(menuPtr->tkwin), name) == 0) {
if (mePtr->state == ENTRY_DISABLED) {
parentDisabled = 1;
@@ -1048,45 +1090,45 @@ ReconfigureIndividualMenu(
break;
}
}
-
+
/*
* First, we get rid of all of the old items.
*/
-
+
count = CountMenuItems(macMenuHdl);
for (index = base; index < count; index++) {
DeleteMenuItem(macMenuHdl, base + 1);
}
count = menuPtr->numEntries;
-
+
for (index = 1; index <= count; index++) {
mePtr = menuPtr->entries[index - 1];
-
+
/*
- * We have to do separators separately because SetMenuItemText does
- * not parse meta-characters.
+ * We have to do separators separately because SetMenuItemText
+ * does not parse meta-characters.
*/
-
+
if (mePtr->type == SEPARATOR_ENTRY) {
- AppendMenuItemTextWithCFString (macMenuHdl, NULL,
- kMenuItemAttrSeparator | kMenuItemAttrDisabled, 0, NULL);
+ AppendMenuItemTextWithCFString (macMenuHdl, NULL,
+ kMenuItemAttrSeparator | kMenuItemAttrDisabled,
+ 0, NULL);
} else {
Tcl_DString itemTextDString;
- CFStringRef cf;
-
+ CFStringRef cf;
GetEntryText(mePtr, &itemTextDString);
- cf = CFStringCreateWithCString(NULL,
- Tcl_DStringValue(&itemTextDString),kCFStringEncodingUTF8);
+ cf = CFStringCreateWithCString(NULL,
+ Tcl_DStringValue(&itemTextDString), kCFStringEncodingUTF8);
if (cf != NULL) {
- AppendMenuItemTextWithCFString (macMenuHdl, cf, 0, 0, NULL);
- CFRelease(cf);
+ AppendMenuItemTextWithCFString (macMenuHdl, cf, 0, 0, NULL);
+ CFRelease(cf);
} else {
- cf = CFSTR ("<Error>");
- AppendMenuItemTextWithCFString (macMenuHdl, cf, 0, 0, NULL);
+ cf = CFSTR ("<Error>");
+ AppendMenuItemTextWithCFString (macMenuHdl, cf, 0, 0, NULL);
}
Tcl_DStringFree(&itemTextDString);
-
+
/*
* Set enabling and disabling correctly.
*/
@@ -1096,60 +1138,61 @@ ReconfigureIndividualMenu(
} else {
EnableMenuItem(macMenuHdl, base + index);
}
-
+
/*
* Set the check mark for check entries and radio entries.
*/
-
- SetItemMark(macMenuHdl, base + index, 0);
+
+ SetItemMark(macMenuHdl, base + index, 0);
if ((mePtr->type == CHECK_BUTTON_ENTRY)
|| (mePtr->type == RADIO_BUTTON_ENTRY)) {
- CheckMenuItem(macMenuHdl, base + index, mePtr->indicatorOn
- && (mePtr->entryFlags & ENTRY_SELECTED));
+ CheckMenuItem(macMenuHdl, base + index, (mePtr->entryFlags
+ & ENTRY_SELECTED) && mePtr->indicatorOn);
if (mePtr->indicatorOn
&& (mePtr->entryFlags & ENTRY_SELECTED)) {
SetItemMark(macMenuHdl, base + index,
FindMarkCharacter(mePtr));
}
}
-
+
if (mePtr->type == CASCADE_ENTRY) {
- if ((mePtr->childMenuRefPtr != NULL)
+ if ((mePtr->childMenuRefPtr != NULL)
&& (mePtr->childMenuRefPtr->menuPtr != NULL)) {
- MenuHandle childMenuHdl =
+ MenuHandle childMenuHdl =
((MacMenu *) mePtr->childMenuRefPtr
->menuPtr->platformData)->menuHdl;
if (childMenuHdl != NULL) {
- SetMenuItemHierarchicalID(macMenuHdl, base + index,
- GetMenuID(childMenuHdl));
+ {
+ SetMenuItemHierarchicalID(macMenuHdl, base + index,
+ GetMenuID(childMenuHdl));
+ }
}
-
/*
* If we changed the highligthing of this menu, its
- * children all have to be reconfigured so that their
- * state will be reflected in the menubar.
+ * children all have to be reconfigured so that
+ * their state will be reflected in the menubar.
*/
-
- if (!(mePtr->childMenuRefPtr->menuPtr->menuFlags
+
+ if (!(mePtr->childMenuRefPtr->menuPtr->menuFlags
& MENU_RECONFIGURE_PENDING)) {
mePtr->childMenuRefPtr->menuPtr->menuFlags
|= MENU_RECONFIGURE_PENDING;
- Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
+ Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
(ClientData) mePtr->childMenuRefPtr->menuPtr);
}
}
}
-
+
if ((mePtr->type != CASCADE_ENTRY) && (mePtr->accelPtr != NULL)) {
- int accelLen, modifiers = 0, hasCmd = 0;
- int offset = ((EntryGeometry *)
- mePtr->platformEntryData)->accelTextStart;
- char *accel = Tcl_GetStringFromObj(mePtr->accelPtr,&accelLen);
-
- accelLen -= offset;
+ int accelLen;
+ int modifiers = 0;
+ int hasCmd = 0;
+ int offset = ((EntryGeometry *)mePtr->platformEntryData)->accelTextStart;
+ char *accel = Tcl_GetStringFromObj(mePtr->accelPtr, &accelLen);
+ accelLen -= offset;
accel+= offset;
-
+
if (mePtr->entryFlags & ENTRY_OPTION_ACCEL) {
modifiers |= kMenuOptionModifier;
}
@@ -1162,75 +1205,71 @@ ReconfigureIndividualMenu(
if (mePtr->entryFlags & ENTRY_COMMAND_ACCEL) {
hasCmd = 1;
}
- if (accelLen == 1) {
- if (hasCmd || (modifiers != 0
- && modifiers != kMenuShiftModifier)) {
- SetItemCmd(macMenuHdl, base + index, accel[0]);
+ if (accelLen == 1) {
+ if (hasCmd || (modifiers != 0 && modifiers != kMenuShiftModifier)) {
+ SetItemCmd(macMenuHdl, base + index, accel[0]);
if (!hasCmd) {
modifiers |= kMenuNoCommandModifier;
}
}
- } else {
- /*
- * Now we need to convert from various textual names to
- * Carbon codes.
+ } else {
+ /*
+ * Now we need to convert from various textual names
+ * to Carbon codes
*/
-
char glyph = 0x0;
- char first = UCHAR(accel[0]);
-
+ char first = UCHAR(accel[0]);
if (first == 'F' && (accel[1] > '0' && accel[1] <= '9')) {
int fkey = accel[1] - '0';
-
if (accel[2] > '0' && accel[2] <= '9') {
fkey = 10*fkey + (accel[2] - '0');
}
if (fkey > 0 && fkey < 16) {
glyph = kMenuF1Glyph + fkey - 1;
}
- } else if (first == 'P' && !strcasecmp(accel,"pageup")) {
- glyph = kMenuPageUpGlyph;
- } else if (first == 'P' && !strcasecmp(accel,"pagedown")) {
- glyph = kMenuPageDownGlyph;
- } else if (first == 'L' && !strcasecmp(accel,"left")) {
- glyph = kMenuLeftArrowGlyph;
- } else if (first == 'R' && !strcasecmp(accel,"right")) {
- glyph = kMenuRightArrowGlyph;
- } else if (first == 'U' && !strcasecmp(accel,"up")) {
- glyph = kMenuUpArrowGlyph;
- } else if (first == 'D' && !strcasecmp(accel,"down")) {
- glyph = kMenuDownArrowGlyph;
- } else if (first == 'E' && !strcasecmp(accel,"escape")) {
- glyph = kMenuEscapeGlyph;
- } else if (first == 'C' && !strcasecmp(accel,"clear")) {
- glyph = kMenuClearGlyph;
- } else if (first == 'E' && !strcasecmp(accel,"enter")) {
- glyph = kMenuEnterGlyph;
- } else if (first == 'D' && !strcasecmp(accel,"backspace")){
- glyph = kMenuDeleteLeftGlyph;
- } else if (first == 'S' && !strcasecmp(accel,"space")) {
- glyph = kMenuSpaceGlyph;
- } else if (first == 'T' && !strcasecmp(accel,"tab")) {
- glyph = kMenuTabRightGlyph;
- } else if (first == 'F' && !strcasecmp(accel,"delete")) {
- glyph = kMenuDeleteRightGlyph;
- } else if (first == 'H' && !strcasecmp(accel,"home")) {
- glyph = kMenuNorthwestArrowGlyph;
- } else if (first == 'R' && !strcasecmp(accel,"return")) {
- glyph = kMenuReturnGlyph;
- } else if (first == 'H' && !strcasecmp(accel,"help")) {
- glyph = kMenuHelpGlyph;
- } else if (first == 'P' && !strcasecmp(accel,"power")) {
- glyph = kMenuPowerGlyph;
- }
+ } else if (first == 'P' && 0 ==strcasecmp(accel,"pageup")) {
+ glyph = kMenuPageUpGlyph;
+ } else if (first == 'P' && 0 ==strcasecmp(accel,"pagedown")) {
+ glyph = kMenuPageDownGlyph;
+ } else if (first == 'L' && 0 ==strcasecmp(accel,"left")) {
+ glyph = kMenuLeftArrowGlyph;
+ } else if (first == 'R' && 0 ==strcasecmp(accel,"right")) {
+ glyph = kMenuRightArrowGlyph;
+ } else if (first == 'U' && 0 ==strcasecmp(accel,"up")) {
+ glyph = kMenuUpArrowGlyph;
+ } else if (first == 'D' && 0 ==strcasecmp(accel,"down")) {
+ glyph = kMenuDownArrowGlyph;
+ } else if (first == 'E' && 0 ==strcasecmp(accel,"escape")) {
+ glyph = kMenuEscapeGlyph;
+ } else if (first == 'C' && 0 ==strcasecmp(accel,"clear")) {
+ glyph = kMenuClearGlyph;
+ } else if (first == 'E' && 0 ==strcasecmp(accel,"enter")) {
+ glyph = kMenuEnterGlyph;
+ } else if (first == 'D' && 0 ==strcasecmp(accel,"backspace")) {
+ glyph = kMenuDeleteLeftGlyph;
+ } else if (first == 'S' && 0 ==strcasecmp(accel,"space")) {
+ glyph = kMenuSpaceGlyph;
+ } else if (first == 'T' && 0 ==strcasecmp(accel,"tab")) {
+ glyph = kMenuTabRightGlyph;
+ } else if (first == 'F' && 0 ==strcasecmp(accel,"delete")) {
+ glyph = kMenuDeleteRightGlyph;
+ } else if (first == 'H' && 0 ==strcasecmp(accel,"home")) {
+ glyph = kMenuNorthwestArrowGlyph;
+ } else if (first == 'R' && 0 ==strcasecmp(accel,"return")) {
+ glyph = kMenuReturnGlyph;
+ } else if (first == 'H' && 0 ==strcasecmp(accel,"help")) {
+ glyph = kMenuHelpGlyph;
+ } else if (first == 'P' && 0 ==strcasecmp(accel,"power")) {
+ glyph = kMenuPowerGlyph;
+ }
if (glyph != 0x0) {
SetMenuItemKeyGlyph(macMenuHdl, base + index, glyph);
if (!hasCmd) {
modifiers |= kMenuNoCommandModifier;
}
}
- }
-
+ }
+
SetMenuItemModifiers(macMenuHdl, base + index, modifiers);
}
}
@@ -1242,24 +1281,25 @@ ReconfigureIndividualMenu(
*
* ReconfigureMacintoshMenu --
*
- * Rebuilds the Macintosh MenuHandle items from the menu. Called usually
- * as an idle handler, but can be called synchronously if the menu is
- * about to be posted.
+ * Rebuilds the Macintosh MenuHandle items from the menu. Called
+ * usually as an idle handler, but can be called synchronously
+ * if the menu is about to be posted.
*
* Results:
* None.
*
* Side effects:
- * Configuration information get set for mePtr; old resources get freed,
- * if any need it.
+ * Configuration information get set for mePtr; old resources
+ * get freed, if any need it.
*
*----------------------------------------------------------------------
*/
static void
ReconfigureMacintoshMenu(
- ClientData clientData) /* Information about menu entry; may or may
- * not already have values for some fields. */
+ ClientData clientData) /* Information about menu entry; may
+ * or may not already have values for
+ * some fields. */
{
TkMenu *menuPtr = (TkMenu *) clientData;
MenuHandle macMenuHdl = ((MacMenu *) menuPtr->platformData)->menuHdl;
@@ -1279,16 +1319,16 @@ ReconfigureMacintoshMenu(
}
*/
if (GetMenuID(macMenuHdl) == currentHelpMenuID) {
- MenuItemIndex helpIndex;
-
- HMGetHelpMenu(&helpMenuHdl, &helpIndex);
+ MenuItemIndex helpIndex;
+ HMGetHelpMenu(&helpMenuHdl,&helpIndex);
if (helpMenuHdl != NULL) {
- ReconfigureIndividualMenu(menuPtr, helpMenuHdl, helpIndex - 1);
+ ReconfigureIndividualMenu(menuPtr, helpMenuHdl,
+ helpIndex - 1);
}
}
if (menuPtr->menuType == MENUBAR) {
- if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) {
+ if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) {
Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL);
menuBarFlags |= MENUBAR_REDRAW_PENDING;
}
@@ -1300,8 +1340,8 @@ ReconfigureMacintoshMenu(
*
* CompleteIdlers --
*
- * Completes all idle handling so that the menus are in sync when the
- * user invokes them with the mouse.
+ * Completes all idle handling so that the menus are in sync when
+ * the user invokes them with the mouse.
*
* Results:
* None.
@@ -1314,7 +1354,7 @@ ReconfigureMacintoshMenu(
static void
CompleteIdlers(
- TkMenu *menuPtr) /* The menu we are completing. */
+ TkMenu *menuPtr) /* The menu we are completing. */
{
int i;
@@ -1322,13 +1362,16 @@ CompleteIdlers(
Tcl_CancelIdleCall(ReconfigureMacintoshMenu, (ClientData) menuPtr);
ReconfigureMacintoshMenu((ClientData) menuPtr);
}
-
+
for (i = 0; i < menuPtr->numEntries; i++) {
- if ((menuPtr->entries[i]->type == CASCADE_ENTRY) &&
- (menuPtr->entries[i]->childMenuRefPtr != NULL) &&
- (menuPtr->entries[i]->childMenuRefPtr->menuPtr != NULL)) {
- CompleteIdlers(menuPtr->entries[i]->childMenuRefPtr->menuPtr);
- }
+ if (menuPtr->entries[i]->type == CASCADE_ENTRY) {
+ if ((menuPtr->entries[i]->childMenuRefPtr != NULL)
+ && (menuPtr->entries[i]->childMenuRefPtr->menuPtr
+ != NULL)) {
+ CompleteIdlers(menuPtr->entries[i]->childMenuRefPtr
+ ->menuPtr);
+ }
+ }
}
}
@@ -1359,20 +1402,22 @@ TkpPostMenu(
{
MenuHandle macMenuHdl = ((MacMenu *) menuPtr->platformData)->menuHdl;
long popUpResult;
- int result, oldMode;
+ int result;
+ int oldMode;
if (inPostMenu) {
- Tcl_AppendResult(interp,
- "Cannot call post menu while already posting menu", NULL);
+ Tcl_AppendResult(interp,
+ "Cannot call post menu while already posting menu",
+ (char *) NULL);
result = TCL_ERROR;
} else {
short menuID;
Window window;
int oldWidth = menuPtr->totalWidth;
Tk_Window parentWindow = Tk_Parent(menuPtr->tkwin);
-
+
inPostMenu++;
-
+
result = TkPreprocessMenu(menuPtr);
if (result != TCL_OK) {
inPostMenu--;
@@ -1380,10 +1425,10 @@ TkpPostMenu(
}
/*
- * The post commands could have deleted the menu, which means we are
- * dead and should go away.
+ * The post commands could have deleted the menu, which means
+ * we are dead and should go away.
*/
-
+
if (menuPtr->tkwin == NULL) {
inPostMenu--;
return TCL_OK;
@@ -1393,15 +1438,15 @@ TkpPostMenu(
if (menuBarFlags & MENUBAR_REDRAW_PENDING) {
Tcl_CancelIdleCall(DrawMenuBarWhenIdle, (ClientData *) NULL);
DrawMenuBarWhenIdle((ClientData *) NULL);
- }
-
+ }
+
if (NULL == parentWindow) {
tearoffStruct.excludeRect.top = tearoffStruct.excludeRect.left
= tearoffStruct.excludeRect.bottom
= tearoffStruct.excludeRect.right = SHRT_MAX;
} else {
int left, top;
-
+
Tk_GetRootCoords(parentWindow, &left, &top);
tearoffStruct.excludeRect.left = left;
tearoffStruct.excludeRect.top = top;
@@ -1409,20 +1454,19 @@ TkpPostMenu(
tearoffStruct.excludeRect.bottom = top + Tk_Height(parentWindow);
if (Tk_Class(parentWindow) == Tk_GetUid("Menubutton")) {
TkWindow *parentWinPtr = (TkWindow *) parentWindow;
- TkMenuButton *mbPtr = (TkMenuButton *)
- parentWinPtr->instanceData;
+ TkMenuButton *mbPtr =
+ (TkMenuButton *) parentWinPtr->instanceData;
int menuButtonWidth = Tk_Width(parentWindow)
- 2 * (mbPtr->highlightWidth + mbPtr->borderWidth + 1);
-
menuPtr->totalWidth = menuButtonWidth > menuPtr->totalWidth
? menuButtonWidth : menuPtr->totalWidth;
}
}
-
+
InsertMenu(macMenuHdl, -1);
RecursivelyInsertMenu(menuPtr);
CountMenuItems(macMenuHdl);
-
+
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
popUpResult = PopUpMenuSelect(macMenuHdl, y, x, menuPtr->active);
Tcl_SetServiceMode(oldMode);
@@ -1430,18 +1474,18 @@ TkpPostMenu(
menuPtr->totalWidth = oldWidth;
RecursivelyDeleteMenu(menuPtr);
DeleteMenu(GetMenuID(macMenuHdl));
-
+
/*
* Simulate the mouse up.
*/
-
+
window = Tk_WindowId(menuPtr->tkwin);
TkGenerateButtonEventForXPointer(window);
-
+
/*
* Dispatch the command.
*/
-
+
menuID = HiWord(popUpResult);
if (menuID != 0) {
result = TkMacOSXDispatchMenuEvent(menuID, LoWord(popUpResult));
@@ -1450,15 +1494,15 @@ TkpPostMenu(
result = TCL_OK;
}
- /*
- * Be careful, here. The command executed in handling the menu event
- * could destroy the window. Don't try to do anything with it then.
- */
-
- if (menuPtr->tkwin) {
+ /*
+ * Be careful, here. The command executed in handling the menu event
+ * could destroy the window. Don't try to do anything with it then.
+ */
+
+ if (menuPtr->tkwin) {
InvalidateMDEFRgns();
RecursivelyClearActiveMenu(menuPtr);
- }
+ }
inPostMenu--;
}
return result;
@@ -1470,8 +1514,9 @@ TkpPostMenu(
* TkpMenuNewEntry --
*
* Adds a pointer to a new menu entry structure with the platform-
- * specific fields filled in. The Macintosh uses the platformEntryData
- * field of the TkMenuEntry record to store geometry information.
+ * specific fields filled in. The Macintosh uses the
+ * platformEntryData field of the TkMenuEntry record to store
+ * geometry information.
*
* Results:
* Standard TCL error.
@@ -1490,7 +1535,7 @@ TkpMenuNewEntry(
EntryGeometry *geometryPtr =
(EntryGeometry *) ckalloc(sizeof(EntryGeometry));
TkMenu *menuPtr = mePtr->menuPtr;
-
+
geometryPtr->accelTextStart = 0;
geometryPtr->accelTextWidth = 0;
geometryPtr->nonAccelMargin = 0;
@@ -1506,11 +1551,12 @@ TkpMenuNewEntry(
/*
*----------------------------------------------------------------------
*
+ *
* Tk_MacOSXTurnOffMenus --
*
- * Turns off all the menu drawing code. This is more than just disabling
- * the "menu" command, this means that Tk will NEVER touch the menubar.
- * It is needed in the Plugin, where Tk does not own the menubar.
+ * Turns off all the menu drawing code. This is more than just disabling
+ * the "menu" command, this means that Tk will NEVER touch the menubar.
+ * It is needed in the Plugin, where Tk does not own the menubar.
*
* Results:
* None.
@@ -1522,7 +1568,7 @@ TkpMenuNewEntry(
*/
void
-Tk_MacOSXTurnOffMenus(void)
+Tk_MacOSXTurnOffMenus()
{
gNoTkMenus = 1;
}
@@ -1530,6 +1576,7 @@ Tk_MacOSXTurnOffMenus(void)
/*
*----------------------------------------------------------------------
*
+ *
* DrawMenuBarWhenIdle --
*
* Update the menu bar next time there is an idle event.
@@ -1551,19 +1598,19 @@ DrawMenuBarWhenIdle(
TkMenu *appleMenuPtr, *helpMenuPtr;
MenuHandle macMenuHdl;
Tcl_HashEntry *hashEntryPtr;
-
+
/*
* If we have been turned off, exit.
*/
-
+
if (gNoTkMenus) {
- return;
+ return;
}
-
+
/*
* We need to clear the apple and help menus of any extra items.
*/
-
+
if (currentAppleMenuID != 0) {
hashEntryPtr = Tcl_FindHashEntry(&commandTable,
(char *) ((int)currentAppleMenuID));
@@ -1572,7 +1619,8 @@ DrawMenuBarWhenIdle(
TkpNewMenu(appleMenuPtr);
appleMenuPtr->menuFlags &= ~MENU_APPLE_MENU;
appleMenuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
- Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) appleMenuPtr);
+ Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
+ (ClientData) appleMenuPtr);
}
if (currentHelpMenuID != 0) {
@@ -1586,11 +1634,12 @@ DrawMenuBarWhenIdle(
Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
(ClientData) helpMenuPtr);
}
-
+
/*
- * We need to find the clone of this menu that is the menubar. Once we do
- * that, for every cascade in the menu, we need to insert the Mac menu in
- * the Mac menubar. Finally, we need to redraw the menubar.
+ * We need to find the clone of this menu that is the menubar.
+ * Once we do that, for every cascade in the menu, we need to
+ * insert the Mac menu in the Mac menubar. Finally, we need
+ * to redraw the menubar.
*/
menuRefPtr = NULL;
@@ -1601,163 +1650,188 @@ DrawMenuBarWhenIdle(
if (menuRefPtr != NULL) {
TkMenu *menuPtr, *menuBarPtr;
TkMenu *cascadeMenuPtr;
- char *appleMenuName, *helpMenuName;
- int appleIndex = -1, helpIndex = -1, i;
-
- menuPtr = menuRefPtr->menuPtr;
- if (menuPtr != NULL) {
- TkMenuReferences *specialMenuRefPtr;
- TkMenuEntry *specialEntryPtr;
-
- appleMenuName = ckalloc(
- strlen(currentMenuBarName) + 1 + strlen(".apple") + 1);
- sprintf(appleMenuName, "%s.apple", Tk_PathName(menuPtr->tkwin));
- specialMenuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
- appleMenuName);
- if ((specialMenuRefPtr != NULL)
- && (specialMenuRefPtr->menuPtr != NULL)) {
- for (specialEntryPtr = specialMenuRefPtr->parentEntryPtr;
- specialEntryPtr != NULL;
- specialEntryPtr = specialEntryPtr->nextCascadePtr) {
+ char *appleMenuName, *helpMenuName;
+ int appleIndex = -1, helpIndex = -1;
+ int i;
+
+ menuPtr = menuRefPtr->menuPtr;
+ if (menuPtr != NULL) {
+ TkMenuReferences *specialMenuRefPtr;
+ TkMenuEntry *specialEntryPtr;
+
+ appleMenuName = ckalloc(strlen(currentMenuBarName)
+ + 1 + strlen(".apple") + 1);
+ sprintf(appleMenuName, "%s.apple",
+ Tk_PathName(menuPtr->tkwin));
+ specialMenuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
+ appleMenuName);
+ if ((specialMenuRefPtr != NULL)
+ && (specialMenuRefPtr->menuPtr != NULL)) {
+ for (specialEntryPtr
+ = specialMenuRefPtr->parentEntryPtr;
+ specialEntryPtr != NULL;
+ specialEntryPtr
+ = specialEntryPtr->nextCascadePtr) {
if (specialEntryPtr->menuPtr == menuPtr) {
appleIndex = specialEntryPtr->index;
break;
}
}
- }
- ckfree(appleMenuName);
-
- helpMenuName = ckalloc(
- strlen(currentMenuBarName) + 1 + strlen(".help") + 1);
- sprintf(helpMenuName, "%s.help", Tk_PathName(menuPtr->tkwin));
- specialMenuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
- helpMenuName);
- if ((specialMenuRefPtr != NULL)
- && (specialMenuRefPtr->menuPtr != NULL)) {
- for (specialEntryPtr = specialMenuRefPtr->parentEntryPtr;
- specialEntryPtr != NULL;
- specialEntryPtr = specialEntryPtr->nextCascadePtr) {
+ }
+ ckfree(appleMenuName);
+
+ helpMenuName = ckalloc(strlen(currentMenuBarName)
+ + 1 + strlen(".help") + 1);
+ sprintf(helpMenuName, "%s.help",
+ Tk_PathName(menuPtr->tkwin));
+ specialMenuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
+ helpMenuName);
+ if ((specialMenuRefPtr != NULL)
+ && (specialMenuRefPtr->menuPtr != NULL)) {
+ for (specialEntryPtr
+ = specialMenuRefPtr->parentEntryPtr;
+ specialEntryPtr != NULL;
+ specialEntryPtr
+ = specialEntryPtr->nextCascadePtr) {
if (specialEntryPtr->menuPtr == menuPtr) {
helpIndex = specialEntryPtr->index;
break;
}
}
}
- ckfree(helpMenuName);
- }
-
- for (menuBarPtr = menuPtr;
- (menuBarPtr != NULL) && (menuBarPtr->menuType != MENUBAR);
- menuBarPtr = menuBarPtr->nextInstancePtr) {
- /*
- * Null loop body.
- */
- }
-
- if (menuBarPtr == NULL) {
- goto setDefault;
- }
-
- if (menuBarPtr->tearoff != menuPtr->tearoff) {
- if (menuBarPtr->tearoff) {
- appleIndex = (-1 == appleIndex) ? appleIndex : appleIndex + 1;
- helpIndex = (-1 == helpIndex) ? helpIndex : helpIndex + 1;
+ ckfree(helpMenuName);
+
+ }
+
+ for (menuBarPtr = menuPtr;
+ (menuBarPtr != NULL)
+ && (menuBarPtr->menuType != MENUBAR);
+ menuBarPtr = menuBarPtr->nextInstancePtr) {
+
+ /*
+ * Null loop body.
+ */
+
+ }
+
+ if (menuBarPtr == NULL) {
+ SetDefaultMenubar();
+ } else {
+ if (menuBarPtr->tearoff != menuPtr->tearoff) {
+ if (menuBarPtr->tearoff) {
+ appleIndex = (-1 == appleIndex) ? appleIndex
+ : appleIndex + 1;
+ helpIndex = (-1 == helpIndex) ? helpIndex
+ : helpIndex + 1;
+ } else {
+ appleIndex = (-1 == appleIndex) ? appleIndex
+ : appleIndex - 1;
+ helpIndex = (-1 == helpIndex) ? helpIndex
+ : helpIndex - 1;
+ }
+ }
+ ClearMenuBar();
+
+ if (appleIndex == -1) {
+ InsertMenu(tkAppleMenu, 0);
+ currentAppleMenuID = 0;
+ tkCurrentAppleMenu = tkAppleMenu;
} else {
- appleIndex = (-1 == appleIndex) ? appleIndex : appleIndex - 1;
- helpIndex = (-1 == helpIndex) ? helpIndex : helpIndex - 1;
+ short appleID;
+ appleMenuPtr = menuBarPtr->entries[appleIndex]
+ ->childMenuRefPtr->menuPtr;
+ TkpDestroyMenu(appleMenuPtr);
+ TkMacOSXGetNewMenuID(appleMenuPtr->interp, appleMenuPtr, 0,
+ &appleID);
+ macMenuHdl = NewMenu(appleID, "\p\024");
+ appleMenuPtr->platformData =
+ (TkMenuPlatformData) ckalloc(sizeof(MacMenu));
+ ((MacMenu *)appleMenuPtr->platformData)->menuHdl
+ = macMenuHdl;
+ SetRect(&((MacMenu *) appleMenuPtr->platformData)->menuRect,
+ 0, 0, 0, 0);
+ appleMenuPtr->menuFlags |= MENU_APPLE_MENU;
+ if (!(appleMenuPtr->menuFlags
+ & MENU_RECONFIGURE_PENDING)) {
+ appleMenuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
+ Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
+ (ClientData) appleMenuPtr);
+ }
+ InsertMenu(macMenuHdl, 0);
+ RecursivelyInsertMenu(appleMenuPtr);
+ currentAppleMenuID = appleID;
+ tkCurrentAppleMenu = macMenuHdl;
}
- }
- ClearMenuBar();
-
- if (appleIndex == -1) {
- InsertMenu(tkAppleMenu, 0);
- currentAppleMenuID = 0;
- tkCurrentAppleMenu = tkAppleMenu;
- } else {
- short appleID;
- appleMenuPtr = menuBarPtr->entries[appleIndex]
- ->childMenuRefPtr->menuPtr;
- TkpDestroyMenu(appleMenuPtr);
- TkMacOSXGetNewMenuID(appleMenuPtr->interp, appleMenuPtr, 0,
- &appleID);
- macMenuHdl = NewMenu(appleID, "\p\024");
- appleMenuPtr->platformData = (TkMenuPlatformData)
- ckalloc(sizeof(MacMenu));
- ((MacMenu *)appleMenuPtr->platformData)->menuHdl = macMenuHdl;
- SetRect(&((MacMenu *) appleMenuPtr->platformData)->menuRect, 0, 0,
- 0, 0);
- appleMenuPtr->menuFlags |= MENU_APPLE_MENU;
- if (!(appleMenuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) {
- appleMenuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
- Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
- (ClientData) appleMenuPtr);
+ if (helpIndex == -1) {
+ currentHelpMenuID = 0;
}
- InsertMenu(macMenuHdl, 0);
- RecursivelyInsertMenu(appleMenuPtr);
- currentAppleMenuID = appleID;
- tkCurrentAppleMenu = macMenuHdl;
- }
- if (helpIndex == -1) {
- currentHelpMenuID = 0;
- }
-
- for (i = 0; i < menuBarPtr->numEntries; i++) {
- if (i == appleIndex) {
- if (menuBarPtr->entries[i]->state == ENTRY_DISABLED) {
- DisableMenuItem(((MacMenu *) menuBarPtr->entries[i]->
- childMenuRefPtr->menuPtr->platformData)->menuHdl,
- 0);
- } else {
- EnableMenuItem(((MacMenu *) menuBarPtr->entries[i]->
- childMenuRefPtr->menuPtr->platformData)->menuHdl,
- 0);
- }
- continue;
- } else if (i == helpIndex) {
- TkMenu *helpMenuPtr = menuBarPtr->entries[i]
- ->childMenuRefPtr->menuPtr;
-
- if (helpMenuPtr == NULL) {
- continue;
- }
- helpMenuPtr->menuFlags |= MENU_HELP_MENU;
- if (!(helpMenuPtr->menuFlags
- & MENU_RECONFIGURE_PENDING)) {
- helpMenuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;
- Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
- (ClientData) helpMenuPtr);
- }
- macMenuHdl = ((MacMenu *) helpMenuPtr->platformData)->menuHdl;
- currentHelpMenuID = GetMenuID(macMenuHdl);
- } else if (menuBarPtr->entries[i]->type == CASCADE_ENTRY) {
- if ((menuBarPtr->entries[i]->childMenuRefPtr != NULL) &&
- menuBarPtr->entries[i]->childMenuRefPtr->menuPtr) {
- cascadeMenuPtr = menuBarPtr->entries[i]
- ->childMenuRefPtr->menuPtr;
- macMenuHdl = ((MacMenu *) cascadeMenuPtr
- ->platformData)->menuHdl;
- DeleteMenu(GetMenuID(macMenuHdl));
- InsertMenu(macMenuHdl, 0);
- RecursivelyInsertMenu(cascadeMenuPtr);
- if (menuBarPtr->entries[i]->state == ENTRY_DISABLED) {
- DisableMenuItem(((MacMenu *) menuBarPtr->entries[i]
- ->childMenuRefPtr->menuPtr
- ->platformData)->menuHdl, 0);
- } else {
- EnableMenuItem(((MacMenu *) menuBarPtr->entries[i]
- ->childMenuRefPtr->menuPtr
- ->platformData)->menuHdl, 0);
+
+ for (i = 0; i < menuBarPtr->numEntries; i++) {
+ if (i == appleIndex) {
+ if (menuBarPtr->entries[i]->state == ENTRY_DISABLED) {
+ DisableMenuItem(((MacMenu *) menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr
+ ->platformData)->menuHdl,
+ 0);
+ } else {
+ EnableMenuItem(((MacMenu *) menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr
+ ->platformData)->menuHdl,
+ 0);
}
- }
+ continue;
+ } else if (i == helpIndex) {
+ TkMenu *helpMenuPtr = menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr;
+
+ if (helpMenuPtr == NULL) {
+ continue;
+ }
+ helpMenuPtr->menuFlags |= MENU_HELP_MENU;
+ if (!(helpMenuPtr->menuFlags
+ & MENU_RECONFIGURE_PENDING)) {
+ helpMenuPtr->menuFlags
+ |= MENU_RECONFIGURE_PENDING;
+ Tcl_DoWhenIdle(ReconfigureMacintoshMenu,
+ (ClientData) helpMenuPtr);
+ }
+ macMenuHdl =
+ ((MacMenu *) helpMenuPtr->platformData)->menuHdl;
+ currentHelpMenuID = GetMenuID(macMenuHdl);
+ } else if (menuBarPtr->entries[i]->type
+ == CASCADE_ENTRY) {
+ if ((menuBarPtr->entries[i]->childMenuRefPtr != NULL)
+ && menuBarPtr->entries[i]->childMenuRefPtr
+ ->menuPtr != NULL) {
+ cascadeMenuPtr = menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr;
+ macMenuHdl = ((MacMenu *) cascadeMenuPtr
+ ->platformData)->menuHdl;
+ DeleteMenu(GetMenuID(macMenuHdl));
+ InsertMenu(macMenuHdl, 0);
+ RecursivelyInsertMenu(cascadeMenuPtr);
+ if (menuBarPtr->entries[i]->state == ENTRY_DISABLED) {
+ DisableMenuItem(((MacMenu *) menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr
+ ->platformData)->menuHdl,
+ 0);
+ } else {
+ EnableMenuItem(((MacMenu *) menuBarPtr->entries[i]
+ ->childMenuRefPtr->menuPtr
+ ->platformData)->menuHdl,
+ 0);
+ }
+ }
+ }
}
}
} else {
- setDefault:
SetDefaultMenubar();
}
DrawMenuBar();
menuBarFlags &= ~MENUBAR_REDRAW_PENDING;
}
+
/*
*----------------------------------------------------------------------
@@ -1778,24 +1852,25 @@ DrawMenuBarWhenIdle(
static void
RecursivelyInsertMenu(
- TkMenu *menuPtr) /* All of the cascade items in this menu will
- * be inserted into the mac menubar. */
+ TkMenu *menuPtr) /* All of the cascade items in this menu
+ * will be inserted into the mac menubar. */
{
int i;
TkMenu *cascadeMenuPtr;
MenuHandle macMenuHdl;
-
+
for (i = 0; i < menuPtr->numEntries; i++) {
- if (menuPtr->entries[i]->type == CASCADE_ENTRY) {
- if ((menuPtr->entries[i]->childMenuRefPtr != NULL)
- && menuPtr->entries[i]->childMenuRefPtr->menuPtr != NULL) {
- cascadeMenuPtr = menuPtr->entries[i]->childMenuRefPtr->menuPtr;
- macMenuHdl =
- ((MacMenu *) cascadeMenuPtr->platformData)->menuHdl;
- InsertMenu(macMenuHdl, -1);
- RecursivelyInsertMenu(cascadeMenuPtr);
+ if (menuPtr->entries[i]->type == CASCADE_ENTRY) {
+ if ((menuPtr->entries[i]->childMenuRefPtr != NULL)
+ && (menuPtr->entries[i]->childMenuRefPtr->menuPtr
+ != NULL)) {
+ cascadeMenuPtr = menuPtr->entries[i]->childMenuRefPtr->menuPtr;
+ macMenuHdl =
+ ((MacMenu *) cascadeMenuPtr->platformData)->menuHdl;
+ InsertMenu(macMenuHdl, -1);
+ RecursivelyInsertMenu(cascadeMenuPtr);
}
- }
+ }
}
}
@@ -1807,6 +1882,7 @@ RecursivelyInsertMenu(
* Takes all of the cascades of this menu out of the Mac hierarchical
* list.
*
+ *
* Results:
* None.
*
@@ -1818,24 +1894,25 @@ RecursivelyInsertMenu(
static void
RecursivelyDeleteMenu(
- TkMenu *menuPtr) /* All of the cascade items in this menu will
- * be inserted into the mac menubar. */
+ TkMenu *menuPtr) /* All of the cascade items in this menu
+ * will be inserted into the mac menubar. */
{
int i;
TkMenu *cascadeMenuPtr;
MenuHandle macMenuHdl;
-
+
for (i = 0; i < menuPtr->numEntries; i++) {
- if (menuPtr->entries[i]->type == CASCADE_ENTRY) {
- if ((menuPtr->entries[i]->childMenuRefPtr != NULL) &&
- (menuPtr->entries[i]->childMenuRefPtr->menuPtr != NULL)) {
- cascadeMenuPtr = menuPtr->entries[i]->childMenuRefPtr->menuPtr;
- macMenuHdl =
- ((MacMenu *) cascadeMenuPtr->platformData)->menuHdl;
- DeleteMenu(GetMenuID(macMenuHdl));
- RecursivelyInsertMenu(cascadeMenuPtr);
+ if (menuPtr->entries[i]->type == CASCADE_ENTRY) {
+ if ((menuPtr->entries[i]->childMenuRefPtr != NULL)
+ && (menuPtr->entries[i]->childMenuRefPtr->menuPtr
+ != NULL)) {
+ cascadeMenuPtr = menuPtr->entries[i]->childMenuRefPtr->menuPtr;
+ macMenuHdl =
+ ((MacMenu *) cascadeMenuPtr->platformData)->menuHdl;
+ DeleteMenu(GetMenuID(macMenuHdl));
+ RecursivelyInsertMenu(cascadeMenuPtr);
}
- }
+ }
}
}
@@ -1856,11 +1933,11 @@ RecursivelyDeleteMenu(
*/
static void
-SetDefaultMenubar(void)
+SetDefaultMenubar()
{
if (currentMenuBarName != NULL) {
- ckfree(currentMenuBarName);
- currentMenuBarName = NULL;
+ ckfree(currentMenuBarName);
+ currentMenuBarName = NULL;
}
currentMenuBarOwner = NULL;
ClearMenuBar();
@@ -1868,8 +1945,8 @@ SetDefaultMenubar(void)
InsertMenu(tkFileMenu, 0);
InsertMenu(tkEditMenu, 0);
if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) {
- Tcl_DoWhenIdle(DrawMenuBarWhenIdle, NULL);
- menuBarFlags |= MENUBAR_REDRAW_PENDING;
+ Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL);
+ menuBarFlags |= MENUBAR_REDRAW_PENDING;
}
}
@@ -1878,8 +1955,8 @@ SetDefaultMenubar(void)
*
* TkpSetMainMenubar --
*
- * Puts the menu associated with a window into the menubar. Should only
- * be called when the window is in front.
+ * Puts the menu associated with a window into the menubar. Should
+ * only be called when the window is in front.
*
* Results:
* None.
@@ -1894,77 +1971,81 @@ void
TkpSetMainMenubar(
Tcl_Interp *interp, /* The interpreter of the application */
Tk_Window tkwin, /* The frame we are setting up */
- char *menuName) /* The name of the menu to put in front. If
- * NULL, use the default menu bar. */
+ char *menuName) /* The name of the menu to put in front.
+ * If NULL, use the default menu bar.
+ */
{
TkWindow *winPtr = (TkWindow *) tkwin;
- CGrafPtr winPort;
+ CGrafPtr winPort;
WindowRef macWindowPtr;
WindowRef frontNonFloating;
winPort = TkMacOSXGetDrawablePort(winPtr->window);
if (!winPort) {
- return;
+ return;
}
macWindowPtr = GetWindowFromPort(winPort);
-
- frontNonFloating = ActiveNonFloatingWindow();
+
+ frontNonFloating = ActiveNonFloatingWindow();
if ((macWindowPtr == NULL) || (macWindowPtr != frontNonFloating)) {
- return;
+ return;
}
- if ((currentMenuBarInterp != interp) || (currentMenuBarOwner != tkwin)
- || (currentMenuBarName == NULL) || (menuName == NULL)
- || (strcmp(menuName, currentMenuBarName) != 0)) {
+ if ((currentMenuBarInterp != interp)
+ || (currentMenuBarOwner != tkwin)
+ || (currentMenuBarName == NULL)
+ || (menuName == NULL)
+ || (strcmp(menuName, currentMenuBarName) != 0)) {
Tk_Window searchWindow;
- TopLevelMenubarList *listPtr;
-
- if (currentMenuBarName != NULL) {
- ckfree(currentMenuBarName);
- }
+ TopLevelMenubarList *listPtr;
+
+ if (currentMenuBarName != NULL) {
+ ckfree(currentMenuBarName);
+ }
if (menuName == NULL) {
searchWindow = tkwin;
if (strcmp(Tk_Class(searchWindow), "Menu") == 0) {
- TkMenuReferences *menuRefPtr;
-
- menuRefPtr = TkFindMenuReferences(interp, Tk_PathName(tkwin));
- if (menuRefPtr != NULL) {
- TkMenu *menuPtr = menuRefPtr->menuPtr;
-
- if (menuPtr != NULL) {
- searchWindow = menuPtr->masterMenuPtr->tkwin;
- }
- }
- }
+ TkMenuReferences *menuRefPtr;
+
+ menuRefPtr = TkFindMenuReferences(interp, Tk_PathName(tkwin));
+ if (menuRefPtr != NULL) {
+ TkMenu *menuPtr = menuRefPtr->menuPtr;
+ if (menuPtr != NULL) {
+ menuPtr = menuPtr->masterMenuPtr;
+ searchWindow = menuPtr->tkwin;
+ }
+ }
+ }
for (; searchWindow != NULL;
searchWindow = Tk_Parent(searchWindow)) {
- for (listPtr = windowListPtr; listPtr != NULL;
- listPtr = listPtr->nextPtr) {
- if (listPtr->tkwin == searchWindow) {
- break;
- }
- }
- if (listPtr != NULL) {
- menuName = Tk_PathName(
- listPtr->menuPtr->masterMenuPtr->tkwin);
- break;
- }
+
+ for (listPtr = windowListPtr; listPtr != NULL;
+ listPtr = listPtr->nextPtr) {
+ if (listPtr->tkwin == searchWindow) {
+ break;
+ }
+ }
+ if (listPtr != NULL) {
+ menuName = Tk_PathName(listPtr->menuPtr->masterMenuPtr
+ ->tkwin);
+ break;
+ }
}
}
-
+
if (menuName == NULL) {
currentMenuBarName = NULL;
- } else {
- currentMenuBarName = ckalloc(strlen(menuName) + 1);
+ } else {
+ currentMenuBarName = ckalloc(strlen(menuName) + 1);
strcpy(currentMenuBarName, menuName);
- }
- currentMenuBarOwner = tkwin;
- currentMenuBarInterp = interp;
+ }
+ currentMenuBarOwner = tkwin;
+ currentMenuBarInterp = interp;
}
if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) {
- Tcl_DoWhenIdle(DrawMenuBarWhenIdle, NULL);
- menuBarFlags |= MENUBAR_REDRAW_PENDING;
+ Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL);
+ menuBarFlags |= MENUBAR_REDRAW_PENDING;
}
}
@@ -1979,8 +2060,8 @@ TkpSetMainMenubar(
* None.
*
* Side effects:
- * On Windows and UNIX, associates the platform menu with the platform
- * window.
+ * On Windows and UNIX, associates the platform menu with the
+ * platform window.
*
*----------------------------------------------------------------------
*/
@@ -1991,44 +2072,45 @@ TkpSetWindowMenuBar(
TkMenu *menuPtr) /* The menu we are setting */
{
TopLevelMenubarList *listPtr, *prevPtr;
-
+
/*
* Remove any existing reference to this window.
*/
-
- for (prevPtr = NULL, listPtr = windowListPtr;
- listPtr != NULL;
- prevPtr = listPtr, listPtr = listPtr->nextPtr) {
+
+ for (prevPtr = NULL, listPtr = windowListPtr;
+ listPtr != NULL;
+ prevPtr = listPtr, listPtr = listPtr->nextPtr) {
if (listPtr->tkwin == tkwin) {
break;
- }
+ }
}
-
+
if (listPtr != NULL) {
- if (prevPtr != NULL) {
- prevPtr->nextPtr = listPtr->nextPtr;
- } else {
- windowListPtr = listPtr->nextPtr;
- }
- ckfree((char *) listPtr);
+ if (prevPtr != NULL) {
+ prevPtr->nextPtr = listPtr->nextPtr;
+ } else {
+ windowListPtr = listPtr->nextPtr;
+ }
+ ckfree((char *) listPtr);
}
-
+
if (menuPtr != NULL) {
- listPtr = (TopLevelMenubarList *) ckalloc(sizeof(TopLevelMenubarList));
- listPtr->nextPtr = windowListPtr;
- windowListPtr = listPtr;
- listPtr->tkwin = tkwin;
- listPtr->menuPtr = menuPtr;
+ listPtr = (TopLevelMenubarList *) ckalloc(sizeof(TopLevelMenubarList));
+ listPtr->nextPtr = windowListPtr;
+ windowListPtr = listPtr;
+ listPtr->tkwin = tkwin;
+ listPtr->menuPtr = menuPtr;
}
}
-
+
+static void
/*
*----------------------------------------------------------------------
*
* EventuallyInvokeMenu --
*
- * This IdleTime callback actually invokes the menu command scheduled in
- * TkMacOSXDispatchMenuEvent.
+ * This IdleTime callback actually invokes the menu command
+ * scheduled in TkMacOSXDispatchMenuEvent.
*
* Results:
* None.
@@ -2039,33 +2121,32 @@ TkpSetWindowMenuBar(
*----------------------------------------------------------------------
*/
-static void
-EventuallyInvokeMenu(
- ClientData data)
+EventuallyInvokeMenu (ClientData data)
{
- struct MenuCommandHandlerData *realData =
- (struct MenuCommandHandlerData *) data;
+ struct MenuCommandHandlerData *realData
+ = (struct MenuCommandHandlerData *) data;
int code;
code = TkInvokeMenu(realData->menuPtr->interp, realData->menuPtr,
- realData->index);
-
- if (code != TCL_OK && code != TCL_CONTINUE && code != TCL_BREAK) {
- Tcl_AddErrorInfo(realData->menuPtr->interp, "\n (menu invoke)");
- Tcl_BackgroundError(realData->menuPtr->interp);
+ realData->index);
+
+ if (code != TCL_OK && code != TCL_CONTINUE
+ && code != TCL_BREAK) {
+ Tcl_AddErrorInfo(realData->menuPtr->interp, "\n (menu invoke)");
+ Tcl_BackgroundError(realData->menuPtr->interp);
}
-
+
Tcl_Release(realData->menuPtr->interp);
Tcl_Release(realData->menuPtr);
}
-
+
/*
*----------------------------------------------------------------------
*
* TkMacOSXDispatchMenuEvent --
*
- * Given a menu id and an item, dispatches the command associated with
- * it.
+ * Given a menu id and an item, dispatches the command associated
+ * with it.
*
* Results:
* None.
@@ -2078,71 +2159,64 @@ EventuallyInvokeMenu(
int
TkMacOSXDispatchMenuEvent(
- int menuID, /* The menu id of the menu we are invoking */
- int index) /* The one-based index of the item that was
- * selected. */
+ int menuID, /* The menu id of the menu we are invoking */
+ int index) /* The one-based index of the item that was
+ * selected. */
{
int result = TCL_OK;
-
if (menuID != 0) {
- if (menuID == kHMHelpMenuID) {
- if (currentMenuBarOwner != NULL) {
- TkMenuReferences *helpMenuRef;
- char *helpMenuName = ckalloc(strlen(currentMenuBarName)
- + strlen(".help") + 1);
-
- sprintf(helpMenuName, "%s.help", currentMenuBarName);
- helpMenuRef = TkFindMenuReferences(currentMenuBarInterp,
- helpMenuName);
- ckfree(helpMenuName);
- if ((helpMenuRef != NULL) && (helpMenuRef->menuPtr != NULL)) {
+ if (menuID == kHMHelpMenuID) {
+ if (currentMenuBarOwner != NULL) {
+ TkMenuReferences *helpMenuRef;
+ char *helpMenuName = ckalloc(strlen(currentMenuBarName)
+ + strlen(".help") + 1);
+ sprintf(helpMenuName, "%s.help", currentMenuBarName);
+ helpMenuRef = TkFindMenuReferences(currentMenuBarInterp,
+ helpMenuName);
+ ckfree(helpMenuName);
+ if ((helpMenuRef != NULL) && (helpMenuRef->menuPtr != NULL)) {
MenuRef outHelpMenu;
MenuItemIndex itemIndex;
int newIndex;
-
HMGetHelpMenu(&outHelpMenu, &itemIndex);
- newIndex = index - itemIndex;
- result = TkInvokeMenu(currentMenuBarInterp,
- helpMenuRef->menuPtr, newIndex);
- }
- }
- } else {
- Tcl_HashEntry *commandEntryPtr =
- Tcl_FindHashEntry(&commandTable, (char *) ((int)menuID));
- TkMenu *menuPtr;
-
- if (commandEntryPtr == NULL) {
- return TCL_ERROR;
- }
-
- menuPtr = (TkMenu *) Tcl_GetHashValue(commandEntryPtr);
-
- if ((currentAppleMenuID == menuID)
- && (index > menuPtr->numEntries + 1)) {
- /*
- * We don't need to do anything here, the standard Application
- * event handler will open the built-in Apple menu item for
- * us.
- */
-
- result = TCL_OK;
- } else {
- struct MenuCommandHandlerData *data =
- (struct MenuCommandHandlerData *)
- ckalloc(sizeof(struct MenuCommandHandlerData));
-
- Tcl_Preserve(menuPtr->interp);
- Tcl_Preserve(menuPtr);
- data->menuPtr = menuPtr;
- data->index = index - 1;
- Tcl_DoWhenIdle(EventuallyInvokeMenu, (ClientData) data);
- /* result = TkInvokeMenu(menuPtr->interp, menuPtr, index-1); */
- }
+ newIndex = index - itemIndex;
+ result = TkInvokeMenu(currentMenuBarInterp,
+ helpMenuRef->menuPtr, newIndex);
+ }
+ }
+ } else {
+ Tcl_HashEntry *commandEntryPtr =
+ Tcl_FindHashEntry(&commandTable, (char *) ((int)menuID));
+ if (commandEntryPtr != NULL) {
+ TkMenu *menuPtr = (TkMenu *) Tcl_GetHashValue(commandEntryPtr);
+ if ((currentAppleMenuID == menuID)
+ && (index > menuPtr->numEntries + 1)) {
+ /*
+ * We don't need to do anything here, the standard
+ * Application event handler will open the built-in
+ * Apple menu item for us.
+ */
+ result = TCL_OK;
+ } else {
+ struct MenuCommandHandlerData *data
+ = (struct MenuCommandHandlerData *)
+ ckalloc(sizeof(struct MenuCommandHandlerData));
+ Tcl_Preserve(menuPtr->interp);
+ Tcl_Preserve(menuPtr);
+ data->menuPtr = menuPtr;
+ data->index = index - 1;
+ Tcl_DoWhenIdle (EventuallyInvokeMenu,
+ (ClientData) data);
+ /* result = TkInvokeMenu(menuPtr->interp, menuPtr, index - 1); */
+ }
+ } else {
+ return TCL_ERROR;
+ }
}
}
return result;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -2169,8 +2243,9 @@ GetMenuIndicatorGeometry (
int *heightPtr) /* The resulting height */
{
char markChar;
-
+
*heightPtr = fmPtr->linespace;
+
markChar = (char) FindMarkCharacter(mePtr);
*widthPtr = Tk_TextWidth(tkfont, &markChar, 1) + 4;
}
@@ -2193,64 +2268,61 @@ GetMenuIndicatorGeometry (
static void
GetMenuAccelGeometry (
- TkMenu *menuPtr, /* The menu we are measuring */
- TkMenuEntry *mePtr, /* The entry we are measuring */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- int *modWidthPtr, /* The width of all of the key modifier
- * symbols. */
- int *textWidthPtr, /* The resulting width */
- int *heightPtr) /* The resulting height */
+ TkMenu *menuPtr, /* The menu we are measuring */
+ TkMenuEntry *mePtr, /* The entry we are measuring */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ int *modWidthPtr, /* The width of all of the key
+ * modifier symbols. */
+ int *textWidthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
*heightPtr = fmPtr->linespace;
*modWidthPtr = 0;
if (mePtr->type == CASCADE_ENTRY) {
- *textWidthPtr = SICN_HEIGHT;
- *modWidthPtr = Tk_TextWidth(tkfont, "W", 1);
+ *textWidthPtr = SICN_HEIGHT;
+ *modWidthPtr = Tk_TextWidth(tkfont, "W", 1);
} else if (0 == mePtr->accelLength) {
- *textWidthPtr = 0;
+ *textWidthPtr = 0;
} else {
- char *accel = (mePtr->accelPtr == NULL) ? ""
- : Tcl_GetString(mePtr->accelPtr);
-
- if (NULL == GetResource('SICN', SICN_RESOURCE_NUMBER)) {
- *textWidthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
- } else {
- int emWidth = Tk_TextWidth(tkfont, "W", 1) + 1;
-
- if ((mePtr->entryFlags & ENTRY_ACCEL_MASK) == 0) {
- int width = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
-
- *textWidthPtr = emWidth;
- if (width < emWidth) {
- *modWidthPtr = 0;
- } else {
- *modWidthPtr = width - emWidth;
- }
- } else {
- int length = ((EntryGeometry *)mePtr->platformEntryData)
- ->accelTextStart;
-
- if (mePtr->entryFlags & ENTRY_CONTROL_ACCEL) {
- *modWidthPtr += CONTROL_ICON_WIDTH;
- }
- if (mePtr->entryFlags & ENTRY_SHIFT_ACCEL) {
- *modWidthPtr += SHIFT_ICON_WIDTH;
- }
- if (mePtr->entryFlags & ENTRY_OPTION_ACCEL) {
- *modWidthPtr += OPTION_ICON_WIDTH;
- }
- if (mePtr->entryFlags & ENTRY_COMMAND_ACCEL) {
- *modWidthPtr += COMMAND_ICON_WIDTH;
- }
- if (1 == (mePtr->accelLength - length)) {
- *textWidthPtr = emWidth;
- } else {
- *textWidthPtr += Tk_TextWidth(tkfont, accel + length,
- mePtr->accelLength - length);
- }
- }
- }
+ char *accel = (mePtr->accelPtr == NULL) ? ""
+ : Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
+
+ if (NULL == GetResource('SICN', SICN_RESOURCE_NUMBER)) {
+ *textWidthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
+ } else {
+ int emWidth = Tk_TextWidth(tkfont, "W", 1) + 1;
+ if ((mePtr->entryFlags & ENTRY_ACCEL_MASK) == 0) {
+ int width = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
+ *textWidthPtr = emWidth;
+ if (width < emWidth) {
+ *modWidthPtr = 0;
+ } else {
+ *modWidthPtr = width - emWidth;
+ }
+ } else {
+ int length = ((EntryGeometry *)mePtr->platformEntryData)
+ ->accelTextStart;
+ if (mePtr->entryFlags & ENTRY_CONTROL_ACCEL) {
+ *modWidthPtr += CONTROL_ICON_WIDTH;
+ }
+ if (mePtr->entryFlags & ENTRY_SHIFT_ACCEL) {
+ *modWidthPtr += SHIFT_ICON_WIDTH;
+ }
+ if (mePtr->entryFlags & ENTRY_OPTION_ACCEL) {
+ *modWidthPtr += OPTION_ICON_WIDTH;
+ }
+ if (mePtr->entryFlags & ENTRY_COMMAND_ACCEL) {
+ *modWidthPtr += COMMAND_ICON_WIDTH;
+ }
+ if (1 == (mePtr->accelLength - length)) {
+ *textWidthPtr = emWidth;
+ } else {
+ *textWidthPtr += Tk_TextWidth(tkfont, accel
+ + length, mePtr->accelLength - length);
+ }
+ }
+ }
}
}
@@ -2272,17 +2344,17 @@ GetMenuAccelGeometry (
static void
GetTearoffEntryGeometry (
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are measuring */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- int *widthPtr, /* The resulting width */
- int *heightPtr) /* The resulting height */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are measuring */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ int *widthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
if ((GetResource('MDEF', 591) == NULL) &&
(menuPtr->menuType == MASTER_MENU)) {
- *heightPtr = fmPtr->linespace;
- *widthPtr = 0;
+ *heightPtr = fmPtr->linespace;
+ *widthPtr = 0;
} else {
*widthPtr = *heightPtr = 0;
}
@@ -2306,18 +2378,18 @@ GetTearoffEntryGeometry (
static void
GetMenuSeparatorGeometry(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are measuring */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalcualted font metrics */
- int *widthPtr, /* The resulting width */
- int *heightPtr) /* The resulting height */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are measuring */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalcualted font metrics */
+ int *widthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
- SInt16 outHeight;
-
- GetThemeMenuSeparatorHeight(&outHeight);
- *widthPtr = 0;
- *heightPtr = outHeight;
+ SInt16 outHeight;
+
+ GetThemeMenuSeparatorHeight(&outHeight);
+ *widthPtr = 0;
+ *heightPtr = outHeight;
}
/*
@@ -2331,53 +2403,54 @@ GetMenuSeparatorGeometry(
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
static void
DrawMenuEntryIndicator(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are drawing */
- Drawable d, /* The drawable we are drawing */
- GC gc, /* The GC we are drawing with */
- GC indicatorGC, /* The GC to use for the indicator */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- int x, /* topleft hand corner of entry */
- int y, /* topleft hand corner of entry */
- int width, /* width of entry */
- int height) /* height of entry */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing */
+ GC gc, /* The GC we are drawing with */
+ GC indicatorGC, /* The GC to use for the indicator */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ int x, /* topleft hand corner of entry */
+ int y, /* topleft hand corner of entry */
+ int width, /* width of entry */
+ int height) /* height of entry */
{
- if ((mePtr->type == CHECK_BUTTON_ENTRY) ||
- (mePtr->type == RADIO_BUTTON_ENTRY)) {
- if (mePtr->indicatorOn && (mePtr->entryFlags & ENTRY_SELECTED)) {
+ if ((mePtr->type == CHECK_BUTTON_ENTRY) ||
+ (mePtr->type == RADIO_BUTTON_ENTRY)) {
+ if (mePtr->indicatorOn
+ && (mePtr->entryFlags & ENTRY_SELECTED)) {
int baseline;
short markShort;
-
- baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
- GetItemMark(((MacMenu *) menuPtr->platformData)->menuHdl,
- mePtr->index + 1, &markShort);
- if (markShort != 0) {
- char markChar, markCharUTF[TCL_UTF_MAX + 1];
+
+ baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
+ GetItemMark(((MacMenu *) menuPtr->platformData)->menuHdl,
+ mePtr->index + 1, &markShort);
+ if (markShort != 0) {
+ char markChar;
+ char markCharUTF[TCL_UTF_MAX + 1];
int dstWrote;
-
- markChar = (char) markShort;
-
- /*
- * Not sure if this is the correct encoding, but this function
- * doesn't appear to be used at all in, since the Carbon Menus
- * draw themselves
- */
-
- Tcl_ExternalToUtf(NULL, NULL, &markChar, 1, 0, NULL,
+
+ markChar = (char) markShort;
+ /*
+ * Not sure if this is the correct encoding, but this function
+ * doesn't appear to be used at all in, since the Carbon Menus
+ * draw themselves
+ */
+ Tcl_ExternalToUtf(NULL, NULL, &markChar, 1, 0, NULL,
markCharUTF, TCL_UTF_MAX + 1, NULL, &dstWrote, NULL);
Tk_DrawChars(menuPtr->display, d, gc, tkfont, markCharUTF,
dstWrote, x + 2, baseline);
- }
+ }
}
- }
+ }
}
/*
@@ -2391,16 +2464,17 @@ DrawMenuEntryIndicator(
* Nothing
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
-
static void
DrawMenuBackground(
- Rect *menuRectPtr, /* The menu rect */
+ Rect *menuRectPtr, /* The menu rect */
Drawable d, /* What we are drawing into */
- ThemeMenuType type) /* Type of menu */
+ ThemeMenuType type /* Type of menu */
+ )
{
CGrafPtr saveWorld;
GDHandle saveDevice;
@@ -2410,8 +2484,9 @@ DrawMenuBackground(
GetGWorld(&saveWorld, &saveDevice);
SetGWorld(destPort, NULL);
TkMacOSXSetUpClippingRgn(d);
- DrawThemeMenuBackground(menuRectPtr, type);
- SetGWorld(saveWorld, saveDevice);
+ DrawThemeMenuBackground (menuRectPtr, type);
+ SetGWorld(saveWorld, saveDevice);
+ return;
}
/*
@@ -2419,70 +2494,71 @@ DrawMenuBackground(
*
* DrawSICN --
*
- * Given a resource id and an index, loads the appropriate SICN and draws
- * it into a given drawable using the given gc.
+ * Given a resource id and an index, loads the appropriate SICN
+ * and draws it into a given drawable using the given gc.
*
* Results:
* Returns 1 if the SICN was found, 0 if not found.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
-
static int
DrawSICN(
- int resourceID, /* The resource # of the SICN table */
- int index, /* The index into the SICN table of the icon
- * we want. */
- Drawable d, /* What we are drawing into */
- GC gc, /* The GC to draw with */
- int x, /* The left hand coord of the SICN */
- int y) /* The top coord of the SICN */
+ int resourceID, /* The resource # of the SICN table */
+ int index, /* The index into the SICN table of the
+ * icon we want. */
+ Drawable d, /* What we are drawing into */
+ GC gc, /* The GC to draw with */
+ int x, /* The left hand coord of the SICN */
+ int y) /* The top coord of the SICN */
{
Handle sicnHandle = (Handle) GetResource('SICN', SICN_RESOURCE_NUMBER);
- BitMap sicnBitmap;
- Rect destRect;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr destPort;
- const BitMap *destBitMap;
- RGBColor origForeColor, origBackColor, foreColor, backColor;
-
+
if (NULL == sicnHandle) {
- return 0;
- }
-
- HLock(sicnHandle);
- destPort = TkMacOSXGetDrawablePort(d);
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(destPort, NULL);
- TkMacOSXSetUpClippingRgn(d);
- TkMacOSXSetUpGraphicsPort(gc, destPort);
- GetForeColor(&origForeColor);
- GetBackColor(&origBackColor);
-
- if (TkSetMacColor(gc->foreground, &foreColor)) {
- RGBForeColor(&foreColor);
- }
+ return 0;
+ } else {
+ BitMap sicnBitmap;
+ Rect destRect;
+ CGrafPtr saveWorld;
+ GDHandle saveDevice;
+ GWorldPtr destPort;
+ const BitMap *destBitMap;
+ RGBColor origForeColor, origBackColor, foreColor, backColor;
+
+ HLock(sicnHandle);
+ destPort = TkMacOSXGetDrawablePort(d);
+ GetGWorld(&saveWorld, &saveDevice);
+ SetGWorld(destPort, NULL);
+ TkMacOSXSetUpClippingRgn(d);
+ TkMacOSXSetUpGraphicsPort(gc, destPort);
+ GetForeColor(&origForeColor);
+ GetBackColor(&origBackColor);
+
+ if (TkSetMacColor(gc->foreground, &foreColor)) {
+ RGBForeColor(&foreColor);
+ }
+
+ if (TkSetMacColor(gc->background, &backColor)) {
+ RGBBackColor(&backColor);
+ }
- if (TkSetMacColor(gc->background, &backColor)) {
- RGBBackColor(&backColor);
+ SetRect(&destRect, x, y, x + SICN_HEIGHT, y + SICN_HEIGHT);
+ sicnBitmap.baseAddr = (Ptr) (*sicnHandle) + index * SICN_HEIGHT
+ * SICN_ROWS;
+ sicnBitmap.rowBytes = SICN_ROWS;
+ SetRect(&sicnBitmap.bounds, 0, 0, 16, 16);
+ destBitMap = GetPortBitMapForCopyBits(destPort);
+ CopyBits(&sicnBitmap, destBitMap, &sicnBitmap.bounds, &destRect, GetPortTextMode(destPort), NULL);
+ HUnlock(sicnHandle);
+ RGBForeColor(&origForeColor);
+ RGBBackColor(&origBackColor);
+ SetGWorld(saveWorld, saveDevice);
+ return 1;
}
-
- SetRect(&destRect, x, y, x + SICN_HEIGHT, y + SICN_HEIGHT);
- sicnBitmap.baseAddr = (Ptr) (*sicnHandle) + index*SICN_HEIGHT*SICN_ROWS;
- sicnBitmap.rowBytes = SICN_ROWS;
- SetRect(&sicnBitmap.bounds, 0, 0, 16, 16);
- destBitMap = GetPortBitMapForCopyBits(destPort);
- CopyBits(&sicnBitmap, destBitMap, &sicnBitmap.bounds, &destRect,
- GetPortTextMode(destPort), NULL);
- HUnlock(sicnHandle);
- RGBForeColor(&origForeColor);
- RGBBackColor(&origBackColor);
- SetGWorld(saveWorld, saveDevice);
- return 1;
}
/*
@@ -2490,90 +2566,93 @@ DrawSICN(
*
* DrawMenuEntryAccelerator --
*
- * This procedure draws the accelerator part of a menu. We need to decide
- * what to draw here. Should we replace strings like "Control",
- * "Command", etc?
+ * This procedure draws the accelerator part of a menu. We
+ * need to decide what to draw here. Should we replace strings
+ * like "Control", "Command", etc?
*
* Results:
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
static void
DrawMenuEntryAccelerator(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are drawing */
- Drawable d, /* The drawable we are drawing in */
- GC gc, /* The gc to draw into */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- Tk_3DBorder activeBorder, /* border for menu background */
- int x, /* The left side of the entry */
- int y, /* The top of the entry */
- int width, /* The width of the entry */
- int height, /* The height of the entry */
- int drawArrow) /* Whether or not to draw cascade arrow */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing in */
+ GC gc, /* The gc to draw into */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ Tk_3DBorder activeBorder, /* border for menu background */
+ int x, /* The left side of the entry */
+ int y, /* The top of the entry */
+ int width, /* The width of the entry */
+ int height, /* The height of the entry */
+ int drawArrow) /* Whether or not to draw cascade arrow */
{
int activeBorderWidth;
-
+
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
- &activeBorderWidth);
+ &activeBorderWidth);
if (mePtr->type == CASCADE_ENTRY) {
- /*
- * Under Appearance, we let the Appearance Manager draw the icon
- */
+ /*
+ * Under Appearance, we let the Appearance Manager draw the icon
+ */
+
} else if (mePtr->accelLength != 0) {
- int leftEdge = x + width;
- int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
- char *accel = Tcl_GetString(mePtr->accelPtr);
+ int leftEdge = x + width;
+ int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
+ char *accel;
+
+ accel = Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
if (NULL == GetResource('SICN', SICN_RESOURCE_NUMBER)) {
leftEdge -= ((EntryGeometry *) mePtr->platformEntryData)
- ->accelTextWidth;
+ ->accelTextWidth;
Tk_DrawChars(menuPtr->display, d, gc, tkfont, accel,
- mePtr->accelLength, leftEdge, baseline);
+ mePtr->accelLength, leftEdge, baseline);
} else {
- EntryGeometry *geometryPtr =
- (EntryGeometry *) mePtr->platformEntryData;
+ EntryGeometry *geometryPtr =
+ (EntryGeometry *) mePtr->platformEntryData;
int length = mePtr->accelLength - geometryPtr->accelTextStart;
-
+
leftEdge -= geometryPtr->accelTextWidth;
if ((mePtr->entryFlags & ENTRY_ACCEL_MASK) == 0) {
- leftEdge -= geometryPtr->modifierWidth;
+ leftEdge -= geometryPtr->modifierWidth;
}
-
- Tk_DrawChars(menuPtr->display, d, gc, tkfont,
- accel + geometryPtr->accelTextStart, length, leftEdge,
- baseline);
+
+ Tk_DrawChars(menuPtr->display, d, gc, tkfont, accel
+ + geometryPtr->accelTextStart, length, leftEdge, baseline);
if (mePtr->entryFlags & ENTRY_COMMAND_ACCEL) {
- leftEdge -= COMMAND_ICON_WIDTH;
- DrawSICN(SICN_RESOURCE_NUMBER, COMMAND_ICON, d, gc, leftEdge,
- (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
+ leftEdge -= COMMAND_ICON_WIDTH;
+ DrawSICN(SICN_RESOURCE_NUMBER, COMMAND_ICON, d, gc,
+ leftEdge, (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
}
if (mePtr->entryFlags & ENTRY_OPTION_ACCEL) {
- leftEdge -= OPTION_ICON_WIDTH;
- DrawSICN(SICN_RESOURCE_NUMBER, OPTION_ICON, d, gc, leftEdge,
- (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
+ leftEdge -= OPTION_ICON_WIDTH;
+ DrawSICN(SICN_RESOURCE_NUMBER, OPTION_ICON, d, gc,
+ leftEdge, (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
}
if (mePtr->entryFlags & ENTRY_SHIFT_ACCEL) {
- leftEdge -= SHIFT_ICON_WIDTH;
- DrawSICN(SICN_RESOURCE_NUMBER, SHIFT_ICON, d, gc, leftEdge,
- (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
+ leftEdge -= SHIFT_ICON_WIDTH;
+ DrawSICN(SICN_RESOURCE_NUMBER, SHIFT_ICON, d, gc,
+ leftEdge, (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
}
if (mePtr->entryFlags & ENTRY_CONTROL_ACCEL) {
- leftEdge -= CONTROL_ICON_WIDTH;
- DrawSICN(SICN_RESOURCE_NUMBER, CONTROL_ICON, d, gc, leftEdge,
- (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
+ leftEdge -= CONTROL_ICON_WIDTH;
+ DrawSICN(SICN_RESOURCE_NUMBER, CONTROL_ICON, d, gc,
+ leftEdge, (y + (height / 2)) - (SICN_HEIGHT / 2) - 1);
}
- }
+ }
}
}
@@ -2588,29 +2667,30 @@ DrawMenuEntryAccelerator(
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
static void
DrawMenuSeparator(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are drawing */
- Drawable d, /* The drawable we are drawing into */
- GC gc, /* The gc we are drawing with */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- int x, /* left coordinate of entry */
- int y, /* top coordinate of entry */
- int width, /* width of entry */
- int height) /* height of entry */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing into */
+ GC gc, /* The gc we are drawing with */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ int x, /* left coordinate of entry */
+ int y, /* top coordinate of entry */
+ int width, /* width of entry */
+ int height) /* height of entry */
{
CGrafPtr saveWorld;
GDHandle saveDevice;
GWorldPtr destPort;
Rect r;
-
+
destPort = TkMacOSXGetDrawablePort(d);
GetGWorld(&saveWorld, &saveDevice);
SetGWorld(destPort, NULL);
@@ -2619,17 +2699,17 @@ DrawMenuSeparator(
r.left = x;
r.bottom = y + height;
r.right = x + width;
-
+
DrawThemeMenuSeparator(&r);
}
/*
*----------------------------------------------------------------------
*
- * AppearanceEntryDrawWrapper --
+ * AppearanceEntryDrawWrapper --
*
- * It routes to the Appearance Managers DrawThemeEntry, which will then
- * call us back after setting up the drawing context.
+ * It routes to the Appearance Managers DrawThemeEntry, which will
+ * then call us back after setting up the drawing context.
*
* Results:
* A menu entry is drawn
@@ -2639,18 +2719,17 @@ DrawMenuSeparator(
*
*----------------------------------------------------------------------
*/
-
-static void
+static void
AppearanceEntryDrawWrapper(
TkMenuEntry *mePtr,
Rect *menuRectPtr,
- MenuTrackingData *mtdPtr,
+ MenuTrackingData *mtdPtr,
Drawable d,
- Tk_FontMetrics *fmPtr,
- Tk_Font tkfont,
- int x,
- int y,
- int width,
+ Tk_FontMetrics *fmPtr,
+ Tk_Font tkfont,
+ int x,
+ int y,
+ int width,
int height)
{
MenuEntryUserData meData;
@@ -2667,30 +2746,32 @@ AppearanceEntryDrawWrapper(
itemRect.left = x;
itemRect.bottom = itemRect.top + height;
itemRect.right = itemRect.left + width;
-
+
if (mePtr->state == ENTRY_ACTIVE) {
- theState = kThemeMenuSelected;
+ theState = kThemeMenuSelected;
} else if (mePtr->state == ENTRY_DISABLED) {
- theState = kThemeMenuDisabled;
+ theState = kThemeMenuDisabled;
} else {
- theState = kThemeMenuActive;
+ theState = kThemeMenuActive;
}
-
+
if (mePtr->type == CASCADE_ENTRY) {
- theType = kThemeMenuItemHierarchical;
+ theType = kThemeMenuItemHierarchical;
} else {
- theType = kThemeMenuItemPlain;
+ theType = kThemeMenuItemPlain;
}
-
- DrawThemeMenuItem (menuRectPtr, &itemRect, mtdPtr->virtualMenuTop,
- mtdPtr->virtualMenuBottom, theState, theType,
- tkThemeMenuItemDrawingUPP, (unsigned long) &meData);
+
+ DrawThemeMenuItem (menuRectPtr, &itemRect,
+ mtdPtr->virtualMenuTop, mtdPtr->virtualMenuBottom, theState,
+ theType, tkThemeMenuItemDrawingUPP,
+ (unsigned long) &meData);
+
}
/*
*----------------------------------------------------------------------
*
- * ThemeMenuItemDrawingProc --
+ * ThemeMenuItemDrawingProc --
*
* This routine is called from the Appearance DrawThemeMenuEntry
*
@@ -2702,28 +2783,27 @@ AppearanceEntryDrawWrapper(
*
*----------------------------------------------------------------------
*/
-
static pascal void
-ThemeMenuItemDrawingProc(
+ThemeMenuItemDrawingProc (
const Rect *inBounds,
- SInt16 inDepth,
- Boolean inIsColorDevice,
+ SInt16 inDepth,
+ Boolean inIsColorDevice,
SInt32 inUserData)
{
MenuEntryUserData *meData = (MenuEntryUserData *) inUserData;
-
- TkpDrawMenuEntry(meData->mePtr, meData->mdefDrawable, meData->tkfont,
- meData->fmPtr, inBounds->left, inBounds->top,
- inBounds->right-inBounds->left,inBounds->bottom-inBounds->top,0,1);
+ TkpDrawMenuEntry(meData->mePtr, meData->mdefDrawable,
+ meData->tkfont, meData->fmPtr, inBounds->left,
+ inBounds->top, inBounds->right - inBounds->left,
+ inBounds->bottom - inBounds->top, 0, 1);
}
/*
*----------------------------------------------------------------------
*
- * TkMacOSXHandleTearoffMenu --
+ * TkMacOSXHandleTearoffMenu() --
*
- * This routine sees if the MDEF has set a menu and a mouse position for
- * tearing off and makes a tearoff menu if it has.
+ * This routine sees if the MDEF has set a menu and a mouse position
+ * for tearing off and makes a tearoff menu if it has.
*
* Results:
* menuPtr->interp will have the result of the tearoff command.
@@ -2738,17 +2818,18 @@ void
TkMacOSXHandleTearoffMenu(void)
{
if (tearoffStruct.menuPtr != NULL) {
- WindowRef whichWindow;
- short windowPart = FindWindow(tearoffStruct.point, &whichWindow);
-
- if (windowPart != inMenuBar) {
- char intString[TCL_INTEGER_SPACE];
- Tcl_DString tearoffCmdStr;
-
- Tcl_DStringInit(&tearoffCmdStr);
- Tcl_DStringAppendElement(&tearoffCmdStr, "tkTearOffMenu");
- Tcl_DStringAppendElement(&tearoffCmdStr,
- Tk_PathName(tearoffStruct.menuPtr->tkwin));
+ Tcl_DString tearoffCmdStr;
+ char intString[TCL_INTEGER_SPACE];
+ short windowPart;
+ WindowRef whichWindow;
+
+ windowPart = FindWindow(tearoffStruct.point, &whichWindow);
+
+ if (windowPart != inMenuBar) {
+ Tcl_DStringInit(&tearoffCmdStr);
+ Tcl_DStringAppendElement(&tearoffCmdStr, "tkTearOffMenu");
+ Tcl_DStringAppendElement(&tearoffCmdStr,
+ Tk_PathName(tearoffStruct.menuPtr->tkwin));
sprintf(intString, "%d", tearoffStruct.point.h);
Tcl_DStringAppendElement(&tearoffCmdStr, intString);
sprintf(intString, "%d", tearoffStruct.point.v);
@@ -2766,25 +2847,24 @@ TkMacOSXHandleTearoffMenu(void)
*
* TkpInitializeMenuBindings --
*
- * For every interp, initializes the bindings for Windows menus. Does
- * nothing on Mac or XWindows.
+ * For every interp, initializes the bindings for Windows
+ * menus. Does nothing on Mac or XWindows.
*
* Results:
* None.
*
* Side effects:
- * C-level bindings are setup for the interp which will handle Alt-key
- * sequences for menus without beeping or interfering with user-defined
- * Alt-key bindings.
+ * C-level bindings are setup for the interp which will
+ * handle Alt-key sequences for menus without beeping
+ * or interfering with user-defined Alt-key bindings.
*
*--------------------------------------------------------------
*/
void
-TkpInitializeMenuBindings(
- Tcl_Interp *interp, /* The interpreter to set. */
- Tk_BindingTable bindingTable)
- /* The table to add to. */
+TkpInitializeMenuBindings(interp, bindingTable)
+ Tcl_Interp *interp; /* The interpreter to set. */
+ Tk_BindingTable bindingTable; /* The table to add to. */
{
/*
* Nothing to do.
@@ -2796,22 +2876,23 @@ TkpInitializeMenuBindings(
*
* TkpComputeMenubarGeometry --
*
- * This procedure is invoked to recompute the size and layout of a menu
- * that is a menubar clone.
+ * This procedure is invoked to recompute the size and
+ * layout of a menu that is a menubar clone.
*
* Results:
* None.
*
* Side effects:
- * Fields of menu entries are changed to reflect their current positions,
- * and the size of the menu window itself may be changed.
+ * Fields of menu entries are changed to reflect their
+ * current positions, and the size of the menu window
+ * itself may be changed.
*
*--------------------------------------------------------------
*/
void
-TkpComputeMenubarGeometry(
- TkMenu *menuPtr) /* Structure describing menu. */
+TkpComputeMenubarGeometry(menuPtr)
+ TkMenu *menuPtr; /* Structure describing menu. */
{
TkpComputeStandardMenuGeometry(menuPtr);
}
@@ -2827,23 +2908,24 @@ TkpComputeMenubarGeometry(
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
void
DrawTearoffEntry(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are drawing */
- Drawable d, /* The drawable we are drawing into */
- GC gc, /* The gc we are drawing with */
- Tk_Font tkfont, /* The font we are drawing with */
- CONST Tk_FontMetrics *fmPtr,/* The metrics we are drawing with */
- int x, /* Left edge of entry. */
- int y, /* Top edge of entry. */
- int width, /* Width of entry. */
- int height) /* Height of entry. */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing into */
+ GC gc, /* The gc we are drawing with */
+ Tk_Font tkfont, /* The font we are drawing with */
+ CONST Tk_FontMetrics *fmPtr, /* The metrics we are drawing with */
+ int x, /* Left edge of entry. */
+ int y, /* Top edge of entry. */
+ int width, /* Width of entry. */
+ int height) /* Height of entry. */
{
XPoint points[2];
int margin, segmentWidth, maxX;
@@ -2852,13 +2934,13 @@ DrawTearoffEntry(
if (menuPtr->menuType != MASTER_MENU ) {
return;
}
-
+
margin = (fmPtr->ascent + fmPtr->descent)/2;
points[0].x = x;
points[0].y = y + height/2;
points[1].y = points[0].y;
segmentWidth = 6;
- maxX = width - 1;
+ maxX = width - 1;
border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);
while (points[0].x < maxX) {
@@ -2877,10 +2959,12 @@ DrawTearoffEntry(
*
* TkMacOSXSetHelpMenuItemCount --
*
- * Has to be called after the first call to InsertMenu. Sets up the
- * global variable for the number of items in the unmodified help menu.
- * NB. Nobody uses this any more, since you can get the number of system
- * help items from HMGetHelpMenu trivially. But it is in the stubs table.
+ * Has to be called after the first call to InsertMenu. Sets
+ * up the global variable for the number of items in the
+ * unmodified help menu.
+ * NB. Nobody uses this any more, since you can get the number
+ * of system help items from HMGetHelpMenu trivially.
+ * But it is in the stubs table...
*
* Results:
* None.
@@ -2891,8 +2975,8 @@ DrawTearoffEntry(
*----------------------------------------------------------------------
*/
-void
-TkMacOSXSetHelpMenuItemCount(void)
+void
+TkMacOSXSetHelpMenuItemCount()
{
}
@@ -2913,26 +2997,26 @@ TkMacOSXSetHelpMenuItemCount(void)
*/
void
-TkMacOSXMenuClick(void)
+TkMacOSXMenuClick()
{
TkMenu *menuPtr;
TkMenuReferences *menuRefPtr;
-
+
if ((currentMenuBarInterp != NULL) && (currentMenuBarName != NULL)) {
- menuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
- currentMenuBarName);
- for (menuPtr = menuRefPtr->menuPtr->masterMenuPtr;
- menuPtr != NULL; menuPtr = menuPtr->nextInstancePtr) {
- if (menuPtr->menuType == MENUBAR) {
- CompleteIdlers(menuPtr);
- break;
- }
- }
+ menuRefPtr = TkFindMenuReferences(currentMenuBarInterp,
+ currentMenuBarName);
+ for (menuPtr = menuRefPtr->menuPtr->masterMenuPtr;
+ menuPtr != NULL; menuPtr = menuPtr->nextInstancePtr) {
+ if (menuPtr->menuType == MENUBAR) {
+ CompleteIdlers(menuPtr);
+ break;
+ }
+ }
}
-
+
if (menuBarFlags & MENUBAR_REDRAW_PENDING) {
- Tcl_CancelIdleCall(DrawMenuBarWhenIdle, (ClientData *) NULL);
- DrawMenuBarWhenIdle((ClientData *) NULL);
+ Tcl_CancelIdleCall(DrawMenuBarWhenIdle, (ClientData *) NULL);
+ DrawMenuBarWhenIdle((ClientData *) NULL);
}
}
@@ -2955,19 +3039,19 @@ TkMacOSXMenuClick(void)
void
TkpDrawMenuEntry(
- TkMenuEntry *mePtr, /* The entry to draw */
- Drawable d, /* What to draw into */
- Tk_Font tkfont, /* Precalculated font for menu */
+ TkMenuEntry *mePtr, /* The entry to draw */
+ Drawable d, /* What to draw into */
+ Tk_Font tkfont, /* Precalculated font for menu */
CONST Tk_FontMetrics *menuMetricsPtr,
- /* Precalculated metrics for menu */
- int x, /* X-coordinate of topleft of entry */
- int y, /* Y-coordinate of topleft of entry */
- int width, /* Width of the entry rectangle */
- int height, /* Height of the current rectangle */
- int strictMotif, /* Boolean flag */
- int drawArrow) /* Whether or not to draw the cascade arrow
- * for cascade items. Only applies to
- * Windows. */
+ /* Precalculated metrics for menu */
+ int x, /* X-coordinate of topleft of entry */
+ int y, /* Y-coordinate of topleft of entry */
+ int width, /* Width of the entry rectangle */
+ int height, /* Height of the current rectangle */
+ int strictMotif, /* Boolean flag */
+ int drawArrow) /* Whether or not to draw the cascade
+ * arrow for cascade items. Only applies
+ * to Windows. */
{
GC gc;
TkMenu *menuPtr = mePtr->menuPtr;
@@ -2980,33 +3064,33 @@ TkpDrawMenuEntry(
int adjustedHeight = height - 2 * padY;
/*
- * Choose the gc for drawing the foreground part of the entry. Under
- * Appearance, we pass a null (appearanceGC) to tell ourselves not to
- * change whatever color the appearance manager has set.
+ * Choose the gc for drawing the foreground part of the entry.
+ * Under Appearance, we pass a null (appearanceGC) to tell
+ * ourselves not to change whatever color the appearance manager has set.
*/
if ((mePtr->state == ENTRY_ACTIVE) && !strictMotif) {
gc = mePtr->activeGC;
if (gc == NULL) {
- gc = menuPtr->activeGC;
+ gc = menuPtr->activeGC;
}
} else {
- TkMenuEntry *cascadeEntryPtr;
- int parentDisabled = 0;
-
- for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
- cascadeEntryPtr != NULL;
- cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
- char *name = (cascadeEntryPtr->namePtr == NULL) ? ""
- : Tcl_GetString(cascadeEntryPtr->namePtr);
-
- if (strcmp(name, Tk_PathName(menuPtr->tkwin)) == 0) {
- if (cascadeEntryPtr->state == ENTRY_DISABLED) {
- parentDisabled = 1;
- }
- break;
- }
- }
+ TkMenuEntry *cascadeEntryPtr;
+ int parentDisabled = 0;
+
+ for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
+ cascadeEntryPtr != NULL;
+ cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
+ char *name = (cascadeEntryPtr->namePtr == NULL) ? ""
+ : Tcl_GetStringFromObj(cascadeEntryPtr->namePtr, NULL);
+
+ if (strcmp(name, Tk_PathName(menuPtr->tkwin)) == 0) {
+ if (cascadeEntryPtr->state == ENTRY_DISABLED) {
+ parentDisabled = 1;
+ }
+ break;
+ }
+ }
if (((parentDisabled || (mePtr->state == ENTRY_DISABLED)))
&& (menuPtr->disabledFgPtr != NULL)) {
@@ -3019,9 +3103,9 @@ TkpDrawMenuEntry(
if (gc == NULL) {
gc = menuPtr->textGC;
}
- }
+ }
}
-
+
indicatorGC = mePtr->indicatorGC;
if (indicatorGC == NULL) {
indicatorGC = menuPtr->indicatorGC;
@@ -3047,22 +3131,22 @@ TkpDrawMenuEntry(
}
/*
- * Need to draw the entire background, including padding. On Unix, for
- * menubars, we have to draw the rest of the entry taking into account the
- * padding.
+ * Need to draw the entire background, including padding. On Unix,
+ * for menubars, we have to draw the rest of the entry taking
+ * into account the padding.
*/
-
- DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder, bgBorder, x, y,
- width, height);
-
+
+ DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder,
+ bgBorder, x, y, width, height);
+
if (mePtr->type == SEPARATOR_ENTRY) {
- DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont,
+ DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont,
fmPtr, x, adjustedY, width, adjustedHeight);
} else if (mePtr->type == TEAROFF_ENTRY) {
DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
width, adjustedHeight);
} else {
- DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x,
+ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x,
adjustedY, width, adjustedHeight);
DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr,
activeBorder, x, adjustedY, width, adjustedHeight, drawArrow);
@@ -3070,6 +3154,7 @@ TkpDrawMenuEntry(
DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont,
fmPtr, x, adjustedY, width, adjustedHeight);
}
+
}
}
@@ -3078,15 +3163,16 @@ TkpDrawMenuEntry(
*
* TkpComputeStandardMenuGeometry --
*
- * This procedure is invoked to recompute the size and layout of a menu
- * that is not a menubar clone.
+ * This procedure is invoked to recompute the size and
+ * layout of a menu that is not a menubar clone.
*
* Results:
* None.
*
* Side effects:
- * Fields of menu entries are changed to reflect their current positions,
- * and the size of the menu window itself may be changed.
+ * Fields of menu entries are changed to reflect their
+ * current positions, and the size of the menu window
+ * itself may be changed.
*
*--------------------------------------------------------------
*/
@@ -3104,15 +3190,15 @@ TkpComputeStandardMenuGeometry(
int entryWidth, maxIndicatorSpace, borderWidth, activeBorderWidth;
TkMenuEntry *mePtr, *columnEntryPtr;
EntryGeometry *geometryPtr;
-
+
if (menuPtr->tkwin == NULL) {
return;
}
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
- &borderWidth);
+ &borderWidth);
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
- &activeBorderWidth);
+ &activeBorderWidth);
x = y = borderWidth;
indicatorSpace = labelWidth = accelWidth = maxAccelTextWidth = 0;
windowHeight = windowWidth = maxWidth = lastColumnBreak = 0;
@@ -3121,13 +3207,14 @@ TkpComputeStandardMenuGeometry(
maxIndicatorSpace = 0;
/*
- * On the Mac especially, getting font metrics can be quite slow, so we
- * want to do it intelligently. We are going to precalculate them and pass
- * them down to all of the measuring and drawing routines. We will measure
- * the font metrics of the menu once. If an entry does not have its own
- * font set, then we give the geometry/drawing routines the menu's font
- * and metrics. If an entry has its own font, we will measure that font
- * and give all of the geometry/drawing the entry's font and metrics.
+ * On the Mac especially, getting font metrics can be quite slow,
+ * so we want to do it intelligently. We are going to precalculate
+ * them and pass them down to all of the measuring and drawing
+ * routines. We will measure the font metrics of the menu once.
+ * If an entry does not have its own font set, then we give
+ * the geometry/drawing routines the menu's font and metrics.
+ * If an entry has its own font, we will measure that font and
+ * give all of the geometry/drawing the entry's font and metrics.
*/
menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
@@ -3138,23 +3225,23 @@ TkpComputeStandardMenuGeometry(
if (mePtr->fontPtr == NULL) {
tkfont = menuFont;
fmPtr = &menuMetrics;
- } else {
+ } else {
tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
- Tk_GetFontMetrics(tkfont, &entryMetrics);
- fmPtr = &entryMetrics;
- }
-
+ Tk_GetFontMetrics(tkfont, &entryMetrics);
+ fmPtr = &entryMetrics;
+ }
+
if ((i > 0) && mePtr->columnBreak) {
if (maxIndicatorSpace != 0) {
maxIndicatorSpace += 2;
}
for (j = lastColumnBreak; j < i; j++) {
- columnEntryPtr = menuPtr->entries[j];
- geometryPtr = (EntryGeometry *)
- columnEntryPtr->platformEntryData;
-
- columnEntryPtr->indicatorSpace = maxIndicatorSpace;
- columnEntryPtr->width = maxIndicatorSpace + maxWidth
+ columnEntryPtr = menuPtr->entries[j];
+ geometryPtr =
+ (EntryGeometry *) columnEntryPtr->platformEntryData;
+
+ columnEntryPtr->indicatorSpace = maxIndicatorSpace;
+ columnEntryPtr->width = maxIndicatorSpace + maxWidth
+ 2 * activeBorderWidth;
geometryPtr->accelTextWidth = maxAccelTextWidth;
geometryPtr->modifierWidth = maxModifierWidth;
@@ -3162,15 +3249,14 @@ TkpComputeStandardMenuGeometry(
columnEntryPtr->entryFlags &= ~ENTRY_LAST_COLUMN;
if (maxEntryWithoutAccelWidth > maxEntryWithAccelWidth) {
geometryPtr->nonAccelMargin = maxEntryWithoutAccelWidth
- - maxEntryWithAccelWidth;
+ - maxEntryWithAccelWidth;
if (geometryPtr->nonAccelMargin > maxNonAccelMargin) {
- geometryPtr->nonAccelMargin = maxNonAccelMargin;
+ geometryPtr->nonAccelMargin = maxNonAccelMargin;
}
} else {
geometryPtr->nonAccelMargin = 0;
- }
+ }
}
-
x += maxIndicatorSpace + maxWidth + 2 * borderWidth;
windowWidth = x;
maxWidth = maxIndicatorSpace = maxAccelTextWidth = 0;
@@ -3182,86 +3268,88 @@ TkpComputeStandardMenuGeometry(
if (mePtr->type == SEPARATOR_ENTRY) {
GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont,
- fmPtr, &entryWidth, &height);
+ fmPtr, &entryWidth, &height);
mePtr->height = height;
} else if (mePtr->type == TEAROFF_ENTRY) {
- GetTearoffEntryGeometry(menuPtr, mePtr, tkfont,
- fmPtr, &entryWidth, &height);
+ GetTearoffEntryGeometry(menuPtr, mePtr, tkfont,
+ fmPtr, &entryWidth, &height);
mePtr->height = height;
} else {
/*
- * For each entry, compute the height required by that particular
- * entry, plus three widths: the width of the label, the width to
- * allow for an indicator to be displayed to the left of the label
- * (if any), and the width of the accelerator to be displayed to
- * the right of the label (if any). These sizes depend, of course,
- * on the type of the entry.
+ * For each entry, compute the height required by that
+ * particular entry, plus three widths: the width of the
+ * label, the width to allow for an indicator to be displayed
+ * to the left of the label (if any), and the width of the
+ * accelerator to be displayed to the right of the label
+ * (if any). These sizes depend, of course, on the type
+ * of the entry.
*/
-
- GetMenuLabelGeometry(mePtr, tkfont, fmPtr, &labelWidth, &height);
+
+ GetMenuLabelGeometry(mePtr, tkfont, fmPtr, &labelWidth,
+ &height);
mePtr->height = height;
-
+
if (mePtr->type == CASCADE_ENTRY) {
- GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr,
- &modifierWidth, &accelWidth, &height);
- nonAccelMargin = 0;
+ GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr,
+ &modifierWidth, &accelWidth, &height);
+ nonAccelMargin = 0;
} else if (mePtr->accelLength == 0) {
- nonAccelMargin = mePtr->hideMargin ? 0
- : Tk_TextWidth(tkfont, "m", 1);
- accelWidth = modifierWidth = 0;
+ nonAccelMargin = mePtr->hideMargin ? 0
+ : Tk_TextWidth(tkfont, "m", 1);
+ accelWidth = modifierWidth = 0;
} else {
- labelWidth += Tk_TextWidth(tkfont, "m", 1);
- GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr,
- &modifierWidth, &accelWidth, &height);
- if (height > mePtr->height) {
- mePtr->height = height;
- }
- nonAccelMargin = 0;
+ labelWidth += Tk_TextWidth(tkfont, "m", 1);
+ GetMenuAccelGeometry(menuPtr, mePtr, tkfont,
+ fmPtr, &modifierWidth, &accelWidth, &height);
+ if (height > mePtr->height) {
+ mePtr->height = height;
+ }
+ nonAccelMargin = 0;
}
if (!(mePtr->hideMargin)) {
- GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont, fmPtr,
- &indicatorSpace, &height);
- if (height > mePtr->height) {
- mePtr->height = height;
- }
+ GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont,
+ fmPtr, &indicatorSpace, &height);
+ if (height > mePtr->height) {
+ mePtr->height = height;
+ }
} else {
- indicatorSpace = 0;
+ indicatorSpace = 0;
}
if (nonAccelMargin > maxNonAccelMargin) {
- maxNonAccelMargin = nonAccelMargin;
+ maxNonAccelMargin = nonAccelMargin;
}
if (accelWidth > maxAccelTextWidth) {
- maxAccelTextWidth = accelWidth;
+ maxAccelTextWidth = accelWidth;
}
if (modifierWidth > maxModifierWidth) {
- maxModifierWidth = modifierWidth;
+ maxModifierWidth = modifierWidth;
}
if (indicatorSpace > maxIndicatorSpace) {
- maxIndicatorSpace = indicatorSpace;
+ maxIndicatorSpace = indicatorSpace;
}
entryWidth = labelWidth + modifierWidth + accelWidth
+ nonAccelMargin;
if (entryWidth > maxWidth) {
- maxWidth = entryWidth;
+ maxWidth = entryWidth;
}
-
+
if (mePtr->accelLength > 0) {
- if (entryWidth > maxEntryWithAccelWidth) {
- maxEntryWithAccelWidth = entryWidth;
- }
+ if (entryWidth > maxEntryWithAccelWidth) {
+ maxEntryWithAccelWidth = entryWidth;
+ }
} else {
- if (entryWidth > maxEntryWithoutAccelWidth) {
- maxEntryWithoutAccelWidth = entryWidth;
- }
+ if (entryWidth > maxEntryWithoutAccelWidth) {
+ maxEntryWithoutAccelWidth = entryWidth;
+ }
}
-
+
mePtr->height += 2 * activeBorderWidth;
- }
- mePtr->y = y;
+ }
+ mePtr->y = y;
y += menuPtr->entries[i]->height + borderWidth;
if (y > windowHeight) {
windowHeight = y;
@@ -3269,11 +3357,11 @@ TkpComputeStandardMenuGeometry(
}
for (j = lastColumnBreak; j < menuPtr->numEntries; j++) {
- columnEntryPtr = menuPtr->entries[j];
- geometryPtr = (EntryGeometry *) columnEntryPtr->platformEntryData;
-
- columnEntryPtr->indicatorSpace = maxIndicatorSpace;
- columnEntryPtr->width = maxIndicatorSpace + maxWidth
+ columnEntryPtr = menuPtr->entries[j];
+ geometryPtr = (EntryGeometry *) columnEntryPtr->platformEntryData;
+
+ columnEntryPtr->indicatorSpace = maxIndicatorSpace;
+ columnEntryPtr->width = maxIndicatorSpace + maxWidth
+ 2 * activeBorderWidth;
geometryPtr->accelTextWidth = maxAccelTextWidth;
geometryPtr->modifierWidth = maxModifierWidth;
@@ -3281,21 +3369,21 @@ TkpComputeStandardMenuGeometry(
columnEntryPtr->entryFlags |= ENTRY_LAST_COLUMN;
if (maxEntryWithoutAccelWidth > maxEntryWithAccelWidth) {
geometryPtr->nonAccelMargin = maxEntryWithoutAccelWidth
- - maxEntryWithAccelWidth;
+ - maxEntryWithAccelWidth;
if (geometryPtr->nonAccelMargin > maxNonAccelMargin) {
- geometryPtr->nonAccelMargin = maxNonAccelMargin;
+ geometryPtr->nonAccelMargin = maxNonAccelMargin;
}
} else {
geometryPtr->nonAccelMargin = 0;
- }
+ }
}
windowWidth = x + maxIndicatorSpace + maxWidth
+ 2 * activeBorderWidth + borderWidth;
windowHeight += borderWidth;
-
+
/*
- * The X server doesn't like zero dimensions, so round up to at least 1 (a
- * zero-sized menu should never really occur, anyway).
+ * The X server doesn't like zero dimensions, so round up to at least
+ * 1 (a zero-sized menu should never really occur, anyway).
*/
if (windowWidth <= 0) {
@@ -3327,153 +3415,168 @@ TkpComputeStandardMenuGeometry(
static void
DrawMenuEntryLabel(
- TkMenu *menuPtr, /* The menu we are drawing */
- TkMenuEntry *mePtr, /* The entry we are drawing */
- Drawable d, /* What we are drawing into */
- GC gc, /* The gc we are drawing into */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
- int x, /* left edge */
- int y, /* right edge */
- int width, /* width of entry */
- int height) /* height of entry */
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* What we are drawing into */
+ GC gc, /* The gc we are drawing into */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated font metrics */
+ int x, /* left edge */
+ int y, /* right edge */
+ int width, /* width of entry */
+ int height) /* height of entry */
{
- int baseline, imageHeight, imageWidth;
+ int baseline;
int indicatorSpace = mePtr->indicatorSpace;
int leftEdge = x + indicatorSpace;
-
+ int imageHeight, imageWidth;
+
/*
* Draw label or bitmap or image for entry.
*/
baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
if (mePtr->image != NULL) {
- Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight);
- if ((mePtr->selectImage != NULL)
- && (mePtr->entryFlags & ENTRY_SELECTED)) {
- Tk_RedrawImage(mePtr->selectImage, 0, 0, imageWidth, imageHeight,
- d, leftEdge, (int) (y + (mePtr->height - imageHeight)/2));
- } else {
- Tk_RedrawImage(mePtr->image, 0, 0, imageWidth, imageHeight,
- d, leftEdge, (int) (y + (mePtr->height - imageHeight)/2));
- }
+ Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight);
+ if ((mePtr->selectImage != NULL)
+ && (mePtr->entryFlags & ENTRY_SELECTED)) {
+ Tk_RedrawImage(mePtr->selectImage, 0, 0,
+ imageWidth, imageHeight, d, leftEdge,
+ (int) (y + (mePtr->height - imageHeight)/2));
+ } else {
+ Tk_RedrawImage(mePtr->image, 0, 0, imageWidth,
+ imageHeight, d, leftEdge,
+ (int) (y + (mePtr->height - imageHeight)/2));
+ }
} else if (mePtr->bitmapPtr != NULL) {
- int width, height;
- Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
-
- Tk_SizeOfBitmap(menuPtr->display, bitmap, &width, &height);
- XCopyPlane(menuPtr->display, bitmap, d, gc, 0, 0,
- (unsigned) width, (unsigned) height, leftEdge,
- (int) (y + (mePtr->height - height)/2), 1);
+ int width, height;
+ Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
+ Tk_SizeOfBitmap(menuPtr->display,
+ bitmap, &width, &height);
+ XCopyPlane(menuPtr->display, bitmap, d, gc, 0, 0,
+ (unsigned) width, (unsigned) height, leftEdge,
+ (int) (y + (mePtr->height - height)/2), 1);
} else {
- if (mePtr->labelLength > 0) {
- Tcl_DString itemTextDString, convertedTextDString;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr destPort;
+ if (mePtr->labelLength > 0) {
+ Tcl_DString itemTextDString, convertedTextDString;
+ CGrafPtr saveWorld;
+ GDHandle saveDevice;
+ GWorldPtr destPort;
#ifdef USE_ATSU
- int xLocation, yLocation, runLengths, length, err;
- CFStringRef stringRef;
- ATSUTextLayout textLayout;
- UniCharCount runLength;
- ATSUStyle style;
- Str255 fontName;
- SInt16 fontSize;
- Style fontStyle;
- ATSUAttributeValuePtr valuePtr;
- ByteCount valueSize;
- Fixed fixedSize;
- short iFONDNumber;
- ATSUFontID fontID;
- ATSUAttributeTag tag;
-
- GetThemeFont(kThemeMenuItemFont, smSystemScript, fontName,
- &fontSize, &fontStyle);
- err = ATSUCreateStyle(&style);
- LOG_ON_ERROR(ATSUCreateStyle);
- if (err != noErr) {
- return;
- }
- fixedSize = fontSize<<16;
- tag = kATSUSizeTag;
- valueSize = sizeof(fixedSize);
- valuePtr = &fixedSize;
+ int xLocation;
+ int yLocation;
+ int runLengths;
+ CFStringRef stringRef;
+ ATSUTextLayout textLayout;
+ UniCharCount runLength;
+ ATSUStyle style;
+ int length;
+ int err;
+ Str255 fontName;
+ SInt16 fontSize;
+ Style fontStyle;
+ ATSUAttributeValuePtr valuePtr;
+ ByteCount valueSize;
+ Fixed fixedSize;
+ short iFONDNumber;
+ ATSUFontID fontID;
+ ATSUAttributeTag tag;
+
+ GetThemeFont (kThemeMenuItemFont, smSystemScript, fontName, &fontSize, &fontStyle);
+ if ((err = ATSUCreateStyle(&style)) != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"ATSUCreateStyle failed, %d\n", err);
+#endif
+ return;
+ }
+ fixedSize = fontSize<<16;
+ tag = kATSUSizeTag;
+ valueSize = sizeof(fixedSize);
+ valuePtr = &fixedSize;
err = ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr);
- LOG_ON_ERROR(ATSUSetAttributes);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"ATSUSetAttributes failed,%d\n", err );
+#endif
+ }
GetFNum(fontName, &iFONDNumber);
- ATSUFONDtoFontID(iFONDNumber, NULL, &fontID);
- tag = kATSUFontTag;
- valueSize = sizeof(fontID);
- valuePtr = &fontID;
+ ATSUFONDtoFontID(iFONDNumber, NULL, &fontID);
+ tag = kATSUFontTag;
+ valueSize = sizeof(fontID);
+ valuePtr = &fontID;
err = ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr);
- LOG_ON_ERROR(ATSUSetAttributes);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"ATSUSetAttributes failed,%d\n", err );
#endif
+ }
- GetEntryText(mePtr, &itemTextDString);
+#endif
+
+ GetEntryText(mePtr, &itemTextDString);
#ifdef USE_ATSU
- runLengths = 1;
- length = Tcl_DStringLength(&itemTextDString);
- stringRef = CFStringCreateWithCString(NULL,
- Tcl_DStringValue(&itemTextDString),
- kCFStringEncodingUTF8);
- if (!stringRef) {
- LOG_MSG("CFStringCreateWithCString failed");
- }
- err = ATSUCreateTextLayoutWithTextPtr(
- CFStringGetCharactersPtr(stringRef), 0, length, length, 1,
- &runLengths, &style, &textLayout);
- LOG_ON_ERROR(ATSUCreateTextLayoutWithTextPtr);
- if (err != noErr) {
- return;
- }
+ runLengths = 1;
+ length = Tcl_DStringLength(&itemTextDString);
+ stringRef = CFStringCreateWithCString(NULL, Tcl_DStringValue(&itemTextDString),
+ kCFStringEncodingUTF8);
+ if (!stringRef) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"CFStringCreateWithCString failed\n");
#endif
+ }
+ err = ATSUCreateTextLayoutWithTextPtr(CFStringGetCharactersPtr(stringRef),
+ 0, length, length,
+ 1, &runLengths, &style, &textLayout)
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"ATSUCreateTextLayoutWithTextPtr failed, %d\n", err);
+#endif
+ return;
+ }
+#endif
+
+ /* Somehow DrawChars is changing the colors, it is odd, since
+ it works for the Apple Platinum Appearance, but not for
+ some Kaleidoscope Themes... Untill I can figure out what
+ exactly is going on, this will have to do: */
- /*
- * Somehow DrawChars is changing the colors, it is odd, since it
- * works for the Apple Platinum Appearance, but not for some
- * Kaleidoscope Themes... Until I can figure out what exactly is
- * going on, this will have to do:
- */
-
- destPort = TkMacOSXGetDrawablePort(d);
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(destPort, NULL);
- TkMacOSXSetUpGraphicsPort(gc, destPort);
+ destPort = TkMacOSXGetDrawablePort(d);
+ GetGWorld(&saveWorld, &saveDevice);
+ SetGWorld(destPort, NULL);
+ TkMacOSXSetUpGraphicsPort(gc, destPort);
MoveTo((short) leftEdge, (short) baseline);
- Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding,
- Tcl_DStringValue(&itemTextDString),
- Tcl_DStringLength(&itemTextDString),
- &convertedTextDString);
+ Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, Tcl_DStringValue(&itemTextDString),
+ Tcl_DStringLength(&itemTextDString), &convertedTextDString);
#ifdef USE_ATSU
- xLocation = leftEdge << 16;
- yLocation = baseline << 16;
- ATSUDrawText(textLayout,kATSUFromTextBeginning, kATSUToTextEnd,
- xLocation, yLocation);
- ATSUDisposeTextLayout(textLayout);
- CFRelease(stringRef);
+ xLocation = leftEdge << 16;
+ yLocation = baseline << 16;
+ ATSUDrawText(textLayout,kATSUFromTextBeginning, kATSUToTextEnd, xLocation, yLocation);
+ ATSUDisposeTextLayout(textLayout);
+ CFRelease(stringRef);
#else
- DrawText(Tcl_DStringValue(&convertedTextDString), 0,
- Tcl_DStringLength(&convertedTextDString));
+ DrawText(Tcl_DStringValue(&convertedTextDString), 0,
+ Tcl_DStringLength(&convertedTextDString));
#endif
-
+
/* Tk_DrawChars(menuPtr->display, d, gc,
- tkfont, Tcl_DStringValue(&itemTextDString),
+ tkfont, Tcl_DStringValue(&itemTextDString),
Tcl_DStringLength(&itemTextDString),
leftEdge, baseline); */
-
+
Tcl_DStringFree(&convertedTextDString);
Tcl_DStringFree(&itemTextDString);
- }
+ }
}
if (mePtr->state == ENTRY_DISABLED) {
if (menuPtr->disabledFgPtr == NULL) {
- } else if ((mePtr->image != NULL)
+ } else if ((mePtr->image != NULL)
&& (menuPtr->disabledImageGC != None)) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
- leftEdge, (int) (y + (mePtr->height - imageHeight)/2),
+ leftEdge,
+ (int) (y + (mePtr->height - imageHeight)/2),
(unsigned) imageWidth, (unsigned) imageHeight);
}
}
@@ -3484,41 +3587,41 @@ DrawMenuEntryLabel(
*
* DrawMenuEntryBackground --
*
- * This procedure draws the background part of a menu entry. Under
- * Appearance, we only draw the background if the entry's border is set,
- * we DO NOT inherit it from the menu...
+ * This procedure draws the background part of a menu entry.
+ * Under Appearance, we only draw the background if the entry's
+ * border is set, we DO NOT inherit it from the menu...
*
* Results:
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its current mode.
+ * Commands are output to X to display the menu in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
static void
DrawMenuEntryBackground(
- TkMenu *menuPtr, /* The menu we are drawing. */
- TkMenuEntry *mePtr, /* The entry we are drawing. */
- Drawable d, /* What we are drawing into */
- Tk_3DBorder activeBorder, /* Border for active items */
- Tk_3DBorder bgBorder, /* Border for the background */
- int x, /* left edge */
- int y, /* top edge */
- int width, /* width of rectangle to draw */
- int height) /* height of rectangle to draw */
+ TkMenu *menuPtr, /* The menu we are drawing. */
+ TkMenuEntry *mePtr, /* The entry we are drawing. */
+ Drawable d, /* What we are drawing into */
+ Tk_3DBorder activeBorder, /* Border for active items */
+ Tk_3DBorder bgBorder, /* Border for the background */
+ int x, /* left edge */
+ int y, /* top edge */
+ int width, /* width of rectangle to draw */
+ int height) /* height of rectangle to draw */
{
if ((menuPtr->menuType == TEAROFF_MENU)
- || ((mePtr->state == ENTRY_ACTIVE)
- && (mePtr->activeBorderPtr != None))
- || ((mePtr->state != ENTRY_ACTIVE)
- && (mePtr->borderPtr != None))) {
- if (mePtr->state == ENTRY_ACTIVE) {
+ || ((mePtr->state == ENTRY_ACTIVE)
+ && (mePtr->activeBorderPtr != None))
+ || ((mePtr->state != ENTRY_ACTIVE) && (mePtr->borderPtr != None))) {
+ if (mePtr->state == ENTRY_ACTIVE) {
bgBorder = activeBorder;
- }
- Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height,
- 0, TK_RELIEF_FLAT);
+ }
+ Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder,
+ x, y, width, height, 0, TK_RELIEF_FLAT);
}
}
@@ -3541,34 +3644,35 @@ DrawMenuEntryBackground(
static void
GetMenuLabelGeometry(
- TkMenuEntry *mePtr, /* The entry we are computing */
- Tk_Font tkfont, /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr,/* The precalculated metrics */
- int *widthPtr, /* The resulting width of the label portion */
- int *heightPtr) /* The resulting height of the label
- * portion. */
+ TkMenuEntry *mePtr, /* The entry we are computing */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr, /* The precalculated metrics */
+ int *widthPtr, /* The resulting width of the label
+ * portion */
+ int *heightPtr) /* The resulting height of the label
+ * portion */
{
TkMenu *menuPtr = mePtr->menuPtr;
-
+
if (mePtr->image != NULL) {
- Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr);
+ Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr);
} else if (mePtr->bitmapPtr != NULL) {
- Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
- Tk_SizeOfBitmap(menuPtr->display, bitmap, widthPtr, heightPtr);
+ Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
+ Tk_SizeOfBitmap(menuPtr->display, bitmap, widthPtr, heightPtr);
} else {
- *heightPtr = fmPtr->linespace;
-
- if (mePtr->labelPtr != NULL) {
- Tcl_DString itemTextDString;
-
- GetEntryText(mePtr, &itemTextDString);
- *widthPtr = Tk_TextWidth(tkfont,
- Tcl_DStringValue(&itemTextDString),
- Tcl_DStringLength(&itemTextDString));
- Tcl_DStringFree(&itemTextDString);
- } else {
- *widthPtr = 0;
- }
+ *heightPtr = fmPtr->linespace;
+
+ if (mePtr->labelPtr != NULL) {
+ Tcl_DString itemTextDString;
+
+ GetEntryText(mePtr, &itemTextDString);
+ *widthPtr = Tk_TextWidth(tkfont,
+ Tcl_DStringValue(&itemTextDString),
+ Tcl_DStringLength(&itemTextDString));
+ Tcl_DStringFree(&itemTextDString);
+ } else {
+ *widthPtr = 0;
+ }
}
*heightPtr += 1;
}
@@ -3578,8 +3682,8 @@ GetMenuLabelGeometry(
*
* MenuSelectEvent --
*
- * Generates a "MenuSelect" virtual event. This can be used to do
- * context-sensitive menu help.
+ * Generates a "MenuSelect" virtual event. This can be used to
+ * do context-sensitive menu help.
*
* Results:
* None.
@@ -3595,7 +3699,7 @@ MenuSelectEvent(
TkMenu *menuPtr) /* the menu we have selected. */
{
XVirtualEvent event;
-
+
bzero(&event, sizeof(XVirtualEvent));
event.type = VirtualEvent;
event.serial = menuPtr->display->request;
@@ -3606,9 +3710,9 @@ MenuSelectEvent(
event.root = XRootWindow(menuPtr->display, 0);
event.subwindow = None;
event.time = TkpGetMS();
-
- XQueryPointer(NULL, None, NULL, NULL, &event.x_root, &event.y_root,
- NULL, NULL, &event.state);
+
+ XQueryPointer(NULL, None, NULL, NULL,
+ &event.x_root, &event.y_root, NULL, NULL, &event.state);
event.same_screen = true;
event.name = Tk_GetUid("MenuSelect");
Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
@@ -3636,17 +3740,17 @@ RecursivelyClearActiveMenu(
{
int i;
TkMenuEntry *mePtr;
-
+
TkActivateMenuEntry(menuPtr, -1);
MenuSelectEvent(menuPtr);
for (i = 0; i < menuPtr->numEntries; i++) {
- mePtr = menuPtr->entries[i];
- if (mePtr->type == CASCADE_ENTRY) {
- if ((mePtr->childMenuRefPtr != NULL)
- && (mePtr->childMenuRefPtr->menuPtr != NULL)) {
- RecursivelyClearActiveMenu(mePtr->childMenuRefPtr->menuPtr);
- }
- }
+ mePtr = menuPtr->entries[i];
+ if (mePtr->type == CASCADE_ENTRY) {
+ if ((mePtr->childMenuRefPtr != NULL)
+ && (mePtr->childMenuRefPtr->menuPtr != NULL)) {
+ RecursivelyClearActiveMenu(mePtr->childMenuRefPtr->menuPtr);
+ }
+ }
}
}
@@ -3655,8 +3759,8 @@ RecursivelyClearActiveMenu(
*
* InvalidateMDEFRgns --
*
- * Invalidates the regions covered by menus that did redrawing and might
- * be damaged.
+ * Invalidates the regions covered by menus that did redrawing and
+ * might be damaged.
*
* Results:
* None.
@@ -3671,33 +3775,31 @@ void
InvalidateMDEFRgns(void)
{
GDHandle saveDevice;
- GWorldPtr saveWorld;
+ GWorldPtr saveWorld, destPort;
+ Point scratch;
+ MacDrawable *macDraw;
TkMacOSXWindowList *listPtr;
-
+
if (totalMenuRgn == NULL) {
- return;
+ return;
}
-
+
GetGWorld(&saveWorld, &saveDevice);
- for (listPtr = tkMacOSXWindowListPtr ; listPtr != NULL;
- listPtr = listPtr->nextPtr) {
- MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(listPtr->winPtr);
-
- if (macDraw->flags & TK_DRAWN_UNDER_MENU) {
- GWorldPtr destPort =
- TkMacOSXGetDrawablePort(Tk_WindowId(listPtr->winPtr));
- Point scratch;
-
- SetGWorld(destPort, NULL);
- scratch.h = scratch.v = 0;
- GlobalToLocal(&scratch);
- OffsetRgn(totalMenuRgn, scratch.v, scratch.h);
- InvalWindowRgn(GetWindowFromPort(destPort),totalMenuRgn);
- OffsetRgn(totalMenuRgn, -scratch.v, -scratch.h);
- macDraw->flags &= ~TK_DRAWN_UNDER_MENU;
- }
+ for (listPtr = tkMacOSXWindowListPtr ; listPtr != NULL;
+ listPtr = listPtr->nextPtr) {
+ macDraw = (MacDrawable *) Tk_WindowId(listPtr->winPtr);
+ if (macDraw->flags & TK_DRAWN_UNDER_MENU) {
+ destPort = TkMacOSXGetDrawablePort(Tk_WindowId(listPtr->winPtr));
+ SetGWorld(destPort, NULL);
+ scratch.h = scratch.v = 0;
+ GlobalToLocal(&scratch);
+ OffsetRgn(totalMenuRgn, scratch.v, scratch.h);
+ InvalWindowRgn(GetWindowFromPort(destPort),totalMenuRgn);
+ OffsetRgn(totalMenuRgn, -scratch.v, -scratch.h);
+ macDraw->flags &= ~TK_DRAWN_UNDER_MENU;
+ }
}
-
+
SetGWorld(saveWorld, saveDevice);
SetEmptyRgn(totalMenuRgn);
}
@@ -3722,20 +3824,20 @@ void
TkMacOSXClearMenubarActive(void)
{
TkMenuReferences *menuBarRefPtr;
-
+
if (currentMenuBarName != NULL) {
- menuBarRefPtr = TkFindMenuReferences(currentMenuBarInterp,
- currentMenuBarName);
- if ((menuBarRefPtr != NULL) && (menuBarRefPtr->menuPtr != NULL)) {
- TkMenu *menuPtr;
-
- for (menuPtr=menuBarRefPtr->menuPtr->masterMenuPtr; menuPtr!=NULL;
- menuPtr = menuPtr->nextInstancePtr) {
- if (menuPtr->menuType == MENUBAR) {
- RecursivelyClearActiveMenu(menuPtr);
- }
- }
- }
+ menuBarRefPtr = TkFindMenuReferences(currentMenuBarInterp,
+ currentMenuBarName);
+ if ((menuBarRefPtr != NULL) && (menuBarRefPtr->menuPtr != NULL)) {
+ TkMenu *menuPtr;
+
+ for (menuPtr = menuBarRefPtr->menuPtr->masterMenuPtr; menuPtr != NULL;
+ menuPtr = menuPtr->nextInstancePtr) {
+ if (menuPtr->menuType == MENUBAR) {
+ RecursivelyClearActiveMenu(menuPtr);
+ }
+ }
+ }
}
InvalidateMDEFRgns();
}
@@ -3746,8 +3848,8 @@ TkMacOSXClearMenubarActive(void)
* TkpMenuNotifyToplevelCreate --
*
* This routine reconfigures the menu and the clones indicated by
- * menuName becuase a toplevel has been created and any system menus need
- * to be created. Only applicable to Windows.
+ * menuName becuase a toplevel has been created and any system
+ * menus need to be created. Only applicable to Windows.
*
* Results:
* None.
@@ -3760,8 +3862,9 @@ TkMacOSXClearMenubarActive(void)
void
TkpMenuNotifyToplevelCreate(
- Tcl_Interp *interp, /* The interp the menu lives in. */
- char *menuName) /* The name of the menu to reconfigure. */
+ Tcl_Interp *interp, /* The interp the menu lives in. */
+ char *menuName) /* The name of the menu to
+ * reconfigure. */
{
/*
* Nothing to do.
@@ -3786,7 +3889,7 @@ TkpMenuNotifyToplevelCreate(
void
TkpMenuInit(void)
-{
+{
lastMenuID = 256;
Tcl_InitHashTable(&commandTable, TCL_ONE_WORD_KEYS);
currentMenuBarOwner = NULL;
@@ -3797,18 +3900,18 @@ TkpMenuInit(void)
currentMenuBarName = NULL;
windowListPtr = NULL;
- tkThemeMenuItemDrawingUPP =
- NewMenuItemDrawingUPP(ThemeMenuItemDrawingProc);
-
- /*
- * We should just hardcode the utf-8 ellipsis character into
- * 'elipsisString' here
+ tkThemeMenuItemDrawingUPP
+ = NewMenuItemDrawingUPP(ThemeMenuItemDrawingProc);
+
+ /*
+ * We should just hardcode the utf-8 ellipsis character into
+ * 'elipsisString' here
*/
-
- Tcl_ExternalToUtf(NULL, Tcl_GetEncoding(NULL, "macRoman"),
- "\311", /* ellipsis character */
- -1, 0, NULL, elipsisString, TCL_UTF_MAX + 1, NULL, NULL, NULL);
-
+ Tcl_ExternalToUtf(NULL, Tcl_GetEncoding(NULL, "macRoman"),
+ "\311", /* ellipsis character */
+ -1, 0, NULL, elipsisString,
+ TCL_UTF_MAX + 1, NULL, NULL, NULL);
+
useMDEFVar = Tcl_NewStringObj("::tk::mac::useCustomMDEF", -1);
}
@@ -3817,7 +3920,8 @@ TkpMenuInit(void)
*
* TkpMenuThreadInit --
*
- * Does platform-specific initialization of thread-specific menu state.
+ * Does platform-specific initialization of thread-specific
+ * menu state.
*
* Results:
* None.
@@ -3829,7 +3933,7 @@ TkpMenuInit(void)
*/
void
-TkpMenuThreadInit(void)
+TkpMenuThreadInit()
{
/*
* Nothing to do.
@@ -3841,28 +3945,28 @@ TkpMenuThreadInit(void)
*
* TkpPreprocessMacMenu --
*
- * Handle preprocessing of menubar if it exists.
+ * Handle preprocessing of menubar if it exists.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * All post commands for the current menubar get executed.
+ * All post commands for the current menubar get executed.
*
*----------------------------------------------------------------------
*/
void
-TkMacOSXPreprocessMenu(void)
+TkMacOSXPreprocessMenu()
{
- if ((currentMenuBarName != NULL) && (currentMenuBarInterp != NULL)) {
- TkMenuReferences *mbRefPtr =
- TkFindMenuReferences(currentMenuBarInterp,currentMenuBarName);
-
- if ((mbRefPtr != NULL) && (mbRefPtr->menuPtr != NULL)) {
- int code;
+ TkMenuReferences *mbRefPtr;
+ int code;
- Tcl_Preserve((ClientData) currentMenuBarInterp);
+ if ((currentMenuBarName != NULL) && (currentMenuBarInterp != NULL)) {
+ mbRefPtr = TkFindMenuReferences(currentMenuBarInterp,
+ currentMenuBarName);
+ if ((mbRefPtr != NULL) && (mbRefPtr->menuPtr != NULL)) {
+ Tcl_Preserve((ClientData)currentMenuBarInterp);
code = TkPreprocessMenu(mbRefPtr->menuPtr->masterMenuPtr);
if ((code != TCL_OK) && (code != TCL_CONTINUE)
&& (code != TCL_BREAK)) {
@@ -3870,8 +3974,8 @@ TkMacOSXPreprocessMenu(void)
"\n (menu preprocess)");
Tcl_BackgroundError(currentMenuBarInterp);
}
- Tcl_Release((ClientData) currentMenuBarInterp);
- }
+ Tcl_Release((ClientData)currentMenuBarInterp);
+ }
}
}
@@ -3880,178 +3984,188 @@ TkMacOSXPreprocessMenu(void)
*
* MenuDefProc --
*
- * This routine is the MDEF handler for Tk. It receives all messages for
- * the menu and dispatches them.
+ * This routine is the MDEF handler for Tk. It receives all messages
+ * for the menu and dispatches them.
*
* Results:
* None.
*
* Side effects:
* This routine causes menus to be drawn and will certainly allocate
- * memory as a result. Also, the menu can scroll up and down, and various
- * other interface actions can take place.
+ * memory as a result. Also, the menu can scroll up and down, and
+ * various other interface actions can take place.
*
*----------------------------------------------------------------------
*/
static void
MenuDefProc(
- SInt16 message, /* What action are we taking? */
- MenuRef menu, /* The menu we are working with */
- Rect *menuRectPtr, /* A pointer to the rect for the whole
- * menu. */
- Point hitPt, /* Where the mouse was clicked for the
- * appropriate messages. */
- SInt16 *whichItem) /* Output result. Which item was hit by the
- * user? */
+ SInt16 message, /* What action are we taking? */
+ MenuRef menu, /* The menu we are working with */
+ Rect *menuRectPtr, /* A pointer to the rect for the
+ * whole menu. */
+ Point hitPt, /* Where the mouse was clicked for
+ * the appropriate messages. */
+ SInt16 *whichItem) /* Output result. Which item was
+ * hit by the user? */
{
TkMenu *menuPtr;
Tcl_HashEntry *commandEntryPtr;
int maxMenuHeight;
MenuID menuID;
BitMap screenBits;
-
+
menuID = GetMenuID(menu);
commandEntryPtr = Tcl_FindHashEntry(&commandTable, (char *) ((int)menuID));
-
+
if (commandEntryPtr) {
- menuPtr = (TkMenu *) Tcl_GetHashValue(commandEntryPtr);
+ menuPtr = (TkMenu *) Tcl_GetHashValue(commandEntryPtr);
} else {
- menuPtr = NULL;
+ menuPtr = NULL;
}
switch (message) {
- case kMenuInitMsg:
- *whichItem = noErr;
- break;
- case kMenuDisposeMsg:
- break;
- case kMenuHiliteItemMsg:
- HandleMenuHiliteMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
- break;
- case kMenuCalcItemMsg:
- HandleMenuCalcItemMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
- break;
- case kMenuDrawItemsMsg:
- /*
- * We do nothing here, because we don't support the Menu Managers
- * dynamic item groups
- */
-
- break;
- case kMenuThemeSavvyMsg:
- *whichItem = kThemeSavvyMenuResponse;
- break;
- case kMenuSizeMsg:
- GetQDGlobalsScreenBits(&screenBits);
- maxMenuHeight = screenBits.bounds.bottom
- - screenBits.bounds.top - GetMBarHeight() - SCREEN_MARGIN;
- SetMenuWidth(menu, menuPtr->totalWidth);
- SetMenuHeight(menu, maxMenuHeight<menuPtr->totalHeight
- ? maxMenuHeight : menuPtr->totalHeight);
- break;
- case kMenuDrawMsg:
- HandleMenuDrawMsg(menu, menuRectPtr, hitPt, whichItem, menuPtr);
- break;
- case kMenuFindItemMsg:
- HandleMenuFindItemsMsg(menu, menuRectPtr, hitPt, whichItem, menuPtr);
- break;
- case kMenuPopUpMsg:
- HandleMenuPopUpMsg(menu, menuRectPtr, hitPt, whichItem, menuPtr);
- break;
+ case kMenuInitMsg:
+ *whichItem = noErr;
+ break;
+ case kMenuDisposeMsg:
+ break;
+ case kMenuHiliteItemMsg: {
+ HandleMenuHiliteMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
+ break;
+ }
+ case kMenuCalcItemMsg:
+ HandleMenuCalcItemMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
+ break;
+ case kMenuDrawItemsMsg: {
+ /*
+ * We do nothing here, because we don't support the Menu Managers
+ * dynamic item groups
+ */
+
+ break;
+ }
+ case kMenuThemeSavvyMsg:
+ *whichItem = kThemeSavvyMenuResponse;
+ break;
+ case kMenuSizeMsg:
+ GetQDGlobalsScreenBits(&screenBits);
+ maxMenuHeight = screenBits.bounds.bottom
+ - screenBits.bounds.top
+ - GetMBarHeight() - SCREEN_MARGIN;
+ SetMenuWidth(menu, menuPtr->totalWidth );
+ SetMenuHeight(menu,maxMenuHeight < menuPtr->totalHeight ? maxMenuHeight : menuPtr->totalHeight );
+ break;
+ case kMenuDrawMsg:
+ HandleMenuDrawMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
+ break;
+ case kMenuFindItemMsg:
+ HandleMenuFindItemsMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
+ break;
+ case kMenuPopUpMsg:
+ HandleMenuPopUpMsg (menu, menuRectPtr, hitPt, whichItem, menuPtr);
+ break;
}
}
void
-HandleMenuHiliteMsg(
- MenuRef menu,
- Rect *menuRectPtr,
- Point hitPt,
- SInt16 *whichItem,
- TkMenu *menuPtr)
+HandleMenuHiliteMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr)
{
TkMenuEntry *mePtr = NULL;
Tk_Font tkfont;
Tk_FontMetrics fontMetrics;
- int err, oldItem, newItem = -1;
- MDEFHiliteItemData *hidPtr = (MDEFHiliteItemData *) whichItem;
- MenuTrackingData mtd, *mtdPtr = &mtd;
-
+ int oldItem;
+ int newItem = -1;
+ MDEFHiliteItemData * hidPtr = ( MDEFHiliteItemData *)whichItem;
+ MenuTrackingData mtd, *mtdPtr = &mtd;
+ int err;
oldItem = hidPtr->previousItem - 1;
newItem = hidPtr->newItem - 1;
-
+
err = GetMenuTrackingData(menu, mtdPtr);
- LOG_ON_ERROR(GetMenuTrackingData);
if (err !=noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"GetMenuTrackingData failed : %d\n", err );
+#endif
return;
}
-
+
if (oldItem >= 0) {
- Rect oldItemRect;
- int width;
-
- mePtr = menuPtr->entries[oldItem];
- if (mePtr->fontPtr == NULL) {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
- } else {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
- }
- Tk_GetFontMetrics(tkfont, &fontMetrics);
-
- width = (mePtr->entryFlags & ENTRY_LAST_COLUMN)
- ? menuPtr->totalWidth - mePtr->x : mePtr->width;
-
- /*
- * In Aqua, have to call EraseMenuBackground when you overdraw a
- * previously selected menu item, otherwise you will see the old
- * select highlight under the transparency of the new menu item.
- */
-
- oldItemRect.left = menuRectPtr->left + mePtr->x;
- oldItemRect.right = oldItemRect.left +width;
- oldItemRect.top = mtdPtr->virtualMenuTop + mePtr->y;
- oldItemRect.bottom = oldItemRect.top + mePtr->height;
-
- EraseMenuBackground(menu, & oldItemRect, NULL);
-
- AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
- (Drawable) &macMDEFDrawable, &fontMetrics, tkfont,
- oldItemRect.left, oldItemRect.top, width, mePtr->height);
+ Rect oldItemRect;
+ int width;
+
+ mePtr = menuPtr->entries[oldItem];
+ if (mePtr->fontPtr == NULL) {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin,
+ menuPtr->fontPtr);
+ } else {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin,
+ mePtr->fontPtr);
+ }
+ Tk_GetFontMetrics(tkfont, &fontMetrics);
+
+ width = (mePtr->entryFlags & ENTRY_LAST_COLUMN)
+ ? menuPtr->totalWidth - mePtr->x : mePtr->width;
+
+ /*
+ * In Aqua, have to call EraseMenuBackground when you overdraw
+ * a previously selected menu item, otherwise you will see the
+ * old select highlight under the transparency of the new menu item.
+ */
+
+ oldItemRect.left = menuRectPtr->left + mePtr->x;
+ oldItemRect.right = oldItemRect.left +width;
+ oldItemRect.top = mtdPtr->virtualMenuTop + mePtr->y;
+ oldItemRect.bottom = oldItemRect.top + mePtr->height;
+
+ EraseMenuBackground(menu, & oldItemRect, NULL);
+
+ AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
+ (Drawable) &macMDEFDrawable, &fontMetrics, tkfont,
+ oldItemRect.left,
+ oldItemRect.top,
+ width,
+ mePtr->height);
}
- if (newItem != -1) {
- mePtr = menuPtr->entries[newItem];
- if (mePtr->state != ENTRY_DISABLED) {
- TkActivateMenuEntry(menuPtr, newItem);
- }
- if (mePtr->fontPtr == NULL) {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
- } else {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
- }
- Tk_GetFontMetrics(tkfont, &fontMetrics);
- AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
- (Drawable) &macMDEFDrawable, &fontMetrics, tkfont,
- menuRectPtr->left + mePtr->x,
- mtdPtr->virtualMenuTop + mePtr->y,
- (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
- menuPtr->totalWidth - mePtr->x : mePtr->width,
- mePtr->height);
+ if (newItem != -1) {
+ mePtr = menuPtr->entries[newItem];
+ if (mePtr->state != ENTRY_DISABLED) {
+ TkActivateMenuEntry(menuPtr, newItem);
+ }
+ if (mePtr->fontPtr == NULL) {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
+ } else {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
+ }
+ Tk_GetFontMetrics(tkfont, &fontMetrics);
+ AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
+ (Drawable) &macMDEFDrawable, &fontMetrics, tkfont,
+ menuRectPtr->left + mePtr->x,
+ mtdPtr->virtualMenuTop + mePtr->y,
+ (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
+ menuPtr->totalWidth - mePtr->x : mePtr->width,
+ mePtr->height);
}
tkUseMenuCascadeRgn = 1;
MenuSelectEvent(menuPtr);
Tcl_ServiceAll();
tkUseMenuCascadeRgn = 0;
if (newItem!=-1 && mePtr->state != ENTRY_DISABLED) {
- TkActivateMenuEntry(menuPtr, -1);
+ TkActivateMenuEntry(menuPtr, -1);
}
+
}
-
+
/*
*----------------------------------------------------------------------
*
- * HandleMenuDrawMsg --
+ * HandleMenuDrawMsg --
*
- * It handles the MenuDefProc's draw message.
+ * It handles the MenuDefProc's draw message.
*
* Results:
* A menu entry is drawn
@@ -4061,266 +4175,289 @@ HandleMenuHiliteMsg(
*
*----------------------------------------------------------------------
*/
-
void
-HandleMenuDrawMsg(
- MenuRef menu,
- Rect *menuRectPtr,
- Point hitPt,
- SInt16 *whichItem,
- TkMenu *menuPtr)
+HandleMenuDrawMsg(MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr)
{
Tk_Font tkfont, menuFont;
- Tk_FontMetrics fontMetrics, entryMetrics, *fmPtr;
+ Tk_FontMetrics fontMetrics, entryMetrics;
+ Tk_FontMetrics *fmPtr;
TkMenuEntry *mePtr;
int i;
GDHandle device;
TkMenu *searchMenuPtr;
Rect menuClipRect;
ThemeMenuType menuType;
- MenuTrackingData *mtdPtr = (MenuTrackingData *) whichItem;
-
+ MenuTrackingData * mtdPtr = (MenuTrackingData *)whichItem;
/*
- * Store away the menu rectangle so we can keep track of the different
- * regions that the menu obscures.
- */
-
+ * Store away the menu rectangle so we can keep track of the
+ * different regions that the menu obscures.
+ */
+
((MacMenu *) menuPtr->platformData)->menuRect = *menuRectPtr;
if (tkMenuCascadeRgn == NULL) {
- tkMenuCascadeRgn = NewRgn();
+ tkMenuCascadeRgn = NewRgn();
}
if (utilRgn == NULL) {
- utilRgn = NewRgn();
+ utilRgn = NewRgn();
}
if (totalMenuRgn == NULL) {
- totalMenuRgn = NewRgn();
+ totalMenuRgn = NewRgn();
}
SetEmptyRgn(tkMenuCascadeRgn);
for (searchMenuPtr = menuPtr; searchMenuPtr != NULL; ) {
- RectRgn(utilRgn,
- &((MacMenu *) searchMenuPtr->platformData)->menuRect);
- InsetRgn(utilRgn, -1, -1);
- UnionRgn(tkMenuCascadeRgn, utilRgn, tkMenuCascadeRgn);
- OffsetRgn(utilRgn, 1, 1);
- UnionRgn(tkMenuCascadeRgn, utilRgn, tkMenuCascadeRgn);
-
- if (searchMenuPtr->menuRefPtr->parentEntryPtr == NULL) {
- break;
- }
- searchMenuPtr = searchMenuPtr->menuRefPtr->parentEntryPtr->menuPtr;
- if (searchMenuPtr->menuType == MENUBAR) {
- break;
- }
+ RectRgn(utilRgn,
+ &((MacMenu *) searchMenuPtr->platformData)->menuRect);
+ InsetRgn(utilRgn, -1, -1);
+ UnionRgn(tkMenuCascadeRgn, utilRgn, tkMenuCascadeRgn);
+ OffsetRgn(utilRgn, 1, 1);
+ UnionRgn(tkMenuCascadeRgn, utilRgn, tkMenuCascadeRgn);
+
+ if (searchMenuPtr->menuRefPtr->parentEntryPtr != NULL) {
+ searchMenuPtr = searchMenuPtr->menuRefPtr
+ ->parentEntryPtr->menuPtr;
+ } else {
+ break;
+ }
+ if (searchMenuPtr->menuType == MENUBAR) {
+ break;
+ }
}
UnionRgn(totalMenuRgn, tkMenuCascadeRgn, totalMenuRgn);
SetEmptyRgn(utilRgn);
-
+
/*
- * Now draw the background if Appearance is present...
- */
-
+ * Now draw the background if Appearance is present...
+ */
+
GetGWorld(&macMDEFDrawable.grafPtr, &device);
-
+
if (menuPtr->menuRefPtr->topLevelListPtr != NULL) {
- menuType = kThemeMenuTypePullDown;
+ menuType = kThemeMenuTypePullDown;
} else if (menuPtr->menuRefPtr->parentEntryPtr != NULL) {
- menuType = kThemeMenuTypeHierarchical;
+ menuType = kThemeMenuTypeHierarchical;
} else {
- menuType = kThemeMenuTypePopUp;
+ menuType = kThemeMenuTypePopUp;
}
-
+
DrawMenuBackground(menuRectPtr, (Drawable) &macMDEFDrawable, menuType);
-
+
/*
- * Next, figure out scrolling information.
- */
-
+ * Next, figure out scrolling information.
+ */
+
menuClipRect = *menuRectPtr;
- if ((menuClipRect.bottom - menuClipRect.top) < menuPtr->totalHeight) {
- if (mtdPtr->virtualMenuTop < menuRectPtr->top) {
- DrawSICN(SICN_RESOURCE_NUMBER, UP_ARROW,
- (Drawable) &macMDEFDrawable, menuPtr->textGC,
- menuRectPtr->left + menuPtr->entries[1]->indicatorSpace,
- menuRectPtr->top);
- menuClipRect.top += SICN_HEIGHT;
- }
- if (mtdPtr->virtualMenuTop+menuPtr->totalHeight>menuRectPtr->bottom) {
- DrawSICN(SICN_RESOURCE_NUMBER, DOWN_ARROW,
- (Drawable) &macMDEFDrawable, menuPtr->textGC,
- menuRectPtr->left + menuPtr->entries[1]->indicatorSpace,
- menuRectPtr->bottom - SICN_HEIGHT);
- menuClipRect.bottom -= SICN_HEIGHT;
- }
- GetClip(utilRgn);
+ if ((menuClipRect.bottom - menuClipRect.top)
+ < menuPtr->totalHeight) {
+ if (mtdPtr->virtualMenuTop < menuRectPtr->top) {
+ DrawSICN(SICN_RESOURCE_NUMBER, UP_ARROW,
+ (Drawable) &macMDEFDrawable,
+ menuPtr->textGC,
+ menuRectPtr->left + menuPtr->entries[1]->indicatorSpace,
+ menuRectPtr->top);
+ menuClipRect.top += SICN_HEIGHT;
+ }
+ if ((mtdPtr->virtualMenuTop + menuPtr->totalHeight)
+ > menuRectPtr->bottom) {
+ DrawSICN(SICN_RESOURCE_NUMBER, DOWN_ARROW,
+ (Drawable) &macMDEFDrawable,
+ menuPtr->textGC,
+ menuRectPtr->left + menuPtr->entries[1]->indicatorSpace,
+ menuRectPtr->bottom - SICN_HEIGHT);
+ menuClipRect.bottom -= SICN_HEIGHT;
+ }
+ GetClip(utilRgn);
}
-
+
/*
- * Now, actually draw the menu. Don't draw entries that are higher than
- * the top arrow, and don't draw entries that are lower than the bottom.
- */
-
+ * Now, actually draw the menu. Don't draw entries that
+ * are higher than the top arrow, and don't draw entries
+ * that are lower than the bottom.
+ */
+
menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
- Tk_GetFontMetrics(menuFont, &fontMetrics);
+ Tk_GetFontMetrics(menuFont, &fontMetrics);
for (i = 0; i < menuPtr->numEntries; i++) {
- mePtr = menuPtr->entries[i];
- if (mtdPtr->virtualMenuTop+mePtr->y+mePtr->height<menuClipRect.top) {
- continue;
- } else if (mtdPtr->virtualMenuTop + mePtr->y > menuClipRect.bottom) {
- continue;
- }
-
- ClipRect(&menuClipRect);
- if (mePtr->fontPtr == NULL) {
- fmPtr = &fontMetrics;
- tkfont = menuFont;
- } else {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
- Tk_GetFontMetrics(tkfont, &entryMetrics);
- fmPtr = &entryMetrics;
- }
- AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
- (Drawable) &macMDEFDrawable, fmPtr, tkfont,
- menuRectPtr->left + mePtr->x,
- mtdPtr->virtualMenuTop + mePtr->y,
- (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
- menuPtr->totalWidth - mePtr->x : mePtr->width,
- menuPtr->entries[i]->height);
+ mePtr = menuPtr->entries[i];
+ if (mtdPtr->virtualMenuTop + mePtr->y + mePtr->height
+ < menuClipRect.top) {
+ continue;
+ } else if (mtdPtr->virtualMenuTop + mePtr->y
+ > menuClipRect.bottom) {
+ continue;
+ }
+ ClipRect(&menuClipRect);
+ if (mePtr->fontPtr == NULL) {
+ fmPtr = &fontMetrics;
+ tkfont = menuFont;
+ } else {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
+ Tk_GetFontMetrics(tkfont, &entryMetrics);
+ fmPtr = &entryMetrics;
+ }
+ AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
+ (Drawable) &macMDEFDrawable, fmPtr, tkfont,
+ menuRectPtr->left + mePtr->x,
+ mtdPtr->virtualMenuTop + mePtr->y,
+ (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
+ menuPtr->totalWidth - mePtr->x : mePtr->width,
+ menuPtr->entries[i]->height);
}
- mtdPtr->virtualMenuBottom = mtdPtr->virtualMenuTop + menuPtr->totalHeight;
+ mtdPtr->virtualMenuBottom = mtdPtr->virtualMenuTop
+ + menuPtr->totalHeight;
if (!EmptyRgn(utilRgn)) {
- SetClip(utilRgn);
- SetEmptyRgn(utilRgn);
+ SetClip(utilRgn);
+ SetEmptyRgn(utilRgn);
}
MDEFScrollFlag = 1;
}
-
+
/*
*----------------------------------------------------------------------
*
- * HandleMenuFindItemsMsg --
+ * HandleMenuFindItemsMsg --
*
- * It handles the MenuDefProc's FindItems message. We have to respond by
- * filling in the itemSelected, itemUnderMouse and itemRect fields. This
- * is also the time to scroll the menu if it is too long to fit on the
- * screen.
+ * It handles the MenuDefProc's FindItems message. We have to
+ * respond by filling in the itemSelected, itemUnderMouse and
+ * itemRect fields. This is also the time to scroll the menu if
+ * it is too long to fit on the screen.
*
* Results:
- * The Menu system is informed of the selected item & the item under the
- * mouse.
+ * The Menu system is informed of the selected item & the item
+ * under the mouse.
*
* Side effects:
* The menu might get scrolled.
*
*----------------------------------------------------------------------
*/
-
void
-HandleMenuFindItemsMsg(
- MenuRef menu,
- Rect *menuRectPtr,
- Point hitPt,
- SInt16 *whichItem,
- TkMenu *menuPtr)
+HandleMenuFindItemsMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr)
{
TkMenuEntry *parentEntryPtr;
-#if 0 /* Unused */
+#if 0 /* Unused */
Tk_Font tkfont;
- Tk_FontMetrics fontMetrics, entryMetrics, *fmPtr;
+ Tk_FontMetrics fontMetrics, entryMetrics;
+ Tk_FontMetrics *fmPtr;
#endif
TkMenuEntry *mePtr;
- int i, newItem = -1, hasTopScroll, hasBottomScroll, itemUnderMouse = -1;
+ int i;
+ int newItem = -1;
GDHandle device;
- short windowPart, scrollAmt = 0;
+ Rect itemRect;
+ short windowPart;
WindowRef whichWindow;
- RGBColor bgColor, fgColor, origFgColor, origForeColor, origBackColor;
+ RGBColor bgColor;
+ RGBColor fgColor;
+ RGBColor origFgColor;
PenState origPenState;
- Rect itemRect, dragRect, menuClipRect, updateRect;
+ Rect dragRect;
Rect scratchRect = {-32768, -32768, 32767, 32767};
RgnHandle oldClipRgn;
TkMenuReferences *menuRefPtr;
- MenuTrackingData *mtdPtr = (MenuTrackingData *) whichItem;
+ Rect menuClipRect;
+
+ int hasTopScroll, hasBottomScroll;
+ MenuTrackingData * mtdPtr = (MenuTrackingData *)whichItem;
+ int itemUnderMouse = -1;
enum {
- DONT_SCROLL, DOWN_SCROLL, UP_SCROLL
+ DONT_SCROLL, DOWN_SCROLL, UP_SCROLL
} scrollDirection;
-
+ Rect updateRect;
+ short scrollAmt = 0;
+ RGBColor origForeColor, origBackColor;
+
/*
- * Find out which item was hit. If it is the same as the old item, we
- * don't need to do anything.
+ * Find out which item was hit. If it is the same as the old item,
+ * we don't need to do anything.
*/
if (PtInRect(hitPt, menuRectPtr)) {
- for (i = 0; i < menuPtr->numEntries; i++) {
- mePtr = menuPtr->entries[i];
- itemRect.left = menuRectPtr->left + mePtr->x;
- itemRect.top = mtdPtr->virtualMenuTop + mePtr->y;
- if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {
- itemRect.right = itemRect.left + menuPtr->totalWidth
- - mePtr->x;
- } else {
- itemRect.right = itemRect.left + mePtr->width;
- }
- itemRect.bottom = itemRect.top
- + mePtr->height;
- if (PtInRect(hitPt, &itemRect)) {
- if ((mePtr->type == SEPARATOR_ENTRY)
- || (mePtr->state == ENTRY_DISABLED)) {
- newItem = -1;
- itemUnderMouse = i;
- } else {
- TkMenuEntry *cascadeEntryPtr;
- int parentDisabled = 0;
-
- for (cascadeEntryPtr=menuPtr->menuRefPtr->parentEntryPtr;
- cascadeEntryPtr != NULL;
- cascadeEntryPtr=cascadeEntryPtr->nextCascadePtr) {
- char *name = Tcl_GetString(cascadeEntryPtr->namePtr);
-
- if (strcmp(name, Tk_PathName(menuPtr->tkwin)) == 0) {
- if (cascadeEntryPtr->state == ENTRY_DISABLED) {
- parentDisabled = 1;
- }
- break;
- }
- }
-
- if (parentDisabled) {
- newItem = -1;
- itemUnderMouse = i;
- } else {
- newItem = i;
- itemUnderMouse = i;
- }
- }
- break;
- }
- }
+ for (i = 0; i < menuPtr->numEntries; i++) {
+ mePtr = menuPtr->entries[i];
+ itemRect.left = menuRectPtr->left + mePtr->x;
+ itemRect.top = mtdPtr->virtualMenuTop + mePtr->y;
+ if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {
+ itemRect.right = itemRect.left + menuPtr->totalWidth
+ - mePtr->x;
+ } else {
+ itemRect.right = itemRect.left + mePtr->width;
+ }
+ itemRect.bottom = itemRect.top
+ + mePtr->height;
+ if (PtInRect(hitPt, &itemRect)) {
+ if ((mePtr->type == SEPARATOR_ENTRY)
+ || (mePtr->state == ENTRY_DISABLED)) {
+ newItem = -1;
+ itemUnderMouse = i;
+ } else {
+ TkMenuEntry *cascadeEntryPtr;
+ int parentDisabled = 0;
+
+ for (cascadeEntryPtr
+ = menuPtr->menuRefPtr->parentEntryPtr;
+ cascadeEntryPtr != NULL;
+ cascadeEntryPtr
+ = cascadeEntryPtr->nextCascadePtr) {
+ char *name;
+
+ name = Tcl_GetStringFromObj(
+ cascadeEntryPtr->namePtr, NULL);
+ if (strcmp(name, Tk_PathName(menuPtr->tkwin))
+ == 0) {
+ if (cascadeEntryPtr->state == ENTRY_DISABLED) {
+ parentDisabled = 1;
+ }
+ break;
+ }
+ }
+
+ if (parentDisabled) {
+ newItem = -1;
+ itemUnderMouse = i;
+ } else {
+ newItem = i;
+ itemUnderMouse = i;
+ }
+ }
+ break;
+ }
+ }
+ } else {
}
/*
* Now we need to take care of scrolling the menu.
*/
-
+
hasTopScroll = mtdPtr->virtualMenuTop < menuRectPtr->top;
hasBottomScroll = mtdPtr->virtualMenuBottom > menuRectPtr->bottom;
scrollDirection = DONT_SCROLL;
if (hasTopScroll && (hitPt.v < menuRectPtr->top + SICN_HEIGHT)) {
- newItem = -1;
- scrollDirection = DOWN_SCROLL;
- } else if (hasBottomScroll && (hitPt.v>menuRectPtr->bottom-SICN_HEIGHT)) {
- newItem = -1;
- scrollDirection = UP_SCROLL;
+ newItem = -1;
+ scrollDirection = DOWN_SCROLL;
+ } else if (hasBottomScroll && (hitPt.v > (menuRectPtr->bottom - SICN_HEIGHT))) {
+ newItem = -1;
+ scrollDirection = UP_SCROLL;
}
-
+
menuClipRect = *menuRectPtr;
if (hasTopScroll) {
- menuClipRect.top += SICN_HEIGHT;
+ menuClipRect.top += SICN_HEIGHT;
}
if (hasBottomScroll) {
- menuClipRect.bottom -= SICN_HEIGHT;
+ menuClipRect.bottom -= SICN_HEIGHT;
}
if (MDEFScrollFlag) {
- scrollDirection = DONT_SCROLL;
- MDEFScrollFlag = 0;
+ scrollDirection = DONT_SCROLL;
+ MDEFScrollFlag = 0;
}
GetClip(utilRgn);
ClipRect(&menuClipRect);
@@ -4328,96 +4465,100 @@ HandleMenuFindItemsMsg(
mtdPtr->itemSelected = newItem + 1;
mtdPtr->itemUnderMouse = itemUnderMouse + 1;
mtdPtr->itemRect = itemRect;
-
+
GetGWorld(&macMDEFDrawable.grafPtr, &device);
GetForeColor(&origForeColor);
GetBackColor(&origBackColor);
if (scrollDirection == UP_SCROLL) {
- scrollAmt = menuClipRect.bottom - hitPt.v;
- if (scrollAmt < menuRectPtr->bottom - mtdPtr->virtualMenuBottom) {
- scrollAmt = menuRectPtr->bottom - mtdPtr->virtualMenuBottom;
- }
- if (!hasTopScroll && ((mtdPtr->virtualMenuTop + scrollAmt)
- < menuRectPtr->top)) {
- SetRect(&updateRect, menuRectPtr->left,
- mtdPtr->virtualMenuTop, menuRectPtr->right,
- mtdPtr->virtualMenuTop + SICN_HEIGHT);
- EraseRect(&updateRect);
- DrawSICN(SICN_RESOURCE_NUMBER, UP_ARROW,
- (Drawable) &macMDEFDrawable, menuPtr->textGC,
- menuRectPtr->left + menuPtr->entries[1]->indicatorSpace,
- menuRectPtr->top);
- menuClipRect.top += SICN_HEIGHT;
- }
+ scrollAmt = menuClipRect.bottom - hitPt.v;
+ if (scrollAmt < menuRectPtr->bottom
+ - mtdPtr->virtualMenuBottom) {
+ scrollAmt = menuRectPtr->bottom - mtdPtr->virtualMenuBottom;
+ }
+ if (!hasTopScroll && ((mtdPtr->virtualMenuTop + scrollAmt)
+ < menuRectPtr->top)) {
+ SetRect(&updateRect, menuRectPtr->left,
+ mtdPtr->virtualMenuTop, menuRectPtr->right,
+ mtdPtr->virtualMenuTop + SICN_HEIGHT);
+ EraseRect(&updateRect);
+ DrawSICN(SICN_RESOURCE_NUMBER, UP_ARROW,
+ (Drawable) &macMDEFDrawable,
+ menuPtr->textGC, menuRectPtr->left
+ + menuPtr->entries[1]->indicatorSpace,
+ menuRectPtr->top);
+ menuClipRect.top += SICN_HEIGHT;
+ }
} else if (scrollDirection == DOWN_SCROLL) {
- scrollAmt = menuClipRect.top - hitPt.v;
- if (scrollAmt > menuRectPtr->top - mtdPtr->virtualMenuTop) {
- scrollAmt = menuRectPtr->top - mtdPtr->virtualMenuTop;
- }
- if (!hasBottomScroll && ((mtdPtr->virtualMenuBottom + scrollAmt)
- > menuRectPtr->bottom)) {
- SetRect(&updateRect, menuRectPtr->left,
- mtdPtr->virtualMenuBottom - SICN_HEIGHT,
- menuRectPtr->right, mtdPtr->virtualMenuBottom);
- EraseRect(&updateRect);
- DrawSICN(SICN_RESOURCE_NUMBER, DOWN_ARROW,
- (Drawable) &macMDEFDrawable,
- menuPtr->textGC, menuRectPtr->left
- + menuPtr->entries[1]->indicatorSpace,
- menuRectPtr->bottom - SICN_HEIGHT);
- menuClipRect.bottom -= SICN_HEIGHT;
- }
+ scrollAmt = menuClipRect.top - hitPt.v;
+ if (scrollAmt > menuRectPtr->top - mtdPtr->virtualMenuTop) {
+ scrollAmt = menuRectPtr->top - mtdPtr->virtualMenuTop;
+ }
+
+ if (!hasBottomScroll && ((mtdPtr->virtualMenuBottom + scrollAmt)
+ > menuRectPtr->bottom)) {
+ SetRect(&updateRect, menuRectPtr->left,
+ mtdPtr->virtualMenuBottom - SICN_HEIGHT,
+ menuRectPtr->right, mtdPtr->virtualMenuBottom);
+ EraseRect(&updateRect);
+ DrawSICN(SICN_RESOURCE_NUMBER, DOWN_ARROW,
+ (Drawable) &macMDEFDrawable,
+ menuPtr->textGC, menuRectPtr->left
+ + menuPtr->entries[1]->indicatorSpace,
+ menuRectPtr->bottom - SICN_HEIGHT);
+ menuClipRect.bottom -= SICN_HEIGHT;
+ }
}
-
+
if (scrollDirection != DONT_SCROLL) {
#if 0
- Tk_Font menuFont;
- RgnHandle updateRgn = NewRgn();
+ Tk_Font menuFont;
+ RgnHandle updateRgn = NewRgn();
#endif
-
- ScrollMenuImage(menu, menuRectPtr, 0, scrollAmt, NULL);
- mtdPtr->virtualMenuTop += scrollAmt;
- mtdPtr->virtualMenuBottom += scrollAmt;
+
+ ScrollMenuImage(menu, menuRectPtr, 0, scrollAmt, NULL);
+ mtdPtr->virtualMenuTop += scrollAmt;
+ mtdPtr->virtualMenuBottom += scrollAmt;
#if 0
- GetRegionBounds(updateRgn,&updateRect);
- DisposeRgn(updateRgn);
- if (mtdPtr->virtualMenuTop == menuRectPtr->top) {
- updateRect.top -= SICN_HEIGHT;
- }
- if (mtdPtr->virtualMenuBottom == menuRectPtr->bottom) {
- updateRect.bottom += SICN_HEIGHT;
- }
- ClipRect(&updateRect);
- EraseRect(&updateRect);
- menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
- Tk_GetFontMetrics(menuFont, &fontMetrics);
- for (i = 0; i < menuPtr->numEntries; i++) {
- mePtr = menuPtr->entries[i];
- if (mtdPtr->virtualMenuTop + mePtr->y + mePtr->height
- < updateRect.top) {
- continue;
- } else if (mtdPtr->virtualMenuTop+mePtr->y > updateRect.bottom) {
- continue;
- }
-
- if (mePtr->fontPtr == NULL) {
- fmPtr = &fontMetrics;
- tkfont = menuFont;
- } else {
- tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
- Tk_GetFontMetrics(tkfont, &entryMetrics);
- fmPtr = &entryMetrics;
- }
- AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
- (Drawable) &macMDEFDrawable, fmPtr, tkfont,
- menuRectPtr->left + mePtr->x,
- mtdPtr->virtualMenuTop + mePtr->y,
- (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
- menuPtr->totalWidth - mePtr->x : mePtr->width,
- menuPtr->entries[i]->height);
- }
+ GetRegionBounds(updateRgn,&updateRect);
+ DisposeRgn(updateRgn);
+ if (mtdPtr->virtualMenuTop == menuRectPtr->top) {
+ updateRect.top -= SICN_HEIGHT;
+ }
+ if (mtdPtr->virtualMenuBottom == menuRectPtr->bottom) {
+ updateRect.bottom += SICN_HEIGHT;
+ }
+ ClipRect(&updateRect);
+ EraseRect(&updateRect);
+ menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
+ Tk_GetFontMetrics(menuFont, &fontMetrics);
+ for (i = 0; i < menuPtr->numEntries; i++) {
+ mePtr = menuPtr->entries[i];
+ if (mtdPtr->virtualMenuTop + mePtr->y + mePtr->height
+ < updateRect.top) {
+ continue;
+ } else if (mtdPtr->virtualMenuTop + mePtr->y
+ > updateRect.bottom) {
+ continue;
+ }
+ if (mePtr->fontPtr == NULL) {
+ fmPtr = &fontMetrics;
+ tkfont = menuFont;
+ } else {
+ tkfont = Tk_GetFontFromObj(menuPtr->tkwin,
+ mePtr->fontPtr);
+ Tk_GetFontMetrics(tkfont, &entryMetrics);
+ fmPtr = &entryMetrics;
+ }
+ AppearanceEntryDrawWrapper(mePtr, menuRectPtr, mtdPtr,
+ (Drawable) &macMDEFDrawable, fmPtr, tkfont,
+ menuRectPtr->left + mePtr->x,
+ mtdPtr->virtualMenuTop + mePtr->y,
+ (mePtr->entryFlags & ENTRY_LAST_COLUMN) ?
+ menuPtr->totalWidth - mePtr->x : mePtr->width,
+ menuPtr->entries[i]->height);
+ }
#endif
}
@@ -4427,95 +4568,95 @@ HandleMenuFindItemsMsg(
RGBBackColor(&origBackColor);
/*
- * If the menu is a tearoff, and the mouse is outside the menu, we need to
- * draw the drag rectangle.
- *
- * In order for tearoffs to work properly, we need to set the active
- * member of the containing menubar.
- */
-
+ * If the menu is a tearoff, and the mouse is outside the menu,
+ * we need to draw the drag rectangle.
+ *
+ * In order for tearoffs to work properly, we need to set
+ * the active member of the containing menubar.
+ */
+
menuRefPtr = TkFindMenuReferences(menuPtr->interp,
- Tk_PathName(menuPtr->tkwin));
-
+ Tk_PathName(menuPtr->tkwin));
+
if ((menuRefPtr != NULL) && (menuRefPtr->parentEntryPtr != NULL)) {
- for (parentEntryPtr = menuRefPtr->parentEntryPtr;
- parentEntryPtr != NULL;
- parentEntryPtr = parentEntryPtr->nextCascadePtr) {
- char *name = Tcl_GetString(parentEntryPtr->namePtr);
-
- if (strcmp(name, Tk_PathName(menuPtr->tkwin)) != 0) {
- break;
- }
- }
- if (parentEntryPtr != NULL) {
- TkActivateMenuEntry(parentEntryPtr->menuPtr,
- parentEntryPtr->index);
- }
+ char *name;
+ for (parentEntryPtr = menuRefPtr->parentEntryPtr;
+ parentEntryPtr != NULL
+ ; parentEntryPtr = parentEntryPtr->nextCascadePtr) {
+ name = Tcl_GetStringFromObj(parentEntryPtr->namePtr,
+ NULL);
+ if (strcmp(name, Tk_PathName(menuPtr->tkwin)) != 0) {
+ break;
+ }
+ }
+ if (parentEntryPtr != NULL) {
+ TkActivateMenuEntry(parentEntryPtr->menuPtr,
+ parentEntryPtr->index);
+ }
}
-
+
if (menuPtr->tearoff) {
- scratchRect = *menuRectPtr;
- if (tearoffStruct.menuPtr == NULL) {
- scratchRect.top -= 10;
- scratchRect.bottom += 10;
- scratchRect.left -= 10;
- scratchRect.right += 10;
- }
-
- windowPart = FindWindow(hitPt, &whichWindow);
- if ((windowPart != inMenuBar) && (newItem == -1)
- && (hitPt.v != 0) && (hitPt.h != 0)
- && (!PtInRect(hitPt, &scratchRect))
- && (!PtInRect(hitPt, &tearoffStruct.excludeRect))) {
- unsigned long dummy;
-
- oldClipRgn = NewRgn();
- GetClip(oldClipRgn);
- GetForeColor(&origFgColor);
- GetPenState(&origPenState);
- GetForeColor(&fgColor);
- GetBackColor(&bgColor);
- GetGray(device, &bgColor, &fgColor);
- RGBForeColor(&fgColor);
- SetRect(&scratchRect, -32768, -32768, 32767, 32767);
- ClipRect(&scratchRect);
-
- dragRect = *menuRectPtr;
- tearoffStruct.menuPtr = menuPtr;
-
- PenMode(srcXor);
- dragRect = *menuRectPtr;
- OffsetRect(&dragRect, -dragRect.left, -dragRect.top);
- OffsetRect(&dragRect, tearoffStruct.point.h,
- tearoffStruct.point.v);
- if ((dragRect.top != 0) && (dragRect.left != 0)) {
- FrameRect(&dragRect);
- Delay(1, &dummy);
- FrameRect(&dragRect);
- }
- tearoffStruct.point = hitPt;
-
- SetClip(oldClipRgn);
- DisposeRgn(oldClipRgn);
- RGBForeColor(&origFgColor);
- SetPenState(&origPenState);
- } else {
- tearoffStruct.menuPtr = NULL;
- tearoffStruct.point.h = tearoffStruct.point.v = 0;
- }
+ scratchRect = *menuRectPtr;
+ if (tearoffStruct.menuPtr == NULL) {
+ scratchRect.top -= 10;
+ scratchRect.bottom += 10;
+ scratchRect.left -= 10;
+ scratchRect.right += 10;
+ }
+
+ windowPart = FindWindow(hitPt, &whichWindow);
+ if ((windowPart != inMenuBar) && (newItem == -1)
+ && (hitPt.v != 0) && (hitPt.h != 0)
+ && (!PtInRect(hitPt, &scratchRect))
+ && (!PtInRect(hitPt, &tearoffStruct.excludeRect))) {
+ unsigned long dummy;
+ oldClipRgn = NewRgn();
+ GetClip(oldClipRgn);
+ GetForeColor(&origFgColor);
+ GetPenState(&origPenState);
+ GetForeColor(&fgColor);
+ GetBackColor(&bgColor);
+ GetGray(device, &bgColor, &fgColor);
+ RGBForeColor(&fgColor);
+ SetRect(&scratchRect, -32768, -32768, 32767, 32767);
+ ClipRect(&scratchRect);
+
+ dragRect = *menuRectPtr;
+ tearoffStruct.menuPtr = menuPtr;
+
+ PenMode(srcXor);
+ dragRect = *menuRectPtr;
+ OffsetRect(&dragRect, -dragRect.left, -dragRect.top);
+ OffsetRect(&dragRect, tearoffStruct.point.h,
+ tearoffStruct.point.v);
+ if ((dragRect.top != 0) && (dragRect.left != 0)) {
+ FrameRect(&dragRect);
+ Delay(1, &dummy);
+ FrameRect(&dragRect);
+ }
+ tearoffStruct.point = hitPt;
+
+ SetClip(oldClipRgn);
+ DisposeRgn(oldClipRgn);
+ RGBForeColor(&origFgColor);
+ SetPenState(&origPenState);
+ } else {
+ tearoffStruct.menuPtr = NULL;
+ tearoffStruct.point.h = tearoffStruct.point.v = 0;
+ }
} else {
- tearoffStruct.menuPtr = NULL;
- tearoffStruct.point.h = tearoffStruct.point.v = 0;
- }
+ tearoffStruct.menuPtr = NULL;
+ tearoffStruct.point.h = tearoffStruct.point.v = 0;
+ }
}
-
+
/*
*----------------------------------------------------------------------
*
- * HandleMenuPopUpMsg --
+ * HandleMenuPopUpMsg --
*
- * It handles the MenuDefProc's PopUp message. The menu is posted with
- * the selected item at the point given in hitPt.
+ * It handles the MenuDefProc's PopUp message. The menu is
+ * posted with the selected item at the point given in hitPt.
*
* Results:
* A menu is posted.
@@ -4525,127 +4666,118 @@ HandleMenuFindItemsMsg(
*
*----------------------------------------------------------------------
*/
-
void
-HandleMenuPopUpMsg(
- MenuRef menu,
- Rect *menuRectPtr,
- Point hitPt,
- SInt16 *whichItem,
- TkMenu *menuPtr)
+HandleMenuPopUpMsg (MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr)
{
- int maxMenuHeight, oldItem;
+ int maxMenuHeight;
+ int oldItem;
Rect portRect;
BitMap screenBits;
/*
- * Note that for some oddball reason, h and v are reversed in the point
- * given to us by the MDEF.
- */
-
+ * Note that for some oddball reason, h and v are reversed in the
+ * point given to us by the MDEF.
+ */
GetQDGlobalsScreenBits(&screenBits);
oldItem = *whichItem;
if (oldItem >= menuPtr->numEntries) {
- oldItem = -1;
+ oldItem = -1;
}
portRect.top = 0;
portRect.bottom = 1280;
maxMenuHeight = screenBits.bounds.bottom
- - screenBits.bounds.top - GetMBarHeight() - SCREEN_MARGIN;
+ - screenBits.bounds.top
+ - GetMBarHeight() - SCREEN_MARGIN;
if (menuPtr->totalHeight > maxMenuHeight) {
- menuRectPtr->top = GetMBarHeight();
+ menuRectPtr->top = GetMBarHeight();
} else {
- int delta;
-
- menuRectPtr->top = hitPt.h;
- if (oldItem >= 0) {
- menuRectPtr->top -= menuPtr->entries[oldItem]->y;
- }
-
- if (menuRectPtr->top < GetMBarHeight()) {
- /*
- * Displace downward if the menu would stick off the top of the
- * screen.
- */
-
- menuRectPtr->top = GetMBarHeight() + SCREEN_MARGIN;
- } else {
- /*
- * Or upward if the menu sticks off the bottom end...
- */
-
- delta = menuRectPtr->top + menuPtr->totalHeight - maxMenuHeight;
- if (delta > 0) {
- menuRectPtr->top -= delta;
- }
- }
+ int delta;
+ menuRectPtr->top = hitPt.h;
+ if (oldItem >= 0) {
+ menuRectPtr->top -= menuPtr->entries[oldItem]->y;
+ }
+
+ if (menuRectPtr->top < GetMBarHeight()) {
+ /* Displace downward if the menu would stick off the
+ * top of the screen.
+ */
+
+ menuRectPtr->top = GetMBarHeight() + SCREEN_MARGIN;
+ } else {
+ /*
+ * Or upward if the menu sticks off the
+ * bottom end...
+ */
+
+ delta = menuRectPtr->top + menuPtr->totalHeight
+ - maxMenuHeight;
+ if (delta > 0) {
+ menuRectPtr->top -= delta;
+ }
+ }
}
menuRectPtr->left = hitPt.v;
menuRectPtr->right = menuRectPtr->left + menuPtr->totalWidth;
- menuRectPtr->bottom = menuRectPtr->top +
- ((maxMenuHeight < menuPtr->totalHeight)
- ? maxMenuHeight : menuPtr->totalHeight);
+ menuRectPtr->bottom = menuRectPtr->top +
+ ((maxMenuHeight < menuPtr->totalHeight)
+ ? maxMenuHeight : menuPtr->totalHeight);
if (menuRectPtr->top == GetMBarHeight()) {
- *whichItem = hitPt.h;
+ *whichItem = hitPt.h;
} else {
- *whichItem = menuRectPtr->top;
+ *whichItem = menuRectPtr->top;
}
}
-
+
/*
*----------------------------------------------------------------------
*
- * HandleMenuCalcItemMsg --
+ * HandleMenuCalcItemMsg --
*
- * It handles the MenuDefProc's CalcItem message. It is supposed to
- * calculate the Rect of the menu entry in whichItem in the menu, and put
- * that in menuRectPtr. I assume this works, but I have never seen the
- * MenuManager send this message.
+ * It handles the MenuDefProc's CalcItem message. It is supposed
+ * to calculate the Rect of the menu entry in whichItem in the
+ * menu, and put that in menuRectPtr. I assume this works, but I
+ * have never seen the MenuManager send this message.
*
* Results:
- * The Menu Manager is informed of the bounding rect of a menu rect.
+ * The Menu Manager is informed of the bounding rect of a
+ * menu rect.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
-
void
-HandleMenuCalcItemMsg(
- MenuRef menu,
- Rect *menuRectPtr,
- Point hitPt,
- SInt16 *whichItem,
- TkMenu *menuPtr)
+HandleMenuCalcItemMsg(MenuRef menu,
+ Rect *menuRectPtr,
+ Point hitPt,
+ SInt16 *whichItem,
+ TkMenu *menuPtr)
{
TkMenuEntry *mePtr;
- MenuTrackingData mtd, *mtdPtr = &mtd;
+ MenuTrackingData mtd, *mtdPtr = &mtd;
int err, virtualTop;
-
+
err = GetMenuTrackingData(menu, mtdPtr);
if (err == noErr) {
- virtualTop = mtdPtr->virtualMenuTop;
+ virtualTop = mtdPtr->virtualMenuTop;
} else {
- virtualTop = 0;
+ virtualTop = 0;
}
-
+
mePtr = menuPtr->entries[*whichItem];
menuRectPtr->left = mePtr->x;
menuRectPtr->top = mePtr->y - virtualTop;
if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {
- menuRectPtr->right = menuPtr->totalWidth;
+ menuRectPtr->right = menuPtr->totalWidth;
} else {
- menuRectPtr->right = mePtr->x + mePtr->width;
+ menuRectPtr->right = mePtr->x + mePtr->width;
}
- menuRectPtr->bottom = menuRectPtr->top + mePtr->height;
+ menuRectPtr->bottom = menuRectPtr->top
+ + mePtr->height;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c
index 65c894f..79cd37a 100644
--- a/macosx/tkMacOSXMenubutton.c
+++ b/macosx/tkMacOSXMenubutton.c
@@ -1,16 +1,16 @@
-/*
+/*
* tkMacOSXMenubutton.c --
*
- * This file implements the Macintosh specific portion of the menubutton
- * widget.
+ * This file implements the Macintosh specific portion of the
+ * menubutton widget.
*
* Copyright (c) 1996 by 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.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXMenubutton.c,v 1.12 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXMenubutton.c,v 1.13 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -24,30 +24,28 @@
#define kMenuAttrDoNotUseUserCommandKeys (1 << 7)
#endif
-#define kShadowOffset (3) /* amount to offset shadow from frame */
-#define kTriangleWidth (11) /* width of the triangle */
-#define kTriangleHeight (6) /* height of the triangle */
-#define kTriangleMargin (5) /* margin around triangle */
+#define kShadowOffset (3) /* amount to offset shadow from frame */
+#define kTriangleWidth (11) /* width of the triangle */
+#define kTriangleHeight (6) /* height of the triangle */
+#define kTriangleMargin (5) /* margin around triangle */
-#define TK_POPUP_OFFSET 32 /* size of popup marker */
+#define TK_POPUP_OFFSET 32 /* size of popup marker */
-MODULE_SCOPE int TkMacOSXGetNewMenuID(Tcl_Interp *interp,
- TkMenu *menuInstPtr, int cascade,
- short *menuIDPtr);
-MODULE_SCOPE void TkMacOSXFreeMenuID(short menuID);
+MODULE_SCOPE int TkMacOSXGetNewMenuID _ANSI_ARGS_((Tcl_Interp *interp, TkMenu *menuInstPtr, int cascade, short *menuIDPtr));
+MODULE_SCOPE void TkMacOSXFreeMenuID _ANSI_ARGS_((short menuID));
typedef struct {
SInt16 initialValue;
SInt16 minValue;
SInt16 maxValue;
SInt16 procID;
- int isBevel;
+ int isBevel;
} MenuButtonControlParams;
typedef struct {
- int len;
- Str255 title;
- ControlFontStyleRec style;
+ int len;
+ Str255 title;
+ ControlFontStyleRec style;
} ControlTitleParams;
/*
@@ -55,49 +53,50 @@ typedef struct {
*/
typedef struct MacMenuButton {
- TkMenuButton info; /* Generic button info. */
- WindowRef windowRef;
- ControlRef userPane;
- ControlRef control;
- MenuRef menuRef;
- RGBColor userPaneBackground;
- MenuButtonControlParams params;
- ControlTitleParams titleParams;
+ TkMenuButton info; /* Generic button info. */
+ WindowRef windowRef;
+ ControlRef userPane;
+ ControlRef control;
+ MenuRef menuRef;
+ RGBColor userPaneBackground;
+ MenuButtonControlParams params;
+ ControlTitleParams titleParams;
ControlButtonContentInfo bevelButtonContent;
- OpenCPicParams picParams;
- int flags;
+ OpenCPicParams picParams;
+ int flags;
} MacMenuButton;
/*
* Forward declarations for procedures defined later in this file:
*/
-static OSErr SetUserPaneDrawProc(ControlRef control,
- ControlUserPaneDrawProcPtr upp);
-static OSErr SetUserPaneSetUpSpecialBackgroundProc(
- ControlRef control,
- ControlUserPaneBackgroundProcPtr upp);
-static void UserPaneDraw(ControlRef control, ControlPartCode cpc);
-static void UserPaneBackgroundProc(ControlHandle,
- ControlBackgroundPtr info);
-static int MenuButtonInitControl(MacMenuButton *mbPtr,
- Rect *paneRect, Rect *cntrRect);
-static int UpdateControlColors(MacMenuButton *mbPtr);
-static void ComputeMenuButtonControlParams(TkMenuButton *mbPtr,
- MenuButtonControlParams *paramsPtr);
-static void ComputeControlTitleParams(TkMenuButton *mbPtr, ControlTitleParams *paramsPtr);
-static void CompareControlTitleParams(ControlTitleParams *p1Ptr,
- ControlTitleParams *p2Ptr, int *titleChanged,
- int *styleChanged);
+static OSErr SetUserPaneDrawProc(ControlRef control,
+ ControlUserPaneDrawProcPtr upp);
+static OSErr SetUserPaneSetUpSpecialBackgroundProc(ControlRef control,
+ ControlUserPaneBackgroundProcPtr upp);
+static void UserPaneDraw(ControlRef control, ControlPartCode cpc);
+static void UserPaneBackgroundProc(ControlHandle,
+ ControlBackgroundPtr info);
+static int MenuButtonInitControl ( MacMenuButton *mbPtr, Rect *paneRect, Rect *cntrRect );
+
+static int UpdateControlColors _ANSI_ARGS_((MacMenuButton *mbPtr ));
+static void ComputeMenuButtonControlParams _ANSI_ARGS_((TkMenuButton * mbPtr, MenuButtonControlParams * paramsPtr));
+static void ComputeControlTitleParams _ANSI_ARGS_((TkMenuButton * mbPtr, ControlTitleParams * paramsPtr));
+static void CompareControlTitleParams(
+ ControlTitleParams * p1Ptr,
+ ControlTitleParams * p2Ptr,
+ int * titleChanged,
+ int * styleChanged
+);
/*
- * The structure below defines menubutton class behavior by means of functions
- * that can be invoked from generic window code.
+ * The structure below defines menubutton class behavior by means of
+ * procedures that can be invoked from generic window code.
*/
Tk_ClassProcs tkpMenubuttonClass = {
- sizeof(Tk_ClassProcs), /* size */
- TkMenuButtonWorldChanged, /* worldChangedProc */
+ sizeof(Tk_ClassProcs), /* size */
+ TkMenuButtonWorldChanged, /* worldChangedProc */
};
/*
@@ -105,13 +104,13 @@ Tk_ClassProcs tkpMenubuttonClass = {
*
* TkpCreateMenuButton --
*
- * Allocate a new TkMenuButton structure.
+ * Allocate a new TkMenuButton structure.
*
* Results:
- * Returns a newly allocated TkMenuButton structure.
+ * Returns a newly allocated TkMenuButton structure.
*
* Side effects:
- * Registers an event handler for the widget.
+ * Registers an event handler for the widget.
*
*----------------------------------------------------------------------
*/
@@ -121,7 +120,6 @@ TkpCreateMenuButton(
Tk_Window tkwin)
{
MacMenuButton *mbPtr = (MacMenuButton *) ckalloc(sizeof(MacMenuButton));
-
mbPtr->userPaneBackground.red = 0;
mbPtr->userPaneBackground.green = 0;
mbPtr->userPaneBackground.blue = ~0;
@@ -148,39 +146,42 @@ TkpCreateMenuButton(
*
* TkpDisplayMenuButton --
*
- * This procedure is invoked to display a menubutton widget.
+ * This procedure is invoked to display a menubutton widget.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Commands are output to X to display the menubutton in its current
- * mode.
+ * Commands are output to X to display the menubutton in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
void
TkpDisplayMenuButton(
- ClientData clientData) /* Information about widget. */
+ ClientData clientData) /* Information about widget. */
{
TkMenuButton *butPtr = (TkMenuButton *) clientData;
Tk_Window tkwin = butPtr->tkwin;
- TkWindow *winPtr;
- Pixmap pixmap;
- MacMenuButton *mbPtr = (MacMenuButton *) butPtr;
+ TkWindow * winPtr;
+ Pixmap pixmap;
+ MacMenuButton * mbPtr = (MacMenuButton *) butPtr;
GWorldPtr dstPort;
CGrafPtr saveWorld;
GDHandle saveDevice;
- int hasImageOrBitmap = 0, width, height, err;
+ int hasImageOrBitmap = 0;
+ int width, height;
+ int err;
ControlButtonGraphicAlignment theAlignment;
+
Rect paneRect, cntrRect;
butPtr->flags &= ~REDRAW_PENDING;
if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
- return;
+ return;
}
- pixmap = (Pixmap) Tk_WindowId(tkwin);
+ pixmap = ( Pixmap )Tk_WindowId(tkwin);
GetGWorld(&saveWorld, &saveDevice);
dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
SetGWorld(dstPort, NULL);
@@ -191,167 +192,170 @@ TkpDisplayMenuButton(
paneRect.top = winPtr->privatePtr->yOff;
paneRect.right = paneRect.left+Tk_Width(butPtr->tkwin)-1;
paneRect.bottom = paneRect.top+Tk_Height(butPtr->tkwin)-1;
-
+
cntrRect = paneRect;
-
+
cntrRect.left += butPtr->inset;
cntrRect.top += butPtr->inset;
cntrRect.right -= butPtr->inset;
cntrRect.bottom -= butPtr->inset;
if (mbPtr->userPane) {
- MenuButtonControlParams params;
- bzero(&params, sizeof(params));
- ComputeMenuButtonControlParams(butPtr, &params );
- if (bcmp(&params,&mbPtr->params,sizeof(params))) {
- if (mbPtr->userPane) {
- DisposeControl(mbPtr->userPane);
- mbPtr->userPane = NULL;
- mbPtr->control = NULL;
- }
- }
- }
- if (!mbPtr->userPane) {
- if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect)) {
- ERR_MSG("Init Control failed");
- return;
- }
- }
+ MenuButtonControlParams params;
+ bzero(&params, sizeof(params));
+ ComputeMenuButtonControlParams(butPtr, &params );
+ if (bcmp(&params,&mbPtr->params,sizeof(params))) {
+ if (mbPtr->userPane) {
+ DisposeControl(mbPtr->userPane);
+ mbPtr->userPane = NULL;
+ mbPtr->control = NULL;
+ }
+ }
+ }
+ if (!mbPtr->userPane) {
+ if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect ) ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Init Control failed\n" );
+#endif
+ return;
+ }
+ }
SetControlBounds(mbPtr->userPane,&paneRect);
- SetControlBounds(mbPtr->control,&cntrRect);
+ SetControlBounds(mbPtr->control,&cntrRect);
/*
* We need to cache the title and its style
*/
-
- if (!(mbPtr->flags & 2)) {
- ControlTitleParams titleParams;
- int titleChanged;
- int styleChanged;
-
- ComputeControlTitleParams(butPtr,&titleParams);
- CompareControlTitleParams(&titleParams,&mbPtr->titleParams,
- &titleChanged,&styleChanged);
- if (titleChanged) {
- CFStringRef cf = CFStringCreateWithCString(NULL,
- (char*) titleParams.title, kCFStringEncodingUTF8);
-
- if (hasImageOrBitmap) {
- SetControlTitleWithCFString(mbPtr->control, cf);
- } else {
- SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf);
- }
- CFRelease(cf);
- bcopy(titleParams.title, mbPtr->titleParams.title,
- titleParams.len + 1);
- mbPtr->titleParams.len = titleParams.len;
- }
- if ((titleChanged||styleChanged) && titleParams .len) {
- if (hasImageOrBitmap) {
- err = SetControlFontStyle(mbPtr->control,&titleParams.style);
- LOG_ON_ERROR(SetControlFontStyle);
- if (err != noErr) {
- return;
- }
- }
- bcopy(&titleParams.style, &mbPtr->titleParams.style,
- sizeof(titleParams.style));
- }
+ if (!(mbPtr->flags&2)) {
+ ControlTitleParams titleParams;
+ int titleChanged;
+ int styleChanged;
+ ComputeControlTitleParams(butPtr,&titleParams);
+ CompareControlTitleParams(&titleParams,&mbPtr->titleParams,
+ &titleChanged,&styleChanged);
+ if (titleChanged) {
+ CFStringRef cf;
+ cf = CFStringCreateWithCString(NULL,
+ (char*) titleParams.title, kCFStringEncodingUTF8);
+ if (hasImageOrBitmap) {
+ SetControlTitleWithCFString(mbPtr->control, cf);
+ } else {
+ SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf);
+ }
+ CFRelease(cf);
+ bcopy(titleParams.title,mbPtr->titleParams.title,titleParams.len+1);
+ mbPtr->titleParams.len = titleParams.len;
+ }
+ if ((titleChanged||styleChanged) && titleParams .len) {
+ if (hasImageOrBitmap) {
+ err = SetControlFontStyle(mbPtr->control,&titleParams.style);
+ if (err !=noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetControlFontStyle failed %d\n", err);
+#endif
+ return;
+ }
+ }
+ bcopy(&titleParams.style,&mbPtr->titleParams.style,sizeof(titleParams.style));
+ }
}
if (butPtr->image != None) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- hasImageOrBitmap = 1;
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ hasImageOrBitmap = 1;
} else if (butPtr->bitmap != None) {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- hasImageOrBitmap = 1;
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ hasImageOrBitmap = 1;
}
if (hasImageOrBitmap) {
- mbPtr->picParams.srcRect.right = width;
- mbPtr->picParams.srcRect.bottom = height;
-
- /*
- * Set the flag to circumvent clipping and bounds problems with OS
- * 10.0.4
- */
-
- tkPictureIsOpen = 1;
- mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams);
- if (!mbPtr->bevelButtonContent.u.picture) {
- ERR_MSG("OpenCPicture failed");
- }
-
- /*
- * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
- * which does not get recorded in the picture. So the bitmap code will
- * fail in that case.
- */
-
- if (butPtr->image != NULL) {
- Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0);
- } else {
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0,
- (unsigned int) width, (unsigned int) height, 0, 0, 1);
- }
- ClosePicture();
-
- tkPictureIsOpen = 0;
+ mbPtr->picParams.srcRect.right = width;
+ mbPtr->picParams.srcRect.bottom = height;
+ /* Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */
+ tkPictureIsOpen = 1;
+ if (!(mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams)) ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"OpenCPicture failed\n");
+#endif
+ }
+ /*
+ * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
+ * which does not get recorded in the picture. So the bitmap code
+ * will fail in that case.
+ */
+ if (butPtr->image != NULL) {
+ Tk_RedrawImage(butPtr->image, 0, 0, width,
+ height, pixmap, 0, 0);
+ } else {
+ XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0,
+ (unsigned int) width, (unsigned int) height, 0, 0, 1);
+ }
+ ClosePicture();
+
+ tkPictureIsOpen = 0;
err = SetControlData(mbPtr->control, kControlButtonPart,
- kControlBevelButtonContentTag,
- sizeof(ControlButtonContentInfo),
- (char *) &mbPtr->bevelButtonContent);
- LOG_ON_ERROR(SetControlData_BevelButtonContent);
- switch (butPtr->anchor) {
- case TK_ANCHOR_N:
- theAlignment = kControlBevelButtonAlignTop;
- break;
- case TK_ANCHOR_NE:
- theAlignment = kControlBevelButtonAlignTopRight;
- break;
- case TK_ANCHOR_E:
- theAlignment = kControlBevelButtonAlignRight;
- break;
- case TK_ANCHOR_SE:
- theAlignment = kControlBevelButtonAlignBottomRight;
- break;
- case TK_ANCHOR_S:
- theAlignment = kControlBevelButtonAlignBottom;
- break;
- case TK_ANCHOR_SW:
- theAlignment = kControlBevelButtonAlignBottomLeft;
- break;
- case TK_ANCHOR_W:
- theAlignment = kControlBevelButtonAlignLeft;
- break;
- case TK_ANCHOR_NW:
- theAlignment = kControlBevelButtonAlignTopLeft;
- break;
- case TK_ANCHOR_CENTER:
- theAlignment = kControlBevelButtonAlignCenter;
- break;
- }
-
+ kControlBevelButtonContentTag,
+ sizeof(ControlButtonContentInfo),
+ (char *) &mbPtr->bevelButtonContent);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err );
+#endif
+ }
+ switch (butPtr->anchor) {
+ case TK_ANCHOR_N:
+ theAlignment = kControlBevelButtonAlignTop;
+ break;
+ case TK_ANCHOR_NE:
+ theAlignment = kControlBevelButtonAlignTopRight;
+ break;
+ case TK_ANCHOR_E:
+ theAlignment = kControlBevelButtonAlignRight;
+ break;
+ case TK_ANCHOR_SE:
+ theAlignment = kControlBevelButtonAlignBottomRight;
+ break;
+ case TK_ANCHOR_S:
+ theAlignment = kControlBevelButtonAlignBottom;
+ break;
+ case TK_ANCHOR_SW:
+ theAlignment = kControlBevelButtonAlignBottomLeft;
+ break;
+ case TK_ANCHOR_W:
+ theAlignment = kControlBevelButtonAlignLeft;
+ break;
+ case TK_ANCHOR_NW:
+ theAlignment = kControlBevelButtonAlignTopLeft;
+ break;
+ case TK_ANCHOR_CENTER:
+ theAlignment = kControlBevelButtonAlignCenter;
+ break;
+ }
+
err = SetControlData(mbPtr->control, kControlButtonPart,
- kControlBevelButtonGraphicAlignTag,
- sizeof(ControlButtonGraphicAlignment),
+ kControlBevelButtonGraphicAlignTag,
+ sizeof(ControlButtonGraphicAlignment),
(char *) &theAlignment);
- LOG_ON_ERROR(SetControlData_BevelButtonGraphicAlign);
+ if (err != noErr ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err );
+#endif
+ }
}
if (butPtr->flags & GOT_FOCUS) {
- HiliteControl(mbPtr->control,kControlButtonPart);
+ HiliteControl(mbPtr->control,kControlButtonPart);
} else {
- HiliteControl(mbPtr->control,kControlNoPart);
+ HiliteControl(mbPtr->control,kControlNoPart);
}
UpdateControlColors(mbPtr);
if (mbPtr->flags&2) {
- ShowControl(mbPtr->control);
- ShowControl(mbPtr->userPane);
- mbPtr->flags ^= 2;
+ ShowControl(mbPtr->control);
+ ShowControl(mbPtr->userPane);
+ mbPtr->flags ^= 2;
} else {
- Draw1Control(mbPtr->userPane);
- SetControlVisibility(mbPtr->control, true, true);
+ Draw1Control(mbPtr->userPane);
+ SetControlVisibility(mbPtr->control, true, true);
}
if (hasImageOrBitmap) {
- KillPicture(mbPtr->bevelButtonContent.u.picture);
+ KillPicture(mbPtr->bevelButtonContent.u.picture);
}
SetGWorld(saveWorld, saveDevice);
}
@@ -361,13 +365,13 @@ TkpDisplayMenuButton(
*
* TkpDestroyMenuButton --
*
- * Free data structures associated with the menubutton control.
+ * Free data structures associated with the menubutton control.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Restores the default control state.
+ * Restores the default control state.
*
*----------------------------------------------------------------------
*/
@@ -376,18 +380,17 @@ void
TkpDestroyMenuButton(
TkMenuButton *mbPtr)
{
- MacMenuButton *macMbPtr = (MacMenuButton *) mbPtr;
-
+ MacMenuButton * macMbPtr = (MacMenuButton *)mbPtr;
if (macMbPtr->userPane) {
- DisposeControl(macMbPtr->userPane);
- macMbPtr->userPane = NULL;
+ DisposeControl(macMbPtr->userPane);
+ macMbPtr->userPane = NULL;
}
if (macMbPtr->menuRef) {
- short menuID = GetMenuID(macMbPtr->menuRef);
-
- TkMacOSXFreeMenuID(menuID);
- DisposeMenu(macMbPtr->menuRef);
- macMbPtr->menuRef = NULL;
+ short menuID;
+ menuID = GetMenuID(macMbPtr->menuRef);
+ TkMacOSXFreeMenuID(menuID);
+ DisposeMenu(macMbPtr->menuRef);
+ macMbPtr->menuRef = NULL;
}
}
@@ -396,82 +399,82 @@ TkpDestroyMenuButton(
*
* TkpComputeMenuButtonGeometry --
*
- * After changes in a menu button's text or bitmap, this procedure
- * recomputes the menu button's geometry and passes this information
- * along to the geometry manager for the window.
+ * After changes in a menu button's text or bitmap, this procedure
+ * recomputes the menu button's geometry and passes this information
+ * along to the geometry manager for the window.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The menu button's window may change size.
+ * The menu button's window may change size.
*
*----------------------------------------------------------------------
*/
void
TkpComputeMenuButtonGeometry(mbPtr)
- register TkMenuButton *mbPtr; /* Widget record for menu button. */
+ register TkMenuButton *mbPtr; /* Widget record for menu button. */
{
int width, height, mm, pixels;
int hasImageOrBitmap = 0;
mbPtr->inset = mbPtr->highlightWidth + mbPtr->borderWidth;
if (mbPtr->image != None) {
- Tk_SizeOfImage(mbPtr->image, &width, &height);
- if (mbPtr->width > 0) {
- width = mbPtr->width;
- }
- if (mbPtr->height > 0) {
- height = mbPtr->height;
- }
- hasImageOrBitmap = 1;
+ Tk_SizeOfImage(mbPtr->image, &width, &height);
+ if (mbPtr->width > 0) {
+ width = mbPtr->width;
+ }
+ if (mbPtr->height > 0) {
+ height = mbPtr->height;
+ }
+ hasImageOrBitmap = 1;
} else if (mbPtr->bitmap != None) {
- Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
- if (mbPtr->width > 0) {
- width = mbPtr->width;
- }
- if (mbPtr->height > 0) {
- height = mbPtr->height;
- }
- hasImageOrBitmap = 1;
+ Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
+ if (mbPtr->width > 0) {
+ width = mbPtr->width;
+ }
+ if (mbPtr->height > 0) {
+ height = mbPtr->height;
+ }
+ hasImageOrBitmap = 1;
} else {
- hasImageOrBitmap = 0;
- Tk_FreeTextLayout(mbPtr->textLayout);
- mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text,
- -1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth,
- &mbPtr->textHeight);
- width = mbPtr->textWidth;
- height = mbPtr->textHeight;
- if (mbPtr->width > 0) {
- width = mbPtr->width * Tk_TextWidth(mbPtr->tkfont, "0", 1);
- }
- if (mbPtr->height > 0) {
- Tk_FontMetrics fm;
-
- Tk_GetFontMetrics(mbPtr->tkfont, &fm);
- height = mbPtr->height * fm.linespace;
- }
- width += 2*mbPtr->padX;
- height += 2*mbPtr->padY;
+ hasImageOrBitmap = 0;
+ Tk_FreeTextLayout(mbPtr->textLayout);
+ mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text,
+ -1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth,
+ &mbPtr->textHeight);
+ width = mbPtr->textWidth;
+ height = mbPtr->textHeight;
+ if (mbPtr->width > 0) {
+ width = mbPtr->width * Tk_TextWidth(mbPtr->tkfont, "0", 1);
+ }
+ if (mbPtr->height > 0) {
+ Tk_FontMetrics fm;
+
+ Tk_GetFontMetrics(mbPtr->tkfont, &fm);
+ height = mbPtr->height * fm.linespace;
+ }
+ width += 2*mbPtr->padX;
+ height += 2*mbPtr->padY;
}
if (mbPtr->indicatorOn) {
- mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
- pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
- mbPtr->indicatorHeight = kTriangleHeight;
- mbPtr->indicatorWidth = kTriangleWidth + kTriangleMargin;
- width += mbPtr->indicatorWidth;
+ mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
+ pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
+ mbPtr->indicatorHeight = kTriangleHeight;
+ mbPtr->indicatorWidth = kTriangleWidth + kTriangleMargin;
+ width += mbPtr->indicatorWidth;
} else {
- mbPtr->indicatorHeight = 0;
- mbPtr->indicatorWidth = 0;
+ mbPtr->indicatorHeight = 0;
+ mbPtr->indicatorWidth = 0;
}
if (!hasImageOrBitmap) {
- width += TK_POPUP_OFFSET;
+ width += TK_POPUP_OFFSET;
}
Tk_GeometryRequest(mbPtr->tkwin, (int) (width + 2*mbPtr->inset),
- (int) (height + 2*mbPtr->inset));
+ (int) (height + 2*mbPtr->inset));
Tk_SetInternalBorder(mbPtr->tkwin, mbPtr->inset);
}
@@ -480,56 +483,55 @@ TkpComputeMenuButtonGeometry(mbPtr)
*
* ComputeMenuButtonControlParams --
*
- * This procedure computes the various parameters used when creating a
- * Carbon control (NewControl). These are determined by the various tk
- * menu button parameters
+ * This procedure computes the various parameters used
+ * when creating a Carbon control (NewControl)
+ * These are determined by the various tk menu button parameters
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Sets the control initialisation parameters
+ * Sets the control initialisation parameters
*
*----------------------------------------------------------------------
*/
static void
-ComputeMenuButtonControlParams(
- TkMenuButton *mbPtr,
- MenuButtonControlParams *paramsPtr)
+ComputeMenuButtonControlParams(TkMenuButton * mbPtr,
+ MenuButtonControlParams * paramsPtr )
{
int fakeMenuID = 256;
- /*
+ /*
* Determine ProcID based on button type and dimensions
*
- * We need to set minValue to some non-zero value. Otherwise, the markers
- * do not show up
+ * We need to set minValue to some non-zero value,
+ * Otherwise, the markers do not show up
*/
paramsPtr->minValue = kControlBehaviorMultiValueMenu;
paramsPtr->maxValue = 0;
if (mbPtr->image || mbPtr->bitmap) {
- paramsPtr->isBevel = 1;
- if (mbPtr->borderWidth <= 2) {
- paramsPtr->procID = kControlBevelButtonSmallBevelProc;
- } else if (mbPtr->borderWidth == 3) {
- paramsPtr->procID = kControlBevelButtonNormalBevelProc;
- } else {
- paramsPtr->procID = kControlBevelButtonLargeBevelProc;
- }
- if (mbPtr->indicatorOn) {
- paramsPtr->initialValue = fakeMenuID;
- } else {
- paramsPtr->initialValue = 0;
- }
+ paramsPtr->isBevel = 1;
+ if (mbPtr->borderWidth <= 2) {
+ paramsPtr->procID = kControlBevelButtonSmallBevelProc;
+ } else if (mbPtr->borderWidth == 3) {
+ paramsPtr->procID = kControlBevelButtonNormalBevelProc;
+ } else {
+ paramsPtr->procID = kControlBevelButtonLargeBevelProc;
+ }
+ if (mbPtr->indicatorOn) {
+ paramsPtr->initialValue = fakeMenuID;
+ } else {
+ paramsPtr->initialValue = 0;
+ }
} else {
- paramsPtr->isBevel = 0;
- paramsPtr->procID = kControlPopupButtonProc
- + kControlPopupVariableWidthVariant;
- paramsPtr->minValue = -12345;
- paramsPtr->maxValue = -1;
- paramsPtr->initialValue = 0;
+ paramsPtr->isBevel = 0;
+ paramsPtr->procID = kControlPopupButtonProc
+ + kControlPopupVariableWidthVariant;
+ paramsPtr->minValue = -12345;
+ paramsPtr->maxValue = -1;
+ paramsPtr->initialValue = 0;
}
}
@@ -539,184 +541,199 @@ ComputeMenuButtonControlParams(
* returns 0 if same, 1 otherwise
*----------------------------------------------------------------------
*/
-
static void
-CompareControlTitleParams(
- ControlTitleParams *p1Ptr,
- ControlTitleParams *p2Ptr,
- int *titleChanged,
- int *styleChanged)
+CompareControlTitleParams(
+ ControlTitleParams * p1Ptr,
+ ControlTitleParams * p2Ptr,
+ int * titleChanged,
+ int * styleChanged
+)
{
if (p1Ptr->len != p2Ptr->len) {
- *titleChanged = 1;
- } else if (bcmp(p1Ptr->title,p2Ptr->title,p1Ptr->len)) {
- *titleChanged = 1;
+ *titleChanged = 1;
} else {
- *titleChanged = 0;
+ if (bcmp(p1Ptr->title,p2Ptr->title,p1Ptr->len)) {
+ *titleChanged = 1;
+ } else {
+ *titleChanged = 0;
+ }
}
-
if (p1Ptr->len && p2Ptr->len) {
- *styleChanged = bcmp(&p1Ptr->style, &p2Ptr->style,
- sizeof(p2Ptr->style));
+ *styleChanged = bcmp(&p1Ptr->style, &p2Ptr->style, sizeof(p2Ptr->style));
} else {
- *styleChanged = p1Ptr->len||p2Ptr->len;
+ *styleChanged = p1Ptr->len||p2Ptr->len;
}
}
-
+
static void
-ComputeControlTitleParams(
- TkMenuButton *butPtr,
- ControlTitleParams *paramsPtr)
+ComputeControlTitleParams(TkMenuButton * butPtr, ControlTitleParams * paramsPtr )
{
Tk_Font font;
-
- paramsPtr->len = TkFontGetFirstTextLayout(butPtr->textLayout, &font,
- (char*) paramsPtr->title);
- paramsPtr->title[paramsPtr->len] = 0;
+ paramsPtr->len =TkFontGetFirstTextLayout(butPtr->textLayout,&font, (char*) paramsPtr->title);
+ paramsPtr->title [paramsPtr->len] = 0;
if (paramsPtr->len) {
- TkMacOSXInitControlFontStyle(font,&paramsPtr->style);
+ TkMacOSXInitControlFontStyle(font,&paramsPtr->style);
}
}
+
/*
*----------------------------------------------------------------------
*
* MenuButtonInitControl --
*
- * This procedure initialises a Carbon control
+ * This procedure initialises a Carbon control
*
* Results:
- * 0 on success, 1 on failure.
+ * 0 on success, 1 on failure.
*
* Side effects:
- * A background pane control and the control itself is created. The
- * contol is embedded in the background control. The background control
- * is embedded in the root control of the containing window. The creation
- * parameters for the control are also computed
+ * A background pane control and the control itself is created
+ * The contol is embedded in the background control
+ * The background control is embedded in the root control
+ * of the containing window
+ * The creation parameters for the control are also computed
*
*----------------------------------------------------------------------
*/
-
int
-MenuButtonInitControl(
- MacMenuButton *mbPtr, /* Mac button. */
- Rect *paneRect,
- Rect *cntrRect)
+MenuButtonInitControl (
+ MacMenuButton *mbPtr, /* Mac button. */
+ Rect *paneRect,
+ Rect *cntrRect
+)
{
- OSStatus err;
- TkMenuButton *butPtr = (TkMenuButton *) mbPtr;
- SInt16 procID, initialValue, minValue, maxValue;
- Boolean initiallyVisible;
- SInt32 controlReference;
- short menuID;
- ControlRef rootControl =
- TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin));
-
- mbPtr->windowRef = GetWindowFromPort(
- TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
-
- /*
+ OSStatus err;
+ TkMenuButton * butPtr = ( TkMenuButton * )mbPtr;
+ ControlRef rootControl;
+ SInt16 procID;
+ Boolean initiallyVisible;
+ SInt16 initialValue;
+ SInt16 minValue;
+ SInt16 maxValue;
+ SInt32 controlReference;
+ short menuID;
+
+ rootControl = TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin));
+ mbPtr->windowRef = GetWindowFromPort(TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
+ /*
* Set up the user pane
*/
-
initiallyVisible = false;
- initialValue = kControlSupportsEmbedding|kControlHasSpecialBackground;
+ initialValue = kControlSupportsEmbedding|
+ kControlHasSpecialBackground;
minValue = 0;
maxValue = 1;
procID = kControlUserPaneProc;
controlReference = (SInt32)mbPtr;
- mbPtr->userPane = NewControl(mbPtr->windowRef, paneRect, "\p",
- initiallyVisible, initialValue, minValue, maxValue, procID,
- controlReference);
+ mbPtr->userPane = NewControl(mbPtr->windowRef,
+ paneRect, "\p",
+ initiallyVisible,
+ initialValue,
+ minValue,
+ maxValue,
+ procID,
+ controlReference );
if (!mbPtr->userPane) {
- ERR_MSG("Failed to create user pane control");
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Failed to create user pane control\n");
+#endif
+ return 1;
}
err = EmbedControl(mbPtr->userPane,rootControl);
- LOG_ON_ERROR(EmbedControl);
if (err != noErr) {
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Failed to embed user pane control %d\n", (int) err);
+#endif
+ return 1;
}
SetUserPaneSetUpSpecialBackgroundProc(mbPtr->userPane,
- UserPaneBackgroundProc);
+ UserPaneBackgroundProc);
SetUserPaneDrawProc(mbPtr->userPane,UserPaneDraw);
initiallyVisible = false;
ComputeMenuButtonControlParams(butPtr,&mbPtr->params);
-
- /*
- * Do this only if we are using bevel buttons.
- */
-
+ /* Do this only if we are using bevel buttons */
ComputeControlTitleParams(butPtr,&mbPtr->titleParams);
mbPtr->control = NewControl(mbPtr->windowRef,
- cntrRect, "\p", /*mbPtr->titleParams.title,*/
- initiallyVisible, mbPtr->params.initialValue,
- mbPtr->params.minValue, mbPtr->params.maxValue,
- mbPtr->params.procID, controlReference);
-
+ cntrRect, "\p", //mbPtr->titleParams.title,
+ initiallyVisible,
+ mbPtr->params.initialValue,
+ mbPtr->params.minValue,
+ mbPtr->params.maxValue,
+ mbPtr->params.procID,
+ controlReference );
if (!mbPtr->control) {
- ERR_MSG("failed to create control of type %d : line %d",
- mbPtr->params.procID, __LINE__);
- return 1;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"failed to create control of type %d : line %d\n",mbPtr->params.procID, __LINE__);
+#endif
+ return 1;
}
- err = EmbedControl(mbPtr->control, mbPtr->userPane);
- if (err != noErr) {
- ERR_MSG("failed to embed control of type %d,%d\n", procID, (int) err);
- return 1;
+ err = EmbedControl(mbPtr->control,mbPtr->userPane);
+ if (err != noErr ) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"failed to embed control of type %d,%d\n",procID, (int) err);
+#endif
+ return 1;
}
if (mbPtr->params.isBevel) {
- CFStringRef cf = CFStringCreateWithCString(NULL,
- (char*) mbPtr->titleParams.title, kCFStringEncodingUTF8);
-
- SetControlTitleWithCFString(mbPtr->control, cf);
- CFRelease(cf);
- if (mbPtr->titleParams.len) {
- err = SetControlFontStyle(mbPtr->control,
- &mbPtr->titleParams.style);
- LOG_ON_ERROR(SetControlFontStyle);
- if (err != noErr) {
- return 1;
- }
- }
+ CFStringRef cf;
+ cf = CFStringCreateWithCString(NULL,
+ (char*) mbPtr->titleParams.title, kCFStringEncodingUTF8);
+ SetControlTitleWithCFString(mbPtr->control, cf);
+ CFRelease(cf);
+ if (mbPtr->titleParams.len) {
+ err = SetControlFontStyle(mbPtr->control,&mbPtr->titleParams.style);
+ if (err !=noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetControlFontStyle failed %d\n", (int) err);
+#endif
+ return 1;
+ }
+ }
} else {
- CFStringRef cfStr;
-
- err = TkMacOSXGetNewMenuID(mbPtr->info.interp, (TkMenu *) mbPtr, 0,
- &menuID);
- if (err != TCL_OK) {
- return 1;
- }
- err = CreateNewMenu(menuID, kMenuAttrDoNotUseUserCommandKeys,
- &(mbPtr->menuRef));
- LOG_ON_ERROR(CreateNewMenu);
- if (err != noErr) {
- return 1;
- }
- cfStr = CFStringCreateWithCString(NULL, Tk_PathName(mbPtr->info.tkwin),
- kCFStringEncodingUTF8);
- if (!cfStr) {
- ERR_MSG("CFStringCreateWithCString failed");
- return 1;
- }
- err = SetMenuTitleWithCFString(mbPtr->menuRef, cfStr);
- LOG_ON_ERROR(SetMenuTitleWithCFString);
- CFRelease(cfStr);
- if (err != noErr) {
- return 1;
- }
- cfStr = CFStringCreateWithCString(NULL,
- (char*) mbPtr->titleParams.title, kCFStringEncodingUTF8);
- AppendMenuItemText(mbPtr->menuRef, "\px");
- if (cfStr) {
- SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cfStr);
- CFRelease(cfStr);
- }
- err = SetControlData(mbPtr->control, kControlNoPart,
- kControlPopupButtonMenuRefTag,
- sizeof(mbPtr->menuRef), &mbPtr->menuRef);
- SetControlMinimum(mbPtr->control, 1);
- SetControlMaximum(mbPtr->control, 1);
- SetControlValue(mbPtr->control, 1);
+ CFStringRef cfStr;
+ err = TkMacOSXGetNewMenuID(mbPtr->info.interp, (TkMenu *)mbPtr, 0, &menuID);
+ if (err != TCL_OK) {
+ return 1;
+ }
+ err = CreateNewMenu(menuID, kMenuAttrDoNotUseUserCommandKeys,
+ &(mbPtr->menuRef));
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"CreateNewMenu failed, %d.\n", (int) err);
+#endif
+ return 1;
+ }
+ cfStr = CFStringCreateWithCString(NULL, Tk_PathName(mbPtr->info.tkwin),
+ kCFStringEncodingUTF8);
+ if (!cfStr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"CFStringCreateWithCString failed.\n");
+#endif
+ return 1;
+ }
+ err = SetMenuTitleWithCFString(mbPtr->menuRef, cfStr);
+ CFRelease(cfStr);
+ if (err != noErr) {
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetMenuTitleWithCFString failed, %d.\n", (int) err);
+#endif
+ return 1;
+ }
+ cfStr = CFStringCreateWithCString(NULL,
+ (char*) mbPtr->titleParams.title, kCFStringEncodingUTF8);
+ AppendMenuItemText(mbPtr->menuRef, "\px");
+ if (cfStr) {
+ SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cfStr);
+ CFRelease(cfStr);
+ }
+ err = SetControlData(mbPtr->control,
+ kControlNoPart,
+ kControlPopupButtonMenuRefTag,
+ sizeof(mbPtr->menuRef), &mbPtr->menuRef);
+ SetControlMinimum(mbPtr->control, 1);
+ SetControlMaximum(mbPtr->control, 1);
+ SetControlValue(mbPtr->control, 1);
}
mbPtr->flags |= 2;
return 0;
@@ -727,14 +744,15 @@ MenuButtonInitControl(
*
* SetUserPane
*
- * Utility function to add a UserPaneDrawProc to a userPane control. From
- * MoreControls code from Apple DTS.
+ * Utility function to add a UserPaneDrawProc
+ * to a userPane control. From MoreControls code
+ * from Apple DTS.
*
* Results:
- * MacOS system error.
+ * MacOS system error.
*
* Side effects:
- * The user pane gets a new UserPaneDrawProc.
+ * The user pane gets a new UserPaneDrawProc.
*
*--------------------------------------------------------------
*/
@@ -742,11 +760,12 @@ OSErr SetUserPaneDrawProc (
ControlRef control,
ControlUserPaneDrawProcPtr upp)
{
- ControlUserPaneDrawUPP myControlUserPaneDrawUPP =
- NewControlUserPaneDrawUPP(upp);
-
- return SetControlData(control, kControlNoPart,kControlUserPaneDrawProcTag,
- sizeof(myControlUserPaneDrawUPP), (Ptr)&myControlUserPaneDrawUPP);
+ ControlUserPaneDrawUPP myControlUserPaneDrawUPP;
+ myControlUserPaneDrawUPP = NewControlUserPaneDrawUPP(upp);
+ return SetControlData (control,
+ kControlNoPart, kControlUserPaneDrawProcTag,
+ sizeof(myControlUserPaneDrawUPP),
+ (Ptr) &myControlUserPaneDrawUPP);
}
/*
@@ -754,29 +773,28 @@ OSErr SetUserPaneDrawProc (
*
* SetUserPaneSetUpSpecialBackgroundProc --
*
- * Utility function to add a UserPaneBackgroundProc to a userPane control
+ * Utility function to add a UserPaneBackgroundProc
+ * to a userPane control
*
* Results:
- * MacOS system error.
+ * MacOS system error.
*
* Side effects:
- * The user pane gets a new UserPaneBackgroundProc.
+ * The user pane gets a new UserPaneBackgroundProc.
*
*--------------------------------------------------------------
*/
-
OSErr
SetUserPaneSetUpSpecialBackgroundProc(
- ControlRef control,
+ ControlRef control,
ControlUserPaneBackgroundProcPtr upp)
{
- ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP =
- NewControlUserPaneBackgroundUPP(upp);
-
- return SetControlData(control, kControlNoPart,
- kControlUserPaneBackgroundProcTag,
- sizeof(myControlUserPaneBackgroundUPP),
- (Ptr) &myControlUserPaneBackgroundUPP);
+ ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP;
+ myControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP(upp);
+ return SetControlData (control, kControlNoPart,
+ kControlUserPaneBackgroundProcTag,
+ sizeof(myControlUserPaneBackgroundUPP),
+ (Ptr) &myControlUserPaneBackgroundUPP);
}
/*
@@ -784,29 +802,28 @@ SetUserPaneSetUpSpecialBackgroundProc(
*
* UserPaneDraw --
*
- * This function draws the background of the user pane that will lie
- * under checkboxes and radiobuttons.
+ * This function draws the background of the user pane that will
+ * lie under checkboxes and radiobuttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The user pane gets updated to the current color.
+ * The user pane gets updated to the current color.
*
*--------------------------------------------------------------
*/
-
void
UserPaneDraw(
ControlRef control,
ControlPartCode cpc)
{
Rect contrlRect;
- MacMenuButton *mbPtr = (MacMenuButton *) GetControlReference(control);
-
+ MacMenuButton * mbPtr;
+ mbPtr = ( MacMenuButton *)GetControlReference(control);
GetControlBounds(control,&contrlRect);
- RGBBackColor(&mbPtr->userPaneBackground);
- EraseRect(&contrlRect);
+ RGBBackColor (&mbPtr->userPaneBackground);
+ EraseRect (&contrlRect);
}
/*
@@ -814,14 +831,14 @@ UserPaneDraw(
*
* UserPaneBackgroundProc --
*
- * This function sets up the background of the user pane that will lie
- * under checkboxes and radiobuttons.
+ * This function sets up the background of the user pane that will
+ * lie under checkboxes and radiobuttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The user pane background gets set to the current color.
+ * The user pane background gets set to the current color.
*
*--------------------------------------------------------------
*/
@@ -831,62 +848,54 @@ UserPaneBackgroundProc(
ControlHandle control,
ControlBackgroundPtr info)
{
- MacMenuButton *mbPtr = (MacMenuButton *) GetControlReference(control);
-
+ MacMenuButton * mbPtr;
+ mbPtr = (MacMenuButton *)GetControlReference(control);
if (info->colorDevice) {
- RGBBackColor(&mbPtr->userPaneBackground);
+ RGBBackColor (&mbPtr->userPaneBackground);
}
}
-
-/*
+
+/*
*--------------------------------------------------------------
- *
+ *
* UpdateControlColors --
- *
- * This function will review the colors used to display a Macintosh
- * button. If any non-standard colors are used we create a custom palette
- * for the button, populate with the colors for the button and install
- * the palette.
- *
- * Under Appearance, we just set the pointer that will be used by the
- * UserPaneDrawProc.
- *
+ *
+ * This function will review the colors used to display
+ * a Macintosh button. If any non-standard colors are
+ * used we create a custom palette for the button, populate
+ * with the colors for the button and install the palette.
+ *
+ * Under Appearance, we just set the pointer that will be
+ * used by the UserPaneDrawProc.
+ *
* Results:
- * None.
- *
+ * None.
+ *
* Side effects:
- * The Macintosh control may get a custom palette installed.
+ * The Macintosh control may get a custom palette installed.
*
*--------------------------------------------------------------
*/
static int
-UpdateControlColors(
- MacMenuButton *mbPtr)
+UpdateControlColors(MacMenuButton * mbPtr)
{
XColor *xcolor;
TkMenuButton * butPtr = ( TkMenuButton * )mbPtr;
-
+
/*
- * Under Appearance we cannot change the background of the button itself.
- * However, the color we are setting is the color of the containing
- * userPane. This will be the color that peeks around the rounded corners
- * of the button. We make this the highlightbackground rather than the
- * background, because if you color the background of a frame containing a
- * button, you usually also color the highlightbackground as well, or you
- * will get a thin grey ring around the button.
+ * Under Appearance we cannot change the background of the
+ * button itself. However, the color we are setting is the color
+ * of the containing userPane. This will be the color that peeks
+ * around the rounded corners of the button.
+ * We make this the highlightbackground rather than the background,
+ * because if you color the background of a frame containing a
+ * button, you usually also color the highlightbackground as well,
+ * or you will get a thin grey ring around the button.
*/
xcolor = Tk_3DBorderColor(butPtr->normalBorder);
TkSetMacColor(xcolor->pixel, &mbPtr->userPaneBackground);
-
+
return false;
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index b43e51d..b49bc4b 100644
--- a/macosx/tkMacOSXMouseEvent.c
+++ b/macosx/tkMacOSXMouseEvent.c
@@ -54,7 +54,7 @@
* software in accordance with the terms specified in this
* license.
*
- * RCS: @(#) $Id: tkMacOSXMouseEvent.c,v 1.26 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXMouseEvent.c,v 1.27 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -234,8 +234,11 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
status = GetEventParameter(eventPtr->eventRef,
kEventParamMouseWheelDelta, typeLongInteger, NULL,
sizeof(long), NULL, &medPtr->delta);
- if (status != noErr) {
- ERR_MSG("Failed to retrieve mouse wheel delta, %d", (int) status);
+ if (status != noErr ) {
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr,
+ "Failed to retrieve mouse wheel delta, %d\n", (int) status);
+#endif
statusPtr->err = 1;
return false;
} else {
@@ -530,22 +533,21 @@ GeneratePollingEvents(MouseEventData * medPtr)
*/
static void
-BringWindowForward(
- WindowRef wRef,
- Boolean isFrontProcess)
+BringWindowForward(WindowRef wRef, Boolean isFrontProcess)
{
if (!isFrontProcess) {
ProcessSerialNumber ourPsn = {0, kCurrentProcess};
OSStatus status = SetFrontProcess(&ourPsn);
if (status != noErr) {
- ERR_MSG("SetFrontProcess failed, %d", (int) status);
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"SetFrontProcess failed, %d\n", (int) status);
+#endif
}
}
-
+
if (!TkpIsWindowFloating(wRef)) {
- if (IsValidWindowPtr(wRef)) {
+ if (IsValidWindowPtr(wRef))
SelectWindow(wRef);
- }
}
}
diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c
index d90791d..8aab83c 100644
--- a/macosx/tkMacOSXScale.c
+++ b/macosx/tkMacOSXScale.c
@@ -1,16 +1,16 @@
-/*
+/*
* tkMacOSXScale.c --
*
- * This file implements the Macintosh specific portion of the scale
- * widget.
+ * This file implements the Macintosh specific portion of the
+ * scale widget.
*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* Copyright (c) 1998-2000 by Scriptics Corporation.
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXScale.c,v 1.9 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXScale.c,v 1.10 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -19,7 +19,6 @@
/*
* Defines used in this file.
*/
-
#define slider 1110
#define inSlider 1
#define inInc 2
@@ -44,10 +43,10 @@ static ControlActionUPP scaleActionProc = NULL; /* Pointer to func. */
* Forward declarations for procedures defined later in this file:
*/
-static void MacScaleEventProc(ClientData clientData,
- XEvent *eventPtr);
-static pascal void ScaleActionProc(ControlRef theControl,
- ControlPartCode partCode);
+static void MacScaleEventProc _ANSI_ARGS_((ClientData clientData,
+ XEvent *eventPtr));
+static pascal void ScaleActionProc _ANSI_ARGS_((ControlRef theControl,
+ ControlPartCode partCode));
/*
*----------------------------------------------------------------------
@@ -66,19 +65,20 @@ static pascal void ScaleActionProc(ControlRef theControl,
*/
TkScale *
-TkpCreateScale(
- Tk_Window tkwin)
+TkpCreateScale(tkwin)
+ Tk_Window tkwin;
{
- MacScale *macScalePtr = (MacScale *) ckalloc(sizeof(MacScale));
-
+ MacScale *macScalePtr;
+
+ macScalePtr = (MacScale *) ckalloc(sizeof(MacScale));
macScalePtr->scaleHandle = NULL;
if (scaleActionProc == NULL) {
scaleActionProc = NewControlActionUPP(ScaleActionProc);
}
-
+
Tk_CreateEventHandler(tkwin, ButtonPressMask,
MacScaleEventProc, (ClientData) macScalePtr);
-
+
return (TkScale *) macScalePtr;
}
@@ -99,15 +99,14 @@ TkpCreateScale(
*/
void
-TkpDestroyScale(
- TkScale *scalePtr)
+TkpDestroyScale(scalePtr)
+ TkScale *scalePtr;
{
MacScale *macScalePtr = (MacScale *) scalePtr;
-
+
/*
* Free Macintosh control.
*/
-
if (macScalePtr->scaleHandle != NULL) {
DisposeControl(macScalePtr->scaleHandle);
}
@@ -118,8 +117,8 @@ TkpDestroyScale(
*
* TkpDisplayScale --
*
- * This procedure is invoked as an idle handler to redisplay the contents
- * of a scale widget.
+ * This procedure is invoked as an idle handler to redisplay
+ * the contents of a scale widget.
*
* Results:
* None.
@@ -131,8 +130,8 @@ TkpDestroyScale(
*/
void
-TkpDisplayScale(
- ClientData clientData) /* Widget record for scale. */
+TkpDisplayScale(clientData)
+ ClientData clientData; /* Widget record for scale. */
{
TkScale *scalePtr = (TkScale *) clientData;
Tk_Window tkwin = scalePtr->tkwin;
@@ -142,13 +141,19 @@ TkpDisplayScale(
MacScale *macScalePtr = (MacScale *) clientData;
Rect r;
WindowRef windowRef;
- CGrafPtr destPort, saveWorld;
+ CGrafPtr destPort;
+ CGrafPtr saveWorld;
GDHandle saveDevice;
MacDrawable *macDraw;
- SInt32 initialValue, minValue, maxValue;
- UInt16 numTicks;
-
- ERR_MSG("TkpDisplayScale");
+ SInt32 initialValue;
+ SInt32 minValue;
+ SInt32 maxValue;
+ UInt16 numTicks;
+
+
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"TkpDisplayScale\n");
+#endif
scalePtr->flags &= ~REDRAW_PENDING;
if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) {
goto done;
@@ -162,7 +167,8 @@ TkpDisplayScale(
if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
Tcl_Preserve((ClientData) interp);
sprintf(string, scalePtr->format, scalePtr->value);
- result = Tcl_VarEval(interp, scalePtr->command, " ", string, NULL);
+ result = Tcl_VarEval(interp, scalePtr->command, " ", string,
+ (char *) NULL);
if (result != TCL_OK) {
Tcl_AddErrorInfo(interp, "\n (command executed by scale)");
Tcl_BackgroundError(interp);
@@ -177,13 +183,15 @@ TkpDisplayScale(
Tcl_Release((ClientData) scalePtr);
/*
- * Now handle the part of redisplay that is the same for horizontal and
- * vertical scales: border and traversal highlight.
+ * Now handle the part of redisplay that is the same for
+ * horizontal and vertical scales: border and traversal
+ * highlight.
*/
if (scalePtr->highlightWidth != 0) {
- GC gc = Tk_GCForColor(scalePtr->highlightColorPtr,Tk_WindowId(tkwin));
-
+ GC gc;
+
+ gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin));
Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth,
Tk_WindowId(tkwin));
}
@@ -196,7 +204,6 @@ TkpDisplayScale(
/*
* Set up port for drawing Macintosh control.
*/
-
macDraw = (MacDrawable *) Tk_WindowId(tkwin);
destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
windowRef = GetWindowFromPort(destPort);
@@ -211,76 +218,79 @@ TkpDisplayScale(
#define MAC_OSX_SCROLL_WIDTH 10
if (scalePtr->orient == ORIENT_HORIZONTAL) {
- int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
-
- if (offset < 0) {
- offset = 0;
- }
-
- r.left = macDraw->xOff + scalePtr->inset;
- r.top = macDraw->yOff + offset;
- r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
- r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2;
+ int offset;
+ offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
+ if (offset < 0) {
+ offset = 0;
+ }
+
+ r.left = macDraw->xOff + scalePtr->inset;
+ r.top = macDraw->yOff + offset;
+ r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
+ r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2;
} else {
- int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
-
- if (offset < 0) {
- offset = 0;
- }
-
- r.left = macDraw->xOff + offset;
- r.top = macDraw->yOff + scalePtr->inset;
- r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2;
- r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
+ int offset;
+
+ offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
+ if (offset < 0) {
+ offset = 0;
+ }
+
+ r.left = macDraw->xOff + offset;
+ r.top = macDraw->yOff + scalePtr->inset;
+ r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2;
+ r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
}
if (macScalePtr->scaleHandle == NULL) {
- ERR_MSG("Initialising scale");
-
- initialValue = scalePtr->value;
- if (scalePtr->orient == ORIENT_HORIZONTAL) {
- minValue = scalePtr->fromValue;
- maxValue = scalePtr->toValue;
- } else {
- minValue = scalePtr->fromValue;
- maxValue = scalePtr->toValue;
- }
-
- if (scalePtr->tickInterval == 0) {
- numTicks = 0;
- } else {
- numTicks = (maxValue - minValue)/scalePtr->tickInterval;
- }
-
- CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue,
- kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc,
- &(macScalePtr->scaleHandle));
- SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr);
+
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Initialising scale\n");
+#endif
+
+ initialValue = scalePtr->value;
+ if (scalePtr->orient == ORIENT_HORIZONTAL) {
+ minValue = scalePtr->fromValue;
+ maxValue = scalePtr->toValue;
+ } else {
+ minValue = scalePtr->fromValue;
+ maxValue = scalePtr->toValue;
+ }
+
+ if (scalePtr->tickInterval == 0) {
+ numTicks = 0;
+ } else {
+ numTicks = (maxValue - minValue)/scalePtr->tickInterval;
+ }
+
+ CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue,
+ kControlSliderPointsDownOrRight, numTicks,
+ 1, scaleActionProc,
+ &(macScalePtr->scaleHandle));
+ SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr);
/*
* If we are foremost than make us active.
*/
-
if (windowRef == FrontWindow()) {
macScalePtr->flags |= ACTIVE;
}
} else {
- SetControlBounds(macScalePtr->scaleHandle, &r);
- SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value);
- SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue);
- SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue);
+ SetControlBounds(macScalePtr->scaleHandle, &r);
+ SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value);
+ SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue);
+ SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue);
}
/*
* Finally draw the control.
*/
-
SetControlVisibility(macScalePtr->scaleHandle,true,true);
HiliteControl(macScalePtr->scaleHandle,0);
Draw1Control(macScalePtr->scaleHandle);
SetGWorld(saveWorld, saveDevice);
- done:
+done:
scalePtr->flags &= ~REDRAW_ALL;
}
@@ -289,12 +299,13 @@ TkpDisplayScale(
*
* TkpScaleElement --
*
- * Determine which part of a scale widget lies under a given point.
+ * Determine which part of a scale widget lies under a given
+ * point.
*
* Results:
- * The return value is either TROUGH1, SLIDER, TROUGH2, or OTHER,
- * depending on which of the scale's active elements (if any) is under
- * the point at (x,y).
+ * The return value is either TROUGH1, SLIDER, TROUGH2, or
+ * OTHER, depending on which of the scale's active elements
+ * (if any) is under the point at (x,y).
*
* Side effects:
* None.
@@ -303,9 +314,9 @@ TkpDisplayScale(
*/
int
-TkpScaleElement(
- TkScale *scalePtr, /* Widget record for scale. */
- int x, int y) /* Coordinates within scalePtr's window. */
+TkpScaleElement(scalePtr, x, y)
+ TkScale *scalePtr; /* Widget record for scale. */
+ int x, y; /* Coordinates within scalePtr's window. */
{
MacScale *macScalePtr = (MacScale *) scalePtr;
ControlPartCode part;
@@ -313,9 +324,10 @@ TkpScaleElement(
Rect bounds;
CGrafPtr saveWorld;
GDHandle saveDevice;
- GWorldPtr destPort;
-
- ERR_MSG("TkpScaleElement");
+ GWorldPtr destPort;
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"TkpScaleElement\n");
+#endif
destPort = TkMacOSXGetDrawablePort(Tk_WindowId(scalePtr->tkwin));
GetGWorld(&saveWorld, &saveDevice);
@@ -323,35 +335,37 @@ TkpScaleElement(
/*
* All of the calculations in this procedure mirror those in
- * DisplayScrollbar. Be sure to keep the two consistent.
+ * DisplayScrollbar. Be sure to keep the two consistent.
*/
- TkMacOSXWinBounds((TkWindow *) scalePtr->tkwin, &bounds);
+ TkMacOSXWinBounds((TkWindow *) scalePtr->tkwin, &bounds);
where.h = x + bounds.left;
where.v = y + bounds.top;
part = TestControl(macScalePtr->scaleHandle, where);
-
+
SetGWorld(saveWorld, saveDevice);
- ERR_MSG("ScalePart %d, pos ( %d %d )", part, where.h, where.v);
-
+#ifdef TK_MAC_DEBUG
+ fprintf (stderr,"ScalePart %d, pos ( %d %d )\n", part, where.h, where.v );
+#endif
+
switch (part) {
- case inSlider:
- return SLIDER;
- case inInc:
- if (scalePtr->orient == ORIENT_VERTICAL) {
- return TROUGH1;
- } else {
- return TROUGH2;
- }
- case inDecr:
- if (scalePtr->orient == ORIENT_VERTICAL) {
- return TROUGH2;
- } else {
- return TROUGH1;
- }
- default:
- return OTHER;
+ case inSlider:
+ return SLIDER;
+ case inInc:
+ if (scalePtr->orient == ORIENT_VERTICAL) {
+ return TROUGH1;
+ } else {
+ return TROUGH2;
+ }
+ case inDecr:
+ if (scalePtr->orient == ORIENT_VERTICAL) {
+ return TROUGH2;
+ } else {
+ return TROUGH1;
+ }
+ default:
+ return OTHER;
}
}
@@ -360,23 +374,23 @@ TkpScaleElement(
*
* MacScaleEventProc --
*
- * This procedure is invoked by the Tk dispatcher for ButtonPress events
- * on scales.
+ * This procedure is invoked by the Tk dispatcher for
+ * ButtonPress events on scales.
*
* Results:
* None.
*
* Side effects:
- * When the window gets deleted, internal structures get cleaned up. When
- * it gets exposed, it is redisplayed.
+ * When the window gets deleted, internal structures get
+ * cleaned up. When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
-MacScaleEventProc(
- ClientData clientData, /* Information about window. */
- XEvent *eventPtr) /* Information about event. */
+MacScaleEventProc(clientData, eventPtr)
+ ClientData clientData; /* Information about window. */
+ XEvent *eventPtr; /* Information about event. */
{
MacScale *macScalePtr = (MacScale *) clientData;
Point where;
@@ -386,43 +400,44 @@ MacScaleEventProc(
GDHandle saveDevice;
GWorldPtr destPort;
- ERR_MSG("MacScaleEventProc");
-
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"MacScaleEventProc\n" );
+#endif
/*
- * To call Macintosh control routines we must have the port set to the
- * window containing the control. We will then test which part of the
- * control was hit and act accordingly.
+ * To call Macintosh control routines we must have the port
+ * set to the window containing the control. We will then test
+ * which part of the control was hit and act accordingly.
*/
-
destPort = TkMacOSXGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin));
GetGWorld(&saveWorld, &saveDevice);
SetGWorld(destPort, NULL);
TkMacOSXSetUpClippingRgn(Tk_WindowId(macScalePtr->info.tkwin));
- TkMacOSXWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds);
+ TkMacOSXWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds);
where.h = eventPtr->xbutton.x + bounds.left;
where.v = eventPtr->xbutton.y + bounds.top;
- ERR_MSG("calling TestControl");
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"calling TestControl\n");
+#endif
part = TestControl(macScalePtr->scaleHandle, where);
if (part == 0) {
return;
}
-
+
part = TrackControl(macScalePtr->scaleHandle, where, scaleActionProc);
-
+
/*
* Update the value for the widget.
*/
-
macScalePtr->info.value = GetControlValue(macScalePtr->scaleHandle);
/* TkScaleSetValue(&macScalePtr->info, macScalePtr->info.value, 1, 0); */
/*
- * The TrackControl call will "eat" the ButtonUp event. We now generate a
- * ButtonUp event so Tk will unset implicit grabs etc.
+ * The TrackControl call will "eat" the ButtonUp event. We now
+ * generate a ButtonUp event so Tk will unset implicit grabs etc.
*/
-
TkGenerateButtonEventForXPointer(Tk_WindowId(macScalePtr->info.tkwin));
+
SetGWorld(saveWorld, saveDevice);
}
@@ -431,9 +446,9 @@ MacScaleEventProc(
*
* ScaleActionProc --
*
- * Callback procedure used by the Macintosh toolbox call TrackControl.
- * This call will update the display while the scrollbar is being
- * manipulated by the user.
+ * Callback procedure used by the Macintosh toolbox call
+ * TrackControl. This call will update the display while
+ * the scrollbar is being manipulated by the user.
*
* Results:
* None.
@@ -452,18 +467,13 @@ ScaleActionProc(
int value;
TkScale *scalePtr = (TkScale *) GetControlReference(theControl);
- ERR_MSG("ScaleActionProc");
- value = GetControlValue(theControl);
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"ScaleActionProc\n");
+#endif
+ value = GetControlValue(theControl);
TkScaleSetValue(scalePtr, value, 1, 1);
Tcl_Preserve((ClientData) scalePtr);
Tcl_DoOneEvent(TCL_IDLE_EVENTS);
Tcl_Release((ClientData) scalePtr);
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
+
diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c
index a20ac8c..1c8901a 100644
--- a/macosx/tkMacOSXWindowEvent.c
+++ b/macosx/tkMacOSXWindowEvent.c
@@ -54,7 +54,7 @@
* software in accordance with the terms specified in this
* license.
*
- * RCS: @(#) $Id: tkMacOSXWindowEvent.c,v 1.19 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXWindowEvent.c,v 1.20 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -203,37 +203,39 @@ TkMacOSXProcessWindowEvent(
sizeof(whichWindow), NULL,
&whichWindow);
if (status != noErr) {
- ERR_MSG("TkMacOSXHandleWindowEvent: Failed to retrieve window");
+#ifdef TK_MAC_DEBUG
+ fprintf ( stderr, "TkMacOSXHandleWindowEvent:Failed to retrieve window" );
+#endif
return 0;
}
-
+
window = TkMacOSXGetXWindow(whichWindow);
switch (eventPtr->eKind) {
- case kEventWindowActivated:
- eventFound |= GenerateActivateEvents(window, 1);
- eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
- break;
- case kEventWindowDeactivated:
- eventFound |= GenerateActivateEvents(window, 0);
- eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
- break;
- case kEventWindowUpdate:
- if (GenerateUpdateEvent(window)) {
- eventFound = true;
- }
- break;
- case kEventWindowExpanded: {
- TkDisplay *dispPtr = TkGetDisplayList();
- TkWindow *winPtr = (TkWindow *)
- Tk_IdToWindow(dispPtr->display, window);
-
- if (winPtr) {
- TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
- ZoomState : NormalState);
- }
- break;
- }
+ case kEventWindowActivated:
+ eventFound |= GenerateActivateEvents(window, 1);
+ eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
+ break;
+ case kEventWindowDeactivated:
+ eventFound |= GenerateActivateEvents(window, 0);
+ eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
+ break;
+ case kEventWindowUpdate:
+ if (GenerateUpdateEvent(window)) {
+ eventFound = true;
+ }
+ break;
+ case kEventWindowExpanded: {
+ TkDisplay *dispPtr;
+ TkWindow *winPtr;
+ dispPtr = TkGetDisplayList();
+ winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
+ if (winPtr) {
+ TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
+ ZoomState : NormalState);
+ }
+ break;
+ }
}
return 0;
}
@@ -243,10 +245,10 @@ TkMacOSXProcessWindowEvent(
*
* GenerateUpdateEvent --
*
- * Given a Macintosh window update event this function generates all the
- * Expose XEvents needed by Tk.
+ * Given a Macintosh window update event this function generates
+ * all the Expose XEvents needed by Tk.
*
- * Results:
+ * Results:
* True if event(s) are generated - false otherwise.
*
* Side effects:
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index d6a78c2..c16f287 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -2,18 +2,18 @@
* tkMacOSXWm.c --
*
* This module takes care of the interactions between a Tk-based
- * application and the window manager. Among other things, it implements
- * the "wm" command and passes geometry information to the window
- * manager.
+ * application and the window manager. Among other things, it
+ * implements the "wm" command and passes geometry information
+ * to the window manager.
*
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2006 Daniel A. Steffen <das@users.sourceforge.net>
*
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXWm.c,v 1.47 2007/04/13 14:51:18 dkf Exp $
+ * RCS: @(#) $Id: tkMacOSXWm.c,v 1.48 2007/04/21 19:06:38 hobbs Exp $
*/
#include "tkMacOSXInt.h"
@@ -41,19 +41,21 @@
TkMacOSXWindowList *tkMacOSXWindowListPtr = NULL;
/*
- * The variable below is used to enable or disable tracing in this module. If
- * tracing is enabled, then information is printed on standard output about
- * interesting interactions with the window manager.
+ * The variable below is used to enable or disable tracing in this
+ * module. If tracing is enabled, then information is printed on
+ * standard output about interesting interactions with the window
+ * manager.
*/
static int wmTracing = 0;
/*
- * The following structure is the official type record for geometry management
- * of top-level windows.
+ * The following structure is the official type record for geometry
+ * management of top-level windows.
*/
-static void TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
+static void TopLevelReqProc _ANSI_ARGS_((ClientData dummy,
+ Tk_Window tkwin));
static const Tk_GeomMgr wmMgrType = {
"wm", /* name */
@@ -78,119 +80,126 @@ static int windowHashInit = false;
* Forward declarations for procedures defined in this file:
*/
-static void InitialWindowBounds(TkWindow *winPtr, Rect *geometry);
-static int ParseGeometry(Tcl_Interp *interp,
- char *string, TkWindow *winPtr);
-static void TopLevelEventProc(ClientData clientData,
- XEvent *eventPtr);
-static void WmStackorderToplevelWrapperMap(TkWindow *winPtr,
- Display *display, Tcl_HashTable *table);
-static void TopLevelReqProc(ClientData dummy,
- Tk_Window tkwin);
-static void UpdateGeometryInfo(ClientData clientData);
-static void UpdateSizeHints(TkWindow *winPtr);
-static void UpdateVRootGeometry(WmInfo *wmPtr);
-static int WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
+static void InitialWindowBounds _ANSI_ARGS_((TkWindow *winPtr,
+ Rect *geometry));
+static int ParseGeometry _ANSI_ARGS_((Tcl_Interp *interp,
+ char *string, TkWindow *winPtr));
+static void TopLevelEventProc _ANSI_ARGS_((ClientData clientData,
+ XEvent *eventPtr));
+static void WmStackorderToplevelWrapperMap _ANSI_ARGS_((
+ TkWindow *winPtr,
+ Display *display,
+ Tcl_HashTable *table));
+static void TopLevelReqProc _ANSI_ARGS_((ClientData dummy,
+ Tk_Window tkwin));
+static void UpdateGeometryInfo _ANSI_ARGS_((
+ ClientData clientData));
+static void UpdateSizeHints _ANSI_ARGS_((TkWindow *winPtr));
+static void UpdateVRootGeometry _ANSI_ARGS_((WmInfo *wmPtr));
+static int WmAspectCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmAttributesCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
static Tcl_Obj * WmAttrGetModifiedStatus(WindowRef macWindow);
static Tcl_Obj * WmAttrGetTitlePath(WindowRef macWindow);
static Tcl_Obj * WmAttrGetAlpha(WindowRef macWindow);
static Tcl_Obj * WmAttrGetNotifyStatus(void);
static void WmAttrSetNotifyStatus(int state);
-static int WmClientCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmColormapwindowsCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmGridCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmOverrideredirectCmd(Tk_Window tkwin, TkWindow*winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmStateCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static int WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]);
-static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
-static int WmWinStyle(Tcl_Interp *interp, TkWindow *winPtr,
- int objc, Tcl_Obj *CONST objv[]);
-static void ApplyWindowAttributeChanges(TkWindow *winPtr,
- int newAttributes, int oldAttributes, int create);
-
+static int WmClientCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmColormapwindowsCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmCommandCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmDeiconifyCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmFocusmodelCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmFrameCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmGeometryCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmGridCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmGroupCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconbitmapCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconifyCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconmaskCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconnameCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconphotoCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconpositionCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmIconwindowCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmMaxsizeCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmMinsizeCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmOverrideredirectCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmPositionfromCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmProtocolCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmResizableCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmSizefromCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmStackorderCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmStateCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmTitleCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmTransientCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static int WmWithdrawCmd _ANSI_ARGS_((Tk_Window tkwin,
+ TkWindow *winPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *CONST objv[]));
+static void WmUpdateGeom _ANSI_ARGS_((WmInfo *wmPtr,
+ TkWindow *winPtr));
+static int WmWinStyle _ANSI_ARGS_((Tcl_Interp *interp,
+ TkWindow *winPtr, int objc,
+ Tcl_Obj * CONST objv[]));
+static void ApplyWindowAttributeChanges _ANSI_ARGS_((
+ TkWindow *winPtr, int newAttributes,
+ int oldAttributes, int create));
+
/*
*--------------------------------------------------------------
*
@@ -2375,12 +2384,12 @@ Tcl_Obj *CONST objv[]; /* Argument objects. */
*/
static int
-WmProtocolCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmProtocolCmd(tkwin, winPtr, interp, objc, objv)
+Tk_Window tkwin; /* Main window of the application. */
+TkWindow *winPtr; /* Toplevel to work with */
+Tcl_Interp *interp; /* Current interpreter. */
+int objc; /* Number of arguments. */
+Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
register ProtocolHandler *protPtr, *prevPtr;
@@ -2396,11 +2405,10 @@ WmProtocolCmd(
/*
* Return a list of all defined protocols for the window.
*/
-
for (protPtr = wmPtr->protPtr; protPtr != NULL;
- protPtr = protPtr->nextPtr) {
+ protPtr = protPtr->nextPtr) {
Tcl_AppendElement(interp,
- Tk_GetAtomName((Tk_Window) winPtr, protPtr->protocol));
+ Tk_GetAtomName((Tk_Window) winPtr, protPtr->protocol));
}
return TCL_OK;
}
@@ -2409,7 +2417,6 @@ WmProtocolCmd(
/*
* Return the command to handle a given protocol.
*/
-
for (protPtr = wmPtr->protPtr; protPtr != NULL;
protPtr = protPtr->nextPtr) {
if (protPtr->protocol == protocol) {
@@ -2421,8 +2428,9 @@ WmProtocolCmd(
}
/*
- * Delete any current protocol handler, then create a new one with the
- * specified command, unless the command is empty.
+ * Delete any current protocol handler, then create a new
+ * one with the specified command, unless the command is
+ * empty.
*/
for (protPtr = wmPtr->protPtr, prevPtr = NULL; protPtr != NULL;
@@ -2467,12 +2475,12 @@ WmProtocolCmd(
*/
static int
-WmResizableCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmResizableCmd(tkwin, winPtr, interp, objc, objv)
+ Tk_Window tkwin; /* Main window of the application. */
+ TkWindow *winPtr; /* Toplevel to work with */
+ Tcl_Interp *interp; /* Current interpreter. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int width, height;
@@ -2542,12 +2550,12 @@ WmResizableCmd(
*/
static int
-WmSizefromCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmSizefromCmd(tkwin, winPtr, interp, objc, objv)
+Tk_Window tkwin; /* Main window of the application. */
+TkWindow *winPtr; /* Toplevel to work with */
+Tcl_Interp *interp; /* Current interpreter. */
+int objc; /* Number of arguments. */
+Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static CONST char *optionStrings[] = {
@@ -2607,12 +2615,12 @@ WmSizefromCmd(
*/
static int
-WmStackorderCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmStackorderCmd(tkwin, winPtr, interp, objc, objv)
+Tk_Window tkwin; /* Main window of the application. */
+TkWindow *winPtr; /* Toplevel to work with */
+Tcl_Interp *interp; /* Current interpreter. */
+int objc; /* Number of arguments. */
+Tcl_Obj *CONST objv[]; /* Argument objects. */
{
TkWindow **windows, **window_ptr;
static CONST char *optionStrings[] = {
@@ -2665,8 +2673,9 @@ WmStackorderCmd(
}
/*
- * Lookup stacking order of all toplevels that are children of "." and
- * find the position of winPtr and winPtr2 in the stacking order.
+ * Lookup stacking order of all toplevels that are children
+ * of "." and find the position of winPtr and winPtr2
+ * in the stacking order.
*/
windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
@@ -2723,16 +2732,16 @@ WmStackorderCmd(
*/
static int
-WmStateCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmStateCmd(tkwin, winPtr, interp, objc, objv)
+Tk_Window tkwin; /* Main window of the application. */
+TkWindow *winPtr; /* Toplevel to work with */
+Tcl_Interp *interp; /* Current interpreter. */
+int objc; /* Number of arguments. */
+Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static CONST char *optionStrings[] = {
- "normal", "iconic", "withdrawn", "zoomed", NULL };
+ "normal", "iconic", "withdrawn", "zoomed", (char *) NULL };
enum options {
OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN, OPT_ZOOMED };
int index;
@@ -2744,37 +2753,41 @@ WmStateCmd(
if (objc == 4) {
if (wmPtr->iconFor != NULL) {
Tcl_AppendResult(interp, "can't change state of ",
- Tcl_GetString(objv[2]), ": it is an icon for ",
- Tk_PathName(wmPtr->iconFor), NULL);
+ Tcl_GetString(objv[2]),
+ ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
+ (char *) NULL);
return TCL_ERROR;
}
if (winPtr->flags & TK_EMBEDDED) {
Tcl_AppendResult(interp, "can't change state of ",
- winPtr->pathName, ": it is an embedded window", NULL);
+ winPtr->pathName, ": it is an embedded window",
+ (char *) NULL);
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
- &index) != TCL_OK) {
+ &index) != TCL_OK) {
return TCL_ERROR;
}
if (index == OPT_NORMAL) {
TkpWmSetState(winPtr, NormalState);
-
/*
- * This varies from 'wm deiconify' because it does not force the
- * window to be raised and receive focus
+ * This varies from 'wm deiconify' because it does not
+ * force the window to be raised and receive focus
*/
} else if (index == OPT_ICONIC) {
if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
- Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
- "\": override-redirect flag is set", NULL);
+ Tcl_AppendResult(interp, "can't iconify \"",
+ winPtr->pathName,
+ "\": override-redirect flag is set",
+ (char *) NULL);
return TCL_ERROR;
}
if (wmPtr->master != None) {
- Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
- "\": it is a transient", NULL);
+ Tcl_AppendResult(interp, "can't iconify \"",
+ winPtr->pathName,
+ "\": it is a transient", (char *) NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, IconicState);
@@ -2793,18 +2806,18 @@ WmStateCmd(
ZoomState : NormalState);
}
switch (wmPtr->hints.initial_state) {
- case NormalState:
- Tcl_SetResult(interp, "normal", TCL_STATIC);
- break;
- case IconicState:
- Tcl_SetResult(interp, "iconic", TCL_STATIC);
- break;
- case WithdrawnState:
- Tcl_SetResult(interp, "withdrawn", TCL_STATIC);
- break;
- case ZoomState:
- Tcl_SetResult(interp, "zoomed", TCL_STATIC);
- break;
+ case NormalState:
+ Tcl_SetResult(interp, "normal", TCL_STATIC);
+ break;
+ case IconicState:
+ Tcl_SetResult(interp, "iconic", TCL_STATIC);
+ break;
+ case WithdrawnState:
+ Tcl_SetResult(interp, "withdrawn", TCL_STATIC);
+ break;
+ case ZoomState:
+ Tcl_SetResult(interp, "zoomed", TCL_STATIC);
+ break;
}
}
}
@@ -2829,12 +2842,12 @@ WmStateCmd(
*/
static int
-WmTitleCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmTitleCmd(tkwin, winPtr, interp, objc, objv)
+Tk_Window tkwin; /* Main window of the application. */
+TkWindow *winPtr; /* Toplevel to work with */
+Tcl_Interp *interp; /* Current interpreter. */
+int objc; /* Number of arguments. */
+Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
char *argv3;
@@ -2845,15 +2858,16 @@ WmTitleCmd(
return TCL_ERROR;
}
if (objc == 3) {
- Tcl_SetResult(interp, (char *) ((wmPtr->titleUid != NULL)
- ? wmPtr->titleUid : winPtr->nameUid), TCL_STATIC);
+ Tcl_SetResult(interp,
+ (char *) ((wmPtr->titleUid != NULL) ? wmPtr->titleUid : winPtr->nameUid),
+ TCL_STATIC);
return TCL_OK;
- }
-
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- wmPtr->titleUid = Tk_GetUid(argv3);
- if (!(wmPtr->flags & WM_NEVER_MAPPED) && !Tk_IsEmbedded(winPtr)) {
- TkSetWMName(winPtr, wmPtr->titleUid);
+ } else {
+ argv3 = Tcl_GetStringFromObj(objv[3], &length);
+ wmPtr->titleUid = Tk_GetUid(argv3);
+ if (!(wmPtr->flags & WM_NEVER_MAPPED) && !Tk_IsEmbedded(winPtr)) {
+ TkSetWMName(winPtr, wmPtr->titleUid);
+ }
}
return TCL_OK;
}
@@ -2876,18 +2890,19 @@ WmTitleCmd(
*/
static int
-WmTransientCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmTransientCmd(tkwin, winPtr, interp, objc, objv)
+ Tk_Window tkwin; /* Main window of the application. */
+ TkWindow *winPtr; /* Toplevel to work with */
+ Tcl_Interp *interp; /* Current interpreter. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Tk_Window master;
WmInfo *wmPtr2;
char *argv3;
- int length, oldAttributes = wmPtr->attributes;
+ int length;
+ int oldAttributes = wmPtr->attributes;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
@@ -2920,9 +2935,11 @@ WmTransientCmd(
Tk_MakeWindowExist(master);
if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't make \"", Tcl_GetString(objv[2]),
- "\" a transient: it is an icon for ",
- Tk_PathName(wmPtr->iconFor), NULL);
+ Tcl_AppendResult(interp, "can't make \"",
+ Tcl_GetString(objv[2]),
+ "\" a transient: it is an icon for ",
+ Tk_PathName(wmPtr->iconFor),
+ (char *) NULL);
return TCL_ERROR;
}
@@ -2943,7 +2960,7 @@ WmTransientCmd(
"\" its own master", NULL);
return TCL_ERROR;
}
-
+
argv3 = Tcl_GetStringFromObj(objv[3], &length);
wmPtr->master = Tk_WindowId(master);
wmPtr->masterWindowName = ckalloc((unsigned) length+1);
@@ -2979,12 +2996,12 @@ WmTransientCmd(
*/
static int
-WmWithdrawCmd(
- Tk_Window tkwin, /* Main window of the application. */
- TkWindow *winPtr, /* Toplevel to work with */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+WmWithdrawCmd(tkwin, winPtr, interp, objc, objv)
+ Tk_Window tkwin; /* Main window of the application. */
+ TkWindow *winPtr; /* Toplevel to work with */
+ Tcl_Interp *interp; /* Current interpreter. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj *CONST objv[]; /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
@@ -2994,22 +3011,22 @@ WmWithdrawCmd(
}
if (wmPtr->iconFor != NULL) {
Tcl_AppendResult(interp, "can't withdraw ", Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
+ ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
+ (char *) NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, WithdrawnState);
return TCL_OK;
}
-
+
/*
- * Invoked by those wm subcommands that affect geometry. Schedules a geometry
- * update.
+ * Invoked by those wm subcommands that affect geometry.
+ * Schedules a geometry update.
*/
-
static void
-WmUpdateGeom(
- WmInfo *wmPtr,
- TkWindow *winPtr)
+WmUpdateGeom(wmPtr, winPtr)
+WmInfo *wmPtr;
+TkWindow *winPtr;
{
if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr);
@@ -3022,33 +3039,33 @@ WmUpdateGeom(
* Tk_SetGrid --
*
* This procedure is invoked by a widget when it wishes to set a grid
- * coordinate system that controls the size of a top-level window. It
- * provides a C interface equivalent to the "wm grid" command and is
- * usually asscoiated with the -setgrid option.
+ * coordinate system that controls the size of a top-level window.
+ * It provides a C interface equivalent to the "wm grid" command and
+ * is usually asscoiated with the -setgrid option.
*
* Results:
* None.
*
* Side effects:
- * Grid-related information will be passed to the window manager, so that
- * the top-level window associated with tkwin will resize on even grid
- * units. If some other window already controls gridding for the
- * top-level window then this procedure call has no effect.
+ * Grid-related information will be passed to the window manager, so
+ * that the top-level window associated with tkwin will resize on
+ * even grid units. If some other window already controls gridding
+ * for the top-level window then this procedure call has no effect.
*
*----------------------------------------------------------------------
*/
void
Tk_SetGrid(
- Tk_Window tkwin, /* Token for window. New window mgr info will
- * be posted for the top-level window
+ Tk_Window tkwin, /* Token for window. New window mgr info
+ * will be posted for the top-level window
* associated with this window. */
- int reqWidth, /* Width (in grid units) corresponding to the
- * requested geometry for tkwin. */
- int reqHeight, /* Height (in grid units) corresponding to the
- * requested geometry for tkwin. */
- int widthInc, int heightInc)/* Pixel increments corresponding to a change
- * of one grid unit. */
+ int reqWidth, /* Width (in grid units) corresponding to
+ * the requested geometry for tkwin. */
+ int reqHeight, /* Height (in grid units) corresponding to
+ * the requested geometry for tkwin. */
+ int widthInc, int heightInc)/* Pixel increments corresponding to a
+ * change of one grid unit. */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr;
@@ -3056,7 +3073,6 @@ Tk_SetGrid(
/*
* Ensure widthInc and heightInc are greater than 0
*/
-
if (widthInc <= 0) {
widthInc = 1;
}
@@ -3088,15 +3104,15 @@ Tk_SetGrid(
}
/*
- * If gridding was previously off, then forget about any window size
- * requests made by the user or via "wm geometry": these are in pixel
- * units and there's no easy way to translate them to grid units since the
- * new requested size of the top-level window in pixels may not yet have
- * been registered yet (it may filter up the hierarchy in DoWhenIdle
- * handlers). However, if the window has never been mapped yet then just
- * leave the window size alone: assume that it is intended to be in grid
- * units but just happened to have been specified before this procedure
- * was called.
+ * If gridding was previously off, then forget about any window
+ * size requests made by the user or via "wm geometry": these are
+ * in pixel units and there's no easy way to translate them to
+ * grid units since the new requested size of the top-level window in
+ * pixels may not yet have been registered yet (it may filter up
+ * the hierarchy in DoWhenIdle handlers). However, if the window
+ * has never been mapped yet then just leave the window size alone:
+ * assume that it is intended to be in grid units but just happened
+ * to have been specified before this procedure was called.
*/
if ((wmPtr->gridWin == NULL) && !(wmPtr->flags & WM_NEVER_MAPPED)) {
@@ -3104,9 +3120,9 @@ Tk_SetGrid(
wmPtr->height = -1;
}
- /*
- * Set the new gridding information, and start the process of passing all
- * of this information to the window manager.
+ /*
+ * Set the new gridding information, and start the process of passing
+ * all of this information to the window manager.
*/
wmPtr->gridWin = tkwin;
@@ -3127,15 +3143,16 @@ Tk_SetGrid(
*
* Tk_UnsetGrid --
*
- * This procedure cancels the effect of a previous call to Tk_SetGrid.
+ * This procedure cancels the effect of a previous call
+ * to Tk_SetGrid.
*
* Results:
* None.
*
* Side effects:
* If tkwin currently controls gridding for its top-level window,
- * gridding is cancelled for that top-level window; if some other window
- * controls gridding then this procedure has no effect.
+ * gridding is cancelled for that top-level window; if some other
+ * window controls gridding then this procedure has no effect.
*
*----------------------------------------------------------------------
*/
@@ -3191,32 +3208,34 @@ Tk_UnsetGrid(
* None.
*
* Side effects:
- * Tk's internal data structures for the window get modified to reflect
- * the structural change.
+ * Tk's internal data structures for the window get modified to
+ * reflect the structural change.
*
*----------------------------------------------------------------------
*/
static void
TopLevelEventProc(
- ClientData clientData, /* Window for which event occurred. */
- XEvent *eventPtr) /* Event that just happened. */
+ ClientData clientData, /* Window for which event occurred. */
+ XEvent *eventPtr) /* Event that just happened. */
{
TkWindow *winPtr = (TkWindow *) clientData;
winPtr->wmInfoPtr->flags |= WM_VROOT_OFFSET_STALE;
if (eventPtr->type == DestroyNotify) {
+ Tk_ErrorHandler handler;
+
if (!(winPtr->flags & TK_ALREADY_DEAD)) {
/*
* A top-level window was deleted externally (e.g., by the window
- * manager). This is probably not a good thing, but cleanup as
- * best we can. The error handler is needed because
+ * manager). This is probably not a good thing, but cleanup as
+ * best we can. The error handler is needed because
* Tk_DestroyWindow will try to destroy the window, but of course
* it's already gone.
*/
-
- Tk_ErrorHandler handler = Tk_CreateErrorHandler(winPtr->display,
- -1, -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL);
+
+ handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1,
+ (Tk_ErrorProc *) NULL, (ClientData) NULL);
Tk_DestroyWindow((Tk_Window) winPtr);
Tk_DeleteErrorHandler(handler);
}
@@ -3233,15 +3252,15 @@ TopLevelEventProc(
*
* TopLevelReqProc --
*
- * This procedure is invoked by the geometry manager whenever the
- * requested size for a top-level window is changed.
+ * This procedure is invoked by the geometry manager whenever
+ * the requested size for a top-level window is changed.
*
* Results:
* None.
*
* Side effects:
- * Arrange for the window to be resized to satisfy the request (this
- * happens as a when-idle action).
+ * Arrange for the window to be resized to satisfy the request
+ * (this happens as a when-idle action).
*
*----------------------------------------------------------------------
*/
@@ -3249,8 +3268,8 @@ TopLevelEventProc(
/* ARGSUSED */
static void
TopLevelReqProc(
- ClientData dummy, /* Not used. */
- Tk_Window tkwin) /* Information about window. */
+ ClientData dummy, /* Not used. */
+ Tk_Window tkwin) /* Information about window. */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr;
@@ -3268,40 +3287,44 @@ TopLevelReqProc(
*
* UpdateGeometryInfo --
*
- * This procedure is invoked when a top-level window is first mapped, and
- * also as a when-idle procedure, to bring the geometry and/or position
- * of a top-level window back into line with what has been requested by
- * the user and/or widgets. This procedure doesn't return until the
- * window manager has responded to the geometry change.
+ * This procedure is invoked when a top-level window is first
+ * mapped, and also as a when-idle procedure, to bring the
+ * geometry and/or position of a top-level window back into
+ * line with what has been requested by the user and/or widgets.
+ * This procedure doesn't return until the window manager has
+ * responded to the geometry change.
*
* Results:
* None.
*
* Side effects:
- * The window's size and location may change, unless the WM prevents that
- * from happening.
+ * The window's size and location may change, unless the WM prevents
+ * that from happening.
*
*----------------------------------------------------------------------
*/
static void
UpdateGeometryInfo(
- ClientData clientData) /* Pointer to the window's record. */
+ ClientData clientData) /* Pointer to the window's record. */
{
TkWindow *winPtr = (TkWindow *) clientData;
WmInfo *wmPtr = winPtr->wmInfoPtr;
- int x, y, width, height, min, max;
+ int x, y, width, height;
+ int min, max;
unsigned long serial;
wmPtr->flags &= ~WM_UPDATE_PENDING;
/*
- * Compute the new size for the top-level window. See the user
- * documentation for details on this, but the size requested depends on
- * (a) the size requested internally by the window's widgets, (b) the size
- * requested by the user in a "wm geometry" command or via wm-based
- * interactive resizing (if any), and (c) whether or not the window is
- * gridded. Don't permit sizes <= 0 because this upsets the X server.
+ * Compute the new size for the top-level window. See the
+ * user documentation for details on this, but the size
+ * requested depends on (a) the size requested internally
+ * by the window's widgets, (b) the size requested by the
+ * user in a "wm geometry" command or via wm-based interactive
+ * resizing (if any), and (c) whether or not the window is
+ * gridded. Don't permit sizes <= 0 because this upsets
+ * the X server.
*/
if (wmPtr->width == -1) {
@@ -3376,10 +3399,10 @@ UpdateGeometryInfo(
/*
* Compute the new position for the upper-left pixel of the window's
- * decorative frame. This is tricky, because we need to include the border
- * widths supplied by a reparented parent in this calculation, but can't
- * use the parent's current overall size since that may change as a result
- * of this code.
+ * decorative frame. This is tricky, because we need to include the
+ * border widths supplied by a reparented parent in this calculation,
+ * but can't use the parent's current overall size since that may
+ * change as a result of this code.
*/
if (wmPtr->flags & WM_NEGATIVE_X) {
@@ -3396,10 +3419,10 @@ UpdateGeometryInfo(
}
/*
- * If the window's size is going to change and the window is supposed to
- * not be resizable by the user, then we have to update the size hints.
- * There may also be a size-hint-update request pending from somewhere
- * else, too.
+ * If the window's size is going to change and the window is
+ * supposed to not be resizable by the user, then we have to
+ * update the size hints. There may also be a size-hint-update
+ * request pending from somewhere else, too.
*/
if (((width != winPtr->changes.width)
@@ -3413,37 +3436,40 @@ UpdateGeometryInfo(
}
/*
- * Reconfigure the window if it isn't already configured correctly. A few
- * tricky points:
+ * Reconfigure the window if it isn't already configured correctly.
+ * A few tricky points:
*
- * 1. If the window is embedded and the container is also in this process,
- * don't actually reconfigure the window; just pass the desired size on
- * to the container. Also, zero out any position information, since
- * embedded windows are not allowed to move.
- * 2. Sometimes the window manager will give us a different size than we
- * asked for (e.g. mwm has a minimum size for windows), so base the
- * size check on what we *asked for* last time, not what we got.
- * 3. Don't move window unless a new position has been requested for it.
- * This is because of "features" in some window managers (e.g. twm, as
- * of 4/24/91) where they don't interpret coordinates according to
- * ICCCM. Moving a window to its current location may cause it to shift
- * position on the screen.
+ * 1. If the window is embedded and the container is also in this
+ * process, don't actually reconfigure the window; just pass the
+ * desired size on to the container. Also, zero out any position
+ * information, since embedded windows are not allowed to move.
+ * 2. Sometimes the window manager will give us a different size
+ * than we asked for (e.g. mwm has a minimum size for windows), so
+ * base the size check on what we *asked for* last time, not what we
+ * got.
+ * 3. Don't move window unless a new position has been requested for
+ * it. This is because of "features" in some window managers (e.g.
+ * twm, as of 4/24/91) where they don't interpret coordinates
+ * according to ICCCM. Moving a window to its current location may
+ * cause it to shift position on the screen.
*/
if (Tk_IsEmbedded(winPtr)) {
- TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);
+ TkWindow *contWinPtr;
+ contWinPtr = TkpGetOtherWindow(winPtr);
+
/*
* NOTE: Here we should handle out of process embedding.
*/
- if (contWinPtr != NULL) {
+ if (contWinPtr != NULL) {
/*
* This window is embedded and the container is also in this
* process, so we don't need to do anything special about the
- * geometry, except to make sure that the desired size is known by
- * the container. Also, zero out any position information, since
- * embedded windows are not allowed to move.
+ * geometry, except to make sure that the desired size is known
+ * by the container. Also, zero out any position information,
+ * since embedded windows are not allowed to move.
*/
wmPtr->x = wmPtr->y = 0;
@@ -3452,7 +3478,6 @@ UpdateGeometryInfo(
}
return;
}
-
serial = NextRequest(winPtr->display);
if (wmPtr->flags & WM_MOVE_PENDING) {
wmPtr->configWidth = width;
@@ -3483,8 +3508,9 @@ UpdateGeometryInfo(
*
* UpdateSizeHints --
*
- * This procedure is called to update the window manager's size hints
- * information from the information in a WmInfo structure.
+ * This procedure is called to update the window manager's
+ * size hints information from the information in a WmInfo
+ * structure.
*
* Results:
* None.
@@ -3511,12 +3537,13 @@ UpdateSizeHints(
*
* ParseGeometry --
*
- * This procedure parses a geometry string and updates information used
- * to control the geometry of a top-level window.
+ * This procedure parses a geometry string and updates
+ * information used to control the geometry of a top-level
+ * window.
*
* Results:
- * A standard Tcl return value, plus an error message in the interp's
- * result if an error occurs.
+ * A standard Tcl return value, plus an error message in
+ * the interp's result if an error occurs.
*
* Side effects:
* The size and/or location of winPtr may change.
@@ -3527,10 +3554,10 @@ UpdateSizeHints(
static int
ParseGeometry(
Tcl_Interp *interp, /* Used for error reporting. */
- char *string, /* String containing new geometry. Has the
+ char *string, /* String containing new geometry. Has the
* standard form "=wxh+x+y". */
- TkWindow *winPtr) /* Pointer to top-level window whose geometry
- * is to be changed. */
+ TkWindow *winPtr) /* Pointer to top-level window whose
+ * geometry is to be changed. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
int x, y, width, height, flags;
@@ -3546,9 +3573,9 @@ ParseGeometry(
}
/*
- * Parse the width and height, if they are present. Don't actually update
- * any of the fields of wmPtr until we've successfully parsed the entire
- * geometry string.
+ * Parse the width and height, if they are present. Don't
+ * actually update any of the fields of wmPtr until we've
+ * successfully parsed the entire geometry string.
*/
width = wmPtr->width;
@@ -3602,10 +3629,10 @@ ParseGeometry(
}
/*
- * Assume that the geometry information came from the user, unless an
- * explicit source has been specified. Otherwise most window managers
- * assume that the size hints were program-specified and they ignore
- * them.
+ * Assume that the geometry information came from the user,
+ * unless an explicit source has been specified. Otherwise
+ * most window managers assume that the size hints were
+ * program-specified and they ignore them.
*/
if ((wmPtr->sizeHintsFlags & (USPosition|PPosition)) == 0) {
@@ -3615,9 +3642,9 @@ ParseGeometry(
}
/*
- * Everything was parsed OK. Update the fields of *wmPtr and arrange for
- * the appropriate information to be percolated out to the window manager
- * at the next idle moment.
+ * Everything was parsed OK. Update the fields of *wmPtr and
+ * arrange for the appropriate information to be percolated out
+ * to the window manager at the next idle moment.
*/
wmPtr->width = width;
@@ -3647,15 +3674,15 @@ ParseGeometry(
*
* Tk_GetRootCoords --
*
- * Given a token for a window, this procedure traces through the window's
- * lineage to find the (virtual) root-window coordinates corresponding to
- * point (0,0) in the window.
+ * Given a token for a window, this procedure traces through the
+ * window's lineage to find the (virtual) root-window coordinates
+ * corresponding to point (0,0) in the window.
*
* Results:
- * The locations pointed to by xPtr and yPtr are filled in with the root
- * coordinates of the (0,0) point in tkwin. If a virtual root window is
- * in effect for the window, then the coordinates in the virtual root are
- * returned.
+ * The locations pointed to by xPtr and yPtr are filled in with
+ * the root coordinates of the (0,0) point in tkwin. If a virtual
+ * root window is in effect for the window, then the coordinates
+ * in the virtual root are returned.
*
* Side effects:
* None.
@@ -3673,8 +3700,9 @@ Tk_GetRootCoords(
TkWindow *winPtr = (TkWindow *) tkwin;
/*
- * Search back through this window's parents all the way to a top-level
- * window, combining the offsets of each window within its parent.
+ * Search back through this window's parents all the way to a
+ * top-level window, combining the offsets of each window within
+ * its parent.
*/
x = y = 0;
@@ -3685,45 +3713,45 @@ Tk_GetRootCoords(
if (!(Tk_IsEmbedded(winPtr))) {
x += winPtr->wmInfoPtr->xInParent;
y += winPtr->wmInfoPtr->yInParent;
- break;
+ break;
} else {
- TkWindow *otherPtr = TkpGetOtherWindow(winPtr);
-
+ TkWindow *otherPtr;
+
+ otherPtr = TkpGetOtherWindow(winPtr);
if (otherPtr != NULL) {
/*
- * The container window is in the same application. Query
- * its coordinates.
+ * The container window is in the same application.
+ * Query its coordinates.
*/
-
winPtr = otherPtr;
-
+
/*
- * Remember to offset by the container window here, since
- * at the end of this if branch, we will pop out to the
- * container's parent...
+ * Remember to offset by the container window here,
+ * since at the end of this if branch, we will
+ * pop out to the container's parent...
*/
-
+
x += winPtr->changes.x + winPtr->changes.border_width;
y += winPtr->changes.y + winPtr->changes.border_width;
+
} else {
Point theOffset;
-
+
if (tkMacOSXEmbedHandler->getOffsetProc != NULL) {
/*
- * We do not require that the changes.x & changes.y
- * for a non-Tk master window be kept up to date. So
- * we first subtract off the possibly bogus values
- * that have been added on at the top of this pass
- * through the loop, and then call out to the
- * getOffsetProc to give us the correct offset.
+ * We do not require that the changes.x & changes.y for
+ * a non-Tk master window be kept up to date. So we
+ * first subtract off the possibly bogus values that have
+ * been added on at the top of this pass through the loop,
+ * and then call out to the getOffsetProc to give us
+ * the correct offset.
*/
-
+
x -= winPtr->changes.x + winPtr->changes.border_width;
y -= winPtr->changes.y + winPtr->changes.border_width;
-
- tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr,
- &theOffset);
-
+
+ tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr, &theOffset);
+
x += theOffset.h;
y += theOffset.v;
}
@@ -3742,14 +3770,14 @@ Tk_GetRootCoords(
*
* Tk_CoordsToWindow --
*
- * This is a Macintosh specific implementation of this function. Given
- * the root coordinates of a point, this procedure returns the token for
- * the top-most window covering that point, if there exists such a window
- * in this application.
+ * This is a Macintosh specific implementation of this function.
+ * Given the root coordinates of a point, this procedure returns
+ * the token for the top-most window covering that point, if
+ * there exists such a window in this application.
*
* Results:
- * The return result is either a token for the window corresponding to
- * rootX and rootY, or else NULL to indicate that there is no such
+ * The return result is either a token for the window corresponding
+ * to rootX and rootY, or else NULL to indicate that there is no such
* window.
*
* Side effects:
@@ -3760,19 +3788,19 @@ Tk_GetRootCoords(
Tk_Window
Tk_CoordsToWindow(
- int rootX, int rootY, /* Coordinates of point in root window. If a
- * virtual-root window manager is in use,
+ int rootX, int rootY, /* Coordinates of point in root window. If
+ * a virtual-root window manager is in use,
* these coordinates refer to the virtual
* root, not the real root. */
- Tk_Window tkwin) /* Token for any window in application; used
- * to identify the display. */
+ Tk_Window tkwin) /* Token for any window in application;
+ * used to identify the display. */
{
WindowPtr whichWin;
Point where;
Window rootChild;
TkWindow *winPtr, *childPtr;
- TkWindow *nextPtr; /* Coordinates of highest child found so far
- * that contains point. */
+ TkWindow *nextPtr; /* Coordinates of highest child found so
+ * far that contains point. */
int x, y; /* Coordinates in winPtr. */
int tmpx, tmpy, bd;
TkDisplay *dispPtr;
@@ -3780,7 +3808,7 @@ Tk_CoordsToWindow(
/*
* Step 1: find the top-level window that contains the desired point.
*/
-
+
where.h = rootX;
where.v = rootY;
FindWindow(where, &whichWin);
@@ -3795,10 +3823,10 @@ Tk_CoordsToWindow(
}
/*
- * Step 2: work down through the hierarchy underneath this window. At each
- * level, scan through all the children to find the highest one in the
- * stacking order that contains the point. Then repeat the whole process
- * on that child.
+ * Step 2: work down through the hierarchy underneath this window.
+ * At each level, scan through all the children to find the highest
+ * one in the stacking order that contains the point. Then repeat
+ * the whole process on that child.
*/
x = rootX - winPtr->wmInfoPtr->xInParent;
@@ -3807,12 +3835,12 @@ Tk_CoordsToWindow(
x -= winPtr->changes.x;
y -= winPtr->changes.y;
nextPtr = NULL;
-
+
/*
* Container windows cannot have children. So if it is a container,
* look there, otherwise inspect the children.
*/
-
+
if (Tk_IsContainer(winPtr)) {
childPtr = TkpGetOtherWindow(winPtr);
if (childPtr != NULL) {
@@ -3820,7 +3848,7 @@ Tk_CoordsToWindow(
tmpx = x - childPtr->changes.x;
tmpy = y - childPtr->changes.y;
bd = childPtr->changes.border_width;
-
+
if ((tmpx >= -bd) && (tmpy >= -bd)
&& (tmpx < (childPtr->changes.width + bd))
&& (tmpy < (childPtr->changes.height + bd))) {
@@ -3828,10 +3856,12 @@ Tk_CoordsToWindow(
}
}
}
+
/*
* NOTE: Here we should handle out of process embedding.
*/
+
} else {
for (childPtr = winPtr->childList; childPtr != NULL;
childPtr = childPtr->nextPtr) {
@@ -3863,16 +3893,17 @@ Tk_CoordsToWindow(
* Tk_TopCoordsToWindow --
*
* Given a Tk Window, and coordinates of a point relative to that window
- * this procedure returns the top-most child of the window (excluding
- * toplevels) covering that point, if there exists such a window in this
- * application. It also sets newX, and newY to the coords of the point
- * relative to the window returned.
+ * this procedure returns the top-most child of the window (excluding
+ * toplevels) covering that point, if there exists such a window in this
+ * application.
+ * It also sets newX, and newY to the coords of the point relative to the
+ * window returned.
*
* Results:
- * The return result is either a token for the window corresponding to
- * rootX and rootY, or else NULL to indicate that there is no such
- * window. newX and newY are also set to the coords of the point relative
- * to the returned window.
+ * The return result is either a token for the window corresponding
+ * to rootX and rootY, or else NULL to indicate that there is no such
+ * window. newX and newY are also set to the coords of the point relative
+ * to the returned window.
*
* Side effects:
* None.
@@ -3885,12 +3916,12 @@ Tk_TopCoordsToWindow(
Tk_Window tkwin, /* Token for a Tk Window which defines the;
* coordinates for rootX & rootY */
int rootX, int rootY, /* Coordinates of a point in tkWin. */
- int *newX, int *newY) /* Coordinates of point in the upperMost child
- * of tkWin containing (rootX,rootY) */
+ int *newX, int *newY) /* Coordinates of point in the upperMost child of
+ * tkWin containing (rootX,rootY) */
{
TkWindow *winPtr, *childPtr;
- TkWindow *nextPtr; /* Coordinates of highest child found so far
- * that contains point. */
+ TkWindow *nextPtr; /* Coordinates of highest child found so
+ * far that contains point. */
int x, y; /* Coordinates in winPtr. */
Window *children; /* Children of winPtr, or NULL. */
@@ -3902,18 +3933,20 @@ Tk_TopCoordsToWindow(
children = NULL;
/*
- * Container windows cannot have children. So if it is a container,
+ * Container windows cannot have children. So if it is a container,
* look there, otherwise inspect the children.
*/
if (Tk_IsContainer(winPtr)) {
childPtr = TkpGetOtherWindow(winPtr);
if (childPtr != NULL) {
- if (Tk_IsMapped(childPtr) &&
- x > childPtr->changes.x &&
- x < childPtr->changes.x+childPtr->changes.width &&
- y > childPtr->changes.y &&
- y < childPtr->changes.y+childPtr->changes.height)) {
+ if (Tk_IsMapped(childPtr) &&
+ (x > childPtr->changes.x &&
+ x < childPtr->changes.x +
+ childPtr->changes.width) &&
+ (y > childPtr->changes.y &&
+ y < childPtr->changes.y +
+ childPtr->changes.height)) {
nextPtr = childPtr;
}
}
@@ -3955,8 +3988,8 @@ Tk_TopCoordsToWindow(
*
* UpdateVRootGeometry --
*
- * This procedure is called to update all the virtual root geometry
- * information in wmPtr.
+ * This procedure is called to update all the virtual root
+ * geometry information in wmPtr.
*
* Results:
* None.
@@ -3987,7 +4020,7 @@ UpdateVRootGeometry(
wmPtr->flags &= ~WM_VROOT_OFFSET_STALE;
if (wmPtr->vRoot == None) {
- noVRoot:
+ noVRoot:
wmPtr->vRootX = wmPtr->vRootY = 0;
wmPtr->vRootWidth = DisplayWidth(winPtr->display, winPtr->screenNum);
wmPtr->vRootHeight = DisplayHeight(winPtr->display, winPtr->screenNum);
@@ -4011,7 +4044,7 @@ UpdateVRootGeometry(
Tk_DeleteErrorHandler(handler);
if (status == 0) {
/*
- * The virtual root is gone! Pretend that it never existed.
+ * The virtual root is gone! Pretend that it never existed.
*/
wmPtr->vRoot = None;
@@ -4024,15 +4057,16 @@ UpdateVRootGeometry(
*
* Tk_GetVRootGeometry --
*
- * This procedure returns information about the virtual root window
- * corresponding to a particular Tk window.
+ * This procedure returns information about the virtual root
+ * window corresponding to a particular Tk window.
*
* Results:
- * The values at xPtr, yPtr, widthPtr, and heightPtr are set with the
- * offset and dimensions of the root window corresponding to tkwin. If
- * tkwin is being managed by a virtual root window manager these values
- * correspond to the virtual root window being used for tkwin; otherwise
- * the offsets will be 0 and the dimensions will be those of the screen.
+ * The values at xPtr, yPtr, widthPtr, and heightPtr are set
+ * with the offset and dimensions of the root window corresponding
+ * to tkwin. If tkwin is being managed by a virtual root window
+ * manager these values correspond to the virtual root window being
+ * used for tkwin; otherwise the offsets will be 0 and the
+ * dimensions will be those of the screen.
*
* Side effects:
* Vroot window information is refreshed if it is out of date.
@@ -4063,8 +4097,8 @@ Tk_GetVRootGeometry(
wmPtr = winPtr->wmInfoPtr;
/*
- * Make sure that the geometry information is up-to-date, then copy it out
- * to the caller.
+ * Make sure that the geometry information is up-to-date, then copy
+ * it out to the caller.
*/
if (wmPtr->flags & WM_VROOT_OFFSET_STALE) {
@@ -4081,17 +4115,18 @@ Tk_GetVRootGeometry(
*
* Tk_MoveToplevelWindow --
*
- * This procedure is called instead of Tk_MoveWindow to adjust the x-y
- * location of a top-level window. It delays the actual move to a later
- * time and keeps window-manager information up-to-date with the move
+ * This procedure is called instead of Tk_MoveWindow to adjust
+ * the x-y location of a top-level window. It delays the actual
+ * move to a later time and keeps window-manager information
+ * up-to-date with the move
*
* Results:
* None.
*
* Side effects:
* The window is eventually moved so that its upper-left corner
- * (actually, the upper-left corner of the window's decorative frame, if
- * there is one) is at (x,y).
+ * (actually, the upper-left corner of the window's decorative
+ * frame, if there is one) is at (x,y).
*
*----------------------------------------------------------------------
*/
@@ -4099,7 +4134,8 @@ Tk_GetVRootGeometry(
void
Tk_MoveToplevelWindow(
Tk_Window tkwin, /* Window to move. */
- int x, int y) /* New location for window (within parent). */
+ int x, int y) /* New location for window (within
+ * parent). */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr = winPtr->wmInfoPtr;
@@ -4118,8 +4154,9 @@ Tk_MoveToplevelWindow(
/*
* If the window has already been mapped, must bring its geometry
- * up-to-date immediately, otherwise an event might arrive from the server
- * that would overwrite wmPtr->x and wmPtr->y and lose the new position.
+ * up-to-date immediately, otherwise an event might arrive from the
+ * server that would overwrite wmPtr->x and wmPtr->y and lose the
+ * new position.
*/
if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
@@ -4128,8 +4165,7 @@ Tk_MoveToplevelWindow(
}
UpdateGeometryInfo((ClientData) winPtr);
}
-}
-
+}
/*
*----------------------------------------------------------------------
*
@@ -4141,9 +4177,9 @@ Tk_MoveToplevelWindow(
* None.
*
* Side effects:
- * WinPtr gets restacked as specified by aboveBelow and otherPtr. This
- * procedure doesn't return until the restack has taken effect and the
- * ConfigureNotify event for it has been received.
+ * WinPtr gets restacked as specified by aboveBelow and otherPtr.
+ * This procedure doesn't return until the restack has taken
+ * effect and the ConfigureNotify event for it has been received.
*
*----------------------------------------------------------------------
*/
@@ -4153,9 +4189,9 @@ TkWmRestackToplevel(
TkWindow *winPtr, /* Window to restack. */
int aboveBelow, /* Gives relative position for restacking;
* must be Above or Below. */
- TkWindow *otherPtr) /* Window relative to which to restack; if
- * NULL, then winPtr gets restacked above or
- * below *all* siblings. */
+ TkWindow *otherPtr) /* Window relative to which to restack;
+ * if NULL, then winPtr gets restacked
+ * above or below *all* siblings. */
{
WmInfo *wmPtr;
@@ -4164,17 +4200,17 @@ TkWmRestackToplevel(
wmPtr = winPtr->wmInfoPtr;
/*
- * Get the mac window. Make sure it exists & is mapped.
+ * Get the mac window. Make sure it exists & is mapped.
*/
-
if (winPtr->window == None) {
Tk_MakeWindowExist((Tk_Window) winPtr);
}
if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
+
/*
- * Can't set stacking order properly until the window is on the screen
- * (mapping it may give it a reparent window), so make sure it's on
- * the screen.
+ * Can't set stacking order properly until the window is on the
+ * screen (mapping it may give it a reparent window), so make sure
+ * it's on the screen.
*/
TkWmMapWindow(winPtr);
@@ -4184,7 +4220,6 @@ TkWmRestackToplevel(
/*
* Get the window in which a raise or lower is in relation to.
*/
-
if (otherPtr != NULL) {
if (otherPtr->window == None) {
Tk_MakeWindowExist((Tk_Window) otherPtr);
@@ -4192,8 +4227,7 @@ TkWmRestackToplevel(
if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
TkWmMapWindow(otherPtr);
}
- otherMacWindow = GetWindowFromPort(
- TkMacOSXGetDrawablePort(otherPtr->window));
+ otherMacWindow = GetWindowFromPort(TkMacOSXGetDrawablePort(otherPtr->window));
} else {
otherMacWindow = NULL;
}
@@ -4202,13 +4236,13 @@ TkWmRestackToplevel(
if (aboveBelow == Above) {
if (macWindow == frontWindow) {
- /*
+ /*
* Do nothing - it's already at the top.
*/
} else if (otherMacWindow == frontWindow || otherMacWindow == NULL) {
/*
- * Raise the window to the top. If the window is visible then we
- * also make it the active window.
+ * Raise the window to the top. If the window is visible then
+ * we also make it the active window.
*/
if (wmPtr->hints.initial_state == WithdrawnState) {
@@ -4218,12 +4252,11 @@ TkWmRestackToplevel(
}
} else {
/*
- * Find the window to be above. (Front window will actually be the
- * window to be behind.) Front window is NULL if no other windows.
+ * Find the window to be above. (Front window will actually be the
+ * window to be behind.) Front window is NULL if no other windows.
*/
-
while (frontWindow != NULL &&
- (tmpWindow=GetNextWindow(frontWindow)) != otherMacWindow) {
+ ( tmpWindow = GetNextWindow (frontWindow) ) != otherMacWindow) {
frontWindow = tmpWindow;
}
if (frontWindow != NULL) {
@@ -4232,12 +4265,10 @@ TkWmRestackToplevel(
}
} else {
/*
- * Send behind. If it was in front find another window to make active.
+ * Send behind. If it was in front find another window to make active.
*/
-
if (macWindow == frontWindow) {
- tmpWindow = GetNextWindow(macWindow);
- if (tmpWindow != NULL) {
+ if ( ( tmpWindow = GetNextWindow ( macWindow )) != NULL) {
SelectWindow(tmpWindow);
}
}
@@ -4251,28 +4282,30 @@ TkWmRestackToplevel(
* TkWmAddToColormapWindows --
*
* This procedure is called to add a given window to the
- * WM_COLORMAP_WINDOWS property for its top-level, if it isn't already
- * there. It is invoked by the Tk code that creates a new colormap, in
- * order to make sure that colormap information is propagated to the
- * window manager by default.
+ * WM_COLORMAP_WINDOWS property for its top-level, if it
+ * isn't already there. It is invoked by the Tk code that
+ * creates a new colormap, in order to make sure that colormap
+ * information is propagated to the window manager by default.
*
* Results:
* None.
*
* Side effects:
- * WinPtr's window gets added to the WM_COLORMAP_WINDOWS property of its
- * nearest top-level ancestor, unless the colormaps have been set
- * explicitly with the "wm colormapwindows" command.
+ * WinPtr's window gets added to the WM_COLORMAP_WINDOWS
+ * property of its nearest top-level ancestor, unless the
+ * colormaps have been set explicitly with the
+ * "wm colormapwindows" command.
*
*----------------------------------------------------------------------
*/
void
TkWmAddToColormapWindows(
- TkWindow *winPtr) /* Window with a non-default colormap. Should
- * not be a top-level window. */
+ TkWindow *winPtr) /* Window with a non-default colormap.
+ * Should not be a top-level window. */
{
- TkWindow *topPtr, **oldPtr, **newPtr;
+ TkWindow *topPtr;
+ TkWindow **oldPtr, **newPtr;
int count, i;
if (winPtr->window == None) {
@@ -4282,7 +4315,7 @@ TkWmAddToColormapWindows(
for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) {
if (topPtr == NULL) {
/*
- * Window is being deleted. Skip the whole operation.
+ * Window is being deleted. Skip the whole operation.
*/
return;
@@ -4309,8 +4342,9 @@ TkWmAddToColormapWindows(
}
/*
- * Make a new bigger array and use it to reset the property. Automatically
- * add the toplevel itself as the last element of the list.
+ * Make a new bigger array and use it to reset the property.
+ * Automatically add the toplevel itself as the last element
+ * of the list.
*/
newPtr = (TkWindow **) ckalloc((unsigned) ((count+2)*sizeof(TkWindow*)));
@@ -4330,8 +4364,9 @@ TkWmAddToColormapWindows(
topPtr->wmInfoPtr->cmapCount = count+1;
/*
- * On the Macintosh all of this is just an excercise in compatability as
- * we don't support colormaps. If we did they would be installed here.
+ * On the Macintosh all of this is just an excercise
+ * in compatability as we don't support colormaps. If
+ * we did they would be installed here.
*/
}
@@ -4341,16 +4376,16 @@ TkWmAddToColormapWindows(
* TkWmRemoveFromColormapWindows --
*
* This procedure is called to remove a given window from the
- * WM_COLORMAP_WINDOWS property for its top-level. It is invoked when
- * windows are deleted.
+ * WM_COLORMAP_WINDOWS property for its top-level. It is invoked
+ * when windows are deleted.
*
* Results:
* None.
*
* Side effects:
- * WinPtr's window gets removed from the WM_COLORMAP_WINDOWS property of
- * its nearest top-level ancestor, unless the top-level itself is being
- * deleted too.
+ * WinPtr's window gets removed from the WM_COLORMAP_WINDOWS
+ * property of its nearest top-level ancestor, unless the
+ * top-level itself is being deleted too.
*
*----------------------------------------------------------------------
*/
@@ -4359,17 +4394,18 @@ void
TkWmRemoveFromColormapWindows(
TkWindow *winPtr) /* Window that may be present in
* WM_COLORMAP_WINDOWS property for its
- * top-level. Should not be a top-level
+ * top-level. Should not be a top-level
* window. */
{
- TkWindow *topPtr, **oldPtr;
+ TkWindow *topPtr;
+ TkWindow **oldPtr;
int count, i, j;
for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) {
if (topPtr == NULL) {
/*
- * Ancestors have been deleted, so skip the whole operation. Seems
- * like this can't ever happen?
+ * Ancestors have been deleted, so skip the whole operation.
+ * Seems like this can't ever happen?
*/
return;
@@ -4380,15 +4416,16 @@ TkWmRemoveFromColormapWindows(
}
if (topPtr->flags & TK_ALREADY_DEAD) {
/*
- * Top-level is being deleted, so there's no need to cleanup the
- * WM_COLORMAP_WINDOWS property.
+ * Top-level is being deleted, so there's no need to cleanup
+ * the WM_COLORMAP_WINDOWS property.
*/
return;
}
/*
- * Find the window and slide the following ones down to cover it up.
+ * Find the window and slide the following ones down to cover
+ * it up.
*/
count = topPtr->wmInfoPtr->cmapCount;
@@ -4412,10 +4449,10 @@ TkWmRemoveFromColormapWindows(
* Fetch the position of the mouse pointer.
*
* Results:
- * *xPtr and *yPtr are filled in with the (virtual) root coordinates of
- * the mouse pointer for tkwin's display. If the pointer isn't on tkwin's
- * screen, then -1 values are returned for both coordinates. The argument
- * tkwin must be a toplevel window.
+ * *xPtr and *yPtr are filled in with the (virtual) root coordinates
+ * of the mouse pointer for tkwin's display. If the pointer isn't
+ * on tkwin's screen, then -1 values are returned for both
+ * coordinates. The argument tkwin must be a toplevel window.
*
* Side effects:
* None.
@@ -4437,10 +4474,10 @@ TkGetPointerCoords(
*
* InitialWindowBounds --
*
- * This function calculates the initial bounds for a new Mac toplevel
- * window. Unless the geometry is specified by the user this code will
- * auto place the windows in a cascade diagonially across the main
- * monitor of the Mac.
+ * This function calculates the initial bounds for a new Mac
+ * toplevel window. Unless the geometry is specified by the user
+ * this code will auto place the windows in a cascade diagonially
+ * across the main monitor of the Mac.
*
* Results:
* The bounds are returned in geometry.
@@ -4461,13 +4498,11 @@ InitialWindowBounds(
static int defaultY = 45;
if (!(wmPtr->sizeHintsFlags & (USPosition | PPosition))) {
- /*
- * We will override the program & hopefully place the window in a
- * "better" location.
+ /*
+ * We will override the program & hopefully place the
+ * window in a "better" location.
*/
-
BitMap screenBits;
-
GetQDGlobalsScreenBits(&screenBits);
if (((screenBits.bounds.right - defaultX) < 30) ||
((screenBits.bounds.bottom - defaultY) < 30)) {
@@ -4491,9 +4526,9 @@ InitialWindowBounds(
*
* TkMacOSXResizable --
*
- * This function determines if the passed in window is part of a toplevel
- * window that is resizable. If the window is resizable in the x, y or
- * both directions, true is returned.
+ * This function determines if the passed in window is part of
+ * a toplevel window that is resizable. If the window is
+ * resizable in the x, y or both directions, true is returned.
*
* Results:
* True if resizable, false otherwise.
@@ -4516,7 +4551,7 @@ TkMacOSXResizable(
while (winPtr->wmInfoPtr == NULL) {
winPtr = winPtr->parentPtr;
}
-
+
wmPtr = winPtr->wmInfoPtr;
if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
(wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
@@ -4531,10 +4566,10 @@ TkMacOSXResizable(
*
* TkMacOSXGrowToplevel --
*
- * The function is invoked when the user clicks in the grow region of a
- * Tk window. The function will handle the dragging procedure and not
- * return until completed. Finally, the function may place information
- * Tk's event queue is the window was resized.
+ * The function is invoked when the user clicks in the grow region
+ * of a Tk window. The function will handle the dragging
+ * procedure and not return until completed. Finally, the function
+ * may place information Tk's event queue is the window was resized.
*
* Results:
* True if events were placed on event queue, false otherwise.
@@ -4595,7 +4630,7 @@ TkMacOSXGrowToplevel(
LoWord(growResult), HiWord(growResult), true);
InvalWindowRect(whichWindow, &portRect); /* TODO: may not be needed */
TkMacOSXInvalClipRgns((Tk_Window) winPtr);
- TkGenWMConfigureEvent((Tk_Window) winPtr, -1, -1,
+ TkGenWMConfigureEvent((Tk_Window) winPtr, -1, -1,
(int) LoWord(growResult), (int) HiWord(growResult),
TK_SIZE_CHANGED);
return true;
@@ -4610,8 +4645,8 @@ TkMacOSXGrowToplevel(
*
* TkSetWMName --
*
- * Set the title for a toplevel window. If the window is embedded, do not
- * change the window title.
+ * Set the title for a toplevel window. If the window is embedded,
+ * do not change the window title.
*
* Results:
* None.
@@ -4627,30 +4662,30 @@ TkSetWMName(
TkWindow *winPtr,
Tk_Uid titleUid)
{
- CFStringRef title;
-
+ CFStringRef title;
+ WindowRef macWin;
+
if (Tk_IsEmbedded(winPtr)) {
return;
}
-
+
title = CFStringCreateWithBytes(NULL, (unsigned char*) titleUid,
- strlen(titleUid), kCFStringEncodingUTF8, false);
+ strlen(titleUid), kCFStringEncodingUTF8, false);
if (title) {
- WindowRef macWin = GetWindowFromPort(
- TkMacOSXGetDrawablePort(winPtr->window));
-
+ macWin = GetWindowFromPort(TkMacOSXGetDrawablePort(winPtr->window));
SetWindowTitleWithCFString(macWin, title);
CFRelease(title);
}
}
+
/*
*----------------------------------------------------------------------
*
* TkGetTransientMaster --
*
- * If the passed window has the TRANSIENT_FOR property set this will
- * return the master window. Otherwise it will return None.
+ * If the passed window has the TRANSIENT_FOR property set this
+ * will return the master window. Otherwise it will return None.
*
* Results:
* The master window or None.
@@ -4708,9 +4743,10 @@ TkMacOSXGetXWindow(
*
* TkMacOSXIsWindowZoomed --
*
- * Ask Carbon if the given window is in the zoomed out state. Because
- * dragging & growing a window can change the Carbon zoom state, we
- * cannot rely on wmInfoPtr->hints.initial_state for this information.
+ * Ask Carbon if the given window is in the zoomed out state.
+ * Because dragging & growing a window can change the Carbon
+ * zoom state, we cannot rely on wmInfoPtr->hints.initial_state
+ * for this information.
*
* Results:
* True if window is zoomed out, false otherwise.
@@ -4727,7 +4763,7 @@ TkMacOSXIsWindowZoomed(
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
Point idealSize;
-
+
if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
(wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
return false;
@@ -4753,10 +4789,11 @@ TkMacOSXIsWindowZoomed(
*
* TkMacOSXZoomToplevel --
*
- * The function is invoked when the user clicks in the zoom region of a
- * Tk window or when the window state is set/unset to "zoomed" manually.
- * If the window is to be zoomed (in or out), the window size is changed
- * and events are generated to let Tk know what happened.
+ * The function is invoked when the user clicks in the zoom region
+ * of a Tk window or when the window state is set/unset to "zoomed"
+ * manually. If the window is to be zoomed (in or out), the window
+ * size is changed and events are generated to let Tk know what
+ * happened.
*
* Results:
* True if events were placed on event queue, false otherwise.
@@ -4785,7 +4822,7 @@ TkMacOSXZoomToplevel(
dispPtr = TkGetDisplayList();
winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
wmPtr = winPtr->wmInfoPtr;
-
+
if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
(wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
return false;
@@ -4802,7 +4839,7 @@ TkMacOSXZoomToplevel(
}
/* Do nothing if already in desired zoom state */
- if (!IsWindowInStandardState(whichWindow, &idealSize, NULL) ==
+ if (!IsWindowInStandardState(whichWindow, &idealSize, NULL) ==
(zoomPart == inZoomIn)) {
return false;
}
@@ -4820,7 +4857,7 @@ TkMacOSXZoomToplevel(
location.h -= xOffset;
location.v -= yOffset;
GetPortBounds(GetWindowPort(whichWindow), &portRect);
- TkGenWMConfigureEvent((Tk_Window) winPtr, location.h, location.v,
+ TkGenWMConfigureEvent((Tk_Window) winPtr, location.h, location.v,
portRect.right - portRect.left, portRect.bottom - portRect.top,
TK_BOTH_CHANGED);
return true;
@@ -4834,9 +4871,10 @@ TkMacOSXZoomToplevel(
*
* TkUnsupported1Cmd --
*
- * This procedure is invoked to process the
- * "::tk::unsupported::MacWindowStyle" Tcl command. This command allows
- * you to set the style of decoration for a Macintosh window.
+ * This procedure is invoked to process the
+ * "::tk::unsupported::MacWindowStyle" Tcl command.
+ * This command allows you to set the style of decoration
+ * for a Macintosh window.
*
* Results:
* A standard Tcl result.
@@ -4879,12 +4917,12 @@ TkUnsupported1ObjCmd(
if (!(winPtr->flags & TK_TOP_LEVEL)) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "window \"", winPtr->pathName,
- "\" isn't a top-level window", NULL);
+ "\" isn't a top-level window", (char *) NULL);
return TCL_ERROR;
}
- if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", 0,
- &index) != TCL_OK) {
+ if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option",
+ 0, &index) != TCL_OK) {
return TCL_ERROR;
}
if (((enum SubCmds) index) == TKMWS_STYLE) {
@@ -4903,9 +4941,10 @@ TkUnsupported1ObjCmd(
*
* WmWinStyle --
*
- * This procedure is invoked to process the
- * "::tk::unsupported::MacWindowStyle style" subcommand. This command
- * allows you to set the style of decoration for a Macintosh window.
+ * This procedure is invoked to process the
+ * "::tk::unsupported::MacWindowStyle style" subcommand.
+ * This command allows you to set the style of decoration
+ * for a Macintosh window.
*
* Results:
* A standard Tcl result.
@@ -4915,7 +4954,6 @@ TkUnsupported1ObjCmd(
*
*----------------------------------------------------------------------
*/
-
static int
WmWinStyle(
Tcl_Interp *interp, /* Current interpreter. */
@@ -5006,7 +5044,7 @@ WmWinStyle(
if (wmPtr->style != -1) {
for (i = 0; styleMap[i].strValue != NULL; i++) {
if (wmPtr->style == styleMap[i].intValue) {
- Tcl_SetObjResult(interp,
+ Tcl_SetObjResult(interp,
Tcl_NewStringObj(styleMap[i].strValue, -1));
return TCL_OK;
}
@@ -5032,7 +5070,7 @@ WmWinStyle(
for (i = 0; compositeAttrMap[i].strValue != NULL; i++) {
if (wmPtr->attributes == compositeAttrMap[i].intValue) {
Tcl_ListObjAppendElement(interp, attributeList,
- Tcl_NewStringObj(compositeAttrMap[i].strValue,-1));
+ Tcl_NewStringObj(compositeAttrMap[i].strValue, -1));
usesComposite = 1;
break;
}
@@ -5050,7 +5088,7 @@ WmWinStyle(
}
} else if (objc == 4) {
if (Tcl_GetIndexFromObjStruct(interp, objv[3], styleMap,
- sizeof(struct StrIntMap), "style", 0, &index) != TCL_OK) {
+ sizeof(struct StrIntMap), "style", 0, &index) != TCL_OK) {
return TCL_ERROR;
}
wmPtr->style = styleMap[index].intValue;
@@ -5061,7 +5099,7 @@ WmWinStyle(
int oldAttributes = wmPtr->attributes;
if (Tcl_GetIndexFromObjStruct(interp, objv[3], classMap,
- sizeof(struct StrIntMap), "class", 0, &index) != TCL_OK) {
+ sizeof(struct StrIntMap), "class", 0, &index) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_ListObjGetElements(interp, objv[4], &attrObjc, &attrObjv)
@@ -5072,11 +5110,12 @@ WmWinStyle(
wmPtr->attributes = kWindowNoAttributes;
for (i = 0; i < attrObjc; i++) {
if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i],
- compositeAttrMap, sizeof(struct StrIntMap), "attribute",
- 0, &index) == TCL_OK) {
+ compositeAttrMap, sizeof(struct StrIntMap),
+ "attribute", 0, &index) == TCL_OK) {
wmPtr->attributes |= compositeAttrMap[index].intValue;
- } else if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i], attrMap,
- sizeof(struct StrIntMap), "attribute", 0,&index)==TCL_OK){
+ } else if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i],
+ attrMap, sizeof(struct StrIntMap),
+ "attribute", 0, &index) == TCL_OK) {
Tcl_ResetResult (interp);
wmPtr->attributes |= attrMap[index].intValue;
} else {
@@ -5098,8 +5137,8 @@ WmWinStyle(
*
* TkpMakeMenuWindow --
*
- * Configure the window to be either a undecorated pull-down (or pop-up)
- * menu, or as a toplevel floating menu (palette).
+ * Configure the window to be either a undecorated pull-down
+ * (or pop-up) menu, or as a toplevel floating menu (palette).
*
* Results:
* None.
@@ -5113,21 +5152,19 @@ WmWinStyle(
void
TkpMakeMenuWindow(
Tk_Window tkwin, /* New window. */
- int transient) /* 1 means menu is only posted briefly as a
- * popup or pulldown or cascade. 0 means menu
- * is always visible, e.g. as a floating
- * menu. */
+ int transient) /* 1 means menu is only posted briefly as
+ * a popup or pulldown or cascade. 0 means
+ * menu is always visible, e.g. as a
+ * floating menu. */
{
- TkWindow *winPtr = (TkWindow *) tkwin;
-
if (transient) {
- winPtr->wmInfoPtr->macClass = kSimpleWindowClass;
- winPtr->wmInfoPtr->attributes = kWindowNoActivatesAttribute;
+ ((TkWindow *) tkwin)->wmInfoPtr->macClass = kSimpleWindowClass;
+ ((TkWindow *) tkwin)->wmInfoPtr->attributes = kWindowNoActivatesAttribute;
} else {
- winPtr->wmInfoPtr->macClass = kFloatingWindowClass;
- winPtr->wmInfoPtr->attributes = kWindowStandardFloatingAttributes;
- winPtr->wmInfoPtr->flags |= WM_WIDTH_NOT_RESIZABLE;
- winPtr->wmInfoPtr->flags |= WM_HEIGHT_NOT_RESIZABLE;
+ ((TkWindow *) tkwin)->wmInfoPtr->macClass = kFloatingWindowClass;
+ ((TkWindow *) tkwin)->wmInfoPtr->attributes = kWindowStandardFloatingAttributes;
+ ((TkWindow *) tkwin)->wmInfoPtr->flags |= WM_WIDTH_NOT_RESIZABLE;
+ ((TkWindow *) tkwin)->wmInfoPtr->flags |= WM_HEIGHT_NOT_RESIZABLE;
}
}
@@ -5136,8 +5173,8 @@ TkpMakeMenuWindow(
*
* TkMacOSXMakeRealWindowExist --
*
- * This function finally creates the real Macintosh window that the Mac
- * actually understands.
+ * This function finally creates the real Macintosh window that
+ * the Mac actually understands.
*
* Results:
* None.
@@ -5153,12 +5190,12 @@ TkMacOSXMakeRealWindowExist(
TkWindow *winPtr) /* Tk window. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowRef newWindow = NULL;
+ WindowRef newWindow = NULL;
ControlRef rootControl = NULL;
MacDrawable *macWin;
Rect geometry = {0,0,0,0};
Tcl_HashEntry *valueHashPtr;
- int isNew;
+ int new;
TkMacOSXWindowList *listPtr;
if (TkMacOSXHostToplevelExists(winPtr)) {
@@ -5168,8 +5205,8 @@ TkMacOSXMakeRealWindowExist(
macWin = (MacDrawable *) winPtr->window;
/*
- * If this is embedded, make sure its container's toplevel exists, then
- * return...
+ * If this is embedded, make sure its container's toplevel exists,
+ * then return...
*/
if (Tk_IsEmbedded(winPtr)) {
@@ -5177,40 +5214,36 @@ TkMacOSXMakeRealWindowExist(
contWinPtr = TkpGetOtherWindow(winPtr);
if (contWinPtr != NULL) {
- TkMacOSXMakeRealWindowExist(
- contWinPtr->privatePtr->toplevel->winPtr);
+ TkMacOSXMakeRealWindowExist(contWinPtr->privatePtr->toplevel->winPtr);
macWin->flags |= TK_HOST_EXISTS;
return;
- }
-
- if (tkMacOSXEmbedHandler == NULL) {
- Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container");
- }
-
- if (tkMacOSXEmbedHandler->containerExistProc != NULL) {
- if (tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr)
- != TCL_OK) {
- Tcl_Panic("ContainerExistProc could not make container");
+ } else if (tkMacOSXEmbedHandler != NULL) {
+ if (tkMacOSXEmbedHandler->containerExistProc != NULL) {
+ if (tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr) != TCL_OK) {
+ Tcl_Panic("ContainerExistProc could not make container");
+ }
}
return;
+ } else {
+ Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container");
}
/*
* NOTE: Here we should handle out of process embedding.
*/
+
}
InitialWindowBounds(winPtr, &geometry);
if (wmPtr->style == -1) {
OSStatus err;
-
/*
- * There seems to be a bug in CreateNewWindow: If I set the window
- * geometry to be the too small for the structure region, then the
- * whole window is positioned incorrectly. Adding this here makes the
- * positioning work, and the size will get overwritten when you
- * actually map the contents of the window.
+ * There seems to be a bug in CreateNewWindow: If I set the
+ * window geometry to be the too small for the structure region,
+ * then the whole window is positioned incorrectly.
+ * Adding this here makes the positioning work, and the size will
+ * get overwritten when you actually map the contents of the window.
*/
geometry.right += 64;
@@ -5220,6 +5253,7 @@ TkMacOSXMakeRealWindowExist(
if (err != noErr) {
newWindow = NULL;
}
+
} else {
newWindow = NewCWindow(NULL, &geometry, "\p", false,
(short) wmPtr->style, (WindowRef) -1, true, 0);
@@ -5248,10 +5282,9 @@ TkMacOSXMakeRealWindowExist(
if ((wmPtr->master != None) && winPtr->atts.override_redirect) {
/*
- * If we are transient and overrideredirect, use the utility class to
- * ensure we are topmost (for dropdowns).
+ * If we are transient and overrideredirect, use the utility class
+ * to ensure we are topmost (for dropdowns).
*/
-
WindowGroupRef group = GetWindowGroupOfClass(kUtilityWindowClass);
if (group != NULL) {
SetWindowGroup(newWindow, group);
@@ -5264,8 +5297,8 @@ TkMacOSXMakeRealWindowExist(
windowHashInit = true;
}
valueHashPtr = Tcl_CreateHashEntry(&windowTable,
- (char *) newWindow, &isNew);
- if (!isNew) {
+ (char *) newWindow, &new);
+ if (!new) {
Tcl_Panic("same macintosh window allocated twice!");
}
Tcl_SetHashValue(valueHashPtr, macWin);
@@ -5278,10 +5311,11 @@ TkMacOSXMakeRealWindowExist(
*
* TkMacOSXRegisterOffScreenWindow --
*
- * This function adds the passed in Off Screen Port to the hash table
- * that maps Mac windows to root X windows.
+ * This function adds the passed in Off Screen Port to the
+ * hash table that maps Mac windows to root X windows.
*
- * FIXME: This is not currently used. Is there any reason to keep it?
+ * FIXME: This is not currently used. Is there any reason
+ * to keep it?
*
* Results:
* None.
@@ -5292,21 +5326,23 @@ TkMacOSXMakeRealWindowExist(
*----------------------------------------------------------------------
*/
-void
+void
TkMacOSXRegisterOffScreenWindow(
- Window window, /* Window structure. */
- GWorldPtr portPtr) /* Pointer to a Mac GWorld. */
+ Window window, /* Window structure. */
+ GWorldPtr portPtr) /* Pointer to a Mac GWorld. */
{
- MacDrawable *macWin = (MacDrawable *) window;
+ MacDrawable *macWin;
Tcl_HashEntry *valueHashPtr;
- int isNew;
+ int new;
+ macWin = (MacDrawable *) window;
if (!windowHashInit) {
Tcl_InitHashTable(&windowTable, TCL_ONE_WORD_KEYS);
windowHashInit = true;
}
- valueHashPtr = Tcl_CreateHashEntry(&windowTable, (char *)portPtr, &isNew);
- if (!isNew) {
+ valueHashPtr = Tcl_CreateHashEntry(&windowTable,
+ (char *) portPtr, &new);
+ if (!new) {
Tcl_Panic("same macintosh window allocated twice!");
}
Tcl_SetHashValue(valueHashPtr, macWin);
@@ -5317,8 +5353,9 @@ TkMacOSXRegisterOffScreenWindow(
*
* TkMacOSXUnregisterMacWindow --
*
- * Given a macintosh port window, this function removes the association
- * between this window and the root X window that Tk cares about.
+ * Given a macintosh port window, this function removes the
+ * association between this window and the root X window that
+ * Tk cares about.
*
* Results:
* None.
@@ -5329,20 +5366,23 @@ TkMacOSXRegisterOffScreenWindow(
*----------------------------------------------------------------------
*/
-void
+void
TkMacOSXUnregisterMacWindow(
WindowRef macWinPtr) /* Reference to a Mac Window */
{
Tcl_HashEntry *entryPtr;
-
if (!windowHashInit) {
Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited");
}
entryPtr = Tcl_FindHashEntry(&windowTable,(char *) macWinPtr);
if (!entryPtr) {
- ERR_MSG("Unregister:failed to find window %08x", (int) macWinPtr);
- } else {
- Tcl_DeleteHashEntry(entryPtr);
+#ifdef TK_MAC_DEBUG
+ fprintf(stderr,"Unregister:failed to find window %08x\n",
+ (int) macWinPtr );
+#endif
+ }
+ else {
+ Tcl_DeleteHashEntry(entryPtr);
}
}
@@ -5351,8 +5391,9 @@ TkMacOSXUnregisterMacWindow(
*
* TkMacOSXSetScrollbarGrow --
*
- * Sets a flag for a toplevel window indicating that the passed Tk
- * scrollbar window will display the grow region for the toplevel window.
+ * Sets a flag for a toplevel window indicating that the passed
+ * Tk scrollbar window will display the grow region for the
+ * toplevel window.
*
* Results:
* None.
@@ -5363,7 +5404,7 @@ TkMacOSXUnregisterMacWindow(
*----------------------------------------------------------------------
*/
-void
+void
TkMacOSXSetScrollbarGrow(
TkWindow *winPtr, /* Tk scrollbar window. */
int flag) /* Boolean value true or false. */
@@ -5377,22 +5418,22 @@ TkMacOSXSetScrollbarGrow(
winPtr->privatePtr->toplevel->winPtr->wmInfoPtr->scrollWinPtr = NULL;
}
}
-
+
/*
*----------------------------------------------------------------------
*
* TkWmFocusToplevel --
*
* This is a utility procedure invoked by focus-management code. It
- * exists because of the extra wrapper windows that exist under Unix; its
- * job is to map from wrapper windows to the corresponding toplevel
- * windows. On PCs and Macs there are no wrapper windows so no mapping is
- * necessary; this procedure just determines whether a window is a
- * toplevel or not.
+ * exists because of the extra wrapper windows that exist under
+ * Unix; its job is to map from wrapper windows to the
+ * corresponding toplevel windows. On PCs and Macs there are no
+ * wrapper windows so no mapping is necessary; this procedure just
+ * determines whether a window is a toplevel or not.
*
* Results:
- * If winPtr is a toplevel window, returns the pointer to the window;
- * otherwise returns NULL.
+ * If winPtr is a toplevel window, returns the pointer to the
+ * window; otherwise returns NULL.
*
* Side effects:
* None.
@@ -5416,13 +5457,13 @@ TkWmFocusToplevel(
*
* TkpGetWrapperWindow --
*
- * This is a utility procedure invoked by focus-management code. It maps
- * to the wrapper for a top-level, which is just the same as the
- * top-level on Macs and PCs.
+ * This is a utility procedure invoked by focus-management code. It
+ * maps to the wrapper for a top-level, which is just the same
+ * as the top-level on Macs and PCs.
*
* Results:
- * If winPtr is a toplevel window, returns the pointer to the window;
- * otherwise returns NULL.
+ * If winPtr is a toplevel window, returns the pointer to the
+ * window; otherwise returns NULL.
*
* Side effects:
* None.
@@ -5446,8 +5487,8 @@ TkpGetWrapperWindow(
*
* TkpWmSetState --
*
- * Sets the window manager state for the wrapper window of a given
- * toplevel window.
+ * Sets the window manager state for the wrapper window of a
+ * given toplevel window.
*
* Results:
* None.
@@ -5459,14 +5500,14 @@ TkpGetWrapperWindow(
*/
void
-TkpWmSetState(
- TkWindow *winPtr, /* Toplevel window to operate on. */
- int state) /* One of IconicState, ZoomState, NormalState,
+TkpWmSetState(winPtr, state)
+ TkWindow *winPtr; /* Toplevel window to operate on. */
+ int state; /* One of IconicState, ZoomState, NormalState,
* or WithdrawnState. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
WindowRef macWin;
-
+
wmPtr->hints.initial_state = state;
if (wmPtr->flags & WM_NEVER_MAPPED) {
return;
@@ -5478,10 +5519,9 @@ TkpWmSetState(
Tk_UnmapWindow((Tk_Window) winPtr);
} else if (state == IconicState) {
/*
- * The window always gets unmapped. If we can show the icon version of
- * the window we also collapse it.
+ * The window always gets unmapped. If we can show the
+ * icon version of the window we also collapse it.
*/
-
if (IsWindowCollapsable(macWin) && !IsWindowCollapsed(macWin)) {
CollapseWindow(macWin, true);
}
@@ -5518,15 +5558,14 @@ TkpWmSetState(
*/
int
-TkpIsWindowFloating(
- WindowRef wRef)
+TkpIsWindowFloating(WindowRef wRef)
{
WindowClass class;
if (wRef == NULL) {
return 0;
}
-
+
GetWindowClass(wRef, &class);
return (class == kFloatingWindowClass);
}
@@ -5548,8 +5587,7 @@ TkpIsWindowFloating(
*/
MODULE_SCOPE WindowClass
-TkMacOSXWindowClass(
- TkWindow *winPtr)
+TkMacOSXWindowClass(TkWindow *winPtr)
{
WindowRef wRef;
WindowClass class;
@@ -5565,21 +5603,21 @@ TkMacOSXWindowClass(
GetWindowClass(wRef, &class);
return class;
}
-
+
/*
*----------------------------------------------------------------------
*
* TkMacOSXWindowOffset --
*
- * Determines the x and y offset from the orgin of the toplevel window
- * dressing (the structure region, i.e. title bar) and the orgin of the
- * content area.
+ * Determines the x and y offset from the orgin of the toplevel
+ * window dressing (the structure region, ie. title bar) and the
+ * orgin of the content area.
*
* Results:
- * The x & y offset in pixels.
+ * The x & y offset in pixels.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
@@ -5597,14 +5635,14 @@ TkMacOSXWindowOffset(
*yOffset = widths.top;
return;
}
-
+
/*
*----------------------------------------------------------------------
*
* TkpGetMS --
*
- * Return a relative time in milliseconds. It doesn't matter when the
- * epoch was.
+ * Return a relative time in milliseconds. It doesn't matter
+ * when the epoch was.
*
* Results:
* Number of milliseconds.
@@ -5618,22 +5656,22 @@ TkMacOSXWindowOffset(
unsigned long
TkpGetMS()
{
- long long *int64Ptr;
+ long long * int64Ptr;
UnsignedWide micros;
-
+
Microseconds(&micros);
int64Ptr = (long long *) &micros;
/*
- * We need 64 bit math to do this. This is available in CW 11 and on.
- * Other's will need to use a different scheme.
+ * We need 64 bit math to do this. This is available in CW 11
+ * and on. Other's will need to use a different scheme.
*/
*int64Ptr /= 1000;
return (long) *int64Ptr;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -5658,7 +5696,7 @@ XSetInputFocus(
Time time)
{
/*
- * Don't need to do a thing. Tk manages the focus for us.
+ * Don't need to do a thing. Tk manages the focus for us.
*/
}
@@ -5667,14 +5705,15 @@ XSetInputFocus(
*
* TkpChangeFocus --
*
- * This procedure is a stub on the Mac because we always own the focus
- * if we are a front most application.
+ * This procedure is a stub on the Mac because we always own the
+ * focus if we are a front most application.
*
* Results:
- * The return value is the serial number of the command that changed
- * the focus. It may be needed by the caller to filter out focus change
- * events that were queued before the command. If the procedure doesn't
- * actually change the focus then it returns 0.
+ * The return value is the serial number of the command that
+ * changed the focus. It may be needed by the caller to filter
+ * out focus change events that were queued before the command.
+ * If the procedure doesn't actually change the focus then
+ * it returns 0.
*
* Side effects:
* None.
@@ -5683,15 +5722,15 @@ XSetInputFocus(
*/
int
-TkpChangeFocus(
- TkWindow *winPtr, /* Window that is to receive the X focus. */
- int force) /* Non-zero means claim the focus even if it
- * didn't originally belong to topLevelPtr's
- * application. */
+TkpChangeFocus(winPtr, force)
+ TkWindow *winPtr; /* Window that is to receive the X focus. */
+ int force; /* Non-zero means claim the focus even
+ * if it didn't originally belong to
+ * topLevelPtr's application. */
{
/*
- * We don't really need to do anything on the Mac. Tk will keep all this
- * state for us.
+ * We don't really need to do anything on the Mac. Tk will
+ * keep all this state for us.
*/
if (winPtr->atts.override_redirect) {
@@ -5699,26 +5738,28 @@ TkpChangeFocus(
}
/*
- * Remember the current serial number for the X server and issue a dummy
- * server request. This marks the position at which we changed the focus,
- * so we can distinguish FocusIn and FocusOut events on either side of the
- * mark.
+ * Remember the current serial number for the X server and issue
+ * a dummy server request. This marks the position at which we
+ * changed the focus, so we can distinguish FocusIn and FocusOut
+ * events on either side of the mark.
*/
return NextRequest(winPtr->display);
}
+
/*
*----------------------------------------------------------------------
*
* WmStackorderToplevelWrapperMap --
*
- * This procedure will create a table that maps the reparent wrapper X id
- * for a toplevel to the TkWindow structure that is wraps. Tk keeps track
- * of a mapping from the window X id to the TkWindow structure but that
- * does us no good here since we only get the X id of the wrapper window.
- * Only those toplevel windows that are mapped have a position in the
- * stacking order.
+ * This procedure will create a table that maps the reparent wrapper
+ * X id for a toplevel to the TkWindow structure that is wraps.
+ * Tk keeps track of a mapping from the window X id to the TkWindow
+ * structure but that does us no good here since we only get the X
+ * id of the wrapper window. Only those toplevel windows that are
+ * mapped have a position in the stacking order.
+ *
*
* Results:
* None.
@@ -5728,12 +5769,11 @@ TkpChangeFocus(
*
*----------------------------------------------------------------------
*/
-
static void
-WmStackorderToplevelWrapperMap(
- TkWindow *winPtr, /* TkWindow to recurse on */
- Display *display, /* X display of parent window */
- Tcl_HashTable *table) /* Maps mac window to TkWindow */
+WmStackorderToplevelWrapperMap(winPtr, display, table)
+ TkWindow *winPtr; /* TkWindow to recurse on */
+ Display *display; /* X display of parent window */
+ Tcl_HashTable *table; /* Maps mac window to TkWindow */
{
TkWindow *childPtr;
Tcl_HashEntry *hPtr;
@@ -5762,8 +5802,8 @@ WmStackorderToplevelWrapperMap(
* This procedure returns the stack order of toplevel windows.
*
* Results:
- * An array of pointers to tk window objects in stacking order or else
- * NULL if there was an error.
+ * An array of pointers to tk window objects in stacking order
+ * or else NULL if there was an error.
*
* Side effects:
* None.
@@ -5772,8 +5812,8 @@ WmStackorderToplevelWrapperMap(
*/
TkWindow **
-TkWmStackorderToplevel(
- TkWindow *parentPtr) /* Parent toplevel window. */
+TkWmStackorderToplevel(parentPtr)
+ TkWindow *parentPtr; /* Parent toplevel window. */
{
WindowRef frontWindow;
TkWindow *childWinPtr, **windows, **window_ptr;
@@ -5788,11 +5828,12 @@ TkWmStackorderToplevel(
Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
WmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);
- windows = (TkWindow**) ckalloc((table.numEntries+1) * sizeof(TkWindow*));
+ windows = (TkWindow **) ckalloc((table.numEntries+1)
+ * sizeof(TkWindow *));
/*
- * Special cases: If zero or one toplevels were mapped there is no need to
- * enumerate Windows.
+ * Special cases: If zero or one toplevels were mapped
+ * there is no need to enumerate Windows.
*/
switch (table.numEntries) {
@@ -5848,11 +5889,8 @@ TkWmStackorderToplevel(
*/
static void
-ApplyWindowAttributeChanges(
- TkWindow *winPtr,
- int newAttributes,
- int oldAttributes,
- int create)
+ApplyWindowAttributeChanges(TkWindow *winPtr, int newAttributes,
+ int oldAttributes, int create)
{
if (newAttributes != oldAttributes) {
if (winPtr->window == None) {
@@ -5875,11 +5913,3 @@ ApplyWindowAttributeChanges(
oldAttributes & (newAttributes ^ oldAttributes));
}
}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */