jpayne@69: /* jpayne@69: * tkScale.h -- jpayne@69: * jpayne@69: * Declarations of types and functions used to implement the scale jpayne@69: * widget. jpayne@69: * jpayne@69: * Copyright (c) 1996 by Sun Microsystems, Inc. jpayne@69: * Copyright (c) 1999-2000 by Scriptics Corporation. jpayne@69: * jpayne@69: * See the file "license.terms" for information on usage and redistribution of jpayne@69: * this file, and for a DISCLAIMER OF ALL WARRANTIES. jpayne@69: */ jpayne@69: jpayne@69: #ifndef _TKSCALE jpayne@69: #define _TKSCALE jpayne@69: jpayne@69: #ifndef _TKINT jpayne@69: #include "tkInt.h" jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Legal values for the "orient" field of TkScale records. jpayne@69: */ jpayne@69: jpayne@69: enum orient { jpayne@69: ORIENT_HORIZONTAL, ORIENT_VERTICAL jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * Legal values for the "state" field of TkScale records. jpayne@69: */ jpayne@69: jpayne@69: enum state { jpayne@69: STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * A data structure of the following type is kept for each scale widget jpayne@69: * managed by this file: jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkScale { jpayne@69: Tk_Window tkwin; /* Window that embodies the scale. NULL means jpayne@69: * that the window has been destroyed but the jpayne@69: * data structures haven't yet been cleaned jpayne@69: * up.*/ jpayne@69: Display *display; /* Display containing widget. Used, among jpayne@69: * other things, so that resources can be jpayne@69: * freed even after tkwin has gone away. */ jpayne@69: Tcl_Interp *interp; /* Interpreter associated with scale. */ jpayne@69: Tcl_Command widgetCmd; /* Token for scale's widget command. */ jpayne@69: Tk_OptionTable optionTable; /* Table that defines configuration options jpayne@69: * available for this widget. */ jpayne@69: enum orient orient; /* Orientation for window (vertical or jpayne@69: * horizontal). */ jpayne@69: int width; /* Desired narrow dimension of scale, in jpayne@69: * pixels. */ jpayne@69: int length; /* Desired long dimension of scale, in jpayne@69: * pixels. */ jpayne@69: double value; /* Current value of scale. */ jpayne@69: Tcl_Obj *varNamePtr; /* Name of variable or NULL. If non-NULL, jpayne@69: * scale's value tracks the contents of this jpayne@69: * variable and vice versa. */ jpayne@69: double fromValue; /* Value corresponding to left or top of jpayne@69: * scale. */ jpayne@69: double toValue; /* Value corresponding to right or bottom of jpayne@69: * scale. */ jpayne@69: double tickInterval; /* Distance between tick marks; 0 means don't jpayne@69: * display any tick marks. */ jpayne@69: double resolution; /* If > 0, all values are rounded to an even jpayne@69: * multiple of this value. */ jpayne@69: int digits; /* Number of significant digits to print in jpayne@69: * values. 0 means we get to choose the number jpayne@69: * based on resolution and/or the range of the jpayne@69: * scale. */ jpayne@69: char valueFormat[16]; /* Sprintf conversion specifier computed from jpayne@69: * digits and other information. */ jpayne@69: char tickFormat[16]; /* Sprintf conversion specifier computed from jpayne@69: * tick interval. */ jpayne@69: double bigIncrement; /* Amount to use for large increments to scale jpayne@69: * value. (0 means we pick a value). */ jpayne@69: char *command; /* Command prefix to use when invoking Tcl jpayne@69: * commands because the scale value changed. jpayne@69: * NULL means don't invoke commands. */ jpayne@69: int repeatDelay; /* How long to wait before auto-repeating on jpayne@69: * scrolling actions (in ms). */ jpayne@69: int repeatInterval; /* Interval between autorepeats (in ms). */ jpayne@69: char *label; /* Label to display above or to right of jpayne@69: * scale; NULL means don't display a label. */ jpayne@69: int labelLength; /* Number of non-NULL chars. in label. */ jpayne@69: enum state state; /* Values are active, normal, or disabled. jpayne@69: * Value of scale cannot be changed when jpayne@69: * disabled. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used when displaying widget: jpayne@69: */ jpayne@69: jpayne@69: int borderWidth; /* Width of 3-D border around window. */ jpayne@69: Tk_3DBorder bgBorder; /* Used for drawing slider and other jpayne@69: * background areas. */ jpayne@69: Tk_3DBorder activeBorder; /* For drawing the slider when active. */ jpayne@69: int sliderRelief; /* Is slider to be drawn raised, sunken, jpayne@69: * etc. */ jpayne@69: XColor *troughColorPtr; /* Color for drawing trough. */ jpayne@69: GC troughGC; /* For drawing trough. */ jpayne@69: GC copyGC; /* Used for copying from pixmap onto screen */ jpayne@69: Tk_Font tkfont; /* Information about text font, or NULL. */ jpayne@69: XColor *textColorPtr; /* Color for drawing text. */ jpayne@69: GC textGC; /* GC for drawing text in normal mode. */ jpayne@69: int relief; /* Indicates whether window as a whole is jpayne@69: * raised, sunken, or flat. */ jpayne@69: int highlightWidth; /* Width in pixels of highlight to draw around jpayne@69: * widget when it has the focus. <= 0 means jpayne@69: * don't draw a highlight. */ jpayne@69: Tk_3DBorder highlightBorder;/* Value of -highlightbackground option: jpayne@69: * specifies background with which to draw 3-D jpayne@69: * default ring and focus highlight area when jpayne@69: * highlight is off. */ jpayne@69: XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ jpayne@69: int inset; /* Total width of all borders, including jpayne@69: * traversal highlight and 3-D border. jpayne@69: * Indicates how much interior stuff must be jpayne@69: * offset from outside edges to leave room for jpayne@69: * borders. */ jpayne@69: int sliderLength; /* Length of slider, measured in pixels along jpayne@69: * long dimension of scale. */ jpayne@69: int showValue; /* Non-zero means to display the scale value jpayne@69: * below or to the left of the slider; zero jpayne@69: * means don't display the value. */ jpayne@69: jpayne@69: /* jpayne@69: * Layout information for horizontal scales, assuming that window gets the jpayne@69: * size it requested: jpayne@69: */ jpayne@69: jpayne@69: int horizLabelY; /* Y-coord at which to draw label. */ jpayne@69: int horizValueY; /* Y-coord at which to draw value text. */ jpayne@69: int horizTroughY; /* Y-coord of top of slider trough. */ jpayne@69: int horizTickY; /* Y-coord at which to draw tick text. */ jpayne@69: /* jpayne@69: * Layout information for vertical scales, assuming that window gets the jpayne@69: * size it requested: jpayne@69: */ jpayne@69: jpayne@69: int vertTickRightX; /* X-location of right side of tick-marks. */ jpayne@69: int vertValueRightX; /* X-location of right side of value string. */ jpayne@69: int vertTroughX; /* X-location of scale's slider trough. */ jpayne@69: int vertLabelX; /* X-location of origin of label. */ jpayne@69: jpayne@69: /* jpayne@69: * Miscellaneous information: jpayne@69: */ jpayne@69: jpayne@69: int fontHeight; /* Height of scale font. */ jpayne@69: Tk_Cursor cursor; /* Current cursor for window, or NULL. */ jpayne@69: Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in the jpayne@69: * C code, but used by keyboard traversal jpayne@69: * scripts. May be NULL. */ jpayne@69: int flags; /* Various flags; see below for jpayne@69: * definitions. */ jpayne@69: } TkScale; jpayne@69: jpayne@69: /* jpayne@69: * Flag bits for scales: jpayne@69: * jpayne@69: * REDRAW_SLIDER - 1 means slider (and numerical readout) need to jpayne@69: * be redrawn. jpayne@69: * REDRAW_OTHER - 1 means other stuff besides slider and value jpayne@69: * need to be redrawn. jpayne@69: * REDRAW_ALL - 1 means the entire widget needs to be redrawn. jpayne@69: * REDRAW_PENDING - 1 means any sort of redraw is pending jpayne@69: * ACTIVE - 1 means the widget is active (the mouse is in jpayne@69: * its window). jpayne@69: * INVOKE_COMMAND - 1 means the scale's command needs to be jpayne@69: * invoked during the next redisplay (the value jpayne@69: * of the scale has changed since the last time jpayne@69: * the command was invoked). jpayne@69: * SETTING_VAR - 1 means that the associated variable is being jpayne@69: * set by us, so there's no need for ScaleVarProc jpayne@69: * to do anything. jpayne@69: * NEVER_SET - 1 means that the scale's value has never been jpayne@69: * set before (so must invoke -command and set jpayne@69: * associated variable even if the value doesn't jpayne@69: * appear to have changed). jpayne@69: * GOT_FOCUS - 1 means that the focus is currently in this jpayne@69: * widget. jpayne@69: * SCALE_DELETED - 1 means the scale widget is being deleted jpayne@69: */ jpayne@69: jpayne@69: #define REDRAW_SLIDER (1<<0) jpayne@69: #define REDRAW_OTHER (1<<1) jpayne@69: #define REDRAW_ALL (REDRAW_OTHER|REDRAW_SLIDER) jpayne@69: #define REDRAW_PENDING (1<<2) jpayne@69: #define ACTIVE (1<<3) jpayne@69: #define INVOKE_COMMAND (1<<4) jpayne@69: #define SETTING_VAR (1<<5) jpayne@69: #define NEVER_SET (1<<6) jpayne@69: #define GOT_FOCUS (1<<7) jpayne@69: #define SCALE_DELETED (1<<8) jpayne@69: jpayne@69: /* jpayne@69: * Symbolic values for the active parts of a slider. These are the values that jpayne@69: * may be returned by the ScaleElement procedure. jpayne@69: */ jpayne@69: jpayne@69: #define OTHER 0 jpayne@69: #define TROUGH1 1 jpayne@69: #define SLIDER 2 jpayne@69: #define TROUGH2 3 jpayne@69: jpayne@69: /* jpayne@69: * Space to leave between scale area and text, and between text and edge of jpayne@69: * window. jpayne@69: */ jpayne@69: jpayne@69: #define SPACING 2 jpayne@69: jpayne@69: /* jpayne@69: * The tick values are all displayed with the same number of decimal places. jpayne@69: * This number of decimal places is such that the displayed values are all jpayne@69: * accurate to within the following proportion of a tick interval. jpayne@69: */ jpayne@69: jpayne@69: #define TICK_VALUES_DISPLAY_ACCURACY 0.2 jpayne@69: jpayne@69: /* jpayne@69: * Declaration of procedures used in the implementation of the scale widget. jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE void TkEventuallyRedrawScale(TkScale *scalePtr, int what); jpayne@69: MODULE_SCOPE double TkRoundValueToResolution(TkScale *scalePtr, double value); jpayne@69: MODULE_SCOPE double TkRoundIntervalToResolution(TkScale *scalePtr, double value); jpayne@69: MODULE_SCOPE TkScale * TkpCreateScale(Tk_Window tkwin); jpayne@69: MODULE_SCOPE void TkpDestroyScale(TkScale *scalePtr); jpayne@69: MODULE_SCOPE void TkpDisplayScale(ClientData clientData); jpayne@69: MODULE_SCOPE int TkpScaleElement(TkScale *scalePtr, int x, int y); jpayne@69: MODULE_SCOPE void TkScaleSetValue(TkScale *scalePtr, double value, jpayne@69: int setVar, int invokeCommand); jpayne@69: MODULE_SCOPE double TkScalePixelToValue(TkScale *scalePtr, int x, int y); jpayne@69: MODULE_SCOPE int TkScaleValueToPixel(TkScale *scalePtr, double value); jpayne@69: jpayne@69: #endif /* _TKSCALE */