| 1 |
/* |
| 2 |
* Copyright 1989 Software Research Associates, Inc., Tokyo, Japan |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and distribute this software and its |
| 5 |
* documentation for any purpose and without fee is hereby granted, provided |
| 6 |
* that the above copyright notice appear in all copies and that both that |
| 7 |
* copyright notice and this permission notice appear in supporting |
| 8 |
* documentation, and that the name of Software Research Associates not be used |
| 9 |
* in advertising or publicity pertaining to distribution of the software |
| 10 |
* without specific, written prior permission. Software Research Associates |
| 11 |
* makes no representations about the suitability of this software for any |
| 12 |
* purpose. It is provided "as is" without express or implied warranty. |
| 13 |
* |
| 14 |
* SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
| 15 |
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
| 16 |
* IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL, |
| 17 |
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 18 |
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
| 19 |
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 20 |
* PERFORMANCE OF THIS SOFTWARE. |
| 21 |
* |
| 22 |
* Author: Erik M. van der Poel |
| 23 |
* Software Research Associates, Inc., Tokyo, Japan |
| 24 |
* [email protected] |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "xdvi-config.h" |
| 28 |
|
| 29 |
#include "kpathsea/c-auto.h" |
| 30 |
#include "kpathsea/config.h" |
| 31 |
#include "kpathsea/c-stat.h" |
| 32 |
#include "xdvi.h" |
| 33 |
#include "x_util.h" |
| 34 |
|
| 35 |
#include "sfDraw.h" |
| 36 |
#include "sfDir.h" |
| 37 |
#include "sfPath.h" |
| 38 |
|
| 39 |
#if !defined(MOTIF) /* for xdvik */ |
| 40 |
|
| 41 |
#define SF_DEFAULT_FONT "9x15" |
| 42 |
|
| 43 |
typedef struct { |
| 44 |
char *font; |
| 45 |
} TextData, *textPtr; |
| 46 |
|
| 47 |
int SFcharWidth, SFcharAscent, SFcharHeight; |
| 48 |
|
| 49 |
int SFcurrentInvert[3] = { -1, -1, -1 }; |
| 50 |
|
| 51 |
static GC SFlineGC, SFscrollGC, SFinvertGC, SFtextGC; |
| 52 |
|
| 53 |
static XtResource textResources[] = { |
| 54 |
{XtNfont, XtCFont, XtRString, sizeof(char *), |
| 55 |
XtOffset(textPtr, font), XtRString, SF_DEFAULT_FONT}, |
| 56 |
}; |
| 57 |
|
| 58 |
static XFontStruct *SFfont; |
| 59 |
|
| 60 |
static int SFcurrentListY; |
| 61 |
|
| 62 |
static XtIntervalId SFscrollTimerId; |
| 63 |
|
| 64 |
void |
| 65 |
SFinitFont(void) |
| 66 |
{ |
| 67 |
TextData *data; |
| 68 |
|
| 69 |
data = XtNew(TextData); |
| 70 |
|
| 71 |
XtGetApplicationResources(selFileForm, (XtPointer) data, textResources, |
| 72 |
XtNumber(textResources), (Arg *) NULL, ZERO); |
| 73 |
|
| 74 |
SFfont = XLoadQueryFont(SFdisplay, data->font); |
| 75 |
if (!SFfont) { |
| 76 |
SFfont = XLoadQueryFont(SFdisplay, SF_DEFAULT_FONT); |
| 77 |
if (!SFfont) { |
| 78 |
char sbuf[256]; |
| 79 |
|
| 80 |
(void)sprintf(sbuf, "XsraSelFile: can't get font %s", |
| 81 |
SF_DEFAULT_FONT); |
| 82 |
|
| 83 |
XtAppError(SFapp, sbuf); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
TRACE_GUI((stderr, "FONT: width %d, %d\n", SFfont->max_bounds.width, SFfont->min_bounds.width)); |
| 88 |
SFcharWidth = (SFfont->max_bounds.width + SFfont->min_bounds.width) / 2; |
| 89 |
SFcharAscent = SFfont->max_bounds.ascent; |
| 90 |
SFcharHeight = SFcharAscent + SFfont->max_bounds.descent; |
| 91 |
if (SFcharWidth == 0) { |
| 92 |
/* if min_bounds.width = -max_bounds.width, we probably |
| 93 |
have a scalable TT font; try to determine its actual |
| 94 |
width by measuring the letter `x': |
| 95 |
*/ |
| 96 |
SFcharWidth = XTextWidth(SFfont, "x", 1); |
| 97 |
} |
| 98 |
if (SFcharWidth == 0) { /* last resort */ |
| 99 |
SFcharWidth = SFfont->max_bounds.width / 2; |
| 100 |
} |
| 101 |
TRACE_GUI((stderr, |
| 102 |
"Using font measures: charwidth %d, ascent %d, height %d", |
| 103 |
SFcharWidth, SFcharAscent, SFcharHeight)); |
| 104 |
} |
| 105 |
|
| 106 |
void |
| 107 |
SFcreateGC(void) |
| 108 |
{ |
| 109 |
XGCValues gcValues; |
| 110 |
XRectangle rectangles[1]; |
| 111 |
|
| 112 |
/* XtVaGetValues(selFileLists[0], */ |
| 113 |
/* XtNforeground, &(gcValues.foreground), */ |
| 114 |
/* XtNbackground, &(gcValues.background), */ |
| 115 |
/* NULL); */ |
| 116 |
gcValues.foreground = SFfore; |
| 117 |
|
| 118 |
SFlineGC = XtGetGC(selFileLists[0], (XtGCMask) |
| 119 |
GCForeground | 0, &gcValues); |
| 120 |
|
| 121 |
SFscrollGC = XtGetGC(selFileLists[0], (XtGCMask) |
| 122 |
0, &gcValues); |
| 123 |
|
| 124 |
gcValues.function = GXinvert; |
| 125 |
/* gcValues.plane_mask = (gcValues.foreground ^ gcValues.background); */ |
| 126 |
gcValues.plane_mask = (SFfore ^ SFback); |
| 127 |
|
| 128 |
SFinvertGC = XtGetGC(selFileLists[0], (XtGCMask) |
| 129 |
GCFunction | GCPlaneMask | 0, &gcValues); |
| 130 |
|
| 131 |
gcValues.foreground = SFfore; |
| 132 |
gcValues.background = SFback; |
| 133 |
gcValues.font = SFfont->fid; |
| 134 |
|
| 135 |
SFtextGC = XCreateGC(SFdisplay, XtWindow(selFileLists[0]), (unsigned long) |
| 136 |
GCForeground | GCBackground | GCFont | 0, &gcValues); |
| 137 |
|
| 138 |
rectangles[0].x = SFlineToTextH + SFbesideText; |
| 139 |
rectangles[0].y = 0; |
| 140 |
rectangles[0].width = SFcharsPerEntry * SFcharWidth; |
| 141 |
rectangles[0].height = SFupperY + 1; |
| 142 |
|
| 143 |
XSetClipRectangles(SFdisplay, SFtextGC, 0, 0, rectangles, 1, Unsorted); |
| 144 |
} |
| 145 |
|
| 146 |
void |
| 147 |
SFclearList(int n, int doScroll) |
| 148 |
{ |
| 149 |
SFDir *dir; |
| 150 |
|
| 151 |
SFcurrentInvert[n] = -1; |
| 152 |
|
| 153 |
XClearWindow(SFdisplay, XtWindow(selFileLists[n])); |
| 154 |
|
| 155 |
XDrawSegments(SFdisplay, XtWindow(selFileLists[n]), SFlineGC, SFsegs, 2); |
| 156 |
|
| 157 |
if (doScroll) { |
| 158 |
dir = &(SFdirs[SFdirPtr + n]); |
| 159 |
|
| 160 |
if ((SFdirPtr + n < SFdirEnd) && dir->nEntries && dir->nChars) { |
| 161 |
XawScrollbarSetThumb(selFileVScrolls[n], |
| 162 |
(double)dir->vOrigin / dir->nEntries, |
| 163 |
(double)(dir->nEntries < SFlistSize |
| 164 |
? dir->nEntries |
| 165 |
: SFlistSize) |
| 166 |
/ dir->nEntries); |
| 167 |
|
| 168 |
XawScrollbarSetThumb(selFileHScrolls[n], |
| 169 |
(double)(dir->hOrigin) / dir->nChars, |
| 170 |
(double)(dir->nChars < SFcharsPerEntry |
| 171 |
? dir-> nChars : SFcharsPerEntry) |
| 172 |
/ dir->nChars); |
| 173 |
} |
| 174 |
else { |
| 175 |
XawScrollbarSetThumb(selFileVScrolls[n], 0.0, 1.0); |
| 176 |
XawScrollbarSetThumb(selFileHScrolls[n], 0.0, 1.0); |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
static void |
| 182 |
SFdeleteEntry(SFDir *dir, SFEntry *entry) |
| 183 |
{ |
| 184 |
SFEntry *e; |
| 185 |
SFEntry *end; |
| 186 |
int n; |
| 187 |
int idx; |
| 188 |
|
| 189 |
idx = entry - dir->entries; |
| 190 |
|
| 191 |
if (idx < dir->beginSelection) { |
| 192 |
dir->beginSelection--; |
| 193 |
} |
| 194 |
if (idx <= dir->endSelection) { |
| 195 |
dir->endSelection--; |
| 196 |
} |
| 197 |
if (dir->beginSelection > dir->endSelection) { |
| 198 |
dir->beginSelection = dir->endSelection = -1; |
| 199 |
} |
| 200 |
|
| 201 |
if (idx < dir->vOrigin) { |
| 202 |
dir->vOrigin--; |
| 203 |
} |
| 204 |
|
| 205 |
XtFree(entry->real); |
| 206 |
|
| 207 |
end = &(dir->entries[dir->nEntries - 1]); |
| 208 |
|
| 209 |
for (e = entry; e < end; e++) { |
| 210 |
*e = *(e + 1); |
| 211 |
} |
| 212 |
|
| 213 |
if (!(--dir->nEntries)) { |
| 214 |
return; |
| 215 |
} |
| 216 |
|
| 217 |
n = dir - &(SFdirs[SFdirPtr]); |
| 218 |
if ((n < 0) || (n > 2)) { |
| 219 |
return; |
| 220 |
} |
| 221 |
|
| 222 |
XawScrollbarSetThumb(selFileVScrolls[n], |
| 223 |
(double)(dir->vOrigin) / dir->nEntries, |
| 224 |
(double)(dir->nEntries < SFlistSize |
| 225 |
? dir->nEntries : SFlistSize) |
| 226 |
/ dir->nEntries); |
| 227 |
} |
| 228 |
|
| 229 |
static void |
| 230 |
SFwriteStatChar(char *name, int last, struct stat *statBuf) |
| 231 |
{ |
| 232 |
name[last] = SFstatChar(statBuf); |
| 233 |
} |
| 234 |
|
| 235 |
static int |
| 236 |
SFstatAndCheck(SFDir *dir, SFEntry *entry) |
| 237 |
{ |
| 238 |
struct stat statBuf; |
| 239 |
char save; |
| 240 |
int last; |
| 241 |
|
| 242 |
/* |
| 243 |
* must be restored before returning |
| 244 |
*/ |
| 245 |
save = *(dir->path); |
| 246 |
*(dir->path) = 0; |
| 247 |
|
| 248 |
if (!SFchdir(SFcurrentPath)) { |
| 249 |
last = strlen(entry->real) - 1; |
| 250 |
entry->real[last] = 0; |
| 251 |
entry->statDone = 1; |
| 252 |
if ((!stat(entry->real, &statBuf)) |
| 253 |
#ifdef S_IFLNK |
| 254 |
|| (!lstat(entry->real, &statBuf)) |
| 255 |
#endif /* ndef S_IFLNK */ |
| 256 |
) { |
| 257 |
if (SFfunc) { |
| 258 |
char *shown; |
| 259 |
|
| 260 |
shown = NULL; |
| 261 |
if (SFfunc(entry->real, &shown, &statBuf)) { |
| 262 |
if (shown) { |
| 263 |
int len; |
| 264 |
|
| 265 |
len = strlen(shown); |
| 266 |
entry->shown = XtMalloc((unsigned)(len + 2) |
| 267 |
); |
| 268 |
(void)strcpy(entry->shown, shown); |
| 269 |
SFwriteStatChar(entry->shown, len, &statBuf); |
| 270 |
entry->shown[len + 1] = 0; |
| 271 |
} |
| 272 |
} |
| 273 |
else { |
| 274 |
SFdeleteEntry(dir, entry); |
| 275 |
|
| 276 |
*(dir->path) = save; |
| 277 |
return 1; |
| 278 |
} |
| 279 |
} |
| 280 |
SFwriteStatChar(entry->real, last, &statBuf); |
| 281 |
} |
| 282 |
else { |
| 283 |
entry->real[last] = ' '; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
*(dir->path) = save; |
| 288 |
return 0; |
| 289 |
} |
| 290 |
|
| 291 |
static void |
| 292 |
SFdrawStrings(Window w, SFDir *dir, int from, int to) |
| 293 |
{ |
| 294 |
int i; |
| 295 |
SFEntry *entry; |
| 296 |
int x; |
| 297 |
|
| 298 |
x = SFtextX - dir->hOrigin * SFcharWidth; |
| 299 |
|
| 300 |
if (dir->vOrigin + to >= dir->nEntries) { |
| 301 |
to = dir->nEntries - dir->vOrigin - 1; |
| 302 |
} |
| 303 |
for (i = from; i <= to; i++) { |
| 304 |
entry = &(dir->entries[dir->vOrigin + i]); |
| 305 |
if (!(entry->statDone)) { |
| 306 |
if (SFstatAndCheck(dir, entry)) { |
| 307 |
if (dir->vOrigin + to >= dir->nEntries) { |
| 308 |
to = dir->nEntries - dir->vOrigin - 1; |
| 309 |
} |
| 310 |
i--; |
| 311 |
continue; |
| 312 |
} |
| 313 |
} |
| 314 |
XDrawImageString(SFdisplay, |
| 315 |
w, |
| 316 |
SFtextGC, |
| 317 |
x, |
| 318 |
SFtextYoffset + i * SFentryHeight, |
| 319 |
entry->shown, strlen(entry->shown)); |
| 320 |
if (dir->vOrigin + i == dir->beginSelection) { |
| 321 |
XDrawLine(SFdisplay, |
| 322 |
w, |
| 323 |
SFlineGC, |
| 324 |
SFlineToTextH + 1, |
| 325 |
SFlowerY + i * SFentryHeight, |
| 326 |
SFlineToTextH + SFentryWidth - 2, |
| 327 |
SFlowerY + i * SFentryHeight); |
| 328 |
} |
| 329 |
if ( |
| 330 |
(dir->vOrigin + i >= dir->beginSelection) && |
| 331 |
(dir->vOrigin + i <= dir->endSelection)) { |
| 332 |
SFcompletionSegs[0].y1 = SFcompletionSegs[1].y1 = |
| 333 |
SFlowerY + i * SFentryHeight; |
| 334 |
SFcompletionSegs[0].y2 = SFcompletionSegs[1].y2 = |
| 335 |
SFlowerY + (i + 1) * SFentryHeight - 1; |
| 336 |
XDrawSegments(SFdisplay, w, SFlineGC, SFcompletionSegs, 2); |
| 337 |
} |
| 338 |
if (dir->vOrigin + i == dir->endSelection) { |
| 339 |
XDrawLine(SFdisplay, |
| 340 |
w, |
| 341 |
SFlineGC, |
| 342 |
SFlineToTextH + 1, |
| 343 |
SFlowerY + (i + 1) * SFentryHeight - 1, |
| 344 |
SFlineToTextH + SFentryWidth - 2, |
| 345 |
SFlowerY + (i + 1) * SFentryHeight - 1); |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
void |
| 351 |
SFdrawList(int n, int doScroll) |
| 352 |
{ |
| 353 |
SFDir *dir; |
| 354 |
Window w; |
| 355 |
|
| 356 |
SFclearList(n, doScroll); |
| 357 |
|
| 358 |
if (SFdirPtr + n < SFdirEnd) { |
| 359 |
dir = &(SFdirs[SFdirPtr + n]); |
| 360 |
w = XtWindow(selFileLists[n]); |
| 361 |
XDrawImageString(SFdisplay, |
| 362 |
w, |
| 363 |
SFtextGC, |
| 364 |
SFtextX - dir->hOrigin * SFcharWidth, |
| 365 |
SFlineToTextV + SFaboveAndBelowText + SFcharAscent, |
| 366 |
dir->dir, strlen(dir->dir) |
| 367 |
); |
| 368 |
SFdrawStrings(w, dir, 0, SFlistSize - 1); |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
void |
| 373 |
SFdrawLists(int doScroll) |
| 374 |
{ |
| 375 |
int i; |
| 376 |
|
| 377 |
for (i = 0; i < 3; i++) { |
| 378 |
SFdrawList(i, doScroll); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
static void |
| 383 |
SFinvertEntry(int n) |
| 384 |
{ |
| 385 |
XFillRectangle(SFdisplay, |
| 386 |
XtWindow(selFileLists[n]), |
| 387 |
SFinvertGC, |
| 388 |
SFlineToTextH, |
| 389 |
SFcurrentInvert[n] * SFentryHeight + SFlowerY, |
| 390 |
SFentryWidth, SFentryHeight); |
| 391 |
} |
| 392 |
|
| 393 |
static unsigned long |
| 394 |
SFscrollTimerInterval(void) |
| 395 |
{ |
| 396 |
static int maxVal = 200; |
| 397 |
static int varyDist = 50; |
| 398 |
static int minDist = 50; |
| 399 |
int t; |
| 400 |
int dist; |
| 401 |
|
| 402 |
if (SFcurrentListY < SFlowerY) { |
| 403 |
dist = SFlowerY - SFcurrentListY; |
| 404 |
} |
| 405 |
else if (SFcurrentListY > SFupperY) { |
| 406 |
dist = SFcurrentListY - SFupperY; |
| 407 |
} |
| 408 |
else { |
| 409 |
return (unsigned long)1; |
| 410 |
} |
| 411 |
|
| 412 |
t = maxVal - ((maxVal / varyDist) * (dist - minDist)); |
| 413 |
|
| 414 |
if (t < 1) { |
| 415 |
t = 1; |
| 416 |
} |
| 417 |
|
| 418 |
if (t > maxVal) { |
| 419 |
t = maxVal; |
| 420 |
} |
| 421 |
|
| 422 |
return (unsigned long)t; |
| 423 |
} |
| 424 |
|
| 425 |
static void |
| 426 |
SFscrollTimer(XtPointer p, XtIntervalId *id) |
| 427 |
{ |
| 428 |
SFDir *dir; |
| 429 |
int save; |
| 430 |
ptrdiff_t n; |
| 431 |
|
| 432 |
UNUSED(id); |
| 433 |
|
| 434 |
n = (ptrdiff_t)p; |
| 435 |
|
| 436 |
fprintf(stderr, "SFscrollTimer called!\n"); |
| 437 |
|
| 438 |
dir = &(SFdirs[SFdirPtr + n]); |
| 439 |
save = dir->vOrigin; |
| 440 |
|
| 441 |
if (SFcurrentListY < SFlowerY) { |
| 442 |
if (dir->vOrigin > 0) { |
| 443 |
SFvSliderMovedCallback(selFileVScrolls[n], n, dir->vOrigin - 1); |
| 444 |
} |
| 445 |
} |
| 446 |
else if (SFcurrentListY > SFupperY) { |
| 447 |
if (dir->vOrigin < dir->nEntries - SFlistSize) { |
| 448 |
SFvSliderMovedCallback(selFileVScrolls[n], n, dir->vOrigin + 1); |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
if (dir->vOrigin != save) { |
| 453 |
if (dir->nEntries) { |
| 454 |
XawScrollbarSetThumb(selFileVScrolls[n], |
| 455 |
(double)(dir->vOrigin) / dir->nEntries, |
| 456 |
(double)(dir->nEntries < SFlistSize |
| 457 |
? dir-> nEntries : SFlistSize) |
| 458 |
/ dir->nEntries); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
if (SFbuttonPressed) { |
| 463 |
SFscrollTimerId = XtAppAddTimeOut(SFapp, |
| 464 |
SFscrollTimerInterval(), |
| 465 |
SFscrollTimer, (XtPointer)n); |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
static int |
| 470 |
SFnewInvertEntry(int n, XMotionEvent *event) |
| 471 |
{ |
| 472 |
int x, y; |
| 473 |
int new; |
| 474 |
static int SFscrollTimerAdded = 0; |
| 475 |
|
| 476 |
x = event->x; |
| 477 |
y = event->y; |
| 478 |
|
| 479 |
if (SFdirPtr + n >= SFdirEnd) { |
| 480 |
return -1; |
| 481 |
} |
| 482 |
else if ((x >= 0) && (x <= SFupperX) && (y >= SFlowerY) && (y <= SFupperY) |
| 483 |
) { |
| 484 |
SFDir *dir = &(SFdirs[SFdirPtr + n]); |
| 485 |
|
| 486 |
if (SFscrollTimerAdded) { |
| 487 |
SFscrollTimerAdded = 0; |
| 488 |
XtRemoveTimeOut(SFscrollTimerId); |
| 489 |
} |
| 490 |
|
| 491 |
new = (y - SFlowerY) / SFentryHeight; |
| 492 |
if (dir->vOrigin + new >= dir->nEntries) { |
| 493 |
return -1; |
| 494 |
} |
| 495 |
return new; |
| 496 |
} |
| 497 |
else { |
| 498 |
if (SFbuttonPressed) { |
| 499 |
SFcurrentListY = y; |
| 500 |
if (!SFscrollTimerAdded) { |
| 501 |
SFscrollTimerAdded = 1; |
| 502 |
SFscrollTimerId = XtAppAddTimeOut(SFapp, |
| 503 |
SFscrollTimerInterval(), |
| 504 |
SFscrollTimer, cast_int_to_XtPointer(n)); |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
return -1; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
void |
| 513 |
SFenterList(Widget w, int n, XEnterWindowEvent *event) |
| 514 |
{ |
| 515 |
int new; |
| 516 |
|
| 517 |
UNUSED(w); |
| 518 |
|
| 519 |
/* sanity */ |
| 520 |
if (SFcurrentInvert[n] != -1) { |
| 521 |
SFinvertEntry(n); |
| 522 |
SFcurrentInvert[n] = -1; |
| 523 |
} |
| 524 |
|
| 525 |
new = SFnewInvertEntry(n, (XMotionEvent *) event); |
| 526 |
if (new != -1) { |
| 527 |
SFcurrentInvert[n] = new; |
| 528 |
SFinvertEntry(n); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
void |
| 533 |
SFleaveList(Widget w, int n, XEvent *event) |
| 534 |
{ |
| 535 |
UNUSED(w); |
| 536 |
UNUSED(event); |
| 537 |
|
| 538 |
if (SFcurrentInvert[n] != -1) { |
| 539 |
SFinvertEntry(n); |
| 540 |
SFcurrentInvert[n] = -1; |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
void |
| 545 |
SFmotionList(Widget w, int n, XMotionEvent *event) |
| 546 |
{ |
| 547 |
int new; |
| 548 |
|
| 549 |
UNUSED(w); |
| 550 |
|
| 551 |
new = SFnewInvertEntry(n, event); |
| 552 |
|
| 553 |
if (new != SFcurrentInvert[n]) { |
| 554 |
if (SFcurrentInvert[n] != -1) { |
| 555 |
SFinvertEntry(n); |
| 556 |
} |
| 557 |
SFcurrentInvert[n] = new; |
| 558 |
if (new != -1) { |
| 559 |
SFinvertEntry(n); |
| 560 |
} |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
void |
| 565 |
SFvFloatSliderMovedCallback(Widget w, int n, float *fnew) |
| 566 |
{ |
| 567 |
int new; |
| 568 |
|
| 569 |
new = (*fnew) * SFdirs[SFdirPtr + n].nEntries; |
| 570 |
|
| 571 |
SFvSliderMovedCallback(w, n, new); |
| 572 |
} |
| 573 |
|
| 574 |
void |
| 575 |
SFvSliderMovedCallback(Widget w, int n, int new) |
| 576 |
{ |
| 577 |
int old; |
| 578 |
Window win; |
| 579 |
SFDir *dir; |
| 580 |
|
| 581 |
UNUSED(w); |
| 582 |
|
| 583 |
dir = &(SFdirs[SFdirPtr + n]); |
| 584 |
|
| 585 |
old = dir->vOrigin; |
| 586 |
dir->vOrigin = new; |
| 587 |
|
| 588 |
if (old == new) { |
| 589 |
return; |
| 590 |
} |
| 591 |
|
| 592 |
win = XtWindow(selFileLists[n]); |
| 593 |
|
| 594 |
if (ABS(new - old) < SFlistSize) { |
| 595 |
if (new > old) { |
| 596 |
XCopyArea(SFdisplay, |
| 597 |
win, |
| 598 |
win, |
| 599 |
SFscrollGC, |
| 600 |
SFlineToTextH, |
| 601 |
SFlowerY + (new - old) * SFentryHeight, |
| 602 |
SFentryWidth + SFlineToTextH, |
| 603 |
(SFlistSize - (new - old)) * SFentryHeight, |
| 604 |
SFlineToTextH, SFlowerY); |
| 605 |
XClearArea(SFdisplay, |
| 606 |
win, |
| 607 |
SFlineToTextH, |
| 608 |
SFlowerY + (SFlistSize - (new - old)) * |
| 609 |
SFentryHeight, |
| 610 |
SFentryWidth + SFlineToTextH, |
| 611 |
(new - old) * SFentryHeight, False); |
| 612 |
SFdrawStrings(win, dir, SFlistSize - (new - old), SFlistSize - 1); |
| 613 |
} |
| 614 |
else { |
| 615 |
XCopyArea(SFdisplay, |
| 616 |
win, |
| 617 |
win, |
| 618 |
SFscrollGC, |
| 619 |
SFlineToTextH, |
| 620 |
SFlowerY, |
| 621 |
SFentryWidth + SFlineToTextH, |
| 622 |
(SFlistSize - (old - new)) * SFentryHeight, |
| 623 |
SFlineToTextH, SFlowerY + (old - new) * SFentryHeight); |
| 624 |
XClearArea(SFdisplay, |
| 625 |
win, |
| 626 |
SFlineToTextH, |
| 627 |
SFlowerY, |
| 628 |
SFentryWidth + SFlineToTextH, |
| 629 |
(old - new) * SFentryHeight, False); |
| 630 |
SFdrawStrings(win, dir, 0, old - new); |
| 631 |
} |
| 632 |
} |
| 633 |
else { |
| 634 |
XClearArea(SFdisplay, |
| 635 |
win, |
| 636 |
SFlineToTextH, |
| 637 |
SFlowerY, |
| 638 |
SFentryWidth + SFlineToTextH, |
| 639 |
SFlistSize * SFentryHeight, False); |
| 640 |
SFdrawStrings(win, dir, 0, SFlistSize - 1); |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
void |
| 645 |
SFvAreaSelectedCallback(Widget w, int n, int pnew) |
| 646 |
{ |
| 647 |
SFDir *dir; |
| 648 |
int new; |
| 649 |
|
| 650 |
dir = &(SFdirs[SFdirPtr + n]); |
| 651 |
|
| 652 |
new = dir->vOrigin + ((double)pnew / SFvScrollHeight) * dir->nEntries; |
| 653 |
|
| 654 |
if (new > dir->nEntries - SFlistSize) { |
| 655 |
new = dir->nEntries - SFlistSize; |
| 656 |
} |
| 657 |
|
| 658 |
if (new < 0) { |
| 659 |
new = 0; |
| 660 |
} |
| 661 |
|
| 662 |
if (dir->nEntries) { |
| 663 |
float f; |
| 664 |
|
| 665 |
f = ((double)new) / dir->nEntries; |
| 666 |
|
| 667 |
XawScrollbarSetThumb(w, f, |
| 668 |
(double)(dir->nEntries < SFlistSize |
| 669 |
? dir->nEntries |
| 670 |
: SFlistSize) |
| 671 |
/ dir->nEntries); |
| 672 |
} |
| 673 |
|
| 674 |
SFvSliderMovedCallback(w, n, new); |
| 675 |
} |
| 676 |
|
| 677 |
void |
| 678 |
SFhSliderMovedCallback(Widget w, int n, float *new) |
| 679 |
{ |
| 680 |
SFDir *dir; |
| 681 |
int save; |
| 682 |
|
| 683 |
UNUSED(w); |
| 684 |
|
| 685 |
dir = &(SFdirs[SFdirPtr + n]); |
| 686 |
save = dir->hOrigin; |
| 687 |
dir->hOrigin = (*new) * dir->nChars; |
| 688 |
if (dir->hOrigin == save) { |
| 689 |
return; |
| 690 |
} |
| 691 |
|
| 692 |
SFdrawList(n, SF_DO_NOT_SCROLL); |
| 693 |
} |
| 694 |
|
| 695 |
void |
| 696 |
SFhAreaSelectedCallback(Widget w, int n, int pnew) |
| 697 |
{ |
| 698 |
SFDir *dir; |
| 699 |
int new; |
| 700 |
|
| 701 |
dir = &(SFdirs[SFdirPtr + n]); |
| 702 |
|
| 703 |
new = dir->hOrigin + (((double)pnew) / SFhScrollWidth) * dir->nChars; |
| 704 |
|
| 705 |
if (new > dir->nChars - SFcharsPerEntry) { |
| 706 |
new = dir->nChars - SFcharsPerEntry; |
| 707 |
} |
| 708 |
|
| 709 |
if (new < 0) { |
| 710 |
new = 0; |
| 711 |
} |
| 712 |
|
| 713 |
if (dir->nChars) { |
| 714 |
float f; |
| 715 |
|
| 716 |
f = (double)new / dir->nChars; |
| 717 |
|
| 718 |
XawScrollbarSetThumb(w, f, |
| 719 |
(double)(dir->nChars < SFcharsPerEntry |
| 720 |
? dir->nChars |
| 721 |
: SFcharsPerEntry) |
| 722 |
/ dir->nChars); |
| 723 |
|
| 724 |
SFhSliderMovedCallback(w, n, &f); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
void |
| 729 |
SFpathSliderMovedCallback(Widget w, XtPointer client_data, float *new) |
| 730 |
{ |
| 731 |
SFDir *dir; |
| 732 |
int n; |
| 733 |
XawTextPosition pos; |
| 734 |
int SFdirPtrSave; |
| 735 |
|
| 736 |
UNUSED(w); |
| 737 |
UNUSED(client_data); |
| 738 |
|
| 739 |
SFdirPtrSave = SFdirPtr; |
| 740 |
SFdirPtr = (*new) * SFdirEnd; |
| 741 |
if (SFdirPtr == SFdirPtrSave) { |
| 742 |
return; |
| 743 |
} |
| 744 |
|
| 745 |
SFdrawLists(SF_DO_SCROLL); |
| 746 |
|
| 747 |
n = 2; |
| 748 |
while (SFdirPtr + n >= SFdirEnd) { |
| 749 |
n--; |
| 750 |
} |
| 751 |
|
| 752 |
dir = &(SFdirs[SFdirPtr + n]); |
| 753 |
|
| 754 |
pos = dir->path - SFcurrentPath; |
| 755 |
|
| 756 |
if (!strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) { |
| 757 |
pos -= strlen(SFstartDir); |
| 758 |
if (pos < 0) { |
| 759 |
pos = 0; |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
XawTextSetInsertionPoint(selFileField, pos); |
| 764 |
} |
| 765 |
|
| 766 |
void |
| 767 |
SFpathAreaSelectedCallback(Widget w, XtPointer client_data, int pnew) |
| 768 |
{ |
| 769 |
int new; |
| 770 |
float f; |
| 771 |
|
| 772 |
UNUSED(client_data); |
| 773 |
|
| 774 |
new = SFdirPtr + (((double)pnew) / SFpathScrollWidth) * SFdirEnd; |
| 775 |
|
| 776 |
if (new > SFdirEnd - 3) { |
| 777 |
new = SFdirEnd - 3; |
| 778 |
} |
| 779 |
|
| 780 |
if (new < 0) { |
| 781 |
new = 0; |
| 782 |
} |
| 783 |
|
| 784 |
f = ((double)new) / SFdirEnd; |
| 785 |
|
| 786 |
XawScrollbarSetThumb(w, f, |
| 787 |
(double)(SFdirEnd < 3 ? SFdirEnd : 3) / SFdirEnd); |
| 788 |
|
| 789 |
SFpathSliderMovedCallback(w, (XtPointer) NULL, &f); |
| 790 |
} |
| 791 |
|
| 792 |
Boolean |
| 793 |
SFworkProc(void) |
| 794 |
{ |
| 795 |
SFDir *dir; |
| 796 |
SFEntry *entry; |
| 797 |
|
| 798 |
for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--) { |
| 799 |
if (!(dir->nEntries)) { |
| 800 |
continue; |
| 801 |
} |
| 802 |
for (entry = &(dir->entries[dir->nEntries - 1]); |
| 803 |
entry >= dir->entries; entry--) { |
| 804 |
if (!(entry->statDone)) { |
| 805 |
(void)SFstatAndCheck(dir, entry); |
| 806 |
return False; |
| 807 |
} |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
SFworkProcAdded = 0; |
| 812 |
|
| 813 |
return True; |
| 814 |
} |
| 815 |
|
| 816 |
#else |
| 817 |
/* silence `empty compilation unit' warnings */ |
| 818 |
static void bar(void); static void foo(void) { bar(); } static void bar(void) { foo(); } |
| 819 |
#endif /* !defined(MOTIF) */ |