Metatarget for copying of testfile fixed.
[AROS.git] / workbench / libs / asl / basicfuncs.c
blob221d9dbe16010b524c03235bdb25788cf3b81512
1 /*
2 Copyright © 1995-2011, 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 therefor 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) */
240 return;
243 /*****************************************************************************************/
245 VOID FreeCommon(struct LayoutData *ld, struct AslBase_intern *AslBase)
247 if (ld)
250 if (ld->ld_IntReq->ir_Catalog) CloseCatalog(ld->ld_IntReq->ir_Catalog);
252 if (ld->ld_Menu)
254 if (ld->ld_Window)
255 ClearMenuStrip(ld->ld_Window);
257 FreeMenus(ld->ld_Menu);
260 if (ld->ld_Window)
262 if (ld->ld_AppWindow)
263 RemoveAppWindow(ld->ld_AppWindow);
264 if (ld->ld_AppMsgPort)
265 DeleteMsgPort(ld->ld_AppMsgPort);
267 if (ld->ld_IntReq->ir_Flags & IF_POPPEDTOFRONT)
269 ld->ld_IntReq->ir_Flags &= ~IF_POPPEDTOFRONT;
270 ScreenToBack(ld->ld_Window->WScreen);
273 if ((ld->ld_IntReq->ir_Flags & IF_PRIVATEIDCMP) || (!ld->ld_IntReq->ir_Window))
275 CloseWindow(ld->ld_Window);
277 else
279 CloseWindowSafely(ld->ld_Window, AslBase);
283 D(bug("Window freed\n"));
285 if (ld->ld_VisualInfo) FreeVisualInfo(ld->ld_VisualInfo);
286 if (ld->ld_Dri) FreeScreenDrawInfo(ld->ld_Screen, ld->ld_Dri);
288 if (ld->ld_ScreenLocked)
289 UnlockPubScreen(NULL, ld->ld_Screen);
291 if (ld->ld_UserData)
292 FreeVec(ld->ld_UserData);
294 if (ld->ld_Font)
295 CloseFont(ld->ld_Font);
297 if (ld->ld_TextAttr.ta_Name)
298 FreeVec(ld->ld_TextAttr.ta_Name);
300 FreeMem(ld, sizeof (struct LayoutData));
303 return;
306 /*****************************************************************************************/
308 struct LayoutData *AllocCommon
310 ULONG udatasize,
311 struct IntReq *intreq,
312 APTR requester,
313 struct AslBase_intern *AslBase
316 struct Screen *screen = NULL;
317 struct LayoutData *ld;
320 ld = AllocMem(sizeof (struct LayoutData), MEMF_ANY|MEMF_CLEAR);
321 if (!ld)
322 goto failure;
324 /* Save the internal and public requester struct, so that the
325 requester type specific hook may find them */
326 ld->ld_IntReq = intreq;
327 ld->ld_Req = requester;
329 InitRastPort(&(ld->ld_DummyRP));
331 /* We need to lock the screen we should open on to be sure it
332 doesn't go away
335 /* Find screen on which to open window */
337 screen = intreq->ir_Screen;
338 if (!screen && intreq->ir_PubScreenName)
340 if ((screen = LockPubScreen(intreq->ir_PubScreenName)))
342 ld->ld_ScreenLocked = TRUE;
345 if (!screen && intreq->ir_Window)
347 screen = intreq->ir_Window->WScreen;
349 if (!screen && !intreq->ir_PubScreenName)
351 if ((screen = LockPubScreen(NULL)))
353 ld->ld_ScreenLocked = TRUE;
357 if (!screen) goto failure;
359 ld->ld_Screen = screen;
361 if (!(ld->ld_Dri = GetScreenDrawInfo(screen))) goto failure;
363 if (!(ld->ld_VisualInfo = GetVisualInfoA(screen, NULL))) goto failure;
365 ld->ld_WBorLeft = screen->WBorLeft;
366 ld->ld_WBorTop = screen->WBorTop + screen->Font->ta_YSize + 1;
367 ld->ld_WBorRight = screen->WBorRight;
368 ld->ld_WBorBottom = 16;
371 struct TagItem sysi_tags[] =
373 {SYSIA_DrawInfo , (IPTR)ld->ld_Dri },
374 {SYSIA_Which , SIZEIMAGE },
375 {TAG_DONE }
378 Object *im;
380 if ((im = NewObjectA(NULL, SYSICLASS, sysi_tags)))
382 IPTR height;
384 if (GetAttr(IA_Height, im, &height))
386 ld->ld_WBorBottom = height;
388 DisposeObject(im);
393 if(GetBitMapAttr(screen->RastPort.BitMap, BMA_DEPTH) > 8) ld->ld_TrueColor = TRUE;
395 if (!(ld->ld_UserData = AllocVec(udatasize, MEMF_ANY|MEMF_CLEAR)))
396 goto failure;
398 if (!GetRequesterFont(ld, ASLB(AslBase)))
399 goto failure;
401 SetFont( &(ld->ld_DummyRP), ld->ld_Font );
403 if (LocaleBase)
405 struct TagItem tags[] =
407 {OC_BuiltInLanguage , (IPTR)"english"},
408 {OC_Version , 0 },
409 {TAG_DONE }
412 intreq->ir_Catalog = OpenCatalogA(intreq->ir_Locale, "System/Libs/asl.catalog", tags);
415 return (ld);
417 failure:
418 FreeCommon(ld, ASLB(AslBase));
420 return (NULL);
424 /*****************************************************************************************/
426 #define SKIPLONG(ptr, num) ptr += sizeof (LONG) * num
428 #define CONVBYTE(ptr, dest) dest = *ptr ++
430 #define SKIPBYTE(ptr) ptr ++;
432 #define CONVWORD(ptr, dest) dest = ptr[0] << 8 | ptr[1]; \
433 ptr += sizeof (WORD);
435 /*****************************************************************************************/
437 #if 0
439 STATIC struct FontPrefs *GetFontPrefs(struct AslBase_intern *AslBase)
441 struct IFFHandle *iff;
442 struct Library *IFFParseBase;
444 struct StoredProperty *sp;
446 struct FontPrefs *fp = NULL;
448 IFFParseBase = OpenLibrary("iffparse.library", 0);
449 if (IFFParseBase)
451 iff = AllocIFF();
452 if (iff)
455 iff->iff_Stream = (IPTR)Open("ENV:Sys/font.prefs", MODE_OLDFILE);
456 if (iff->iff_Stream)
458 InitIFFasDOS(iff);
460 if (OpenIFF(iff, IFFF_READ) == 0)
462 PropChunk(iff, ID_PREF, ID_FONT);
465 if (ParseIFF(iff, IFFPARSE_SCAN) != 0)
468 sp = FindProp(iff, ID_PREF, ID_FONT);
469 if (sp)
472 fp = AllocMem(sizeof (struct FontPrefs), MEMF_ANY);
473 if (fp)
475 UBYTE *ptr;
476 STRPTR fontname;
479 /* Set ptr to start of struct FontPrefs */
480 ptr = sp->sp_Data;
482 /* Skip 4 first reserved longs */
483 SKIPLONG(ptr, 4);
484 CONVBYTE(ptr, fp->fp_FrontPen);
485 CONVBYTE(ptr, fp->fp_BackPen);
486 CONVBYTE(ptr, fp->fp_DrawMode);
488 CONVWORD(ptr, fp->fp_TextAttr.ta_YSize);
489 CONVBYTE(ptr, fp->fp_TextAttr.ta_Style);
490 CONVBYTE(ptr, fp->fp_TextAttr.ta_Flags);
493 fontname = AllocVec( strlen(ptr) + 1, MEMF_ANY);
494 if (fontname)
496 strcpy(fontname, ptr);
498 fp->fp_TextAttr.ta_Name = fontname;
500 else
502 FreeMem(fp, sizeof (struct FontPrefs));
503 fp = NULL;
506 } /* if (tattr) */
508 } /* if (sp) */
510 } /* if (ParseIFF(iff, IFFPARSE_SCAN) != 0) */
511 CloseIFF(iff);
513 } /* if (OpenIFF(iff)) */
514 Close( (BPTR)iff->iff_Stream );
516 } /* if (iff->iff_Stream) */
517 FreeIFF(iff);
519 } /* if (iff) */
520 CloseLibrary(IFFParseBase);
522 } /* if (IFFParseBase) */
524 return (fp);
526 } /* GetFontPrefs() */
528 #endif
530 /*****************************************************************************************/
532 #if 0
534 STATIC VOID FreeFontPrefs(struct FontPrefs *fp, struct AslBase_intern *AslBase)
537 FreeVec(fp->fp_TextAttr.ta_Name);
538 FreeMem(fp, sizeof (struct FontPrefs));
540 return;
543 #endif
545 /*****************************************************************************************/
547 BOOL GetRequesterFont(struct LayoutData *ld, struct AslBase_intern *AslBase)
549 struct TextFont *font = NULL;
551 struct TextAttr *usedattr, askattr;
553 BOOL success = FALSE;
555 static struct TextAttr topaz8 = {"topaz.font", 8, 0, 0 };
557 /* Default to satisfy GCC */
558 usedattr = &topaz8;
561 Open the font we should use in the GUI.
562 First look for a user supplied TextAttr.
563 If not present, try to get the font preferences from ENV:Sys/font.prefs
564 If this fails, we fall back to topaz 8
567 /* Is there a user supplied font */
568 usedattr = ld->ld_IntReq->ir_TextAttr;
570 if (usedattr)
572 font = OpenDiskFont (usedattr);
575 /* If not, try screen font */
577 if (!font)
579 usedattr = ld->ld_Screen->Font;
580 if (usedattr)
582 font = OpenDiskFont (usedattr);
586 #if 0
587 /* If no font has been opened yet, try the preferences one */
588 if (!font)
590 struct FontPrefs *fprefs;
592 fprefs = GetFontPrefs(ASLB(AslBase));
593 if (fprefs)
595 D(bug("Fontprefs found\n"));
597 D(bug("Name: %s, YSize :%d", fprefs->fp_TextAttr.ta_Name, fprefs->fp_TextAttr.ta_YSize));
599 usedattr = &(fprefs->fp_TextAttr);
600 font = OpenDiskFont(usedattr);
602 if (!font)
604 FreeFontPrefs(fprefs, ASLB(AslBase));
608 #endif
610 /* No success, so try system default font */
612 if (!font)
614 usedattr = &askattr;
616 SetFont(&(ld->ld_DummyRP), GfxBase->DefaultFont);
617 AskFont(&(ld->ld_DummyRP), usedattr);
619 font = OpenDiskFont(usedattr);
622 /* Yet no font, try topaz 8 */
624 if (!font)
626 usedattr = &topaz8;
628 /* Here we should really use OpenDiskFont, but
629 * since AROS can't render diskfonts yet, we must use OpenFont()
632 font = OpenFont(usedattr);
635 if (font)
637 STRPTR fontname;
638 /* We have to store the used textattr for later */
640 fontname = AllocVec (strlen (usedattr->ta_Name) + 1, MEMF_ANY);
642 if (fontname)
644 strcpy (fontname, usedattr->ta_Name);
646 ld->ld_TextAttr.ta_Name = fontname;
647 ld->ld_TextAttr.ta_YSize = usedattr->ta_YSize;
648 ld->ld_TextAttr.ta_Style = usedattr->ta_Style;
649 ld->ld_TextAttr.ta_Flags = usedattr->ta_Flags;
651 ld->ld_Font = font;
653 success = TRUE;
656 return (success);
659 /*****************************************************************************************/
661 BOOL HandleEvents(struct LayoutData *ld, struct AslReqInfo *reqinfo, struct AslBase_intern *AslBase)
663 struct IntReq *intreq = ld->ld_IntReq;
664 APTR req = ld->ld_Req;
665 struct IntuiMessage *imsg;
666 struct MsgPort *port;
667 BOOL success = TRUE;
668 BOOL terminated = FALSE;
670 EnterFunc(bug("HandleEvents(ld=%p, reqinfo=%p)\n", ld, reqinfo));
671 port = ld->ld_Window->UserPort;
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 ReplyMsg((struct Message *)imsg);
736 } /* while ((imsg = (struct IntuiMessage *)GetMsg(port))) */
738 while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort)))
740 ld->ld_Command = LDCMD_HANDLEAPPWINDOW;
741 success = CallHookPkt( &(reqinfo->GadgetryHook), ld, ASLB(AslBase));
742 ReplyMsg ((struct Message *) ld->ld_AppMsg);
744 /* Do Intuition stuff only now, so we can have replied message quite early */
745 RefreshGadgets(((struct Gadget *)((struct FRUserData *)ld->ld_UserData)->Listview), ld->ld_Window, (struct Requester *)ld->ld_Req);
746 ActivateWindow(ld->ld_Window);
748 if (ld->ld_ForeignerFiles)
750 FRDropFromDifferentDrawersRequester(ld, AslBase);
751 MyFreeVecPooled(ld->ld_ForeignerFiles, AslBase);
752 ld->ld_ForeignerFiles = NULL;
755 if (success == LDRET_FINISHED)
757 success = TRUE;
758 terminated = TRUE;
760 if (!success)
762 success = FALSE;
763 terminated = TRUE;
765 } /* while ((ld->ld_AppMsgPort) && (ld->ld_AppMsg = (struct AppMessage *) GetMsg(ld->ld_AppMsgPort))) */
766 } /* while (!terminated) */
768 ReturnBool ("HandleEvents", success);
770 } /* HandleEvents() */
772 /*****************************************************************************************/
774 UWORD BiggestTextLength(STRPTR *strarray,
775 UWORD numstrings,
776 struct RastPort *rp,
777 struct AslBase_intern * AslBase)
780 UWORD i, w = 0, new_w;
782 for (i = 0; strarray[i] && i < numstrings; i ++)
784 new_w = TextLength(rp, strarray[i], strlen(strarray[i]));
785 if (new_w > w)
787 w = new_w;
790 return (w);
793 /*****************************************************************************************/
795 /* Strip special info from the requester structure */
797 VOID StripRequester(APTR req, UWORD reqtype, struct AslBase_intern *AslBase)
799 switch (reqtype)
801 case ASL_FileRequest:
803 #undef GetFR
804 #define GetFR(r) ((struct FileRequester *)r)
807 * We can`t free it here, because it`s called by FreeAslRequest
808 * and AslRequest may have been overtaken by some other patch.
809 * Original FreeAslRequest doesn't free them.
810 * With MFR+mungwall it crashed here.
811 * It's freeed anyway when the Pool is deleted.
813 // dprintf("StripRequester: drawer 0x%lx\n",GetFR(req)->fr_Drawer);
814 // MyFreeVecPooled(GetFR(req)->fr_Drawer, AslBase);
815 GetFR(req)->fr_Drawer = NULL;
817 // dprintf("StripRequester: file 0x%lx\n",GetFR(req)->fr_File);
818 // MyFreeVecPooled(GetFR(req)->fr_File, AslBase);
819 GetFR(req)->fr_File = NULL;
821 // dprintf("StripRequester: pattern 0x%lx\n",GetFR(req)->fr_Pattern);
822 // MyFreeVecPooled(GetFR(req)->fr_Pattern, AslBase);
823 GetFR(req)->fr_Pattern = NULL;
825 // dprintf("StripRequester: arglist 0x%lx\n",GetFR(req)->fr_ArgList);
826 if (GetFR(req)->fr_ArgList)
828 struct WBArg *wbarg;
829 BPTR lock = GetFR(req)->fr_ArgList->wa_Lock;
831 // dprintf("StripRequester: lock 0x%lx\n",lock);
832 if (lock) UnLock(lock);
834 // dprintf("StripRequester: numargs 0x%lx\n",GetFR(req)->fr_NumArgs);
836 for (wbarg = GetFR(req)->fr_ArgList; GetFR(req)->fr_NumArgs --; wbarg ++)
838 // dprintf("StripRequester: wbarg 0x%lx\n",wbarg);
839 MyFreeVecPooled(wbarg->wa_Name, AslBase);
842 // dprintf("StripRequester: free arglist\n");
843 MyFreeVecPooled(GetFR(req)->fr_ArgList, AslBase);
844 GetFR(req)->fr_ArgList = NULL;
848 break;
850 case ASL_FontRequest:
852 #undef GetFO
853 #define GetFO(r) ((struct FontRequester *)r)
855 MyFreeVecPooled(GetFO(req)->fo_TAttr.tta_Name, AslBase);
856 GetFO(req)->fo_TAttr.tta_Name = NULL;
858 break;
860 case ASL_ScreenModeRequest:
861 break;
864 return;
867 /*****************************************************************************************/
869 WORD CountNodes(struct List *list, WORD flag)
871 struct Node *node;
872 WORD result = 0;
874 ForeachNode(list, node)
876 if ((node->ln_Pri & flag) == flag) result++;
879 return result;
882 /*****************************************************************************************/
884 struct Node *FindListNode(struct List *list, WORD which)
886 struct Node *node = NULL;
888 if (which >= 0)
890 for(node = list->lh_Head; node->ln_Succ && which; node = node->ln_Succ, which--)
893 if (!node->ln_Succ) node = NULL;
896 return node;
899 /*****************************************************************************************/
901 void SortInNode(APTR req, struct List *list, struct Node *node,
902 WORD (*compare)(APTR req, APTR node1, APTR node2, struct AslBase_intern *AslBase),
903 struct AslBase_intern *AslBase)
905 struct Node *prevnode = NULL;
906 struct Node *checknode;
908 ForeachNode(list, checknode)
910 if (compare(req, node, checknode, AslBase) < 0) break;
912 prevnode = checknode;
915 Insert(list, node, prevnode);
918 /*****************************************************************************************/
920 APTR MyAllocVecPooled(APTR pool, IPTR size, struct AslBase_intern *AslBase)
922 IPTR *mem;
924 //dprintf("MyAllocVecPooled: pool 0x%lx size %ld\n",pool,size);
926 size += sizeof(APTR) * 2;
928 if ((mem = AllocPooled(pool, size)))
930 //dprintf("MyAllocVecPooled: pool 0x%lx mem 0x%lx size %ld\n",pool,mem,size);
931 *mem++ = (IPTR)pool;
932 *mem++ = size;
933 //dprintf("MyAllocVecPooled: mem 0x%lx\n");
936 return mem;
939 /*****************************************************************************************/
941 void MyFreeVecPooled(APTR mem, struct AslBase_intern *AslBase)
943 IPTR *imem = (IPTR *)mem;
945 if (mem)
947 IPTR size = *--imem;
948 APTR pool = (APTR)*--imem;
950 //dprintf("MyFreeVecPooled: pool 0x%lx imem 0x%lx size %ld\n",pool,imem,size);
952 FreePooled(pool, imem, size);
956 /*****************************************************************************************/
958 char *PooledCloneString(const char *name1, const char *name2, APTR pool,
959 struct AslBase_intern *AslBase)
961 char *clone;
962 WORD len1 = strlen(name1) + 1;
963 WORD len2 = name2 ? strlen(name2) : 0;
965 if ((clone = AllocPooled(pool, len1 + len2)))
967 CopyMem(name1, clone, len1);
968 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
971 return clone;
974 /*****************************************************************************************/
976 char *PooledCloneStringLen(const char *name1, ULONG len1, const char *name2, ULONG len2, APTR pool,
977 struct AslBase_intern *AslBase)
979 char *clone;
980 if ((clone = AllocPooled(pool, len1 + len2 + 1)))
982 CopyMem(name1, clone, len1);
983 clone[len1] = '\0';
984 if (name2)
986 CopyMem(name2, clone + len1, len2);
988 clone[len1+len2] = '\0';
990 return clone;
993 /*****************************************************************************************/
995 char *VecCloneString(const char *name1, const char *name2, struct AslBase_intern *AslBase)
997 char *clone;
998 WORD len1 = strlen(name1) + 1;
999 WORD len2 = name2 ? strlen(name2) : 0;
1001 if ((clone = AllocVec(len1 + len2, MEMF_PUBLIC)))
1003 CopyMem(name1, clone, len1);
1004 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1007 return clone;
1010 /*****************************************************************************************/
1012 char *VecPooledCloneString(const char *name1, const char *name2, APTR pool, struct AslBase_intern *AslBase)
1014 char *clone;
1015 WORD len1 = strlen(name1) + 1;
1016 WORD len2 = name2 ? strlen(name2) : 0;
1018 if ((clone = MyAllocVecPooled(pool, len1 + len2, AslBase)))
1020 CopyMem(name1, clone, len1);
1021 if (name2) CopyMem(name2, clone + len1 - 1, len2 + 1);
1024 return clone;
1027 /*****************************************************************************************/
1029 AROS_UFH2 (void, puttostr,
1030 AROS_UFHA(UBYTE, chr, D0),
1031 AROS_UFHA(STRPTR *,strPtrPtr,A3)
1034 AROS_USERFUNC_INIT
1035 *(*strPtrPtr)= chr;
1036 (*strPtrPtr) ++;
1037 AROS_USERFUNC_EXIT
1040 /*****************************************************************************************/
1042 char *PooledUIntegerToString(IPTR value, APTR pool, struct AslBase_intern *AslBase)
1044 char buffer[30];
1045 char *str = buffer;
1046 char *clone;
1047 WORD len;
1049 /* Create the text */
1051 RawDoFmt("%lu", &value, (VOID_FUNC)AROS_ASMSYMNAME(puttostr), &str);
1053 len = strlen(buffer) + 1;
1055 if ((clone = AllocPooled(pool, len)))
1057 CopyMem(buffer, clone, len);
1060 return clone;
1063 /*****************************************************************************************/
1065 void CloseWindowSafely(struct Window *window, struct AslBase_intern *AslBase)
1067 struct IntuiMessage *msg;
1068 struct Node *succ;
1070 Forbid();
1072 if(window->UserPort != NULL)
1074 msg = (struct IntuiMessage *)window->UserPort->mp_MsgList.lh_Head;
1076 while((succ = msg->ExecMessage.mn_Node.ln_Succ))
1078 if(msg->IDCMPWindow == window)
1080 Remove((struct Node *)msg);
1081 ReplyMsg((struct Message *)msg);
1084 msg = (struct IntuiMessage *)succ;
1088 window->UserPort = NULL;
1090 ModifyIDCMP(window, 0);
1092 Permit();
1094 CloseWindow(window);
1097 /*****************************************************************************************/
1099 AROS_UFH3(ULONG, StringEditFunc,
1100 AROS_UFHA(struct Hook *, hook, A0),
1101 AROS_UFHA(struct SGWork *, sgw, A2),
1102 AROS_UFHA(ULONG *, command, A1))
1104 AROS_USERFUNC_INIT
1106 ULONG retcode = 0;
1108 switch(*command)
1110 case SGH_KEY:
1111 retcode = 1;
1112 switch(sgw->IEvent->ie_Code)
1114 case RAWKEY_PAGEUP:
1115 case RAWKEY_PAGEDOWN:
1116 case RAWKEY_HOME:
1117 case RAWKEY_END:
1118 case RAWKEY_ESCAPE:
1119 case RAWKEY_NM_WHEEL_UP:
1120 case RAWKEY_NM_WHEEL_DOWN:
1121 sgw->Code = STRINGCODE_NOP;
1122 sgw->Actions = SGA_END | SGA_REUSE;
1123 break;
1125 case CURSORUP:
1126 sgw->EditOp = EO_SPECIAL;
1127 sgw->Code = STRINGCODE_CURSORUP;
1128 sgw->Actions = SGA_END;
1129 break;
1131 case CURSORDOWN:
1132 sgw->EditOp = EO_SPECIAL;
1133 sgw->Code = STRINGCODE_CURSORDOWN;
1134 sgw->Actions = SGA_END;
1135 break;
1137 break;
1141 return retcode;
1143 AROS_USERFUNC_EXIT
1147 /*****************************************************************************************/
1149 void PaintInnerFrame(struct RastPort *rp, struct DrawInfo *dri, Object *frameobj,
1150 struct IBox *framebox, struct IBox *innerbox, ULONG pen,
1151 struct AslBase_intern *AslBase)
1153 struct impFrameBox fmsg;
1154 struct IBox cbox;
1155 struct IBox fbox;
1156 WORD x1, y1, x2, y2;
1157 WORD ix1, iy1, ix2, iy2;
1159 cbox.Left = framebox->Left;
1160 cbox.Top = framebox->Top;
1161 cbox.Width = framebox->Width;
1162 cbox.Height = framebox->Height;
1164 fmsg.MethodID = IM_FRAMEBOX;
1165 fmsg.imp_ContentsBox = &cbox;
1166 fmsg.imp_FrameBox = &fbox;
1167 fmsg.imp_DrInfo = dri;
1168 fmsg.imp_FrameFlags = 0;
1170 DoMethodA(frameobj, (Msg)&fmsg);
1172 SetABPenDrMd(rp, pen, 0, JAM1);
1174 x1 = fbox.Left;
1175 y1 = fbox.Top;
1176 x2 = x1 + fbox.Width - 1;
1177 y2 = y1 + fbox.Height - 1;
1179 ix1 = cbox.Left;
1180 iy1 = cbox.Top;
1181 ix2 = ix1 + cbox.Width - 1;
1182 iy2 = iy1 + cbox.Height - 1;
1184 ix1 += (ix1 - x1);
1185 iy1 += (iy1 - y1);
1186 ix2 += (ix2 - x2);
1187 iy2 += (iy2 - y2);
1189 x1 = innerbox->Left - 1;
1190 y1 = innerbox->Top - 1;
1191 x2 = innerbox->Left + innerbox->Width;
1192 y2 = innerbox->Top + innerbox->Height;
1194 RectFill(rp, ix1, iy1, ix2, y1);
1195 RectFill(rp, ix1, iy1, x1, iy2);
1196 RectFill(rp, x2, iy1, ix2, iy2);
1197 RectFill(rp, ix1, y2, ix2, iy2);
1201 /*****************************************************************************************/
1203 void PaintBoxFrame(struct RastPort *rp, struct IBox *outerbox, struct IBox *innerbox,
1204 ULONG pen, struct AslBase_intern *AslBase)
1206 WORD x1, y1, x2, y2;
1207 WORD ix1, iy1, ix2, iy2;
1209 ix1 = outerbox->Left;
1210 iy1 = outerbox->Top - 1;
1211 ix2 = outerbox->Left + outerbox->Width - 1;
1212 iy2 = outerbox->Top + outerbox->Height - 1;
1214 x1 = innerbox->Left - 1;
1215 y1 = innerbox->Top - 1;
1216 x2 = innerbox->Left + innerbox->Width;
1217 y2 = innerbox->Top + innerbox->Height;
1219 SetABPenDrMd(rp, pen, 0, JAM1);
1221 RectFill(rp, ix1, iy1, ix2, y1);
1222 RectFill(rp, ix1, iy1, x1, iy2);
1223 RectFill(rp, x2, iy1, ix2, iy2);
1224 RectFill(rp, ix1, y2, ix2, iy2);
1228 /*****************************************************************************************/