CopyToAFS: Remove dead FMF_* flags
[AROS.git] / rom / intuition / closeworkbench.c
blobc19333e8b38be4cb398a656d79dd2afef8b1cd50
1 /*
2 Copyright 1995-2010, 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 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
58 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%p\n", wbscreen));
60 if (wbscreen) FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_BEFORE_CLOSEWB, IntuitionBase);
62 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
63 LockPubScreenList();
64 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
66 if (!wbscreen)
68 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
69 UnlockPubScreenList();
71 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
73 return(FALSE);
75 else
77 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
78 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
79 if (GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount != 0)
81 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
82 (ULONG) GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount));
83 retval = FALSE;
87 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
88 UnlockPubScreenList();
89 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
91 /* If there is a Workbench process running, tell it to close its windows. */
93 /* Don't call this function while pub screen list is locked! */
95 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
96 TellWBTaskToCloseWindows(IntuitionBase);
98 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
99 LockPubScreenList();
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
102 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
104 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
105 (ULONG) wbscreen));
107 /* Try to close the Workbench screen, if there is any. */
108 if( wbscreen != NULL )
110 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
111 if (CloseScreen(wbscreen))
113 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
114 GetPrivIBase(IntuitionBase)->WorkBench = NULL;
115 wbscreen = NULL;
116 retval = TRUE;
118 else
120 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
121 * to avoid that someone else can kill it, because I must tell Workbench
122 * task that it shall open its windows again
125 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
126 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount++;
127 retval = FALSE;
130 else
132 retval = FALSE;
135 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
136 UnlockPubScreenList();
137 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
139 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
140 (ULONG) wbscreen,
141 (ULONG) retval));
142 if (wbscreen && !retval)
144 /* Don't call this function while pub screen list is locked! */
145 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
146 TellWBTaskToOpenWindows(IntuitionBase);
148 /* Fix psn_VisitorCount which was increased above */
149 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
150 LockPubScreenList();
151 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
152 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
153 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
154 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount--;
155 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
156 UnlockPubScreenList();
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
160 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval));
162 if (!retval)
164 /* Workbench screen failed to close, notify that the screen is open again */
165 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
167 else
169 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_CLOSEWB, IntuitionBase);
172 return retval;
174 AROS_LIBFUNC_EXIT
176 } /* CloseWorkBench */