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