home *** CD-ROM | disk | FTP | other *** search
/ Practical Programming in Tcl & Tk (4th Edition) / TCLBOOK4.BIN / mac / exsource.old / 47_3.c < prev    next >
Text File  |  2003-04-15  |  2KB  |  83 lines

  1. /*
  2.  * Example 47-3
  3.  * The ClockCmd command procedure.
  4.  */
  5.  
  6. int
  7. ClockCmd(clientData, interp, argc, argv)
  8.     ClientData clientData;                        /* Main window of the app */
  9.     Tcl_Interp *interp;                        /* Current interpreter. */
  10.     int argc;                        /* Number of arguments. */
  11.     char **argv;                        /* Argument strings. */
  12. {
  13.     Tk_Window main = (Tk_Window) clientData;
  14.     Clock *clockPtr;
  15.     Tk_Window tkwin;
  16.  
  17.     if (argc < 2) {
  18.         Tcl_AppendResult(interp, "wrong # args: should be \"",
  19.              argv[0], " pathName ?options?\"", (char *) NULL);
  20.         return TCL_ERROR;
  21.     }
  22.     tkwin = Tk_CreateWindowFromPath(interp, main,
  23.              argv[1], (char *) NULL);
  24.     if (tkwin == NULL) {
  25.         return TCL_ERROR;
  26.     }
  27.     /*
  28.      * Set resource class.
  29.      */
  30.     Tk_SetClass(tkwin, "Clock");
  31.     /*
  32.      * Allocate and initialize the widget record.
  33.      */
  34.     clockPtr = (Clock *) Tcl_Alloc(sizeof(Clock));
  35.     clockPtr->tkwin = tkwin;
  36.     clockPtr->display = Tk_Display(tkwin);
  37.     clockPtr->interp = interp;
  38.     clockPtr->borderWidth = 0;
  39.     clockPtr->highlightWidth = 0;
  40.     clockPtr->relief = TK_RELIEF_FLAT;
  41.     clockPtr->background = NULL;
  42.     clockPtr->foreground = NULL;
  43.     clockPtr->highlight = NULL;
  44.     clockPtr->highlightBg = NULL;
  45.     clockPtr->tkfont = NULL;
  46.     clockPtr->textGC = None;
  47.     clockPtr->token = NULL;
  48.     clockPtr->clock = NULL;
  49.     clockPtr->format = NULL;
  50.     clockPtr->numChars = 0;
  51.     clockPtr->textWidth = 0;
  52.     clockPtr->textHeight = 0;
  53.     clockPtr->padX = 0;
  54.     clockPtr->padY = 0;
  55.     clockPtr->flags = 0;
  56.     /*
  57.      * Register a handler for when the window is
  58.      * exposed or resized.
  59.      */
  60.     Tk_CreateEventHandler(clockPtr->tkwin,
  61.         ExposureMask|StructureNotifyMask|FocusChangeMask,
  62.         ClockEventProc, (ClientData) clockPtr);
  63.     /*
  64.      * Create a Tcl command that operates on the widget.
  65.      */
  66.     clockPtr->widgetCmd = Tcl_CreateCommand(interp,
  67.         Tk_PathName(clockPtr->tkwin),
  68.         ClockInstanceCmd,
  69.         (ClientData) clockPtr, (void (*)()) NULL);
  70.     /*
  71.      * Parse the command line arguments.
  72.      */
  73.     if (ClockConfigure(interp, clockPtr,
  74.              argc-2, argv+2, 0) != TCL_OK) {
  75.         Tk_DestroyWindow(clockPtr->tkwin);
  76.         return TCL_ERROR;
  77.     }
  78.     interp->result = Tk_PathName(clockPtr->tkwin);
  79.     return TCL_OK;
  80. }
  81.  
  82.  
  83.