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