Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / intuition / screendepth.c
blobe414fa4d03ea9c76acde3ded34945a890343080c
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$
6 Change order of screens.
7 */
9 #include <proto/graphics.h>
11 #include "intuition_intern.h"
12 #include "inputhandler.h"
13 #include "inputhandler_actions.h"
15 struct ScreenDepthActionMsg
17 struct IntuiActionMsg msg;
18 struct Screen *screen;
19 ULONG flags;
22 static VOID int_screendepth(struct ScreenDepthActionMsg *msg,
23 struct IntuitionBase *IntuitionBase);
25 /*****************************************************************************
27 NAME */
28 #include <proto/intuition.h>
30 AROS_LH3(void, ScreenDepth,
32 /* SYNOPSIS */
33 AROS_LHA(struct Screen *, screen, A0),
34 AROS_LHA(ULONG , flags, D0),
35 AROS_LHA(APTR , reserved, A1),
37 /* LOCATION */
38 struct IntuitionBase *, IntuitionBase, 131, Intuition)
40 /* FUNCTION
41 Move the specified screen to the front or back, based on passed flag.
42 If the screen is in a group, the screen will change its position in
43 the group only. If the screen is the parent of a group, the whole
44 group will be moved.
46 INPUTS
47 screen - Move this screen.
48 flags - SDEPTH_TOFRONT or SDEPTH_TOBACK for bringing the screen to
49 front or back.
50 If the screen is a child of another screen you may specify
51 SDEPTH_INFAMILY to move the screen within the family. If
52 not specified the whole family will move.
53 reserved - For future use. MUST be NULL by now.
55 RESULT
56 None.
58 NOTES
59 Only the owner of the screen should use SDEPTH_INFAMILY.
60 Intentionally commodities should not change the internal arrangement
61 of screen families.
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 ScreenToBack(), ScreenToFront()
70 INTERNALS
72 *****************************************************************************/
74 AROS_LIBFUNC_INIT
76 struct ScreenDepthActionMsg msg;
78 FireScreenNotifyMessageCode((IPTR) screen, flags, SNOTIFY_SCREENDEPTH, IntuitionBase);
80 if (reserved != NULL) return;
81 SANITY_CHECK(screen)
83 msg.screen = screen;
84 msg.flags = flags;
85 DoASyncAction((APTR)int_screendepth, &msg.msg, sizeof(msg), IntuitionBase);
87 AROS_LIBFUNC_EXIT
89 } /* ScreenDepth */
91 /*****************************************************************************************/
93 static VOID int_screendepth(struct ScreenDepthActionMsg *msg,
94 struct IntuitionBase *IntuitionBase)
96 struct Screen *screen = msg->screen;
97 ULONG flags = msg->flags;
98 ULONG ilock = LockIBase(0); /* before access to FirstScreen */
99 struct Screen *family = NULL,
100 *current = IntuitionBase->FirstScreen,
101 #ifndef __MORPHOS__
102 *oldfront = current,
103 #endif
104 *previous = NULL,
105 *prefamily = NULL;
106 struct Window *win;
108 /* Find the screen in the list and check for family */
109 while ( current && current!=screen )
111 if ( flags & SDEPTH_INFAMILY )
113 /* Check if this is the first child in a family */
114 if ( !family && (GetPrivScreen(current)->SpecialFlags & SF_IsChild) )
116 family = current;
117 prefamily = previous;
119 /* Check if this screen is a child so next one belongs to current family */
120 if ( family && !(GetPrivScreen(current)->SpecialFlags & SF_IsChild) )
122 family = NULL;
123 prefamily = NULL;
126 previous = current;
127 current = current->NextScreen;
130 if ( current )
132 if ( ! (flags & SDEPTH_TOBACK) ) /* SDEPTH_TOFRONT is #defined as 0 */
134 if ( previous ) /* I'm not the very first screen */
136 if ( flags & SDEPTH_INFAMILY )
138 if ( GetPrivScreen(current)->SpecialFlags & SF_IsChild )
139 { /* Move me in the front of my family */
140 if ( family ) /* I'm not the first one in my family */
142 previous->NextScreen = current->NextScreen;
143 current->NextScreen = family;
144 if ( prefamily )
146 prefamily->NextScreen = current;
148 else
150 IntuitionBase->FirstScreen = current;
154 else if ( GetPrivScreen(current)->SpecialFlags & SF_IsParent )
155 { /* Move whole family */
156 if ( prefamily ) /* We are not the first family */
158 prefamily->NextScreen = current->NextScreen;
159 current->NextScreen = IntuitionBase->FirstScreen;
160 IntuitionBase->FirstScreen = family;
163 else
164 { /* I have no family */
165 previous->NextScreen = current->NextScreen;
166 current->NextScreen = IntuitionBase->FirstScreen;
167 IntuitionBase->FirstScreen = current;
170 } /* SDEPTH_INFAMILY */
171 else
173 if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) )
174 { /* Move my whole family */
175 if ( !family )
177 prefamily = previous;
178 family = current;
180 if ( prefamily )
181 { /* We are not the first family */
182 while ( !(GetPrivScreen(current)->SpecialFlags & SF_IsParent) )
184 current = current->NextScreen;
186 prefamily->NextScreen = current->NextScreen;
187 current->NextScreen = IntuitionBase->FirstScreen;
188 IntuitionBase->FirstScreen = family;
191 else
192 { /* I have no family */
193 previous->NextScreen = current->NextScreen;
194 current->NextScreen = IntuitionBase->FirstScreen;
195 IntuitionBase->FirstScreen = current;
198 } /* ! SDEPTH_INFAMILY */
200 } /* if (previous) */
202 } /* if SDEPTH_TO_FRONT */
204 else if ( flags & SDEPTH_TOBACK )
206 if ( flags & SDEPTH_INFAMILY )
208 if ( GetPrivScreen(current)->SpecialFlags & SF_IsChild )
210 /* Go to last screen of this family */
211 while ( !GetPrivScreen(current->NextScreen)->SpecialFlags & SF_IsParent )
213 current = current->NextScreen;
215 if ( current != screen ) /* I'm not the last screen of my family */
217 if ( previous )
219 previous->NextScreen = screen->NextScreen;
221 else
223 IntuitionBase->FirstScreen = screen->NextScreen;
225 screen->NextScreen = current->NextScreen;
226 current->NextScreen = screen;
229 else if ( GetPrivScreen(current)->SpecialFlags & SF_IsParent )
231 if ( current->NextScreen ) /* I'm not the last screen */
233 while ( current->NextScreen )
235 current = current->NextScreen;
237 if ( prefamily )
239 prefamily->NextScreen = screen->NextScreen;
241 else
243 IntuitionBase->FirstScreen = screen->NextScreen;
245 if ( family )
247 current->NextScreen = family;
249 else
251 current->NextScreen = screen;
253 screen->NextScreen = NULL;
256 else
258 if ( current->NextScreen ) /* I'm not the last screen */
260 while ( current->NextScreen )
262 current = current->NextScreen;
264 if ( previous )
266 previous->NextScreen = screen->NextScreen;
268 else
270 IntuitionBase->FirstScreen = screen->NextScreen;
272 current->NextScreen = screen;
273 screen->NextScreen = NULL;
277 } /* SDEPTH_INFAMILY */
278 else
280 struct Screen *last;
282 if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) )
284 if ( !family )
286 family = current;
287 prefamily = previous;
289 /* Go to last screen of this family */
290 while ( !GetPrivScreen(current)->SpecialFlags & SF_IsParent )
292 current = current->NextScreen;
294 if ( current->NextScreen ) /* We are not the last family */
296 last = current->NextScreen;
297 while ( last->NextScreen )
299 last = last->NextScreen;
301 if ( prefamily )
303 prefamily->NextScreen = current->NextScreen;
305 else
307 IntuitionBase->FirstScreen = current->NextScreen;
309 last->NextScreen = family;
310 current->NextScreen = NULL;
313 } /* if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) ) */
314 else
316 if ( current->NextScreen ) /* I'm not the last screen */
318 while ( current->NextScreen )
320 current = current->NextScreen;
322 if ( previous )
324 previous->NextScreen = screen->NextScreen;
326 else
328 IntuitionBase->FirstScreen = screen->NextScreen;
330 current->NextScreen = screen;
331 screen->NextScreen = NULL;
334 } /* current not SF_isChild | SF_IsParent */
336 } /* ! SDEPTH_INFAMILY */
338 } /* if SDEPTH_TO_BACK */
340 } /* if (current) */
342 #ifdef __MORPHOS__
343 IntuitionBase->ActiveScreen = IntuitionBase->FirstScreen;
344 RethinkDisplay();
345 #else
346 if (IntuitionBase->FirstScreen != oldfront)
348 SetFrontBitMap(IntuitionBase->FirstScreen->RastPort.BitMap, TRUE);
349 IntuitionBase->ActiveScreen = IntuitionBase->FirstScreen;
351 #endif
353 win = NULL;
354 #if 0 /* FIXME: backport, disabled */
355 if (IntuitionBase->FirstScreen && GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_SCREENACTIVATION)
357 struct Window *scanw = 0;
359 for (scanw = IntuitionBase->FirstScreen->FirstWindow; scanw ; scanw = scanw->NextWindow)
361 if (win)
363 if ((IW(scanw)->activationtime.tv_secs > IW(win)->activationtime.tv_secs) ||
364 ((IW(scanw)->activationtime.tv_secs == IW(win)->activationtime.tv_secs) && (IW(scanw)->activationtime.tv_micro > IW(win)->activationtime.tv_micro)))
366 win = scanw;
370 if (!win) win = scanw;
373 if (!win) win = IntuitionBase->FirstScreen->FirstWindow;
374 if (IntuitionBase->ActiveWindow && IntuitionBase->ActiveWindow->WScreen == IntuitionBase->FirstScreen) win = NULL;
376 #endif
378 /* now set the default pub screen */
379 /* if the screen is not a public one we just ignore this */
381 if (IntuitionBase->FirstScreen && GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_DEFPUBSCREEN)
383 if (GetPrivScreen(IntuitionBase->FirstScreen)->pubScrNode && (IntuitionBase->FirstScreen->Flags & (PUBLICSCREEN | WBENCHSCREEN)))
385 GetPrivIBase(IntuitionBase)->DefaultPubScreen = IntuitionBase->FirstScreen;
389 UnlockIBase(ilock);
391 if (win)
393 ActivateWindow(win);