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