aboutsummaryrefslogtreecommitdiff
path: root/FNREQ.C
blob: c99bcc50f941aef0c0250b94bcc8d22100125d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/** fnreq.c ******************************************************************/
/*                                                                           */
/* A file name requester                                                     */
/*                                                                           */
/* Date      Who Changes                                                     */
/* --------- --- ----------------------------------------------------------- */
/* 28-Aug-85 mrp created from imagedit's dos requester                       */
/* 15-Sep-85 DDS modified to do own event processing, take x,y coord.        */
/*                                                                           */
/*****************************************************************************/
/*  1) define a file and a drawer                                            */
/*                                                                           */
/*     UBYTE mydrawer[31] = {""};                                            */
/*     UBYTE myfile[31] = {"test.vcs"};                                      */
/*                                                                           */
/*  2) Issue a request, when the user picks your Load menu item              */
/*                                                                           */
/*  res  = FN_Request(mywindow,x,y,mydrawer,myfile,NULL,NULL,NULL,"Load");   */
/*      where res = TRUE if user did action, FALSE if he cancelled           */
/*                                                                           */
/*****************************************************************************/

#include <system.h>
#include <librarie\dos.h>
#include <fnreq.h>
#include <clib\ctype.h>

#define local

#define YES 1
#define NO 0

#define MAX(a,b)   	((a)>(b)?(a):(b))
#define MIN(a,b)   	((a)<(b)?(a):(b))

#define FN_GADGMIN 10  /* minimum gadget number used by this requester */
#define FN_GADGMAX 29  /* maximum gadget number used by this requester */

#define FN_CANCEL  10  /* user canceled the requester */
#define FN_GOTNAME 11  /* user pressed return on name or picked OK gadget */
#define FN_FILE    12  /* user selected filename gadget */
#define FN_DRAWER  13  /* user selected drawer name gadget */
#define FN_UP      14  /* user selected up one name gadget */
#define FN_DOWN    15  /* user selected down one name gadget */
#define FN_SLIDE   16  /* user did something to proportional gadget */

#define HIWIDTH 320
#define LOWIDTH 264
#define REQW  LOWIDTH                 /* width of requester */ 
#define REQH  147                      /* height of requester */

#define MAXFNAMES 50 	/* max number of file names in a dir */
#define MAXSHOW 8 	/* max number of file names visible in req*/

local struct Window *reqwindow;       /* window requester is in */
local struct Requester fn_req = {0};        /* the requester */
local LONG forbug = 0;		/* fix 1.06 Intuition bug */
local struct IntuiText fn_text[3];    /* requester text */
local struct IntuiText gadg_text[2];  /* gadget text */

local UBYTE deftitle[] = "FR";
local UBYTE defcancel[] = "Cancel";
local UBYTE defdoverb[] = "Ok";

local LONG firstname=0;                 /* index of first name in the list */

BOOL fndbg = NO;
                                                        
struct TextAttr reqfont = {            /* font to use for requester text */
   "topaz.font",
   TOPAZ_SIXTY,                        /* will be set to user's preference */
   0,
   0};

local UBYTE undofile[26];
local UBYTE undodrawer[26];

local SHORT reqX = 0;                      /* leftedge of requester */
local SHORT reqY = 0;                      /* topedge of requester */
local SHORT reqWidth = LOWIDTH;

local BOOL dosready = FALSE;          /* TRUE after requester is initialized */

local UWORD reqpts[] = {              /* xy table of border and reqion lines */
   2,1,
   2,REQH-2,
   REQW-3,REQH-2,
   REQW-3,12,
   2,12,
   2,1,
   REQW-3,1,
   REQW-3,93,
    2,93
    };
        
local struct Border reqborder = {     /* border for the requester */
   0,0,
   0,1,
   JAM1,
   9,
   (SHORT *)&reqpts,
   NULL};

/*=======================*/
/*== CANCEL GADGET ======*/
/*=======================*/

local UWORD dt0box1[] = {0,0,0,0,0,0,0,0,0,0};
local UWORD dt0box2[] = {1,2,0,2,0,0,1,0,1,2};
   
local struct Border dt0bor2 = {    /* Blue box */
   0,0,
   0,1,
   JAM1,
   5,
   (SHORT *)&dt0box2,
   NULL};
local struct Border dt0bor1 = {    /* Orange box */
   0,0,
   3,0,
   JAM1,
   5,
   (SHORT *)&dt0box1,
   &dt0bor2};

local struct Gadget cancelgadget = {
   NULL,          
   -58,-20,
   48,17,         
   GADGHCOMP | GRELBOTTOM | GRELRIGHT,     
   RELVERIFY | GADGIMMEDIATE | ENDGADGET, 
   REQGADGET | BOOLGADGET, 
   (APTR)&dt0bor1,         
   NULL,         
   &gadg_text[0],
   0,            
   NULL,         
   FN_CANCEL,    
   NULL };       

/*=========================*/
/*== GOTNAME, GADGET ======*/
/*=========================*/

local UWORD dt1box1[] = {0,0,0,0,0,0,0,0,0,0};
local UWORD dt1box2[] = {1,2,0,2,0,0,1,0,1,2};
   
local struct Border dt1bor2 = {     /* Blue box */
   0,0,
   0,1,
   JAM1,
   5,
   (SHORT *)&dt1box2,
   NULL};
local struct Border dt1bor1 = {     /* Orange box */
   0,0,
   3,0,
   JAM1,
   5,
   (SHORT *)&dt1box1,
   &dt1bor2};

local struct Gadget gotnamegadget = {
   &cancelgadget,
   10,-20,
   64,17,          
   GADGHCOMP | GRELBOTTOM,        
   RELVERIFY | GADGIMMEDIATE | ENDGADGET, 
   REQGADGET | BOOLGADGET, 
   (APTR)&dt1bor1,         
   NULL,          
   &gadg_text[1], 
   0,          
   NULL,       
   FN_GOTNAME, 
   NULL };


/*======================*/
/*== FILE, GADGET ======*/
/*======================*/

#define FG_WIDTH 184
#define FG_HEIGHT 13       


local UWORD dt2box1[] = {
   -2,-2,
   FG_WIDTH+1,-2,
   FG_WIDTH+1,FG_HEIGHT-3,
   -2,FG_HEIGHT-3,
   -2,-2};

local struct Border dt2bor1 = {
   0,0,
   0,1,
   JAM1,
   5,
   (SHORT *)&dt2box1,
   NULL};

local struct StringInfo filestr = {
   NULL,          /* default and final string */
   &undofile[0],  /* optional undo buffer (later) */
   0,             /* character position in buffer */
   25,            /* max characters in buffer */
   0,             /* buffer position of first displayed character */
   0,0,0,0,0,NULL,0,NULL };     /* intuition local variables */

local struct Gadget filegadget = {
   &gotnamegadget,
   -FG_WIDTH-12,-33,
   FG_WIDTH,FG_HEIGHT,
   GADGHCOMP | GRELBOTTOM | GRELRIGHT,
   RELVERIFY | GADGIMMEDIATE /* | ENDGADGET */ , 
   REQGADGET | STRGADGET,
   (APTR) &dt2bor1,      
   NULL,                 
   NULL,                 
   0,                    
   (APTR)&filestr,    
   FN_FILE,           
   NULL };            

/*========================*/
/*== DRAWER, GADGET ======*/
/*========================*/

#define DG_WIDTH 184
#define DG_HEIGHT 13       


local UWORD dt3box1[] = {
   -2,-2,
   DG_WIDTH+1,-2,
   DG_WIDTH+1,DG_HEIGHT-3,
   -2,DG_HEIGHT-3,
   -2,-2};

local struct Border dt3bor1 = {
   0,0,
   0,1,
   JAM1,
   5,
   (SHORT *)&dt3box1,
   NULL};

local struct StringInfo drawerstr = {
   NULL,          
   &undodrawer[0],
   0,             
   25,            
   0,             
   0,0,0,0,0,NULL,0,NULL };

local struct Gadget drawergadget = {
   &filegadget,         
   -DG_WIDTH-12,-48,
   DG_WIDTH,DG_HEIGHT,  
   GADGHCOMP | GRELBOTTOM | GRELRIGHT,
   RELVERIFY | GADGIMMEDIATE, 
   REQGADGET | STRGADGET,
   (APTR) &dt3bor1,      
   NULL,                 
   NULL,                 
   0,                    
   (APTR)&drawerstr,     
   FN_DRAWER,            
   NULL };               


/*========================*/
/*== SLIDER, GADGET ======*/
/*========================*/

local struct Image slideknob = {
   0,0,
   0,
   0,0,
   0,
   0,
   0,
   NULL};

local struct PropInfo slideprop =
   {
   AUTOKNOB | FREEVERT,
   0,0,
   0xffff,0x5555,
   12,52,
   0,0,
   2,0
   };
         
struct Gadget slidegadget =
   {
   &drawergadget,
   -19,27,
   20,52,
   GRELRIGHT | GADGIMAGE | GADGHCOMP | GADGHBOX,
   RELVERIFY | GADGIMMEDIATE,
   PROPGADGET| REQGADGET,
   (APTR) &slideknob,
   NULL,
   NULL,
   NULL,
   (APTR) &slideprop,
   FN_SLIDE,
   NULL
   };

/*====================*/
/*== UP, GADGET ======*/
/*====================*/
extern SHORT up0[];

local struct Image uparrow = {
   0,0,
   16,
   16,1,
   (USHORT *)&up0,
   0x01,
   0x00,
   NULL};

local struct Gadget upgadget = {
   &slidegadget,
   -17,12,
   16,16,          
   GADGHCOMP | GRELRIGHT | GADGIMAGE, 
   RELVERIFY | GADGIMMEDIATE, 
   REQGADGET | BOOLGADGET, 
   (APTR)&uparrow,         
   NULL,          
   NULL,      
   0,         
   NULL,      
   FN_UP,     
   NULL };

/*======================*/
/*== DOWN, GADGET ======*/
/*======================*/
extern SHORT down0[];

local struct Image downarrow = {
   0,0,
   16,
   16,1,
   (USHORT *)&down0,
   0x01,
   0x00,
   NULL};

local struct Gadget downgadget = {
   &upgadget,
   -17,78,
   16,16,          
   GADGHCOMP | GRELRIGHT | GADGIMAGE,
   RELVERIFY | GADGIMMEDIATE, 
   REQGADGET | BOOLGADGET, 
   (APTR)&downarrow,          
   NULL,     
   NULL,     
   0,        
   NULL,     
   FN_DOWN,  
   NULL };

              
/*========================*/
/*== NAMES, GADGETS ======*/
/*========================*/

SHORT NFNames = 0; 	/* The number of file names in currren dir */
UBYTE *names[MAXFNAMES] = {NULL};
UBYTE namedir[MAXFNAMES];

local struct IntuiText nametext[MAXSHOW];

#define MAXCHARS 30
typedef UBYTE NameStr[MAXCHARS];
NameStr  *showNames;

local struct Gadget namegadget[MAXSHOW] = {0};

AllocShowNames() {
    showNames = (NameStr *)DAlloc(MAXSHOW*sizeof(NameStr), MEMF_PUBLIC);
    }
    
FreeShowNames() {  DFree(showNames);  }
    
FN_InitReq()
   {
   LONG n;
   InitRequester(&fn_req);
   fn_req.LeftEdge = reqX;
   fn_req.TopEdge = reqY;
   fn_req.Width = reqWidth;
   fn_req.Height = REQH;
   fn_req.ReqGadget = &namegadget[MAXSHOW-1];
   fn_req.ReqBorder = &reqborder;
   fn_req.ReqText = &fn_text[2];   
   fn_req.BackFill = 1;

   fn_text[0].FrontPen = 3;
   fn_text[0].BackPen = 1;
   fn_text[0].DrawMode = JAM2;
   fn_text[0].ITextFont = &reqfont;
   fn_text[0].NextText = NULL;
   fn_text[0].IText = NULL;
   fn_text[0].LeftEdge = 0;
   fn_text[0].TopEdge = 3;

   fn_text[1].FrontPen = 0;
   fn_text[1].BackPen = 1;
   fn_text[1].DrawMode = JAM2;
   fn_text[1].ITextFont = &reqfont;
   fn_text[1].NextText = &fn_text[0];
   fn_text[1].LeftEdge = 5;
   fn_text[1].TopEdge = REQH-49;
   fn_text[1].IText = (UBYTE *)"Drawer:";

   fn_text[2].FrontPen = 0;
   fn_text[2].BackPen = 1;
   fn_text[2].DrawMode = JAM2;
   fn_text[2].ITextFont = &reqfont;
   fn_text[2].NextText = &fn_text[1];
   fn_text[2].LeftEdge = 21;
   fn_text[2].TopEdge = REQH-34;
   fn_text[2].IText = (UBYTE *)"File:";
   
   for(n=0;n<MAXSHOW;n++)     {
	nametext[n].FrontPen = 0;
	nametext[n].BackPen = 1;
	nametext[n].DrawMode = JAM2;
	nametext[n].ITextFont = &reqfont;
	nametext[n].NextText = NULL;
	nametext[n].LeftEdge = 2;
	nametext[n].TopEdge = 1;   
	}
    reqpts[4] = reqpts[6] = reqpts[12] = reqpts[14] = reqWidth-3;
    }

/*****************************************************************************/
/* FN_FixBox                                                                 */
/*                                                                           */
/* Adjust a box's corners to a specified width and height                    */
/*                                                                           */
/*****************************************************************************/

VOID FN_FixBox(box1,box2,width,height)
UWORD box1[],box2[];
UWORD width,height;
   {
   box1[2] = width-1;
   box1[4] = width-1;
   box1[5] = height-1;
   box1[7] = height-1;
   box2[2] = width-2;
   box2[4] = width-2;
   box2[5] = height-3;
   box2[7] = height-3;
   }               
                                                         
/*****************************************************************************/
/* FN_InitText                                                               */
/*                                                                           */
/* Initialize text used in this requester                                    */
/*                                                                           */
/*****************************************************************************/
VOID FN_InitText()
   {
   SHORT n;
   for(n=0; n<2; n++)
      {
      gadg_text[n].FrontPen = 0;
      gadg_text[n].BackPen = 1;
      gadg_text[n].DrawMode = JAM2;
      gadg_text[n].ITextFont = &reqfont;
      gadg_text[n].NextText = NULL;
      gadg_text[n].LeftEdge = 4;
      gadg_text[n].TopEdge = 4;
      }
   gadg_text[0].IText = NULL;
   gadg_text[1].IText = NULL;   

   for(n=0;n<MAXSHOW;n++)
      {
      if (n==0) namegadget[n].NextGadget = &downgadget;
      else namegadget[n].NextGadget = &namegadget[n-1];
      namegadget[n].LeftEdge = 3;
      namegadget[n].TopEdge = 13+(n*10);
      namegadget[n].Width = REQW-22;
      namegadget[n].Height = 9;
      namegadget[n].Flags = GADGHCOMP;
      namegadget[n].Activation = RELVERIFY | GADGIMMEDIATE;
      namegadget[n].GadgetType = REQGADGET | BOOLGADGET;
      namegadget[n].GadgetID = FN_SLIDE + 1 + n;
      namegadget[n].GadgetText = &nametext[n];
      }
   }               

UBYTE emptyName[] = "";
int nrange = 0;
#define MAXCHWIDE 20
StuffReqNames() {
    int i,n,j;
    int newpot,newbody;
    if (firstname<0) firstname = 0;
    if (NFNames<=MAXSHOW) firstname = 0;
    else if (firstname > (NFNames-MAXSHOW)) firstname = NFNames-MAXSHOW;
    n = firstname;
    for (i=0; i<MAXSHOW; i++)  {
	if (n<NFNames)  strncpy(showNames[i],names[n],MAXCHARS);
	else showNames[i][0] = 0;
	nametext[i].IText = showNames[i];
	for (j = strlen(showNames[i]); j<MAXCHARS-1; j++)
		showNames[i][j] = ' ';
	showNames[i][MAXCHARS-1] = 0;
	n++;
	}
    nrange = NFNames - MAXSHOW + 1;
    if (nrange<=0)   {  newpot = 0x0;  newbody = 0xffff;   }
    else  {
	newpot = (firstname<<16)/nrange;
	newbody = (MAXSHOW<<16)/NFNames;
	}
#ifdef foob
    printf("newpot, newbody = %4lx %4lx\n",newpot,newbody);
    printf("NFNames = %ld\n",NFNames);
    printf("firstname = %ld\n",firstname);                 
#endif
    slideprop.VertBody = newbody;
    slideprop.VertPot = newpot;
    }
    

FreeFileNames() {
    int n;
    for(n=0; n<MAXFNAMES; n++) 	{
	if (names[n] != NULL) DFree(names[n]);
	names[n] = NULL;
	namedir[n] = FALSE;
	}
    }

local BOOL okDrawer;

strToLower(d,s) char *d,*s; {
    char c;
    do { c = *s++;  *d++ = tolower(c); } while(c!=0);
    }
    
CmpStr(s,t) char *s,*t; {
    char a[40],b[40];
    strToLower(a,s);
    strToLower(b,t);
    return(stscmp(a,b));
    }

local UBYTE dotinfo[] = ".info";

DotInfo(nm) char *nm; {
    int l = strlen(nm);
    if (l<5) return(NO);
    return( strcmp(dotinfo,nm+l-5) == 0);
    }
/*----------------------------------------------------------------------*/
/* GetFileNames  							*/
/*         Read in all the file names, allocating space for them	*/
/*----------------------------------------------------------------------*/
VOID GetFileNames(drawername) UBYTE drawername[];   {                     
    BOOL success;
    LONG lock;                     
    LONG n, ln, t, bound;
    UBYTE *tmp, tmpb;
    struct FileInfoBlock *fib;                      
    
    ZZZCursor();
    FreeFileNames();
    okDrawer = NO;
    NFNames = 0;
    lock = Lock(drawername,SHARED_LOCK);
    success = (lock!=0);
    if (success) {                      
	fib = (struct FileInfoBlock *)DAlloc(sizeof(struct FileInfoBlock),MEMF_PUBLIC);
	success = Examine(lock,fib);
	if (success)   {
	    okDrawer = YES;
	    n = 0;
	    while (success) {
		success = ExNext(lock,fib);
		if (success&&(n<MAXFNAMES))    {
		    ln = strlen(fib->fib_FileName);
		    if (fib->fib_DirEntryType>0) { 
			namedir[n] = TRUE;
			ln += 6;
			}
		    else {
			if (DotInfo(fib->fib_FileName)) continue;
			namedir[n] = FALSE;
			}
		    names[n] = (UBYTE *)DAlloc(ln+1,MEMF_PUBLIC);
		    strcpy(names[n],fib->fib_FileName);
		    if (namedir[n]) strcat(names[n]," (Dir)");
		    n++;
		    }
		} /* end while */                         
	    NFNames = n;
	    }
	DFree(fib);
	UnLock(lock);  
	}
    /** bubble sort file names **/
    t = NFNames-1;
    while (t>0) {
	bound = t; 
	t = 0;
	for (n=0; n<bound; n++) {
	    if (CmpStr(names[n],names[n+1])>0) {
		tmp = names[n]; names[n] = names[n+1]; names[n+1] = tmp;
		tmpb = namedir[n]; namedir[n] = namedir[n+1];
		namedir[n+1] = tmpb;
		t = n;
		}
	    }
	}
    UnZZZCursor();
    } /* end GetFileNames() */

local BOOL doAction;

/*****************************************************************************/
/* FN_GadgUp                                                                 */
/*                                                                           */
/* Handle gadget up events                                                   */
/*                                                                           */
/*****************************************************************************/

RedoNames() {
    StuffReqNames();
    RefreshGadgets(&namegadget[MAXSHOW-1],reqwindow,&fn_req);
    }

VOID FN_GadgUp(gid,x,y) UWORD gid; int x,y;   {     
    LONG n;
    UBYTE tmp[31];
    /* ---- names in the directory display */
    if ((gid >= (FN_SLIDE+1)) && (gid <= (FN_SLIDE+MAXSHOW)))      {
	n = gid - FN_SLIDE - 1 + firstname;
	if (namedir[n]) {
	    strncpy(tmp,names[n],strlen(names[n])-6);
	    ConcatPath(drawerstr.Buffer,tmp);
	    GetFileNames(drawerstr.Buffer);
	    drawerstr.BufferPos = 0; /*strlen(drawerstr.Buffer);*/
	    filestr.DispPos = 0;
	    firstname = 0;
	    StuffReqNames();
	    }             
	else {
	    strcpy(filestr.Buffer,names[n]);
	    filestr.BufferPos = 0; /*strlen(filestr.Buffer);*/
	    filestr.DispPos = 0;
	    }
	/*RefreshGadgets(&namegadget[MAXSHOW-1],reqwindow,&fn_req); */
	/* try to keep it from redrawing whole thing-- didnt work */
	RefreshGadgets(&filegadget,reqwindow,&fn_req); 
	}
    if (gid==FN_SLIDE) {
	firstname = ((slideprop.VertPot*nrange)>>16);
	RedoNames();
	}
    if (gid==FN_DRAWER)  {
	GetFileNames(drawerstr.Buffer);
	firstname = 0;
	RedoNames();
	}
    if ((gid==FN_UP)||(gid==FN_DOWN) ) {
	if (gid==FN_UP) firstname--;	else  firstname++;
	RedoNames();
	}
   }

/*****************************************************************************/
/* Handle events for the File Name requester                                */
/*****************************************************************************/
local BOOL FN_HandleEvent(event) struct IntuiMessage *event; {                                
    WORD gadgetid;
    BOOL keepGoing = YES;
    switch(event->Class)
	{
	case GADGETUP:
	    gadgetid = ((struct Gadget *)event->IAddress)->GadgetID;
	    if (gadgetid == FN_CANCEL) 	keepGoing = NO;
	    else if (gadgetid==FN_GOTNAME) { doAction = TRUE;
		keepGoing = NO;
		}
	    else if ((gadgetid>=FN_GADGMIN) && (gadgetid<=FN_GADGMAX))
		FN_GadgUp(gadgetid);
	    break;
	}
    return(keepGoing);
    }


/*****************************************************************************/
/* FN_Request                                                                */
/*                                                                           */
/* Initialize and display the requester                                      */
/* Returns TRUE if do, FALSE if cancel                                       */
/*****************************************************************************/
BOOL FN_Request(w,x,y,drawername,filename,extension,title,cancelverb,doverb)
struct Window *w; SHORT x,y;
    UBYTE drawername[]; UBYTE filename[]; UBYTE extension[]; UBYTE title[];
    UBYTE doverb[]; UBYTE cancelverb[];                       
    {
    UWORD width0,width1,width,height;
    ULONG saveIDCMP;
    
    
    FixMenCols();
    AllocShowNames();
    reqX = x;
    reqY = y;
    reqwindow = w;
    saveIDCMP = w->IDCMPFlags;
    
    reqWidth = ( (w->WScreen->ViewPort.Modes & (HIRES|LACE)) == 
     (HIRES|LACE)) ? HIWIDTH: LOWIDTH;
    
    /* --- What class of events do we want to know about? --- */

    ModifyIDCMP( reqwindow, RAWKEY | MOUSEBUTTONS |  GADGETUP | GADGETDOWN);

    if (!dosready) {                   
	/* Initialize stuff the first time through */
	GetPrefs(&reqfont.ta_YSize,2); 
	FN_InitReq();
	FN_InitText();
	dosready = TRUE;
	}
    drawerstr.Buffer = drawername;
    filestr.Buffer = filename;

    if (title==NULL) fn_text[0].IText = deftitle;
    else fn_text[0].IText = title;
    fn_text[0].LeftEdge = (reqWidth-10*strlen(fn_text[0].IText))/2;
    
    if (cancelverb==NULL) gadg_text[0].IText = defcancel;
    else gadg_text[0].IText = cancelverb;

    if (doverb==NULL) gadg_text[1].IText = defdoverb;
    else gadg_text[1].IText = doverb;

    width0 = strlen(gadg_text[0].IText)*10+10;
    width1 = strlen(gadg_text[1].IText)*10+10;
    width = MAX(width0,width1);
    height = 17;            

    cancelgadget.LeftEdge = -10-width;
    cancelgadget.Width = width;
    cancelgadget.Height = height;
    FN_FixBox(&dt0box1,&dt0box2,width,height);

    gotnamegadget.Width = width;
    gotnamegadget.Height = height;
    FN_FixBox(&dt1box1,&dt1box2,width,height);
    
    GetFileNames(drawerstr.Buffer);

    StuffReqNames();

    ZZZCursor();
    
    Request(&fn_req,w);
    
    UnZZZCursor();

    doAction = FALSE;

    ReqListen(w->UserPort,&FN_HandleEvent);
   
    FreeFileNames();

    /* restore the IDCMP to its original state */
    ModifyIDCMP(reqwindow, saveIDCMP);

    FreeShowNames();    
    UnFixMenCols();
    return( (BOOL)
	(doAction? ( okDrawer? FN_OK: FN_NoSuchDrawer): FN_Cancel ));
    }