New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / openscreen.c
blobc4a955684375134dd91a269ba50984c23718fca8
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 Open a new screen.
7 */
9 #include <exec/memory.h>
10 #include <utility/tagitem.h>
11 #include <intuition/screens.h>
12 #include <intuition/intuition.h>
13 #include <intuition/imageclass.h>
14 #include <intuition/windecorclass.h>
15 #include <intuition/scrdecorclass.h>
16 #include <intuition/gadgetclass.h>
17 #include <graphics/modeid.h>
18 #include <graphics/videocontrol.h>
19 #include <graphics/displayinfo.h>
20 #include <prefs/screenmode.h>
21 #include <proto/exec.h>
22 #include <proto/graphics.h>
23 #include <proto/layers.h>
24 #include <proto/utility.h>
25 #include <proto/intuition.h>
26 #include <string.h>
27 #ifdef __MORPHOS__
28 #include <proto/cybergraphics.h>
29 #include <cybergraphx/cybergraphics.h>
30 #endif
31 #include "intuition_intern.h"
32 #include "intuition_customize.h"
33 #include "intuition_extend.h"
34 #include "inputhandler.h"
35 #include "inputhandler_support.h"
36 #include "inputhandler_actions.h"
37 #include "menus.h"
39 #ifndef DEBUG_OpenScreen
40 #define DEBUG_OpenScreen 0
41 #endif
42 #undef DEBUG
43 #if DEBUG_OpenScreen
44 #define DEBUG 1
45 #endif
46 #include <aros/debug.h>
48 struct OpenScreenActionMsg
50 struct IntuiActionMsg msg;
51 struct IntScreen *Screen;
52 struct NewScreen *NewScreen;
53 struct List *List;
56 static VOID int_openscreen(struct OpenScreenActionMsg *msg,
57 struct IntuitionBase *IntuitionBase);
59 #ifdef __MORPHOS__
60 extern const ULONG defaultdricolors[DRIPEN_NUMDRIPENS];
61 #else
62 //FIXME: NUMDRIPENS == DRIPEN_NUMDRIPENS ???
63 extern const ULONG defaultdricolors[NUMDRIPENS];
64 #endif
66 #if DEBUG
67 #undef THIS_FILE
68 static const char THIS_FILE[] = __FILE__;
69 #endif
72 #if 0
73 #define DEBUG_OBTAINPEN(x) x;
75 /******* graphics.library/ObtainPen **********************************************
77 * NAME
78 * ObtainPen -- Obtain a free palette entry for use by your program. (V39)
81 * SYNOPSIS
82 * n = ObtainPen( cm, n, r, g, b, flags)
83 * d0 a0 d0 d1 d2 d3 d4
85 * LONG ObtainPen(struct ColorMap *,ULONG,ULONG,ULONG,ULONG,ULONG);
87 * FUNCTION
88 * Attempt to allocate an entry in the colormap for use by the application.
89 * If successful, you should ReleasePen() this entry after you have finished
90 * with it.
92 * Applications needing exclusive use of a color register (say for color
93 * cycling) will typically call this function with n=-1. Applications needing
94 * only the shared use of a color will typically use ObtainBestPenA() instead.
95 * Other uses of this function are rare.
97 * INPUTS
98 * cm = A pointer to a color map created by GetColorMap().
99 * n = The index of the desired entry, or -1 if any one is acceptable
100 * rgb = The RGB values (32 bit left justified fractions) to set the new
101 * palette entry to.
102 * flags= PEN_EXCLUSIVE - tells the system that you want exclusive
103 * (non-shared) use of this pen value. Default is shared access.
105 * PEN_NO_SETCOLOR - tells the system to not change the rgb values
106 * for the selected pen. Really only makes sense for exclusive pens.
109 * RESULTS
111 * n = The allocated pen. -1 will be returned if there is no pen available
112 * for you.
114 * BUGS
116 * NOTES
117 * When you allocate a palette entry in non-exclusive mode, you
118 * should not change it (via SetRGB32), because other programs on the
119 * same screen may be using it. With PEN_EXCLUSIVE mode, you can
120 * change the returned entry at will.
122 * To avoid visual artifacts, you should not free up a palette
123 * entry until you are sure that your application is not displaying
124 * any pixels in that color at the time you free it. Otherwise, another
125 * task could allocate and set that color index, thus changing the colors
126 * of your pixels.
128 * Generally, for shared access, you should use ObtainBestPenA()
129 * instead, since it will not allocate a new color if there is one
130 * "close enough" to the one you want already.
131 * If there is no Palextra attached to the colormap, then this
132 * routine will always fail.
134 * SEE ALSO
135 * GetColorMap() ReleasePen() AttachPalExtra() ObtainBestPenA()
137 *********************************************************************************/
139 LONG MyObtainPen(struct ColorMap *cm,
140 ULONG n,
141 ULONG r,
142 ULONG g,
143 ULONG b,
144 ULONG flags,
145 struct IntuitionBase *IntuitionBase)
147 // struct Library *SysBase = (struct Library *)GfxBase->ExecBase;
148 struct PaletteExtra *pe=cm->PalExtra;
149 long retvalue=-1;
151 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen(cm 0x%lx n %ld r 0x%08lx g 0x%08lx b 0x%08lx flags %ld)\n",cm,n,r,g,b,flags);)
153 DEBUG_OBTAINPEN(dprintf("LIB_ObtainSemaphore: NestCount 0x%lx,QueueCount 0x%lx,Owner %s\n",
154 pe->pe_Semaphore.ss_NestCount,
155 pe->pe_Semaphore.ss_QueueCount,
156 ((ULONG) pe->pe_Semaphore.ss_Owner > 1) ? pe->pe_Semaphore.ss_Owner->tc_Node.ln_Name : "Shared\n"));
158 ObtainSemaphore(&pe->pe_Semaphore);
160 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: obtained the semaphore\n"));
162 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_NFree 0x%lx\n",
163 pe->pe_NFree));
165 if (pe->pe_NFree != 0)
167 UWORD *refcnt;
168 UBYTE *alloclist;
169 long alloc;
171 refcnt = (UWORD *)pe->pe_RefCnt;
172 alloclist = (char *)pe->pe_AllocList;
174 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_RefCnt 0x%lx\n",
175 pe->pe_RefCnt));
177 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_AllocList 0x%lx\n",
178 pe->pe_AllocList));
179 if (n != -1L)
181 // if not allocatable, fail
182 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_SharableColors 0x%lx\n",
183 pe->pe_SharableColors));
184 if (pe->pe_SharableColors >= n)
186 if (refcnt[n] == 0)
188 refcnt[n]++;
189 retvalue = n;
191 // decrement avail count
192 pe->pe_NFree--;
193 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_NFree 0x%lx\n",
194 pe->pe_NFree));
196 if (pe->pe_NFree != 0)
198 UWORD j;
201 j = pe->pe_FirstFree;
203 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_FirstFree 0x%lx\n",
204 pe->pe_FirstFree));
206 if (j == n)
208 // we don't need to walk through the list
209 // first = n -> next
210 pe->pe_FirstFree = alloclist[n];
212 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_FirstFree = alloclist[%ld] 0x%lx\n",
214 alloclist[n]));
217 else
219 while(alloclist[j] != n)
221 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: alloclist[%ld] %ld != %ld\n",
222 j,alloclist[j],n));
223 j = alloclist[j];
225 // j -> next = n -> next
226 alloclist[j] = alloclist[n];
230 // check exclusive
232 if ((flags & PENF_EXCLUSIVE) == 0)
234 // not exclusive, so add it to shared list
235 pe->pe_NShared++;
236 alloclist[n]=pe->pe_FirstShared;
237 pe->pe_FirstShared=n;
240 else
242 DEBUG_OBTAINPEN(dprintf("(index already allocated)");)
245 else
247 DEBUG_OBTAINPEN(dprintf("(not allocatable,sharable=%ld)",pe->pe_SharableColors);)
250 else
252 // decrement avail count
253 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: decrement avail cnt\n"));
254 pe->pe_NFree--;
255 alloc = pe->pe_FirstFree;
256 refcnt[alloc]++;
257 // FirstFree = alloc->next
258 pe->pe_FirstFree = alloclist[alloc];
259 retvalue = alloc;
261 // check exclusive
263 if ((flags & PENF_EXCLUSIVE) == 0)
265 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: add shared list\n"));
266 // not exclusive, so add it to shared list
267 pe->pe_NShared++;
268 alloclist[alloc]=pe->pe_FirstShared;
269 pe->pe_FirstShared=alloc;
273 if (retvalue != -1L)
275 long i = retvalue;
277 if ((flags & PENF_NO_SETCOLOR) == 0)
279 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: set color\n"));
280 SetRGB32(pe->pe_ViewPort,i,r,g,b);
285 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: release it\n"));
286 ReleaseSemaphore(&pe->pe_Semaphore);
288 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen(cm 0x%lx n %ld r 0x%08lx g 0x%08lx b 0x%08lx flags %ld) -> retvalue %lx\n",cm,n,r,g,b,flags,retvalue);)
290 return(retvalue);
293 #undef ObtainPen
295 #define ObtainPen(cm,n,r,g,b,flags) MyObtainPen(cm,n,r,g,b,flags,IntuitionBase)
296 #endif
298 /* Default colors for the new screen */
300 const ULONG coltab[] =
302 (16L << 16) + 0, /* 16 colors, loaded at index 0 */
304 /* X11 color names */
305 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
306 0x00000000, 0x00000000, 0x00000000, /* Black */
307 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
308 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
310 0x00000000, 0x00000000, 0xFFFFFFFF, /* Blue */
311 0x00000000, 0xFFFFFFFF, 0x00000000, /* Green */
312 0xFFFFFFFF, 0x00000000, 0x00000000, /* Red */
313 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, /* Cyan */
315 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, /* Magenta */
316 0xEEEEEEEE, 0x82828282, 0xEEEEEEEE, /* Violet */
317 0xA5A5A5A5, 0x2A2A2A2A, 0x2A2A2A2A, /* Brown */
318 0xFFFFFFFF, 0xE4E4E4E4, 0xC4C4C4C4, /* Bisque */
320 0xE6E6E6E6, 0xE6E6E6E6, 0xFAFAFAFA, /* Lavender */
321 0x00000000, 0x00000000, 0x80808080, /* Navy */
322 0xF0F0F0F0, 0xE6E6E6E6, 0x8C8C8C8C, /* Khaki */
323 0xA0A0A0A0, 0x52525252, 0x2D2D2D2D, /* Sienna */
324 0L /* Termination */
327 /*****************************************************************************
329 NAME */
331 AROS_LH1(struct Screen *, OpenScreen,
333 /* SYNOPSIS */
334 AROS_LHA(struct NewScreen *, newScreen, A0),
336 /* LOCATION */
337 struct IntuitionBase *, IntuitionBase, 33, Intuition)
339 /* FUNCTION
341 INPUTS
343 RESULT
345 NOTES
347 EXAMPLE
349 BUGS
351 SEE ALSO
353 INTERNALS
355 HISTORY
356 29-10-95 digulla automatically created from
357 intuition_lib.fd and clib/intuition_protos.h
359 *****************************************************************************/
361 AROS_LIBFUNC_INIT
362 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
364 struct NewScreen ns;
365 struct TagItem *tag, *tagList;
366 struct IntScreen *screen;
367 int success;
368 struct Hook *layer_info_hook = NULL;
369 struct ColorSpec *colors = NULL;
370 ULONG *errorPtr; /* Store error at user specified location */
371 UWORD *customdripens = NULL;
372 ULONG *colors32 = NULL;
373 WORD sysfont = -1;
374 BOOL ok = TRUE, rp_inited = FALSE, li_inited = FALSE, sharepens = FALSE;
375 #ifdef USEWINDOWLOCK
376 BOOL windowlock = FALSE;
377 #endif
378 struct Rectangle *dclip = NULL;
379 LONG overscan = OSCAN_TEXT;
380 DisplayInfoHandle displayinfo;
381 struct DimensionInfo dimensions;
382 struct MonitorInfo monitor;
383 #ifdef __MORPHOS__
384 ULONG allocbitmapflags = BMF_DISPLAYABLE;
385 #else
386 BOOL frontbm_set = FALSE;
387 struct BitMap *old_front_bm = NULL;
388 #endif
389 //ULONG lock;
390 WORD numcolors;
391 BOOL workbench = FALSE;
392 struct TagItem modetags[] =
394 { BIDTAG_Depth , 0UL },
395 { BIDTAG_DesiredWidth , 0UL },
396 { BIDTAG_DesiredHeight , 0UL },
397 { TAG_DONE }
399 ULONG modeid = INVALID_ID;
401 ASSERT_VALID_PTR_ROMOK(newScreen);
403 #define COPY(x) screen->Screen.x = ns.x
404 #define SetError(x) if (errorPtr != NULL) *errorPtr = x;
406 D(bug("OpenScreen (%p = { Left=%d Top=%d Width=%d Height=%d Depth=%d })\n"
407 , newScreen
408 , newScreen->LeftEdge
409 , newScreen->TopEdge
410 , newScreen->Width
411 , newScreen->Height
412 , newScreen->Depth
415 #ifndef __MORPHOS__
416 if (IntuitionBase->FirstScreen)
417 old_front_bm = IntuitionBase->FirstScreen->RastPort.BitMap;
418 #endif
420 FireScreenNotifyMessage((IPTR) newScreen, SNOTIFY_BEFORE_OPENSCREEN, IntuitionBase);
422 ns = *newScreen;
424 if (newScreen->Type & NS_EXTENDED)
426 tagList = ((struct ExtNewScreen *)newScreen)->Extension;
428 else
430 tagList = NULL;
433 DEBUG_OPENSCREEN(dprintf("OpenScreen: Left %d Top %d Width %d Height %d Depth %d Tags 0x%lx\n",
434 ns.LeftEdge, ns.TopEdge, ns.Width, ns.Height, ns.Depth, tagList));
436 #ifdef __MORPHOS__
437 if (!CyberGfxBase) CyberGfxBase = OpenLibrary("cybergraphics.library",0);
438 if (!CyberGfxBase) return NULL;
440 if (!LocaleBase) LocaleBase = OpenLibrary("locale.library",0);
441 if (!LocaleBase) return NULL;
442 #endif
444 #ifdef USEGETIPREFS //needs INTUITION_THEME_ENCHANCEMENT!
445 if (!GetPrivIBase(IntuitionBase)->IPrefsLoaded && FindPort(SKINMANAGERPORTNAME))
447 /* let's init prefs before 1st OpenScreen that needs them*/
448 int_SkinAction(SKA_GetIPrefs,0,0,IntuitionBase);
450 #endif
452 screen = AllocMem(sizeof (struct IntScreen), MEMF_ANY | MEMF_CLEAR);
454 DEBUG_OPENSCREEN(dprintf("OpenScreen: screen 0x%lx\n", screen));
456 /* Do this really early to be able to report errors */
457 errorPtr = (ULONG *)GetTagData((Tag)SA_ErrorCode, (ULONG)NULL, (struct TagItem *)tagList);
459 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ErrorCode 0x%lx\n",errorPtr));
461 if (screen == NULL)
463 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
464 SetError(OSERR_NOMEM);
465 return NULL;
468 if (tagList)
470 if (GetTagData(SA_LikeWorkbench, FALSE, tagList))
473 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_LikeWorkbench\n"));
475 ns.Width = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Width;
476 ns.Height = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Height;
477 ns.Depth = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Depth;
478 modeid = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID;
480 if (GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Control & SMF_AUTOSCROLL)
482 /* need to mark autoscroll */
483 ns.Type |= AUTOSCROLL;
485 sysfont = 1;
486 sharepens = TRUE; /* not sure */
489 while((tag = NextTagItem ((const struct TagItem **)&tagList)))
491 #if 1
492 DEBUG_OPENSCREEN(dprintf("OpenScreen: Tag 0x%08lx Data 0x%08lx\n",
493 tag->ti_Tag, tag->ti_Data));
494 #endif
495 switch(tag->ti_Tag)
497 case SA_Left:
498 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Left %ld\n",tag->ti_Data));
499 ns.LeftEdge = tag->ti_Data;
500 break;
502 case SA_Top:
503 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Top %ld\n",tag->ti_Data));
504 ns.TopEdge = tag->ti_Data;
505 break;
507 case SA_Width:
508 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Width %ld\n",tag->ti_Data));
509 ns.Width = tag->ti_Data;
510 break;
512 case SA_Height:
513 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Height %ld\n",tag->ti_Data));
514 ns.Height = tag->ti_Data;
515 break;
517 case SA_Depth:
518 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Depth %ld\n",tag->ti_Data));
519 ns.Depth = tag->ti_Data;
520 break;
522 case SA_DetailPen:
523 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DetailPen %ld\n",tag->ti_Data));
524 ns.DetailPen = tag->ti_Data;
525 break;
527 case SA_BlockPen:
528 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BlockPen %ld\n",tag->ti_Data));
529 ns.BlockPen = tag->ti_Data;
530 break;
532 case SA_Type:
533 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Type 0x%lx\n",tag->ti_Data));
534 ns.Type &= ~SCREENTYPE;
535 ns.Type |= tag->ti_Data;
536 break;
538 case SA_Title:
539 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Title <%s>\n",tag->ti_Data));
540 ns.DefaultTitle = (UBYTE *)tag->ti_Data;
541 break;
543 case SA_Font:
544 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Font 0x%lx\n",tag->ti_Data));
545 ns.Font = (struct TextAttr *)tag->ti_Data;
546 break;
548 case SA_Colors32:
549 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Colors32 0x%lx\n",tag->ti_Data));
550 colors32 = (ULONG *)tag->ti_Data;
551 break;
553 case SA_Colors:
554 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Colors 0x%lx\n",tag->ti_Data));
555 colors = (struct ColorSpec *)tag->ti_Data;
556 break;
558 case SA_SysFont:
559 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_SysFont 0x%lx\n",tag->ti_Data));
560 sysfont = (WORD)tag->ti_Data;
561 break;
563 case SA_BitMap:
564 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BitMap 0x%lx\n",tag->ti_Data));
565 if(tag->ti_Data)
567 ns.Type |= CUSTOMBITMAP;
568 ns.CustomBitMap = (struct BitMap *)tag->ti_Data;
570 else
572 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BitMap==NULL specified, custom bitmap use disabled\n"));
574 break;
576 /* Name of this public screen. */
577 case SA_PubName:
578 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubName <%s>\n",tag->ti_Data));
579 if (!tag->ti_Data)
581 screen->pubScrNode = AllocMem(sizeof(struct PubScreenNode), MEMF_CLEAR);
582 break;
584 else
586 struct Screen *old;
588 LockPubScreenList();
590 if (strcmp((char *)tag->ti_Data, "Workbench") == 0)
592 #warning This would still not be safe, if a normal app tried to open its own screen with SA_PubName=Workbench
593 if (GetPrivIBase(IntuitionBase)->WorkBench)
595 UnlockPubScreenList();
597 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
599 return NULL;
601 workbench = TRUE;
603 else
605 old = LockPubScreen((STRPTR)tag->ti_Data);
607 if (old != NULL)
609 UnlockPubScreen(NULL, old);
610 SetError(OSERR_PUBNOTUNIQUE);
611 UnlockPubScreenList();
612 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
614 return NULL;
618 UnlockPubScreenList();
621 screen->pubScrNode = AllocMem(sizeof(struct PubScreenNode), MEMF_CLEAR);
623 DEBUG_OPENSCREEN(dprintf("OpenScreen: pubScrNode 0x%lx\n",screen->pubScrNode));
625 if (screen->pubScrNode == NULL)
627 SetError(OSERR_NOMEM);
628 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
630 return NULL;
633 if ((ns.Type & SCREENTYPE) == CUSTOMSCREEN)
635 ns.Type &= ~SCREENTYPE;
636 ns.Type |= PUBLICSCREEN;
639 screen->pubScrNode->psn_Node.ln_Name = AllocVec(MAXPUBSCREENNAME + 1,
640 MEMF_ANY);
642 if (screen->pubScrNode->psn_Node.ln_Name == NULL)
644 SetError(OSERR_NOMEM);
645 FreeMem(screen->pubScrNode, sizeof(struct PubScreenNode));
646 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
648 return NULL;
651 /* Always open public screens in private mode. */
652 screen->pubScrNode->psn_Flags |= PSNF_PRIVATE;
653 strcpy(screen->pubScrNode->psn_Node.ln_Name, (STRPTR)tag->ti_Data);
654 break;
656 /* Signal bit number to use when signalling public screen
657 signal task. */
658 case SA_PubSig:
659 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubSig 0x%lx\n",tag->ti_Data));
660 if (screen->pubScrNode == NULL)
662 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
664 return NULL;
666 /* If no PubTask is set, we set the calling task as default */
667 if (screen->pubScrNode->psn_SigTask == NULL)
668 screen->pubScrNode->psn_SigTask = FindTask(NULL);
670 screen->pubScrNode->psn_SigBit = (UBYTE)tag->ti_Data;
671 break;
673 /* Task that should be signalled when the public screen loses
674 its last visitor window. */
675 case SA_PubTask:
676 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubTask 0x%lx\n",tag->ti_Data));
677 if (screen->pubScrNode == NULL)
679 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
680 return NULL;
682 screen->pubScrNode->psn_SigTask = (struct Task *)tag->ti_Data;
683 break;
685 case SA_BackFill:
686 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BackFill Hook 0x%lx\n",tag->ti_Data));
687 layer_info_hook = (struct Hook *)tag->ti_Data;
688 break;
690 case SA_Quiet:
691 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Quiet 0x%lx\n",tag->ti_Data));
692 if (tag->ti_Data)
694 ns.Type |= SCREENQUIET;
696 else
698 ns.Type &= ~SCREENQUIET;
700 break;
702 case SA_ShowTitle:
703 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ShowTitle 0x%lx\n",tag->ti_Data));
704 if (tag->ti_Data)
706 ns.Type |= SHOWTITLE;
708 else
710 ns.Type &= ~SHOWTITLE;
712 break;
714 case SA_Pens:
715 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Pens 0x%lx\n",tag->ti_Data));
716 customdripens = (UWORD *)tag->ti_Data;
717 break;
719 case SA_DisplayID:
720 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DisplayID 0x%lx\n",tag->ti_Data));
721 //if (modeid == INVALID_ID)
722 modeid = tag->ti_Data;
723 break;
725 case SA_SharePens:
726 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_SharePens 0x%lx\n",tag->ti_Data));
727 sharepens = tag->ti_Data ? TRUE : FALSE;
728 if (tag->ti_Data)
730 ns.Type |= PENSHARED;
732 else
734 ns.Type &= ~PENSHARED;
736 break;
738 case SA_Interleaved:
739 #ifdef __MORPHOS__
740 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Interleaved 0x%lx\n",tag->ti_Data));
741 if (tag->ti_Data)
743 allocbitmapflags |= BMF_INTERLEAVED;
745 else
747 allocbitmapflags &= ~BMF_INTERLEAVED;
749 #endif
750 break;
752 case SA_Behind:
753 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Behind 0x%lx\n",tag->ti_Data));
754 if (tag->ti_Data)
756 ns.Type |= SCREENBEHIND;
758 else
760 ns.Type &= ~SCREENBEHIND;
762 break;
764 case SA_DClip:
765 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DClip 0x%lx\n",tag->ti_Data));
766 dclip = (struct Rectangle *)tag->ti_Data;
767 break;
769 case SA_Overscan:
770 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_OverScan 0x%lx\n",tag->ti_Data));
771 overscan = tag->ti_Data;
772 break;
774 case SA_LikeWorkbench:
775 case SA_ErrorCode:
777 * handled elsewhere
779 break;
781 case SA_AutoScroll:
782 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_AutoScroll 0x%lx\n",tag->ti_Data));
783 ns.Type |= AUTOSCROLL;
784 break;
786 case SA_FullPalette:
787 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_FullPalette 0x%lx\n",tag->ti_Data));
788 break;
790 case SA_ColorMapEntries:
791 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ColorMapEntries 0x%lx\n",tag->ti_Data));
792 break;
794 case SA_Parent:
795 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Parent 0x%lx\n",tag->ti_Data));
796 break;
798 case SA_Draggable:
799 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Draggable 0x%lx\n",tag->ti_Data));
800 break;
802 case SA_Exclusive:
803 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Exclusive 0x%lx\n",tag->ti_Data));
804 break;
806 case SA_VideoControl:
807 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_VideoControl 0x%lx\n",tag->ti_Data));
808 break;
810 case SA_FrontChild:
811 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_FrontChild 0x%lx\n",tag->ti_Data));
812 break;
814 case SA_BackChild:
815 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BackChild 0x%lx\n",tag->ti_Data));
816 break;
818 case SA_MinimizeISG:
819 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_MinimizeISG 0x%lx\n",tag->ti_Data));
820 break;
822 #warning TODO: Missing SA_ Tags
823 default:
824 DEBUG_OPENSCREEN(dprintf("OpenScreen: unknown tag 0x%lx data 0x%lx\n",
825 tag->ti_Tag,
826 tag->ti_Data));
827 break;
829 } /* switch (tag->ti_Tag) */
831 } /* while ((tag = NextTagItem (&tagList))) */
833 } /* if (tagList) */
835 DEBUG_OPENSCREEN(dprintf("OpenScreen: Left %d Top %d Width %d Height %d Depth %d Tags 0x%lx\n",
836 ns.LeftEdge, ns.TopEdge, ns.Width, ns.Height, ns.Depth, tagList));
838 /* First Init the RastPort then get the BitPlanes!! */
840 modetags[0].ti_Data = ns.Depth;
841 if (ns.Width != STDSCREENWIDTH)
843 modetags[1].ti_Data = ns.Width;
845 else
847 modetags[1].ti_Tag = TAG_IGNORE;
850 if (ns.Height != STDSCREENHEIGHT)
852 modetags[2].ti_Data = ns.Height;
854 else
856 modetags[2].ti_Tag = TAG_IGNORE;
859 #ifdef __MORPHOS__
860 // if default HIRES_KEY or HIRESLACE_KEY is passed, make sure we find a replacement
861 // cybergraphx mode
863 if (INVALID_ID != modeid)
865 if (FindDisplayInfo(modeid) == NULL)
867 switch(modeid)
869 case HIRES_KEY:
870 case HIRESLACE_KEY:
872 struct TagItem bestmodetags[] =
874 { CYBRBIDTG_Depth , 0UL },
875 { CYBRBIDTG_NominalWidth , 0UL },
876 { CYBRBIDTG_NominalHeight , 0UL },
877 { TAG_DONE }
880 bestmodetags[0].ti_Data = 8;
881 bestmodetags[1].ti_Data = ns.Width;
882 bestmodetags[2].ti_Data = ns.Height;
884 DEBUG_OPENSCREEN(dprintf("resetting native mode id !!\n");)
885 DEBUG_OPENSCREEN(dprintf("ns.Width %ld ns.Height %ld ns.Depth %ld !!\n",
886 (LONG) ns.Width, (LONG) ns.Height, (LONG) ns.Depth);)
889 modeid = BestCModeIDTagList(bestmodetags);
891 DEBUG_OPENSCREEN(dprintf("BestCModeIDTagList returned %ld\n",modeid);)
893 break;
895 default:
896 break;
901 #endif
903 if (INVALID_ID == modeid)
905 modeid = BestModeIDA(modetags);
906 if (INVALID_ID == modeid)
908 DEBUG_OPENSCREEN(dprintf("!!! OpenScreen(): Could not find valid modeid !!!\n");)
909 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
911 return NULL;
915 DEBUG_OPENSCREEN(dprintf("OpenScreen: ModeID 0x%08lx\n", modeid));
917 #ifdef __MORPHOS__
919 InitRastPort(&screen->Screen.RastPort);
920 rp_inited = TRUE;
921 success = FALSE;
922 numcolors = 0;
924 if ((displayinfo = FindDisplayInfo(modeid)) != NULL &&
925 GetDisplayInfoData(displayinfo, &dimensions, sizeof(dimensions), DTAG_DIMS, modeid) &&
926 GetDisplayInfoData(displayinfo, &monitor, sizeof(monitor), DTAG_MNTR, modeid))
928 success = TRUE;
930 screen->Monitor = monitor.Mspc;
932 if (dclip == NULL)
934 switch (overscan)
936 case OSCAN_STANDARD:
937 dclip = &dimensions.StdOScan;
938 break;
940 case OSCAN_MAX:
941 dclip = &dimensions.MaxOScan;
942 break;
944 case OSCAN_VIDEO:
945 dclip = &dimensions.VideoOScan;
946 break;
948 default:
949 dclip = &dimensions.TxtOScan;
950 break;
954 if (ns.Width == STDSCREENWIDTH)
955 ns.Width = dclip->MaxX - dclip->MinX + 1;
957 if (ns.Height == STDSCREENHEIGHT)
958 ns.Height = dclip->MaxY - dclip->MinY + 1;
960 DEBUG_OPENSCREEN(dprintf("OpenScreen: Monitor 0x%lx Width %ld Height %ld\n",
961 screen->Monitor, ns.Width, ns.Height));
963 if (ns.Type & CUSTOMBITMAP)
965 struct BitMap *custombm;
967 custombm = ns.CustomBitMap;
969 if (IsCyberModeID(modeid) && custombm)
971 int pixfmt = GetCyberIDAttr(CYBRIDATTR_PIXFMT,modeid);
973 if(GetCyberMapAttr(custombm,CYBRMATTR_PIXFMT) != pixfmt)
975 // incompatible formats !
976 custombm = NULL;
980 if(custombm != NULL)
982 screen->Screen.RastPort.BitMap = custombm;
983 ns.Depth = GetBitMapAttr(ns.CustomBitMap,BMA_DEPTH);
984 DEBUG_OPENSCREEN(dprintf("OpenScreen: CustomBitmap Depth %ld\n",
985 ns.Depth));
987 else
989 ns.CustomBitMap = NULL;
990 ns.Type &= ~CUSTOMBITMAP;
993 else
995 screen->Screen.RastPort.BitMap = NULL;
999 if(screen->Screen.RastPort.BitMap == NULL)
1001 ULONG pixfmt;
1002 ULONG Depth;
1004 Depth = (dimensions.MaxDepth > 8) ? dimensions.MaxDepth : ns.Depth;
1006 switch(Depth)
1008 case 15:
1009 pixfmt = PIXFMT_RGB15;
1010 break;
1011 case 16:
1012 pixfmt = PIXFMT_RGB16;
1013 break;
1014 case 24:
1015 pixfmt = PIXFMT_BGR24;
1016 break;
1017 case 32:
1018 pixfmt = PIXFMT_ARGB32;
1019 break;
1020 default:
1021 pixfmt = PIXFMT_LUT8;
1022 break;
1025 if (IsCyberModeID(modeid))
1027 pixfmt = GetCyberIDAttr(CYBRIDATTR_PIXFMT,modeid);
1031 allocbitmapflags |= (BMF_SPECIALFMT|BMF_CLEAR);
1033 screen->Screen.RastPort.BitMap = AllocBitMap(ns.Width,
1034 ns.Height,
1035 Depth,
1036 allocbitmapflags | (pixfmt << 24),
1037 NULL);
1039 screen->AllocatedBitmap = screen->Screen.RastPort.BitMap;
1041 memcpy(&screen->Screen.BitMap,screen->Screen.RastPort.BitMap,sizeof(struct BitMap));
1044 DEBUG_OPENSCREEN(dprintf("OpenScreen: BitMap 0x%lx\n",
1045 screen->Screen.RastPort.BitMap));
1047 else
1049 DEBUG_OPENSCREEN(dprintf("OpenScreen: no displayinfo\n"));
1051 #else
1052 if ((displayinfo = FindDisplayInfo(modeid)) != NULL &&
1053 GetDisplayInfoData(displayinfo, (UBYTE *)&dimensions, sizeof(dimensions), DTAG_DIMS, modeid) &&
1054 GetDisplayInfoData(displayinfo, (UBYTE *)&monitor, sizeof(monitor), DTAG_MNTR, modeid))
1056 screen->Monitor = monitor.Mspc;
1058 if (dclip == NULL)
1060 switch (overscan)
1062 case OSCAN_STANDARD:
1063 dclip = &dimensions.StdOScan;
1064 break;
1066 case OSCAN_MAX:
1067 dclip = &dimensions.MaxOScan;
1068 break;
1070 case OSCAN_VIDEO:
1071 dclip = &dimensions.VideoOScan;
1072 break;
1074 default:
1075 dclip = &dimensions.TxtOScan;
1076 break;
1080 if (ns.Width == STDSCREENWIDTH)
1081 ns.Width = dclip->MaxX - dclip->MinX + 1;
1083 if (ns.Height == STDSCREENHEIGHT)
1084 ns.Height = dclip->MaxY - dclip->MinY + 1;
1088 if ((success = InitRastPort (&screen->Screen.RastPort)))
1090 rp_inited = TRUE;
1093 screen->Screen.RastPort.BitMap = screen->AllocatedBitmap = AllocScreenBitMap(modeid);
1095 #endif
1096 D(bug("got bitmap\n"));
1098 /* Init screen's viewport */
1099 InitVPort(&screen->Screen.ViewPort);
1101 /* Allocate a RasInfo struct in which we have a pointer
1102 to the struct BitMap, into which the driver can
1103 store its stuff. (Eg. pointer to a BitMap HIDD object)
1105 screen->Screen.ViewPort.RasInfo = AllocMem(sizeof(struct RasInfo), MEMF_ANY | MEMF_CLEAR);
1107 DEBUG_OPENSCREEN(dprintf("OpenScreen: RasInfo 0x%lx\n",
1108 screen->Screen.ViewPort.RasInfo));
1110 if (!success ||
1111 (screen->Screen.RastPort.BitMap == NULL) ||
1112 (screen->Screen.ViewPort.RasInfo == NULL))
1114 ok = FALSE;
1116 else
1118 /* Store pointer to bitmap, so we can get hold of it
1119 from withing LoadRGBxx() functions
1121 D(bug("got allocated stuff\n"));
1122 screen->Screen.ViewPort.RasInfo->BitMap = screen->Screen.RastPort.BitMap;
1126 if (ok)
1128 /* Read depth from the bitmap to avoid AttachPalExtra/ObtainPen getting
1129 * confused if cgx decided to allocate a higher depth bitmap than what
1130 * was asked.
1132 ns.Depth = GetBitMapAttr(screen->Screen.RastPort.BitMap,BMA_DEPTH);
1134 numcolors = (ns.Depth <= 8) ? (1L << ns.Depth) : 256;
1136 /* Get a color map structure. Sufficient colors?? */
1138 DEBUG_OPENSCREEN(dprintf("OpenScreen: Colormap Entries %ld\n",
1139 numcolors));
1141 if ((screen->Screen.ViewPort.ColorMap = GetColorMap(numcolors < 32 ? 32 : numcolors)) != NULL)
1144 #ifndef __MORPHOS__ /* Use VideoControl for MorphOS */
1145 screen->Screen.ViewPort.ColorMap->VPModeID = modeid;
1146 #endif
1148 if (0 == AttachPalExtra(screen->Screen.ViewPort.ColorMap,
1149 &screen->Screen.ViewPort))
1151 #if 0
1152 int i = 0;
1153 char *alloclist;
1154 UWORD *refcnt;
1156 refcnt =(UWORD*) screen->Screen.ViewPort.ColorMap->PalExtra->pe_RefCnt;
1157 alloclist = (UBYTE *)(refcnt + screen->Screen.ViewPort.ColorMap->Count);
1159 DEBUG_OPENSCREEN(dprintf("OpenScreen: PalExtra alloclist 0x%lx Count %ld\n",alloclist,screen->Screen.ViewPort.ColorMap->Count));
1161 while(i < screen->Screen.ViewPort.ColorMap->Count)
1163 // initialize alloc list to -1,0,1,2,3,4
1165 DEBUG_OPENSCREEN(dprintf("OpenScreen: alloclist[%ld]=%ld\n",
1166 i,alloclist[i]));
1167 i++;
1169 #endif
1171 else
1173 ok = FALSE;
1176 else
1178 ok = FALSE;
1181 DEBUG_OPENSCREEN(dprintf("OpenScreen: ColorMap 0x%lx\n",
1182 screen->Screen.ViewPort.ColorMap));
1185 #ifdef __MORPHOS__
1187 screen->ModeID = modeid;
1189 if (ok)
1191 struct ViewPortExtra *vpe = GfxNew(VIEWPORT_EXTRA_TYPE);
1193 DEBUG_OPENSCREEN(dprintf("OpenScreen: ViewPortExtra 0x%lx\n", vpe));
1195 ok = FALSE;
1197 if (vpe)
1199 struct TagItem tags[6];
1201 memcpy(&vpe->DisplayClip, dclip,sizeof(struct Rectangle));
1203 screen->Screen.ViewPort.DWidth = dclip->MaxX - dclip->MinX + 1;//ns.Width; /* or from dclip ? */
1204 screen->Screen.ViewPort.DHeight = dclip->MaxY - dclip->MinY + 1;//ns.Height;
1206 tags[0].ti_Tag = VTAG_ATTACH_CM_SET;
1207 tags[0].ti_Data = (IPTR)&screen->Screen.ViewPort;
1208 tags[1].ti_Tag = VTAG_VIEWPORTEXTRA_SET;
1209 tags[1].ti_Data = (IPTR)vpe;
1210 tags[2].ti_Tag = VTAG_NORMAL_DISP_SET;
1211 tags[2].ti_Data = (IPTR)displayinfo;
1212 tags[3].ti_Tag = VTAG_VPMODEID_SET;
1213 tags[3].ti_Data = modeid;
1214 tags[4].ti_Tag = VTAG_END_CM;
1215 tags[5].ti_Tag = TAG_END;
1217 if (VideoControl(screen->Screen.ViewPort.ColorMap, tags) == 0)
1219 DEBUG_OPENSCREEN(dprintf("OpenScreen: VideoControl ok\n"));
1220 ok = TRUE;
1222 else
1224 DEBUG_OPENSCREEN(dprintf("OpenScreen: VideoControl failed\n"));
1228 // added 2002-03-10, pre iprefs openscreen has all first 4 colours black (cyfm)
1229 // removed 2002-26-12, I now set the pens on start (zapek)
1230 #if 0
1231 if ((p = GetPrivIBase(IntuitionBase)->Colors))
1233 int Sum;
1235 DEBUG_OPENSCREEN(dprintf("OpenScreen: Intuition Color32 Table 0x%lx\n",p);)
1237 Sum = p[0].red + p[0].green + p[0].blue;
1238 Sum += p[1].red + p[1].green + p[1].blue;
1239 Sum += p[2].red + p[2].green + p[2].blue;
1240 Sum += p[3].red + p[3].green + p[3].blue;
1241 if (Sum==0)
1243 int i;
1245 DEBUG_OPENSCREEN(dprintf("OpenScreen: All 4 first colours black, reset !!\n");)
1247 for (i = 0; i < COLORTABLEENTRIES; i++)
1249 DEBUG_OPENSCREEN(dprintf("OpenScreen: Current Color32[%ld] R 0x%lx G 0x%lx B 0x%lx\n",
1251 p[i].red, p[i].green, p[i].blue));
1253 p[0].red = 0xAAAAAAAA;
1254 p[0].green = 0xAAAAAAAA;
1255 p[0].blue = 0xAAAAAAAA;
1257 p[1].red = 0x00000000;
1258 p[1].green = 0x00000000;
1259 p[1].blue = 0x00000000;
1261 p[2].red = 0xFFFFFFFF;
1262 p[2].green = 0xFFFFFFFF;
1263 p[2].blue = 0xFFFFFFFF;
1265 p[3].red = 0x55555555;
1266 p[3].green = 0x77777777;
1267 p[3].blue = 0xAAAAAAAA;
1271 #endif
1274 #endif
1276 if (ok)
1278 // struct Color32 *p;
1279 int k;
1280 UWORD *q;
1282 DEBUG_OPENSCREEN(dprintf("OpenScreen: Load Colors\n"));
1284 D(bug("Loading colors\n"));
1286 /* First load default colors for the screen */
1287 LoadRGB32(&screen->Screen.ViewPort, (ULONG *)coltab);
1289 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set first 4 colors\n"));
1291 #warning "FIXME: backport: #if'ed out"
1292 #if 0
1293 p = GetPrivIBase(IntuitionBase)->Colors;
1294 for (k = 0; k < 4 && k < numcolors; ++k)
1296 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB32 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1297 screen->Screen.ViewPort,
1298 k, p[k].red, p[k].green, p[k].blue));
1299 SetRGB32(&screen->Screen.ViewPort, k, p[k].red, p[k].green, p[k].blue);
1302 if (ns.Depth >= 3)
1304 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set last 4 colors\n"));
1306 #warning Isn`t that only set for FullPalette ?
1307 for (k = 0; k < 4; ++k)
1309 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB32 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1310 screen->Screen.ViewPort,
1311 numcolors - k - 1, p[k+4].red, p[k+4].green, p[k+4].blue));
1313 #if 1
1314 ObtainPen(screen->Screen.ViewPort.ColorMap,
1315 numcolors - 4 + k,
1316 p[k+4].red,
1317 p[k+4].green,
1318 p[k+4].blue,
1319 PEN_EXCLUSIVE);
1320 #else
1321 SetRGB32(&screen->Screen.ViewPort, numcolors - k - 1, p[k+4].red, p[k+4].green, p[k+4].blue);
1322 #endif
1325 #endif
1327 DEBUG_OPENSCREEN(dprintf("OpenScreen: Obtain Mousepointer colors\n"));
1329 /* Allocate pens for the mouse pointer */
1330 q = &GetPrivIBase(IntuitionBase)->ActivePreferences->color17;
1331 for (k = 0; k < 3; ++k, ++q)
1333 DEBUG_OPENSCREEN(dprintf("OpenScreen: ColorMap 0x%lx Pen %ld R 0x%lx G 0x%lx B 0x%lx\n",
1334 screen->Screen.ViewPort.ColorMap,
1335 k + 17,
1336 (*q >> 8) * 0x11111111,
1337 ((*q >> 4) & 0xf) * 0x11111111,
1338 (*q & 0xf) * 0x11111111));
1339 if (k + 17 < numcolors)
1341 ObtainPen(screen->Screen.ViewPort.ColorMap,
1342 k + 17,
1343 (*q >> 8) * 0x11111111,
1344 ((*q >> 4) & 0xf) * 0x11111111,
1345 (*q & 0xf) * 0x11111111,
1346 PEN_EXCLUSIVE);
1348 else
1350 /* Can't be allocated, but can still be set. */
1351 SetRGB32(&screen->Screen.ViewPort,
1352 k + 17,
1353 (*q >> 8) * 0x11111111,
1354 ((*q >> 4) & 0xf) * 0x11111111,
1355 (*q & 0xf) * 0x11111111);
1359 if (colors) /* if SA_Colors tag exists */
1361 DEBUG_OPENSCREEN(dprintf("OpenScreen: set SA_Colors 0x%lx\n",colors));
1362 for(; colors->ColorIndex != (WORD)~0; colors++)
1364 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB4 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1365 screen->Screen.ViewPort,
1366 colors,
1367 colors->Red,
1368 colors->Green,
1369 colors->Blue));
1370 SetRGB4(&screen->Screen.ViewPort,
1371 colors->ColorIndex,
1372 colors->Red,
1373 colors->Green,
1374 colors->Blue);
1378 if (colors32) /* if SA_Colors32 tag exists */
1380 DEBUG_OPENSCREEN(dprintf("OpenScreen: LoadRGB32 colors32 0x%lx\n",colors32));
1381 LoadRGB32(&screen->Screen.ViewPort, (const ULONG *)colors32);
1384 D(bug("Loaded colors\n"));
1386 COPY(LeftEdge);
1387 COPY(TopEdge);
1388 COPY(Width);
1389 COPY(Height);
1390 COPY(DetailPen);
1391 COPY(BlockPen);
1392 COPY(Font);
1393 COPY(DefaultTitle);
1395 //intui68k filters this
1396 screen->Screen.Flags = (ns.Type & ~NS_EXTENDED);
1398 /* Temporary hack */
1399 if (ns.Width >= 500 || ns.Height >= 300)
1400 screen->Screen.Flags |= SCREENHIRES;
1402 #ifndef __MORPHOS__
1403 /* Mark the bitmap of the screen as an AROS-displayed BitMap */
1404 screen->Screen.RastPort.BitMap->Flags |= BMF_AROS_HIDD;
1405 #endif
1408 Copy the data from the rastport's bitmap
1409 to the screen's bitmap structure
1411 screen->Screen.BitMap = *screen->Screen.RastPort.BitMap;
1413 #ifdef __MORPHOS__
1414 screen->Screen.WBorTop = 2;
1415 screen->Screen.WBorLeft = 4;
1416 screen->Screen.WBorRight = 4;
1417 screen->Screen.WBorBottom = 2;
1418 #else
1419 screen->Screen.WBorTop = 3; /* Amiga default is 2 */
1420 screen->Screen.WBorLeft = 4;
1421 screen->Screen.WBorRight = 4;
1422 screen->Screen.WBorBottom = 2; /* Amiga default is 2 */
1423 #endif
1425 screen->Screen.Title = ns.DefaultTitle;
1428 DEBUG_OPENSCREEN(dprintf("OpenScreen: init layers\n"));
1429 InitLayers(&screen->Screen.LayerInfo);
1430 li_inited = TRUE;
1432 #if 0
1433 /* Root layer now installed automatically by first call
1434 to CreateLayerTagList */
1436 #ifdef CreateLayerTagList
1438 struct TagItem tags[4] =
1440 {LA_Visible , FALSE },
1441 {LA_Priority, ROOTPRIORITY },
1442 {TAG_DONE }
1445 screen->rootLayer =
1446 CreateLayerTagList(&screen->Screen.LayerInfo,
1447 screen->Screen.RastPort.BitMap,
1448 screen->Screen.LeftEdge,
1449 screen->Screen.TopEdge,
1450 screen->Screen.LeftEdge + screen->Screen.Width - 1,
1451 screen->Screen.TopEdge + screen->Screen.Height - 1,
1453 tags);
1455 DEBUG_OPENSCREEN(dprintf("OpenScreen: rootLayer 0x%lx\n",screen->rootLayer));
1457 #endif
1458 #endif
1460 if (NULL != layer_info_hook)
1462 DEBUG_OPENSCREEN(dprintf("OpenScreen: instal layerinfohook\n"));
1463 InstallLayerInfoHook(&screen->Screen.LayerInfo, layer_info_hook);
1465 D(bug("layers intited screen\n"));
1467 screen->DInfo.dri.dri_Version = DRI_VERSION;
1468 screen->DInfo.dri.dri_NumPens = NUMDRIPENS;
1469 screen->DInfo.dri.dri_Pens = screen->Pens;
1470 /* dri_Depth is 8 on hi/true color screens like in AmigaOS with picasso96/cybergraphx */
1471 screen->DInfo.dri.dri_Depth = (ns.Depth <= 8) ? ns.Depth : 8;
1472 #warning These are probably monitor dependent
1473 screen->DInfo.dri.dri_Resolution.X = 44;
1474 screen->DInfo.dri.dri_Resolution.Y = 44;
1475 screen->DInfo.dri.dri_Flags = 0;
1476 screen->DInfo.dri_Screen = &screen->Screen;
1477 InitSemaphore(&screen->DInfo.dri_WinDecorSem);
1478 InitSemaphore(&screen->DInfo.dri_ScrDecorSem);
1480 /* SA_SysFont overrides SA_Font! */
1482 DEBUG_OPENSCREEN(dprintf("OpenScreen: SysFont = %d, ns.Font = %p\n", sysfont, ns.Font));
1484 if (sysfont == 0)
1486 /* Is handled below */
1487 DEBUG_OPENSCREEN(dprintf("OpenScreen: skip SysFont for now\n"));
1489 else if (sysfont == 1)
1491 #if 1
1492 /* Use safe OpenFont here - Piru
1494 screen->DInfo.dri.dri_Font = SafeReopenFont(IntuitionBase, &GetPrivIBase(IntuitionBase)->ScreenFont);
1495 #else
1497 #warning: Really hacky way of re-opening ScreenFont
1499 Forbid();
1500 screen->DInfo.dri.dri_Font = GetPrivIBase(IntuitionBase)->ScreenFont;
1501 screen->DInfo.dri.dri_Font->tf_Accessors++;
1502 Permit();
1503 #endif
1505 screen->SpecialFlags |= SF_SysFont;
1507 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set ScreenFont\n"));
1510 else if (ns.Font)
1512 screen->DInfo.dri.dri_Font = OpenFont(ns.Font);
1513 DEBUG_OPENSCREEN(dprintf("OpenScreen: custom font 0x%lx\n",screen->DInfo.dri.dri_Font));
1516 if (!screen->DInfo.dri.dri_Font)
1518 /* GfxBase->DefaultFont is *not* always topaz 8. It
1519 can be set with the Font prefs program!! */
1521 #if 1
1522 /* Use safe OpenFont.. - Piru
1524 screen->DInfo.dri.dri_Font = SafeReopenFont(IntuitionBase, &GfxBase->DefaultFont);
1525 #else
1527 #warning: Really hacky way of re-opening system default font
1529 Forbid();
1530 screen->DInfo.dri.dri_Font = GfxBase->DefaultFont;
1531 screen->DInfo.dri.dri_Font->tf_Accessors++;
1532 Permit();
1533 #endif
1536 if (!screen->DInfo.dri.dri_Font) ok = FALSE;
1538 } /* if (ok) */
1540 if (ok)
1542 /* set default values for pens */
1543 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set Default Pens\n"));
1545 CopyMem(ns.Depth == 1 ? GetPrivIBase(IntuitionBase)->DriPens2
1546 : ns.Depth == 4 ? GetPrivIBase(IntuitionBase)->DriPens4
1547 : GetPrivIBase(IntuitionBase)->DriPens8,
1548 screen->Pens,
1549 sizeof(screen->Pens));
1551 if (ns.Depth > 1)
1553 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set NewLook\n"));
1554 screen->DInfo.dri.dri_Flags |= DRIF_NEWLOOK;
1558 if (customdripens)
1560 WORD i;
1562 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set Custom Pens\n"));
1564 screen->Pens[DETAILPEN] = screen->Screen.DetailPen;
1565 screen->Pens[BLOCKPEN] = screen->Screen.BlockPen;
1567 for(i = 0; (i < NUMDRIPENS) && (customdripens[i] != (UWORD)~0); i++)
1569 DEBUG_OPENSCREEN(dprintf("OpenScreen: Pen[%ld] %ld\n",i,screen->Pens[i]));
1570 screen->Pens[i] = customdripens[i];
1573 else
1576 * Let`s do some broken software validation of the pens
1577 * so we may not run into a black desktop.
1580 DEBUG_OPENSCREEN(dprintf("OpenScreen: Check Default Pens if the make sense\n"));
1581 if (screen->Screen.DetailPen == screen->Screen.BlockPen)
1583 DEBUG_OPENSCREEN(dprintf("OpenScreen: DetailPen==BlockPen..correct\n"));
1584 screen->Screen.DetailPen = 0;
1585 screen->Screen.BlockPen = 1;
1587 else
1588 if (screen->Screen.BlockPen == 0)
1590 DEBUG_OPENSCREEN(dprintf("OpenScreen: BlockPen==0..correct\n"));
1591 screen->Screen.BlockPen = screen->Screen.DetailPen;
1592 screen->Screen.DetailPen = 0;
1595 screen->Pens[DETAILPEN] = screen->Screen.DetailPen;
1596 screen->Pens[BLOCKPEN] = screen->Screen.BlockPen;
1599 /* Allocate shared/exclusive colors */
1602 BYTE color_alloced[256];
1604 WORD i;
1606 for(i = 0; i < 256; i++)
1608 color_alloced[i] = FALSE;
1611 /* Mouse pointer colors */
1613 color_alloced[17] = TRUE;
1614 color_alloced[18] = TRUE;
1615 color_alloced[19] = TRUE;
1617 /* The Pens in the DrawInfo must be allocated as shared */
1619 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen DrawInfo Pens as shared\n"));
1621 for(i = 0; i < NUMDRIPENS; i++)
1623 int pen = screen->Pens[i];
1625 if (!color_alloced[pen])
1627 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen ColorMap 0x%lx Pen %ld\n",
1628 screen->Screen.ViewPort.ColorMap,
1629 pen));
1631 ObtainPen(screen->Screen.ViewPort.ColorMap,
1632 pen,
1636 PENF_NO_SETCOLOR);
1637 color_alloced[pen] = TRUE;
1640 DEBUG_OPENSCREEN(dprintf("OpenScreen: done\n"));
1642 /* If SA_SharePens is FALSE then allocate the rest of the colors
1643 in the colormap as exclusive */
1645 if (!sharepens)
1647 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen the remaining Pens as exclusive\n"));
1649 for(i = 0; i < numcolors; i++)
1651 if (!color_alloced[i])
1653 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen ColorMap 0x%lx Pen %ld\n",
1654 screen->Screen.ViewPort.ColorMap,
1655 i));
1656 ObtainPen(screen->Screen.ViewPort.ColorMap,
1661 PENF_EXCLUSIVE | PENF_NO_SETCOLOR);
1665 } /* if (!sharepens) */
1670 #ifndef __MORPHOS__
1671 if (ok)
1673 if (!SetFrontBitMap(screen->Screen.RastPort.BitMap, TRUE))
1674 ok = FALSE;
1675 else
1676 frontbm_set = TRUE;
1678 #endif
1680 #ifdef SKINS
1681 if (ok)
1683 ULONG realdepth;
1685 screen->DInfo.dri_Screen = &screen->Screen; //useful sometimes ;)
1687 realdepth = GetBitMapAttr( screen->Screen.RastPort.BitMap, BMA_DEPTH );
1688 if (realdepth > 8)
1690 screen->DInfo.dri_Flags |= DRIF_DIRECTCOLOR;
1692 else
1694 screen->DInfo.dri_Flags &= ~DRIF_DIRECTCOLOR;
1697 if (!(screen->DInfo.dri_Colors = AllocMem(4 * DRIPEN_NUMDRIPENS,MEMF_PUBLIC)))
1698 ok = FALSE;
1700 if (ok)
1702 CopyMem(&defaultdricolors,screen->DInfo.dri_Colors,sizeof (defaultdricolors));
1703 memset(((UBYTE *) screen->DInfo.dri_Colors) + sizeof(defaultdricolors), 0, 4 * DRIPEN_NUMDRIPENS - sizeof(defaultdricolors));
1706 if (ok)
1708 if ((screen->DInfo.dri_Customize = AllocMem(sizeof (struct IntuitionCustomize),MEMF_PUBLIC|MEMF_CLEAR)))
1710 struct IntuitionCustomize *ic;
1711 ic = screen->DInfo.dri_Customize;
1712 screen->DInfo.dri_Flags |= DRIF_SKINSSUPPORT;
1713 /* This initializes CustomizePrefs structure */
1715 int_SkinAction(SKA_LoadSkin,(ULONG*)&screen->DInfo,(struct Screen *)screen,IntuitionBase);
1717 else
1719 ok = FALSE;
1724 if (ok)
1726 struct windowclassprefs *wcprefs;
1728 wcprefs = (struct windowclassprefs *)int_GetCustomPrefs(TYPE_WINDOWCLASS,&screen->DInfo,IntuitionBase);
1729 if (wcprefs->flags & WINDOWCLASS_PREFS_1TO1FRAMES)
1731 screen->Screen.WBorLeft = screen->Screen.WBorTop;
1732 screen->Screen.WBorRight = screen->Screen.WBorTop;
1733 screen->Screen.WBorBottom = screen->Screen.WBorTop;
1735 #ifdef TITLEHACK
1736 screen->Screen.WBorTop += wcprefs->titlebarincrement;
1737 #endif
1738 int_FreeCustomPrefs(TYPE_WINDOWCLASS,&screen->DInfo,IntuitionBase);
1741 #endif
1743 if (ok)
1745 struct TagItem windecor_tags[] =
1747 {WDA_DrawInfo , (IPTR)&screen->DInfo },
1748 {WDA_Screen , (IPTR)screen },
1749 {TAG_DONE }
1752 screen->DInfo.dri_WinDecorObj = NewObjectA(NULL, WINDECORCLASS, windecor_tags);
1753 if (!screen->DInfo.dri_WinDecorObj)
1755 ok = FALSE;
1759 if (ok)
1761 struct TagItem scrdecor_tags[] =
1763 {SDA_DrawInfo , (IPTR)&screen->DInfo },
1764 {SDA_Screen , (IPTR)screen },
1765 {TAG_DONE }
1768 screen->DInfo.dri_ScrDecorObj = NewObjectA(NULL, SCRDECORCLASS, scrdecor_tags);
1769 if (!screen->DInfo.dri_ScrDecorObj)
1771 ok = FALSE;
1775 if (ok)
1777 struct TagItem sysi_tags[] =
1779 {SYSIA_Which , MENUCHECK },
1780 {SYSIA_DrawInfo , (IPTR)&screen->DInfo },
1781 {TAG_DONE }
1784 screen->DInfo.dri.dri_CheckMark = NewObjectA(NULL, "sysiclass", sysi_tags);
1785 DEBUG_OPENSCREEN(dprintf("OpenScreen: CheckMark 0x%lx\n",
1786 screen->DInfo.dri_CheckMark));
1788 sysi_tags[0].ti_Data = AMIGAKEY;
1790 screen->DInfo.dri.dri_AmigaKey = NewObjectA(NULL, "sysiclass", sysi_tags);
1791 DEBUG_OPENSCREEN(dprintf("OpenScreen: AmigaKey 0x%lx\n",
1792 screen->DInfo.dri.dri_AmigaKey));
1793 #ifdef SKINS
1794 sysi_tags[0].ti_Data = SUBMENUIMAGE;
1795 screen->DInfo.dri_Customize->submenu = NewObjectA(NULL, "sysiclass", sysi_tags);
1796 sysi_tags[0].ti_Data = MENUTOGGLEIMAGE;
1797 screen->DInfo.dri_Customize->menutoggle = NewObjectA(NULL, "sysiclass", sysi_tags);
1798 if (!screen->DInfo.dri_Customize->submenu ||
1799 !screen->DInfo.dri_Customize->menutoggle) ok = FALSE;
1800 #endif
1802 if (!screen->DInfo.dri.dri_CheckMark || !screen->DInfo.dri.dri_AmigaKey) ok = FALSE;
1805 if (ok)
1807 SetFont(&screen->Screen.RastPort, screen->DInfo.dri.dri_Font);
1809 AskFont(&screen->Screen.RastPort, (struct TextAttr *) &screen->textattr);
1811 screen->Screen.Font = (struct TextAttr *) &screen->textattr;
1813 DEBUG_OPENSCREEN(dprintf("OpenScreen: Font %s/%d\n",
1814 screen->textattr.tta_Name, screen->textattr.tta_YSize));
1816 #ifdef __MORPHOS__
1817 screen->Screen.BarVBorder = 1;
1818 screen->Screen.BarHBorder = 5;
1819 screen->Screen.MenuVBorder = 2;
1820 screen->Screen.MenuHBorder = 4;
1821 #else
1822 screen->Screen.BarVBorder = 1; /* on the Amiga it is (usually?) 1 */
1823 screen->Screen.BarHBorder = 5;
1824 screen->Screen.MenuVBorder = 2; /* on the Amiga it is (usually?) 2 */
1825 screen->Screen.MenuHBorder = 4;
1826 #endif
1827 #ifdef TITLEHACK
1828 screen->Screen.BarHeight = screen->DInfo.dri.dri_Font->tf_YSize + screen->Screen.WBorTop-2 +
1829 screen->Screen.BarVBorder * 2; /* real layer will be 1 pixel higher! */
1830 #else
1831 screen->Screen.BarHeight = screen->DInfo.dri.dri_Font->tf_YSize +
1832 screen->Screen.BarVBorder * 2; /* real layer will be 1 pixel higher! */
1833 #endif
1836 #define SDEPTH_HEIGHT (screen->Screen.BarHeight + 1)
1837 #ifdef IA_Screen
1838 #undef IA_Screen
1839 #endif
1840 #define IA_Screen (IA_Dummy + 0x1f) /* OS v44 includes!*/
1842 struct TagItem sdepth_tags[] =
1844 {GA_Image , 0 },
1845 {GA_Top , 0 },
1846 #if SQUARE_WIN_GADGETS
1847 {GA_Width , SDEPTH_HEIGHT },
1848 #endif
1849 {GA_Height , SDEPTH_HEIGHT },
1850 {GA_SysGadget , TRUE },
1851 {GA_SysGType , GTYP_SDEPTH },
1852 {GA_RelVerify , TRUE },
1853 {TAG_DONE }
1856 Object *im = 0;
1858 if (!(screen->Screen.Flags & SCREENQUIET))
1860 im = CreateStdSysImage(SDEPTHIMAGE, SDEPTH_HEIGHT, &screen->Screen,
1861 (struct DrawInfo *)&screen->DInfo, IntuitionBase);
1864 sdepth_tags[0].ti_Data = (IPTR)im;
1866 screen->depthgadget = NewObjectA(NULL, BUTTONGCLASS, sdepth_tags );
1868 DEBUG_OPENSCREEN(dprintf("OpenScreen: DepthGadget 0x%lx\n",
1869 screen->depthgadget));
1871 screen->Screen.FirstGadget = (struct Gadget *)screen->depthgadget;
1872 if (screen->Screen.FirstGadget)
1874 struct IntDrawInfo *dri = &screen->DInfo;
1875 struct sdpLayoutScreenGadgets msg;
1877 screen->Screen.FirstGadget->GadgetType |= GTYP_SCRGADGET;
1879 msg.MethodID = SDM_LAYOUT_SCREENGADGETS;
1880 msg.sdp_Layer = screen->Screen.BarLayer;
1881 msg.sdp_Gadgets = screen->Screen.FirstGadget;
1882 msg.sdp_Flags = SDF_LSG_INITIAL | SDF_LSG_MULTIPLE;
1884 LOCKSHARED_SCRDECOR(dri);
1885 DoMethodA(dri->dri_ScrDecorObj, (Msg)&msg);
1886 UNLOCK_SCRDECOR(dri);
1888 #if 0
1889 struct TagItem gadtags[] =
1891 {GA_RelRight, 0 },
1892 {TAG_DONE }
1894 IPTR width;
1896 GetAttr(GA_Width, screen->depthgadget, &width);
1898 gadtags[0].ti_Data = -width + 1;
1899 SetAttrsA(screen->depthgadget, gadtags);
1900 #endif
1903 else
1905 if (im) DisposeObject(im);
1911 #if 1
1913 int i;
1915 for (i = 0;i <= screen->DInfo.dri.dri_NumPens; i++)
1917 DEBUG_OPENSCREEN(dprintf("OpenScreen: dri_Pen[%ld] = %ld\n",i,screen->DInfo.dri.dri_Pens[i]));
1920 #endif
1922 #ifdef USEWINDOWLOCK
1923 /* let's wait for user to finish window drag/size actions to avoid
1924 deadlocks and not break user's input */
1925 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->WindowLock);
1926 windowlock = TRUE;
1927 #endif
1929 #ifdef SKINS
1930 int_CalcSkinInfo(&screen->Screen,IntuitionBase);
1931 int_InitTitlebarBuffer(screen,IntuitionBase);
1932 #endif
1933 D(bug("callling SetRast()\n"));
1935 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set background color Pen %ld\n",screen->Pens[BACKGROUNDPEN]));
1936 /* Set screen to background color */
1937 SetRast(&screen->Screen.RastPort, screen->Pens[BACKGROUNDPEN]);
1939 D(bug("SetRast() called\n"));
1941 DEBUG_OPENSCREEN(dprintf("OpenScreen: Creating screen bar\n"));
1943 #ifdef SKINS
1944 if (workbench)
1946 if (GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_NOWBTITLEBAR) screen->SpecialFlags |= SF_InvisibleBar;
1947 if (GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_DISAPPEARINGTITLEBAR) screen->SpecialFlags |= SF_AppearingBar;
1949 #endif
1951 //jDc: ALL screens MUST have BarLayer!
1952 CreateScreenBar(&screen->Screen, IntuitionBase);
1954 if (!screen->Screen.BarLayer) ok = FALSE;
1957 ** jDc: better modify the screen list in sync with inputhandler, this for example allows us to scan the list
1958 ** without any locks when we are on input.device context
1960 if (ok)
1962 struct OpenScreenActionMsg msg;
1963 struct List *list = LockPubScreenList();
1965 msg.Screen = screen;
1966 msg.NewScreen = &ns;
1967 msg.List = list;
1969 DoSyncAction((APTR)int_openscreen,&msg.msg,IntuitionBase);
1971 UnlockPubScreenList();
1974 } /* if (ok) */
1976 if (ok)
1978 GetAttr(POINTERA_SharedPointer, GetPrivIBase(IntuitionBase)->DefaultPointer, (IPTR *)&screen->Pointer);
1979 ObtainSharedPointer(screen->Pointer, IntuitionBase);
1980 DEBUG_OPENSCREEN(dprintf("OpenScreen: Sprite DefaultPtr 0x%lx\n",&screen->Pointer));
1983 #ifdef __MORPHOS__
1984 if (ok)
1986 ok = MakeScreen(&screen->Screen) == 0;
1987 DEBUG_OPENSCREEN(dprintf("OpenScreen: MakeScreen %s\n", ok ? "ok" : "failed"));
1990 if (ok)
1992 ok = RethinkDisplay() == 0;
1993 DEBUG_OPENSCREEN(dprintf("OpenScreen: RethinkDisplay %s\n", ok ? "ok" : "failed"));
1995 #endif
1997 #ifdef SKINS
1998 if (ok)
2000 FireMenuMessage(MMCODE_STARTCLOCK,NULL,NULL,IntuitionBase);
2002 #endif
2004 #ifdef USEWINDOWLOCK
2005 if (windowlock) ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->WindowLock);
2006 #endif
2008 if (!ok)
2010 #ifndef __MORPHOS__
2011 if (frontbm_set)
2013 if (NULL != old_front_bm)
2014 SetFrontBitMap(old_front_bm, FALSE);
2016 #endif
2018 if (li_inited)
2020 DEBUG_OPENSCREEN(dprintf("OpenScreen: Get ThinLayerInfo\n"));
2021 ThinLayerInfo(&screen->Screen.LayerInfo);
2024 if (screen->Screen.ViewPort.ColorMap)
2026 #ifdef __MORPHOS__
2027 struct TagItem tags[2];
2029 tags[0].ti_Tag = VTAG_ATTACH_CM_GET;
2030 tags[0].ti_Data = 0;
2031 tags[1].ti_Tag = VTAG_END_CM;
2033 if (VideoControl(screen->Screen.ViewPort.ColorMap, tags) == 0 &&
2034 tags[0].ti_Data)
2036 GfxFree((APTR)tags[0].ti_Data);
2038 #endif
2040 FreeColorMap(screen->Screen.ViewPort.ColorMap);
2043 if (screen->Screen.BarLayer)
2045 DEBUG_OPENSCREEN(dprintf("OpenScreen: KillScreenBar\n"));
2046 KillScreenBar(&screen->Screen, IntuitionBase);
2049 if (screen->DInfo.dri_ScrDecorObj)
2051 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose ScrDecor Object\n"));
2052 DisposeObject(screen->DInfo.dri_ScrDecorObj);
2055 if (screen->DInfo.dri_WinDecorObj)
2057 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose WinDecor Object\n"));
2058 DisposeObject(screen->DInfo.dri_WinDecorObj);
2060 #ifdef SKINS
2061 DisposeObject(screen->DInfo.dri_Customize->submenu);
2062 DisposeObject(screen->DInfo.dri_Customize->menutoggle);
2063 if (screen->DInfo.dri_Customize) FreeMem(screen->DInfo.dri_Customize,sizeof (struct IntuitionCustomize));
2064 if (screen->DInfo.dri_Colors) FreeMem(screen->DInfo.dri_Colors,4 * DRIPEN_NUMDRIPENS);
2065 #endif
2066 if (screen->DInfo.dri.dri_AmigaKey)
2068 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose AmigaKey Object\n"));
2069 DisposeObject(screen->DInfo.dri.dri_AmigaKey);
2071 if (screen->DInfo.dri.dri_CheckMark)
2073 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose CheckMark Object\n"));
2074 DisposeObject(screen->DInfo.dri.dri_CheckMark);
2077 if (screen->DInfo.dri.dri_Font)
2079 DEBUG_OPENSCREEN(dprintf("OpenScreen: Close Font\n"));
2080 CloseFont(screen->DInfo.dri.dri_Font);
2083 if (screen->AllocatedBitmap && !(ns.Type & CUSTOMBITMAP))
2085 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free BitMap\n"));
2086 FreeBitMap(screen->AllocatedBitmap);
2089 if (screen->Screen.ViewPort.RasInfo)
2091 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free RasInfo\n"));
2092 FreeMem(screen->Screen.ViewPort.RasInfo, sizeof (struct RasInfo));
2095 if (rp_inited)
2097 DEBUG_OPENSCREEN(dprintf("OpenScreen: Trash Rastport\n"));
2098 DeinitRastPort(&screen->Screen.RastPort);
2101 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free Screen\n"));
2102 FreeMem (screen, sizeof (struct IntScreen));
2104 screen = 0;
2106 } /* if (!ok) */
2108 DEBUG_OPENSCREEN(dprintf("OpenScreen: return 0x%lx\n", screen));
2110 FireScreenNotifyMessage((IPTR) screen, SNOTIFY_AFTER_OPENSCREEN, IntuitionBase);
2112 ReturnPtr ("OpenScreen", struct Screen *, (struct Screen *)screen);
2114 AROS_LIBFUNC_EXIT
2116 } /* OpenScreen */
2118 static VOID int_openscreen(struct OpenScreenActionMsg *msg,
2119 struct IntuitionBase *IntuitionBase)
2121 ULONG lock;
2122 struct IntScreen *screen = msg->Screen;
2123 struct NewScreen *ns = msg->NewScreen;
2124 struct List *list = msg->List;
2126 DEBUG_OPENSCREEN(dprintf("OpenScreen: Checking for pubScrNode (0x%lx)\n",screen->pubScrNode));
2128 /* If this is a public screen, we link it into the intuition global
2129 public screen list */
2130 if (screen->pubScrNode != NULL)
2132 /* Set the pointer to ourselves */
2133 GetPrivScreen(screen)->pubScrNode->psn_Screen = &screen->Screen;
2135 DEBUG_OPENSCREEN(dprintf("OpenScreen: Add Screen to PubList\n"));
2136 AddTail(list, (struct Node *)GetPrivScreen(screen)->pubScrNode);
2139 lock = LockIBase((ULONG)NULL);
2140 if (ns->Type & SCREENBEHIND)
2142 struct Screen **ptr = &IntuitionBase->FirstScreen;
2144 DEBUG_OPENSCREEN(dprintf("OpenScreen: Sort Behind\n"));
2145 if (!*ptr)
2146 IntuitionBase->ActiveScreen = &screen->Screen;
2147 while (*ptr)
2148 ptr = &(*ptr)->NextScreen;
2149 *ptr = &screen->Screen;
2151 else
2153 screen->Screen.NextScreen = IntuitionBase->FirstScreen;
2154 IntuitionBase->FirstScreen =
2155 IntuitionBase->ActiveScreen = &screen->Screen;
2156 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set as ActiveScreen\n"));
2159 /* set the default pub screen */
2160 if (GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags & ICF_DEFPUBSCREEN)
2162 if ((IntuitionBase->FirstScreen == &screen->Screen) && screen->pubScrNode && (screen->Screen.Flags & (PUBLICSCREEN | WBENCHSCREEN)))
2164 GetPrivIBase(IntuitionBase)->DefaultPubScreen = &screen->Screen;
2168 UnlockIBase(lock);
2170 D(bug("set active screen\n"));
2172 AddResourceToList(screen, RESOURCE_SCREEN, IntuitionBase);