tkButton.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * tkButton.h --
  3. *
  4. * Declarations of types and functions used to implement button-like
  5. * widgets.
  6. *
  7. * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
  8. *
  9. * See the file "license.terms" for information on usage and redistribution of
  10. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. */
  12. #ifndef _TKBUTTON
  13. #define _TKBUTTON
  14. #ifndef _TKINT
  15. #include "tkInt.h"
  16. #endif
  17. /*
  18. * Legal values for the "compound" field of TkButton records.
  19. */
  20. enum compound {
  21. COMPOUND_BOTTOM, COMPOUND_CENTER, COMPOUND_LEFT, COMPOUND_NONE,
  22. COMPOUND_RIGHT, COMPOUND_TOP
  23. };
  24. /*
  25. * Legal values for the "state" field of TkButton records.
  26. */
  27. enum state {
  28. STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL
  29. };
  30. /*
  31. * Legal values for the "defaultState" field of TkButton records.
  32. */
  33. enum defaultState {
  34. DEFAULT_ACTIVE, DEFAULT_DISABLED, DEFAULT_NORMAL
  35. };
  36. /*
  37. * A data structure of the following type is kept for each widget managed by
  38. * this file:
  39. */
  40. typedef struct {
  41. Tk_Window tkwin; /* Window that embodies the button. NULL means
  42. * that the window has been destroyed. */
  43. Display *display; /* Display containing widget. Needed to free
  44. * up resources after tkwin is gone. */
  45. Tcl_Interp *interp; /* Interpreter associated with button. */
  46. Tcl_Command widgetCmd; /* Token for button's widget command. */
  47. int type; /* Type of widget, such as TYPE_LABEL:
  48. * restricts operations that may be performed
  49. * on widget. See below for legal values. */
  50. Tk_OptionTable optionTable; /* Table that defines configuration options
  51. * available for this widget. */
  52. /*
  53. * Information about what's in the button.
  54. */
  55. Tcl_Obj *textPtr; /* Value of -text option: specifies text to
  56. * display in button. */
  57. int underline; /* Value of -underline option: specifies index
  58. * of character to underline. < 0 means don't
  59. * underline anything. */
  60. Tcl_Obj *textVarNamePtr; /* Value of -textvariable option: specifies
  61. * name of variable or NULL. If non-NULL,
  62. * button displays the contents of this
  63. * variable. */
  64. Pixmap bitmap; /* Value of -bitmap option. If not None,
  65. * specifies bitmap to display and text and
  66. * textVar are ignored. */
  67. Tcl_Obj *imagePtr; /* Value of -image option: specifies image to
  68. * display in window, or NULL if none. If
  69. * non-NULL, bitmap, text, and textVarName are
  70. * ignored.*/
  71. Tk_Image image; /* Derived from imagePtr by calling
  72. * Tk_GetImage, or NULL if imagePtr is
  73. * NULL. */
  74. Tcl_Obj *selectImagePtr; /* Value of -selectimage option: specifies
  75. * image to display in window when selected,
  76. * or NULL if none. Ignored if imagePtr is
  77. * NULL. */
  78. Tk_Image selectImage; /* Derived from selectImagePtr by calling
  79. * Tk_GetImage, or NULL if selectImagePtr is
  80. * NULL. */
  81. Tcl_Obj *tristateImagePtr; /* Value of -tristateimage option: specifies
  82. * image to display in window when selected,
  83. * or NULL if none. Ignored if imagePtr is
  84. * NULL. */
  85. Tk_Image tristateImage; /* Derived from tristateImagePtr by calling
  86. * Tk_GetImage, or NULL if tristateImagePtr is
  87. * NULL. */
  88. /*
  89. * Information used when displaying widget:
  90. */
  91. enum state state; /* Value of -state option: specifies state of
  92. * button for display purposes.*/
  93. Tk_3DBorder normalBorder; /* Value of -background option: specifies
  94. * color for background (and border) when
  95. * window isn't active. */
  96. Tk_3DBorder activeBorder; /* Value of -activebackground option: this is
  97. * the color used to draw 3-D border and
  98. * background when widget is active. */
  99. Tcl_Obj *borderWidthPtr; /* Value of -borderWidth option: specifies
  100. * width of border in pixels. */
  101. int borderWidth; /* Integer value corresponding to
  102. * borderWidthPtr. Always >= 0. */
  103. int relief; /* Value of -relief option: specifies 3-d
  104. * effect for border, such as
  105. * TK_RELIEF_RAISED. */
  106. int overRelief; /* Value of -overrelief option: specifies a
  107. * 3-d effect for the border, such as
  108. * TK_RELIEF_RAISED, to be used when the mouse
  109. * is over the button. */
  110. int offRelief; /* Value of -offrelief option: specifies a 3-d
  111. * effect for the border, such as
  112. * TK_RELIEF_RAISED, to be used when a
  113. * checkbutton or radiobutton without
  114. * indicator is off. */
  115. Tcl_Obj *highlightWidthPtr; /* Value of -highlightthickness option:
  116. * specifies width in pixels of highlight to
  117. * draw around widget when it has the focus.
  118. * <= 0 means don't draw a highlight. */
  119. int highlightWidth; /* Integer value corresponding to
  120. * highlightWidthPtr. Always >= 0. */
  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; /* Value of -highlightcolor option: specifies
  126. * 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 be
  130. * offset from outside edges to leave room for
  131. * borders. */
  132. Tk_Font tkfont; /* Value of -font option: specifies font to
  133. * use for display text. */
  134. XColor *normalFg; /* Value of -font option: specifies foreground
  135. * color in normal mode. */
  136. XColor *activeFg; /* Value of -activeforeground option:
  137. * foreground color in active mode. NULL means
  138. * use -foreground instead. */
  139. XColor *disabledFg; /* Value of -disabledforeground option:
  140. * foreground color when disabled. NULL means
  141. * use normalFg with a 50% stipple instead. */
  142. GC normalTextGC; /* GC for drawing text in normal mode. Also
  143. * used to copy from off-screen pixmap onto
  144. * screen. */
  145. GC activeTextGC; /* GC for drawing text in active mode (NULL
  146. * means use normalTextGC). */
  147. GC disabledGC; /* Used to produce disabled effect for text
  148. * and check/radio marks. */
  149. GC stippleGC; /* Used to produce disabled stipple effect for
  150. * images when disabled. */
  151. Pixmap gray; /* Pixmap for displaying disabled text if
  152. * disabledFg is NULL. */
  153. GC copyGC; /* Used for copying information from an
  154. * off-screen pixmap to the screen. */
  155. Tcl_Obj *widthPtr; /* Value of -width option. */
  156. int width; /* Integer value corresponding to widthPtr. */
  157. Tcl_Obj *heightPtr; /* Value of -height option. */
  158. int height; /* Integer value corresponding to heightPtr. */
  159. Tcl_Obj *wrapLengthPtr; /* Value of -wraplength option: specifies line
  160. * length (in pixels) at which to wrap onto
  161. * next line. <= 0 means don't wrap except at
  162. * newlines. */
  163. int wrapLength; /* Integer value corresponding to
  164. * wrapLengthPtr. */
  165. Tcl_Obj *padXPtr; /* Value of -padx option: specifies how many
  166. * pixels of extra space to leave on left and
  167. * right of text. Ignored for bitmaps and
  168. * images. */
  169. int padX; /* Integer value corresponding to padXPtr. */
  170. Tcl_Obj *padYPtr; /* Value of -padx option: specifies how many
  171. * pixels of extra space to leave above and
  172. * below text. Ignored for bitmaps and
  173. * images. */
  174. int padY; /* Integer value corresponding to padYPtr. */
  175. Tk_Anchor anchor; /* Value of -anchor option: specifies where
  176. * text/bitmap should be displayed inside
  177. * button region. */
  178. Tk_Justify justify; /* Value of -justify option: specifies how to
  179. * align lines of multi-line text. */
  180. int indicatorOn; /* Value of -indicatoron option: 1 means draw
  181. * indicator in checkbuttons and radiobuttons,
  182. * 0 means don't draw it. */
  183. Tk_3DBorder selectBorder; /* Value of -selectcolor option: specifies
  184. * color for drawing indicator background, or
  185. * perhaps widget background, when
  186. * selected. */
  187. int textWidth; /* Width needed to display text as requested,
  188. * in pixels. */
  189. int textHeight; /* Height needed to display text as requested,
  190. * in pixels. */
  191. Tk_TextLayout textLayout; /* Saved text layout information. */
  192. int indicatorSpace; /* Horizontal space (in pixels) allocated for
  193. * display of indicator. */
  194. int indicatorDiameter; /* Diameter of indicator, in pixels. */
  195. enum defaultState defaultState;
  196. /* Value of -default option, such as
  197. * DEFAULT_NORMAL: specifies state of default
  198. * ring for buttons (normal, active, or
  199. * disabled). NULL for other classes. */
  200. /*
  201. * For check and radio buttons, the fields below are used to manage the
  202. * variable indicating the button's state.
  203. */
  204. Tcl_Obj *selVarNamePtr; /* Value of -variable option: specifies name
  205. * of variable used to control selected state
  206. * of button. */
  207. Tcl_Obj *onValuePtr; /* Value of -offvalue option: specifies value
  208. * to store in variable when this button is
  209. * selected. */
  210. Tcl_Obj *offValuePtr; /* Value of -offvalue option: specifies value
  211. * to store in variable when this button isn't
  212. * selected. Used only by checkbuttons. */
  213. Tcl_Obj *tristateValuePtr; /* Value of -tristatevalue option: specifies
  214. * value to display Tristate or Multivalue
  215. * mode when variable matches this value.
  216. * Used by check- buttons. */
  217. /*
  218. * Miscellaneous information:
  219. */
  220. Tk_Cursor cursor; /* Value of -cursor option: if not NULL,
  221. * specifies current cursor for window. */
  222. Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in the
  223. * C code, but used by keyboard traversal
  224. * scripts. */
  225. Tcl_Obj *commandPtr; /* Value of -command option: specifies script
  226. * to execute when button is invoked. If
  227. * widget is label or has no command, this is
  228. * NULL. */
  229. int compound; /* Value of -compound option; specifies
  230. * whether the button should show both an
  231. * image and text, and, if so, how. */
  232. int repeatDelay; /* Value of -repeatdelay option; specifies the
  233. * number of ms after which the button will
  234. * start to auto-repeat its command. */
  235. int repeatInterval; /* Value of -repeatinterval option; specifies
  236. * the number of ms between auto-repeat
  237. * invocataions of the button command. */
  238. int flags; /* Various flags; see below for
  239. * definitions. */
  240. } TkButton;
  241. /*
  242. * Possible "type" values for buttons. These are the kinds of widgets
  243. * supported by this file. The ordering of the type numbers is significant:
  244. * greater means more features and is used in the code.
  245. */
  246. #define TYPE_LABEL 0
  247. #define TYPE_BUTTON 1
  248. #define TYPE_CHECK_BUTTON 2
  249. #define TYPE_RADIO_BUTTON 3
  250. /*
  251. * Flag bits for buttons:
  252. *
  253. * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
  254. * already been queued to redraw this window.
  255. * SELECTED: Non-zero means this button is selected, so
  256. * special highlight should be drawn.
  257. * GOT_FOCUS: Non-zero means this button currently has the
  258. * input focus.
  259. * BUTTON_DELETED: Non-zero needs that this button has been
  260. * deleted, or is in the process of being deleted
  261. */
  262. #define REDRAW_PENDING (1 << 0)
  263. #define SELECTED (1 << 1)
  264. #define GOT_FOCUS (1 << 2)
  265. #define BUTTON_DELETED (1 << 3)
  266. #define TRISTATED (1 << 4)
  267. /*
  268. * Declaration of button class functions structure
  269. * and button/label defaults, for use in optionSpecs.
  270. */
  271. MODULE_SCOPE const Tk_ClassProcs tkpButtonProcs;
  272. MODULE_SCOPE char tkDefButtonHighlightWidth[TCL_INTEGER_SPACE];
  273. MODULE_SCOPE char tkDefButtonPadx[TCL_INTEGER_SPACE];
  274. MODULE_SCOPE char tkDefButtonPady[TCL_INTEGER_SPACE];
  275. MODULE_SCOPE char tkDefButtonBorderWidth[TCL_INTEGER_SPACE];
  276. MODULE_SCOPE char tkDefLabelHighlightWidth[TCL_INTEGER_SPACE];
  277. MODULE_SCOPE char tkDefLabelPadx[TCL_INTEGER_SPACE];
  278. MODULE_SCOPE char tkDefLabelPady[TCL_INTEGER_SPACE];
  279. /*
  280. * Declaration of functions used in the implementation of the button widget.
  281. */
  282. #ifndef TkpButtonSetDefaults
  283. MODULE_SCOPE void TkpButtonSetDefaults(void);
  284. #endif
  285. MODULE_SCOPE void TkButtonWorldChanged(ClientData instanceData);
  286. MODULE_SCOPE void TkpComputeButtonGeometry(TkButton *butPtr);
  287. MODULE_SCOPE TkButton *TkpCreateButton(Tk_Window tkwin);
  288. #ifndef TkpDestroyButton
  289. MODULE_SCOPE void TkpDestroyButton(TkButton *butPtr);
  290. #endif
  291. #ifndef TkpDisplayButton
  292. MODULE_SCOPE void TkpDisplayButton(ClientData clientData);
  293. #endif
  294. MODULE_SCOPE int TkInvokeButton(TkButton *butPtr);
  295. #endif /* _TKBUTTON */