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

📄 tkmacscale.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
    /*     * All of the calculations in this procedure mirror those in     * DisplayScrollbar.  Be sure to keep the two consistent.     */    TkMacWinBounds((TkWindow *) scalePtr->tkwin, &bounds);		    where.h = x + bounds.left;    where.v = y + bounds.top;    part = TestControl(macScalePtr->scaleHandle, where);        SetGWorld(saveWorld, saveDevice);        switch (part) {    	case inSlider:	    return SLIDER;    	case inInc:	    if (scalePtr->vertical) {		return TROUGH1;	    } else {		return TROUGH2;	    }    	case inDecr:	    if (scalePtr->vertical) {		return TROUGH2;	    } else {		return TROUGH1;	    }    	default:	    return OTHER;    }}/* *-------------------------------------------------------------- * * TkpSetScaleValue -- * *	This procedure changes the value of a scale and invokes *	a Tcl command to reflect the current position of a scale * * Results: *	None. * * Side effects: *	A Tcl command is invoked, and an additional error-processing *	command may also be invoked.  The scale's slider is redrawn. * *-------------------------------------------------------------- */voidTkpSetScaleValue(scalePtr, value, setVar, invokeCommand)    register TkScale *scalePtr;	/* Info about widget. */    double value;		/* New value for scale.  Gets adjusted				 * if it's off the scale. */    int setVar;			/* Non-zero means reflect new value through				 * to associated variable, if any. */    int invokeCommand;		/* Non-zero means invoked -command option				 * to notify of new value, 0 means don't. */{    char string[PRINT_CHARS];    value = TkRoundToResolution(scalePtr, value);    if ((value < scalePtr->fromValue)	    ^ (scalePtr->toValue < scalePtr->fromValue)) {	value = scalePtr->fromValue;    }    if ((value > scalePtr->toValue)	    ^ (scalePtr->toValue < scalePtr->fromValue)) {	value = scalePtr->toValue;    }    if (scalePtr->flags & NEVER_SET) {	scalePtr->flags &= ~NEVER_SET;    } else if (scalePtr->value == value) {	return;    }    scalePtr->value = value;    if (invokeCommand) {	scalePtr->flags |= INVOKE_COMMAND;    }    TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER);    if (setVar && (scalePtr->varName != NULL)) {	sprintf(string, scalePtr->format, scalePtr->value);	scalePtr->flags |= SETTING_VAR;	Tcl_SetVar(scalePtr->interp, scalePtr->varName, string,	       TCL_GLOBAL_ONLY);	scalePtr->flags &= ~SETTING_VAR;    }}/* *---------------------------------------------------------------------- * * TkpPixelToValue -- * *	Given a pixel within a scale window, return the scale *	reading corresponding to that pixel. * * Results: *	A double-precision scale reading.  If the value is outside *	the legal range for the scale then it's rounded to the nearest *	end of the scale. * * Side effects: *	None. * *---------------------------------------------------------------------- */doubleTkpPixelToValue(scalePtr, x, y)    register TkScale *scalePtr;		/* Information about widget. */    int x, y;				/* Coordinates of point within					 * window. */{    double value, pixelRange;    if (scalePtr->vertical) {	pixelRange = Tk_Height(scalePtr->tkwin) - scalePtr->sliderLength		- 2*scalePtr->inset - 2*scalePtr->borderWidth;	value = y;    } else {	pixelRange = Tk_Width(scalePtr->tkwin) - scalePtr->sliderLength		- 2*scalePtr->inset - 2*scalePtr->borderWidth;	value = x;    }    if (pixelRange <= 0) {	/*	 * Not enough room for the slider to actually slide:  just return	 * the scale's current value.	 */	return scalePtr->value;    }    value -= scalePtr->sliderLength/2 + scalePtr->inset		+ scalePtr->borderWidth;    value /= pixelRange;    if (value < 0) {	value = 0;    }    if (value > 1) {	value = 1;    }    value = scalePtr->fromValue +		value * (scalePtr->toValue - scalePtr->fromValue);    return TkRoundToResolution(scalePtr, value);}/* *---------------------------------------------------------------------- * * TkpValueToPixel -- * *	Given a reading of the scale, return the x-coordinate or *	y-coordinate corresponding to that reading, depending on *	whether the scale is vertical or horizontal, respectively. * * Results: *	An integer value giving the pixel location corresponding *	to reading.  The value is restricted to lie within the *	defined range for the scale. * * Side effects: *	None. * *---------------------------------------------------------------------- */intTkpValueToPixel(scalePtr, value)    register TkScale *scalePtr;		/* Information about widget. */    double value;			/* Reading of the widget. */{    int y, pixelRange;    double valueRange;    valueRange = scalePtr->toValue - scalePtr->fromValue;    pixelRange = (scalePtr->vertical ? Tk_Height(scalePtr->tkwin)	    : Tk_Width(scalePtr->tkwin)) - scalePtr->sliderLength	    - 2*scalePtr->inset - 2*scalePtr->borderWidth;    if (valueRange == 0) {	y = 0;    } else {	y = (int) ((value - scalePtr->fromValue) * pixelRange		  / valueRange + 0.5);	if (y < 0) {	    y = 0;	} else if (y > pixelRange) {	    y = pixelRange;	}    }    y += scalePtr->sliderLength/2 + scalePtr->inset + scalePtr->borderWidth;    return y;}/* *-------------------------------------------------------------- * * MacScaleEventProc -- * *	This procedure is invoked by the Tk dispatcher for  *	ButtonPress events on scales. * * Results: *	None. * * Side effects: *	When the window gets deleted, internal structures get *	cleaned up.  When it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */static voidMacScaleEventProc(clientData, eventPtr)    ClientData clientData;	/* Information about window. */    XEvent *eventPtr;		/* Information about event. */{    MacScale *macScalePtr = (MacScale *) clientData;    Point where;    Rect bounds;    int part, x, y, dummy;    unsigned int state;    CGrafPtr saveWorld;    GDHandle saveDevice;    GWorldPtr destPort;    Window dummyWin;    /*     * To call Macintosh control routines we must have the port     * set to the window containing the control.  We will then test     * which part of the control was hit and act accordingly.     */    destPort = TkMacGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin));    GetGWorld(&saveWorld, &saveDevice);    SetGWorld(destPort, NULL);    TkMacSetUpClippingRgn(Tk_WindowId(macScalePtr->info.tkwin));    TkMacWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds);		    where.h = eventPtr->xbutton.x + bounds.left;    where.v = eventPtr->xbutton.y + bounds.top;    part = TestControl(macScalePtr->scaleHandle, where);    if (part == 0) {	return;    }        part = TrackControl(macScalePtr->scaleHandle, where, scaleActionProc);        /*     * Update the value for the widget.     */    macScalePtr->info.value = (**macScalePtr->scaleHandle).contrlValue;    /* TkpSetScaleValue(&macScalePtr->info, macScalePtr->info.value, 1, 0); */    /*     * The TrackControl call will "eat" the ButtonUp event.  We now     * generate a ButtonUp event so Tk will unset implicit grabs etc.     */    GetMouse(&where);    XQueryPointer(NULL, None, &dummyWin, &dummyWin, &x,	&y, &dummy, &dummy, &state);    TkGenerateButtonEvent(x, y, Tk_WindowId(macScalePtr->info.tkwin), state);    SetGWorld(saveWorld, saveDevice);}/* *-------------------------------------------------------------- * * ScaleActionProc -- * *	Callback procedure used by the Macintosh toolbox call *	TrackControl.  This call will update the display while *	the scrollbar is being manipulated by the user. * * Results: *	None. * * Side effects: *	May change the display. * *-------------------------------------------------------------- */static pascal voidScaleActionProc(ControlRef theControl, ControlPartCode partCode)    /* ControlRef theControl;	/* Handle to scrollbat control */    /* ControlPartCode partCode;	/* Part of scrollbar that was "hit" */{    register int value;    register TkScale *scalePtr = (TkScale *) GetCRefCon(theControl);    value = (**theControl).contrlValue;    TkpSetScaleValue(scalePtr, value, 1, 1);    Tcl_Preserve((ClientData) scalePtr);    Tcl_DoOneEvent(TCL_IDLE_EVENTS);    Tcl_Release((ClientData) scalePtr);}

⌨️ 快捷键说明

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