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