alsa.audio: limit the supported frequencies to common set
[AROS.git] / workbench / libs / reqtools / filereqmain.c
blobaaf790fe105cce860f6d5cb530cf0392578b8c91
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 IPTR 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, *tstate = taglist;
113 struct AvailFontsHeader *afh;
114 struct AvailFonts *af;
115 struct ReqEntry *entry;
116 struct DosList *dlist;
117 struct AppMessage *appmsg;
118 struct AssignList *assignlist, *fontslist, **prevassign;
119 int clicked, ctype, sel, val, code, qual, doubleclick, checkbox;
120 int i, step, start, stop, shortage, buffsize, mon, doactgad, lastpos;
121 UBYTE *fdir = NULL, *filename = NULL, *str, *str2, *str3, key;
122 ULONG tagdata;
123 BPTR parent;
124 APTR winlock;
125 ULONG id;
127 /* uncomment if sigs is no longer ignored */
128 // if (glob->DoNotWait) sigs = SetSignal (0, 0);
130 doactgad = !(glob->buttoninfo.lastcode);
132 if (glob->reqtype == RT_FILEREQ)
134 freq = glob->freq;
135 filename = freq->filename;
136 fdir = freq->dirname;
139 if (glob->reqtype == RT_FONTREQ)
141 fontreq = glob->fontreq;
142 filename = fontreq->fontname;
145 buff = glob->buff;
147 /* parse tags */
148 while ((tag = NextTagItem (&tstate)))
150 tagdata = tag->ti_Data;
151 if (tag->ti_Tag > RT_TagBase)
153 switch (tag->ti_Tag)
155 case RTRH_EndRequest:
156 if (tagdata == REQ_OK)
157 return (LeaveReq (glob, filename));
159 FreeAllCheckBuffer (glob);
161 return (FALSE);
167 /* MAIN LOOP */
169 if (glob->appwinport)
171 while ((appmsg = (struct AppMessage *)GetMsg (glob->appwinport)))
173 if (appmsg->am_Type == MTYPE_APPWINDOW)
175 if (appmsg->am_NumArgs >= 1)
177 NameFromLock (appmsg->am_ArgList->wa_Lock, fdir, 256);
178 my_SetStringGadget (glob->reqwin, glob->filegad,
179 appmsg->am_ArgList->wa_Name);
180 NewDir (glob);
182 ReplyMsg ((struct Message *)appmsg);
183 goto iterate;
185 ReplyMsg ((struct Message *)appmsg);
189 if (glob->newdir)
192 glob->disks = FALSE;
194 if (!glob->bufferentry)
196 ClearFilesRect (glob);
197 ClearAndInitReqBuffer (glob);
198 AdjustScroller (glob);
200 else RethinkReqDisplay (glob);
202 glob->selectedpos = -1;
203 glob->numselected = 0;
204 UpdateNumSelGad (glob);
205 glob->lastclicked = -1;
206 glob->exnext = FALSE;
208 if (!glob->bufferentry)
210 if (glob->reqtype == RT_FILEREQ)
212 if (!glob->volumerequest)
214 /* Render LED before lock, for good behaviour with ArcHandler */
215 glob->ledon = TRUE;
216 RenderLED (glob);
217 if ((glob->lock = Lock (fdir, SHARED_LOCK)))
219 Examine (glob->lock, &glob->fib);
220 if (glob->fib.fib_EntryType <= 0)
221 UnLockReqLock (glob);
223 else if ((glob->flags & FREQF_SAVE) &&
224 fdir[strlen(fdir)-1] != ':' &&
225 IoErr() != ERROR_DEVICE_NOT_MOUNTED)
227 struct TagItem tags[] =
229 {RT_Window , (IPTR)glob->reqwin },
230 {RT_IntuiMsgFunc , (IPTR)&glob->intuihook},
231 {TAG_MORE , (IPTR)ezreqtags }
234 if (rtEZRequestA (GetStr (glob->catalog, MSG_CREATE_DRAWER),
235 GetStr (glob->catalog, MSG_OK_BAR_CANCEL),
236 NULL, &glob->drawerstr, tags))
237 glob->lock = CreateDir (glob->drawerstr);
240 if (!glob->lock)
242 glob->ledon = FALSE;
243 RenderLED (glob);
244 SetWinTitleFlash (glob->reqwin,
245 GetStr (glob->catalog, MSG_DIR_ERROR));
246 FreeReqBuffer (glob->req);
247 ClearDisplayList (glob);
248 glob->nodir = TRUE;
250 else
252 i = strlen (fdir);
254 if (fdir[i-1] == '/' && i > 1)
256 if (fdir[i-2] != ':' && fdir[i-2] != '/') fdir[i-1] = 0;
259 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
260 glob->exnext = TRUE;
261 glob->nodir = FALSE;
262 /* first examine before ExNext */
263 Examine (glob->lock, &glob->fib);
264 StartTimer (glob, 500000);
265 glob->firsttimer = glob->quiet = TRUE;
269 } /* if (glob->reqtype == RT_FILEREQ) */
270 else
272 /* Volume requester */
273 AddDiskNames (glob, glob->volumerequest);
275 if (fdir[0])
277 if (!FindCurrentPos (glob, fdir, MAXINT, VOLUME))
278 FindCurrentPos (glob, fdir, MAXINT, ASSIGN);
280 glob->buff->pos -= (glob->numentries - 1);
282 if (glob->buff->pos < 0) glob->buff->pos = 0;
284 glob->buff->gotopos = glob->buff->pos;
287 RethinkReqDisplay (glob);
288 glob->disks = TRUE;
290 } /* if (glob->reqtype == RT_FILEREQ) else ... */
292 } /* if (glob->reqtype == RT_FILEREQ) */
293 else if (glob->reqtype == RT_FONTREQ)
295 winlock = rtLockWindow (glob->reqwin);
296 ReqToolsBase->AvailFontsLock = TRUE;
297 afh = ReqToolsBase->AvailFontsHeader;
299 dlist = LockDosList (LDF_DEVICES|LDF_ASSIGNS|LDF_READ);
300 dlist = FindDosEntry (dlist, "FONTS", LDF_DEVICES|LDF_ASSIGNS);
302 if (afh)
304 if (!dlist) afh = NULL;
305 else
307 if (ReqToolsBase->FontsAssignType != dlist->dol_Type) afh = NULL;
308 else
310 if (ReqToolsBase->FontsAssignLock != dlist->dol_Lock)
311 afh = NULL;
312 else
314 fontslist = ReqToolsBase->FontsAssignList;
315 assignlist = dlist->dol_misc.dol_assign.dol_List;
317 while (assignlist)
319 if (fontslist->al_Lock != assignlist->al_Lock)
321 afh = NULL;
322 break;
324 fontslist = fontslist->al_Next;
325 assignlist = assignlist->al_Next;
328 if (fontslist) afh = NULL;
333 if (!afh) FreeReqToolsFonts();
336 if (!afh)
338 buffsize = 2000;
339 for (;;)
341 if (!(afh = AllocVec (buffsize, 0))) break;
343 shortage = AvailFonts ((STRPTR)afh, buffsize, AFF_DISK|AFF_MEMORY);
344 if (shortage)
346 buffsize += shortage;
347 FreeVec (afh);
349 else break;
352 ReqToolsBase->AvailFontsHeader = afh;
353 if (dlist)
355 ReqToolsBase->FontsAssignType = dlist->dol_Type;
356 ReqToolsBase->FontsAssignLock = dlist->dol_Lock;
358 if (dlist->dol_Type == DLT_DIRECTORY)
360 assignlist = dlist->dol_misc.dol_assign.dol_List;
361 prevassign = &(ReqToolsBase->FontsAssignList);
363 while (assignlist)
365 fontslist = AllocVec (sizeof (struct AssignList), MEMF_CLEAR);
366 *prevassign = fontslist;
368 if (!fontslist) break;
370 fontslist->al_Lock = assignlist->al_Lock;
371 assignlist = assignlist->al_Next;
372 prevassign = &(fontslist->al_Next);
380 } /* if (!afh) */
382 UnLockDosList (LDF_DEVICES|LDF_ASSIGNS|LDF_READ);
384 if (!afh)
385 DisplayBeep (NULL);
386 else
388 af = (struct AvailFonts *)((long)afh + 2);
389 for (i = 0; i < afh->afh_NumEntries; i++, af++)
391 if ((af->af_Type == AFF_MEMORY) &&
392 !(af->af_Attr.ta_Flags & FPF_ROMFONT)) continue;
394 if (glob->filterhook)
396 if (!CallHookPkt (glob->filterhook, fontreq, &af->af_Attr))
397 continue;
399 else
401 if (glob->flags & FREQF_DOWILDFUNC)
403 IPTR args[] = { REQHOOK_WILDFONT, (IPTR)&af->af_Attr };
404 if (CallHookA (fontreq->Hook, (Object *)fontreq, args ))
405 continue;
409 str = af->af_Attr.ta_Name;
410 val = strlen(str) - 5;
411 str[val] = 0;
413 if (!(entry = AddEntry (glob, buff, str, af->af_Attr.ta_YSize, FONT)))
414 break;
416 str[val] = '.';
417 entry->re_Flags = af->af_Attr.ta_Flags;
418 entry->re_Style = af->af_Attr.ta_Style;
421 str = filename;
422 val = strlen(str) - 5;
423 str[val] = 0;
424 FindCurrentPos (glob, str, glob->fontreq->Attr.ta_YSize, FONT);
425 str[val] = '.';
429 ReqToolsBase->AvailFontsLock = FALSE;
430 RethinkReqDisplay (glob);
431 rtUnlockWindow (glob->reqwin, winlock);
433 } /* else if (glob->reqtype == RT_FONTREQ) */
434 else
436 id = INVALID_ID;
437 while ((id = NextDisplayInfo (id)) != INVALID_ID)
439 if (glob->filterhook)
441 if (!CallHookPkt (glob->filterhook, glob->scrmodereq, (APTR)(IPTR)id))
442 continue;
445 /* filter out dual playfield modes */
446 if (id & DUALPF) continue;
447 /* filter out modes with default monitor */
448 if ((id & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID) continue;
449 if (!GetModeData (glob, id, &mon)) continue;
450 /* is mode available ? */
451 if (glob->dispinfo.NotAvailable) continue;
452 if (!(entry = AddEntry (glob, buff, glob->nameinfo.Name, id, SCRMODE)))
453 break;
455 /* get mode data for currently selected mode */
456 GetModeData (glob, glob->modeid, &mon);
458 if (!FindCurrentPos (glob, glob->nameinfo.Name, glob->modeid, SCRMODE))
460 if (glob->firstentry->re_Next)
462 glob->modeid = (ULONG)(((struct ReqEntry *)glob->firstentry->re_Next)->re_Size);
463 SetTextGad (glob, glob->modetxtgad, ((struct ReqEntry *)glob->firstentry->re_Next)->re_Name);
464 GetModeData (glob, glob->modeid, &mon);
466 else
468 glob->modeid = INVALID_ID;
469 SetTextGad (glob, glob->modetxtgad, NULL);
471 if (glob->depthgad)
473 glob->currmindepth = glob->currmaxdepth = glob->maxdepth = glob->mindepth = glob->depth = 0;
474 UpdateDepthGad (glob);
475 myGT_SetGadgetAttrs (glob->maxcolgad, glob->reqwin, NULL, GTTX_Text, (IPTR) "0", TAG_END);
478 if (glob->flags & SCREQF_SIZEGADS)
480 myGT_SetGadgetAttrs (glob->widthgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
481 myGT_SetGadgetAttrs (glob->defwgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
482 myGT_SetGadgetAttrs (glob->heightgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
483 myGT_SetGadgetAttrs (glob->defhgad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
486 if (glob->flags & SCREQF_OVERSCANGAD)
487 myGT_SetGadgetAttrs (glob->overscangad, glob->reqwin, NULL, GA_Disabled, TRUE, TAG_END);
489 if (glob->flags & SCREQF_AUTOSCROLLGAD)
490 myGT_SetGadgetAttrs (glob->checkboxgad[CHECKBOX_AUTOSCROLL], glob->reqwin, NULL,
491 GA_Disabled, TRUE, TAG_END);
494 } /* else if (glob->reqtype == RT_FONTREQ)*/
496 GetModeDimensions (glob);
497 DisplayModeAttrs (glob);
498 RethinkReqDisplay (glob);
501 } /* if (!glob->bufferentry) */
503 glob->bufferentry = glob->newdir = FALSE;
505 } /* if (glob->newdir) */
507 if (glob->exnext)
509 if ((glob->exnext = ExNext (glob->lock, &glob->fib)))
511 ULONG size = glob->fib.fib_Size;
513 ctype = glob->fib.fib_EntryType;
515 /* Try to examine links */
516 if( ( glob->fib.fib_EntryType == ST_SOFTLINK ) && ExpandLink( glob ) )
518 size = glob->linkfib.fib_Size;
519 ctype = glob->linkfib.fib_EntryType;
522 /* Hooks */
523 if (glob->filterhook)
525 SetDrawerAndFileFields (glob);
526 val = CallHookPkt (glob->filterhook, freq, &glob->fib);
527 ResetDrawerAndFileFields (glob);
529 if (!val) goto skipfile;
531 else
533 if (glob->flags & FREQF_DOWILDFUNC)
535 IPTR args[] = { REQHOOK_WILDFILE, (IPTR)&glob->fib};
536 SetDrawerAndFileFields (glob);
537 val = CallHookA (freq->Hook, (Object *)freq, args);
538 ResetDrawerAndFileFields (glob);
540 if (val) goto skipfile;
544 ctype = ( ctype > 0 ) ? glob->directory_id : glob->file_id;
546 if( !AddEntry( glob, buff, glob->fib.fib_FileName, size, ctype ) )
547 glob->exnext = FALSE;
549 skipfile:
552 } /* if ((glob->exnext = ExNext (glob->lock, &glob->fib))) */
554 if (!glob->exnext)
556 UnLockReqLock (glob);
557 EndQuiet (glob);
560 } /* if (glob->exnext) */
564 reqmsg = NULL;
566 while ((imsg = (struct IntuiMessage *)GetMsg (glob->reqwin->UserPort)))
568 /* Reply message from timer.device ? */
569 if ((struct timerequest *)imsg == &glob->timereq)
571 glob->timerstarted = FALSE;
572 EndQuiet (glob);
573 continue;
576 /* Message from string gadget hook ? */
577 if (!imsg->Class && !imsg->Seconds)
579 /* Mark message so string gadget hook knows it has been received */
580 imsg->Micros = 0;
582 if (glob->selectedpos != -1)
584 DeselectFiles (glob, -1, FALSE);
585 CountAllDeselect (glob, FALSE);
586 UpdateNumSelGad (glob);
587 glob->selectedpos = -1;
590 if (*glob->filestr && !glob->disks)
591 FindEntryPos (glob, glob->filestr, glob->file_id);
592 continue;
595 if ((reqmsg = ProcessWin_Msg_Freq (glob, imsg))) break;
598 if (reqmsg)
600 memcpy( &im, reqmsg, sizeof( im ) );
601 Reply_GT_Msg (reqmsg);
603 gad = (struct Gadget *)im.IAddress;
604 code = im.Code;
605 qual = im.Qualifier;
607 switch (im.Class)
609 case IDCMP_DISKINSERTED:
610 case IDCMP_DISKREMOVED:
611 if (glob->disks)
613 glob->disks = FALSE;
614 ShowDisks (glob);
616 break;
618 case IDCMP_REFRESHWINDOW:
619 RenderReqWindow (glob, TRUE, FALSE);
620 break;
622 case IDCMP_CLOSEWINDOW:
623 FreeAllCheckBuffer (glob);
624 return (FALSE);
626 case IDCMP_NEWSIZE:
627 if (glob->filegad)
629 strcpy (glob->tempfname, glob->filestr);
631 RemoveGList (glob->reqwin, glob->buttoninfo.glist, -1);
632 my_FreeGadgets (glob->buttoninfo.glist);
633 glob->buttoninfo.glist = NULL;
634 my_FreeLabelImages (&glob->labelimages);
635 glob->labelimages.NextImage = NULL;
636 glob->reqheight = glob->reqwin->Height;
638 if (!SetupReqWindow (glob, TRUE))
640 glob->reqheight = glob->reqwin->MinHeight;
641 glob->reqwidth = glob->reqwin->MinWidth;
643 if (!SetupReqWindow (glob, TRUE))
645 DisplayBeep (NULL);
646 FreeAllCheckBuffer (glob);
647 return (FALSE);
651 my_SetStringGadget (glob->reqwin, glob->filegad, glob->tempfname);
653 if (!glob->nodir || glob->disks)
655 i = glob->buff->currentnum - glob->numentries;
657 if (i < 0)
658 glob->buff->gotopos = glob->buff->pos = 0;
659 else if (glob->buff->pos > i)
660 glob->buff->gotopos = glob->buff->pos = i;
662 AdjustScroller (glob);
663 UpdateDisplayList (glob);
664 PrintFiles (glob);
666 RenderReqWindow (glob, FALSE, FALSE);
667 break;
669 case IDCMP_MOUSEMOVE:
670 if (!glob->downgadget) break;
672 if (glob->downgadget == FILES)
674 if (glob->clicked != ~0)
676 clicked = CalcClicked (glob, &im);
677 sel = !(glob->displaylist[glob->clicked]->re_Flags & ENTRYF_HIGHLIGHTED);
678 val = !(clicked != glob->clicked || im.MouseX < glob->boxleft
679 || im.MouseX > glob->boxright);
680 if (val == sel) CompClicked (glob);
683 else if (gad->GadgetID == FPROP) ScrollerMoved (glob, code);
684 else if (gad->GadgetID == DEPTH) UpdateDepthDisplay (glob, code, glob->modeid);
685 break;
687 case IDCMP_MOUSEBUTTONS:
688 glob->downgadget = 0;
690 if( glob->reqtype == RT_FILEREQ )
692 if( ( code == MENUDOWN ) && !glob->volumerequest )
694 if( !glob->disks )
696 ShowDisks( glob );
698 else
700 strcpy( fdir, glob->drawerstr );
701 NewDir( glob );
704 else if( code == MIDDLEDOWN )
706 BOOL doit;
708 doit = rtLockPrefs()->Flags & RTPRF_MMBPARENT;
709 rtUnlockPrefs();
711 if( doit )
713 goto parentdir;
718 break;
720 case IDCMP_GADGETDOWN:
721 EndQuiet (glob);
722 glob->downgadget = id = gad->GadgetID;
723 if (id == FILES)
725 glob->clicked = ~0;
726 clicked = CalcClicked (glob, &im);
727 if (ClickDown (glob, clicked, &im, qual))
728 return (LeaveReq (glob, filename));
730 else if (id == FPROP)
732 ScrollerMoved (glob, code);
734 break;
736 case IDCMP_RAWKEY:
737 if ((glob->reqtype == RT_FILEREQ) && !(glob->flags & FREQF_NOFILES) &&
738 (code == RAWKEY_UP || code == RAWKEY_DOWN))
740 glob->activegadget = glob->mainstrgad;
742 if (glob->selectcurrpos || !glob->buff->firstname) break;
744 lastpos = glob->selectedpos;
746 if (glob->selectedpos == -1)
748 if (qual & IEQUALIFIER_SHIFT)
750 if (code == RAWKEY_UP)
751 glob->selectedpos = glob->buff->pos;
752 else
753 glob->selectedpos = glob->buff->pos +
754 MIN (glob->numentries, glob->buff->currentnum) - 1;
756 else if (qual & IEQUALIFIER_CONTROL)
758 if (code == RAWKEY_UP) glob->selectedpos = 0;
759 else glob->selectedpos = glob->buff->currentnum - 1;
761 else
763 if (glob->disks) i = (qual & IEQUALIFIER_ALT) ? ASSIGN : VOLUME;
764 else i = (qual & IEQUALIFIER_ALT) ? glob->directory_id : glob->file_id;
765 glob->selectedpos = FindEntryPos (glob, glob->filestr, i);
768 else
770 if (code == RAWKEY_UP)
772 if (qual & IEQUALIFIER_SHIFT)
774 if (glob->selectedpos != glob->buff->pos)
775 glob->selectedpos = glob->buff->pos;
776 else glob->selectedpos -= (glob->numentries - 1);
777 if (glob->selectedpos < 0) glob->selectedpos = 0;
779 else if (qual & IEQUALIFIER_CONTROL)
780 glob->selectedpos = 0;
781 else if (glob->selectedpos) glob->selectedpos--;
783 else
785 if (qual & IEQUALIFIER_SHIFT)
787 val = (glob->buff->pos + glob->numentries - 1);
788 if (glob->selectedpos != val) glob->selectedpos = val;
789 else glob->selectedpos += glob->numentries - 1;
790 if (glob->selectedpos >= glob->buff->currentnum)
791 glob->selectedpos = glob->buff->currentnum - 1;
793 else if (qual & IEQUALIFIER_CONTROL)
794 glob->selectedpos = glob->buff->currentnum - 1;
795 else if (glob->selectedpos < (glob->buff->currentnum - 1))
796 glob->selectedpos++;
800 if (glob->selectedpos != lastpos)
802 i = (glob->selectedpos - glob->buff->pos);
803 val = glob->buff->gotopos;
805 if (i < 0)
807 val += i;
808 if (val < 0) val = 0;
811 if (i >= glob->numentries)
813 val += (i - glob->numentries) + 1;
814 if (val > (glob->buff->currentnum - glob->numentries))
815 val = (glob->buff->currentnum - glob->numentries);
817 ScrollerMoved (glob, val);
819 if (glob->buff->pos != glob->buff->gotopos)
820 AdjustScroller (glob);
822 glob->selectcurrpos = TRUE;
824 break;
827 if ((id = CheckGadgetKey (code, qual, &key, &glob->buttoninfo)))
828 goto dogadgetup;
830 gad = NULL;
831 checkbox = -1;
833 if (key == 27) /* Esc? */
834 goto docancel;
835 else if (key == glob->gadkey[CHECKBOX_AUTOSCROLL])
836 checkbox = CHECKBOX_AUTOSCROLL;
837 else if (key == glob->gadkey[CHECKBOX_BOLD])
838 checkbox = CHECKBOX_BOLD;
839 else if (key == glob->gadkey[CHECKBOX_ITALIC])
840 checkbox = CHECKBOX_ITALIC;
841 else if (key == glob->gadkey[CHECKBOX_UNDERLINE])
842 checkbox = CHECKBOX_UNDERLINE;
843 else if (key == glob->patkey) gad = glob->patgad;
844 else if (key == glob->heightkey) gad = glob->heightgad;
845 else if (key == glob->widthkey) gad = glob->widthgad;
846 else if (key == glob->overscankey)
848 if (glob->overscangad)
850 if (qual & IEQUALIFIER_SHIFT)
851 glob->overscantype--;
852 else
853 glob->overscantype++;
855 if (glob->overscantype > OSCAN_MAX) glob->overscantype = 0;
856 if (glob->overscantype < 0) glob->overscantype = OSCAN_MAX;
858 code = glob->overscantype;
859 myGT_SetGadgetAttrs (glob->overscangad, glob->reqwin, NULL,
860 GTCY_Active, code, TAG_END);
861 id = OVERSCN;
862 goto dogadgetup;
865 else if (key == glob->depthkey)
867 if (glob->depthgad)
869 if (qual & IEQUALIFIER_SHIFT)
871 if (glob->depth > glob->currmindepth) glob->depth--;
873 else
875 if (glob->depth < glob->currmaxdepth) glob->depth++;
877 UpdateDepthGad (glob);
881 if (gad) glob->activegadget = gad;
883 if (checkbox != -1)
885 if ((gad = glob->checkboxgad[checkbox]))
887 IPTR checked;
888 struct TagItem get_tags[] =
890 {GTCB_Checked, (IPTR)&checked},
891 {TAG_DONE }
894 #ifdef __AROS__
895 /* the other way (checking GFLG_SELECTED) does
896 not work with AROS gadtools.library, and in
897 general not with boopsi gadgets. Only with
898 non-boopsi bool gadgets it works (but not
899 yet in AROS) */
901 GT_GetGadgetAttrsA(gad, glob->reqwin, NULL, get_tags);
902 myGT_SetGadgetAttrs (gad, glob->reqwin, NULL,
903 GTCB_Checked, !checked, TAG_END);
905 #else
906 myGT_SetGadgetAttrs (gad, glob->reqwin, NULL,
907 GTCB_Checked, !(gad->Flags & GFLG_SELECTED), TAG_END);
908 #endif
909 goto fakegadgetup;
912 break;
914 case IDCMP_GADGETUP:
915 #ifdef __AROS__
916 /* AROS gadtools library gadgets are boopsi gadgets, so checking
917 for GTYP_STRGADGET does not work*/
918 if ((code == KEYB_SHORTCUT) && ((gad->GadgetID == PATSTR) ||
919 (gad->GadgetID == DRAWERSTR) ||
920 (gad->GadgetID == FILESTR)) )
923 #else
924 if (((gad->GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
925 && (code == KEYB_SHORTCUT))
926 #endif
928 doactgad = FALSE;
929 continue;
932 fakegadgetup:
933 id = gad->GadgetID;
934 dogadgetup:
935 glob->downgadget = 0;
936 switch (id)
938 case FILES:
939 clicked = CalcClicked (glob, &im);
941 if (clicked != glob->clicked) break;
943 entry = glob->displaylist[clicked];
944 str = entry->re_Name;
945 doubleclick = ((clicked == glob->lastclicked)
946 && DoubleClick (glob->sec, glob->mic, im.Seconds, im.Micros));
947 ctype = entry->re_Type;
949 if (ctype == glob->directory_id)
951 if (!(glob->flags & FREQF_SELECTDIRS))
953 AddPart (fdir, str, 256);
954 NewDir (glob);
956 /* CHECKME: added hoping to fix MuForce hit. See below. */
958 entry = NULL;
960 /* END CHECKME */
961 break;
964 else switch (ctype)
966 case VOLUME:
967 case ASSIGN:
968 CompClicked (glob);
969 if (ctype == VOLUME)
971 str2 = str;
972 while (*str2 != ' ') str2++;
973 str3 = str2;
974 while (*str3 == ' ') str3++;
975 if ((glob->volumerequest && !( *str == '-' && str[ 1 ] == ' ' ))
976 || *str3 == ':'
977 || FindVolume (glob, str3, entry))
979 strcpy (fdir, str);
980 fdir[str2-str] = 0;
982 else strcpy (fdir, str3);
984 else strcpy (fdir, str);
986 if (!glob->volumerequest)
988 NewDir (glob);
990 /* CHECKME: added hoping to fix MuForce hit. See below. */
992 entry = NULL;
994 /* END CHECKME */
996 break;
999 my_SetStringGadget (glob->reqwin, glob->drawergad, fdir);
1000 checkdoubleclick:
1001 if (doubleclick)
1002 return (LeaveReq (glob, filename));
1004 goto rememberclicked;
1006 case FONT:
1007 CompClicked (glob);
1008 strcpy (filename, str);
1009 StrCat (filename, DOTFONTSTR);
1010 my_SetStringGadget (glob->reqwin,
1011 glob->filegad, filename);
1012 if (doubleclick)
1013 return (LeaveReq (glob, filename));
1015 fontreq->Attr.ta_YSize = entry->re_Size;
1016 fontreq->Attr.ta_Flags = entry->re_Flags;
1017 fontreq->Attr.ta_Style = entry->re_Style;
1018 fontreq->Attr.ta_Style &= ~(FSF_ITALIC|FSF_BOLD|FSF_UNDERLINED);
1019 fontreq->Attr.ta_Style |= glob->fontstyle;
1020 my_SetIntegerGadget (glob->reqwin,
1021 glob->drawergad, entry->re_Size);
1022 ShowFontSample (glob, FALSE, TRUE);
1023 rememberclicked:
1024 glob->lastclicked = clicked;
1025 glob->sec = im.Seconds; glob->mic = im.Micros;
1026 break;
1028 case SCRMODE:
1029 CompClicked (glob);
1030 SetTextGad (glob, glob->modetxtgad, str);
1031 glob->modeid = (ULONG)entry->re_Size;
1032 if (!GetModeData (glob, glob->modeid, &mon))
1033 DisplayBeep (glob->scr);
1034 else
1036 GetModeDimensions (glob);
1037 DisplayModeAttrs (glob);
1039 goto checkdoubleclick;
1042 /* FIXME: check following line. causes MuForces hits on Amiga when clicking
1043 * on volume or assign entry. Both with old Amiga reqtools.library and
1044 * 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 = BNULL, 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 /****************************************************************************************/