{***********************************************************************}
{									}
{ __DispWin   Display a window. 					}
{									}
{ function  __DispWin(WinPtr : _WindowPtr) : boolean;			}
{									}
{	      WinPtr	Pointer to _Window record describing the window }
{			to be displayed.				}
{									}
{ Description This function  displays the window specified in the	}
{	      record structure on the physical screen.	First it is	}
{	      verified that WinPtr does point to a previously con-	}
{	      structed window (see __MakeWin); if it does not,		}
{	      __DispWin returns FALSE and exits immediately.		}
{									}
{	      If the window record component _Active is FALSE,		}
{	      then this screen is not active, and logically it can	}
{	      be viewed as being placed on top of any other active	}
{	      windows.	In this case, storage is allocated for a screen }
{	      image and it is moved into _Image^.  If _Active is TRUE,	}
{	      then this window is already active (has been displayed)	}
{	      and cannot be redisplayed until it is removed (see	}
{	      __RemWin).  Instead of displaying the window, it is	}
{	      simply made the current window; screen images need not be }
{	      saved. Whether the window is active or not, the window	}
{	      is cleared and the cursor is positioned home (1,1).	}
{									}
{	      The _CurWindow record is set so that other TOOLS		}
{	      procedures know the logical window size, and the Turbo	}
{	      Pascal variables WindMin and WindMax are set to Turbo	}
{	      Pascal intrinsic routines know the current window size.	}
{	      Finally, the current window pointer (_WinCur) is set to	}
{	      WinPtr.							}
{									}
{	      Displaying a window that is "covered" by another window	}
{	      results in the displayed and covered window to have	}
{	      inaccurate screen images.  When they are removed, the	}
{	      images replaced no longer reflect the screen state.  It	}
{	      is not recommended that a "hidden" window be displayed.	}
{	      Your should remove (see __RemWin) windows in the order in }
{	      which they are stacked.  Use __TopWin to move a hidden	}
{	      window to the top.  If on the otherhand, the windows	}
{	      do not overlap, there is no danger is displaying either	}
{	      even if they are both active.  In fact, this is a con-	}
{	      venient method for initializing the window (that is,	}
{	      clearing the window and setting the cursor to the home	}
{	      position).						}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __DispWin(WinPtr : _WindowPtr) : boolean;

  var
    TempPtr   : _WindowPtr;
    ImagePtr  : Pointer;
    ImageSize : word;
    CTop,CBot : byte;
    Found     : boolean;
    Ch	      : char;

  begin {__DispWin}

    Found   := FALSE;
    TempPtr := _WinRoot;
    while ((not Found) and (TempPtr <> NIL)) do
      if (TempPtr = WinPtr) then
	 Found := TRUE
      else
	 TempPtr := TempPtr^._WinTop;
    if (not Found) then
       begin
	 __DispWin := FALSE;
	 Exit			       { No record found, so return.	}
       end;

    { Now display the window .........................................	}

    with WinPtr^ do
      begin
	if (not _Active) then	       { This is a new activation, so	}
	   begin		       { allocate space for the image.	}
	     _Active := TRUE;
	     GetMem(_Image,_ImageSize);

	     { Now save that portion of the screen which is covered by	}
	     { the window.  For efficiency, only the necessary data	}
	     { is moved.						}

	     with _Dim do
	       if (_Border._BorType = _NOBORD_WIN) then
		  __MoveScn(_XUpper,_YUpper,_XLower,_YLower,
							  @_Image^,FALSE)
	       else
		  __MoveScn(_XUpper - 1,_YUpper - 1,
			    _XLower + 1,_YLower + 1,@_Image^,FALSE)

	   end;

	if (_WinCur <> NIL) then       { Save the cursor position of	}
	   with _WinCur^ do	       { the currently active window	}
	     __WhereWin(_XCursor,_YCursor,CTop,CBot)
	else			       { Save parameters for the entire }
	   with EntScn_ do	       { screen.			}
	     begin
	       __WhereScn(_XCursor,_YCursor,_TopScan,_BotScan);
	       Ch := __RCharScn(_Fore,_Back);
	       with _Dim do
		 begin
		   _XUpper := 1;
		   _YUpper := 1;
		   _XLower := _CurColumns;
		   _YLower := _CurRows
		 end
	     end;

	{ Display the border if there is a request for one, display the }
	{ title, if any, and clear the window.				}

	with _Border do
	  if (_BorType <> _NOBORD_WIN) then
	    begin
	      __BoxScn(_Dim._XUpper - 1,_Dim._YUpper - 1,
		       _Dim._XLower + 1,_Dim._YLower + 1,
		       _BorType,_BorFore,_BorBack);

	      if (Length(_Title._TitleStr) <> 0) then
		  __FastTWin(WinPtr)
	    end;
	__VertScn(_Dim._XUpper,_Dim._YUpper,
		  _Dim._XLower,_Dim._YLower,0,_Fore,_Back,TRUE);

	{ Set the Turbo Pascal variable that track the current window	}
	{ size so that GotoXY and WhereX, WhereY work properly. 	}
	{ Also set _CurWindow so all POWER TOOLS PLUS routines know the }
	{ current window dimensions.					}

	with _Dim do
	  begin
	    WindMin := __2WordSup(_YUpper - 1,_XUpper - 1);
	    WindMax := __2WordSup(_YLower - 1,_XLower - 1)
	  end;
	_CurWindow  := _Dim;

	{ Set the cursor size, and set the Turbo Pascal TextAttr	}
	{ variable so that the Turbo Pascal output routines display	}
	{ with the proper attributes.					}

	__CSizeScn(_TopScan,_BotScan);
	TextAttr := __2ByteSup(_Back,_Fore);

	__GotoWin(1,1)			 { Place the cursor home	}
      end;

    { Finally adjust the window record pointers so that this record is	}
    { the last one in the list (i.e., it is on top of all others).	}

    if (WinLast_ <> WinPtr) then	 { There is something to do,	}
       with WinPtr^ do			 { because there are windows	}
	 begin				 { on top of this one.		}
	   if (WinPtr = _WinRoot) then	 { It is the first record, so	}
	      _WinRoot := _WinTop	 { the root must be altered.	}
	   else 			 { If not the first, the one	}
	      _WinUnder^._WinTop := _WinTop;  {underneath is altered.	}
	   _WinTop^._WinUnder := _WinUnder;
	   WinLast_^._WinTop  := WinPtr;
	   _WinTop	      := NIL;
	   _WinUnder	      := WinLast_;
	   WinLast_	      := WinPtr
	 end;
    _WinCur   := WinPtr;	       { Set the current window pointer }
    __DispWin := TRUE

  end;	{__DispWin}
