added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / closeworkbench.c
blobd30eb9c7de76d4f510fe6220c15a333dc465c65c
1 /*
2 Copyright 1995-2007, 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:
25 - Check for open application windows. return FALSE if there are any
26 - Clean up all special buffers
27 - Close the Workbench screen
28 - Make the Workbench program mostly inactive
29 (disk activity will still be monitored)
30 - Return TRUE
32 INPUTS
34 RESULT
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 OpenWorkBench()
45 INTERNALS
47 HISTORY
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 struct Screen *wbscreen;
54 BOOL retval = TRUE;
56 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: <%s>\n",
57 FindTask(NULL)->tc_Node.ln_Name));
59 if (wbscreen) FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_BEFORE_CLOSEWB, IntuitionBase);
61 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
62 LockPubScreenList();
63 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
65 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
67 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen 0x%lx\n",
68 (ULONG) wbscreen));
70 if (!wbscreen)
72 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: no wbscreen, do nothing\n"));
73 UnlockPubScreenList();
75 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
77 return(FALSE);
79 else
81 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Workbench Screen's pubnode 0x%lx\n",
82 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
83 if (GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount != 0)
85 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: visitor count %ld, do nothing\n",
86 (ULONG) GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount));
87 retval = FALSE;
91 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList\n"));
92 UnlockPubScreenList();
93 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnlockPubScreenList done\n"));
96 /* If there is a Workbench process running, tell it to close it's windows. */
98 /* Don't call this function while pub screen list is locked! */
100 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to close windows\n"));
101 TellWBTaskToCloseWindows(IntuitionBase);
103 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
104 LockPubScreenList();
105 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
107 wbscreen = GetPrivIBase(IntuitionBase)->WorkBench;
109 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: current wbscreen 0x%lx\n",
110 (ULONG) wbscreen));
112 /* Try to close the Workbench screen, if there is any. */
113 if( wbscreen != NULL )
115 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen\n"));
116 if (CloseScreen(wbscreen))
118 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen worked\n"));
119 GetPrivIBase(IntuitionBase)->WorkBench = NULL;
120 wbscreen = NULL;
121 retval = TRUE;
123 else
125 /* Grrr ... closing screen failed. I inc psn_VisitorCount by hand here,
126 * to avoid that someone else can kill it, because I must tell Workbench
127 * task that it shall open its windows again
130 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: CloseScreen failed\n"));
131 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount++;
132 retval = FALSE;
135 else
137 retval = FALSE;
140 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
141 UnlockPubScreenList();
142 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
144 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: wbscreen 0x%lx retval %ld\n",
145 (ULONG) wbscreen,
146 (ULONG) retval));
147 if (wbscreen && !retval)
149 /* Don't call this function while pub screen list is locked! */
150 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Tell WB to reopen windows\n"));
151 TellWBTaskToOpenWindows(IntuitionBase);
153 /* Fix psn_VisitorCount which was increased above */
154 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList\n"));
155 LockPubScreenList();
156 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: LockPubScreenList done\n"));
157 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: WBScreen's pubnode 0x%lx\n",
158 (ULONG) GetPrivScreen(wbscreen)->pubScrNode));
159 GetPrivScreen(wbscreen)->pubScrNode->psn_VisitorCount--;
160 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList\n"));
161 UnlockPubScreenList();
162 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: UnLockPubScreenList done\n"));
165 DEBUG_CLOSEWORKBENCH(dprintf("CloseWorkBench: Return %d\n", retval));
167 if (!retval)
169 /* Workbench screen failed to close, notify that the screen is open again */
170 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_OPENWB, IntuitionBase);
172 else
174 FireScreenNotifyMessage((IPTR) wbscreen, SNOTIFY_AFTER_CLOSEWB, IntuitionBase);
177 return retval;
179 AROS_LIBFUNC_EXIT
181 } /* CloseWorkBench */