/*
* app.h
*
* Turbo Vision - Version 2.0
*
* Copyright (c) 1994 by Borland International
* All Rights Reserved.
*
* Modified by Sergio Sigala <ssigala@globalnet.it>
*/
#if defined( Uses_TBackground ) && !defined( __TBackground )
#define __TBackground
class TRect;
/**
* The default desktop background.
*
* TBackground is a very simple view which by default is the background of the
* desktop. It is a rectangle painted with an uniform pattern.
* @see TDeskTop
* @short The default desktop background
*/
class TBackground : public TView
{
public:
/**
* Constructor.
*
* `bounds' is the bounding rectangle of the background. `aPattern'
* specifies the pattern to use.
*/
TBackground( const TRect& bounds, char aPattern );
/**
* Fills the view with the pattern.
*/
virtual void draw();
/**
* Returns a reference to the standard TBackground palette.
*/
virtual TPalette& getPalette() const;
protected:
/**
* Is the pattern used to fill the view.
*/
char pattern;
private:
virtual const char *streamableName() const
{ return name; }
protected:
/**
* Constructor.
*
* Used to recover the view from a stream.
*/
TBackground( StreamableInit );
/**
* Used to store the view in a stream.
*/
virtual void write( opstream& os );
/**
* Used to recover the view from a stream.
*/
virtual void *read( ipstream& is );
public:
static const char * const name;
/**
* Creates a new TBackground.
*
* Used to recover the view from a stream.
*/
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TBackground& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TBackground*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TBackground& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TBackground* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TBackground
#if defined( Uses_TDeskTop ) && !defined( __TDeskTop )
#define __TDeskTop
class TBackground;
class TRect;
class TEvent;
class TDeskInit
{
public:
TDeskInit( TBackground *(*cBackground)( TRect ) );
protected:
TBackground *(*createBackground)( TRect );
};
/**
* The desktop of the application.
*
* TDesktop is a simple child of TGroup. By default it has a TBackground
* object inside which paints its background. All the application windows are
* inserted and showed in this object.
* @see TApplication
* @see TGroup
* @short The desktop of the application
*/
class TDeskTop : public TGroup, public virtual TDeskInit
{
public:
/**
* Constructor.
*
* `bounds' is the bounding rectangle of the desktop.
*/
TDeskTop( const TRect& bounds );
/**
* Moves all the windows in a cascade-like fashion.
*/
void cascade( const TRect& );
/**
* Standard TGroup event handler.
*
* Calls TGroup::handleEvent() and after checks for commands cmNext and
* cmPrev.
* @see TGroup::handleEvent
*/
virtual void handleEvent( TEvent& );
/**
* Creates a new background.
*
* Returns a pointer to a newly-allocated TBackground object. Just
* redefine it if you want a custom background.
* @see TBackground
*/
static TBackground *initBackground( TRect );
/**
* Moves all the windows in a tile-like fashion.
*/
void tile( const TRect& );
/**
* Called on tiling error.
*
* This method is called whenever cascade() or tile() run into troubles in
* moving the windows. You can redefine it if you want to give an error
* message to the user.
* @see TDeskTop::cascade
* @see TDeskTop::tile
*/
virtual void tileError();
/**
* Releases TDeskTop resources.
*
* This method releases all the resources allocated by the TDeskTop. It
* sets pointer `background' to 0 and then calls TGroup::shutDown().
* @see TDeskTop::background
* @see TGroup::shutDown
*/
virtual void shutDown();
/**
* The default pattern which will be used for painting the background.
*/
static char defaultBkgrnd;
protected:
/**
* This variable stores a pointer to the background object.
*/
TBackground *background;
/**
* True if method tile() should favour columns first.
* @see TDeskTop::tile
*/
Boolean tileColumnsFirst;
private:
virtual const char *streamableName() const
{ return name; }
protected:
/**
* Constructor.
*
* Used to recover the view from a stream.
*/
TDeskTop( StreamableInit );
public:
static const char * const name;
/**
* Creates a new TDeskTop.
*
* Used to recover the view from a stream.
*/
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TDeskTop& cl )
{ return is >> (TStreamable&)(TGroup&)cl; }
inline ipstream& operator >> ( ipstream& is, TDeskTop*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TDeskTop& cl )
{ return os << (TStreamable&)(TGroup&)cl; }
inline opstream& operator << ( opstream& os, TDeskTop* cl )
{ return os << (TStreamable *)(TGroup *)cl; }
#endif
// Turbo Vision 2.0 Color Palettes
#ifndef __UNPATCHED
#define cpAppColor \
"\x71\x70\x78\x74\x20\x28\x24\x17\x1F\x1A\x31\x31\x1E\x71\x1F" \
"\x37\x3F\x3A\x13\x13\x3E\x21\x3F\x70\x7F\x7A\x13\x13\x70\x7F\x7E" \
"\x70\x7F\x7A\x13\x13\x70\x70\x7F\x7E\x20\x2B\x2F\x78\x2E\x70\x30" \
"\x3F\x3E\x1F\x2F\x1A\x20\x72\x31\x31\x30\x2F\x3E\x31\x13\x38\x00" \
"\x17\x1F\x1A\x71\x71\x1E\x17\x1F\x1E\x20\x2B\x2F\x78\x2E\x10\x30" \
"\x3F\x3E\x70\x2F\x7A\x20\x12\x31\x31\x30\x2F\x3E\x31\x13\x38\x00" \
"\x37\x3F\x3A\x13\x13\x3E\x30\x3F\x3E\x20\x2B\x2F\x78\x2E\x30\x70" \
"\x7F\x7E\x1F\x2F\x1A\x20\x32\x31\x71\x70\x2F\x7E\x71\x13\x78\x00" \
"\x37\x3F\x3A\x13\x13\x30\x3E\x1E" // help colors
#else
#define cpAppColor \
"\x71\x70\x78\x74\x20\x28\x24\x17\x1F\x1A\x31\x31\x1E\x71\x1F" \
"\x37\x3F\x3A\x13\x13\x3E\x21\x3F\x70\x7F\x7A\x13\x13\x70\x7F\x7E" \
"\x70\x7F\x7A\x13\x13\x70\x70\x7F\x7E\x20\x2B\x2F\x78\x2E\x70\x30" \
"\x3F\x3E\x1F\x2F\x1A\x20\x72\x31\x31\x30\x2F\x3E\x31\x13\x38\x00" \
"\x17\x1F\x1A\x71\x71\x1E\x17\x1F\x1E\x20\x2B\x2F\x78\x2E\x10\x30" \
"\x3F\x3E\x70\x2F\x7A\x20\x12\x31\x31\x30\x2F\x3E\x31\x13\x38\x00" \
"\x37\x3F\x3A\x13\x13\x3E\x30\x3F\x3E\x20\x2B\x2F\x78\x2E\x30\x70" \
"\x7F\x7E\x1F\x2F\x1A\x20\x32\x31\x71\x70\x2F\x7E\x71\x13\x38\x00" \
"\x37\x3F\x3A\x13\x13\x30\x3E\x1E" // help colors
#endif
#ifndef __UNPATCHED
#define cpAppBlackWhite \
"\x70\x70\x78\x7F\x07\x07\x0F\x07\x0F\x07\x70\x70\x07\x70\x0F" \
"\x07\x0F\x07\x70\x70\x07\x70\x0F\x70\x7F\x7F\x70\x07\x70\x07\x0F" \
"\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F\x07\x0F\x0F\x78\x0F\x78\x07" \
"\x0F\x0F\x0F\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07\x07\x08\x00" \
"\x07\x0F\x0F\x07\x70\x07\x07\x0F\x0F\x70\x78\x7F\x08\x7F\x08\x70" \
"\x7F\x7F\x7F\x0F\x70\x70\x07\x70\x70\x70\x07\x7F\x70\x07\x78\x00" \
"\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F\x07\x0F\x0F\x78\x0F\x78\x07" \
"\x0F\x0F\x0F\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07\x07\x08\x00" \
"\x07\x0F\x07\x70\x70\x07\x0F\x70" // help colors
#else
#define cpAppBlackWhite \
"\x70\x70\x78\x7F\x07\x07\x0F\x07\x0F\x07\x70\x70\x07\x70\x0F" \
"\x07\x0F\x07\x70\x70\x07\x70\x0F\x70\x7F\x7F\x70\x07\x70\x07\x0F" \
"\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F\x07\x0F\x0F\x78\x0F\x78\x07" \
"\x0F\x0F\x0F\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07\x07\x78\x00" \
"\x07\x0F\x0F\x07\x70\x07\x07\x0F\x0F\x70\x78\x7F\x08\x7F\x08\x70" \
"\x7F\x7F\x7F\x0F\x70\x70\x07\x70\x70\x70\x07\x7F\x70\x07\x78\x00" \
"\x70\x7F\x7F\x70\x07\x70\x70\x7F\x7F\x07\x0F\x0F\x78\x0F\x78\x07" \
"\x0F\x0F\x0F\x70\x0F\x07\x70\x70\x70\x07\x70\x0F\x07\x07\x78\x00" \
"\x07\x0F\x07\x70\x70\x07\x0F\x70" // help colors
#endif
#ifndef __UNPATCHED
#define cpAppMonochrome \
"\x70\x07\x07\x0F\x70\x70\x70\x07\x0F\x07\x70\x70\x07\x70\x00" \
"\x07\x0F\x07\x70\x70\x07\x70\x00\x70\x70\x70\x07\x07\x70\x07\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x70\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x01\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x01\x00" \
"\x07\x0F\x07\x70\x70\x07\x0F\x70" // help colors
#else
#define cpAppMonochrome \
"\x70\x07\x07\x0F\x70\x70\x70\x07\x0F\x07\x70\x70\x07\x70\x00" \
"\x07\x0F\x07\x70\x70\x07\x70\x00\x70\x70\x70\x07\x07\x70\x07\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x70\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x70\x00" \
"\x70\x70\x70\x07\x07\x70\x70\x70\x0F\x07\x07\x0F\x70\x0F\x70\x07" \
"\x0F\x0F\x07\x70\x07\x07\x70\x07\x07\x07\x70\x0F\x07\x07\x70\x00" \
"\x07\x0F\x07\x70\x70\x07\x0F\x70" // help colors
#endif
#if defined( Uses_TProgram ) && !defined( __TProgram )
#define __TProgram
// Standard application help contexts
// Note: range $FF00 - $FFFF of help contexts are reserved by Borland
const unsigned short hcNew = 0xFF01;
const unsigned short hcOpen = 0xFF02;
const unsigned short hcSave = 0xFF03;
const unsigned short hcSaveAs = 0xFF04;
const unsigned short hcSaveAll = 0xFF05;
const unsigned short hcChangeDir = 0xFF06;
const unsigned short hcDosShell = 0xFF07;
const unsigned short hcExit = 0xFF08;
const unsigned short hcUndo = 0xFF10;
const unsigned short hcCut = 0xFF11;
const unsigned short hcCopy = 0xFF12;
const unsigned short hcPaste = 0xFF13;
const unsigned short hcClear = 0xFF14;
const unsigned short hcTile = 0xFF20;
const unsigned short hcCascade = 0xFF21;
const unsigned short hcCloseAll = 0xFF22;
const unsigned short hcResize = 0xFF23;
const unsigned short hcZoom = 0xFF24;
const unsigned short hcNext = 0xFF25;
const unsigned short hcPrev = 0xFF26;
const unsigned short hcClose = 0xFF27;
class TStatusLine;
class TMenuBar;
class TDeskTop;
class TEvent;
class TView;
class TProgInit
{
public:
TProgInit( TStatusLine *(*cStatusLine)( TRect ),
TMenuBar *(*cMenuBar)( TRect ),
TDeskTop *(*cDeskTop )( TRect )
);
protected:
TStatusLine *(*createStatusLine)( TRect );
TMenuBar *(*createMenuBar)( TRect );
TDeskTop *(*createDeskTop)( TRect );
};
/* ---------------------------------------------------------------------- */
/* class TProgram */
/* */
/* Palette layout */
/* 1 = TBackground */
/* 2- 7 = TMenuView and TStatusLine */
/* 8-15 = TWindow(Blue) */
/* 16-23 = TWindow(Cyan) */
/* 24-31 = TWindow(Gray) */
/* 32-63 = TDialog */
/* ---------------------------------------------------------------------- */
const
// TApplication palette entries
int apColor = 0,
apBlackWhite = 1,
apMonochrome = 2;
class TDialog;
class TWindow;
/**
* The mother of TApplication.
*
* Every program must be inherited from TProgram or from its child
* TApplication. TApplication differs from TProgram only for its constructor
* and destructor. However most applications will be derived from
* TApplication.
* @short The mother of TApplication
* @see TApplication
*/
class TProgram : public TGroup, public virtual TProgInit
{
public:
/**
* Constructor.
*/
TProgram();
/**
* Destructor.
*/
virtual ~TProgram();
/**
* Returns True if the focus can be moved from one desktop view to another
* one.
*
* It just returns deskTop->valid(cmReleasedFocus).
* @see TGroup::valid
*/
virtual Boolean canMoveFocus();
/**
* Executes a dialog.
*
* `pD' points to the dialog. The dialog is executed only if it is valid.
* `data' is a pointer to the memory area where the dialog data will be
* read before executing the dialog and where the dialog data will be
* written after executing the dialog. If `data' is 0 no data area is
* used. This method calls TGroup::execView() to execute the dialog. The
* dialog is destroyed before returning from the function, so a call to
* delete is not necessary. executeDialog() returns cmCancel if the view
* is not valid, otherwise it returns the return value of
* TGroup::execView().
* @see TDialog::valid
* @see TGroup::execView
* @see TGroup::getData
* @see TGroup::setData
*/
virtual ushort executeDialog(TDialog* pD, void*data = 0);
/**
* Gets an event.
*
* This method collects events from the system like key events, mouse
* events and timer events and returns them in the event structure.
* @see TScreen
*/
virtual void getEvent(TEvent& event);
/**
* Returns a reference to the standard TProgram palette.
*/
virtual TPalette& getPalette() const;
/**
* Standard TProgram event handler.
*
* This method first checks for keyboard events. When it catches keys from
* Alt-1 to Alt-9 it generates an evBroadcast event with the `command'
* field equal to cmSelectWindowNum and the `infoPtr' field in the range 1
* to 9. Then it calls TGroup::handleEvent(). Last it checks for a cmQuit
* command. On success it calls TGroup::endModal(cmQuit) to end the modal
* state. This causes TProgram::run() method to return. In most
* applications this will result in program termination.
* @see TGroup::handleEvent
* @see TGroup::endModal
* @see TProgram::run
*/
virtual void handleEvent(TEvent& event);
/**
* Called when in idle state.
*
* This method is called whenever the library is in idle state, i.e. there
* is not any event to serve. The main task it does is to update the
* status line (if one exists). In the original DOS version this method
* was called continously. In my port this method is called about 10 times
* for second. This result in less CPU load. The user may redefine this
* method for example to update a clock in the upper right corner of the
* screen, like the demo program does.
*/
virtual void idle();
/**
* Initializes the screen.
*
* This method is called by the TProgram constructor. Its goal is to
* select the application palette (color, monochrome or black & white) and
* to set the shadow size. The shadows are usually painted in the right
* and bottom sides of menus and windows.
*/
virtual void initScreen();
/**
* Called on out of memory condition.
*
* It is called from TProgram::validView() whenever lowMemory() returns
* True. This happens when there is few free memory. Of course this should
* rarely happen. This method may be redefined to tell the user (by
* calling messageBox() for example) that there is not free memory to end
* the current task.
* @see TProgram::validView
* @see lowMemory
* @see messageBox
*/
virtual void outOfMemory();
/**
* Sets a pending event.
*
* Puts an event in the pending state. Only one event is allowed to be
* pending. The next call to getEvent() will return this pending event
* even if there are other events in the system queue to be handled.
* @see TProgram::pending
* @see TProgram::getEvent
*/
virtual void putEvent( TEvent& event );
/**
* Runs TProgram.
*
* Executes TProgram by calling its method execute(), which TProgram
* inherits from TGroup.
* @see TGroup::execute
*/
virtual void run();
/**
* Inserts a window in the TProgram.
*/
virtual TWindow* insertWindow(TWindow*);
/**
* Sets a new screen mode.
*
* The `mode' parameter can by one of the constants smCO80, smBW80 or
* smMono. Optionally the value may be or-ed with smFont8x8. In my port
* this method only redraws the screen.
*/
void setScreenMode( ushort mode );
/**
* Checks if a view is valid.
*
* Returns `p' if the view pointed by `p' is valid. Otherwise returns a
* null pointer.
*
* First, if `p' is 0 the call returns 0. Next, if lowMemory() returns
* True the view pointed by `p' is released by calling TObject::destroy()
* followed by outOfMemory() and the function returns 0.
*
* Last if a call to p->valid(cmValid) returns False the view pointed by
* `p' is released and the function returns 0.
*
* Otherwise the method returns the pointer `p' and the view is valid.
* @see lowMemory
* @see TObject::destroy
* @see TView::valid
*/
TView *validView( TView *p );
/**
* Releases TProgram resources.
*
* This method releases all the resources allocated by TProgram. It sets
* pointers `statusLine', `menuBar' and `deskTop' to 0 and then calls
* TGroup::shutDown() and TVMemMgr::clearSafetyPool().
* @see TGroup::shutDown
* @see TVMemMgr::clearSafetyPool
*/
virtual void shutDown();
/**
* Stops the execution of the application.
*
* This method is empty. Will be redefined in TApplication which is a
* child of TProgram.
* @see TApplication
*/
virtual void suspend() {}
/**
* Restores the execution of the application.
*
* This method is empty. Will be redefined in TApplication which is a
* child of TProgram.
* @see TApplication
*/
virtual void resume() {}
/**
* Creates a new status line.
*
* This method creates a standard TStatusLine view and returns its
* address. Most applications redefine it to have a custom status line.
* @see TStatusLine
*/
static TStatusLine *initStatusLine( TRect );
/**
* Creates a new menu bar.
*
* This method creates a standard TMenuBar view and returns its address.
* Every application should redefine it to have custom menus.
* @see TMenuBar
*/
static TMenuBar *initMenuBar( TRect );
/**
* Creates a new desktop.
*
* This method creates a standard TDeskTop view and returns its address.
* Few applications need to redefine it to have a custom desktop.
* @see TDeskTop
*/
static TDeskTop *initDeskTop( TRect );
/**
* A pointer to the current TProgram object.
*
* Only one TProgram object can exist at any time. In this way every
* object can call TProgram methods even if it does't know its name.
*/
static TProgram * application;
/**
* A pointer to the current status line view.
*
* May be 0 if none exists.
*/
static TStatusLine * statusLine;
/**
* A pointer to the current menu bar view.
*
* May be 0 if none exists.
*/
static TMenuBar * menuBar;
/**
* A pointer to the current desktop view.
*
* May be 0 if none exists.
*/
static TDeskTop * deskTop;
/**
* The current application palette.
*
* This value may be apBlackWhite, apColor or apMonoChrome. Its value is
* chosen automatically at startup by initScreen().
* @see TProgram::initScreen
*/
static int appPalette;
protected:
/**
* The current pending event.
*
* This structure contains the current pending event, if any exists. A
* maximum of one pending event may be set by calling putEvent().
* @see TProgram::putEvent
*/
static TEvent pending;
private:
static const char * exitText;
};
#endif
#if defined( Uses_TApplication ) && !defined( __TApplication )
#define __TApplication
/**
* The mother of all applications.
*
* TApplication is a shell around TProgram and differs from it mainly in
* constructor and destructor. TApplication provides the application with a
* standard menu bar, a standard desktop and a standard status bar. In any
* real application, you usually need to inherit TApplication and redefine
* some of its methods. For example to add custom menus you must redefine
* TProgram::initMenuBar(). To add a custom status line, you need to redefine
* TProgram::initStatusLine(). In the same way to add a custom desktop you
* need to redefine TProgram::initDeskTop().
* @see TProgram
* @short The mother of all applications
*/
class TApplication : public TScreen, public TProgram
{
protected:
/**
* Constructor.
*
* Initializes the basics of the library.
*/
TApplication();
/**
* Destructor.
*/
virtual ~TApplication();
public:
/**
* Stops the execution of the application.
*
* Suspends the program, used usually before temporary exit. By default
* this function is called just after the user presses Ctrl-Z to suspend
* the program.
* @see TScreen::suspend
*/
virtual void suspend();
/**
* Restores the execution of the application.
*
* Resumes the normal program execution. By default it is called after the
* user recovers the execution of the program with `fg'.
* @see TScreen::resume
*/
virtual void resume();
/**
* Gets the next event from the event queue.
*
* Simply calls TProgram::getEvent().
* @see TProgram::getEvent
*/
void getEvent(TEvent& event) { TProgram::getEvent(event); };
};
#endif
Documentation generated by sergio@athena.milk.it on Wed Feb 10 22:11:47 CET 1999