jpayne@69
|
1 /*
|
jpayne@69
|
2 * tkScale.h --
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Declarations of types and functions used to implement the scale
|
jpayne@69
|
5 * widget.
|
jpayne@69
|
6 *
|
jpayne@69
|
7 * Copyright (c) 1996 by Sun Microsystems, Inc.
|
jpayne@69
|
8 * Copyright (c) 1999-2000 by Scriptics Corporation.
|
jpayne@69
|
9 *
|
jpayne@69
|
10 * See the file "license.terms" for information on usage and redistribution of
|
jpayne@69
|
11 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
jpayne@69
|
12 */
|
jpayne@69
|
13
|
jpayne@69
|
14 #ifndef _TKSCALE
|
jpayne@69
|
15 #define _TKSCALE
|
jpayne@69
|
16
|
jpayne@69
|
17 #ifndef _TKINT
|
jpayne@69
|
18 #include "tkInt.h"
|
jpayne@69
|
19 #endif
|
jpayne@69
|
20
|
jpayne@69
|
21 /*
|
jpayne@69
|
22 * Legal values for the "orient" field of TkScale records.
|
jpayne@69
|
23 */
|
jpayne@69
|
24
|
jpayne@69
|
25 enum orient {
|
jpayne@69
|
26 ORIENT_HORIZONTAL, ORIENT_VERTICAL
|
jpayne@69
|
27 };
|
jpayne@69
|
28
|
jpayne@69
|
29 /*
|
jpayne@69
|
30 * Legal values for the "state" field of TkScale records.
|
jpayne@69
|
31 */
|
jpayne@69
|
32
|
jpayne@69
|
33 enum state {
|
jpayne@69
|
34 STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL
|
jpayne@69
|
35 };
|
jpayne@69
|
36
|
jpayne@69
|
37 /*
|
jpayne@69
|
38 * A data structure of the following type is kept for each scale widget
|
jpayne@69
|
39 * managed by this file:
|
jpayne@69
|
40 */
|
jpayne@69
|
41
|
jpayne@69
|
42 typedef struct TkScale {
|
jpayne@69
|
43 Tk_Window tkwin; /* Window that embodies the scale. NULL means
|
jpayne@69
|
44 * that the window has been destroyed but the
|
jpayne@69
|
45 * data structures haven't yet been cleaned
|
jpayne@69
|
46 * up.*/
|
jpayne@69
|
47 Display *display; /* Display containing widget. Used, among
|
jpayne@69
|
48 * other things, so that resources can be
|
jpayne@69
|
49 * freed even after tkwin has gone away. */
|
jpayne@69
|
50 Tcl_Interp *interp; /* Interpreter associated with scale. */
|
jpayne@69
|
51 Tcl_Command widgetCmd; /* Token for scale's widget command. */
|
jpayne@69
|
52 Tk_OptionTable optionTable; /* Table that defines configuration options
|
jpayne@69
|
53 * available for this widget. */
|
jpayne@69
|
54 enum orient orient; /* Orientation for window (vertical or
|
jpayne@69
|
55 * horizontal). */
|
jpayne@69
|
56 int width; /* Desired narrow dimension of scale, in
|
jpayne@69
|
57 * pixels. */
|
jpayne@69
|
58 int length; /* Desired long dimension of scale, in
|
jpayne@69
|
59 * pixels. */
|
jpayne@69
|
60 double value; /* Current value of scale. */
|
jpayne@69
|
61 Tcl_Obj *varNamePtr; /* Name of variable or NULL. If non-NULL,
|
jpayne@69
|
62 * scale's value tracks the contents of this
|
jpayne@69
|
63 * variable and vice versa. */
|
jpayne@69
|
64 double fromValue; /* Value corresponding to left or top of
|
jpayne@69
|
65 * scale. */
|
jpayne@69
|
66 double toValue; /* Value corresponding to right or bottom of
|
jpayne@69
|
67 * scale. */
|
jpayne@69
|
68 double tickInterval; /* Distance between tick marks; 0 means don't
|
jpayne@69
|
69 * display any tick marks. */
|
jpayne@69
|
70 double resolution; /* If > 0, all values are rounded to an even
|
jpayne@69
|
71 * multiple of this value. */
|
jpayne@69
|
72 int digits; /* Number of significant digits to print in
|
jpayne@69
|
73 * values. 0 means we get to choose the number
|
jpayne@69
|
74 * based on resolution and/or the range of the
|
jpayne@69
|
75 * scale. */
|
jpayne@69
|
76 char valueFormat[16]; /* Sprintf conversion specifier computed from
|
jpayne@69
|
77 * digits and other information. */
|
jpayne@69
|
78 char tickFormat[16]; /* Sprintf conversion specifier computed from
|
jpayne@69
|
79 * tick interval. */
|
jpayne@69
|
80 double bigIncrement; /* Amount to use for large increments to scale
|
jpayne@69
|
81 * value. (0 means we pick a value). */
|
jpayne@69
|
82 char *command; /* Command prefix to use when invoking Tcl
|
jpayne@69
|
83 * commands because the scale value changed.
|
jpayne@69
|
84 * NULL means don't invoke commands. */
|
jpayne@69
|
85 int repeatDelay; /* How long to wait before auto-repeating on
|
jpayne@69
|
86 * scrolling actions (in ms). */
|
jpayne@69
|
87 int repeatInterval; /* Interval between autorepeats (in ms). */
|
jpayne@69
|
88 char *label; /* Label to display above or to right of
|
jpayne@69
|
89 * scale; NULL means don't display a label. */
|
jpayne@69
|
90 int labelLength; /* Number of non-NULL chars. in label. */
|
jpayne@69
|
91 enum state state; /* Values are active, normal, or disabled.
|
jpayne@69
|
92 * Value of scale cannot be changed when
|
jpayne@69
|
93 * disabled. */
|
jpayne@69
|
94
|
jpayne@69
|
95 /*
|
jpayne@69
|
96 * Information used when displaying widget:
|
jpayne@69
|
97 */
|
jpayne@69
|
98
|
jpayne@69
|
99 int borderWidth; /* Width of 3-D border around window. */
|
jpayne@69
|
100 Tk_3DBorder bgBorder; /* Used for drawing slider and other
|
jpayne@69
|
101 * background areas. */
|
jpayne@69
|
102 Tk_3DBorder activeBorder; /* For drawing the slider when active. */
|
jpayne@69
|
103 int sliderRelief; /* Is slider to be drawn raised, sunken,
|
jpayne@69
|
104 * etc. */
|
jpayne@69
|
105 XColor *troughColorPtr; /* Color for drawing trough. */
|
jpayne@69
|
106 GC troughGC; /* For drawing trough. */
|
jpayne@69
|
107 GC copyGC; /* Used for copying from pixmap onto screen */
|
jpayne@69
|
108 Tk_Font tkfont; /* Information about text font, or NULL. */
|
jpayne@69
|
109 XColor *textColorPtr; /* Color for drawing text. */
|
jpayne@69
|
110 GC textGC; /* GC for drawing text in normal mode. */
|
jpayne@69
|
111 int relief; /* Indicates whether window as a whole is
|
jpayne@69
|
112 * raised, sunken, or flat. */
|
jpayne@69
|
113 int highlightWidth; /* Width in pixels of highlight to draw around
|
jpayne@69
|
114 * widget when it has the focus. <= 0 means
|
jpayne@69
|
115 * don't draw a highlight. */
|
jpayne@69
|
116 Tk_3DBorder highlightBorder;/* Value of -highlightbackground option:
|
jpayne@69
|
117 * specifies background with which to draw 3-D
|
jpayne@69
|
118 * default ring and focus highlight area when
|
jpayne@69
|
119 * highlight is off. */
|
jpayne@69
|
120 XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
|
jpayne@69
|
121 int inset; /* Total width of all borders, including
|
jpayne@69
|
122 * traversal highlight and 3-D border.
|
jpayne@69
|
123 * Indicates how much interior stuff must be
|
jpayne@69
|
124 * offset from outside edges to leave room for
|
jpayne@69
|
125 * borders. */
|
jpayne@69
|
126 int sliderLength; /* Length of slider, measured in pixels along
|
jpayne@69
|
127 * long dimension of scale. */
|
jpayne@69
|
128 int showValue; /* Non-zero means to display the scale value
|
jpayne@69
|
129 * below or to the left of the slider; zero
|
jpayne@69
|
130 * means don't display the value. */
|
jpayne@69
|
131
|
jpayne@69
|
132 /*
|
jpayne@69
|
133 * Layout information for horizontal scales, assuming that window gets the
|
jpayne@69
|
134 * size it requested:
|
jpayne@69
|
135 */
|
jpayne@69
|
136
|
jpayne@69
|
137 int horizLabelY; /* Y-coord at which to draw label. */
|
jpayne@69
|
138 int horizValueY; /* Y-coord at which to draw value text. */
|
jpayne@69
|
139 int horizTroughY; /* Y-coord of top of slider trough. */
|
jpayne@69
|
140 int horizTickY; /* Y-coord at which to draw tick text. */
|
jpayne@69
|
141 /*
|
jpayne@69
|
142 * Layout information for vertical scales, assuming that window gets the
|
jpayne@69
|
143 * size it requested:
|
jpayne@69
|
144 */
|
jpayne@69
|
145
|
jpayne@69
|
146 int vertTickRightX; /* X-location of right side of tick-marks. */
|
jpayne@69
|
147 int vertValueRightX; /* X-location of right side of value string. */
|
jpayne@69
|
148 int vertTroughX; /* X-location of scale's slider trough. */
|
jpayne@69
|
149 int vertLabelX; /* X-location of origin of label. */
|
jpayne@69
|
150
|
jpayne@69
|
151 /*
|
jpayne@69
|
152 * Miscellaneous information:
|
jpayne@69
|
153 */
|
jpayne@69
|
154
|
jpayne@69
|
155 int fontHeight; /* Height of scale font. */
|
jpayne@69
|
156 Tk_Cursor cursor; /* Current cursor for window, or NULL. */
|
jpayne@69
|
157 Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in the
|
jpayne@69
|
158 * C code, but used by keyboard traversal
|
jpayne@69
|
159 * scripts. May be NULL. */
|
jpayne@69
|
160 int flags; /* Various flags; see below for
|
jpayne@69
|
161 * definitions. */
|
jpayne@69
|
162 } TkScale;
|
jpayne@69
|
163
|
jpayne@69
|
164 /*
|
jpayne@69
|
165 * Flag bits for scales:
|
jpayne@69
|
166 *
|
jpayne@69
|
167 * REDRAW_SLIDER - 1 means slider (and numerical readout) need to
|
jpayne@69
|
168 * be redrawn.
|
jpayne@69
|
169 * REDRAW_OTHER - 1 means other stuff besides slider and value
|
jpayne@69
|
170 * need to be redrawn.
|
jpayne@69
|
171 * REDRAW_ALL - 1 means the entire widget needs to be redrawn.
|
jpayne@69
|
172 * REDRAW_PENDING - 1 means any sort of redraw is pending
|
jpayne@69
|
173 * ACTIVE - 1 means the widget is active (the mouse is in
|
jpayne@69
|
174 * its window).
|
jpayne@69
|
175 * INVOKE_COMMAND - 1 means the scale's command needs to be
|
jpayne@69
|
176 * invoked during the next redisplay (the value
|
jpayne@69
|
177 * of the scale has changed since the last time
|
jpayne@69
|
178 * the command was invoked).
|
jpayne@69
|
179 * SETTING_VAR - 1 means that the associated variable is being
|
jpayne@69
|
180 * set by us, so there's no need for ScaleVarProc
|
jpayne@69
|
181 * to do anything.
|
jpayne@69
|
182 * NEVER_SET - 1 means that the scale's value has never been
|
jpayne@69
|
183 * set before (so must invoke -command and set
|
jpayne@69
|
184 * associated variable even if the value doesn't
|
jpayne@69
|
185 * appear to have changed).
|
jpayne@69
|
186 * GOT_FOCUS - 1 means that the focus is currently in this
|
jpayne@69
|
187 * widget.
|
jpayne@69
|
188 * SCALE_DELETED - 1 means the scale widget is being deleted
|
jpayne@69
|
189 */
|
jpayne@69
|
190
|
jpayne@69
|
191 #define REDRAW_SLIDER (1<<0)
|
jpayne@69
|
192 #define REDRAW_OTHER (1<<1)
|
jpayne@69
|
193 #define REDRAW_ALL (REDRAW_OTHER|REDRAW_SLIDER)
|
jpayne@69
|
194 #define REDRAW_PENDING (1<<2)
|
jpayne@69
|
195 #define ACTIVE (1<<3)
|
jpayne@69
|
196 #define INVOKE_COMMAND (1<<4)
|
jpayne@69
|
197 #define SETTING_VAR (1<<5)
|
jpayne@69
|
198 #define NEVER_SET (1<<6)
|
jpayne@69
|
199 #define GOT_FOCUS (1<<7)
|
jpayne@69
|
200 #define SCALE_DELETED (1<<8)
|
jpayne@69
|
201
|
jpayne@69
|
202 /*
|
jpayne@69
|
203 * Symbolic values for the active parts of a slider. These are the values that
|
jpayne@69
|
204 * may be returned by the ScaleElement procedure.
|
jpayne@69
|
205 */
|
jpayne@69
|
206
|
jpayne@69
|
207 #define OTHER 0
|
jpayne@69
|
208 #define TROUGH1 1
|
jpayne@69
|
209 #define SLIDER 2
|
jpayne@69
|
210 #define TROUGH2 3
|
jpayne@69
|
211
|
jpayne@69
|
212 /*
|
jpayne@69
|
213 * Space to leave between scale area and text, and between text and edge of
|
jpayne@69
|
214 * window.
|
jpayne@69
|
215 */
|
jpayne@69
|
216
|
jpayne@69
|
217 #define SPACING 2
|
jpayne@69
|
218
|
jpayne@69
|
219 /*
|
jpayne@69
|
220 * The tick values are all displayed with the same number of decimal places.
|
jpayne@69
|
221 * This number of decimal places is such that the displayed values are all
|
jpayne@69
|
222 * accurate to within the following proportion of a tick interval.
|
jpayne@69
|
223 */
|
jpayne@69
|
224
|
jpayne@69
|
225 #define TICK_VALUES_DISPLAY_ACCURACY 0.2
|
jpayne@69
|
226
|
jpayne@69
|
227 /*
|
jpayne@69
|
228 * Declaration of procedures used in the implementation of the scale widget.
|
jpayne@69
|
229 */
|
jpayne@69
|
230
|
jpayne@69
|
231 MODULE_SCOPE void TkEventuallyRedrawScale(TkScale *scalePtr, int what);
|
jpayne@69
|
232 MODULE_SCOPE double TkRoundValueToResolution(TkScale *scalePtr, double value);
|
jpayne@69
|
233 MODULE_SCOPE double TkRoundIntervalToResolution(TkScale *scalePtr, double value);
|
jpayne@69
|
234 MODULE_SCOPE TkScale * TkpCreateScale(Tk_Window tkwin);
|
jpayne@69
|
235 MODULE_SCOPE void TkpDestroyScale(TkScale *scalePtr);
|
jpayne@69
|
236 MODULE_SCOPE void TkpDisplayScale(ClientData clientData);
|
jpayne@69
|
237 MODULE_SCOPE int TkpScaleElement(TkScale *scalePtr, int x, int y);
|
jpayne@69
|
238 MODULE_SCOPE void TkScaleSetValue(TkScale *scalePtr, double value,
|
jpayne@69
|
239 int setVar, int invokeCommand);
|
jpayne@69
|
240 MODULE_SCOPE double TkScalePixelToValue(TkScale *scalePtr, int x, int y);
|
jpayne@69
|
241 MODULE_SCOPE int TkScaleValueToPixel(TkScale *scalePtr, double value);
|
jpayne@69
|
242
|
jpayne@69
|
243 #endif /* _TKSCALE */
|