2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Basic helpfuncs for Asl.
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>
35 #include "asl_intern.h"
36 #include "filereqsupport.h"
37 #include "filereqhooks.h"
43 #include <aros/debug.h>
45 /*****************************************************************************************/
47 STATIC BOOL
GetRequesterFont(struct LayoutData
*, struct AslBase_intern
*);
50 STATIC
struct FontPrefs
*GetFontPrefs(struct AslBase_intern
*);
51 STATIC VOID
FreeFontPrefs(struct FontPrefs
*, struct AslBase_intern
*);
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
;
73 ReleaseSemaphore( &(AslBase
->ReqListSem
) );
75 return (foundreqnode
);
78 /*****************************************************************************************/
82 struct IntReq
*intreq
,
83 struct TagItem
*taglist
,
84 struct AslBase_intern
*AslBase
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
101 /* case ASLFO_Window:
103 case ASL_Window: */ /* Obsolete */
104 intreq
->ir_Window
= (struct Window
*)tidata
;
108 /* case ASLFO_Screen:
109 case ASLSM_Screen: */
110 intreq
->ir_Screen
= (struct Screen
*)tidata
;
113 case ASLFR_PubScreenName
:
114 /* case ASLFO_PubScreenName:
115 case ASLSM_PubScreenName: */
117 intreq
->ir_PubScreenName
= (STRPTR
)tidata
;
120 case ASLFR_PrivateIDCMP
:
121 /* case ASLFO_PrivateIDCMP:
122 case ASLSM_PrivateIDCMP: */
124 intreq
->ir_Flags
|= IF_PRIVATEIDCMP
;
126 intreq
->ir_Flags
&= ~IF_PRIVATEIDCMP
;
130 case ASLFR_IntuiMsgFunc
:
131 /* case ASLFO_IntuiMsgFunc:
132 case ASLSM_IntuiMsgFunc: */
133 intreq
->ir_IntuiMsgFunc
= (struct Hook
*)tidata
;
136 case ASLFR_SleepWindow
:
137 /* case ASLFO_SleepWindow:
138 case ASLSM_SleepWindow: */
140 intreq
->ir_Flags
|= IF_SLEEPWINDOW
;
142 intreq
->ir_Flags
&= ~IF_SLEEPWINDOW
;
145 case ASLFR_PopToFront
:
146 /* case ASLFO_PopToFront:
147 case ASLSM_PopToFront: */
149 intreq
->ir_Flags
|= IF_POPTOFRONT
;
151 intreq
->ir_Flags
&= ~IF_POPTOFRONT
;
155 /* case ASLFO_Activate:
156 case ASLSM_Activate: */
158 intreq
->ir_Flags
&= ~IF_OPENINACTIVE
;
160 intreq
->ir_Flags
|= IF_OPENINACTIVE
;
164 /* case ASLFO_TextAttr:
165 case ASLSM_TextAttr: */
166 intreq
->ir_TextAttr
= (struct TextAttr
*)tidata
;
170 /* case ASLFO_Locale:
171 case ASLSM_Locale: */
172 intreq
->ir_Locale
= (struct Locale
*)tidata
;
175 case ASLFR_TitleText
:
176 /* case ASLFO_TitleText:
177 case ASLSM_TitleText:
178 case ASL_Hail: */ /* Obsolete */
180 intreq
->ir_TitleText
= (STRPTR
)tidata
;
184 case ASLFR_PositiveText
:
185 /* case ASLFO_PositiveText:
186 case ASLSM_PositiveText:
187 case ASL_OKText: */ /* Obsolete */
190 intreq
->ir_PositiveText
= (STRPTR
)tidata
;
191 intreq
->ir_Flags
|= IF_USER_POSTEXT
;
195 case ASLFR_NegativeText
:
196 /* case ASLFO_NegativeText:
197 case ASLSM_NegativeText:
198 case ASL_CancelText: */ /* Obsolete */
201 intreq
->ir_NegativeText
= (STRPTR
)tidata
;
202 intreq
->ir_Flags
|= IF_USER_NEGTEXT
;
206 case ASLFR_InitialLeftEdge
:
207 /* case ASLFO_InitialLeftEdge:
208 case ASLSM_InitialLeftEdge:
209 case ASL_LeftEdge: */ /* Obsolete */
210 intreq
->ir_LeftEdge
= (UWORD
)tidata
;
213 case ASLFR_InitialTopEdge
:
214 /* case ASLFO_InitialTopEdge:
215 case ASLSM_InitialTopEdge:
216 case ASL_TopEdge: */ /* Obsolete */
217 intreq
->ir_TopEdge
= (UWORD
)tidata
;
220 case ASLFR_InitialWidth
:
221 /* case ASLFO_InitialWidth:
222 case ASLSM_InitialWidth:
223 case ASL_Width: */ /* Obsolete */
224 intreq
->ir_Width
= (UWORD
)tidata
;
227 case ASLFR_InitialHeight
:
228 /* case ASLFO_InitialHeight:
229 case ASLSM_InitialHeight:
230 case ASL_Height: */ /* Obsolete */
231 intreq
->ir_Height
= (UWORD
)tidata
;
237 } /* switch (tag->ti_Tag) */
239 } /* while ((tag = NextTagItem(&tstate)) != NULL) */
243 /*****************************************************************************************/
245 VOID
FreeCommon(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
250 if (ld
->ld_IntReq
->ir_Catalog
) CloseCatalog(ld
->ld_IntReq
->ir_Catalog
);
255 ClearMenuStrip(ld
->ld_Window
);
257 FreeMenus(ld
->ld_Menu
);
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
);
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
);
292 FreeVec(ld
->ld_UserData
);
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
));
306 /*****************************************************************************************/
308 struct LayoutData
*AllocCommon
311 struct IntReq
*intreq
,
313 struct AslBase_intern
*AslBase
316 struct Screen
*screen
= NULL
;
317 struct LayoutData
*ld
;
320 ld
= AllocMem(sizeof (struct LayoutData
), MEMF_ANY
|MEMF_CLEAR
);
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
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
},
380 if ((im
= NewObjectA(NULL
, SYSICLASS
, sysi_tags
)))
384 if (GetAttr(IA_Height
, im
, &height
))
386 ld
->ld_WBorBottom
= height
;
393 if(GetBitMapAttr(screen
->RastPort
.BitMap
, BMA_DEPTH
) > 8) ld
->ld_TrueColor
= TRUE
;
395 if (!(ld
->ld_UserData
= AllocVec(udatasize
, MEMF_ANY
|MEMF_CLEAR
)))
398 if (!GetRequesterFont(ld
, ASLB(AslBase
)))
401 SetFont( &(ld
->ld_DummyRP
), ld
->ld_Font
);
405 struct TagItem tags
[] =
407 {OC_BuiltInLanguage
, (IPTR
)"english"},
412 intreq
->ir_Catalog
= OpenCatalogA(intreq
->ir_Locale
, "System/Libs/asl.catalog", tags
);
418 FreeCommon(ld
, ASLB(AslBase
));
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 /*****************************************************************************************/
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);
455 iff
->iff_Stream
= (IPTR
)Open("ENV:Sys/font.prefs", MODE_OLDFILE
);
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
);
472 fp
= AllocMem(sizeof (struct FontPrefs
), MEMF_ANY
);
479 /* Set ptr to start of struct FontPrefs */
482 /* Skip 4 first reserved longs */
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
);
496 strcpy(fontname
, ptr
);
498 fp
->fp_TextAttr
.ta_Name
= fontname
;
502 FreeMem(fp
, sizeof (struct FontPrefs
));
510 } /* if (ParseIFF(iff, IFFPARSE_SCAN) != 0) */
513 } /* if (OpenIFF(iff)) */
514 Close( (BPTR
)iff
->iff_Stream
);
516 } /* if (iff->iff_Stream) */
520 CloseLibrary(IFFParseBase
);
522 } /* if (IFFParseBase) */
526 } /* GetFontPrefs() */
530 /*****************************************************************************************/
534 STATIC VOID
FreeFontPrefs(struct FontPrefs
*fp
, struct AslBase_intern
*AslBase
)
537 FreeVec(fp
->fp_TextAttr
.ta_Name
);
538 FreeMem(fp
, sizeof (struct FontPrefs
));
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 */
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
;
572 font
= OpenDiskFont (usedattr
);
575 /* If not, try screen font */
579 usedattr
= ld
->ld_Screen
->Font
;
582 font
= OpenDiskFont (usedattr
);
587 /* If no font has been opened yet, try the preferences one */
590 struct FontPrefs
*fprefs
;
592 fprefs
= GetFontPrefs(ASLB(AslBase
));
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
);
604 FreeFontPrefs(fprefs
, ASLB(AslBase
));
610 /* No success, so try system default font */
616 SetFont(&(ld
->ld_DummyRP
), GfxBase
->DefaultFont
);
617 AskFont(&(ld
->ld_DummyRP
), usedattr
);
619 font
= OpenDiskFont(usedattr
);
622 /* Yet no font, try topaz 8 */
628 /* Here we should really use OpenDiskFont, but
629 * since AROS can't render diskfonts yet, we must use OpenFont()
632 font
= OpenFont(usedattr
);
638 /* We have to store the used textattr for later */
640 fontname
= AllocVec (strlen (usedattr
->ta_Name
) + 1, MEMF_ANY
);
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
;
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
;
668 BOOL terminated
= FALSE
;
670 EnterFunc(bug("HandleEvents(ld=%p, reqinfo=%p)\n", ld
, reqinfo
));
671 port
= ld
->ld_Window
->UserPort
;
675 if (ld
->ld_AppMsgPort
)
676 Wait((1L << port
->mp_SigBit
) | (1L << ld
->ld_AppMsgPort
->mp_SigBit
));
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
))
687 case IDCMP_MOUSEMOVE
:
691 ld
->ld_Command
= LDCMD_LAYOUT
;
692 CallHookPkt(&(reqinfo
->GadgetryHook
), ld
, ASLB(AslBase
));
695 case IDCMP_REFRESHWINDOW
:
696 BeginRefresh(imsg
->IDCMPWindow
);
697 EndRefresh(imsg
->IDCMPWindow
, TRUE
);
701 /* Call the requester specific hook to handle events */
702 ld
->ld_Command
= LDCMD_HANDLEEVENTS
;
705 success
= CallHookPkt( &(reqinfo
->GadgetryHook
), ld
, ASLB(AslBase
));
706 if (success
== LDRET_FINISHED
)
719 } /* switch (imsg->Class) */
721 } /* if (imsg->IDCMPWindow is ld->ld_Window or ld->ld_Window2) */
722 else if (intreq
->ir_IntuiMsgFunc
)
725 REG_A4
= (ULONG
)intreq
->ir_BasePtr
; /* Compatability */
726 REG_A0
= (ULONG
)intreq
->ir_IntuiMsgFunc
;
728 REG_A1
= (ULONG
)imsg
;
729 (*MyEmulHandle
->EmulCallDirect68k
)(intreq
->ir_IntuiMsgFunc
->h_Entry
);
731 CallHookPkt(intreq
->ir_IntuiMsgFunc
, req
, imsg
);
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
)
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
,
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
]));
793 /*****************************************************************************************/
795 /* Strip special info from the requester structure */
797 VOID
StripRequester(APTR req
, UWORD reqtype
, struct AslBase_intern
*AslBase
)
801 case ASL_FileRequest
:
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
)
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
;
850 case ASL_FontRequest
:
853 #define GetFO(r) ((struct FontRequester *)r)
855 MyFreeVecPooled(GetFO(req
)->fo_TAttr
.tta_Name
, AslBase
);
856 GetFO(req
)->fo_TAttr
.tta_Name
= NULL
;
860 case ASL_ScreenModeRequest
:
867 /*****************************************************************************************/
869 WORD
CountNodes(struct List
*list
, WORD flag
)
874 ForeachNode(list
, node
)
876 if ((node
->ln_Pri
& flag
) == flag
) result
++;
882 /*****************************************************************************************/
884 struct Node
*FindListNode(struct List
*list
, WORD which
)
886 struct Node
*node
= NULL
;
890 for(node
= list
->lh_Head
; node
->ln_Succ
&& which
; node
= node
->ln_Succ
, which
--)
893 if (!node
->ln_Succ
) node
= NULL
;
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
)
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);
933 //dprintf("MyAllocVecPooled: mem 0x%lx\n");
939 /*****************************************************************************************/
941 void MyFreeVecPooled(APTR mem
, struct AslBase_intern
*AslBase
)
943 IPTR
*imem
= (IPTR
*)mem
;
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
)
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);
974 /*****************************************************************************************/
976 char *PooledCloneStringLen(const char *name1
, ULONG len1
, const char *name2
, ULONG len2
, APTR pool
,
977 struct AslBase_intern
*AslBase
)
980 if ((clone
= AllocPooled(pool
, len1
+ len2
+ 1)))
982 CopyMem(name1
, clone
, len1
);
986 CopyMem(name2
, clone
+ len1
, len2
);
988 clone
[len1
+len2
] = '\0';
993 /*****************************************************************************************/
995 char *VecCloneString(const char *name1
, const char *name2
, struct AslBase_intern
*AslBase
)
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);
1010 /*****************************************************************************************/
1012 char *VecPooledCloneString(const char *name1
, const char *name2
, APTR pool
, struct AslBase_intern
*AslBase
)
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);
1027 /*****************************************************************************************/
1029 AROS_UFH2 (void, puttostr
,
1030 AROS_UFHA(UBYTE
, chr
, D0
),
1031 AROS_UFHA(STRPTR
*,strPtrPtr
,A3
)
1040 /*****************************************************************************************/
1042 char *PooledUIntegerToString(IPTR value
, APTR pool
, struct AslBase_intern
*AslBase
)
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
);
1063 /*****************************************************************************************/
1065 void CloseWindowSafely(struct Window
*window
, struct AslBase_intern
*AslBase
)
1067 struct IntuiMessage
*msg
;
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);
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
))
1112 switch(sgw
->IEvent
->ie_Code
)
1115 case RAWKEY_PAGEDOWN
:
1119 case RAWKEY_NM_WHEEL_UP
:
1120 case RAWKEY_NM_WHEEL_DOWN
:
1121 sgw
->Code
= STRINGCODE_NOP
;
1122 sgw
->Actions
= SGA_END
| SGA_REUSE
;
1126 sgw
->EditOp
= EO_SPECIAL
;
1127 sgw
->Code
= STRINGCODE_CURSORUP
;
1128 sgw
->Actions
= SGA_END
;
1132 sgw
->EditOp
= EO_SPECIAL
;
1133 sgw
->Code
= STRINGCODE_CURSORDOWN
;
1134 sgw
->Actions
= SGA_END
;
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
;
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
);
1176 x2
= x1
+ fbox
.Width
- 1;
1177 y2
= y1
+ fbox
.Height
- 1;
1181 ix2
= ix1
+ cbox
.Width
- 1;
1182 iy2
= iy1
+ cbox
.Height
- 1;
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 /*****************************************************************************************/