summaryrefslogtreecommitdiffstats
path: root/generic/tkFocus.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkFocus.c')
-rw-r--r--generic/tkFocus.c163
1 files changed, 86 insertions, 77 deletions
diff --git a/generic/tkFocus.c b/generic/tkFocus.c
index 0db24ff..31ca652 100644
--- a/generic/tkFocus.c
+++ b/generic/tkFocus.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: tkFocus.c,v 1.3 1999/02/04 20:53:53 stanton Exp $
+ * RCS: @(#) $Id: tkFocus.c,v 1.4 1999/04/16 01:51:14 stanton Exp $
*/
#include "tkInt.h"
@@ -76,12 +76,6 @@ typedef struct TkDisplayFocusInfo {
} DisplayFocusInfo;
/*
- * Global used for debugging.
- */
-
-int tclFocusDebug = 0;
-
-/*
* The following magic value is stored in the "send_event" field of
* FocusIn and FocusOut events that are generated in this file. This
* allows us to separate "real" events coming from the server from
@@ -106,7 +100,7 @@ static void SetFocus _ANSI_ARGS_((TkWindow *winPtr, int force));
/*
*--------------------------------------------------------------
*
- * Tk_FocusCmd --
+ * Tk_FocusObjCmd --
*
* This procedure is invoked to process the "focus" Tcl command.
* See the user documentation for details on what it does.
@@ -121,28 +115,30 @@ static void SetFocus _ANSI_ARGS_((TkWindow *winPtr, int force));
*/
int
-Tk_FocusCmd(clientData, interp, argc, argv)
+Tk_FocusObjCmd(clientData, interp, objc, objv)
ClientData clientData; /* Main window associated with
* interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
- int argc; /* Number of arguments. */
- char **argv; /* Argument strings. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj *CONST objv[]; /* Argument objects. */
{
+ static char *focusOptions[] = {"-displayof", "-force", "-lastfor",
+ (char *) NULL};
Tk_Window tkwin = (Tk_Window) clientData;
TkWindow *winPtr = (TkWindow *) clientData;
TkWindow *newPtr, *focusWinPtr, *topLevelPtr;
ToplevelFocusInfo *tlFocusPtr;
- char c;
- size_t length;
+ char *windowName;
+ int index;
/*
* If invoked with no arguments, just return the current focus window.
*/
- if (argc == 1) {
+ if (objc == 1) {
focusWinPtr = TkGetFocusWin(winPtr);
if (focusWinPtr != NULL) {
- interp->result = focusWinPtr->pathName;
+ Tcl_SetResult(interp, focusWinPtr->pathName, TCL_STATIC);
}
return TCL_OK;
}
@@ -152,12 +148,18 @@ Tk_FocusCmd(clientData, interp, argc, argv)
* on that window.
*/
- if (argc == 2) {
- if (argv[1][0] == 0) {
+ if (objc == 2) {
+ windowName = Tcl_GetStringFromObj(objv[1], (int *) NULL);
+
+ /*
+ * The empty string case exists for backwards compatibility.
+ */
+
+ if (windowName[0] == '\0') {
return TCL_OK;
}
- if (argv[1][0] == '.') {
- newPtr = (TkWindow *) Tk_NameToWindow(interp, argv[1], tkwin);
+ if (windowName[0] == '.') {
+ newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin);
if (newPtr == NULL) {
return TCL_ERROR;
}
@@ -168,65 +170,72 @@ Tk_FocusCmd(clientData, interp, argc, argv)
}
}
- length = strlen(argv[1]);
- c = argv[1][1];
- if ((c == 'd') && (strncmp(argv[1], "-displayof", length) == 0)) {
- if (argc != 3) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " -displayof window\"", (char *) NULL);
- return TCL_ERROR;
- }
- newPtr = (TkWindow *) Tk_NameToWindow(interp, argv[2], tkwin);
- if (newPtr == NULL) {
- return TCL_ERROR;
- }
- newPtr = TkGetFocusWin(newPtr);
- if (newPtr != NULL) {
- interp->result = newPtr->pathName;
- }
- } else if ((c == 'f') && (strncmp(argv[1], "-force", length) == 0)) {
- if (argc != 3) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " -force window\"", (char *) NULL);
- return TCL_ERROR;
- }
- if (argv[2][0] == 0) {
- return TCL_OK;
- }
- newPtr = (TkWindow *) Tk_NameToWindow(interp, argv[2], tkwin);
- if (newPtr == NULL) {
- return TCL_ERROR;
- }
- SetFocus(newPtr, 1);
- } else if ((c == 'l') && (strncmp(argv[1], "-lastfor", length) == 0)) {
- if (argc != 3) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " -lastfor window\"", (char *) NULL);
- return TCL_ERROR;
+ if (Tcl_GetIndexFromObj(interp, objv[1], focusOptions, "option", 0,
+ &index) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "window");
+ return TCL_ERROR;
+ }
+ switch (index) {
+ case 0: { /* -displayof */
+ windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL);
+ newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin);
+ if (newPtr == NULL) {
+ return TCL_ERROR;
+ }
+ newPtr = TkGetFocusWin(newPtr);
+ if (newPtr != NULL) {
+ Tcl_SetResult(interp, newPtr->pathName, TCL_STATIC);
+ }
+ break;
}
- newPtr = (TkWindow *) Tk_NameToWindow(interp, argv[2], tkwin);
- if (newPtr == NULL) {
- return TCL_ERROR;
+ case 1: { /* -force */
+ windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL);
+
+ /*
+ * The empty string case exists for backwards compatibility.
+ */
+
+ if (windowName[0] == '\0') {
+ return TCL_OK;
+ }
+ newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin);
+ if (newPtr == NULL) {
+ return TCL_ERROR;
+ }
+ SetFocus(newPtr, 1);
+ break;
}
- for (topLevelPtr = newPtr; topLevelPtr != NULL;
- topLevelPtr = topLevelPtr->parentPtr) {
- if (topLevelPtr->flags & TK_TOP_LEVEL) {
- for (tlFocusPtr = newPtr->mainPtr->tlFocusPtr;
- tlFocusPtr != NULL;
- tlFocusPtr = tlFocusPtr->nextPtr) {
- if (tlFocusPtr->topLevelPtr == topLevelPtr) {
- interp->result = tlFocusPtr->focusWinPtr->pathName;
- return TCL_OK;
+ case 2: { /* -lastfor */
+ windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL);
+ newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin);
+ if (newPtr == NULL) {
+ return TCL_ERROR;
+ }
+ for (topLevelPtr = newPtr; topLevelPtr != NULL;
+ topLevelPtr = topLevelPtr->parentPtr) {
+ if (topLevelPtr->flags & TK_TOP_LEVEL) {
+ for (tlFocusPtr = newPtr->mainPtr->tlFocusPtr;
+ tlFocusPtr != NULL;
+ tlFocusPtr = tlFocusPtr->nextPtr) {
+ if (tlFocusPtr->topLevelPtr == topLevelPtr) {
+ Tcl_SetResult(interp,
+ tlFocusPtr->focusWinPtr->pathName,
+ TCL_STATIC);
+ return TCL_OK;
+ }
}
+ Tcl_SetResult(interp, topLevelPtr->pathName, TCL_STATIC);
+ return TCL_OK;
}
- interp->result = topLevelPtr->pathName;
- return TCL_OK;
}
+ break;
+ }
+ default: {
+ panic("bad const entries to focusOptions in focus command");
}
- } else {
- Tcl_AppendResult(interp, "bad option \"", argv[1],
- "\": must be -displayof, -force, or -lastfor", (char *) NULL);
- return TCL_ERROR;
}
return TCL_OK;
}
@@ -479,7 +488,7 @@ TkFocusFilterEvent(winPtr, eventPtr)
if (eventPtr->xcrossing.focus &&
(displayFocusPtr->focusWinPtr == NULL)
&& !(winPtr->flags & TK_EMBEDDED)) {
- if (tclFocusDebug) {
+ if (dispPtr->focusDebug) {
printf("Focussed implicitly on %s\n",
newFocusPtr->pathName);
}
@@ -504,7 +513,7 @@ TkFocusFilterEvent(winPtr, eventPtr)
if ((dispPtr->implicitWinPtr != NULL)
&& !(winPtr->flags & TK_EMBEDDED)) {
- if (tclFocusDebug) {
+ if (dispPtr->focusDebug) {
printf("Defocussed implicit Async\n");
}
GenerateFocusEvents(displayFocusPtr->focusWinPtr,
@@ -820,7 +829,7 @@ TkFocusDeadWindow(winPtr)
*/
if (dispPtr->implicitWinPtr == winPtr) {
- if (tclFocusDebug) {
+ if (dispPtr->focusDebug) {
printf("releasing focus to root after %s died\n",
tlFocusPtr->topLevelPtr->pathName);
}
@@ -848,7 +857,7 @@ TkFocusDeadWindow(winPtr)
tlFocusPtr->focusWinPtr = tlFocusPtr->topLevelPtr;
if ((displayFocusPtr->focusWinPtr == winPtr)
&& !(tlFocusPtr->topLevelPtr->flags & TK_ALREADY_DEAD)) {
- if (tclFocusDebug) {
+ if (dispPtr->focusDebug) {
printf("forwarding focus to %s after %s died\n",
tlFocusPtr->topLevelPtr->pathName,
winPtr->pathName);
@@ -943,7 +952,7 @@ FocusMapProc(clientData, eventPtr)
if (eventPtr->type == VisibilityNotify) {
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr,
winPtr->dispPtr);
- if (tclFocusDebug) {
+ if (winPtr->dispPtr->focusDebug) {
printf("auto-focussing on %s, force %d\n", winPtr->pathName,
displayFocusPtr->forceFocus);
}