| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "bltInt.h" |
| 20 |
|
| 21 |
#ifndef NO_TILESCROLLBAR |
| 22 |
|
| 23 |
#include "bltTile.h" |
| 24 |
|
| 25 |
extern Tk_CustomOption bltTileOption; |
| 26 |
|
| 27 |
#define NORMAL_BG "#d9d9d9" |
| 28 |
#define ACTIVE_BG "#ececec" |
| 29 |
#define SELECT_BG "#c3c3c3" |
| 30 |
#define TROUGH "#c3c3c3" |
| 31 |
#define INDICATOR "#b03060" |
| 32 |
#define DISABLED "#a3a3a3" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#define DEF_SCROLLBAR_ACTIVE_BACKGROUND ACTIVE_BG |
| 38 |
#define DEF_SCROLLBAR_ACTIVE_BG_MONO RGB_BLACK |
| 39 |
#define DEF_SCROLLBAR_ACTIVE_RELIEF "raised" |
| 40 |
#define DEF_SCROLLBAR_BACKGROUND NORMAL_BG |
| 41 |
#define DEF_SCROLLBAR_BG_MONO RGB_WHITE |
| 42 |
#define DEF_SCROLLBAR_BORDERWIDTH "2" |
| 43 |
#define DEF_SCROLLBAR_COMMAND "" |
| 44 |
#define DEF_SCROLLBAR_CURSOR "" |
| 45 |
#define DEF_SCROLLBAR_EL_BORDERWIDTH "-1" |
| 46 |
#define DEF_SCROLLBAR_HIGHLIGHT_BG NORMAL_BG |
| 47 |
#define DEF_SCROLLBAR_HIGHLIGHT RGB_BLACK |
| 48 |
#define DEF_SCROLLBAR_HIGHLIGHT_WIDTH "2" |
| 49 |
#define DEF_SCROLLBAR_JUMP "0" |
| 50 |
#define DEF_SCROLLBAR_ORIENT "vertical" |
| 51 |
#define DEF_SCROLLBAR_RELIEF "sunken" |
| 52 |
#define DEF_SCROLLBAR_REPEAT_DELAY "300" |
| 53 |
#define DEF_SCROLLBAR_REPEAT_INTERVAL "100" |
| 54 |
#define DEF_SCROLLBAR_TAKE_FOCUS (char *) NULL |
| 55 |
#define DEF_SCROLLBAR_TROUGH_COLOR TROUGH |
| 56 |
#define DEF_SCROLLBAR_TROUGH_MONO RGB_WHITE |
| 57 |
#define DEF_SCROLLBAR_WIDTH "15" |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
typedef struct { |
| 66 |
Tk_Window tkwin; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
Display *display; |
| 71 |
|
| 72 |
|
| 73 |
Tcl_Interp *interp; |
| 74 |
Tcl_Command widgetCmd; |
| 75 |
Tk_Uid orientUid; |
| 76 |
|
| 77 |
int vertical; |
| 78 |
|
| 79 |
int width; |
| 80 |
|
| 81 |
char *command; |
| 82 |
|
| 83 |
|
| 84 |
int commandSize; |
| 85 |
int repeatDelay; |
| 86 |
|
| 87 |
int repeatInterval; |
| 88 |
int jump; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
int borderWidth; |
| 95 |
Tk_3DBorder bgBorder; |
| 96 |
|
| 97 |
Tk_3DBorder activeBorder; |
| 98 |
|
| 99 |
XColor *troughColorPtr; |
| 100 |
GC troughGC; |
| 101 |
GC copyGC; |
| 102 |
int relief; |
| 103 |
|
| 104 |
int highlightWidth; |
| 105 |
|
| 106 |
|
| 107 |
XColor *highlightBgColorPtr; |
| 108 |
|
| 109 |
|
| 110 |
XColor *highlightColorPtr; |
| 111 |
int inset; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
int elementBorderWidth; |
| 117 |
|
| 118 |
|
| 119 |
int arrowLength; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
int sliderFirst; |
| 124 |
|
| 125 |
int sliderLast; |
| 126 |
|
| 127 |
|
| 128 |
int activeField; |
| 129 |
|
| 130 |
|
| 131 |
int activeRelief; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
int totalUnits; |
| 146 |
|
| 147 |
|
| 148 |
int windowUnits; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int firstUnit; |
| 153 |
|
| 154 |
|
| 155 |
int lastUnit; |
| 156 |
|
| 157 |
|
| 158 |
double firstFraction; |
| 159 |
|
| 160 |
|
| 161 |
double lastFraction; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
Tk_Cursor cursor; |
| 170 |
char *takeFocus; |
| 171 |
|
| 172 |
|
| 173 |
int flags; |
| 174 |
|
| 175 |
Blt_Tile tile, tile2, activeTile; |
| 176 |
char *imagePtr; |
| 177 |
Tk_Image image; |
| 178 |
} Scrollbar; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
#define OUTSIDE 0 |
| 186 |
#define TOP_ARROW 1 |
| 187 |
#define TOP_GAP 2 |
| 188 |
#define SLIDER 3 |
| 189 |
#define BOTTOM_GAP 4 |
| 190 |
#define BOTTOM_ARROW 5 |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
#define REDRAW_PENDING 1 |
| 207 |
#define NEW_STYLE_COMMANDS 2 |
| 208 |
#define GOT_FOCUS 4 |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
#define MIN_SLIDER_LENGTH 8 |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
static Tk_ConfigSpec configSpecs[] = |
| 222 |
{ |
| 223 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", |
| 224 |
DEF_SCROLLBAR_ACTIVE_BACKGROUND, Tk_Offset(Scrollbar, activeBorder), |
| 225 |
TK_CONFIG_COLOR_ONLY}, |
| 226 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", |
| 227 |
DEF_SCROLLBAR_ACTIVE_BG_MONO, Tk_Offset(Scrollbar, activeBorder), |
| 228 |
TK_CONFIG_MONO_ONLY}, |
| 229 |
{TK_CONFIG_RELIEF, "-activerelief", "activeRelief", "Relief", |
| 230 |
DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(Scrollbar, activeRelief), 0}, |
| 231 |
{TK_CONFIG_CUSTOM, "-activetile", "activeTile", "Tile", |
| 232 |
(char *)NULL, Tk_Offset(Scrollbar, activeTile), TK_CONFIG_NULL_OK, |
| 233 |
&bltTileOption}, |
| 234 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 235 |
DEF_SCROLLBAR_BACKGROUND, Tk_Offset(Scrollbar, bgBorder), |
| 236 |
TK_CONFIG_COLOR_ONLY}, |
| 237 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 238 |
DEF_SCROLLBAR_BG_MONO, Tk_Offset(Scrollbar, bgBorder), |
| 239 |
TK_CONFIG_MONO_ONLY}, |
| 240 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, |
| 241 |
(char *)NULL, 0, 0}, |
| 242 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, |
| 243 |
(char *)NULL, 0, 0}, |
| 244 |
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", |
| 245 |
DEF_SCROLLBAR_BORDERWIDTH, Tk_Offset(Scrollbar, borderWidth), 0}, |
| 246 |
{TK_CONFIG_STRING, "-command", "command", "Command", |
| 247 |
DEF_SCROLLBAR_COMMAND, Tk_Offset(Scrollbar, command), |
| 248 |
TK_CONFIG_NULL_OK}, |
| 249 |
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", |
| 250 |
DEF_SCROLLBAR_CURSOR, Tk_Offset(Scrollbar, cursor), TK_CONFIG_NULL_OK}, |
| 251 |
{TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth", |
| 252 |
"BorderWidth", DEF_SCROLLBAR_EL_BORDERWIDTH, |
| 253 |
Tk_Offset(Scrollbar, elementBorderWidth), 0}, |
| 254 |
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground", |
| 255 |
"HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG, |
| 256 |
Tk_Offset(Scrollbar, highlightBgColorPtr), 0}, |
| 257 |
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", |
| 258 |
DEF_SCROLLBAR_HIGHLIGHT, |
| 259 |
Tk_Offset(Scrollbar, highlightColorPtr), 0}, |
| 260 |
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", |
| 261 |
"HighlightThickness", |
| 262 |
DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(Scrollbar, highlightWidth), 0}, |
| 263 |
{TK_CONFIG_STRING, "-image", "image", "Image", |
| 264 |
NULL, Tk_Offset(TkScrollbar, imagePtr), 0}, |
| 265 |
{TK_CONFIG_BOOLEAN, "-jump", "jump", "Jump", |
| 266 |
DEF_SCROLLBAR_JUMP, Tk_Offset(Scrollbar, jump), 0}, |
| 267 |
{TK_CONFIG_UID, "-orient", "orient", "Orient", |
| 268 |
DEF_SCROLLBAR_ORIENT, Tk_Offset(Scrollbar, orientUid), 0}, |
| 269 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 270 |
DEF_SCROLLBAR_RELIEF, Tk_Offset(Scrollbar, relief), 0}, |
| 271 |
{TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay", |
| 272 |
DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(Scrollbar, repeatDelay), 0}, |
| 273 |
{TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval", |
| 274 |
DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(Scrollbar, repeatInterval), 0}, |
| 275 |
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 276 |
DEF_SCROLLBAR_TAKE_FOCUS, Tk_Offset(Scrollbar, takeFocus), |
| 277 |
TK_CONFIG_NULL_OK}, |
| 278 |
{TK_CONFIG_CUSTOM, "-tile", "tile", "Tile", |
| 279 |
(char *)NULL, Tk_Offset(Scrollbar, tile), TK_CONFIG_NULL_OK, |
| 280 |
&bltTileOption}, |
| 281 |
{TK_CONFIG_CUSTOM, "-tile2", "tile2", "Tile", |
| 282 |
(char *)NULL, Tk_Offset(Scrollbar, tile2), TK_CONFIG_NULL_OK, |
| 283 |
&bltTileOption}, |
| 284 |
{TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background", |
| 285 |
DEF_SCROLLBAR_TROUGH_COLOR, Tk_Offset(Scrollbar, troughColorPtr), |
| 286 |
TK_CONFIG_COLOR_ONLY}, |
| 287 |
{TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background", |
| 288 |
DEF_SCROLLBAR_TROUGH_MONO, Tk_Offset(Scrollbar, troughColorPtr), |
| 289 |
TK_CONFIG_MONO_ONLY}, |
| 290 |
{TK_CONFIG_PIXELS, "-width", "width", "Width", |
| 291 |
DEF_SCROLLBAR_WIDTH, Tk_Offset(Scrollbar, width), 0}, |
| 292 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 293 |
(char *)NULL, 0, 0} |
| 294 |
}; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
static void ComputeScrollbarGeometry _ANSI_ARGS_(( |
| 301 |
Scrollbar *scrollPtr)); |
| 302 |
static int ConfigureScrollbar _ANSI_ARGS_((Tcl_Interp *interp, |
| 303 |
Scrollbar *scrollPtr, int argc, char **argv, |
| 304 |
int flags)); |
| 305 |
static void DestroyScrollbar _ANSI_ARGS_((DestroyData *memPtr)); |
| 306 |
static void DisplayScrollbar _ANSI_ARGS_((ClientData clientData)); |
| 307 |
static void EventuallyRedraw _ANSI_ARGS_((Scrollbar *scrollPtr)); |
| 308 |
static void ScrollbarCmdDeletedProc _ANSI_ARGS_(( |
| 309 |
ClientData clientData)); |
| 310 |
static void ScrollbarEventProc _ANSI_ARGS_((ClientData clientData, |
| 311 |
XEvent *eventPtr)); |
| 312 |
static int ScrollbarPosition _ANSI_ARGS_((Scrollbar *scrollPtr, |
| 313 |
int x, int y)); |
| 314 |
static int ScrollbarWidgetCmd _ANSI_ARGS_((ClientData clientData, |
| 315 |
Tcl_Interp *, int argc, char **argv)); |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
static int |
| 336 |
scrollbarCmd(clientData, interp, argc, argv, stype) |
| 337 |
ClientData clientData; |
| 338 |
|
| 339 |
Tcl_Interp *interp; |
| 340 |
int argc; |
| 341 |
char **argv; |
| 342 |
int stype; |
| 343 |
{ |
| 344 |
register Scrollbar *scrollPtr; |
| 345 |
Tk_Window tkwin; |
| 346 |
|
| 347 |
if (argc < 2) { |
| 348 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 349 |
argv[0], " pathName ?options?\"", (char *)NULL); |
| 350 |
return TCL_ERROR; |
| 351 |
} |
| 352 |
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1], |
| 353 |
(char *)NULL); |
| 354 |
if (tkwin == NULL) { |
| 355 |
return TCL_ERROR; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
scrollPtr = Blt_Calloc(1, sizeof(Scrollbar)); |
| 364 |
scrollPtr->tkwin = tkwin; |
| 365 |
scrollPtr->display = Tk_Display(tkwin); |
| 366 |
scrollPtr->interp = interp; |
| 367 |
scrollPtr->widgetCmd = Tcl_CreateCommand(interp, |
| 368 |
Tk_PathName(scrollPtr->tkwin), ScrollbarWidgetCmd, |
| 369 |
(ClientData)scrollPtr, ScrollbarCmdDeletedProc); |
| 370 |
#ifdef ITCL_NAMESPACES |
| 371 |
Itk_SetWidgetCommand(scrollPtr->tkwin, scrollPtr->widgetCmd); |
| 372 |
#endif |
| 373 |
scrollPtr->orientUid = NULL; |
| 374 |
scrollPtr->vertical = 0; |
| 375 |
scrollPtr->width = 0; |
| 376 |
scrollPtr->command = NULL; |
| 377 |
scrollPtr->commandSize = 0; |
| 378 |
scrollPtr->repeatDelay = 0; |
| 379 |
scrollPtr->repeatInterval = 0; |
| 380 |
scrollPtr->borderWidth = 0; |
| 381 |
scrollPtr->bgBorder = NULL; |
| 382 |
scrollPtr->activeBorder = NULL; |
| 383 |
scrollPtr->troughColorPtr = NULL; |
| 384 |
scrollPtr->troughGC = None; |
| 385 |
scrollPtr->copyGC = None; |
| 386 |
scrollPtr->relief = TK_RELIEF_FLAT; |
| 387 |
scrollPtr->highlightWidth = 0; |
| 388 |
scrollPtr->highlightBgColorPtr = NULL; |
| 389 |
scrollPtr->highlightColorPtr = NULL; |
| 390 |
scrollPtr->inset = 0; |
| 391 |
scrollPtr->elementBorderWidth = -1; |
| 392 |
scrollPtr->arrowLength = 0; |
| 393 |
scrollPtr->sliderFirst = 0; |
| 394 |
scrollPtr->sliderLast = 0; |
| 395 |
scrollPtr->activeField = 0; |
| 396 |
scrollPtr->activeRelief = TK_RELIEF_RAISED; |
| 397 |
scrollPtr->totalUnits = 0; |
| 398 |
scrollPtr->windowUnits = 0; |
| 399 |
scrollPtr->firstUnit = 0; |
| 400 |
scrollPtr->lastUnit = 0; |
| 401 |
scrollPtr->firstFraction = 0.0; |
| 402 |
scrollPtr->lastFraction = 0.0; |
| 403 |
scrollPtr->cursor = None; |
| 404 |
scrollPtr->takeFocus = NULL; |
| 405 |
scrollPtr->flags = 0; |
| 406 |
scrollPtr->tile = scrollPtr->tile2 = scrollPtr->activeTile = NULL; |
| 407 |
|
| 408 |
if (stype) { |
| 409 |
Tk_SetClass(scrollPtr->tkwin, "BScrollbar"); |
| 410 |
} else { |
| 411 |
Tk_SetClass(scrollPtr->tkwin, "Scrollbar"); |
| 412 |
} |
| 413 |
Tk_CreateEventHandler(scrollPtr->tkwin, |
| 414 |
ExposureMask | StructureNotifyMask | FocusChangeMask, |
| 415 |
ScrollbarEventProc, (ClientData)scrollPtr); |
| 416 |
if (ConfigureScrollbar(interp, scrollPtr, argc - 2, argv + 2, 0) != TCL_OK) { |
| 417 |
goto error; |
| 418 |
} |
| 419 |
Tcl_SetResult(interp, Tk_PathName(scrollPtr->tkwin), TCL_VOLATILE); |
| 420 |
return TCL_OK; |
| 421 |
|
| 422 |
error: |
| 423 |
Tk_DestroyWindow(scrollPtr->tkwin); |
| 424 |
return TCL_ERROR; |
| 425 |
} |
| 426 |
|
| 427 |
static int |
| 428 |
BScrollbarCmd(clientData, interp, argc, argv) |
| 429 |
ClientData clientData; |
| 430 |
|
| 431 |
Tcl_Interp *interp; |
| 432 |
int argc; |
| 433 |
char **argv; |
| 434 |
{ |
| 435 |
return scrollbarCmd(clientData, interp, argc, argv, 1); |
| 436 |
} |
| 437 |
|
| 438 |
static int |
| 439 |
ScrollbarCmd(clientData, interp, argc, argv) |
| 440 |
ClientData clientData; |
| 441 |
|
| 442 |
Tcl_Interp *interp; |
| 443 |
int argc; |
| 444 |
char **argv; |
| 445 |
{ |
| 446 |
return scrollbarCmd(clientData, interp, argc, argv, 0); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
static int |
| 468 |
ScrollbarWidgetCmd(clientData, interp, argc, argv) |
| 469 |
ClientData clientData; |
| 470 |
|
| 471 |
Tcl_Interp *interp; |
| 472 |
int argc; |
| 473 |
char **argv; |
| 474 |
{ |
| 475 |
register Scrollbar *scrollPtr = clientData; |
| 476 |
char string[200]; |
| 477 |
int result = TCL_OK; |
| 478 |
size_t length; |
| 479 |
int c; |
| 480 |
|
| 481 |
if (argc < 2) { |
| 482 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 483 |
argv[0], " option ?arg arg ...?\"", (char *)NULL); |
| 484 |
return TCL_ERROR; |
| 485 |
} |
| 486 |
Tcl_Preserve((ClientData)scrollPtr); |
| 487 |
c = argv[1][0]; |
| 488 |
length = strlen(argv[1]); |
| 489 |
if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) { |
| 490 |
if (argc == 2) { |
| 491 |
switch (scrollPtr->activeField) { |
| 492 |
case TOP_ARROW: |
| 493 |
Tcl_SetResult(interp, "arrow1", TCL_STATIC); |
| 494 |
break; |
| 495 |
case SLIDER: |
| 496 |
Tcl_SetResult(interp, "slider", TCL_STATIC); |
| 497 |
break; |
| 498 |
case BOTTOM_ARROW: |
| 499 |
Tcl_SetResult(interp, "arrow2", TCL_STATIC); |
| 500 |
break; |
| 501 |
} |
| 502 |
goto done; |
| 503 |
} |
| 504 |
if (argc != 3) { |
| 505 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 506 |
argv[0], " activate element\"", (char *)NULL); |
| 507 |
goto error; |
| 508 |
} |
| 509 |
c = argv[2][0]; |
| 510 |
length = strlen(argv[2]); |
| 511 |
if ((c == 'a') && (strcmp(argv[2], "arrow1") == 0)) { |
| 512 |
scrollPtr->activeField = TOP_ARROW; |
| 513 |
} else if ((c == 'a') && (strcmp(argv[2], "arrow2") == 0)) { |
| 514 |
scrollPtr->activeField = BOTTOM_ARROW; |
| 515 |
} else if ((c == 's') && (strncmp(argv[2], "slider", length) == 0)) { |
| 516 |
scrollPtr->activeField = SLIDER; |
| 517 |
} else { |
| 518 |
scrollPtr->activeField = OUTSIDE; |
| 519 |
} |
| 520 |
EventuallyRedraw(scrollPtr); |
| 521 |
} else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0) |
| 522 |
&& (length >= 2)) { |
| 523 |
if (argc != 3) { |
| 524 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 525 |
argv[0], " cget option\"", |
| 526 |
(char *)NULL); |
| 527 |
goto error; |
| 528 |
} |
| 529 |
result = Tk_ConfigureValue(interp, scrollPtr->tkwin, configSpecs, |
| 530 |
(char *)scrollPtr, argv[2], 0); |
| 531 |
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0) |
| 532 |
&& (length >= 2)) { |
| 533 |
if (argc == 2) { |
| 534 |
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin, configSpecs, |
| 535 |
(char *)scrollPtr, (char *)NULL, 0); |
| 536 |
} else if (argc == 3) { |
| 537 |
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin, configSpecs, |
| 538 |
(char *)scrollPtr, argv[2], 0); |
| 539 |
} else { |
| 540 |
result = ConfigureScrollbar(interp, scrollPtr, argc - 2, argv + 2, |
| 541 |
TK_CONFIG_ARGV_ONLY); |
| 542 |
} |
| 543 |
} else if ((c == 'd') && (strncmp(argv[1], "delta", length) == 0)) { |
| 544 |
int xDelta, yDelta, pixels, barWidth; |
| 545 |
double fraction; |
| 546 |
|
| 547 |
if (argc != 4) { |
| 548 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 549 |
argv[0], " delta xDelta yDelta\"", (char *)NULL); |
| 550 |
goto error; |
| 551 |
} |
| 552 |
if ((Tcl_GetInt(interp, argv[2], &xDelta) != TCL_OK) |
| 553 |
|| (Tcl_GetInt(interp, argv[3], &yDelta) != TCL_OK)) { |
| 554 |
goto error; |
| 555 |
} |
| 556 |
if (scrollPtr->vertical) { |
| 557 |
pixels = yDelta; |
| 558 |
barWidth = Tk_Height(scrollPtr->tkwin) - 1 |
| 559 |
- 2 * (scrollPtr->arrowLength + scrollPtr->inset); |
| 560 |
} else { |
| 561 |
pixels = xDelta; |
| 562 |
barWidth = Tk_Width(scrollPtr->tkwin) - 1 |
| 563 |
- 2 * (scrollPtr->arrowLength + scrollPtr->inset); |
| 564 |
} |
| 565 |
if (barWidth == 0) { |
| 566 |
fraction = 0.0; |
| 567 |
} else { |
| 568 |
fraction = ((double)pixels / (double)barWidth); |
| 569 |
} |
| 570 |
sprintf(interp->result, "%g", fraction); |
| 571 |
} else if ((c == 'f') && (strncmp(argv[1], "fraction", length) == 0)) { |
| 572 |
int x, y, pos, barWidth; |
| 573 |
double fraction; |
| 574 |
|
| 575 |
if (argc != 4) { |
| 576 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 577 |
argv[0], " fraction x y\"", (char *)NULL); |
| 578 |
goto error; |
| 579 |
} |
| 580 |
if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) |
| 581 |
|| (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) { |
| 582 |
goto error; |
| 583 |
} |
| 584 |
if (scrollPtr->vertical) { |
| 585 |
pos = y - (scrollPtr->arrowLength + scrollPtr->inset); |
| 586 |
barWidth = Tk_Height(scrollPtr->tkwin) - 1 |
| 587 |
- 2 * (scrollPtr->arrowLength + scrollPtr->inset); |
| 588 |
} else { |
| 589 |
pos = x - (scrollPtr->arrowLength + scrollPtr->inset); |
| 590 |
barWidth = Tk_Width(scrollPtr->tkwin) - 1 |
| 591 |
- 2 * (scrollPtr->arrowLength + scrollPtr->inset); |
| 592 |
} |
| 593 |
if (barWidth == 0) { |
| 594 |
fraction = 0.0; |
| 595 |
} else { |
| 596 |
fraction = ((double)pos / (double)barWidth); |
| 597 |
} |
| 598 |
if (fraction < 0) { |
| 599 |
fraction = 0; |
| 600 |
} else if (fraction > 1.0) { |
| 601 |
fraction = 1.0; |
| 602 |
} |
| 603 |
sprintf(string, "%g", fraction); |
| 604 |
Tcl_SetResult(interp, string, TCL_VOLATILE); |
| 605 |
} else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) { |
| 606 |
if (argc != 2) { |
| 607 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 608 |
argv[0], " get\"", (char *)NULL); |
| 609 |
goto error; |
| 610 |
} |
| 611 |
if (scrollPtr->flags & NEW_STYLE_COMMANDS) { |
| 612 |
char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE]; |
| 613 |
|
| 614 |
Tcl_PrintDouble(interp, scrollPtr->firstFraction, first); |
| 615 |
Tcl_PrintDouble(interp, scrollPtr->lastFraction, last); |
| 616 |
Tcl_AppendResult(interp, first, " ", last, (char *)NULL); |
| 617 |
} else { |
| 618 |
sprintf(string, "%d %d %d %d", scrollPtr->totalUnits, |
| 619 |
scrollPtr->windowUnits, scrollPtr->firstUnit, |
| 620 |
scrollPtr->lastUnit); |
| 621 |
Tcl_SetResult(interp, string, TCL_VOLATILE); |
| 622 |
} |
| 623 |
} else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) { |
| 624 |
int x, y, thing; |
| 625 |
|
| 626 |
if (argc != 4) { |
| 627 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 628 |
argv[0], " identify x y\"", (char *)NULL); |
| 629 |
goto error; |
| 630 |
} |
| 631 |
if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) |
| 632 |
|| (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) { |
| 633 |
goto error; |
| 634 |
} |
| 635 |
thing = ScrollbarPosition(scrollPtr, x, y); |
| 636 |
switch (thing) { |
| 637 |
case TOP_ARROW: |
| 638 |
Tcl_SetResult(interp, "arrow1", TCL_STATIC); |
| 639 |
break; |
| 640 |
case TOP_GAP: |
| 641 |
Tcl_SetResult(interp, "trough1", TCL_STATIC); |
| 642 |
break; |
| 643 |
case SLIDER: |
| 644 |
Tcl_SetResult(interp, "slider", TCL_STATIC); |
| 645 |
break; |
| 646 |
case BOTTOM_GAP: |
| 647 |
Tcl_SetResult(interp, "trough2", TCL_STATIC); |
| 648 |
break; |
| 649 |
case BOTTOM_ARROW: |
| 650 |
Tcl_SetResult(interp, "arrow2", TCL_STATIC); |
| 651 |
break; |
| 652 |
} |
| 653 |
} else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) { |
| 654 |
int totalUnits, windowUnits, firstUnit, lastUnit; |
| 655 |
|
| 656 |
if (argc == 4) { |
| 657 |
double first, last; |
| 658 |
|
| 659 |
if (Tcl_GetDouble(interp, argv[2], &first) != TCL_OK) { |
| 660 |
goto error; |
| 661 |
} |
| 662 |
if (Tcl_GetDouble(interp, argv[3], &last) != TCL_OK) { |
| 663 |
goto error; |
| 664 |
} |
| 665 |
if (first < 0) { |
| 666 |
scrollPtr->firstFraction = 0; |
| 667 |
} else if (first > 1.0) { |
| 668 |
scrollPtr->firstFraction = 1.0; |
| 669 |
} else { |
| 670 |
scrollPtr->firstFraction = first; |
| 671 |
} |
| 672 |
if (last < scrollPtr->firstFraction) { |
| 673 |
scrollPtr->lastFraction = scrollPtr->firstFraction; |
| 674 |
} else if (last > 1.0) { |
| 675 |
scrollPtr->lastFraction = 1.0; |
| 676 |
} else { |
| 677 |
scrollPtr->lastFraction = last; |
| 678 |
} |
| 679 |
scrollPtr->flags |= NEW_STYLE_COMMANDS; |
| 680 |
} else if (argc == 6) { |
| 681 |
if (Tcl_GetInt(interp, argv[2], &totalUnits) != TCL_OK) { |
| 682 |
goto error; |
| 683 |
} |
| 684 |
if (totalUnits < 0) { |
| 685 |
totalUnits = 0; |
| 686 |
} |
| 687 |
if (Tcl_GetInt(interp, argv[3], &windowUnits) != TCL_OK) { |
| 688 |
goto error; |
| 689 |
} |
| 690 |
if (windowUnits < 0) { |
| 691 |
windowUnits = 0; |
| 692 |
} |
| 693 |
if (Tcl_GetInt(interp, argv[4], &firstUnit) != TCL_OK) { |
| 694 |
goto error; |
| 695 |
} |
| 696 |
if (Tcl_GetInt(interp, argv[5], &lastUnit) != TCL_OK) { |
| 697 |
goto error; |
| 698 |
} |
| 699 |
if (totalUnits > 0) { |
| 700 |
if (lastUnit < firstUnit) { |
| 701 |
lastUnit = firstUnit; |
| 702 |
} |
| 703 |
} else { |
| 704 |
firstUnit = lastUnit = 0; |
| 705 |
} |
| 706 |
scrollPtr->totalUnits = totalUnits; |
| 707 |
scrollPtr->windowUnits = windowUnits; |
| 708 |
scrollPtr->firstUnit = firstUnit; |
| 709 |
scrollPtr->lastUnit = lastUnit; |
| 710 |
if (scrollPtr->totalUnits == 0) { |
| 711 |
scrollPtr->firstFraction = 0.0; |
| 712 |
scrollPtr->lastFraction = 1.0; |
| 713 |
} else { |
| 714 |
scrollPtr->firstFraction = ((double)firstUnit) / totalUnits; |
| 715 |
scrollPtr->lastFraction = ((double)(lastUnit + 1)) / totalUnits; |
| 716 |
} |
| 717 |
scrollPtr->flags &= ~NEW_STYLE_COMMANDS; |
| 718 |
} else { |
| 719 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 720 |
argv[0], " set firstFraction lastFraction\" or \"", |
| 721 |
argv[0], |
| 722 |
" set totalUnits windowUnits firstUnit lastUnit\"", |
| 723 |
(char *)NULL); |
| 724 |
goto error; |
| 725 |
} |
| 726 |
ComputeScrollbarGeometry(scrollPtr); |
| 727 |
EventuallyRedraw(scrollPtr); |
| 728 |
} else { |
| 729 |
Tcl_AppendResult(interp, "bad option \"", argv[1], |
| 730 |
"\": must be activate, cget, configure, delta, fraction, ", |
| 731 |
"get, identify, or set", (char *)NULL); |
| 732 |
goto error; |
| 733 |
} |
| 734 |
done: |
| 735 |
Tcl_Release((ClientData)scrollPtr); |
| 736 |
return result; |
| 737 |
|
| 738 |
error: |
| 739 |
Tcl_Release((ClientData)scrollPtr); |
| 740 |
return TCL_ERROR; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
static void |
| 762 |
DestroyScrollbar(memPtr) |
| 763 |
DestroyData *memPtr; |
| 764 |
{ |
| 765 |
register Scrollbar *scrollPtr = (Scrollbar *)memPtr; |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
if (scrollPtr->troughGC != None) { |
| 774 |
Tk_FreeGC(scrollPtr->display, scrollPtr->troughGC); |
| 775 |
} |
| 776 |
if (scrollPtr->copyGC != None) { |
| 777 |
Tk_FreeGC(scrollPtr->display, scrollPtr->copyGC); |
| 778 |
} |
| 779 |
if (scrollPtr->activeTile != NULL) { |
| 780 |
Blt_FreeTile(scrollPtr->activeTile); |
| 781 |
} |
| 782 |
if (scrollPtr->tile != NULL) { |
| 783 |
Blt_FreeTile(scrollPtr->tile); |
| 784 |
} |
| 785 |
if (scrollPtr->tile2 != NULL) { |
| 786 |
Blt_FreeTile(scrollPtr->tile2); |
| 787 |
} |
| 788 |
if (scrollPtr->image != NULL) { |
| 789 |
Tk_FreeImage(scrollPtr->image); |
| 790 |
} |
| 791 |
Tk_FreeOptions(configSpecs, (char *)scrollPtr, scrollPtr->display, 0); |
| 792 |
Blt_Free(scrollPtr); |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
static void |
| 809 |
TileChangedProc(clientData, tile) |
| 810 |
ClientData clientData; |
| 811 |
Blt_Tile tile; |
| 812 |
{ |
| 813 |
Scrollbar *scrollPtr = clientData; |
| 814 |
|
| 815 |
if (scrollPtr->tkwin != NULL) { |
| 816 |
EventuallyRedraw(scrollPtr); |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
static void |
| 839 |
ScrollbarImageProc( |
| 840 |
ClientData clientData, |
| 841 |
int x, int y, |
| 842 |
|
| 843 |
int width, int height, |
| 844 |
|
| 845 |
int imgWidth, int imgHeight) |
| 846 |
{ |
| 847 |
register TkScrollbar *scrollPtr = (TkScrollbar *) clientData; |
| 848 |
|
| 849 |
if (scrollPtr->tkwin != NULL) { |
| 850 |
ComputeScrollbarGeometry(scrollPtr); |
| 851 |
if (Tk_IsMapped(scrollPtr->tkwin) && !(scrollPtr->flags & REDRAW_PENDING)) { |
| 852 |
Tcl_DoWhenIdle(TkpDisplayScrollbar, (ClientData) scrollPtr); |
| 853 |
scrollPtr->flags |= REDRAW_PENDING; |
| 854 |
} |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
static int |
| 880 |
ConfigureScrollbar(interp, scrollPtr, argc, argv, flags) |
| 881 |
Tcl_Interp *interp; |
| 882 |
register Scrollbar *scrollPtr; |
| 883 |
|
| 884 |
|
| 885 |
int argc; |
| 886 |
char **argv; |
| 887 |
int flags; |
| 888 |
|
| 889 |
{ |
| 890 |
size_t length; |
| 891 |
XGCValues gcValues; |
| 892 |
GC new; |
| 893 |
Tk_Image image; |
| 894 |
|
| 895 |
if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, configSpecs, |
| 896 |
argc, argv, (char *)scrollPtr, flags) != TCL_OK) { |
| 897 |
return TCL_ERROR; |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
length = strlen(scrollPtr->orientUid); |
| 905 |
if (strncmp(scrollPtr->orientUid, "vertical", length) == 0) { |
| 906 |
scrollPtr->vertical = 1; |
| 907 |
} else if (strncmp(scrollPtr->orientUid, "horizontal", length) == 0) { |
| 908 |
scrollPtr->vertical = 0; |
| 909 |
} else { |
| 910 |
Tcl_AppendResult(interp, "bad orientation \"", scrollPtr->orientUid, |
| 911 |
"\": must be vertical or horizontal", (char *)NULL); |
| 912 |
return TCL_ERROR; |
| 913 |
} |
| 914 |
|
| 915 |
if (scrollPtr->command != NULL) { |
| 916 |
scrollPtr->commandSize = strlen(scrollPtr->command); |
| 917 |
} else { |
| 918 |
scrollPtr->commandSize = 0; |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
if (scrollPtr->imagePtr != NULL) { |
| 926 |
image = Tk_GetImage(scrollPtr->interp, scrollPtr->tkwin, |
| 927 |
scrollPtr->imagePtr, ScrollbarImageProc, |
| 928 |
(ClientData) scrollPtr); |
| 929 |
} else { |
| 930 |
image = NULL; |
| 931 |
} |
| 932 |
if (scrollPtr->image != NULL) { |
| 933 |
Tk_FreeImage(scrollPtr->image); |
| 934 |
} |
| 935 |
scrollPtr->image = image; |
| 936 |
|
| 937 |
|
| 938 |
if (scrollPtr->activeTile != NULL) { |
| 939 |
Blt_SetTileChangedProc(scrollPtr->activeTile, TileChangedProc, |
| 940 |
(ClientData)scrollPtr); |
| 941 |
} |
| 942 |
if (scrollPtr->tile != NULL) { |
| 943 |
Blt_SetTileChangedProc(scrollPtr->tile, TileChangedProc, |
| 944 |
(ClientData)scrollPtr); |
| 945 |
} |
| 946 |
if (scrollPtr->tile2 != NULL) { |
| 947 |
Blt_SetTileChangedProc(scrollPtr->tile2, TileChangedProc, |
| 948 |
(ClientData)scrollPtr); |
| 949 |
} |
| 950 |
Tk_SetBackgroundFromBorder(scrollPtr->tkwin, scrollPtr->bgBorder); |
| 951 |
|
| 952 |
gcValues.foreground = scrollPtr->troughColorPtr->pixel; |
| 953 |
new = Tk_GetGC(scrollPtr->tkwin, GCForeground, &gcValues); |
| 954 |
if (scrollPtr->troughGC != None) { |
| 955 |
Tk_FreeGC(scrollPtr->display, scrollPtr->troughGC); |
| 956 |
} |
| 957 |
scrollPtr->troughGC = new; |
| 958 |
if (scrollPtr->copyGC == None) { |
| 959 |
gcValues.graphics_exposures = False; |
| 960 |
scrollPtr->copyGC = Tk_GetGC(scrollPtr->tkwin, GCGraphicsExposures, |
| 961 |
&gcValues); |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
ComputeScrollbarGeometry(scrollPtr); |
| 971 |
EventuallyRedraw(scrollPtr); |
| 972 |
return TCL_OK; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
static void |
| 994 |
DisplayScrollbar(clientData) |
| 995 |
ClientData clientData; |
| 996 |
{ |
| 997 |
register Scrollbar *scrollPtr = clientData; |
| 998 |
register Tk_Window tkwin = scrollPtr->tkwin; |
| 999 |
XPoint points[7]; |
| 1000 |
Tk_3DBorder border; |
| 1001 |
int relief, width, elementBorderWidth; |
| 1002 |
Pixmap pixmap; |
| 1003 |
Blt_Tile tile; |
| 1004 |
|
| 1005 |
if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { |
| 1006 |
goto done; |
| 1007 |
} |
| 1008 |
if (scrollPtr->vertical) { |
| 1009 |
width = Tk_Width(tkwin) - 2 * scrollPtr->inset; |
| 1010 |
} else { |
| 1011 |
width = Tk_Height(tkwin) - 2 * scrollPtr->inset; |
| 1012 |
} |
| 1013 |
elementBorderWidth = scrollPtr->elementBorderWidth; |
| 1014 |
if (elementBorderWidth < 0) { |
| 1015 |
elementBorderWidth = scrollPtr->borderWidth; |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
pixmap = Tk_GetPixmap(scrollPtr->display, Tk_WindowId(tkwin), |
| 1026 |
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); |
| 1027 |
|
| 1028 |
if (scrollPtr->highlightWidth != 0) { |
| 1029 |
GC gc; |
| 1030 |
|
| 1031 |
if (scrollPtr->flags & GOT_FOCUS) { |
| 1032 |
gc = Tk_GCForColor(scrollPtr->highlightColorPtr, pixmap); |
| 1033 |
} else { |
| 1034 |
gc = Tk_GCForColor(scrollPtr->highlightBgColorPtr, pixmap); |
| 1035 |
} |
| 1036 |
Tk_DrawFocusHighlight(tkwin, gc, scrollPtr->highlightWidth, pixmap); |
| 1037 |
} |
| 1038 |
Blt_Draw3DRectangle(tkwin, pixmap, scrollPtr->bgBorder, |
| 1039 |
scrollPtr->highlightWidth, scrollPtr->highlightWidth, |
| 1040 |
Tk_Width(tkwin) - 2 * scrollPtr->highlightWidth, |
| 1041 |
Tk_Height(tkwin) - 2 * scrollPtr->highlightWidth, |
| 1042 |
scrollPtr->borderWidth, scrollPtr->relief); |
| 1043 |
|
| 1044 |
if (Blt_HasTile(scrollPtr->tile)) { |
| 1045 |
Blt_SetTileOrigin(tkwin, scrollPtr->tile, 0, 0); |
| 1046 |
Blt_TileRectangle(tkwin, pixmap, scrollPtr->tile, scrollPtr->inset, |
| 1047 |
scrollPtr->inset, |
| 1048 |
(unsigned)(Tk_Width(tkwin) - 2 * scrollPtr->inset), |
| 1049 |
(unsigned)(Tk_Height(tkwin) - 2 * scrollPtr->inset)); |
| 1050 |
} else { |
| 1051 |
XFillRectangle(scrollPtr->display, pixmap, scrollPtr->troughGC, |
| 1052 |
scrollPtr->inset, scrollPtr->inset, |
| 1053 |
(unsigned)(Tk_Width(tkwin) - 2 * scrollPtr->inset), |
| 1054 |
(unsigned)(Tk_Height(tkwin) - 2 * scrollPtr->inset)); |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
tile = NULL; |
| 1065 |
if (scrollPtr->activeField == TOP_ARROW) { |
| 1066 |
border = scrollPtr->activeBorder; |
| 1067 |
relief = scrollPtr->activeField == TOP_ARROW ? scrollPtr->activeRelief |
| 1068 |
: TK_RELIEF_RAISED; |
| 1069 |
if (scrollPtr->activeTile != NULL) { |
| 1070 |
Blt_SetTileOrigin(tkwin, scrollPtr->activeTile, 0, 0); |
| 1071 |
tile = scrollPtr->activeTile; |
| 1072 |
} |
| 1073 |
} else { |
| 1074 |
border = scrollPtr->bgBorder; |
| 1075 |
relief = TK_RELIEF_RAISED; |
| 1076 |
if (scrollPtr->tile != NULL) { |
| 1077 |
tile = scrollPtr->tile; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
if (scrollPtr->vertical) { |
| 1081 |
points[0].x = scrollPtr->inset - 1; |
| 1082 |
points[0].y = scrollPtr->arrowLength + scrollPtr->inset - 1; |
| 1083 |
points[1].x = width + scrollPtr->inset; |
| 1084 |
points[1].y = points[0].y; |
| 1085 |
points[2].x = width / 2 + scrollPtr->inset; |
| 1086 |
points[2].y = scrollPtr->inset - 1; |
| 1087 |
} else { |
| 1088 |
points[0].x = scrollPtr->arrowLength + scrollPtr->inset - 1; |
| 1089 |
points[0].y = scrollPtr->inset - 1; |
| 1090 |
points[1].x = scrollPtr->inset; |
| 1091 |
points[1].y = width / 2 + scrollPtr->inset; |
| 1092 |
points[2].x = points[0].x; |
| 1093 |
points[2].y = width + scrollPtr->inset; |
| 1094 |
} |
| 1095 |
if (Blt_HasTile(tile)) { |
| 1096 |
Blt_TilePolygon(tkwin, pixmap, tile, points, 3); |
| 1097 |
Tk_Draw3DPolygon(tkwin, pixmap, border, points, 3, |
| 1098 |
scrollPtr->borderWidth, relief); |
| 1099 |
} else { |
| 1100 |
Tk_Fill3DPolygon(tkwin, pixmap, border, points, 3, |
| 1101 |
scrollPtr->borderWidth, relief); |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
tile = NULL; |
| 1108 |
if (scrollPtr->activeField == BOTTOM_ARROW) { |
| 1109 |
border = scrollPtr->activeBorder; |
| 1110 |
relief = scrollPtr->activeField == BOTTOM_ARROW |
| 1111 |
? scrollPtr->activeRelief : TK_RELIEF_RAISED; |
| 1112 |
if (scrollPtr->activeTile != NULL) { |
| 1113 |
Blt_SetTileOrigin(tkwin, scrollPtr->activeTile, 0, 0); |
| 1114 |
tile = scrollPtr->activeTile; |
| 1115 |
} |
| 1116 |
} else { |
| 1117 |
border = scrollPtr->bgBorder; |
| 1118 |
relief = TK_RELIEF_RAISED; |
| 1119 |
if (scrollPtr->tile != NULL) { |
| 1120 |
tile = scrollPtr->tile; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
if (scrollPtr->vertical) { |
| 1124 |
points[0].x = scrollPtr->inset; |
| 1125 |
points[0].y = Tk_Height(tkwin) - scrollPtr->arrowLength |
| 1126 |
- scrollPtr->inset + 1; |
| 1127 |
points[1].x = width / 2 + scrollPtr->inset; |
| 1128 |
points[1].y = Tk_Height(tkwin) - scrollPtr->inset; |
| 1129 |
points[2].x = width + scrollPtr->inset; |
| 1130 |
points[2].y = points[0].y; |
| 1131 |
} else { |
| 1132 |
points[0].x = Tk_Width(tkwin) - scrollPtr->arrowLength |
| 1133 |
- scrollPtr->inset + 1; |
| 1134 |
points[0].y = scrollPtr->inset - 1; |
| 1135 |
points[1].x = points[0].x; |
| 1136 |
points[1].y = width + scrollPtr->inset; |
| 1137 |
points[2].x = Tk_Width(tkwin) - scrollPtr->inset; |
| 1138 |
points[2].y = width / 2 + scrollPtr->inset; |
| 1139 |
} |
| 1140 |
if (Blt_HasTile(tile)) { |
| 1141 |
Blt_TilePolygon(tkwin, pixmap, tile, points, 3); |
| 1142 |
Tk_Draw3DPolygon(tkwin, pixmap, border, points, 3, |
| 1143 |
scrollPtr->borderWidth, relief); |
| 1144 |
} else { |
| 1145 |
Tk_Fill3DPolygon(tkwin, pixmap, border, points, 3, |
| 1146 |
scrollPtr->borderWidth, relief); |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
if (scrollPtr->activeField == SLIDER) { |
| 1153 |
border = scrollPtr->activeBorder; |
| 1154 |
relief = scrollPtr->activeField == SLIDER ? scrollPtr->activeRelief |
| 1155 |
: TK_RELIEF_RAISED; |
| 1156 |
tile = scrollPtr->activeTile; |
| 1157 |
} else { |
| 1158 |
border = scrollPtr->bgBorder; |
| 1159 |
relief = TK_RELIEF_RAISED; |
| 1160 |
tile = (scrollPtr->tile2 ? scrollPtr->tile2 : scrollPtr->tile); |
| 1161 |
} |
| 1162 |
if (scrollPtr->vertical) { |
| 1163 |
if (Blt_HasTile(tile)) { |
| 1164 |
Blt_TileRectangle(tkwin, pixmap, tile, scrollPtr->inset, |
| 1165 |
scrollPtr->sliderFirst, width - 1, |
| 1166 |
scrollPtr->sliderLast - scrollPtr->sliderFirst - 1); |
| 1167 |
Blt_Draw3DRectangle(tkwin, pixmap, border, |
| 1168 |
scrollPtr->inset, scrollPtr->sliderFirst, |
| 1169 |
width, scrollPtr->sliderLast - scrollPtr->sliderFirst, |
| 1170 |
scrollPtr->borderWidth, relief); |
| 1171 |
} else { |
| 1172 |
Blt_Fill3DRectangle(tkwin, pixmap, border, |
| 1173 |
scrollPtr->inset, scrollPtr->sliderFirst, |
| 1174 |
width, scrollPtr->sliderLast - scrollPtr->sliderFirst, |
| 1175 |
elementBorderWidth, relief); |
| 1176 |
} |
| 1177 |
} else { |
| 1178 |
if (Blt_HasTile(tile)) { |
| 1179 |
Blt_TileRectangle(tkwin, pixmap, tile, scrollPtr->sliderFirst, |
| 1180 |
scrollPtr->inset, |
| 1181 |
scrollPtr->sliderLast - scrollPtr->sliderFirst - 1, width - 1); |
| 1182 |
Blt_Draw3DRectangle(tkwin, pixmap, border, |
| 1183 |
scrollPtr->sliderFirst, scrollPtr->inset, |
| 1184 |
scrollPtr->sliderLast - scrollPtr->sliderFirst, width, |
| 1185 |
scrollPtr->borderWidth, relief); |
| 1186 |
} else { |
| 1187 |
Blt_Fill3DRectangle(tkwin, pixmap, border, |
| 1188 |
scrollPtr->sliderFirst, scrollPtr->inset, |
| 1189 |
scrollPtr->sliderLast - scrollPtr->sliderFirst, width, |
| 1190 |
scrollPtr->borderWidth, relief); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
if (scrollPtr->image != NULL) { |
| 1195 |
|
| 1196 |
int imgW, imgH, xLen, yLen, yStart, xStart, yOfs = 0, xOfs = 0, pad = 1; |
| 1197 |
|
| 1198 |
Tk_SizeOfImage(scrollPtr->image, &imgW, &imgH); |
| 1199 |
|
| 1200 |
if (scrollPtr->vertical) { |
| 1201 |
xLen = width; |
| 1202 |
yLen = scrollPtr->sliderLast - scrollPtr->sliderFirst; |
| 1203 |
} else { |
| 1204 |
yLen = width; |
| 1205 |
xLen = scrollPtr->sliderLast - scrollPtr->sliderFirst; |
| 1206 |
|
| 1207 |
} |
| 1208 |
if (imgW > (xLen-pad*2)) { |
| 1209 |
int oWid = imgW; |
| 1210 |
imgW = (xLen-pad*2); |
| 1211 |
xOfs = (oWid-imgW)/2; |
| 1212 |
} |
| 1213 |
if (imgH > (yLen-pad*2)) { |
| 1214 |
int oWid = imgH; |
| 1215 |
imgH = (yLen-pad*2); |
| 1216 |
yOfs = (oWid-imgH)/2; |
| 1217 |
} |
| 1218 |
xStart = (xLen - imgW)/2+pad; |
| 1219 |
yStart = (yLen - imgH)/2+pad; |
| 1220 |
if (scrollPtr->vertical) { |
| 1221 |
yStart += scrollPtr->sliderFirst; |
| 1222 |
} else { |
| 1223 |
xStart += scrollPtr->sliderFirst; |
| 1224 |
} |
| 1225 |
if (xStart>=0 && yStart>=0 && imgW > 0 && imgH > 0) { |
| 1226 |
Tk_RedrawImage(scrollPtr->image, xOfs, yOfs, imgW, imgH, pixmap, xStart, yStart); |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
XCopyArea(scrollPtr->display, pixmap, Tk_WindowId(tkwin), |
| 1236 |
scrollPtr->copyGC, 0, 0, (unsigned)Tk_Width(tkwin), |
| 1237 |
(unsigned)Tk_Height(tkwin), 0, 0); |
| 1238 |
Tk_FreePixmap(scrollPtr->display, pixmap); |
| 1239 |
|
| 1240 |
done: |
| 1241 |
scrollPtr->flags &= ~REDRAW_PENDING; |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
static void |
| 1263 |
ScrollbarEventProc(clientData, eventPtr) |
| 1264 |
ClientData clientData; |
| 1265 |
XEvent *eventPtr; |
| 1266 |
{ |
| 1267 |
Scrollbar *scrollPtr = clientData; |
| 1268 |
|
| 1269 |
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { |
| 1270 |
EventuallyRedraw(scrollPtr); |
| 1271 |
} else if (eventPtr->type == DestroyNotify) { |
| 1272 |
if (scrollPtr->tkwin != NULL) { |
| 1273 |
scrollPtr->tkwin = NULL; |
| 1274 |
Tcl_DeleteCommandFromToken(scrollPtr->interp,scrollPtr->widgetCmd); |
| 1275 |
} |
| 1276 |
if (scrollPtr->flags & REDRAW_PENDING) { |
| 1277 |
Tcl_CancelIdleCall(DisplayScrollbar, (ClientData)scrollPtr); |
| 1278 |
} |
| 1279 |
Tcl_EventuallyFree((ClientData)scrollPtr, |
| 1280 |
(Tcl_FreeProc *)DestroyScrollbar); |
| 1281 |
} else if (eventPtr->type == ConfigureNotify) { |
| 1282 |
ComputeScrollbarGeometry(scrollPtr); |
| 1283 |
EventuallyRedraw(scrollPtr); |
| 1284 |
} else if (eventPtr->type == FocusIn) { |
| 1285 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 1286 |
scrollPtr->flags |= GOT_FOCUS; |
| 1287 |
if (scrollPtr->highlightWidth > 0) { |
| 1288 |
EventuallyRedraw(scrollPtr); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
} else if (eventPtr->type == FocusOut) { |
| 1292 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 1293 |
scrollPtr->flags &= ~GOT_FOCUS; |
| 1294 |
if (scrollPtr->highlightWidth > 0) { |
| 1295 |
EventuallyRedraw(scrollPtr); |
| 1296 |
} |
| 1297 |
} |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
static void |
| 1320 |
ScrollbarCmdDeletedProc(clientData) |
| 1321 |
ClientData clientData; |
| 1322 |
{ |
| 1323 |
Scrollbar *scrollPtr = clientData; |
| 1324 |
Tk_Window tkwin = scrollPtr->tkwin; |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
if (tkwin != NULL) { |
| 1334 |
#ifdef ITCL_NAMESPACES |
| 1335 |
Itk_SetWidgetCommand(scrollPtr->tkwin, (Tcl_Command) NULL); |
| 1336 |
#endif |
| 1337 |
scrollPtr->tkwin = NULL; |
| 1338 |
Tk_DestroyWindow(tkwin); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
static void |
| 1361 |
ComputeScrollbarGeometry(scrollPtr) |
| 1362 |
register Scrollbar *scrollPtr; |
| 1363 |
|
| 1364 |
{ |
| 1365 |
int width, fieldLength; |
| 1366 |
|
| 1367 |
if (scrollPtr->highlightWidth < 0) { |
| 1368 |
scrollPtr->highlightWidth = 0; |
| 1369 |
} |
| 1370 |
scrollPtr->inset = scrollPtr->highlightWidth + scrollPtr->borderWidth; |
| 1371 |
width = (scrollPtr->vertical) ? Tk_Width(scrollPtr->tkwin) |
| 1372 |
: Tk_Height(scrollPtr->tkwin); |
| 1373 |
scrollPtr->arrowLength = width - 2 * scrollPtr->inset + 1; |
| 1374 |
fieldLength = (scrollPtr->vertical ? Tk_Height(scrollPtr->tkwin) |
| 1375 |
: Tk_Width(scrollPtr->tkwin)) |
| 1376 |
- 2 * (scrollPtr->arrowLength + scrollPtr->inset); |
| 1377 |
if (fieldLength < 0) { |
| 1378 |
fieldLength = 0; |
| 1379 |
} |
| 1380 |
scrollPtr->sliderFirst = fieldLength * scrollPtr->firstFraction; |
| 1381 |
scrollPtr->sliderLast = fieldLength * scrollPtr->lastFraction; |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
if (scrollPtr->sliderFirst > (fieldLength - 2 * scrollPtr->borderWidth)) { |
| 1390 |
scrollPtr->sliderFirst = fieldLength - 2 * scrollPtr->borderWidth; |
| 1391 |
} |
| 1392 |
if (scrollPtr->sliderFirst < 0) { |
| 1393 |
scrollPtr->sliderFirst = 0; |
| 1394 |
} |
| 1395 |
if (scrollPtr->sliderLast < (scrollPtr->sliderFirst + MIN_SLIDER_LENGTH)) { |
| 1396 |
scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH; |
| 1397 |
} |
| 1398 |
if (scrollPtr->sliderLast > fieldLength) { |
| 1399 |
scrollPtr->sliderLast = fieldLength; |
| 1400 |
} |
| 1401 |
scrollPtr->sliderFirst += scrollPtr->arrowLength + scrollPtr->inset; |
| 1402 |
scrollPtr->sliderLast += scrollPtr->arrowLength + scrollPtr->inset; |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
if (scrollPtr->vertical) { |
| 1412 |
Tk_GeometryRequest(scrollPtr->tkwin, |
| 1413 |
scrollPtr->width + 2 * scrollPtr->inset, |
| 1414 |
2 * (scrollPtr->arrowLength + scrollPtr->borderWidth |
| 1415 |
+ scrollPtr->inset)); |
| 1416 |
} else { |
| 1417 |
Tk_GeometryRequest(scrollPtr->tkwin, |
| 1418 |
2 * (scrollPtr->arrowLength + scrollPtr->borderWidth |
| 1419 |
+ scrollPtr->inset), scrollPtr->width + 2 * scrollPtr->inset); |
| 1420 |
} |
| 1421 |
Tk_SetInternalBorder(scrollPtr->tkwin, scrollPtr->inset); |
| 1422 |
} |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
static int |
| 1444 |
ScrollbarPosition(scrollPtr, x, y) |
| 1445 |
register Scrollbar *scrollPtr; |
| 1446 |
int x, y; |
| 1447 |
|
| 1448 |
{ |
| 1449 |
int length, width, tmp; |
| 1450 |
|
| 1451 |
if (scrollPtr->vertical) { |
| 1452 |
length = Tk_Height(scrollPtr->tkwin); |
| 1453 |
width = Tk_Width(scrollPtr->tkwin); |
| 1454 |
} else { |
| 1455 |
tmp = x; |
| 1456 |
x = y; |
| 1457 |
y = tmp; |
| 1458 |
length = Tk_Width(scrollPtr->tkwin); |
| 1459 |
width = Tk_Height(scrollPtr->tkwin); |
| 1460 |
} |
| 1461 |
|
| 1462 |
if ((x < scrollPtr->inset) || (x >= (width - scrollPtr->inset)) |
| 1463 |
|| (y < scrollPtr->inset) || (y >= (length - scrollPtr->inset))) { |
| 1464 |
return OUTSIDE; |
| 1465 |
} |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
if (y < (scrollPtr->inset + scrollPtr->arrowLength)) { |
| 1472 |
return TOP_ARROW; |
| 1473 |
} |
| 1474 |
if (y < scrollPtr->sliderFirst) { |
| 1475 |
return TOP_GAP; |
| 1476 |
} |
| 1477 |
if (y < scrollPtr->sliderLast) { |
| 1478 |
return SLIDER; |
| 1479 |
} |
| 1480 |
if (y >= (length - (scrollPtr->arrowLength + scrollPtr->inset))) { |
| 1481 |
return BOTTOM_ARROW; |
| 1482 |
} |
| 1483 |
return BOTTOM_GAP; |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
static void |
| 1504 |
EventuallyRedraw(scrollPtr) |
| 1505 |
register Scrollbar *scrollPtr; |
| 1506 |
{ |
| 1507 |
if ((scrollPtr->tkwin == NULL) || (!Tk_IsMapped(scrollPtr->tkwin))) { |
| 1508 |
return; |
| 1509 |
} |
| 1510 |
if ((scrollPtr->flags & REDRAW_PENDING) == 0) { |
| 1511 |
Tcl_DoWhenIdle(DisplayScrollbar, (ClientData)scrollPtr); |
| 1512 |
scrollPtr->flags |= REDRAW_PENDING; |
| 1513 |
} |
| 1514 |
} |
| 1515 |
|
| 1516 |
int |
| 1517 |
Blt_ScrollbarInit(interp) |
| 1518 |
Tcl_Interp *interp; |
| 1519 |
{ |
| 1520 |
static Blt_CmdSpec cmdSpecs[2] = |
| 1521 |
{ |
| 1522 |
{ "scrollbar", ScrollbarCmd, }, |
| 1523 |
{ "bscrollbar", BScrollbarCmd, }, |
| 1524 |
}; |
| 1525 |
|
| 1526 |
return Blt_InitCmds(interp, "blt::tile", cmdSpecs, 2); |
| 1527 |
} |
| 1528 |
|
| 1529 |
#endif |