Commits

Anonymous committed 90d7fed

DOS windowing library (alternative to NCurses or Turbo Vision)

  • Participants

Comments (0)

Files changed (8)

+/* |--------------------------------------------------------------|
+   | MS-DOS Window management library by David Duncan Ross Palmer |
+   | Copyright Š 1997, Abbott & Palmer Corporation                |
+   |--------------------------------------------------------------|
+*/
+
+/* DOS menuing system */
+//------------------------------------------------------------------------------
+#include "c:\bc5\projects\shared\DOS\DosWL\DosMnu.h" /* This module's header */
+#include <conio.h>
+#include <stdio.h>
+#include <stdlib.h>
+//#include <string.h>
+#ifndef DOSMNUH
+	#pragma message DOS windowing library (menus): Translation unit should be built with DOSMNU.H
+#endif
+#ifdef DOSWINDOW_DEBUGMODE
+	#pragma message DOS windowing library (menus): !DEBUGGING MODE DEFINED! - remove before release build by undefining DOSWINDOW_DEBUGMODE
+#endif
+//------------------------------------------------------------------------------
+__fastcall TDOSMainMenu::TDOSMainMenu(bool SaveUnderneath)
+{
+	/* Constructor */
+   /* Initializer list (the defaults) */
+   SaveUnderSwitch /*cmf*/ = SaveUnderneath;
+   InactiveColor = WHITE;
+   InactiveTextColor = BLACK;
+   ActiveColor = BLACK;
+   ActiveTextColor = WHITE;
+   //UsedEntries = new bool[DOSMAINMENU_MAX + 1];
+   //for (int i=0; i<DOSMAINMENU_MAX; i++)
+   //	UsedEntries[i] = false;
+   //PointerToMenu = new void*[DOSMAINMENU_MAX + 1];
+   //for (int i=0; i<DOSMAINMENU_MAX; i++)
+   //	PointerToMenu[i] = 0;
+   SavedPortion = 0; // So we can tell when an address is assigned
+   /* display */
+   if (SaveUnderSwitch)
+   	SaveUnder();
+   Refresh();
+}
+//------------------------------------------------------------------------------
+__fastcall TDOSMainMenu::~TDOSMainMenu()
+{
+	/* Destructor */
+   if (SaveUnderSwitch) // only load if originally saved, otherwise I cause an access violation
+   	LoadUnder(); // Load underneath effected area
+   /* destruction list */
+   // delete[] &UsedEntries;      // Uncomment these when pointer arrays are in use, and won't cause general prot. faults
+   // delete[] &PointerToMenu;
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::SetInactiveColor(int NewColor)
+{
+	if (NewColor == InactiveColor)
+   	return; // abort change if color is current
+   InactiveColor = NewColor; // set the new color
+   Refresh();
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::SetInactiveTextColor(int NewColor)
+{
+	if (NewColor == InactiveTextColor)
+   	return;
+   InactiveTextColor = NewColor;
+   Refresh();
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::SetActiveColor(int NewColor)
+{
+	if (NewColor == ActiveColor)
+   	return;
+   ActiveColor = NewColor;
+   Refresh();
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::SetActiveTextColor(int NewColor)
+{
+	if (NewColor == ActiveTextColor)
+   	return;
+   ActiveTextColor = NewColor;
+   Refresh();
+}
+//------------------------------------------------------------------------------
+int TDOSMainMenu::GetInactiveColor()
+{
+	return InactiveColor;
+}
+//------------------------------------------------------------------------------
+int TDOSMainMenu::GetInactiveTextColor()
+{
+	return InactiveTextColor;
+}
+//------------------------------------------------------------------------------
+int TDOSMainMenu::GetActiveColor()
+{
+	return ActiveColor;
+}
+//------------------------------------------------------------------------------
+int TDOSMainMenu::GetActiveTextColor()
+{
+	return ActiveTextColor;
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::Refresh() /* draws the menu header */
+{
+	/* This routine is public, but is usually used with internal routines,
+   it has been left public just incase the programmer needs the menu to be redrawn */
+
+   /* Set the menu colors */
+   textcolor(InactiveTextColor);
+   textbackground(InactiveColor);
+
+   /* Set the cursor up */
+   int OldX = wherex();
+   int OldY = wherey();
+   gotoxy(1,1); // Top left of screen
+
+   /* Draw header */
+   for (int i=1; i<DOSWINDOW_SCREENCOLS; i++)
+   {
+   	cputs(" "); // write a space
+   }
+
+   /* reset the cursor */
+   gotoxy(OldX,OldY);
+}
+//------------------------------------------------------------------------------
+bool TDOSMainMenu::SaveUnder()
+{
+	/* Saves underneath, ready to draw menu on */
+   if (SavedPortion)
+   {
+   	#ifdef DOSWINDOW_DEBUGMODE
+      	printf("DOS Windowing library: (menus) - SavedPortion already in use, SaveUnder() may have\n been called before.\n");
+      #endif
+      abort();
+   }
+   SavedPortion = new char[DOSWINDOW_SCREENCOLS*2];
+   if (!SavedPortion) return false; // heap could not be allocated
+   if (!gettext(1,1,DOSWINDOW_SCREENCOLS,1, SavedPortion))
+   	return false;
+	return true; // operation successful
+}
+//------------------------------------------------------------------------------
+void TDOSMainMenu::LoadUnder()
+{
+	/* Restores underneath and releases related heap space */
+   if (SavedPortion)
+   {
+   	puttext(1,1,DOSWINDOW_SCREENCOLS,1, SavedPortion);
+      delete[] SavedPortion;
+   }
+   else
+   {
+   	#ifdef DOSWINDOW_DEBUGMODE
+      	printf("DOS windowing library (menus): SavedPortion pointer is zero, LoadUnder() aborted\n");
+   	#endif
+      abort();
+   }
+}
+//------------------------------------------------------------------------------
+#ifndef DOSWINH
+/* |--------------------------------------------------------------|
+   | MS-DOS Window management library by David Duncan Ross Palmer |
+   | Copyright Š 1997, Abbott & Palmer Corporation                |
+   |--------------------------------------------------------------|
+   HEADER FILE TO ACCESS FUNCTIONS OF DOSMNU.CPP LIBRARY, ADD TO .CPP
+   FILES WANTING TO USE THESE WINDOWING FUNCTIONS
+
+   WARNING! Library utilizes classes and therefore requires C++
+*/
+
+#ifndef __cplusplus
+	#error DosMnu windowing library requires C++
+#endif
+
+#define DOSMNUH
+
+#define DOSWINDOW_SCREENCOLS 80
+#define DOSWINDOW_SCREENLINES 25
+
+/* Possible run-time errors */
+#include "c:\bc5\projects\shared\dos\doswl\wlerr.h"
+
+#define DOSWINDOW_DEBUGMODE
+/* Remove above line if not debugging library usage to ensure extended error
+information is not written to the .EXE file, and if the library is used incorrectly
+once removed, only the string 'Abonormal Program Termination' is printed. */
+
+/* THIS MENU SYSTEM SUPPORTS UP TO TEN MENU OPTION ON THE MAIN MENU */
+#define DOSMAINMENU_MIN 0
+#define DOSMAINMENU_MAX 9
+//------------------------------------------------------------------------------
+class TDOSMainMenu
+{
+private:
+	/* colors */
+	int InactiveColor;
+   int InactiveTextColor;
+   int ActiveColor;
+   int ActiveTextColor;
+   /* drawing system */
+   char* SavedPortion; /* will point to saved portion of underneath */
+   bool SaveUnderSwitch; /* Set by constructor, should not be modified elsewhere */
+   	bool SaveUnder(void); /* Saves text underneath effected area */
+      void LoadUnder(void); /* restores underneath, and frees memory */
+public:
+		__fastcall TDOSMainMenu(bool SaveUnderneath = false);
+      __fastcall ~TDOSMainMenu(void);
+   bool UsedEntries;
+   void* PointerToMenu;
+   	void SetInactiveColor(int);
+      void SetInactiveTextColor(int);
+      void SetActiveColor(int);
+      void SetActiveTextColor(int);
+      int GetInactiveColor(void);
+      int GetInactiveTextColor(void);
+      int GetActiveColor(void);
+      int GetActiveTextColor(void);
+      void Refresh(void); /* Usually internal, but programmer MAY use it */
+};
+//------------------------------------------------------------------------------
+#endif // (!DOSMNUH (end of header file))
+#ifndef __INC_DOSWIN_H
+/* |--------------------------------------------------------------|
+   | MS-DOS Window management library by David Duncan Ross Palmer |
+   | Copyright Š 1997, Daybo Logic        					         |
+   |--------------------------------------------------------------|
+   HEADER FILE TO ACCESS FUNCTIONS OF DOSWIN.CPP LIBRARY, ADD TO .CPP
+   FILES WANTING TO USE THESE WINDOWING FUNCTIONS
+
+   WARNING! Library utilizes classes and therefore requires C++
+*/
+
+#ifndef __cplusplus
+	#error DosWin windowing library requires C++
+#endif
+
+#define __INC_DOSWIN_H
+
+#include "DOSwl\wlerr.h" /* Possible run-time errors */
+#include "Headers\PieCrust.h" // for TAbsBase
+
+/* Define DOSWINDOW_DEBUGMODE is you want extended error
+information to be written to the .EXE file, and if the library is used incorrectly
+once removed, only the string 'Abonormal Program Termination' is printed. */
+
+#ifndef __NO_NAMESPACES__
+namespace Doswl // Part of the DOS windowing library
+{
+#endif
+	#ifdef __NO_NAMESPACES__ // Not allowed namespaces
+	class TDOSWindow : TAbsBase {
+	#else // Allowed namespaces?
+	class TDOSWindow : PieCrust::TAbsBase {
+	#endif /*__NO_NAMESPACES__*/
+	private:
+			int oldx;
+			int oldy;
+			// Above variables are used to remember coordinates and size of window so that
+			// the screen may be restored later
+			char* savedportion;
+			// Will be made to point to a buffer storing portion of screen overwritten
+			// by window
+			int BackgroundColor;
+			int ForegroundColor;
+			BOOL Visible;
+			int ScreenColumns;
+			int ScreenLines;
+			inline void ResetVisibillity(BOOL OldVisible);
+	protected:
+			int tleftx;
+			int tlefty;
+			int boxwidth;
+			int boxheight;
+	public:
+		TDOSWindow(void); // Constructor
+		~TDOSWindow(void); // Destructor
+		/* Functions for the programmer... */
+		void SetHeight(int Height);
+		int GetHeight(void);
+		void SetWidth(int Width);
+		int GetWidth(void);
+		void SetLeft(int Left);
+		int GetLeft(void);
+		void SetTop(int Top);
+		int GetTop(void);
+		void SetForegroundColor(int NewColor);
+		int GetForegroundColor(void);
+		void SetBackgroundColor(int NewColor);
+		int GetBackgroundColor(void);
+		void SetScreenColumns(int NewCols);
+		int GetScreenColumns(void);
+		void SetScreenLines(int NewLines);
+		int GetScreenLines(void);
+		virtual void Show(void); // Main show proc
+		void Hide(void); // Call if you want, but the destructor will call this if you don't
+		void MoveToCentre(void); // Based on a DOSWINDOW_SCREENCOLS * DOSWINDOW_SCREENLINES text display
+		int PutText(int Line, const char* PlainText);
+		void GotoWindowRelativeXY(int RowX, int ColY);
+		int GetExpectedWidth(const char* FutureString);
+	}; // class TDOSWindow
+#ifndef __NO_NAMESPACES__
+} // end of namespace Doswl
+#endif
+//------------------------------------------------------------------------------
+#endif // __INC_DOSWIN_H
+#ifndef __INC_PSWDLG_H
+/* |--------------------------------------------------------------|
+	| MS-DOS Window management library by David Duncan Ross Palmer |
+	| Copyright Š 1997-1999, Daybo Logic        					      |
+	|--------------------------------------------------------------|
+*/
+#ifndef __cplusplus
+	#error DOS windowing library's password dialog requires C++
+#endif // __cplusplus
+
+#define __INC_PSWDLG_H
+
+#include "DOSWL\DosWin.H" // TDOSWindow
+//------------------------------------------------------------------------------
+#ifndef __NO_NAMESPACES__
+namespace Doswl // Part of the Daybo Logic MS-DOS windowing library
+{
+#endif /*!__NO_NAMESPACES__*/
+	class TPswDlg : public TDOSWindow // Extention on a very basic window class
+	{
+	private:
+			char* _PPsw; // Password is stored as it is typed with no limit
+	public:
+			BOOL Masked; // True if asterisks mask input
+		TPswDlg(); // Constructor
+		~TPswDlg(); // Destructor
+		size_t GetPswLen(); // Returns the length of the password in the dialog, -1 is given if the password is not allocated
+		const char* GetPsw(); // Returns a pointer to the password which can be copied into caller's buffer
+		const char* SetPsw(const char* NewPsw); // Sets password in dialog
+		void Show(); // This Show() is specific to this class, it adds prompt and hands input control to 'PromptForPsw()'
+		void SecureErasePsw(); // Wipes password and releases assosiated memory, pointer is NULLed
+	protected:
+		void PromptForPsw(); // Carries on editing until the user presses [ENTER] or [ESC]
+		void RepaintPswPrompt(); // Repaints the prompt text and wipes the line of text
+	}; // end class decl 'TPswDlg'
+#ifndef __NO_NAMESPACES__
+} // end namespace 'Doswl'
+#endif /*!__NO_NAMESPACES__*/
+//------------------------------------------------------------------------------
+#endif // __INC_PSWDLG_H
+The Daybo Logic Windowing Library for consoles Version 2.0
+Copyright 1997-2003 Daybo Logic, all rights reserved.
+Written and designed by David Duncan Ross Palmer
+http://www.daybologic.co.uk/
+
+1. About this library
+2. Supported platforms and filenames
+3. Licenses
+4. About Daybo Logic (as of 20031214)
+
+
+1. About this library
+=====================
+This library has the following goals:
+   . Portable support for DOS, UNIX and Win32
+       These goals each have a compatibillity layer to reach the underlying
+       technology.  For DOS it is Borland C's conio library, for UNIX it is
+       curses or ncurses.  For Win32, it is the Daybo Logic conio->Win32
+       compatibillity library called libdlconio32.
+
+   . Reuse of common dialogs
+       Such things as standard windows which restore what was underneath them
+       when they are destroyed or moved, a password dialog and the like.
+
+when this ibrary was first created in 1997, it used very non-portable
+techniques such as Borland's pre-standard C++.  This has now all been removed
+and the library is totally written in C.  That's all I can say for now, this
+readme.txt will be updated as the project continues.  Trying to continue
+after a gap of six years with no development is quite a feat!
+
+2. Supported platforms and filenames
+====================================
+UNIX (ensure you download the package for your flavour of UNIX)
+---------------------------------------------------------------
+libdlcwl        ncurses or curses release library
+
+DOS
+---
+dlcwlbor.lib    Large memory model 16-bit DOS library for Borland C
+
+Win32
+-----
+dlcwlms6.lib    32-bit flat Microsoft Visual C++ 6, relies on libdlconio32
+dlcwl2.dll      Win32 DLL for all compilers (built with Borland)
+
+3. Licenses
+===========
+A trial version of this library is available through the internet for
+free, the commercial version can be purchased through the Daybo Logic
+website.  The file license.txt lists the full terms and conditions of
+use and details of copyright.  The source version is also sold for a
+premium and different sections of the license apply.  Please read
+license.txt for more information.
+
+4. About Daybo Logic (as of 20031214)
+=====================================
+Daybo Logic is a programming and support small business based in Cornwall,
+Great Britain.  As well as offering tools and libraries on the internet and
+for private clients, we also offer callout services for teaching the
+internet, networking and software and limited hardware support.  We have
+a totally transparent relationship with clients and we promote airing of their
+views, good or bad on our website.  Daybo Logic was a non-profit group of
+programmers until June 2003, when it officially became a company.
+#ifndef __INC_WLERR_H
+	#define __INC_WLERR_H
+   /* Header contents... */
+   #define DOSWINDOW_NOERROR 0x00
+	#define DOSWINDOW_STRING2LONG 0x01
+#endif // !__INC_WLERR_H
+/* |--------------------------------------------------------------|
+   | MS-DOS Window management library by David Duncan Ross Palmer |
+   | Copyright Š 1997-1999, Abbott & Palmer Corporation           |
+   |--------------------------------------------------------------|
+*/
+
+/* Revision 1.02 */
+//------------------------------------------------------------------------------
+#include <conio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Stds\DLStdInc.H"
+#pragma hdrstop
+
+#include "DOSwl\DosWin.h" /* This module's header */
+
+#ifndef __INC_DOSWIN_H
+	#pragma message DOS windowing library: Module should be built with DOSWIN.H
+#endif
+#ifdef DOSWINDOW_DEBUGMODE
+	#pragma message DOS windowing library: !DEBUGGING MODE DEFINED! - remove before release build by undefining DOSWINDOW_DEBUGMODE
+#endif
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+TDOSWindow::TDOSWindow(void)
+#else
+Doswl::TDOSWindow::TDOSWindow(void)
+#endif
+:	/* Initializer sequence - these are really defaults*/
+	oldx(1),
+	oldy(1),
+	tleftx(1),
+	tlefty(1),
+	boxwidth(10),
+	boxheight(5),
+	BackgroundColor(WHITE),
+	ForegroundColor(BLACK),
+	Visible(FALSE),
+	ScreenColumns(80), // The default for EGA/VGA text mode under DOS
+	ScreenLines(25) // The default for EGA/VGA text mode under DOS
+{
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+TDOSWindow::~TDOSWindow(void)
+#else
+Doswl::TDOSWindow::~TDOSWindow(void)
+#endif
+{
+	/* Destructor */
+	if (Visible)
+		Hide();
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetHeight(int Height)
+#else
+void Doswl::TDOSWindow::SetHeight(int Height)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	boxheight = Height;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetHeight(void)
+#else
+int Doswl::TDOSWindow::GetHeight(void)
+#endif
+{
+	return boxheight;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetWidth(int Width)
+#else
+void Doswl::TDOSWindow::SetWidth(int Width)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	boxwidth = Width;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetWidth(void)
+#else
+int Doswl::TDOSWindow::GetWidth(void)
+#endif
+{
+	return boxwidth;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetLeft(int Left)
+#else
+void Doswl::TDOSWindow::SetLeft(int Left)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	tleftx = Left;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetLeft(void)
+#else
+int Doswl::TDOSWindow::GetLeft(void)
+#endif
+{
+	return tleftx;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetTop(int Top)
+#else
+void Doswl::TDOSWindow::SetTop(int Top)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	tlefty = Top;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetTop(void)
+#else
+int Doswl::TDOSWindow::GetTop(void)
+#endif
+{
+	return tlefty;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetForegroundColor(int NewColor)
+#else
+void Doswl::TDOSWindow::SetForegroundColor(int NewColor)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	ForegroundColor = NewColor;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetForegroundColor(void)
+#else
+int Doswl::TDOSWindow::GetForegroundColor(void)
+#endif
+{
+	return ForegroundColor;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetBackgroundColor(int NewColor)
+#else
+void Doswl::TDOSWindow::SetBackgroundColor(int NewColor)
+#endif
+{
+	BOOL OldVisible = Visible;
+	Hide();
+	BackgroundColor = NewColor;
+	ResetVisibillity(OldVisible);
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetBackgroundColor(void)
+#else
+int Doswl::TDOSWindow::GetBackgroundColor(void)
+#endif
+{
+	return BackgroundColor;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::Show()
+#else
+void Doswl::TDOSWindow::Show()
+#endif
+{
+	if (!Visible)
+	{
+		/* This is the main show procedure */
+		int i, j;
+		// Save info about window so that screen may be restored later...
+		// ...save old cursor position
+		oldx=wherex(); oldy=wherey();
+
+		// ...save existing contents by allocating a block of memory to save it in
+		// (each character occupies 2 bytes)...
+		savedportion = new char [boxheight*boxwidth*2];
+
+		// ...and copy screen under area we're about to alter
+		gettext(tleftx, tlefty, tleftx+boxwidth-1, tlefty+boxheight-1, savedportion);
+
+		// Set up colors for window
+		textcolor(ForegroundColor);
+		textbackground(BackgroundColor);
+
+		// Put cursor at top left position of window
+		gotoxy(tleftx, tlefty);
+
+		// Draw top line
+		putch(218);	for (i=0; i<boxwidth-2; i++) putch(196);
+		putch(191);
+
+		// Vertical lines & interior
+		for (i=1; i <= boxheight-2; i++)
+		{
+			gotoxy(tleftx, tlefty+i); putch(179);
+      	for (j=1; j <= boxwidth-2; j++) putch(' ');
+			gotoxy(tleftx+boxwidth-1, tlefty+i); putch(179);
+		}
+
+		// Bottom line
+		gotoxy(tleftx, tlefty+boxheight-1);
+		putch(192); for (i=0; i<boxwidth-2; i++) putch(196); putch(217);
+
+   	Visible = TRUE;
+   } /* (!Visible) */
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::Hide(void)
+#else
+void Doswl::TDOSWindow::Hide(void)
+#endif
+{
+	if (Visible)
+	{
+		// Put saved portion of screen back on the display
+		puttext(tleftx, tlefty, tleftx+boxwidth-1, tlefty+boxheight-1, savedportion);
+
+		// Delete memory previously allocated with NEW
+		delete[] savedportion;
+
+		// Go to old cursor position
+		gotoxy(oldx, oldy);
+   	Visible = FALSE;
+   } /* (Visible) */
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+inline void TDOSWindow::ResetVisibillity(BOOL OldVisible)
+#else
+inline void Doswl::TDOSWindow::ResetVisibillity(BOOL OldVisible)
+#endif
+{
+	/* Private member function to reset visibillity status
+   after a hide to change window attributes */
+   if (OldVisible)
+   {
+   	Show();
+   }
+   /* Else the form is already hidden and we do not need to
+   call this again
+   */
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::MoveToCentre()
+#else
+void Doswl::TDOSWindow::MoveToCentre()
+#endif
+{
+	BOOL OldVisible = Visible; // Save visibillity for later restoration
+   Hide();
+   tleftx /* left */ = (ScreenColumns / 2) - (boxwidth / 2) + 1;
+   tlefty /* top */  = (ScreenLines / 2)- (boxheight / 2) + 1;
+   ResetVisibillity(OldVisible);
+   return;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::PutText(int Line, const char* PlainText)
+#else
+int Doswl::TDOSWindow::PutText(int Line, const char* PlainText)
+#endif
+{
+	/* Puts a line of text onto the dialog box at Line */
+   if (Visible)
+   {
+   	/* must verify some things first */
+      if (Line <= 0)
+      {
+      	#ifdef DOSWINDOW_DEBUGMODE
+         	printf("DOS windowing error: PutText() above window or in title row!\n");
+         #endif
+         abort();
+      }
+      if (Line >= boxheight)
+      {
+      	#ifdef DOSWINDOW_DEBUGMODE
+         	printf("DOS windowing error: PutText() below window or on lower border!\n");
+      	#endif
+         abort();
+      }
+      if (!PlainText)
+      {
+      	#ifdef DOSWINDOW_DEBUGMODE
+         	printf("DOS windowing error: PutText() bad text pointer!\n");
+         #endif
+         abort();
+      }
+      if ((int)strlen(PlainText) > boxwidth - 3) /* 1 for lborder, comfort space and rborder */
+      {
+      	return DOSWINDOW_STRING2LONG;
+      }
+
+   	/* save cursor position */
+      int PrePutX = wherex();  int PrePutY = wherey();
+      /* Set color, else window will be corrupted */
+      textcolor(ForegroundColor);
+      textbackground(BackgroundColor);
+      /* Put text on window */
+      gotoxy(tleftx /* left */ + 2,tlefty /* top */ + Line);
+      cputs(PlainText);
+      /* Return cursor to it's old position */
+      gotoxy(PrePutX,PrePutY);
+      /* END OF MAIN PUTTEXT CODE */
+   }
+   else /* (!Visible) */
+   {
+   	#ifdef DOSWINDOW_DEBUGMODE
+      	printf("DOS Windowing error: Can't put text on a hidden window!\n");
+      #endif
+      abort();
+   }
+   return DOSWINDOW_NOERROR; /* No error has occoured in routine */
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::GotoWindowRelativeXY(int RowX, int ColY)
+#else
+void Doswl::TDOSWindow::GotoWindowRelativeXY(int RowX, int ColY)
+#endif
+{
+	/* Does a gotoxy within a window */
+   /* Must test some conditions first */
+   if (RowX < 1 || RowX > boxwidth - 2 /*lborder & rborder*/)
+   {
+   	#ifdef DOSWINDOW_DEBUGMODE
+      	printf("DOS windowing error: X is not relative to window, window bounds exceeded\n");
+      #endif
+      abort();
+   }
+   if (ColY > boxheight)
+   {
+   	#ifdef DOSWINDOW_DEBUGMODE
+      	printf("DOS windowing error: Y is not relative to window, window bounds exceeded\n");
+      #endif
+      abort();
+   }
+   /* Now lets set the cursor relative to the window */
+   gotoxy(tleftx + RowX,tlefty + ColY);
+   return;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetExpectedWidth(const char* FutureString)
+#else
+int Doswl::TDOSWindow::GetExpectedWidth(const char* FutureString)
+#endif
+{
+	/* Returns the window width needed to hold the string that will
+   be displayed on it */
+   return strlen(FutureString) + 4;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetScreenColumns(int NewCols)
+#else
+void Doswl::TDOSWindow::SetScreenColumns(int NewCols)
+#endif
+{
+	if (NewCols == ScreenColumns)
+   	return; // ignore set to current value
+
+   ScreenColumns = NewCols; // Set the new value
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetScreenColumns(void)
+#else
+int Doswl::TDOSWindow::GetScreenColumns(void)
+#endif
+{
+	return ScreenColumns;
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+void TDOSWindow::SetScreenLines(int NewLines)
+#else
+void Doswl::TDOSWindow::SetScreenLines(int NewLines)
+#endif
+{
+	if (NewLines == ScreenLines)
+		return; // ignore attempt to set to current value
+
+	ScreenLines = NewLines; // set new value
+}
+//------------------------------------------------------------------------------
+#ifdef __NO_NAMESPACES__
+int TDOSWindow::GetScreenLines(void)
+#else
+int Doswl::TDOSWindow::GetScreenLines(void)
+#endif
+{
+	return ScreenLines;
+}
+//------------------------------------------------------------------------------
+#include <String.H>
+#include <ConIO.H>
+#include "Stds\DLStdInc.H" /* Daybo Logic main header */
+#pragma hdrstop
+
+#include "DOSWL\PswDlg.H"
+//------------------------------------------------------------------------------
+/* TPswDlg : This class offers a dialog with masked input for a password,
+it is based upon the most basic window class in the library (TDOSWindow)
+on which nearly every other window is based.  By inheriting from TDOSWindow
+it already has a basic way of being shown, changing position and the like from
+code, although no interaction (apart from a visual one) is taken with the user,
+there is no way to move it or size it.  A Class that is based on TDOSWindow
+which has not been made at time of writing will add these abilities.
+TPswDlg does not need any of these abilities though.  The only interaction
+with the user it must have is the single one of accepting simple typing */
+//------------------------------------------------------------------------------
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::TPswDlg() // Constructor
+:	_PPsw(0),
+	Masked(TRUE) // Input is masked by default
+{
+}
+//------------------------------------------------------------------------------
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::~TPswDlg() // Destructor
+{
+	if (_PPsw) // Password allocated in mem?
+		SecureErasePsw(); // Make sure it's gone away from evil people
+}
+//------------------------------------------------------------------------------
+size_t
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::GetPswLen()
+{
+	if (_PPsw) return strlen(_PPsw);
+	return -1;
+}
+//------------------------------------------------------------------------------
+const char*
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::GetPsw()
+{
+	return _PPsw;
+}
+//------------------------------------------------------------------------------
+const char*
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::SetPsw(const char* NewPsw)
+{
+	if (_PPsw) // Password allocated?
+		SecureErasePsw(); // Make sure it's gone
+
+	if (!NewPsw) return NULL; // Send NULL if you want deallocation like this!
+
+	// Otherwise allocate the new string
+	_PPsw = new char[strlen(NewPsw)+1]; // Allocate enough space top copy string
+	strcpy(_PPsw, NewPsw); // Copy string now
+	return _PPsw; // Return my private new pointer to the copy of the string
+}
+//------------------------------------------------------------------------------
+void
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::SecureErasePsw()
+{
+	if (_PPsw) // Password allocated? - it better be or I do nothing!
+	{
+		size_t pswlen = strlen(_PPsw); // Calculate length of password
+		for (size_t i=0;i<pswlen;i++) // All elements of password
+			_PPsw[i] = 0x0; // Zero byte in this position
+
+		delete[] _PPsw; // Dealloc password memory
+		_PPsw = NULL; // Indicates pointer no longer in use
+	}
+}
+//------------------------------------------------------------------------------
+void
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::Show() // Actually show dialog (although parent does most of this work)
+{
+	boxheight = 3; // Force client area to be one line high only
+	TDOSWindow::Show(); // Call parent for normal showing procdure
+
+	PromptForPsw(); // Prompts for password and wants input NOW!
+}
+//------------------------------------------------------------------------------
+void
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::RepaintPswPrompt()
+{
+	int oldx = wherex();
+	int oldy = wherey(); // Save old cursor co-ordinates
+	GotoWindowRelativeXY(2,1); // Only line of text here!
+	cputs("Password:"); // Put prompt label on dialog
+	gotoxy(oldx,oldy); // Restore cursor position
+}
+//------------------------------------------------------------------------------
+void
+#ifndef __NO_NAMESPACES__
+Doswl::
+#endif /*!__NO_NAMESPACES__*/
+TPswDlg::PromptForPsw()
+{
+	RepaintPswPrompt(); // Display prompt
+
+	int Length = 0; // Length of entered password now
+	char LocalPsw[48]; // Local password editing buffer
+	LocalPsw[0] = NULL; // Make sure we can see string is empty
+
+	ReadNextChar: // Label to get another char (jump to)
+	char nextchar = (char)getch(); // Read a character from the keyboard
+	if (nextchar == 0x08) // Backspace?
+	{
+		if (Length > 0) // Some to take!?
+		{
+			Length--; // One char taken away
+			LocalPsw[Length] = NULL; // Mark new end of string
+			int OldX = wherex(); // Save old cursor pos
+			int OldY = wherey();
+			GotoWindowRelativeXY(2+strlen("Password:")+1+(Length),1); // Goto * to discard
+			cputs(" "); // Space to overwrite asterisk
+			gotoxy(OldX,OldY); // Restore original cursor pos
+		}
+	}
+	else if (nextchar == 0x0d || nextchar == 0x0a) // End editing normally (ENTER)
+	{
+		SecureErasePsw(); // Get rid of current password
+		_PPsw = new char[Length+1]; // Allocate space for new password
+		strcpy(_PPsw, LocalPsw); // Save current password
+		return; // Get out of here
+	}
+	else if (nextchar == 0x1b) // [ESC]
+	{
+		SecureErasePsw(); // Get rid of current password
+		_PPsw = new char[0]; // Allocate no space!
+		char EmptyString[] = "";
+		EmptyString[0] = NULL;
+		strcpy(_PPsw, EmptyString); // Make sure string is empty
+		return; // Get out of here
+	}
+	else // Valid character
+	{
+		if (Length < 47) // Providing max has not been reached
+		{
+			Length++; // Indicate one byte longer in length
+			LocalPsw[Length] = NULL; // Indicate end of string
+			LocalPsw[Length-1] = nextchar; // Put char in string
+			// Now update the screen to allow the user to see what they have done
+			int OldX = wherex(); // Save old cursor position
+			int OldY = wherey();
+			GotoWindowRelativeXY(2+strlen("Password:")+1 + (Length-1),1); // Goto prompting position
+
+			if (Masked)
+			{
+				cputs("*"); // Put asterisk here to indicate hidden character
+			}
+			else // Not masked
+			{
+				char display[2];
+				display[0] = nextchar;
+				display[1] = NULL; // Terminate string
+				cputs(display); // Put char on display
+			}
+
+			gotoxy(OldX,OldY); // Goto original cursor position
+		}
+	}
+	goto ReadNextChar; // Get next character from user
+
+	// Can't exit here!
+}
+//------------------------------------------------------------------------------