/*
 * system.h
 *
 * Turbo Vision - Version 2.0
 *
 * Copyright (c) 1994 by Borland International
 * All Rights Reserved.
 *
 * Modified by Sergio Sigala <ssigala@globalnet.it>
 */

#if !defined( __EVENT_CODES )
#define __EVENT_CODES

/* Event codes */

const int evMouseDown = 0x0001;
const int evMouseUp   = 0x0002;
const int evMouseMove = 0x0004;
const int evMouseAuto = 0x0008;
const int evKeyDown   = 0x0010;
const int evCommand   = 0x0100;
const int evBroadcast = 0x0200;

/* Event masks */

const int evNothing   = 0x0000;
const int evMouse     = 0x000f;
const int evKeyboard  = 0x0010;
const int evMessage   = 0xFF00;

/* Mouse button state masks */

const int mbLeftButton  = 0x01;
const int mbRightButton = 0x02;

/* Mouse event flags */

const int meMouseMoved = 0x01;
const int meDoubleClick = 0x02;

#endif  // __EVENT_CODES


#if defined( Uses_TEvent ) && !defined( __TEvent )
#define __TEvent
/**
 * Stores mouse events.
 *
 * This structure is used to give informations about mouse events.
 * @see TEvent
 * @see TEventQueue
 * @short Informations about mouse events
 */
struct MouseEventType
{
    /**
     * This is the position where the event happened.
     */
    TPoint where;
    /**
     * Helps to specify the event.
     *
     * This variable is set to meDoubleClick if a double-click event happened.
     * If the mouse is simply moved its value is meMouseMoved. Otherwise its
     * value is 0.
     */
    ulong eventFlags;           // Replacement for doubleClick.
    /**
     * Stores the status of the control keys when the event happened.
     *
     * Its value may be a bitmap of the following bits:
     *
     * kbLeftShift - left shift key was pressed
     *
     * kbRightShift - right shift key was pressed
     *
     * kbLeftCtrl - left control key was pressed
     *
     * kbRightCtrl - right control key was pressed
     *
     * kbLeftAlt - left alt key was pressed
     *
     * kbRightAlt - right alt key was pressed
     *
     * Its value is 0 if none of these keys where pressed. Warning: this
     * information is not reliable. Its value depends on your operating system
     * and libraries (gpm, ncurses). See `system.cc' for details.
     */
    ulong controlKeyState;
    /**
     * This variable reports the status of the mouse buttons when the event
     * happened.
     *
     * It is a bitmap of the following values:
     *
     * 0x01 - mbLeftButton
     *
     * 0x02 - mbRightButton
     *
     * Note: you can swap left and right buttons by setting
     * TEventQueue::mouseReverse to True.
     * @see TEventQueue
     */
    uchar buttons;
};

#ifdef __FreeBSD__
#include <machine/endian.h>
#else
#include <endian.h>
#endif

/**
 * This structure stores informations about a key.
 * @see KeyDownEvent
 * @see TEvent
 * @short Informations about a key
 */
struct CharScanType
{
#if (BYTE_ORDER == LITTLE_ENDIAN)
    /**
     * This is the character code.
     *
     * Its value is non-zero if the key has a standard code, like ASCII
     * characters. The value is zero if the key falls in the special key
     * class, like arrows, page up, etc.
     */
    uchar charCode;
    /**
     * This is the scan code.
     *
     * Its value is non-zero if the key falls in the special key class. The
     * value is zero if the key is an ASCII character.
     */
    uchar scanCode;
#elif (BYTE_ORDER == BIG_ENDIAN)
    /**
     * @internal
     */
    uchar scanCode;
    /**
     * @internal
     */
    uchar charCode;
#else
    #error architecture not supported by this library
#endif
};

/**
 * This structure stores informations about key presses.
 *
 * See `tkeys.h' for a list of keycodes.
 * @see TEvent
 * @short Informations about key presses
 */
struct KeyDownEvent
{
    union
        {
        /**
         * This is the key code.
         *
         * It is the concatenation of the scan code and the character code.
         * @see CharScanType
         */
        ushort keyCode;
        /**
         * The same as above, but splitted in its two components.
         * @see CharScanType
         */
        CharScanType charScan;
        };
    /**
     * Stores the status of the control keys when the event happened.
     *
     * Its value may be a bitmap of the following bits:
     *
     * kbLeftShift - left shift key was pressed
     *
     * kbRightShift - right shift key was pressed
     *
     * kbLeftCtrl - left control key was pressed
     *
     * kbRightCtrl - right control key was pressed
     *
     * kbLeftAlt - left alt key was pressed
     *
     * kbRightAlt - right alt key was pressed
     *
     * Its value is 0 if none of these keys where pressed. Warning: this
     * information is not reliable. Its value depends on your operating system
     * and libraries (gpm, ncurses). See `system.cc' for details.
     */
    ulong controlKeyState;
};

/**
 * This structure stores informations about message events.
 * @short Informations about message events
 * @see TEvent
 */
struct MessageEvent
{
    /**
     * Is the code of the command.
     *
     * See `views.h' for a list of standard commands. Other commands are
     * defined in `colorsel.h', `dialogs.h', `editors.h', `outline.h' and
     * `stddlg.h'.
     */
    ushort command;
    union
        {
        /**
         * A generic pointer.
         *
         * I suggest you to pay attention to these fields. Use always the same
         * type in the transmitter and in the receivers of the message.
         * Otherwise you may experiment portability problems.
         */
        void *infoPtr;
        /**
         * A signed long.
         */
        long infoLong;
        /**
         * An unsigned short.
         */
        ushort infoWord;
        /**
         * A signed short.
         */
        short infoInt;
        /**
         * An unsigned byte.
         */
        uchar infoByte;
        /**
         * A signed character.
         */
        char infoChar;
        };
};

struct TEvent
{

    ushort what;
    union
    {
        MouseEventType mouse;
        KeyDownEvent keyDown;
        MessageEvent message;
    };

};

#endif  // Uses_TEvent

#if defined( Uses_TEventQueue ) && !defined( __TEventQueue )
#define __TEventQueue

/**
 * Stores some informations about mouse.
 *
 * Other old stuff is removed.
 * @see MouseEventType
 * @short Informations about mouse
 */
class TEventQueue
{
public:
    /**
     * In this time interval button presses are recognized as double-click
     * events.
     *
     * Not used in my port. It is still here only for backward compatibility
     * (the demo uses it). See `system.cc' for details.
     */
    static ushort doubleDelay;
    /**
     * If set to True left and right mouse buttons are swapped.
     */
    static Boolean mouseReverse;
};

#endif  // Uses_TEventQueue

#if defined( Uses_TScreen ) && !defined( __TScreen )
#define __TScreen

class TDisplay
{
public:
	enum videoModes
	{
		smBW80		= 0x0002,
		smCO80		= 0x0003,
		smMono		= 0x0007,
		smFont8x8	= 0x0100
        };
};

/**
 * A low-level class used to interface to the system.
 *
 * Since this class was written by me, it is not a standard class and you
 * should not use it. Otherwise you may end with a non-portable program.
 * @short The interface to the system
 */
class TScreen: public TDisplay
{
public:
        /**
         * Constructor.
         *
         * Reads enviroment variables, acquires screen size, opens mouse and
         * screen devices, catches some useful signals and starts an interval
         * timer.
         */
	TScreen();
	/**
	 * Destructor.
	 *
	 * Releases the resources allocated by the constructor.
	 */
	~TScreen();
	/**
	 * Returns the first available event.
	 */
	static void getEvent(TEvent &event);
	/**
	 * Emits a beep.
	 */
	static void makeBeep();
	/**
	 * Puts an event in the event queue.
	 *
	 * Do not use it, use TProgram::putEvent() if you need.
	 * @see TProgram::putEvent
	 */
	static void putEvent(TEvent &event);
	/**
	 * Recovers the execution of the application.
	 *
	 * Resumes the execution of the process after the user stopped it.
	 * Called by TApplication::resume(). You should call the latter
	 * method.
	 * @see TApplication::resume
	 */
	static void resume();
	/**
	 * Stops the execution of the application.
	 *
	 * Suspends execution of the process. Called by
	 * TApplication::suspend(). You should call the latter method.
	 * @see TApplication::suspend
	 */
	static void suspend();
	/**
	 * Shows or hides the cursor.
	 *
	 * Flag `show' specifies the operation to perform.
	 */
	static void drawCursor(int show);
	/**
	 * Shows or hides the mouse pointer.
	 *
	 * Flag `show' specifies the operation to perform.
	 */
	static void drawMouse(int show);
	/**
	 * Moves the cursor to another place.
	 *
	 * Parameters `x' and `y' are 0-based.
	 */
	static void moveCursor(int x, int y);
	/**
	 * Writes a row of character & attribute pairs on the screen.
	 *
	 * `dst' is the destination position, `src' is a pointer to the source
	 * buffer and `len' is the size of the buffer expressed as the number
	 * of pairs.
	 */
	static void writeRow(int dst, ushort *src, int len);
	/**
	 * Holds the current screen mode.
	 *
	 * It is initialized by the constructor if this class. It is read by
	 * TProgram::initScreen().
	 * @see TProgram::initScreen
	 */
	static ushort screenMode;
	/**
	 * Holds the current screen width.
	 *
	 * It is initialized by the constructor of this class.
	 */
	static uchar screenWidth;
	/**
	 * Holds the current screen height.
	 *
	 * It is initialized by the constructor of this class.
	 */
	static uchar screenHeight;
	/**
	 * Holds the current screen buffer address.
	 *
	 * It is initialized by the constructor of this class.
	 */
	static ushort *screenBuffer;
};

#endif  // Uses_TScreen

Documentation generated by sergio@athena.milk.it on Wed Feb 10 22:11:47 CET 1999