//====================================================================== // File: laf.h // Author: Timothy P. Justice // Created: March 24, 1992 // Revised: March 29, 1993 // Description: This file contains the interface of the // classes for the Little Application Framework. // // Copyright (c) 1992 by Timothy P. Justice. All Rights Reserved. //====================================================================== #ifndef LAF_H #define LAF_H #include // Microsoft Windows interface #include // C++ standard i/o library #include // C++ standard library #include // C++ string library #include // C++ string streams // Class Hierarchy: Little Application Framework class wostream; class window; class application; class button; class editText; class staticText; class listBox; // Other Types enum streamBase { octBase, decBase, hexBase }; enum color { black, blue, green, cyan, red, magenta, brown, gray, white, brightBlue, brightGreen, brightCyan, brightRed, brightMagenta, brightYellow, brightGray }; enum lineStyle { solidLine, dashedLine, dottedLine, nullLine }; enum textAlign { leftText, centerText, rightText }; struct menuItem { char * name; int number; }; // --- Window Stream Class --------------------------------------------- // // wostream is used to simulate the behavior of C++ output // streams in a window. //---------------------------------------------------------------------- class wostream { public: wostream(window *); streamBase base() const; streamBase base(streamBase); int precision() const; int precision(int); int width() const; int width(int); window * outputWindow(); wostream & operator << (char); wostream & operator << (const char *); wostream & operator << (double); wostream & operator << (float); wostream & operator << (int); wostream & operator << (long); private: int fieldWidth; int floatPrecision; streamBase numberBase; window * winptr; }; // --- Window Class ---------------------------------------------------- // // Window is an abstract class that defines the behavior common // to all windows. //---------------------------------------------------------------------- class window { public: friend class wostream; window(); int avgCharWidth(); int bottom(); void cartesianOff(); void cartesianOn(color, lineStyle, int); void circle(const int, const int, const int); void circle(const POINT &, const int); void checkMenuItem(int); void clearAndUpdate(); virtual void command(int) = 0; virtual void create() = 0; button createButton(char *, int, int, int, int, int); editText createEditText(int, int, int, int, int, textAlign = leftText, int = 1, char * = 0); listBox createListBox(int, int, int, int, int, int = 1); staticText createStaticText(int, int, int, int, textAlign = leftText, int = 0, char * = 0); virtual void doubleClick(int, int) = 0; void gridOn(color, lineStyle, int); void gridOff(); HWND handle(); int height(); HANDLE instance(); int left(); void line(const int, const int, const int, const int); void line(const POINT &, const POINT &); virtual void mouseDown(int, int) = 0; virtual void paint() = 0; void point(const int, const int); void polygon(POINT [], int); long process(HWND, WORD, WORD, LONG); void rectangle(const int, const int, const int, const int); int right(); void scrollToBottom(); void scrollToLeft(); void scrollToRight(); void scrollToTop(); void setBrush(color); void setMaxX(int); void setMaxY(int); void setMenu(menuItem [], int); void setPen(color, lineStyle, int); void setTextPosition(int, int); int show(int); virtual void size(int, int) = 0; int textHeight(); int textWidth(char *); void textPosition(int &, int &); virtual void timer() = 0; int top(); void uncheckMenuItem(int); void update(); void vector(const int, const int, const int, const int); int width(); wostream wout; protected: void createBrush(); void createPen(); void deleteBrush(); void deletePen(); void print(const char *); COLORREF brushColor; color cartesianColor; lineStyle cartesianStyle; int cartesianWidth; int clientX; int clientY; HBRUSH currentBrush; HPEN currentPen; HDC device; color gridColor; lineStyle gridStyle; int gridWidth; HMENU hmenu; int hScrollPos; HWND hwnd; int initialHeight; int initialWidth; POINT lowerRight; int maxX; int maxY; TEXTMETRIC metric; char * name; POINT nextPos; COLORREF penColor; int penStyle; int penWidth; POINT upperLeft; int vScrollPos; HANDLE prevInstance; POINT prevPos; int tabStop[10]; HANDLE thisInstance; char * title; }; // --- Application Class ----------------------------------------------- // // Application is the basic framework class. It is a special kind // of window that is opened when the application is started. By // itself, application is not very functional. If you create an // instance of application and send it the message "run", a blank // window is displayed. The only functionality available is to // resize, move, minimize, maximize, and close the window (i.e., // terminate the application). The main work done by an application // that is visible to the user is performed by the "paint" method. // Normally, you will create a subclass of application and override // the "paint" method (and probably other methods) to perform the // processing required by your application. //---------------------------------------------------------------------- class application : public window { public: application(char *, char *, HANDLE, HANDLE, int = CW_USEDEFAULT, int = CW_USEDEFAULT); // event handling void create(); void command(int); void doubleClick(int, int); void mouseDown(int, int); void paint(); void size(int, int); void timer(); // non-event behavior int okBox(char *, char * = 0); int debugBox(char *); int run(); void quit(); void startTimer(unsigned int = 1000); void stopTimer(); void sendTimerMessage(); BOOL registerApplication(WNDCLASS *); private: int timerInterval; }; // --- Button Class ---------------------------------------------------- // // The button class implements buttons. //---------------------------------------------------------------------- class button { public: // constructors button(); button(window *, char *, int, int, int, int, int); button(const button &); // destructor ~button(); private: window * win; char * titleValue; int idValue; POINT upperLeft; int heightValue; int widthValue; HWND hwnd; }; // --- EditText Class -------------------------------------------------- // // The editText class implements fields of editable text. //---------------------------------------------------------------------- class editText { public: // constructors editText(); editText(window *, int, int, int, int, int, textAlign = leftText, int = 1, char * = 0); editText(const editText &); // destructor ~editText(); // set input focus on void setFocus(); // get the maximum number of characters int size(); // copy text to string char * text(char *); // assignment operator editText & operator = (const editText &); // text output editText & operator << (char *); editText & operator << (char); editText & operator << (int); editText & operator << (editText & (*)(editText &)); private: window * win; int idValue; POINT upperLeft; int heightValue; int widthValue; DWORD style; HWND hwnd; }; // --- Static Text Class ----------------------------------------------- // // The staticText class implements fields of fixed text. //---------------------------------------------------------------------- class staticText { public: // constructors staticText(); staticText(window *, int, int, int, int, textAlign = leftText, int = 0, char * = 0); staticText(const staticText &); // destructor ~staticText(); // assignment operator staticText & operator = (const staticText &); // equality operator int operator == (const staticText &); // text output staticText & operator << (char *); staticText & operator << (char); staticText & operator << (int); staticText & operator << (staticText & (*)(staticText &)); protected: window * win; POINT upperLeft; int heightValue; int widthValue; DWORD style; HWND hwnd; }; // --- List Box Class -------------------------------------------------- // // The listBox class implements a scrollable list of strings. //---------------------------------------------------------------------- class listBox { public: // constructors listBox(); listBox(window *, int, int, int, int, int, int = 1); listBox(const listBox &); // destructor ~listBox(); // list manipulation void clear(); const char * add(const char *); // assignment operator listBox & operator = (const listBox &); protected: window * win; int idValue; POINT upperLeft; int heightValue; int widthValue; DWORD style; HWND hwnd; }; //--- Templates -------------------------------------------------------- template T max(T x, T y) { return (x > y) ? x : y; }; template T min(T x, T y) { return (x < y) ? x : y; }; template class WO_MANIP { public: WO_MANIP(wostream & (*ff)(wostream &, T), T ii) : f(ff), i(ii) { } friend wostream & operator << (wostream & wos, WO_MANIP & m) { return (*m.f)(wos, m.i); } private: T i; wostream & (*f)(wostream &, T); }; template class WO_MANIP2 { public: WO_MANIP2(wostream & (*ff)(wostream &, T, T), T aa, T bb) : f(ff), a(aa), b(bb) { } friend wostream & operator << (wostream & wos, WO_MANIP2 & m) { return (*m.f)(wos, m.a, m.b); } private: T a; T b; wostream & (*f)(wostream &, T, T); }; //--- Function Prototypes ---------------------------------------------- editText & eraseText(editText &); staticText & eraseText(staticText &); wostream & dec(wostream &); wostream & hex(wostream &); wostream & oct(wostream &); wostream & endl(wostream &); wostream & eraseToEol(wostream &); wostream & operator << (wostream & wos, wostream & (*)(wostream &)); WO_MANIP setbase(streamBase); WO_MANIP2 setpos(int, int); WO_MANIP setprecision(int); WO_MANIP setw(int); void debugBox(); int randomInt(int, int); //--- External Variables ----------------------------------------------- extern ostrstream dout; // debug output stream #endif