jpayne@69: /* jpayne@69: * tkButton.h -- jpayne@69: * jpayne@69: * Declarations of types and functions used to implement button-like jpayne@69: * widgets. jpayne@69: * jpayne@69: * Copyright (c) 1996-1998 by Sun Microsystems, Inc. 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 _TKBUTTON jpayne@69: #define _TKBUTTON jpayne@69: jpayne@69: #ifndef _TKINT jpayne@69: #include "tkInt.h" jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Legal values for the "compound" field of TkButton records. jpayne@69: */ jpayne@69: jpayne@69: enum compound { jpayne@69: COMPOUND_BOTTOM, COMPOUND_CENTER, COMPOUND_LEFT, COMPOUND_NONE, jpayne@69: COMPOUND_RIGHT, COMPOUND_TOP jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * Legal values for the "state" field of TkButton 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: * Legal values for the "defaultState" field of TkButton records. jpayne@69: */ jpayne@69: jpayne@69: enum defaultState { jpayne@69: DEFAULT_ACTIVE, DEFAULT_DISABLED, DEFAULT_NORMAL jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * A data structure of the following type is kept for each widget managed by jpayne@69: * this file: jpayne@69: */ jpayne@69: jpayne@69: typedef struct { jpayne@69: Tk_Window tkwin; /* Window that embodies the button. NULL means jpayne@69: * that the window has been destroyed. */ jpayne@69: Display *display; /* Display containing widget. Needed to free jpayne@69: * up resources after tkwin is gone. */ jpayne@69: Tcl_Interp *interp; /* Interpreter associated with button. */ jpayne@69: Tcl_Command widgetCmd; /* Token for button's widget command. */ jpayne@69: int type; /* Type of widget, such as TYPE_LABEL: jpayne@69: * restricts operations that may be performed jpayne@69: * on widget. See below for legal values. */ jpayne@69: Tk_OptionTable optionTable; /* Table that defines configuration options jpayne@69: * available for this widget. */ jpayne@69: jpayne@69: /* jpayne@69: * Information about what's in the button. jpayne@69: */ jpayne@69: jpayne@69: Tcl_Obj *textPtr; /* Value of -text option: specifies text to jpayne@69: * display in button. */ jpayne@69: int underline; /* Value of -underline option: specifies index jpayne@69: * of character to underline. < 0 means don't jpayne@69: * underline anything. */ jpayne@69: Tcl_Obj *textVarNamePtr; /* Value of -textvariable option: specifies jpayne@69: * name of variable or NULL. If non-NULL, jpayne@69: * button displays the contents of this jpayne@69: * variable. */ jpayne@69: Pixmap bitmap; /* Value of -bitmap option. If not None, jpayne@69: * specifies bitmap to display and text and jpayne@69: * textVar are ignored. */ jpayne@69: Tcl_Obj *imagePtr; /* Value of -image option: specifies image to jpayne@69: * display in window, or NULL if none. If jpayne@69: * non-NULL, bitmap, text, and textVarName are jpayne@69: * ignored.*/ jpayne@69: Tk_Image image; /* Derived from imagePtr by calling jpayne@69: * Tk_GetImage, or NULL if imagePtr is jpayne@69: * NULL. */ jpayne@69: Tcl_Obj *selectImagePtr; /* Value of -selectimage option: specifies jpayne@69: * image to display in window when selected, jpayne@69: * or NULL if none. Ignored if imagePtr is jpayne@69: * NULL. */ jpayne@69: Tk_Image selectImage; /* Derived from selectImagePtr by calling jpayne@69: * Tk_GetImage, or NULL if selectImagePtr is jpayne@69: * NULL. */ jpayne@69: Tcl_Obj *tristateImagePtr; /* Value of -tristateimage option: specifies jpayne@69: * image to display in window when selected, jpayne@69: * or NULL if none. Ignored if imagePtr is jpayne@69: * NULL. */ jpayne@69: Tk_Image tristateImage; /* Derived from tristateImagePtr by calling jpayne@69: * Tk_GetImage, or NULL if tristateImagePtr is jpayne@69: * NULL. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used when displaying widget: jpayne@69: */ jpayne@69: jpayne@69: enum state state; /* Value of -state option: specifies state of jpayne@69: * button for display purposes.*/ jpayne@69: Tk_3DBorder normalBorder; /* Value of -background option: specifies jpayne@69: * color for background (and border) when jpayne@69: * window isn't active. */ jpayne@69: Tk_3DBorder activeBorder; /* Value of -activebackground option: this is jpayne@69: * the color used to draw 3-D border and jpayne@69: * background when widget is active. */ jpayne@69: Tcl_Obj *borderWidthPtr; /* Value of -borderWidth option: specifies jpayne@69: * width of border in pixels. */ jpayne@69: int borderWidth; /* Integer value corresponding to jpayne@69: * borderWidthPtr. Always >= 0. */ jpayne@69: int relief; /* Value of -relief option: specifies 3-d jpayne@69: * effect for border, such as jpayne@69: * TK_RELIEF_RAISED. */ jpayne@69: int overRelief; /* Value of -overrelief option: specifies a jpayne@69: * 3-d effect for the border, such as jpayne@69: * TK_RELIEF_RAISED, to be used when the mouse jpayne@69: * is over the button. */ jpayne@69: int offRelief; /* Value of -offrelief option: specifies a 3-d jpayne@69: * effect for the border, such as jpayne@69: * TK_RELIEF_RAISED, to be used when a jpayne@69: * checkbutton or radiobutton without jpayne@69: * indicator is off. */ jpayne@69: Tcl_Obj *highlightWidthPtr; /* Value of -highlightthickness option: jpayne@69: * specifies width in pixels of highlight to jpayne@69: * draw around widget when it has the focus. jpayne@69: * <= 0 means don't draw a highlight. */ jpayne@69: int highlightWidth; /* Integer value corresponding to jpayne@69: * highlightWidthPtr. Always >= 0. */ 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; /* Value of -highlightcolor option: specifies jpayne@69: * 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: Tk_Font tkfont; /* Value of -font option: specifies font to jpayne@69: * use for display text. */ jpayne@69: XColor *normalFg; /* Value of -font option: specifies foreground jpayne@69: * color in normal mode. */ jpayne@69: XColor *activeFg; /* Value of -activeforeground option: jpayne@69: * foreground color in active mode. NULL means jpayne@69: * use -foreground instead. */ jpayne@69: XColor *disabledFg; /* Value of -disabledforeground option: jpayne@69: * foreground color when disabled. NULL means jpayne@69: * use normalFg with a 50% stipple instead. */ jpayne@69: GC normalTextGC; /* GC for drawing text in normal mode. Also jpayne@69: * used to copy from off-screen pixmap onto jpayne@69: * screen. */ jpayne@69: GC activeTextGC; /* GC for drawing text in active mode (NULL jpayne@69: * means use normalTextGC). */ jpayne@69: GC disabledGC; /* Used to produce disabled effect for text jpayne@69: * and check/radio marks. */ jpayne@69: GC stippleGC; /* Used to produce disabled stipple effect for jpayne@69: * images when disabled. */ jpayne@69: Pixmap gray; /* Pixmap for displaying disabled text if jpayne@69: * disabledFg is NULL. */ jpayne@69: GC copyGC; /* Used for copying information from an jpayne@69: * off-screen pixmap to the screen. */ jpayne@69: Tcl_Obj *widthPtr; /* Value of -width option. */ jpayne@69: int width; /* Integer value corresponding to widthPtr. */ jpayne@69: Tcl_Obj *heightPtr; /* Value of -height option. */ jpayne@69: int height; /* Integer value corresponding to heightPtr. */ jpayne@69: Tcl_Obj *wrapLengthPtr; /* Value of -wraplength option: specifies line jpayne@69: * length (in pixels) at which to wrap onto jpayne@69: * next line. <= 0 means don't wrap except at jpayne@69: * newlines. */ jpayne@69: int wrapLength; /* Integer value corresponding to jpayne@69: * wrapLengthPtr. */ jpayne@69: Tcl_Obj *padXPtr; /* Value of -padx option: specifies how many jpayne@69: * pixels of extra space to leave on left and jpayne@69: * right of text. Ignored for bitmaps and jpayne@69: * images. */ jpayne@69: int padX; /* Integer value corresponding to padXPtr. */ jpayne@69: Tcl_Obj *padYPtr; /* Value of -padx option: specifies how many jpayne@69: * pixels of extra space to leave above and jpayne@69: * below text. Ignored for bitmaps and jpayne@69: * images. */ jpayne@69: int padY; /* Integer value corresponding to padYPtr. */ jpayne@69: Tk_Anchor anchor; /* Value of -anchor option: specifies where jpayne@69: * text/bitmap should be displayed inside jpayne@69: * button region. */ jpayne@69: Tk_Justify justify; /* Value of -justify option: specifies how to jpayne@69: * align lines of multi-line text. */ jpayne@69: int indicatorOn; /* Value of -indicatoron option: 1 means draw jpayne@69: * indicator in checkbuttons and radiobuttons, jpayne@69: * 0 means don't draw it. */ jpayne@69: Tk_3DBorder selectBorder; /* Value of -selectcolor option: specifies jpayne@69: * color for drawing indicator background, or jpayne@69: * perhaps widget background, when jpayne@69: * selected. */ jpayne@69: int textWidth; /* Width needed to display text as requested, jpayne@69: * in pixels. */ jpayne@69: int textHeight; /* Height needed to display text as requested, jpayne@69: * in pixels. */ jpayne@69: Tk_TextLayout textLayout; /* Saved text layout information. */ jpayne@69: int indicatorSpace; /* Horizontal space (in pixels) allocated for jpayne@69: * display of indicator. */ jpayne@69: int indicatorDiameter; /* Diameter of indicator, in pixels. */ jpayne@69: enum defaultState defaultState; jpayne@69: /* Value of -default option, such as jpayne@69: * DEFAULT_NORMAL: specifies state of default jpayne@69: * ring for buttons (normal, active, or jpayne@69: * disabled). NULL for other classes. */ jpayne@69: jpayne@69: /* jpayne@69: * For check and radio buttons, the fields below are used to manage the jpayne@69: * variable indicating the button's state. jpayne@69: */ jpayne@69: jpayne@69: Tcl_Obj *selVarNamePtr; /* Value of -variable option: specifies name jpayne@69: * of variable used to control selected state jpayne@69: * of button. */ jpayne@69: Tcl_Obj *onValuePtr; /* Value of -offvalue option: specifies value jpayne@69: * to store in variable when this button is jpayne@69: * selected. */ jpayne@69: Tcl_Obj *offValuePtr; /* Value of -offvalue option: specifies value jpayne@69: * to store in variable when this button isn't jpayne@69: * selected. Used only by checkbuttons. */ jpayne@69: Tcl_Obj *tristateValuePtr; /* Value of -tristatevalue option: specifies jpayne@69: * value to display Tristate or Multivalue jpayne@69: * mode when variable matches this value. jpayne@69: * Used by check- buttons. */ jpayne@69: jpayne@69: /* jpayne@69: * Miscellaneous information: jpayne@69: */ jpayne@69: jpayne@69: Tk_Cursor cursor; /* Value of -cursor option: if not NULL, jpayne@69: * specifies current cursor for window. */ 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. */ jpayne@69: Tcl_Obj *commandPtr; /* Value of -command option: specifies script jpayne@69: * to execute when button is invoked. If jpayne@69: * widget is label or has no command, this is jpayne@69: * NULL. */ jpayne@69: int compound; /* Value of -compound option; specifies jpayne@69: * whether the button should show both an jpayne@69: * image and text, and, if so, how. */ jpayne@69: int repeatDelay; /* Value of -repeatdelay option; specifies the jpayne@69: * number of ms after which the button will jpayne@69: * start to auto-repeat its command. */ jpayne@69: int repeatInterval; /* Value of -repeatinterval option; specifies jpayne@69: * the number of ms between auto-repeat jpayne@69: * invocataions of the button command. */ jpayne@69: int flags; /* Various flags; see below for jpayne@69: * definitions. */ jpayne@69: } TkButton; jpayne@69: jpayne@69: /* jpayne@69: * Possible "type" values for buttons. These are the kinds of widgets jpayne@69: * supported by this file. The ordering of the type numbers is significant: jpayne@69: * greater means more features and is used in the code. jpayne@69: */ jpayne@69: jpayne@69: #define TYPE_LABEL 0 jpayne@69: #define TYPE_BUTTON 1 jpayne@69: #define TYPE_CHECK_BUTTON 2 jpayne@69: #define TYPE_RADIO_BUTTON 3 jpayne@69: jpayne@69: /* jpayne@69: * Flag bits for buttons: jpayne@69: * jpayne@69: * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has jpayne@69: * already been queued to redraw this window. jpayne@69: * SELECTED: Non-zero means this button is selected, so jpayne@69: * special highlight should be drawn. jpayne@69: * GOT_FOCUS: Non-zero means this button currently has the jpayne@69: * input focus. jpayne@69: * BUTTON_DELETED: Non-zero needs that this button has been jpayne@69: * deleted, or is in the process of being deleted jpayne@69: */ jpayne@69: jpayne@69: #define REDRAW_PENDING (1 << 0) jpayne@69: #define SELECTED (1 << 1) jpayne@69: #define GOT_FOCUS (1 << 2) jpayne@69: #define BUTTON_DELETED (1 << 3) jpayne@69: #define TRISTATED (1 << 4) jpayne@69: jpayne@69: /* jpayne@69: * Declaration of button class functions structure jpayne@69: * and button/label defaults, for use in optionSpecs. jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE const Tk_ClassProcs tkpButtonProcs; jpayne@69: MODULE_SCOPE char tkDefButtonHighlightWidth[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefButtonPadx[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefButtonPady[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefButtonBorderWidth[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefLabelHighlightWidth[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefLabelPadx[TCL_INTEGER_SPACE]; jpayne@69: MODULE_SCOPE char tkDefLabelPady[TCL_INTEGER_SPACE]; jpayne@69: jpayne@69: /* jpayne@69: * Declaration of functions used in the implementation of the button widget. jpayne@69: */ jpayne@69: jpayne@69: #ifndef TkpButtonSetDefaults jpayne@69: MODULE_SCOPE void TkpButtonSetDefaults(void); jpayne@69: #endif jpayne@69: MODULE_SCOPE void TkButtonWorldChanged(ClientData instanceData); jpayne@69: MODULE_SCOPE void TkpComputeButtonGeometry(TkButton *butPtr); jpayne@69: MODULE_SCOPE TkButton *TkpCreateButton(Tk_Window tkwin); jpayne@69: #ifndef TkpDestroyButton jpayne@69: MODULE_SCOPE void TkpDestroyButton(TkButton *butPtr); jpayne@69: #endif jpayne@69: #ifndef TkpDisplayButton jpayne@69: MODULE_SCOPE void TkpDisplayButton(ClientData clientData); jpayne@69: #endif jpayne@69: MODULE_SCOPE int TkInvokeButton(TkButton *butPtr); jpayne@69: jpayne@69: #endif /* _TKBUTTON */