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

📄 tkbutton.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*     * Recompute GCs.     */    gcValues.font = Tk_FontId(butPtr->tkfont);    gcValues.foreground = butPtr->normalFg->pixel;    gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel;        /*     * Note: GraphicsExpose events are disabled in normalTextGC because it's     * used to copy stuff from an off-screen pixmap onto the screen (we know     * that there's no problem with obscured areas).     */    gcValues.graphics_exposures = False;    mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;    newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);    if (butPtr->normalTextGC != None) {	Tk_FreeGC(butPtr->display, butPtr->normalTextGC);    }    butPtr->normalTextGC = newGC;    if (butPtr->activeFg != NULL) {	gcValues.font = Tk_FontId(butPtr->tkfont);	gcValues.foreground = butPtr->activeFg->pixel;	gcValues.background = Tk_3DBorderColor(butPtr->activeBorder)->pixel;	mask = GCForeground | GCBackground | GCFont;	newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);	if (butPtr->activeTextGC != None) {	    Tk_FreeGC(butPtr->display, butPtr->activeTextGC);	}	butPtr->activeTextGC = newGC;    }    if (butPtr->type != TYPE_LABEL) {	gcValues.font = Tk_FontId(butPtr->tkfont);	gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel;	if ((butPtr->disabledFg != NULL) && (butPtr->imageString == NULL)) {	    gcValues.foreground = butPtr->disabledFg->pixel;	    mask = GCForeground | GCBackground | GCFont;	} else {	    gcValues.foreground = gcValues.background;	    mask = GCForeground;	    if (butPtr->gray == None) {		butPtr->gray = Tk_GetBitmap(NULL, butPtr->tkwin, 			Tk_GetUid("gray50"));	    }	    if (butPtr->gray != None) {		gcValues.fill_style = FillStippled;		gcValues.stipple = butPtr->gray;		mask |= GCFillStyle | GCStipple;	    }	}	newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);	if (butPtr->disabledGC != None) {	    Tk_FreeGC(butPtr->display, butPtr->disabledGC);	}	butPtr->disabledGC = newGC;    }    if (butPtr->copyGC == None) {	butPtr->copyGC = Tk_GetGC(butPtr->tkwin, 0, &gcValues);    }    TkpComputeButtonGeometry(butPtr);    /*     * Lastly, arrange for the button to be redisplayed.     */    if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) {	Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	butPtr->flags |= REDRAW_PENDING;    }}/* *-------------------------------------------------------------- * * ButtonEventProc -- * *	This procedure is invoked by the Tk dispatcher for various *	events on buttons. * * Results: *	None. * * Side effects: *	When the window gets deleted, internal structures get *	cleaned up.  When it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */static voidButtonEventProc(clientData, eventPtr)    ClientData clientData;	/* Information about window. */    XEvent *eventPtr;		/* Information about event. */{    TkButton *butPtr = (TkButton *) clientData;    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {	goto redraw;    } else if (eventPtr->type == ConfigureNotify) {	/*	 * Must redraw after size changes, since layout could have changed	 * and borders will need to be redrawn.	 */	goto redraw;    } else if (eventPtr->type == DestroyNotify) {	TkpDestroyButton(butPtr);	if (butPtr->tkwin != NULL) {	    butPtr->tkwin = NULL;            Tcl_DeleteCommandFromToken(butPtr->interp, butPtr->widgetCmd);	}	if (butPtr->flags & REDRAW_PENDING) {	    Tcl_CancelIdleCall(TkpDisplayButton, (ClientData) butPtr);	}	DestroyButton(butPtr);    } else if (eventPtr->type == FocusIn) {	if (eventPtr->xfocus.detail != NotifyInferior) {	    butPtr->flags |= GOT_FOCUS;	    if (butPtr->highlightWidth > 0) {		goto redraw;	    }	}    } else if (eventPtr->type == FocusOut) {	if (eventPtr->xfocus.detail != NotifyInferior) {	    butPtr->flags &= ~GOT_FOCUS;	    if (butPtr->highlightWidth > 0) {		goto redraw;	    }	}    }    return;    redraw:    if ((butPtr->tkwin != NULL) && !(butPtr->flags & REDRAW_PENDING)) {	Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	butPtr->flags |= REDRAW_PENDING;    }}/* *---------------------------------------------------------------------- * * ButtonCmdDeletedProc -- * *	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 voidButtonCmdDeletedProc(clientData)    ClientData clientData;	/* Pointer to widget record for widget. */{    TkButton *butPtr = (TkButton *) clientData;    Tk_Window tkwin = butPtr->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) {	butPtr->tkwin = NULL;	Tk_DestroyWindow(tkwin);    }}/* *---------------------------------------------------------------------- * * TkInvokeButton -- * *	This procedure is called to carry out the actions associated *	with a button, such as invoking a Tcl command or setting a *	variable.  This procedure is invoked, for example, when the *	button is invoked via the mouse. * * Results: *	A standard Tcl return value.  Information is also left in *	interp->result. * * Side effects: *	Depends on the button and its associated command. * *---------------------------------------------------------------------- */intTkInvokeButton(butPtr)    register TkButton *butPtr;		/* Information about button. */{    if (butPtr->type == TYPE_CHECK_BUTTON) {	if (butPtr->flags & SELECTED) {	    if (Tcl_SetVar(butPtr->interp, butPtr->selVarName, butPtr->offValue,		    TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) == NULL) {		return TCL_ERROR;	    }	} else {	    if (Tcl_SetVar(butPtr->interp, butPtr->selVarName, butPtr->onValue,		    TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) == NULL) {		return TCL_ERROR;	    }	}    } else if (butPtr->type == TYPE_RADIO_BUTTON) {	if (Tcl_SetVar(butPtr->interp, butPtr->selVarName, butPtr->onValue,		TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) == NULL) {	    return TCL_ERROR;	}    }    if ((butPtr->type != TYPE_LABEL) && (butPtr->command != NULL)) {	return TkCopyAndGlobalEval(butPtr->interp, butPtr->command);    }    return TCL_OK;}/* *-------------------------------------------------------------- * * ButtonVarProc -- * *	This procedure is invoked when someone changes the *	state variable associated with a radio button.  Depending *	on the new value of the button's variable, the button *	may be selected or deselected. * * Results: *	NULL is always returned. * * Side effects: *	The button may become selected or deselected. * *-------------------------------------------------------------- */	/* ARGSUSED */static char *ButtonVarProc(clientData, interp, name1, name2, flags)    ClientData clientData;	/* Information about button. */    Tcl_Interp *interp;		/* Interpreter containing variable. */    char *name1;		/* Name of variable. */    char *name2;		/* Second part of variable name. */    int flags;			/* Information about what happened. */{    register TkButton *butPtr = (TkButton *) clientData;    char *value;    /*     * If the variable is being unset, then just re-establish the     * trace unless the whole interpreter is going away.     */    if (flags & TCL_TRACE_UNSETS) {	butPtr->flags &= ~SELECTED;	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {	    Tcl_TraceVar(interp, butPtr->selVarName,		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,		    ButtonVarProc, clientData);	}	goto redisplay;    }    /*     * Use the value of the variable to update the selected status of     * the button.     */    value = Tcl_GetVar(interp, butPtr->selVarName, TCL_GLOBAL_ONLY);    if (value == NULL) {	value = "";    }    if (strcmp(value, butPtr->onValue) == 0) {	if (butPtr->flags & SELECTED) {	    return (char *) NULL;	}	butPtr->flags |= SELECTED;    } else if (butPtr->flags & SELECTED) {	butPtr->flags &= ~SELECTED;    } else {	return (char *) NULL;    }    redisplay:    if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin)	    && !(butPtr->flags & REDRAW_PENDING)) {	Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	butPtr->flags |= REDRAW_PENDING;    }    return (char *) NULL;}/* *-------------------------------------------------------------- * * ButtonTextVarProc -- * *	This procedure is invoked when someone changes the variable *	whose contents are to be displayed in a button. * * Results: *	NULL is always returned. * * Side effects: *	The text displayed in the button will change to match the *	variable. * *-------------------------------------------------------------- */	/* ARGSUSED */static char *ButtonTextVarProc(clientData, interp, name1, name2, flags)    ClientData clientData;	/* Information about button. */    Tcl_Interp *interp;		/* Interpreter containing variable. */    char *name1;		/* Not used. */    char *name2;		/* Not used. */    int flags;			/* Information about what happened. */{    register TkButton *butPtr = (TkButton *) clientData;    char *value;    /*     * If the variable is unset, then immediately recreate it unless     * the whole interpreter is going away.     */    if (flags & TCL_TRACE_UNSETS) {	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {	    Tcl_SetVar(interp, butPtr->textVarName, butPtr->text,		    TCL_GLOBAL_ONLY);	    Tcl_TraceVar(interp, butPtr->textVarName,		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,		    ButtonTextVarProc, clientData);	}	return (char *) NULL;    }    value = Tcl_GetVar(interp, butPtr->textVarName, TCL_GLOBAL_ONLY);    if (value == NULL) {	value = "";    }    if (butPtr->text != NULL) {	ckfree(butPtr->text);    }    butPtr->text = (char *) ckalloc((unsigned) (strlen(value) + 1));    strcpy(butPtr->text, value);    TkpComputeButtonGeometry(butPtr);    if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin)	    && !(butPtr->flags & REDRAW_PENDING)) {	Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	butPtr->flags |= REDRAW_PENDING;    }    return (char *) NULL;}/* *---------------------------------------------------------------------- * * ButtonImageProc -- * *	This procedure is invoked by the image code whenever the manager *	for an image does something that affects the size of contents *	of an image displayed in a button. * * Results: *	None. * * Side effects: *	Arranges for the button to get redisplayed. * *---------------------------------------------------------------------- */static voidButtonImageProc(clientData, x, y, width, height, imgWidth, imgHeight)    ClientData clientData;		/* Pointer to widget record. */    int x, y;				/* Upper left pixel (within image)					 * that must be redisplayed. */    int width, height;			/* Dimensions of area to redisplay					 * (may be <= 0). */    int imgWidth, imgHeight;		/* New dimensions of image. */{    register TkButton *butPtr = (TkButton *) clientData;    if (butPtr->tkwin != NULL) {	TkpComputeButtonGeometry(butPtr);	if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) {	    Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	    butPtr->flags |= REDRAW_PENDING;	}    }}/* *---------------------------------------------------------------------- * * ButtonSelectImageProc -- * *	This procedure is invoked by the image code whenever the manager *	for an image does something that affects the size of contents *	of the image displayed in a button when it is selected. * * Results: *	None. * * Side effects: *	May arrange for the button to get redisplayed. * *---------------------------------------------------------------------- */static voidButtonSelectImageProc(clientData, x, y, width, height, imgWidth, imgHeight)    ClientData clientData;		/* Pointer to widget record. */    int x, y;				/* Upper left pixel (within image)					 * that must be redisplayed. */    int width, height;			/* Dimensions of area to redisplay					 * (may be <= 0). */    int imgWidth, imgHeight;		/* New dimensions of image. */{    register TkButton *butPtr = (TkButton *) clientData;    /*     * Don't recompute geometry:  it's controlled by the primary image.     */    if ((butPtr->flags & SELECTED) && (butPtr->tkwin != NULL)	    && Tk_IsMapped(butPtr->tkwin)	    && !(butPtr->flags & REDRAW_PENDING)) {	Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) butPtr);	butPtr->flags |= REDRAW_PENDING;    }}

⌨️ 快捷键说明

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