tkMenubutton.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * tkMenubutton.h --
  3. *
  4. * Declarations of types and functions used to implement the menubutton
  5. * widget.
  6. *
  7. * Copyright (c) 1996-1997 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 _TKMENUBUTTON
  13. #define _TKMENUBUTTON
  14. #ifndef _TKINT
  15. #include "tkInt.h"
  16. #endif
  17. #ifndef _TKMENU
  18. #include "tkMenu.h"
  19. #endif
  20. /*
  21. * Legal values for the "orient" field of TkMenubutton records.
  22. */
  23. enum direction {
  24. DIRECTION_ABOVE, DIRECTION_BELOW, DIRECTION_FLUSH,
  25. DIRECTION_LEFT, DIRECTION_RIGHT
  26. };
  27. /*
  28. * Legal values for the "state" field of TkMenubutton records.
  29. */
  30. enum state {
  31. STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL
  32. };
  33. /*
  34. * A data structure of the following type is kept for each widget managed by
  35. * this file:
  36. */
  37. typedef struct {
  38. Tk_Window tkwin; /* Window that embodies the widget. NULL means
  39. * that the window has been destroyed but the
  40. * data structures haven't yet been cleaned
  41. * up. */
  42. Display *display; /* Display containing widget. Needed, among
  43. * other things, so that resources can bee
  44. * freed up even after tkwin has gone away. */
  45. Tcl_Interp *interp; /* Interpreter associated with menubutton. */
  46. Tcl_Command widgetCmd; /* Token for menubutton's widget command. */
  47. Tk_OptionTable optionTable; /* Table that defines configuration options
  48. * available for this widget. */
  49. char *menuName; /* Name of menu associated with widget.
  50. * Malloc-ed. */
  51. /*
  52. * Information about what's displayed in the menu button:
  53. */
  54. char *text; /* Text to display in button (malloc'ed) or
  55. * NULL. */
  56. int underline; /* Index of character to underline. */
  57. char *textVarName; /* Name of variable (malloc'ed) or NULL. If
  58. * non-NULL, button displays the contents of
  59. * this variable. */
  60. Pixmap bitmap; /* Bitmap to display or None. If not None then
  61. * text and textVar and underline are
  62. * ignored. */
  63. char *imageString; /* Name of image to display (malloc'ed), or
  64. * NULL. If non-NULL, bitmap, text, and
  65. * textVarName are ignored. */
  66. Tk_Image image; /* Image to display in window, or NULL if
  67. * none. */
  68. /*
  69. * Information used when displaying widget:
  70. */
  71. enum state state; /* State of button for display purposes:
  72. * normal, active, or disabled. */
  73. Tk_3DBorder normalBorder; /* Structure used to draw 3-D border and
  74. * background when window isn't active. NULL
  75. * means no such border exists. */
  76. Tk_3DBorder activeBorder; /* Structure used to draw 3-D border and
  77. * background when window is active. NULL
  78. * means no such border exists. */
  79. int borderWidth; /* Width of border. */
  80. int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */
  81. int highlightWidth; /* Width in pixels of highlight to draw around
  82. * widget when it has the focus. <= 0 means
  83. * don't draw a highlight. */
  84. XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area
  85. * when highlight is off. */
  86. XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
  87. int inset; /* Total width of all borders, including
  88. * traversal highlight and 3-D border.
  89. * Indicates how much interior stuff must be
  90. * offset from outside edges to leave room for
  91. * borders. */
  92. Tk_Font tkfont; /* Information about text font, or NULL. */
  93. XColor *normalFg; /* Foreground color in normal mode. */
  94. XColor *activeFg; /* Foreground color in active mode. NULL means
  95. * use normalFg instead. */
  96. XColor *disabledFg; /* Foreground color when disabled. NULL means
  97. * use normalFg with a 50% stipple instead. */
  98. GC normalTextGC; /* GC for drawing text in normal mode. */
  99. GC activeTextGC; /* GC for drawing text in active mode (NULL
  100. * means use normalTextGC). */
  101. Pixmap gray; /* Pixmap for displaying disabled text/icon if
  102. * disabledFg is NULL. */
  103. GC disabledGC; /* Used to produce disabled effect for
  104. * text. */
  105. GC stippleGC; /* Used to produce disabled stipple effect for
  106. * images when disabled. */
  107. int leftBearing; /* Distance from text origin to leftmost drawn
  108. * pixel (positive means to right). */
  109. int rightBearing; /* Amount text sticks right from its
  110. * origin. */
  111. char *widthString; /* Value of -width option. Malloc'ed. */
  112. char *heightString; /* Value of -height option. Malloc'ed. */
  113. int width, height; /* If > 0, these specify dimensions to request
  114. * for window, in characters for text and in
  115. * pixels for bitmaps. In this case the actual
  116. * size of the text string or bitmap is
  117. * ignored in computing desired window
  118. * size. */
  119. int wrapLength; /* Line length (in pixels) at which to wrap
  120. * onto next line. <= 0 means don't wrap
  121. * except at newlines. */
  122. int padX, padY; /* Extra space around text or bitmap (pixels
  123. * on each side). */
  124. Tk_Anchor anchor; /* Where text/bitmap should be displayed
  125. * inside window region. */
  126. Tk_Justify justify; /* Justification to use for multi-line
  127. * text. */
  128. int textWidth; /* Width needed to display text as requested,
  129. * in pixels. */
  130. int textHeight; /* Height needed to display text as requested,
  131. * in pixels. */
  132. Tk_TextLayout textLayout; /* Saved text layout information. */
  133. int indicatorOn; /* Non-zero means display indicator; 0 means
  134. * don't display. */
  135. int indicatorHeight; /* Height of indicator in pixels. This same
  136. * amount of extra space is also left on each
  137. * side of the indicator. 0 if no
  138. * indicator. */
  139. int indicatorWidth; /* Width of indicator in pixels, including
  140. * indicatorHeight in padding on each side. 0
  141. * if no indicator. */
  142. /*
  143. * Miscellaneous information:
  144. */
  145. int compound; /* Value of -compound option; specifies
  146. * whether the menubutton should show both an
  147. * image and text, and, if so, how. */
  148. enum direction direction; /* Direction for where to pop the menu. Valid
  149. * directions are "above", "below", "left",
  150. * "right", and "flush". "flush" means that
  151. * the upper left corner of the menubutton is
  152. * where the menu pops up. "above" and "below"
  153. * will attempt to pop the menu compleletly
  154. * above or below the menu respectively.
  155. * "left" and "right" will pop the menu left
  156. * or right, and the active item will be next
  157. * to the button. */
  158. Tk_Cursor cursor; /* Current cursor for window, or NULL. */
  159. char *takeFocus; /* Value of -takefocus option; not used in the
  160. * C code, but used by keyboard traversal
  161. * scripts. Malloc'ed, but may be NULL. */
  162. int flags; /* Various flags; see below for
  163. * definitions. */
  164. } TkMenuButton;
  165. /*
  166. * Flag bits for buttons:
  167. *
  168. * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
  169. * already been queued to redraw this window.
  170. * POSTED: Non-zero means that the menu associated with
  171. * this button has been posted (typically because
  172. * of an active button press).
  173. * GOT_FOCUS: Non-zero means this button currently has the
  174. * input focus.
  175. */
  176. #define REDRAW_PENDING 1
  177. #define POSTED 2
  178. #define GOT_FOCUS 4
  179. /*
  180. * The following constants define the dimensions of the cascade indicator,
  181. * which is displayed if the "-indicatoron" option is true. The units for
  182. * these options are 1/10 millimeters.
  183. */
  184. #define INDICATOR_WIDTH 40
  185. #define INDICATOR_HEIGHT 17
  186. /*
  187. * Declaration of procedures used in the implementation of the button widget.
  188. */
  189. MODULE_SCOPE void TkpComputeMenuButtonGeometry(TkMenuButton *mbPtr);
  190. MODULE_SCOPE TkMenuButton *TkpCreateMenuButton(Tk_Window tkwin);
  191. MODULE_SCOPE void TkpDisplayMenuButton(ClientData clientData);
  192. MODULE_SCOPE void TkpDestroyMenuButton(TkMenuButton *mbPtr);
  193. MODULE_SCOPE void TkMenuButtonWorldChanged(ClientData instanceData);
  194. #endif /* _TKMENUBUTTON */