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

📄 tklistbox.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 5 页
字号:
    interp->result = Tk_PathName(listPtr->tkwin);    return TCL_OK;    error:    Tk_DestroyWindow(listPtr->tkwin);    return TCL_ERROR;}/* *-------------------------------------------------------------- * * ListboxWidgetCmd -- * *	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 intListboxWidgetCmd(clientData, interp, argc, argv)    ClientData clientData;		/* Information about listbox widget. */    Tcl_Interp *interp;			/* Current interpreter. */    int argc;				/* Number of arguments. */    char **argv;			/* Argument strings. */{    register Listbox *listPtr = (Listbox *) clientData;    int result = TCL_OK;    size_t length;    int c;    Tk_FontMetrics fm;    if (argc < 2) {	Tcl_AppendResult(interp, "wrong # args: should be \"",		argv[0], " option ?arg arg ...?\"", (char *) NULL);	return TCL_ERROR;    }    Tcl_Preserve((ClientData) listPtr);    c = argv[1][0];    length = strlen(argv[1]);    if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) {	int index;	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " activate index\"",		    (char *) NULL);	    goto error;	}	ListboxRedrawRange(listPtr, listPtr->active, listPtr->active);	if (GetListboxIndex(interp, listPtr, argv[2], 0, &index) != TCL_OK) {	    goto error;	}	if (index >= listPtr->numElements) {	    index = listPtr->numElements-1;	}	if (index < 0) {	    index = 0;	}	listPtr->active = index;	ListboxRedrawRange(listPtr, listPtr->active, listPtr->active);    } else if ((c == 'b') && (strncmp(argv[1], "bbox", length) == 0)) {	int index, x, y, i;	Element *elPtr;	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " bbox index\"", (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 0, &index) != TCL_OK) {	    goto error;	}	if ((index >= listPtr->numElements) || (index < 0)) {	    goto done;	}	for (i = 0, elPtr = listPtr->firstPtr; i < index;		i++, elPtr = elPtr->nextPtr) {	    /* Empty loop body. */	}	if ((index >= listPtr->topIndex) && (index < listPtr->numElements)		    && (index < (listPtr->topIndex + listPtr->fullLines		    + listPtr->partialLine))) {	    x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset;	    y = ((index - listPtr->topIndex)*listPtr->lineHeight)		    + listPtr->inset + listPtr->selBorderWidth;	    Tk_GetFontMetrics(listPtr->tkfont, &fm);	    sprintf(interp->result, "%d %d %d %d", x, y, elPtr->pixelWidth,		    fm.linespace);	}    } else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)	    && (length >= 2)) {	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " cget option\"",		    (char *) NULL);	    goto error;	}	result = Tk_ConfigureValue(interp, listPtr->tkwin, configSpecs,		(char *) listPtr, argv[2], 0);    } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)	    && (length >= 2)) {	if (argc == 2) {	    result = Tk_ConfigureInfo(interp, listPtr->tkwin, configSpecs,		    (char *) listPtr, (char *) NULL, 0);	} else if (argc == 3) {	    result = Tk_ConfigureInfo(interp, listPtr->tkwin, configSpecs,		    (char *) listPtr, argv[2], 0);	} else {	    result = ConfigureListbox(interp, listPtr, argc-2, argv+2,		    TK_CONFIG_ARGV_ONLY);	}    } else if ((c == 'c') && (strncmp(argv[1], "curselection", length) == 0)	    && (length >= 2)) {	int i, count;	char index[20];	Element *elPtr;	if (argc != 2) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " curselection\"",		    (char *) NULL);	    goto error;	}	count = 0;	for (i = 0, elPtr = listPtr->firstPtr; elPtr != NULL;		i++, elPtr = elPtr->nextPtr) {	    if (elPtr->selected) {		sprintf(index, "%d", i);		Tcl_AppendElement(interp, index);		count++;	    }	}	if (count != listPtr->numSelected) {	    panic("ListboxWidgetCmd: selection count incorrect");	}    } else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {	int first, last;	if ((argc < 3) || (argc > 4)) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " delete firstIndex ?lastIndex?\"",		    (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 0, &first) != TCL_OK) {	    goto error;	}	if (first < listPtr->numElements) {	    if (argc == 3) {		last = first;	    } else {		if (GetListboxIndex(interp, listPtr, argv[3], 0,			&last) != TCL_OK) {		    goto error;		}		if (last >= listPtr->numElements) {		    last = listPtr->numElements-1;		}	    }	    DeleteEls(listPtr, first, last);	}    } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {	int first, last, i;	Element *elPtr;	if ((argc != 3) && (argc != 4)) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " get first ?last?\"", (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 0, &first) != TCL_OK) {	    goto error;	}	if ((argc == 4) && (GetListboxIndex(interp, listPtr, argv[3],		0, &last) != TCL_OK)) {	    goto error;	}	if (first >= listPtr->numElements) {	    goto done;	}	if (last >= listPtr->numElements) {	    last = listPtr->numElements-1;	}	for (elPtr = listPtr->firstPtr, i = 0; i < first;		i++, elPtr = elPtr->nextPtr) {	    /* Empty loop body. */	}	if (elPtr != NULL) {	    if (argc == 3) {		if (first >= 0) {		    interp->result = elPtr->text;		}	    } else {		for (  ; i <= last; i++, elPtr = elPtr->nextPtr) {		    Tcl_AppendElement(interp, elPtr->text);		}	    }	}    } else if ((c == 'i') && (strncmp(argv[1], "index", length) == 0)	    && (length >= 3)) {	int index;	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " index index\"",		    (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 1, &index)		!= TCL_OK) {	    goto error;	}	sprintf(interp->result, "%d", index);    } else if ((c == 'i') && (strncmp(argv[1], "insert", length) == 0)	    && (length >= 3)) {	int index;	if (argc < 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " insert index ?element element ...?\"",		    (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 1, &index)		!= TCL_OK) {	    goto error;	}	InsertEls(listPtr, index, argc-3, argv+3);    } else if ((c == 'n') && (strncmp(argv[1], "nearest", length) == 0)) {	int index, y;	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " nearest y\"", (char *) NULL);	    goto error;	}	if (Tcl_GetInt(interp, argv[2], &y) != TCL_OK) {	    goto error;	}	index = NearestListboxElement(listPtr, y);	sprintf(interp->result, "%d", index);    } else if ((c == 's') && (length >= 2)	    && (strncmp(argv[1], "scan", length) == 0)) {	int x, y;	if (argc != 5) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " scan mark|dragto x y\"", (char *) NULL);	    goto error;	}	if ((Tcl_GetInt(interp, argv[3], &x) != TCL_OK)		|| (Tcl_GetInt(interp, argv[4], &y) != TCL_OK)) {	    goto error;	}	if ((argv[2][0] == 'm')		&& (strncmp(argv[2], "mark", strlen(argv[2])) == 0)) {	    listPtr->scanMarkX = x;	    listPtr->scanMarkY = y;	    listPtr->scanMarkXOffset = listPtr->xOffset;	    listPtr->scanMarkYIndex = listPtr->topIndex;	} else if ((argv[2][0] == 'd')		&& (strncmp(argv[2], "dragto", strlen(argv[2])) == 0)) {	    ListboxScanTo(listPtr, x, y);	} else {	    Tcl_AppendResult(interp, "bad scan option \"", argv[2],		    "\": must be mark or dragto", (char *) NULL);	    goto error;	}    } else if ((c == 's') && (strncmp(argv[1], "see", length) == 0)	    && (length >= 3)) {	int index, diff;	if (argc != 3) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " see index\"",		    (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[2], 0, &index) != TCL_OK) {	    goto error;	}	if (index >= listPtr->numElements) {	    index = listPtr->numElements-1;	}	if (index < 0) {	    index = 0;	}	diff = listPtr->topIndex-index;	if (diff > 0) {	    if (diff <= (listPtr->fullLines/3)) {		ChangeListboxView(listPtr, index);	    } else {		ChangeListboxView(listPtr, index - (listPtr->fullLines-1)/2);	    }	} else {	    diff = index - (listPtr->topIndex + listPtr->fullLines - 1);	    if (diff > 0) {		if (diff <= (listPtr->fullLines/3)) {		    ChangeListboxView(listPtr, listPtr->topIndex + diff);		} else {		    ChangeListboxView(listPtr,			    index - (listPtr->fullLines-1)/2);		}	    }	}    } else if ((c == 's') && (length >= 3)	    && (strncmp(argv[1], "selection", length) == 0)) {	int first, last;	if ((argc != 4) && (argc != 5)) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " selection option index ?index?\"",		    (char *) NULL);	    goto error;	}	if (GetListboxIndex(interp, listPtr, argv[3], 0, &first) != TCL_OK) {	    goto error;	}	if (argc == 5) {	    if (GetListboxIndex(interp, listPtr, argv[4], 0, &last) != TCL_OK) {		goto error;	    }	} else {	    last = first;	}	length = strlen(argv[2]);	c = argv[2][0];	if ((c == 'a') && (strncmp(argv[2], "anchor", length) == 0)) {	    if (argc != 4) {		Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " selection anchor index\"", (char *) NULL);		goto error;	    }	    if (first >= listPtr->numElements) {		first = listPtr->numElements-1;	    }	    if (first < 0) {		first = 0;	    }	    listPtr->selectAnchor = first;	} else if ((c == 'c') && (strncmp(argv[2], "clear", length) == 0)) {	    ListboxSelect(listPtr, first, last, 0);	} else if ((c == 'i') && (strncmp(argv[2], "includes", length) == 0)) {	    int i;	    Element *elPtr;    	    if (argc != 4) {		Tcl_AppendResult(interp, "wrong # args: should be \"",			argv[0], " selection includes index\"", (char *) NULL);		goto error;	    }	    if ((first < 0) || (first >= listPtr->numElements)) {		interp->result = "0";		goto done;	    }	    for (elPtr = listPtr->firstPtr, i = 0; i < first;		    i++, elPtr = elPtr->nextPtr) {		/* Empty loop body. */	    }	    if (elPtr->selected) {		interp->result = "1";	    } else {		interp->result = "0";	    }	} else if ((c == 's') && (strncmp(argv[2], "set", length) == 0)) {	    ListboxSelect(listPtr, first, last, 1);	} else {	    Tcl_AppendResult(interp, "bad selection option \"", argv[2],		    "\": must be anchor, clear, includes, or set",		    (char *) NULL);	    goto error;	}    } else if ((c == 's') && (length >= 2)	    && (strncmp(argv[1], "size", length) == 0)) {	if (argc != 2) {	    Tcl_AppendResult(interp, "wrong # args: should be \"",		    argv[0], " size\"", (char *) NULL);	    goto error;	}	sprintf(interp->result, "%d", listPtr->numElements);    } else if ((c == 'x') && (strncmp(argv[1], "xview", length) == 0)) {	int index, count, type, windowWidth, windowUnits;	int offset = 0;		/* Initialized to stop gcc warnings. */	double fraction, fraction2;	windowWidth = Tk_Width(listPtr->tkwin)	    - 2*(listPtr->inset + listPtr->selBorderWidth);	if (argc == 2) {	    if (listPtr->maxWidth == 0) {		interp->result = "0 1";	    } else {		fraction = listPtr->xOffset/((double) listPtr->maxWidth);		fraction2 = (listPtr->xOffset + windowWidth)			/((double) listPtr->maxWidth);		if (fraction2 > 1.0) {		    fraction2 = 1.0;		}		sprintf(interp->result, "%g %g", fraction, fraction2);	    }	} else if (argc == 3) {	    if (Tcl_GetInt(interp, argv[2], &index) != TCL_OK) {		goto error;	    }	    ChangeListboxOffset(listPtr, index*listPtr->xScrollUnit);	} else {	    type = Tk_GetScrollInfo(interp, argc, argv, &fraction, &count);	    switch (type) {		case TK_SCROLL_ERROR:		    goto error;		case TK_SCROLL_MOVETO:		    offset = (int) (fraction*listPtr->maxWidth + 0.5);		    break;		case TK_SCROLL_PAGES:		    windowUnits = windowWidth/listPtr->xScrollUnit;		    if (windowUnits > 2) {			offset = listPtr->xOffset				+ count*listPtr->xScrollUnit*(windowUnits-2);		    } else {			offset = listPtr->xOffset + count*listPtr->xScrollUnit;		    }

⌨️ 快捷键说明

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