home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / DFPP02.ZIP / FRAME.CPP < prev    next >
C/C++ Source or Header  |  1993-08-15  |  3KB  |  153 lines

  1. // ------------- frame.cpp
  2.  
  3. #include "desktop.h"
  4. #include "frame.h"
  5.  
  6. Frame::Frame(DFWindow *par, int mx)    :
  7.     DFWindow(par->Left(), par->Top(), par->Height(), par->Width(), par)
  8. {
  9.     windowtype = FrameWindow;
  10.     SetAttribute(BORDER | SAVESELF);
  11.     DblBorder = False;
  12.     moving = (Bool) (mx != -1);
  13.     diff = moving ? mx-Left() : 0;
  14.     CaptureFocus();
  15.     minx = 0;
  16.     miny = 0;
  17.     maxx = desktop.screen().Width()-1;
  18.     maxy = desktop.screen().Height()-1;
  19.  
  20.     if (!moving)    {
  21.         minx = par->Left()+10;
  22.         miny = par->Top()+10;
  23.     }
  24.     desktop.mouse().SetTravel(minx+diff, maxx, miny, maxy);
  25. }
  26.  
  27. // -------- set the fg/bg colors for the window 
  28. void Frame::SetColors()
  29. {
  30.     colors.fg =
  31.     colors.sfg =
  32.     colors.ffg =
  33.     colors.hfg = GREEN;
  34.     colors.fbg =
  35.     colors.sbg = 
  36.     colors.bg =
  37.     colors.hbg = LIGHTGRAY;
  38. }
  39.  
  40. // ---------- display the frame
  41. void Frame::Show()
  42. {
  43.     if (!visible)    {
  44.         SetColors();
  45.         visible = True;
  46.         videosave = new char[rect.Height() * rect.Width() * 2];
  47.         desktop.screen().GetBuffer(rect, videosave);
  48.         Border();
  49.     }
  50. }
  51.  
  52. // ----------- hide the frame
  53. void Frame::Hide()
  54. {
  55.     if (visible)    {
  56.         visible = False;
  57.         desktop.screen().PutBuffer(rect, videosave);
  58.         delete videosave;
  59.         videosave = 0;
  60.     }
  61. }
  62.  
  63. void Frame::LeftButton(int, int)
  64. {
  65.     // --- intercept the left button
  66. }
  67.  
  68. void Frame::DestroyFrame()
  69. {
  70.     delete this;
  71.     desktop.mouse().SetTravel(0, desktop.screen().Width()-1, 0, desktop.screen().Height()-1);
  72. }
  73.  
  74. void Frame::CloseFrame(int lf, int tp, int rt, int bt)
  75. {
  76.     DFWindow *par = Parent();
  77.     DestroyFrame();
  78.     if (moving)    {
  79.         if (par->Left() != lf || par->Top() != tp)
  80.             par->Move(lf, tp);
  81.     }
  82.     else if (par->Right() != rt || par->Bottom() != bt)
  83.         par->Size(rt, bt);
  84. }
  85.  
  86. void Frame::ButtonReleased(int, int)
  87. {
  88.     CloseFrame(Left(), Top(), Right(), Bottom());
  89. }
  90.  
  91. void Frame::MouseMoved(int mx, int my)
  92. {
  93.     if (mx != prevmousecol || my != prevmouseline)    {
  94.         if (moving)
  95.             Move(mx-diff, my);
  96.         else
  97.             Size(mx, my);
  98.     }
  99. }
  100.  
  101. void Frame::Keyboard(int key)
  102. {
  103.     int lf = Left();
  104.     int tp = Top();
  105.     int rt = Right();
  106.     int bt = Bottom();
  107.     switch (key)    {
  108.         case ESC:
  109.             DestroyFrame();
  110.             break;
  111.         case '\r':
  112.             CloseFrame(Left(), Top(), Right(), Bottom());
  113.             break;
  114.         case FWD:
  115.             if (moving)    {
  116.                 if (lf < maxx)
  117.                     Move(lf+1, tp);
  118.             }
  119.             else
  120.                 if (rt < maxx)
  121.                     Size(rt+1, bt);
  122.             break;
  123.         case BS:
  124.             if (moving)    {
  125.                 if (lf > minx)
  126.                     Move(lf-1, tp);
  127.             }
  128.             else if (rt > minx)
  129.                 Size(rt-1, bt);
  130.             break;
  131.         case UP:
  132.             if (moving)    {
  133.                 if (tp > miny)
  134.                     Move(lf, tp-1);
  135.             }
  136.             else if (bt > miny)
  137.                 Size(rt, bt-1);
  138.             break;
  139.         case DN:
  140.             if (moving)    {
  141.                 if (tp < maxy)
  142.                     Move(lf, tp+1);
  143.             }
  144.             else if (bt < maxy)
  145.                 Size(rt, bt+1);
  146.             break;
  147.         default:
  148.             break;
  149.     }
  150. }
  151.  
  152.  
  153.