Article View: comp.sys.amiga.tech
Article #12117CloseWindowSafely
From: Jim Mackraz
Date: Thu, 06 Apr 1989 00:58
Date: Thu, 06 Apr 1989 00:58
88 lines
2820 bytes
2820 bytes
So, I found my copy of CloseWindowSafely(), so I thought I'd toss it
out there for those who haven't got it. I apologize to those who
asked for me to mail it to them and got no response. I knew it
was around somewhere.
Some people think that this function should test for NULL window pointer. Bah.
--------------------- cut here --------------------------------
/* CloseWindowSafely.c -- use like crazy
* Author: Neil Katin (edited by Jim Mackraz)
*/
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/ports.h"
#include "intuition/intuition.h"
/* this function closes an Intuition window
* that shares a port with other Intuition
* windows (or other compatible IPC).
*
* It is careful to set the window's UserPort to
* null before closing, and to reply to
* any messages that might be pending.
*/
CloseWindowSafely( win )
struct Window *win;
{
/* we forbid here to keep out of race conditions with Intuition */
Forbid();
/* send back any messages for this window
* that have not yet been processed
*/
StripIntuiMessages( win->UserPort, win );
/* clear UserPort so Intuition will not free it */
win->UserPort = NULL;
/* tell inuition to stop sending more messages */
ModifyIDCMP( win, 0L );
/* turn tasking back on */
Permit();
/* and really close the window */
CloseWindow( win );
}
/* Remove and reply any IntuiMessages hanging off of a port
* which were addressed to a particular window.
* Note that technique does not rely on ln_Succ of a message
* after it has been replied.
*/
StripIntuiMessages( mp, win )
struct MsgPort *mp;
struct Window *win;
{
struct IntuiMessage *msg;
struct Node *succ;
msg = (struct IntuiMessage *) mp->mp_MsgList.lh_Head;
while( succ = msg->ExecMessage.mn_Node.ln_Succ ) {
if( msg->IDCMPWindow == win ) {
/* Intuition is about to rudely free this message.
* Make sure that we have politely sent it back.
*/
Remove( msg );
ReplyMsg( msg );
}
msg = (struct IntuiMessage *) succ;
}
}
enjoy
jimm
--
Jim Mackraz, I and I Computing "Like you said when we crawled down
{cbmvax,well,oliveb}!amiga!jimm from the trees: We're in transition."
- Gang of Four
Opinions are my own. Comments are not to be taken as Commodore official policy.
Technical Details
Message-ID:
<3719@amiga.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!oliveb!amiga!jimmShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!oliveb!amiga!jimm From: jimm@amiga.UUCP (Jim Mackraz) Newsgroups: comp.sys.amiga.tech Subject: CloseWindowSafely Message-ID: <3719@amiga.UUCP> Date: 6 Apr 89 00:58:23 GMT Reply-To: jimm@amiga.UUCP (Jim Mackraz) Organization: Commodore-Amiga Inc, Los Gatos CA Lines: 88