📄 tkscrollbar.c
字号:
if (fraction < 0) { fraction = 0; } else if (fraction > 1.0) { fraction = 1.0; } sprintf(interp->result, "%g", fraction); } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) { if (argc != 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " get\"", (char *) NULL); goto error; } if (scrollPtr->flags & NEW_STYLE_COMMANDS) { char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE]; Tcl_PrintDouble(interp, scrollPtr->firstFraction, first); Tcl_PrintDouble(interp, scrollPtr->lastFraction, last); Tcl_AppendResult(interp, first, " ", last, (char *) NULL); } else { sprintf(interp->result, "%d %d %d %d", scrollPtr->totalUnits, scrollPtr->windowUnits, scrollPtr->firstUnit, scrollPtr->lastUnit); } } else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) { int x, y, thing; if (argc != 4) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " identify x y\"", (char *) NULL); goto error; } if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) { goto error; } thing = TkpScrollbarPosition(scrollPtr, x,y); switch (thing) { case TOP_ARROW: interp->result = "arrow1"; break; case TOP_GAP: interp->result = "trough1"; break; case SLIDER: interp->result = "slider"; break; case BOTTOM_GAP: interp->result = "trough2"; break; case BOTTOM_ARROW: interp->result = "arrow2"; break; } } else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) { int totalUnits, windowUnits, firstUnit, lastUnit; if (argc == 4) { double first, last; if (Tcl_GetDouble(interp, argv[2], &first) != TCL_OK) { goto error; } if (Tcl_GetDouble(interp, argv[3], &last) != TCL_OK) { goto error; } if (first < 0) { scrollPtr->firstFraction = 0; } else if (first > 1.0) { scrollPtr->firstFraction = 1.0; } else { scrollPtr->firstFraction = first; } if (last < scrollPtr->firstFraction) { scrollPtr->lastFraction = scrollPtr->firstFraction; } else if (last > 1.0) { scrollPtr->lastFraction = 1.0; } else { scrollPtr->lastFraction = last; } scrollPtr->flags |= NEW_STYLE_COMMANDS; } else if (argc == 6) { if (Tcl_GetInt(interp, argv[2], &totalUnits) != TCL_OK) { goto error; } if (totalUnits < 0) { totalUnits = 0; } if (Tcl_GetInt(interp, argv[3], &windowUnits) != TCL_OK) { goto error; } if (windowUnits < 0) { windowUnits = 0; } if (Tcl_GetInt(interp, argv[4], &firstUnit) != TCL_OK) { goto error; } if (Tcl_GetInt(interp, argv[5], &lastUnit) != TCL_OK) { goto error; } if (totalUnits > 0) { if (lastUnit < firstUnit) { lastUnit = firstUnit; } } else { firstUnit = lastUnit = 0; } scrollPtr->totalUnits = totalUnits; scrollPtr->windowUnits = windowUnits; scrollPtr->firstUnit = firstUnit; scrollPtr->lastUnit = lastUnit; if (scrollPtr->totalUnits == 0) { scrollPtr->firstFraction = 0.0; scrollPtr->lastFraction = 1.0; } else { scrollPtr->firstFraction = ((double) firstUnit)/totalUnits; scrollPtr->lastFraction = ((double) (lastUnit+1))/totalUnits; } scrollPtr->flags &= ~NEW_STYLE_COMMANDS; } else { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " set firstFraction lastFraction\" or \"", argv[0], " set totalUnits windowUnits firstUnit lastUnit\"", (char *) NULL); goto error; } TkpComputeScrollbarGeometry(scrollPtr); TkScrollbarEventuallyRedraw(scrollPtr); } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be activate, cget, configure, delta, fraction, ", "get, identify, or set", (char *) NULL); goto error; } done: Tcl_Release((ClientData) scrollPtr); return result; error: Tcl_Release((ClientData) scrollPtr); return TCL_ERROR;}/* *---------------------------------------------------------------------- * * ConfigureScrollbar -- * * This procedure is called to process an argv/argc list, plus * the Tk option database, in order to configure (or * reconfigure) a scrollbar 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 scrollPtr; old resources get freed, * if there were any. * *---------------------------------------------------------------------- */static intConfigureScrollbar(interp, scrollPtr, argc, argv, flags) Tcl_Interp *interp; /* Used for error reporting. */ register TkScrollbar *scrollPtr; /* Information about widget; may or * may not already have values for * some fields. */ int argc; /* Number of valid entries in argv. */ char **argv; /* Arguments. */ int flags; /* Flags to pass to * Tk_ConfigureWidget. */{ size_t length; if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, tkpScrollbarConfigSpecs, argc, argv, (char *) scrollPtr, flags) != TCL_OK) { return TCL_ERROR; } /* * A few options need special processing, such as parsing the * orientation or setting the background from a 3-D border. */ length = strlen(scrollPtr->orientUid); if (strncmp(scrollPtr->orientUid, "vertical", length) == 0) { scrollPtr->vertical = 1; } else if (strncmp(scrollPtr->orientUid, "horizontal", length) == 0) { scrollPtr->vertical = 0; } else { Tcl_AppendResult(interp, "bad orientation \"", scrollPtr->orientUid, "\": must be vertical or horizontal", (char *) NULL); return TCL_ERROR; } if (scrollPtr->command != NULL) { scrollPtr->commandSize = strlen(scrollPtr->command); } else { scrollPtr->commandSize = 0; } /* * Configure platform specific options. */ TkpConfigureScrollbar(scrollPtr); /* * Register the desired geometry for the window (leave enough space * for the two arrows plus a minimum-size slider, plus border around * the whole window, if any). Then arrange for the window to be * redisplayed. */ TkpComputeScrollbarGeometry(scrollPtr); TkScrollbarEventuallyRedraw(scrollPtr); return TCL_OK;}/* *-------------------------------------------------------------- * * TkScrollbarEventProc -- * * This procedure is invoked by the Tk dispatcher for various * events on scrollbars. * * Results: * None. * * Side effects: * When the window gets deleted, internal structures get * cleaned up. When it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */voidTkScrollbarEventProc(clientData, eventPtr) ClientData clientData; /* Information about window. */ XEvent *eventPtr; /* Information about event. */{ TkScrollbar *scrollPtr = (TkScrollbar *) clientData; if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { TkScrollbarEventuallyRedraw(scrollPtr); } else if (eventPtr->type == DestroyNotify) { TkpDestroyScrollbar(scrollPtr); if (scrollPtr->tkwin != NULL) { scrollPtr->tkwin = NULL; Tcl_DeleteCommandFromToken(scrollPtr->interp, scrollPtr->widgetCmd); } if (scrollPtr->flags & REDRAW_PENDING) { Tcl_CancelIdleCall(TkpDisplayScrollbar, (ClientData) scrollPtr); } /* * Free up all the stuff that requires special handling, then * let Tk_FreeOptions handle all the standard option-related * stuff. */ Tk_FreeOptions(tkpScrollbarConfigSpecs, (char *) scrollPtr, scrollPtr->display, 0); Tcl_EventuallyFree((ClientData) scrollPtr, TCL_DYNAMIC); } else if (eventPtr->type == ConfigureNotify) { TkpComputeScrollbarGeometry(scrollPtr); TkScrollbarEventuallyRedraw(scrollPtr); } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { scrollPtr->flags |= GOT_FOCUS; if (scrollPtr->highlightWidth > 0) { TkScrollbarEventuallyRedraw(scrollPtr); } } } else if (eventPtr->type == FocusOut) { if (eventPtr->xfocus.detail != NotifyInferior) { scrollPtr->flags &= ~GOT_FOCUS; if (scrollPtr->highlightWidth > 0) { TkScrollbarEventuallyRedraw(scrollPtr); } } }}/* *---------------------------------------------------------------------- * * ScrollbarCmdDeletedProc -- * * 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 voidScrollbarCmdDeletedProc(clientData) ClientData clientData; /* Pointer to widget record for widget. */{ TkScrollbar *scrollPtr = (TkScrollbar *) clientData; Tk_Window tkwin = scrollPtr->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) { scrollPtr->tkwin = NULL; Tk_DestroyWindow(tkwin); }}/* *-------------------------------------------------------------- * * TkScrollbarEventuallyRedraw -- * * Arrange for one or more of the fields of a scrollbar * to be redrawn. * * Results: * None. * * Side effects: * None. * *-------------------------------------------------------------- */voidTkScrollbarEventuallyRedraw(scrollPtr) register TkScrollbar *scrollPtr; /* Information about widget. */{ if ((scrollPtr->tkwin == NULL) || (!Tk_IsMapped(scrollPtr->tkwin))) { return; } if ((scrollPtr->flags & REDRAW_PENDING) == 0) { Tcl_DoWhenIdle(TkpDisplayScrollbar, (ClientData) scrollPtr); scrollPtr->flags |= REDRAW_PENDING; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -