grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / asl / basicfuncs.c
blobe0cd55269517a5cc9775ab2553b7cb01ab886f53
1 /*
2 Copyright © 1995-2015, 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 APTR req = ld->ld_Req;
661 struct IntuiMessage *imsg;
662 struct MsgPort *port;
663 BOOL success = TRUE;
664 BOOL terminated = FALSE;
666 EnterFunc(bug("HandleEvents(ld=%p, reqinfo=%p)\n", ld, reqinfo));
667 port = ld->ld_Window->UserPort;
669 while (!terminated)
671 if (ld->ld_AppMsgPort)
672 Wait((1L << port->mp_SigBit) | (1L << ld->ld_AppMsgPort->mp_SigBit));
673 else
674 Wait((1L << port->mp_SigBit));
676 while ((imsg = (struct IntuiMessage *)GetMsg(port)))
678 if ((imsg->IDCMPWindow == ld->ld_Window) ||
679 (imsg->IDCMPWindow == ld->ld_Window2))
681 switch (imsg->Class)
683 case IDCMP_MOUSEMOVE:
684 break;
686 case IDCMP_NEWSIZE:
687 ld->ld_Command = LDCMD_LAYOUT;
688 CallHookPkt(&(reqinfo->GadgetryHook), ld, ASLB(AslBase));
689 break;
691 case IDCMP_REFRESHWINDOW:
692 BeginRefresh(imsg->IDCMPWindow);
693 EndRefresh(imsg->IDCMPWindow, TRUE);
694 break;
696 default:
697 /* Call the requester specific hook to handle events */
698 ld->ld_Command = LDCMD_HANDLEEVENTS;
699 ld->ld_Event = imsg;
701 success = CallHookPkt( &(reqinfo->GadgetryHook), ld, ASLB(AslBase));
702 if (success == LDRET_FINISHED)
704 success = TRUE;
705 terminated = TRUE;
707 if (!success)
709 success = FALSE;
710 terminated = TRUE;
712 break;
715 } /* switch (imsg->Class) */
717 } /* if (imsg->IDCMPWindow is ld->ld_Window or ld->ld_Window2) */
718 else if (intreq->ir_IntuiMsgFunc)
720 #ifdef __MORPHOS__
721 REG_A4 = (ULONG)intreq->ir_BasePtr; /* Compatability */
722 REG_A0 = (ULONG)intreq->ir_IntuiMsgFunc;
723 REG_A2 = (ULONG)req;
724 REG_A1 = (ULONG)imsg;
725 (*MyEmulHandle->EmulCallDirect68k)(intreq->ir_IntuiMsgFunc->h_Entry);
726 #else
727 CallHookPkt(intreq->ir_IntuiMsgFunc, req, imsg);
728 #endif
730 ReplyMsg((struct Message *)imsg);
732 } /* while ((imsg = (struct IntuiMessage *)GetMsg(port))) */
734 while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort)))
736 ld->ld_Command = LDCMD_HANDLEAPPWINDOW;
737 success = CallHookPkt( &(reqinfo->GadgetryHook), ld, ASLB(AslBase));
738 ReplyMsg ((struct Message *) ld->ld_AppMsg);
740 /* Do Intuition stuff only now, so we can have replied message quite early */
741 RefreshGadgets(((struct Gadget *)((struct FRUserData *)ld->ld_UserData)->Listview), ld->ld_Window, (struct Requester *)ld->ld_Req);
742 ActivateWindow(ld->ld_Window);
744 if (ld->ld_ForeignerFiles)
746 FRDropFromDifferentDrawersRequester(ld, AslBase);
747 MyFreeVecPooled(ld->ld_ForeignerFiles, AslBase);
748 ld->ld_ForeignerFiles = NULL;
751 if (success == LDRET_FINISHED)
753 success = TRUE;
754 terminated = TRUE;
756 if (!success)
758 success = FALSE;
759 terminated = TRUE;
761 } /* while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort))) */
762 } /* while (!terminated) */
764 ReturnBool ("HandleEvents", success);
766 } /* HandleEvents() */
768 /*****************************************************************************************/
770 UWORD BiggestTextLength(STRPTR *strarray,
771 UWORD numstrings,
772 struct RastPort *rp,
773 struct AslBase_intern * AslBase)
776 UWORD i, w = 0, new_w;
778 for (i = 0; strarray[i] && i < numstrings; i ++)
780 new_w = TextLength(rp, strarray[i], strlen(strarray[i]));
781 if (new_w > w)
783 w = new_w;
786 return (w);
789 /*****************************************************************************************/
791 /* Strip special info from the requester structure */
793 VOID StripRequester(APTR req, UWORD reqtype, struct AslBase_intern *AslBase)
795 switch (reqtype)
797 case ASL_FileRequest:
799 #undef GetFR
800 #define GetFR(r) ((struct FileRequester *)r)
803 * We can`t free it here, because it`s called by FreeAslRequest
804 * and AslRequest may have been overtaken by some other patch.
805 * Original FreeAslRequest doesn't free them.
806 * With MFR+mungwall it crashed here.
807 * It's freeed anyway when the Pool is deleted.
809 // dprintf("StripRequester: drawer 0x%lx\n",GetFR(req)->fr_Drawer);
810 // MyFreeVecPooled(GetFR(req)->fr_Drawer, AslBase);
811 GetFR(req)->fr_Drawer = NULL;
813 // dprintf("StripRequester: file 0x%lx\n",GetFR(req)->fr_File);
814 // MyFreeVecPooled(GetFR(req)->fr_File, AslBase);
815 GetFR(req)->fr_File = NULL;
817 // dprintf("StripRequester: pattern 0x%lx\n",GetFR(req)->fr_Pattern);
818 // MyFreeVecPooled(GetFR(req)->fr_Pattern, AslBase);
819 GetFR(req)->fr_Pattern = NULL;
821 // dprintf("StripRequester: arglist 0x%lx\n",GetFR(req)->fr_ArgList);
822 if (GetFR(req)->fr_ArgList)
824 struct WBArg *wbarg;
825 BPTR lock = GetFR(req)->fr_ArgList->wa_Lock;
827 // dprintf("StripRequester: lock 0x%lx\n",lock);
828 if (lock) UnLock(lock);
830 // dprintf("StripRequester: numargs 0x%lx\n",GetFR(req)->fr_NumArgs);
832 for (wbarg = GetFR(req)->fr_ArgList; GetFR(req)->fr_NumArgs --; wbarg ++)
834 // dprintf("StripRequester: wbarg 0x%lx\n",wbarg);
835 MyFreeVecPooled(wbarg->wa_Name, AslBase);
838 // dprintf("StripRequester: free arglist\n");
839 MyFreeVecPooled(GetFR(req)->fr_ArgList, AslBase);
840 GetFR(req)->fr_ArgList = NULL;
844 break;
846 case ASL_FontRequest:
848 #undef GetFO
849 #define GetFO(r) ((struct FontRequester *)r)
851 MyFreeVecPooled(GetFO(req)->fo_TAttr.tta_Name, AslBase);
852 GetFO(req)->fo_TAttr.tta_Name = NULL;
854 break;
856 case ASL_ScreenModeRequest:
857 break;
862 /*****************************************************************************************/
864 WORD CountNodes(struct List *list, WORD flag)
866 struct Node *node;
867 WORD result = 0;
869 ForeachNode(list, node)
871 if ((node->ln_Pri & flag) == flag) result++;
874 return result;
877 /*****************************************************************************************/
879 struct Node *FindListNode(struct List *list, WORD which)
881 struct Node *node = NULL;
883 if (which >= 0)
885 for(node = list->lh_Head; node->ln_Succ && which; node = node->ln_Succ, which--)
888 if (!node->ln_Succ) node = NULL;
891 return node;
894 /*****************************************************************************************/
896 void SortInNode(APTR req, struct List *list, struct Node *node,
897 WORD (*compare)(APTR req, APTR node1, APTR node2, struct AslBase_intern *AslBase),
898 struct AslBase_intern *AslBase)
900 struct Node *prevnode = NULL;
901 struct Node *checknode;
903 ForeachNode(list, checknode)
905 if (compare(req, node, checknode, AslBase) < 0) break;
907 prevnode = checknode;
910 Insert(list, node, prevnode);
913 /*****************************************************************************************/
915 APTR MyAllocVecPooled(APTR pool, IPTR size, struct AslBase_intern *AslBase)
917 IPTR *mem;
919 //dprintf("MyAllocVecPooled: pool 0x%lx size %ld\n",pool,size);
921 size += sizeof(APTR) * 2;
923 if ((mem = AllocPooled(pool, size)))
925 //dprintf("MyAllocVecPooled: pool 0x%lx mem 0x%lx size %ld\n",pool,mem,size);
926 *mem++ = (IPTR)pool;
927 *mem++ = size;
928 //dprintf("MyAllocVecPooled: mem 0x%lx\n");
931 return mem;
934 /*****************************************************************************************/
936 void MyFreeVecPooled(APTR mem, struct AslBase_intern *AslBase)
938 IPTR *imem = (IPTR *)mem;
940 if (mem)
942 IPTR size = *--imem;
943 APTR pool = (APTR)*--imem;
945 //dprintf("MyFreeVecPooled: pool 0x%lx imem 0x%lx size %ld\n",pool,imem,size);
947 FreePooled(pool, imem, size);
951 /*****************************************************************************************/
953 char *PooledCloneString(const char *name1, const char *name2, APTR pool,
954 struct AslBase_intern *AslBase)
956 char *clone;
957 WORD len1 = strlen(name1) + 1;
958 WORD len2 = name2 ? strlen(name2) : 0;
960 if ((clone = AllocPooled(pool, len1 + len2)))
962 CopyMem(name1, clone, len1);
963 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
966 return clone;
969 /*****************************************************************************************/
971 char *PooledCloneStringLen(const char *name1, ULONG len1, const char *name2, ULONG len2, APTR pool,
972 struct AslBase_intern *AslBase)
974 char *clone;
975 if ((clone = AllocPooled(pool, len1 + len2 + 1)))
977 CopyMem(name1, clone, len1);
978 clone[len1] = '\0';
979 if (name2)
981 CopyMem(name2, clone + len1, len2);
983 clone[len1+len2] = '\0';
985 return clone;
988 /*****************************************************************************************/
990 char *VecCloneString(const char *name1, const char *name2, struct AslBase_intern *AslBase)
992 char *clone;
993 WORD len1 = strlen(name1) + 1;
994 WORD len2 = name2 ? strlen(name2) : 0;
996 if ((clone = AllocVec(len1 + len2, MEMF_PUBLIC)))
998 CopyMem(name1, clone, len1);
999 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1002 return clone;
1005 /*****************************************************************************************/
1007 char *VecPooledCloneString(const char *name1, const char *name2, APTR pool, struct AslBase_intern *AslBase)
1009 char *clone;
1010 WORD len1 = strlen(name1) + 1;
1011 WORD len2 = name2 ? strlen(name2) : 0;
1013 if ((clone = MyAllocVecPooled(pool, len1 + len2, AslBase)))
1015 CopyMem(name1, clone, len1);
1016 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1019 return clone;
1022 /*****************************************************************************************/
1024 AROS_UFH2 (void, puttostr,
1025 AROS_UFHA(UBYTE, chr, D0),
1026 AROS_UFHA(STRPTR *,strPtrPtr,A3)
1029 AROS_USERFUNC_INIT
1030 *(*strPtrPtr)= chr;
1031 (*strPtrPtr) ++;
1032 AROS_USERFUNC_EXIT
1035 /*****************************************************************************************/
1037 /* This is used for printing out fib_Size, which is why
1038 * is takes a IPTR instead of a ULONG
1040 char *PooledUIntegerToString(IPTR value, APTR pool, struct AslBase_intern *AslBase)
1042 char buffer[30];
1043 char *str = buffer;
1044 char *clone;
1045 WORD len;
1047 /* Create the text */
1049 RawDoFmt("%iu", (RAWARG)&value, (VOID_FUNC)AROS_ASMSYMNAME(puttostr), &str);
1051 len = strlen(buffer) + 1;
1053 if ((clone = AllocPooled(pool, len)))
1055 CopyMem(buffer, clone, len);
1058 return clone;
1061 /*****************************************************************************************/
1063 void CloseWindowSafely(struct Window *window, struct AslBase_intern *AslBase)
1065 struct IntuiMessage *msg;
1066 struct Node *succ;
1068 Forbid();
1070 if(window->UserPort != NULL)
1072 msg = (struct IntuiMessage *)window->UserPort->mp_MsgList.lh_Head;
1074 while((succ = msg->ExecMessage.mn_Node.ln_Succ))
1076 if(msg->IDCMPWindow == window)
1078 Remove((struct Node *)msg);
1079 ReplyMsg((struct Message *)msg);
1082 msg = (struct IntuiMessage *)succ;
1086 window->UserPort = NULL;
1088 ModifyIDCMP(window, 0);
1090 Permit();
1092 CloseWindow(window);
1095 /*****************************************************************************************/
1097 AROS_UFH3(ULONG, StringEditFunc,
1098 AROS_UFHA(struct Hook *, hook, A0),
1099 AROS_UFHA(struct SGWork *, sgw, A2),
1100 AROS_UFHA(ULONG *, command, A1))
1102 AROS_USERFUNC_INIT
1104 ULONG retcode = 0;
1106 switch(*command)
1108 case SGH_KEY:
1109 retcode = 1;
1110 switch(sgw->IEvent->ie_Code)
1112 case RAWKEY_PAGEUP:
1113 case RAWKEY_PAGEDOWN:
1114 case RAWKEY_HOME:
1115 case RAWKEY_END:
1116 case RAWKEY_ESCAPE:
1117 case RAWKEY_NM_WHEEL_UP:
1118 case RAWKEY_NM_WHEEL_DOWN:
1119 sgw->Code = STRINGCODE_NOP;
1120 sgw->Actions = SGA_END | SGA_REUSE;
1121 break;
1123 case CURSORUP:
1124 sgw->EditOp = EO_SPECIAL;
1125 sgw->Code = STRINGCODE_CURSORUP;
1126 sgw->Actions = SGA_END;
1127 break;
1129 case CURSORDOWN:
1130 sgw->EditOp = EO_SPECIAL;
1131 sgw->Code = STRINGCODE_CURSORDOWN;
1132 sgw->Actions = SGA_END;
1133 break;
1135 break;
1139 return retcode;
1141 AROS_USERFUNC_EXIT
1145 /*****************************************************************************************/
1147 void PaintInnerFrame(struct RastPort *rp, struct DrawInfo *dri, Object *frameobj,
1148 struct IBox *framebox, struct IBox *innerbox, ULONG pen,
1149 struct AslBase_intern *AslBase)
1151 struct impFrameBox fmsg;
1152 struct IBox cbox;
1153 struct IBox fbox;
1154 WORD x1, y1, x2, y2;
1155 WORD ix1, iy1, ix2, iy2;
1157 cbox.Left = framebox->Left;
1158 cbox.Top = framebox->Top;
1159 cbox.Width = framebox->Width;
1160 cbox.Height = framebox->Height;
1162 fmsg.MethodID = IM_FRAMEBOX;
1163 fmsg.imp_ContentsBox = &cbox;
1164 fmsg.imp_FrameBox = &fbox;
1165 fmsg.imp_DrInfo = dri;
1166 fmsg.imp_FrameFlags = 0;
1168 DoMethodA(frameobj, (Msg)&fmsg);
1170 SetABPenDrMd(rp, pen, 0, JAM1);
1172 x1 = fbox.Left;
1173 y1 = fbox.Top;
1174 x2 = x1 + fbox.Width - 1;
1175 y2 = y1 + fbox.Height - 1;
1177 ix1 = cbox.Left;
1178 iy1 = cbox.Top;
1179 ix2 = ix1 + cbox.Width - 1;
1180 iy2 = iy1 + cbox.Height - 1;
1182 ix1 += (ix1 - x1);
1183 iy1 += (iy1 - y1);
1184 ix2 += (ix2 - x2);
1185 iy2 += (iy2 - y2);
1187 x1 = innerbox->Left - 1;
1188 y1 = innerbox->Top - 1;
1189 x2 = innerbox->Left + innerbox->Width;
1190 y2 = innerbox->Top + innerbox->Height;
1192 RectFill(rp, ix1, iy1, ix2, y1);
1193 RectFill(rp, ix1, iy1, x1, iy2);
1194 RectFill(rp, x2, iy1, ix2, iy2);
1195 RectFill(rp, ix1, y2, ix2, iy2);
1199 /*****************************************************************************************/
1201 void PaintBoxFrame(struct RastPort *rp, struct IBox *outerbox, struct IBox *innerbox,
1202 ULONG pen, struct AslBase_intern *AslBase)
1204 WORD x1, y1, x2, y2;
1205 WORD ix1, iy1, ix2, iy2;
1207 ix1 = outerbox->Left;
1208 iy1 = outerbox->Top - 1;
1209 ix2 = outerbox->Left + outerbox->Width - 1;
1210 iy2 = outerbox->Top + outerbox->Height - 1;
1212 x1 = innerbox->Left - 1;
1213 y1 = innerbox->Top - 1;
1214 x2 = innerbox->Left + innerbox->Width;
1215 y2 = innerbox->Top + innerbox->Height;
1217 SetABPenDrMd(rp, pen, 0, JAM1);
1219 RectFill(rp, ix1, iy1, ix2, y1);
1220 RectFill(rp, ix1, iy1, x1, iy2);
1221 RectFill(rp, x2, iy1, ix2, iy2);
1222 RectFill(rp, ix1, y2, ix2, iy2);
1226 /*****************************************************************************************/