{***********************************************************************}
{									}
{ __TitleWin  Add a title to an existing window 			}
{									}
{ function  __TitleWin(WinPtr : _WindowPtr;				}
{			Title : _WinTitleStr				}
{		    Fore,Back : byte;					}
{			 TPos : _WinTitlePos) : boolean;		}
{									}
{	      WinPtr	Pointer to _Window record to which titles are	}
{			to be added.					}
{	      Title	The title string itself.			}
{	      Fore	Foreground attribute for the title		}
{	      Back	Background attribute for the title		}
{	      TPos	One of six position options.			}
{			_TopCenter     Top border, centered		}
{			_TopRight      Top border, right justified	}
{			_TopLeft       Top border, left justified	}
{			_BottomCenter  Bottom border, centered		}
{			_BottomRight   Bottom border, right justified	}
{			_BottomLeft    Bottom border, left justified	}
{									}
{ Description __TitleWin adds a title to the border of the window	}
{	      referred to by WinPtr.  If this is the current window,	}
{	      the window is updated on screen with the title specified, }
{	      otherwise the title will appear when the window is dis-	}
{	      played with __DispWin.  This means that windows that are	}
{	      active but not current will not display their titles	}
{	      unless redisplayed with __DispWin.			}
{									}
{	      If Title is the null string (''), the function will re-	}
{	      move any previously defined title from the window.	}
{									}
{	      If the specified window pointer does not point to an	}
{	      existing window, or if the window has no border (_BorType }
{	      is 255) then the function returns FALSE, otherwise	}
{	      it returns TRUE.	Titles which are too long to fit on	}
{	      the border are truncated. 				}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __TitleWin(WinPtr : _WindowPtr;
		      Title : _WinTitleStr;
		  Fore,Back : byte;
		       TPos : _WinTitlePos) : boolean;

  var
    TempPtr   : _WindowPtr;
    Found     : boolean;

  begin {__TitleWin}

    { First make sure that WinPtr^ really exists.			}

    Found   := FALSE;
    TempPtr := _WinRoot;
    while ((not Found) and (TempPtr <> NIL)) do
      if (TempPtr = WinPtr) then
	Found := TRUE		       { Window found			}
      else
	 TempPtr := TempPtr^._WinTop;  { Keep looking.			}

    if ((not Found) or (WinPtr^._Border._BorType = _NOBORD_WIN)) then
       begin
	 __TitleWin := FALSE;	       { No window record found, or no	}
	 Exit			       { border on which to put title.	}
       end;

    with WinPtr^._Title do	       { Update _Window record		}
      begin
	_TitlePos := TPos;
	_TitleStr := Title;
	_TFore	  := Fore;
	_TBack	  := Back
      end;

    if (WinPtr = _WinCur) then	       { The window is already current. }
      with WinPtr^ do
	begin
	  __BoxScn(_Dim._XUpper - 1,_Dim._YUpper - 1,
		   _Dim._XLower + 1,_Dim._YLower + 1,
		   _Border._BorType,
		   _Border._BorFore,
		   _Border._BorBack);
	  __FastTWin(WinPtr)	       { Update screen			}
	end;

    __TitleWin	:= TRUE

  end;	{__TitleWin}
