~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to lefty/ws/x11/libfilereq/Draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

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