home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / DFWINDOW.H < prev    next >
C/C++ Source or Header  |  1993-09-25  |  10KB  |  295 lines

  1. // ------------ dfwindow.h
  2.  
  3. #ifndef DFWINDOW_H
  4. #define DFWINDOW_H
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10. #include <conio.h>
  11.  
  12. #include "dflatdef.h"
  13. #include "rectangl.h"
  14. #include "strings.h"
  15. #include "family.h"
  16.  
  17. // -------- window attribute flags
  18. const int MOVEABLE   = 0x0001;
  19. const int SIZEABLE   = 0x0002;
  20. const int BORDER     = 0x0004;
  21. const int TITLEBAR   = 0x0008;
  22. const int CONTROLBOX = 0x0010;
  23. const int MINBOX     = 0x0020;
  24. const int MAXBOX     = 0x0040;
  25. const int SHADOW     = 0x0080;
  26. const int SAVESELF   = 0x0100;
  27. const int FRAMEWND   = 0x0200;
  28. const int MENUBAR    = 0x0400;
  29. const int STATUSBAR  = 0x0800;
  30. const int VSCROLLBAR = 0x1000;
  31. const int HSCROLLBAR = 0x2000;
  32. const int TOOLBAR    = 0x4000;
  33.  
  34. #if !defined(__COLORS)
  35. #define __COLORS
  36.  
  37. // --------------- Color Macros
  38. enum COLORS {
  39.     BLACK,
  40.     BLUE,
  41.     GREEN,
  42.     CYAN,
  43.     RED,
  44.     MAGENTA,
  45.     BROWN,
  46.     LIGHTGRAY,
  47.     DARKGRAY,
  48.     LIGHTBLUE,
  49.     LIGHTGREEN,
  50.     LIGHTCYAN,
  51.     LIGHTRED,
  52.     LIGHTMAGENTA,
  53.     YELLOW,
  54.     WHITE
  55. };
  56.  
  57. #endif
  58.  
  59. // ------ window shadow attributes
  60. const unsigned char ShadowFG = DARKGRAY;
  61. const unsigned char ShadowBG = BLACK;
  62.  
  63. // --------------- border characters
  64. const unsigned char FOCUS_NW   = '\xc9';
  65. const unsigned char FOCUS_NE   = '\xbb';
  66. const unsigned char FOCUS_SE   = '\xbc';
  67. const unsigned char FOCUS_SW   = '\xc8';
  68. const unsigned char FOCUS_SIDE = '\xba';
  69. const unsigned char FOCUS_LINE = '\xcd';
  70. const unsigned char NW         = '\xda';
  71. const unsigned char NE         = '\xbf';
  72. const unsigned char SE         = '\xd9';
  73. const unsigned char SW         = '\xc0';
  74. const unsigned char SIDE       = '\xb3';
  75. const unsigned char LINE       = '\xc4';
  76.  
  77. // ----------------- title bar characters
  78. const unsigned char CONTROLBOXCHAR = '\xf0';
  79. const unsigned char MAXPOINTER     = 24;
  80. const unsigned char MINPOINTER     = 25;
  81. const unsigned char RESTOREPOINTER = 18;
  82.  
  83. // ----------- window states
  84. enum WndState     {
  85.     OPEN,
  86.     CLOSING,
  87.     CLOSED
  88. };
  89.  
  90. // ---------- window colors
  91. struct Color {
  92.     COLORS fg, bg;      // standard colors
  93.     COLORS sfg, sbg;    // selected text colors
  94.     COLORS ffg, fbg;    // window frame colors
  95.     COLORS hfg, hbg;    // highlighted text colors
  96. };
  97.  
  98. class Application;
  99. class StatusBar;
  100. class PopDown;
  101.  
  102. struct BoxLines    {
  103.     int nw, n, ne, e, se, s, sw, w;
  104. };
  105.  
  106. class DFWindow    {
  107. protected:
  108.     WndType windowtype;   // window type
  109.     int prevmouseline;    // holders for
  110.     int prevmousecol;     // mouse coordinates
  111. private:
  112.     String *title;              // window title
  113.     // -------------- window attributes
  114.     int restored_attrib;        // attributes when restored
  115.     Rect restored_rc;           // restored state rect
  116.     // ----- control menu
  117.     PopDown *ctlmenu;
  118.     void DeleteCtlMenu();
  119.     // --------- common window contructor code
  120.     void InitWindow(const char *ttl,
  121.         int lf, int tp, int ht, int wd, DFWindow *par);
  122.     void InitWindow(int lf, int tp, int ht, int wd,
  123.         DFWindow *par);
  124. protected:
  125.     // -------- for clearing the window
  126.     char clearch;
  127.     // --------------- video memory save data
  128.     char *videosave;      // video save buffer
  129.     Bool visible;         // True = window has been shown
  130.     int attrib;           // Window attribute flags
  131.     Bool DblBorder;       // True = dbl border on focus
  132.     Color colors;         // window colors
  133.     WndState windowstate; // OPEN, CLOSING, CLOSED
  134.     Rect rect;            // window coordinates
  135.                           // (0/0 to 79/24)
  136.     // ------ previous capture focus handles
  137.     DFWindow *prevcapture;
  138.     DFWindow *prevfocus;
  139.     // -------- system-wide
  140.     void Enqueue();
  141.     void Dequeue();
  142.     void NextSiblingFocus();
  143.     void PrevSiblingFocus();
  144.     void WriteClientString(String &ln,int x,int y,int fg,int bg);
  145.     void WriteWindowString(String &ln,int x,int y,int fg,int bg);
  146.     void WriteWindowChar(int ch,int x,int y,int fg,int bg);
  147.     void WriteClientChar(int ch,int x,int y,int fg,int bg);
  148.     void WriteChar(int ch, int x, int y, int fg, int bg);
  149.     virtual void WriteString(String &ln, int x, int y, int fg, int bg);
  150.     void OpenCtlMenu();
  151.     // ------------- client window coordinate adjustments
  152.     virtual void AdjustBorders();
  153.     int BorderAdj;              // adjust for border
  154.     int TopBorderAdj;           // adjust for top border
  155.     int BottomBorderAdj;        // adjust for bottom border
  156.     // -----
  157.     Bool HitControlBox(int x, int y)
  158.         { return (Bool)(x-Left() == 2 && y-Top() == 0 &&
  159.             (attrib & CONTROLBOX)); }
  160.     void ChangePosition(int x, int y);
  161.     virtual void ParentSized(int, int) {}
  162. public:
  163.     // ---- window parent/children structure
  164.     Family<DFWindow> family;
  165.     // ( above must be public so can access others members )
  166.     // -------- constructors
  167.     DFWindow(const char *ttl, int lf, int tp, int ht, int wd,
  168.                 DFWindow *par = 0)
  169.         { InitWindow(ttl, lf, tp, ht, wd, par); }
  170.     DFWindow(const char *ttl, int ht, int wd, DFWindow *par = 0)
  171.         { InitWindow(ttl, -1, -1, ht, wd, par); }
  172.     DFWindow(int lf, int tp, int ht, int wd, DFWindow *par = 0)
  173.         { InitWindow(lf, tp, ht, wd, par); }
  174.     DFWindow(int ht, int wd, DFWindow *par = 0)
  175.         { InitWindow(-1, -1, ht, wd, par); }
  176.     DFWindow(const char *ttl, DFWindow *par = 0)
  177.         { InitWindow(ttl, 0, 0, -1, -1, par); }
  178.     DFWindow(DFWindow *par = 0)
  179.         { InitWindow(0, 0, -1, -1, par); }
  180.     // -------- destructor
  181.     virtual ~DFWindow()
  182.         { if (windowstate != CLOSED) CloseWindow(); }
  183.     // ------- window dimensions and position
  184.     Rect WindowRect()    { return rect; }
  185.     Rect ShadowedRect();
  186.     int Right()          { return rect.Right(); }
  187.     int Left()           { return rect.Left(); }
  188.     int Top()            { return rect.Top(); }
  189.     int Bottom()         { return rect.Bottom(); }
  190.     int Height()         { return Bottom() - Top() + 1; }
  191.     int Width()          { return Right() - Left() + 1; }
  192.     // ------ client space dimensions and position
  193.     Rect ClientRect();
  194.     int ClientRight()    { return Right()-BorderAdj; }
  195.     int ClientLeft()     { return Left()+BorderAdj; }
  196.     int ClientTop()      { return Top()+TopBorderAdj; }
  197.     int ClientBottom()   { return Bottom()-BottomBorderAdj; }
  198.     int ClientHeight()   { return Height()-TopBorderAdj-
  199.                               BottomBorderAdj; }
  200.     int ClientWidth()    { return Width()-BorderAdj*2; }
  201.  
  202.     // ---- this window's parent
  203.     DFWindow *Parent()   { return family.Parent(); }
  204.     void SetParent(DFWindow *par)  { family.SetParent(par); };
  205.     // ----- this window's children
  206.     DFWindow *First()    { return family.FirstChild(); }
  207.     DFWindow *Last()     { return family.LastChild(); }
  208.     // ----- this window's siblings
  209.     DFWindow *Next()      { return family.NextSibling(); }
  210.     DFWindow *Prev()      { return family.PrevSibling(); }
  211.     Bool isDescendedFrom(DFWindow *ancestor);
  212.  
  213.     Bool isVisible()     { return visible; }
  214.     int Attribute()      { return attrib; }
  215.     void SetAttribute(int atr)
  216.                          { attrib |= atr; AdjustBorders(); }
  217.     void ClearAttribute(int atr)
  218.                          { attrib &= ~atr; AdjustBorders(); }
  219.     WndType WindowType() { return windowtype; }
  220.     // ----- Control Menu messages
  221.     void CtlMenuMove();
  222.     void CtlMenuSize();
  223.     // -------- API messages
  224.     virtual void CloseWindow();
  225.     virtual void Show();
  226.     virtual void Hide();
  227.     virtual Bool SetFocus();
  228.     virtual void ResetFocus();
  229.     virtual void EnterFocus(DFWindow *child) {}
  230.     virtual void LeaveFocus(DFWindow *child) {}
  231.     virtual void OKFunction() {}
  232.     virtual void CancelFunction() {}
  233.     virtual void HelpFunction();
  234.     void CaptureFocus();
  235.     void ReleaseFocus();
  236.     virtual void Paint();
  237.     virtual void Paint(Rect rc);
  238.     virtual void Border();
  239.     virtual void DrawBorder(BoxLines bl);
  240.     virtual void Shadow();
  241.     virtual void Title();
  242.     virtual void SetTitle(const char *ttl);
  243.     virtual void ClearWindow();
  244.     virtual void ShiftChanged(int sk);
  245.     virtual void Keyboard(int key);
  246.     virtual void KeyReleased() {}
  247.     virtual void DoubleClick(int mx, int my);
  248.     virtual void LeftButton(int mx, int my);
  249.     virtual void ButtonReleased(int mx, int my);
  250.     virtual void MouseMoved(int mx, int my) {}
  251.     virtual void Move(int x, int y);
  252.     virtual void Size(int x, int y);
  253.     virtual void ClockTick() {}
  254.     WndState State() { return windowstate; }
  255.     void SetColor(Color clr) { colors = clr; }
  256.     Color Colors()       { return colors; }
  257.     COLORS ClientFG()    { return colors.fg; }
  258.     COLORS ClientBG()    { return colors.bg; }
  259.     COLORS SelectedFG()  { return colors.sfg; }
  260.     COLORS SelectedBG()  { return colors.sbg; }
  261.     COLORS FrameFG()     { return colors.ffg; }
  262.     COLORS FrameBG()     { return colors.fbg; }
  263.     COLORS HighlightFG() { return colors.ffg; }
  264.     COLORS HighlightBG() { return colors.fbg; }
  265.     void SetClearChar(char ch) { clearch = ch; }
  266.     virtual void ControlSelected(DFWindow *Wnd) {}
  267.     virtual void ControlChosen(DFWindow *Wnd) {}
  268. };
  269.  
  270. inline void DFWindow::WriteClientString(String &ln,
  271.                     int x,int y,int fg,int bg)
  272. {
  273.     WriteString(ln,x+ClientLeft(),y+ClientTop(),fg,bg);
  274. }
  275.  
  276. inline void DFWindow::WriteWindowString(String &ln,
  277.                     int x,int y,int fg,int bg)
  278. {
  279.     WriteString(ln,x+Left(),y+Top(),fg,bg);
  280. }
  281.  
  282. inline void DFWindow::WriteWindowChar(int ch,int x,int y,int fg,int bg)
  283. {
  284.     WriteChar(ch, x+Left(), y+Top(), fg, bg);
  285. }
  286.  
  287. inline void DFWindow::WriteClientChar(int ch,int x,int y,int fg,int bg)
  288. {
  289.     WriteChar(ch, x+ClientLeft(), y+ClientTop(), fg, bg);
  290. }
  291.  
  292. #endif
  293.  
  294.  
  295.