📄 tktest.c
字号:
/* * tkTest.c -- * * This file contains C command procedures for a bunch of additional * Tcl commands that are used for testing out Tcl's C interfaces. * These commands are not normally included in Tcl applications; * they're only used for testing. * * Copyright (c) 1993-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkTest.c 1.50 97/11/06 16:56:32 */#include "tkInt.h"#include "tkPort.h" #ifdef __WIN32__#include "tkWinInt.h"#endif#ifdef MAC_TCL#include "tkScrollbar.h"#endif#ifdef __UNIX__#include "tkUnixInt.h"#endif/* * The following data structure represents the master for a test * image: */typedef struct TImageMaster { Tk_ImageMaster master; /* Tk's token for image master. */ Tcl_Interp *interp; /* Interpreter for application. */ int width, height; /* Dimensions of image. */ char *imageName; /* Name of image (malloc-ed). */ char *varName; /* Name of variable in which to log * events for image (malloc-ed). */} TImageMaster;/* * The following data structure represents a particular use of a * particular test image. */typedef struct TImageInstance { TImageMaster *masterPtr; /* Pointer to master for image. */ XColor *fg; /* Foreground color for drawing in image. */ GC gc; /* Graphics context for drawing in image. */} TImageInstance;/* * The type record for test images: */static int ImageCreate _ANSI_ARGS_((Tcl_Interp *interp, char *name, int argc, char **argv, Tk_ImageType *typePtr, Tk_ImageMaster master, ClientData *clientDataPtr));static ClientData ImageGet _ANSI_ARGS_((Tk_Window tkwin, ClientData clientData));static void ImageDisplay _ANSI_ARGS_((ClientData clientData, Display *display, Drawable drawable, int imageX, int imageY, int width, int height, int drawableX, int drawableY));static void ImageFree _ANSI_ARGS_((ClientData clientData, Display *display));static void ImageDelete _ANSI_ARGS_((ClientData clientData));static Tk_ImageType imageType = { "test", /* name */ ImageCreate, /* createProc */ ImageGet, /* getProc */ ImageDisplay, /* displayProc */ ImageFree, /* freeProc */ ImageDelete, /* deleteProc */ (Tk_ImageType *) NULL /* nextPtr */};/* * One of the following structures describes each of the interpreters * created by the "testnewapp" command. This information is used by * the "testdeleteinterps" command to destroy all of those interpreters. */typedef struct NewApp { Tcl_Interp *interp; /* Token for interpreter. */ struct NewApp *nextPtr; /* Next in list of new interpreters. */} NewApp;static NewApp *newAppPtr = NULL; /* First in list of all new interpreters. *//* * Declaration for the square widget's class command procedure: */extern int SquareCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]));typedef struct CBinding { Tcl_Interp *interp; char *command; char *delete;} CBinding;/* * Forward declarations for procedures defined later in this file: */static int CBindingEvalProc _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, XEvent *eventPtr, Tk_Window tkwin, KeySym keySym));static void CBindingFreeProc _ANSI_ARGS_((ClientData clientData));int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));static int ImageCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));static int TestcbindCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#ifdef __WIN32__static int TestclipboardCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#endifstatic int TestdeleteappsCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));static int TestmakeexistCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));static int TestmenubarCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#if defined(__WIN32__) || defined(MAC_TCL)static int TestmetricsCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#endifstatic int TestsendCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));static int TestpropCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#if !(defined(__WIN32__) || defined(MAC_TCL))static int TestwrapperCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, char **argv));#endif/* * External (platform specific) initialization routine: */EXTERN int TkplatformtestInit _ANSI_ARGS_(( Tcl_Interp *interp));#ifndef MAC_TCL#define TkplatformtestInit(x) TCL_OK#endif/* *---------------------------------------------------------------------- * * Tktest_Init -- * * This procedure performs intialization for the Tk test * suite exensions. * * Results: * Returns a standard Tcl completion code, and leaves an error * message in interp->result if an error occurs. * * Side effects: * Creates several test commands. * *---------------------------------------------------------------------- */intTktest_Init(interp) Tcl_Interp *interp; /* Interpreter for application. */{ static int initialized = 0; /* * Create additional commands for testing Tk. */ if (Tcl_PkgProvide(interp, "Tktest", TK_VERSION) == TCL_ERROR) { return TCL_ERROR; } Tcl_CreateCommand(interp, "square", SquareCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#ifdef __WIN32__ Tcl_CreateCommand(interp, "testclipboard", TestclipboardCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#endif Tcl_CreateCommand(interp, "testcbind", TestcbindCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testdeleteapps", TestdeleteappsCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testembed", TkpTestembedCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testmakeexist", TestmakeexistCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testmenubar", TestmenubarCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#if defined(__WIN32__) || defined(MAC_TCL) Tcl_CreateCommand(interp, "testmetrics", TestmetricsCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#endif Tcl_CreateCommand(interp, "testprop", TestpropCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testsend", TestsendCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#if !(defined(__WIN32__) || defined(MAC_TCL)) Tcl_CreateCommand(interp, "testwrapper", TestwrapperCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);#endif/* * Create test image type. */ if (!initialized) { initialized = 1; Tk_CreateImageType(&imageType); } /* * And finally add any platform specific test commands. */ return TkplatformtestInit(interp);}/* *---------------------------------------------------------------------- * * TestclipboardCmd -- * * This procedure implements the testclipboard command. It provides * a way to determine the actual contents of the Windows clipboard. * * Results: * A standard Tcl result. * * Side effects: * None. * *---------------------------------------------------------------------- */#ifdef __WIN32__static intTestclipboardCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ TkWindow *winPtr = (TkWindow *) clientData; HGLOBAL handle; char *data; if (OpenClipboard(NULL)) { handle = GetClipboardData(CF_TEXT); if (handle != NULL) { data = GlobalLock(handle); Tcl_AppendResult(interp, data, (char *) NULL); GlobalUnlock(handle); } CloseClipboard(); } return TCL_OK;}#endif/* *---------------------------------------------------------------------- * * TestcbindCmd -- * * This procedure implements the "testcbinding" command. It provides * a set of functions for testing C bindings in tkBind.c. * * Results: * A standard Tcl result. * * Side effects: * Depends on option; see below. * *---------------------------------------------------------------------- */static intTestcbindCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ TkWindow *winPtr; Tk_Window tkwin; ClientData object; CBinding *cbindPtr; if (argc < 4 || argc > 5) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " bindtag pattern command ?deletecommand?", (char *) NULL); return TCL_ERROR; } tkwin = (Tk_Window) clientData; if (argv[1][0] == '.') { winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[1], tkwin); if (winPtr == NULL) { return TCL_ERROR; } object = (ClientData) winPtr->pathName; } else { winPtr = (TkWindow *) clientData; object = (ClientData) Tk_GetUid(argv[1]); } if (argv[3][0] == '\0') { return Tk_DeleteBinding(interp, winPtr->mainPtr->bindingTable, object, argv[2]); } cbindPtr = (CBinding *) ckalloc(sizeof(CBinding)); cbindPtr->interp = interp; cbindPtr->command = strcpy((char *) ckalloc(strlen(argv[3]) + 1), argv[3]); if (argc == 4) { cbindPtr->delete = NULL; } else { cbindPtr->delete = strcpy((char *) ckalloc(strlen(argv[4]) + 1), argv[4]); } if (TkCreateBindingProcedure(interp, winPtr->mainPtr->bindingTable, object, argv[2], CBindingEvalProc, CBindingFreeProc, (ClientData) cbindPtr) == 0) { ckfree((char *) cbindPtr->command); if (cbindPtr->delete != NULL) { ckfree((char *) cbindPtr->delete); } ckfree((char *) cbindPtr); return TCL_ERROR; } return TCL_OK;}static intCBindingEvalProc(clientData, interp, eventPtr, tkwin, keySym) ClientData clientData; Tcl_Interp *interp; XEvent *eventPtr; Tk_Window tkwin; KeySym keySym;{ CBinding *cbindPtr; cbindPtr = (CBinding *) clientData; return Tcl_GlobalEval(interp, cbindPtr->command);}static voidCBindingFreeProc(clientData) ClientData clientData;{ CBinding *cbindPtr = (CBinding *) clientData; if (cbindPtr->delete != NULL) { Tcl_GlobalEval(cbindPtr->interp, cbindPtr->delete);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -