4 #include "globalvars.h"
6 #include <devices/conunit.h>
10 #include <aros/debug.h>
11 #include <aros/macros.h>
16 #define AROS_ASMSYMNAME(x) x
17 #define AROS_LONG2BE(x) x
18 #define AROS_WORD2BE(x) x
22 /****************************************************************************************/
26 struct Requester rtwl_Requester
;
28 struct rtWindowLock
*rtwl_RequesterPtr
;
30 ULONG rtwl_ReqInstalled
;
32 /* To save window parameters */
44 /****************************************************************************************/
46 SAVEDS ASM
struct ReqToolsBase
*RTFuncs_Init(REGPARAM(d0
, struct ReqToolsBase
*, RTBase
),
47 REGPARAM(a0
, BPTR
, segList
))
50 /* SysBase is setup in reqtools_init.c */
52 SysBase
= *(struct ExecBase
**)4L;
54 RTBase
->SegList
= segList
;
57 InitSemaphore(&RTBase
->ReqToolsPrefs
.PrefsSemaphore
);
58 RTBase
->ReqToolsPrefs
.PrefsSize
= RTPREFS_SIZE
;
60 /* Set default preferences */
61 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].Size
= 75;
62 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].ReqPos
= REQPOS_TOPLEFTSCR
;
63 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].LeftOffset
= 25;
64 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].TopOffset
= 18;
65 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].MinEntries
= 10;
66 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FILEREQ
].MaxEntries
= 50;
68 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].Size
= 65;
69 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].ReqPos
= REQPOS_TOPLEFTSCR
;
70 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].LeftOffset
= 25;
71 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].TopOffset
= 18;
72 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].MinEntries
= 6;
73 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_FONTREQ
].MaxEntries
= 10;
75 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].Size
= 65;
76 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].ReqPos
= REQPOS_TOPLEFTSCR
;
77 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].LeftOffset
= 25;
78 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].TopOffset
= 18;
79 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].MinEntries
= 6;
80 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_PALETTEREQ
].MaxEntries
= 10;
82 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].Size
= 65;
83 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].ReqPos
= REQPOS_TOPLEFTSCR
;
84 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].LeftOffset
= 25;
85 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].TopOffset
= 18;
86 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].MinEntries
= 6;
87 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_SCREENMODEREQ
].MaxEntries
= 10;
89 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].Size
= 65;
90 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].ReqPos
= REQPOS_TOPLEFTSCR
;
91 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].LeftOffset
= 25;
92 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].TopOffset
= 18;
93 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].MinEntries
= 6;
94 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_VOLUMEREQ
].MaxEntries
= 10;
96 // RTBase->ReqToolsPrefs.ReqDefaults[RTPREF_OTHERREQ].Size = 65;
97 // RTBase->ReqToolsPrefs.ReqDefaults[RTPREF_OTHERREQ].ReqPos = REQPOS_TOPLEFTSCR;
98 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_OTHERREQ
].LeftOffset
= 25;
99 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_OTHERREQ
].TopOffset
= 18;
100 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_OTHERREQ
].MinEntries
= 6;
101 RTBase
->ReqToolsPrefs
.ReqDefaults
[RTPREF_OTHERREQ
].MaxEntries
= 10;
106 /****************************************************************************************/
108 SAVEDS ASM
struct ReqToolsBase
*RTFuncs_Open(REGPARAM(a6
, struct ReqToolsBase
*, RTBase
),
109 REGPARAM(d0
, ULONG
, ver
))
113 UBYTE configbuffer
[RTPREFS_SIZE
];
115 DOSBase
= RTBase
->DOSBase
= (struct DosLibrary
*)OpenLibrary("dos.library", 37);
120 /* Read config file */
122 D(bug("reqtools.library: Inside libopen func. Reading config file\n"));
124 memset(configbuffer
, 0, sizeof(configbuffer
));
126 if (GetVar("ReqTools.prefs",
128 sizeof(configbuffer
),
129 GVF_BINARY_VAR
| GVF_GLOBAL_ONLY
| LV_VAR
| GVF_DONT_NULL_TERM
) == RTPREFS_SIZE
)
131 UBYTE
*configptr
= configbuffer
;
135 D(bug("reqtools.library: Inside libopen func. Configfile loaded successfully\n"));
137 #define READ_ULONG *((ULONG *)configptr);configptr += sizeof(ULONG)
138 #define READ_UWORD *((UWORD *)configptr);configptr += sizeof(UWORD)
139 #define RTPREFS (RTBase->ReqToolsPrefs)
142 RTPREFS
.Flags
= AROS_LONG2BE(val
);
144 for(i
= 0;i
< RTPREF_NR_OF_REQ
; i
++)
147 RTPREFS
.ReqDefaults
[i
].Size
= AROS_LONG2BE(val
);
150 RTPREFS
.ReqDefaults
[i
].ReqPos
= AROS_LONG2BE(val
);
153 RTPREFS
.ReqDefaults
[i
].LeftOffset
= AROS_WORD2BE(val
);
156 RTPREFS
.ReqDefaults
[i
].TopOffset
= AROS_WORD2BE(val
);
159 RTPREFS
.ReqDefaults
[i
].MinEntries
= AROS_WORD2BE(val
);
162 RTPREFS
.ReqDefaults
[i
].MaxEntries
= AROS_WORD2BE(val
);
167 } /* if (DOSBase == NULL) */
169 if(IntuitionBase
== NULL
)
170 IntuitionBase
= RTBase
->IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 37);
171 if(IntuitionBase
== NULL
)
175 GfxBase
= RTBase
->GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 37);
179 if(UtilityBase
== NULL
)
180 UtilityBase
= RTBase
->UtilityBase
= (struct UtilityBase
*)OpenLibrary("utility.library", 37);
181 if(UtilityBase
== NULL
)
184 if(GadToolsBase
== NULL
)
185 GadToolsBase
= RTBase
->GadToolsBase
= OpenLibrary("gadtools.library", 37);
186 if(GadToolsBase
== NULL
)
189 if(LayersBase
== NULL
)
190 LayersBase
= OpenLibrary("layers.library", 37);
191 if(LayersBase
== NULL
)
194 if(LocaleBase
== NULL
)
195 LocaleBase
= (struct LocaleBase
*)OpenLibrary("locale.library", 37);
196 if(LocaleBase
== NULL
)
199 D(bug("reqtools.library: Inside libopen func. Libraries opened successfully.\n"));
201 if (ConsoleDevice
== NULL
)
203 iorequest
.io_Message
.mn_Length
= sizeof(iorequest
);
205 if (OpenDevice("console.device", CONU_LIBRARY
, (struct IORequest
*)&iorequest
, 0))
209 ConsoleDevice
= iorequest
.io_Device
;
211 if (ConsoleDevice
== NULL
)
214 D(bug("reqtools.library: Inside libopen func. Console.device opened successfully.\n"));
216 if (ButtonImgClass
== NULL
)
218 ButtonImgClass
= MakeClass(NULL
, IMAGECLASS
, NULL
, sizeof(struct LocalObjData
), 0);
221 ButtonImgClass
->cl_Dispatcher
.h_Entry
= (APTR
)AROS_ASMSYMNAME(myBoopsiDispatch
);
222 ButtonImgClass
->cl_Dispatcher
.h_SubEntry
= NULL
;
223 ButtonImgClass
->cl_UserData
= (IPTR
)RTBase
;
226 if (ButtonImgClass
== NULL
)
229 D(bug("reqtools.library: Inside libopen func. ButtonImgClass create successfully.\n"));
232 /* I have one more opener. */
233 RTBase
->LibNode
.lib_Flags
&= ~LIBF_DELEXP
;
234 RTBase
->LibNode
.lib_OpenCnt
++;
237 D(bug("reqtools.library: Inside libopen func. Returning success.\n"));
242 /****************************************************************************************/
244 SAVEDS ASM BPTR
RTFuncs_Close(REGPARAM(a6
, struct ReqToolsBase
*, RTBase
))
247 /* I have one fewer opener. */
248 RTBase
->LibNode
.lib_OpenCnt
--;
250 if((RTBase
->LibNode
.lib_Flags
& LIBF_DELEXP
) != 0)
252 /* CHECKME: used expunge() from reqtools_intern.h. */
254 if(RTBase
->LibNode
.lib_OpenCnt
== 0)
255 return RTFuncs_Expunge(RTBase
);
257 RTBase
->LibNode
.lib_Flags
&= ~LIBF_DELEXP
;
264 /****************************************************************************************/
266 SAVEDS ASM BPTR
RTFuncs_Expunge(REGPARAM(a6
, struct ReqToolsBase
*, RTBase
))
271 if(RTBase
->LibNode
.lib_OpenCnt
!= 0)
273 /* Set the delayed expunge flag and return. */
274 RTBase
->LibNode
.lib_Flags
|= LIBF_DELEXP
;
278 /* Get rid of the library. Remove it from the list. */
279 Remove(&RTBase
->LibNode
.lib_Node
);
281 /* Get returncode here - FreeMem() will destroy the field. */
282 ret
= RTBase
->SegList
;
285 D(bug("reqtools.library: Inside libexpunge func. Freeing ButtonImgClass.\n"));
287 if (ButtonImgClass
) FreeClass(ButtonImgClass
);
289 D(bug("reqtools.library: Inside libexpunge func. Closing console.device.\n"));
291 if (ConsoleDevice
) CloseDevice((struct IORequest
*)&iorequest
);
293 D(bug("reqtools.library: Inside libexpunge func. Closing libraries.\n"));
295 CloseLibrary((struct Library
*)DOSBase
);
296 CloseLibrary((struct Library
*)IntuitionBase
);
297 CloseLibrary((struct Library
*)UtilityBase
);
298 CloseLibrary((struct Library
*)GfxBase
);
299 CloseLibrary((struct Library
*)LocaleBase
);
300 CloseLibrary(GadToolsBase
);
301 CloseLibrary(LayersBase
);
303 D(bug("reqtools.library: Inside libexpunge func. Freeing libbase.\n"));
306 /* Free the memory. */
307 FreeMem((char *)RTBase
-RTBase
->LibNode
.lib_NegSize
,
308 RTBase
->LibNode
.lib_NegSize
+ RTBase
->LibNode
.lib_PosSize
);
314 /****************************************************************************************/
316 SAVEDS ASM
int RTFuncs_Null(REGPARAM(a6
, struct ReqToolsBase
*, RTBase
))
322 /****************************************************************************************/
324 SAVEDS ASM
struct ReqToolsPrefs
*RTFuncs_LockPrefs(REGPARAM(a6
, struct ReqToolsBase
*, ReqToolsBase
))
326 ObtainSemaphore(&ReqToolsBase
->ReqToolsPrefs
.PrefsSemaphore
);
328 return &ReqToolsBase
->ReqToolsPrefs
;
331 /****************************************************************************************/
333 SAVEDS ASM
void RTFuncs_UnlockPrefs(REGPARAM(a6
, struct ReqToolsBase
*, ReqToolsBase
))
335 ReleaseSemaphore(&ReqToolsBase
->ReqToolsPrefs
.PrefsSemaphore
);
338 /****************************************************************************************/
340 SAVEDS ASM ULONG
RTFuncs_rtReqHandlerA(REGPARAM(a1
, struct rtHandlerInfo
*, handlerinfo
),
341 REGPARAM(d0
, ULONG
, sigs
),
342 REGPARAM(a0
, struct TagItem
*, taglist
))
344 return ((ULONG (*)(REGPARAM(a1
, struct rtHandlerInfo
*,),
345 REGPARAM(d0
, ULONG
,),
346 REGPARAM(a0
, struct TagItem
*,)))handlerinfo
->private1
)(handlerinfo
, sigs
, taglist
);
349 /****************************************************************************************/
351 SAVEDS ASM
void RTFuncs_rtSetWaitPointer(REGPARAM(a0
, struct Window
*, window
))
353 struct TagItem tags
[] = { { WA_BusyPointer
, TRUE
},
356 SetWindowPointerA(window
, (struct TagItem
*)&tags
);
359 /****************************************************************************************/
361 SAVEDS ASM APTR
RTFuncs_rtLockWindow(REGPARAM(a0
, struct Window
*, window
))
363 struct rtWindowLock
*winLock
;
365 /* Is this window already locked? */
366 if(window
->FirstRequest
!= NULL
)
368 struct rtWindowLock
*wLock
= (struct rtWindowLock
*)window
->FirstRequest
;
372 if(wLock
->rtwl_Magic
== ('r' << 24 | 't' << 16 | 'L' << 8 | 'W'))
374 if(wLock
->rtwl_RequesterPtr
== wLock
)
376 /* Window was already locked */
377 wLock
->rtwl_LockCount
++;
383 wLock
= (struct rtWindowLock
*)wLock
->rtwl_Requester
.OlderRequest
;
386 winLock
= (struct rtWindowLock
*)AllocVec(sizeof(struct rtWindowLock
),
393 winLock
->rtwl_Magic
= 'r' << 24 | 't' << 16 | 'L' << 8 | 'W';
394 winLock
->rtwl_RequesterPtr
= winLock
;
396 winLock
->rtwl_MinHeight
= window
->MinHeight
;
397 winLock
->rtwl_MaxHeight
= window
->MaxHeight
;
398 winLock
->rtwl_MinWidth
= window
->MinWidth
;
399 winLock
->rtwl_MaxWidth
= window
->MaxWidth
;
401 WindowLimits(window
, window
->Width
, window
->Height
,
402 window
->Width
, window
->Height
);
404 InitRequester((struct Requester
*)winLock
);
405 winLock
->rtwl_ReqInstalled
= Request((struct Requester
*)winLock
, window
);
407 winLock
->rtwl_Pointer
= window
->Pointer
;
408 winLock
->rtwl_PtrHeight
= window
->PtrHeight
;
409 winLock
->rtwl_PtrWidth
= window
->PtrWidth
;
411 rtSetWaitPointer(window
);
413 return (APTR
)winLock
;
416 /****************************************************************************************/
418 SAVEDS ASM VOID
RTFuncs_rtUnlockWindow(REGPARAM(a0
, struct Window
*, window
),
419 REGPARAM(a1
, APTR
, windowlock
))
422 struct rtWindowLock
*wLock
= (struct rtWindowLock
*)windowlock
;
427 if(wLock
->rtwl_LockCount
!= 0)
429 wLock
->rtwl_LockCount
--;
433 struct TagItem tags
[] = { { WA_Pointer
, (IPTR
)wLock
->rtwl_Pointer
},
436 SetWindowPointerA(window
, tags
);
438 if (wLock
->rtwl_ReqInstalled
)
439 EndRequest((struct Requester
*)wLock
, window
);
441 WindowLimits(window
, wLock
->rtwl_MinWidth
, wLock
->rtwl_MinHeight
,
442 wLock
->rtwl_MaxWidth
, wLock
->rtwl_MaxHeight
);
448 /****************************************************************************************/
450 SAVEDS ASM
void RTFuncs_rtSpread(REGPARAM(a0
, ULONG
*, posarray
),
451 REGPARAM(a1
, ULONG
*, sizearray
),
452 REGPARAM(d0
, ULONG
, totalsize
),
453 REGPARAM(d1
, ULONG
, min
),
454 REGPARAM(d2
, ULONG
, max
),
455 REGPARAM(d3
, ULONG
, num
))
457 ULONG gadpos
= min
<< 16;
461 gadgap
= ((max
- min
- totalsize
) << 16) / (num
- 1);
465 for(i
= 1; i
< num
- 1; i
++)
467 gadpos
+= (sizearray
[i
- 1] << 16) + gadgap
;
468 posarray
[i
] = gadpos
>> 16;
471 posarray
[num
- 1] = max
- sizearray
[i
];
475 /****************************************************************************************/
477 SAVEDS ASM
void RTFuncs_ScreenToFrontSafely(REGPARAM(a0
, struct Screen
*, screen
))
484 /* Bugfixes: 1. Lock *before* peeking IntuitionBase->FirstScreen
485 2. Favor LockIBase() over Forbid() */
490 ilock
= LockIBase(0);
493 scr
= IntuitionBase
->FirstScreen
;
500 ScreenToFront(screen
);
503 /* Forbid before UnlockIBase() to avoid screen from disappearing */
506 /* UnlockIBase() basically does ReleaseSemaphore() and that never
507 Wait(), and thus cannot break Forbid(). */
510 /* Actually this will break the Forbid() if it need to Wait() for
511 semaphore, so this function isn't 100% bulletproof anyway... */
512 ScreenToFront(screen
);
516 /* Note: return not break!
522 scr
= scr
->NextScreen
;
532 /****************************************************************************************/
534 SAVEDS ASM
void RTFuncs_rtSetReqPosition(REGPARAM(d0
, ULONG
, reqpos
),
535 REGPARAM(a0
, struct NewWindow
*, nw
),
536 REGPARAM(a1
, struct Screen
*, scr
),
537 REGPARAM(a2
, struct Window
*, win
))
539 #warning Taken from rtfuncs.asm where the C version was in comments. Might be out of date
541 int mx
= 0, my
= 0, val
, leftedge
, topedge
;
542 ULONG scrwidth
, scrheight
;
543 int width
, height
, left
, top
;
545 rtGetVScreenSize (scr
, &scrwidth
, &scrheight
);
547 leftedge
= -scr
->LeftEdge
;
548 if (leftedge
< 0) leftedge
= 0;
550 topedge
= -scr
->TopEdge
;
551 if (topedge
< 0) topedge
= 0;
553 left
= leftedge
; top
= topedge
;
554 width
= scrwidth
; height
= scrheight
;
564 mx
= scr
->MouseX
; my
= scr
->MouseY
;
567 case REQPOS_CENTERWIN
:
570 left
= win
->LeftEdge
; top
= win
->TopEdge
;
571 width
= win
->Width
; height
= win
->Height
;
574 case REQPOS_CENTERSCR
:
575 mx
= (width
- nw
->Width
) / 2 + left
;
576 my
= (height
- nw
->Height
) / 2 + top
;
579 case REQPOS_TOPLEFTWIN
:
582 left
= win
->LeftEdge
;
586 case REQPOS_TOPLEFTSCR
:
591 } /* switch (reqpos) */
593 /* keep window completely visible */
594 mx
+= nw
->LeftEdge
; my
+= nw
->TopEdge
;
595 val
= leftedge
+ scrwidth
- nw
->Width
;
597 if (mx
< leftedge
) mx
= leftedge
;
598 else if (mx
> val
) mx
= val
;
600 val
= topedge
+ scrheight
- nw
->Height
;
602 if (my
< topedge
) my
= topedge
;
603 else if (my
> val
) my
= val
;
605 nw
->LeftEdge
= mx
; nw
->TopEdge
= my
;
609 /****************************************************************************************/
611 /* This one is from closewindowsafely.asm */
613 SAVEDS ASM
void RTFuncs_CloseWindowSafely(REGPARAM(a0
, struct Window
*, window
))
615 struct IntuiMessage
*msg
;
620 if(window
->UserPort
!= NULL
)
622 msg
= (struct IntuiMessage
*)window
->UserPort
->mp_MsgList
.lh_Head
;
624 while((succ
= msg
->ExecMessage
.mn_Node
.ln_Succ
))
626 if(msg
->IDCMPWindow
== window
)
628 Remove((struct Node
*)msg
);
629 ReplyMsg((struct Message
*)msg
);
632 msg
= (struct IntuiMessage
*)succ
;
636 window
->UserPort
= NULL
;
638 ModifyIDCMP(window
, 0);
645 /****************************************************************************************/
646 /****************************************************************************************/