/*
* tkScrollbar.c --
*
* This module implements a scrollbar widgets for the Tk
* toolkit. A scrollbar displays a slider and two arrows;
* mouse clicks on features within the scrollbar cause
* scrolling commands to be invoked.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkScrollbar.c 1.79 96/02/15 18:52:40
*/
#include "tkInt.h"
#include "tkDefault.h"
/*
* A data structure of the following type is kept for each scrollbar
* widget managed by this file:
*/
typedef struct {
* means that the window has been destroyed
* but the data structures haven't yet been
* cleaned up.*/
* other things, so that resources can be
* freed even after tkwin has gone away. */
* "horizontal"). */
* requested, zero means horizontal. */
* in pixels. */
* scrolling commands. NULL means don't
* invoke commands. Malloc'ed. */
* on scrolling actions (in ms). */
/*
* Information used when displaying widget:
*/
* surfaces except for trough). */
* when mouse is positioned over element). */
* raised, sunken, or flat. */
* around widget when it has the focus.
* <= 0 means don't draw a highlight. */
/* Color for drawing traversal highlight
* area when highlight is off. */
* traversal highlight and 3-D border.
* Indicates how much interior stuff must
* be offset from outside edges to leave
* room for borders. */
* inside scrollbar (arrows and slider).
* -1 means use borderWidth. */
* scrollbar, including space for a small gap
* between the arrow and the slider.
* Recomputed on window size changes. */
* of slider area, including border. */
* or right edge of slider area, including
* border. */
* colors, such as TOP_ARROW, or 0 for
* no field. */
* to use for active element. */
/*
* Information describing the application related to the scrollbar.
* This information is provided by the application by invoking the
* "set" widget command. This information can now be provided in
* two ways: the "old" form (totalUnits, windowUnits, firstUnit,
* and lastUnit), or the "new" form (firstFraction and lastFraction).
* FirstFraction and lastFraction will always be valid, but
* the old-style information is only valid if the NEW_STYLE_COMMANDS
* flag is 0.
*/
* units. Valid only if the NEW_STYLE_COMMANDS
* flag isn't set. */
* displayed in the window at once. Valid
* only if the NEW_STYLE_COMMANDS flag isn't
* set. */
* application's window. Valid only if the
* NEW_STYLE_COMMANDS flag isn't set. */
* Valid only if the NEW_STYLE_COMMANDS
* flag isn't set. */
* specified as a fraction between 0 and
* 1.0. */
* specified as a fraction between 0 and
* 1.0. */
/*
* Miscellaneous information:
*/
* the C code, but used by keyboard traversal
* scripts. Malloc'ed, but may be NULL. */
* definitions. */
} Scrollbar;
/*
* Legal values for "activeField" field of Scrollbar structures. These
* are also the return values from the ScrollbarPosition procedure.
*/
#define OUTSIDE 0
/*
* Flag bits for scrollbars:
*
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler
* has already been queued to redraw
* this window.
* NEW_STYLE_COMMANDS: Non-zero means the new style of commands
* should be used to communicate with the
* widget: ".t yview scroll 2 lines", instead
* of ".t yview 40", for example.
* GOT_FOCUS: Non-zero means this window has the input
* focus.
*/
/*
* Minimum slider length, in pixels (designed to make sure that the slider
* is always easy to grab with the mouse).
*/
/*
* Information used for argv parsing.
*/
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
"BorderWidth", DEF_SCROLLBAR_EL_BORDER_WIDTH,
"HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG,
"HighlightThickness",
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
static void ComputeScrollbarGeometry _ANSI_ARGS_((
int flags));
static void ScrollbarCmdDeletedProc _ANSI_ARGS_((
int x, int y));
/*
*--------------------------------------------------------------
*
* Tk_ScrollbarCmd --
*
* This procedure is invoked to process the "scrollbar" Tcl
* command. See the user documentation for details on what
* it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
if (argc < 2) {
return TCL_ERROR;
}
return TCL_ERROR;
}
/*
* Initialize fields that won't be initialized by ConfigureScrollbar,
* or which ConfigureScrollbar expects to have reasonable values
* (e.g. resource pointers).
*/
scrollPtr->commandSize = 0;
scrollPtr->repeatDelay = 0;
scrollPtr->repeatInterval = 0;
scrollPtr->borderWidth = 0;
scrollPtr->highlightWidth = 0;
scrollPtr->arrowLength = 0;
scrollPtr->sliderFirst = 0;
scrollPtr->sliderLast = 0;
scrollPtr->activeField = 0;
scrollPtr->totalUnits = 0;
scrollPtr->windowUnits = 0;
goto error;
}
return TCL_OK;
return TCL_ERROR;
}
/*
*--------------------------------------------------------------
*
* ScrollbarWidgetCmd --
*
* This procedure is invoked to process the Tcl command
* that corresponds to a widget managed by this module.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
static int
* widget. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int c;
if (argc < 2) {
return TCL_ERROR;
}
c = argv[1][0];
if (argc == 2) {
switch (scrollPtr->activeField) {
}
goto done;
}
if (argc != 3) {
goto error;
}
c = argv[2][0];
} else {
}
&& (length >= 2)) {
if (argc != 3) {
argv[0], " cget option\"",
(char *) NULL);
goto error;
}
&& (length >= 2)) {
if (argc == 2) {
} else if (argc == 3) {
} else {
}
double fraction;
if (argc != 4) {
goto error;
}
goto error;
}
} else {
}
if (length == 0) {
fraction = 0.0;
} else {
}
double fraction;
if (argc != 4) {
goto error;
}
goto error;
}
} else {
}
if (length == 0) {
fraction = 0.0;
} else {
}
if (fraction < 0) {
fraction = 0;
} else if (fraction > 1.0) {
fraction = 1.0;
}
if (argc != 2) {
goto error;
}
} else {
}
int x, y, thing;
if (argc != 4) {
goto error;
}
goto error;
}
switch (thing) {
}
if (argc == 4) {
goto error;
}
goto error;
}
if (first < 0) {
scrollPtr->firstFraction = 0;
} else if (first > 1.0) {
} else {
}
} else if (last > 1.0) {
} else {
}
} else if (argc == 6) {
goto error;
}
if (totalUnits < 0) {
totalUnits = 0;
}
goto error;
}
if (windowUnits < 0) {
windowUnits = 0;
}
goto error;
}
goto error;
}
if (totalUnits > 0) {
}
} else {
}
if (scrollPtr->totalUnits == 0) {
} else {
}
} else {
argv[0], " set firstFraction lastFraction\" or \"",
argv[0],
" set totalUnits windowUnits firstUnit lastUnit\"",
(char *) NULL);
goto error;
}
} else {
"\": must be activate, cget, configure, delta, fraction, ",
"get, identify, or set", (char *) NULL);
goto error;
}
done:
return result;
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* DestroyScrollbar --
*
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
* to clean up the internal structure of a scrollbar at a safe time
* (when no-one is using it anymore).
*
* Results:
* None.
*
* Side effects:
* Everything associated with the scrollbar is freed up.
*
*----------------------------------------------------------------------
*/
static void
char *memPtr; /* Info about scrollbar widget. */
{
/*
* Free up all the stuff that requires special handling, then
* let Tk_FreeOptions handle all the standard option-related
* stuff.
*/
}
}
}
/*
*----------------------------------------------------------------------
*
* ConfigureScrollbar --
*
* the Tk option database, in order to configure (or
* reconfigure) a scrollbar widget.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side effects:
* Configuration information, such as colors, border width,
* etc. get set for scrollPtr; old resources get freed,
* if there were any.
*
*----------------------------------------------------------------------
*/
static int
* may not already have values for
* some fields. */
int argc; /* Number of valid entries in argv. */
char **argv; /* Arguments. */
int flags; /* Flags to pass to
* Tk_ConfigureWidget. */
{
return TCL_ERROR;
}
/*
* A few options need special processing, such as parsing the
* orientation or setting the background from a 3-D border.
*/
} else {
"\": must be vertical or horizontal", (char *) NULL);
return TCL_ERROR;
}
} else {
scrollPtr->commandSize = 0;
}
}
&gcValues);
}
/*
* Register the desired geometry for the window (leave enough space
* for the two arrows plus a minimum-size slider, plus border around
* the whole window, if any). Then arrange for the window to be
* redisplayed.
*/
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DisplayScrollbar --
*
* This procedure redraws the contents of a scrollbar window.
* It is invoked as a do-when-idle handler, so it only runs
* when there's nothing else for the application to do.
*
* Results:
* None.
*
* Side effects:
* Information appears on the screen.
*
*--------------------------------------------------------------
*/
static void
{
goto done;
}
} else {
}
if (elementBorderWidth < 0) {
}
/*
* In order to avoid screen flashes, this procedure redraws
* the scrollbar in a pixmap, then copies the pixmap to the
* screen in a single operation. This means that there's no
* point in time where the on-sreen image has been cleared.
*/
if (scrollPtr->highlightWidth != 0) {
} else {
}
}
/*
* Draw the top or left arrow. The coordinates of the polygon
* points probably seem odd, but they were carefully chosen with
* respect to X's rules for filling polygons. These point choices
* cause the arrows to just fill the narrow dimension of the
* scrollbar and be properly centered.
*/
} else {
}
} else {
}
/*
* Display the bottom or right arrow.
*/
} else {
}
} else {
}
/*
* Display the slider.
*/
} else {
}
} else {
}
/*
* Copy the information from the off-screen pixmap onto the screen,
* then delete the pixmap.
*/
done:
}
/*
*--------------------------------------------------------------
*
* ScrollbarEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on scrollbars.
*
* Results:
* None.
*
* Side effects:
* When the window gets deleted, internal structures get
* cleaned up. When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
{
}
}
if (scrollPtr->highlightWidth > 0) {
}
}
if (scrollPtr->highlightWidth > 0) {
}
}
}
}
/*
*----------------------------------------------------------------------
*
* ScrollbarCmdDeletedProc --
*
* This procedure is invoked when a widget command is deleted. If
* the widget isn't already in the process of being destroyed,
* this command destroys it.
*
* Results:
* None.
*
* Side effects:
* The widget is destroyed.
*
*----------------------------------------------------------------------
*/
static void
{
/*
* This procedure could be invoked either because the window was
* destroyed and the command was then deleted (in which case tkwin
* is NULL) or because the command was deleted, and then this procedure
* destroys the widget.
*/
}
}
/*
*----------------------------------------------------------------------
*
* ComputeScrollbarGeometry --
*
* After changes in a scrollbar's size or configuration, this
* procedure recomputes various geometry information used in
* displaying the scrollbar.
*
* Results:
* None.
*
* Side effects:
* The scrollbar will be displayed differently.
*
*----------------------------------------------------------------------
*/
static void
* have changed. */
{
if (scrollPtr->highlightWidth < 0) {
scrollPtr->highlightWidth = 0;
}
if (fieldLength < 0) {
fieldLength = 0;
}
/*
* Adjust the slider so that some piece of it is always
* displayed in the scrollbar and so that it has at least
* a minimal width (so it can be grabbed with the mouse).
*/
}
if (scrollPtr->sliderFirst < 0) {
scrollPtr->sliderFirst = 0;
}
+ MIN_SLIDER_LENGTH)) {
}
}
/*
* Register the desired geometry for the window (leave enough space
* for the two arrows plus a minimum-size slider, plus border around
* the whole window, if any). Then arrange for the window to be
* redisplayed.
*/
} else {
}
}
/*
*--------------------------------------------------------------
*
* ScrollbarPosition --
*
* Determine the scrollbar element corresponding to a
* given position.
*
* Results:
* One of TOP_ARROW, TOP_GAP, etc., indicating which element
* of the scrollbar covers the position given by (x, y). If
* (x,y) is outside the scrollbar entirely, then OUTSIDE is
* returned.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static int
int x, y; /* Coordinates within scrollPtr's
* window. */
{
} else {
tmp = x;
x = y;
y = tmp;
}
return OUTSIDE;
}
/*
* All of the calculations in this procedure mirror those in
* DisplayScrollbar. Be sure to keep the two consistent.
*/
return TOP_ARROW;
}
if (y < scrollPtr->sliderFirst) {
return TOP_GAP;
}
if (y < scrollPtr->sliderLast) {
return SLIDER;
}
return BOTTOM_ARROW;
}
return BOTTOM_GAP;
}
/*
*--------------------------------------------------------------
*
* EventuallyRedraw --
*
* Arrange for one or more of the fields of a scrollbar
* to be redrawn.
*
* Results:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static void
{
return;
}
}
}