Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : WINDOW.HPP

Output of file : WINDOW.HPP contained in archive : DOSUIT07.ZIP

// Basic Window class.
// Drawing in a Window translates coordinates to screen coords.
#ifndef WINDOW_HPP
#define WINDOW_HPP

#ifndef GROUP_HPP
#include "group.hpp"

extern ColorSet defaultColors; // Used when no specific colors specified.

class ClipRectangle/*!*/;
class GStackClipRectangle/*!*/;

Basic output window.
All drawing on the screen is done through a Window - each VObject (except
Window itself) retains a pointer to its Window so that it can draw itself.
All coordinates of VObjects in a Window are translated to screen
coordinates by the Window.
class Window : public Group {
Window(const char *n,const ColorSet &c = defaultColors);
color currentColor;

Window(VObject *contents = 0,AlignFlag a = AFHexpand|AFVexpand,
const ColorSet &c = defaultColors,const char *n = "Window");
// The AlignFlag is used to align the Window on the Screen automatically.
Window(const coord l,const coord t,const coord r,const coord b,
VObject *v = 0,const ColorSet &c = defaultColors,
const char *n = "Window");
// The exact dimensions are specified.

void setcolors(const ColorSet &c) // Change colors.
{ colors = c; currentColor = c.colors[getcolor()]; dirty(); }
void setCurrentColor(color c) { currentColor = c; }
color getCurrentColor() const { return currentColor; }
void setCurrentColorFromState(int state)
{ if(state >= 0) currentColor = colors.colors[state]; }

virtual void contentsDeleted(VObject* v);
// Method called by objects inside this one if they are deleted.

//~Manipulate Windows in Application
void enter();
// Pops the Window up as the top Window in the Application. Events will
// not be passed to other Windows underneath this one, until this
// Window is removed (a modal window).
void show();
// Adds the Window to the Application (a non-modal window).
void removeWindow();
// Remove the Window from the Application.

//~Set which VObject gets unwanted keyboard input
// The currently active object will be passed all keyboard input that
// is not wanted by the focussed object. This is used for default
// buttons (see CloseButton).
void setactive(VObject *v);
void clearactive(VObject *v);

//~Can we close this window ?
// Attempt to close or cancel this Window. If close or cancel is not
// permitted (e.g. if something is not filled in correctly), this
// method should return 0. Otherwise it should call the Window method,
// which creates a new CloseEvent for the Window.
virtual int closeok();
virtual int cancelok();

void scroll(Rectangle r,int color,int nlines = 1);
// Scroll part of the Window
// Set nlines = 0 to clear
// Set nlines < 0 to scroll down instead of up
// If part of the area is not visible, this will merely dirty the rectangle

//~Print a string.
void printstring(Point at,const Rectangle &clip,int color,
const char *s,int length = -1);
// Print a string, clipping it to the supplied Rectangle. The color is
// used as an offset into the ColorSet for the Window. The default
// length (-1) indicates the whole string is to be printed (up to the C
// '\0' terminator).
void printstring(const Point &at,int color,const char *s,
int length = -1);
// The clipping Rectangle is the whole Screen.
void printstring(const Point &at,const char *s,int length = -1)
{ printstring(at,getcolor(),s,length); }
// Uses the appropriate color for the current state of the Window.

//~Fill a Rectangle with a character.
void fillrect(Rectangle r,int color,const char x);
// Again, color is used as an offset into the ColorSet for the Window.
void fillrect(const Rectangle& r,const char x = ' ')
{ fillrect(r,getcolor(),x); }
// Use the appropriate color for the current state of the Window.

//~Clear whole window to a particular character.
void clear(int color,const char x = ' ');
void clear(const char x = ' ') { clear(getcolor(),x); }

//~Draw a box.
void drawbox(const Rectangle& r,const Rectangle &clip,int color,
const BorderFlag s,const char *title = "");
// Draw a box, clipping it to the supplied Rectangle. The color is used
// as an offset into the ColorSet for the Window. The BorderFlag
// determines the style of the box.
void drawbox(const Rectangle& r,int color,const BorderFlag s,
const char *title = "")
// The clipping Rectangle is the box itself.
{ drawbox(r,r,color,s,title); }
void drawbox(const Rectangle& r,const BorderFlag s = BFsingle)
{ drawbox(r,r,getcolor(),s); }
// Uses the appropriate color for the current state of the Window.

//~Move text cursor to a point.
void cursor(coord x,coord y);
void cursor(const Point& p) { cursor(p.x,p.y); }

//~Show and hide text cursor.
void showcursor(int block = 0);
// Set block non-sero to get a block (insert) cursor (the default is an
// underline cursor).
void hidecursor();

//~Move whole window.
virtual void move(coord x,coord y);

//~Draw the Window.
virtual void paint(Rectangle r);

//~Translate Window coordinates to Screen coordinates.
void screenCoords(Point &p) const { p += topleft(); }
void screenCoords(Rectangle &r) const { r.move(topleft()); }

//~Translate Screen coordinates to Window coordinates.
void windowCoords(Point &p) const { p -= topleft(); }
void windowCoords(Rectangle &r) const { r.move(-topleft().x,-topleft().y); }

//~Handle keyboard input.
virtual int kbdevent(KeyboardEvent& e);
// The Window deals with passing unwanted input to the active VObject
// (if any), and enabling the Tab and BackTab keys to pass the focus
// between tabstop items.
virtual char *inspectinfo(char *buffer = 0,const char *s = 0) const/*!*/;
Point cursorpt; // Cursor
ColorSet colors;
VObject *actfocus; // This item gets unwanted keyboard input

enum Visibility /*!*/ { Error = -1, Visible = 0, Hidden = 1 };
// Test to see if a Rectangle is visible or hidden by other Windows
int visible(const Rectangle &r) const;

// Set up cliplist to contain list of ClipRectangles exactly covering
// the visible part of Rectangle clip.
void startclip(Rectangle& clip) const;

// Take a ClipRectangle from a Window underneath this one, and make a list
// of ClipRectangles which are not hidden by this Window
void split(GStackClipRectangle& list,ClipRectangle& clip) const;

// Once cliplist has been set up (by a call to startclip),
// return successive visible ClipRectangles - 0 at the end.
// User is responsible for deleting ClipRectangles returned.
ClipRectangle *cliprect() const;