Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / reqtools / filereqalloc.c
blob8915a8523e6ae09690233ff31ea02175887cbcf6
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 *)(((LONG)&fibspace[3] >> 2) << 2);
189 struct TagItem *tag;
190 const struct TagItem *tstate = taglist;
191 struct RealFileRequester *freq;
192 struct ReqEntry *entry, *curr;
193 struct BufferData *buff;
194 struct Screen *scr;
195 IPTR tagdata;
197 /* parse tags */
198 while ((tag = NextTagItem (&tstate)))
200 tagdata = tag->ti_Data;
201 if (tag->ti_Tag > RT_TagBase)
203 switch (tag->ti_Tag)
205 case RTFI_Dir:
206 FreeReqBuffer (req);
207 strcpy (((struct RealFileRequester *)req)->dirname, (char *)tagdata);
208 break;
210 case RTFI_MatchPat:
211 strcpy (((struct RealFileRequester *)req)->patstr, (char *)tagdata);
212 break;
214 case RTFI_AddEntry:
215 case RTFI_RemoveEntry:
216 freq = (struct RealFileRequester *)req;
217 buff = &(freq->buff);
218 if (!buff->firstname) return (TRUE);
219 if (tag->ti_Tag == RTFI_AddEntry)
221 Examine ((BPTR)tagdata, fib);
222 return ((LONG)(AddEntry (NULL, buff, fib->fib_FileName, fib->fib_Size,
223 (fib->fib_EntryType > 0)
224 ? buff->directory_id : buff->file_id) != NULL));
226 else
228 entry = FindEntry (buff, (char *)tagdata, -1, -1, NULL, 0);
229 curr = (struct ReqEntry *)entry->re_Next;
230 if (!curr || Stricmp ((char *)tagdata, entry->re_Next->ln_Name))
231 return( 0 );
232 entry->re_Next = curr->re_Next;
233 FreeVecPooled (buff->pool, curr);
235 break;
237 case RTFO_FontName:
238 strcpy (((struct RealFontRequester *)req)->fontname, (char *)tagdata);
239 break;
241 case RTFO_FontHeight:
242 ((struct RealFontRequester *)req)->Attr.ta_YSize = tagdata;
243 break;
245 case RTFO_FontStyle:
246 ((struct RealFontRequester *)req)->Attr.ta_Style = tagdata;
247 break;
249 case RTFO_FontFlags:
250 ((struct RealFontRequester *)req)->Attr.ta_Flags = tagdata;
251 break;
253 case RTSC_ModeFromScreen:
254 scr = (struct Screen *)tagdata;
255 ((SC_REQ)req)->DisplayID = GetVPModeID (&scr->ViewPort);
256 ((SC_REQ)req)->DisplayWidth = scr->Width;
257 ((SC_REQ)req)->DisplayHeight = scr->Height;
258 ((SC_REQ)req)->DisplayDepth = scr->BitMap.Depth;
259 ((SC_REQ)req)->AutoScroll = (scr->Flags & AUTOSCROLL);
260 break;
262 case RTSC_DisplayID:
263 ((SC_REQ)req)->DisplayID = tagdata & ~(0x00000440);
264 ((SC_REQ)req)->DisplayWidth = ((SC_REQ)req)->DisplayHeight
265 = ((SC_REQ)req)->DisplayDepth = 0xffff;
266 break;
268 case RTSC_DisplayWidth:
269 ((SC_REQ)req)->DisplayWidth = tagdata;
270 break;
272 case RTSC_DisplayHeight:
273 ((SC_REQ)req)->DisplayHeight = tagdata;
274 break;
276 case RTSC_DisplayDepth:
277 ((SC_REQ)req)->DisplayDepth = tagdata;
278 break;
280 case RTSC_OverscanType:
281 ((SC_REQ)req)->OverscanType = tagdata;
282 break;
284 case RTSC_AutoScroll:
285 ((SC_REQ)req)->AutoScroll = tagdata;
286 break;
288 } /* switch (tag->ti_Tag) */
290 } /* if (tag->ti_Tag > RT_TagBase) */
292 } /* while ((tag = NextTagItem (&tstate))) */
294 #warning There was a missing return. For AROS I added return 1!?
296 return 1;
299 /****************************************************************************************/
301 /*******************
302 * rtFreeFileList() *
303 *******************/
305 void ASM SAVEDS FreeFileList (REGPARAM(a0, struct rtFileList *,selfile))
307 struct rtFileList *last;
309 while (selfile)
311 last = selfile;
312 selfile = selfile->Next;
313 FreeVec (last);
317 /****************************************************************************************/