grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / intuition / activatewindow.c
blob25e45098f889b6515ede158942d4978213ef2d54
1 /*
2 Copyright © 1995-2013, 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 "monitorclass_private.h"
21 #include <intuition/pointerclass.h>
23 struct ActivateWindowActionMsg
25 struct IntuiActionMsg msg;
26 struct Window *window;
29 static VOID int_activatewindow(struct ActivateWindowActionMsg *msg,
30 struct IntuitionBase *IntuitionBase);
32 /*****************************************************************************
34 NAME */
35 #include <proto/intuition.h>
37 AROS_LH1(void, ActivateWindow,
39 /* SYNOPSIS */
40 AROS_LHA(struct Window *, window, A0),
42 /* LOCATION */
43 struct IntuitionBase *, IntuitionBase, 75, Intuition)
45 /* FUNCTION
46 Activates the specified window. The window gets the focus
47 and all further input is sent to that window. If the window
48 requested it, it will get a IDCMP_ACTIVEWINDOW message.
50 INPUTS
51 window - The window to activate
53 RESULT
54 None.
56 NOTES
57 If the user has an autopointer tool (sunmouse), the call will
58 succeed, but the tool will deactivate the window right after
59 this function has activated it. It is not a good idea to try to
60 prevent this by waiting for IDCMP_INACTIVEWINDOW and activating
61 the window again since that will produce an annoying flicker and
62 it will slow down the computer a lot.
64 EXAMPLE
66 BUGS
68 SEE ALSO
69 ModifyIDCMP(), OpenWindow(), CloseWindow()
71 INTERNALS
73 *****************************************************************************/
75 AROS_LIBFUNC_INIT
77 struct ActivateWindowActionMsg msg;
79 DEBUG_ACTIVATEWINDOW(dprintf("ActivateWindow: Window 0x%lx\n",
80 window));
82 msg.window = window;
83 DoASyncAction((APTR)int_activatewindow, &msg.msg, sizeof(msg), IntuitionBase);
85 AROS_LIBFUNC_EXIT
87 } /* ActivateWindow */
89 /* This is called on the input.device's context */
91 static VOID int_activatewindow(struct ActivateWindowActionMsg *msg,
92 struct IntuitionBase *IntuitionBase)
94 struct IIHData *iihdata = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
96 /* On the Amiga ActivateWindow is delayed if there
97 is an active gadget (altough this does not seem
98 to be true for string gadgets). We just ignore
99 ActivateWindow in such a case. */
101 struct Window *window = msg->window;
102 ULONG lock;
103 struct Window *oldactive;
104 Object *pointer = NULL;
105 struct IntScreen *scr = NULL;
106 struct InputEvent *ie;
108 if (!ResourceExisting(window, RESOURCE_WINDOW, IntuitionBase)) return;
109 // if (window->Flags & WFLG_TOOLBOX) return;
111 if ((!iihdata->ActiveGadget) ||
112 (iihdata->ActiveGadget && ((iihdata->ActiveGadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_SDEPTH)))
115 lock = LockIBase(0UL);
117 if (window->Flags & WFLG_TOOLBOX) oldactive = NULL; else oldactive = IntuitionBase->ActiveWindow;
118 if ((window->Flags & WFLG_TOOLBOX) == 0) IntuitionBase->ActiveWindow = window;
120 DEBUG_ACTIVATEWINDOW(dprintf("IntActivateWindow: Window 0x%lx OldActive 0x%lx\n",
121 window, oldactive));
123 if (oldactive != window)
125 GetPrivIBase(IntuitionBase)->PointerDelay = 0;
127 if (oldactive)
129 ih_fire_intuimessage(oldactive,
130 IDCMP_INACTIVEWINDOW,
132 oldactive,
133 IntuitionBase);
135 scr = GetPrivScreen(oldactive->WScreen);
136 scr->Screen.Title = scr->Screen.DefaultTitle;
139 if (window)
142 Tasks are allowed to modify window->Flags, for example
143 set/clear WFLG_RMBTRAP. It is not certain that every
144 compiler on every machine produces an atomic instruction.
146 /* FIXME: check that window->Flags is atomically set everywhere */
147 AROS_ATOMIC_OR(window->Flags, WFLG_WINDOWACTIVE);
149 pointer = IW(window)->pointer;
150 if (IW(window)->busy)
151 pointer = GetPrivIBase(IntuitionBase)->BusyPointer;
153 scr = GetPrivScreen(window->WScreen);
154 if (window->ScreenTitle)
156 scr->Screen.Title = window->ScreenTitle;
158 else
160 scr->Screen.Title = scr->Screen.DefaultTitle;
164 /* now set the ActiveScreen! */
165 if (scr)
167 struct Screen *old;
168 struct Window *win;
170 old = IntuitionBase->ActiveScreen;
172 if (old && (old != (struct Screen *)scr))
175 /* this avoids mouse "jump" effect */
176 /* .. but causes setting wrong coordinates - sonic
177 scr->Screen.MouseX = old->MouseX;
178 scr->Screen.MouseY = old->MouseY;*/
180 win = scr->Screen.FirstWindow;
182 while (win)
184 UpdateMouseCoords(win);
185 win = win->NextWindow;
189 IntuitionBase->ActiveScreen = (struct Screen *)scr;
193 if (scr)
195 struct SharedPointer *shared_pointer;
197 if (!pointer)
198 pointer = GetPrivIBase(IntuitionBase)->DefaultPointer;
200 GetAttr(POINTERA_SharedPointer, pointer, (IPTR *)&shared_pointer);
202 DEBUG_POINTER(dprintf("ActivateWindow: scr 0x%lx pointer 0x%lx sprite 0x%lx\n",
203 scr, pointer, shared_pointer->sprite));
205 if (DoMethod(scr->IMonitorNode, MM_SetPointerShape, shared_pointer))
207 ObtainSharedPointer(shared_pointer, IntuitionBase);
208 ReleaseSharedPointer(scr->Pointer, IntuitionBase);
209 scr->Pointer = shared_pointer;
210 if (window)
212 window->XOffset = shared_pointer->xoffset;
213 window->YOffset = shared_pointer->yoffset;
216 else
218 DEBUG_POINTER(dprintf("ActivateWindow: can't set pointer.\n"));
223 UnlockIBase(lock);
225 if (oldactive && oldactive != window)
227 AROS_ATOMIC_AND(oldactive->Flags, ~WFLG_WINDOWACTIVE);
229 int_refreshwindowframe(oldactive, REFRESHGAD_BORDER, 0, IntuitionBase);
230 if (!window || oldactive->WScreen != window->WScreen)
231 RenderScreenBar(oldactive->WScreen, FALSE, IntuitionBase);
235 if (window && oldactive != window)
237 int_refreshwindowframe(window, REFRESHGAD_BORDER, 0, IntuitionBase);
238 RenderScreenBar(window->WScreen, FALSE, IntuitionBase);
241 #ifdef TIMEVALWINDOWACTIVATION
242 if (window)
244 GetSysTime(&IW(window)->activationtime);
246 #endif
248 if ((ie = AllocInputEvent(iihdata)))
250 ie->ie_Class = IECLASS_EVENT;
251 ie->ie_Code = IECODE_NEWACTIVE;
252 ie->ie_EventAddress = window;
253 CurrentTime(&ie->ie_TimeStamp.tv_secs, &ie->ie_TimeStamp.tv_micro);
256 if (window)
258 if ((window->Flags & WFLG_TOOLBOX) == 0)
259 ih_fire_intuimessage(window,
260 IDCMP_ACTIVEWINDOW,
262 window,
263 IntuitionBase);
266 else
268 int_refreshwindowframe(window, REFRESHGAD_BORDER, 0, IntuitionBase);
271 #ifdef __MORPHOS__
272 Forbid();
273 if (window && window->UserPort)
275 struct Task *apptask = window->UserPort->mp_SigTask;
277 if (apptask && (!apptask->tc_SigWait) && (apptask->tc_State == TS_WAIT))
279 //task is DEAD!
280 //give some visual feedback to the user
282 IW(window)->specialflags |= SPFLAG_IAMDEAD;
284 int_refreshwindowframe(window,REFRESHGAD_TOPBORDER,0,IntuitionBase);
287 else
289 IW(window)->specialflags &= ~SPFLAG_IAMDEAD;
292 Permit();
293 #endif