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