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

📄 tksquare.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
 * SquareConfigure -- * *	This procedure is called to process an argv/argc list in *	conjunction with the Tk option database to configure (or *	reconfigure) a square widget. * * Results: *	The return value is a standard Tcl result.  If TCL_ERROR is *	returned, then interp->result contains an error message. * * Side effects: *	Configuration information, such as colors, border width, *	etc. get set for squarePtr;  old resources get freed, *	if there were any. * *---------------------------------------------------------------------- */static intSquareConfigure(interp, squarePtr, argc, argv, flags)    Tcl_Interp *interp;			/* Used for error reporting. */    Square *squarePtr;			/* Information about widget. */    int argc;				/* Number of valid entries in argv. */    char **argv;			/* Arguments. */    int flags;				/* Flags to pass to					 * Tk_ConfigureWidget. */{    if (Tk_ConfigureWidget(interp, squarePtr->tkwin, configSpecs,	    argc, argv, (char *) squarePtr, flags) != TCL_OK) {	return TCL_ERROR;    }    /*     * Set the background for the window and create a graphics context     * for use during redisplay.     */    Tk_SetWindowBackground(squarePtr->tkwin,	    Tk_3DBorderColor(squarePtr->bgBorder)->pixel);    if ((squarePtr->gc == None) && (squarePtr->doubleBuffer)) {	XGCValues gcValues;	gcValues.function = GXcopy;	gcValues.graphics_exposures = False;	squarePtr->gc = Tk_GetGC(squarePtr->tkwin,		GCFunction|GCGraphicsExposures, &gcValues);    }    /*     * Register the desired geometry for the window.  Then arrange for     * the window to be redisplayed.     */    Tk_GeometryRequest(squarePtr->tkwin, 200, 150);    Tk_SetInternalBorder(squarePtr->tkwin, squarePtr->borderWidth);    if (!squarePtr->updatePending) {	Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);	squarePtr->updatePending = 1;    }    return TCL_OK;}/* *-------------------------------------------------------------- * * SquareEventProc -- * *	This procedure is invoked by the Tk dispatcher for various *	events on squares. * * Results: *	None. * * Side effects: *	When the window gets deleted, internal structures get *	cleaned up.  When it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */static voidSquareEventProc(clientData, eventPtr)    ClientData clientData;	/* Information about window. */    XEvent *eventPtr;		/* Information about event. */{    Square *squarePtr = (Square *) clientData;    if (eventPtr->type == Expose) {	if (!squarePtr->updatePending) {	    Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);	    squarePtr->updatePending = 1;	}    } else if (eventPtr->type == ConfigureNotify) {	KeepInWindow(squarePtr);	if (!squarePtr->updatePending) {	    Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);	    squarePtr->updatePending = 1;	}    } else if (eventPtr->type == DestroyNotify) {	if (squarePtr->tkwin != NULL) {	    squarePtr->tkwin = NULL;	    Tcl_DeleteCommandFromToken(squarePtr->interp,		    squarePtr->widgetCmd);	}	if (squarePtr->updatePending) {	    Tcl_CancelIdleCall(SquareDisplay, (ClientData) squarePtr);	}	Tcl_EventuallyFree((ClientData) squarePtr, SquareDestroy);    }}/* *---------------------------------------------------------------------- * * SquareCmdDeletedProc -- * *	This procedure is invoked when a widget command is deleted.  If *	the widget isn't already in the process of being destroyed, *	this command destroys it. * * Results: *	None. * * Side effects: *	The widget is destroyed. * *---------------------------------------------------------------------- */static voidSquareCmdDeletedProc(clientData)    ClientData clientData;	/* Pointer to widget record for widget. */{    Square *squarePtr = (Square *) clientData;    Tk_Window tkwin = squarePtr->tkwin;    /*     * This procedure could be invoked either because the window was     * destroyed and the command was then deleted (in which case tkwin     * is NULL) or because the command was deleted, and then this procedure     * destroys the widget.     */    if (tkwin != NULL) {	squarePtr->tkwin = NULL;	Tk_DestroyWindow(tkwin);    }}/* *-------------------------------------------------------------- * * SquareDisplay -- * *	This procedure redraws the contents of a square window. *	It is invoked as a do-when-idle handler, so it only runs *	when there's nothing else for the application to do. * * Results: *	None. * * Side effects: *	Information appears on the screen. * *-------------------------------------------------------------- */static voidSquareDisplay(clientData)    ClientData clientData;	/* Information about window. */{    Square *squarePtr = (Square *) clientData;    Tk_Window tkwin = squarePtr->tkwin;    Pixmap pm = None;    Drawable d;    squarePtr->updatePending = 0;    if (!Tk_IsMapped(tkwin)) {	return;    }    /*     * Create a pixmap for double-buffering, if necessary.     */    if (squarePtr->doubleBuffer) {	pm = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),		Tk_Width(tkwin), Tk_Height(tkwin),		DefaultDepthOfScreen(Tk_Screen(tkwin)));	d = pm;    } else {	d = Tk_WindowId(tkwin);    }    /*     * Redraw the widget's background and border.     */    Tk_Fill3DRectangle(tkwin, d, squarePtr->bgBorder, 0, 0, Tk_Width(tkwin),	    Tk_Height(tkwin), squarePtr->borderWidth, squarePtr->relief);    /*     * Display the square.     */    Tk_Fill3DRectangle(tkwin, d, squarePtr->fgBorder, squarePtr->x,	    squarePtr->y, squarePtr->size, squarePtr->size,	    squarePtr->borderWidth, TK_RELIEF_RAISED);    /*     * If double-buffered, copy to the screen and release the pixmap.     */    if (squarePtr->doubleBuffer) {	XCopyArea(Tk_Display(tkwin), pm, Tk_WindowId(tkwin), squarePtr->gc,		0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),		0, 0);	Tk_FreePixmap(Tk_Display(tkwin), pm);    }}/* *---------------------------------------------------------------------- * * SquareDestroy -- * *	This procedure is invoked by Tcl_EventuallyFree or Tcl_Release *	to clean up the internal structure of a square at a safe time *	(when no-one is using it anymore). * * Results: *	None. * * Side effects: *	Everything associated with the square is freed up. * *---------------------------------------------------------------------- */static voidSquareDestroy(memPtr)    char *memPtr;		/* Info about square widget. */{    Square *squarePtr = (Square *) memPtr;    Tk_FreeOptions(configSpecs, (char *) squarePtr, squarePtr->display, 0);    if (squarePtr->gc != None) {	Tk_FreeGC(squarePtr->display, squarePtr->gc);    }    ckfree((char *) squarePtr);}/* *---------------------------------------------------------------------- * * KeepInWindow -- * *	Adjust the position of the square if necessary to keep it in *	the widget's window. * * Results: *	None. * * Side effects: *	The x and y position of the square are adjusted if necessary *	to keep the square in the window. * *---------------------------------------------------------------------- */static voidKeepInWindow(squarePtr)    register Square *squarePtr;		/* Pointer to widget record. */{    int i, bd;    bd = 0;    if (squarePtr->relief != TK_RELIEF_FLAT) {	bd = squarePtr->borderWidth;    }    i = (Tk_Width(squarePtr->tkwin) - bd) - (squarePtr->x + squarePtr->size);    if (i < 0) {	squarePtr->x += i;    }    i = (Tk_Height(squarePtr->tkwin) - bd) - (squarePtr->y + squarePtr->size);    if (i < 0) {	squarePtr->y += i;    }    if (squarePtr->x < bd) {	squarePtr->x = bd;    }    if (squarePtr->y < bd) {	squarePtr->y = bd;    }}

⌨️ 快捷键说明

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