grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / intuition / lockpubscreen.c
blob9900f86e28370c81f07891ace14d93d50f0b71b3
1 /*
2 Copyright © 1995-2013, 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
26 Locks a public screen, thus preventing it from closing. This is
27 useful if you want to put up a visitor window on a public screen
28 and need to check some of the public screen's fields first -- not
29 locking the screen may lead to the public screen not existing when
30 your visitor window is ready.
32 If you try to lock the Workbench screen or the default public screen
33 and there isn't any, the Workbench screen will be automatically opened
34 and locked.
36 INPUTS
37 name - Name of the public screen or NULL for the default public
38 screen. The name "Workbench" refers to the Workbench screen.
39 The name is case insensitive.
41 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
44 doesn't exist.
46 NOTES
47 You don't need to hold the lock when your visitor window is opened as
48 the pubscreen cannot be closed as long as there are visitor windows
49 on it.
51 EXAMPLE
52 To open a visitor window which needs information from the screen
53 structure of the public screen to open on, do this:
55 if((pubscreen = LockPubScreen("PubScreentoOpenon")) != NULL)
57 ...check pubscreen's internal data...
58 OpenWindow(VisitorWindow, pubscreen);
59 UnlockPubScreen(NULL, pubscreen);
60 ...use your visitor window...
61 CloseWindow(VisitorWindow);
64 BUGS
66 SEE ALSO
67 OpenWindow(), UnlockPubScreen(), GetScreenData()
69 INTERNALS
71 *****************************************************************************/
73 AROS_LIBFUNC_INIT
75 struct Screen *screen = NULL;
76 struct List *list;
78 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: name <%s>\n",
79 name ? name : (CONST_STRPTR)"NULL"));
80 DEBUG_LOCKPUBSCREEN({struct Task *t = FindTask(NULL);
81 dprintf("LockPubScreen: task %p <%s>\n",
83 t->tc_Node.ln_Name ? t->tc_Node.ln_Name : "NULL");});
85 list = LockPubScreenList();
87 if( !name )
90 screen = GetPrivIBase(IntuitionBase)->DefaultPubScreen;
92 /* If IntuitionBase->DefaultPubScreen is NULL, then Workbench screen
93 is default public screen. But note that, Workbench screen might
94 here not be open either. */
96 if (!screen) screen = GetPrivIBase(IntuitionBase)->WorkBench;
98 if (screen)
100 ASSERT_VALID_PTR(screen);
101 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
102 DEBUG_VISITOR(dprintf("LockPubScreen: 1 screen %p count %ld Task <%s>\n",
103 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
104 FindTask(NULL)->tc_Node.ln_Name));
105 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
106 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
110 else
112 struct PubScreenNode *psn;
114 ASSERT_VALID_PTR(name);
116 /* Browse the public screen list */
117 if( (psn = findcasename(list, (UBYTE *)name )) )
119 ASSERT_VALID_PTR(psn);
121 /* Don't lock screens in private state */
122 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
124 /* Increment screen lock count */
125 psn->psn_VisitorCount++;
126 screen = psn->psn_Screen;
127 DEBUG_VISITOR(dprintf("LockPubScreen: 2 node %p screen %p count %ld <%s>\n",
128 psn, screen, psn->psn_VisitorCount,
129 FindTask(NULL)->tc_Node.ln_Name));
130 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: node %p screen %p count %d\n",
131 psn, screen, psn->psn_VisitorCount));
132 ASSERT_VALID_PTR(screen);
138 UnlockPubScreenList();
140 /* If no screen was found and the requested one was the Workbench screen or
141 * the default public screen, open the Workbench screen and lock it. */
142 if( (screen == NULL) && ((name == NULL) || (strcasecmp( name, "Workbench" ) == 0)) )
144 OpenWorkBench();
145 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: opened workbench\n"));
147 LockPubScreenList();
149 screen = GetPrivIBase(IntuitionBase)->WorkBench;
150 if (!screen)
152 struct PubScreenNode *psn;
154 /* Maybe something patched OpenWorkbench, and there is a 'Workbench'
155 * screen in the list. Our private pointer is just not set. */
156 if( (psn = findcasename(list, "Workbench" )) )
158 /* Don't lock screens in private state */
159 if( (psn != NULL) && !(psn->psn_Flags & PSNF_PRIVATE) )
160 screen = psn->psn_Screen;
164 if( screen )
166 ASSERT_VALID_PTR(screen);
167 GetPrivScreen(screen)->pubScrNode->psn_VisitorCount++;
168 DEBUG_VISITOR(dprintf("LockPubScreen: 3 screen %p count %d <%s>\n",
169 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount,
170 FindTask(NULL)->tc_Node.ln_Name));
172 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: screen %p count %d\n",
173 screen, GetPrivScreen(screen)->pubScrNode->psn_VisitorCount));
176 UnlockPubScreenList();
179 FireScreenNotifyMessage((IPTR) screen, SNOTIFY_LOCKPUBSCREEN, IntuitionBase);
181 DEBUG_LOCKPUBSCREEN(dprintf("LockPubScreen: return %p\n", screen));
183 return screen;
185 AROS_LIBFUNC_EXIT
186 } /* LockPubScreen */
189 /* case insensitive FindName() */
190 static struct PubScreenNode *findcasename(struct List *list, const UBYTE *name)
192 struct Node *node;
194 for (node = GetHead(list); node; node = GetSucc(node))
196 if(node->ln_Name)
198 if (!strcasecmp (node->ln_Name, name))
199 break;
202 return (struct PubScreenNode *)node;