Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / reqtools / filereqmain.c
bloba014650784dce05c6471fe9ba9c46f5c1f0077f8
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /**************************************************************
10 * *
11 * File/Font/Screenmode requester *
12 * *
13 * (c) Nico François 1991-1994 *
14 **************************************************************/
16 #include "filereq.h"
18 /* The AmigaOS V40 ScrollWindowRaster() function is buggy and
19 causes Enforcer Hits */
21 #define NO_SCROLLWINDOWRASTER 1
23 #ifdef __AROS__
25 #define DEBUG 1
26 #include <aros/debug.h>
27 #else
29 #define D(x)
31 #endif
34 /****************************************************************************************/
36 #ifdef __AROS__
37 #define fib_EntryType fib_DirEntryType
38 #endif
40 /****************************************************************************************/
42 #ifndef MTYPE_APPWINDOW
43 #define MTYPE_APPWINDOW 7 /* msg from an app window */
44 #endif
46 /****************************************************************************************/
48 static const IPTR getstringtags[] = { RTGS_Width,180,RT_LockWindow,TRUE,
49 RT_ReqPos,REQPOS_CENTERWIN,RT_ShareIDCMP,TRUE,TAG_END };
50 static const IPTR ezreqtags[] = { RT_Underscore,'_',RTEZ_Flags,EZREQF_NORETURNKEY,
51 TAG_MORE, (IPTR)&getstringtags[2] };
54 /****************************************************************************************/
56 BOOL
57 ExpandLink( GlobData *glob )
59 #ifndef __AROS__
60 struct FileLock *fl;
61 #endif
62 BOOL rc = FALSE;
63 LONG res;
65 *glob->winaddr = ( APTR ) -1;
67 #ifdef __AROS__
68 res = ReadLink(NULL, glob->lock, glob->fib.fib_FileName, glob->linkbuf,
69 sizeof(glob->linkbuf));
70 #else
71 fl = BADDR( glob->lock );
72 res = ReadLink(fl->fl_Task, glob->lock, glob->fib.fib_FileName, glob->linkbuf, sizeof(glob->linkbuf));
73 #endif
75 if(res != 0)
77 BPTR lock;
79 if( ( lock = Lock( glob->linkbuf, SHARED_LOCK ) ) )
81 STRPTR end = FilePart( glob->linkbuf );
83 if( end != glob->linkbuf )
85 *end = 0;
88 Examine( lock, &glob->linkfib );
89 UnLock( lock );
90 rc = TRUE;
94 *glob->winaddr = glob->reqwin;
96 return( rc );
99 /****************************************************************************************/
101 ULONG ASM SAVEDS PropReqHandler (
102 REGPARAM(a1, struct RealHandlerInfo *, glob),
103 REGPARAM(d0, ULONG, sigs),
104 REGPARAM(a0, struct TagItem *, taglist))
106 struct IntuiMessage *reqmsg = NULL, *imsg, im;
107 struct Gadget *gad;
108 struct RealFileRequester *freq = NULL;
109 struct RealFontRequester *fontreq = NULL;
110 struct BufferData *buff;
111 struct DiskfontBase *DiskfontBase = glob->diskfontbase;
112 struct TagItem *tag;
113 const struct TagItem *tstate = taglist;
114 struct AvailFontsHeader *afh;
115 struct AvailFonts *af;
116 struct ReqEntry *entry;
117 struct DosList *dlist;
118 struct AppMessage *appmsg;
119 struct AssignList *assignlist, *fontslist, **prevassign;
120 int clicked, ctype, sel, val, code, qual, doubleclick, checkbox;
121 int i, step, start, stop, shortage, buffsize, mon, doactgad, lastpos;
122 UBYTE *fdir = NULL, *filename = NULL, *str, *str2, *str3, key;
123 ULONG tagdata;
124 BPTR parent;
125 APTR winlock;
126 ULONG id;
128 /* uncomment if sigs is no longer ignored */
129 // if (glob->DoNotWait) sigs = SetSignal (0, 0);
131 doactgad = !(glob->buttoninfo.lastcode);
133 if (glob->reqtype == RT_FILEREQ)
135 freq = glob->freq;
136 filename = freq->filename;
137 fdir = freq->dirname;
140 if (glob->reqtype == RT_FONTREQ)
142 fontreq = glob->fontreq;
143 filename = fontreq->fontname;
146 buff = glob->buff;
148 /* parse tags */
149 while ((tag = NextTagItem (&tstate)))
151 tagdata = tag->ti_Data;
152 if (tag->ti_Tag > RT_TagBase)
154 switch (tag->ti_Tag)
156 case RTRH_EndRequest:
157 if (tagdata == REQ_OK)
158 return (LeaveReq (glob, filename));
160 FreeAllCheckBuffer (glob);
162 return (FALSE);
168 /* MAIN LOOP */
170 if (glob->appwinport)
172 while ((appmsg = (struct AppMessage *)GetMsg (glob->appwinport)))
174 if (appmsg->am_Type == MTYPE_APPWINDOW)
176 if (appmsg->am_NumArgs >= 1)
178 NameFromLock (appmsg->am_ArgList->wa_Lock, fdir, 256);
179 my_SetStringGadget (glob->reqwin, glob->filegad,
180 appmsg->am_ArgList->wa_Name);
181 NewDir (glob);
183 ReplyMsg ((struct Message *)appmsg);
184 goto iterate;
186 ReplyMsg ((struct Message *)appmsg);
190 if (glob->newdir)
193 glob->disks = FALSE;
195 if (!glob->bufferentry)
197 ClearFilesRect (glob);
198 ClearAndInitReqBuffer (glob);
199 AdjustScroller (glob);
201 else RethinkReqDisplay (glob);
203 glob->selectedpos = -1;
204 glob->numselected = 0;
205 UpdateNumSelGad (glob);
206 glob->lastclicked = -1;
207 glob->exnext = FALSE;
209 if (!glob->bufferentry)
211 if (glob->reqtype == RT_FILEREQ)
213 if (!glob->volumerequest)
215 /* Render LED before lock, for good behaviour with ArcHandler */
216 glob->ledon = TRUE;
217 RenderLED (glob);
218 if ((glob->lock = Lock (fdir, SHARED_LOCK)))
220 Examine (glob->lock, &glob->fib);
221 if (glob->fib.fib_EntryType <= 0)
222 UnLockReqLock (glob);
224 else if ((glob->flags & FREQF_SAVE) &&
225 fdir[strlen(fdir)-1] != ':' &&
226 IoErr() != ERROR_DEVICE_NOT_MOUNTED)
228 struct TagItem tags[] =
230 {RT_Window , (IPTR)glob->reqwin },
231 {RT_IntuiMsgFunc , (IPTR)&glob->intuihook},
232 {TAG_MORE , (IPTR)ezreqtags }
235 if (rtEZRequestA (GetStr (glob->catalog, MSG_CREATE_DRAWER),
236 GetStr (glob->catalog, MSG_OK_BAR_CANCEL),
237 NULL, &glob->drawerstr, tags))
238 glob->lock = CreateDir (glob->drawerstr);
241 if (!glob->lock)
243 glob->ledon = FALSE;
244 RenderLED (glob);
245 SetWinTitleFlash (glob->reqwin,
246 GetStr (glob->catalog, MSG_DIR_ERROR));
247 FreeReqBuffer (glob->req);
248 ClearDisplayList (glob);
249 glob->nodir = TRUE;
251 else
253 i = strlen (fdir);
255 if (fdir[i-1] == '/' && i > 1)
257 if (fdir[i-2] != ':' && fdir[i-2] != '/') fdir[i-1] = 0;
260 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
261 glob->exnext = TRUE;
262 glob->nodir = FALSE;
263 /* first examine before ExNext */
264 Examine (glob->lock, &glob->fib);
265 StartTimer (glob, 500000);
266 glob->firsttimer = glob->quiet = TRUE;
270 } /* if (glob->reqtype == RT_FILEREQ) */
271 else
273 /* Volume requester */
274 AddDiskNames (glob, glob->volumerequest);
276 if (fdir[0])
278 if (!FindCurrentPos (glob, fdir, MAXINT, VOLUME))
279 FindCurrentPos (glob, fdir, MAXINT, ASSIGN);
281 glob->buff->pos -= (glob->numentries - 1);
283 if (glob->buff->pos < 0) glob->buff->pos = 0;
285 glob->buff->gotopos = glob->buff->pos;
288 RethinkReqDisplay (glob);
289 glob->disks = TRUE;
291 } /* if (glob->reqtype == RT_FILEREQ) else ... */
293 } /* if (glob->reqtype == RT_FILEREQ) */
294 else if (glob->reqtype == RT_FONTREQ)
296 winlock = rtLockWindow (glob->reqwin);
297 ReqToolsBase->AvailFontsLock = TRUE;
298 afh = ReqToolsBase->AvailFontsHeader;
300 dlist = LockDosList (LDF_DEVICES|LDF_ASSIGNS|LDF_READ);
301 dlist = FindDosEntry (dlist, "FONTS", LDF_DEVICES|LDF_ASSIGNS);
303 if (afh)
305 if (!dlist) afh = NULL;
306 else
308 if (ReqToolsBase->FontsAssignType != dlist->dol_Type) afh = NULL;
309 else
311 if (ReqToolsBase->FontsAssignLock != dlist->dol_Lock)
312 afh = NULL;
313 else
315 fontslist = ReqToolsBase->FontsAssignList;
316 assignlist = dlist->dol_misc.dol_assign.dol_List;
318 while (assignlist)
320 if (fontslist->al_Lock != assignlist->al_Lock)
322 afh = NULL;
323 break;
325 fontslist = fontslist->al_Next;
326 assignlist = assignlist->al_Next;
329 if (fontslist) afh = NULL;
334 if (!afh) FreeReqToolsFonts();
337 if (!afh)
339 buffsize = 2000;
340 for (;;)
342 if (!(afh = AllocVec (buffsize, 0))) break;
344 shortage = AvailFonts ((STRPTR)afh, buffsize, AFF_DISK|AFF_MEMORY);
345 if (shortage)
347 buffsize += shortage;
348 FreeVec (afh);
350 else break;
353 ReqToolsBase->AvailFontsHeader = afh;
354 if (dlist)
356 ReqToolsBase->FontsAssignType = dlist->dol_Type;
357 ReqToolsBase->FontsAssignLock = dlist->dol_Lock;
359 if (dlist->dol_Type == DLT_DIRECTORY)
361 assignlist = dlist->dol_misc.dol_assign.dol_List;
362 prevassign = &(ReqToolsBase->FontsAssignList);
364 while (assignlist)
366 fontslist = AllocVec (sizeof (struct AssignList), MEMF_CLEAR);
367 *prevassign = fontslist;
369 if (!fontslist) break;
371 fontslist->al_Lock = assignlist->al_Lock;
372 assignlist = assignlist->al_Next;
373 prevassign = &(fontslist->al_Next);
381 } /* if (!afh) */
383 UnLockDosList (LDF_DEVICES|LDF_ASSIGNS|LDF_READ);
385 if (!afh)
386 DisplayBeep (NULL);
387 else
389 af = (struct AvailFonts *)((long)afh + 2);
390 for (i = 0; i < afh->afh_NumEntries; i++, af++)
392 if ((af->af_Type == AFF_MEMORY) &&
393 !(af->af_Attr.ta_Flags & FPF_ROMFONT)) continue;
395 if (glob->filterhook)
397 if (!CallHookPkt (glob->filterhook, fontreq, &af->af_Attr))
398 continue;
400 else
402 if (glob->flags & FREQF_DOWILDFUNC)
404 IPTR args[] = { REQHOOK_WILDFONT, (IPTR)&af->af_Attr };
405 if (CallHookA (fontreq->Hook, (Object *)fontreq, args ))
406 continue;
410 str = af->af_Attr.ta_Name;
411 val = strlen(str) - 5;
412 str[val] = 0;
414 if (!(entry = AddEntry (glob, buff, str, af->af_Attr.ta_YSize, FONT)))
415 break;
417 str[val] = '.';
418 entry->re_Flags = af->af_Attr.ta_Flags;
419 entry->re_Style = af->af_Attr.ta_Style;
422 str = filename;
423 val = strlen(str) - 5;
424 str[val] = 0;
425 FindCurrentPos (glob, str, glob->fontreq->Attr.ta_YSize, FONT);
426 str[val] = '.';
430 ReqToolsBase->AvailFontsLock = FALSE;
431 RethinkReqDisplay (glob);
432 rtUnlockWindow (glob->reqwin, winlock);
434 } /* else if (glob->reqtype == RT_FONTREQ) */
435 else
437 id = INVALID_ID;
438 while ((id = NextDisplayInfo (id)) != INVALID_ID)
440 if (glob->filterhook)
442 if (!CallHookPkt (glob->filterhook, glob->scrmodereq, (APTR)id))
443 continue;
446 /* filter out dual playfield modes */
447 if (id & DUALPF) continue;
448 /* filter out modes with default monitor */
449 if ((id & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID) continue;
450 if (!GetModeData (glob, id, &mon)) continue;
451 /* is mode available ? */
452 if (glob->dispinfo.NotAvailable) continue;
453 if (!(entry = AddEntry (glob, buff, glob->nameinfo.Name, id, SCRMODE)))
454 break;
456 /* get mode data for currently selected mode */
457 GetModeData (glob, glob->modeid, &mon);
459 if (!FindCurrentPos (glob, glob->nameinfo.Name, glob->modeid, SCRMODE))
461 if (glob->firstentry->re_Next)
463 glob->modeid = (ULONG)(((struct ReqEntry *)glob->firstentry->re_Next)->re_Size);
464 SetTextGad (glob, glob->modetxtgad, ((struct ReqEntry *)glob->firstentry->re_Next)->re_Name);
465 GetModeData (glob, glob->modeid, &mon);
467 else
469 glob->modeid = INVALID_ID;
470 SetTextGad (glob, glob->modetxtgad, NULL);
472 if (glob->depthgad)
474 glob->currmindepth = glob->currmaxdepth = glob->maxdepth = glob->mindepth = glob->depth = 0;
475 UpdateDepthGad (glob);
476 myGT_SetGadgetAttrs (glob->maxcolgad, glob->reqwin, NULL, GTTX_Text, (IPTR) "0", TAG_END);
479 if (glob->flags & SCREQF_SIZEGADS)
481 myGT_SetGadgetAttrs (glob->widthgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
482 myGT_SetGadgetAttrs (glob->defwgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
483 myGT_SetGadgetAttrs (glob->heightgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
484 myGT_SetGadgetAttrs (glob->defhgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
487 if (glob->flags & SCREQF_OVERSCANGAD)
488 myGT_SetGadgetAttrs (glob->overscangad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
490 if (glob->flags & SCREQF_AUTOSCROLLGAD)
491 myGT_SetGadgetAttrs (glob->checkboxgad[CHECKBOX_AUTOSCROLL], glob->reqwin, NULL,
492 GA_Disabled, TRUE, TAG_END);
495 } /* else if (glob->reqtype == RT_FONTREQ)*/
497 GetModeDimensions (glob);
498 DisplayModeAttrs (glob);
499 RethinkReqDisplay (glob);
502 } /* if (!glob->bufferentry) */
504 glob->bufferentry = glob->newdir = FALSE;
506 } /* if (glob->newdir) */
508 if (glob->exnext)
510 if ((glob->exnext = ExNext (glob->lock, &glob->fib)))
512 ULONG size = glob->fib.fib_Size;
514 ctype = glob->fib.fib_EntryType;
516 /* Try to examine links */
517 if( ( glob->fib.fib_EntryType == ST_SOFTLINK ) && ExpandLink( glob ) )
519 size = glob->linkfib.fib_Size;
520 ctype = glob->linkfib.fib_EntryType;
523 /* Hooks */
524 if (glob->filterhook)
526 SetDrawerAndFileFields (glob);
527 val = CallHookPkt (glob->filterhook, freq, &glob->fib);
528 ResetDrawerAndFileFields (glob);
530 if (!val) goto skipfile;
532 else
534 if (glob->flags & FREQF_DOWILDFUNC)
536 IPTR args[] = { REQHOOK_WILDFILE, (IPTR)&glob->fib};
537 SetDrawerAndFileFields (glob);
538 val = CallHookA (freq->Hook, (Object *)freq, args);
539 ResetDrawerAndFileFields (glob);
541 if (val) goto skipfile;
545 ctype = ( ctype > 0 ) ? glob->directory_id : glob->file_id;
547 if( !AddEntry( glob, buff, glob->fib.fib_FileName, size, ctype ) )
548 glob->exnext = FALSE;
550 skipfile:
553 } /* if ((glob->exnext = ExNext (glob->lock, &glob->fib))) */
555 if (!glob->exnext)
557 UnLockReqLock (glob);
558 EndQuiet (glob);
561 } /* if (glob->exnext) */
565 reqmsg = NULL;
567 while ((imsg = (struct IntuiMessage *)GetMsg (glob->reqwin->UserPort)))
569 /* Reply message from timer.device ? */
570 if ((struct timerequest *)imsg == &glob->timereq)
572 glob->timerstarted = FALSE;
573 EndQuiet (glob);
574 continue;
577 /* Message from string gadget hook ? */
578 if (!imsg->Class && !imsg->Seconds)
580 /* Mark message so string gadget hook knows it has been received */
581 imsg->Micros = 0;
583 if (glob->selectedpos != -1)
585 DeselectFiles (glob, -1, FALSE);
586 CountAllDeselect (glob, FALSE);
587 UpdateNumSelGad (glob);
588 glob->selectedpos = -1;
591 if (*glob->filestr && !glob->disks)
592 FindEntryPos (glob, glob->filestr, glob->file_id);
593 continue;
596 if ((reqmsg = ProcessWin_Msg_Freq (glob, imsg))) break;
599 if (reqmsg)
601 memcpy( &im, reqmsg, sizeof( im ) );
602 Reply_GT_Msg (reqmsg);
604 gad = (struct Gadget *)im.IAddress;
605 code = im.Code;
606 qual = im.Qualifier;
608 switch (im.Class)
610 case IDCMP_DISKINSERTED:
611 case IDCMP_DISKREMOVED:
612 if (glob->disks)
614 glob->disks = FALSE;
615 ShowDisks (glob);
617 break;
619 case IDCMP_REFRESHWINDOW:
620 RenderReqWindow (glob, TRUE, FALSE);
621 break;
623 case IDCMP_CLOSEWINDOW:
624 FreeAllCheckBuffer (glob);
625 return (FALSE);
627 case IDCMP_NEWSIZE:
628 if (glob->filegad)
630 strcpy (glob->tempfname, glob->filestr);
632 RemoveGList (glob->reqwin, glob->buttoninfo.glist, -1);
633 my_FreeGadgets (glob->buttoninfo.glist);
634 glob->buttoninfo.glist = NULL;
635 my_FreeLabelImages (&glob->labelimages);
636 glob->labelimages.NextImage = NULL;
637 glob->reqheight = glob->reqwin->Height;
639 if (!SetupReqWindow (glob, TRUE))
641 glob->reqheight = glob->reqwin->MinHeight;
642 glob->reqwidth = glob->reqwin->MinWidth;
644 if (!SetupReqWindow (glob, TRUE))
646 DisplayBeep (NULL);
647 FreeAllCheckBuffer (glob);
648 return (FALSE);
652 my_SetStringGadget (glob->reqwin, glob->filegad, glob->tempfname);
654 if (!glob->nodir || glob->disks)
656 i = glob->buff->currentnum - glob->numentries;
658 if (i < 0)
659 glob->buff->gotopos = glob->buff->pos = 0;
660 else if (glob->buff->pos > i)
661 glob->buff->gotopos = glob->buff->pos = i;
663 AdjustScroller (glob);
664 UpdateDisplayList (glob);
665 PrintFiles (glob);
667 RenderReqWindow (glob, FALSE, FALSE);
668 break;
670 case IDCMP_MOUSEMOVE:
671 if (!glob->downgadget) break;
673 if (glob->downgadget == FILES)
675 if (glob->clicked != ~0)
677 clicked = CalcClicked (glob, &im);
678 sel = !(glob->displaylist[glob->clicked]->re_Flags & ENTRYF_HIGHLIGHTED);
679 val = !(clicked != glob->clicked || im.MouseX < glob->boxleft
680 || im.MouseX > glob->boxright);
681 if (val == sel) CompClicked (glob);
684 else if (gad->GadgetID == FPROP) ScrollerMoved (glob, code);
685 else if (gad->GadgetID == DEPTH) UpdateDepthDisplay (glob, code, glob->modeid);
686 break;
688 case IDCMP_MOUSEBUTTONS:
689 glob->downgadget = 0;
691 if( glob->reqtype == RT_FILEREQ )
693 if( ( code == MENUDOWN ) && !glob->volumerequest )
695 if( !glob->disks )
697 ShowDisks( glob );
699 else
701 strcpy( fdir, glob->drawerstr );
702 NewDir( glob );
705 else if( code == MIDDLEDOWN )
707 BOOL doit;
709 doit = rtLockPrefs()->Flags & RTPRF_MMBPARENT;
710 rtUnlockPrefs();
712 if( doit )
714 goto parentdir;
719 break;
721 case IDCMP_GADGETDOWN:
722 EndQuiet (glob);
723 glob->downgadget = id = gad->GadgetID;
724 if (id == FILES)
726 glob->clicked = ~0;
727 clicked = CalcClicked (glob, &im);
728 if (ClickDown (glob, clicked, &im, qual))
729 return (LeaveReq (glob, filename));
731 else if (id == FPROP)
733 ScrollerMoved (glob, code);
735 break;
737 case IDCMP_RAWKEY:
738 if ((glob->reqtype == RT_FILEREQ) && !(glob->flags & FREQF_NOFILES) &&
739 (code == RAWKEY_UP || code == RAWKEY_DOWN))
741 glob->activegadget = glob->mainstrgad;
743 if (glob->selectcurrpos || !glob->buff->firstname) break;
745 lastpos = glob->selectedpos;
747 if (glob->selectedpos == -1)
749 if (qual & IEQUALIFIER_SHIFT)
751 if (code == RAWKEY_UP)
752 glob->selectedpos = glob->buff->pos;
753 else
754 glob->selectedpos = glob->buff->pos +
755 MIN (glob->numentries, glob->buff->currentnum) - 1;
757 else if (qual & IEQUALIFIER_CONTROL)
759 if (code == RAWKEY_UP) glob->selectedpos = 0;
760 else glob->selectedpos = glob->buff->currentnum - 1;
762 else
764 if (glob->disks) i = (qual & IEQUALIFIER_ALT) ? ASSIGN : VOLUME;
765 else i = (qual & IEQUALIFIER_ALT) ? glob->directory_id : glob->file_id;
766 glob->selectedpos = FindEntryPos (glob, glob->filestr, i);
769 else
771 if (code == RAWKEY_UP)
773 if (qual & IEQUALIFIER_SHIFT)
775 if (glob->selectedpos != glob->buff->pos)
776 glob->selectedpos = glob->buff->pos;
777 else glob->selectedpos -= (glob->numentries - 1);
778 if (glob->selectedpos < 0) glob->selectedpos = 0;
780 else if (qual & IEQUALIFIER_CONTROL)
781 glob->selectedpos = 0;
782 else if (glob->selectedpos) glob->selectedpos--;
784 else
786 if (qual & IEQUALIFIER_SHIFT)
788 val = (glob->buff->pos + glob->numentries - 1);
789 if (glob->selectedpos != val) glob->selectedpos = val;
790 else glob->selectedpos += glob->numentries - 1;
791 if (glob->selectedpos >= glob->buff->currentnum)
792 glob->selectedpos = glob->buff->currentnum - 1;
794 else if (qual & IEQUALIFIER_CONTROL)
795 glob->selectedpos = glob->buff->currentnum - 1;
796 else if (glob->selectedpos < (glob->buff->currentnum - 1))
797 glob->selectedpos++;
801 if (glob->selectedpos != lastpos)
803 i = (glob->selectedpos - glob->buff->pos);
804 val = glob->buff->gotopos;
806 if (i < 0)
808 val += i;
809 if (val < 0) val = 0;
812 if (i >= glob->numentries)
814 val += (i - glob->numentries) + 1;
815 if (val > (glob->buff->currentnum - glob->numentries))
816 val = (glob->buff->currentnum - glob->numentries);
818 ScrollerMoved (glob, val);
820 if (glob->buff->pos != glob->buff->gotopos)
821 AdjustScroller (glob);
823 glob->selectcurrpos = TRUE;
825 break;
828 if ((id = CheckGadgetKey (code, qual, &key, &glob->buttoninfo)))
829 goto dogadgetup;
831 gad = NULL;
832 checkbox = -1;
834 if (key == 27) /* Esc? */
835 goto docancel;
836 else if (key == glob->gadkey[CHECKBOX_AUTOSCROLL])
837 checkbox = CHECKBOX_AUTOSCROLL;
838 else if (key == glob->gadkey[CHECKBOX_BOLD])
839 checkbox = CHECKBOX_BOLD;
840 else if (key == glob->gadkey[CHECKBOX_ITALIC])
841 checkbox = CHECKBOX_ITALIC;
842 else if (key == glob->gadkey[CHECKBOX_UNDERLINE])
843 checkbox = CHECKBOX_UNDERLINE;
844 else if (key == glob->patkey) gad = glob->patgad;
845 else if (key == glob->heightkey) gad = glob->heightgad;
846 else if (key == glob->widthkey) gad = glob->widthgad;
847 else if (key == glob->overscankey)
849 if (glob->overscangad)
851 if (qual & IEQUALIFIER_SHIFT)
852 glob->overscantype--;
853 else
854 glob->overscantype++;
856 if (glob->overscantype > OSCAN_MAX) glob->overscantype = 0;
857 if (glob->overscantype < 0) glob->overscantype = OSCAN_MAX;
859 code = glob->overscantype;
860 myGT_SetGadgetAttrs (glob->overscangad, glob->reqwin, NULL,
861 GTCY_Active, code, TAG_END);
862 id = OVERSCN;
863 goto dogadgetup;
866 else if (key == glob->depthkey)
868 if (glob->depthgad)
870 if (qual & IEQUALIFIER_SHIFT)
872 if (glob->depth > glob->currmindepth) glob->depth--;
874 else
876 if (glob->depth < glob->currmaxdepth) glob->depth++;
878 UpdateDepthGad (glob);
882 if (gad) glob->activegadget = gad;
884 if (checkbox != -1)
886 if ((gad = glob->checkboxgad[checkbox]))
888 IPTR checked;
889 struct TagItem get_tags[] =
891 {GTCB_Checked, (IPTR)&checked},
892 {TAG_DONE }
895 #ifdef __AROS__
896 /* the other way (checking GFLG_SELECTED) does
897 not work with AROS gadtools.library, and in
898 general not with boopsi gadgets. Only with
899 non-boopsi bool gadgets it works (but not
900 yet in AROS) */
902 GT_GetGadgetAttrsA(gad, glob->reqwin, NULL, get_tags);
903 myGT_SetGadgetAttrs (gad, glob->reqwin, NULL,
904 GTCB_Checked, !checked, TAG_END);
906 #else
907 myGT_SetGadgetAttrs (gad, glob->reqwin, NULL,
908 GTCB_Checked, !(gad->Flags & GFLG_SELECTED), TAG_END);
909 #endif
910 goto fakegadgetup;
913 break;
915 case IDCMP_GADGETUP:
916 #ifdef __AROS__
917 /* AROS gadtools library gadgets are boopsi gadgets, so checking
918 for GTYP_STRGADGET does not work*/
919 if ((code == KEYB_SHORTCUT) && ((gad->GadgetID == PATSTR) ||
920 (gad->GadgetID == DRAWERSTR) ||
921 (gad->GadgetID == FILESTR)) )
924 #else
925 if (((gad->GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
926 && (code == KEYB_SHORTCUT))
927 #endif
929 doactgad = FALSE;
930 continue;
933 fakegadgetup:
934 id = gad->GadgetID;
935 dogadgetup:
936 glob->downgadget = 0;
937 switch (id)
939 case FILES:
940 clicked = CalcClicked (glob, &im);
942 if (clicked != glob->clicked) break;
944 entry = glob->displaylist[clicked];
945 str = entry->re_Name;
946 doubleclick = ((clicked == glob->lastclicked)
947 && DoubleClick (glob->sec, glob->mic, im.Seconds, im.Micros));
948 ctype = entry->re_Type;
950 if (ctype == glob->directory_id)
952 if (!(glob->flags & FREQF_SELECTDIRS))
954 AddPart (fdir, str, 256);
955 NewDir (glob);
957 /* CHECKME: added hoping to fix MuForce hit. See below. */
959 entry = NULL;
961 /* END CHECKME */
962 break;
965 else switch (ctype)
967 case VOLUME:
968 case ASSIGN:
969 CompClicked (glob);
970 if (ctype == VOLUME)
972 str2 = str;
973 while (*str2 != ' ') str2++;
974 str3 = str2;
975 while (*str3 == ' ') str3++;
976 if ((glob->volumerequest && !( *str == '-' && str[ 1 ] == ' ' ))
977 || *str3 == ':'
978 || FindVolume (glob, str3, entry))
980 strcpy (fdir, str);
981 fdir[str2-str] = 0;
983 else strcpy (fdir, str3);
985 else strcpy (fdir, str);
987 if (!glob->volumerequest)
989 NewDir (glob);
991 /* CHECKME: added hoping to fix MuForce hit. See below. */
993 entry = NULL;
995 /* END CHECKME */
997 break;
1000 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
1001 checkdoubleclick:
1002 if (doubleclick)
1003 return (LeaveReq (glob, filename));
1005 goto rememberclicked;
1007 case FONT:
1008 CompClicked (glob);
1009 strcpy (filename, str);
1010 StrCat (filename, DOTFONTSTR);
1011 my_SetStringGadget (glob->reqwin,
1012 glob->filegad, filename);
1013 if (doubleclick)
1014 return (LeaveReq (glob, filename));
1016 fontreq->Attr.ta_YSize = entry->re_Size;
1017 fontreq->Attr.ta_Flags = entry->re_Flags;
1018 fontreq->Attr.ta_Style = entry->re_Style;
1019 fontreq->Attr.ta_Style &= ~(FSF_ITALIC|FSF_BOLD|FSF_UNDERLINED);
1020 fontreq->Attr.ta_Style |= glob->fontstyle;
1021 my_SetIntegerGadget (glob->reqwin,
1022 glob->drawergad, entry->re_Size);
1023 ShowFontSample (glob, FALSE, TRUE);
1024 rememberclicked:
1025 glob->lastclicked = clicked;
1026 glob->sec = im.Seconds; glob->mic = im.Micros;
1027 break;
1029 case SCRMODE:
1030 CompClicked (glob);
1031 SetTextGad (glob, glob->modetxtgad, str);
1032 glob->modeid = (ULONG)entry->re_Size;
1033 if (!GetModeData (glob, glob->modeid, &mon))
1034 DisplayBeep (glob->scr);
1035 else
1037 GetModeDimensions (glob);
1038 DisplayModeAttrs (glob);
1040 goto checkdoubleclick;
1043 #warning check following line. causes MuForces hits on Amiga when clicking
1044 #warning on volume or assign entry. Both with old Amiga reqtools.library and
1045 #warning in new reqtools.library compiled from AROS sources.
1047 #if 0
1048 entry->re_Flags &= ~ENTRYF_HIGHLIGHTED;
1049 #else
1050 if (entry) entry->re_Flags &= ~ENTRYF_HIGHLIGHTED;
1051 #endif
1052 break;
1054 case FONTSIZE:
1055 fontreq->Attr.ta_YSize = ((struct StringInfo *)glob->drawergad->SpecialInfo)->LongInt;
1056 ShowFontSample (glob, FALSE, TRUE);
1057 glob->activegadget = glob->mainstrgad;
1058 break;
1060 case ITALIC:
1061 #ifdef __AROS__
1063 IPTR checked;
1064 struct TagItem get_tags[] =
1066 {GTCB_Checked, (IPTR)&checked},
1067 {TAG_DONE }
1070 GT_GetGadgetAttrsA(glob->checkboxgad[CHECKBOX_ITALIC], glob->reqwin, NULL, get_tags);
1071 if (checked)
1073 glob->fontstyle |= FSF_ITALIC;
1075 else
1077 glob->fontstyle &= ~FSF_ITALIC;
1081 #else
1083 if (glob->checkboxgad[CHECKBOX_ITALIC]->Flags & GFLG_SELECTED)
1084 glob->fontstyle |= FSF_ITALIC;
1085 else glob->fontstyle &= ~FSF_ITALIC;
1087 #endif
1089 goto updatestyle;
1091 case UNDERLINE:
1092 #ifdef __AROS__
1094 IPTR checked;
1095 struct TagItem get_tags[] =
1097 {GTCB_Checked, (IPTR)&checked},
1098 {TAG_DONE }
1101 GT_GetGadgetAttrsA(glob->checkboxgad[CHECKBOX_UNDERLINE], glob->reqwin, NULL, get_tags);
1102 if (checked)
1104 glob->fontstyle |= FSF_UNDERLINED;
1106 else
1108 glob->fontstyle &= ~FSF_UNDERLINED;
1112 #else
1114 if (glob->checkboxgad[CHECKBOX_UNDERLINE]->Flags & GFLG_SELECTED)
1115 glob->fontstyle |= FSF_UNDERLINED;
1116 else glob->fontstyle &= ~FSF_UNDERLINED;
1117 #endif
1119 goto updatestyle;
1121 case BOLD:
1122 #ifdef __AROS__
1124 IPTR checked;
1125 struct TagItem get_tags[] =
1127 {GTCB_Checked, (IPTR)&checked},
1128 {TAG_DONE }
1131 GT_GetGadgetAttrsA(glob->checkboxgad[CHECKBOX_BOLD], glob->reqwin, NULL, get_tags);
1132 if (checked)
1134 glob->fontstyle |= FSF_BOLD;
1136 else
1138 glob->fontstyle &= ~FSF_BOLD;
1142 #else
1144 if (glob->checkboxgad[CHECKBOX_BOLD]->Flags & GFLG_SELECTED)
1145 glob->fontstyle |= FSF_BOLD;
1146 else glob->fontstyle &= ~FSF_BOLD;
1147 #endif
1148 updatestyle:
1149 ShowFontSample (glob, FALSE, TRUE);
1150 break;
1152 case ALL:
1153 EndQuiet (glob);
1154 if (!glob->nodir && !glob->disks) SelectAll (glob, "#?");
1155 break;
1157 case PATTERN:
1158 EndQuiet (glob);
1159 if (!glob->nodir && !glob->disks)
1161 struct TagItem tags[] =
1163 {RT_Window , (IPTR)glob->reqwin },
1164 {RT_IntuiMsgFunc , (IPTR)&glob->intuihook},
1165 {TAG_MORE , (IPTR)getstringtags }
1168 if (rtGetStringA (glob->selpattern, 123,
1169 GetStr (glob->catalog, MSG_MATCH_WINTITLE),
1170 NULL, tags))
1171 SelectAll (glob, glob->selpattern);
1173 break;
1175 case CLR:
1176 EndQuiet (glob);
1177 if (!glob->nodir && !glob->disks)
1179 CountAllDeselect (glob, FALSE);
1180 UpdateNumSelGad (glob);
1181 PrintFiles (glob);
1182 my_SetStringGadget (glob->reqwin, glob->filegad, "");
1184 break;
1186 case PATSTR:
1187 EndQuiet (glob);
1188 if (Stricmp (freq->patstr, glob->patgadstr))
1190 strcpy (freq->patstr, glob->patgadstr);
1191 ParsePatternNoCase (freq->patstr, glob->matchpat, sizeof( glob->matchpat ) );
1192 glob->activegadget = glob->mainstrgad;
1193 goto refreshlist;
1195 glob->activegadget = glob->mainstrgad;
1196 break;
1198 case INFO:
1199 EndQuiet (glob);
1200 freq->hideinfo = !freq->hideinfo;
1201 refreshlist:
1202 RethinkReqDisplay (glob);
1203 UpdateNumSelGad (glob);
1204 break;
1206 case DRAWERSTR:
1207 glob->activegadget = glob->mainstrgad;
1209 if (glob->flags & FREQF_NOFILES)
1211 if (glob->volumerequest ||
1212 (!glob->nodir && !Stricmp (fdir, glob->drawerstr)))
1214 if (qual & IEQUALIFIER_SHIFT) break;
1216 strcpy (fdir, glob->drawerstr);
1217 val = (glob->volumerequest && !*fdir);
1218 my_SelectGadget (!val ? glob->okgad : glob->cancelgad, glob->reqwin);
1219 ShortDelay();
1221 if (val) goto docancel;
1223 return (LeaveReq (glob, filename));
1227 if (!glob->nodir && !glob->disks
1228 && !Stricmp (fdir, glob->drawerstr))
1229 break;
1231 /* FALLTHROUGH */
1233 case GETDIR:
1234 strcpy (fdir, glob->drawerstr);
1235 NewDir (glob);
1236 break;
1238 case FILESTR:
1239 if (code == 0x09) break;
1241 if (qual & IEQUALIFIER_SHIFT)
1243 glob->activegadget = glob->drawergad;
1244 break;
1247 if ((qual & IEQUALIFIER_ALT) && (glob->flags & FREQF_PATGAD))
1249 glob->activegadget = glob->patgad;
1250 break;
1253 if (glob->reqtype == RT_FILEREQ)
1255 /* extract path from filename if one was entered */
1256 char tempstr[108];
1257 BPTR templock = NULL, dirlock, oldcd;
1259 str = glob->filestr;
1261 if (*str == '/') {
1262 strcpy (tempstr, str + 1);
1263 my_SetStringGadget (glob->reqwin, glob->filegad,
1264 tempstr);
1265 goto parentdir;
1268 if (*str)
1270 *glob->winaddr = (APTR)-1;
1272 if ((dirlock = Lock (glob->drawerstr, SHARED_LOCK)))
1274 oldcd = CurrentDir (dirlock);
1275 templock = Lock (str, SHARED_LOCK);
1276 CurrentDir (oldcd);
1279 *glob->winaddr = glob->reqwin;
1281 if (dirlock) UnLock (dirlock);
1283 if (templock)
1285 Examine (templock, &glob->fib);
1286 UnLock (templock);
1288 if (glob->fib.fib_EntryType > 0)
1290 if (dirlock)
1292 strcpy (fdir, glob->drawerstr);
1293 AddPart (fdir, str, 256);
1295 else strcpy (fdir, str);
1297 tempstr[0] = 0;
1299 goto setfnamedirgads;
1304 if (PathPart (str) != str)
1306 val = strlen (str);
1308 for (i = 0; i < val; i++)
1310 if (str[i] == ':')
1312 strcpy (fdir, str);
1313 break;
1317 if (i >= val) AddPart (fdir, str, 256);
1319 *(PathPart (fdir)) = 0;
1320 strcpy (tempstr, FilePart (glob->filestr));
1321 setfnamedirgads:
1322 NewDir (glob);
1323 my_SetStringGadget (glob->reqwin, glob->filegad, tempstr);
1324 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
1325 break;
1329 } /* if (glob->reqtype == RT_FILEREQ) */
1331 my_SelectGadget (
1332 (!glob->nodir &&
1333 (*glob->filestr || glob->allowempty
1334 || ((glob->flags & FREQF_MULTISELECT) &&
1335 (glob->numselected > 0))
1337 ) ? glob->okgad : glob->cancelgad, glob->reqwin);
1338 ShortDelay();
1340 case OK:
1341 return (LeaveReq (glob, filename));
1343 case CANCEL:
1344 docancel:
1345 FreeAllCheckBuffer (glob);
1346 return (FALSE);
1348 case PARENT:
1349 parentdir:
1350 UnLockReqLock (glob);
1351 // strcpy (fdir, glob->drawerstr);
1352 str = PathPart ( fdir );
1353 if (*str)
1355 *str = 0;
1356 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
1357 NewDir (glob);
1358 break;
1360 else
1362 if ((glob->lock = Lock (glob->drawerstr, SHARED_LOCK)))
1364 if ((parent = ParentDir (glob->lock)))
1366 NameFromLock (parent, fdir, 256);
1367 UnLock (parent);
1368 NewDir (glob);
1369 break;
1374 if(glob->disks)
1375 break;
1376 /* FALLTHROUGH! */
1378 case DISKS:
1379 if (!glob->disks)
1380 ShowDisks (glob);
1381 else
1383 strcpy (fdir, glob->drawerstr);
1384 NewDir (glob);
1386 break;
1388 case DEPTH:
1389 UpdateDepthDisplay (glob, code, glob->modeid);
1390 glob->depth = code;
1391 break;
1393 case SCRWIDTH:
1394 glob->width = IntGadgetBounds (glob, glob->widthgad,
1395 MAX (glob->diminfo.MinRasterWidth, glob->minwidth),
1396 MIN (glob->diminfo.MaxRasterWidth, glob->maxwidth));
1397 glob->usedefwidth = (glob->width == glob->defwidth);
1398 myGT_SetGadgetAttrs (glob->defwgad, glob->reqwin, NULL,
1399 GTCB_Checked, glob->usedefwidth, TAG_END);
1400 glob->activegadget = glob->mainstrgad;
1401 break;
1403 case SCRHEIGHT:
1404 glob->height = IntGadgetBounds (glob, glob->heightgad,
1405 MAX (glob->diminfo.MinRasterHeight, glob->minheight),
1406 MIN (glob->diminfo.MaxRasterHeight, glob->maxheight));
1407 glob->usedefheight = (glob->height == glob->defheight);
1408 myGT_SetGadgetAttrs (glob->defhgad, glob->reqwin, NULL,
1409 GTCB_Checked, glob->usedefheight, TAG_END);
1410 glob->activegadget = glob->mainstrgad;
1411 break;
1413 case DEFWIDTH:
1414 glob->usedefwidth = !glob->usedefwidth;
1415 SetSizeGads (glob);
1416 break;
1418 case DEFHEIGHT:
1419 glob->usedefheight = !glob->usedefheight;
1420 SetSizeGads (glob);
1421 break;
1423 case AUTOSCR:
1424 glob->autoscroll = !glob->autoscroll;
1425 break;
1427 case OVERSCN:
1428 glob->overscantype = code;
1429 GetModeDimensions (glob);
1430 SetSizeGads (glob);
1431 break;
1433 } /* switch (id) */
1434 break;
1436 } /* switch (im.Class) */
1438 } /* if (reqmsg) */
1440 iterate:
1441 if ((glob->downgadget != FILES) && (glob->buff->gotopos != glob->buff->pos))
1443 #if NO_SCROLLWINDOWRASTER
1444 BOOL refreshall = FALSE;
1445 #endif
1447 start = 0; stop = glob->numentries;
1448 step = glob->buff->gotopos - glob->buff->pos;
1450 if (ABS(step) < stop)
1452 if (ABS(step) > 1) step /= 2;
1453 if (step > 3) step = 3;
1454 if (step < -3) step = -3;
1456 SetBPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
1457 mySetWriteMask (glob->reqrp, glob->entrymask);
1459 #if !NO_SCROLLWINDOWRASTER
1460 if (glob->os30)
1462 ScrollWindowRaster (glob->reqwin, 0, step * glob->entryheight,
1463 glob->boxleft, glob->boxtop, glob->boxright,
1464 glob->boxtop + glob->boxheight - 1);
1466 else
1468 #endif
1469 ScrollRaster (glob->reqrp, 0, step * glob->entryheight,
1470 glob->boxleft, glob->boxtop, glob->boxright,
1471 glob->boxtop + glob->boxheight - 1);
1472 if (glob->reqrp->Layer->Flags & LAYERREFRESH)
1473 refreshall = TRUE; /* RenderReqWindow (glob, TRUE, FALSE); */
1475 #if !NO_SCROLLWINDOWRASTER
1477 #endif
1478 mySetWriteMask (glob->reqrp, glob->rpmask);
1480 if (step > 0)
1481 start = stop - step;
1482 else
1483 stop = -step;
1485 } /* if (ABS(step) < stop) */
1487 glob->buff->pos += step;
1488 UpdateDisplayList (glob);
1490 #if NO_SCROLLWINDOWRASTER
1491 if (refreshall)
1493 RenderReqWindow (glob, TRUE, FALSE);
1495 #endif
1497 for (i = start; i < stop; i++) PrintEntry (glob, i);
1499 glob->DoNotWait = TRUE;
1501 } /* if ((glob->downgadget != FILES) && (glob->buff->gotopos != glob->buff->pos)) */
1502 else
1504 glob->DoNotWait = glob->exnext || glob->newdir;
1507 if (glob->selectcurrpos && (glob->buff->pos == glob->buff->gotopos))
1509 if (glob->selectedpos != -1)
1511 ClickDown (glob, (glob->selectedpos - glob->buff->pos), NULL, 0);
1513 glob->selectcurrpos = FALSE;
1516 } while (reqmsg && !glob->newdir);
1518 if (doactgad)
1521 #ifdef __AROS__
1522 #warning Disabled this gadget activation here, as in Intuition this functions is slow (why? ask stegerg)
1523 #else
1525 ActivateGadget (glob->activegadget, glob->reqwin, NULL);
1528 #endif
1530 if (!(glob->reqwin->IDCMPFlags & IDCMP_RAWKEY))
1532 /* Add RAWKEY IDCMP only after initialzing and refreshing the window */
1533 ModifyIDCMP (glob->reqwin, IDCMP_RAWKEY|REQ_IDCMP);
1537 return ((ULONG)CALL_HANDLER);
1540 /****************************************************************************************/