︙ | | |
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
COMMAND_IDENTIFY, COMMAND_SET
};
/*
* Forward declarations for procedures defined later in this file:
*/
static void ComputeFormat(TkScale *scalePtr);
static void ComputeFormat(TkScale *scalePtr, int forTicks);
static void ComputeScaleGeometry(TkScale *scalePtr);
static int ConfigureScale(Tcl_Interp *interp, TkScale *scalePtr,
int objc, Tcl_Obj *const objv[]);
static void DestroyScale(char *memPtr);
static double MaxTickRoundingError(TkScale *scalePtr,
double tickResolution);
static void ScaleCmdDeletedProc(ClientData clientData);
static void ScaleEventProc(ClientData clientData,
XEvent *eventPtr);
static char * ScaleVarProc(ClientData clientData,
Tcl_Interp *interp, const char *name1,
const char *name2, int flags);
static int ScaleWidgetObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static void ScaleWorldChanged(ClientData instanceData);
static void ScaleSetVariable(TkScale *scalePtr);
/*
* The structure below defines scale class behavior by means of procedures
* that can be invoked from generic window code.
*/
static const Tk_ClassProcs scaleClass = {
sizeof(Tk_ClassProcs), /* size */
ScaleWorldChanged, /* worldChangedProc */
NULL, /* createProc */
NULL /* modalProc */
NULL, /* createProc */
NULL /* modalProc */
};
/*
*--------------------------------------------------------------
*
* ScaleDigit, ScaleMax, ScaleMin, ScaleRound --
*
* Simple math helper functions, designed to be automatically inlined by
* the compiler most of the time.
*
*--------------------------------------------------------------
*/
static inline int
ScaleDigit(
double value)
{
return (int) floor(log10(fabs(value)));
}
static inline double
ScaleMax(
double a,
double b)
{
return (a > b) ? a : b;
}
static inline double
ScaleMin(
double a,
double b)
{
return (a < b) ? a : b;
}
static inline int
ScaleRound(
double value)
{
return (int) floor(value + 0.5);
}
/*
*--------------------------------------------------------------
*
* Tk_ScaleObjCmd --
*
* This procedure is invoked to process the "scale" Tcl command. See the
|
︙ | | |
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
-
+
|
} else {
if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK) ||
(Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
goto error;
}
value = TkScalePixelToValue(scalePtr, x, y);
}
Tcl_SetObjResult(interp, Tcl_ObjPrintf(scalePtr->format, value));
Tcl_SetObjResult(interp, Tcl_ObjPrintf(scalePtr->valueFormat, value));
break;
}
case COMMAND_IDENTIFY: {
int x, y;
const char *zone = "";
if (objc != 4) {
|
︙ | | |
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
-
+
+
|
*/
if ((scalePtr->tickInterval < 0)
^ ((scalePtr->toValue - scalePtr->fromValue) < 0)) {
scalePtr->tickInterval = -scalePtr->tickInterval;
}
ComputeFormat(scalePtr);
ComputeFormat(scalePtr, 0);
ComputeFormat(scalePtr, 1);
scalePtr->labelLength = scalePtr->label ? (int)strlen(scalePtr->label) : 0;
Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder);
if (scalePtr->highlightWidth < 0) {
scalePtr->highlightWidth = 0;
|
︙ | | |
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
|
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
-
-
+
+
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
* know how much space is needed now.
*/
ComputeScaleGeometry(scalePtr);
TkEventuallyRedrawScale(scalePtr, REDRAW_ALL);
}
/*
*----------------------------------------------------------------------
*
/*
*----------------------------------------------------------------------
*
* MaxTickRoundingError --
*
* Given the separation between values that can be displayed on ticks,
* this calculates the maximum magnitude of error for the displayed
* value. Tries to be clever by working out the increment in error
* between ticks rather than testing all of them, so may overestimate
* error if it is greater than 0.25 x the value separation.
*
* Results:
* Maximum error magnitude of tick numbers.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static double
MaxTickRoundingError(
TkScale *scalePtr, /* Information about scale widget. */
double tickResolution) /* Separation between displayable values. */
{
double tickPosn, firstTickError, lastTickError, intervalError;
int tickCount;
/*
* Compute the error for each tick-related measure.
*/
tickPosn = scalePtr->fromValue / tickResolution;
firstTickError = tickPosn - ScaleRound(tickPosn);
tickPosn = scalePtr->tickInterval / tickResolution;
intervalError = tickPosn - ScaleRound(tickPosn);
tickCount = (int) ((scalePtr->toValue - scalePtr->fromValue) /
scalePtr->tickInterval); /* not including first */
lastTickError = ScaleMin(0.5,
fabs(firstTickError + tickCount * intervalError));
/*
* Compute the maximum cumulative rounding error.
*/
return ScaleMax(fabs(firstTickError), lastTickError) * tickResolution;
}
/*
*----------------------------------------------------------------------
*
* ComputeFormat --
*
* This procedure is invoked to recompute the "format" field of a scale's
* widget record, which determines how the value of the scale is
* converted to a string.
* This procedure is invoked to recompute the "valueFormat" or
* "tickFormat" field of a scale's widget record, which determines how
* the value of the scale or one of its ticks is converted to a string.
*
* Results:
* None.
*
* Side effects:
* Side effects: The valueFormat or tickFormat field of scalePtr is modified.
* The format field of scalePtr is modified.
*
*----------------------------------------------------------------------
*/
static void
ComputeFormat(
TkScale *scalePtr) /* Information about scale widget. */
TkScale *scalePtr, /* Information about scale widget. */
int forTicks) /* Do for ticks rather than value */
{
double maxValue, x;
int mostSigDigit, numDigits, leastSigDigit, afterDecimal;
int eDigits, fDigits;
/*
* Compute the displacement from the decimal of the most significant digit
* required for any number in the scale's range.
*/
maxValue = fabs(scalePtr->fromValue);
x = fabs(scalePtr->toValue);
if (x > maxValue) {
maxValue = x;
}
if (maxValue == 0) {
maxValue = 1;
}
mostSigDigit = (int) floor(log10(maxValue));
mostSigDigit = ScaleDigit(maxValue);
if (forTicks) {
/*
* If the number of significant digits wasn't specified explicitly,
* compute it. It's the difference between the most significant digit
* needed to represent any number on the scale and the most significant
* digit of the smallest difference between numbers on the scale. In other
* words, display enough digits so that at least one digit will be
* different between any two adjacent positions of the scale.
*/
/*
* Display only enough digits to ensure adjacent ticks have different
* values.
*/
if (scalePtr->tickInterval != 0) {
leastSigDigit = ScaleDigit(scalePtr->tickInterval);
/*
* Now add more digits until max error is less than
* TICK_VALUES_DISPLAY_ACCURACY intervals
*/
while (MaxTickRoundingError(scalePtr, pow(10, leastSigDigit))
> fabs(TICK_VALUES_DISPLAY_ACCURACY * scalePtr->tickInterval)) {
--leastSigDigit;
}
numDigits = 1 + mostSigDigit - leastSigDigit;
} else {
numDigits = 1;
}
} else {
/*
* If the number of significant digits wasn't specified explicitly,
* compute it. It's the difference between the most significant digit
* needed to represent any number on the scale and the most
* significant digit of the smallest difference between numbers on the
* scale. In other words, display enough digits so that at least one
* digit will be different between any two adjacent positions of the
* scale.
*/
numDigits = scalePtr->digits;
if (numDigits > TCL_MAX_PREC) {
numDigits = 0;
}
if (numDigits <= 0) {
if (scalePtr->resolution > 0) {
/*
* A resolution was specified for the scale, so just use it.
*/
numDigits = scalePtr->digits;
if (numDigits > TCL_MAX_PREC) {
numDigits = 0;
}
if (numDigits <= 0) {
if (scalePtr->resolution > 0) {
/*
* A resolution was specified for the scale, so just use it.
*/
leastSigDigit = (int) floor(log10(scalePtr->resolution));
} else {
/*
* No resolution was specified, so compute the difference in value
* between adjacent pixels and use it for the least significant
* digit.
*/
leastSigDigit = ScaleDigit(scalePtr->resolution);
} else {
/*
* No resolution was specified, so compute the difference in
* value between adjacent pixels and use it for the least
* significant digit.
*/
x = fabs(scalePtr->fromValue - scalePtr->toValue);
if (scalePtr->length > 0) {
x /= scalePtr->length;
}
if (x > 0){
leastSigDigit = (int) floor(log10(x));
} else {
leastSigDigit = 0;
}
}
numDigits = mostSigDigit - leastSigDigit + 1;
if (numDigits < 1) {
numDigits = 1;
x = fabs(scalePtr->fromValue - scalePtr->toValue);
if (scalePtr->length > 0) {
x /= scalePtr->length;
}
if (x > 0) {
leastSigDigit = ScaleDigit(x);
} else {
leastSigDigit = 0;
}
}
numDigits = mostSigDigit - leastSigDigit + 1;
if (numDigits < 1) {
numDigits = 1;
}
}
}
/*
* Compute the number of characters required using "e" format and "f"
* format, and then choose whichever one takes fewer characters.
*/
|
︙ | | |
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
|
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
|
fDigits = (mostSigDigit >= 0) ? mostSigDigit + afterDecimal : afterDecimal;
if (afterDecimal > 0) {
fDigits++; /* Decimal point. */
}
if (mostSigDigit < 0) {
fDigits++; /* Zero to left of decimal point. */
}
if (forTicks) {
if (fDigits <= eDigits) {
sprintf(scalePtr->format, "%%.%df", afterDecimal);
} else {
sprintf(scalePtr->format, "%%.%de", numDigits-1);
if (fDigits <= eDigits) {
sprintf(scalePtr->tickFormat, "%%.%df", afterDecimal);
} else {
sprintf(scalePtr->tickFormat, "%%.%de", numDigits - 1);
}
} else {
if (fDigits <= eDigits) {
sprintf(scalePtr->valueFormat, "%%.%df", afterDecimal);
} else {
sprintf(scalePtr->valueFormat, "%%.%de", numDigits - 1);
}
}
}
/*
*----------------------------------------------------------------------
*
* ComputeScaleGeometry --
|
︙ | | |
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
|
-
+
|
*/
static void
ComputeScaleGeometry(
register TkScale *scalePtr) /* Information about widget. */
{
char valueString[TCL_DOUBLE_SPACE];
int tmp, valuePixels, x, y, extraSpace;
int tmp, valuePixels, tickPixels, x, y, extraSpace;
Tk_FontMetrics fm;
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
scalePtr->fontHeight = fm.linespace + SPACING;
/*
* Horizontal scales are simpler than vertical ones because all sizes are
|
︙ | | |
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
|
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
|
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
/*
* Vertical scale: compute the amount of space needed to display the
* scales value by formatting strings for the two end points; use
* whichever length is longer.
*/
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format,
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
scalePtr->fromValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
valuePixels = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format,
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
scalePtr->toValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
tmp = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (valuePixels < tmp) {
valuePixels = tmp;
}
/*
* Now do the same thing for the tick values
*/
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
scalePtr->fromValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
tickPixels = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
scalePtr->toValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
tmp = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (tickPixels < tmp) {
tickPixels = tmp;
}
/*
* Assign x-locations to the elements of the scale, working from left to
* right.
*/
x = scalePtr->inset;
if ((scalePtr->tickInterval != 0) && (scalePtr->showValue)) {
scalePtr->vertTickRightX = x + SPACING + valuePixels;
scalePtr->vertTickRightX = x + SPACING + tickPixels;
scalePtr->vertValueRightX = scalePtr->vertTickRightX + valuePixels
+ fm.ascent/2;
x = scalePtr->vertValueRightX + SPACING;
} else if (scalePtr->tickInterval != 0) {
scalePtr->vertTickRightX = x + SPACING + valuePixels;
scalePtr->vertTickRightX = x + SPACING + tickPixels;
scalePtr->vertValueRightX = scalePtr->vertTickRightX;
x = scalePtr->vertTickRightX + SPACING;
} else if (scalePtr->showValue) {
scalePtr->vertTickRightX = x;
scalePtr->vertValueRightX = x + SPACING + valuePixels;
x = scalePtr->vertValueRightX + SPACING;
} else {
|
︙ | | |
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
|
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
|
-
+
|
static void
ScaleSetVariable(
register TkScale *scalePtr) /* Info about widget. */
{
if (scalePtr->varNamePtr != NULL) {
char string[TCL_DOUBLE_SPACE];
if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format,
if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
scalePtr->value) < 0) {
string[TCL_DOUBLE_SPACE - 1] = '\0';
}
scalePtr->flags |= SETTING_VAR;
Tcl_ObjSetVar2(scalePtr->interp, scalePtr->varNamePtr, NULL,
Tcl_NewStringObj(string, -1), TCL_GLOBAL_ONLY);
scalePtr->flags &= ~SETTING_VAR;
|
︙ | | |
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
|
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
|
-
-
+
+
|
valueRange = scalePtr->toValue - scalePtr->fromValue;
pixelRange = ((scalePtr->orient == ORIENT_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);
y = ScaleRound((value - scalePtr->fromValue) * pixelRange
/ valueRange);
if (y < 0) {
y = 0;
} else if (y > pixelRange) {
y = pixelRange;
}
}
y += scalePtr->sliderLength/2 + scalePtr->inset + scalePtr->borderWidth;
|
︙ | | |
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
-
+
+
-
+
+
|
/*
* Forward declarations for functions defined later in this file:
*/
static void DisplayHorizontalScale(TkScale *scalePtr,
Drawable drawable, XRectangle *drawnAreaPtr);
static void DisplayHorizontalValue(TkScale *scalePtr,
Drawable drawable, double value, int top);
Drawable drawable, double value, int top,
const char *format);
static void DisplayVerticalScale(TkScale *scalePtr,
Drawable drawable, XRectangle *drawnAreaPtr);
static void DisplayVerticalValue(TkScale *scalePtr,
Drawable drawable, double value, int rightEdge);
Drawable drawable, double value, int rightEdge,
const char *format);
/*
*----------------------------------------------------------------------
*
* TkpCreateScale --
*
* Allocate a new TkScale structure.
|
︙ | | |
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
+
-
+
|
}
} else {
if (tickValue < scalePtr->toValue) {
break;
}
}
DisplayVerticalValue(scalePtr, drawable, tickValue,
scalePtr->vertTickRightX);
scalePtr->vertTickRightX, scalePtr->tickFormat);
}
}
}
/*
* Display the value, if it is desired.
*/
if (scalePtr->showValue) {
DisplayVerticalValue(scalePtr, drawable, scalePtr->value,
scalePtr->vertValueRightX);
scalePtr->vertValueRightX, scalePtr->valueFormat);
}
/*
* Display the trough and the slider.
*/
Tk_Draw3DRectangle(tkwin, drawable,
|
︙ | | |
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
-
-
+
+
|
if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
Tk_FontMetrics fm;
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
scalePtr->tkfont, scalePtr->label,
scalePtr->labelLength, scalePtr->vertLabelX,
scalePtr->inset + (3*fm.ascent)/2);
scalePtr->labelLength, scalePtr->vertLabelX,
scalePtr->inset + (3 * fm.ascent) / 2);
}
}
/*
*----------------------------------------------------------------------
*
* DisplayVerticalValue --
|
︙ | | |
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
-
+
+
-
-
+
+
-
+
-
+
|
register TkScale *scalePtr, /* Information about widget in which to
* display value. */
Drawable drawable, /* Pixmap or window in which to draw the
* value. */
double value, /* Y-coordinate of number to display,
* specified in application coords, not in
* pixels (we'll compute pixels). */
int rightEdge) /* X-coordinate of right edge of text,
int rightEdge, /* X-coordinate of right edge of text,
* specified in pixels. */
const char *format) /* Format string to use for the value */
{
register Tk_Window tkwin = scalePtr->tkwin;
int y, width, length;
char valueString[TCL_DOUBLE_SPACE];
Tk_FontMetrics fm;
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
y = TkScaleValueToPixel(scalePtr, value) + fm.ascent/2;
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, value) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
if (snprintf(valueString, TCL_DOUBLE_SPACE, format, value) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
length = (int) strlen(valueString);
width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
/*
* Adjust the y-coordinate if necessary to keep the text entirely inside
* the window.
*/
if ((y - fm.ascent) < (scalePtr->inset + SPACING)) {
if (y - fm.ascent < scalePtr->inset + SPACING) {
y = scalePtr->inset + SPACING + fm.ascent;
}
if ((y + fm.descent) > (Tk_Height(tkwin) - scalePtr->inset - SPACING)) {
if (y + fm.descent > Tk_Height(tkwin) - scalePtr->inset - SPACING) {
y = Tk_Height(tkwin) - scalePtr->inset - SPACING - fm.descent;
}
Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
scalePtr->tkfont, valueString, length, rightEdge - width, y);
}
/*
|
︙ | | |
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
-
+
|
XRectangle *drawnAreaPtr) /* Initally contains area of window; if only a
* part of the scale is redrawn, gets modified
* to reflect the part of the window that was
* redrawn. */
{
register Tk_Window tkwin = scalePtr->tkwin;
int x, y, width, height, shadowWidth;
double tickValue, tickInterval = scalePtr->tickInterval;
double tickInterval = scalePtr->tickInterval;
Tk_3DBorder sliderBorder;
/*
* Display the information from bottom to top across the window.
*/
if (!(scalePtr->flags & REDRAW_OTHER)) {
|
︙ | | |
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
-
+
-
-
-
-
+
+
+
+
-
+
-
-
+
+
-
+
+
-
+
|
if (scalePtr->flags & REDRAW_OTHER) {
/*
* Display the tick marks.
*/
if (tickInterval != 0) {
char valueString[TCL_DOUBLE_SPACE];
double ticks, maxTicks;
double ticks, maxTicks, tickValue;
/*
* Ensure that we will only draw enough of the tick values such
* that they don't overlap. We base this off the width that
* fromValue would take. Not exact, but better than no constraint.
*/
ticks = fabs((scalePtr->toValue - scalePtr->fromValue)
/ tickInterval);
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format,
scalePtr->fromValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
scalePtr->fromValue) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
maxTicks = (double) Tk_Width(tkwin)
/ (double) Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (ticks > maxTicks) {
tickInterval *= (ticks / maxTicks);
tickInterval *= ticks / maxTicks;
}
for (tickValue = scalePtr->fromValue; ;
tickValue += tickInterval) {
tickValue = scalePtr->fromValue;
while (1) {
/*
* The TkRoundValueToResolution call gets rid of accumulated
* round-off errors, if any.
*/
tickValue = TkRoundValueToResolution(scalePtr, tickValue);
if (scalePtr->toValue >= scalePtr->fromValue) {
if (tickValue > scalePtr->toValue) {
break;
}
} else {
if (tickValue < scalePtr->toValue) {
break;
}
}
DisplayHorizontalValue(scalePtr, drawable, tickValue,
scalePtr->horizTickY);
scalePtr->horizTickY, scalePtr->tickFormat);
tickValue += tickInterval;
}
}
}
/*
* Display the value, if it is desired.
*/
if (scalePtr->showValue) {
DisplayHorizontalValue(scalePtr, drawable, scalePtr->value,
scalePtr->horizValueY);
scalePtr->horizValueY, scalePtr->valueFormat);
}
/*
* Display the trough and the slider.
*/
y = scalePtr->horizTroughY;
|
︙ | | |
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
-
-
+
+
|
if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
Tk_FontMetrics fm;
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
scalePtr->tkfont, scalePtr->label,
scalePtr->labelLength, scalePtr->inset + fm.ascent/2,
scalePtr->horizLabelY + fm.ascent);
scalePtr->labelLength, scalePtr->inset + fm.ascent/2,
scalePtr->horizLabelY + fm.ascent);
}
}
/*
*----------------------------------------------------------------------
*
* DisplayHorizontalValue --
|
︙ | | |
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
-
+
+
-
-
+
+
-
-
+
+
|
register TkScale *scalePtr, /* Information about widget in which to
* display value. */
Drawable drawable, /* Pixmap or window in which to draw the
* value. */
double value, /* X-coordinate of number to display,
* specified in application coords, not in
* pixels (we'll compute pixels). */
int top) /* Y-coordinate of top edge of text, specified
int top, /* Y-coordinate of top edge of text, specified
* in pixels. */
const char *format) /* Format string to use for the value */
{
register Tk_Window tkwin = scalePtr->tkwin;
int x, y, length, width;
char valueString[TCL_DOUBLE_SPACE];
Tk_FontMetrics fm;
x = TkScaleValueToPixel(scalePtr, value);
Tk_GetFontMetrics(scalePtr->tkfont, &fm);
y = top + fm.ascent;
if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, value) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
if (snprintf(valueString, TCL_DOUBLE_SPACE, format, value) < 0) {
valueString[TCL_DOUBLE_SPACE - 1] = '\0';
}
length = (int) strlen(valueString);
width = Tk_TextWidth(scalePtr->tkfont, valueString, length);
/*
* Adjust the x-coordinate if necessary to keep the text entirely inside
* the window.
*/
x -= (width)/2;
if (x < (scalePtr->inset + SPACING)) {
x -= width / 2;
if (x < scalePtr->inset + SPACING) {
x = scalePtr->inset + SPACING;
}
/*
* Check the right border so use starting point +text width for the check.
*/
|
︙ | | |
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
-
-
-
-
+
+
+
+
|
/*
* Invoke the scale's command if needed.
*/
Tcl_Preserve(scalePtr);
if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
Tcl_Preserve(interp);
if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format,
scalePtr->value) < 0) {
string[TCL_DOUBLE_SPACE - 1] = '\0';
}
if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
scalePtr->value) < 0) {
string[TCL_DOUBLE_SPACE - 1] = '\0';
}
Tcl_DStringInit(&buf);
Tcl_DStringAppend(&buf, scalePtr->command, -1);
Tcl_DStringAppend(&buf, " ", -1);
Tcl_DStringAppend(&buf, string, -1);
result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
Tcl_DStringFree(&buf);
if (result != TCL_OK) {
|
︙ | | |
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
-
+
|
if (scalePtr->highlightWidth != 0) {
GC gc;
if (scalePtr->flags & GOT_FOCUS) {
gc = Tk_GCForColor(scalePtr->highlightColorPtr, pixmap);
} else {
gc = Tk_GCForColor(
Tk_3DBorderColor(scalePtr->highlightBorder), pixmap);
Tk_3DBorderColor(scalePtr->highlightBorder), pixmap);
}
Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, pixmap);
}
}
#ifndef TK_NO_DOUBLE_BUFFERING
/*
|
︙ | | |
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
|
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
|
-
+
-
+
|
return OTHER;
}
sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
- scalePtr->sliderLength/2;
if (y < sliderFirst) {
return TROUGH1;
}
if (y < (sliderFirst+scalePtr->sliderLength)) {
if (y < sliderFirst + scalePtr->sliderLength) {
return SLIDER;
}
return TROUGH2;
}
if ((y < scalePtr->horizTroughY)
|| (y >= (scalePtr->horizTroughY + 2*scalePtr->borderWidth +
scalePtr->width))) {
return OTHER;
}
if ((x < scalePtr->inset)
|| (x >= (Tk_Width(scalePtr->tkwin) - scalePtr->inset))) {
return OTHER;
}
sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
- scalePtr->sliderLength/2;
if (x < sliderFirst) {
return TROUGH1;
}
if (x < (sliderFirst+scalePtr->sliderLength)) {
if (x < sliderFirst + scalePtr->sliderLength) {
return SLIDER;
}
return TROUGH2;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|