use a flag to mark when a file is fetched.
[AROS.git] / workbench / libs / asl / basicfuncs.c
blobf5b2aee4a573acd071201ca41281701b88947820
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Basic helpfuncs for Asl.
6 Lang: english
7 */
9 #include <proto/alib.h>
10 #include <proto/exec.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/iffparse.h>
14 #include <proto/diskfont.h>
15 #include <proto/graphics.h>
16 #include <proto/gadtools.h>
17 #include <proto/dos.h>
18 #include <proto/locale.h>
19 #include <proto/workbench.h>
21 #include <exec/lists.h>
22 #include <exec/memory.h>
23 #include <intuition/intuition.h>
24 #include <intuition/screens.h>
25 #include <intuition/classusr.h>
26 #include <intuition/imageclass.h>
27 #include <graphics/gfxbase.h>
28 #include <devices/rawkeycodes.h>
29 #include <prefs/prefhdr.h>
30 #include <prefs/font.h>
31 #include <libraries/iffparse.h>
33 #include <string.h>
35 #include "asl_intern.h"
36 #include "filereqsupport.h"
37 #include "filereqhooks.h"
38 #include "layout.h"
40 #define SDEBUG 0
41 #define DEBUG 0
43 #include <aros/debug.h>
45 /*****************************************************************************************/
47 STATIC BOOL GetRequesterFont(struct LayoutData *, struct AslBase_intern *);
49 #if 0
50 STATIC struct FontPrefs *GetFontPrefs(struct AslBase_intern *);
51 STATIC VOID FreeFontPrefs(struct FontPrefs *, struct AslBase_intern *);
52 #endif
54 /*****************************************************************************************/
56 /* Finds the internal requester data for a requester */
58 struct ReqNode *FindReqNode(APTR req, struct AslBase_intern *AslBase)
60 struct ReqNode *reqnode, *foundreqnode = NULL;
62 ObtainSemaphoreShared( &(AslBase->ReqListSem) );
64 ForeachNode( &(AslBase->ReqList), reqnode)
66 if (reqnode->rn_Req == req)
68 foundreqnode = reqnode;
69 break;
73 ReleaseSemaphore( &(AslBase->ReqListSem) );
75 return (foundreqnode);
78 /*****************************************************************************************/
80 VOID ParseCommonTags
82 struct IntReq *intreq,
83 struct TagItem *taglist,
84 struct AslBase_intern *AslBase
87 struct TagItem *tag;
88 struct TagItem *tstate = taglist;
90 while ((tag = NextTagItem(&tstate)) != NULL)
92 IPTR tidata = tag->ti_Data;
94 /* The tags that are put "in a row" are defined as the same value,
95 and therefore we only use one of them, but the effect is for all of them
98 switch (tag->ti_Tag)
100 case ASLFR_Window:
101 /* case ASLFO_Window:
102 case ASLSM_Window:
103 case ASL_Window: */ /* Obsolete */
104 intreq->ir_Window = (struct Window *)tidata;
105 break;
107 case ASLFR_Screen:
108 /* case ASLFO_Screen:
109 case ASLSM_Screen: */
110 intreq->ir_Screen = (struct Screen *)tidata;
111 break;
113 case ASLFR_PubScreenName:
114 /* case ASLFO_PubScreenName:
115 case ASLSM_PubScreenName: */
116 if (tidata)
117 intreq->ir_PubScreenName = (STRPTR)tidata;
118 break;
120 case ASLFR_PrivateIDCMP:
121 /* case ASLFO_PrivateIDCMP:
122 case ASLSM_PrivateIDCMP: */
123 if (tidata)
124 intreq->ir_Flags |= IF_PRIVATEIDCMP;
125 else
126 intreq->ir_Flags &= ~IF_PRIVATEIDCMP;
127 break;
130 case ASLFR_IntuiMsgFunc:
131 /* case ASLFO_IntuiMsgFunc:
132 case ASLSM_IntuiMsgFunc: */
133 intreq->ir_IntuiMsgFunc = (struct Hook *)tidata;
134 break;
136 case ASLFR_SleepWindow:
137 /* case ASLFO_SleepWindow:
138 case ASLSM_SleepWindow: */
139 if (tidata)
140 intreq->ir_Flags |= IF_SLEEPWINDOW;
141 else
142 intreq->ir_Flags &= ~IF_SLEEPWINDOW;
143 break;
145 case ASLFR_PopToFront:
146 /* case ASLFO_PopToFront:
147 case ASLSM_PopToFront: */
148 if (tidata)
149 intreq->ir_Flags |= IF_POPTOFRONT;
150 else
151 intreq->ir_Flags &= ~IF_POPTOFRONT;
152 break;
154 case ASLFR_Activate:
155 /* case ASLFO_Activate:
156 case ASLSM_Activate: */
157 if (tidata)
158 intreq->ir_Flags &= ~IF_OPENINACTIVE;
159 else
160 intreq->ir_Flags |= IF_OPENINACTIVE;
161 break;
163 case ASLFR_TextAttr:
164 /* case ASLFO_TextAttr:
165 case ASLSM_TextAttr: */
166 intreq->ir_TextAttr = (struct TextAttr *)tidata;
167 break;
169 case ASLFR_Locale:
170 /* case ASLFO_Locale:
171 case ASLSM_Locale: */
172 intreq->ir_Locale = (struct Locale *)tidata;
173 break;
175 case ASLFR_TitleText:
176 /* case ASLFO_TitleText:
177 case ASLSM_TitleText:
178 case ASL_Hail: */ /* Obsolete */
179 if (tidata)
180 intreq->ir_TitleText = (STRPTR)tidata;
181 break;
184 case ASLFR_PositiveText:
185 /* case ASLFO_PositiveText:
186 case ASLSM_PositiveText:
187 case ASL_OKText: */ /* Obsolete */
188 if (tidata)
190 intreq->ir_PositiveText = (STRPTR)tidata;
191 intreq->ir_Flags |= IF_USER_POSTEXT;
193 break;
195 case ASLFR_NegativeText:
196 /* case ASLFO_NegativeText:
197 case ASLSM_NegativeText:
198 case ASL_CancelText: */ /* Obsolete */
199 if (tidata)
201 intreq->ir_NegativeText = (STRPTR)tidata;
202 intreq->ir_Flags |= IF_USER_NEGTEXT;
204 break;
206 case ASLFR_InitialLeftEdge:
207 /* case ASLFO_InitialLeftEdge:
208 case ASLSM_InitialLeftEdge:
209 case ASL_LeftEdge: */ /* Obsolete */
210 intreq->ir_LeftEdge = (UWORD)tidata;
211 break;
213 case ASLFR_InitialTopEdge:
214 /* case ASLFO_InitialTopEdge:
215 case ASLSM_InitialTopEdge:
216 case ASL_TopEdge: */ /* Obsolete */
217 intreq->ir_TopEdge = (UWORD)tidata;
218 break;
220 case ASLFR_InitialWidth:
221 /* case ASLFO_InitialWidth:
222 case ASLSM_InitialWidth:
223 case ASL_Width: */ /* Obsolete */
224 intreq->ir_Width = (UWORD)tidata;
225 break;
227 case ASLFR_InitialHeight:
228 /* case ASLFO_InitialHeight:
229 case ASLSM_InitialHeight:
230 case ASL_Height: */ /* Obsolete */
231 intreq->ir_Height = (UWORD)tidata;
232 break;
234 default:
235 break;
237 } /* switch (tag->ti_Tag) */
239 } /* while ((tag = NextTagItem(&tstate)) != NULL) */
242 /*****************************************************************************************/
244 VOID FreeCommon(struct LayoutData *ld, struct AslBase_intern *AslBase)
246 if (ld)
249 if (ld->ld_IntReq->ir_Catalog) CloseCatalog(ld->ld_IntReq->ir_Catalog);
251 if (ld->ld_Menu)
253 if (ld->ld_Window)
254 ClearMenuStrip(ld->ld_Window);
256 FreeMenus(ld->ld_Menu);
259 if (ld->ld_Window)
261 if (ld->ld_AppWindow)
262 RemoveAppWindow(ld->ld_AppWindow);
263 if (ld->ld_AppMsgPort)
264 DeleteMsgPort(ld->ld_AppMsgPort);
266 if (ld->ld_IntReq->ir_Flags & IF_POPPEDTOFRONT)
268 ld->ld_IntReq->ir_Flags &= ~IF_POPPEDTOFRONT;
269 ScreenToBack(ld->ld_Window->WScreen);
272 if ((ld->ld_IntReq->ir_Flags & IF_PRIVATEIDCMP) || (!ld->ld_IntReq->ir_Window))
274 CloseWindow(ld->ld_Window);
276 else
278 CloseWindowSafely(ld->ld_Window, AslBase);
282 D(bug("Window freed\n"));
284 if (ld->ld_VisualInfo) FreeVisualInfo(ld->ld_VisualInfo);
285 if (ld->ld_Dri) FreeScreenDrawInfo(ld->ld_Screen, ld->ld_Dri);
287 if (ld->ld_ScreenLocked)
288 UnlockPubScreen(NULL, ld->ld_Screen);
290 if (ld->ld_UserData)
291 FreeVec(ld->ld_UserData);
293 if (ld->ld_Font)
294 CloseFont(ld->ld_Font);
296 if (ld->ld_TextAttr.ta_Name)
297 FreeVec(ld->ld_TextAttr.ta_Name);
299 FreeMem(ld, sizeof (struct LayoutData));
303 /*****************************************************************************************/
305 struct LayoutData *AllocCommon
307 ULONG udatasize,
308 struct IntReq *intreq,
309 APTR requester,
310 struct AslBase_intern *AslBase
313 struct Screen *screen = NULL;
314 struct LayoutData *ld;
317 ld = AllocMem(sizeof (struct LayoutData), MEMF_ANY|MEMF_CLEAR);
318 if (!ld)
319 goto failure;
321 /* Save the internal and public requester struct, so that the
322 requester type specific hook may find them */
323 ld->ld_IntReq = intreq;
324 ld->ld_Req = requester;
326 InitRastPort(&(ld->ld_DummyRP));
328 /* We need to lock the screen we should open on to be sure it
329 doesn't go away
332 /* Find screen on which to open window */
334 screen = intreq->ir_Screen;
335 if (!screen && intreq->ir_PubScreenName)
337 if ((screen = LockPubScreen(intreq->ir_PubScreenName)))
339 ld->ld_ScreenLocked = TRUE;
342 if (!screen && intreq->ir_Window)
344 screen = intreq->ir_Window->WScreen;
346 if (!screen && !intreq->ir_PubScreenName)
348 if ((screen = LockPubScreen(NULL)))
350 ld->ld_ScreenLocked = TRUE;
354 if (!screen) goto failure;
356 ld->ld_Screen = screen;
358 if (!(ld->ld_Dri = GetScreenDrawInfo(screen))) goto failure;
360 if (!(ld->ld_VisualInfo = GetVisualInfoA(screen, NULL))) goto failure;
362 ld->ld_WBorLeft = screen->WBorLeft;
363 ld->ld_WBorTop = screen->WBorTop + screen->Font->ta_YSize + 1;
364 ld->ld_WBorRight = screen->WBorRight;
365 ld->ld_WBorBottom = 16;
368 struct TagItem sysi_tags[] =
370 {SYSIA_DrawInfo , (IPTR)ld->ld_Dri },
371 {SYSIA_Which , SIZEIMAGE },
372 {TAG_DONE }
375 Object *im;
377 if ((im = NewObjectA(NULL, SYSICLASS, sysi_tags)))
379 IPTR height;
381 if (GetAttr(IA_Height, im, &height))
383 ld->ld_WBorBottom = height;
385 DisposeObject(im);
390 if(GetBitMapAttr(screen->RastPort.BitMap, BMA_DEPTH) > 8) ld->ld_TrueColor = TRUE;
392 if (!(ld->ld_UserData = AllocVec(udatasize, MEMF_ANY|MEMF_CLEAR)))
393 goto failure;
395 if (!GetRequesterFont(ld, ASLB(AslBase)))
396 goto failure;
398 SetFont( &(ld->ld_DummyRP), ld->ld_Font );
400 if (LocaleBase)
402 struct TagItem tags[] =
404 {OC_BuiltInLanguage , (IPTR)"english"},
405 {OC_Version , 2 },
406 {TAG_DONE }
409 intreq->ir_Catalog = OpenCatalogA(intreq->ir_Locale, "System/Libs/asl.catalog", tags);
412 return (ld);
414 failure:
415 FreeCommon(ld, ASLB(AslBase));
417 return (NULL);
421 /*****************************************************************************************/
423 #define SKIPLONG(ptr, num) ptr += sizeof (LONG) * num
425 #define CONVBYTE(ptr, dest) dest = *ptr ++
427 #define SKIPBYTE(ptr) ptr ++;
429 #define CONVWORD(ptr, dest) dest = ptr[0] << 8 | ptr[1]; \
430 ptr += sizeof (WORD);
432 /*****************************************************************************************/
434 #if 0
436 STATIC struct FontPrefs *GetFontPrefs(struct AslBase_intern *AslBase)
438 struct IFFHandle *iff;
439 struct Library *IFFParseBase;
441 struct StoredProperty *sp;
443 struct FontPrefs *fp = NULL;
445 IFFParseBase = OpenLibrary("iffparse.library", 0);
446 if (IFFParseBase)
448 iff = AllocIFF();
449 if (iff)
452 iff->iff_Stream = (IPTR)Open("ENV:Sys/font.prefs", MODE_OLDFILE);
453 if (iff->iff_Stream)
455 InitIFFasDOS(iff);
457 if (OpenIFF(iff, IFFF_READ) == 0)
459 PropChunk(iff, ID_PREF, ID_FONT);
462 if (ParseIFF(iff, IFFPARSE_SCAN) != 0)
465 sp = FindProp(iff, ID_PREF, ID_FONT);
466 if (sp)
469 fp = AllocMem(sizeof (struct FontPrefs), MEMF_ANY);
470 if (fp)
472 UBYTE *ptr;
473 STRPTR fontname;
476 /* Set ptr to start of struct FontPrefs */
477 ptr = sp->sp_Data;
479 /* Skip 4 first reserved longs */
480 SKIPLONG(ptr, 4);
481 CONVBYTE(ptr, fp->fp_FrontPen);
482 CONVBYTE(ptr, fp->fp_BackPen);
483 CONVBYTE(ptr, fp->fp_DrawMode);
485 CONVWORD(ptr, fp->fp_TextAttr.ta_YSize);
486 CONVBYTE(ptr, fp->fp_TextAttr.ta_Style);
487 CONVBYTE(ptr, fp->fp_TextAttr.ta_Flags);
490 fontname = AllocVec( strlen(ptr) + 1, MEMF_ANY);
491 if (fontname)
493 strcpy(fontname, ptr);
495 fp->fp_TextAttr.ta_Name = fontname;
497 else
499 FreeMem(fp, sizeof (struct FontPrefs));
500 fp = NULL;
503 } /* if (tattr) */
505 } /* if (sp) */
507 } /* if (ParseIFF(iff, IFFPARSE_SCAN) != 0) */
508 CloseIFF(iff);
510 } /* if (OpenIFF(iff)) */
511 Close( (BPTR)iff->iff_Stream );
513 } /* if (iff->iff_Stream) */
514 FreeIFF(iff);
516 } /* if (iff) */
517 CloseLibrary(IFFParseBase);
519 } /* if (IFFParseBase) */
521 return (fp);
523 } /* GetFontPrefs() */
525 #endif
527 /*****************************************************************************************/
529 #if 0
531 STATIC VOID FreeFontPrefs(struct FontPrefs *fp, struct AslBase_intern *AslBase)
534 FreeVec(fp->fp_TextAttr.ta_Name);
535 FreeMem(fp, sizeof (struct FontPrefs));
539 #endif
541 /*****************************************************************************************/
543 BOOL GetRequesterFont(struct LayoutData *ld, struct AslBase_intern *AslBase)
545 struct TextFont *font = NULL;
547 struct TextAttr *usedattr, askattr;
549 BOOL success = FALSE;
551 static struct TextAttr topaz8 = {"topaz.font", 8, 0, 0 };
553 /* Default to satisfy GCC */
554 usedattr = &topaz8;
557 Open the font we should use in the GUI.
558 First look for a user supplied TextAttr.
559 If not present, try to get the font preferences from ENV:Sys/font.prefs
560 If this fails, we fall back to topaz 8
563 /* Is there a user supplied font */
564 usedattr = ld->ld_IntReq->ir_TextAttr;
566 if (usedattr)
568 font = OpenDiskFont (usedattr);
571 /* If not, try screen font */
573 if (!font)
575 usedattr = ld->ld_Screen->Font;
576 if (usedattr)
578 font = OpenDiskFont (usedattr);
582 #if 0
583 /* If no font has been opened yet, try the preferences one */
584 if (!font)
586 struct FontPrefs *fprefs;
588 fprefs = GetFontPrefs(ASLB(AslBase));
589 if (fprefs)
591 D(bug("Fontprefs found\n"));
593 D(bug("Name: %s, YSize :%d", fprefs->fp_TextAttr.ta_Name, fprefs->fp_TextAttr.ta_YSize));
595 usedattr = &(fprefs->fp_TextAttr);
596 font = OpenDiskFont(usedattr);
598 if (!font)
600 FreeFontPrefs(fprefs, ASLB(AslBase));
604 #endif
606 /* No success, so try system default font */
608 if (!font)
610 usedattr = &askattr;
612 SetFont(&(ld->ld_DummyRP), GfxBase->DefaultFont);
613 AskFont(&(ld->ld_DummyRP), usedattr);
615 font = OpenDiskFont(usedattr);
618 /* Yet no font, try topaz 8 */
620 if (!font)
622 usedattr = &topaz8;
624 /* Here we should really use OpenDiskFont, but
625 * since AROS can't render diskfonts yet, we must use OpenFont()
628 font = OpenFont(usedattr);
631 if (font)
633 STRPTR fontname;
634 /* We have to store the used textattr for later */
636 fontname = AllocVec (strlen (usedattr->ta_Name) + 1, MEMF_ANY);
638 if (fontname)
640 strcpy (fontname, usedattr->ta_Name);
642 ld->ld_TextAttr.ta_Name = fontname;
643 ld->ld_TextAttr.ta_YSize = usedattr->ta_YSize;
644 ld->ld_TextAttr.ta_Style = usedattr->ta_Style;
645 ld->ld_TextAttr.ta_Flags = usedattr->ta_Flags;
647 ld->ld_Font = font;
649 success = TRUE;
652 return (success);
655 /*****************************************************************************************/
657 BOOL HandleEvents(struct LayoutData *ld, struct AslReqInfo *reqinfo, struct AslBase_intern *AslBase)
659 struct IntReq *intreq = ld->ld_IntReq;
660 struct IntFileReq *ifreq = (struct IntFileReq *)ld->ld_IntReq;
661 APTR req = ld->ld_Req;
662 struct IntuiMessage *imsg;
663 struct MsgPort *port;
664 BOOL success = TRUE;
665 BOOL terminated = FALSE;
667 EnterFunc(bug("HandleEvents(ld=%p, reqinfo=%p)\n", ld, reqinfo));
668 port = ld->ld_Window->UserPort;
670 if (!port)
671 port = ld->ld_Window->WindowPort;
673 while (!terminated)
675 if (ld->ld_AppMsgPort)
676 Wait((1L << port->mp_SigBit) | (1L << ld->ld_AppMsgPort->mp_SigBit));
677 else
678 Wait((1L << port->mp_SigBit));
680 while ((imsg = (struct IntuiMessage *)GetMsg(port)))
682 if ((imsg->IDCMPWindow == ld->ld_Window) ||
683 (imsg->IDCMPWindow == ld->ld_Window2))
685 switch (imsg->Class)
687 case IDCMP_MOUSEMOVE:
688 break;
690 case IDCMP_NEWSIZE:
691 ld->ld_Command = LDCMD_LAYOUT;
692 CallHookPkt(&(reqinfo->GadgetryHook), ld, ASLB(AslBase));
693 break;
695 case IDCMP_REFRESHWINDOW:
696 BeginRefresh(imsg->IDCMPWindow);
697 EndRefresh(imsg->IDCMPWindow, TRUE);
698 break;
700 default:
701 /* Call the requester specific hook to handle events */
702 ld->ld_Command = LDCMD_HANDLEEVENTS;
703 ld->ld_Event = imsg;
705 success = CallHookPkt( &(reqinfo->GadgetryHook), ld, ASLB(AslBase));
706 if (success == LDRET_FINISHED)
708 success = TRUE;
709 terminated = TRUE;
711 if (!success)
713 success = FALSE;
714 terminated = TRUE;
716 break;
719 } /* switch (imsg->Class) */
721 } /* if (imsg->IDCMPWindow is ld->ld_Window or ld->ld_Window2) */
722 else if (intreq->ir_IntuiMsgFunc)
724 #ifdef __MORPHOS__
725 REG_A4 = (ULONG)intreq->ir_BasePtr; /* Compatability */
726 REG_A0 = (ULONG)intreq->ir_IntuiMsgFunc;
727 REG_A2 = (ULONG)req;
728 REG_A1 = (ULONG)imsg;
729 (*MyEmulHandle->EmulCallDirect68k)(intreq->ir_IntuiMsgFunc->h_Entry);
730 #else
731 CallHookPkt(intreq->ir_IntuiMsgFunc, req, imsg);
732 #endif
734 else if ((intreq->ir_ReqType == ASL_FileRequest) && ifreq->ifr_HookFunc && (ifreq->ifr_Flags1 & FRF_INTUIFUNC))
736 ifreq->ifr_HookFunc(FRF_INTUIFUNC, imsg, req);
738 ReplyMsg((struct Message *)imsg);
740 } /* while ((imsg = (struct IntuiMessage *)GetMsg(port))) */
742 while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort)))
744 ld->ld_Command = LDCMD_HANDLEAPPWINDOW;
745 success = CallHookPkt( &(reqinfo->GadgetryHook), ld, ASLB(AslBase));
746 ReplyMsg ((struct Message *) ld->ld_AppMsg);
748 /* Do Intuition stuff only now, so we can have replied message quite early */
749 RefreshGadgets(((struct Gadget *)((struct FRUserData *)ld->ld_UserData)->Listview), ld->ld_Window, (struct Requester *)ld->ld_Req);
750 ActivateWindow(ld->ld_Window);
752 if (ld->ld_ForeignerFiles)
754 FRDropFromDifferentDrawersRequester(ld, AslBase);
755 MyFreeVecPooled(ld->ld_ForeignerFiles, AslBase);
756 ld->ld_ForeignerFiles = NULL;
759 if (success == LDRET_FINISHED)
761 success = TRUE;
762 terminated = TRUE;
764 if (!success)
766 success = FALSE;
767 terminated = TRUE;
769 } /* while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort))) */
770 } /* while (!terminated) */
772 ReturnBool ("HandleEvents", success);
774 } /* HandleEvents() */
776 /*****************************************************************************************/
778 UWORD BiggestTextLength(STRPTR *strarray,
779 UWORD numstrings,
780 struct RastPort *rp,
781 struct AslBase_intern * AslBase)
784 UWORD i, w = 0, new_w;
786 for (i = 0; strarray[i] && i < numstrings; i ++)
788 new_w = TextLength(rp, strarray[i], strlen(strarray[i]));
789 if (new_w > w)
791 w = new_w;
794 return (w);
797 /*****************************************************************************************/
799 /* Strip special info from the requester structure */
801 VOID StripRequester(APTR req, UWORD reqtype, struct AslBase_intern *AslBase)
803 switch (reqtype)
805 case ASL_FileRequest:
807 #undef GetFR
808 #define GetFR(r) ((struct FileRequester *)r)
811 * We can`t free it here, because it`s called by FreeAslRequest
812 * and AslRequest may have been overtaken by some other patch.
813 * Original FreeAslRequest doesn't free them.
814 * With MFR+mungwall it crashed here.
815 * It's freeed anyway when the Pool is deleted.
817 // dprintf("StripRequester: drawer 0x%lx\n",GetFR(req)->fr_Drawer);
818 // MyFreeVecPooled(GetFR(req)->fr_Drawer, AslBase);
819 GetFR(req)->fr_Drawer = NULL;
821 // dprintf("StripRequester: file 0x%lx\n",GetFR(req)->fr_File);
822 // MyFreeVecPooled(GetFR(req)->fr_File, AslBase);
823 GetFR(req)->fr_File = NULL;
825 // dprintf("StripRequester: pattern 0x%lx\n",GetFR(req)->fr_Pattern);
826 // MyFreeVecPooled(GetFR(req)->fr_Pattern, AslBase);
827 GetFR(req)->fr_Pattern = NULL;
829 // dprintf("StripRequester: arglist 0x%lx\n",GetFR(req)->fr_ArgList);
830 if (GetFR(req)->fr_ArgList)
832 struct WBArg *wbarg;
833 BPTR lock = GetFR(req)->fr_ArgList->wa_Lock;
835 // dprintf("StripRequester: lock 0x%lx\n",lock);
836 if (lock) UnLock(lock);
838 // dprintf("StripRequester: numargs 0x%lx\n",GetFR(req)->fr_NumArgs);
840 for (wbarg = GetFR(req)->fr_ArgList; GetFR(req)->fr_NumArgs --; wbarg ++)
842 // dprintf("StripRequester: wbarg 0x%lx\n",wbarg);
843 MyFreeVecPooled(wbarg->wa_Name, AslBase);
846 // dprintf("StripRequester: free arglist\n");
847 MyFreeVecPooled(GetFR(req)->fr_ArgList, AslBase);
848 GetFR(req)->fr_ArgList = NULL;
852 break;
854 case ASL_FontRequest:
856 #undef GetFO
857 #define GetFO(r) ((struct FontRequester *)r)
859 MyFreeVecPooled(GetFO(req)->fo_TAttr.tta_Name, AslBase);
860 GetFO(req)->fo_TAttr.tta_Name = NULL;
862 break;
864 case ASL_ScreenModeRequest:
865 break;
870 /*****************************************************************************************/
872 WORD CountNodes(struct List *list, WORD flag)
874 struct Node *node;
875 WORD result = 0;
877 ForeachNode(list, node)
879 if ((node->ln_Pri & flag) == flag) result++;
882 return result;
885 /*****************************************************************************************/
887 struct Node *FindListNode(struct List *list, WORD which)
889 struct Node *node = NULL;
891 if (which >= 0)
893 for(node = list->lh_Head; node->ln_Succ && which; node = node->ln_Succ, which--)
896 if (!node->ln_Succ) node = NULL;
899 return node;
902 /*****************************************************************************************/
904 void SortInNode(APTR req, struct List *list, struct Node *node,
905 WORD (*compare)(APTR req, APTR node1, APTR node2, struct AslBase_intern *AslBase),
906 struct AslBase_intern *AslBase)
908 struct Node *prevnode = NULL;
909 struct Node *checknode;
911 ForeachNode(list, checknode)
913 if (compare(req, node, checknode, AslBase) < 0) break;
915 prevnode = checknode;
918 Insert(list, node, prevnode);
921 /*****************************************************************************************/
923 APTR MyAllocVecPooled(APTR pool, IPTR size, struct AslBase_intern *AslBase)
925 IPTR *mem;
927 //dprintf("MyAllocVecPooled: pool 0x%lx size %ld\n",pool,size);
929 size += sizeof(APTR) * 2;
931 if ((mem = AllocPooled(pool, size)))
933 //dprintf("MyAllocVecPooled: pool 0x%lx mem 0x%lx size %ld\n",pool,mem,size);
934 *mem++ = (IPTR)pool;
935 *mem++ = size;
936 //dprintf("MyAllocVecPooled: mem 0x%lx\n");
939 return mem;
942 /*****************************************************************************************/
944 void MyFreeVecPooled(APTR mem, struct AslBase_intern *AslBase)
946 IPTR *imem = (IPTR *)mem;
948 if (mem)
950 IPTR size = *--imem;
951 APTR pool = (APTR)*--imem;
953 //dprintf("MyFreeVecPooled: pool 0x%lx imem 0x%lx size %ld\n",pool,imem,size);
955 FreePooled(pool, imem, size);
959 /*****************************************************************************************/
961 char *PooledCloneString(const char *name1, const char *name2, APTR pool,
962 struct AslBase_intern *AslBase)
964 char *clone;
965 WORD len1 = strlen(name1) + 1;
966 WORD len2 = name2 ? strlen(name2) : 0;
968 if ((clone = AllocPooled(pool, len1 + len2)))
970 CopyMem(name1, clone, len1);
971 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
974 return clone;
977 /*****************************************************************************************/
979 char *PooledCloneStringLen(const char *name1, ULONG len1, const char *name2, ULONG len2, APTR pool,
980 struct AslBase_intern *AslBase)
982 char *clone;
983 if ((clone = AllocPooled(pool, len1 + len2 + 1)))
985 CopyMem(name1, clone, len1);
986 clone[len1] = '\0';
987 if (name2)
989 CopyMem(name2, clone + len1, len2);
991 clone[len1+len2] = '\0';
993 return clone;
996 /*****************************************************************************************/
998 char *VecCloneString(const char *name1, const char *name2, struct AslBase_intern *AslBase)
1000 char *clone;
1001 WORD len1 = strlen(name1) + 1;
1002 WORD len2 = name2 ? strlen(name2) : 0;
1004 if ((clone = AllocVec(len1 + len2, MEMF_PUBLIC)))
1006 CopyMem(name1, clone, len1);
1007 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1010 return clone;
1013 /*****************************************************************************************/
1015 char *VecPooledCloneString(const char *name1, const char *name2, APTR pool, struct AslBase_intern *AslBase)
1017 char *clone;
1018 WORD len1 = strlen(name1) + 1;
1019 WORD len2 = name2 ? strlen(name2) : 0;
1021 if ((clone = MyAllocVecPooled(pool, len1 + len2, AslBase)))
1023 CopyMem(name1, clone, len1);
1024 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1027 return clone;
1030 /*****************************************************************************************/
1032 AROS_UFH2 (void, puttostr,
1033 AROS_UFHA(UBYTE, chr, D0),
1034 AROS_UFHA(STRPTR *,strPtrPtr,A3)
1037 AROS_USERFUNC_INIT
1038 *(*strPtrPtr)= chr;
1039 (*strPtrPtr) ++;
1040 AROS_USERFUNC_EXIT
1043 /*****************************************************************************************/
1045 /* This is used for printing out fib_Size, which is why
1046 * is takes a IPTR instead of a ULONG
1048 char *PooledUIntegerToString(IPTR value, APTR pool, struct AslBase_intern *AslBase)
1050 char buffer[30];
1051 char *str = buffer;
1052 char *clone;
1053 WORD len;
1055 /* Create the text */
1057 RawDoFmt("%iu", (RAWARG)&value, (VOID_FUNC)AROS_ASMSYMNAME(puttostr), &str);
1059 len = strlen(buffer) + 1;
1061 if ((clone = AllocPooled(pool, len)))
1063 CopyMem(buffer, clone, len);
1066 return clone;
1069 /*****************************************************************************************/
1071 void CloseWindowSafely(struct Window *window, struct AslBase_intern *AslBase)
1073 struct IntuiMessage *msg;
1074 struct Node *succ;
1076 Forbid();
1078 if(window->UserPort != NULL)
1080 msg = (struct IntuiMessage *)window->UserPort->mp_MsgList.lh_Head;
1082 while((succ = msg->ExecMessage.mn_Node.ln_Succ))
1084 if(msg->IDCMPWindow == window)
1086 Remove((struct Node *)msg);
1087 ReplyMsg((struct Message *)msg);
1090 msg = (struct IntuiMessage *)succ;
1094 window->UserPort = NULL;
1096 ModifyIDCMP(window, 0);
1098 Permit();
1100 CloseWindow(window);
1103 /*****************************************************************************************/
1105 AROS_UFH3(ULONG, StringEditFunc,
1106 AROS_UFHA(struct Hook *, hook, A0),
1107 AROS_UFHA(struct SGWork *, sgw, A2),
1108 AROS_UFHA(ULONG *, command, A1))
1110 AROS_USERFUNC_INIT
1112 ULONG retcode = 0;
1114 switch(*command)
1116 case SGH_KEY:
1117 retcode = 1;
1118 switch(sgw->IEvent->ie_Code)
1120 case RAWKEY_PAGEUP:
1121 case RAWKEY_PAGEDOWN:
1122 case RAWKEY_HOME:
1123 case RAWKEY_END:
1124 case RAWKEY_ESCAPE:
1125 case RAWKEY_NM_WHEEL_UP:
1126 case RAWKEY_NM_WHEEL_DOWN:
1127 sgw->Code = STRINGCODE_NOP;
1128 sgw->Actions = SGA_END | SGA_REUSE;
1129 break;
1131 case CURSORUP:
1132 sgw->EditOp = EO_SPECIAL;
1133 sgw->Code = STRINGCODE_CURSORUP;
1134 sgw->Actions = SGA_END;
1135 break;
1137 case CURSORDOWN:
1138 sgw->EditOp = EO_SPECIAL;
1139 sgw->Code = STRINGCODE_CURSORDOWN;
1140 sgw->Actions = SGA_END;
1141 break;
1143 break;
1147 return retcode;
1149 AROS_USERFUNC_EXIT
1153 /*****************************************************************************************/
1155 void PaintInnerFrame(struct RastPort *rp, struct DrawInfo *dri, Object *frameobj,
1156 struct IBox *framebox, struct IBox *innerbox, ULONG pen,
1157 struct AslBase_intern *AslBase)
1159 struct impFrameBox fmsg;
1160 struct IBox cbox;
1161 struct IBox fbox;
1162 WORD x1, y1, x2, y2;
1163 WORD ix1, iy1, ix2, iy2;
1165 cbox.Left = framebox->Left;
1166 cbox.Top = framebox->Top;
1167 cbox.Width = framebox->Width;
1168 cbox.Height = framebox->Height;
1170 fmsg.MethodID = IM_FRAMEBOX;
1171 fmsg.imp_ContentsBox = &cbox;
1172 fmsg.imp_FrameBox = &fbox;
1173 fmsg.imp_DrInfo = dri;
1174 fmsg.imp_FrameFlags = 0;
1176 DoMethodA(frameobj, (Msg)&fmsg);
1178 SetABPenDrMd(rp, pen, 0, JAM1);
1180 x1 = fbox.Left;
1181 y1 = fbox.Top;
1182 x2 = x1 + fbox.Width - 1;
1183 y2 = y1 + fbox.Height - 1;
1185 ix1 = cbox.Left;
1186 iy1 = cbox.Top;
1187 ix2 = ix1 + cbox.Width - 1;
1188 iy2 = iy1 + cbox.Height - 1;
1190 ix1 += (ix1 - x1);
1191 iy1 += (iy1 - y1);
1192 ix2 += (ix2 - x2);
1193 iy2 += (iy2 - y2);
1195 x1 = innerbox->Left - 1;
1196 y1 = innerbox->Top - 1;
1197 x2 = innerbox->Left + innerbox->Width;
1198 y2 = innerbox->Top + innerbox->Height;
1200 RectFill(rp, ix1, iy1, ix2, y1);
1201 RectFill(rp, ix1, iy1, x1, iy2);
1202 RectFill(rp, x2, iy1, ix2, iy2);
1203 RectFill(rp, ix1, y2, ix2, iy2);
1207 /*****************************************************************************************/
1209 void PaintBoxFrame(struct RastPort *rp, struct IBox *outerbox, struct IBox *innerbox,
1210 ULONG pen, struct AslBase_intern *AslBase)
1212 WORD x1, y1, x2, y2;
1213 WORD ix1, iy1, ix2, iy2;
1215 ix1 = outerbox->Left;
1216 iy1 = outerbox->Top - 1;
1217 ix2 = outerbox->Left + outerbox->Width - 1;
1218 iy2 = outerbox->Top + outerbox->Height - 1;
1220 x1 = innerbox->Left - 1;
1221 y1 = innerbox->Top - 1;
1222 x2 = innerbox->Left + innerbox->Width;
1223 y2 = innerbox->Top + innerbox->Height;
1225 SetABPenDrMd(rp, pen, 0, JAM1);
1227 RectFill(rp, ix1, iy1, ix2, y1);
1228 RectFill(rp, ix1, iy1, x1, iy2);
1229 RectFill(rp, x2, iy1, ix2, iy2);
1230 RectFill(rp, ix1, y2, ix2, iy2);
1234 /*****************************************************************************************/