/[dtapublic]/projs/trunk/shared_source/tk_base/tkunixscale.c
ViewVC logotype

Annotation of /projs/trunk/shared_source/tk_base/tkunixscale.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations) (download)
Fri Oct 14 01:50:00 2016 UTC (8 years, 1 month ago) by dashley
File MIME type: text/plain
File size: 21926 byte(s)
Move shared source code to commonize.
1 dashley 25 /* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkunixscale.c,v 1.1.1.1 2001/06/13 05:11:27 dtashley Exp $ */
2    
3     /*
4     * tkUnixScale.c --
5     *
6     * This file implements the X specific portion of the scrollbar
7     * widget.
8     *
9     * Copyright (c) 1996 by Sun Microsystems, Inc.
10     * Copyright (c) 1998-2000 by Scriptics Corporation.
11     *
12     * See the file "license.terms" for information on usage and redistribution
13     * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14     *
15     * RCS: @(#) $Id: tkunixscale.c,v 1.1.1.1 2001/06/13 05:11:27 dtashley Exp $
16     */
17    
18     #include "tkScale.h"
19     #include "tkInt.h"
20    
21     /*
22     * Forward declarations for procedures defined later in this file:
23     */
24    
25     static void DisplayHorizontalScale _ANSI_ARGS_((TkScale *scalePtr,
26     Drawable drawable, XRectangle *drawnAreaPtr));
27     static void DisplayHorizontalValue _ANSI_ARGS_((TkScale *scalePtr,
28     Drawable drawable, double value, int top));
29     static void DisplayVerticalScale _ANSI_ARGS_((TkScale *scalePtr,
30     Drawable drawable, XRectangle *drawnAreaPtr));
31     static void DisplayVerticalValue _ANSI_ARGS_((TkScale *scalePtr,
32     Drawable drawable, double value, int rightEdge));
33    
34     /*
35     *----------------------------------------------------------------------
36     *
37     * TkpCreateScale --
38     *
39     * Allocate a new TkScale structure.
40     *
41     * Results:
42     * Returns a newly allocated TkScale structure.
43     *
44     * Side effects:
45     * None.
46     *
47     *----------------------------------------------------------------------
48     */
49    
50     TkScale *
51     TkpCreateScale(tkwin)
52     Tk_Window tkwin;
53     {
54     return (TkScale *) ckalloc(sizeof(TkScale));
55     }
56    
57     /*
58     *----------------------------------------------------------------------
59     *
60     * TkpDestroyScale --
61     *
62     * Destroy a TkScale structure. It's necessary to do this with
63     * Tcl_EventuallyFree to allow the Tcl_Preserve(scalePtr) to work
64     * as expected in TkpDisplayScale. (hobbs)
65     *
66     * Results:
67     * None
68     *
69     * Side effects:
70     * Memory is freed.
71     *
72     *----------------------------------------------------------------------
73     */
74    
75     void
76     TkpDestroyScale(scalePtr)
77     TkScale *scalePtr;
78     {
79     Tcl_EventuallyFree((ClientData) scalePtr, TCL_DYNAMIC);
80     }
81    
82     /*
83     *--------------------------------------------------------------
84     *
85     * DisplayVerticalScale --
86     *
87     * This procedure redraws the contents of a vertical scale
88     * window. It is invoked as a do-when-idle handler, so it only
89     * runs when there's nothing else for the application to do.
90     *
91     * Results:
92     * There is no return value. If only a part of the scale needs
93     * to be redrawn, then drawnAreaPtr is modified to reflect the
94     * area that was actually modified.
95     *
96     * Side effects:
97     * Information appears on the screen.
98     *
99     *--------------------------------------------------------------
100     */
101    
102     static void
103     DisplayVerticalScale(scalePtr, drawable, drawnAreaPtr)
104     TkScale *scalePtr; /* Widget record for scale. */
105     Drawable drawable; /* Where to display scale (window
106     * or pixmap). */
107     XRectangle *drawnAreaPtr; /* Initally contains area of window;
108     * if only a part of the scale is
109     * redrawn, gets modified to reflect
110     * the part of the window that was
111     * redrawn. */
112     {
113     Tk_Window tkwin = scalePtr->tkwin;
114     int x, y, width, height, shadowWidth;
115     double tickValue, tickInterval = scalePtr->tickInterval;
116     Tk_3DBorder sliderBorder;
117    
118     /*
119     * Display the information from left to right across the window.
120     */
121    
122     if (!(scalePtr->flags & REDRAW_OTHER)) {
123     drawnAreaPtr->x = scalePtr->vertTickRightX;
124     drawnAreaPtr->y = scalePtr->inset;
125     drawnAreaPtr->width = scalePtr->vertTroughX + scalePtr->width
126     + 2*scalePtr->borderWidth - scalePtr->vertTickRightX;
127     drawnAreaPtr->height -= 2*scalePtr->inset;
128     }
129     Tk_Fill3DRectangle(tkwin, drawable, scalePtr->bgBorder,
130     drawnAreaPtr->x, drawnAreaPtr->y, drawnAreaPtr->width,
131     drawnAreaPtr->height, 0, TK_RELIEF_FLAT);
132     if (scalePtr->flags & REDRAW_OTHER) {
133     /*
134     * Display the tick marks.
135     */
136    
137     if (tickInterval != 0) {
138     double ticks, maxTicks;
139    
140     /*
141     * Ensure that we will only draw enough of the tick values
142     * such that they don't overlap
143     */
144     ticks = fabs((scalePtr->toValue - scalePtr->fromValue)
145     / tickInterval);
146     maxTicks = (double) Tk_Height(tkwin)
147     / (double) scalePtr->fontHeight;
148     if (ticks > maxTicks) {
149     tickInterval *= (ticks / maxTicks);
150     }
151     for (tickValue = scalePtr->fromValue; ;
152     tickValue += tickInterval) {
153     /*
154     * The TkRoundToResolution call gets rid of accumulated
155     * round-off errors, if any.
156     */
157    
158     tickValue = TkRoundToResolution(scalePtr, tickValue);
159     if (scalePtr->toValue >= scalePtr->fromValue) {
160     if (tickValue > scalePtr->toValue) {
161     break;
162     }
163     } else {
164     if (tickValue < scalePtr->toValue) {
165     break;
166     }
167     }
168     DisplayVerticalValue(scalePtr, drawable, tickValue,
169     scalePtr->vertTickRightX);
170     }
171     }
172     }
173    
174     /*
175     * Display the value, if it is desired.
176     */
177    
178     if (scalePtr->showValue) {
179     DisplayVerticalValue(scalePtr, drawable, scalePtr->value,
180     scalePtr->vertValueRightX);
181     }
182    
183     /*
184     * Display the trough and the slider.
185     */
186    
187     Tk_Draw3DRectangle(tkwin, drawable,
188     scalePtr->bgBorder, scalePtr->vertTroughX, scalePtr->inset,
189     scalePtr->width + 2*scalePtr->borderWidth,
190     Tk_Height(tkwin) - 2*scalePtr->inset, scalePtr->borderWidth,
191     TK_RELIEF_SUNKEN);
192     XFillRectangle(scalePtr->display, drawable, scalePtr->troughGC,
193     scalePtr->vertTroughX + scalePtr->borderWidth,
194     scalePtr->inset + scalePtr->borderWidth,
195     (unsigned) scalePtr->width,
196     (unsigned) (Tk_Height(tkwin) - 2*scalePtr->inset
197     - 2*scalePtr->borderWidth));
198     if (scalePtr->state == STATE_ACTIVE) {
199     sliderBorder = scalePtr->activeBorder;
200     } else {
201     sliderBorder = scalePtr->bgBorder;
202     }
203     width = scalePtr->width;
204     height = scalePtr->sliderLength/2;
205     x = scalePtr->vertTroughX + scalePtr->borderWidth;
206     y = TkScaleValueToPixel(scalePtr, scalePtr->value) - height;
207     shadowWidth = scalePtr->borderWidth/2;
208     if (shadowWidth == 0) {
209     shadowWidth = 1;
210     }
211     Tk_Draw3DRectangle(tkwin, drawable, sliderBorder, x, y, width,
212     2*height, shadowWidth, scalePtr->sliderRelief);
213     x += shadowWidth;
214     y += shadowWidth;
215     width -= 2*shadowWidth;
216     height -= shadowWidth;
217     Tk_Fill3DRectangle(tkwin, drawable, sliderBorder, x, y, width,
218     height, shadowWidth, scalePtr->sliderRelief);
219     Tk_Fill3DRectangle(tkwin, drawable, sliderBorder, x, y+height,
220     width, height, shadowWidth, scalePtr->sliderRelief);
221    
222     /*
223     * Draw the label to the right of the scale.
224     */
225    
226     if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
227     Tk_FontMetrics fm;
228    
229     Tk_GetFontMetrics(scalePtr->tkfont, &fm);
230     Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
231     scalePtr->tkfont, scalePtr->label,
232     scalePtr->labelLength, scalePtr->vertLabelX,
233     scalePtr->inset + (3*fm.ascent)/2);
234     }
235     }
236    
237     /*
238     *----------------------------------------------------------------------
239     *
240     * DisplayVerticalValue --
241     *
242     * This procedure is called to display values (scale readings)
243     * for vertically-oriented scales.
244     *
245     * Results:
246     * None.
247     *
248     * Side effects:
249     * The numerical value corresponding to value is displayed with
250     * its right edge at "rightEdge", and at a vertical position in
251     * the scale that corresponds to "value".
252     *
253     *----------------------------------------------------------------------
254     */
255    
256     static void
257     DisplayVerticalValue(scalePtr, drawable, value, rightEdge)
258     register TkScale *scalePtr; /* Information about widget in which to
259     * display value. */
260     Drawable drawable; /* Pixmap or window in which to draw
261     * the value. */
262     double value; /* Y-coordinate of number to display,
263     * specified in application coords, not
264     * in pixels (we'll compute pixels). */
265     int rightEdge; /* X-coordinate of right edge of text,
266     * specified in pixels. */
267     {
268     register Tk_Window tkwin = scalePtr->tkwin;
269     int y, width, length;
270     char valueString[PRINT_CHARS];
271     Tk_FontMetrics fm;
272    
273     Tk_GetFontMetrics(scalePtr->tkfont, &fm);
274     y = TkScaleValueToPixel(scalePtr, value) + fm.ascent/2;
275     sprintf(valueString, scalePtr->format, value);
276     length = strlen(valueString);
277     width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
278    
279     /*
280     * Adjust the y-coordinate if necessary to keep the text entirely
281     * inside the window.
282     */
283    
284     if ((y - fm.ascent) < (scalePtr->inset + SPACING)) {
285     y = scalePtr->inset + SPACING + fm.ascent;
286     }
287     if ((y + fm.descent) > (Tk_Height(tkwin) - scalePtr->inset - SPACING)) {
288     y = Tk_Height(tkwin) - scalePtr->inset - SPACING - fm.descent;
289     }
290     Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
291     scalePtr->tkfont, valueString, length, rightEdge - width, y);
292     }
293    
294     /*
295     *--------------------------------------------------------------
296     *
297     * DisplayHorizontalScale --
298     *
299     * This procedure redraws the contents of a horizontal scale
300     * window. It is invoked as a do-when-idle handler, so it only
301     * runs when there's nothing else for the application to do.
302     *
303     * Results:
304     * There is no return value. If only a part of the scale needs
305     * to be redrawn, then drawnAreaPtr is modified to reflect the
306     * area that was actually modified.
307     *
308     * Side effects:
309     * Information appears on the screen.
310     *
311     *--------------------------------------------------------------
312     */
313    
314     static void
315     DisplayHorizontalScale(scalePtr, drawable, drawnAreaPtr)
316     TkScale *scalePtr; /* Widget record for scale. */
317     Drawable drawable; /* Where to display scale (window
318     * or pixmap). */
319     XRectangle *drawnAreaPtr; /* Initally contains area of window;
320     * if only a part of the scale is
321     * redrawn, gets modified to reflect
322     * the part of the window that was
323     * redrawn. */
324     {
325     register Tk_Window tkwin = scalePtr->tkwin;
326     int x, y, width, height, shadowWidth;
327     double tickValue, tickInterval = scalePtr->tickInterval;
328     Tk_3DBorder sliderBorder;
329    
330     /*
331     * Display the information from bottom to top across the window.
332     */
333    
334     if (!(scalePtr->flags & REDRAW_OTHER)) {
335     drawnAreaPtr->x = scalePtr->inset;
336     drawnAreaPtr->y = scalePtr->horizValueY;
337     drawnAreaPtr->width -= 2*scalePtr->inset;
338     drawnAreaPtr->height = scalePtr->horizTroughY + scalePtr->width
339     + 2*scalePtr->borderWidth - scalePtr->horizValueY;
340     }
341     Tk_Fill3DRectangle(tkwin, drawable, scalePtr->bgBorder,
342     drawnAreaPtr->x, drawnAreaPtr->y, drawnAreaPtr->width,
343     drawnAreaPtr->height, 0, TK_RELIEF_FLAT);
344     if (scalePtr->flags & REDRAW_OTHER) {
345     /*
346     * Display the tick marks.
347     */
348    
349     if (tickInterval != 0) {
350     char valueString[PRINT_CHARS];
351     double ticks, maxTicks;
352    
353     /*
354     * Ensure that we will only draw enough of the tick values
355     * such that they don't overlap. We base this off the width that
356     * fromValue would take. Not exact, but better than no constraint.
357     */
358     ticks = fabs((scalePtr->toValue - scalePtr->fromValue)
359     / tickInterval);
360     sprintf(valueString, scalePtr->format, scalePtr->fromValue);
361     maxTicks = (double) Tk_Width(tkwin)
362     / (double) Tk_TextWidth(scalePtr->tkfont, valueString, -1);
363     if (ticks > maxTicks) {
364     tickInterval *= (ticks / maxTicks);
365     }
366     for (tickValue = scalePtr->fromValue; ;
367     tickValue += tickInterval) {
368     /*
369     * The TkRoundToResolution call gets rid of accumulated
370     * round-off errors, if any.
371     */
372    
373     tickValue = TkRoundToResolution(scalePtr, tickValue);
374     if (scalePtr->toValue >= scalePtr->fromValue) {
375     if (tickValue > scalePtr->toValue) {
376     break;
377     }
378     } else {
379     if (tickValue < scalePtr->toValue) {
380     break;
381     }
382     }
383     DisplayHorizontalValue(scalePtr, drawable, tickValue,
384     scalePtr->horizTickY);
385     }
386     }
387     }
388    
389     /*
390     * Display the value, if it is desired.
391     */
392    
393     if (scalePtr->showValue) {
394     DisplayHorizontalValue(scalePtr, drawable, scalePtr->value,
395     scalePtr->horizValueY);
396     }
397    
398     /*
399     * Display the trough and the slider.
400     */
401    
402     y = scalePtr->horizTroughY;
403     Tk_Draw3DRectangle(tkwin, drawable,
404     scalePtr->bgBorder, scalePtr->inset, y,
405     Tk_Width(tkwin) - 2*scalePtr->inset,
406     scalePtr->width + 2*scalePtr->borderWidth,
407     scalePtr->borderWidth, TK_RELIEF_SUNKEN);
408     XFillRectangle(scalePtr->display, drawable, scalePtr->troughGC,
409     scalePtr->inset + scalePtr->borderWidth,
410     y + scalePtr->borderWidth,
411     (unsigned) (Tk_Width(tkwin) - 2*scalePtr->inset
412     - 2*scalePtr->borderWidth),
413     (unsigned) scalePtr->width);
414     if (scalePtr->state == STATE_ACTIVE) {
415     sliderBorder = scalePtr->activeBorder;
416     } else {
417     sliderBorder = scalePtr->bgBorder;
418     }
419     width = scalePtr->sliderLength/2;
420     height = scalePtr->width;
421     x = TkScaleValueToPixel(scalePtr, scalePtr->value) - width;
422     y += scalePtr->borderWidth;
423     shadowWidth = scalePtr->borderWidth/2;
424     if (shadowWidth == 0) {
425     shadowWidth = 1;
426     }
427     Tk_Draw3DRectangle(tkwin, drawable, sliderBorder,
428     x, y, 2*width, height, shadowWidth, scalePtr->sliderRelief);
429     x += shadowWidth;
430     y += shadowWidth;
431     width -= shadowWidth;
432     height -= 2*shadowWidth;
433     Tk_Fill3DRectangle(tkwin, drawable, sliderBorder, x, y, width, height,
434     shadowWidth, scalePtr->sliderRelief);
435     Tk_Fill3DRectangle(tkwin, drawable, sliderBorder, x+width, y,
436     width, height, shadowWidth, scalePtr->sliderRelief);
437    
438     /*
439     * Draw the label at the top of the scale.
440     */
441    
442     if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
443     Tk_FontMetrics fm;
444    
445     Tk_GetFontMetrics(scalePtr->tkfont, &fm);
446     Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
447     scalePtr->tkfont, scalePtr->label,
448     scalePtr->labelLength, scalePtr->inset + fm.ascent/2,
449     scalePtr->horizLabelY + fm.ascent);
450     }
451     }
452    
453     /*
454     *----------------------------------------------------------------------
455     *
456     * DisplayHorizontalValue --
457     *
458     * This procedure is called to display values (scale readings)
459     * for horizontally-oriented scales.
460     *
461     * Results:
462     * None.
463     *
464     * Side effects:
465     * The numerical value corresponding to value is displayed with
466     * its bottom edge at "bottom", and at a horizontal position in
467     * the scale that corresponds to "value".
468     *
469     *----------------------------------------------------------------------
470     */
471    
472     static void
473     DisplayHorizontalValue(scalePtr, drawable, value, top)
474     register TkScale *scalePtr; /* Information about widget in which to
475     * display value. */
476     Drawable drawable; /* Pixmap or window in which to draw
477     * the value. */
478     double value; /* X-coordinate of number to display,
479     * specified in application coords, not
480     * in pixels (we'll compute pixels). */
481     int top; /* Y-coordinate of top edge of text,
482     * specified in pixels. */
483     {
484     register Tk_Window tkwin = scalePtr->tkwin;
485     int x, y, length, width;
486     char valueString[PRINT_CHARS];
487     Tk_FontMetrics fm;
488    
489     x = TkScaleValueToPixel(scalePtr, value);
490     Tk_GetFontMetrics(scalePtr->tkfont, &fm);
491     y = top + fm.ascent;
492     sprintf(valueString, scalePtr->format, value);
493     length = strlen(valueString);
494     width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
495    
496     /*
497     * Adjust the x-coordinate if necessary to keep the text entirely
498     * inside the window.
499     */
500    
501     x -= (width)/2;
502     if (x < (scalePtr->inset + SPACING)) {
503     x = scalePtr->inset + SPACING;
504     }
505     if (x > (Tk_Width(tkwin) - scalePtr->inset)) {
506     x = Tk_Width(tkwin) - scalePtr->inset - SPACING - width;
507     }
508     Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
509     scalePtr->tkfont, valueString, length, x, y);
510     }
511    
512     /*
513     *----------------------------------------------------------------------
514     *
515     * TkpDisplayScale --
516     *
517     * This procedure is invoked as an idle handler to redisplay
518     * the contents of a scale widget.
519     *
520     * Results:
521     * None.
522     *
523     * Side effects:
524     * The scale gets redisplayed.
525     *
526     *----------------------------------------------------------------------
527     */
528    
529     void
530     TkpDisplayScale(clientData)
531     ClientData clientData; /* Widget record for scale. */
532     {
533     TkScale *scalePtr = (TkScale *) clientData;
534     Tk_Window tkwin = scalePtr->tkwin;
535     Tcl_Interp *interp = scalePtr->interp;
536     Pixmap pixmap;
537     int result;
538     char string[PRINT_CHARS];
539     XRectangle drawnArea;
540    
541     scalePtr->flags &= ~REDRAW_PENDING;
542     if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) {
543     goto done;
544     }
545    
546     /*
547     * Invoke the scale's command if needed.
548     */
549     Tcl_Preserve((ClientData) scalePtr);
550     if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
551     Tcl_Preserve((ClientData) interp);
552     sprintf(string, scalePtr->format, scalePtr->value);
553     result = Tcl_VarEval(interp, scalePtr->command, " ", string,
554     (char *) NULL);
555     if (result != TCL_OK) {
556     Tcl_AddErrorInfo(interp, "\n (command executed by scale)");
557     Tcl_BackgroundError(interp);
558     }
559     Tcl_Release((ClientData) interp);
560     }
561     scalePtr->flags &= ~INVOKE_COMMAND;
562     if (scalePtr->flags & SCALE_DELETED) {
563     Tcl_Release((ClientData) scalePtr);
564     goto done;
565     }
566     Tcl_Release((ClientData) scalePtr);
567    
568     /*
569     * In order to avoid screen flashes, this procedure redraws
570     * the scale in a pixmap, then copies the pixmap to the
571     * screen in a single operation. This means that there's no
572     * point in time where the on-sreen image has been cleared.
573     */
574    
575     pixmap = Tk_GetPixmap(scalePtr->display, Tk_WindowId(tkwin),
576     Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
577     drawnArea.x = 0;
578     drawnArea.y = 0;
579     drawnArea.width = Tk_Width(tkwin);
580     drawnArea.height = Tk_Height(tkwin);
581    
582     /*
583     * Much of the redisplay is done totally differently for
584     * horizontal and vertical scales. Handle the part that's
585     * different.
586     */
587    
588     if (scalePtr->orient == ORIENT_VERTICAL) {
589     DisplayVerticalScale(scalePtr, pixmap, &drawnArea);
590     } else {
591     DisplayHorizontalScale(scalePtr, pixmap, &drawnArea);
592     }
593    
594     /*
595     * Now handle the part of redisplay that is the same for
596     * horizontal and vertical scales: border and traversal
597     * highlight.
598     */
599    
600     if (scalePtr->flags & REDRAW_OTHER) {
601     if (scalePtr->relief != TK_RELIEF_FLAT) {
602     Tk_Draw3DRectangle(tkwin, pixmap, scalePtr->bgBorder,
603     scalePtr->highlightWidth, scalePtr->highlightWidth,
604     Tk_Width(tkwin) - 2*scalePtr->highlightWidth,
605     Tk_Height(tkwin) - 2*scalePtr->highlightWidth,
606     scalePtr->borderWidth, scalePtr->relief);
607     }
608     if (scalePtr->highlightWidth != 0) {
609     GC gc;
610    
611     if (scalePtr->flags & GOT_FOCUS) {
612     gc = Tk_GCForColor(scalePtr->highlightColorPtr, pixmap);
613     } else {
614     gc = Tk_GCForColor(
615     Tk_3DBorderColor(scalePtr->highlightBorder), pixmap);
616     }
617     Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, pixmap);
618     }
619     }
620    
621     /*
622     * Copy the information from the off-screen pixmap onto the screen,
623     * then delete the pixmap.
624     */
625    
626     XCopyArea(scalePtr->display, pixmap, Tk_WindowId(tkwin),
627     scalePtr->copyGC, drawnArea.x, drawnArea.y, drawnArea.width,
628     drawnArea.height, drawnArea.x, drawnArea.y);
629     Tk_FreePixmap(scalePtr->display, pixmap);
630    
631     done:
632     scalePtr->flags &= ~REDRAW_ALL;
633     }
634    
635     /*
636     *----------------------------------------------------------------------
637     *
638     * TkpScaleElement --
639     *
640     * Determine which part of a scale widget lies under a given
641     * point.
642     *
643     * Results:
644     * The return value is either TROUGH1, SLIDER, TROUGH2, or
645     * OTHER, depending on which of the scale's active elements
646     * (if any) is under the point at (x,y).
647     *
648     * Side effects:
649     * None.
650     *
651     *----------------------------------------------------------------------
652     */
653    
654     int
655     TkpScaleElement(scalePtr, x, y)
656     TkScale *scalePtr; /* Widget record for scale. */
657     int x, y; /* Coordinates within scalePtr's window. */
658     {
659     int sliderFirst;
660    
661     if (scalePtr->orient == ORIENT_VERTICAL) {
662     if ((x < scalePtr->vertTroughX)
663     || (x >= (scalePtr->vertTroughX + 2*scalePtr->borderWidth +
664     scalePtr->width))) {
665     return OTHER;
666     }
667     if ((y < scalePtr->inset)
668     || (y >= (Tk_Height(scalePtr->tkwin) - scalePtr->inset))) {
669     return OTHER;
670     }
671     sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
672     - scalePtr->sliderLength/2;
673     if (y < sliderFirst) {
674     return TROUGH1;
675     }
676     if (y < (sliderFirst+scalePtr->sliderLength)) {
677     return SLIDER;
678     }
679     return TROUGH2;
680     }
681    
682     if ((y < scalePtr->horizTroughY)
683     || (y >= (scalePtr->horizTroughY + 2*scalePtr->borderWidth +
684     scalePtr->width))) {
685     return OTHER;
686     }
687     if ((x < scalePtr->inset)
688     || (x >= (Tk_Width(scalePtr->tkwin) - scalePtr->inset))) {
689     return OTHER;
690     }
691     sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
692     - scalePtr->sliderLength/2;
693     if (x < sliderFirst) {
694     return TROUGH1;
695     }
696     if (x < (sliderFirst+scalePtr->sliderLength)) {
697     return SLIDER;
698     }
699     return TROUGH2;
700     }
701    
702    
703     /* $History: tkUnixScale.c $
704     *
705     * ***************** Version 1 *****************
706     * User: Dtashley Date: 1/02/01 Time: 3:13a
707     * Created in $/IjuScripter, IjuConsole/Source/Tk Base
708     * Initial check-in.
709     */
710    
711     /* End of TKUNIXSCALE.C */

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25