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

📄 tkbutton.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  * tkButton.c -- * *	This module implements a collection of button-like *	widgets for the Tk toolkit.  The widgets implemented *	include labels, buttons, check buttons, and radio *	buttons. * * Copyright (c) 1990-1994 The Regents of the University of California. * Copyright (c) 1994-1995 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: @(#) tkButton.c 1.144 97/07/31 09:04:57 */#include "tkButton.h"#include "default.h"/* * Class names for buttons, indexed by one of the type values above. */static char *classNames[] = {"Label", "Button", "Checkbutton", "Radiobutton"};/* * The class procedure table for the button widget. */static int configFlags[] = {LABEL_MASK, BUTTON_MASK,	CHECK_BUTTON_MASK, RADIO_BUTTON_MASK};/* * Information used for parsing configuration specs: */Tk_ConfigSpec tkpButtonConfigSpecs[] = {    {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",	DEF_BUTTON_ACTIVE_BG_COLOR, Tk_Offset(TkButton, activeBorder),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK	|TK_CONFIG_COLOR_ONLY},    {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",	DEF_BUTTON_ACTIVE_BG_MONO, Tk_Offset(TkButton, activeBorder),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK	|TK_CONFIG_MONO_ONLY},    {TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Background",	DEF_BUTTON_ACTIVE_FG_COLOR, Tk_Offset(TkButton, activeFg), 	BUTTON_MASK|TK_CONFIG_COLOR_ONLY},    {TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Background",	DEF_CHKRAD_ACTIVE_FG_COLOR, Tk_Offset(TkButton, activeFg), 	CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_COLOR_ONLY},    {TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Background",	DEF_BUTTON_ACTIVE_FG_MONO, Tk_Offset(TkButton, activeFg), 	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK	|TK_CONFIG_MONO_ONLY},    {TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",	DEF_BUTTON_ANCHOR, Tk_Offset(TkButton, anchor), ALL_MASK},    {TK_CONFIG_BORDER, "-background", "background", "Background",	DEF_BUTTON_BG_COLOR, Tk_Offset(TkButton, normalBorder),	ALL_MASK | TK_CONFIG_COLOR_ONLY},    {TK_CONFIG_BORDER, "-background", "background", "Background",	DEF_BUTTON_BG_MONO, Tk_Offset(TkButton, normalBorder),	ALL_MASK | TK_CONFIG_MONO_ONLY},    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,	(char *) NULL, 0, ALL_MASK},    {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,	(char *) NULL, 0, ALL_MASK},    {TK_CONFIG_BITMAP, "-bitmap", "bitmap", "Bitmap",	DEF_BUTTON_BITMAP, Tk_Offset(TkButton, bitmap),	ALL_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",	DEF_BUTTON_BORDER_WIDTH, Tk_Offset(TkButton, borderWidth), ALL_MASK},    {TK_CONFIG_STRING, "-command", "command", "Command",	DEF_BUTTON_COMMAND, Tk_Offset(TkButton, command),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",	DEF_BUTTON_CURSOR, Tk_Offset(TkButton, cursor),	ALL_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_UID, "-default", "default", "Default",        DEF_BUTTON_DEFAULT, Tk_Offset(TkButton, defaultState), BUTTON_MASK},    {TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground",	"DisabledForeground", DEF_BUTTON_DISABLED_FG_COLOR,	Tk_Offset(TkButton, disabledFg), BUTTON_MASK|CHECK_BUTTON_MASK	|RADIO_BUTTON_MASK|TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},    {TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground",	"DisabledForeground", DEF_BUTTON_DISABLED_FG_MONO,	Tk_Offset(TkButton, disabledFg), BUTTON_MASK|CHECK_BUTTON_MASK	|RADIO_BUTTON_MASK|TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},    {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,	(char *) NULL, 0, ALL_MASK},    {TK_CONFIG_FONT, "-font", "font", "Font",	DEF_BUTTON_FONT, Tk_Offset(TkButton, tkfont),	ALL_MASK},    {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",	DEF_BUTTON_FG, Tk_Offset(TkButton, normalFg), LABEL_MASK|BUTTON_MASK},    {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",	DEF_CHKRAD_FG, Tk_Offset(TkButton, normalFg), CHECK_BUTTON_MASK	|RADIO_BUTTON_MASK},    {TK_CONFIG_STRING, "-height", "height", "Height",	DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightString), ALL_MASK},    {TK_CONFIG_BORDER, "-highlightbackground", "highlightBackground",	"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG,	Tk_Offset(TkButton, highlightBorder), ALL_MASK},    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",	DEF_BUTTON_HIGHLIGHT, Tk_Offset(TkButton, highlightColorPtr),	ALL_MASK},    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",	"HighlightThickness",	DEF_LABEL_HIGHLIGHT_WIDTH, Tk_Offset(TkButton, highlightWidth),	LABEL_MASK},    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",	"HighlightThickness",	DEF_BUTTON_HIGHLIGHT_WIDTH, Tk_Offset(TkButton, highlightWidth),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_STRING, "-image", "image", "Image",	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, imageString),	ALL_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn",	DEF_BUTTON_INDICATOR, Tk_Offset(TkButton, indicatorOn),	CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify",	DEF_BUTTON_JUSTIFY, Tk_Offset(TkButton, justify), ALL_MASK},    {TK_CONFIG_STRING, "-offvalue", "offValue", "Value",	DEF_BUTTON_OFF_VALUE, Tk_Offset(TkButton, offValue),	CHECK_BUTTON_MASK},    {TK_CONFIG_STRING, "-onvalue", "onValue", "Value",	DEF_BUTTON_ON_VALUE, Tk_Offset(TkButton, onValue),	CHECK_BUTTON_MASK},    {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",	DEF_BUTTON_PADX, Tk_Offset(TkButton, padX), BUTTON_MASK},    {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",	DEF_LABCHKRAD_PADX, Tk_Offset(TkButton, padX),	LABEL_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",	DEF_BUTTON_PADY, Tk_Offset(TkButton, padY), BUTTON_MASK},    {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",	DEF_LABCHKRAD_PADY, Tk_Offset(TkButton, padY),	LABEL_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",	DEF_BUTTON_RELIEF, Tk_Offset(TkButton, relief), BUTTON_MASK},    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",	DEF_LABCHKRAD_RELIEF, Tk_Offset(TkButton, relief),	LABEL_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_BORDER, "-selectcolor", "selectColor", "Background",	DEF_BUTTON_SELECT_COLOR, Tk_Offset(TkButton, selectBorder),	CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_COLOR_ONLY	|TK_CONFIG_NULL_OK},    {TK_CONFIG_BORDER, "-selectcolor", "selectColor", "Background",	DEF_BUTTON_SELECT_MONO, Tk_Offset(TkButton, selectBorder),	CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_MONO_ONLY	|TK_CONFIG_NULL_OK},    {TK_CONFIG_STRING, "-selectimage", "selectImage", "SelectImage",	DEF_BUTTON_SELECT_IMAGE, Tk_Offset(TkButton, selectImageString),	CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_UID, "-state", "state", "State",	DEF_BUTTON_STATE, Tk_Offset(TkButton, state),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK},    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",	DEF_LABEL_TAKE_FOCUS, Tk_Offset(TkButton, takeFocus),	LABEL_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",	DEF_BUTTON_TAKE_FOCUS, Tk_Offset(TkButton, takeFocus),	BUTTON_MASK|CHECK_BUTTON_MASK|RADIO_BUTTON_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_STRING, "-text", "text", "Text",	DEF_BUTTON_TEXT, Tk_Offset(TkButton, text), ALL_MASK},    {TK_CONFIG_STRING, "-textvariable", "textVariable", "Variable",	DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(TkButton, textVarName),	ALL_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_INT, "-underline", "underline", "Underline",	DEF_BUTTON_UNDERLINE, Tk_Offset(TkButton, underline), ALL_MASK},    {TK_CONFIG_STRING, "-value", "value", "Value",	DEF_BUTTON_VALUE, Tk_Offset(TkButton, onValue),	RADIO_BUTTON_MASK},    {TK_CONFIG_STRING, "-variable", "variable", "Variable",	DEF_RADIOBUTTON_VARIABLE, Tk_Offset(TkButton, selVarName),	RADIO_BUTTON_MASK},    {TK_CONFIG_STRING, "-variable", "variable", "Variable",	DEF_CHECKBUTTON_VARIABLE, Tk_Offset(TkButton, selVarName),	CHECK_BUTTON_MASK|TK_CONFIG_NULL_OK},    {TK_CONFIG_STRING, "-width", "width", "Width",	DEF_BUTTON_WIDTH, Tk_Offset(TkButton, widthString), ALL_MASK},    {TK_CONFIG_PIXELS, "-wraplength", "wrapLength", "WrapLength",	DEF_BUTTON_WRAP_LENGTH, Tk_Offset(TkButton, wrapLength), ALL_MASK},    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,	(char *) NULL, 0, 0}};/* * String to print out in error messages, identifying options for * widget commands for different types of labels or buttons: */static char *optionStrings[] = {    "cget or configure",    "cget, configure, flash, or invoke",    "cget, configure, deselect, flash, invoke, select, or toggle",    "cget, configure, deselect, flash, invoke, or select"};/* * Forward declarations for procedures defined later in this file: */static void		ButtonCmdDeletedProc _ANSI_ARGS_((			    ClientData clientData));static int		ButtonCreate _ANSI_ARGS_((ClientData clientData,			    Tcl_Interp *interp, int argc, char **argv,			    int type));static void		ButtonEventProc _ANSI_ARGS_((ClientData clientData,			    XEvent *eventPtr));static void		ButtonImageProc _ANSI_ARGS_((ClientData clientData,			    int x, int y, int width, int height,			    int imgWidth, int imgHeight));static void		ButtonSelectImageProc _ANSI_ARGS_((			    ClientData clientData, int x, int y, int width,			    int height, int imgWidth, int imgHeight));static char *		ButtonTextVarProc _ANSI_ARGS_((ClientData clientData,			    Tcl_Interp *interp, char *name1, char *name2,			    int flags));static char *		ButtonVarProc _ANSI_ARGS_((ClientData clientData,			    Tcl_Interp *interp, char *name1, char *name2,			    int flags));static int		ButtonWidgetCmd _ANSI_ARGS_((ClientData clientData,			    Tcl_Interp *interp, int argc, char **argv));static int		ConfigureButton _ANSI_ARGS_((Tcl_Interp *interp,			    TkButton *butPtr, int argc, char **argv,			    int flags));static void		DestroyButton _ANSI_ARGS_((TkButton *butPtr));/* *-------------------------------------------------------------- * * Tk_ButtonCmd, Tk_CheckbuttonCmd, Tk_LabelCmd, Tk_RadiobuttonCmd -- * *	These procedures are invoked to process the "button", "label", *	"radiobutton", and "checkbutton" Tcl commands.  See the *	user documentation for details on what they do. * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation.  These procedures are just wrappers; *	they call ButtonCreate to do all of the real work. * *-------------------------------------------------------------- */intTk_ButtonCmd(clientData, interp, argc, argv)    ClientData clientData;	/* Main window associated with				 * interpreter. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */{    return ButtonCreate(clientData, interp, argc, argv, TYPE_BUTTON);}intTk_CheckbuttonCmd(clientData, interp, argc, argv)    ClientData clientData;	/* Main window associated with				 * interpreter. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */{    return ButtonCreate(clientData, interp, argc, argv, TYPE_CHECK_BUTTON);}intTk_LabelCmd(clientData, interp, argc, argv)    ClientData clientData;	/* Main window associated with				 * interpreter. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */{    return ButtonCreate(clientData, interp, argc, argv, TYPE_LABEL);}intTk_RadiobuttonCmd(clientData, interp, argc, argv)    ClientData clientData;	/* Main window associated with				 * interpreter. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */{    return ButtonCreate(clientData, interp, argc, argv, TYPE_RADIO_BUTTON);}/* *-------------------------------------------------------------- * * ButtonCreate -- * *	This procedure does all the real work of implementing the *	"button", "label", "radiobutton", and "checkbutton" Tcl *	commands.  See the user documentation for details on what it does. * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation. * *-------------------------------------------------------------- */static intButtonCreate(clientData, interp, argc, argv, type)    ClientData clientData;	/* Main window associated with				 * interpreter. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */    int type;			/* Type of button to create: TYPE_LABEL,				 * TYPE_BUTTON, TYPE_CHECK_BUTTON, or				 * TYPE_RADIO_BUTTON. */{    register TkButton *butPtr;    Tk_Window tkwin = (Tk_Window) clientData;    Tk_Window new;    if (argc < 2) {	Tcl_AppendResult(interp, "wrong # args: should be \"",		argv[0], " pathName ?options?\"", (char *) NULL);	return TCL_ERROR;    }    /*     * Create the new window.     */    new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], (char *) NULL);    if (new == NULL) {	return TCL_ERROR;    }    Tk_SetClass(new, classNames[type]);    butPtr = TkpCreateButton(new);    TkSetClassProcs(new, &tkpButtonProcs, (ClientData) butPtr);    /*     * Initialize the data structure for the button.     */    butPtr->tkwin = new;    butPtr->display = Tk_Display(new);    butPtr->widgetCmd = Tcl_CreateCommand(interp, Tk_PathName(butPtr->tkwin),	    ButtonWidgetCmd, (ClientData) butPtr, ButtonCmdDeletedProc);    butPtr->interp = interp;    butPtr->type = type;    butPtr->text = NULL;    butPtr->underline = -1;    butPtr->textVarName = NULL;    butPtr->bitmap = None;    butPtr->imageString = NULL;    butPtr->image = NULL;    butPtr->selectImageString = NULL;    butPtr->selectImage = NULL;    butPtr->state = tkNormalUid;    butPtr->normalBorder = NULL;    butPtr->activeBorder = NULL;    butPtr->borderWidth = 0;    butPtr->relief = TK_RELIEF_FLAT;    butPtr->highlightWidth = 0;    butPtr->highlightBorder = NULL;    butPtr->highlightColorPtr = NULL;    butPtr->inset = 0;    butPtr->tkfont = NULL;    butPtr->normalFg = NULL;    butPtr->activeFg = NULL;    butPtr->disabledFg = NULL;    butPtr->normalTextGC = None;    butPtr->activeTextGC = None;    butPtr->gray = None;    butPtr->disabledGC = None;    butPtr->copyGC = None;    butPtr->widthString = NULL;    butPtr->heightString = NULL;    butPtr->width = 0;    butPtr->height = 0;    butPtr->wrapLength = 0;    butPtr->padX = 0;    butPtr->padY = 0;    butPtr->anchor = TK_ANCHOR_CENTER;    butPtr->justify = TK_JUSTIFY_CENTER;    butPtr->textLayout = NULL;    butPtr->indicatorOn = 0;    butPtr->selectBorder = NULL;    butPtr->indicatorSpace = 0;    butPtr->indicatorDiameter = 0;    butPtr->defaultState = tkDisabledUid;    butPtr->selVarName = NULL;    butPtr->onValue = NULL;    butPtr->offValue = NULL;    butPtr->cursor = None;    butPtr->command = NULL;    butPtr->takeFocus = NULL;    butPtr->flags = 0;    Tk_CreateEventHandler(butPtr->tkwin,	    ExposureMask|StructureNotifyMask|FocusChangeMask,	    ButtonEventProc, (ClientData) butPtr);    if (ConfigureButton(interp, butPtr, argc - 2, argv + 2,	    configFlags[type]) != TCL_OK) {	Tk_DestroyWindow(butPtr->tkwin);	return TCL_ERROR;    }    interp->result = Tk_PathName(butPtr->tkwin);    return TCL_OK;}/* *-------------------------------------------------------------- * * ButtonWidgetCmd -- * *	This procedure is invoked to process the Tcl command *	that corresponds to a widget managed by this module. *	See the user documentation for details on what it does. * * Results: *	A standard Tcl result. * * Side effects: *	See the user documentation. * *-------------------------------------------------------------- */static intButtonWidgetCmd(clientData, interp, argc, argv)    ClientData clientData;	/* Information about button widget. */    Tcl_Interp *interp;		/* Current interpreter. */    int argc;			/* Number of arguments. */    char **argv;		/* Argument strings. */{    register TkButton *butPtr = (TkButton *) clientData;    int result = TCL_OK;    size_t length;    int c;

⌨️ 快捷键说明

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