revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / reqtools / filereq.c
blobf83139075dc761c9c41e0ac65a4e95da4672e5fa
1 /**f************************************************************
2 * *
3 * File/Font/Screenmode requester *
4 * *
5 * (c) Nico François 1991-1994 *
6 **************************************************************/
8 #include <proto/wb.h>
10 #include "filereq.h"
12 /****************************************************************************************/
14 struct Library *WorkbenchBase;
16 char TOPAZSTR[] = "topaz.font";
17 char DOTINFOSTR[] = ".info";
19 struct TextAttr topaz80 = { "topaz.font",8,FS_NORMAL,FPF_ROMFONT|FPF_DESIGNED };
22 /****************************************************************************************/
24 #define FILEREQ_FLAGS \
25 (FREQF_NOBUFFER|FREQF_DOWILDFUNC|FREQF_MULTISELECT|FREQF_SAVE|FREQF_NOFILES|\
26 FREQF_PATGAD|FREQF_SELECTDIRS)
27 #define FONTREQ_FLAGS \
28 (FREQF_NOBUFFER|FREQF_DOWILDFUNC|FREQF_FIXEDWIDTH|FREQF_COLORFONTS|\
29 FREQF_CHANGEPALETTE|FREQF_LEAVEPALETTE|FREQF_SCALE|FREQF_STYLE)
30 #define SCREENMODEREQ_FLAGS \
31 (SCREQF_SIZEGADS|SCREQF_DEPTHGAD|SCREQF_NONSTDMODES|SCREQF_GUIMODES|\
32 SCREQF_AUTOSCROLLGAD|SCREQF_OVERSCANGAD)
34 /****************************************************************************************/
36 /********************
37 * *
38 * REQUESTER ENTRY *
39 * *
40 ********************/
42 /* This is also FontRequestA and ScreenModeRequestA! */
44 APTR ASM SAVEDS FileRequestA (
45 REGPARAM(a1, struct RealFileRequester *, freq),
46 REGPARAM(a2, char *, filename),
47 REGPARAM(a3, char *, title),
48 REGPARAM(a0, struct TagItem *, taglist))
50 GlobData *glob;
51 struct ReqEntry *entry;
52 struct TagItem *tag, *tstate = taglist;
53 struct RealFontRequester *fontreq;
54 struct RealScreenModeRequester *scrmodereq = NULL;
55 struct DiskfontBase *DiskfontBase;
56 struct TextAttr *fontattr = NULL;
57 struct TextFont *deffont;
58 struct Locale *locale = NULL;
59 char *pubname = NULL;
60 int reqhandler = FALSE, mon, propmaskset = FALSE;
61 IPTR tagdata;
64 if (!(glob = AllocVec (sizeof(GlobData), MEMF_PUBLIC|MEMF_CLEAR)))
65 return ((APTR)FALSE);
67 glob->reqtype = REQTYPE(freq);
68 if (glob->reqtype == RT_FILEREQ)
71 /* AROS timer.device checks IO length to make sure apps
72 dont use a too small/wrong iorequest structure */
74 glob->timereq.tr_node.io_Message.mn_Length = sizeof(glob->timereq);
76 if (OpenDevice ("timer.device", UNIT_VBLANK, (struct IORequest *)&glob->timereq, 0))
79 FreeVec (glob);
80 return ((APTR)FALSE);
83 glob->buff = &freq->buff;
84 glob->freq = freq;
85 freq->filename = filename;
86 glob->wilddotinfo = EndsInDotInfo (freq->patstr, strlen (freq->patstr));
87 ParsePatternNoCase (freq->patstr, glob->matchpat, sizeof( glob->matchpat ) );
89 else if (glob->reqtype == RT_FONTREQ)
92 DiskfontBase = (struct DiskfontBase *)OldOpenLibrary ("diskfont.library");
93 glob->diskfontbase = DiskfontBase;
95 if (!DiskfontBase)
97 FreeAll (glob);
98 return ((APTR)FALSE);
101 glob->fontreq = fontreq = (struct RealFontRequester *)freq;
102 glob->buff = &fontreq->buff;
103 filename = fontreq->fontname;
104 glob->sampleheight = 24;
105 glob->maxsize = MAXINT;
107 else
108 { /* RT_SCREENMODEREQ */
110 glob->scrmodereq = scrmodereq = (struct RealScreenModeRequester *)freq;
111 glob->buff = &scrmodereq->buff;
114 /* defaults */
115 glob->flags = freq->Flags; /* = [scmd|font]req->Flags */
116 glob->reqpos = freq->ReqPos; /* = [scmd|font]req->ReqPos */
117 glob->leftedge = freq->LeftOffset; /* = [scmd|font]req->LeftOffset */
118 glob->topedge = freq->TopOffset; /* = [scmd|font]req->TopOffset */
119 deffont = freq->DefaultFont; /* = [scmd|font]req->DefaultFont */
120 glob->waitpointer = freq->WaitPointer; /* = [scmd|font]req->WaitPointer */
121 glob->lockwindow = freq->LockWindow; /* = [scmd|font]req->LockWindow */
122 glob->shareidcmp = freq->ShareIDCMP; /* = [scmd|font]req->ShareIDCMP */
123 glob->reqheight = freq->ReqHeight; /* = [scmd|font]req->ReqHeight */
125 /* These must be (but automatically are, MEMF_CLEAR) NULL */
126 // glob->gadtxt[4] = NULL;
127 // glob->underchar = 0;
129 /* init global vars */
130 glob->firstentry = glob->buff->firstname;
131 glob->bufferentry = (glob->firstentry != NULL);
132 glob->req = freq;
133 glob->newdir = TRUE;
134 glob->maxdepth = glob->maxwidth = glob->maxheight = MAXINT;
138 /* parse tags */
139 while ((tag = NextTagItem (&tstate)))
141 tagdata = tag->ti_Data;
142 if (tag->ti_Tag > RT_TagBase)
144 switch (tag->ti_Tag)
146 case RT_Window: glob->prwin = (struct Window *)tagdata;
147 break;
148 case RT_ReqPos: glob->reqpos = tagdata; break;
149 case RT_LeftOffset: glob->leftedge = tagdata; break;
150 case RT_TopOffset: glob->topedge = tagdata; break;
151 case RT_PubScrName: pubname = (char *)tagdata; break;
152 case RT_Screen: glob->scr = (struct Screen *)tagdata; break;
153 case RT_ReqHandler: *(APTR *)tagdata = glob;
154 reqhandler = TRUE;
155 break;
156 case RT_DefaultFont: deffont = (struct TextFont *)tagdata; break;
157 case RT_WaitPointer: glob->waitpointer = tagdata; break;
158 case RT_Underscore: glob->underchar = tagdata; break;
159 case RT_ShareIDCMP: glob->shareidcmp = tagdata; break;
160 case RT_LockWindow: glob->lockwindow = tagdata; break;
161 case RT_ScreenToFront: glob->noscreenpop = !tagdata; break;
162 case RT_TextAttr: fontattr = (struct TextAttr *)tagdata; break;
163 case RT_IntuiMsgFunc: glob->imsghook = (struct Hook *)tagdata; break;
164 case RT_Locale: locale = (struct Locale *)tagdata; break;
165 /* RTFO_Flags, RTSC_Flags */
166 case RTFI_Flags: if (glob->reqtype == RT_FILEREQ)
167 tagdata &= FILEREQ_FLAGS;
168 else if (glob->reqtype == RT_FONTREQ)
169 tagdata &= FONTREQ_FLAGS;
170 else
172 tagdata &= SCREENMODEREQ_FLAGS;
173 tagdata |= FREQF_NOBUFFER;
175 glob->flags = tagdata;
176 break;
177 /* RTFO_Height, RTSC_Height */
178 case RTFI_Height: glob->reqheight = tagdata;
179 break;
180 /* RTFO_OkText, RTSC_OkText */
181 case RTFI_OkText: glob->gadtxt[4] = (char *)tagdata; break;
182 case RTFI_VolumeRequest: glob->volumerequest = 0x80000000 | tagdata; break;
183 /* RTFO_FilterFunc, RTSC_FilterFunc */
184 case RTFI_FilterFunc: glob->filterhook = (struct Hook *)tagdata; break;
185 case RTFI_AllowEmpty: glob->allowempty = tagdata; break;
186 case RTFO_SampleHeight: glob->sampleheight = tagdata; break;
187 case RTFO_MinHeight: glob->minsize = tagdata; break;
188 case RTFO_MaxHeight: glob->maxsize = tagdata; break;
189 case RTSC_PropertyFlags: glob->propertyflags = tagdata;
190 if (!propmaskset) glob->propertymask = 0xFFFFFFFF;
191 break;
192 case RTSC_PropertyMask: glob->propertymask = tagdata;
193 propmaskset = TRUE;
194 break;
195 case RTSC_MinWidth: glob->minwidth = tagdata; break;
196 case RTSC_MaxWidth: glob->maxwidth = tagdata; break;
197 case RTSC_MinHeight: glob->minheight = tagdata; break;
198 case RTSC_MaxHeight: glob->maxheight = tagdata; break;
199 case RTSC_MinDepth: glob->mindepth = tagdata; break;
200 case RTSC_MaxDepth: glob->maxdepth = tagdata; break;
208 glob->catalog = RT_OpenCatalog (locale);
209 if (!glob->gadtxt[4])
211 glob->gadtxt[4] = GetStr (glob->catalog, MSG_OK);
212 glob->underchar = '_';
216 if (glob->volumerequest)
218 FreeReqBuffer (glob->req);
219 glob->flags |= FREQF_NOFILES|FREQF_NOBUFFER;
220 glob->flags &= ~(FREQF_SAVE|FREQF_PATGAD|FREQF_SELECTDIRS);
224 if (glob->reqtype == RT_FILEREQ)
226 if (glob->flags & FREQF_NOFILES)
227 SetFileDirMode (glob->buff, glob->flags);
228 glob->file_id = glob->buff->file_id;
229 glob->directory_id = glob->buff->directory_id;
233 if (!glob->prwin || !glob->prwin->UserPort
234 || (glob->prwin->UserPort->mp_SigTask != ThisProcess()))
235 glob->shareidcmp = FALSE;
238 if (!(glob->scr = GetReqScreen (&glob->newreqwin, &glob->prwin,
239 glob->scr, pubname)))
241 FreeAll (glob);
242 return ((APTR)FALSE);
246 glob->vp = &glob->scr->ViewPort;
247 if (glob->flags & FREQF_CHANGEPALETTE)
249 if (!(glob->colcount = GetVpCM (glob->vp, &glob->colormap)))
251 FreeAll (glob);
252 return ((APTR)FALSE);
254 glob->colcount = (1 << glob->colcount);
258 if (fontattr) glob->font = *fontattr;
259 else glob->font = *glob->scr->Font;
261 if (glob->reqtype == RT_SCREENMODEREQ)
264 if (scrmodereq->DisplayID == INVALID_ID)
266 glob->modeid = GetVPModeID (glob->vp);
267 glob->depth = GetBitMapAttr(glob->scr->RastPort.BitMap, BMA_DEPTH);
268 glob->width = glob->scr->Width;
269 glob->height = glob->scr->Height;
270 glob->autoscroll = (glob->scr->Flags & AUTOSCROLL);
272 else
274 glob->modeid = scrmodereq->DisplayID;
275 glob->depth = scrmodereq->DisplayDepth;
276 glob->width = scrmodereq->DisplayWidth;
277 glob->height = scrmodereq->DisplayHeight;
278 glob->autoscroll = scrmodereq->AutoScroll;
281 glob->overscantype = scrmodereq->OverscanType;
282 if (!GetModeData (glob, glob->modeid, &mon))
283 glob->modeid = INVALID_ID;
284 else
286 GetModeDimensions (glob);
287 if (glob->width == 0xffff) glob->width = glob->defwidth;
288 if (glob->height == 0xffff) glob->height = glob->defheight;
289 if (glob->depth == 0xffff) glob->depth = glob->diminfo.MaxDepth;
290 if (!(glob->flags & SCREQF_SIZEGADS))
291 glob->usedefwidth = glob->usedefheight = TRUE;
292 else
294 glob->usedefwidth = (glob->width == glob->defwidth);
295 glob->usedefheight = (glob->height == glob->defheight);
301 if (!(glob->visinfo = GetVisualInfoA (glob->scr, NULL))
302 || !(glob->drinfo = GetScreenDrawInfo (glob->scr)))
304 FreeAll (glob);
305 return ((APTR)FALSE);
309 glob->pens = glob->drinfo->dri_Pens;
310 glob->title = title;
311 glob->os30 = (IntuitionBase->LibNode.lib_Version >= 39);
313 if (!glob->buff->firstname)
315 glob->buff->gotopos = glob->buff->pos = glob->buff->currentnum = 0;
319 entry = glob->buff->firstname;
320 while (entry)
322 entry->re_EntryLen = entry->re_SizeLenPix = 0;
323 entry = (struct ReqEntry *)entry->re_Next;
327 retryopenwin:
329 if (!(glob->reqfont = GetReqFont (&glob->font, deffont, &glob->fontheight,
330 &glob->fontwidth, TRUE)))
332 FreeAll (glob);
333 return ((APTR)FALSE);
335 glob->fontbase = glob->reqfont->tf_Baseline;
338 if (!SetupReqWindow (glob, FALSE))
341 if (glob->font.ta_YSize > 8)
343 glob->font = topaz80;
344 CloseFont (glob->reqfont);
345 goto retryopenwin;
347 FreeAll (glob);
348 return ((APTR)FALSE);
352 if (glob->reqtype == RT_SCREENMODEREQ) DisplayModeAttrs (glob);
353 RenderReqWindow (glob, FALSE, TRUE);
354 glob->winlock = DoLockWindow (glob->prwin, glob->lockwindow, NULL, TRUE);
355 DoWaitPointer (glob->prwin, glob->waitpointer, TRUE);
357 /* initialize hook structure */
358 glob->intuihook.h_Entry = (HOOKFUNC)IntuiMsgFunc;
359 glob->intuihook.h_Data = (void *)glob;
361 glob->frontscr = IntuitionBase->FirstScreen;
362 DoScreenToFront (glob->scr, glob->noscreenpop, TRUE);
364 my_SetStringGadget (glob->reqwin, glob->filegad, filename);
366 /* fill in RealHandlerInfo */
367 glob->func = (IPTR (*)())PropReqHandler;
368 glob->WaitMask = glob->winmask = (1 << glob->reqwin->UserPort->mp_SigBit);
369 if (glob->appwindow) glob->WaitMask |= (1 << glob->appwinport->mp_SigBit);
370 glob->DoNotWait = TRUE;
372 if (reqhandler) return ((APTR)CALL_HANDLER);
373 return ((APTR)LoopReqHandler ((struct rtHandlerInfo *)glob));
376 /****************************************************************************************/
378 /**************
380 * MAIN LOOP *
382 ***************/
384 void STDARGS SAVEDS FreeReqToolsFonts (void)
386 struct AssignList *list, *next;
388 FreeVec (ReqToolsBase->AvailFontsHeader);
389 list = ReqToolsBase->FontsAssignList;
390 while (list)
392 next = list->al_Next;
393 FreeVec (list);
394 list = next;
396 ReqToolsBase->AvailFontsHeader = NULL;
397 ReqToolsBase->FontsAssignList = NULL;
400 /****************************************************************************************/
402 int REGARGS CalcClicked (GlobData *glob, struct IntuiMessage *im)
404 return ((im->MouseY - glob->boxtop) / glob->entryheight);
407 /****************************************************************************************/
409 void REGARGS CompClicked (GlobData *glob)
411 glob->displaylist[glob->clicked]->re_Flags ^= ENTRYF_SELECTED|ENTRYF_HIGHLIGHTED;
412 PrintEntry (glob, glob->clicked);
415 /****************************************************************************************/
417 /* TIMER STUFF */
419 void REGARGS StopTimer (GlobData *glob)
421 struct Node *node;
422 int othermsgs = FALSE, gotreply = FALSE;
424 if (glob->timerstarted)
426 AbortIO ((struct IORequest *)&glob->timereq);
427 /* We don't use WaitIO() since not sure it leaves other messages
428 intact. */
429 while (!gotreply)
431 Wait (glob->winmask);
432 /* Traverse message list and look for timereq msg */
433 Disable();
434 for (node = glob->reqwin->UserPort->mp_MsgList.lh_Head;
435 node->ln_Succ; node = node->ln_Succ)
437 if (node == (struct Node *)&glob->timereq)
439 Remove (node);
440 gotreply = TRUE;
441 break;
443 else othermsgs = TRUE;
445 Enable();
448 if (othermsgs) Signal ((struct Task *)ThisProcess(), glob->winmask);
449 glob->timerstarted = FALSE;
454 /****************************************************************************************/
456 void REGARGS StartTimer (GlobData *glob, int micros)
458 StopTimer (glob);
460 glob->timereq.tr_node.io_Command = TR_ADDREQUEST;
461 glob->timereq.tr_time.tv_secs = 0;
462 glob->timereq.tr_time.tv_micro = micros;
463 SendIO ((struct IORequest *)&glob->timereq);
465 glob->timerstarted = TRUE;
468 /****************************************************************************************/
470 void REGARGS EndQuiet (GlobData *glob)
472 int i;
474 if (glob->quiet)
476 if (!glob->exnext)
478 if (rtLockPrefs()->Flags & RTPRF_IMMSORT) glob->firsttimer = TRUE;
479 rtUnlockPrefs();
482 if (glob->firsttimer)
484 ScrollerMoved (glob, glob->buff->gotopos);
485 glob->firsttimer = FALSE;
487 else
489 if (glob->lastdisplaylistnum != -1)
491 if (glob->lastdisplaylistnum < glob->numentries)
493 i = glob->lastdisplaylistnum;
494 glob->lastdisplaylistnum = -1;
495 while (i < glob->numentries) PrintEntry (glob, i++);
498 AdjustScroller (glob);
502 if (glob->exnext) StartTimer (glob, 200000);
503 else
505 StopTimer (glob);
506 glob->quiet = FALSE;
510 /****************************************************************************************/
512 /* MAIN LOOP */
514 struct IntuiMessage *REGARGS ProcessWin_Msg_Freq (GlobData *glob, struct IntuiMessage *imsg)
516 struct IntuiMessage *reqmsg;
518 if (imsg->IDCMPWindow == glob->reqwin)
520 reqmsg = GT_FilterIMsg (imsg);
521 if (reqmsg) return (reqmsg);
522 ReplyMsg ((struct Message *)imsg);
524 else
526 if (glob->imsghook)
528 SetDrawerAndFileFields (glob);
529 CallHookPkt (glob->imsghook, glob->req, imsg);
530 ResetDrawerAndFileFields (glob);
532 ReplyMsg ((struct Message *)imsg);
535 return (NULL);
538 /****************************************************************************************/
540 void REGARGS SetDrawerAndFileFields (GlobData *glob)
542 if (REQTYPE(glob->req) == RT_FILEREQ)
544 glob->tempdir = glob->freq->Dir;
545 glob->freq->Dir = glob->freq->dirname;
546 if (!(glob->flags & FREQF_NOFILES))
548 strcpy (glob->tempfname, glob->freq->filename);
549 strcpy (glob->freq->filename, ((struct StringInfo *)glob->filegad->SpecialInfo)->Buffer);
554 /****************************************************************************************/
556 void REGARGS ResetDrawerAndFileFields (GlobData *glob)
558 if (REQTYPE(glob->req) == RT_FILEREQ)
560 glob->freq->Dir = glob->tempdir;
561 if (!(glob->flags & FREQF_NOFILES))
562 strcpy (glob->freq->filename, glob->tempfname);
566 /****************************************************************************************/
568 #ifdef __AROS__
569 AROS_UFH3(void, IntuiMsgFunc,
570 AROS_UFHA(struct Hook *, hook, A0),
571 AROS_UFHA(APTR, req, A2),
572 AROS_UFHA(struct IntuiMessage *, imsg, A1))
574 AROS_USERFUNC_INIT
575 #else
576 void ASM SAVEDS IntuiMsgFunc (
577 REGPARAM(a0, struct Hook *, hook),
578 REGPARAM(a2, APTR, req),
579 REGPARAM(a1, struct IntuiMessage *,imsg))
581 #endif
582 GlobData *glob = (GlobData *)hook->h_Data;
584 if (imsg->IDCMPWindow == glob->reqwin)
586 if (imsg->Class == IDCMP_REFRESHWINDOW) RenderReqWindow (glob, TRUE, FALSE);
588 else if ((glob->imsghook) && (glob->imsghook != hook))
590 SetDrawerAndFileFields (glob);
591 CallHookPkt (glob->imsghook, glob->req, imsg);
592 ResetDrawerAndFileFields (glob);
594 #ifdef __AROS__
595 AROS_USERFUNC_EXIT
596 #endif
599 /****************************************************************************************/
601 /* Improve this function to handle:
602 * 1) Volume lists in the file requester
603 * 2) The font requester
605 int REGARGS FindEntryPos (GlobData *glob, char *name, int entry_id)
607 struct ReqEntry *entry, *entry2;
608 int i, val;
610 if (!glob->buff->firstname) return (0);
611 i = 0;
612 if (*name && (entry = FindEntry (glob->buff, name, -1, entry_id, NULL, FIND_VOLUMENAME)))
614 entry2 = (struct ReqEntry *)glob->buff->firstname->re_Next;
615 while (entry2 != (struct ReqEntry *)entry->re_Next)
617 if (!(entry2->re_Flags & ENTRYF_HIDDEN)) i++;
618 entry2 = (struct ReqEntry *)entry2->re_Next;
622 glob->buff->gotopos = i;
623 val = glob->buff->currentnum - glob->numentries;
625 if (glob->buff->gotopos > val) glob->buff->gotopos = val;
626 if (glob->buff->gotopos < 0) glob->buff->gotopos = 0;
628 if (glob->buff->pos != glob->buff->gotopos)
630 glob->buff->pos = glob->buff->gotopos;
631 AdjustScroller (glob);
632 UpdateDisplayList (glob);
633 PrintFiles (glob);
636 if (i >= glob->buff->currentnum) i = (glob->buff->currentnum - 1);
638 return (i);
641 /****************************************************************************************/
643 void REGARGS DeselectFiles (GlobData *glob, int clicked, int dirsonly)
645 int i;
647 for (i = 0; i < glob->numentries; i++)
649 if (i >= glob->buff->currentnum) break;
651 if (i != clicked)
653 if (dirsonly && (glob->displaylist[i]->re_Type == glob->file_id))
654 continue;
656 if (glob->displaylist[i]->re_Flags & ENTRYF_SELECTED)
658 glob->numselected--;
659 glob->displaylist[i]->re_Flags &= ~ENTRYF_SELECTED;
660 PrintEntry (glob, i);
666 /****************************************************************************************/
668 int REGARGS
669 ClickDown( GlobData *glob, int clicked, struct IntuiMessage *reqmsg, int qual )
671 struct BufferData *buff;
672 struct ReqEntry *entry;
673 char *str, *str2, tempstr[108];
674 int ctype, val;
676 buff = glob->buff;
678 if( clicked >= buff->currentnum )
680 return( FALSE );
683 glob->clicked = clicked;
684 entry = glob->displaylist[ clicked ];
686 if( entry->re_Flags & ENTRYF_GHOSTED )
688 entry->re_Flags &= ~ENTRYF_SELECTED;
689 glob->downgadget = 0;
690 return( FALSE );
693 str = entry->re_Name;
694 str2 = "";
695 val = !( ( glob->flags & FREQF_MULTISELECT ) && ( qual & IEQUALIFIER_SHIFT ) );
696 ctype = entry->re_Type;
698 if( ctype == glob->file_id )
700 if( !( entry->re_Flags & ENTRYF_SELECTED ) || val )
702 str2 = str;
705 goto filefont;
707 else if( ctype == glob->directory_id )
709 if( !reqmsg )
711 strcpy( tempstr, str );
712 StrCat( tempstr, "/" );
713 str2 = tempstr;
715 else if( !( glob->flags & FREQF_SELECTDIRS ) )
717 goto nodirselect;
720 filefont:
721 my_SetStringGadget( glob->reqwin, glob->filegad, str2 );
723 if( !( glob->flags & FREQF_SELECTDIRS ) )
725 DeselectFiles( glob, clicked, TRUE );
726 CountAllDeselect( glob, TRUE );
729 if( val )
731 DeselectFiles( glob, clicked, FALSE );
732 CountAllDeselect (glob, FALSE);
735 if( reqmsg )
737 if( ( clicked == glob->lastclicked ) &&
738 DoubleClick( glob->sec, glob->mic, reqmsg->Seconds, reqmsg->Micros ) )
740 if( ctype == glob->directory_id )
742 AddPart( glob->freq->dirname, str, sizeof( glob->freq->dirname ) );
743 NewDir( glob );
744 return( FALSE );
746 else if( !( glob->flags & ( FREQF_SAVE | FREQF_NOFILES ) ) )
748 entry->re_Flags |= ENTRYF_SELECTED;
749 return( TRUE );
754 if( glob->flags & FREQF_MULTISELECT )
756 if( entry->re_Flags & ENTRYF_SELECTED )
758 glob->numselected--;
760 else
762 glob->numselected++;
765 UpdateNumSelGad( glob );
768 entry->re_Flags ^= ENTRYF_SELECTED;
770 if( ( entry->re_Flags & ENTRYF_SELECTED ) && glob->buff->sorted )
772 glob->selectedpos = ( glob->buff->pos + clicked );
775 PrintEntry( glob, clicked );
776 glob->downgadget = 0;
778 if( reqmsg )
780 glob->sec = reqmsg->Seconds;
781 glob->mic = reqmsg->Micros;
782 glob->lastclicked = clicked;
785 else
787 if( !reqmsg )
789 str2 = str;
791 if( ctype == VOLUME )
793 while( *str2++ != ' ' )
797 while( *str2 == ' ' )
799 str2++;
803 goto filefont;
807 nodirselect:
808 CompClicked( glob );
811 return( FALSE );
814 /****************************************************************************************/
816 /*****************
817 * Requester exit *
818 *****************/
820 IPTR REGARGS LeaveReq (GlobData *glob, char *filename)
822 struct rtFileList *selfile = (APTR)TRUE;
823 int flags = glob->flags, nodir = glob->nodir;
824 int allowempty = glob->allowempty;
826 if (glob->filestr) strcpy (filename, glob->filestr);
828 if (glob->reqtype == RT_FILEREQ)
830 if (!(flags & FREQF_MULTISELECT))
832 FreeAllCheckBuffer (glob);
833 /* can't use glob here anymore because it is freed! */
834 if (flags & FREQF_NOFILES) return ((ULONG)!nodir);
835 if (!nodir && (filename[0] || allowempty)) return (TRUE);
836 return 0;
839 if (!nodir)
841 if (!(glob->flags & FREQF_SELECTDIRS)) CountAllDeselect (glob, TRUE);
842 selfile = AllocSelectedFiles (glob);
844 else selfile = NULL;
846 else if (glob->reqtype == RT_FONTREQ)
848 glob->fontreq->Attr.ta_Style &= ~(FSF_ITALIC|FSF_BOLD|FSF_UNDERLINED);
849 glob->fontreq->Attr.ta_Style |= glob->fontstyle;
850 selfile = (APTR)(IPTR)(filename[0] != 0);
852 else
854 if (glob->modeid == INVALID_ID) selfile = FALSE;
855 else
857 glob->scrmodereq->DisplayID = glob->modeid;
858 if (glob->modeid & HAM ) glob->depth = (glob->depth == 7 ? 6 : 8 );
859 glob->scrmodereq->DisplayDepth = glob->depth;
860 glob->scrmodereq->DisplayWidth = glob->width;
861 glob->scrmodereq->DisplayHeight = glob->height;
862 glob->scrmodereq->OverscanType = glob->overscantype;
863 glob->scrmodereq->AutoScroll = glob->autoscroll;
867 FreeAllCheckBuffer (glob);
869 return ((IPTR)selfile);
872 /****************************************************************************************/
874 static void REGARGS CloseWinFreeRest (GlobData *glob)
876 StopTimer (glob);
878 if (glob->reqtype == RT_FILEREQ)
879 CloseDevice ((struct IORequest *)&glob->timereq);
880 FreeVpCM (glob->vp, glob->colormap, !(glob->flags & FREQF_LEAVEPALETTE));
882 if (glob->newreqwin.Type == PUBLICSCREEN) UnlockPubScreen (NULL, glob->scr);
883 DoScreenToFront (glob->frontscr, glob->noscreenpop, FALSE);
885 if (glob->reqwin)
887 *glob->winaddr = glob->oldwinptr;
888 DoLockWindow (glob->prwin, glob->lockwindow, glob->winlock, FALSE);
889 DoWaitPointer (glob->prwin, glob->waitpointer, FALSE);
891 if (glob->appwindow) RemoveAppWindow (glob->appwindow);
893 DeleteMsgPort (glob->appwinport);
894 CloseLibrary (WorkbenchBase);
895 DoCloseWindow (glob->reqwin, glob->shareidcmp);
898 my_FreeGadgets (glob->buttoninfo.glist);
899 my_FreeLabelImages (&glob->labelimages);
900 FreeVisualInfo (glob->visinfo);
902 if (glob->drinfo) FreeScreenDrawInfo (glob->scr, glob->drinfo);
903 if (glob->reqfont) CloseFont (glob->reqfont);
905 CloseLibrary (glob->diskfontbase);
906 FreeVec (glob);
909 /****************************************************************************************/
911 void REGARGS FreeAllCheckBuffer (GlobData *glob)
913 if (glob->lock || (glob->disks && !glob->volumerequest)
914 || (glob->flags & FREQF_NOBUFFER))
915 FreeAll (glob);
916 else CloseWinFreeRest (glob);
919 /****************************************************************************************/
921 void REGARGS FreeAll (GlobData *glob)
923 FreeReqBuffer (glob->req);
924 UnLockReqLock (glob);
925 CloseWinFreeRest (glob);
928 /****************************************************************************************/
930 struct rtFileList *REGARGS AllocSelectedFiles (GlobData *glob)
932 struct rtFileList *ptr, **last, *selfile;
933 struct ReqEntry *entry;
934 int len, isfile, foundstr = FALSE;
935 /* We do some checks agains the file gadget if available,
936 * or the path gadget, if there is no file gadget, and we thus
937 * are a volume requester or something similar
939 char *str, *gadstr = glob->filegad ? glob->filestr : glob->patgadstr;
941 selfile = NULL; last = &selfile;
942 for (entry = (struct ReqEntry *)glob->firstentry->re_Next;;
943 entry = (struct ReqEntry *)entry->re_Next)
945 if (!entry)
947 /* We build the filelist, now we check if the filename in
948 the gadget is among the ones in the list */
949 str = gadstr;
950 if (foundstr || !*str) break;
951 /* The filename in the gadget is not is the list!
952 We will discard the list and only return the filename in the
953 gadget! This is the most intuitive behaviour! */
954 rtFreeFileList (selfile);
955 selfile = NULL; last = &selfile;
956 isfile = TRUE;
958 else
960 if (!(entry->re_Flags & ENTRYF_SELECTED)) continue;
961 str = entry->re_Name;
962 isfile = entry->re_Type == glob->file_id;
963 if (!Stricmp (str, gadstr)) foundstr = TRUE;
966 len = strlen (str);
968 if (!(ptr = (struct rtFileList *)AllocVec(sizeof (struct rtFileList) + len + 1,
969 MEMF_PUBLIC|MEMF_CLEAR)))
971 rtFreeFileList (selfile);
972 return (NULL);
975 ptr->StrLen = isfile ? len : -1;
976 ptr->Name = (char *)(4 + (IPTR)&ptr->Name);
977 strcpy (ptr->Name, str);
978 *last = ptr;
979 last = &ptr->Next;
981 if (!entry) break;
984 return (selfile);
987 /****************************************************************************************/