⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tktest.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
	ckfree((char *) cbindPtr->delete);    }    ckfree((char *) cbindPtr->command);    ckfree((char *) cbindPtr);}/* *---------------------------------------------------------------------- * * TestdeleteappsCmd -- * *	This procedure implements the "testdeleteapps" command.  It cleans *	up all the interpreters left behind by the "testnewapp" command. * * Results: *	A standard Tcl result. * * Side effects: *	All the intepreters created by previous calls to "testnewapp" *	get deleted. * *---------------------------------------------------------------------- */	/* ARGSUSED */static intTestdeleteappsCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Main window for application. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    NewApp *nextPtr;    while (newAppPtr != NULL) {	nextPtr = newAppPtr->nextPtr;	Tcl_DeleteInterp(newAppPtr->interp);	ckfree((char *) newAppPtr);	newAppPtr = nextPtr;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * ImageCreate -- * *	This procedure is called by the Tk image code to create "test" *	images. * * Results: *	A standard Tcl result. * * Side effects: *	The data structure for a new image is allocated. * *---------------------------------------------------------------------- */	/* ARGSUSED */static intImageCreate(interp, name, argc, argv, typePtr, master, clientDataPtr)    Tcl_Interp *interp;		/* Interpreter for application containing				 * image. */    char *name;			/* Name to use for image. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings for options (doesn't				 * include image name or type). */    Tk_ImageType *typePtr;	/* Pointer to our type record (not used). */    Tk_ImageMaster master;	/* Token for image, to be used by us in				 * later callbacks. */    ClientData *clientDataPtr;	/* Store manager's token for image here;				 * it will be returned in later callbacks. */{    TImageMaster *timPtr;    char *varName;    int i;    varName = "log";    for (i = 0; i < argc; i += 2) {	if (strcmp(argv[i], "-variable") != 0) {	    Tcl_AppendResult(interp, "bad option name \"", argv[i],		    "\"", (char *) NULL);	    return TCL_ERROR;	}	if ((i+1) == argc) {	    Tcl_AppendResult(interp, "no value given for \"", argv[i],		    "\" option", (char *) NULL);	    return TCL_ERROR;	}	varName = argv[i+1];    }    timPtr = (TImageMaster *) ckalloc(sizeof(TImageMaster));    timPtr->master = master;    timPtr->interp = interp;    timPtr->width = 30;    timPtr->height = 15;    timPtr->imageName = (char *) ckalloc((unsigned) (strlen(name) + 1));    strcpy(timPtr->imageName, name);    timPtr->varName = (char *) ckalloc((unsigned) (strlen(varName) + 1));    strcpy(timPtr->varName, varName);    Tcl_CreateCommand(interp, name, ImageCmd, (ClientData) timPtr,	    (Tcl_CmdDeleteProc *) NULL);    *clientDataPtr = (ClientData) timPtr;    Tk_ImageChanged(master, 0, 0, 30, 15, 30, 15);    return TCL_OK;}/* *---------------------------------------------------------------------- * * ImageCmd -- * *	This procedure implements the commands corresponding to individual *	images.  * * Results: *	A standard Tcl result. * * Side effects: *	Forces windows to be created. * *---------------------------------------------------------------------- */	/* ARGSUSED */static intImageCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Main window for application. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    TImageMaster *timPtr = (TImageMaster *) clientData;    int x, y, width, height;    if (argc < 2) {	Tcl_AppendResult(interp, "wrong # args: should be \"",		argv[0], "option ?arg arg ...?", (char *) NULL);	return TCL_ERROR;    }    if (strcmp(argv[1], "changed") == 0) {	if (argc != 8) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " changed x y width height imageWidth imageHeight",		    (char *) NULL);	    return TCL_ERROR;	}	if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)		|| (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)		|| (Tcl_GetInt(interp, argv[4], &width) != TCL_OK)		|| (Tcl_GetInt(interp, argv[5], &height) != TCL_OK)		|| (Tcl_GetInt(interp, argv[6], &timPtr->width) != TCL_OK)		|| (Tcl_GetInt(interp, argv[7], &timPtr->height) != TCL_OK)) {	    return TCL_ERROR;	}	Tk_ImageChanged(timPtr->master, x, y, width, height, timPtr->width,		timPtr->height);    } else {	Tcl_AppendResult(interp, "bad option \"", argv[1],		"\": must be changed", (char *) NULL);	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * ImageGet -- * *	This procedure is called by Tk to set things up for using a *	test image in a particular widget. * * Results: *	The return value is a token for the image instance, which is *	used in future callbacks to ImageDisplay and ImageFree. * * Side effects: *	None. * *---------------------------------------------------------------------- */static ClientDataImageGet(tkwin, clientData)    Tk_Window tkwin;		/* Token for window in which image will				 * be used. */    ClientData clientData;	/* Pointer to TImageMaster for image. */{    TImageMaster *timPtr = (TImageMaster *) clientData;    TImageInstance *instPtr;    char buffer[100];    XGCValues gcValues;    sprintf(buffer, "%s get", timPtr->imageName);    Tcl_SetVar(timPtr->interp, timPtr->varName, buffer,	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);    instPtr = (TImageInstance *) ckalloc(sizeof(TImageInstance));    instPtr->masterPtr = timPtr;    instPtr->fg = Tk_GetColor(timPtr->interp, tkwin, "#ff0000");    gcValues.foreground = instPtr->fg->pixel;    instPtr->gc = Tk_GetGC(tkwin, GCForeground, &gcValues);    return (ClientData) instPtr;}/* *---------------------------------------------------------------------- * * ImageDisplay -- * *	This procedure is invoked to redisplay part or all of an *	image in a given drawable. * * Results: *	None. * * Side effects: *	The image gets partially redrawn, as an "X" that shows the *	exact redraw area. * *---------------------------------------------------------------------- */static voidImageDisplay(clientData, display, drawable, imageX, imageY, width, height,	drawableX, drawableY)    ClientData clientData;	/* Pointer to TImageInstance for image. */    Display *display;		/* Display to use for drawing. */    Drawable drawable;		/* Where to redraw image. */    int imageX, imageY;		/* Origin of area to redraw, relative to				 * origin of image. */    int width, height;		/* Dimensions of area to redraw. */    int drawableX, drawableY;	/* Coordinates in drawable corresponding to				 * imageX and imageY. */{    TImageInstance *instPtr = (TImageInstance *) clientData;    char buffer[200];    sprintf(buffer, "%s display %d %d %d %d %d %d",	    instPtr->masterPtr->imageName, imageX, imageY, width, height,	    drawableX, drawableY);    Tcl_SetVar(instPtr->masterPtr->interp, instPtr->masterPtr->varName, buffer,	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);    if (width > (instPtr->masterPtr->width - imageX)) {	width = instPtr->masterPtr->width - imageX;    }    if (height > (instPtr->masterPtr->height - imageY)) {	height = instPtr->masterPtr->height - imageY;    }    XDrawRectangle(display, drawable, instPtr->gc, drawableX, drawableY,	    (unsigned) (width-1), (unsigned) (height-1));    XDrawLine(display, drawable, instPtr->gc, drawableX, drawableY,	    (int) (drawableX + width - 1), (int) (drawableY + height - 1));    XDrawLine(display, drawable, instPtr->gc, drawableX,	    (int) (drawableY + height - 1),	    (int) (drawableX + width - 1), drawableY);}/* *---------------------------------------------------------------------- * * ImageFree -- * *	This procedure is called when an instance of an image is * 	no longer used. * * Results: *	None. * * Side effects: *	Information related to the instance is freed. * *---------------------------------------------------------------------- */static voidImageFree(clientData, display)    ClientData clientData;	/* Pointer to TImageInstance for instance. */    Display *display;		/* Display where image was to be drawn. */{    TImageInstance *instPtr = (TImageInstance *) clientData;    char buffer[200];    sprintf(buffer, "%s free", instPtr->masterPtr->imageName);    Tcl_SetVar(instPtr->masterPtr->interp, instPtr->masterPtr->varName, buffer,	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);    Tk_FreeColor(instPtr->fg);    Tk_FreeGC(display, instPtr->gc);    ckfree((char *) instPtr);}/* *---------------------------------------------------------------------- * * ImageDelete -- * *	This procedure is called to clean up a test image when *	an application goes away. * * Results: *	None. * * Side effects: *	Information about the image is deleted. * *---------------------------------------------------------------------- */static voidImageDelete(clientData)    ClientData clientData;	/* Pointer to TImageMaster for image.  When				 * this procedure is called, no more				 * instances exist. */{    TImageMaster *timPtr = (TImageMaster *) clientData;    char buffer[100];    sprintf(buffer, "%s delete", timPtr->imageName);    Tcl_SetVar(timPtr->interp, timPtr->varName, buffer,	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);    Tcl_DeleteCommand(timPtr->interp, timPtr->imageName);    ckfree(timPtr->imageName);    ckfree(timPtr->varName);    ckfree((char *) timPtr);}/* *---------------------------------------------------------------------- * * TestmakeexistCmd -- * *	This procedure implements the "testmakeexist" command.  It calls *	Tk_MakeWindowExist on each of its arguments to force the windows *	to be created. * * Results: *	A standard Tcl result. * * Side effects: *	Forces windows to be created. * *---------------------------------------------------------------------- */	/* ARGSUSED */static intTestmakeexistCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Main window for application. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    Tk_Window mainwin = (Tk_Window) clientData;    int i;    Tk_Window tkwin;    for (i = 1; i < argc; i++) {	tkwin = Tk_NameToWindow(interp, argv[i], mainwin);	if (tkwin == NULL) {	    return TCL_ERROR;	}	Tk_MakeWindowExist(tkwin);    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * TestmenubarCmd -- * *	This procedure implements the "testmenubar" command.  It is used *	to test the Unix facilities for creating space above a toplevel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -