home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / BORDER.CPP < prev    next >
C/C++ Source or Header  |  1993-09-14  |  3KB  |  121 lines

  1. // -------- border.cpp
  2.  
  3. #include "desktop.h"
  4. #include "dfwindow.h"
  5.  
  6. void DFWindow::AdjustBorders()
  7. {
  8.     BorderAdj = TopBorderAdj = BottomBorderAdj = 0;
  9.     if (attrib & BORDER)
  10.         BorderAdj = TopBorderAdj = BottomBorderAdj = 1;
  11.     if (attrib & TITLEBAR)
  12.         TopBorderAdj = 1;
  13. }
  14.  
  15. void DFWindow::Title()
  16. {
  17.     if (visible && (attrib & TITLEBAR) && title != 0)    {
  18.         int wd = ClientWidth();
  19.         int tlen = min(title->Strlen(), wd-4);
  20.         String sp1((wd-tlen)/2, ' ');
  21.         String sp2(wd - (sp1.Strlen() + tlen), ' ');
  22.         String tlin = sp1 + title->left(tlen) + sp2;
  23.           int fg = BLACK;
  24.  
  25.         WriteWindowString(tlin, BorderAdj, 0, fg, CYAN);
  26.         if (attrib & CONTROLBOX)
  27.             WriteWindowChar(CONTROLBOXCHAR, 2, 0, fg, CYAN);
  28.     }
  29. }
  30.  
  31. void DFWindow::DrawBorder(BoxLines bl)
  32. {
  33.     int wd = ClientWidth();
  34.     int ht = Height() - 1;
  35.     int rt = Width() - 1;
  36.  
  37.     String topline(wd, bl.n);
  38.     String bottomline(wd, bl.s);
  39.  
  40.     // ------- top border
  41.     int fg = colors.ffg;
  42.     int bg = colors.fbg;
  43.     WriteWindowChar(bl.nw, 0,  0, fg, bg);
  44.     WriteWindowChar(bl.ne, rt, 0, fg, bg);
  45.     if (!(attrib & TITLEBAR))
  46.         WriteWindowString(topline, 1, 0, fg, bg);
  47.  
  48.     // ------ side borders
  49.     for (int y = 1; y < ht; y++)    {
  50.         WriteWindowChar(bl.w, 0, y, fg, bg);
  51.         if (!(attrib & VSCROLLBAR))
  52.             WriteWindowChar(bl.e, rt, y, fg, bg);
  53.     }
  54.  
  55.     // ----- bottom border
  56.     WriteWindowChar(bl.sw, 0,  y, fg, bg);
  57.     WriteWindowChar(bl.se, rt, y, fg, bg);
  58.     if (!(attrib & (HSCROLLBAR | STATUSBAR)))
  59.         WriteWindowString(bottomline, 1, y, fg, bg);
  60. }
  61.  
  62. static BoxLines inFocusBorder = {
  63.     FOCUS_NW,
  64.     FOCUS_LINE,
  65.     FOCUS_NE,
  66.     FOCUS_SIDE,
  67.     FOCUS_SE,
  68.     FOCUS_LINE,
  69.     FOCUS_SW,
  70.     FOCUS_SIDE
  71. };
  72.  
  73. static BoxLines outFocusBorder = {
  74.     NW,
  75.     LINE,
  76.     NE,
  77.     SIDE,
  78.     SE,
  79.     LINE,
  80.     SW,
  81.     SIDE
  82. };
  83.  
  84. void DFWindow::Border()
  85. {
  86.     if (visible)    {
  87.         if (attrib & BORDER)    {
  88.             if (DblBorder && this == desktop.InFocus())
  89.                 DrawBorder(inFocusBorder);
  90.             else
  91.                 DrawBorder(outFocusBorder);
  92.         }
  93.         Title();
  94.     }
  95. }
  96.  
  97. void DFWindow::Shadow()
  98. {
  99.     if (visible && (attrib & SHADOW))    {
  100.         int lf = Left();
  101.         int tp = Top();
  102.         int ht = Height();
  103.         int wd = Width();
  104.         int x = wd;
  105.         int c;
  106.         for (int y = 1; y < ht; y++)    {
  107.             c = desktop.screen().GetVideoChar(x+lf, y+tp);
  108.             WriteWindowChar(c, x, y, ShadowFG, ShadowBG);
  109.         }
  110.         String ln(wd, ' ');
  111.         for (x = 0; x < wd; x++)
  112.             ln[x] = desktop.screen().GetVideoChar(x+1+lf, y+tp);
  113.         int lc = ln[wd-1];    // wws will truncate ln by one char
  114.         WriteWindowString(ln, 1, y, ShadowFG, ShadowBG);
  115.         WriteWindowChar(lc, wd, y, ShadowFG, ShadowBG);
  116.     }
  117. }
  118.  
  119.  
  120.  
  121.