home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 12588 < prev    next >
Encoding:
Text File  |  1992-08-23  |  5.2 KB  |  168 lines

  1. Path: sparky!uunet!nntp1.radiomail.net!portal!cup.portal.com!Lee_Robert_Willis
  2. From: Lee_Robert_Willis@cup.portal.com
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: idcmp port
  5. Message-ID: <64501@cup.portal.com>
  6. Date: Sun, 23 Aug 92 11:16:51 PDT
  7. Organization: The Portal System (TM)
  8. Distribution: world
  9. References:  <1992Aug23.848.15894@dosgate>
  10. Lines: 156
  11.  
  12. #ifndef INTUITION_UTILS_H
  13. #define INTUITION_UTILS_H
  14.  
  15. #include <exec/types.h>
  16. #include <intuition/intuition.h>
  17.  
  18.  
  19.  
  20. /*F:OpenWindowWithSharedUserPort*
  21.  
  22. ------------------------------------------------------------
  23.  
  24.                OpenWindowWithSharedUserPort
  25.  
  26. ------------------------------------------------------------
  27.  
  28. Name:          OpenWindowWithSharedUserPort - opens a window with a shared port.
  29. Syntax:        | window = OpenWindowWithSharedPort( nw, port );
  30.                | struct Window    *window;
  31.                | struct NewWindow *nw;
  32.                | struct MsgPort   *port;
  33.  
  34. Description:   To handle multiple windows within the one application, the
  35.                best method (usually) is to have all the windows share the
  36.                same UserPort.  This way, one can still do a 'WaitPort()'.
  37.                (Otherwise one has to mess with signal bits.)
  38.  
  39.                In order to force a window to have a specific UserPort, one
  40.                must first create the port (using 'CreatePort()'), and then
  41.                there is a sequence of steps involved in opening the window.
  42.                (This is described in the 1.3 RKM Libraries and Devices manual
  43.                on page 167 "SETTING UP YOUR OWN IDCMP MONITOR TASK AND USER
  44.                PORT")
  45.  
  46.                'OpenWindowWithSharedPort()' does all the steps after the
  47.                creation of the MsgPort.   All you do is pass in the NewWindow
  48.                structure and the message port, and
  49.                'OpenWindowWithSharedUserPort' will open the window and do
  50.                the UserPort setup.
  51.  
  52. Note:          Windows opened with this function must be closed using
  53.                'CloseWindowWithSharedUserPort()', NOT 'CloseWindow()'!
  54.  
  55. See Also:      CloseWindowWithSharedUserPort
  56. Author:        Lee R. Willis
  57. */
  58.  
  59. struct Window *OpenWindowWithSharedUserPort( struct NewWindow *nw,
  60.                                              struct MsgPort   *shared );
  61.  
  62.  
  63. /*F:CloseWindowWithSharedUserPort*
  64.  
  65. ------------------------------------------------------------
  66.  
  67.                CloseWindowWithSharedUserPort
  68.  
  69. ------------------------------------------------------------
  70.  
  71. Name:          CloseWindowWithSharedUserPort - closes a window with a shared port.
  72. Syntax:        | CloseWindowWithSharedPort( w );
  73.                | struct Window *w;
  74. Description:   To handle multiple windows within the one application, the
  75.                best method (usually) is to have all the windows share the
  76.                same UserPort.  This way, one still to a 'WaitPort()' or
  77.                'WaitForMessage()'.  (Otherwise one has to mess with signal
  78.                bits.)
  79.  
  80.                Closing such a window requires some care, as Intuition normally
  81.                deallocates the UserPort for such a window on closing, and
  82.                since the port is shared, other windows are still using it!
  83.                (This is described in the 1.3 RKM Libraries and Devices manual
  84.                on page 167 "SETTING UP YOUR OWN IDCMP MONITOR TASK AND USER
  85.                PORT")
  86.  
  87.                'CloseWindowWithSharedUserPort()' does all this for you.
  88.  
  89. See Also:      OpenWindowWithSharedUserPort
  90. Author:        Lee R. Willis
  91. */
  92.  
  93. void CloseWindowWithSharedUserPort( struct Window *w );
  94.    /* Taken from 1.3 RKM:L&D, page 171 'CloseWindowSafely' */
  95.  
  96. #endif
  97.  
  98. /*-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=-=-=--=*/
  99.  
  100. #include "Intuition_utils.h"
  101. #ifdef LATTICE
  102. #include <proto/all.h>
  103. #endif
  104.  
  105.  
  106. struct Window *OpenWindowWithSharedUserPort( struct NewWindow *nw,
  107.                                              struct MsgPort   *shared )
  108. {
  109.    ULONG IDCMPbuf;
  110.    struct Window *w;
  111.  
  112.    IDCMPbuf       = nw->IDCMPFlags;
  113.    nw->IDCMPFlags = 0;  /* no IDCMP flags. */
  114.  
  115.    if (w = OpenWindow( nw ))
  116.    {
  117.       w->UserPort = shared;         /* assign UserPort. */
  118.       ModifyIDCMP( w, IDCMPbuf );   /* turn on IDCMP    */
  119.    }
  120.    nw->IDCMPFlags = IDCMPbuf; /* return 'nw' to its previous state. */
  121.    return w;
  122. }
  123.  
  124.  
  125. void StripIntuiMessages( struct Window *w )
  126. /*
  127.    *ASSUMES* a Forbid() has been called!
  128.  
  129.    Taken from 1.3 RKM:L&D, page 171
  130. */
  131. {
  132.    struct MsgPort *mp;
  133.    struct IntuiMessage *msg, *succ;
  134.  
  135.    mp = w->UserPort;
  136.  
  137.    /*
  138.     * Loop through all messages waiting at this port, remove any
  139.     * which are for Window 'w'.
  140.     */
  141.  
  142.    msg = (struct IntuiMessage*) mp->mp_MsgList.lh_Head;
  143.    while( succ = (struct IntuiMessage*) msg->ExecMessage.mn_Node.ln_Succ )
  144.    {
  145.       if (msg->IDCMPWindow == w)
  146.       {
  147.          Remove((struct Node *) msg);
  148.          ReplyMsg((struct Message *) msg);
  149.       }
  150.  
  151.       msg = succ;
  152.    }
  153. }
  154.  
  155. void CloseWindowWithSharedUserPort( struct Window *w )
  156.    /* Taken from 1.3 RKM:L&D, page 171, 'CloseWindowSafely()' */
  157. {
  158.    Forbid();               /* Turn off multitasking */
  159.  
  160.    StripIntuiMessages( w );  /* remove all messages for this window. */
  161.  
  162.    w->UserPort = NULL;
  163.    ModifyIDCMP( w, 0 ); /* prevents new messages from occuring. */
  164.    Permit();
  165.  
  166.    CloseWindow( w );
  167. }
  168.