summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorwolfsuit <wolfsuit>2004-02-16 00:42:33 (GMT)
committerwolfsuit <wolfsuit>2004-02-16 00:42:33 (GMT)
commit304822dcdcdc1a1445448a983ff16a5e6c8b4fc5 (patch)
tree12bebf3e6d48b35ab147bf17d2c87861606f8460 /macosx
parent22f577bfa564c60c562e1e0720624585dbc69e30 (diff)
downloadtk-304822dcdcdc1a1445448a983ff16a5e6c8b4fc5.zip
tk-304822dcdcdc1a1445448a983ff16a5e6c8b4fc5.tar.gz
tk-304822dcdcdc1a1445448a983ff16a5e6c8b4fc5.tar.bz2
Backport Mac OS X specific fixes from TOT. See ChangeLog for details.
In tk_getOpenFile filters, handle the case where you have a Macintosh file type and the files have no filetype. Fix various formatting nits.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXAppInit.c4
-rw-r--r--macosx/tkMacOSXButton.c84
-rw-r--r--macosx/tkMacOSXClipboard.c11
-rw-r--r--macosx/tkMacOSXColor.c36
-rw-r--r--macosx/tkMacOSXDebug.c32
-rw-r--r--macosx/tkMacOSXDialog.c498
-rw-r--r--macosx/tkMacOSXDraw.c10
-rw-r--r--macosx/tkMacOSXEvent.c26
-rw-r--r--macosx/tkMacOSXFont.c18
-rw-r--r--macosx/tkMacOSXHLEvents.c7
-rw-r--r--macosx/tkMacOSXKeyEvent.c2
-rw-r--r--macosx/tkMacOSXKeyboard.c812
-rw-r--r--macosx/tkMacOSXMenu.c45
-rw-r--r--macosx/tkMacOSXMenubutton.c88
-rw-r--r--macosx/tkMacOSXMouseEvent.c51
-rw-r--r--macosx/tkMacOSXNotify.c10
-rw-r--r--macosx/tkMacOSXPort.h5
-rw-r--r--macosx/tkMacOSXScale.c30
-rw-r--r--macosx/tkMacOSXScrlbr.c6
-rw-r--r--macosx/tkMacOSXSubwindows.c6
-rw-r--r--macosx/tkMacOSXWindowEvent.c2
-rw-r--r--macosx/tkMacOSXWm.c10
22 files changed, 1216 insertions, 577 deletions
diff --git a/macosx/tkMacOSXAppInit.c b/macosx/tkMacOSXAppInit.c
index ec141d0..151c68e 100644
--- a/macosx/tkMacOSXAppInit.c
+++ b/macosx/tkMacOSXAppInit.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: tkMacOSXAppInit.c,v 1.4 2002/10/21 04:37:34 das Exp $
+ * RCS: @(#) $Id: tkMacOSXAppInit.c,v 1.4.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <pthread.h>
#include <sys/stat.h>
@@ -133,7 +133,7 @@ main(argc, argv)
}
#endif
- textEncoding=GetApplicationTextEncoding();
+ textEncoding = GetApplicationTextEncoding();
/*
* Now add the scripts folder to the auto_path.
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index dc9f405..9cd2994 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -10,7 +10,7 @@
* 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.2.2.4 2003/10/10 20:20:47 hobbs Exp $
+ * RCS: @(#) $Id: tkMacOSXButton.c,v 1.2.2.5 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkButton.h"
@@ -149,16 +149,16 @@ TkpCreateButton(
macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
Tk_CreateEventHandler(tkwin, ActivateMask,
ButtonEventProc, (ClientData) macButtonPtr);
- macButtonPtr->id=bCount++;
- macButtonPtr->usingControl=0;
- macButtonPtr->flags=0;
- macButtonPtr->userPaneBackground.red=0;
- macButtonPtr->userPaneBackground.green=0;
- macButtonPtr->userPaneBackground.blue=~0;
- macButtonPtr->userPane=NULL;
- macButtonPtr->control=NULL;
- macButtonPtr->controlTitle[0]=
- macButtonPtr->controlTitle[1]=0;
+ macButtonPtr->id = bCount++;
+ macButtonPtr->usingControl = 0;
+ macButtonPtr->flags = 0;
+ macButtonPtr->userPaneBackground.red = 0;
+ macButtonPtr->userPaneBackground.green = 0;
+ macButtonPtr->userPaneBackground.blue = ~0;
+ macButtonPtr->userPane = NULL;
+ macButtonPtr->control = NULL;
+ macButtonPtr->controlTitle[0] = 0;
+ macButtonPtr->controlTitle[1] = 0;
macButtonPtr->picParams.version = -2;
macButtonPtr->picParams.hRes = 0x00480000;
macButtonPtr->picParams.vRes = 0x00480000;
@@ -222,11 +222,15 @@ TkpDisplayButton(
wasUsingControl = macButtonPtr->usingControl;
if (TkMacOSXComputeDrawParams(butPtr, &drawParams) ) {
- macButtonPtr->usingControl=1;
- macButtonPtr->useTkText=DEFAULT_USE_TK_TEXT;
+ 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;
}
/*
@@ -817,14 +821,14 @@ TkMacOSXInitControl (
* Set up the user pane
*/
- initiallyVisible=false;
- initialValue=kControlSupportsEmbedding|
+ initiallyVisible = false;
+ initialValue = kControlSupportsEmbedding|
kControlHasSpecialBackground;
- minValue=0;
- maxValue=1;
- procID=kControlUserPaneProc;
- controlReference=(SInt32)mbPtr;
- mbPtr->userPane=NewControl(mbPtr->windowRef,
+ minValue = 0;
+ maxValue = 1;
+ procID = kControlUserPaneProc;
+ controlReference = (SInt32)mbPtr;
+ mbPtr->userPane = NewControl(mbPtr->windowRef,
paneRect, "\p",
initiallyVisible,
initialValue,
@@ -838,7 +842,7 @@ TkMacOSXInitControl (
return 1;
}
- if ((status=EmbedControl(mbPtr->userPane,rootControl))!=noErr) {
+ if ((status=EmbedControl(mbPtr->userPane,rootControl)) != noErr) {
fprintf(stderr,"Failed to embed user pane control %d\n", status);
return 1;
}
@@ -846,9 +850,9 @@ TkMacOSXInitControl (
SetUserPaneSetUpSpecialBackgroundProc(mbPtr->userPane,
UserPaneBackgroundProc);
SetUserPaneDrawProc(mbPtr->userPane,UserPaneDraw);
- initiallyVisible=false;
+ initiallyVisible = false;
TkMacOSXComputeControlParams(butPtr,&mbPtr->params);
- mbPtr->control=NewControl(mbPtr->windowRef,
+ mbPtr->control = NewControl(mbPtr->windowRef,
cntrRect, "\p",
initiallyVisible,
mbPtr->params.initialValue,
@@ -867,7 +871,7 @@ TkMacOSXInitControl (
return 1;
}
- mbPtr->flags|=(1 + 2);
+ mbPtr->flags |= (1 + 2);
return 0;
}
@@ -905,28 +909,26 @@ TkMacOSXDrawControl(
TkWindow * winPtr;
Rect paneRect;
Rect cntrRect;
- int hilitePart = -1;
-
- winPtr=(TkWindow *)butPtr->tkwin;
+ 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 = paneRect;
/*
- cntrRect.left+=butPtr->inset;
- cntrRect.top+=butPtr->inset;
- cntrRect.right-=butPtr->inset;
- cntrRect.bottom-=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.bottom-=DEF_INSET_BOTTOM;
+ 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
@@ -1135,7 +1137,7 @@ SetupBevelButton(
ClosePicture();
tkPictureIsOpen = 0;
- if ( (err=SetControlData(controlHandle, kControlButtonPart,
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
kControlBevelButtonContentTag,
sizeof(ControlButtonContentInfo),
(char *) &mbPtr->bevelButtonContent)) != noErr ) {
@@ -1163,7 +1165,7 @@ SetupBevelButton(
theAlignment = kControlBevelButtonAlignCenter;
}
- if ((err=SetControlData(controlHandle, kControlButtonPart,
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
kControlBevelButtonGraphicAlignTag,
sizeof(ControlButtonGraphicAlignment),
(char *) &theAlignment)) != noErr ) {
@@ -1183,7 +1185,7 @@ SetupBevelButton(
} else if (butPtr->compound == COMPOUND_RIGHT) {
thePlacement = kControlBevelButtonPlaceToLeftOfGraphic;
}
- if ((err=SetControlData(controlHandle, kControlButtonPart,
+ if ((err = SetControlData(controlHandle, kControlButtonPart,
kControlBevelButtonTextPlaceTag,
sizeof(ControlButtonTextPlacement),
(char *) &thePlacement)) != noErr ) {
diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c
index 3c083e1..acfd94c 100644
--- a/macosx/tkMacOSXClipboard.c
+++ b/macosx/tkMacOSXClipboard.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: tkMacOSXClipboard.c,v 1.2.2.2 2003/11/11 18:21:09 hobbs Exp $
+ * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.2.2.3 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkInt.h"
@@ -66,7 +66,7 @@ TkSelGetSelection(
* Get the scrap from the Macintosh global clipboard.
*/
- err=GetCurrentScrap(&scrapRef);
+ err = GetCurrentScrap(&scrapRef);
if (err != noErr) {
Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
" GetCurrentScrap failed.", (char *) NULL);
@@ -340,8 +340,11 @@ TkSuspendClipboard()
ClearCurrentScrap();
GetCurrentScrap(&scrapRef);
- Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer, length, &encodedText);
- PutScrapFlavor(scrapRef, 'TEXT', 0, Tcl_DStringLength(&encodedText), Tcl_DStringValue(&encodedText) );
+ Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer,
+ length, &encodedText);
+ PutScrapFlavor(scrapRef, 'TEXT', 0,
+ Tcl_DStringLength(&encodedText),
+ Tcl_DStringValue(&encodedText) );
Tcl_DStringFree(&encodedText);
/*
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index 492f098..d634bdd 100644
--- a/macosx/tkMacOSXColor.c
+++ b/macosx/tkMacOSXColor.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXColor.c,v 1.2 2002/08/31 06:12:29 das Exp $
+ * RCS: @(#) $Id: tkMacOSXColor.c,v 1.2.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <tkColor.h>
@@ -330,8 +330,9 @@ TkpGetColorByValue(
* GetControlPartColor --
*
* Given a part number this function will return the standard
- * system default color for that part. It does this by looking
- * in the system's 'cctb' resource.
+ * system default color for that part. On MacOS X this uses the
+ * Theme Brushes to find the active color, though for now, only
+ * the "Text Color" is supported.
*
* Results:
* True if a color is found, false otherwise.
@@ -348,24 +349,21 @@ GetControlPartColor(
short part, /* Part code. */
RGBColor *macColor) /* Pointer to Mac color. */
{
-/* Stubbed out for OS X
- short index;
- CCTabHandle ccTab;
-
- if (defaultAuxCtlHandle == NULL) {
- GetAuxiliaryControlRecord(NULL, &defaultAuxCtlHandle);
- }
- ccTab = (**defaultAuxCtlHandle).acCTable;
- if(ccTab && (ResError() == noErr)) {
- for(index = 0; index <= (**ccTab).ctSize; index++) {
- if((**ccTab).ctTable[index].value == part) {
- *macColor = (**ccTab).ctTable[index].rgb;
- return true;
+ int retVal = false;
+ OSErr err;
+
+ switch (part) {
+ case cTextColor:
+ err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32,
+ true, macColor);
+ if (err == noErr) {
+ retVal = true;
}
- }
+ break;
+ default:
+ retVal = false;
}
-*/
- return false;
+ return retVal;
}
/*
diff --git a/macosx/tkMacOSXDebug.c b/macosx/tkMacOSXDebug.c
index 53997e8..674d5a3 100644
--- a/macosx/tkMacOSXDebug.c
+++ b/macosx/tkMacOSXDebug.c
@@ -260,7 +260,7 @@ CarbonEventToAscii(EventRef eventRef, char * buf)
strcat(buf, " ");
buf += strlen(buf);
while (list->names && (!names) ) {
- if (eventClass==list->c) {
+ if (eventClass == list->c) {
names = list -> names;
} else {
list++;
@@ -269,9 +269,9 @@ CarbonEventToAscii(EventRef eventRef, char * buf)
if (names) {
found = 0;
while (names->name && !found) {
- if (eventKind==names->kind) {
+ if (eventKind == names->kind) {
sprintf(buf, "%-20s", names->name);
- found=1;
+ found = 1;
} else {
names++;
}
@@ -302,11 +302,11 @@ char * CarbonEventKindToAscii(EventRef eventRef, char * buf )
}
}
if (names) {
- found=0;
+ found = 0;
while ( names->name && !found ) {
- if (eventKind==names->kind) {
+ if (eventKind == names->kind) {
sprintf(buf,"%s",names->name);
- found=1;
+ found = 1;
} else {
names++;
}
@@ -326,17 +326,17 @@ char * ClassicEventToAscii(EventRecord * eventPtr, char * buf )
int found = 0;
names = classicEventNames;
while ( names -> name && !found )
- if (eventPtr->what==names->kind) {
+ if (eventPtr->what == names->kind) {
int * iPtr;
char cBuf[8];
- iPtr=( int *)&cBuf;
+ iPtr=(int *) &cBuf;
*iPtr = eventPtr->message;
cBuf[4] = 0;
sprintf(buf, "%-16s %08x %04x %s", names->name,
(int) eventPtr->message,
eventPtr->modifiers,
cBuf);
- found=1;
+ found = 1;
} else {
names++;
}
@@ -358,8 +358,8 @@ void printPoint(char * tag, Point * p )
void printRect(char * tag, Rect * r )
{
fprintf(stderr,"%s %4d %4d %4d %4d (%dx%d)\n",
- tag,r->left,r->top,r->right,r->bottom,
- r->right-r->left+1,r->bottom-r->top+1 );
+ tag, r->left, r->top, r->right, r->bottom,
+ r->right - r->left + 1, r->bottom - r->top + 1);
}
void printRegion(char * tag, RgnHandle rgn )
@@ -373,7 +373,7 @@ void printWindowTitle(char * tag, WindowRef window )
{
Str255 title;
GetWTitle(window,title);
- title [ title[0] + 1 ] = 0;
+ title [title[0] + 1] = 0;
fprintf(stderr, "%s %s\n", tag, title +1 );
}
@@ -402,7 +402,7 @@ TkMacOSXMenuMessageToAscii(int msg, char * s)
{
MsgName * msgNamePtr;
for (msgNamePtr = msgNames;msgNamePtr->name;) {
- if (msgNamePtr->msg==msg) {
+ if (msgNamePtr->msg == msg) {
strcpy(s,msgNamePtr->name);
return s;
} else {
@@ -428,9 +428,9 @@ char * MouseTrackingResultToAscii(MouseTrackingResult r, char * buf)
{ -1, NULL }
};
MsgName * namePtr;
- for (namePtr=trackingNames;namePtr->name;namePtr++) {
- if (namePtr->msg==r) {
- strcpy(buf,namePtr->name);
+ for (namePtr = trackingNames; namePtr->name; namePtr++) {
+ if (namePtr->msg == r) {
+ strcpy(buf, namePtr->name);
return buf;
}
}
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 25883ce..074dca6 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.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: tkMacOSXDialog.c,v 1.4.2.1 2004/02/14 01:08:28 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.2 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <Carbon/Carbon.h>
@@ -58,6 +58,18 @@ typedef struct _OpenFileData {
} OpenFileData;
+/*
+ * The following structure is used in the tk_messageBox
+ * implementation.
+ */
+typedef struct {
+ WindowRef windowRef;
+ int buttonIndex;
+} CallbackUserData;
+
+
+static OSStatus AlertHandler _ANSI_ARGS_(( EventHandlerCallRef callRef,
+ EventRef eventRef, void *userData ));
static Boolean MatchOneType _ANSI_ARGS_((StringPtr fileNamePtr, OSType fileType,
OpenFileData *myofdPtr, FileFilter *filterPtr));
static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info,
@@ -747,11 +759,11 @@ NavServicesGetFile(
diagOptions.location.v = -1;
diagOptions.optionFlags = kNavDontAutoTranslate
+ kNavDontAddTranslateItems;
-
if (multiple) {
diagOptions.optionFlags += kNavAllowMultipleFiles;
}
-
+ diagOptions.modality = kWindowModalityAppModal;
+
if (ofdPtr != NULL && ofdPtr->usePopup) {
FileFilter *filterPtr;
@@ -775,7 +787,7 @@ NavServicesGetFile(
filterPtr->name, encoding);
}
diagOptions.popupExtension = CFArrayCreate(NULL,
- (const void **)menuItemNames, ofdPtr->fl.numFilters, NULL);;
+ (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL);
} else {
diagOptions.optionFlags += kNavNoTypePopup;
diagOptions.popupExtension = NULL;
@@ -815,7 +827,7 @@ NavServicesGetFile(
openFileFilterUPP,
ofdPtr,
&dialogRef);
- if (err!=noErr){
+ if (err != noErr) {
fprintf(stderr,"NavCreateGetFileDialog failed, %d\n", err );
dialogRef = NULL;
}
@@ -857,7 +869,7 @@ NavServicesGetFile(
* Most commands assume that the file dialogs return a single
* item, not a list. So only build a list if multiple is true...
*/
- if (err==noErr) {
+ if (err == noErr) {
if (multiple) {
theResult = Tcl_NewListObj(0, NULL);
} else {
@@ -867,7 +879,7 @@ NavServicesGetFile(
err = memFullErr;
}
}
- if (theReply.validRecord && err==noErr) {
+ if (theReply.validRecord && err == noErr) {
AEDesc resultDesc;
long count;
Tcl_DString fileName;
@@ -962,7 +974,7 @@ NavServicesGetFile(
if (menuItemNames) {
int i;
- for (i=0;i < ofdPtr->fl.numFilters;i++) {
+ for (i = 0;i < ofdPtr->fl.numFilters; i++) {
CFRelease(menuItemNames[i]);
}
ckfree((void *)menuItemNames);
@@ -981,30 +993,59 @@ OpenFileFilterProc(
NavFilterModes filterMode )
{
OpenFileData *ofdPtr = (OpenFileData *) callBackUD;
+
if (!ofdPtr || !ofdPtr->usePopup) {
return true;
} else {
if (ofdPtr->fl.numFilters == 0) {
return true;
} else {
-
- if ( theItem->descriptorType == typeFSS ) {
- NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*)info;
+ 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;
- HLock((Handle)theItem->dataHandle);
- fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name);
+ 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, fileNamePtr + 1, len);
+ fileName[len] = '\0';
+ fileNamePtr = 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 = Tcl_DStringValue(&fileNameDString);
+ } else {
+ fileNamePtr = NULL;
+ }
+ }
if (ofdPtr->usePopup) {
i = ofdPtr->curType;
- for (filterPtr = ofdPtr->fl.filters; filterPtr && i > 0; i--) {
+ for (filterPtr = ofdPtr->fl.filters;
+ filterPtr && i > 0; i--) {
filterPtr = filterPtr->next;
}
if (filterPtr) {
@@ -1015,9 +1056,11 @@ OpenFileFilterProc(
}
} else {
/*
- * We are not using the popup menu. In this case, the file is
- * considered matched if it matches any of the file filters.
+ * 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) {
@@ -1029,7 +1072,7 @@ OpenFileFilterProc(
}
}
- HUnlock((Handle)theItem->dataHandle);
+ Tcl_DStringFree (&fileNameDString);
return (result == MATCHED);
} else {
return true;
@@ -1086,7 +1129,7 @@ OpenEventProc(
static Boolean
MatchOneType(
StringPtr fileNamePtr, /* Name of the file */
- OSType fileType, /* Type 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 */
@@ -1110,7 +1153,8 @@ MatchOneType(
* considered an error.
*/
- for (clausePtr=filterPtr->clauses; clausePtr; clausePtr=clausePtr->next) {
+ for (clausePtr = filterPtr->clauses; clausePtr;
+ clausePtr = clausePtr->next) {
int macMatched = 0;
int globMatched = 0;
GlobPattern * globPtr;
@@ -1123,18 +1167,13 @@ MatchOneType(
macMatched = 1;
}
- for (globPtr=clausePtr->patterns; globPtr; globPtr=globPtr->next) {
- char filename[256];
- int len;
- char * p, *q, *ext;
+ for (globPtr = clausePtr->patterns; globPtr;
+ globPtr = globPtr->next) {
+ char *q, *ext;
if (fileNamePtr == NULL) {
continue;
}
- p = (char*)(fileNamePtr);
- len = p[0];
- strncpy(filename, p+1, len);
- filename[len] = '\0';
ext = globPtr->pattern;
if (ext[0] == '\0') {
@@ -1142,7 +1181,8 @@ MatchOneType(
* We don't want any extensions: OK if the filename doesn't
* have "." in it
*/
- for (q=filename; *q; q++) {
+
+ for (q = fileNamePtr; *q; q++) {
if (*q == '.') {
goto glob_unmatched;
}
@@ -1150,7 +1190,7 @@ MatchOneType(
goto glob_matched;
}
- if (Tcl_StringMatch(filename, ext)) {
+ if (Tcl_StringMatch(fileNamePtr, ext)) {
goto glob_matched;
} else {
goto glob_unmatched;
@@ -1164,14 +1204,24 @@ MatchOneType(
break;
}
- for (mfPtr=clausePtr->macTypes; mfPtr; mfPtr=mfPtr->next) {
+ for (mfPtr = clausePtr->macTypes; mfPtr; mfPtr = mfPtr->next) {
if (fileType == mfPtr->type) {
macMatched = 1;
break;
}
}
- if (globMatched && macMatched) {
+ /*
+ * 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))) {
return MATCHED;
}
}
@@ -1209,7 +1259,7 @@ TkAboutDlg()
return;
}
- windowRef=GetDialogWindow(aboutDlog);
+ windowRef = GetDialogWindow(aboutDlog);
SelectWindow(windowRef);
while (itemHit != 1) {
@@ -1222,3 +1272,385 @@ TkAboutDlg()
return;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tk_MessageBoxObjCmd --
+ *
+ * Implements the tk_messageBox in native Mac OS X style.
+ *
+ * Results:
+ * A standard Tcl result.
+ *
+ * Side effects:
+ * 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. */
+{
+ 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;
+ Boolean haveParentOption = false;
+ char *str;
+ int index;
+ int defaultButtonIndex;
+ int defaultNativeButtonIndex; /* 1, 2, 3: right to left. */
+ int typeIndex;
+ int i;
+ int indexDefaultOption;
+ int result = TCL_OK;
+
+ static CONST char *movableAlertStrings[] = {
+ "-default", /* "-finemessage", */ "-icon",
+ "-message", "-parent",
+ "-title", "-type",
+ (char *)NULL
+ };
+ static CONST char *movableTypeStrings[] = {
+ "abortretryignore", "ok",
+ "okcancel", "retrycancel",
+ "yesno", "yesnocancel",
+ (char *)NULL
+ };
+ static CONST char *movableButtonStrings[] = {
+ "abort", "retry", "ignore",
+ "ok", "cancel", "yes", "no",
+ (char *)NULL
+ };
+ static CONST char *movableIconStrings[] = {
+ "error", "info", "question", "warning",
+ (char *)NULL
+ };
+ enum movableAlertOptions {
+ ALERT_DEFAULT, /* ALERT_FINEMESSAGE, */ ALERT_ICON,
+ ALERT_MESSAGE, ALERT_PARENT,
+ ALERT_TITLE, ALERT_TYPE
+ };
+ enum movableTypeOptions {
+ 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
+ };
+ 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.
+ */
+
+ 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 */
+ {0, 0, 0, 1, 2, 0, 0}, /* okcancel */
+ {0, 1, 0, 0, 2, 0, 0}, /* retrycancel */
+ {0, 0, 0, 0, 0, 1, 2}, /* yesno */
+ {0, 0, 0, 0, 3, 1, 2}, /* yesnocancel */
+ };
+
+ /*
+ * Need also the inverse mapping, from native button (1, 2, 3) to the
+ * descriptive button text string index.
+ */
+
+ short nativeButtonIndexAndTypeToButtonIndex[][4] = {
+ {-1, 0, 1, 2}, /* abortretryignore */
+ {-1, 3, 0, 0}, /* ok */
+ {-1, 3, 4, 0}, /* okcancel */
+ {-1, 1, 4, 0}, /* retrycancel */
+ {-1, 5, 6, 0}, /* yesno */
+ {-1, 5, 6, 4}, /* yesnocancel */
+ };
+
+ alertType = kAlertPlainAlert;
+ typeIndex = TYPE_OK;
+
+ GetStandardAlertDefaultParams( &paramCFStringRec, kStdCFStringAlertVersionOne );
+ paramCFStringRec.movable = true;
+ paramCFStringRec.helpButton = false;
+ paramCFStringRec.defaultButton = kAlertStdAlertOKButton;
+
+ for (i = 1; i < objc; i += 2) {
+ int iconIndex;
+ char *string;
+
+ if (Tcl_GetIndexFromObj( interp, objv[i], movableAlertStrings, "option",
+ 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",
+ (char *) NULL);
+ result = TCL_ERROR;
+ goto end;
+ }
+
+ switch (index) {
+
+ case ALERT_DEFAULT:
+
+ /*
+ * Need to postpone processing of this option until we are
+ * sure to know the '-type' as well.
+ */
+
+ haveDefaultOption = true;
+ indexDefaultOption = i;
+ break;
+
+/* case ALERT_FINEMESSAGE:
+ str = Tcl_GetStringFromObj( objv[i + 1], NULL );
+ finemessageTextCF = CFStringCreateWithCString( NULL, str, kCFStringEncodingUTF8 );
+ break;
+*/
+ case ALERT_ICON:
+ /* not sure about UTF translation here... */
+ if (Tcl_GetIndexFromObj( interp, objv[i + 1], movableIconStrings,
+ "value", TCL_EXACT, &iconIndex ) != TCL_OK) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ switch (iconIndex) {
+ case ICON_ERROR:
+ alertType = kAlertStopAlert;
+ break;
+ case ICON_INFO:
+ alertType = kAlertNoteAlert;
+ break;
+ case ICON_QUESTION:
+ alertType = kAlertCautionAlert;
+ break;
+ case ICON_WARNING:
+ alertType = kAlertCautionAlert;
+ break;
+ }
+ break;
+
+ case ALERT_MESSAGE:
+ str = Tcl_GetStringFromObj( objv[i + 1], NULL );
+ messageTextCF = CFStringCreateWithCString( NULL, str, kCFStringEncodingUTF8 );
+ break;
+
+ case ALERT_PARENT:
+ str = Tcl_GetStringFromObj( objv[i + 1], NULL );
+ tkwin = Tk_NameToWindow( interp, str, tkwin );
+ if (tkwin == NULL) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ haveParentOption = true;
+ break;
+
+ case ALERT_TITLE:
+ break;
+
+ case ALERT_TYPE:
+ /* not sure about UTF translation here... */
+ if (Tcl_GetIndexFromObj( interp, objv[i + 1], movableTypeStrings,
+ "value", TCL_EXACT, &typeIndex ) != TCL_OK) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ switch (typeIndex) {
+ case TYPE_ABORTRETRYIGNORE:
+ paramCFStringRec.defaultText = CFSTR("Abort");
+ paramCFStringRec.cancelText = CFSTR("Retry");
+ paramCFStringRec.otherText = CFSTR("Ignore");
+ break;
+ case TYPE_OK:
+ paramCFStringRec.defaultText = CFSTR("OK");
+ break;
+ case TYPE_OKCANCEL:
+ paramCFStringRec.defaultText = CFSTR("OK");
+ paramCFStringRec.cancelText = CFSTR("Cancel");
+ break;
+ case TYPE_RETRYCANCEL:
+ paramCFStringRec.defaultText = CFSTR("Retry");
+ paramCFStringRec.cancelText = CFSTR("Cancel");
+ break;
+ case TYPE_YESNO:
+ paramCFStringRec.defaultText = CFSTR("Yes");
+ paramCFStringRec.cancelText = CFSTR("No");
+ break;
+ case TYPE_YESNOCANCEL:
+ paramCFStringRec.defaultText = CFSTR("Yes");
+ paramCFStringRec.cancelText = CFSTR("No");
+ paramCFStringRec.otherText = CFSTR("Cancel");
+ break;
+ }
+ break;
+ }
+ }
+
+ if (haveDefaultOption) {
+
+ /*
+ * 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) {
+ result = TCL_ERROR;
+ goto end;
+ }
+
+ /* 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( "Illegel default option", -1 ));
+ result = TCL_ERROR;
+ goto end;
+ }
+ paramCFStringRec.defaultButton = defaultNativeButtonIndex;
+ }
+ SetThemeCursor( kThemeArrowCursor );
+
+ if (haveParentOption) {
+ TkWindow *winPtr;
+ MacDrawable *macWin;
+ WindowRef windowRef;
+ EventTargetRef notifyTarget;
+ EventHandlerUPP handler;
+ CallbackUserData data;
+ const EventTypeSpec kEvents[] = {
+ {kEventClassCommand, kEventProcessCommand}
+ };
+
+ winPtr = (TkWindow *) tkwin;
+
+ /*
+ * Create the underlying Mac window for this Tk window.
+ */
+
+ macWin = (MacDrawable *) winPtr->window;
+ windowRef = GetWindowFromPort( TkMacOSXGetDrawablePort((Drawable) macWin) );
+ notifyTarget = GetWindowEventTarget( windowRef );
+ osError = CreateStandardSheet( alertType, messageTextCF,
+ finemessageTextCF, &paramCFStringRec,
+ notifyTarget, &dialogRef );
+ if(osError != noErr) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ data.windowRef = windowRef;
+ data.buttonIndex = 1;
+ handler = NewEventHandlerUPP( AlertHandler );
+ InstallEventHandler(notifyTarget, handler,
+ GetEventTypeCount(kEvents),
+ kEvents, &data, NULL );
+ osError = ShowSheetWindow( GetDialogWindow(dialogRef), windowRef );
+ if(osError != noErr) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ osError = RunAppModalLoopForWindow( windowRef );
+
+ itemHit = data.buttonIndex;
+ DisposeEventHandlerUPP( handler );
+ } else {
+ osError = CreateStandardAlert( alertType, messageTextCF,
+ finemessageTextCF, &paramCFStringRec, &dialogRef );
+ if(osError != noErr) {
+ result = TCL_ERROR;
+ goto end;
+ }
+ osError = RunStandardAlert( dialogRef, NULL, &itemHit );
+ }
+ if(osError == noErr) {
+ int ind;
+
+ /*
+ * Map 'itemHit' (1, 2, 3) to descriptive text string.
+ */
+
+ ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit];
+ Tcl_SetObjResult( interp,
+ Tcl_NewStringObj( movableButtonStrings[ind], -1 ));
+ } else {
+ result = TCL_ERROR;
+ }
+
+ end:
+ if (finemessageTextCF != NULL) {
+ CFRelease( finemessageTextCF );
+ }
+ if (messageTextCF != NULL) {
+ CFRelease( messageTextCF );
+ }
+ return result;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * AlertHandler --
+ *
+ * Carbon event handler for the Standard Sheet dialog.
+ *
+ * Results:
+ * OSStatus if event handled or not.
+ *
+ * Side effects:
+ * May set userData.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static OSStatus
+AlertHandler( EventHandlerCallRef callRef, EventRef eventRef, void *userData )
+{
+ OSStatus result = eventNotHandledErr;
+ HICommand cmd;
+ CallbackUserData *dataPtr = (CallbackUserData *) userData;
+
+ GetEventParameter( eventRef, kEventParamDirectObject, typeHICommand,
+ NULL, sizeof(cmd), NULL, &cmd );
+ switch (cmd.commandID) {
+ case kHICommandOK:
+ dataPtr->buttonIndex = 1;
+ result = noErr;
+ break;
+ case kHICommandCancel:
+ dataPtr->buttonIndex = 2;
+ result = noErr;
+ break;
+ case kHICommandOther:
+ dataPtr->buttonIndex = 3;
+ result = noErr;
+ break;
+ }
+ if (result == noErr) {
+ result = QuitAppModalLoopForWindow( dataPtr->windowRef );
+ }
+ return result;
+}
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 3edcfe9..13d746c 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.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: tkMacOSXDraw.c,v 1.2 2002/08/31 06:12:29 das Exp $
+ * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.2.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkInt.h"
@@ -289,8 +289,8 @@ XCopyPlane(
* Case 2: transparent bitmaps. If it's color we ignore
* the forecolor.
*/
- pm=GetPortPixMap(srcPort);
- if (GetPixDepth(pm)== 1) {
+ pm = GetPortPixMap(srcPort);
+ if (GetPixDepth(pm) == 1) {
tmode = srcOr;
} else {
tmode = transparent;
@@ -453,7 +453,7 @@ XFillRectangles(
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
XRectangle *rectangles, /* Rectangle array. */
- int n_rectangels) /* Number of rectangles. */
+ int n_rectangles) /* Number of rectangles. */
{
MacDrawable *macWin = (MacDrawable *) d;
CGrafPtr saveWorld;
@@ -472,7 +472,7 @@ XFillRectangles(
TkMacOSXSetUpGraphicsPort(gc, destPort);
- for (i=0; i<n_rectangels; i++) {
+ for (i = 0; i < n_rectangles; i++) {
theRect.left = (short) (macWin->xOff + rectangles[i].x);
theRect.top = (short) (macWin->yOff + rectangles[i].y);
theRect.right = (short) (theRect.left + rectangles[i].width);
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c
index f0448e6..838c0a9 100644
--- a/macosx/tkMacOSXEvent.c
+++ b/macosx/tkMacOSXEvent.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: tkMacOSXEvent.c,v 1.3 2003/02/19 19:27:46 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.3.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <stdio.h>
@@ -69,10 +69,20 @@ tkMacOSXFlushWindows ()
if (QDIsPortBuffered(portPtr)) {
QDFlushPortBuffer(portPtr, NULL);
}
- wRef=GetNextWindow(wRef);
+ wRef = GetNextWindow(wRef);
}
}
+
+
+int
+XSync (Display *display, Bool flag)
+{
+ tkMacOSXFlushWindows();
+ display->request++;
+ return 0;
+}
+
/*
*----------------------------------------------------------------------
*
@@ -133,8 +143,8 @@ TkMacOSXProcessAppleEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
EventRecord eventRecord;
if (ConvertEventRefToEventRecord(eventPtr->eventRef,
&eventRecord )) {
- err=TkMacOSXDoHLEvent(&eventRecord);
- if (err!=noErr) {
+ err = TkMacOSXDoHLEvent(&eventRecord);
+ if (err != noErr) {
char buf1 [ 256 ];
char buf2 [ 256 ];
fprintf(stderr,
@@ -243,7 +253,7 @@ ReceiveAndProcessEvent()
* into this routine, and are guaranteed to have one waiting.
*/
- err=ReceiveNextEvent(0, NULL, kEventDurationNoWait,
+ err = ReceiveNextEvent(0, NULL, kEventDurationNoWait,
true, &macEvent.eventRef);
if (err != noErr) {
return err;
@@ -254,10 +264,10 @@ ReceiveAndProcessEvent()
TkMacOSXProcessEvent(&macEvent,&eventStatus);
if (!eventStatus.stopProcessing) {
if (!targetRef) {
- targetRef=GetEventDispatcherTarget();
+ targetRef = GetEventDispatcherTarget();
}
- err= SendEventToEventTarget(macEvent.eventRef,targetRef);
+ err = SendEventToEventTarget(macEvent.eventRef,targetRef);
if (err != noErr
#if !TK_MAC_DEBUG
&& err != eventNotHandledErr
@@ -265,7 +275,7 @@ ReceiveAndProcessEvent()
) {
fprintf(stderr,
"RCNE SendEventToEventTarget (%s) failed, %d\n",
- CarbonEventToAscii(macEvent.eventRef,buf ),err);
+ CarbonEventToAscii(macEvent.eventRef, buf),err);
}
}
ReleaseEvent(macEvent.eventRef);
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 1a6556c..875e1a3 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.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: tkMacOSXFont.c,v 1.3 2002/10/16 19:44:05 das Exp $
+ * RCS: @(#) $Id: tkMacOSXFont.c,v 1.3.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <Carbon/Carbon.h>
@@ -1166,7 +1166,7 @@ TkMacOSXIsCharacterMissing(
fm.device = 0;
fm.numer.h = fm.numer.v = fm.denom.h = fm.denom.v = 1;
- fmOutPtr=FMSwapFont(&fm);
+ fmOutPtr = FMSwapFont(&fm);
fprintf(stderr,"fmOut %08x, handle %08x\n", (int)fmOutPtr, fmOutPtr->fontHandle);
#if !defined(UNIVERSAL_INTERFACES_VERSION) || (UNIVERSAL_INTERFACES_VERSION < 0x0300)
@@ -1749,13 +1749,13 @@ FontMapLoadPage(
* For some reason, FMSwapFont alywas returns a structure where the returned font handle
* is NULL. Until we figure this one out, assume all characters are allowed
*/
- fmOut=FMSwapFont(&fm);
- fHandle=fmOut->fontHandle;
- isMultiByteFont=subFontPtr->familyPtr->isMultiByteFont;
+ fmOut = FMSwapFont(&fm);
+ fHandle = fmOut->fontHandle;
+ isMultiByteFont = subFontPtr->familyPtr->isMultiByteFont;
#ifndef MAC_OSX_TK
GetResInfo(fHandle, &theID, &theType, theName);
fprintf ( stderr, "ResError() %d, %x\n", ResError (), fHandle );
- if (theType=='sfnt') {
+ if (theType == 'sfnt') {
#endif
/*
* Found an outline font which has very complex font record.
@@ -2241,7 +2241,7 @@ int TkMacOSXUseAntialiasedText(interp, enable)
static UInt32 (*swaptextflags)(UInt32) = NULL;
if(!initialized) {
- NSSymbol nsSymbol=NULL;
+ NSSymbol nsSymbol = NULL;
if(NSIsSymbolNameDefinedWithHint("_QDSwapTextFlags", "QD")) {
nsSymbol = NSLookupAndBindSymbolWithHint("_QDSwapTextFlags", "QD");
} else if(NSIsSymbolNameDefinedWithHint("_SwapQDTextFlags", "QD")) {
@@ -2267,9 +2267,9 @@ int TkMacOSXUseAntialiasedText(interp, enable)
Tcl_ResetResult(interp);
}
}
- if(swaptextflags) {
+ if (swaptextflags) {
swaptextflags(enable ? kQDUseCGTextRendering | kQDUseCGTextMetrics
- : kQDUseTrueTypeScalerGlyphs);
+ : kQDUseTrueTypeScalerGlyphs);
TkMacOSXAntialiasedTextEnabled = enable;
return TCL_OK;
} else {
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index ac167f2..47907fd 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.1 2003/05/13 02:42:57 das Exp $
+ * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.2 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkMacOSXPort.h"
@@ -329,10 +329,11 @@ ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
else {
AEGetDescData(&theDesc,data,size);
data [ size ] = 0;
- for (i=0; i<size; i++)
+ for (i = 0; i < size; i++)
if (data[i] == '\r')
data[i] = '\n';
- AEReplaceDescData(theDesc.descriptorType,data,size+1,&theDesc);
+ AEReplaceDescData(theDesc.descriptorType, data,
+ size + 1, &theDesc);
}
Tcl_ExternalToUtfDString(NULL, data, size,
&encodedText);
diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c
index ed9535a..05f4c3e 100644
--- a/macosx/tkMacOSXKeyEvent.c
+++ b/macosx/tkMacOSXKeyEvent.c
@@ -365,7 +365,7 @@ GenerateKeyEvent(
} else {
- for (i=0; i<numChars; ++i) {
+ for (i = 0; i < numChars; ++i) {
/*
* Encode one char in the trans_chars array that was already
diff --git a/macosx/tkMacOSXKeyboard.c b/macosx/tkMacOSXKeyboard.c
index e568e9f..24ada94 100644
--- a/macosx/tkMacOSXKeyboard.c
+++ b/macosx/tkMacOSXKeyboard.c
@@ -1,7 +1,7 @@
/*
* tkMacOSXKeyboard.c --
*
- * Routines to support keyboard events on the Macintosh.
+ * Routines to support keyboard events on the Macintosh.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
@@ -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: tkMacOSXKeyboard.c,v 1.5.2.1 2003/11/21 13:05:09 cc_benny Exp $
+ * RCS: @(#) $Id: tkMacOSXKeyboard.c,v 1.5.2.2 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkInt.h"
@@ -18,11 +18,31 @@
#include <Carbon/Carbon.h>
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h" /* TkMacOSXKeycodeToUnicode() FIXME: That
- * function should probably move here */
+ * function should probably move here. */
+
+/*
+ * A couple of simple definitions to make code a bit more self-explaining.
+ *
+ * For the assignments of Mod1==alt==command and Mod2==meta==option, see also
+ * tkMacOSXMouseEvent.c.
+ */
+
+#define LATIN1_MAX 255
+#define MAC_KEYCODE_MAX 0x7F
+#define MAC_KEYCODE_MASK 0x7F
+#define ALT_MASK Mod1Mask
+#define OPTION_MASK Mod2Mask
+
+
+/*
+ * Tables enumerating the special keys defined on Mac keyboards. These are
+ * necessary for correct keysym mappings for all keys where the keysyms are
+ * not identical with their ASCII or Latin-1 code points.
+ */
typedef struct {
- int keycode; /* Macintosh keycode */
- KeySym keysym; /* X windows Keysym */
+ int keycode; /* Macintosh keycode. */
+ KeySym keysym; /* X windows keysym. */
} KeyInfo;
/*
@@ -30,61 +50,73 @@ typedef struct {
*
* 0x34, XK_Return - Powerbooks use this and some keymaps define it.
*
+ * 0x4C, XK_Return - XFree86 and Apple's X11 call this one XK_KP_Enter.
+ *
* 0x47, XK_Clear - This key is NumLock when used on PCs, but Mac
- * applications don't use it like that.
+ * applications don't use it like that, nor does Apple's X11.
*
* All other keycodes are taken from the published ADB keyboard layouts.
*/
static KeyInfo keyArray[] = {
- {0x4C, XK_Return},
- {0x24, XK_Return},
- {0x34, XK_Return},
- {0x33, XK_BackSpace},
- {0x75, XK_Delete},
- {0x30, XK_Tab},
- {0x74, XK_Page_Up},
- {0x79, XK_Page_Down},
- {0x73, XK_Home},
- {0x77, XK_End},
- {0x7B, XK_Left},
- {0x7C, XK_Right},
- {0x7E, XK_Up},
- {0x7D, XK_Down},
- {0x72, XK_Help},
- {0x35, XK_Escape},
- {0x47, XK_Clear},
- {0, 0}
+ {0x24, XK_Return},
+ {0x30, XK_Tab},
+ {0x33, XK_BackSpace},
+ {0x34, XK_Return},
+ {0x35, XK_Escape},
+
+ {0x47, XK_Clear},
+ {0x4C, XK_Return},
+
+ {0x72, XK_Help},
+ {0x73, XK_Home},
+ {0x74, XK_Page_Up},
+ {0x75, XK_Delete},
+ {0x77, XK_End},
+ {0x79, XK_Page_Down},
+
+ {0x7B, XK_Left},
+ {0x7C, XK_Right},
+ {0x7D, XK_Down},
+ {0x7E, XK_Up},
+
+ {0, 0}
};
-static KeyInfo vituralkeyArray[] = {
- {122, XK_F1},
- {120, XK_F2},
- {99, XK_F3},
- {118, XK_F4},
- {96, XK_F5},
- {97, XK_F6},
- {98, XK_F7},
- {100, XK_F8},
- {101, XK_F9},
- {109, XK_F10},
- {103, XK_F11},
- {111, XK_F12},
- {105, XK_F13},
- {107, XK_F14},
- {113, XK_F15},
- {0, 0}
+static KeyInfo virtualkeyArray[] = {
+ {122, XK_F1},
+ {120, XK_F2},
+ {99, XK_F3},
+ {118, XK_F4},
+ {96, XK_F5},
+ {97, XK_F6},
+ {98, XK_F7},
+ {100, XK_F8},
+ {101, XK_F9},
+ {109, XK_F10},
+ {103, XK_F11},
+ {111, XK_F12},
+ {105, XK_F13},
+ {107, XK_F14},
+ {113, XK_F15},
+ {0, 0}
};
static int initialized = 0;
-static Tcl_HashTable keycodeTable; /* keyArray hashed by keycode value. */
-static Tcl_HashTable vkeyTable; /* vituralkeyArray hashed by virtual
- keycode value. */
+static Tcl_HashTable keycodeTable; /* keyArray hashed by keycode value. */
+static Tcl_HashTable vkeyTable; /* virtualkeyArray hashed by virtual
+ * keycode value. */
+
+static int latin1Table[LATIN1_MAX+1]; /* Reverse mapping table for
+ * controls, ASCII and Latin-1. */
/*
* Prototypes for static functions used in this file.
*/
-static void InitKeyMaps _ANSI_ARGS_((void));
+
+static void InitKeyMaps (void);
+static void InitLatin1Table(Display *display);
+static int XKeysymToMacKeycode(Display *display, KeySym keysym);
/*
@@ -92,13 +124,17 @@ static void InitKeyMaps _ANSI_ARGS_((void));
*
* InitKeyMaps --
*
- * Creates hash tables used by some of the functions in this file.
+ * Creates hash tables used by some of the functions in this file.
+ *
+ * FIXME: As keycodes are defined to be in the limited range 0-127, it
+ * would be easier and more efficient to use directly initialized plain
+ * arrays and drop this function.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Allocates memory & creates some hash tables.
+ * Allocates memory & creates some hash tables.
*
*----------------------------------------------------------------------
*/
@@ -109,18 +145,18 @@ InitKeyMaps()
Tcl_HashEntry *hPtr;
KeyInfo *kPtr;
int dummy;
-
+
Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
- hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
- &dummy);
- Tcl_SetHashValue(hPtr, kPtr->keysym);
+ hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
+ &dummy);
+ Tcl_SetHashValue(hPtr, kPtr->keysym);
}
Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
- for (kPtr = vituralkeyArray; kPtr->keycode != 0; kPtr++) {
- hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
- &dummy);
- Tcl_SetHashValue(hPtr, kPtr->keysym);
+ for (kPtr = virtualkeyArray; kPtr->keycode != 0; kPtr++) {
+ hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
+ &dummy);
+ Tcl_SetHashValue(hPtr, kPtr->keysym);
}
initialized = 1;
}
@@ -128,16 +164,92 @@ InitKeyMaps()
/*
*----------------------------------------------------------------------
*
+ * InitLatin1Table --
+ *
+ * Creates a simple table to be used for mapping from keysyms to
+ * keycodes. Always needs to be called before using latin1Table,
+ * because the keyboard layout may have changed, and than the table must
+ * be re-computed.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Sets the global latin1Table.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+InitLatin1Table(
+ Display *display)
+{
+ static Boolean latin1_initialized = false;
+ static SInt16 lastKeyLayoutID = -1;
+
+ SInt16 keyScript;
+ SInt16 keyLayoutID;
+
+ keyScript = GetScriptManagerVariable(smKeyScript);
+ keyLayoutID = GetScriptVariable(keyScript,smScriptKeys);
+
+ if (!latin1_initialized || (lastKeyLayoutID != keyLayoutID)) {
+ int keycode;
+ KeySym keysym;
+ int state;
+ int modifiers;
+
+ latin1_initialized = true;
+ lastKeyLayoutID = keyLayoutID;
+
+ memset(latin1Table, 0, sizeof(latin1Table));
+
+ /*
+ * In the common X11 implementations, a keymap has four columns
+ * "plain", "Shift", "Mode_switch" and "Mode_switch + Shift". We
+ * don't use "Mode_switch", but we use "Option" instead. (This is
+ * similar to Apple's X11 implementation, where "Mode_switch" is used
+ * as an alias for "Option".)
+ *
+ * So here we go through all 4 columns of the keymap and find all
+ * Latin-1 compatible keycodes. We go through the columns
+ * back-to-front from the more exotic columns to the more simple, so
+ * that simple keycode-modifier combinations are preferred in the
+ * resulting table.
+ */
+
+ for (state = 3; state >= 0; state--) {
+ modifiers = 0;
+ if (state & 1) {
+ modifiers |= shiftKey;
+ }
+ if (state & 2) {
+ modifiers |= optionKey;
+ }
+
+ for (keycode = 0; keycode <= MAC_KEYCODE_MAX; keycode++) {
+ keysym = XKeycodeToKeysym(display,keycode<<16,state);
+ if (keysym <= LATIN1_MAX) {
+ latin1Table[keysym] = keycode | modifiers;
+ }
+ }
+ }
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* XKeycodeToKeysym --
*
- * Translate from a system-dependent keycode to a
- * system-independent keysym.
+ * Translate from a system-dependent keycode to a system-independent
+ * keysym.
*
* Results:
- * Returns the translated keysym, or NoSymbol on failure.
+ * Returns the translated keysym, or NoSymbol on failure.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
@@ -146,68 +258,61 @@ KeySym
XKeycodeToKeysym(
Display* display,
KeyCode keycode,
- int index)
+ int index)
{
register Tcl_HashEntry *hPtr;
- int c;
- int virtualKey;
int newKeycode;
UniChar newChar;
+ (void) display; /*unused*/
+
if (!initialized) {
- InitKeyMaps();
- }
- if (keycode == 0) {
- /*
- * This means we had a pure modifier keypress or
- * something similar which is a TO DO.
- */
- return NoSymbol;
- }
-
- virtualKey = keycode >> 16;
- c = (keycode) & 0xffff;
- if (c > 255) {
- return NoSymbol;
+ InitKeyMaps();
}
/*
- * When determining what keysym to produce we first check to see if
- * the key is a function key. We then check to see if the character
- * is another non-printing key. Finally, we return the key syms
- * for all ASCII chars.
+ * When determining what keysym to produce we first check to see if the
+ * key is a function key. We then check to see if the character is
+ * another non-printing key. Finally, we return the key syms for all
+ * ASCII and Latin-1 chars.
*/
- if (c == 0x10) {
- hPtr = Tcl_FindHashEntry(&vkeyTable, (char *) virtualKey);
- if (hPtr != NULL) {
+
+ newKeycode = keycode >> 16;
+
+ if ((keycode & 0xFFFF) == 0x10) {
+ hPtr = Tcl_FindHashEntry(&vkeyTable, (char *) newKeycode);
+ if (hPtr != NULL) {
return (KeySym) Tcl_GetHashValue(hPtr);
- }
+ }
}
- hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
+ hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) newKeycode);
if (hPtr != NULL) {
- return (KeySym) Tcl_GetHashValue(hPtr);
+ return (KeySym) Tcl_GetHashValue(hPtr);
}
/*
- * Recompute the character based on the Shift key only.
- * TODO: The index may also specify the NUM_LOCK.
+ * Add in the Mac modifier flags for shift and option.
*/
- newKeycode = virtualKey;
- if (index & 0x01) {
- newKeycode += 0x0200;
+
+ if (index & 1) {
+ newKeycode |= shiftKey;
+ }
+ if (index & 2) {
+ newKeycode |= optionKey;
}
newChar = 0;
TkMacOSXKeycodeToUnicode(
- &newChar, 1, kEventRawKeyDown,
- newKeycode & 0x00FF, newKeycode & 0xFF00, NULL);
+ &newChar, 1, kEventRawKeyDown,
+ newKeycode & 0x00FF, newKeycode & 0xFF00, NULL);
/*
* X11 keysyms are identical to Unicode for ASCII and Latin-1. Give up
* for other characters for now.
*/
- if (newChar >= XK_space && newChar <= 0x255) {
- return newChar;
+
+ if ((newChar >= XK_space) && (newChar <= LATIN1_MAX)) {
+ return newChar;
}
return NoSymbol;
@@ -218,24 +323,24 @@ XKeycodeToKeysym(
*
* TkpGetString --
*
- * Retrieve the string equivalent for the given keyboard event.
+ * Retrieve the string equivalent for the given keyboard event.
*
* Results:
- * Returns the UTF string.
+ * Returns the UTF string.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
char *
TkpGetString(
- TkWindow *winPtr, /* Window where event occurred: needed to
- * get input context. */
- XEvent *eventPtr, /* X keyboard event. */
- Tcl_DString *dsPtr) /* Uninitialized or empty string to hold
- * result. */
+ TkWindow *winPtr, /* Window where event occurred: Needed to get
+ * input context. */
+ XEvent *eventPtr, /* X keyboard event. */
+ Tcl_DString *dsPtr) /* Uninitialized or empty string to hold
+ * result. */
{
(void) winPtr; /*unused*/
Tcl_DStringInit(dsPtr);
@@ -247,13 +352,13 @@ TkpGetString(
*
* XGetModifierMapping --
*
- * Fetch the current keycodes used as modifiers.
+ * Fetch the current keycodes used as modifiers.
*
* Results:
- * Returns a new modifier map.
+ * Returns a new modifier map.
*
* Side effects:
- * Allocates a new modifier map data structure.
+ * Allocates a new modifier map data structure.
*
*----------------------------------------------------------------------
*/
@@ -264,6 +369,13 @@ XGetModifierMapping(
{
XModifierKeymap * modmap;
+ (void) display; /*unused*/
+
+ /*
+ * MacOSX doesn't use the key codes for the modifiers for anything, and
+ * we don't generate them either. So there is no modifier map.
+ */
+
modmap = (XModifierKeymap *) ckalloc(sizeof(XModifierKeymap));
modmap->max_keypermod = 0;
modmap->modifiermap = NULL;
@@ -275,14 +387,13 @@ XGetModifierMapping(
*
* XFreeModifiermap --
*
- * Deallocate a modifier map that was created by
- * XGetModifierMapping.
+ * Deallocate a modifier map that was created by XGetModifierMapping.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Frees the datastructure referenced by modmap.
+ * Frees the datastructure referenced by modmap.
*
*----------------------------------------------------------------------
*/
@@ -292,7 +403,7 @@ XFreeModifiermap(
XModifierKeymap *modmap)
{
if (modmap->modifiermap != NULL) {
- ckfree((char *) modmap->modifiermap);
+ ckfree((char *) modmap->modifiermap);
}
ckfree((char *) modmap);
}
@@ -302,16 +413,16 @@ XFreeModifiermap(
*
* XKeysymToString, XStringToKeysym --
*
- * These X window functions map Keysyms to strings & strings to
- * keysyms. However, Tk already does this for the most common keysyms.
- * Therefor, these functions only need to support keysyms that will be
- * specific to the Macintosh. Currently, there are none.
+ * These X window functions map keysyms to strings & strings to keysyms.
+ * However, Tk already does this for the most common keysyms.
+ * Therefore, these functions only need to support keysyms that will be
+ * specific to the Macintosh. Currently, there are none.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
@@ -325,7 +436,7 @@ XKeysymToString(
KeySym
XStringToKeysym(
- const char* string)
+ const char* string)
{
return NoSymbol;
}
@@ -333,19 +444,83 @@ XStringToKeysym(
/*
*----------------------------------------------------------------------
*
+ * XKeysymToMacKeycode --
+ *
+ * An internal function like XKeysymToKeycode but only generating the
+ * Mac specific keycode plus the modifiers Shift and Option.
+ *
+ * Results:
+ * A Mac keycode with the actual keycode in the low byte and Mac-style
+ * modifier bits in the high byte.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+XKeysymToMacKeycode(
+ Display *display,
+ KeySym keysym)
+{
+ if (keysym <= LATIN1_MAX) {
+
+ /*
+ * Handle keysyms in the Latin-1 range where keysym and Unicode
+ * character code point are the same.
+ */
+
+ InitLatin1Table(display);
+ return latin1Table[keysym];
+
+ } else {
+
+ /*
+ * Handle special keys from our exception tables. Don't mind if this
+ * is slow, neither the test suite nor [event generate] need to be
+ * optimized (we hope).
+ */
+
+ KeyInfo *kPtr;
+
+ for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
+ if (kPtr->keysym == keysym) {
+ return kPtr->keycode;
+ }
+ }
+ for (kPtr = virtualkeyArray; kPtr->keycode != 0; kPtr++) {
+ if (kPtr->keysym == keysym) {
+ return kPtr->keycode;
+ }
+ }
+
+ /*
+ * For other keysyms (not Latin-1 and not special keys), we'd need a
+ * generic keysym-to-unicode table. We don't have that, so we give
+ * up here.
+ */
+
+ return 0;
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* XKeysymToKeycode --
*
- * The function XKeysymToKeycode is only used by tkTest.c and
- * currently only implementes the support for keys used in the
- * Tk test suite.
- * FIXME - This is no longer true. This function is now used in
- * "event generate" so we really should make it work.
+ * The function XKeysymToKeycode takes an X11 keysym and converts it
+ * into a Mac keycode. It is in the stubs table for compatibility but
+ * not used anywhere in the core.
*
* Results:
- * None.
+ * A 32 bit keycode with the the mac keycode (without modifiers) in the
+ * higher 16 bits of the keycode and the ASCII or Latin-1 code in the
+ * lower 8 bits of the keycode.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
@@ -355,9 +530,28 @@ XKeysymToKeycode(
Display* display,
KeySym keysym)
{
- KeyCode keycode = 0;
- char virtualKeyCode = 0;
+ int macKeycode = XKeysymToMacKeycode(display, keysym);
+ KeyCode result;
+ /*
+ * See also TkpSetKeycodeAndState. The 0x0010 magic is used in
+ * XKeycodeToKeysym. For special keys like XK_Return the lower 8 bits of
+ * the keysym are usually a related ASCII control code.
+ */
+
+ if ((keysym >= XK_F1) && (keysym <= XK_F35)) {
+ result = 0x0010;
+ } else {
+ result = 0x00FF & keysym;
+ }
+ result |= (macKeycode & MAC_KEYCODE_MASK) << 16;
+
+ return result;
+}
+
+/*
+NB: Keep this commented code for a moment for reference.
+
if ((keysym >= XK_space) && (XK_asciitilde)) {
if (keysym == 'a') {
virtualKeyCode = 0x00;
@@ -375,54 +569,72 @@ XKeysymToKeycode(
virtualKeyCode = 0x24;
keysym = '\r';
}
- keycode = keysym + (virtualKeyCode <<16);
+ keycode = keysym + (virtualKeyCode <<16);
}
return keycode;
-}
+*/
/*
- * When mapping from a keysym to a keycode, need
- * information about the modifier state that should be used
- * so that when they call XKeycodeToKeysym taking into
- * account the xkey.state, they will get back the original
- * keysym.
+ *----------------------------------------------------------------------
+ *
+ * TkpSetKeycodeAndState --
+ *
+ * The function TkpSetKeycodeAndState takes a keysym and fills in the
+ * appropriate members of an XEvent. It is similar to XKeysymToKeycode,
+ * but it also sets the modifier mask in the XEvent. It is used by
+ * [event generate] and it is in the stubs table.
+ *
+ * Results:
+ * Fills an XEvent, sets the member xkey.keycode with a keycode
+ * formatted the same as XKeysymToKeycode and the member xkey.state with
+ * the modifiers implied by the keysym. Also fills in xkey.trans_chars,
+ * so that the actual characters can be retrieved later.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
*/
void
-TkpSetKeycodeAndState(tkwin, keySym, eventPtr)
- Tk_Window tkwin;
- KeySym keySym;
- XEvent *eventPtr;
+TkpSetKeycodeAndState(
+ Tk_Window tkwin,
+ KeySym keysym,
+ XEvent *eventPtr)
{
- Display *display;
- int state;
- KeyCode keycode;
-
- display = Tk_Display(tkwin);
-
- if (keySym == NoSymbol) {
- keycode = 0;
+ if (keysym == NoSymbol) {
+ eventPtr->xkey.keycode = 0;
} else {
- keycode = XKeysymToKeycode(display, keySym);
- }
- if (keycode != 0) {
- for (state = 0; state < 4; state++) {
- if (XKeycodeToKeysym(display, keycode, state) == keySym) {
- if (state & 1) {
- eventPtr->xkey.state |= ShiftMask;
- }
- if (state & 2) {
- TkDisplay *dispPtr;
-
- dispPtr = ((TkWindow *) tkwin)->dispPtr;
- eventPtr->xkey.state |= dispPtr->modeModMask;
- }
- break;
- }
- }
+ Display *display = Tk_Display(tkwin);
+ int macKeycode = XKeysymToMacKeycode(display, keysym);
+
+ /*
+ * See also XKeysymToKeycode.
+ */
+
+ if ((keysym >= XK_F1) && (keysym <= XK_F35)) {
+ eventPtr->xkey.keycode = 0x0010;
+ } else {
+ eventPtr->xkey.keycode = 0x00FF & keysym;
+ }
+ eventPtr->xkey.keycode |= (macKeycode & MAC_KEYCODE_MASK) << 16;
+
+ if (shiftKey & macKeycode) {
+ eventPtr->xkey.state |= ShiftMask;
+ }
+ if (optionKey & macKeycode) {
+ eventPtr->xkey.state |= OPTION_MASK;
+ }
+
+ if (keysym <= LATIN1_MAX) {
+ int done;
+ done = Tcl_UniCharToUtf(keysym,eventPtr->xkey.trans_chars);
+ eventPtr->xkey.trans_chars[done] = 0;
+ } else {
+ eventPtr->xkey.trans_chars[0] = 0;
+ }
}
- eventPtr->xkey.keycode = keycode;
}
/*
@@ -430,105 +642,132 @@ TkpSetKeycodeAndState(tkwin, keySym, eventPtr)
*
* TkpGetKeySym --
*
- * Given an X KeyPress or KeyRelease event, map the
- * keycode in the event into a KeySym.
+ * Given an X KeyPress or KeyRelease event, map the keycode in the event
+ * into a keysym.
*
* Results:
- * The return value is the KeySym corresponding to
- * eventPtr, or NoSymbol if no matching Keysym could be
- * found.
+ * The return value is the keysym corresponding to eventPtr, or NoSymbol
+ * if no matching keysym could be found.
*
* Side effects:
- * In the first call for a given display, keycode-to-
- * KeySym maps get loaded.
+ * In the first call for a given display, keycode-to-keysym maps get
+ * loaded.
*
*----------------------------------------------------------------------
*/
KeySym
-TkpGetKeySym(dispPtr, eventPtr)
- TkDisplay *dispPtr; /* Display in which to
- * map keycode. */
- XEvent *eventPtr; /* Description of X event. */
+TkpGetKeySym(
+ TkDisplay *dispPtr, /* Display in which to map keycode. */
+ XEvent *eventPtr) /* Description of X event. */
{
KeySym sym;
int index;
/*
- * Refresh the mapping information if it's stale
+ * Refresh the mapping information if it's stale.
*/
if (dispPtr->bindInfoStale) {
- TkpInitKeymapInfo(dispPtr);
+ TkpInitKeymapInfo(dispPtr);
}
/*
- * Figure out which of the four slots in the keymap vector to
- * use for this key. Refer to Xlib documentation for more info
- * on how this computation works.
+ * Handle pure modifier keys specially. We use -1 as a signal for
+ * this.
+ */
+
+ if (eventPtr->xany.send_event == -1) {
+ int modifier = eventPtr->xkey.keycode;
+ if (modifier == cmdKey) {
+ return XK_Alt_L;
+ } else if (modifier == shiftKey) {
+ return XK_Shift_L;
+ } else if (modifier == alphaLock) {
+ return XK_Caps_Lock;
+ } else if (modifier == optionKey) {
+ return XK_Meta_L;
+ } else if (modifier == controlKey) {
+ return XK_Control_L;
+ } else if (modifier == rightShiftKey) {
+ return XK_Shift_R;
+ } else if (modifier == rightOptionKey) {
+ return XK_Meta_R;
+ } else if (modifier == rightControlKey) {
+ return XK_Control_R;
+ } else {
+
+ /*
+ * If we get here, we probably need to implement something new.
+ */
+
+ return NoSymbol;
+ }
+ }
+
+ /*
+ * Figure out which of the four slots in the keymap vector to use for
+ * this key. Refer to Xlib documentation for more info on how this
+ * computation works. (Note: We use "Option" in keymap columns 2 and 3
+ * where other implementations have "Mode_switch".)
*/
index = 0;
- if (eventPtr->xkey.state & dispPtr->modeModMask) {
- index = 2;
+
+ /*
+ * We want Option key combinations to use their base chars as keysyms, so
+ * we ignore the option modifier here.
+ */
+
+#if 0
+ if (eventPtr->xkey.state & OPTION_MASK) {
+ index |= 2;
}
+#endif
+
if ((eventPtr->xkey.state & ShiftMask)
- || ((dispPtr->lockUsage != LU_IGNORE)
- && (eventPtr->xkey.state & LockMask))) {
- index += 1;
- }
- if (eventPtr->xany.send_event == -1) {
- /* We use -1 as a special signal for a pure modifier */
- int modifier = eventPtr->xkey.keycode;
- if (modifier == cmdKey) {
- return XK_Alt_L;
- } else if (modifier == shiftKey) {
- return XK_Shift_L;
- } else if (modifier == alphaLock) {
- return XK_Caps_Lock;
- } else if (modifier == optionKey) {
- return XK_Meta_L;
- } else if (modifier == controlKey) {
- return XK_Control_L;
- } else if (modifier == rightShiftKey) {
- return XK_Shift_R;
- } else if (modifier == rightOptionKey) {
- return XK_Meta_R;
- } else if (modifier == rightControlKey) {
- return XK_Control_R;
- } else {
- /* If we get here, we probably need to implement something new */
- return NoSymbol;
- }
+ || (/* (dispPtr->lockUsage != LU_IGNORE)
+ && */ (eventPtr->xkey.state & LockMask))) {
+ index |= 1;
}
+
+ /*
+ * First try of the actual translation.
+ */
+
sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, index);
/*
- * Special handling: if the key was shifted because of Lock, but
- * lock is only caps lock, not shift lock, and the shifted keysym
- * isn't upper-case alphabetic, then switch back to the unshifted
- * keysym.
+ * Special handling: If the key was shifted because of Lock, but lock is
+ * only caps lock, not shift lock, and the shifted keysym isn't
+ * upper-case alphabetic, then switch back to the unshifted keysym.
*/
if ((index & 1) && !(eventPtr->xkey.state & ShiftMask)
- && (dispPtr->lockUsage == LU_CAPS)) {
- if (!(((sym >= XK_A) && (sym <= XK_Z))
- || ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
- || ((sym >= XK_Ooblique) && (sym <= XK_Thorn)))) {
- index &= ~1;
- sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
- index);
- }
+ /*&& (dispPtr->lockUsage == LU_CAPS)*/ ) {
+
+ /*
+ * FIXME: Keysyms are only identical to Unicode for ASCII and
+ * Latin-1, so we can't use Tcl_UniCharIsUpper() for keysyms outside
+ * that range. This may be a serious problem here.
+ */
+
+ if ((sym == NoSymbol) || (sym > LATIN1_MAX)
+ || !Tcl_UniCharIsUpper(sym)) {
+ index &= ~1;
+ sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
+ index);
+ }
}
/*
- * Another bit of special handling: if this is a shifted key and there
- * is no keysym defined, then use the keysym for the unshifted key.
+ * Another bit of special handling: If this is a shifted key and there is
+ * no keysym defined, then use the keysym for the unshifted key.
*/
if ((index & 1) && (sym == NoSymbol)) {
- sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
- index & ~1);
+ sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
+ index & ~1);
}
return sym;
}
@@ -538,127 +777,48 @@ TkpGetKeySym(dispPtr, eventPtr)
*
* TkpInitKeymapInfo --
*
- * This procedure is invoked to scan keymap information
- * to recompute stuff that's important for binding, such
- * as the modifier key (if any) that corresponds to "mode
- * switch".
+ * This procedure is invoked to scan keymap information to recompute
+ * stuff that's important for binding, such as the modifier key (if any)
+ * that corresponds to the "Mode_switch" keysym.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Keymap-related information in dispPtr is updated.
+ * Keymap-related information in dispPtr is updated.
*
*--------------------------------------------------------------
*/
void
-TkpInitKeymapInfo(dispPtr)
- TkDisplay *dispPtr; /* Display for which to recompute keymap
- * information. */
+TkpInitKeymapInfo(
+ TkDisplay *dispPtr) /* Display for which to recompute keymap
+ * information. */
{
- XModifierKeymap *modMapPtr;
- KeyCode *codePtr;
- KeySym keysym;
- int count, i, j, max, arraySize;
-#define KEYCODE_ARRAY_SIZE 20
-
dispPtr->bindInfoStale = 0;
- modMapPtr = XGetModifierMapping(dispPtr->display);
-
- /*
- * Check the keycodes associated with the Lock modifier. If
- * any of them is associated with the XK_Shift_Lock modifier,
- * then Lock has to be interpreted as Shift Lock, not Caps Lock.
- */
-
- dispPtr->lockUsage = LU_IGNORE;
- codePtr = modMapPtr->modifiermap + modMapPtr->max_keypermod*LockMapIndex;
- for (count = modMapPtr->max_keypermod; count > 0; count--, codePtr++) {
- if (*codePtr == 0) {
- continue;
- }
- keysym = XKeycodeToKeysym(dispPtr->display, *codePtr, 0);
- if (keysym == XK_Shift_Lock) {
- dispPtr->lockUsage = LU_SHIFT;
- break;
- }
- if (keysym == XK_Caps_Lock) {
- dispPtr->lockUsage = LU_CAPS;
- break;
- }
- }
/*
- * Look through the keycodes associated with modifiers to see if
- * the the "mode switch", "meta", or "alt" keysyms are associated
- * with any modifiers. If so, remember their modifier mask bits.
+ * Behaviours that are variable on X11 are defined constant on MacOSX.
+ * lockUsage is only used above in TkpGetKeySym(), nowhere else
+ * currently. There is no offical "Mode_switch" key.
*/
+ dispPtr->lockUsage = LU_CAPS;
dispPtr->modeModMask = 0;
- dispPtr->metaModMask = 0;
- dispPtr->altModMask = 0;
- codePtr = modMapPtr->modifiermap;
- max = 8*modMapPtr->max_keypermod;
- for (i = 0; i < max; i++, codePtr++) {
- if (*codePtr == 0) {
- continue;
- }
- keysym = XKeycodeToKeysym(dispPtr->display, *codePtr, 0);
- if (keysym == XK_Mode_switch) {
- dispPtr->modeModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
- }
- if ((keysym == XK_Meta_L) || (keysym == XK_Meta_R)) {
- dispPtr->metaModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
- }
- if ((keysym == XK_Alt_L) || (keysym == XK_Alt_R)) {
- dispPtr->altModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
- }
- }
+ dispPtr->altModMask = ALT_MASK;
+ dispPtr->metaModMask = OPTION_MASK;
/*
- * Create an array of the keycodes for all modifier keys.
+ * MacOSX doesn't use the keycodes for the modifiers for anything, and we
+ * don't generate them either (the keycodes actually given in the
+ * simulated modifier events are bogus). So there is no modifier map.
+ * If we ever want to simulate real modifier keycodes, the list will be
+ * constant in the Carbon implementation.
*/
if (dispPtr->modKeyCodes != NULL) {
- ckfree((char *) dispPtr->modKeyCodes);
+ ckfree((char *) dispPtr->modKeyCodes);
}
dispPtr->numModKeyCodes = 0;
- arraySize = KEYCODE_ARRAY_SIZE;
- dispPtr->modKeyCodes = (KeyCode *) ckalloc((unsigned)
- (KEYCODE_ARRAY_SIZE * sizeof(KeyCode)));
- for (i = 0, codePtr = modMapPtr->modifiermap; i < max; i++, codePtr++) {
- if (*codePtr == 0) {
- continue;
- }
-
- /*
- * Make sure that the keycode isn't already in the array.
- */
-
- for (j = 0; j < dispPtr->numModKeyCodes; j++) {
- if (dispPtr->modKeyCodes[j] == *codePtr) {
- goto nextModCode;
- }
- }
- if (dispPtr->numModKeyCodes >= arraySize) {
- KeyCode *new;
-
- /*
- * Ran out of space in the array; grow it.
- */
-
- arraySize *= 2;
- new = (KeyCode *) ckalloc((unsigned)
- (arraySize * sizeof(KeyCode)));
- memcpy((VOID *) new, (VOID *) dispPtr->modKeyCodes,
- (dispPtr->numModKeyCodes * sizeof(KeyCode)));
- ckfree((char *) dispPtr->modKeyCodes);
- dispPtr->modKeyCodes = new;
- }
- dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr;
- dispPtr->numModKeyCodes++;
- nextModCode: continue;
- }
- XFreeModifiermap(modMapPtr);
+ dispPtr->modKeyCodes = NULL;
}
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index eec9c77..5ae94a7 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.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: tkMacOSXMenu.c,v 1.6.2.3 2004/02/14 01:08:28 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.6.2.4 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkMacOSXInt.h"
#include "tkMenuButton.h"
@@ -262,7 +262,7 @@ 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 EventuallyInvokeMenu (ClientData data);
static void GetEntryText _ANSI_ARGS_((TkMenuEntry *mePtr,
Tcl_DString *dStringPtr));
static void GetMenuAccelGeometry _ANSI_ARGS_((TkMenu *menuPtr,
@@ -1039,7 +1039,7 @@ ReconfigureIndividualMenu(
int base) /* The last index that we do not want
* touched. 0 for normal menus;
* # of system help menu items
- * for help menus. */
+ * for help menus. */
{
int count;
int index;
@@ -1954,7 +1954,7 @@ TkpSetMainMenubar(
WindowRef macWindowPtr;
WindowRef frontNonFloating;
- winPort=TkMacOSXGetDrawablePort(winPtr->window);
+ winPort = TkMacOSXGetDrawablePort(winPtr->window);
if (!winPort) {
return;
}
@@ -2076,7 +2076,7 @@ TkpSetWindowMenuBar(
listPtr->menuPtr = menuPtr;
}
}
-
+
static void
/*
*----------------------------------------------------------------------
@@ -2105,7 +2105,7 @@ EventuallyInvokeMenu (ClientData data)
TkInvokeMenu(realData->menuPtr->interp, realData->menuPtr,
realData->index);
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -2141,10 +2141,10 @@ TkMacOSXDispatchMenuEvent(
helpMenuName);
ckfree(helpMenuName);
if ((helpMenuRef != NULL) && (helpMenuRef->menuPtr != NULL)) {
- MenuRef outHelpMenu;
- MenuItemIndex itemIndex;
- int newIndex;
- HMGetHelpMenu(&outHelpMenu, &itemIndex);
+ MenuRef outHelpMenu;
+ MenuItemIndex itemIndex;
+ int newIndex;
+ HMGetHelpMenu(&outHelpMenu, &itemIndex);
newIndex = index - itemIndex;
result = TkInvokeMenu(currentMenuBarInterp,
helpMenuRef->menuPtr, newIndex);
@@ -2182,7 +2182,7 @@ TkMacOSXDispatchMenuEvent(
}
return result;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -3429,6 +3429,8 @@ DrawMenuEntryLabel(
GDHandle saveDevice;
GWorldPtr destPort;
#ifdef USE_ATSU
+ int xLocation;
+ int yLocation;
int runLengths;
CFStringRef stringRef;
ATSUTextLayout textLayout;
@@ -3455,7 +3457,8 @@ DrawMenuEntryLabel(
tag = kATSUSizeTag;
valueSize = sizeof(fixedSize);
valuePtr = &fixedSize;
- if ((err=ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr))!= noErr) {
+ err = ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr);
+ if (err != noErr) {
fprintf(stderr,"ATSUSetAttributes failed,%d\n", err );
}
@@ -3464,7 +3467,8 @@ DrawMenuEntryLabel(
tag = kATSUFontTag;
valueSize = sizeof(fontID);
valuePtr = &fontID;
- if ((err=ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr))!= noErr) {
+ err = ATSUSetAttributes(style, 1, &tag, &valueSize, &valuePtr);
+ if (err != noErr) {
fprintf(stderr,"ATSUSetAttributes failed,%d\n", err );
}
@@ -3474,12 +3478,15 @@ DrawMenuEntryLabel(
#ifdef USE_ATSU
runLengths = 1;
length = Tcl_DStringLength(&itemTextDString);
- stringRef = CFStringCreateWithCString(NULL, Tcl_DStringValue(&itemTextDString), GetApplicationTextEncoding());
+ stringRef = CFStringCreateWithCString(NULL, Tcl_DStringValue(&itemTextDString),
+ kCFStringEncodingUTF8);
if (!stringRef) {
fprintf(stderr,"CFStringCreateWithCString failed\n");
}
- if ((err=ATSUCreateTextLayoutWithTextPtr(CFStringGetCharactersPtr(stringRef), 0, length, length,
- 1, &runLengths, &style, &textLayout)) != noErr) {
+ err = ATSUCreateTextLayoutWithTextPtr(CFStringGetCharactersPtr(stringRef),
+ 0, length, length,
+ 1, &runLengths, &style, &textLayout)
+ if (err != noErr) {
fprintf(stderr,"ATSUCreateTextLayoutWithTextPtr failed, %d\n", err);
return;
}
@@ -3496,11 +3503,11 @@ DrawMenuEntryLabel(
TkMacOSXSetUpGraphicsPort(gc, destPort);
MoveTo((short) leftEdge, (short) baseline);
- Tcl_UtfToExternalDString(NULL, Tcl_DStringValue(&itemTextDString),
+ Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, Tcl_DStringValue(&itemTextDString),
Tcl_DStringLength(&itemTextDString), &convertedTextDString);
#ifdef USE_ATSU
- xLocation = leftEdge<<16;
- yLocation = baseline<<16;
+ xLocation = leftEdge << 16;
+ yLocation = baseline << 16;
ATSUDrawText(textLayout,kATSUFromTextBeginning, kATSUToTextEnd, xLocation, yLocation);
ATSUDisposeTextLayout(textLayout);
CFRelease(stringRef);
diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c
index 52b239c..64a14a1 100644
--- a/macosx/tkMacOSXMenubutton.c
+++ b/macosx/tkMacOSXMenubutton.c
@@ -10,7 +10,7 @@
* 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.2 2002/08/31 06:12:30 das Exp $
+ * RCS: @(#) $Id: tkMacOSXMenubutton.c,v 1.2.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <Carbon/Carbon.h>
@@ -187,18 +187,18 @@ TkpDisplayMenuButton(
SetGWorld(dstPort, NULL);
TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
- winPtr=(TkWindow *)butPtr->tkwin;
- paneRect.left=winPtr->privatePtr->xOff;
- paneRect.top=winPtr->privatePtr->yOff;
- paneRect.right=paneRect.left+Tk_Width(butPtr->tkwin)-1;
- paneRect.bottom=paneRect.top+Tk_Height(butPtr->tkwin)-1;
+ winPtr = (TkWindow *)butPtr->tkwin;
+ paneRect.left = winPtr->privatePtr->xOff;
+ 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 = paneRect;
- cntrRect.left+=butPtr->inset;
- cntrRect.top+=butPtr->inset;
- cntrRect.right-=butPtr->inset;
- cntrRect.bottom-=butPtr->inset;
+ cntrRect.left += butPtr->inset;
+ cntrRect.top += butPtr->inset;
+ cntrRect.right -= butPtr->inset;
+ cntrRect.bottom -= butPtr->inset;
if (mbPtr->userPane) {
MenuButtonControlParams params;
@@ -246,7 +246,8 @@ TkpDisplayMenuButton(
}
if ((titleChanged||styleChanged) && titleParams .len) {
if (hasImageOrBitmap) {
- if ((err=SetControlFontStyle(mbPtr->control,&titleParams.style))!=noErr) {
+ err = SetControlFontStyle(mbPtr->control,&titleParams.style);
+ if (err !=noErr) {
fprintf(stderr,"SetControlFontStyle failed %d\n", err);
return;
}
@@ -284,10 +285,11 @@ TkpDisplayMenuButton(
ClosePicture();
tkPictureIsOpen = 0;
- if ( (err=SetControlData(mbPtr->control, kControlButtonPart,
+ err = SetControlData(mbPtr->control, kControlButtonPart,
kControlBevelButtonContentTag,
sizeof(ControlButtonContentInfo),
- (char *) &mbPtr->bevelButtonContent)) != noErr ) {
+ (char *) &mbPtr->bevelButtonContent);
+ if (err != noErr) {
fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err );
}
switch (butPtr->anchor) {
@@ -320,10 +322,11 @@ TkpDisplayMenuButton(
break;
}
- if ((err=SetControlData(mbPtr->control, kControlButtonPart,
+ err = SetControlData(mbPtr->control, kControlButtonPart,
kControlBevelButtonGraphicAlignTag,
sizeof(ControlButtonGraphicAlignment),
- (char *) &theAlignment)) != noErr ) {
+ (char *) &theAlignment);
+ if (err != noErr ) {
fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err );
}
}
@@ -449,7 +452,7 @@ TkpComputeMenuButtonGeometry(mbPtr)
if (mbPtr->indicatorOn) {
mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
- mbPtr->indicatorHeight= kTriangleHeight;
+ mbPtr->indicatorHeight = kTriangleHeight;
mbPtr->indicatorWidth = kTriangleWidth + kTriangleMargin;
width += mbPtr->indicatorWidth;
} else {
@@ -604,31 +607,32 @@ MenuButtonInitControl (
int length;
Str255 itemText;
- rootControl=TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin));
- mbPtr->windowRef=GetWindowFromPort(TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
+ rootControl = TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin));
+ mbPtr->windowRef = GetWindowFromPort(TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin)));
/*
* Set up the user pane
*/
initiallyVisible = false;
initialValue = kControlSupportsEmbedding|
- kControlHasSpecialBackground;
+ 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) {
fprintf(stderr,"Failed to create user pane control\n");
return 1;
}
- if ((status=EmbedControl(mbPtr->userPane,rootControl))!=noErr) {
+ status = EmbedControl(mbPtr->userPane,rootControl);
+ if (status != noErr) {
fprintf(stderr,"Failed to embed user pane control %d\n", status);
return 1;
}
@@ -651,7 +655,8 @@ MenuButtonInitControl (
fprintf(stderr,"failed to create control of type %d : line %d\n",mbPtr->params.procID, __LINE__);
return 1;
}
- if ((err=EmbedControl(mbPtr->control,mbPtr->userPane)) != noErr ) {
+ err = EmbedControl(mbPtr->control,mbPtr->userPane);
+ if (err != noErr ) {
fprintf(stderr,"failed to embed control of type %d,%d\n",procID, err);
return 1;
}
@@ -662,35 +667,36 @@ MenuButtonInitControl (
SetControlTitleWithCFString(mbPtr->control, cf);
CFRelease(cf);
if (mbPtr->titleParams.len) {
- if ((err=SetControlFontStyle(mbPtr->control,&mbPtr->titleParams.style))!=noErr) {
+ err = SetControlFontStyle(mbPtr->control,&mbPtr->titleParams.style);
+ if (err !=noErr) {
fprintf(stderr,"SetControlFontStyle failed %d\n", err);
return 1;
}
}
} else {
- CFStringRef cf;
+ CFStringRef cf;
err = TkMacOSXGetNewMenuID(mbPtr->info.interp, (TkMenu *)mbPtr, 0, &menuID);
if (err != TCL_OK) {
return err;
}
length = strlen(Tk_PathName(mbPtr->info.tkwin));
memmove(&itemText[1], Tk_PathName(mbPtr->info.tkwin),
- (length > 230) ? 230 : length);
+ (length > 230) ? 230 : length);
itemText[0] = (length > 230) ? 230 : length;
if (!(mbPtr->menuRef = NewMenu(menuID,itemText))) {
return 1;
}
- cf = CFStringCreateWithCString(NULL,
- mbPtr->titleParams.title, kCFStringEncodingUTF8);
+ cf = CFStringCreateWithCString(NULL,
+ mbPtr->titleParams.title, kCFStringEncodingUTF8);
AppendMenuItemText(mbPtr->menuRef, "\px");
if (cf != NULL) {
SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf);
CFRelease(cf);
}
err = SetControlData(mbPtr->control,
- kControlNoPart,
- kControlPopupButtonMenuRefTag,
- sizeof(mbPtr->menuRef), &mbPtr->menuRef);
+ kControlNoPart,
+ kControlPopupButtonMenuRefTag,
+ sizeof(mbPtr->menuRef), &mbPtr->menuRef);
SetControlMinimum(mbPtr->control, 1);
SetControlMaximum(mbPtr->control, 1);
SetControlValue(mbPtr->control, 1);
@@ -723,9 +729,9 @@ OSErr SetUserPaneDrawProc (
ControlUserPaneDrawUPP myControlUserPaneDrawUPP;
myControlUserPaneDrawUPP = NewControlUserPaneDrawUPP(upp);
return SetControlData (control,
- kControlNoPart, kControlUserPaneDrawProcTag,
- sizeof(myControlUserPaneDrawUPP),
- (Ptr) &myControlUserPaneDrawUPP);
+ kControlNoPart, kControlUserPaneDrawProcTag,
+ sizeof(myControlUserPaneDrawUPP),
+ (Ptr) &myControlUserPaneDrawUPP);
}
/*
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index 2516ef8..150519c 100644
--- a/macosx/tkMacOSXMouseEvent.c
+++ b/macosx/tkMacOSXMouseEvent.c
@@ -156,12 +156,13 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
medPtr->state |= Mod2Mask; /* option key */
}
if (eventPtr->eKind == kEventMouseDown
- || eventPtr->eKind== kEventMouseDragged ) {
+ || eventPtr->eKind == kEventMouseDragged ) {
EventMouseButton mouseButton;
- if ((status=GetEventParameter(eventPtr->eventRef,
- kEventParamMouseButton,
- typeMouseButton, NULL,
- sizeof(mouseButton), NULL,&mouseButton)) != noErr ) {
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamMouseButton,
+ typeMouseButton, NULL,
+ sizeof(mouseButton), NULL,&mouseButton);
+ if (status != noErr ) {
fprintf (stderr, "Failed to retrieve mouse button, %d\n", status);
statusPtr->err = 1;
return 0;
@@ -169,7 +170,7 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
medPtr->state |= 1 << ((mouseButton-1)+8);
}
- medPtr->windowPart= FindWindow(where, &medPtr->whichWin);
+ medPtr->windowPart = FindWindow(where, &medPtr->whichWin);
window = TkMacOSXGetXWindow(medPtr->whichWin);
if (medPtr->whichWin != NULL && window == None) {
return 0;
@@ -193,10 +194,11 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
window, medPtr->state);
}
if (eventPtr->eKind == kEventMouseWheelMoved) {
- if ((status=GetEventParameter(eventPtr->eventRef,
- kEventParamMouseWheelDelta,
- typeLongInteger, NULL,
- sizeof(medPtr->delta), NULL,&medPtr->delta)) != noErr ) {
+ status = GetEventParameter(eventPtr->eventRef,
+ kEventParamMouseWheelDelta,
+ typeLongInteger, NULL,
+ sizeof(medPtr->delta), NULL,&medPtr->delta);
+ if (status != noErr ) {
fprintf (stderr,
"Failed to retrieve mouse wheel delta, %d\n", status);
statusPtr->err = 1;
@@ -233,23 +235,26 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
}
}
- if (medPtr->whichWin && eventPtr->eKind==kEventMouseDown) {
+ if (medPtr->whichWin && eventPtr->eKind == kEventMouseDown) {
ProcessSerialNumber frontPsn, ourPsn;
Boolean flag;
- if ((err=GetFrontProcess(&frontPsn))!=noErr) {
+ err = GetFrontProcess(&frontPsn);
+ if (err != noErr) {
fprintf(stderr, "GetFrontProcess failed, %d\n", err);
statusPtr->err = 1;
return 1;
}
GetCurrentProcess(&ourPsn);
- if ((err=SameProcess(&frontPsn, &ourPsn, &flag))!=noErr) {
+ err = SameProcess(&frontPsn, &ourPsn, &flag);
+ if (err != noErr) {
fprintf(stderr, "SameProcess failed, %d\n", err);
statusPtr->err = 1;
return 1;
} else {
if (!flag) {
- if ((err=SetFrontProcess(&ourPsn)) != noErr) {
+ err = SetFrontProcess(&ourPsn);
+ if (err != noErr) {
fprintf(stderr,"SetFrontProcess failed,%d\n", err);
statusPtr->err = 1;
return 1;
@@ -271,11 +276,25 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
if (!(TkpIsWindowFloating(medPtr->whichWin))
&& (medPtr->whichWin != medPtr->activeNonFloating)) {
Tk_Window grabWin = TkMacOSXGetCapture();
+ if ((grabWin == NULL)) {
+ int grabState = TkGrabState((TkWindow*)tkwin);
+ if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
+ /* Now we want to set the focus to the local grabWin */
+ TkMacOSXSetEatButtonUp(true);
+ grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
+ BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
+ statusPtr->stopProcessing = 1;
+ return false;
+ }
+ }
if ((grabWin != NULL) && (grabWin != tkwin)) {
TkWindow * tkw, * grb;
tkw = (TkWindow *)tkwin;
grb = (TkWindow *)grabWin;
- SysBeep(1);
+ /* Now we want to set the focus to the global grabWin */
+ TkMacOSXSetEatButtonUp(true);
+ BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
+ statusPtr->stopProcessing = 1;
return false;
}
@@ -470,7 +489,7 @@ HandleInCollapse(WindowRef win)
static int
GeneratePollingEvents(MouseEventData * medPtr)
{
- Tk_Window tkwin, rootwin, grabWin, topPtr;
+ Tk_Window tkwin, rootwin, grabWin;
Window window;
int local_x, local_y;
TkDisplay *dispPtr;
diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c
index 0d0764f..4a87b64 100644
--- a/macosx/tkMacOSXNotify.c
+++ b/macosx/tkMacOSXNotify.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXNotify.c,v 1.5 2002/09/26 17:07:33 das Exp $
+ * RCS: @(#) $Id: tkMacOSXNotify.c,v 1.5.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tclInt.h"
@@ -1155,11 +1155,11 @@ TkMacOSXCreateFakeEvent ()
EventTime eTime;
EventRef eventRef;
EventAttributes flags;
- eClass=kEventClassWish;
+ eClass = kEventClassWish;
eKind = 0xffff;
- eTime =GetLastUserEventTime() + 0.001;
- flags=kEventAttributeUserEvent;
- if (CreateEvent(NULL,eClass,eKind,eTime,flags,&eventRef)!=noErr) {
+ eTime = GetLastUserEventTime() + 0.001;
+ flags = kEventAttributeUserEvent;
+ if (CreateEvent(NULL,eClass,eKind,eTime,flags,&eventRef) != noErr) {
fprintf(stderr,"CreateEvent failed\n");
return NULL;
}
diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h
index 8f9d2be..dcb8359 100644
--- a/macosx/tkMacOSXPort.h
+++ b/macosx/tkMacOSXPort.h
@@ -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: tkMacOSXPort.h,v 1.3 2002/09/26 17:07:33 das Exp $
+ * RCS: @(#) $Id: tkMacOSXPort.h,v 1.3.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#ifndef _TKMACPORT
@@ -159,9 +159,10 @@ extern int strncasecmp _ANSI_ARGS_((CONST char *s1,
#define XNoOp(display) {display->request++;}
#define XUngrabServer(display)
#define XSynchronize(display, bool) {display->request++;}
-#define XSync(display, bool) {display->request++;}
#define XVisualIDFromVisual(visual) (visual->visualid)
+int XSync(Display *display, Bool discard);
+
/*
* The following functions are not used on the Mac, so we stub them out.
*/
diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c
index 3c00610..9022387 100644
--- a/macosx/tkMacOSXScale.c
+++ b/macosx/tkMacOSXScale.c
@@ -10,7 +10,7 @@
* 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.2 2002/08/31 06:12:30 das Exp $
+ * RCS: @(#) $Id: tkMacOSXScale.c,v 1.2.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkScale.h"
@@ -152,7 +152,7 @@ TkpDisplayScale(clientData)
SInt16 maxValue;
SInt16 procID;
SInt32 controlReference;
- Boolean initiallyVisible=true;
+ Boolean initiallyVisible = true;
fprintf(stderr,"TkpDisplayScale\n");
scalePtr->flags &= ~REDRAW_PENDING;
@@ -206,8 +206,8 @@ TkpDisplayScale(clientData)
* Set up port for drawing Macintosh control.
*/
macDraw = (MacDrawable *) Tk_WindowId(tkwin);
- destPort=TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
- windowRef=GetWindowFromPort(destPort);
+ destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
+ windowRef = GetWindowFromPort(destPort);
GetGWorld(&saveWorld, &saveDevice);
SetGWorld(destPort, NULL);
TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
@@ -217,16 +217,16 @@ TkpDisplayScale(clientData)
*/
if (macScalePtr->scaleHandle == NULL) {
fprintf(stderr,"Initialising scale\n");
- r.left=macDraw->xOff;
- r.top=macDraw->yOff;
- r.right=macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
- r.bottom=macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
-
- initialValue=scalePtr->value;
- minValue=scalePtr->toValue;
- maxValue=scalePtr->fromValue;
- procID=kControlSliderProc;
- controlReference=(SInt32) macScalePtr;
+ r.left = macDraw->xOff;
+ r.top = macDraw->yOff;
+ r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
+ r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
+
+ initialValue = scalePtr->value;
+ minValue = scalePtr->toValue;
+ maxValue = scalePtr->fromValue;
+ procID = kControlSliderProc;
+ controlReference = (SInt32) macScalePtr;
macScalePtr->scaleHandle = NewControl(windowRef,
&r, "\p", initiallyVisible, initialValue,minValue,maxValue,
procID, controlReference);
@@ -234,7 +234,7 @@ TkpDisplayScale(clientData)
/*
* If we are foremost than make us active.
*/
- if (windowRef==FrontWindow()) {
+ if (windowRef == FrontWindow()) {
macScalePtr->flags |= ACTIVE;
}
}
diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c
index f7e40e5..778b447 100644
--- a/macosx/tkMacOSXScrlbr.c
+++ b/macosx/tkMacOSXScrlbr.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: tkMacOSXScrlbr.c,v 1.5.2.1 2003/12/17 18:08:29 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXScrlbr.c,v 1.5.2.2 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkScrollbar.h"
@@ -637,7 +637,7 @@ ThumbActionProc()
NULL,
&trackingResult);
- if ((err==noErr)
+ if ((err == noErr)
&& ((trackingResult == kMouseTrackingMouseDragged)
|| (trackingResult == kMouseTrackingMouseMoved))) {
/*
@@ -681,7 +681,7 @@ ThumbActionProc()
Tcl_GlobalEval(interp, cmdString.string);
Tcl_Release((ClientData) interp);
}
- } while ((err==noErr) && trackingResult!=kMouseTrackingMouseReleased );
+ } while ((err == noErr) && trackingResult != kMouseTrackingMouseReleased);
Tcl_DStringFree(&cmdString);
return;
diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c
index 380725f..1d881cf 100644
--- a/macosx/tkMacOSXSubwindows.c
+++ b/macosx/tkMacOSXSubwindows.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: tkMacOSXSubwindows.c,v 1.2 2002/08/31 06:12:30 das Exp $
+ * RCS: @(#) $Id: tkMacOSXSubwindows.c,v 1.2.2.1 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include "tkInt.h"
@@ -898,8 +898,8 @@ TkMacOSXInvalidateWindow(
WindowRef windowRef;
CGrafPtr grafPtr;
- grafPtr=TkMacOSXGetDrawablePort((Drawable)macWin);
- windowRef=GetWindowFromPort(grafPtr);
+ grafPtr = TkMacOSXGetDrawablePort((Drawable)macWin);
+ windowRef = GetWindowFromPort(grafPtr);
if (flag == TK_WINDOW_ONLY) {
InvalWindowRgn(windowRef,macWin->clipRgn);
diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c
index af3619b..f718d08 100644
--- a/macosx/tkMacOSXWindowEvent.c
+++ b/macosx/tkMacOSXWindowEvent.c
@@ -235,7 +235,7 @@ GenerateUpdateEvent(Window window)
GetRegionBounds(visRgn,&bounds);
bounds.right -= bounds.left;
bounds.bottom -= bounds.top;
- bounds.left=
+ bounds.left = 0;
bounds.top=0;
RectRgn(visRgn, &bounds);
GenerateUpdates(visRgn, winPtr);
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index 6973213..4a5203b 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -12,7 +12,7 @@
* 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.7.2.2 2004/02/14 01:08:29 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXWm.c,v 1.7.2.3 2004/02/16 00:42:34 wolfsuit Exp $
*/
#include <Carbon/Carbon.h>
@@ -5029,7 +5029,7 @@ TkMacOSXUnregisterMacWindow(
if (!windowHashInit) {
panic("TkMacOSXUnregisterMacWindow: unmapping before inited");
}
- entryPtr=Tcl_FindHashEntry(&windowTable,(char *) macWinPtr);
+ entryPtr = Tcl_FindHashEntry(&windowTable,(char *) macWinPtr);
if (!entryPtr) {
fprintf(stderr,"Unregister:failed to find window %08x\n",
(int) macWinPtr );
@@ -5253,15 +5253,15 @@ TkMacOSXWindowOffset(
if (!strucRgn) {
if(!(strucRgn = NewRgn())) {
- err=MemError();
+ err = MemError();
}
}
if (!contRgn) {
if(!(contRgn = NewRgn())) {
- err=MemError();
+ err = MemError();
}
}
- if (err==noErr) {
+ if (err == noErr) {
GetWindowRegion(wRef, kWindowStructureRgn, strucRgn);
GetWindowRegion(wRef, kWindowContentRgn, contRgn);
GetRegionBounds(strucRgn,&strucRect);