{***********************************************************************}
{									}
{ __RemWin    Remove the current window 				}
{									}
{ function  __RemWin : boolean; 					}
{									}
{ Description This function removes the current window from the cur-	}
{	      ent display page.  The list of window records is searched }
{	      for an active window.  If one is found the variable	}
{	      _WinCur is set to point to this record, and the screen	}
{	      is reset with the appropriate cursor size, text attri-	}
{	      butes, cursor position and image.  If there is no active	}
{	      window the screen is returned to its original image, and	}
{	      _WinCur is set to NIL (no current window).  Note that	}
{	      only the current window can be removed, and if there is	}
{	      no current window, the function returns the value FALSE.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __RemWin : boolean;

  var
    TempPtr  : _WindowPtr;
    ResetWin : _Window;
    Found    : boolean;

  begin {__RemWin}

    if (_WinCur = NIL) then
       begin
	 __RemWin := FALSE;
	 Exit			       { No current window, so return	}
       end;

    with _WinCur^ do		       { Put the screen information	}
      begin			       { back up.			}
	with _Dim do
	  if (_Border._BorType = _NOBORD_WIN) then
	     __MoveScn(_XUpper,_YUpper,_XLower,_YLower,@_Image^,TRUE)
	  else
	     __MoveScn(_XUpper - 1,_YUpper - 1,
			       _XLower + 1,_YLower + 1,@_Image^,TRUE);
	FreeMem(_Image,_ImageSize);
	_Active := FALSE;	       { Now the window is inactive.	}
	_Image	:= NIL
    end;

    TempPtr := _WinCur^._WinUnder;     { Find an active window, if one	}
    Found   := FALSE;		       { exists below the current one.	}
    while ((TempPtr <> NIL) and (not Found)) do
      if (TempPtr^._Image <> NIL) then
	 Found := TRUE
      else
	 TempPtr := TempPtr^._WinUnder;

    if (Found) then		       { Reset the screen with para-	}
       begin			       { meters of the new window.	}
	 _WinCur := TempPtr;
	 ResetWin := TempPtr^
       end
    else
       begin
	 _WinCur := NIL;
	 ResetWin := EntScn_
       end;

    { Reset the current window and the Turbo Pascal window variables.	}

    with ResetWin do
      begin
	with _Dim do
	  begin
	    WindMin := __2WordSup(_YUpper - 1,_XUpper - 1);
	    WindMax := __2WordSup(_YLower - 1,_XLower - 1)
	  end;
	_CurWindow := _Dim;
	TextAttr   := __2ByteSup(_Back,_Fore);
	__CSizeScn(_TopScan,_BotScan);
	__GotoWin (_XCursor,_YCursor)
      end;
    __RemWin := TRUE

  end;	{__RemWin}
