]> www.wagner.pp.ru Git - oss/ck.git/blob - ckFocus.c
Ck console graphics toolkit
[oss/ck.git] / ckFocus.c
1 /* 
2  * ckFocus.c --
3  *
4  *      This file contains procedures that manage the input focus.
5  *
6  * Copyright (c) 1990-1994 The Regents of the University of California.
7  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
8  * Copyright (c) 1995 Christian Werner
9  *
10  * See the file "license.terms" for information on usage and redistribution
11  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12  */
13
14 #include "ckPort.h"
15 #include "ck.h"
16
17 \f
18 /*
19  *--------------------------------------------------------------
20  *
21  * Ck_FocusCmd --
22  *
23  *      This procedure is invoked to process the "focus" Tcl command.
24  *      See the user documentation for details on what it does.
25  *
26  * Results:
27  *      A standard Tcl result.
28  *
29  * Side effects:
30  *      See the user documentation.
31  *
32  *--------------------------------------------------------------
33  */
34
35 int
36 Ck_FocusCmd(clientData, interp, argc, argv)
37     ClientData clientData;      /* Main window associated with
38                                  * interpreter. */
39     Tcl_Interp *interp;         /* Current interpreter. */
40     int argc;                   /* Number of arguments. */
41     char **argv;                /* Argument strings. */
42 {
43     CkWindow *winPtr = (CkWindow *) clientData;
44     CkWindow *newPtr, *focusWinPtr;
45
46     /*
47      * If invoked with no arguments, just return the current focus window.
48      */
49
50     if (argc == 1) {
51         focusWinPtr = winPtr->mainPtr->focusPtr;
52         if (focusWinPtr != NULL)
53             interp->result = focusWinPtr->pathName;
54         return TCL_OK;
55     }
56
57     /*
58      * If invoked with a single argument beginning with "." then focus
59      * on that window.
60      */
61
62     if (argc == 2) {
63         if (argv[1][0] == 0) {
64             return TCL_OK;
65         }
66         if (argv[1][0] == '.') {
67             newPtr = (CkWindow *) Ck_NameToWindow(interp, argv[1], winPtr);
68             if (newPtr == NULL)
69                 return TCL_ERROR;
70             if (!(newPtr->flags & CK_ALREADY_DEAD))
71                 Ck_SetFocus(newPtr);
72             return TCL_OK;
73         }
74     }
75
76     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
77         " ?pathName?\"", (char *) NULL);
78     return TCL_ERROR;
79 }