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