New attempt to get the svn revision into the AboutAROS requester.
[cake.git] / rom / intuition / closeworkbench.c
blob49e5984b49b6d21193b888927e0e5d43a0cc5af3
1 /*
2 Copyright 1995-2008, 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>
12 /*****************************************************************************
14 NAME */
16 AROS_LH0(LONG, CloseWorkBench,
18 /* SYNOPSIS */
20 /* LOCATION */
21 struct IntuitionBase *, IntuitionBase, 13, Intuition)
23 /* FUNCTION
24 Attempt to close the Workbench screen. This will fail if there are any
25 non-Drawer windows open on it.
27 INPUTS
29 RESULT
30 success - TRUE if Workbench screen could be closed.
32 NOTES
33 If the Workbench screen is already closed when this function is called,
34 FALSE is returned.
36 EXAMPLE
38 BUGS
40 SEE ALSO
41 OpenWorkBench()
43 INTERNALS
45 HISTORY
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct Screen *wbscreen;
52 BOOL retval = TRUE;
54 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: <%s>\n",
55 FindTask(NULL)->tc_Node.ln_Name));
57 if (wbscreen) FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_BEFORE_CLOSEWB, IntuitionBase);
59 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
60 LockPubScreenList();
61 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
63 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
65 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%lx\n",
66 (ULONG) wbscreen));
68 if (!wbscreen)
70 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
71 UnlockPubScreenList();
73 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
75 return(FALSE);
77 else
79 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
80 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
81 if (GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount != 0)
83 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
84 (ULONG) GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount));
85 retval = FALSE;
89 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
90 UnlockPubScreenList();
91 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
93 /* If there is a Workbench process running, tell it to close its windows. */
95 /* Don't call this function while pub screen list is locked! */
97 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
98 TellWBTaskToCloseWindows(IntuitionBase);
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
101 LockPubScreenList();
102 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
104 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
106 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
107 (ULONG) wbscreen));
109 /* Try to close the Workbench screen, if there is any. */
110 if( wbscreen != NULL )
112 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
113 if (CloseScreen(wbscreen))
115 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
116 GetPrivIBase(IntuitionBase)->WorkBench = NULL;
117 wbscreen = NULL;
118 retval = TRUE;
120 else
122 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
123 * to avoid that someone else can kill it, because I must tell Workbench
124 * task that it shall open its windows again
127 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
128 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount++;
129 retval = FALSE;
132 else
134 retval = FALSE;
137 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
138 UnlockPubScreenList();
139 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
141 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
142 (ULONG) wbscreen,
143 (ULONG) retval));
144 if (wbscreen && !retval)
146 /* Don't call this function while pub screen list is locked! */
147 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
148 TellWBTaskToOpenWindows(IntuitionBase);
150 /* Fix psn_VisitorCount which was increased above */
151 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
152 LockPubScreenList();
153 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
154 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
155 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
156 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount--;
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
158 UnlockPubScreenList();
159 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
162 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval));
164 if (!retval)
166 /* Workbench screen failed to close, notify that the screen is open again */
167 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
169 else
171 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_CLOSEWB, IntuitionBase);
174 return retval;
176 AROS_LIBFUNC_EXIT
178 } /* CloseWorkBench */