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

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