CopyToAFS: Remove dead FMF_* flags
[AROS.git] / rom / intuition / lockpubscreen.c
blobeb88c65d02bd45c131b6fdb832f3138a64f7aca1
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 <string.h>
8 #include "intuition_intern.h"
10 static struct PubScreenNode *findcasename(struct List *list, const UBYTE *name);
12 /*****************************************************************************
14 NAME */
15 #include <proto/intuition.h>
17 AROS_LH1(struct Screen *, LockPubScreen,
19 /* SYNOPSIS */
20 AROS_LHA(CONST_STRPTR, name, A0),
22 /* LOCATION */
23 struct IntuitionBase *, IntuitionBase, 85, Intuition)
25 /* FUNCTION
27 Locks a public screen, thus preventing it from closing.
28 This is useful if you want to put up a visitor window on a public screen
29 and need to check some of the public screen's field first -- not locking
30 the screen may lead to the public screen not existing when your visitor
31 window is ready.
33 If you try to lock the Workbench screen or the default public screen
34 and there isn't any, the Workbench screen will be automatically opened
35 and locked.
37 INPUTS
39 Name -- Name of the public screen or NULL for the default public
40 screen. The name "Workbench" refers to the Workbench screen.
41 The name is case insensitive.
43 RESULT
45 A pointer to the screen or NULL if something went wrong. Failure can
46 happen for instance when the public screen is in private state or doesn't
47 exist.
49 NOTES
51 You don't need to hold the lock when your visitor window is opened as
52 the pubscreen cannot be closed as long as there are visitor windows
53 on it.
55 EXAMPLE
57 To open a visitor window which needs information from the screen structure
58 of the public screen to open on, do this:
60 if((pubscreen = LockPubScreen("PubScreentoOpenon")) != NULL)
62 ...check pubscreen's internal data...
63 OpenWindow(VisitorWindow, pubscreen);
64 UnlockPubScreen(NULL, pubscreen);
65 ...use your visitor window...
66 CloseWindow(VisitorWindow);
69 BUGS
71 SEE ALSO
73 OpenWindow(), UnlockPubScreen(), GetScreenData()
75 INTERNALS
77 HISTORY
78 29-10-95 digulla automatically created from
79 intuition_lib.fd and clib/intuition_protos.h
81 *****************************************************************************/
83 AROS_LIBFUNC_INIT
85 struct Screen *screen = NULL;
86 struct List *list;
88 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: name <%s>\n",
89 name ? name : (CONST_STRPTR)"NULL"));
90 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: task %p <%s>\n",
91 SysBase->ThisTask,
92 SysBase->ThisTask->tc_Node.ln_Name ? SysBase->ThisTask->tc_Node.ln_Name : "NULL"));
94 list = LockPubScreenList();
96 if( !name )
99 screen = GetPrivIBase(IntuitionBase)->DefaultPubScreen;
101 /* If IntuitionBase->DefaultPubScreen is NULL, then Workbench screen
102 is default public screen. But note that, Workbench screen might
103 here not be open either. */
105 if (!screen) screen = GetPrivIBase(IntuitionBase)->WorkBench;
107 if (screen)
109 ASSERT_VALID_PTR(screen);
110 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
111 DEBUG_VISITOR(dprintf("LockPubScreen: 1 screen %p count %ld Task <%s>\n",
112 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
113 FindTask(NULL)->tc_Node.ln_Name));
114 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
115 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
119 else
121 struct PubScreenNode *psn;
123 ASSERT_VALID_PTR(name);
125 /* Browse the public screen list */
126 if( (psn = findcasename(list, (UBYTE *)name )) )
128 ASSERT_VALID_PTR(psn);
130 /* Don't lock screens in private state */
131 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
133 /* Increment screen lock count */
134 psn->psn_VisitorCount++;
135 screen = psn->psn_Screen;
136 DEBUG_VISITOR(dprintf("LockPubScreen: 2 node %p screen %p count %ld <%s>\n",
137 psn, screen, psn->psn_VisitorCount,
138 FindTask(NULL)->tc_Node.ln_Name));
139 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: node %p screen %p count %d\n",
140 psn, screen, psn->psn_VisitorCount));
141 ASSERT_VALID_PTR(screen);
147 UnlockPubScreenList();
149 /* If no screen was found and the requested one was the Workbench screen or
150 * the default public screen, open the Workbench screen and lock it. */
151 if( (screen == NULL) && ((name == NULL) || (strcasecmp( name, "Workbench" ) == 0)) )
153 OpenWorkBench();
154 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: opened workbench\n"));
156 LockPubScreenList();
158 screen = GetPrivIBase(IntuitionBase)->WorkBench;
159 if (!screen)
161 struct PubScreenNode *psn;
163 /* Maybe something patched OpenWorkbench, and there is a 'Workbench'
164 * screen in the list. Our private pointer is just not set. */
165 if( (psn = findcasename(list, "Workbench" )) )
167 /* Don't lock screens in private state */
168 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
169 screen = psn->psn_Screen;
173 if( screen )
175 ASSERT_VALID_PTR(screen);
176 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
177 DEBUG_VISITOR(dprintf("LockPubScreen: 3 screen %p count %d <%s>\n",
178 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
179 FindTask(NULL)->tc_Node.ln_Name));
181 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
182 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
185 UnlockPubScreenList();
188 FireScreenNotifyMessage((IPTR) screen, SNOTIFY_LOCKPUBSCREEN, IntuitionBase);
190 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: return %p\n", screen));
192 return screen;
194 AROS_LIBFUNC_EXIT
195 } /* LockPubScreen */
198 /* case insensitive FindName() */
199 static struct PubScreenNode *findcasename(struct List *list, const UBYTE *name)
201 struct Node *node;
203 for (node = GetHead(list); node; node = GetSucc(node))
205 if(node->ln_Name)
207 if (!strcasecmp (node->ln_Name, name))
208 break;
211 return (struct PubScreenNode *)node;