home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / unix / tkUnixDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  5.6 KB  |  208 lines  |  [TEXT/CWIE]

  1. /*
  2.  * tkUnixDialog.c --
  3.  *
  4.  *    Contains the Unix implementation of the common dialog boxes:
  5.  *
  6.  * Copyright (c) 1996 Sun Microsystems, Inc.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * SCCS: @(#) tkUnixDialog.c 1.5 96/08/28 21:21:01
  12.  *
  13.  */
  14.  
  15. #include "tkPort.h"
  16. #include "tkInt.h"
  17. #include "tkUnixInt.h"
  18.  
  19. /*
  20.  *----------------------------------------------------------------------
  21.  *
  22.  * EvalArgv --
  23.  *
  24.  *    Invokes the Tcl procedure with the arguments. argv[0] is set by
  25.  *    the caller of this function. It may be different than cmdName.
  26.  *    The TCL command will see argv[0], not cmdName, as its name if it
  27.  *    invokes [lindex [info level 0] 0]
  28.  *
  29.  * Results:
  30.  *    TCL_ERROR if the command does not exist and cannot be autoloaded.
  31.  *    Otherwise, return the result of the evaluation of the command.
  32.  *
  33.  * Side effects:
  34.  *    The command may be autoloaded.
  35.  *
  36.  *----------------------------------------------------------------------
  37.  */
  38.  
  39. static int EvalArgv(interp, cmdName, argc, argv)
  40.     Tcl_Interp *interp;        /* Current interpreter. */
  41.     char * cmdName;        /* Name of the TCL command to call */
  42.     int argc;            /* Number of arguments. */
  43.     char **argv;        /* Argument strings. */
  44. {
  45.     Tcl_CmdInfo cmdInfo;
  46.  
  47.     if (!Tcl_GetCommandInfo(interp, cmdName, &cmdInfo)) {
  48.     char * cmdArgv[2];
  49.  
  50.     /*
  51.      * This comand is not in the interpreter yet -- looks like we
  52.      * have to auto-load it
  53.      */
  54.     if (!Tcl_GetCommandInfo(interp, "auto_load", &cmdInfo)) {
  55.         Tcl_ResetResult(interp);
  56.         Tcl_AppendResult(interp, "cannot execute command \"auto_load\"",
  57.         NULL);
  58.         return TCL_ERROR;
  59.     }
  60.  
  61.     cmdArgv[0] = "auto_load";
  62.     cmdArgv[1] = cmdName;
  63.  
  64.     if ((*cmdInfo.proc)(cmdInfo.clientData, interp, 2, cmdArgv)!= TCL_OK){ 
  65.         return TCL_ERROR;
  66.     }
  67.  
  68.     if (!Tcl_GetCommandInfo(interp, cmdName, &cmdInfo)) {
  69.         Tcl_ResetResult(interp);
  70.         Tcl_AppendResult(interp, "cannot auto-load command \"",
  71.         cmdName, "\"",NULL);
  72.         return TCL_ERROR;
  73.     }
  74.     }
  75.  
  76.     return (*cmdInfo.proc)(cmdInfo.clientData, interp, argc, argv);
  77. }
  78.  
  79. /*
  80.  *----------------------------------------------------------------------
  81.  *
  82.  * Tk_ChooseColorCmd --
  83.  *
  84.  *    This procedure implements the color dialog box for the Unix
  85.  *    platform. See the user documentation for details on what it
  86.  *    does.
  87.  *
  88.  * Results:
  89.  *    See user documentation.
  90.  *
  91.  * Side effects:
  92.  *    A dialog window is created the first time this procedure is called.
  93.  *    This window is not destroyed and will be reused the next time the
  94.  *    application invokes the "tk_chooseColor" command.
  95.  *
  96.  *----------------------------------------------------------------------
  97.  */
  98.  
  99. int
  100. Tk_ChooseColorCmd(clientData, interp, argc, argv)
  101.     ClientData clientData;    /* Main window associated with interpreter. */
  102.     Tcl_Interp *interp;        /* Current interpreter. */
  103.     int argc;            /* Number of arguments. */
  104.     char **argv;        /* Argument strings. */
  105. {
  106.     return EvalArgv(interp, "tkColorDialog", argc, argv);
  107. }
  108.  
  109. /*
  110.  *----------------------------------------------------------------------
  111.  *
  112.  * Tk_GetOpenFileCmd --
  113.  *
  114.  *    This procedure implements the "open file" dialog box for the
  115.  *    Unix platform. See the user documentation for details on what
  116.  *    it does.
  117.  *
  118.  * Results:
  119.  *    See user documentation.
  120.  *
  121.  * Side effects:
  122.  *    A dialog window is created the first this procedure is called.
  123.  *    This window is not destroyed and will be reused the next time
  124.  *    the application invokes the "tk_getOpenFile" or
  125.  *    "tk_getSaveFile" command.
  126.  *
  127.  *----------------------------------------------------------------------
  128.  */
  129.  
  130. int
  131. Tk_GetOpenFileCmd(clientData, interp, argc, argv)
  132.     ClientData clientData;    /* Main window associated with interpreter. */
  133.     Tcl_Interp *interp;        /* Current interpreter. */
  134.     int argc;            /* Number of arguments. */
  135.     char **argv;        /* Argument strings. */
  136. {
  137.     Tk_Window tkwin = (Tk_Window)clientData;
  138.  
  139.     if (Tk_StrictMotif(tkwin)) {
  140.     return EvalArgv(interp, "tkMotifFDialog", argc, argv);
  141.     } else {
  142.     return EvalArgv(interp, "tkFDialog", argc, argv);
  143.     }
  144. }
  145.  
  146. /*
  147.  *----------------------------------------------------------------------
  148.  *
  149.  * Tk_GetSaveFileCmd --
  150.  *
  151.  *    Same as Tk_GetOpenFileCmd but opens a "save file" dialog box
  152.  *    instead
  153.  *
  154.  * Results:
  155.  *    Same as Tk_GetOpenFileCmd.
  156.  *
  157.  * Side effects:
  158.  *    Same as Tk_GetOpenFileCmd.
  159.  *
  160.  *----------------------------------------------------------------------
  161.  */
  162.  
  163. int
  164. Tk_GetSaveFileCmd(clientData, interp, argc, argv)
  165.     ClientData clientData;    /* Main window associated with interpreter. */
  166.     Tcl_Interp *interp;        /* Current interpreter. */
  167.     int argc;            /* Number of arguments. */
  168.     char **argv;        /* Argument strings. */
  169. {
  170.     Tk_Window tkwin = (Tk_Window)clientData;
  171.  
  172.     if (Tk_StrictMotif(tkwin)) {
  173.     return EvalArgv(interp, "tkMotifFDialog", argc, argv);
  174.     } else {
  175.     return EvalArgv(interp, "tkFDialog", argc, argv);
  176.     }
  177. }
  178.  
  179. /*
  180.  *----------------------------------------------------------------------
  181.  *
  182.  * Tk_MessageBoxCmd --
  183.  *
  184.  *    This procedure implements the MessageBox window for the
  185.  *    Unix platform. See the user documentation for details on what
  186.  *    it does.
  187.  *
  188.  * Results:
  189.  *    See user documentation.
  190.  *
  191.  * Side effects:
  192.  *    None. The MessageBox window will be destroy before this procedure
  193.  *    returns.
  194.  *
  195.  *----------------------------------------------------------------------
  196.  */
  197.  
  198. int
  199. Tk_MessageBoxCmd(clientData, interp, argc, argv)
  200.     ClientData clientData;    /* Main window associated with interpreter. */
  201.     Tcl_Interp *interp;        /* Current interpreter. */
  202.     int argc;            /* Number of arguments. */
  203.     char **argv;        /* Argument strings. */
  204. {
  205.     return EvalArgv(interp, "tkMessageBox", argc, argv);
  206. }
  207.  
  208.