define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / intuition / lockpubscreen.c
blob1a8ab0a9fc34cb6aa63af3a99e6d252f76556c1e
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 <string.h>
8 #include "intuition_intern.h"
10 /*****************************************************************************
12 NAME */
13 #include <proto/intuition.h>
15 AROS_LH1(struct Screen *, LockPubScreen,
17 /* SYNOPSIS */
18 AROS_LHA(CONST_STRPTR, name, A0),
20 /* LOCATION */
21 struct IntuitionBase *, IntuitionBase, 85, Intuition)
23 /* FUNCTION
25 Locks a public screen, thus preventing it from closing.
26 This is useful if you want to put up a visitor window on a public screen
27 and need to check some of the public screen's field first -- not locking
28 the screen may lead to the public screen not existing when your visitor
29 window is ready.
31 If you try to lock the Workbench screen or the default public screen
32 and there isn't any, the Workbench screen will be automatically opened
33 and locked.
35 INPUTS
37 Name -- Name of the public screen or NULL for the default public
38 screen. The name "Workbench" refers to the Workbench screen.
40 RESULT
42 A pointer to the screen or NULL if something went wrong. Failure can
43 happen for instance when the public screen is in private state or doesn't
44 exist.
46 NOTES
48 You don't need to hold the lock when your visitor window is opened as
49 the pubscreen cannot be closed as long as there are visitor windows
50 on it.
52 EXAMPLE
54 To open a visitor window which needs information from the screen structure
55 of the public screen to open on, do this:
57 if((pubscreen = LockPubScreen("PubScreentoOpenon")) != NULL)
59 ...check pubscreen's internal data...
60 OpenWindow(VisitorWindow, pubscreen);
61 UnlockPubScreen(NULL, pubscreen);
62 ...use your visitor window...
63 CloseWindow(VisitorWindow);
66 BUGS
68 SEE ALSO
70 OpenWindow(), UnlockPubScreen(), GetScreenData()
72 INTERNALS
74 HISTORY
75 29-10-95 digulla automatically created from
76 intuition_lib.fd and clib/intuition_protos.h
78 *****************************************************************************/
80 AROS_LIBFUNC_INIT
82 struct Screen *screen = NULL;
83 struct List *list;
85 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: name <%s>\n",
86 name ? name : (CONST_STRPTR)"NULL"));
87 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: task %p <%s>\n",
88 SysBase->ThisTask,
89 SysBase->ThisTask->tc_Node.ln_Name ? SysBase->ThisTask->tc_Node.ln_Name : "NULL"));
91 list = LockPubScreenList();
93 if( !name )
96 screen = GetPrivIBase(IntuitionBase)->DefaultPubScreen;
98 /* If IntuitionBase->DefaultPubScreen is NULL, then Workbench screen
99 is default public screen. But note that, Workbench screen might
100 here not be open either. */
102 if (!screen) screen = GetPrivIBase(IntuitionBase)->WorkBench;
104 if (screen)
106 ASSERT_VALID_PTR(screen);
107 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
108 DEBUG_VISITOR(dprintf("LockPubScreen: 1 screen %p count %ld Task <%s>\n",
109 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
110 FindTask(NULL)->tc_Node.ln_Name));
111 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
112 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
116 else
118 struct PubScreenNode *psn;
120 ASSERT_VALID_PTR_ROMOK(name);
122 /* Browse the public screen list */
123 if( (psn = (struct PubScreenNode *) FindName(list, (UBYTE *)name )) )
125 ASSERT_VALID_PTR(psn);
127 /* Don't lock screens in private state */
128 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
130 /* Increment screen lock count */
131 psn->psn_VisitorCount++;
132 screen = psn->psn_Screen;
133 DEBUG_VISITOR(dprintf("LockPubScreen: 2 node %p screen %p count %ld <%s>\n",
134 psn, screen, psn->psn_VisitorCount,
135 FindTask(NULL)->tc_Node.ln_Name));
136 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: node %p screen %p count %d\n",
137 psn, screen, psn->psn_VisitorCount));
138 ASSERT_VALID_PTR(screen);
144 UnlockPubScreenList();
146 /* If no screen was found and the requested one was the Workbench screen or
147 * the default public screen, open the Workbench screen and lock it. */
148 if( (screen == NULL) && ((name == NULL) || (strcmp( name, "Workbench" ) == 0)) )
150 OpenWorkBench();
151 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: opened workbench\n"));
153 LockPubScreenList();
155 screen = GetPrivIBase(IntuitionBase)->WorkBench;
156 if (!screen)
158 struct PubScreenNode *psn;
160 /* Maybe something patched OpenWorkbench, and there is a 'Workbench'
161 * screen in the list. Our private pointer is just not set. */
162 if( (psn = (struct PubScreenNode *) FindName(list, "Workbench" )) )
164 /* Don't lock screens in private state */
165 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
166 screen = psn->psn_Screen;
170 if( screen )
172 ASSERT_VALID_PTR(screen);
173 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
174 DEBUG_VISITOR(dprintf("LockPubScreen: 3 screen %p count %d <%s>\n",
175 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
176 FindTask(NULL)->tc_Node.ln_Name));
178 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
179 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
182 UnlockPubScreenList();
185 FireScreenNotifyMessage((IPTR) screen, SNOTIFY_LOCKPUBSCREEN, IntuitionBase);
187 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: return %p\n", screen));
189 return screen;
191 AROS_LIBFUNC_EXIT
192 } /* LockPubScreen */