2 Copyright © 1995-2017, 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 therefore 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) */
242 /*****************************************************************************************/
244 VOID
FreeCommon(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
249 if (ld
->ld_IntReq
->ir_Catalog
) CloseCatalog(ld
->ld_IntReq
->ir_Catalog
);
254 ClearMenuStrip(ld
->ld_Window
);
256 FreeMenus(ld
->ld_Menu
);
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
);
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
);
291 FreeVec(ld
->ld_UserData
);
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
308 struct IntReq
*intreq
,
310 struct AslBase_intern
*AslBase
313 struct Screen
*screen
= NULL
;
314 struct LayoutData
*ld
;
317 ld
= AllocMem(sizeof (struct LayoutData
), MEMF_ANY
|MEMF_CLEAR
);
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
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
},
377 if ((im
= NewObjectA(NULL
, SYSICLASS
, sysi_tags
)))
381 if (GetAttr(IA_Height
, im
, &height
))
383 ld
->ld_WBorBottom
= height
;
390 if(GetBitMapAttr(screen
->RastPort
.BitMap
, BMA_DEPTH
) > 8) ld
->ld_TrueColor
= TRUE
;
392 if (!(ld
->ld_UserData
= AllocVec(udatasize
, MEMF_ANY
|MEMF_CLEAR
)))
395 if (!GetRequesterFont(ld
, ASLB(AslBase
)))
398 SetFont( &(ld
->ld_DummyRP
), ld
->ld_Font
);
402 struct TagItem tags
[] =
404 {OC_BuiltInLanguage
, (IPTR
)"english"},
409 intreq
->ir_Catalog
= OpenCatalogA(intreq
->ir_Locale
, "System/Libs/asl.catalog", tags
);
415 FreeCommon(ld
, ASLB(AslBase
));
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 /*****************************************************************************************/
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);
452 iff
->iff_Stream
= (IPTR
)Open("ENV:Sys/font.prefs", MODE_OLDFILE
);
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
);
469 fp
= AllocMem(sizeof (struct FontPrefs
), MEMF_ANY
);
476 /* Set ptr to start of struct FontPrefs */
479 /* Skip 4 first reserved longs */
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
);
493 strcpy(fontname
, ptr
);
495 fp
->fp_TextAttr
.ta_Name
= fontname
;
499 FreeMem(fp
, sizeof (struct FontPrefs
));
507 } /* if (ParseIFF(iff, IFFPARSE_SCAN) != 0) */
510 } /* if (OpenIFF(iff)) */
511 Close( (BPTR
)iff
->iff_Stream
);
513 } /* if (iff->iff_Stream) */
517 CloseLibrary(IFFParseBase
);
519 } /* if (IFFParseBase) */
523 } /* GetFontPrefs() */
527 /*****************************************************************************************/
531 STATIC VOID
FreeFontPrefs(struct FontPrefs
*fp
, struct AslBase_intern
*AslBase
)
534 FreeVec(fp
->fp_TextAttr
.ta_Name
);
535 FreeMem(fp
, sizeof (struct FontPrefs
));
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 */
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
;
568 font
= OpenDiskFont (usedattr
);
571 /* If not, try screen font */
575 usedattr
= ld
->ld_Screen
->Font
;
578 font
= OpenDiskFont (usedattr
);
583 /* If no font has been opened yet, try the preferences one */
586 struct FontPrefs
*fprefs
;
588 fprefs
= GetFontPrefs(ASLB(AslBase
));
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
);
600 FreeFontPrefs(fprefs
, ASLB(AslBase
));
606 /* No success, so try system default font */
612 SetFont(&(ld
->ld_DummyRP
), GfxBase
->DefaultFont
);
613 AskFont(&(ld
->ld_DummyRP
), usedattr
);
615 font
= OpenDiskFont(usedattr
);
618 /* Yet no font, try topaz 8 */
624 /* Here we should really use OpenDiskFont, but
625 * since AROS can't render diskfonts yet, we must use OpenFont()
628 font
= OpenFont(usedattr
);
634 /* We have to store the used textattr for later */
636 fontname
= AllocVec (strlen (usedattr
->ta_Name
) + 1, MEMF_ANY
);
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
;
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
;
665 BOOL terminated
= FALSE
;
667 EnterFunc(bug("HandleEvents(ld=%p, reqinfo=%p)\n", ld
, reqinfo
));
668 port
= ld
->ld_Window
->UserPort
;
671 port
= ld
->ld_Window
->WindowPort
;
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 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
)
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
,
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
]));
797 /*****************************************************************************************/
799 /* Strip special info from the requester structure */
801 VOID
StripRequester(APTR req
, UWORD reqtype
, struct AslBase_intern
*AslBase
)
805 case ASL_FileRequest
:
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
)
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
;
854 case ASL_FontRequest
:
857 #define GetFO(r) ((struct FontRequester *)r)
859 MyFreeVecPooled(GetFO(req
)->fo_TAttr
.tta_Name
, AslBase
);
860 GetFO(req
)->fo_TAttr
.tta_Name
= NULL
;
864 case ASL_ScreenModeRequest
:
870 /*****************************************************************************************/
872 WORD
CountNodes(struct List
*list
, WORD flag
)
877 ForeachNode(list
, node
)
879 if ((node
->ln_Pri
& flag
) == flag
) result
++;
885 /*****************************************************************************************/
887 struct Node
*FindListNode(struct List
*list
, WORD which
)
889 struct Node
*node
= NULL
;
893 for(node
= list
->lh_Head
; node
->ln_Succ
&& which
; node
= node
->ln_Succ
, which
--)
896 if (!node
->ln_Succ
) node
= NULL
;
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
)
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);
936 //dprintf("MyAllocVecPooled: mem 0x%lx\n");
942 /*****************************************************************************************/
944 void MyFreeVecPooled(APTR mem
, struct AslBase_intern
*AslBase
)
946 IPTR
*imem
= (IPTR
*)mem
;
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
)
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);
977 /*****************************************************************************************/
979 char *PooledCloneStringLen(const char *name1
, ULONG len1
, const char *name2
, ULONG len2
, APTR pool
,
980 struct AslBase_intern
*AslBase
)
983 if ((clone
= AllocPooled(pool
, len1
+ len2
+ 1)))
985 CopyMem(name1
, clone
, len1
);
989 CopyMem(name2
, clone
+ len1
, len2
);
991 clone
[len1
+len2
] = '\0';
996 /*****************************************************************************************/
998 char *VecCloneString(const char *name1
, const char *name2
, struct AslBase_intern
*AslBase
)
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);
1013 /*****************************************************************************************/
1015 char *VecPooledCloneString(const char *name1
, const char *name2
, APTR pool
, struct AslBase_intern
*AslBase
)
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);
1030 /*****************************************************************************************/
1032 AROS_UFH2 (void, puttostr
,
1033 AROS_UFHA(UBYTE
, chr
, D0
),
1034 AROS_UFHA(STRPTR
*,strPtrPtr
,A3
)
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
)
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
);
1069 /*****************************************************************************************/
1071 void CloseWindowSafely(struct Window
*window
, struct AslBase_intern
*AslBase
)
1073 struct IntuiMessage
*msg
;
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);
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
))
1118 switch(sgw
->IEvent
->ie_Code
)
1121 case RAWKEY_PAGEDOWN
:
1125 case RAWKEY_NM_WHEEL_UP
:
1126 case RAWKEY_NM_WHEEL_DOWN
:
1127 sgw
->Code
= STRINGCODE_NOP
;
1128 sgw
->Actions
= SGA_END
| SGA_REUSE
;
1132 sgw
->EditOp
= EO_SPECIAL
;
1133 sgw
->Code
= STRINGCODE_CURSORUP
;
1134 sgw
->Actions
= SGA_END
;
1138 sgw
->EditOp
= EO_SPECIAL
;
1139 sgw
->Code
= STRINGCODE_CURSORDOWN
;
1140 sgw
->Actions
= SGA_END
;
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
;
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
);
1182 x2
= x1
+ fbox
.Width
- 1;
1183 y2
= y1
+ fbox
.Height
- 1;
1187 ix2
= ix1
+ cbox
.Width
- 1;
1188 iy2
= iy1
+ cbox
.Height
- 1;
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 /*****************************************************************************************/