Added kernel module for starting the usb stack at boot time. It's not activated thoug...
[cake.git] / rom / intuition / activatewindow.c
blob9b3815a256f09473112791da68af5a4ce44c67d6
1 /*
2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
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"
18 #include "gadgets.h"
19 #include "menus.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 /*****************************************************************************
33 NAME */
34 #include <proto/intuition.h>
36 AROS_LH1(void, ActivateWindow,
38 /* SYNOPSIS */
39 AROS_LHA(struct Window *, window, A0),
41 /* LOCATION */
42 struct IntuitionBase *, IntuitionBase, 75, Intuition)
44 /* FUNCTION
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.
49 INPUTS
50 window - The window to activate
52 RESULT
53 None.
55 NOTES
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.
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 ModifyIDCMP(), OpenWindow(), CloseWindow()
70 INTERNALS
72 *****************************************************************************/
74 AROS_LIBFUNC_INIT
76 struct ActivateWindowActionMsg msg;
78 DEBUG_ACTIVATEWINDOW(dprintf("ActivateWindow: Window 0x%lx\n",
79 window));
81 msg.window = window;
82 DoASyncAction((APTR)int_activatewindow, &msg.msg, sizeof(msg), IntuitionBase);
84 AROS_LIBFUNC_EXIT
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;
101 ULONG lock;
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",
120 window, oldactive));
122 if (oldactive != window)
124 GetPrivIBase(IntuitionBase)->PointerDelay = 0;
126 if (oldactive)
128 ih_fire_intuimessage(oldactive,
129 IDCMP_INACTIVEWINDOW,
131 oldactive,
132 IntuitionBase);
134 scr = GetPrivScreen(oldactive->WScreen);
135 scr->Screen.Title = scr->Screen.DefaultTitle;
138 if (window)
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;
157 else
159 scr->Screen.Title = scr->Screen.DefaultTitle;
163 /* now set the ActiveScreen! */
164 if (scr)
166 struct Screen *old;
167 struct Window *win;
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;
180 while (win)
182 UpdateMouseCoords(win);
183 win = win->NextWindow;
187 IntuitionBase->ActiveScreen = (struct Screen *)scr;
191 if (scr)
193 struct SharedPointer *shared_pointer;
195 if (!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;
209 if (window)
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);
218 else
220 DEBUG_POINTER(dprintf("ActivateWindow: can't set pointer.\n"));
225 UnlockIBase(lock);
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
244 if (window)
246 GetSysTime(&IW(window)->activationtime);
248 #endif
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);
258 if (window)
260 if ((window->Flags & WFLG_TOOLBOX) == 0)
261 ih_fire_intuimessage(window,
262 IDCMP_ACTIVEWINDOW,
264 window,
265 IntuitionBase);
268 else
270 int_refreshwindowframe(window, REFRESHGAD_BORDER, 0, IntuitionBase);
273 #ifdef __MORPHOS__
274 Forbid();
275 if (window && window->UserPort)
277 struct Task *apptask = window->UserPort->mp_SigTask;
279 if (apptask && (!apptask->tc_SigWait) && (apptask->tc_State == TS_WAIT))
281 //task is DEAD!
282 //give some visual feedback to the user
284 IW(window)->specialflags |= SPFLAG_IAMDEAD;
286 int_refreshwindowframe(window,REFRESHGAD_TOPBORDER,0,IntuitionBase);
289 else
291 IW(window)->specialflags &= ~SPFLAG_IAMDEAD;
294 Permit();
295 #endif