New attempt to get the svn revision into the AboutAROS requester.
[cake.git] / rom / intuition / activatewindow.c
blobf7a94365aa70423d5a054f1c4debbe52445186c1
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)
154 scr->Screen.Title = window->ScreenTitle;
157 /* now set the ActiveScreen! */
158 if (scr)
160 struct Screen *old;
161 struct Window *win;
163 old = IntuitionBase->ActiveScreen;
165 if (old && (old != (struct Screen *)scr))
168 /* this avoids mouse "jump" effect */
169 scr->Screen.MouseX = old->MouseX;
170 scr->Screen.MouseY = old->MouseY;
172 win = scr->Screen.FirstWindow;
174 while (win)
176 UpdateMouseCoords(win);
177 win = win->NextWindow;
181 IntuitionBase->ActiveScreen = (struct Screen *)scr;
185 if (scr)
187 struct SharedPointer *shared_pointer;
189 if (!pointer)
190 pointer = GetPrivIBase(IntuitionBase)->DefaultPointer;
192 GetAttr(POINTERA_SharedPointer, pointer, (IPTR *)&shared_pointer);
194 DEBUG_POINTER(dprintf("ActivateWindow: scr 0x%lx pointer 0x%lx sprite 0x%lx\n",
195 scr, pointer, shared_pointer->sprite));
197 if (ChangeExtSpriteA(&scr->Screen.ViewPort,
198 scr->Pointer->sprite, shared_pointer->sprite, NULL))
200 ObtainSharedPointer(shared_pointer, IntuitionBase);
201 ReleaseSharedPointer(scr->Pointer, IntuitionBase);
202 scr->Pointer = shared_pointer;
203 if (window)
205 window->XOffset = shared_pointer->xoffset;
206 window->YOffset = shared_pointer->yoffset;
209 //jDc: fix some weird refresh pbs
210 SetPointerPos(scr->Screen.MouseX, scr->Screen.MouseY);
212 else
214 DEBUG_POINTER(dprintf("ActivateWindow: can't set pointer.\n"));
219 UnlockIBase(lock);
221 if (oldactive && oldactive != window)
223 AROS_ATOMIC_AND(oldactive->Flags, ~WFLG_WINDOWACTIVE);
225 int_refreshwindowframe(oldactive, REFRESHGAD_BORDER, 0, IntuitionBase);
226 if (!window || oldactive->WScreen != window->WScreen)
227 RenderScreenBar(oldactive->WScreen, FALSE, IntuitionBase);
231 if (window && oldactive != window)
233 int_refreshwindowframe(window, REFRESHGAD_BORDER, 0, IntuitionBase);
234 RenderScreenBar(window->WScreen, FALSE, IntuitionBase);
237 #ifdef TIMEVALWINDOWACTIVATION
238 if (window)
240 GetSysTime(&IW(window)->activationtime);
242 #endif
244 if ((ie = AllocInputEvent(iihdata)))
246 ie->ie_Class = IECLASS_EVENT;
247 ie->ie_Code = IECODE_NEWACTIVE;
248 ie->ie_EventAddress = window;
249 CurrentTime(&ie->ie_TimeStamp.tv_secs, &ie->ie_TimeStamp.tv_micro);
252 if (window)
254 if ((window->Flags & WFLG_TOOLBOX) == 0)
255 ih_fire_intuimessage(window,
256 IDCMP_ACTIVEWINDOW,
258 window,
259 IntuitionBase);
262 else
264 int_refreshwindowframe(window, REFRESHGAD_BORDER, 0, IntuitionBase);
267 #ifdef __MORPHOS__
268 Forbid();
269 if (window && window->UserPort)
271 struct Task *apptask = window->UserPort->mp_SigTask;
273 if (apptask && (!apptask->tc_SigWait) && (apptask->tc_State == TS_WAIT))
275 //task is DEAD!
276 //give some visual feedback to the user
278 IW(window)->specialflags |= SPFLAG_IAMDEAD;
280 int_refreshwindowframe(window,REFRESHGAD_TOPBORDER,0,IntuitionBase);
283 else
285 IW(window)->specialflags &= ~SPFLAG_IAMDEAD;
288 Permit();
289 #endif