New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / openworkbench.c
blob64de7ffc355eef7dd1e9f9d9db32a2cf572c224d
1 /*
2 Copyright 1995-2004, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include "intuition_intern.h"
9 #include <intuition/intuition.h>
10 #include <proto/intuition.h>
11 #include <proto/graphics.h>
13 /*****************************************************************************
15 NAME */
17 AROS_LH0(IPTR, OpenWorkBench,
19 /* SYNOPSIS */
21 /* LOCATION */
22 struct IntuitionBase *, IntuitionBase, 35, Intuition)
24 /* FUNCTION
25 Attempt to open the Workbench screen.
27 INPUTS
28 None.
30 RESULT
31 Tries to (re)open WorkBench screen. If successful return value
32 is a pointer to the screen structure, which shouldn't be used,
33 because other programs may close the WorkBench and make the
34 pointer invalid.
35 If this function fails the return value is NULL.
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
44 CloseWorkBench()
46 INTERNALS
48 *****************************************************************************/
50 AROS_LIBFUNC_INIT
51 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
53 struct Screen *wbscreen;
55 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: <%s>\n",
56 FindTask(NULL)->tc_Node.ln_Name));
58 LockPubScreenList();
60 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
62 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Workbench 0x%lx\n",
63 (ULONG) wbscreen));
65 if (wbscreen)
67 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: returning Workbench screen at 0x%lx\n",
68 (ULONG) wbscreen));
70 UnlockPubScreenList();
72 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
74 return (IPTR)wbscreen;
76 else
78 /* Open the Workbench screen if we don't have one. */
80 WORD width = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Width;
81 WORD height = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Height;
82 WORD depth = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Depth;
83 ULONG modeid = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID;
85 struct TagItem screenTags[] =
87 { SA_Width, 0 }, /* 0 */
88 { SA_Height, 0 }, /* 1 */
89 { SA_Depth, depth }, /* 2 */
90 { SA_DisplayID, 0 }, /* 3 */
91 { SA_LikeWorkbench, TRUE }, /* 4 */
92 { SA_Type, WBENCHSCREEN }, /* 5 */
93 { SA_Title, (IPTR) "Workbench Screen" }, /* 6 */
94 { SA_PubName, (IPTR) "Workbench" }, /* 7 */
95 { SA_SharePens, TRUE }, /* 8 */
96 { TAG_END, 0 }
99 APTR disphandle = FindDisplayInfo(modeid);
101 if (!disphandle)
103 struct TagItem modetags[] =
105 { BIDTAG_DesiredWidth, width },
106 { BIDTAG_DesiredHeight, height },
107 { BIDTAG_Depth, depth },
108 { TAG_DONE, 0 }
111 modeid = BestModeIDA(modetags);
112 disphandle = FindDisplayInfo(modeid);
115 if (disphandle)
117 struct DimensionInfo dim;
119 #define BOUND(min, val, max) \
120 (((min) > (val)) ? (min) : ((max) < (val)) ? (max) : (val))
122 if (GetDisplayInfoData(disphandle, (UBYTE *)&dim, sizeof(dim), DTAG_DIMS, 0))
124 width = BOUND(dim.MinRasterWidth, width, dim.MaxRasterWidth);
125 height = BOUND(dim.MinRasterHeight, height, dim.MaxRasterHeight);
127 screenTags[3].ti_Data = modeid;
129 else
130 screenTags[3].ti_Tag = TAG_IGNORE;
132 screenTags[0].ti_Data = width;
133 screenTags[1].ti_Data = height;
135 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: Trying to open Workbench screen\n"));
137 FireScreenNotifyMessage((IPTR) NULL, SNOTIFY_BEFORE_OPENWB, IntuitionBase);
139 wbscreen = OpenScreenTagList(NULL, screenTags);
141 if( !wbscreen )
143 DEBUG_OPENWORKBENCH(dprintf("OpenWorkBench: failed to open Workbench screen !!!!\n"));
145 UnlockPubScreenList();
146 return 0;
149 GetPrivIBase(IntuitionBase)->WorkBench = wbscreen;
151 /* Make the screen public. */
152 PubScreenStatus( wbscreen, 0 );
156 /* We have opened the Workbench Screen. Now tell the Workbench process
157 to open it's windows, if there is one. We still do have the pub screen
158 list locked. But while sending the Message to the Workbench task we
159 must unlock the semaphore, otherwise there can be deadlocks if the
160 Workbench task itself does something which locks the pub screen list.
162 But if we unlock the pub screen list, then some other task could try
163 to close the Workbench screen in the meantime. The trick to solve
164 this problem is to increase the psn_VisitorCount of the Workbench
165 screen here, before unlocking the pub screen list. This way the
166 Workbench screen cannot go away. */
168 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount++;
169 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
170 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount));
172 UnlockPubScreenList();
174 DEBUG_VISITOR(dprintf("OpenWorkbench: notify Workbench\n"));
176 /* Don't call this function while pub screen list is locked! */
177 TellWBTaskToOpenWindows(IntuitionBase);
179 /* Now fix the psn_VisitorCount we have increased by one, above. It's probably
180 better to do this by hand, instead of calling UnlockPubScreen, because Un-
181 lockPubScreen can send signal to psn_SigTask. */
183 LockPubScreenList();
184 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount--;
185 DEBUG_VISITOR(dprintf("OpenWorkbench: new VisitorCount %ld\n",
186 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount));
187 UnlockPubScreenList();
189 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
191 return (IPTR)wbscreen;
193 AROS_LIBFUNC_EXIT
195 } /* OpenWorkBench */