tkScale.h 8.8 KB

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