home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / spmio10.zip / gcc2 / stdwin / framectl.cc < prev    next >
C/C++ Source or Header  |  1994-06-05  |  4KB  |  116 lines

  1.  
  2. #include "framectl.h"
  3.  
  4. FrameControl::FrameControl ()
  5. : mode (frmctl_mode_normal),
  6.   resize_lockout (0)
  7. {
  8. }
  9.  
  10. void FrameControl::set_behavior_normal ()
  11. {
  12.   mode = frmctl_mode_normal;
  13. }
  14.  
  15. void FrameControl::set_exact_size (int awidth, int aheight)
  16. {
  17.   width = awidth;
  18.   height = aheight;
  19.   mode = frmctl_mode_absolute;
  20. }
  21.  
  22.  
  23. void FrameControl::framemsg_windowposchanged (SWP *swp, unsigned flags)
  24. {
  25.   switch (mode)
  26.     {
  27.     case frmctl_mode_absolute:
  28.       if (swp->fl & SWP_SIZE)
  29.     {
  30.       // Calc the current size of the frame rectangle
  31.       RECTL rectl;
  32.       rectl.xLeft = swp->x;
  33.       rectl.yBottom = swp->y;
  34.       rectl.xRight = rectl.xLeft + swp->cx;
  35.       rectl.yTop = rectl.yBottom + swp->cy;
  36.       // Then convert this size into a client rectangle size
  37.       WinCalcFrameRect (frame, &rectl, TRUE);
  38.       // If the current client size is wrong, correct the problem
  39.       if (rectl.xRight - rectl.xLeft != width
  40.           || rectl.yTop - rectl.yBottom != height)
  41.         {
  42.           // Otherwise, alter the client rectangle into a shape that
  43.           // does have the correct dimensions
  44.           rectl.xRight = rectl.xLeft + width;
  45.           rectl.yBottom = rectl.yTop - height;
  46.           // Then calculate the frame rectangle that corresponds to such
  47.           // a client rectangle
  48.           WinCalcFrameRect (frame, &rectl, FALSE);
  49.           // Then reconfigure the frame into the desired shape
  50.           WinSetWindowPos (frame, 0,
  51.                    rectl.xLeft, rectl.yBottom,
  52.                    rectl.xRight - rectl.xLeft,
  53.                    rectl.yTop - rectl.yBottom,
  54.                    SWP_SIZE | SWP_MOVE);
  55.           resize_lockout = 1;
  56.           return;
  57.         }
  58.     }
  59.       inherited::framemsg_windowposchanged (swp, flags);
  60.       resize_lockout = 1;
  61.       return;
  62.     case frmctl_mode_normal:
  63.       break;
  64.     }
  65.   inherited::framemsg_windowposchanged (swp, flags);
  66. }
  67.  
  68. int FrameControl::framemsg_querytrackinfo (unsigned short flags,
  69.                        TRACKINFO *trackinfo)
  70. {
  71.   int ret;
  72.   switch (mode)
  73.     {
  74.     case frmctl_mode_absolute:
  75.       // Let the default routine perform the calculation
  76.       ret = inherited::framemsg_querytrackinfo (flags, trackinfo);
  77.       // If the default routine fails, punt
  78.       if (ret == 0)
  79.     return ret;
  80.       // If resize lockout has not yet been activated, don't do anything
  81.       // extra
  82.       if (!resize_lockout)
  83.     return ret;
  84.       // Get the frame rectangle
  85.       RECTL rectl = trackinfo->rclTrack;
  86.       // Convert the rectangle into a client rectangle
  87.       WinCalcFrameRect (frame, &rectl, TRUE);
  88.       // Calculate the width and height of both rectangles
  89.       int frame_width = trackinfo->rclTrack.xRight - trackinfo->rclTrack.xLeft;
  90.       int frame_height= trackinfo->rclTrack.yTop - trackinfo->rclTrack.yBottom;
  91.       int client_width = rectl.xRight - rectl.xLeft;
  92.       int client_height = rectl.yTop - rectl.yBottom;
  93.       // Calculate how much extra space the frame is using up above and
  94.       // beyond what the client needs
  95.       int extra_width = frame_width - client_width;
  96.       int extra_height = frame_height - client_height;
  97.       // Constrain all resize operations so that they leave the client
  98.       // with the required fixed dimensions
  99.       trackinfo->ptlMinTrackSize.x = trackinfo->ptlMaxTrackSize.x
  100.     = width + extra_width;
  101.       trackinfo->ptlMinTrackSize.y = trackinfo->ptlMaxTrackSize.y
  102.     = height + extra_height;
  103.       return ret;
  104.     case frmctl_mode_normal:
  105.       break;
  106.     }
  107.   return inherited::framemsg_querytrackinfo (flags, trackinfo);
  108. }
  109.  
  110. void FrameControl::attach (HWND aframe)
  111. {
  112.   inherited::attach (aframe);
  113.   screen_width = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  114.   screen_height = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  115. }
  116.