home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / closewindow.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  4KB  |  166 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: closewindow.c,v 1.9 1997/01/27 00:36:36 ldp Exp $
  4.     $Log: closewindow.c,v $
  5.     Revision 1.9  1997/01/27 00:36:36  ldp
  6.     Polish
  7.  
  8.     Revision 1.8  1996/12/10 14:00:01  aros
  9.     Moved #include into first column to allow makedepend to see it.
  10.  
  11.     Revision 1.7  1996/11/08 11:28:00  aros
  12.     All OS function use now Amiga types
  13.  
  14.     Moved intuition-driver protos to intuition_intern.h
  15.  
  16.     Revision 1.6  1996/10/31 13:50:55  aros
  17.     Don't forget to free the RastPort
  18.  
  19.     Revision 1.5  1996/10/24 15:51:18  aros
  20.     Use the official AROS macros over the __AROS versions.
  21.  
  22.     Revision 1.4  1996/10/15 15:45:31  digulla
  23.     Two new functions: LockIBase() and UnlockIBase()
  24.     Modified code to make sure that it is impossible to access illegal data (ie.
  25.     fields of a window which is currently beeing closed).
  26.  
  27.     Revision 1.3  1996/09/21 14:16:26  digulla
  28.     Debug code
  29.     Only change the ActiveWindow is it is beeing closed
  30.     Search for a new ActiveWindow
  31.  
  32.     Revision 1.2  1996/08/29 13:33:30  digulla
  33.     Moved common code from driver to Intuition
  34.     More docs
  35.  
  36.     Revision 1.1  1996/08/13 15:37:26  digulla
  37.     First function for intuition.library
  38.  
  39.  
  40.     Desc:
  41.     Lang: english
  42. */
  43. #include "intuition_intern.h"
  44. #include <proto/exec.h>
  45. #include <proto/graphics.h>
  46.  
  47. #ifndef DEBUG_CloseWindow
  48. #   define DEBUG_CloseWindow 0
  49. #endif
  50. #if DEBUG_CloseWindow
  51. #   undef DEBUG
  52. #   define DEBUG 1
  53. #endif
  54. #include <aros/debug.h>
  55.  
  56. /*****************************************************************************
  57.  
  58.     NAME */
  59. #include <proto/intuition.h>
  60.  
  61.     AROS_LH1(void, CloseWindow,
  62.  
  63. /*  SYNOPSIS */
  64.     AROS_LHA(struct Window *, window, A0),
  65.  
  66. /*  LOCATION */
  67.     struct IntuitionBase *, IntuitionBase, 12, Intuition)
  68.  
  69. /*  FUNCTION
  70.     Closes a window. Depending on the display, this might not happen
  71.     at the time when this function returns, but you must not use
  72.     the window pointer after this function has been called.
  73.  
  74.     INPUTS
  75.     window - The window to close
  76.  
  77.     RESULT
  78.     None.
  79.  
  80.     NOTES
  81.     The window might not have been disappeared when this function returns.
  82.  
  83.     EXAMPLE
  84.  
  85.     BUGS
  86.  
  87.     SEE ALSO
  88.     OpenWindow(), OpenWindowTags()
  89.  
  90.     INTERNALS
  91.  
  92.     HISTORY
  93.     29-10-95    digulla automatically created from
  94.                 intuition_lib.fd and clib/intuition_protos.h
  95.  
  96. *****************************************************************************/
  97. {
  98.     AROS_LIBFUNC_INIT
  99.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  100.     struct IntuiMessage * im;
  101.     ULONG lock;
  102.  
  103.     D(bug("CloseWindow (%p)\n", window));
  104.  
  105.     lock = LockIBase (0);
  106.  
  107.     if (window->MoreFlags & EWFLG_DELAYCLOSE)
  108.     {
  109.     window->MoreFlags |= EWFLG_CLOSEWINDOW;
  110.     ReturnVoid ("CloseWindow");
  111.     }
  112.  
  113.     if (window == IntuitionBase->ActiveWindow)
  114.     IntuitionBase->ActiveWindow = NULL;
  115.  
  116.     /* Remove window from the chain and find next active window */
  117.     if (window->Descendant)
  118.     {
  119.     window->Descendant->Parent = window->Parent;
  120.     ActivateWindow (window->Descendant);
  121.     }
  122.     if (window->Parent)
  123.     {
  124.     window->Parent->NextWindow =
  125.         window->Parent->Descendant =
  126.         window->Descendant;
  127.  
  128.     if (!IntuitionBase->ActiveWindow)
  129.         ActivateWindow (window->Parent);
  130.     }
  131.  
  132.     /* Make sure the Screen is still valid */
  133.     if (window == window->WScreen->FirstWindow)
  134.     window->WScreen->FirstWindow = window->NextWindow;
  135.  
  136.     UnlockIBase (lock);
  137.  
  138.     /* Let the driver clean up */
  139.     intui_CloseWindow (window, IntuitionBase);
  140.  
  141.     /* Free resources */
  142.     CloseFont (window->RPort->Font);
  143.  
  144.     FreeRastPort (window->RPort);
  145.  
  146.     if (window->UserPort)
  147.     {
  148.     /* Delete all pending messages */
  149.     Forbid ();
  150.  
  151.     while ((im = (struct IntuiMessage *) GetMsg (window->UserPort)))
  152.         ReplyMsg ((struct Message *)im);
  153.  
  154.     Permit ();
  155.  
  156.     /* Delete message port */
  157.     DeleteMsgPort (window->UserPort);
  158.     }
  159.  
  160.     /* Free memory for the window */
  161.     FreeMem (window, intui_GetWindowSize ());
  162.  
  163.     ReturnVoid ("CloseWindow");
  164.     AROS_LIBFUNC_EXIT
  165. } /* CloseWindow */
  166.