1 /*
2  * tkScrollbar.h --
3  *
4  *	Declarations of types and functions used to implement the scrollbar
5  *	widget.
6  *
7  * Copyright (c) 1996 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 
13 #ifndef _TKSCROLLBAR
14 #define _TKSCROLLBAR
15 
16 #ifndef _TKINT
17 #include "tkInt.h"
18 #endif
19 
20 /*
21  * A data structure of the following type is kept for each scrollbar widget.
22  */
23 
24 typedef struct TkScrollbar {
25     Tk_Window tkwin;		/* Window that embodies the scrollbar. NULL
26 				 * means that the window has been destroyed
27 				 * but the data structures haven't yet been
28 				 * cleaned up.*/
29     Display *display;		/* Display containing widget. Used, among
30 				 * other things, so that resources can be
31 				 * freed even after tkwin has gone away. */
32     Tcl_Interp *interp;		/* Interpreter associated with scrollbar. */
33     Tcl_Command widgetCmd;	/* Token for scrollbar's widget command. */
34     int vertical;		/* Non-zero means vertical orientation
35 				 * requested, zero means horizontal. */
36     int width;			/* Desired narrow dimension of scrollbar, in
37 				 * pixels. */
38     char *command;		/* Command prefix to use when invoking
39 				 * scrolling commands. NULL means don't invoke
40 				 * commands. Malloc'ed. */
41     int commandSize;		/* Number of non-NULL bytes in command. */
42     int repeatDelay;		/* How long to wait before auto-repeating on
43 				 * scrolling actions (in ms). */
44     int repeatInterval;		/* Interval between autorepeats (in ms). */
45     int jump;			/* Value of -jump option. */
46 
47     /*
48      * Information used when displaying widget:
49      */
50 
51     int borderWidth;		/* Width of 3-D borders. */
52     Tk_3DBorder bgBorder;	/* Used for drawing background (all flat
53 				 * surfaces except for trough). */
54     Tk_3DBorder activeBorder;	/* For drawing backgrounds when active (i.e.
55 				 * when mouse is positioned over element). */
56     XColor *troughColorPtr;	/* Color for drawing trough. */
57     int relief;			/* Indicates whether window as a whole is
58 				 * raised, sunken, or flat. */
59     int highlightWidth;		/* Width in pixels of highlight to draw around
60 				 * widget when it has the focus. <= 0 means
61 				 * don't draw a highlight. */
62     XColor *highlightBgColorPtr;
63 				/* Color for drawing traversal highlight area
64 				 * when highlight is off. */
65     XColor *highlightColorPtr;	/* Color for drawing traversal highlight. */
66     int inset;			/* Total width of all borders, including
67 				 * traversal highlight and 3-D border.
68 				 * Indicates how much interior stuff must be
69 				 * offset from outside edges to leave room for
70 				 * borders. */
71     int elementBorderWidth;	/* Width of border to draw around elements
72 				 * inside scrollbar (arrows and slider). -1
73 				 * means use borderWidth. */
74     int arrowLength;		/* Length of arrows along long dimension of
75 				 * scrollbar, including space for a small gap
76 				 * between the arrow and the slider.
77 				 * Recomputed on window size changes. */
78     int sliderFirst;		/* Pixel coordinate of top or left edge of
79 				 * slider area, including border. */
80     int sliderLast;		/* Coordinate of pixel just after bottom or
81 				 * right edge of slider area, including
82 				 * border. */
83     int activeField;		/* Names field to be displayed in active
84 				 * colors, such as TOP_ARROW, or 0 for no
85 				 * field. */
86     int activeRelief;		/* Value of -activeRelief option: relief to
87 				 * use for active element. */
88 
89     /*
90      * Information describing the application related to the scrollbar. This
91      * information is provided by the application by invoking the "set" widget
92      * command. This information can now be provided in two ways: the "old"
93      * form (totalUnits, windowUnits, firstUnit, and lastUnit), or the "new"
94      * form (firstFraction and lastFraction). FirstFraction and lastFraction
95      * will always be valid, but the old-style information is only valid if
96      * the NEW_STYLE_COMMANDS flag is 0.
97      */
98 
99     int totalUnits;		/* Total dimension of application, in units.
100 				 * Valid only if the NEW_STYLE_COMMANDS flag
101 				 * isn't set. */
102     int windowUnits;		/* Maximum number of units that can be
103 				 * displayed in the window at once. Valid only
104 				 * if the NEW_STYLE_COMMANDS flag isn't set. */
105     int firstUnit;		/* Number of last unit visible in
106 				 * application's window. Valid only if the
107 				 * NEW_STYLE_COMMANDS flag isn't set. */
108     int lastUnit;		/* Index of last unit visible in window.
109 				 * Valid only if the NEW_STYLE_COMMANDS flag
110 				 * isn't set. */
111     double firstFraction;	/* Position of first visible thing in window,
112 				 * specified as a fraction between 0 and
113 				 * 1.0. */
114     double lastFraction;	/* Position of last visible thing in window,
115 				 * specified as a fraction between 0 and
116 				 * 1.0. */
117 
118     /*
119      * Miscellaneous information:
120      */
121 
122     Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
123     char *takeFocus;		/* Value of -takefocus option; not used in the
124 				 * C code, but used by keyboard traversal
125 				 * scripts. Malloc'ed, but may be NULL. */
126     int flags;			/* Various flags; see below for
127 				 * definitions. */
128 } TkScrollbar;
129 
130 /*
131  * Legal values for "activeField" field of Scrollbar structures. These are
132  * also the return values from the ScrollbarPosition function.
133  */
134 
135 #define OUTSIDE		0
136 #define TOP_ARROW	1
137 #define TOP_GAP		2
138 #define SLIDER		3
139 #define BOTTOM_GAP	4
140 #define BOTTOM_ARROW	5
141 
142 /*
143  * Flag bits for scrollbars:
144  *
145  * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler has
146  *				already been queued to redraw this window.
147  * NEW_STYLE_COMMANDS:		Non-zero means the new style of commands
148  *				should be used to communicate with the widget:
149  *				".t yview scroll 2 lines", instead of
150  *				".t yview 40", for example.
151  * GOT_FOCUS:			Non-zero means this window has the input
152  *				focus.
153  */
154 
155 #define REDRAW_PENDING		1
156 #define NEW_STYLE_COMMANDS	2
157 #define GOT_FOCUS		4
158 
159 /*
160  * Declaration of scrollbar class functions structure
161  * and default scrollbar width, for use in configSpec.
162  */
163 
164 MODULE_SCOPE const Tk_ClassProcs tkpScrollbarProcs;
165 MODULE_SCOPE char tkDefScrollbarWidth[TCL_INTEGER_SPACE];
166 
167 /*
168  * Declaration of functions used in the implementation of the scrollbar
169  * widget.
170  */
171 
172 MODULE_SCOPE void	TkScrollbarEventProc(ClientData clientData,
173 			    XEvent *eventPtr);
174 MODULE_SCOPE void	TkScrollbarEventuallyRedraw(TkScrollbar *scrollPtr);
175 MODULE_SCOPE void	TkpComputeScrollbarGeometry(TkScrollbar *scrollPtr);
176 MODULE_SCOPE TkScrollbar *TkpCreateScrollbar(Tk_Window tkwin);
177 MODULE_SCOPE void 	TkpDestroyScrollbar(TkScrollbar *scrollPtr);
178 MODULE_SCOPE void	TkpDisplayScrollbar(ClientData clientData);
179 MODULE_SCOPE void	TkpConfigureScrollbar(TkScrollbar *scrollPtr);
180 MODULE_SCOPE int	TkpScrollbarPosition(TkScrollbar *scrollPtr,
181 			    int x, int y);
182 
183 #endif /* _TKSCROLLBAR */
184