home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xframe.cpp < prev    next >
C/C++ Source or Header  |  1997-09-29  |  4KB  |  207 lines

  1. #include "XFrmWnd.h"
  2. #include "XFrame.h"
  3. #include "XFrmCnt.h"
  4. #include "XScrlBar.h"
  5. #include "XRect.h"
  6.  
  7. #include <stdlib.h>
  8.  
  9.  
  10. XWindow *XFrame::QueryWindow(const ULONG id) const
  11. {
  12.     if (id == WIN_PARENT)
  13.         return frame;
  14.     else
  15.         return XWindow :: QueryWindow(id);
  16. }
  17.  
  18.  
  19. XFrame :: ~XFrame()
  20. {
  21.     SHORT i;
  22.  
  23.     for (i = 0; i < controls; i++)
  24.         delete cont[i];
  25. }
  26.  
  27.  
  28. XFrame :: XFrame(const XFrameWindow * f):XControl(f->frame)
  29. {
  30.     cont = NULL;
  31.     controls = 0;
  32.     adds = 0;
  33.     frame = (XFrameWindow *) f;
  34. }
  35.  
  36.  
  37. XFrame :: XFrame(const HWND hwnd):XControl(hwnd)
  38. {
  39.     cont = NULL;
  40.     controls = 0;
  41.     adds = 0;
  42.     frame = NULL;
  43. }
  44.  
  45.  
  46. void XFrame::AddFrameControl(XFrameControl * f)
  47. {
  48.     controls += 1;
  49.     cont = (XFrameControl **) realloc(cont, controls * sizeof(void *));
  50.  
  51.     if (f->style & TB_RIGHT || f->style & TB_LEFT)
  52.         cont[controls - 1] = f;
  53.     else
  54.     {
  55.         SHORT insert = controls - 1;
  56.  
  57.         for (int i = controls - 2; i > 0; i--)
  58.         {
  59.             BOOL swap = FALSE;
  60.  
  61.             if (cont[i]->style & TB_RIGHT || cont[i]->style & TB_LEFT)
  62.             {
  63.                 insert = i;
  64.                 swap = TRUE;
  65.             }
  66.             if (swap)
  67.                 cont[i + 1] = cont[i];
  68.         }
  69.         cont[insert] = f;
  70.     }
  71.     if (frame->dlgHandle)
  72.     {
  73.         XRect rec1;
  74.  
  75.         frame->GetSize(&rec1);
  76.         rec1.SetHeight(rec1.GetHeight() + f->cy);
  77.         frame->SetSize(&rec1);
  78.     }
  79. }
  80.  
  81.  
  82. void XFrame::RemoveFrameControl(XFrameControl * f)
  83. {
  84.     BOOL swap = FALSE, found = FALSE;
  85.  
  86.     for (int i = 0; i < controls; i++)
  87.     {
  88.         if (cont[i] == f)
  89.         {
  90.             if (i < controls)
  91.                 swap = TRUE;
  92.             found = TRUE;
  93.         }
  94.         if (swap)
  95.             cont[i] = cont[i + 1];
  96.     }
  97.     if (found)
  98.     {
  99.         controls -= 1;
  100.         cont = (XFrameControl **) realloc(cont, controls * sizeof(void *));
  101.     }
  102. }
  103.  
  104.  
  105. SHORT sly = 0;
  106. SHORT slx = 0;
  107.  
  108.  
  109. MRESULT XFrame::HandleMessage(ULONG msg, MPARAM mp1, MPARAM mp2)
  110. {
  111.     SHORT countSwp;
  112.  
  113.     switch (msg)
  114.     {
  115.       case WM_CLOSE:
  116.          return 0;
  117.       case WM_SYSCOMMAND:
  118.          {
  119.                 if(frame)
  120.             {
  121.                if(frame->DoSysCommand(SHORT1FROMMP(mp1)) == TRUE)
  122.                   return oldfunc(winhandle, msg, mp1, mp2);
  123.             }
  124.          }
  125.            return 0;
  126.     case WM_QUERYFRAMECTLCOUNT:
  127.         return MRFROMSHORT((ULONG) oldfunc(winhandle, msg, mp1, mp2) + controls + adds);
  128.     case WM_FORMATFRAME:
  129.         {
  130.             SHORT i = 0;
  131.             PSWP pswp, sav;
  132.  
  133.             if (slx == 0)
  134.             {
  135.                 sly = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
  136.                 slx = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
  137.             }
  138.  
  139.             countSwp = (int) oldfunc(winhandle, msg, mp1, mp2);
  140.  
  141.             pswp = (PSWP) mp1;
  142.             sav = &pswp[countSwp - 1];
  143.  
  144.             for (i = 0; i < controls; i++)
  145.                 cont[i]->AdjustSize(&pswp[countSwp + i], sav);
  146.  
  147.             if (frame)
  148.             {
  149.                 if (frame->vert)
  150.                 {
  151.                     sav->cx -= slx;
  152.                     SHORT y = sav->y;
  153.  
  154.                     if (frame->horz)
  155.                         y += sly;
  156.                     pswp[countSwp + i].x = sav->cx + sav->x;
  157.                     pswp[countSwp + i].cx = slx;
  158.                     pswp[countSwp + i].y = y;
  159.                     pswp[countSwp + i].cy = sav->y + sav->cy - y;
  160.                     pswp[countSwp + i].hwnd = frame->vert->winhandle;
  161.                     pswp[countSwp + i].fl = SWP_SIZE | SWP_MOVE;
  162.                     i += 1;
  163.                 }
  164.  
  165.                 if (frame->horz)
  166.                 {
  167.                     pswp[countSwp + i].x = sav->x;
  168.                     pswp[countSwp + i].cx = sav->cx;
  169.                     pswp[countSwp + i].y = sav->y;
  170.                     if (sav->cy > sly)
  171.                         pswp[countSwp + i].cy = sly;
  172.                     else
  173.                         pswp[countSwp + i].cy = sav->cy;
  174.                     pswp[countSwp + i].hwnd = frame->horz->winhandle;
  175.                     pswp[countSwp + i].fl = SWP_SIZE | SWP_MOVE;
  176.                     sav->y += pswp[countSwp + i].cy;
  177.                     sav->cy -= pswp[countSwp + i].cy;
  178.                     i++;
  179.                 }
  180.                 if (frame->dummy)
  181.                 {
  182.                     pswp[countSwp + i].x = sav->cx + sav->x;
  183.                     pswp[countSwp + i].cx = slx;
  184.                     pswp[countSwp + i].y = pswp[countSwp + i - 1].y;
  185.                     pswp[countSwp + i].cy = pswp[countSwp + i - 1].cy;
  186.                     pswp[countSwp + i].hwnd = frame->dummy;
  187.                     pswp[countSwp + i].fl = SWP_SIZE | SWP_MOVE;
  188.                     i++;
  189.                 }
  190.                 if (frame->clientWindow)
  191.                 {
  192.                     pswp[countSwp + i].x = sav->x;
  193.                     pswp[countSwp + i].cx = sav->cx;
  194.                     pswp[countSwp + i].y = sav->y;
  195.                     pswp[countSwp + i].cy = sav->cy;
  196.                     pswp[countSwp + i].hwnd = frame->clientWindow->winhandle;
  197.                     pswp[countSwp + i].fl = SWP_SIZE | SWP_MOVE;
  198.                 }
  199.             }
  200.         }
  201.         return MRFROMSHORT(countSwp + controls + adds);
  202.     default:
  203.         return (MRESULT) FALSE;
  204.     }
  205.     return (MRESULT) FALSE;
  206. }
  207.