revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / reqtools / filereqalloc.c
blob2d6ed0fabc460934433bb7a9f628a058d07b6688
1 /**************************************************************
2 * *
3 * File/Font/Screenmode requester *
4 * *
5 * (c) Nico François 1991-1994 *
6 **************************************************************/
8 #include "filereq.h"
10 /****************************************************************************************/
12 #ifdef __AROS__
13 #define fib_EntryType fib_DirEntryType
14 #endif
16 /****************************************************************************************/
18 ULONG structsize[] =
20 sizeof (struct RealFileRequester) + sizeof(ULONG), /* RT_FILEREQ */
21 sizeof (struct rtReqInfo) + sizeof(ULONG), /* RT_REQINFO */
22 sizeof (struct RealFontRequester) + sizeof(ULONG), /* RT_FONTREQ */
23 sizeof (struct RealScreenModeRequester) + sizeof(ULONG), /* RT_SCREENMODEREQ */
26 /****************************************************************************************/
28 /********************
29 * rtAllocRequestA() *
30 ********************/
32 void REGARGS
33 SetFileDirMode (struct BufferData *buff, ULONG flags)
35 ULONG prefsflags;
37 /* Check preferences if we have to display files or directories first */
38 prefsflags = rtLockPrefs()->Flags;
39 buff->dirsmixed = (prefsflags & RTPRF_DIRSMIXED);
41 if (flags & FREQF_NOFILES)
43 prefsflags |= RTPRF_DIRSFIRST;
44 buff->dirsmixed = FALSE;
47 if (prefsflags & RTPRF_DIRSFIRST)
49 buff->file_id = 1;
50 buff->directory_id = 0;
52 else
54 buff->file_id = 0;
55 buff->directory_id = 1;
58 rtUnlockPrefs();
61 /****************************************************************************************/
63 ASM struct BufferData *GetBufferDataPtr (OPT_REGPARAM(a1, APTR, req))
65 switch (REQTYPE(req))
67 case RT_FILEREQ:
68 return (&((struct RealFileRequester *)req)->buff);
70 case RT_FONTREQ:
71 return (&((struct RealFontRequester *)req)->buff);
73 case RT_SCREENMODEREQ:
74 return (&((struct RealScreenModeRequester *)req)->buff);
78 return (NULL);
82 /****************************************************************************************/
84 APTR ASM SAVEDS AllocRequestA (
85 REGPARAM(d0, ULONG, type),
86 REGPARAM(a0, struct TagItem *,taglist))
88 struct BufferData *buff;
89 ULONG *reqstruct;
91 if (!(reqstruct = AllocVec (structsize[type], MEMF_PUBLIC | MEMF_CLEAR)))
92 return (NULL);
94 *reqstruct++ = type;
96 switch (type)
98 case RT_FILEREQ:
99 ((FI_REQ)reqstruct)->Dir = ((FI_REQ)reqstruct)->dirname;
100 ((FI_REQ)reqstruct)->MatchPat = ((FI_REQ)reqstruct)->patstr;
101 ((FI_REQ)reqstruct)->hideinfo = TRUE;
102 SetFileDirMode (&((FI_REQ)reqstruct)->buff, 0);
103 break;
105 case RT_FONTREQ:
106 ((FO_REQ)reqstruct)->Attr = topaz80;
107 /* copy 'topaz.font' to name buffer and point name pointer there */
108 strcpy (((FO_REQ)reqstruct)->fontname, TOPAZSTR);
109 ((FO_REQ)reqstruct)->Attr.ta_Name = ((FO_REQ)reqstruct)->fontname;
110 break;
112 case RT_SCREENMODEREQ:
113 ((SC_REQ)reqstruct)->DisplayID = INVALID_ID;
114 ((SC_REQ)reqstruct)->OverscanType = OSCAN_TEXT;
115 ((SC_REQ)reqstruct)->AutoScroll = TRUE;
116 break;
120 ((struct rtReqInfo *)reqstruct)->ReqPos = REQPOS_DEFAULT;
122 buff = GetBufferDataPtr (reqstruct);
123 if (buff && (DOSBase->dl_lib.lib_Version >= 39))
125 buff->pool = CreatePool (MEMF_PUBLIC | MEMF_CLEAR, 8192, 4096);
128 return (reqstruct);
131 /****************************************************************************************/
133 /********************
134 * rtFreeReqBuffer() *
135 ********************/
137 void ASM SAVEDS FreeReqBuffer (REGPARAM(a1, APTR, req))
139 struct BufferData *buff;
140 struct ReqEntry *entry, *temp;
142 if ((buff = GetBufferDataPtr (req)))
144 entry = buff->firstname;
145 while ((temp = entry))
147 entry = (struct ReqEntry *)entry->re_Next;
148 FreeVecPooled (buff->pool, temp);
150 buff->firstname = NULL;
155 /****************************************************************************************/
157 /******************
158 * rtFreeRequest() *
159 ******************/
161 void ASM SAVEDS FreeRequest (REGPARAM(a1, APTR, req))
163 struct BufferData *buff;
165 if (!req) return;
167 FreeReqBuffer (req);
169 if ((buff = GetBufferDataPtr (req)))
171 if (buff->pool) DeletePool (buff->pool);
174 FreeVec ((APTR)(((IPTR)req) - sizeof(ULONG)));
177 /****************************************************************************************/
179 /*********************
180 * rtChangeReqAttrA() *
181 *********************/
183 LONG ASM SAVEDS
184 ChangeReqAttrA (REGPARAM(a1, APTR, req),
185 REGPARAM(a0, struct TagItem *, taglist))
187 UBYTE fibspace[sizeof(struct FileInfoBlock)+4];
188 struct FileInfoBlock *fib = (struct FileInfoBlock *)(((IPTR)&fibspace[3] >> 2) << 2);
189 struct TagItem *tag, *tstate = taglist;
190 struct RealFileRequester *freq;
191 struct ReqEntry *entry, *curr;
192 struct BufferData *buff;
193 struct Screen *scr;
194 IPTR tagdata;
196 /* parse tags */
197 while ((tag = NextTagItem (&tstate)))
199 tagdata = tag->ti_Data;
200 if (tag->ti_Tag > RT_TagBase)
202 switch (tag->ti_Tag)
204 case RTFI_Dir:
205 FreeReqBuffer (req);
206 strcpy (((struct RealFileRequester *)req)->dirname, (char *)tagdata);
207 break;
209 case RTFI_MatchPat:
210 strcpy (((struct RealFileRequester *)req)->patstr, (char *)tagdata);
211 break;
213 case RTFI_AddEntry:
214 case RTFI_RemoveEntry:
215 freq = (struct RealFileRequester *)req;
216 buff = &(freq->buff);
217 if (!buff->firstname) return (TRUE);
218 if (tag->ti_Tag == RTFI_AddEntry)
220 Examine ((BPTR)tagdata, fib);
221 return ((LONG)(AddEntry (NULL, buff, fib->fib_FileName, fib->fib_Size,
222 (fib->fib_EntryType > 0)
223 ? buff->directory_id : buff->file_id) != NULL));
225 else
227 entry = FindEntry (buff, (char *)tagdata, -1, -1, NULL, 0);
228 curr = (struct ReqEntry *)entry->re_Next;
229 if (!curr || Stricmp ((char *)tagdata, entry->re_Next->ln_Name))
230 return( 0 );
231 entry->re_Next = curr->re_Next;
232 FreeVecPooled (buff->pool, curr);
234 break;
236 case RTFO_FontName:
237 strcpy (((struct RealFontRequester *)req)->fontname, (char *)tagdata);
238 break;
240 case RTFO_FontHeight:
241 ((struct RealFontRequester *)req)->Attr.ta_YSize = tagdata;
242 break;
244 case RTFO_FontStyle:
245 ((struct RealFontRequester *)req)->Attr.ta_Style = tagdata;
246 break;
248 case RTFO_FontFlags:
249 ((struct RealFontRequester *)req)->Attr.ta_Flags = tagdata;
250 break;
252 case RTSC_ModeFromScreen:
253 scr = (struct Screen *)tagdata;
254 ((SC_REQ)req)->DisplayID = GetVPModeID (&scr->ViewPort);
255 ((SC_REQ)req)->DisplayWidth = scr->Width;
256 ((SC_REQ)req)->DisplayHeight = scr->Height;
257 ((SC_REQ)req)->DisplayDepth = GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH);
258 ((SC_REQ)req)->AutoScroll = (scr->Flags & AUTOSCROLL);
259 break;
261 case RTSC_DisplayID:
262 ((SC_REQ)req)->DisplayID = tagdata & ~(0x00000440);
263 ((SC_REQ)req)->DisplayWidth = ((SC_REQ)req)->DisplayHeight
264 = ((SC_REQ)req)->DisplayDepth = 0xffff;
265 break;
267 case RTSC_DisplayWidth:
268 ((SC_REQ)req)->DisplayWidth = tagdata;
269 break;
271 case RTSC_DisplayHeight:
272 ((SC_REQ)req)->DisplayHeight = tagdata;
273 break;
275 case RTSC_DisplayDepth:
276 ((SC_REQ)req)->DisplayDepth = tagdata;
277 break;
279 case RTSC_OverscanType:
280 ((SC_REQ)req)->OverscanType = tagdata;
281 break;
283 case RTSC_AutoScroll:
284 ((SC_REQ)req)->AutoScroll = tagdata;
285 break;
287 } /* switch (tag->ti_Tag) */
289 } /* if (tag->ti_Tag > RT_TagBase) */
291 } /* while ((tag = NextTagItem (&tstate))) */
293 /* FIXME: There was a missing return. For AROS I added return 1!? */
295 return 1;
298 /****************************************************************************************/
300 /*******************
301 * rtFreeFileList() *
302 *******************/
304 void ASM SAVEDS FreeFileList (REGPARAM(a0, struct rtFileList *,selfile))
306 struct rtFileList *last;
308 while (selfile)
310 last = selfile;
311 selfile = selfile->Next;
312 FreeVec (last);
316 /****************************************************************************************/