New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / screendepth.c
bloba6dd679e43ddbe2d3ca1953a82c79dc75fc4f742
1 /*
2 Copyright 1995-2003, 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
75 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
77 struct ScreenDepthActionMsg msg;
79 FireScreenNotifyMessageCode((IPTR) screen, flags, SNOTIFY_SCREENDEPTH, IntuitionBase);
81 if (reserved != NULL) return;
82 SANITY_CHECK(screen)
84 msg.screen = screen;
85 msg.flags = flags;
86 DoASyncAction((APTR)int_screendepth, &msg.msg, sizeof(msg), IntuitionBase);
88 AROS_LIBFUNC_EXIT
90 } /* ScreenDepth */
92 /*****************************************************************************************/
94 static VOID int_screendepth(struct ScreenDepthActionMsg *msg,
95 struct IntuitionBase *IntuitionBase)
97 struct Screen *screen = msg->screen;
98 ULONG flags = msg->flags;
99 ULONG ilock = LockIBase(0); /* before access to FirstScreen */
100 struct Screen *family = NULL,
101 *current = IntuitionBase->FirstScreen,
102 #ifndef __MORPHOS__
103 *oldfront = current,
104 #endif
105 *previous = NULL,
106 *prefamily = NULL;
107 struct Window *win;
109 /* Find the screen in the list and check for family */
110 while ( current && current!=screen )
112 if ( flags & SDEPTH_INFAMILY )
114 /* Check if this is the first child in a family */
115 if ( !family && (GetPrivScreen(current)->SpecialFlags & SF_IsChild) )
117 family = current;
118 prefamily = previous;
120 /* Check if this screen is a child so next one belongs to current family */
121 if ( family && !(GetPrivScreen(current)->SpecialFlags & SF_IsChild) )
123 family = NULL;
124 prefamily = NULL;
127 previous = current;
128 current = current->NextScreen;
131 if ( current )
133 if ( ! (flags & SDEPTH_TOBACK) ) /* SDEPTH_TOFRONT is #defined as 0 */
135 if ( previous ) /* I'm not the very first screen */
137 if ( flags & SDEPTH_INFAMILY )
139 if ( GetPrivScreen(current)->SpecialFlags & SF_IsChild )
140 { /* Move me in the front of my family */
141 if ( family ) /* I'm not the first one in my family */
143 previous->NextScreen = current->NextScreen;
144 current->NextScreen = family;
145 if ( prefamily )
147 prefamily->NextScreen = current;
149 else
151 IntuitionBase->FirstScreen = current;
155 else if ( GetPrivScreen(current)->SpecialFlags & SF_IsParent )
156 { /* Move whole family */
157 if ( prefamily ) /* We are not the first family */
159 prefamily->NextScreen = current->NextScreen;
160 current->NextScreen = IntuitionBase->FirstScreen;
161 IntuitionBase->FirstScreen = family;
164 else
165 { /* I have no family */
166 previous->NextScreen = current->NextScreen;
167 current->NextScreen = IntuitionBase->FirstScreen;
168 IntuitionBase->FirstScreen = current;
171 } /* SDEPTH_INFAMILY */
172 else
174 if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) )
175 { /* Move my whole family */
176 if ( !family )
178 prefamily = previous;
179 family = current;
181 if ( prefamily )
182 { /* We are not the first family */
183 while ( !(GetPrivScreen(current)->SpecialFlags & SF_IsParent) )
185 current = current->NextScreen;
187 prefamily->NextScreen = current->NextScreen;
188 current->NextScreen = IntuitionBase->FirstScreen;
189 IntuitionBase->FirstScreen = family;
192 else
193 { /* I have no family */
194 previous->NextScreen = current->NextScreen;
195 current->NextScreen = IntuitionBase->FirstScreen;
196 IntuitionBase->FirstScreen = current;
199 } /* ! SDEPTH_INFAMILY */
201 } /* if (previous) */
203 } /* if SDEPTH_TO_FRONT */
205 else if ( flags & SDEPTH_TOBACK )
207 if ( flags & SDEPTH_INFAMILY )
209 if ( GetPrivScreen(current)->SpecialFlags & SF_IsChild )
211 /* Go to last screen of this family */
212 while ( !GetPrivScreen(current->NextScreen)->SpecialFlags & SF_IsParent )
214 current = current->NextScreen;
216 if ( current != screen ) /* I'm not the last screen of my family */
218 if ( previous )
220 previous->NextScreen = screen->NextScreen;
222 else
224 IntuitionBase->FirstScreen = screen->NextScreen;
226 screen->NextScreen = current->NextScreen;
227 current->NextScreen = screen;
230 else if ( GetPrivScreen(current)->SpecialFlags & SF_IsParent )
232 if ( current->NextScreen ) /* I'm not the last screen */
234 while ( current->NextScreen )
236 current = current->NextScreen;
238 if ( prefamily )
240 prefamily->NextScreen = screen->NextScreen;
242 else
244 IntuitionBase->FirstScreen = screen->NextScreen;
246 if ( family )
248 current->NextScreen = family;
250 else
252 current->NextScreen = screen;
254 screen->NextScreen = NULL;
257 else
259 if ( current->NextScreen ) /* I'm not the last screen */
261 while ( current->NextScreen )
263 current = current->NextScreen;
265 if ( previous )
267 previous->NextScreen = screen->NextScreen;
269 else
271 IntuitionBase->FirstScreen = screen->NextScreen;
273 current->NextScreen = screen;
274 screen->NextScreen = NULL;
278 } /* SDEPTH_INFAMILY */
279 else
281 struct Screen *last;
283 if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) )
285 if ( !family )
287 family = current;
288 prefamily = previous;
290 /* Go to last screen of this family */
291 while ( !GetPrivScreen(current)->SpecialFlags & SF_IsParent )
293 current = current->NextScreen;
295 if ( current->NextScreen ) /* We are not the last family */
297 last = current->NextScreen;
298 while ( last->NextScreen )
300 last = last->NextScreen;
302 if ( prefamily )
304 prefamily->NextScreen = current->NextScreen;
306 else
308 IntuitionBase->FirstScreen = current->NextScreen;
310 last->NextScreen = family;
311 current->NextScreen = NULL;
314 } /* if ( GetPrivScreen(current)->SpecialFlags & (SF_IsChild|SF_IsParent) ) */
315 else
317 if ( current->NextScreen ) /* I'm not the last screen */
319 while ( current->NextScreen )
321 current = current->NextScreen;
323 if ( previous )
325 previous->NextScreen = screen->NextScreen;
327 else
329 IntuitionBase->FirstScreen = screen->NextScreen;
331 current->NextScreen = screen;
332 screen->NextScreen = NULL;
335 } /* current not SF_isChild | SF_IsParent */
337 } /* ! SDEPTH_INFAMILY */
339 } /* if SDEPTH_TO_BACK */
341 } /* if (current) */
343 #ifdef __MORPHOS__
344 IntuitionBase->ActiveScreen = IntuitionBase->FirstScreen;
345 RethinkDisplay();
346 #else
347 if (IntuitionBase->FirstScreen != oldfront)
349 SetFrontBitMap(IntuitionBase->FirstScreen->RastPort.BitMap, TRUE);
350 IntuitionBase->ActiveScreen = IntuitionBase->FirstScreen;
352 #endif
354 win = NULL;
355 #if 0 /* FIXME: backport, disabled */
356 if (IntuitionBase->FirstScreen && GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_SCREENACTIVATION)
358 struct Window *scanw = 0;
360 for (scanw = IntuitionBase->FirstScreen->FirstWindow; scanw ; scanw = scanw->NextWindow)
362 if (win)
364 if ((IW(scanw)->activationtime.tv_secs > IW(win)->activationtime.tv_secs) ||
365 ((IW(scanw)->activationtime.tv_secs == IW(win)->activationtime.tv_secs) && (IW(scanw)->activationtime.tv_micro > IW(win)->activationtime.tv_micro)))
367 win = scanw;
371 if (!win) win = scanw;
374 if (!win) win = IntuitionBase->FirstScreen->FirstWindow;
375 if (IntuitionBase->ActiveWindow && IntuitionBase->ActiveWindow->WScreen == IntuitionBase->FirstScreen) win = NULL;
377 #endif
379 /* now set the default pub screen */
380 /* if the screen is not a public one we just ignore this */
382 if (IntuitionBase->FirstScreen && GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_DEFPUBSCREEN)
384 if (GetPrivScreen(IntuitionBase->FirstScreen)->pubScrNode && (IntuitionBase->FirstScreen->Flags & (PUBLICSCREEN | WBENCHSCREEN)))
386 GetPrivIBase(IntuitionBase)->DefaultPubScreen = IntuitionBase->FirstScreen;
390 UnlockIBase(ilock);
392 if (win)
394 ActivateWindow(win);