diff options
-rw-r--r-- | macosx/tkMacOSXBitmap.c | 8 | ||||
-rw-r--r-- | macosx/tkMacOSXCursor.c | 158 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 812 | ||||
-rw-r--r-- | macosx/tkMacOSXEmbed.c | 497 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 125 | ||||
-rw-r--r-- | macosx/tkMacOSXSend.c | 391 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 1636 | ||||
-rw-r--r-- | macosx/tkMacOSXXStubs.c | 271 |
8 files changed, 1934 insertions, 1964 deletions
diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c index 7b66a38..d25b74d 100644 --- a/macosx/tkMacOSXBitmap.c +++ b/macosx/tkMacOSXBitmap.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: tkMacOSXBitmap.c,v 1.7 2007/04/23 21:24:32 das Exp $ + * RCS: @(#) $Id: tkMacOSXBitmap.c,v 1.7.4.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXInt.h" @@ -249,9 +249,9 @@ TkpGetNativeAppBitmap( 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. + * 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); diff --git a/macosx/tkMacOSXCursor.c b/macosx/tkMacOSXCursor.c index 64b967c..d8863db 100644 --- a/macosx/tkMacOSXCursor.c +++ b/macosx/tkMacOSXCursor.c @@ -7,18 +7,18 @@ * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2006-2007 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: tkMacOSXCursor.c,v 1.13 2007/12/13 15:27:08 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXCursor.c,v 1.13.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXPrivate.h" /* - * There are three different ways to set the cursor on the Mac. - * The default theme cursors (listed in cursorNames below), - * color resource cursors, & normal cursors. + * There are three different ways to set the cursor on the Mac. The default + * theme cursors (listed in cursorNames below), color resource cursors, & + * normal cursors. */ #define NONE -1 /* Hidden cursor */ @@ -28,17 +28,17 @@ #define NORMAL 3 /* Cursors of type CURS. */ /* - * The following data structure contains the system specific data - * necessary to control Windows cursors. + * The following data structure contains the system specific data necessary to + * control Windows cursors. */ typedef struct { TkCursor info; /* Generic cursor info used by tkCursor.c */ - Handle macCursor; /* Resource containing Macintosh cursor. - * For theme cursors, this is -1. */ - int type; /* Type of Mac cursor: for theme cursors - * this is the theme cursor constant, - * otherwise one of crsr or CURS */ + Handle macCursor; /* Resource containing Macintosh cursor. For + * theme cursors, this is -1. */ + int type; /* Type of Mac cursor: for theme cursors this + * is the theme cursor constant, otherwise one + * of crsr or CURS. */ int count; /* For animating cursors, the count for the * cursor. */ } TkMacOSXCursor; @@ -94,25 +94,23 @@ static struct CursorName animatedThemeCursorNames[] = { * Declarations of static variables used in this file. */ -static TkMacOSXCursor * gCurrentCursor = NULL; /* A pointer to the current - * cursor. */ -static int gResizeOverride = false; /* A boolean indicating whether - * we should use the resize - * cursor during installations. */ -static int gTkOwnsCursor = true; /* A boolean indicating whether - * Tk owns the cursor. If not (for - * instance, in the case where a Tk - * window is embedded in another app's - * window, and the cursor is out of - * the tk window, we will not attempt - * to adjust the cursor */ +static TkMacOSXCursor * gCurrentCursor = NULL; + /* A pointer to the current cursor. */ +static int gResizeOverride = false; + /* A boolean indicating whether we should use + * the resize cursor during installations. */ +static int gTkOwnsCursor = true;/* A boolean indicating whether Tk owns the + * cursor. If not (for instance, in the case + * where a Tk window is embedded in another + * app's window, and the cursor is out of the + * tk window, we will not attempt to adjust + * the cursor. */ /* * Declarations of procedures local to this file */ static void FindCursorByName(TkMacOSXCursor *macCursorPtr, const char *string); - /* *---------------------------------------------------------------------- @@ -120,10 +118,9 @@ static void FindCursorByName(TkMacOSXCursor *macCursorPtr, const char *string); * FindCursorByName -- * * Retrieve a system cursor by name, and fill the macCursorPtr - * structure. If the cursor cannot be found, the macCursor field - * will be NULL. The function first attempts to load a color - * cursor. If that fails it will attempt to load a black & white - * cursor. + * structure. If the cursor cannot be found, the macCursor field will be + * NULL. The function first attempts to load a color cursor. If that + * fails it will attempt to load a black & white cursor. * * Results: * Fills the macCursorPtr record. @@ -205,9 +202,9 @@ TkGetCursorByName( macCursorPtr->info.cursor = (Tk_Cursor) macCursorPtr; /* - * To find a cursor we must first determine if it is one of the - * builtin cursors or the standard arrow cursor. Otherwise, we - * attempt to load the cursor as a named Mac resource. + * To find a cursor we must first determine if it is one of the builtin + * cursors or the standard arrow cursor. Otherwise, we attempt to load the + * cursor as a named Mac resource. */ if (strcmp(noneCursorName.name, string) == 0) { @@ -225,11 +222,14 @@ TkGetCursorByName( if (namePtr->name == NULL) { for (namePtr = animatedThemeCursorNames; namePtr->name != NULL; namePtr++) { - int namelen = strlen (namePtr->name); + int namelen = strlen(namePtr->name); + if (strncmp(namePtr->name, string, namelen) == 0) { const char *numPtr = string + namelen; + if (*numPtr) { int result = Tcl_GetInt(NULL, numPtr, &count); + if (result != TCL_OK) { continue; } @@ -251,9 +251,9 @@ TkGetCursorByName( int argc; /* - * The user may be trying to specify an XCursor with fore - * & back colors. We don't want this to be an error, so pick - * off the first word, and try again. + * The user may be trying to specify an XCursor with fore & back + * colors. We don't want this to be an error, so pick off the + * first word, and try again. */ if (Tcl_SplitList(interp, string, &argc, &argv) == TCL_OK ) { @@ -269,9 +269,8 @@ TkGetCursorByName( ckfree((char *)macCursorPtr); Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"", NULL); return NULL; - } else { - return (TkCursor *) macCursorPtr; } + return (TkCursor *) macCursorPtr; } /* @@ -327,12 +326,12 @@ TkpFreeCursor( TkMacOSXCursor *macCursorPtr = (TkMacOSXCursor *) cursorPtr; switch (macCursorPtr->type) { - case COLOR: - DisposeCCursor((CCrsrHandle) macCursorPtr->macCursor); - break; - case NORMAL: - ReleaseResource(macCursorPtr->macCursor); - break; + case COLOR: + DisposeCCursor((CCrsrHandle) macCursorPtr->macCursor); + break; + case NORMAL: + ReleaseResource(macCursorPtr->macCursor); + break; } if (macCursorPtr == gCurrentCursor) { @@ -345,9 +344,8 @@ TkpFreeCursor( * * TkMacOSXInstallCursor -- * - * Installs either the current cursor as defined by TkpSetCursor - * or a resize cursor as the cursor the Macintosh should currently - * display. + * Installs either the current cursor as defined by TkpSetCursor or a + * resize cursor as the cursor the Macintosh should currently display. * * Results: * None. @@ -382,35 +380,35 @@ TkMacOSXInstallCursor( SetThemeCursor(kThemeArrowCursor); } else { struct CursorName *namePtr; + switch (macCursorPtr->type) { - case NONE: - if (!cursorHidden) { - cursorHidden = 1; - HideCursor(); - } - cursorNone = 1; - break; - case THEME: - namePtr = (struct CursorName *) macCursorPtr->macCursor; - SetThemeCursor( - namePtr->id); - break; - case ANIMATED: - namePtr = (struct CursorName *) macCursorPtr->macCursor; - if (macCursorPtr->count == -1) { - SetAnimatedThemeCursor(namePtr->id, cursorStep++); - } else { - SetAnimatedThemeCursor(namePtr->id, macCursorPtr->count); - } - break; - case COLOR: - ccursor = (CCrsrHandle) macCursorPtr->macCursor; - SetCCursor(ccursor); - break; - case NORMAL: - cursor = (CursHandle) macCursorPtr->macCursor; - SetCursor(*cursor); - break; + case NONE: + if (!cursorHidden) { + cursorHidden = 1; + HideCursor(); + } + cursorNone = 1; + break; + case THEME: + namePtr = (struct CursorName *) macCursorPtr->macCursor; + SetThemeCursor(namePtr->id); + break; + case ANIMATED: + namePtr = (struct CursorName *) macCursorPtr->macCursor; + if (macCursorPtr->count == -1) { + SetAnimatedThemeCursor(namePtr->id, cursorStep++); + } else { + SetAnimatedThemeCursor(namePtr->id, macCursorPtr->count); + } + break; + case COLOR: + ccursor = (CCrsrHandle) macCursorPtr->macCursor; + SetCCursor(ccursor); + break; + case NORMAL: + cursor = (CursHandle) macCursorPtr->macCursor; + SetCursor(*cursor); + break; } } if (cursorHidden && !cursorNone) { @@ -448,10 +446,10 @@ TkpSetCursor( if (cursor == None) { /* * This is a little tricky. We can't really tell whether - * gCurrentCursor is NULL because it was NULL last time around - * or because we just freed the current cursor. So if the input - * cursor is NULL, we always need to reset it, we can't trust the - * cursorChanged logic. + * gCurrentCursor is NULL because it was NULL last time around or + * because we just freed the current cursor. So if the input cursor is + * NULL, we always need to reset it, we can't trust the cursorChanged + * logic. */ gCurrentCursor = NULL; diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 24c74e3..f7daf7d 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.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: tkMacOSXDialog.c,v 1.36 2007/12/13 15:27:08 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.36.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -104,16 +104,14 @@ 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. @@ -133,7 +131,7 @@ Tk_ChooseColorObjCmd( { OSStatus err; int result = TCL_ERROR; - Tk_Window parent, tkwin = (Tk_Window) clientData; + Tk_Window parent, tkwin = clientData; const char *title; int i, srcRead, dstWrote; CMError cmerr; @@ -204,7 +202,7 @@ Tk_ChooseColorObjCmd( cpinfo.placeWhere = kCenterOnMainScreen; /* Currently, this does not actually change the colorpicker title */ Tcl_UtfToExternal(NULL, TkMacOSXCarbonEncoding, title, -1, 0, NULL, - StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL); + StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL); StrLength(cpinfo.prompt) = (unsigned char) dstWrote; TkMacOSXTrackingLoop(1); @@ -225,7 +223,7 @@ Tk_ChooseColorObjCmd( } result = TCL_OK; -end: + end: return result; } @@ -234,9 +232,8 @@ end: * * 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. @@ -301,51 +298,54 @@ Tk_GetOpenFileObjCmd( } switch (index) { - case OPEN_DEFAULT: - break; - case OPEN_FILETYPES: - types = objv[i + 1]; - if (TkGetFileFilters(interp, &ofd.fl, types, 0) != TCL_OK) { - 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_GetString(objv[i + 1]); - /* 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) { - goto end; - } - break; - case OPEN_PARENT: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, - (Tk_Window) clientData); - if (parent == NULL) { - 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_TYPEVARIABLE: - typeVariablePtr = objv[i + 1]; - break; + case OPEN_DEFAULT: + break; + case OPEN_FILETYPES: + types = objv[i + 1]; + if (TkGetFileFilters(interp, &ofd.fl, types, 0) != TCL_OK) { + 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_GetString(objv[i + 1]); + /* 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) { + goto end; + } + break; + case OPEN_PARENT: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + parent = Tk_NameToWindow(interp, choice, clientData); + if (parent == NULL) { + 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_TYPEVARIABLE: + typeVariablePtr = objv[i + 1]; + break; } } @@ -372,7 +372,7 @@ Tk_GetOpenFileObjCmd( Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), filterPtr->name, 0); } -end: + end: TkFreeFileFilters(&ofd.fl); if (initialDesc.dataHandle) { ChkErr(AEDisposeDesc, &initialDesc); @@ -394,8 +394,7 @@ end: * * Tk_GetSaveFileObjCmd -- * - * Same as Tk_GetOpenFileCmd but opens a "save file" dialog box - * instead + * Same as Tk_GetOpenFileCmd but opens a "save file" dialog box instead. * * Results: * A standard Tcl result. @@ -453,47 +452,46 @@ Tk_GetSaveFileObjCmd( goto end; } switch (index) { - case SAVE_DEFAULT: - break; - case SAVE_FILETYPES: - types = objv[i + 1]; - if (TkGetFileFilters(interp, &ofd.fl, types, 0) != TCL_OK) { - goto end; - } - 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) { - 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, - (Tk_Window) clientData); - if (parent == NULL) { - 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: + types = objv[i + 1]; + if (TkGetFileFilters(interp, &ofd.fl, types, 0) != TCL_OK) { + goto end; + } + 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) { + 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, (Tk_Window) clientData); + if (parent == NULL) { + goto end; + } + break; + case SAVE_TITLE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + title = CFStringCreateWithBytes(NULL, (unsigned char *) choice, + choiceLen, kCFStringEncodingUTF8, false); + break; } } @@ -503,7 +501,7 @@ Tk_GetSaveFileObjCmd( result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL, title, message, NULL, false, SAVE_FILE, parent); TkFreeFileFilters(&ofd.fl); -end: + end: if (initialDesc.dataHandle) { ChkErr(AEDisposeDesc, &initialDesc); } @@ -521,9 +519,9 @@ end: * * 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 + * MacOS X platform. See the user documentation for details on what it + * does. * * Results: * See user documentation. @@ -535,11 +533,11 @@ end: */ int -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. */ +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. */ { int i, result = TCL_ERROR; Tk_Window parent = NULL; @@ -560,9 +558,8 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) } for (i = 1; i < objc; i += 2) { - char *choice; + char *string, *choice; int index, choiceLen; - char *string; if (Tcl_GetIndexFromObj(interp, objv[i], chooseOptionStrings, "option", TCL_EXACT, &index) != TCL_OK) { @@ -575,31 +572,30 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) goto end; } switch (index) { - case CHOOSE_INITDIR: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - if (choiceLen && HandleInitialDirectory(interp, NULL, choice, - &dirRef, NULL, &initialDesc) != TCL_OK) { - goto end; - } - break; - case CHOOSE_MESSAGE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) - choice, choiceLen, kCFStringEncodingUTF8, false); - break; - case CHOOSE_PARENT: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, - (Tk_Window) clientData); - if (parent == NULL) { - goto end; - } - break; - case CHOOSE_TITLE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, - choiceLen, kCFStringEncodingUTF8, false); - break; + case CHOOSE_INITDIR: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + if (choiceLen && HandleInitialDirectory(interp, NULL, choice, + &dirRef, NULL, &initialDesc) != TCL_OK) { + goto end; + } + break; + case CHOOSE_MESSAGE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + message = CFStringCreateWithBytes(NULL, (unsigned char *) choice, + choiceLen, kCFStringEncodingUTF8, false); + break; + case CHOOSE_PARENT: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + parent = Tk_NameToWindow(interp, choice, clientData); + if (parent == NULL) { + goto end; + } + break; + case CHOOSE_TITLE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + title = CFStringCreateWithBytes(NULL, (unsigned char *) choice, + choiceLen, kCFStringEncodingUTF8, false); + break; } } @@ -611,7 +607,7 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, title, message, NULL, false, CHOOSE_FOLDER, parent); TkFreeFileFilters(&ofd.fl); -end: + end: if (initialDesc.dataHandle) { ChkErr(AEDisposeDesc, &initialDesc); } @@ -660,16 +656,16 @@ HandleInitialDirectory( if (dirName == NULL) { goto end; } - err = ChkErr(FSPathMakeRef, (unsigned char*) dirName, - dirRef, &isDirectory); + err = ChkErr(FSPathMakeRef, (unsigned char *) dirName, dirRef, + &isDirectory); if (err != noErr) { Tcl_AppendResult(interp, "bad directory \"", initialDir, "\"", NULL); goto end; } if (!isDirectory) { - Tcl_AppendResult(interp, "-intialdir \"", - initialDir, " is a file, not a directory.\"", NULL); + Tcl_AppendResult(interp, "-intialdir \"", initialDir, "\"" + " is a file, not a directory.", NULL); goto end; } ChkErr(AECreateDesc, typeFSRef, dirRef, sizeof(*dirRef), dirDescPtr); @@ -690,7 +686,7 @@ HandleInitialDirectory( ChkErr(AECreateList, NULL, 0, false, selectDescPtr); - err = ChkErr(FSPathMakeRef, (unsigned char*) namePtr, &fileRef, + err = ChkErr(FSPathMakeRef, (unsigned char *) namePtr, &fileRef, &isDirectory); if (err != noErr) { Tcl_AppendResult(interp, "bad initialfile \"", initialFile, @@ -702,7 +698,7 @@ HandleInitialDirectory( ChkErr(AEDisposeDesc, &fileDesc); } result = TCL_OK; -end: + end: if (dirName) { Tcl_DStringFree(&ds); } @@ -766,7 +762,7 @@ NavServicesGetFile( NavHandlerUserData data; NavDialogCreationOptions options; NavDialogRef dialogRef = NULL; - CFStringRef * menuItemNames = NULL; + CFStringRef *menuItemNames = NULL; OSStatus err; Tcl_Obj *theResult = NULL; int result = TCL_ERROR; @@ -782,7 +778,7 @@ NavServicesGetFile( options.optionFlags |= kNavAllowMultipleFiles; } options.modality = kWindowModalityAppModal; - if (parent && ((TkWindow*)parent)->window != None && + if (parent && ((TkWindow *) parent)->window != None && TkMacOSXHostToplevelExists(parent)) { options.parentWindow = TkMacOSXDrawableWindow(Tk_WindowId(parent)); TK_IF_HI_TOOLBOX (5, @@ -802,10 +798,10 @@ NavServicesGetFile( * Now process the selection list. We have to use the popupExtension * to fill the menu. */ + if (ofdPtr && ofdPtr->usePopup) { - FileFilter *filterPtr; + FileFilter *filterPtr = ofdPtr->fl.filters; - filterPtr = ofdPtr->fl.filters; if (filterPtr == NULL) { ofdPtr->usePopup = 0; } @@ -815,8 +811,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++) { @@ -836,8 +832,8 @@ NavServicesGetFile( options.message = message; options.windowTitle = title; if (initialFile) { - options.saveFileName = CFStringCreateWithCString(NULL, - initialFile, kCFStringEncodingUTF8); + options.saveFileName = CFStringCreateWithCString(NULL, initialFile, + kCFStringEncodingUTF8); } else { options.saveFileName = NULL; } @@ -878,9 +874,10 @@ NavServicesGetFile( } /* - * Most commands assume that the file dialogs return a single - * item, not a list. So only build a list if multiple is true... + * 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 (multiple) { theResult = Tcl_NewListObj(0, NULL); @@ -893,67 +890,89 @@ NavServicesGetFile( } if (err == noErr && data.reply.validRecord) { AEDesc resultDesc; - long count; + long count, i; FSRef fsRef; char pathPtr[PATH_MAX + 1]; + char saveName[PATH_MAX + 1]; err = ChkErr(AECountItems, &data.reply.selection, &count); - if (err == noErr) { - long i; + if (err != noErr) { + /* + * There was an error when counting the items? Treat as if no + * items were chosen. + */ - for (i = 1; i <= count; i++) { - err = ChkErr(AEGetNthDesc, &data.reply.selection, i, - typeFSRef, NULL, &resultDesc); - if (err == noErr) { - err = ChkErr(AEGetDescData, &resultDesc, &fsRef, - sizeof(fsRef)); - if (err == noErr) { - err = ChkErr(FSRefMakePath, &fsRef, (unsigned char*) - pathPtr, PATH_MAX + 1); - if (err == noErr) { - int pathValid = 0; - - if (isOpen == SAVE_FILE) { - if (data.saveNameRef) { - char saveName [PATH_MAX + 1]; - - if (CFStringGetCString(data.saveNameRef, - saveName, PATH_MAX + 1, - kCFStringEncodingUTF8)) { - if (strlen(pathPtr) + strlen(saveName) - < PATH_MAX) { - strcat(pathPtr, "/"); - strcat(pathPtr, saveName); - pathValid = 1; - } else { - TkMacOSXDbgMsg("Path name too " - "long"); - } - } else { - TkMacOSXDbgMsg("CFStringGetCString " - "failed"); - } - } else { - TkMacOSXDbgMsg("NavDialogGetSaveFileName " - "failed"); - } - } else { - pathValid = 1; - } - if (pathValid) { - if (multiple) { - Tcl_ListObjAppendElement(interp, theResult, - Tcl_NewStringObj(pathPtr, -1)); - } else { - Tcl_SetStringObj(theResult, pathPtr, -1); - } - } - } - } - ChkErr(AEDisposeDesc, &resultDesc); + goto installResult; + } + + /* + * Process the chosen files. This will be one unless -multiple was + * specified. + */ + + for (i = 1; i <= count; i++) { + /* + * Get the name of the selected file. + */ + + err = ChkErr(AEGetNthDesc, &data.reply.selection, i, + typeFSRef, NULL, &resultDesc); + if (err != noErr) { + continue; + } + err = ChkErr(AEGetDescData, &resultDesc, &fsRef, sizeof(fsRef)); + if (err != noErr) { + goto nextFilename; + } + err = ChkErr(FSRefMakePath, &fsRef, (unsigned char *) pathPtr, + PATH_MAX + 1); + if (err != noErr) { + goto nextFilename; + } + + /* + * If we're saving the file, we're creating a new filename and + * must therefore check whether it is a legal filename (not + * exceeding path length limits, etc.) + */ + + if (isOpen == SAVE_FILE) { + if (!data.saveNameRef) { + TkMacOSXDbgMsg("NavDialogGetSaveFileName failed"); + goto nextFilename; + } + + if (!CFStringGetCString(data.saveNameRef, saveName, + PATH_MAX + 1, kCFStringEncodingUTF8)) { + TkMacOSXDbgMsg("CFStringGetCString failed"); + goto nextFilename; } + + if (strlen(pathPtr) + strlen(saveName) >= PATH_MAX) { + TkMacOSXDbgMsg("Path name too long"); + goto nextFilename; + } + + strcat(pathPtr, "/"); + strcat(pathPtr, saveName); } + + /* + * Got a valid file name; put it in the result object. + */ + + if (multiple) { + Tcl_ListObjAppendElement(interp, theResult, + Tcl_NewStringObj(pathPtr, -1)); + } else { + Tcl_SetStringObj(theResult, pathPtr, -1); + } + + nextFilename: + ChkErr(AEDisposeDesc, &resultDesc); } + + installResult: Tcl_SetObjResult(interp, theResult); result = TCL_OK; } else if (err == userCanceledErr) { @@ -979,10 +998,11 @@ NavServicesGetFile( } if (menuItemNames) { int i; + for (i = 0; i < ofdPtr->fl.numFilters; i++) { CFRelease(menuItemNames[i]); } - ckfree((void *)menuItemNames); + ckfree((void *) menuItemNames); } if (options.popupExtension) { CFRelease(options.popupExtension); @@ -1032,7 +1052,7 @@ OpenEventProc( selectItem.menuCreator = 0; selectItem.menuType = ofd->initialType; selectItem.menuItemName[0] = strlen(filterPtr->name); - strncpy((char*) &selectItem.menuItemName[1], + strncpy((char *) &selectItem.menuItemName[1], filterPtr->name, 255); ChkErr(NavCustomControl, callBackParams->context, kNavCtlSelectCustomType, &selectItem); @@ -1093,85 +1113,80 @@ OpenEventProc( pascal Boolean OpenFileFilterProc( - AEDesc* theItem, void* info, + AEDesc *theItem, + void *info, NavCallBackUserData callBackUD, NavFilterModes filterMode) { - OpenFileData *ofdPtr = ((NavHandlerUserData*) callBackUD)->ofdPtr; + OpenFileData *ofdPtr = ((NavHandlerUserData *) callBackUD)->ofdPtr; int result = MATCHED; - if (ofdPtr && ofdPtr->usePopup) { - if (ofdPtr->fl.numFilters > 0) { - if ((theItem->descriptorType == typeFSS) - || (theItem->descriptorType == typeFSRef)) { - NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info; - char fileName[256]; - - if (!theInfo->isFolder) { - OSType fileType; - StringPtr fileNamePtr = NULL; - 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 = ChkErr(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); - } - } - 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; - } - } + if (ofdPtr && ofdPtr->usePopup && ofdPtr->fl.numFilters > 0 && + ((theItem->descriptorType == typeFSS) + || (theItem->descriptorType == typeFSRef))) { + NavFileOrFolderInfo *theInfo = info; + char fileName[256]; + OSType fileType; + StringPtr fileNamePtr = NULL; + Tcl_DString fileNameDString; + int i; + FileFilter *filterPtr; + + if (!theInfo->isFolder) { + 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 = ChkErr(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); + } + } + 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); } } + Tcl_DStringFree(&fileNameDString); } } return (result == MATCHED); @@ -1206,20 +1221,20 @@ MatchOneType( 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; @@ -1261,10 +1276,7 @@ MatchOneType( if (Tcl_StringMatch((char*) fileNamePtr, ext)) { goto glob_matched; - } else { - goto glob_unmatched; } - glob_unmatched: continue; @@ -1281,13 +1293,12 @@ 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))) { @@ -1303,8 +1314,8 @@ MatchOneType( * * 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. @@ -1360,7 +1371,7 @@ Tk_MessageBoxObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *CONST objv[]) /* Argument objects. */ { - Tk_Window tkwin = (Tk_Window) clientData; + Tk_Window tkwin = clientData; AlertStdCFStringAlertParamRec paramCFStringRec; AlertType alertType; DialogRef dialogRef; @@ -1459,107 +1470,103 @@ Tk_MessageBoxObjCmd( } 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_DEFAULT: + /* + * Need to postpone processing of this option until we are sure to + * know the '-type' as well. + */ - case ALERT_DETAIL: - str = Tcl_GetString(objv[i + 1]); - finemessageTextCF = CFStringCreateWithCString(NULL, str, - kCFStringEncodingUTF8); - break; + haveDefaultOption = true; + indexDefaultOption = i; + break; - case ALERT_ICON: - if (Tcl_GetIndexFromObj(interp, objv[i + 1], - movableIconStrings, "value", TCL_EXACT, &iconIndex) - != TCL_OK) { - 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_DETAIL: + str = Tcl_GetString(objv[i + 1]); + finemessageTextCF = CFStringCreateWithCString(NULL, str, + kCFStringEncodingUTF8); + break; - case ALERT_MESSAGE: - str = Tcl_GetString(objv[i + 1]); - messageTextCF = CFStringCreateWithCString(NULL, str, - kCFStringEncodingUTF8); + case ALERT_ICON: + if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableIconStrings, + "value", TCL_EXACT, &iconIndex) != TCL_OK) { + goto end; + } + switch (iconIndex) { + case ICON_ERROR: + alertType = kAlertStopAlert; break; - - case ALERT_PARENT: - str = Tcl_GetString(objv[i + 1]); - tkwin = Tk_NameToWindow(interp, str, tkwin); - if (tkwin == NULL) { - goto end; - } - if (((TkWindow*)tkwin)->window != None && - TkMacOSXHostToplevelExists(tkwin)) { - haveParentOption = true; - } + case ICON_INFO: + alertType = kAlertNoteAlert; break; - - case ALERT_TITLE: + case ICON_QUESTION: + alertType = kAlertCautionAlert; + break; + case ICON_WARNING: + alertType = kAlertCautionAlert; break; + } + break; - case ALERT_TYPE: - if (Tcl_GetIndexFromObj(interp, objv[i + 1],\ - movableTypeStrings, "value", TCL_EXACT, &typeIndex) - != TCL_OK) { - goto end; - } - switch (typeIndex) { - case TYPE_ABORTRETRYIGNORE: - paramCFStringRec.defaultText = CFSTR("Abort"); - paramCFStringRec.cancelText = CFSTR("Retry"); - paramCFStringRec.otherText = CFSTR("Ignore"); - paramCFStringRec.cancelButton = - kAlertStdAlertOtherButton; - 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"); - paramCFStringRec.cancelButton = - kAlertStdAlertOtherButton; - break; - } + case ALERT_MESSAGE: + str = Tcl_GetString(objv[i + 1]); + messageTextCF = CFStringCreateWithCString(NULL, str, + kCFStringEncodingUTF8); + break; + + case ALERT_PARENT: + str = Tcl_GetString(objv[i + 1]); + tkwin = Tk_NameToWindow(interp, str, tkwin); + if (tkwin == NULL) { + goto end; + } + if (((TkWindow *) tkwin)->window != None && + TkMacOSXHostToplevelExists(tkwin)) { + haveParentOption = true; + } + break; + + case ALERT_TITLE: + break; + + case ALERT_TYPE: + if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableTypeStrings, + "value", TCL_EXACT, &typeIndex) != TCL_OK) { + goto end; + } + switch (typeIndex) { + case TYPE_ABORTRETRYIGNORE: + paramCFStringRec.defaultText = CFSTR("Abort"); + paramCFStringRec.cancelText = CFSTR("Retry"); + paramCFStringRec.otherText = CFSTR("Ignore"); + paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; + 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"); + paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; + break; + } + break; } } if (haveDefaultOption) { - /* * Any '-default' option needs to know the '-type' option, which is why * we do this here. @@ -1642,19 +1649,18 @@ Tk_MessageBoxObjCmd( } } if (err == noErr) { - int ind; - /* * Map 'itemHit' (1, 2, 3) to descriptive text string. */ - ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit]; + int ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit]; + Tcl_SetObjResult(interp, Tcl_NewStringObj(movableButtonStrings[ind], -1)); result = TCL_OK; } -end: + end: if (finemessageTextCF) { CFRelease(finemessageTextCF); } @@ -1686,21 +1692,21 @@ AlertHandler( EventRef eventRef, void *userData) { - AlertHandlerUserData *data = (AlertHandlerUserData *) userData; + AlertHandlerUserData *data = userData; HICommand cmd; ChkErr(GetEventParameter,eventRef, kEventParamDirectObject, typeHICommand, NULL, sizeof(cmd), NULL, &cmd); switch (cmd.commandID) { - case kHICommandOK: - data->buttonIndex = 1; - break; - case kHICommandCancel: - data->buttonIndex = 2; - break; - case kHICommandOther: - data->buttonIndex = 3; - break; + case kHICommandOK: + data->buttonIndex = 1; + break; + case kHICommandCancel: + data->buttonIndex = 2; + break; + case kHICommandOther: + data->buttonIndex = 3; + break; } if (data->buttonIndex) { ChkErr(QuitAppModalLoopForWindow, data->dialogWindow); diff --git a/macosx/tkMacOSXEmbed.c b/macosx/tkMacOSXEmbed.c index a971c0d..eab7f29 100644 --- a/macosx/tkMacOSXEmbed.c +++ b/macosx/tkMacOSXEmbed.c @@ -3,52 +3,49 @@ * * This file contains platform-specific procedures for theMac to provide * basic operations needed for application embedding (where one - * application can use as its main window an internal window from - * some other application). - * Currently only Toplevel embedding within the same Tk application is - * allowed on the Macintosh. + * application can use as its main window an internal window from some + * other application). Currently only Toplevel embedding within the same + * Tk application is allowed on the Macintosh. * * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2006-2007 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: tkMacOSXEmbed.c,v 1.16 2007/12/13 15:27:09 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXEmbed.c,v 1.16.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXInt.h" /* * One of the following structures exists for each container in this - * application. It keeps track of the container window and its - * associated embedded window. + * application. It keeps track of the container window and its associated + * embedded window. */ typedef struct Container { - Window parent; /* The Mac Drawable for the parent of - * the pair (the container). */ - TkWindow *parentPtr; /* Tk's information about the container, - * or NULL if the container isn't + Window parent; /* The Mac Drawable for the parent of the pair + * (the container). */ + TkWindow *parentPtr; /* Tk's information about the container, or + * NULL if the container isn't in this + * process. */ + Window embedded; /* The MacDrawable for the embedded window. + * Starts off as None, but gets filled in when + * the window is eventually created. */ + TkWindow *embeddedPtr; /* Tk's information about the embedded window, + * or NULL if the embedded application isn't * in this process. */ - Window embedded; /* The MacDrawable for the embedded - * window. Starts off as None, but - * gets filled in when the window is - * eventually created. */ - TkWindow *embeddedPtr; /* Tk's information about the embedded - * window, or NULL if the - * embedded application isn't in - * this process. */ - struct Container *nextPtr; /* Next in list of all containers in - * this process. */ + struct Container *nextPtr; /* Next in list of all containers in this + * process. */ } Container; static Container *firstContainerPtr = NULL; - /* First in list of all containers - * managed by this process. */ + /* First in list of all containers managed by + * this process. */ /* - * Globals defined in this file + * Globals defined in this file: */ TkMacOSXEmbedHandler *tkMacOSXEmbedHandler = NULL; @@ -57,25 +54,24 @@ TkMacOSXEmbedHandler *tkMacOSXEmbedHandler = NULL; * Prototypes for static procedures defined in this file: */ -static void ContainerEventProc(ClientData clientData, XEvent *eventPtr); -static void EmbeddedEventProc(ClientData clientData, XEvent *eventPtr); -static void EmbedActivateProc(ClientData clientData, XEvent *eventPtr); -static void EmbedFocusProc(ClientData clientData, XEvent *eventPtr); -static void EmbedGeometryRequest(Container * containerPtr, int width, - int height); -static void EmbedSendConfigure(Container *containerPtr); -static void EmbedStructureProc(ClientData clientData, XEvent *eventPtr); -static void EmbedWindowDeleted(TkWindow *winPtr); - +static void ContainerEventProc(ClientData clientData, XEvent *eventPtr); +static void EmbeddedEventProc(ClientData clientData, XEvent *eventPtr); +static void EmbedActivateProc(ClientData clientData, XEvent *eventPtr); +static void EmbedFocusProc(ClientData clientData, XEvent *eventPtr); +static void EmbedGeometryRequest(Container *containerPtr, int width, + int height); +static void EmbedSendConfigure(Container *containerPtr); +static void EmbedStructureProc(ClientData clientData, XEvent *eventPtr); +static void EmbedWindowDeleted(TkWindow *winPtr); /* *---------------------------------------------------------------------- * * Tk_MacOSXSetEmbedHandler -- * - * Registers a handler for an in process form of embedding, like - * Netscape plugins, where Tk is loaded into the process, but does - * not control the main window + * Registers a handler for an in process form of embedding, like Netscape + * plugins, where Tk is loaded into the process, but does not control the + * main window * * Results: * None @@ -95,7 +91,8 @@ Tk_MacOSXSetEmbedHandler( Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc) { if (tkMacOSXEmbedHandler == NULL) { - tkMacOSXEmbedHandler = (TkMacOSXEmbedHandler *) ckalloc(sizeof(TkMacOSXEmbedHandler)); + tkMacOSXEmbedHandler = (TkMacOSXEmbedHandler *) + ckalloc(sizeof(TkMacOSXEmbedHandler)); } tkMacOSXEmbedHandler->registerWinProc = registerWinProc; tkMacOSXEmbedHandler->getPortProc = getPortProc; @@ -129,9 +126,8 @@ TkpMakeWindow( XEvent event; /* - * If this window is marked as embedded then - * the window structure should have already been - * created in the TkpUseWindow function. + * If this window is marked as embedded then the window structure should + * have already been created in the TkpUseWindow function. */ if (Tk_IsEmbedded(winPtr)) { @@ -158,22 +154,24 @@ TkpMakeWindow( macWin->size = CGSizeZero; if (Tk_IsTopLevel(macWin->winPtr)) { /* - *This will be set when we are mapped. + * This will be set when we are mapped. */ + macWin->xOff = 0; macWin->yOff = 0; macWin->toplevel = macWin; } else { macWin->xOff = winPtr->parentPtr->privatePtr->xOff + - winPtr->parentPtr->changes.border_width + - winPtr->changes.x; + winPtr->parentPtr->changes.border_width + + winPtr->changes.x; macWin->yOff = winPtr->parentPtr->privatePtr->yOff + - winPtr->parentPtr->changes.border_width + - winPtr->changes.y; + winPtr->parentPtr->changes.border_width + + winPtr->changes.y; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; } macWin->toplevel->referenceCount++; } + /* * TODO: need general solution for visibility events. */ @@ -195,15 +193,15 @@ TkpMakeWindow( * * TkpUseWindow -- * - * This procedure causes a Tk window to use a given X window as - * its parent window, rather than the root window for the screen. - * It is invoked by an embedded application to specify the window - * in which it is embedded. + * This procedure causes a Tk window to use a given X window as its + * parent window, rather than the root window for the screen. It is + * invoked by an embedded application to specify the window in which it + * is embedded. * * Results: - * The return value is normally TCL_OK. If an error occurs (such - * as string not being a valid window spec), then the return value - * is TCL_ERROR and an error message is left in the interp's result if + * The return value is normally TCL_OK. If an error occurs (such as + * string not being a valid window spec), then the return value is + * TCL_ERROR and an error message is left in the interp's result if * interp is non-NULL. * * Side effects: @@ -214,12 +212,12 @@ TkpMakeWindow( int TkpUseWindow( - Tcl_Interp *interp, /* If not NULL, used for error reporting - * if string is bogus. */ + Tcl_Interp *interp, /* If not NULL, used for error reporting if + * string is bogus. */ Tk_Window tkwin, /* Tk window that does not yet have an * associated X window. */ - CONST char *string) /* String identifying an X window to use - * for tkwin; must be an integer value. */ + CONST char *string) /* String identifying an X window to use for + * tkwin; must be an integer value. */ { TkWindow *winPtr = (TkWindow *) tkwin; TkWindow *usePtr; @@ -233,13 +231,12 @@ TkpUseWindow( } /* - * Decode the container pointer, and look for it among the - * list of available containers. + * Decode the container pointer, and look for it among the list of + * available containers. * * N.B. For now, we are limiting the containers to be in the same Tk - * application as tkwin, since otherwise they would not be in our list - * of containers. - * + * application as tkwin, since otherwise they would not be in our list of + * containers. */ if (Tcl_GetInt(interp, string, (int*) &parent) != TCL_OK) { @@ -261,8 +258,8 @@ TkpUseWindow( */ /* - * Save information about the container and the embedded window - * in a Container structure. Currently, there must already be an existing + * Save information about the container and the embedded window in a + * Container structure. Currently, there must already be an existing * Container structure, since we only allow the case where both container * and embedded app. are in the same process. */ @@ -290,11 +287,11 @@ TkpUseWindow( winPtr->privatePtr = macWin; /* - * The grafPtr will be NULL for a Tk in Tk embedded window. - * It is none of our business what it is for a Tk not in Tk embedded window, - * but we will initialize it to NULL, and let the registerWinProc - * set it. In any case, you must always use TkMacOSXGetDrawablePort - * to get the portPtr. It will correctly find the container's port. + * The grafPtr will be NULL for a Tk in Tk embedded window. It is none of + * our business what it is for a Tk not in Tk embedded window, but we will + * initialize it to NULL, and let the registerWinProc set it. In any case, + * you must always use TkMacOSXGetDrawablePort to get the portPtr. It will + * correctly find the container's port. */ macWin->grafPtr = NULL; @@ -310,19 +307,17 @@ TkpUseWindow( winPtr->flags |= TK_EMBEDDED; - /* - * Make a copy of the TK_EMBEDDED flag, since sometimes - * we need this to get the port after the TkWindow structure - * has been freed. + * Make a copy of the TK_EMBEDDED flag, since sometimes we need this to + * get the port after the TkWindow structure has been freed. */ macWin->flags |= TK_EMBEDDED; /* - * Now check whether it is embedded in another Tk widget. If not (the first - * case below) we see if there is an in-process embedding handler registered, - * and if so, let that fill in the rest of the macWin. + * Now check whether it is embedded in another Tk widget. If not (the + * first case below) we see if there is an in-process embedding handler + * registered, and if so, let that fill in the rest of the macWin. */ if (containerPtr == NULL) { @@ -345,10 +340,8 @@ TkpUseWindow( containerPtr->embeddedPtr = macWin->winPtr; containerPtr->nextPtr = firstContainerPtr; firstContainerPtr = containerPtr; - } } else { - /* * The window is embedded in another Tk window. */ @@ -360,10 +353,9 @@ TkpUseWindow( parent->winPtr->changes.border_width + winPtr->changes.y; - /* - * Finish filling up the container structure with the embedded window's - * information. + * Finish filling up the container structure with the embedded + * window's information. */ containerPtr->embedded = (Window) macWin; @@ -375,8 +367,7 @@ TkpUseWindow( */ Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc, - (ClientData) winPtr); - + winPtr); } return TCL_OK; @@ -387,10 +378,10 @@ TkpUseWindow( * * TkpMakeContainer -- * - * This procedure is called to indicate that a particular window - * will be a container for an embedded application. This changes - * certain aspects of the window's behavior, such as whether it - * will receive events anymore. + * This procedure is called to indicate that a particular window will be + * a container for an embedded application. This changes certain aspects + * of the window's behavior, such as whether it will receive events + * anymore. * * Results: * None. @@ -403,18 +394,17 @@ TkpUseWindow( void TkpMakeContainer( - Tk_Window tkwin) /* Token for a window that is about to - * become a container. */ + Tk_Window tkwin) /* Token for a window that is about to become + * a container. */ { TkWindow *winPtr = (TkWindow *) tkwin; Container *containerPtr; /* - * Register the window as a container so that, for example, we can - * make sure the argument to -use is valid. + * Register the window as a container so that, for example, we can make + * sure the argument to -use is valid. */ - Tk_MakeWindowExist(tkwin); containerPtr = (Container *) ckalloc(sizeof(Container)); containerPtr->parent = Tk_WindowId(tkwin); @@ -426,23 +416,22 @@ TkpMakeContainer( winPtr->flags |= TK_CONTAINER; /* - * Request SubstructureNotify events so that we can find out when - * the embedded application creates its window or attempts to - * resize it. Also watch Configure events on the container so that - * we can resize the child to match. Also, pass activate events from - * the container down to the embedded toplevel. + * Request SubstructureNotify events so that we can find out when the + * embedded application creates its window or attempts to resize it. Also + * watch Configure events on the container so that we can resize the child + * to match. Also, pass activate events from the container down to the + * embedded toplevel. */ Tk_CreateEventHandler(tkwin, SubstructureNotifyMask|SubstructureRedirectMask, - ContainerEventProc, (ClientData) winPtr); + ContainerEventProc, winPtr); Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbedStructureProc, - (ClientData) containerPtr); + containerPtr); Tk_CreateEventHandler(tkwin, ActivateMask, EmbedActivateProc, - (ClientData) containerPtr); + containerPtr); Tk_CreateEventHandler(tkwin, FocusChangeMask, EmbedFocusProc, - (ClientData) containerPtr); - + containerPtr); } /* @@ -454,8 +443,7 @@ TkpMakeContainer( * identifier for the associated container window. * * Results: - * The return value is the MacDrawable for winPtr's - * container window. + * The return value is the MacDrawable for winPtr's container window. * * Side effects: * None. @@ -464,8 +452,8 @@ TkpMakeContainer( */ MacDrawable * -TkMacOSXContainerId(winPtr) - TkWindow *winPtr; /* Tk's structure for an embedded window. */ +TkMacOSXContainerId( + TkWindow *winPtr) /* Tk's structure for an embedded window. */ { Container *containerPtr; @@ -484,8 +472,8 @@ TkMacOSXContainerId(winPtr) * * TkMacOSXGetHostToplevel -- * - * Given the TkWindow, return the MacDrawable for the outermost - * toplevel containing it. This will be a real Macintosh window. + * Given the TkWindow, return the MacDrawable for the outermost toplevel + * containing it. This will be a real Macintosh window. * * Results: * Returns a MacDrawable corresponding to a Macintosh Toplevel @@ -504,20 +492,18 @@ TkMacOSXGetHostToplevel( topWinPtr = winPtr->privatePtr->toplevel->winPtr; if (!Tk_IsEmbedded(topWinPtr)) { - return winPtr->privatePtr->toplevel; - } else { - contWinPtr = TkpGetOtherWindow(topWinPtr); + return winPtr->privatePtr->toplevel; + } + contWinPtr = TkpGetOtherWindow(topWinPtr); - /* - * TODO: Here we should handle out of process embedding. - */ + /* + * TODO: Here we should handle out of process embedding. + */ - if (contWinPtr != NULL) { - return TkMacOSXGetHostToplevel(contWinPtr); - } else { - return None; - } + if (contWinPtr == NULL) { + return None; } + return TkMacOSXGetHostToplevel(contWinPtr); } /* @@ -525,10 +511,10 @@ TkMacOSXGetHostToplevel( * * TkpClaimFocus -- * - * This procedure is invoked when someone asks for the input focus - * to be put on a window in an embedded application, but the - * application doesn't currently have the focus. It requests the - * input focus from the container application. + * This procedure is invoked when someone asks for the input focus to be + * put on a window in an embedded application, but the application + * doesn't currently have the focus. It requests the input focus from the + * container application. * * Results: * None. @@ -541,11 +527,11 @@ TkMacOSXGetHostToplevel( void TkpClaimFocus( - TkWindow *topLevelPtr, /* Top-level window containing desired - * focus window; should be embedded. */ - int force) /* One means that the container should - * claim the focus if it doesn't - * currently have it. */ + TkWindow *topLevelPtr, /* Top-level window containing desired focus + * window; should be embedded. */ + int force) /* One means that the container should claim + * the focus if it doesn't currently have + * it. */ { XEvent event; Container *containerPtr; @@ -560,7 +546,6 @@ TkpClaimFocus( /* Empty loop body. */ } - event.xfocus.type = FocusIn; event.xfocus.serial = LastKnownRequestProcessed(topLevelPtr->display); event.xfocus.send_event = 1; @@ -576,9 +561,8 @@ TkpClaimFocus( * * TkpTestembedCmd -- * - * This procedure implements the "testembed" command. It returns - * some or all of the information in the list pointed to by - * firstContainerPtr. + * This procedure implements the "testembed" command. It returns some or + * all of the information in the list pointed to by firstContainerPtr. * * Results: * A standard Tcl result. @@ -612,13 +596,11 @@ TkpTestembedCmd( Tcl_DStringStartSublist(&dString); if (containerPtr->parent == None) { Tcl_DStringAppendElement(&dString, ""); + } else if (all) { + sprintf(buffer, "0x%x", (int) containerPtr->parent); + Tcl_DStringAppendElement(&dString, buffer); } else { - if (all) { - sprintf(buffer, "0x%x", (int) containerPtr->parent); - Tcl_DStringAppendElement(&dString, buffer); - } else { - Tcl_DStringAppendElement(&dString, "XXX"); - } + Tcl_DStringAppendElement(&dString, "XXX"); } if (containerPtr->parentPtr == NULL) { Tcl_DStringAppendElement(&dString, ""); @@ -628,13 +610,11 @@ TkpTestembedCmd( } if (containerPtr->embedded == None) { Tcl_DStringAppendElement(&dString, ""); + } else if (all) { + sprintf(buffer, "0x%x", (int) containerPtr->embedded); + Tcl_DStringAppendElement(&dString, buffer); } else { - if (all) { - sprintf(buffer, "0x%x", (int) containerPtr->embedded); - Tcl_DStringAppendElement(&dString, buffer); - } else { - Tcl_DStringAppendElement(&dString, "XXX"); - } + Tcl_DStringAppendElement(&dString, "XXX"); } if (containerPtr->embeddedPtr == NULL) { Tcl_DStringAppendElement(&dString, ""); @@ -653,13 +633,13 @@ TkpTestembedCmd( * * TkpRedirectKeyEvent -- * - * This procedure is invoked when a key press or release event - * arrives for an application that does not believe it owns the - * input focus. This can happen because of embedding; for example, - * X can send an event to an embedded application when the real - * focus window is in the container application and is an ancestor - * of the container. This procedure's job is to forward the event - * back to the application where it really belongs. + * This procedure is invoked when a key press or release event arrives + * for an application that does not believe it owns the input focus. This + * can happen because of embedding; for example, X can send an event to + * an embedded application when the real focus window is in the container + * application and is an ancestor of the container. This procedure's job + * is to forward the event back to the application where it really + * belongs. * * Results: * None. @@ -674,8 +654,8 @@ void TkpRedirectKeyEvent( TkWindow *winPtr, /* Window to which the event was originally * reported. */ - XEvent *eventPtr) /* X event to redirect (should be KeyPress - * or KeyRelease). */ + XEvent *eventPtr) /* X event to redirect (should be KeyPress or + * KeyRelease). */ { } @@ -684,13 +664,13 @@ TkpRedirectKeyEvent( * * TkpGetOtherWindow -- * - * If both the container and embedded window are in the same - * process, this procedure will return either one, given the other. + * If both the container and embedded window are in the same process, + * this procedure will return either one, given the other. * * Results: * If winPtr is a container, the return value is the token for the - * embedded window, and vice versa. If the "other" window isn't in - * this process, NULL is returned. + * embedded window, and vice versa. If the "other" window isn't in this + * process, NULL is returned. * * Side effects: * None. @@ -700,14 +680,14 @@ TkpRedirectKeyEvent( TkWindow * TkpGetOtherWindow( - TkWindow *winPtr) /* Tk's structure for a container or - * embedded window. */ + TkWindow *winPtr) /* Tk's structure for a container or embedded + * window. */ { Container *containerPtr; /* - * TkpGetOtherWindow returns NULL if both windows are not - * in the same process... + * TkpGetOtherWindow returns NULL if both windows are not in the same + * process... */ if (!(winPtr->flags & TK_BOTH_HALVES)) { @@ -749,7 +729,7 @@ EmbeddedEventProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; if (eventPtr->type == DestroyNotify) { EmbedWindowDeleted(winPtr); @@ -762,19 +742,19 @@ EmbeddedEventProc( * ContainerEventProc -- * * This procedure is invoked by the Tk event dispatcher when various - * useful events are received for the children of a container - * window. It forwards relevant information, such as geometry - * requests, from the events into the container's application. + * useful events are received for the children of a container window. It + * forwards relevant information, such as geometry requests, from the + * events into the container's application. * - * NOTE: on the Mac, only the DestroyNotify branch is ever taken. - * We don't synthesize the other events. + * NOTE: on the Mac, only the DestroyNotify branch is ever taken. We + * don't synthesize the other events. * * Results: * None. * * Side effects: - * Depends on the event. For example, when ConfigureRequest events - * occur, geometry information gets set for the container window. + * Depends on the event. For example, when ConfigureRequest events occur, + * geometry information gets set for the container window. * *---------------------------------------------------------------------- */ @@ -784,18 +764,18 @@ ContainerEventProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; Container *containerPtr; Tk_ErrorHandler errHandler; /* - * Ignore any X protocol errors that happen in this procedure - * (almost any operation could fail, for example, if the embedded - * application has deleted its window). + * Ignore any X protocol errors that happen in this procedure (almost any + * operation could fail, for example, if the embedded application has + * deleted its window). */ errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1, - -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL); + -1, -1, NULL, NULL); /* * Find the Container structure associated with the parent window. @@ -811,10 +791,9 @@ ContainerEventProc( if (eventPtr->type == CreateNotify) { /* - * A new child window has been created in the container. Record - * its id in the Container structure (if more than one child is - * created, just remember the last one and ignore the earlier - * ones). + * A new child window has been created in the container. Record its id + * in the Container structure (if more than one child is created, just + * remember the last one and ignore the earlier ones). */ containerPtr->embedded = eventPtr->xcreatewindow.window; @@ -822,14 +801,13 @@ ContainerEventProc( if ((eventPtr->xconfigurerequest.x != 0) || (eventPtr->xconfigurerequest.y != 0)) { /* - * The embedded application is trying to move itself, which - * isn't legal. At this point, the window hasn't actually - * moved, but we need to send it a ConfigureNotify event to - * let it know that its request has been denied. If the - * embedded application was also trying to resize itself, a - * ConfigureNotify will be sent by the geometry management - * code below, so we don't need to do anything. Otherwise, - * generate a synthetic event. + * The embedded application is trying to move itself, which isn't + * legal. At this point, the window hasn't actually moved, but we + * need to send it a ConfigureNotify event to let it know that its + * request has been denied. If the embedded application was also + * trying to resize itself, a ConfigureNotify will be sent by the + * geometry management code below, so we don't need to do + * anything. Otherwise, generate a synthetic event. */ if ((eventPtr->xconfigurerequest.width == winPtr->changes.width) @@ -844,8 +822,8 @@ ContainerEventProc( } else if (eventPtr->type == MapRequest) { /* * The embedded application's map request was ignored and simply - * passed on to us, so we have to map the window for it to appear - * on the screen. + * passed on to us, so we have to map the window for it to appear on + * the screen. */ XMapWindow(eventPtr->xmaprequest.display, @@ -865,11 +843,10 @@ ContainerEventProc( * * EmbedStructureProc -- * - * This procedure is invoked by the Tk event dispatcher when - * a container window owned by this application gets resized - * (and also at several other times that we don't care about). - * This procedure reflects the size change in the embedded - * window that corresponds to the container. + * This procedure is invoked by the Tk event dispatcher when a container + * window owned by this application gets resized (and also at several + * other times that we don't care about). This procedure reflects the + * size change in the embedded window that corresponds to the container. * * Results: * None. @@ -885,7 +862,7 @@ EmbedStructureProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { - Container *containerPtr = (Container *) clientData; + Container *containerPtr = clientData; Tk_ErrorHandler errHandler; if (eventPtr->type == ConfigureNotify) { @@ -896,12 +873,10 @@ EmbedStructureProc( */ errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1, - -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL); + -1, -1, NULL, NULL); Tk_MoveResizeWindow((Tk_Window) containerPtr->embeddedPtr, 0, 0, - (unsigned int) Tk_Width( - (Tk_Window) containerPtr->parentPtr), - (unsigned int) Tk_Height( - (Tk_Window) containerPtr->parentPtr)); + (unsigned) Tk_Width((Tk_Window) containerPtr->parentPtr), + (unsigned) Tk_Height((Tk_Window)containerPtr->parentPtr)); Tk_DeleteErrorHandler(errHandler); } } else if (eventPtr->type == DestroyNotify) { @@ -914,10 +889,10 @@ EmbedStructureProc( * * EmbedActivateProc -- * - * This procedure is invoked by the Tk event dispatcher when - * Activate and Deactivate events occur for a container window owned - * by this application. It is responsible for forwarding an activate - * event down into the embedded toplevel. + * This procedure is invoked by the Tk event dispatcher when Activate and + * Deactivate events occur for a container window owned by this + * application. It is responsible for forwarding an activate event down + * into the embedded toplevel. * * Results: * None. @@ -933,7 +908,7 @@ EmbedActivateProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { - Container *containerPtr = (Container *) clientData; + Container *containerPtr = clientData; if (containerPtr->embeddedPtr != NULL) { if (eventPtr->type == ActivateNotify) { @@ -949,11 +924,10 @@ EmbedActivateProc( * * EmbedFocusProc -- * - * This procedure is invoked by the Tk event dispatcher when - * FocusIn and FocusOut events occur for a container window owned - * by this application. It is responsible for moving the focus - * back and forth between a container application and an embedded - * application. + * This procedure is invoked by the Tk event dispatcher when FocusIn and + * FocusOut events occur for a container window owned by this + * application. It is responsible for moving the focus back and forth + * between a container application and an embedded application. * * Results: * None. @@ -969,37 +943,37 @@ EmbedFocusProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { - Container *containerPtr = (Container *) clientData; + Container *containerPtr = clientData; Display *display; XEvent event; if (containerPtr->embeddedPtr != NULL) { - display = Tk_Display(containerPtr->parentPtr); + display = Tk_Display(containerPtr->parentPtr); event.xfocus.serial = LastKnownRequestProcessed(display); event.xfocus.send_event = false; event.xfocus.display = display; event.xfocus.mode = NotifyNormal; event.xfocus.window = containerPtr->embedded; - if (eventPtr->type == FocusIn) { - /* - * The focus just arrived at the container. Change the X focus - * to move it to the embedded application, if there is one. - * Ignore X errors that occur during this operation (it's - * possible that the new focus window isn't mapped). - */ + if (eventPtr->type == FocusIn) { + /* + * The focus just arrived at the container. Change the X focus to + * move it to the embedded application, if there is one. Ignore X + * errors that occur during this operation (it's possible that the + * new focus window isn't mapped). + */ event.xfocus.detail = NotifyNonlinear; event.xfocus.type = FocusIn; - } else if (eventPtr->type == FocusOut) { - /* When the container gets a FocusOut event, it has to tell the embedded app - * that it has lost the focus. - */ + /* + * When the container gets a FocusOut event, it has to tell the + * embedded app that it has lost the focus. + */ event.xfocus.type = FocusOut; event.xfocus.detail = NotifyNonlinear; - } + } Tk_QueueWindowEvent(&event, TCL_QUEUE_MARK); } @@ -1010,10 +984,10 @@ EmbedFocusProc( * * EmbedGeometryRequest -- * - * This procedure is invoked when an embedded application requests - * a particular size. It processes the request (which may or may - * not actually honor the request) and reflects the results back - * to the embedded application. + * This procedure is invoked when an embedded application requests a + * particular size. It processes the request (which may or may not + * actually honor the request) and reflects the results back to the + * embedded application. * * NOTE: On the Mac, this is a stub, since we don't synthesize * ConfigureRequest events. @@ -1022,10 +996,10 @@ EmbedFocusProc( * None. * * Side effects: - * If we deny the child's size change request, a Configure event - * is synthesized to let the child know how big it ought to be. - * Events get processed while we're waiting for the geometry - * managers to do their thing. + * If we deny the child's size change request, a Configure event is + * synthesized to let the child know how big it ought to be. Events get + * processed while we're waiting for the geometry managers to do their + * thing. * *---------------------------------------------------------------------- */ @@ -1038,13 +1012,13 @@ EmbedGeometryRequest( TkWindow *winPtr = containerPtr->parentPtr; /* - * Forward the requested size into our geometry management hierarchy - * via the container window. We need to send a Configure event back - * to the embedded application if we decide not to honor its - * request; to make this happen, process all idle event handlers - * synchronously here (so that the geometry managers have had a - * chance to do whatever they want to do), and if the window's size - * didn't change then generate a configure event. + * Forward the requested size into our geometry management hierarchy via + * the container window. We need to send a Configure event back to the + * embedded application if we decide not to honor its request; to make + * this happen, process all idle event handlers synchronously here (so + * that the geometry managers have had a chance to do whatever they want + * to do), and if the window's size didn't change then generate a + * configure event. */ Tk_GeometryRequest((Tk_Window) winPtr, width, height); @@ -1062,13 +1036,12 @@ EmbedGeometryRequest( * * EmbedSendConfigure -- * - * This is currently a stub. It is called to notify an - * embedded application of its current size and location. This - * procedure is called when the embedded application made a - * geometry request that we did not grant, so that the embedded - * application knows that its geometry didn't change after all. - * It is a response to ConfigureRequest events, which we do not - * currently synthesize on the Mac + * This is currently a stub. It is called to notify an embedded + * application of its current size and location. This procedure is called + * when the embedded application made a geometry request that we did not + * grant, so that the embedded application knows that its geometry didn't + * change after all. It is a response to ConfigureRequest events, which + * we do not currently synthesize on the Mac * * Results: * None. @@ -1090,9 +1063,9 @@ EmbedSendConfigure( * * EmbedWindowDeleted -- * - * This procedure is invoked when a window involved in embedding - * (as either the container or the embedded application) is - * destroyed. It cleans up the Container structure for the window. + * This procedure is invoked when a window involved in embedding (as + * either the container or the embedded application) is destroyed. It + * cleans up the Container structure for the window. * * Results: * None. @@ -1111,16 +1084,14 @@ EmbedWindowDeleted( Container *containerPtr, *prevPtr; /* - * Find the Container structure for this window. Delete the - * information about the embedded application and free the container's - * record. + * Find the Container structure for this window. Delete the information + * about the embedded application and free the container's record. */ prevPtr = NULL; containerPtr = firstContainerPtr; while (1) { if (containerPtr->embeddedPtr == winPtr) { - /* * We also have to destroy our parent, to clean up the container. * Fabricate an event to do this. @@ -1131,20 +1102,18 @@ EmbedWindowDeleted( XEvent event; event.xany.serial = - Tk_Display(containerPtr->parentPtr)->request; - event.xany.send_event = False; - event.xany.display = Tk_Display(containerPtr->parentPtr); - - event.xany.type = DestroyNotify; - event.xany.window = containerPtr->parent; - event.xdestroywindow.event = containerPtr->parent; - Tk_QueueWindowEvent(&event, TCL_QUEUE_HEAD); - + Tk_Display(containerPtr->parentPtr)->request; + event.xany.send_event = False; + event.xany.display = Tk_Display(containerPtr->parentPtr); + + event.xany.type = DestroyNotify; + event.xany.window = containerPtr->parent; + event.xdestroywindow.event = containerPtr->parent; + Tk_QueueWindowEvent(&event, TCL_QUEUE_HEAD); } containerPtr->embedded = None; containerPtr->embeddedPtr = NULL; - break; } if (containerPtr->parentPtr == winPtr) { diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 59418f5..f9b67f5 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -8,10 +8,10 @@ * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2005-2007 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: tkMacOSXInit.c,v 1.34 2007/12/13 15:27:09 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXInit.c,v 1.34.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -24,19 +24,20 @@ #include <mach-o/getsect.h> /* - * Define the following to 0 to not attempt to use an undocumented SPI - * to notify the window server that an unbundled executable is a full - * GUI application after loading Tk. + * Define the following to 0 to not attempt to use an undocumented SPI to + * notify the window server that an unbundled executable is a full GUI + * application after loading Tk. */ + #ifndef MAC_OSX_TK_USE_CPS_SPI #define MAC_OSX_TK_USE_CPS_SPI 1 #endif /* * The following structures are used to map the script/language codes of a - * font to the name that should be passed to Tcl_GetEncoding() to obtain - * the encoding for that font. The set of numeric constants is fixed and - * defined by Apple. + * font to the name that should be passed to Tcl_GetEncoding() to obtain the + * encoding for that font. The set of numeric constants is fixed and defined + * by Apple. */ typedef struct Map { @@ -83,13 +84,13 @@ static Map scriptMap[] = { Tcl_Encoding TkMacOSXCarbonEncoding = NULL; /* - * If the App is in an App package, then we want to add the Scripts - * directory to the auto_path. + * If the App is in an App package, then we want to add the Scripts directory + * to the auto_path. */ + static char scriptPath[PATH_MAX + 1] = ""; float tkMacOSXToolboxVersionNumber = 0; - /* *---------------------------------------------------------------------- @@ -100,8 +101,8 @@ float tkMacOSXToolboxVersionNumber = 0; * tk_library variable. * * Results: - * Returns a standard Tcl result. Leaves an error message or result - * in the interp's result. + * Returns a standard Tcl result. Leaves an error message or result in + * the interp's result. * * Side effects: * Sets "tk_library" Tcl variable, runs "tk.tcl" script. @@ -119,9 +120,9 @@ TkpInit( Tk_MacOSXSetupTkNotifier(); /* - * Since it is possible for TkInit to be called multiple times - * and we don't want to do the following initialization multiple times - * we protect against doing it more than once. + * Since it is possible for TkInit to be called multiple times and we + * don't want to do the following initialization multiple times we protect + * against doing it more than once. */ if (!initialized) { @@ -130,7 +131,7 @@ TkpInit( CFURLRef bundleUrl = NULL; CFStringEncoding encoding; const char *encodingStr = NULL; - int i; + int i; struct utsname name; long osVersion = 0; @@ -145,7 +146,7 @@ TkpInit( } if (osVersion && osVersion < (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10) { Tcl_Panic("Mac OS X 10.%d or later required !", - (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10); + (MAC_OS_X_VERSION_MIN_REQUIRED-1000)/10); } TK_IF_MAC_OS_X_API (3, &kHIToolboxVersionNumber, tkMacOSXToolboxVersionNumber = kHIToolboxVersionNumber; @@ -174,7 +175,7 @@ TkpInit( "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK) #endif - { + { /* Tk.framework not found, check if resource file is open */ Handle rsrc = Get1NamedResource('CURS', "\phand"); if (rsrc) { @@ -194,7 +195,7 @@ TkpInit( image = _dyld_get_image_header(i); if (image) { data = getsectdatafromheader(image, SEG_TEXT, - "__tk_rsrc", (void*)&size); + "__tk_rsrc", (void *) &size); if (data) { data += _dyld_get_image_vmaddr_slide(i); break; @@ -222,7 +223,7 @@ TkpInit( if (write(fd, data, size) == -1) { break; } - if(ChkErr(FSPathMakeRef, (unsigned char*)fileName, &ref, + if(ChkErr(FSPathMakeRef, (unsigned char *) fileName, &ref, NULL) != noErr) { break; } @@ -260,11 +261,14 @@ TkpInit( * executable's url and compare the resulting url with the main * bundle url. */ + int j = 3; CFURLRef url = CFBundleCopyExecutableURL(bundleRef); + while (url && j--) { - CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, - url); + CFURLRef parent = + CFURLCreateCopyDeletingLastPathComponent(NULL, url); + CFRelease(url); url = parent; } @@ -275,8 +279,11 @@ TkpInit( CFRelease(bundleUrl); } - /* If we are not a bundled executable, notify the window server that - * we are a foregroundable app. */ + /* + * If we are not a bundled executable, notify the window server that + * we are a foregroundable app. + */ + if (!bundledExecutable) { OSStatus err = procNotFound; ProcessSerialNumber psn = { 0, kCurrentProcess }; @@ -293,6 +300,7 @@ TkpInit( * server. Load the SPI symbol dynamically, so that we don't * break if it ever disappears or changes its name. */ + TkMacOSXInitNamedSymbol(CoreGraphics, OSStatus, CPSEnableForegroundOperation, ProcessSerialNumberPtr); if (CPSEnableForegroundOperation) { @@ -327,8 +335,8 @@ TkpInit( } /* - * FIXME: Close stdin & stdout for remote debugging otherwise we - * will fight with gdb for stdin & stdout + * FIXME: Close stdin & stdout for remote debugging otherwise we will + * fight with gdb for stdin & stdout */ if (getenv("XCNOSTDIN") != NULL) { @@ -389,9 +397,9 @@ TkpInit( * * TkpGetAppName -- * - * Retrieves the name of the current application from a platform - * specific location. For Unix, the application name is the tail - * of the path contained in the tcl variable argv0. + * Retrieves the name of the current application from a platform specific + * location. For Unix, the application name is the tail of the path + * contained in the tcl variable argv0. * * Results: * Returns the application name in the given Tcl_DString. @@ -426,8 +434,8 @@ TkpGetAppName( * * TkpDisplayWarning -- * - * This routines is called from Tk_Main to display warning - * messages that occur during startup. + * This routines is called from Tk_Main to display warning messages that + * occur during startup. * * Results: * None. @@ -444,6 +452,7 @@ TkpDisplayWarning( CONST char *title) /* Title of warning. */ { Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); + if (errChannel) { Tcl_WriteChars(errChannel, title, -1); Tcl_WriteChars(errChannel, ": ", 2); @@ -457,13 +466,11 @@ TkpDisplayWarning( * * TkMacOSXDefaultStartupScript -- * - * - * On MacOS X, we look for a file in the Resources/Scripts - * directory called AppMain.tcl and if found, we set argv[1] to - * that, so that the rest of the code will find it, and add the - * Scripts folder to the auto_path. If we don't find the startup - * script, we just bag it, assuming the user is starting up some - * other way. + * On MacOS X, we look for a file in the Resources/Scripts directory + * called AppMain.tcl and if found, we set argv[1] to that, so that the + * rest of the code will find it, and add the Scripts folder to the + * auto_path. If we don't find the startup script, we just bag it, + * assuming the user is starting up some other way. * * Results: * None. @@ -482,24 +489,21 @@ TkMacOSXDefaultStartupScript(void) bundleRef = CFBundleGetMainBundle(); if (bundleRef != NULL) { - CFURLRef appMainURL; - appMainURL = CFBundleCopyResourceURL(bundleRef, - CFSTR("AppMain"), - CFSTR("tcl"), - CFSTR("Scripts")); + CFURLRef appMainURL = CFBundleCopyResourceURL(bundleRef, + CFSTR("AppMain"), CFSTR("tcl"), CFSTR("Scripts")); if (appMainURL != NULL) { CFURLRef scriptFldrURL; char startupScript[PATH_MAX + 1]; if (CFURLGetFileSystemRepresentation (appMainURL, true, - (unsigned char*) startupScript, PATH_MAX)) { - Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, -1), NULL); - scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent( - NULL, appMainURL); + (unsigned char *) startupScript, PATH_MAX)) { + Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL); + scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL, + appMainURL); if (scriptFldrURL != NULL) { - CFURLGetFileSystemRepresentation(scriptFldrURL, - true, (unsigned char*) scriptPath, PATH_MAX); + CFURLGetFileSystemRepresentation(scriptFldrURL, true, + (unsigned char *) scriptPath, PATH_MAX); CFRelease(scriptFldrURL); } } @@ -513,11 +517,9 @@ TkMacOSXDefaultStartupScript(void) * * TkMacOSXGetNamedSymbol -- * - * - * Dynamically acquire address of a named symbol from a loaded - * dynamic library, so that we can use API that may not be - * available on all OS versions. - * If module is non-NULL and not the empty string, use twolevel + * Dynamically acquire address of a named symbol from a loaded dynamic + * library, so that we can use API that may not be available on all OS + * versions. If module is non-NULL and not the empty string, use twolevel * namespace lookup. * * Results: @@ -535,18 +537,19 @@ TkMacOSXGetNamedSymbol( const char* symbol) { NSSymbol nsSymbol = NULL; + if (module && *module) { - if(NSIsSymbolNameDefinedWithHint(symbol, module)) { + if (NSIsSymbolNameDefinedWithHint(symbol, module)) { nsSymbol = NSLookupAndBindSymbolWithHint(symbol, module); } } else { - if(NSIsSymbolNameDefined(symbol)) { + if (NSIsSymbolNameDefined(symbol)) { nsSymbol = NSLookupAndBindSymbol(symbol); } } - if (nsSymbol) { - return NSAddressOfSymbol(nsSymbol); - } else { + + if (!nsSymbol) { return NULL; } + return NSAddressOfSymbol(nsSymbol); } diff --git a/macosx/tkMacOSXSend.c b/macosx/tkMacOSXSend.c index c65833b..85e23b2 100644 --- a/macosx/tkMacOSXSend.c +++ b/macosx/tkMacOSXSend.c @@ -1,175 +1,171 @@ /* * tkMacOSXSend.c -- * - * This file provides procedures that implement the "send" - * command, allowing commands to be passed from interpreter - * to interpreter. This current implementation for the Mac - * has most functionality stubed out. - * - * The current plan, which we have not had time to implement, is - * for the first Wish app to create a gestalt of type 'WIsH'. - * This gestalt will point to a table, in system memory, of - * Tk apps. Each Tk app, when it starts up, will register their - * name, and process ID, in this table. This will allow us to - * implement "tk appname". - * - * Then the send command will look up the process id of the target - * app in this table, and send an AppleEvent to that process. The - * AppleEvent handler is much like the do script handler, except that - * you have to specify the name of the tk app as well, since there may - * be many interps in one wish app, and you need to send it to the - * right one. - * - * Implementing this has been on our list of things to do, but what - * with the demise of Tcl at Sun, and the lack of resources at - * Scriptics it may not get done for awhile. So this sketch is - * offered for the brave to attempt if they need the functionality... + * This file provides procedures that implement the "send" command, + * allowing commands to be passed from interpreter to interpreter. This + * current implementation for the Mac has most functionality stubed out. + * + * The current plan, which we have not had time to implement, is for the + * first Wish app to create a gestalt of type 'WIsH'. This gestalt will + * point to a table, in system memory, of Tk apps. Each Tk app, when it + * starts up, will register their name, and process ID, in this table. + * This will allow us to implement "tk appname". + * + * Then the send command will look up the process id of the target app in + * this table, and send an AppleEvent to that process. The AppleEvent + * handler is much like the do script handler, except that you have to + * specify the name of the tk app as well, since there may be many + * interps in one wish app, and you need to send it to the right one. + * + * Implementing this has been on our list of things to do, but what with + * the demise of Tcl at Sun, and the lack of resources at Scriptics it + * may not get done for awhile. So this sketch is offered for the brave + * to attempt if they need the functionality... * * Copyright (c) 1989-1994 The Regents of the University of California. * Copyright (c) 1994-1998 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2005-2007 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: tkMacOSXSend.c,v 1.8 2007/12/13 15:27:10 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXSend.c,v 1.8.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXInt.h" /* - * The following structure is used to keep track of the - * interpreters registered by this process. + * The following structure is used to keep track of the interpreters + * registered by this process. */ typedef struct RegisteredInterp { char *name; /* Interpreter's name (malloc-ed). */ - Tcl_Interp *interp; /* Interpreter associated with - * name. */ + Tcl_Interp *interp; /* Interpreter associated with name. */ struct RegisteredInterp *nextPtr; - /* Next in list of names associated - * with interps in this process. - * NULL means end of list. */ + /* Next in list of names associated with + * interps in this process. NULL means end of + * list. */ } RegisteredInterp; /* - * A registry of all interpreters for a display is kept in a - * property "InterpRegistry" on the root window of the display. - * It is organized as a series of zero or more concatenated strings - * (in no particular order), each of the form + * A registry of all interpreters for a display is kept in a property + * "InterpRegistry" on the root window of the display. It is organized as a + * series of zero or more concatenated strings (in no particular order), each + * of the form * window space name '\0' - * where "window" is the hex id of the comm. window to use to talk - * to an interpreter named "name". + * where "window" is the hex id of the comm. window to use to talk to an + * interpreter named "name". * - * When the registry is being manipulated by an application (e.g. to - * add or remove an entry), it is loaded into memory using a structure - * of the following type: + * When the registry is being manipulated by an application (e.g. to add or + * remove an entry), it is loaded into memory using a structure of the + * following type: */ typedef struct NameRegistry { TkDisplay *dispPtr; /* Display from which the registry was * read. */ - int locked; /* Non-zero means that the display was - * locked when the property was read in. */ - int modified; /* Non-zero means that the property has - * been modified, so it needs to be written - * out when the NameRegistry is closed. */ + int locked; /* Non-zero means that the display was locked + * when the property was read in. */ + int modified; /* Non-zero means that the property has been + * modified, so it needs to be written out + * when the NameRegistry is closed. */ unsigned long propLength; /* Length of the property, in bytes. */ - char *property; /* The contents of the property, or NULL - * if none. See format description above; - * this is *not* terminated by the first - * null character. Dynamically allocated. */ + char *property; /* The contents of the property, or NULL if + * none. See format description above; this is + * *not* terminated by the first null + * character. Dynamically allocated. */ int allocedByX; /* Non-zero means must free property with * XFree; zero means use ckfree. */ } NameRegistry; -static int initialized = false; /* A flag to denote if we have initialized yet. */ +static int initialized = false; /* A flag to denote if we have initialized + * yet. */ static RegisteredInterp *interpListPtr = NULL; -/* List of all interpreters - * registered by this process. */ - - /* - * The information below is used for communication between processes - * during "send" commands. Each process keeps a private window, never - * even mapped, with one property, "Comm". When a command is sent to - * an interpreter, the command is appended to the comm property of the - * communication window associated with the interp's process. Similarly, - * when a result is returned from a sent command, it is also appended - * to the comm property. - * - * Each command and each result takes the form of ASCII text. For a - * command, the text consists of a zero character followed by several - * null-terminated ASCII strings. The first string consists of the - * single letter "c". Subsequent strings have the form "option value" - * where the following options are supported: - * - * -r commWindow serial - * - * This option means that a response should be sent to the window - * whose X identifier is "commWindow" (in hex), and the response should - * be identified with the serial number given by "serial" (in decimal). - * If this option isn't specified then the send is asynchronous and - * no response is sent. - * - * -n name - * "Name" gives the name of the application for which the command is - * intended. This option must be present. - * - * -s script - * - * "Script" is the script to be executed. This option must be present. - * - * The options may appear in any order. The -n and -s options must be - * present, but -r may be omitted for asynchronous RPCs. For compatibility - * with future releases that may add new features, there may be additional - * options present; as long as they start with a "-" character, they will - * be ignored. - * - * A result also consists of a zero character followed by several null- - * terminated ASCII strings. The first string consists of the single - * letter "r". Subsequent strings have the form "option value" where - * the following options are supported: - * - * -s serial - * - * Identifies the command for which this is the result. It is the - * same as the "serial" field from the -s option in the command. This - * option must be present. - * - * -c code - * - * "Code" is the completion code for the script, in decimal. If the - * code is omitted it defaults to TCL_OK. - * - * -r result - * - * "Result" is the result string for the script, which may be either - * a result or an error message. If this field is omitted then it - * defaults to an empty string. - * - * -i errorInfo - * - * "ErrorInfo" gives a string with which to initialize the errorInfo - * variable. This option may be omitted; it is ignored unless the - * completion code is TCL_ERROR. - * - * -e errorCode - * - * "ErrorCode" gives a string with with to initialize the errorCode - * variable. This option may be omitted; it is ignored unless the - * completion code is TCL_ERROR. - * - * Options may appear in any order, and only the -s option must be - * present. As with commands, there may be additional options besides - * these; unknown options are ignored. - */ - - /* - * Maximum size property that can be read at one time by - * this module: - */ + /* List of all interpreters registered by this + * process. */ + +/* + * The information below is used for communication between processes during + * "send" commands. Each process keeps a private window, never even mapped, + * with one property, "Comm". When a command is sent to an interpreter, the + * command is appended to the comm property of the communication window + * associated with the interp's process. Similarly, when a result is returned + * from a sent command, it is also appended to the comm property. + * + * Each command and each result takes the form of ASCII text. For a command, + * the text consists of a zero character followed by several null-terminated + * ASCII strings. The first string consists of the single letter "c". + * Subsequent strings have the form "option value" where the following options + * are supported: + * + * -r commWindow serial + * + * This option means that a response should be sent to the window whose X + * identifier is "commWindow" (in hex), and the response should be + * identified with the serial number given by "serial" (in decimal). If + * this option isn't specified then the send is asynchronous and no + * response is sent. + * + * -n name + * + * "Name" gives the name of the application for which the command is + * intended. This option must be present. + * + * -s script + * + * "Script" is the script to be executed. This option must be present. + * + * The options may appear in any order. The -n and -s options must be present, + * but -r may be omitted for asynchronous RPCs. For compatibility with future + * releases that may add new features, there may be additional options + * present; as long as they start with a "-" character, they will be ignored. + * + * + * A result also consists of a zero character followed by several null- + * terminated ASCII strings. The first string consists of the single letter + * "r". Subsequent strings have the form "option value" where the following + * options are supported: + * + * -s serial + * + * Identifies the command for which this is the result. It is the same as + * the "serial" field from the -s option in the command. This option must + * be present. + * + * -c code + * + * "Code" is the completion code for the script, in decimal. If the code + * is omitted it defaults to TCL_OK. + * + * -r result + * + * "Result" is the result string for the script, which may be either a + * result or an error message. If this field is omitted then it defaults + * to an empty string. + * + * -i errorInfo + * + * "ErrorInfo" gives a string with which to initialize the errorInfo + * variable. This option may be omitted; it is ignored unless the + * completion code is TCL_ERROR. + * + * -e errorCode + * + * "ErrorCode" gives a string with with to initialize the errorCode + * variable. This option may be omitted; it is ignored unless the + * completion code is TCL_ERROR. + * + * Options may appear in any order, and only the -s option must be present. As + * with commands, there may be additional options besides these; unknown + * options are ignored. + */ + +/* + * Maximum size property that can be read at one time by this module: + */ #define MAX_PROP_WORDS 100000 @@ -178,7 +174,6 @@ static RegisteredInterp *interpListPtr = NULL; */ static int SendInit(Tcl_Interp *interp); - /* *-------------------------------------------------------------- @@ -186,34 +181,33 @@ static int SendInit(Tcl_Interp *interp); * Tk_SetAppName -- * * This procedure is called to associate an ASCII name with a Tk - * application. If the application has already been named, the - * name replaces the old one. + * application. If the application has already been named, the name + * replaces the old one. * * Results: - * The return value is the name actually given to the application. - * This will normally be the same as name, but if name was already - * in use for an application then a name of the form "name #2" will - * be chosen, with a high enough number to make the name unique. + * The return value is the name actually given to the application. This + * will normally be the same as name, but if name was already in use for + * an application then a name of the form "name #2" will be chosen, with + * a high enough number to make the name unique. * * Side effects: - * Registration info is saved, thereby allowing the "send" command - * to be used later to invoke commands in the application. In - * addition, the "send" command is created in the application's - * interpreter. The registration will be removed automatically - * if the interpreter is deleted or the "send" command is removed. + * Registration info is saved, thereby allowing the "send" command to be + * used later to invoke commands in the application. In addition, the + * "send" command is created in the application's interpreter. The + * registration will be removed automatically if the interpreter is + * deleted or the "send" command is removed. * *-------------------------------------------------------------- */ CONST char * Tk_SetAppName( - Tk_Window tkwin, /* Token for any window in the application - * to be named: it is just used to identify - * the application and the display. */ - CONST char *name) /* The name that will be used to - * refer to the interpreter in later - * "send" commands. Must be globally - * unique. */ + Tk_Window tkwin, /* Token for any window in the application to + * be named: it is just used to identify the + * application and the display. */ + CONST char *name) /* The name that will be used to refer to the + * interpreter in later "send" commands. Must + * be globally unique. */ { TkWindow *winPtr = (TkWindow *) tkwin; Tcl_Interp *interp = winPtr->mainPtr->interp; @@ -229,9 +223,9 @@ Tk_SetAppName( } /* - * See if the application is already registered; if so, remove its - * current name from the registry. The deletion of the command - * will take care of disposing of this entry. + * See if the application is already registered; if so, remove its current + * name from the registry. The deletion of the command will take care of + * disposing of this entry. */ for (riPtr = interpListPtr, prevPtr = NULL; riPtr != NULL; @@ -247,10 +241,9 @@ Tk_SetAppName( } /* - * Pick a name to use for the application. Use "name" if it's not - * already in use. Otherwise add a suffix such as " #2", trying - * larger and larger numbers until we eventually find one that is - * unique. + * Pick a name to use for the application. Use "name" if it's not already + * in use. Otherwise add a suffix such as " #2", trying larger and larger + * numbers until we eventually find one that is unique. */ actualName = name; @@ -301,8 +294,7 @@ Tk_SetAppName( * TODO: DeleteProc */ - Tcl_CreateObjCommand(interp, "send", Tk_SendObjCmd, - (ClientData) riPtr, NULL); + Tcl_CreateObjCommand(interp, "send", Tk_SendObjCmd, riPtr, NULL); if (Tcl_IsSafe(interp)) { Tcl_HideCommand(interp, "send", "send"); } @@ -316,8 +308,8 @@ Tk_SetAppName( * * Tk_SendObjCmd -- * - * This procedure is invoked to process the "send" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "send" Tcl command. See the + * user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -375,11 +367,10 @@ Tk_SendObjCmd( resultPtr = Tcl_GetObjResult(interp); /* - * See if the target interpreter is local. If so, execute - * the command directly without going through the DDE server. - * The only tricky thing is passing the result from the target - * interpreter to the invoking interpreter. Watch out: they - * could be the same! + * See if the target interpreter is local. If so, execute the command + * directly without going through the DDE server. The only tricky thing is + * passing the result from the target interpreter to the invoking + * interpreter. Watch out: they could be the same! */ for (riPtr = interpListPtr; (riPtr != NULL) @@ -387,29 +378,29 @@ Tk_SendObjCmd( /* * Empty loop body. */ - } if (riPtr != NULL) { /* - * This command is to a local interp. No need to go through - * the server. + * This command is to a local interp. No need to go through the + * server. */ Tcl_Interp *localInterp; - Tcl_Preserve((ClientData) riPtr); + Tcl_Preserve(riPtr); localInterp = riPtr->interp; - Tcl_Preserve((ClientData) localInterp); + Tcl_Preserve(localInterp); if (firstArg == (objc - 1)) { /* - * This might be one of those cases where the new - * parser is faster. + * This might be one of those cases where the new parser is + * faster. */ - result = Tcl_EvalObjEx(localInterp, objv[firstArg], TCL_EVAL_DIRECT); + result = Tcl_EvalObjEx(localInterp, objv[firstArg], + TCL_EVAL_DIRECT); } else { - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); + listObjPtr = Tcl_NewListObj(0, NULL); for (i = firstArg; i < objc; i++) { Tcl_ListObjAppendList(interp, listObjPtr, objv[i]); } @@ -425,9 +416,9 @@ Tk_SendObjCmd( * An error occurred, so transfer error information from the * destination interpreter back to our interpreter. Must clear * interp's result before calling Tcl_AddErrorInfo, since - * Tcl_AddErrorInfo will store the interp's result in errorInfo - * before appending riPtr's $errorInfo; we've already got - * everything we need in riPtr's $errorInfo. + * Tcl_AddErrorInfo will store the interp's result in + * errorInfo before appending riPtr's $errorInfo; we've + * already got everything we need in riPtr's $errorInfo. */ Tcl_ResetResult(interp); @@ -439,12 +430,12 @@ Tk_SendObjCmd( } Tcl_SetObjResult(interp, Tcl_GetObjResult(localInterp)); } - Tcl_Release((ClientData) riPtr); - Tcl_Release((ClientData) localInterp); + Tcl_Release(riPtr); + Tcl_Release(localInterp); } else { /* - * TODO: This is a non-local request. Send the script to the server and - * poll it for a result. + * TODO: This is a non-local request. Send the script to the server + * and poll it for a result. */ } @@ -456,15 +447,14 @@ Tk_SendObjCmd( * * TkGetInterpNames -- * - * This procedure is invoked to fetch a list of all the - * interpreter names currently registered for the display - * of a particular window. + * This procedure is invoked to fetch a list of all the interpreter names + * currently registered for the display of a particular window. * * Results: - * A standard Tcl return value. Interp->result will be set - * to hold a list of all the interpreter names defined for - * tkwin's display. If an error occurs, then TCL_ERROR - * is returned and interp->result will hold an error message. + * A standard Tcl return value. Interp->result will be set to hold a list + * of all the interpreter names defined for tkwin's display. If an error + * occurs, then TCL_ERROR is returned and interp->result will hold an + * error message. * * Side effects: * None. @@ -475,13 +465,13 @@ Tk_SendObjCmd( int TkGetInterpNames( Tcl_Interp *interp, /* Interpreter for returning a result. */ - Tk_Window tkwin) /* Window whose display is to be used - * for the lookup. */ + Tk_Window tkwin) /* Window whose display is to be used for the + * lookup. */ { Tcl_Obj *listObjPtr; RegisteredInterp *riPtr; - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); + listObjPtr = Tcl_NewListObj(0, NULL); riPtr = interpListPtr; while (riPtr != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, @@ -498,9 +488,8 @@ TkGetInterpNames( * * SendInit -- * - * This procedure is called to initialize the - * communication channels for sending commands and - * receiving results. + * This procedure is called to initialize the communication channels for + * sending commands and receiving results. * * Results: * None. @@ -513,8 +502,8 @@ TkGetInterpNames( static int SendInit( - Tcl_Interp *interp) /* Interpreter to use for error reporting - * (no errors are ever returned, but the + Tcl_Interp *interp) /* Interpreter to use for error reporting (no + * errors are ever returned, but the * interpreter is needed anyway). */ { return TCL_OK; diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 7fbde07..2a7d1a8 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-2007 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.63 2007/12/13 15:27:10 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.63.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -52,25 +52,24 @@ static const char *WmAttributeNames[] = { 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 const Tk_GeomMgr wmMgrType = { - "wm", /* name */ - TopLevelReqProc, /* requestProc */ - (Tk_GeomLostSlaveProc *) NULL, /* lostSlaveProc */ + "wm", /* name */ + TopLevelReqProc, /* requestProc */ + NULL, /* lostSlaveProc */ }; /* @@ -174,16 +173,14 @@ static WindowGroupRef WmGetWindowGroup(TkWindow *winPtr); static void GetMinSize(TkWindow *winPtr, int *minWidthPtr, int *minHeightPtr); static void GetMaxSize(TkWindow *winPtr, int *maxWidthPtr, int *maxHeightPtr); static void RemapWindows(TkWindow *winPtr, MacDrawable *parentWin); - /* *---------------------------------------------------------------------- * * TkWmNewWindow -- * - * This procedure is invoked whenever a new top-level - * window is created. Its job is to initialize the WmInfo - * structure for the window. + * This procedure is invoked whenever a new top-level window is created. + * Its job is to initialize the WmInfo structure for the window. * * Results: * None. @@ -198,9 +195,8 @@ void TkWmNewWindow( TkWindow *winPtr) /* Newly-created top-level window. */ { - WmInfo *wmPtr; + WmInfo *wmPtr = (WmInfo *) ckalloc(sizeof(WmInfo)); - wmPtr = (WmInfo *) ckalloc(sizeof(WmInfo)); wmPtr->winPtr = winPtr; wmPtr->reparent = None; wmPtr->titleUid = NULL; @@ -233,9 +229,9 @@ TkWmNewWindow( wmPtr->x = winPtr->changes.x; wmPtr->y = winPtr->changes.y; wmPtr->parentWidth = winPtr->changes.width - + 2*winPtr->changes.border_width; + + 2*winPtr->changes.border_width; wmPtr->parentHeight = winPtr->changes.height - + 2*winPtr->changes.border_width; + + 2*winPtr->changes.border_width; wmPtr->xInParent = 0; wmPtr->yInParent = 0; wmPtr->cmapList = NULL; @@ -259,16 +255,16 @@ TkWmNewWindow( UpdateVRootGeometry(wmPtr); /* - * Tk must monitor structure events for top-level windows, in order - * to detect size and position changes caused by window managers. + * Tk must monitor structure events for top-level windows, in order to + * detect size and position changes caused by window managers. */ Tk_CreateEventHandler((Tk_Window) winPtr, StructureNotifyMask, - TopLevelEventProc, (ClientData) winPtr); + TopLevelEventProc, winPtr); /* - * Arrange for geometry requests to be reflected from the window - * to the window manager. + * Arrange for geometry requests to be reflected from the window to the + * window manager. */ Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0); @@ -279,28 +275,28 @@ TkWmNewWindow( * * TkWmMapWindow -- * - * This procedure is invoked to map a top-level window. This - * module gets a chance to update all window-manager-related - * information in properties before the window manager sees - * the map event and checks the properties. It also gets to - * decide whether or not to even map the window after all. + * This procedure is invoked to map a top-level window. This module gets + * a chance to update all window-manager-related information in + * properties before the window manager sees the map event and checks the + * properties. It also gets to decide whether or not to even map the + * window after all. * * Results: * None. * * Side effects: - * Properties of winPtr may get updated to provide up-to-date - * information to the window manager. The window may also get - * mapped, but it may not be if this procedure decides that - * isn't appropriate (e.g. because the window is withdrawn). + * Properties of winPtr may get updated to provide up-to-date information + * to the window manager. The window may also get mapped, but it may not + * be if this procedure decides that isn't appropriate (e.g. because the + * window is withdrawn). * *---------------------------------------------------------------------- */ void TkWmMapWindow( - TkWindow *winPtr) /* Top-level window that's about to - * be mapped. */ + TkWindow *winPtr) /* Top-level window that's about to be + * mapped. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; @@ -310,6 +306,7 @@ TkWmMapWindow( /* * Create the underlying Mac window for this Tk window. */ + if (!TkMacOSXHostToplevelExists(winPtr)) { TkMacOSXMakeRealWindowExist(winPtr); } @@ -321,9 +318,8 @@ TkWmMapWindow( TK_LOCATION_CHANGED); /* - * This is the first time this window has ever been mapped. - * Store all the window-manager-related information for the - * window. + * This is the first time this window has ever been mapped. Store all + * the window-manager-related information for the window. */ if (wmPtr->titleUid == NULL) { @@ -357,11 +353,12 @@ TkWmMapWindow( /* * Update geometry information. */ + wmPtr->flags |= WM_ABOUT_TO_MAP; if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } - UpdateGeometryInfo((ClientData) winPtr); + UpdateGeometryInfo(winPtr); wmPtr->flags &= ~WM_ABOUT_TO_MAP; /* @@ -376,8 +373,8 @@ TkWmMapWindow( * * TkWmUnmapWindow -- * - * This procedure is invoked to unmap a top-level window. - * On the Macintosh all we do is call XUnmapWindow. + * This procedure is invoked to unmap a top-level window. On the + * Macintosh all we do is call XUnmapWindow. * * Results: * None. @@ -390,8 +387,8 @@ TkWmMapWindow( void TkWmUnmapWindow( - TkWindow *winPtr) /* Top-level window that's about to - * be mapped. */ + TkWindow *winPtr) /* Top-level window that's about to be + * mapped. */ { XUnmapWindow(winPtr->display, winPtr->window); } @@ -401,9 +398,8 @@ TkWmUnmapWindow( * * TkWmDeadWindow -- * - * This procedure is invoked when a top-level window is - * about to be deleted. It cleans up the wm-related data - * structures for the window. + * This procedure is invoked when a top-level window is about to be + * deleted. It cleans up the wm-related data structures for the window. * * Results: * None. @@ -450,7 +446,7 @@ TkWmDeadWindow( protPtr = wmPtr->protPtr; wmPtr->protPtr = protPtr->nextPtr; - Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC); + Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); } if (wmPtr->cmdArgv != NULL) { ckfree((char *) wmPtr->cmdArgv); @@ -459,7 +455,7 @@ TkWmDeadWindow( ckfree((char *) wmPtr->clientMachine); } if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } ckfree((char *) wmPtr); winPtr->wmInfoPtr = NULL; @@ -470,11 +466,10 @@ TkWmDeadWindow( * * TkWmSetClass -- * - * This procedure is invoked whenever a top-level window's - * class is changed. If the window has been mapped then this - * procedure updates the window manager property for the - * class. If the window hasn't been mapped, the update is - * deferred until just before the first mapping. + * This procedure is invoked whenever a top-level window's class is + * changed. If the window has been mapped then this procedure updates the + * window manager property for the class. If the window hasn't been + * mapped, the update is deferred until just before the first mapping. * * Results: * None. @@ -497,8 +492,8 @@ TkWmSetClass( * * Tk_WmObjCmd -- * - * This procedure is invoked to process the "wm" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm" Tcl command. See the + * user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -543,7 +538,7 @@ Tk_WmObjCmd( TkWindow *winPtr; if (objc < 2) { -wrongNumArgs: + wrongNumArgs: Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?"); return TCL_ERROR; } @@ -563,7 +558,7 @@ wrongNumArgs: } if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } @@ -576,78 +571,77 @@ wrongNumArgs: return TCL_ERROR; } if (!Tk_IsTopLevel(winPtr) - && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET) - ) { + && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET)) { Tcl_AppendResult(interp, "window \"", winPtr->pathName, "\" isn't a top-level window", NULL); return TCL_ERROR; } switch ((enum options) index) { - case WMOPT_ASPECT: - return WmAspectCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ATTRIBUTES: - return WmAttributesCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_CLIENT: - return WmClientCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_COLORMAPWINDOWS: - return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_COMMAND: - return WmCommandCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_DEICONIFY: - return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_FOCUSMODEL: - return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_FORGET: - return WmForgetCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_FRAME: - return WmFrameCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GEOMETRY: - return WmGeometryCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GRID: - return WmGridCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GROUP: - return WmGroupCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONBITMAP: - return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONIFY: - return WmIconifyCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONMASK: - return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONNAME: - return WmIconnameCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONPHOTO: - return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONPOSITION: - return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONWINDOW: - return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_MANAGE: - return WmManageCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_MAXSIZE: - return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_MINSIZE: - return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_OVERRIDEREDIRECT: - return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_POSITIONFROM: - return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_PROTOCOL: - return WmProtocolCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_RESIZABLE: - return WmResizableCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_SIZEFROM: - return WmSizefromCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_STACKORDER: - return WmStackorderCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_STATE: - return WmStateCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_TITLE: - return WmTitleCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_TRANSIENT: - return WmTransientCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_WITHDRAW: - return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ASPECT: + return WmAspectCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ATTRIBUTES: + return WmAttributesCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_CLIENT: + return WmClientCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_COLORMAPWINDOWS: + return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_COMMAND: + return WmCommandCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_DEICONIFY: + return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FOCUSMODEL: + return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FORGET: + return WmForgetCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FRAME: + return WmFrameCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GEOMETRY: + return WmGeometryCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GRID: + return WmGridCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GROUP: + return WmGroupCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONBITMAP: + return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONIFY: + return WmIconifyCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONMASK: + return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONNAME: + return WmIconnameCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONPHOTO: + return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONPOSITION: + return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONWINDOW: + return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MANAGE: + return WmManageCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MAXSIZE: + return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MINSIZE: + return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_OVERRIDEREDIRECT: + return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_POSITIONFROM: + return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_PROTOCOL: + return WmProtocolCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_RESIZABLE: + return WmResizableCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_SIZEFROM: + return WmSizefromCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_STACKORDER: + return WmStackorderCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_STATE: + return WmStateCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_TITLE: + return WmTitleCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_TRANSIENT: + return WmTransientCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_WITHDRAW: + return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv); } /* This should not happen */ @@ -659,8 +653,8 @@ wrongNumArgs: * * WmAspectCmd -- * - * This procedure is invoked to process the "wm aspect" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm aspect" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -702,15 +696,14 @@ WmAspectCmd( wmPtr->sizeHintsFlags &= ~PAspect; } else { if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) { return TCL_ERROR; } if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) || - (denom2 <= 0)) { - Tcl_SetResult(interp, "aspect number can't be <= 0", - TCL_STATIC); + (denom2 <= 0)) { + Tcl_SetResult(interp, "aspect number can't be <= 0", TCL_STATIC); return TCL_ERROR; } wmPtr->minAspect.x = numer1; @@ -729,17 +722,19 @@ WmAspectCmd( * * WmSetAttribute -- * - * Helper routine for WmAttributesCmd. Sets the value - * of the specified attribute. + * Helper routine for WmAttributesCmd. Sets the value of the specified + * attribute. * * Returns: * - * TCL_OK if successful, TCL_ERROR otherwise. In case of an - * error, leaves a message in the interpreter's result. + * TCL_OK if successful, TCL_ERROR otherwise. In case of an error, leaves + * a message in the interpreter's result. * *---------------------------------------------------------------------- */ -static int WmSetAttribute( + +static int +WmSetAttribute( TkWindow *winPtr, /* Toplevel to work with */ WindowRef macWindow, Tcl_Interp *interp, /* Current interpreter */ @@ -750,152 +745,150 @@ static int WmSetAttribute( int boolean; switch (attribute) { - case WMATT_ALPHA: { - double dval; + case WMATT_ALPHA: { + double dval; - if (Tcl_GetDoubleFromObj(interp, value, &dval) != TCL_OK) { - return TCL_ERROR; - } - /* - * The user should give (transparent) 0 .. 1.0 (opaque) - */ - if (dval < 0.0) { - dval = 0.0; - } else if (dval > 1.0) { - dval = 1.0; - } - ChkErr(SetWindowAlpha, macWindow, dval); - break; + if (Tcl_GetDoubleFromObj(interp, value, &dval) != TCL_OK) { + return TCL_ERROR; } - case WMATT_FULLSCREEN: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; - } - if (boolean != ((wmPtr->flags & WM_FULLSCREEN) != 0)) { - if(TkMacOSXMakeFullscreen(winPtr, macWindow, boolean, interp) - != TCL_OK) { - return TCL_ERROR; - } - } - break; - case WMATT_MODIFIED: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; - } - if (boolean != IsWindowModified(macWindow)) { - ChkErr(SetWindowModified, macWindow, boolean); - } - break; - case WMATT_NOTIFY: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + + /* + * The user should give (transparent) 0 .. 1.0 (opaque) + */ + + if (dval < 0.0) { + dval = 0.0; + } else if (dval > 1.0) { + dval = 1.0; + } + ChkErr(SetWindowAlpha, macWindow, dval); + break; + } + case WMATT_FULLSCREEN: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_FULLSCREEN) != 0)) { + if (TkMacOSXMakeFullscreen(winPtr, macWindow, boolean, interp) + != TCL_OK) { return TCL_ERROR; } - if (boolean == !tkMacOSXWmAttrNotifyVal) { - static NMRec notifyRec; - - if (boolean) { - bzero(¬ifyRec, sizeof(notifyRec)); - notifyRec.qType = nmType; - notifyRec.nmMark = 1; - ChkErr(NMInstall, ¬ifyRec); - } else { - ChkErr(NMRemove, ¬ifyRec); - } - tkMacOSXWmAttrNotifyVal = boolean; - } - break; - case WMATT_TITLEPATH: { - const char *path; - OSStatus err; - - path = Tcl_FSGetNativePath(value); - if (path && *path) { - FSRef ref; - Boolean d; - - err = ChkErr(FSPathMakeRef, (const unsigned char*) path, &ref, - &d); - if (err == noErr) { - TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, - err = ChkErr(HIWindowSetProxyFSRef, macWindow, &ref); - ) TK_ELSE_MAC_OS_X (4, - AliasHandle alias; - - err = ChkErr(FSNewAlias, NULL, &ref, &alias); - if (err == noErr) { - err = ChkErr(SetWindowProxyAlias, macWindow, - alias); - DisposeHandle((Handle) alias); - } - ) TK_ENDIF - } - } else { - int len; + } + break; + case WMATT_MODIFIED: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != IsWindowModified(macWindow)) { + ChkErr(SetWindowModified, macWindow, boolean); + } + break; + case WMATT_NOTIFY: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean == !tkMacOSXWmAttrNotifyVal) { + static NMRec notifyRec; - Tcl_GetStringFromObj(value, &len); - if (!len) { - err = ChkErr(RemoveWindowProxy, macWindow); - } else { - err = fnfErr; - } - } - if (err != noErr) { - return TCL_ERROR; + if (boolean) { + bzero(¬ifyRec, sizeof(notifyRec)); + notifyRec.qType = nmType; + notifyRec.nmMark = 1; + ChkErr(NMInstall, ¬ifyRec); + } else { + ChkErr(NMRemove, ¬ifyRec); } - break; + tkMacOSXWmAttrNotifyVal = boolean; } - case WMATT_TOPMOST: { - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; + break; + case WMATT_TITLEPATH: { + const char *path = Tcl_FSGetNativePath(value); + OSStatus err; + + if (path && *path) { + FSRef ref; + Boolean d; + + err = ChkErr(FSPathMakeRef, (const unsigned char*)path, &ref, &d); + if (err == noErr) { + TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, + err = ChkErr(HIWindowSetProxyFSRef, macWindow, &ref); + ) TK_ELSE_MAC_OS_X (4, + AliasHandle alias; + + err = ChkErr(FSNewAlias, NULL, &ref, &alias); + if (err == noErr) { + err = ChkErr(SetWindowProxyAlias, macWindow, alias); + DisposeHandle((Handle) alias); + } + ) TK_ENDIF } - if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) { - WindowGroupRef group; + } else { + int len; - if (boolean) { - wmPtr->flags |= WM_TOPMOST; - } else { - wmPtr->flags &= ~WM_TOPMOST; - } - group = WmGetWindowGroup(winPtr); - if (group && group != GetWindowGroup(macWindow)) { - ChkErr(SetWindowGroup, macWindow, group); - } + Tcl_GetStringFromObj(value, &len); + if (!len) { + err = ChkErr(RemoveWindowProxy, macWindow); + } else { + err = fnfErr; } - break; } - case WMATT_TRANSPARENT: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; + if (err != noErr) { + return TCL_ERROR; + } + break; + } + case WMATT_TOPMOST: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) { + WindowGroupRef group; + + if (boolean) { + wmPtr->flags |= WM_TOPMOST; + } else { + wmPtr->flags &= ~WM_TOPMOST; } - if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) { - WindowAttributes oldAttributes = wmPtr->attributes; - - if (boolean) { - wmPtr->flags |= WM_TRANSPARENT; - wmPtr->attributes |= kWindowNoShadowAttribute; - TK_IF_MAC_OS_X_API (3, HIWindowChangeFeatures, - UInt32 features; - - ChkErr(GetWindowFeatures, macWindow, &features); - if (features & kWindowIsOpaque) { - ChkErr(HIWindowChangeFeatures, macWindow, 0, - kWindowIsOpaque); - } - ) TK_ENDIF - } else { - wmPtr->flags &= ~WM_TRANSPARENT; - wmPtr->attributes &= ~kWindowNoShadowAttribute; - } - ApplyWindowClassAttributeChanges(winPtr, macWindow, - wmPtr->macClass, oldAttributes, 1); - ChkErr(ReshapeCustomWindow, macWindow); - TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window), - TK_PARENT_WINDOW); + group = WmGetWindowGroup(winPtr); + if (group && group != GetWindowGroup(macWindow)) { + ChkErr(SetWindowGroup, macWindow, group); } - break; - case _WMATT_LAST_ATTRIBUTE: - default: + } + break; + case WMATT_TRANSPARENT: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) { + WindowAttributes oldAttributes = wmPtr->attributes; + + if (boolean) { + wmPtr->flags |= WM_TRANSPARENT; + wmPtr->attributes |= kWindowNoShadowAttribute; + TK_IF_MAC_OS_X_API (3, HIWindowChangeFeatures, + UInt32 features; + + ChkErr(GetWindowFeatures, macWindow, &features); + if (features & kWindowIsOpaque) { + ChkErr(HIWindowChangeFeatures, macWindow, 0, + kWindowIsOpaque); + } + ) TK_ENDIF + } else { + wmPtr->flags &= ~WM_TRANSPARENT; + wmPtr->attributes &= ~kWindowNoShadowAttribute; + } + ApplyWindowClassAttributeChanges(winPtr, macWindow, + wmPtr->macClass, oldAttributes, 1); + ChkErr(ReshapeCustomWindow, macWindow); + TkMacOSXInvalidateWindow((MacDrawable *) winPtr->window, + TK_PARENT_WINDOW); + } + break; + case _WMATT_LAST_ATTRIBUTE: + default: + return TCL_ERROR; } return TCL_OK; } @@ -905,12 +898,14 @@ static int WmSetAttribute( * * WmGetAttribute -- * - * Helper routine for WmAttributesCmd. Returns the current value - * of the specified attribute. + * Helper routine for WmAttributesCmd. Returns the current value of the + * specified attribute. * *---------------------------------------------------------------------- */ -static Tcl_Obj *WmGetAttribute( + +static Tcl_Obj * +WmGetAttribute( TkWindow *winPtr, /* Toplevel to work with */ WindowRef macWindow, WmAttribute attribute) /* Code of attribute to get */ @@ -919,57 +914,56 @@ static Tcl_Obj *WmGetAttribute( Tcl_Obj *result = NULL; switch (attribute) { - case WMATT_ALPHA: { - float fval = 1.0; - - ChkErr(GetWindowAlpha, macWindow, &fval); - result = Tcl_NewDoubleObj(fval); - break; - } - case WMATT_FULLSCREEN: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN); - break; - case WMATT_MODIFIED: - result = Tcl_NewBooleanObj(IsWindowModified(macWindow)); - break; - case WMATT_NOTIFY: - result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal); - break; - case WMATT_TITLEPATH: { - FSRef ref; - UInt8 path[PATH_MAX+1]; - OSStatus err; - - TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, - err = ChkErr(HIWindowGetProxyFSRef, macWindow, &ref); - ) TK_ELSE_MAC_OS_X (4, - Boolean wasChanged; - AliasHandle alias; - - err = ChkErr(GetWindowProxyAlias, macWindow, &alias); - if (err == noErr) { - err = ChkErr(FSResolveAlias, NULL, alias, &ref, - &wasChanged); - } - ) TK_ENDIF + case WMATT_ALPHA: { + float fval = 1.0; + + ChkErr(GetWindowAlpha, macWindow, &fval); + result = Tcl_NewDoubleObj(fval); + break; + } + case WMATT_FULLSCREEN: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN); + break; + case WMATT_MODIFIED: + result = Tcl_NewBooleanObj(IsWindowModified(macWindow)); + break; + case WMATT_NOTIFY: + result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal); + break; + case WMATT_TITLEPATH: { + FSRef ref; + UInt8 path[PATH_MAX+1]; + OSStatus err; + + TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, + err = ChkErr(HIWindowGetProxyFSRef, macWindow, &ref); + ) TK_ELSE_MAC_OS_X (4, + Boolean wasChanged; + AliasHandle alias; + + err = ChkErr(GetWindowProxyAlias, macWindow, &alias); if (err == noErr) { - err = ChkErr(FSRefMakePath, &ref, path, PATH_MAX); + err = ChkErr(FSResolveAlias, NULL, alias, &ref, &wasChanged); } - if (err != noErr) { - *path = 0; - } - result = Tcl_NewStringObj((char*) path, -1); - break; + ) TK_ENDIF + if (err == noErr) { + err = ChkErr(FSRefMakePath, &ref, path, PATH_MAX); } - case WMATT_TOPMOST: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST); - break; - case WMATT_TRANSPARENT: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT); - break; - case _WMATT_LAST_ATTRIBUTE: - default: - break; + if (err != noErr) { + *path = 0; + } + result = Tcl_NewStringObj((char*) path, -1); + break; + } + case WMATT_TOPMOST: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST); + break; + case WMATT_TRANSPARENT: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT); + break; + case _WMATT_LAST_ATTRIBUTE: + default: + break; } return result; } @@ -1051,8 +1045,8 @@ WmAttributesCmd( * * WmClientCmd -- * - * This procedure is invoked to process the "wm client" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm client" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1096,8 +1090,7 @@ WmClientCmd( if (wmPtr->clientMachine != NULL) { ckfree((char *) wmPtr->clientMachine); } - wmPtr->clientMachine = (char *) - ckalloc((unsigned) (length + 1)); + wmPtr->clientMachine = ckalloc((unsigned) length + 1); strcpy(wmPtr->clientMachine, argv3); return TCL_OK; } @@ -1107,9 +1100,8 @@ WmClientCmd( * * WmColormapwindowsCmd -- * - * This procedure is invoked to process the "wm colormapwindows" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm colormapwindows" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1154,11 +1146,10 @@ WmColormapwindowsCmd( return TCL_ERROR; } cmapList = (TkWindow **) ckalloc((unsigned) - ((windowObjc+1)*sizeof(TkWindow*))); + ((windowObjc+1) * sizeof(TkWindow*))); for (i = 0; i < windowObjc; i++) { if (TkGetWindowFromObj(interp, tkwin, windowObjv[i], - (Tk_Window *) &winPtr2) != TCL_OK) - { + (Tk_Window *) &winPtr2) != TCL_OK) { ckfree((char *) cmapList); return TCL_ERROR; } @@ -1185,9 +1176,8 @@ WmColormapwindowsCmd( wmPtr->cmapCount = windowObjc; /* - * 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. */ return TCL_OK; @@ -1229,8 +1219,7 @@ WmCommandCmd( } if (objc == 3) { if (wmPtr->cmdArgv != NULL) { - Tcl_SetResult(interp, - Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv), + Tcl_SetResult(interp, Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv), TCL_DYNAMIC); } return TCL_OK; @@ -1280,6 +1269,7 @@ WmDeiconifyCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; + if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "window"); return TCL_ERROR; @@ -1342,7 +1332,7 @@ WmFocusmodelCmd( } if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_ACTIVE) { @@ -1371,15 +1361,15 @@ WmFocusmodelCmd( */ static int -WmForgetCmd(tkwin, winPtr, interp, objc, objv) - Tk_Window tkwin; /* Main window of the application. */ - TkWindow *winPtr; /* Toplevel or Frame to work with */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +WmForgetCmd( + Tk_Window tkwin, /* Main window of the application. */ + TkWindow *winPtr, /* Toplevel or Frame to work with */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { #if 1 - Tcl_AppendResult(interp, "wm forget is not yet supported", (char*)NULL); + Tcl_AppendResult(interp, "wm forget is not yet supported", NULL); return TCL_ERROR; #else register Tk_Window frameWin = (Tk_Window)winPtr; @@ -1393,8 +1383,8 @@ WmForgetCmd(tkwin, winPtr, interp, objc, objv) Tk_UnmapWindow(frameWin); if (destPort != NULL) { - WindowRef winRef; - winRef = GetWindowFromPort(destPort); + WindowRef winRef = GetWindowFromPort(destPort); + TkMacOSXUnregisterMacWindow(winRef); DisposeWindow(winRef); } @@ -1404,7 +1394,8 @@ WmForgetCmd(tkwin, winPtr, interp, objc, objv) RemapWindows(winPtr, macWin); TkWmDeadWindow(winPtr); - winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); + winPtr->flags &= + ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); TkMapTopFrame(frameWin); } else { @@ -1419,8 +1410,8 @@ WmForgetCmd(tkwin, winPtr, interp, objc, objv) * * WmFrameCmd -- * - * This procedure is invoked to process the "wm frame" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm frame" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1504,8 +1495,8 @@ WmGeometryCmd( width = winPtr->changes.width; height = winPtr->changes.height; } - sprintf(buf, "%dx%d%c%d%c%d", width, height, xSign, wmPtr->x, - ySign, wmPtr->y); + sprintf(buf, "%dx%d%c%d%c%d", + width, height, xSign, wmPtr->x, ySign, wmPtr->y); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_OK; } @@ -1524,8 +1515,8 @@ WmGeometryCmd( * * WmGridCmd -- * - * This procedure is invoked to process the "wm grid" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm grid" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1565,8 +1556,8 @@ WmGridCmd( } if (*Tcl_GetString(objv[3]) == '\0') { /* - * Turn off gridding and reset the width and height - * to make sense as ungridded numbers. + * Turn off gridding and reset the width and height to make sense as + * ungridded numbers. */ wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc); @@ -1580,9 +1571,9 @@ WmGridCmd( wmPtr->heightInc = 1; } else { if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[6], &heightInc) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[6], &heightInc)!=TCL_OK)) { return TCL_ERROR; } if (reqWidth < 0) { @@ -1614,8 +1605,8 @@ WmGridCmd( * * WmGroupCmd -- * - * This procedure is invoked to process the "wm group" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm group" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1829,8 +1820,7 @@ WmIconmaskCmd( } if (objc == 3) { if (wmPtr->hints.flags & IconMaskHint) { - Tcl_SetResult(interp, - (char*)Tk_NameOfBitmap(winPtr->display, + Tcl_SetResult(interp, (char *) Tk_NameOfBitmap(winPtr->display, wmPtr->hints.icon_mask), TCL_STATIC); } return TCL_OK; @@ -1886,8 +1876,7 @@ WmIconnameCmd( return TCL_ERROR; } if (objc == 3) { - Tcl_SetResult(interp, - (char*)((wmPtr->iconName != NULL) ? + Tcl_SetResult(interp, (char *) ((wmPtr->iconName != NULL) ? wmPtr->iconName : ""), TCL_STATIC); return TCL_OK; } else { @@ -1895,7 +1884,7 @@ WmIconnameCmd( ckfree((char *) wmPtr->iconName); } argv3 = Tcl_GetStringFromObj(objv[3], &length); - wmPtr->iconName = ckalloc((unsigned) (length + 1)); + wmPtr->iconName = ckalloc((unsigned) length + 1); strcpy(wmPtr->iconName, argv3); if (!(wmPtr->flags & WM_NEVER_MAPPED)) { XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName); @@ -1909,10 +1898,9 @@ WmIconnameCmd( * * WmIconphotoCmd -- * - * This procedure is invoked to process the "wm iconphoto" - * Tcl command. - * See the user documentation for details on what it does. - * Not yet implemented for OS X. + * This procedure is invoked to process the "wm iconphoto" Tcl command. + * See the user documentation for details on what it does. Not yet + * implemented for OS X. * * Results: * A standard Tcl result. @@ -1947,10 +1935,12 @@ WmIconphotoCmd( return TCL_ERROR; } } + /* * Iterate over all images to retrieve their sizes, in order to allocate a * buffer large enough to hold all images. */ + for (i = 3 + isDefault; i < objc; i++) { photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); if (photo == NULL) { @@ -1960,10 +1950,12 @@ WmIconphotoCmd( } Tk_PhotoGetSize(photo, &width, &height); } + /* - * This requires implementation for OS X, but we silently return - * for now. + * TODO: This requires implementation for OS X, but we silently return for + * now. */ + return TCL_OK; } @@ -1972,9 +1964,8 @@ WmIconphotoCmd( * * WmIconpositionCmd -- * - * This procedure is invoked to process the "wm iconposition" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm iconposition" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2112,8 +2103,8 @@ WmIconwindowCmd( * * WmManageCmd -- * - * This procedure is invoked to process the "wm manage" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm manage" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2133,7 +2124,7 @@ WmManageCmd( Tcl_Obj *CONST objv[]) /* Argument objects. */ { #if 1 - Tcl_AppendResult(interp, "wm manage is not yet supported", (char*)NULL); + Tcl_AppendResult(interp, "wm manage is not yet supported", NULL); return TCL_ERROR; #else register Tk_Window frameWin = (Tk_Window)winPtr; @@ -2159,8 +2150,9 @@ WmManageCmd( macWin->grafPtr = NULL; macWin->toplevel = macWin; RemapWindows(winPtr, macWin); - winPtr->flags |= (TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); - TkMapTopFrame (frameWin); + winPtr->flags |= + (TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); + TkMapTopFrame(frameWin); } else if (Tk_IsTopLevel(frameWin)) { /* Already managed by wm - ignore it */ } @@ -2260,7 +2252,7 @@ WmMinsizeCmd( return TCL_OK; } if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) { return TCL_ERROR; } wmPtr->minWidth = width; @@ -2275,9 +2267,8 @@ WmMinsizeCmd( * * WmOverrideredirectCmd -- * - * This procedure is invoked to process the "wm overrideredirect" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm overrideredirect" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2366,7 +2357,7 @@ WmPositionfromCmd( wmPtr->sizeHintsFlags &= ~(USPosition|PPosition); } else { if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_USER) { @@ -2421,6 +2412,7 @@ WmProtocolCmd( /* * Return a list of all defined protocols for the window. */ + for (protPtr = wmPtr->protPtr; protPtr != NULL; protPtr = protPtr->nextPtr) { Tcl_AppendElement(interp, @@ -2445,9 +2437,8 @@ 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; @@ -2458,7 +2449,7 @@ WmProtocolCmd( } else { prevPtr->nextPtr = protPtr->nextPtr; } - Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC); + Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); break; } } @@ -2546,7 +2537,7 @@ WmResizableCmd( } WmUpdateGeom(wmPtr, winPtr); ApplyWindowClassAttributeChanges(winPtr, NULL, wmPtr->macClass, - oldAttributes, 1); + oldAttributes, 1); return TCL_OK; } @@ -2599,7 +2590,7 @@ WmSizefromCmd( wmPtr->sizeHintsFlags &= ~(USSize|PSize); } else { if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_USER) { @@ -2656,13 +2647,13 @@ WmStackorderCmd( windows = TkWmStackorderToplevel(winPtr); if (windows == NULL) { Tcl_Panic("TkWmStackorderToplevel failed"); - } else { - for (window_ptr = windows; *window_ptr ; window_ptr++) { - Tcl_AppendElement(interp, (*window_ptr)->pathName); - } - ckfree((char *) windows); - return TCL_OK; } + + for (window_ptr = windows; *window_ptr ; window_ptr++) { + Tcl_AppendElement(interp, (*window_ptr)->pathName); + } + ckfree((char *) windows); + return TCL_OK; } else { TkWindow *winPtr2; int index1=-1, index2=-1, result; @@ -2691,9 +2682,8 @@ 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); @@ -2703,21 +2693,25 @@ WmStackorderCmd( return TCL_ERROR; } else { for (window_ptr = windows; *window_ptr ; window_ptr++) { - if (*window_ptr == winPtr) + if (*window_ptr == winPtr) { index1 = (window_ptr - windows); - if (*window_ptr == winPtr2) + } + if (*window_ptr == winPtr2) { index2 = (window_ptr - windows); + } } - if (index1 == -1) + if (index1 == -1) { Tcl_Panic("winPtr window not found"); - if (index2 == -1) + } + if (index2 == -1) { Tcl_Panic("winPtr2 window not found"); + } ckfree((char *) windows); } if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_ISABOVE) { @@ -2736,8 +2730,8 @@ WmStackorderCmd( * * WmStateCmd -- * - * This procedure is invoked to process the "wm state" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm state" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2818,18 +2812,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; } } } @@ -2841,8 +2835,8 @@ WmStateCmd( * * WmTitleCmd -- * - * This procedure is invoked to process the "wm title" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm title" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -3017,7 +3011,7 @@ WmInfo *wmPtr; TkWindow *winPtr; { if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3028,33 +3022,33 @@ TkWindow *winPtr; * 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; @@ -3094,15 +3088,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)) { @@ -3111,8 +3105,8 @@ Tk_SetGrid( } /* - * 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; @@ -3123,7 +3117,7 @@ Tk_SetGrid( wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc; wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3133,16 +3127,15 @@ 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. * *---------------------------------------------------------------------- */ @@ -3181,7 +3174,7 @@ Tk_UnsetGrid( wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3198,8 +3191,8 @@ 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. * *---------------------------------------------------------------------- */ @@ -3209,7 +3202,7 @@ TopLevelEventProc( ClientData clientData, /* Window for which event occurred. */ XEvent *eventPtr) /* Event that just happened. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; winPtr->wmInfoPtr->flags |= WM_VROOT_OFFSET_STALE; if (eventPtr->type == DestroyNotify) { @@ -3223,7 +3216,7 @@ TopLevelEventProc( */ Tk_ErrorHandler handler = Tk_CreateErrorHandler(winPtr->display, - -1, -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL); + -1, -1, -1, NULL, NULL); Tk_DestroyWindow((Tk_Window) winPtr); Tk_DeleteErrorHandler(handler); } @@ -3240,15 +3233,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). * *---------------------------------------------------------------------- */ @@ -3265,7 +3258,7 @@ TopLevelReqProc( wmPtr = winPtr->wmInfoPtr; wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3275,19 +3268,18 @@ 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. * *---------------------------------------------------------------------- */ @@ -3296,7 +3288,7 @@ static void UpdateGeometryInfo( ClientData clientData) /* Pointer to the window's record. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; WmInfo *wmPtr = winPtr->wmInfoPtr; int x, y, width, height, min, max; unsigned long serial; @@ -3308,14 +3300,12 @@ UpdateGeometryInfo( } /* - * 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) { @@ -3390,10 +3380,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) { @@ -3410,10 +3400,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) @@ -3427,22 +3417,21 @@ 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)) { @@ -3456,9 +3445,9 @@ UpdateGeometryInfo( /* * 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; @@ -3498,9 +3487,8 @@ 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. @@ -3518,8 +3506,6 @@ UpdateSizeHints( WmInfo *wmPtr = winPtr->wmInfoPtr; wmPtr->flags &= ~WM_UPDATE_SIZE_HINTS; - - return; } /* @@ -3527,13 +3513,12 @@ 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. @@ -3546,8 +3531,8 @@ ParseGeometry( Tcl_Interp *interp, /* Used for error reporting. */ 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; @@ -3563,9 +3548,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; @@ -3619,10 +3604,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) { @@ -3632,9 +3617,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; @@ -3654,12 +3639,12 @@ ParseGeometry( wmPtr->flags = flags; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } return TCL_OK; -error: + error: Tcl_AppendResult(interp, "bad geometry specifier \"", string, "\"", NULL); return TCL_ERROR; } @@ -3669,15 +3654,15 @@ error: * * 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. @@ -3695,9 +3680,8 @@ 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; @@ -3714,15 +3698,16 @@ Tk_GetRootCoords( 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; @@ -3733,12 +3718,12 @@ Tk_GetRootCoords( 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; @@ -3765,14 +3750,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: @@ -3783,19 +3768,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; @@ -3818,10 +3803,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; @@ -3888,13 +3873,12 @@ Tk_CoordsToWindow( * 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. + * 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 + * 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. * @@ -3906,15 +3890,15 @@ Tk_CoordsToWindow( Tk_Window Tk_TopCoordsToWindow( - Tk_Window tkwin, /* Token for a Tk Window which defines the; + 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) */ { 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. */ @@ -3979,24 +3963,23 @@ 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. * * Side effects: - * The vRootX, vRootY, vRootWidth, and vRootHeight fields in - * wmPtr are filled with the most up-to-date information. + * The vRootX, vRootY, vRootWidth, and vRootHeight fields in wmPtr are + * filled with the most up-to-date information. * *---------------------------------------------------------------------- */ static void UpdateVRootGeometry( - WmInfo *wmPtr) /* Window manager information to be - * updated. The wmPtr->vRoot field must - * be valid. */ + WmInfo *wmPtr) /* Window manager information to be updated. + * The wmPtr->vRoot field must be valid. */ { TkWindow *winPtr = wmPtr->winPtr; unsigned int bd, dummy; @@ -4022,8 +4005,7 @@ UpdateVRootGeometry( * Refresh the virtual root information if it's out of date. */ - handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, - (Tk_ErrorProc *) NULL, (ClientData) NULL); + handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, NULL, NULL); status = XGetGeometry(winPtr->display, wmPtr->vRoot, &dummy2, &wmPtr->vRootX, &wmPtr->vRootY, &wmPtr->vRootWidth, &wmPtr->vRootHeight, &bd, &dummy); @@ -4035,7 +4017,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; @@ -4048,16 +4030,15 @@ 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. @@ -4088,8 +4069,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) { @@ -4106,18 +4087,17 @@ 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). * *---------------------------------------------------------------------- */ @@ -4125,8 +4105,7 @@ 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; @@ -4145,16 +4124,15 @@ 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)) { if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } - UpdateGeometryInfo((ClientData) winPtr); + UpdateGeometryInfo(winPtr); } } @@ -4169,9 +4147,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. * *---------------------------------------------------------------------- */ @@ -4181,9 +4159,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; @@ -4194,15 +4172,15 @@ TkWmRestackToplevel( /* * 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); @@ -4212,6 +4190,7 @@ 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); @@ -4233,8 +4212,8 @@ TkWmRestackToplevel( */ } 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) { @@ -4277,27 +4256,26 @@ 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; TkWindow **oldPtr, **newPtr; @@ -4337,14 +4315,13 @@ 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*))); + newPtr = (TkWindow **) ckalloc((unsigned) (count+2)*sizeof(TkWindow *)); if (count > 0) { - memcpy(newPtr, oldPtr, count * sizeof(TkWindow*)); + memcpy(newPtr, oldPtr, count * sizeof(TkWindow *)); } if (count == 0) { count++; @@ -4359,9 +4336,8 @@ 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. */ } @@ -4371,16 +4347,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. * *---------------------------------------------------------------------- */ @@ -4398,8 +4374,8 @@ TkWmRemoveFromColormapWindows( 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; @@ -4410,16 +4386,15 @@ 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; @@ -4443,10 +4418,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. @@ -4456,8 +4431,8 @@ TkWmRemoveFromColormapWindows( void TkGetPointerCoords( - Tk_Window tkwin, /* Toplevel window that identifies screen - * on which lookup is to be done. */ + Tk_Window tkwin, /* Toplevel window that identifies screen on + * which lookup is to be done. */ int *xPtr, int *yPtr) /* Store pointer coordinates here. */ { XQueryPointer(NULL, None, NULL, NULL, xPtr, yPtr, NULL, NULL, NULL); @@ -4468,10 +4443,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. @@ -4527,9 +4502,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. @@ -4567,10 +4542,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. @@ -4689,8 +4664,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. @@ -4712,7 +4687,7 @@ TkSetWMName( return; } - title = CFStringCreateWithBytes(NULL, (const unsigned char*) titleUid, + title = CFStringCreateWithBytes(NULL, (const unsigned char *) titleUid, strlen(titleUid), kCFStringEncodingUTF8, false); if (title) { WindowRef macWin = TkMacOSXDrawableWindow(winPtr->window); @@ -4727,8 +4702,8 @@ TkSetWMName( * * 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. @@ -4786,10 +4761,9 @@ 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. @@ -4846,11 +4820,10 @@ 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. @@ -4915,13 +4888,12 @@ TkMacOSXZoomToplevel( } err = ChkErr(ZoomWindowIdeal, whichWindow, zoomPart, &idealSize); - if (err == noErr) { - wmPtr->hints.initial_state = - (zoomPart == inZoomIn ? NormalState : ZoomState); - return true; - } else { + if (err != noErr) { return false; } + wmPtr->hints.initial_state = + (zoomPart == inZoomIn ? NormalState : ZoomState); + return true; } /* @@ -4930,9 +4902,8 @@ 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. + * "::tk::unsupported::MacWindowStyle" Tcl command. This command allows + * you to set the style of decoration for a Macintosh window. * * Results: * A standard Tcl result. @@ -4946,11 +4917,10 @@ TkMacOSXZoomToplevel( /* ARGSUSED */ int TkUnsupported1ObjCmd( - ClientData clientData, /* Main window associated with - * interpreter. */ + ClientData clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj * const objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { static const char *subcmds[] = { "style", NULL @@ -4958,7 +4928,7 @@ TkUnsupported1ObjCmd( enum SubCmds { TKMWS_STYLE }; - Tk_Window tkwin = (Tk_Window) clientData; + Tk_Window tkwin = clientData; TkWindow *winPtr; int index; @@ -4967,8 +4937,8 @@ TkUnsupported1ObjCmd( return TCL_ERROR; } - winPtr = (TkWindow *) Tk_NameToWindow(interp, - Tcl_GetString(objv[2]), tkwin); + winPtr = (TkWindow *) + Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); if (winPtr == NULL) { return TCL_ERROR; } @@ -5000,9 +4970,8 @@ 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. + * "::tk::unsupported::MacWindowStyle style" subcommand. This command + * allows you to set the style of decoration for a Macintosh window. * * Results: * A standard Tcl result. @@ -5012,6 +4981,7 @@ TkUnsupported1ObjCmd( * *---------------------------------------------------------------------- */ + static int WmWinStyle( Tcl_Interp *interp, /* Current interpreter. */ @@ -5100,7 +5070,7 @@ WmWinStyle( if (objc == 3) { if (wmPtr->style != -1) { for (i = 0; styleMap[i].strValue != NULL; i++) { - if (wmPtr->style == (short)(styleMap[i].intValue)) { + if (wmPtr->style == (short) styleMap[i].intValue) { Tcl_SetObjResult(interp, Tcl_NewStringObj(styleMap[i].strValue, -1)); return TCL_OK; @@ -5201,8 +5171,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. @@ -5216,10 +5186,10 @@ 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; @@ -5239,8 +5209,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. @@ -5390,8 +5360,8 @@ 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. * * Results: * None. @@ -5426,9 +5396,8 @@ 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. @@ -5461,9 +5430,8 @@ 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. @@ -5495,15 +5463,15 @@ TkMacOSXSetScrollbarGrow( * 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. @@ -5527,13 +5495,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. @@ -5557,8 +5525,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. @@ -5570,9 +5538,9 @@ TkpGetWrapperWindow( */ void -TkpWmSetState(winPtr, state) - TkWindow *winPtr; /* Toplevel window to operate on. */ - int state; /* One of IconicState, ZoomState, NormalState, +TkpWmSetState( + TkWindow *winPtr, /* Toplevel window to operate on. */ + int state) /* One of IconicState, ZoomState, NormalState, * or WithdrawnState. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; @@ -5589,9 +5557,10 @@ TkpWmSetState(winPtr, state) 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); } @@ -5669,9 +5638,9 @@ TkMacOSXWindowClass( * * TkMacOSXWindowOffset -- * - * 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. + * 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. * * Results: * The x & y offset in pixels. @@ -5704,8 +5673,8 @@ TkMacOSXWindowOffset( * * 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. @@ -5758,15 +5727,14 @@ 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. @@ -5775,15 +5743,15 @@ XSetInputFocus( */ int -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. */ +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. */ { /* - * 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) { @@ -5791,10 +5759,10 @@ TkpChangeFocus(winPtr, force) } /* - * 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); @@ -5805,13 +5773,12 @@ TkpChangeFocus(winPtr, force) * * 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. @@ -5838,7 +5805,7 @@ WmStackorderToplevelWrapperMap( macWindow = TkMacOSXDrawableWindow(winPtr->window); hPtr = Tcl_CreateHashEntry(table, - (const char *) macWindow, &newEntry); + (const char *) macWindow, &newEntry); Tcl_SetHashValue(hPtr, winPtr); } @@ -5856,8 +5823,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. @@ -5866,8 +5833,8 @@ WmStackorderToplevelWrapperMap( */ TkWindow ** -TkWmStackorderToplevel(parentPtr) - TkWindow *parentPtr; /* Parent toplevel window. */ +TkWmStackorderToplevel( + TkWindow *parentPtr) /* Parent toplevel window. */ { WindowRef frontWindow; TkWindow *childWinPtr, **windows, **window_ptr; @@ -5882,12 +5849,12 @@ TkWmStackorderToplevel(parentPtr) 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) { @@ -5896,7 +5863,7 @@ TkWmStackorderToplevel(parentPtr) goto done; case 1: hPtr = Tcl_FirstHashEntry(&table, &search); - windows[0] = (TkWindow *) Tcl_GetHashValue(hPtr); + windows[0] = Tcl_GetHashValue(hPtr); windows[1] = NULL; goto done; } @@ -5908,20 +5875,21 @@ TkWmStackorderToplevel(parentPtr) } else { window_ptr = windows + table.numEntries; *window_ptr-- = NULL; - while (frontWindow != NULL) { - hPtr = Tcl_FindHashEntry(&table, (char *) frontWindow); - if (hPtr != NULL) { - childWinPtr = (TkWindow *) Tcl_GetHashValue(hPtr); - *window_ptr-- = childWinPtr; - } - frontWindow = GetNextWindow(frontWindow); + while (frontWindow != NULL) { + hPtr = Tcl_FindHashEntry(&table, (char *) frontWindow); + if (hPtr != NULL) { + childWinPtr = (TkWindow *) Tcl_GetHashValue(hPtr); + *window_ptr-- = childWinPtr; } - if (window_ptr != (windows-1)) + frontWindow = GetNextWindow(frontWindow); + } + if (window_ptr != (windows-1)) { Tcl_Panic("num matched toplevel windows does not equal num " "children"); + } } - done: + done: Tcl_DeleteHashTable(&table); return windows; } @@ -5998,7 +5966,7 @@ ApplyWindowClassAttributeChanges( } } TkMacOSXInvalClipRgns((Tk_Window) winPtr); - TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window), + TkMacOSXInvalidateWindow((MacDrawable *) winPtr->window, TK_PARENT_WINDOW); } @@ -6006,6 +5974,7 @@ ApplyWindowClassAttributeChanges( * The change of window class/attributes might have changed the window * structure widths: */ + GetWindowStructureWidths(macWindow, &strWidths); wmPtr->xInParent = strWidths.left; wmPtr->yInParent = strWidths.top; @@ -6068,7 +6037,7 @@ ApplyMasterOverrideChanges( WindowGroupRef group; ApplyWindowClassAttributeChanges(winPtr, macWindow, oldClass, - oldAttributes, 0); + oldAttributes, 0); if (winPtr->atts.override_redirect && wmPtr->master != None) { wmPtr->flags |= WM_TOPMOST; @@ -6109,8 +6078,8 @@ WmGetWindowGroup( group = GetWindowGroupOfClass(kUtilityWindowClass); } else if (wmPtr->master != None) { TkDisplay *dispPtr = TkGetDisplayList(); - TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, - wmPtr->master); + TkWindow *masterWinPtr = (TkWindow *) + Tk_IdToWindow(dispPtr->display, wmPtr->master); if (masterWinPtr && masterWinPtr->window != None && TkMacOSXHostToplevelExists(masterWinPtr)) { @@ -6165,9 +6134,11 @@ TkMacOSXMakeFullscreen( if (fullscreen) { int screenWidth = WidthOfScreen(Tk_Screen(winPtr)); int screenHeight = HeightOfScreen(Tk_Screen(winPtr)); + /* * Check max width and height if set by the user. */ + if ((wmPtr->maxWidth > 0 && wmPtr->maxWidth < screenWidth) || (wmPtr->maxHeight > 0 && wmPtr->maxHeight < screenHeight)) { if (interp) { @@ -6272,8 +6243,8 @@ TkMacOSXEnterExitFullscreen( * * GetMinSize -- * - * This function computes the current minWidth and minHeight values for - * a window, taking into account the possibility that they may be + * This function computes the current minWidth and minHeight values for a + * window, taking into account the possibility that they may be * defaulted. * * Results: @@ -6307,41 +6278,43 @@ GetMinSize( */ switch (wmPtr->macClass) { - case kDocumentWindowClass: - case kMovableAlertWindowClass: - case kMovableModalWindowClass: - minWidth = 72; - if (wmPtr->attributes & kWindowResizableAttribute) { - minHeight = 15; - } - if (wmPtr->attributes & kWindowToolbarButtonAttribute) { - minWidth += 29; - } - break; - case kFloatingWindowClass: - case kUtilityWindowClass: - minWidth = 59; - if (wmPtr->attributes & kWindowResizableAttribute) { - minHeight = 11; - } - if (wmPtr->attributes & kWindowSideTitlebarAttribute) { - int tmp = minWidth; - minWidth = minHeight; - minHeight = tmp; - } else if (wmPtr->attributes & kWindowToolbarButtonAttribute) { - minWidth += 29; - } - break; - default: - if (wmPtr->attributes & kWindowResizableAttribute) { - minWidth = 15; - minHeight = 15; - } - break; + case kDocumentWindowClass: + case kMovableAlertWindowClass: + case kMovableModalWindowClass: + minWidth = 72; + if (wmPtr->attributes & kWindowResizableAttribute) { + minHeight = 15; + } + if (wmPtr->attributes & kWindowToolbarButtonAttribute) { + minWidth += 29; + } + break; + case kFloatingWindowClass: + case kUtilityWindowClass: + minWidth = 59; + if (wmPtr->attributes & kWindowResizableAttribute) { + minHeight = 11; + } + if (wmPtr->attributes & kWindowSideTitlebarAttribute) { + int tmp = minWidth; + + minWidth = minHeight; + minHeight = tmp; + } else if (wmPtr->attributes & kWindowToolbarButtonAttribute) { + minWidth += 29; + } + break; + default: + if (wmPtr->attributes & kWindowResizableAttribute) { + minWidth = 15; + minHeight = 15; + } + break; } if (wmPtr->gridWin != NULL) { int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc); + if (base < 0) { base = 0; } @@ -6367,8 +6340,8 @@ GetMinSize( * * GetMaxSize -- * - * This function computes the current maxWidth and maxHeight values for - * a window, taking into account the possibility that they may be + * This function computes the current maxWidth and maxHeight values for a + * window, taking into account the possibility that they may be * defaulted. * * Results: @@ -6398,6 +6371,7 @@ GetMaxSize( *maxWidthPtr = wmPtr->maxWidth; } else { int maxWidth = maxBounds->right - maxBounds->left - wmPtr->xInParent; + if (wmPtr->gridWin != NULL) { maxWidth = wmPtr->reqGridWidth + (maxWidth - winPtr->reqWidth)/wmPtr->widthInc; @@ -6408,6 +6382,7 @@ GetMaxSize( *maxHeightPtr = wmPtr->maxHeight; } else { int maxHeight = maxBounds->bottom - maxBounds->top - wmPtr->yInParent; + if (wmPtr->gridWin != NULL) { maxHeight = wmPtr->reqGridHeight + (maxHeight - winPtr->reqHeight)/wmPtr->heightInc; @@ -6421,8 +6396,7 @@ GetMaxSize( * * RemapWindows * - * Adjust parent/child relation ships of - * the given window hierarchy. + * Adjust parent/child relation ships of the given window hierarchy. * * Results: * none @@ -6432,16 +6406,22 @@ GetMaxSize( * *---------------------------------------------------------------------- */ + static void -RemapWindows(TkWindow *winPtr, MacDrawable *parentWin) +RemapWindows( + TkWindow *winPtr, + MacDrawable *parentWin) { TkWindow *childPtr; - /* Remove the OS specific window. - * It will get rebuilt when the window gets Mapped. + /* + * Remove the OS specific window. It will get rebuilt when the window gets + * Mapped. */ + if (winPtr->window != None) { MacDrawable *macWin = (MacDrawable *) winPtr->window; + macWin->grafPtr = NULL; macWin->toplevel = parentWin->toplevel; winPtr->flags &= ~TK_MAPPED; diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c index 2e66cb4..f7f0f8a 100644 --- a/macosx/tkMacOSXXStubs.c +++ b/macosx/tkMacOSXXStubs.c @@ -1,19 +1,19 @@ /* * tkMacOSXXStubs.c -- * - * This file contains most of the X calls called by Tk. Many of - * these calls are just stubs and either don't make sense on the - * Macintosh or thier implamentation just doesn't do anything. Other - * calls will eventually be moved into other files. + * This file contains most of the X calls called by Tk. Many of these + * calls are just stubs and either don't make sense on the Macintosh or + * their implamentation just doesn't do anything. Other calls will + * eventually be moved into other files. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2005-2007 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: tkMacOSXXStubs.c,v 1.25 2007/12/13 15:27:10 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXXStubs.c,v 1.25.2.1 2008/05/03 21:09:16 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -23,8 +23,8 @@ /* * Because this file is still under major development Debugger statements are - * used through out this file. The define TCL_DEBUG will decide whether - * the debugger statements actually call the debugger or not. + * used through out this file. The define TCL_DEBUG will decide whether the + * debugger statements actually call the debugger or not. */ #ifndef TCL_DEBUG @@ -37,29 +37,32 @@ * Declarations of static variables used in this file. */ -static TkDisplay *gMacDisplay = NULL; /* Macintosh display. */ -static const char *macScreenName = ":0"; /* Default name of macintosh display. */ +static TkDisplay *gMacDisplay = NULL; + /* Macintosh display. */ +static const char *macScreenName = ":0"; + /* Default name of macintosh display. */ /* * Forward declarations of procedures used in this file. */ -static XID MacXIdAlloc(Display *display); -static int DefaultErrorHandler(Display* display, XErrorEvent* err_evt); +static XID MacXIdAlloc(Display *display); +static int DefaultErrorHandler(Display *display, + XErrorEvent *err_evt); /* * Other declarations */ -static int DestroyImage(XImage *image); -static unsigned long ImageGetPixel(XImage *image, int x, int y); -static int PutPixel(XImage *image, int x, int y, unsigned long pixel); +static int DestroyImage(XImage *image); +static unsigned long ImageGetPixel(XImage *image, int x, int y); +static int PutPixel(XImage *image, int x, int y, + unsigned long pixel); #if 0 -static XImage *SubImage(XImage *image, int x, int y, - unsigned int width, unsigned int height); -static int AddPixel(XImage *image, long value); +static XImage * SubImage(XImage *image, int x, int y, + unsigned int width, unsigned int height); +static int AddPixel(XImage *image, long value); #endif - /* *---------------------------------------------------------------------- @@ -79,7 +82,8 @@ static int AddPixel(XImage *image, long value); */ void -TkMacOSXDisplayChanged(Display *display) +TkMacOSXDisplayChanged( + Display *display) { GDHandle graphicsDevice; Screen *screen; @@ -91,17 +95,17 @@ TkMacOSXDisplayChanged(Display *display) screen = display->screens; graphicsDevice = GetMainDevice(); - screen->root_depth = (*(*graphicsDevice)->gdPMap)->cmpSize * - (*(*graphicsDevice)->gdPMap)->cmpCount; - screen->height = (*graphicsDevice)->gdRect.bottom - - (*graphicsDevice)->gdRect.top; - screen->width = (*graphicsDevice)->gdRect.right - - (*graphicsDevice)->gdRect.left; + screen->root_depth = (*(*graphicsDevice)->gdPMap)->cmpSize * + (*(*graphicsDevice)->gdPMap)->cmpCount; + screen->height = (*graphicsDevice)->gdRect.bottom - + (*graphicsDevice)->gdRect.top; + screen->width = (*graphicsDevice)->gdRect.right - + (*graphicsDevice)->gdRect.left; - screen->mwidth = (screen->width * 254 + 360) / 720; - screen->mheight = (screen->height * 254 + 360) / 720; + screen->mwidth = (screen->width * 254 + 360) / 720; + screen->mheight = (screen->height * 254 + 360) / 720; - maxBounds = (Rect*) screen->ext_data; + maxBounds = (Rect *) screen->ext_data; *maxBounds = bounds; graphicsDevice = GetDeviceList(); while (graphicsDevice) { @@ -121,8 +125,8 @@ TkMacOSXDisplayChanged(Display *display) * * TkpOpenDisplay -- * - * Create the Display structure and fill it with device - * specific information. + * Create the Display structure and fill it with device specific + * information. * * Results: * Returns a Display structure on success or NULL on failure. @@ -162,13 +166,13 @@ TkpOpenDisplay( display->screens = screen; display->nscreens = 1; display->default_screen = 0; - display->display_name = (char*)macScreenName; + display->display_name = (char *) macScreenName; - Gestalt(gestaltQuickdrawVersion, (long*)&display->proto_minor_version); + Gestalt(gestaltQuickdrawVersion, (long *) &display->proto_minor_version); display->proto_major_version = 10; display->proto_minor_version -= gestaltMacOSXQD; display->vendor = "Apple"; - Gestalt(gestaltSystemVersion, (long*)&display->release); + Gestalt(gestaltSystemVersion, (long *) &display->release); /* * These screen bits never change @@ -177,7 +181,7 @@ TkpOpenDisplay( screen->display = display; screen->black_pixel = 0x00000000 | PIXEL_MAGIC << 24; screen->white_pixel = 0x00FFFFFF | PIXEL_MAGIC << 24; - screen->ext_data = (XExtData*) &maxBounds; + screen->ext_data = (XExtData *) &maxBounds; screen->root_visual = (Visual *) ckalloc(sizeof(Visual)); screen->root_visual->visualid = 0; @@ -191,13 +195,14 @@ TkpOpenDisplay( /* * Initialize screen bits that may change */ + TkMacOSXDisplayChanged(display); gMacDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay)); /* - * This is the quickest way to make sure that all the *Init - * flags get properly initialized + * This is the quickest way to make sure that all the *Init flags get + * properly initialized */ bzero(gMacDisplay, sizeof(TkDisplay)); @@ -226,13 +231,14 @@ TkpCloseDisplay( TkDisplay *displayPtr) { Display *display = displayPtr->display; + if (gMacDisplay != displayPtr) { Tcl_Panic("TkpCloseDisplay: tried to call TkpCloseDisplay on bad display"); } gMacDisplay = NULL; - if (display->screens != (Screen *) NULL) { - if (display->screens->root_visual != (Visual *) NULL) { + if (display->screens != NULL) { + if (display->screens->root_visual != NULL) { ckfree((char *) display->screens->root_visual); } ckfree((char *) display->screens); @@ -245,11 +251,10 @@ TkpCloseDisplay( * * TkClipCleanup -- * - * This procedure is called to cleanup resources associated with - * claiming clipboard ownership and for receiving selection get - * results. This function is called in tkWindow.c. This has to be - * called by the display cleanup function because we still need the - * access display elements. + * This procedure is called to cleanup resources associated with claiming + * clipboard ownership and for receiving selection get results. This + * function is called in tkWindow.c. This has to be called by the display + * cleanup function because we still need the access display elements. * * Results: * None. @@ -261,12 +266,12 @@ TkpCloseDisplay( */ void -TkClipCleanup(dispPtr) - TkDisplay *dispPtr; /* display associated with clipboard */ +TkClipCleanup( + TkDisplay *dispPtr) /* display associated with clipboard */ { /* - * Make sure that the local scrap is transfered to the global - * scrap if needed. + * Make sure that the local scrap is transfered to the global scrap if + * needed. */ TkSuspendClipboard(); @@ -278,7 +283,7 @@ TkClipCleanup(dispPtr) dispPtr->windowAtom); Tk_DestroyWindow(dispPtr->clipWindow); - Tcl_Release((ClientData) dispPtr->clipWindow); + Tcl_Release(dispPtr->clipWindow); dispPtr->clipWindow = NULL; } } @@ -288,31 +293,31 @@ TkClipCleanup(dispPtr) * * MacXIdAlloc -- * - * This procedure is invoked by Xlib as the resource allocator - * for a display. + * This procedure is invoked by Xlib as the resource allocator for a + * display. * * Results: - * The return value is an X resource identifier that isn't currently - * in use. + * The return value is an X resource identifier that isn't currently in + * use. * * Side effects: - * The identifier is removed from the stack of free identifiers, - * if it was previously on the stack. + * The identifier is removed from the stack of free identifiers, if it + * was previously on the stack. * *---------------------------------------------------------------------- */ static XID MacXIdAlloc( - Display *display) /* Display for which to allocate. */ + Display *display) /* Display for which to allocate. */ { - static long int cur_id = 100; - /* - * Some special XIds are reserved - * - this is why we start at 100 - */ + static long int cur_id = 100; + /* + * Some special XIds are reserved + * - this is why we start at 100 + */ - return ++cur_id; + return ++cur_id; } /* @@ -347,8 +352,8 @@ TkpWindowWasRecentlyDeleted( * * DefaultErrorHandler -- * - * This procedure is the default X error handler. Tk uses it's - * own error handler so this call should never be called. + * This procedure is the default X error handler. Tk uses it's own error + * handler so this call should never be called. * * Results: * None. @@ -365,14 +370,14 @@ DefaultErrorHandler( XErrorEvent* err_evt) { /* - * This call should never be called. Tk replaces - * it with its own error handler. + * This call should never be called. Tk replaces it with its own error + * handler. */ + Tcl_Panic("Warning hit bogus error handler!"); return 0; } - char * XGetAtomName( Display * display, @@ -383,7 +388,8 @@ XGetAtomName( } int -_XInitImageFuncPtrs(XImage *image) +_XInitImageFuncPtrs( + XImage *image) { return 0; } @@ -396,24 +402,25 @@ XSetErrorHandler( } Window -XRootWindow(Display *display, int screen_number) +XRootWindow( + Display *display, + int screen_number) { display->request++; return ROOT_ID; } int -XGetGeometry(display, d, root_return, x_return, y_return, width_return, - height_return, border_width_return, depth_return) - Display* display; - Drawable d; - Window* root_return; - int* x_return; - int* y_return; - unsigned int* width_return; - unsigned int* height_return; - unsigned int* border_width_return; - unsigned int* depth_return; +XGetGeometry( + Display *display, + Drawable d, + Window *root_return, + int *x_return, + int *y_return, + unsigned int *width_return, + unsigned int *height_return, + unsigned int *border_width_return, + unsigned int *depth_return) { TkWindow *winPtr = ((MacDrawable *) d)->winPtr; @@ -488,8 +495,8 @@ XSizeHints * XAllocSizeHints(void) { /* - * Always return NULL. Tk code checks to see if NULL - * is returned & does nothing if it is. + * Always return NULL. Tk code checks to see if NULL is returned & does + * nothing if it is. */ return NULL; @@ -670,10 +677,11 @@ XForceScreenSaver( int mode) { /* - * This function is just a no-op. It is defined to - * reset the screen saver. However, there is no real - * way to do this on a Mac. Let me know if there is! + * This function is just a no-op. It is defined to reset the screen saver. + * However, there is no real way to do this on a Mac. Let me know if there + * is! */ + display->request++; } @@ -727,9 +735,9 @@ XSetClipRectangles( * * TkGetServerInfo -- * - * Given a window, this procedure returns information about - * the window server for that window. This procedure provides - * the guts of the "winfo server" command. + * Given a window, this procedure returns information about the window + * server for that window. This procedure provides the guts of the "winfo + * server" command. * * Results: * None. @@ -742,10 +750,10 @@ XSetClipRectangles( void TkGetServerInfo( - Tcl_Interp *interp, /* The server information is returned in - * this interpreter's result. */ - Tk_Window tkwin) /* Token for window; this selects a - * particular display and server. */ + Tcl_Interp *interp, /* The server information is returned in this + * interpreter's result. */ + Tk_Window tkwin) /* Token for window; this selects a particular + * display and server. */ { char buffer[8 + TCL_INTEGER_SPACE * 2]; char buffer2[TCL_INTEGER_SPACE]; @@ -880,11 +888,15 @@ XGetImage( if (TkMacOSXGetDrawablePort(d)) { if (format == ZPixmap) { if (width > 0 && height > 0) { - /* Tk_GetPixmap fails for zero width or height */ + /* + * Tk_GetPixmap fails for zero width or height. + */ + pixmap = Tk_GetPixmap(display, d, width, height, depth); } if (win) { XGCValues values; + gc = Tk_GetGC(win, 0, &values); } else { gc = XCreateGC(display, pixmap, 0, NULL); @@ -893,18 +905,22 @@ XGetImage( XCopyArea(display, d, pixmap, gc, x, y, width, height, 0, 0); } imagePtr = XCreateImage(display, NULL, depth, format, offset, - (char*)TkMacOSXGetDrawablePort(pixmap), - width, height, bitmap_pad, bytes_per_line); - /* Track Pixmap underlying the XImage in the unused obdata field * - * so that we can treat XImages coming from XGetImage specially. */ + (char *) TkMacOSXGetDrawablePort(pixmap), + width, height, bitmap_pad, bytes_per_line); + + /* + * Track Pixmap underlying the XImage in the unused obdata field + * so that we can treat XImages coming from XGetImage specially. + */ + imagePtr->obdata = (XPointer) pixmap; if (!win) { XFreeGC(display, gc); } } else { TkpDisplayWarning( - "XGetImage: only ZPixmap types are implemented", - "XGetImage Failure"); + "XGetImage: only ZPixmap types are implemented", + "XGetImage Failure"); } } return imagePtr; @@ -968,11 +984,14 @@ ImageGetPixel( RGBColor cPix; unsigned long r, g, b, c; - destPort = (CGrafPtr)image->data; + destPort = (CGrafPtr) image->data; portChanged = QDSwapPort(destPort, &savePort); GetCPixel(x, y, &cPix); if (image->obdata) { - /* Image from XGetImage, 16 bit color values */ + /* + * Image from XGetImage, 16 bit color values. + */ + r = (cPix . red) >> 8; g = (cPix . green) >> 8; b = (cPix . blue) >> 8; @@ -1018,18 +1037,21 @@ PutPixel( destPort = (CGrafPtr)image->data; portChanged = QDSwapPort(destPort, &savePort); - r = (pixel & image->red_mask)>>16; - g = (pixel & image->green_mask)>>8; - b = (pixel & image->blue_mask); + r = (pixel & image->red_mask)>>16; + g = (pixel & image->green_mask)>>8; + b = (pixel & image->blue_mask); if (image->obdata) { - /* Image from XGetImage, 16 bit color values */ - cPix . red = r << 8; - cPix . green = g << 8; - cPix . blue = b << 8; + /* + * Image from XGetImage, 16 bit color values. + */ + + cPix.red = r << 8; + cPix.green = g << 8; + cPix.blue = b << 8; } else { - cPix . red = r; - cPix . green = g; - cPix . blue = b; + cPix.red = r; + cPix.green = g; + cPix.blue = b; } SetCPixel(x, y, &cPix); if (portChanged) { @@ -1068,8 +1090,8 @@ AddPixel( * XSetWindowBackgroundPixmap, XSetWindowBorder, XSetWindowBorderPixmap, * XSetWindowBorderWidth, XSetWindowColormap * - * These functions are all no-ops. They all have equivilent - * Tk calls that should always be used instead. + * These functions are all no-ops. They all have equivalent Tk calls that + * should always be used instead. * * Results: * None. @@ -1202,8 +1224,8 @@ TkGetDefaultScreenName( * Return the number of milliseconds the user was inactive. * * Results: - * The number of milliseconds the user has been inactive, - * or -1 if querying the inactive time is not supported. + * The number of milliseconds the user has been inactive, or -1 if + * querying the inactive time is not supported. * * Side effects: * None. @@ -1211,13 +1233,15 @@ TkGetDefaultScreenName( */ long -Tk_GetUserInactiveTime(Display *dpy) +Tk_GetUserInactiveTime( + Display *dpy) { io_registry_entry_t regEntry; CFMutableDictionaryRef props = NULL; CFTypeRef timeObj; long ret = -1l; uint64_t time; + IOReturn result; regEntry = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem")); @@ -1226,7 +1250,7 @@ Tk_GetUserInactiveTime(Display *dpy) return -1l; } - IOReturn result = IORegistryEntryCreateCFProperties(regEntry, &props, + result = IORegistryEntryCreateCFProperties(regEntry, &props, kCFAllocatorDefault, 0); IOObjectRelease(regEntry); @@ -1244,13 +1268,13 @@ Tk_GetUserInactiveTime(Display *dpy) CFRangeMake(0, sizeof(time)), (UInt8 *) &time); /* Convert nanoseconds to milliseconds. */ /* ret /= kMillisecondScale; */ - ret = (long)(time/kMillisecondScale); + ret = (long) (time/kMillisecondScale); } else if (type == CFNumberGetTypeID()) { /* Panther+ */ CFNumberGetValue((CFNumberRef)timeObj, kCFNumberSInt64Type, &time); /* Convert nanoseconds to milliseconds. */ /* ret /= kMillisecondScale; */ - ret = (long)(time/kMillisecondScale); + ret = (long) (time/kMillisecondScale); } else { ret = -1l; } @@ -1272,14 +1296,15 @@ Tk_GetUserInactiveTime(Display *dpy) * none * * Side effects: - * The user inactivity timer of the underlaying windowing system - * is reset to zero. + * The user inactivity timer of the underlaying windowing system is reset + * to zero. * *---------------------------------------------------------------------- */ void -Tk_ResetUserInactiveTime(Display *dpy) +Tk_ResetUserInactiveTime( + Display *dpy) { UpdateSystemActivity(OverallAct); } |