2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 #include <proto/graphics.h>
8 #include <proto/timer.h>
9 #include <intuition/gadgetclass.h>
10 #include "intuition_intern.h"
11 #include "inputhandler.h"
12 #include "inputhandler_actions.h"
13 #include "inputhandler_support.h"
14 #include "boopsigadgets.h"
15 #include "boolgadgets.h"
16 #include "propgadgets.h"
17 #include "strgadgets.h"
20 #include <intuition/pointerclass.h>
22 struct ActivateWindowActionMsg
24 struct IntuiActionMsg msg
;
25 struct Window
*window
;
28 static VOID
int_activatewindow(struct ActivateWindowActionMsg
*msg
,
29 struct IntuitionBase
*IntuitionBase
);
31 /*****************************************************************************
34 #include <proto/intuition.h>
36 AROS_LH1(void, ActivateWindow
,
39 AROS_LHA(struct Window
*, window
, A0
),
42 struct IntuitionBase
*, IntuitionBase
, 75, Intuition
)
45 Activates the specified window. The window gets the focus
46 and all further input it sent to that window. If the window
47 requested it, it will get a IDCMP_ACTIVEWINDOW message.
50 window - The window to activate
56 If the user has an autopointer tool (sunmouse), the call will
57 succeed, but the tool will deactivate the window right after
58 this function has activated it. It is no good idea to try to
59 prevent this by waiting for IDCMP_INACTIVEWINDOW and activating
60 the window again since that will produce an anoying flicker and
61 it will slow down the computer a lot.
68 ModifyIDCMP(), OpenWindow(), CloseWindow()
72 *****************************************************************************/
76 struct ActivateWindowActionMsg msg
;
78 DEBUG_ACTIVATEWINDOW(dprintf("ActivateWindow: Window 0x%lx\n",
82 DoASyncAction((APTR
)int_activatewindow
, &msg
.msg
, sizeof(msg
), IntuitionBase
);
86 } /* ActivateWindow */
88 /* This is called on the input.device's context */
90 static VOID
int_activatewindow(struct ActivateWindowActionMsg
*msg
,
91 struct IntuitionBase
*IntuitionBase
)
93 struct IIHData
*iihdata
= (struct IIHData
*)GetPrivIBase(IntuitionBase
)->InputHandler
->is_Data
;
95 /* On the Amiga ActivateWindow is delayed if there
96 is an active gadget (altough this does not seem
97 to be true for string gadgets). We just ignore
98 ActivateWindow in such a case. */
100 struct Window
*window
= msg
->window
;
102 struct Window
*oldactive
;
103 Object
*pointer
= NULL
;
104 struct IntScreen
*scr
= NULL
;
105 struct InputEvent
*ie
;
107 if (!ResourceExisting(window
, RESOURCE_WINDOW
, IntuitionBase
)) return;
108 // if (window->Flags & WFLG_TOOLBOX) return;
110 if ((!iihdata
->ActiveGadget
) ||
111 (iihdata
->ActiveGadget
&& ((iihdata
->ActiveGadget
->GadgetType
& GTYP_SYSTYPEMASK
) == GTYP_SDEPTH
)))
114 lock
= LockIBase(0UL);
116 if (window
->Flags
& WFLG_TOOLBOX
) oldactive
= NULL
; else oldactive
= IntuitionBase
->ActiveWindow
;
117 if ((window
->Flags
& WFLG_TOOLBOX
) == 0) IntuitionBase
->ActiveWindow
= window
;
119 DEBUG_ACTIVATEWINDOW(dprintf("IntActivateWindow: Window 0x%lx OldActive 0x%lx\n",
122 if (oldactive
!= window
)
124 GetPrivIBase(IntuitionBase
)->PointerDelay
= 0;
128 ih_fire_intuimessage(oldactive
,
129 IDCMP_INACTIVEWINDOW
,
134 scr
= GetPrivScreen(oldactive
->WScreen
);
135 scr
->Screen
.Title
= scr
->Screen
.DefaultTitle
;
141 Tasks are allowed to modify window->Flags, for example
142 set/clear WFLG_RMBTRAP. It is not certain that every
143 compiler on every machine produces an atomic instruction.
145 #warning check that window->Flags is atomically set everywhere!
146 AROS_ATOMIC_OR(window
->Flags
, WFLG_WINDOWACTIVE
);
148 pointer
= IW(window
)->pointer
;
149 if (IW(window
)->busy
)
150 pointer
= GetPrivIBase(IntuitionBase
)->BusyPointer
;
152 scr
= GetPrivScreen(window
->WScreen
);
153 if (window
->ScreenTitle
)
155 scr
->Screen
.Title
= window
->ScreenTitle
;
159 scr
->Screen
.Title
= scr
->Screen
.DefaultTitle
;
163 /* now set the ActiveScreen! */
169 old
= IntuitionBase
->ActiveScreen
;
171 if (old
&& (old
!= (struct Screen
*)scr
))
174 /* this avoids mouse "jump" effect */
175 scr
->Screen
.MouseX
= old
->MouseX
;
176 scr
->Screen
.MouseY
= old
->MouseY
;
178 win
= scr
->Screen
.FirstWindow
;
182 UpdateMouseCoords(win
);
183 win
= win
->NextWindow
;
187 IntuitionBase
->ActiveScreen
= (struct Screen
*)scr
;
193 struct SharedPointer
*shared_pointer
;
196 pointer
= GetPrivIBase(IntuitionBase
)->DefaultPointer
;
198 GetAttr(POINTERA_SharedPointer
, pointer
, (IPTR
*)&shared_pointer
);
200 DEBUG_POINTER(dprintf("ActivateWindow: scr 0x%lx pointer 0x%lx sprite 0x%lx\n",
201 scr
, pointer
, shared_pointer
->sprite
));
203 if (ChangeExtSpriteA(&scr
->Screen
.ViewPort
,
204 scr
->Pointer
->sprite
, shared_pointer
->sprite
, NULL
))
206 ObtainSharedPointer(shared_pointer
, IntuitionBase
);
207 ReleaseSharedPointer(scr
->Pointer
, IntuitionBase
);
208 scr
->Pointer
= shared_pointer
;
211 window
->XOffset
= shared_pointer
->xoffset
;
212 window
->YOffset
= shared_pointer
->yoffset
;
215 //jDc: fix some weird refresh pbs
216 SetPointerPos(scr
->Screen
.MouseX
, scr
->Screen
.MouseY
);
220 DEBUG_POINTER(dprintf("ActivateWindow: can't set pointer.\n"));
227 if (oldactive
&& oldactive
!= window
)
229 AROS_ATOMIC_AND(oldactive
->Flags
, ~WFLG_WINDOWACTIVE
);
231 int_refreshwindowframe(oldactive
, REFRESHGAD_BORDER
, 0, IntuitionBase
);
232 if (!window
|| oldactive
->WScreen
!= window
->WScreen
)
233 RenderScreenBar(oldactive
->WScreen
, FALSE
, IntuitionBase
);
237 if (window
&& oldactive
!= window
)
239 int_refreshwindowframe(window
, REFRESHGAD_BORDER
, 0, IntuitionBase
);
240 RenderScreenBar(window
->WScreen
, FALSE
, IntuitionBase
);
243 #ifdef TIMEVALWINDOWACTIVATION
246 GetSysTime(&IW(window
)->activationtime
);
250 if ((ie
= AllocInputEvent(iihdata
)))
252 ie
->ie_Class
= IECLASS_EVENT
;
253 ie
->ie_Code
= IECODE_NEWACTIVE
;
254 ie
->ie_EventAddress
= window
;
255 CurrentTime(&ie
->ie_TimeStamp
.tv_secs
, &ie
->ie_TimeStamp
.tv_micro
);
260 if ((window
->Flags
& WFLG_TOOLBOX
) == 0)
261 ih_fire_intuimessage(window
,
270 int_refreshwindowframe(window
, REFRESHGAD_BORDER
, 0, IntuitionBase
);
275 if (window
&& window
->UserPort
)
277 struct Task
*apptask
= window
->UserPort
->mp_SigTask
;
279 if (apptask
&& (!apptask
->tc_SigWait
) && (apptask
->tc_State
== TS_WAIT
))
282 //give some visual feedback to the user
284 IW(window
)->specialflags
|= SPFLAG_IAMDEAD
;
286 int_refreshwindowframe(window
,REFRESHGAD_TOPBORDER
,0,IntuitionBase
);
291 IW(window
)->specialflags
&= ~SPFLAG_IAMDEAD
;