home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xfrmwnd.cpp < prev    next >
C/C++ Source or Header  |  1998-04-23  |  51KB  |  1,596 lines

  1. #include "XFrmwnd.h"
  2. #include "xexcept.h"
  3. #include "XResLib.h"
  4. #include "XMsgBox.h"
  5. #include "XRes.h"
  6. #include "XRect.h"
  7. #include "XString.h"
  8. #include "XFrame.h"
  9. #include "XColor.h"
  10. #include "XCombo.H"
  11. #include "XMLE.h"
  12. #include "XSlider.h"
  13. #include "xapp.h"
  14. #include "XEntry.h"
  15. #include "XCheckBx.h"
  16. #include "XPushBtn.h"
  17. #include "XScrlBar.h"
  18. #include "XSpinBtn.h"
  19. #include "XListBox.h"
  20. #include "XCircSld.h"
  21. #include "XGroupBx.h"
  22. #include "XSBitmap.h"
  23. #include "XSIcon.h"
  24. #include "XSText.h"
  25. #include "XSFrame.h"
  26. #include "XValuSet.h"
  27. #include "XIcon.h"
  28. #include "XRadio.h"
  29. #include "XMenuBar.h"
  30. #include "XContain.h"
  31. #include "XProcess.h"
  32. #include "Xcntrevn.h"
  33. #include "XMedia.h"
  34. #include "XTimer.h"
  35. #include "XDragHdl.h"
  36. #include "XDragEvn.h"
  37. #include "XMousHdl.h"
  38. #include "XMousevn.h"
  39. #include "XWindow.h"
  40. #include "XContHdl.h"
  41. #include "XItmDHdl.h"
  42. #include "XBackHdl.h"
  43. #include "XStylHdl.h"
  44. #include "XdefHdl.h"
  45. #include "XTimer.h"
  46. #include "XScrlWnd.h"
  47. #include "XCntEvnt.h"
  48. #include "XCnEdEvn.h"
  49. #include "XCndrEvn.h"
  50. #include "xkeyevnt.h"
  51. #include "xkeybhdl.h"
  52. #include "XItmDEvn.h"
  53. #include "XBackEvn.h"
  54. #include "XNoteBk.h"
  55. #include "xnbevent.h"
  56. #include "xnbhdlr.h"
  57. #include "xcontobj.h"
  58. #include "xcontcol.h"
  59. #include "xlayout.h"
  60. #include "xdragtra.h"
  61. #include "xcolcont.h"
  62.  
  63. #include <stdlib.h>
  64. #include <string.h>
  65.  
  66. LONG MAXX = 0;
  67. LONG MAXY;
  68. SHORT cxDlgFrame;
  69. SHORT cyDlgFrame;
  70. SHORT cxBorder;
  71. SHORT cyBorder;
  72. SHORT cxSizeBorder;
  73. SHORT cySizeBorder;
  74.  
  75.  
  76. MRESULT HandleDefault(XWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled)
  77. {
  78.    handled = TRUE;
  79.  
  80.    switch (msg)
  81.    {
  82.       case 0x0601:
  83.       {
  84.          HWND hwnd;
  85.          char className[50];
  86.          HENUM enumWindow = WinBeginEnumWindows(w->GetHandle());
  87.          while ((hwnd = WinGetNextWindow(enumWindow)) != 0)
  88.          {
  89.             WinQueryClassName(hwnd, 50, (PCH) className);
  90.             if(strcmp(className, "ColorSelectClass") == 0)
  91.             {
  92.                XColorControl * x = (XColorControl *) WinQueryWindowULong(hwnd, QWL_USER+4);
  93.                x->color = (ULONG) mp1;
  94.                x->ColorSelected((ULONG) mp1);
  95.                return 0;
  96.             } /* end if */
  97.          };
  98.       }
  99.       break;
  100. //      case DM_DRAGERROR:
  101.       case DM_RENDER:
  102.       case DM_RENDERFILE:
  103.       case DM_RENDERPREPARE:
  104.       case DM_RENDERCOMPLETE:
  105.          {
  106.             for (int i = 0; i < w->handlers; i++)
  107.             {
  108.                if (w->regHandlers[i]->GetID() == OOL_DRAGHANDLER)
  109.                {
  110.                   XDragTransfer dev((PDRAGTRANSFER) mp1, msg, (ULONG) SHORT1FROMMP(mp2));
  111.                   handled = ((XDragHandler *) w->regHandlers[i])->HandleRenderEvent(&dev);
  112.                   return (MRESULT) handled;
  113.                }
  114.             }
  115.          }
  116.          return 0;
  117.    case WM_TIMER:
  118.       {
  119.          handled = FALSE;
  120.          for (int i = 0; i < w->handlers; i++)
  121.          {
  122.             if (w->regHandlers[i]->GetID() == OOL_TIMER)
  123.             {
  124.                if (((XTimer *) w->regHandlers[i])->timerID == SHORT1FROMMP(mp1))
  125.                {
  126.                   ((XTimer *) w->regHandlers[i])->TimerEvent();
  127.                   handled = TRUE;
  128.                   return (MRESULT) handled;
  129.                }
  130.             }
  131.          }
  132.       }
  133.       break;
  134.    case WM_HELP:
  135.       if (SHORT1FROMMR(WinSendMsg(WinQueryHelpInstance(w->winhandle), HM_DISPLAY_HELP, MPFROM2SHORT(WinQueryWindowUShort(WinQueryFocus(HWND_DESKTOP), QWS_ID), NULL), MPFROMSHORT(HM_RESOURCEID))) != 0)
  136.       {
  137.          if ((LONG) mp1 > 0)
  138.          {
  139.             if (SHORT1FROMMR(WinSendMsg(WinQueryHelpInstance(w->winhandle), HM_DISPLAY_HELP, mp1, MPFROMSHORT(HM_RESOURCEID))) != 0)
  140.                WinSendMsg(WinQueryHelpInstance(w->winhandle), HM_DISPLAY_HELP, MPFROM2SHORT(WinQueryWindowUShort(WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT), QWS_ID), NULL), MPFROMSHORT(HM_RESOURCEID));
  141.          }
  142.          else
  143.             WinSendMsg(WinQueryHelpInstance(w->winhandle), HM_DISPLAY_HELP, MPFROM2SHORT(WinQueryWindowUShort(WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT), QWS_ID), NULL), MPFROMSHORT(HM_RESOURCEID));
  144.       }
  145.       return 0;
  146.    case WM_CONTROL:
  147.       switch (SHORT2FROMMP(mp1))
  148.       {
  149.          case CN_REALLOCPSZ:
  150.          {
  151.             CNREDITDATA * cnEdit = (CNREDITDATA *) mp2;
  152.             if( cnEdit->pRecord && cnEdit->pFieldInfo == NULL)
  153.             {
  154.                RECORDCORE *pr = (RECORDCORE *) ((PBYTE) cnEdit->pRecord + sizeof(RECORDCORE));
  155.                XContainerObject *obj;
  156.                memcpy(&obj, pr, 4);
  157.                XString dummy;
  158.                dummy.GetBuffer( cnEdit->cbText +1 );
  159.                dummy.ReleaseBuffer(cnEdit->cbText);
  160.                for(int i = 0; i < cnEdit->cbText; i++)
  161.                   dummy[i] = ' ';
  162.                dummy[cnEdit->cbText] = 0;
  163.                obj->SetTitle( dummy );
  164.                return (MRESULT) TRUE;
  165.             }
  166.             else if( cnEdit->pRecord && cnEdit->pFieldInfo )
  167.             {
  168.                RECORDCORE *pr = (RECORDCORE *) ((PBYTE) cnEdit->pRecord + sizeof(RECORDCORE));
  169.                XContainerObject *obj;
  170.                memcpy(&obj, pr, 4);
  171.                XContainerColumn * col = (XContainerColumn *) cnEdit->pFieldInfo->pUserData;
  172.                return (MRESULT) obj->AllocMemory( (char*) *cnEdit->ppszText, cnEdit->cbText, col );
  173.             }
  174.             else if( cnEdit->pFieldInfo == NULL && cnEdit->pRecord == NULL && cnEdit->id == CID_CNRTITLEWND)
  175.             {
  176.                XContainerControl * cont = (XContainerControl *) WinQueryWindowULong( cnEdit->hwndCnr, 0);
  177.                cont->title.GetBuffer( cnEdit->cbText +1 );
  178.                cont->title.ReleaseBuffer(cnEdit->cbText);
  179.                for(int i = 0; i < cnEdit->cbText; i++)
  180.                   cont->title[i] = ' ';
  181.                cont->title[cnEdit->cbText] = 0;
  182.                return (MRESULT) TRUE;
  183.             }
  184.             else if( cnEdit->pFieldInfo && cnEdit->pRecord == NULL && (cnEdit->id == CID_LEFTCOLTITLEWND ||  cnEdit->id == CID_RIGHTCOLTITLEWND))
  185.             {
  186.                XContainerColumn * col = (XContainerColumn *) cnEdit->pFieldInfo->pUserData;
  187.                col->title.GetBuffer( cnEdit->cbText +1 );
  188.                col->title.ReleaseBuffer(cnEdit->cbText);
  189.                for(int i = 0; i < cnEdit->cbText; i++)
  190.                   col->title[i] = ' ';
  191.                col->title[cnEdit->cbText] = 0;
  192.                return (MRESULT) TRUE;
  193.             }
  194.          }
  195.          break;
  196.          case CN_ENDEDIT:
  197.          {
  198.             CNREDITDATA * cnEdit = (CNREDITDATA *) mp2;
  199.             if( cnEdit->pFieldInfo == NULL && cnEdit->pRecord )
  200.             {
  201.                RECORDCORE *pr = (RECORDCORE *) ((PBYTE) cnEdit->pRecord + sizeof(RECORDCORE));
  202.                XContainerObject *obj;
  203.                memcpy(&obj, pr, 4);
  204.                obj->TitleEdited( (char*) *cnEdit->ppszText );
  205.                return (MRESULT) TRUE;
  206.             }
  207.             else if( cnEdit->pFieldInfo && cnEdit->pRecord )
  208.             {
  209.                RECORDCORE *pr = (RECORDCORE *) ((PBYTE) cnEdit->pRecord + sizeof(RECORDCORE));
  210.                XContainerObject *obj;
  211.                memcpy(&obj, pr, 4);
  212.                XContainerColumn * col = (XContainerColumn *) cnEdit->pFieldInfo->pUserData;
  213.                obj->TitleEdited( (char*) *cnEdit->ppszText, col );
  214.                return (MRESULT) TRUE;
  215.             }
  216.             else if( cnEdit->pFieldInfo == NULL && cnEdit->pRecord == NULL && cnEdit->id == CID_CNRTITLEWND)
  217.             {
  218.                XContainerControl * cont = (XContainerControl *) WinQueryWindowULong( cnEdit->hwndCnr, 0);
  219.                cont->TitleEdited( cont->title );
  220.                return (MRESULT) TRUE;
  221.             }
  222.             else if( cnEdit->pFieldInfo && cnEdit->pRecord == NULL && (cnEdit->id == CID_LEFTCOLTITLEWND ||  cnEdit->id == CID_RIGHTCOLTITLEWND))
  223.             {
  224.                XContainerColumn * col = (XContainerColumn *) cnEdit->pFieldInfo->pUserData;
  225.                col->TitleEdited( col->title );
  226.                return (MRESULT) TRUE;
  227.             }
  228.          }
  229.          break;
  230.          case CN_SCROLL:
  231.          {
  232.             PNOTIFYSCROLL scroll = (PNOTIFYSCROLL) mp2;
  233.             XContainerControl *x = (XContainerControl*) WinQueryWindowPtr(WinWindowFromID(w->GetHandle(), SHORT1FROMMP(mp1)), 0);
  234.             if( scroll->fScroll & CMA_VERTICAL )
  235.                x->DoVScroll(scroll->lScrollInc);
  236.             else
  237.                x->DoHScroll(scroll->lScrollInc);
  238.             return 0;
  239.          }
  240.          case CN_BEGINEDIT:
  241.          case CN_ENTER:
  242.          case CN_CONTEXTMENU:
  243.          case CN_DRAGOVER:
  244.          case CN_INITDRAG:
  245.          case CN_DROP:
  246.          case CN_EMPHASIS:
  247.          {
  248.             SHORT i, ms = SHORT2FROMMP(mp1);
  249.             XWindow *x = (XWindow *) WinQueryWindowPtr(WinWindowFromID(w->GetHandle(), SHORT1FROMMP(mp1)), 0);
  250.  
  251.             if (!x)
  252.                break;
  253.  
  254.             for (i = 0; i < x->handlers; i++)
  255.             {
  256.                if (x->regHandlers[i]->GetID() == OOL_CONTAINERHANDLER)
  257.                {
  258.                   if (ms == CN_DRAGOVER || ms == CN_DROP)
  259.                   {
  260.                      XContainerDragEvent dev(x, mp1, mp2);
  261.  
  262.                      ((XContainerHandler *) x->regHandlers[i])->HandleEvent(&dev);
  263.                      return MRFROM2SHORT(dev.accept, dev.operation);
  264.                   }
  265.                   else if (ms == CN_BEGINEDIT)// || ms == CN_ENDEDIT || ms == CN_REALLOCPSZ)
  266.                   {
  267.                      XContainerEditEvent dev(x, mp1, mp2);
  268.                      if (((XContainerHandler *) x->regHandlers[i])->HandleEvent(&dev) == TRUE)
  269.                         handled = TRUE;
  270.                      else
  271.                         handled = FALSE;
  272.                      return (MRESULT) 0;
  273. /*
  274.                      if( ms == CN_REALLOCPSZ )
  275.                      {
  276.                        return (MRESULT) handled;
  277.                      else
  278.                        return (MRESULT) 0;
  279. */
  280.                   }
  281.                   else
  282.                   {
  283.                      XContainerEvent dev((XContainerControl *) x, mp1, mp2);
  284.  
  285.                      if (((XContainerHandler *) x->regHandlers[i])->HandleEvent(&dev) == TRUE)
  286.                         handled = TRUE;
  287.                      return 0;
  288.                   }
  289.                }
  290.             }
  291.          }
  292.          break;
  293.  
  294.       case XNOTEBOOK_PAGESELECTED:
  295.       case XNOTEBOOK_PAGESELECTEDPENDING:
  296.       case XNOTEBOOK_HELP:
  297.       case XNOTEBOOK_PAGEDELETED:
  298.       case XNOTEBOOK_NEWPAGESIZE:
  299.       {
  300.             handled = FALSE;
  301.             for (int i = 0; i < w->handlers; i++)
  302.             {
  303.                if (w->regHandlers[i]->GetID() == OOL_NOTEBOOKHANDLER)
  304.                {
  305.                   XNoteBookEvent e(w, (void*) mp1, (void*) mp2);
  306.                   if (((XNoteBookHandler *) w->regHandlers[i])->HandleEvent(&e) == TRUE)
  307.                      handled = TRUE;
  308.                }
  309.             }
  310.             return (MRESULT) handled;
  311.       }
  312.       break;
  313.       default:
  314.          {
  315.             XControlEvent e(w, mp1, mp2);
  316.             handled = FALSE;
  317.          }
  318.       }
  319.       return (MRESULT) handled;
  320.    case WM_DRAWITEM:
  321.       {
  322.          handled = FALSE;
  323.          SHORT i;
  324.          POWNERITEM o = (POWNERITEM) mp2;
  325.          XWindow *x = (XWindow *) WinQueryWindowPtr(o->hwnd, 0);
  326.  
  327.          if (x == 0)
  328.          {
  329.             HWND hwnd = WinQueryWindow(o->hwnd, QW_OWNER);
  330.  
  331.             while (hwnd)
  332.             {
  333.                x = (XWindow *) WinQueryWindowPtr(hwnd, 0);
  334.                if (x)
  335.                   break;
  336.                hwnd = WinQueryWindow(hwnd, QW_OWNER);
  337.             }
  338.             if (x == 0)
  339.                break;
  340.          }
  341.          for (i = 0; i < x->handlers; i++)
  342.          {
  343.             if (x->regHandlers[i]->GetID() == OOL_ITMDRAWHANDLER)
  344.             {
  345.                XItemDrawEvent dev(msg, mp1, mp2, ((XItemDrawHandler *) x->regHandlers[i])->type);
  346.                if (((XItemDrawHandler *) x->regHandlers[i])->HandleEvent(&dev) == TRUE)
  347.                {
  348.                   handled = TRUE;
  349.                   return (MRESULT) TRUE;
  350.                }
  351.             }
  352.          }
  353.       }
  354.       break;
  355.    case WM_COMMAND:
  356.       if (w->DoCommand(SHORT1FROMMP(mp1)) == FALSE)
  357.          handled = FALSE;
  358.       return 0;
  359.    case WM_PRESPARAMCHANGED:
  360.       {
  361.          handled = FALSE;
  362.          for (int i = 0; i < w->handlers; i++)
  363.          {
  364.             if (w->regHandlers[i]->GetID() == OOL_STYLEHANDLER)
  365.             {
  366.                XEvent evn((LONG) mp1);
  367.  
  368.                if (((XStyleHandler *) w->regHandlers[i])->HandleEvent(&evn) == TRUE)
  369.                   handled = TRUE;
  370.                return (MRESULT) handled;
  371.             }
  372.          }
  373.       }
  374.       break;
  375.    case CM_PAINTBACKGROUND:
  376.       {
  377.          handled = FALSE;
  378.          for (int i = 0; i < w->handlers; i++)
  379.          {
  380.             if (w->regHandlers[i]->GetID() == OOL_BACKDRAWHANDLER)
  381.             {
  382.                XBackgroundDrawEvent dev(msg, mp1);
  383.  
  384.                if (((XBackgroundDrawHandler *) w->regHandlers[i])->HandleEvent(&dev) == TRUE)
  385.                   handled = TRUE;
  386.                return (MRESULT) handled;
  387.             }
  388.          }
  389.       }
  390.       return (MRESULT) FALSE;
  391.    case WM_BUTTON1DOWN:
  392.    case WM_BUTTON1DBLCLK:
  393.    case WM_BUTTON1CLICK:
  394.    case WM_BUTTON1UP:
  395.    case WM_BUTTON2DOWN:
  396.    case WM_BUTTON2DBLCLK:
  397.    case WM_BUTTON2CLICK:
  398.    case WM_BUTTON2UP:
  399.    case WM_BUTTON3DOWN:
  400.    case WM_BUTTON3DBLCLK:
  401.    case WM_BUTTON3CLICK:
  402.    case WM_BUTTON3UP:
  403.    case WM_BEGINDRAG:
  404.    case WM_MOUSEMOVE:
  405.    case MOU_ENTER:
  406.    case MOU_EXIT:
  407.       {
  408.          handled = FALSE;
  409.          for (int i = 0; i < w->handlers; i++)
  410.          {
  411.             if (w->regHandlers[i]->GetID() == OOL_MOUSEHANDLER)
  412.             {
  413.                XMouseEvent dev(msg, mp1, mp2);
  414.  
  415.                if((handled = ((XMouseHandler *) w->regHandlers[i])->HandleEvent(&dev)) == TRUE)
  416.                   return (MRESULT) handled;
  417.             }
  418.          }
  419.       }
  420.       break;
  421.  
  422.    case WM_CHAR:
  423.       {
  424.          handled = FALSE;
  425.          for (int i = 0; i < w->handlers; i++)
  426.          {
  427.             if (w->regHandlers[i]->GetID() == OOL_KEYBHANDLER)
  428.             {
  429.                XKeyboardEvent dev(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), CHAR4FROMMP(mp1), SHORT1FROMMP(mp1));
  430.                if (((XKeyboardHandler *) w->regHandlers[i])->HandleEvent(&dev) == TRUE)
  431.                {
  432.                   handled = TRUE;
  433.                   return (MRESULT) TRUE;
  434.                }
  435.             }
  436.          }
  437.       }
  438.       break;
  439.    case DM_DISCARDOBJECT:
  440.    case DM_PRINTOBJECT:
  441.    case DM_ENDCONVERSATION:
  442.       {
  443.          char className[5];
  444.  
  445.          WinQueryClassName(w->GetHandle(), 5, (PCH) className);
  446.          className[0] = ' ';
  447.          SHORT classtype = atol(className);
  448.          XContainerControl *cd = NULL;
  449.  
  450.          if (classtype == 37)
  451.          {
  452.             if (!(w))
  453.                return (MRESULT) FALSE;
  454.          }
  455.          for (int i = 0; i < w->handlers; i++)
  456.          {
  457.             if (w->regHandlers[i]->GetID() == OOL_DRAGHANDLER)
  458.             {
  459.                XDragEvent dev(msg, mp1);
  460.  
  461.                if (msg == DM_PRINTOBJECT)
  462.                   dev.printer = (PPRINTDEST) mp2;
  463.                ((XDragHandler *) w->regHandlers[i])->HandleEvent(&dev);
  464.                return MRFROM2SHORT(dev.accept, dev.operation);
  465.             }
  466.             if (w->regHandlers[i]->GetID() == OOL_CONTAINERHANDLER)
  467.             {
  468.                cd = (XContainerControl *) ((XContainerHandler *) w->regHandlers[i])->GetWindow();
  469.                if (msg == DM_DISCARDOBJECT || msg == DM_PRINTOBJECT)
  470.                {
  471.                   XContainerDragEvent dev(cd, NULL, NULL);
  472.  
  473.                   dev.dragInfo = (PDRAGINFO) mp1;
  474.                   dev.window = cd;
  475.                   dev.windowID = WinQueryWindowUShort(cd->GetHandle(), QWS_ID);
  476.                   dev.eventID = msg;
  477.                   if (msg == DM_PRINTOBJECT)
  478.                      dev.printer = (PPRINTDEST) mp2;
  479.                   ((XContainerHandler *) w->regHandlers[i])->HandleEvent(&dev);
  480.                }
  481.                else
  482.                {
  483.                   XContainerEvent dev(cd, mp1, mp2);
  484.  
  485.                   dev.eventID = msg;
  486.                   handled = TRUE;
  487.                   return (MRESULT) ((XContainerHandler *) w->regHandlers[i])->HandleEvent(&dev);
  488.                }
  489.             }
  490.          }
  491.       }
  492.       return (MRESULT) FALSE;
  493.    case DM_DROP:
  494.    case DM_DRAGOVER:
  495.       {
  496.          for (int i = 0; i < w->handlers; i++)
  497.          {
  498.             if (w->regHandlers[i]->GetID() == OOL_DRAGHANDLER)
  499.             {
  500.                XDragEvent dev(msg, mp1);
  501.  
  502.                ((XDragHandler *) w->regHandlers[i])->HandleEvent(&dev);
  503.                return MRFROM2SHORT(dev.accept, dev.operation);
  504.             }
  505.          }
  506.          handled = FALSE;
  507.       }
  508.       return (MRESULT) FALSE;
  509.    case WM_MOVE:
  510.       handled = FALSE;
  511.       w->DoMove();
  512.       break;
  513.    case WM_SIZE:
  514.       {
  515.          XSize s(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  516.          for (int i = 0; i < w->handlers; i++)
  517.          {
  518.             if (w->regHandlers[i]->GetID() == OOL_LAYOUTHANDLER)
  519.             {
  520.                ((XLayout *) w->regHandlers[i])->Arrange(&s);
  521.                return 0;
  522.             } /* end if */
  523.          }
  524.          w->DoSize( &s);
  525.          handled = FALSE;
  526.       }
  527.       return 0;
  528.    case WM_DESTROY:
  529.       return 0;
  530.    case WM_PAINT:
  531.       w->Draw();
  532.       handled = FALSE;
  533.       break;
  534.    case WM_MEASUREITEM:
  535.       {
  536.          handled = FALSE;
  537.          XWindow *x;
  538.          HWND hwnd = WinWindowFromID(w->GetHandle(), (ULONG) SHORT1FROMMP(mp1));
  539.  
  540.          if (hwnd)
  541.             return 0;
  542.  
  543.          POWNERITEM o = (POWNERITEM) mp2;
  544.  
  545.          x = (XWindow *) WinQueryWindowPtr(o->hwnd, 0);
  546.          if (x == 0)
  547.          {
  548.             hwnd = WinQueryWindow(o->hwnd, QW_OWNER);
  549.             while (hwnd)
  550.             {
  551.                x = (XWindow *) WinQueryWindowPtr(hwnd, 0);
  552.                if (x)
  553.                   break;
  554.                hwnd = WinQueryWindow(hwnd, QW_OWNER);
  555.             }
  556.             if (x == 0)
  557.                break;
  558.          }
  559.          for (int i = 0; i < x->handlers; i++)
  560.          {
  561.             if (x->regHandlers[i]->GetID() == OOL_ITMDRAWHANDLER)
  562.             {
  563.                XItemDrawHandler *d = (XItemDrawHandler *) x->regHandlers[i];
  564.  
  565.                handled = TRUE;
  566.                o->rclItem.yTop = d->height;
  567.                o->rclItem.xRight = d->width;
  568.                return MRFROM2SHORT(d->width, d->height);
  569.             }
  570.          }
  571.       }
  572.       break;
  573.    case MEDIA_NOTIFY:
  574.       {
  575.          XControlEvent evn(SHORT2FROMMP(mp1));
  576.          w->DoControl(&evn);
  577.       }
  578.       return 0;
  579.    default:
  580.       {
  581.          handled = FALSE;
  582.          for (int i = 0; i < w->handlers; i++)
  583.          {
  584.             if (w->regHandlers[i]->GetID() == OOL_DEFAULTHANDLER)
  585.             {
  586.                LONG retVal = 0;
  587.                if(((XDefaultHandler *) w->regHandlers[i])->HandleEvent(msg, mp1, mp2, &retVal) == TRUE)
  588.                {
  589.                   handled = TRUE;
  590.                   return (MRESULT) retVal;
  591.                } /* end if */
  592.             }
  593.          }
  594.       }
  595.       handled = FALSE;
  596.       break;
  597.    }
  598.    return (MRESULT) FALSE;
  599. }
  600.  
  601.  
  602. MRESULT HandleFrameDefault(XFrameWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled)
  603. {
  604.    handled = TRUE;
  605.  
  606.    switch (msg)
  607.    {
  608.       case WM_COMMAND:
  609.          handled = TRUE;
  610.          w->DoCommand(SHORT1FROMMP(mp1));
  611.          return 0;
  612.       case WM_INITMENU:
  613.       {
  614. //         XMenu *menu = (XMenu *) WinQueryWindowPtr((HWND) mp2, 0);
  615.  
  616.          w->InitMenu(w->GetMenu());//
  617.          handled = FALSE;
  618.       }
  619.       return 0;
  620.    case WM_CLOSE:
  621.       {
  622.          handled= TRUE;
  623.          if (w->QueryForClose() == TRUE)
  624.             delete w;
  625.       }
  626.       return 0;
  627.    case WM_FOCUSCHANGE:
  628.       {
  629.          MRESULT res;
  630.          res = WinDefWindowProc( w->winhandle, msg, mp1, mp2);
  631.          w->FocusChanged( SHORT1FROMMP(mp2) );
  632.          handled = FALSE;
  633.          return res;
  634.       }
  635.       break;
  636.    case WM_SIZE:
  637.       {
  638.          handled = TRUE;
  639.          if( w->dlgHandle == 0)
  640.             WinDefWindowProc( w->GetHandle(), msg, mp1, mp2);
  641.          else
  642.          {
  643.             WinDefDlgProc( w->GetHandle(), msg, mp1, mp2);
  644.             WinSetWindowPos(w->dlgHandle, 0, 0, 0, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SWP_SIZE);
  645.          }
  646.          XSize s(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
  647.          for (int i = 0; i < w->handlers; i++)
  648.          {
  649.             if (w->regHandlers[i]->GetID() == OOL_LAYOUTHANDLER)
  650.                ((XLayout *) w->regHandlers[i])->Arrange(&s);
  651.          }
  652.          w->DoSize( &s);
  653.       }
  654.       return 0;
  655.    }
  656.    return HandleDefault(w, msg, mp1, mp2, handled);
  657. }
  658.  
  659.  
  660. MRESULT EXPENTRY WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  661. {
  662.    XFrameWindow *w;
  663.  
  664.    if (msg == WM_CREATE)
  665.    {
  666. //      WinSetWindowPtr(hwnd, 0, (void *) mp1);
  667. //      mp1 = NULL;
  668.       return WinDefWindowProc(hwnd, msg, mp1, mp2);
  669.    }
  670.    else
  671.       w = (XFrameWindow *) WinQueryWindowPtr(hwnd, 0);
  672.  
  673.    if (w )
  674.    {
  675.       if (w->enabled == FALSE && msg != WM_PAINT && msg != WM_CONTROLPOINTER && msg != WM_DRAWITEM && msg != WM_ERASEBACKGROUND && msg != WM_QUERYBORDERSIZE)
  676.          return 0;
  677.  
  678.       BOOL handeld = FALSE;
  679.       MRESULT mr = HandleFrameDefault(w, msg, mp1, mp2, handeld);
  680.       if (handeld)
  681.          return mr;
  682.    }
  683.    return WinDefWindowProc(hwnd, msg, mp1, mp2);
  684. }
  685.  
  686.  
  687. MRESULT EXPENTRY DProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  688. {
  689.    XFrameWindow * w = (XFrameWindow *) WinQueryWindowPtr(hwnd, 0);
  690.  
  691.    if (w)
  692.    {
  693.       if (w->enabled == FALSE && msg != WM_PAINT && msg != WM_CONTROLPOINTER && msg != WM_DRAWITEM && msg != WM_ERASEBACKGROUND && msg != WM_QUERYBORDERSIZE && msg != WM_HELP)   // && msg != WM_CONTROL)
  694.          return 0;
  695.       BOOL handeld = FALSE;
  696.       if(msg == WM_FOCUSCHANGE)
  697.       {
  698.          MRESULT res = WinDefDlgProc( hwnd, msg, mp1, mp2);
  699.          w->FocusChanged( SHORT1FROMMP(mp2) );
  700.          return res;
  701.       }
  702.  
  703.       MRESULT mr = HandleFrameDefault(w, msg, mp1, mp2, handeld);
  704.  
  705.       if (handeld)
  706.          return mr;
  707.    }
  708.    return WinDefDlgProc(hwnd, msg, mp1, mp2);
  709. }
  710.  
  711.  
  712. /*@
  713. @class XFrameWindow
  714. @parent XWindow
  715. @type overview
  716. @symbol _
  717. @remarks XFrameWindow is a window class which has a child and a frame. It supports menus and toolbars.
  718. */
  719.  
  720.  
  721. /*@ XFrameWindow::Activate(void)
  722. @group display a window
  723. @remarks Activate the window
  724. */
  725. void XFrameWindow::Activate(void) const
  726. {
  727.    WinSetActiveWindow(HWND_DESKTOP, frame);
  728. }
  729.  
  730. /*@ XFrameWindow::Minimize(void)
  731. @group display a window
  732. @remarks Minimize the window
  733. */
  734. void XFrameWindow::Minimize(void) const
  735. {
  736.    WinSetWindowPos( frame, HWND_TOP, 0,0,0,0,SWP_MINIMIZE);
  737. }
  738.  
  739. /*@ XFrameWindow::Maximize(void)
  740. @group display a window
  741. @remarks Maximize the window
  742. */
  743. void XFrameWindow::Maximize(void) const
  744. {
  745.    WinSetWindowPos( frame, HWND_TOP, 0,0,0,0,SWP_MAXIMIZE);
  746. }
  747.  
  748. /*@ XFrameWindow::Restore(void)
  749. @group display a window
  750. @remarks Restores the window if it is maximized or minimized
  751. */
  752. void XFrameWindow::Restore(void) const
  753. {
  754.    WinSetWindowPos( frame, HWND_TOP, 0,0,0,0,SWP_RESTORE);
  755. }
  756.  
  757. /*@ XFrameWindow :: ~XFrameWindow()
  758. @group constructors/destructors
  759. @remarks Destructors of windows are called automaticaly when the window is closed.
  760. The destructor of XFrameWindow calles the destructor of every client window, menus and
  761. toolbars. Also the destructors of handlers (derived classes of XHandler) which are
  762. attached with it are called. If the last XFrameWindow of a process is closed, the process
  763. will terminate.<BR>
  764. If you want to close a window yourself, destruct the window with delete.
  765. */
  766. XFrameWindow :: ~XFrameWindow()
  767. {
  768.    HWND hwnd;
  769.    HENUM enumWindow;
  770.  
  771.    if( sEntry )
  772.       WinRemoveSwitchEntry(sEntry);
  773.  
  774.    if (lockingWin)
  775.    {
  776.       lockingWin->enabled = TRUE;
  777.       lockingWin->Enable();
  778.       lockingWin = NULL;
  779.    }
  780.  
  781.    WinSetWindowPtr(frameWin->winhandle, 0, NULL);
  782.    WinSetWindowPtr(winhandle, 0, NULL);
  783.  
  784.    hwnd = WinWindowFromID(frame, FID_MENU);
  785.    XMenuBar *m = (XMenuBar *) WinQueryWindowPtr(hwnd, 0);
  786.  
  787.    if (m)
  788.       delete m;
  789.  
  790.    if (dlgHandle)
  791.    {
  792.       enumWindow = WinBeginEnumWindows(dlgHandle);
  793.       while ((hwnd = WinGetNextWindow(enumWindow)) != 0)
  794.       {
  795.          XWindow *w = (XWindow *) WinQueryWindowPtr(hwnd, 0);
  796.  
  797.          if (w)
  798.             delete w;
  799.       };
  800.       WinEndEnumWindows(enumWindow);
  801.       WinDismissDlg(dlgHandle, 1);
  802.       WinDestroyWindow(dlgHandle);
  803.    }
  804.  
  805.    enumWindow = WinBeginEnumWindows(winhandle);
  806.    char str[5];
  807.  
  808.    while ((hwnd = WinGetNextWindow(enumWindow)) != NULLHANDLE)
  809.    {
  810.       XWindow *w = (XWindow *) WinQueryWindowPtr(hwnd, 0);
  811.  
  812.       if (w && w != this)
  813.       {
  814.          WinQueryClassName(hwnd, 5, (PCH) str);
  815.          if (strcmp(str, "#1") == 0)
  816.          {
  817.             XFrame *f = (XFrame *) w;
  818.             if(f)
  819.             {
  820. /*               if (f->frame)
  821.                   delete f->frame;
  822.                else */
  823.                   delete f;
  824.             } /* end if */
  825.          }
  826.          else
  827.             delete w;
  828.       }
  829.    }
  830.    WinEndEnumWindows(enumWindow);
  831.  
  832. //   XApplication *p = (XApplication *) WinQueryWindowULong(winhandle, 4);
  833.  
  834.    XApplication::GetApplication()->RemoveWindow(this);      // test
  835.  
  836.    delete frameWin;
  837.  
  838.    if (clientWindow)
  839.       delete clientWindow;
  840.  
  841.    WinDestroyWindow(frame);
  842. }
  843.  
  844.  
  845. /*@ XFrameWindow::ShowModal(XFrameWindow * w)
  846. @group display a window
  847. @remarks ShowModal displays a window modal for another window which is specified in the first parameter,
  848. that means that the user cannot perform any input with the specified window.
  849. WARNING: you should only use this function for windows which are constructed with a resource template!
  850. If you do so the operating system stops with executing the calling code until the window is closed,
  851. otherwise the calling code is executed while the window is displayed.
  852. @parameters XFrameWindow * theOwnerWindow   the window which is disabled until this window is closed
  853. */
  854. void XFrameWindow::ShowModal(XFrameWindow * w)
  855. {
  856.    if (!w)
  857.       return;
  858.  
  859.    lockingWin = w;
  860.    w->enabled = FALSE;
  861.    w->Enable(FALSE);
  862.  
  863.    if (dlgHandle)
  864.       WinProcessDlg(dlgHandle);
  865. }
  866.  
  867.  
  868. /*@ XFrameWindow::InitMenu()
  869. @group display a window
  870. @remarks If a menu must be initialized this function is called. If you
  871. want to setup the menu dynamicaly, override this function.
  872. @parameters   XMenu * theMenu
  873. */
  874.  
  875.  
  876. /*@ XFrameWindow::GetHandle()
  877. @group misc
  878. @remarks GetHandle returns the window-handle defined by the operating system. The handle is different
  879. from the ID of the window and the pointers used by the OOL. In XFrameWindow the function returns:
  880. <OL COMPACT>
  881. <LI>if you have set a client window with function XFrameWindow::SetClient() the handle of the client
  882. <LI>if the XFrameWindow displays a resource-defined window, the resource window handle is returned
  883. <LI>on default, the handle of the client-rect is returned
  884. </OL>
  885. @returns       OOL_WINDOWHANDLE  theSystemHandle
  886. */
  887. OOL_WINDOWHANDLE XFrameWindow::GetHandle() const
  888. {
  889.    if (clientWindow)
  890.       return clientWindow->winhandle;
  891.    return dlgHandle ? dlgHandle : winhandle;
  892. }
  893.  
  894.  
  895. /*@ XFrameWindow::Enable(const BOOL enable)
  896. @group display a window
  897. @remarks Enables/disables a window for user-input
  898. @parameters  BOOL enable  enables/disables the window (default is TRUE)
  899. */
  900. void XFrameWindow::Enable(const BOOL enable)
  901. {
  902.    WinEnableWindow(frame, enable);
  903. }
  904.  
  905.  
  906. /*@ XFrameWindow::EnableWindowUpdate(const BOOL enable)
  907. @group drawing a window
  908. @remarks This function can stop drawing the window contents until you allow drawing.
  909. For complex windows there can be some performance-advantages.<BR>
  910. <B>WARNING:</B> If you disable drawing of a window and attach a XToolBar to it, the position
  911. and size of the toolbar can not set correctly.
  912. @parameters    BOOL enable    enable/disable window drawing (default is TRUE)
  913. */
  914. void XFrameWindow::EnableWindowUpdate(const BOOL enable) const
  915. {
  916.    WinEnableWindowUpdate(winhandle, enable);
  917. }
  918.  
  919.  
  920. /*@ XFrameWindow::FillBackground(void)
  921. @group drawing a window
  922. @remarks FillBackground fills the background in the color you have set with
  923. SetBackgroundColor (default is black). Usualy you call this function when
  924. you have overridden XFrameWindow::Draw(). You don∩t have to call this function if a resource defined
  925. window is displayed or a window is set as client with XFrameWindow::SetClient().
  926. */
  927. void XFrameWindow::FillBackground(void)
  928. {
  929.    RECTL rec;
  930.    HPS hps = WinBeginPaint(winhandle, NULLHANDLE, &rec);
  931.  
  932.    GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0, 1, &backCol);
  933.    WinFillRect(hps, &rec, (LONG) backCol);
  934.    WinEndPaint(hps);
  935. }
  936.  
  937.  
  938. /*@ XFrameWindow::SetBackgroundColor(const XColor * col)
  939. @group colors
  940. @remarks With this function you set the color wich is used to fill the
  941. background in XFrameWindow::FillBackground(). Default color is black. If you change
  942. background color, you should do this before you start to insert
  943. client-windows.
  944. @parameters XColor * theNewColor
  945. */
  946. BOOL XFrameWindow::SetBackgroundColor(const XColor * col)
  947. {
  948.    backCol = col->GetColor();
  949.    if (dlgHandle)
  950.       WinSetPresParam(dlgHandle, PP_BACKGROUNDCOLOR, 4, &backCol);
  951.    return TRUE;
  952. }
  953.  
  954.  
  955. void XFrameWindow::GetBackgroundColor(XColor * rgb) const
  956. {
  957.    if (dlgHandle)
  958.    {
  959.       LONG c;
  960.  
  961.       WinQueryPresParam(dlgHandle, PP_BACKGROUNDCOLOR, 0, NULL, 4, &c, QPF_PURERGBCOLOR);
  962.       rgb->SetColor(c);
  963.    }
  964.    else
  965.       rgb->SetColor(backCol);
  966. }
  967.  
  968. /*@ XFrameWindow::GetText(XString * buffer)
  969. @group text functions
  970. @remarks Query the title of the window
  971. @parameters    XString * theBuffer       theBuffer will contain the title of the window
  972. */
  973. void XFrameWindow::GetText(XString * buffer) const
  974. {
  975.    SHORT r = WinQueryWindowTextLength(frame);
  976.  
  977.    r = WinQueryWindowText(frame, r + 1, (PCH) buffer->GetBuffer(r + 1));
  978.    buffer->ReleaseBuffer(r);
  979. }
  980.  
  981.  
  982. /*@ XFrameWindow::SetBottom(void)
  983. @group size/position/order
  984. @remarks Set the window to the bottom (in z-order)
  985. */
  986. void XFrameWindow::SetBottom(void) const
  987. {
  988.    WinSetWindowPos(frame, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
  989. }
  990.  
  991.  
  992. /*@ XFrameWindow::SetIcon(const XIcon * icon)
  993. @group misc
  994. @remarks Set the icon which is displayed in the button of the system menu.
  995. @parameters    OOL_ICONHANDLE theNewIcon
  996. */
  997. void XFrameWindow::SetIcon(const XIcon * icon)
  998. {
  999.    WinSendMsg(frame, WM_SETICON, MPFROMP(icon->GetHandle()), 0);
  1000. }
  1001.  
  1002.  
  1003. /*@ XFrameWindow::SetText(const char *buffer)
  1004. @group text functions
  1005. @remarks Set the Text which is displayed in the titlebar
  1006. @parameters    char * theNewText
  1007. */
  1008. void XFrameWindow::SetText(const char *buffer)
  1009. {
  1010.    if( sEntry )
  1011.    {
  1012.       SWCNTRL switchEntry;
  1013.       WinQuerySwitchEntry( sEntry, &switchEntry );
  1014.       XString bu = buffer;
  1015.       if( bu.GetLength() > MAXNAMEL )
  1016.          bu = bu.Left( MAXNAMEL );
  1017.       strncpy( switchEntry.szSwtitle, (char*) bu, bu.GetLength() + 1);
  1018.       WinChangeSwitchEntry( sEntry, &switchEntry );
  1019.    }
  1020.    WinSetWindowText(frame, (PSZ) buffer);
  1021. }
  1022.  
  1023.  
  1024. /*@ XFrameWindow::SetTop(void)
  1025. @group size/position/order
  1026. @remarks Set the window to the top (in z-order)
  1027. */
  1028. void XFrameWindow::SetTop(void) const
  1029. {
  1030.    WinSetWindowPos(frame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
  1031. }
  1032.  
  1033.  
  1034. /*@ XFrameWindow::Show(const BOOL show)
  1035. @group size/position/order
  1036. @remarks Displayes a window. The window wil be activated an be shown at the topmost position
  1037. (in z-order). If the window is minimized the old position and size will be restored.
  1038. @parameters BOOL show            TRUE=show, FALSE=hide
  1039. */
  1040. void XFrameWindow::Show(const BOOL show)
  1041. {
  1042.    if (show)
  1043.       WinSetWindowPos(frame, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE | SWP_RESTORE);
  1044.    else
  1045.       WinSetWindowPos(frame, 0, 0, 0, 0, 0, SWP_HIDE);
  1046. }
  1047.  
  1048.  
  1049. /*@ XFrameWindow::SetClient(const XWindow * c)
  1050. @group misc
  1051. @remarks SetClient is used to set a window, for example a control like a XMultiLineEdit,
  1052. as a clientwindow of the XFrameWindow so sizing, moving and painting is automaticaly done.
  1053. Moving/Sizing automaticaly may fail if the client is a frame-window.
  1054. @parameters XWindow * theNewClient
  1055. */
  1056. BOOL XFrameWindow::SetClient(const XWindow * c)
  1057. {
  1058.    if(c)
  1059.    {
  1060.    if (c->GetHandle() == 0)
  1061.       return FALSE;
  1062.    if (frameWin)
  1063.       frameWin->adds += 1;
  1064.    WinSetOwner(c->winhandle, frame);
  1065.    WinSetParent(c->winhandle, frame, FALSE);
  1066.    clientWindow = (XWindow *) c;
  1067.    SWP swp;
  1068.  
  1069.    WinQueryWindowPos(winhandle, &swp);
  1070.    WinSetWindowPos(c->winhandle, 0, swp.x, swp.y, swp.cx, swp.cy, SWP_SIZE | SWP_MOVE | SWP_SHOW);
  1071.    }
  1072.    else
  1073.       clientWindow = NULL;
  1074.    return TRUE;
  1075. }
  1076.  
  1077.  
  1078. void BuildChilds(HWND dlgHandle)
  1079. {
  1080.    HWND hwnd;
  1081.    char className[50];
  1082.    SHORT classtype;
  1083.    HENUM enumWindow = WinBeginEnumWindows(dlgHandle);
  1084.    XWindow *du;
  1085.  
  1086.    while ((hwnd = WinGetNextWindow(enumWindow)) != 0)
  1087.    {
  1088.       WinQueryClassName(hwnd, 50, (PCH) className);
  1089.       className[0] = ' ';
  1090.       classtype = atol(className);
  1091.       switch (classtype)
  1092.       {
  1093.       case 1:            // Frame
  1094.          du = new XFrame(hwnd);
  1095.          break;
  1096.       case 2:            // Combobox
  1097.          du = new XComboBox(hwnd);
  1098.          break;
  1099.       case 3:            // Button
  1100.          {
  1101.             ULONG style = WinQueryWindowULong(hwnd, QWL_STYLE);
  1102.  
  1103.             if (style & BS_AUTOCHECKBOX)
  1104.                du = new XCheckBox(hwnd);   // CheckBox
  1105.             else
  1106.             {
  1107.                if (style & BS_AUTORADIOBUTTON)   // RadioButton
  1108.                   du = new XRadioButton(hwnd);
  1109.                else
  1110.                   du = new XPushButton(hwnd);   // PushButton
  1111.             }
  1112.          }
  1113.          break;
  1114.       case 4:            // Menu
  1115.          du = new XMenuBar(hwnd);
  1116.          break;
  1117.       case 5:            // Static
  1118.          {
  1119.             ULONG style = WinQueryWindowULong(hwnd, QWL_STYLE);
  1120.  
  1121.             if (style & SS_GROUPBOX)
  1122.                du = new XGroupBox(hwnd);
  1123.             if (style & SS_TEXT)
  1124.                du = new XStaticText(hwnd);
  1125.             if (style & SS_ICON)
  1126.                du = new XStaticIcon(hwnd);
  1127.             if (style & SS_BITMAP)
  1128.                du = new XStaticBitmap(hwnd);
  1129.          }
  1130.          break;
  1131.       case 6:            // EntryField
  1132.          du = new XEntryField(hwnd);
  1133.          break;
  1134.       case 7:            // Listbox
  1135.          du = new XListBox(hwnd);
  1136.          break;
  1137.       case 8:            // ScrollBar
  1138.          du = new XScrollBar(hwnd);
  1139.          break;
  1140.       case 10:            // MLE
  1141.          du = new XMultiLineEdit(hwnd);
  1142.          break;
  1143.       case 32:            // SpinButton
  1144.          du = new XSpinButton(hwnd);
  1145.          break;
  1146.       case 37:            // Container
  1147.          du = new XContainerControl(hwnd);
  1148.          break;
  1149.       case 38:            // Slider
  1150.          du = new XSlider(hwnd);
  1151.          break;
  1152.       case 39:            // ValueSet
  1153.          du = new XValueSet(hwnd);
  1154.          break;
  1155.       case 40:            // Notebook
  1156.          du = new XNoteBook(hwnd);
  1157.          break;
  1158. /*
  1159.                  case 64:                                                   //GraphicButton
  1160.                     du = new XGraphicButton( hwnd ); break;
  1161. */
  1162.       case 65:            // CircularSlider
  1163.          du = new XCircularSlider(hwnd);
  1164.          break;
  1165.       }
  1166.    }
  1167.    WinEndEnumWindows(enumWindow);
  1168. }
  1169.  
  1170.  
  1171. /*@ XFrameWindow::GetMenu(void)
  1172. @group menu functions
  1173. @remarks Retrieve a pointer to the windows main-window
  1174. @returns XMenuBar* a pointer to the menuBar
  1175. @fixed
  1176. */
  1177. XMenuBar * XFrameWindow::GetMenu(void) const
  1178. {
  1179.    HWND hwnd = WinWindowFromID( WinQueryWindow(GetHandle(), QW_PARENT), FID_MENU);
  1180.      return (XMenuBar *) WinQueryWindowPtr( hwnd, 0);
  1181. }
  1182.  
  1183.  
  1184. void GetScreenValues()
  1185. {
  1186.    MAXX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  1187.    MAXY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  1188.    cxDlgFrame = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME);
  1189.    cyDlgFrame = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME);
  1190.    cxBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
  1191.    cyBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
  1192.    cxSizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  1193.    cySizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  1194. }
  1195.  
  1196.  
  1197. /*@ XFrameWindow :: XFrameWindow(const XResource * id, const char *title, const ULONG style, const XRect * rec, const XFrameWindow * parent, const BOOL build, const BOOL animate)
  1198. @group constructors/destructors
  1199. @remarks Construct a frame-window
  1200. Note that destructors of windows are called automaticaly when a window is closed! (see ~XFrameWindow)
  1201. @parameters <t '°' c=2>
  1202.             °XResource * resource        °a XResource contains two informations, an ID and a pointer
  1203.                                         to a XResourceLibrary. If you want to create a window out of
  1204.                                         a resourcefile you must specify the ID (otherwise it can be zero)
  1205.                                         and the XResourceLibrary which contains the window-resource.
  1206.                                         The window which is created always belongs to the process who
  1207.                                         owns the resource library, so if you work with multiple processes
  1208.                                         every process must have its own resource library.
  1209.             °char * theTitle             °The title of the window which is displayed in the titlebar
  1210.             °ULONG style                 °You can specify the style of the window with the following defines,
  1211.                                         which can be or-ed:
  1212. <BR>
  1213. FRM_TITLEBAR the window gets a titlebar
  1214. <BR>
  1215. FRM_SYSMENU the window gets the system menu
  1216. <BR>
  1217. FRM_MINBUTTON the titlebar get a button to minimize the window
  1218. <BR>
  1219.                                            FRM_MAXBUTTON the titlebar get a button to maximize the window
  1220. <BR>
  1221.                                            FRM_CENTER the window is created in the midle of the workplace
  1222. <BR>
  1223.                                            FRM_SIZEBORDER the windowsize can be changed by the user
  1224. <BR>
  1225.                                            FRM_DIALOGBORDER the window gets a thick border
  1226. <BR>
  1227.                                            FRM_BORDER the window gets a thin border
  1228. <BR>
  1229.                                            FRM_TASKLIST the window is displayed in the tasklist
  1230. <BR>
  1231.                                            FRM_NOMOVEWITHOWNER the window dont∩t move when the parent is moved
  1232. <BR>
  1233.                                            FRM_ICON  the window get an icon wich is identified by theResourceID,                                                            if the icon is not found in the resource-library, an error ocurses
  1234. <BR>
  1235.                                            FRM_ACCELTABLE an acceltable will be loaded from the resources with the windows id.
  1236. <BR>
  1237.                                            FRM_SYSMODAL the window is displayed system-modal
  1238. <BR>
  1239. FRM_SCREENALIGN
  1240. <BR>
  1241. FRM_MOUSEALIGN
  1242. <BR>
  1243. FRM_HIDEBUTTON
  1244. <BR>
  1245. FRM_HIDEMAX
  1246. <BR>
  1247. FRM_AUTOICON
  1248. <BR>
  1249. there are three static member-variables for default styles
  1250. <BR>
  1251. defaultStyle default setting for a framewindow
  1252. <BR>
  1253. defaultClientStyle default setting for windows wich are displayed as a clientwindow of a framewindow
  1254. <BR>
  1255. defaultDialogStyle default setting for windows wich are displayed as a dialog
  1256. <BR>
  1257.                                         Default is defaultStyle.
  1258.             °XRect * theRectangle        °On default a window is created with length and hight of zero. Windows
  1259.                                         which are created with an resource template get the size of the template.
  1260.                                         Default is NULL.
  1261.                                         If theRectangle is specified, the window gets the size of it.
  1262.             °XFrameWindow * parent       °If parent is specified the window is a client of the parent. The
  1263.                                         behavior depends on the styles you have set.
  1264.                                         Default is NULL.
  1265.             °BOOL buildFromResource      °If this variable is set OOL try to build the window with a resource
  1266.                                         template which is identified by theResourceID. If the template is
  1267.                                         not found, an error ocurses.
  1268.                                         Default is FALSE.
  1269.             °BOOL animate                °Enable/disable animation on window creation. Default is FALSE
  1270.             </t>
  1271. @exceptions   If the method fails an exception of the type XException is thrown.
  1272. @fixed
  1273. */
  1274.  
  1275. XFrameWindow :: XFrameWindow(const XResource * id,
  1276.           const char *title,
  1277.           const ULONG style,
  1278.           const XRect& rec,
  1279.           const XFrameWindow * parent,
  1280.           const BOOL build,
  1281.           const BOOL animate)
  1282. {
  1283.    CreateWindow( id->GetID(), id->GetResourceLibrary(), title, style, &rec, parent, build, animate);
  1284. }
  1285.  
  1286.  
  1287. XFrameWindow :: XFrameWindow( const ULONG id,
  1288.                      const char * title,
  1289.                      const ULONG style,
  1290.                      const XRect& rec,
  1291.                      const XFrameWindow * parent,
  1292.                      const BOOL build,
  1293.                      const BOOL animate)
  1294. {
  1295.    CreateWindow( id, NULL, title, style, &rec, parent, build, animate);
  1296. }
  1297.  
  1298. void XFrameWindow :: CreateWindow( const ULONG id, const XResourceLibrary * lib,
  1299.                      const char * title,
  1300.                      const ULONG style,
  1301.                      const XRect * rec,
  1302.                      const XFrameWindow * parent,
  1303.                      const BOOL build,
  1304.                      const BOOL animate)
  1305. {
  1306.    HWND p = parent ? parent->winhandle : HWND_DESKTOP;
  1307.    SWP swp;
  1308.    LONG xRight = 0, yBottom = 0;
  1309.    ULONG st = style;
  1310.  
  1311.    memset(&swp, 0, sizeof(SWP));
  1312.  
  1313.    frame = 0;
  1314.    clientWindow = NULL;
  1315.    vert = horz = NULL;
  1316.    lockingWin = NULL;
  1317.  
  1318.    if (MAXX == 0)
  1319.       GetScreenValues();
  1320.  
  1321.    enabled = TRUE;
  1322.    dummy = 0;
  1323.  
  1324.    if (WinRegisterClass( XApplication::GetApplication()->hab, (PSZ) "OOL_FRAMEWND", (PFNWP) WindowProc, CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT, 4) == FALSE)
  1325.       OOLThrow("error creating framewindow - couldn∩t register class", -10);
  1326.  
  1327.    backCol = 0;
  1328.    dlgHandle = 0;
  1329.  
  1330. //   FRAMECDATA fcmd;
  1331.  
  1332.    BOOL sw = FALSE;
  1333.    if( st & FCF_TASKLIST)
  1334.    {
  1335.       sw = TRUE;
  1336.       st ^= FCF_TASKLIST;
  1337.    }
  1338.    FRAMECDATA fcmd;
  1339.    fcmd.cb = sizeof(fcmd);
  1340.    fcmd.flCreateFlags = st | FCF_NOBYTEALIGN;
  1341.    if(lib)
  1342.       fcmd.hmodResources = lib->GetModuleHandle();
  1343.    else
  1344.       fcmd.hmodResources = 0;
  1345.  
  1346.    fcmd.idResources = id;
  1347.  
  1348.    frame = WinCreateWindow(p, WC_FRAME, (PSZ) title, 0, 0, 0, 0, 0, p, HWND_TOP, id, &fcmd, NULL);
  1349. //   winhandle = WinCreateWindow(frame, (PSZ) "OOL_FRAMEWND", (PSZ) "", (animate ? WIN_ANIMATE : 0), 0, 0, 0, 0, 0, HWND_TOP, FID_CLIENT, this, NULL);
  1350.    winhandle = WinCreateWindow(frame, (PSZ) "OOL_FRAMEWND", (PSZ) "", (animate ? WIN_ANIMATE : 0), 0, 0, 0, 0, 0, HWND_TOP, FID_CLIENT, NULL, NULL);
  1351.    WinSetWindowULong(winhandle, QWL_USER, (ULONG) this);
  1352.  
  1353.    if( sw )
  1354.    {
  1355.        SWCNTRL switchEntry;
  1356.       switchEntry.hwnd = frame;
  1357.       switchEntry.hwndIcon = NULLHANDLE;
  1358.       switchEntry.hprog = NULLHANDLE;
  1359.       switchEntry.idProcess = 0;
  1360.       switchEntry.idSession = 0;
  1361.       switchEntry.uchVisibility = SWL_VISIBLE;
  1362.       switchEntry.fbJump = SWL_JUMPABLE;
  1363.       if(title)
  1364.       {
  1365.          XString bu = title;
  1366.          if( bu.GetLength() > MAXNAMEL )
  1367.             bu = bu.Left( MAXNAMEL );
  1368.          strncpy( switchEntry.szSwtitle, (char*) bu, bu.GetLength() + 1);
  1369.       }
  1370.       else
  1371.          switchEntry.szSwtitle[0] = 0;
  1372.       sEntry = WinAddSwitchEntry( &switchEntry );
  1373.       if (sEntry == NULLHANDLE)
  1374.          OOLThrow("error creating task-switch!", -10);
  1375.    }
  1376.    else
  1377.       sEntry = 0;
  1378.  
  1379.    if (frame == 0)
  1380.       OOLThrow("error creating framewindow - couldn∩t create frame, perhaps resources missing", -10);
  1381.  
  1382.    WinSetWindowULong(winhandle, 4, (LONG) XApplication::GetApplication()->GetApplication());
  1383.  
  1384.    frameWin = new XFrame(this);
  1385.  
  1386.    if (st & FRM_MENU)
  1387.    {
  1388.       HWND menu = WinWindowFromID( WinQueryWindow(GetHandle(), QW_PARENT), FID_MENU);
  1389.       XMenuBar *b = new XMenuBar(menu);
  1390.    }
  1391.  
  1392.    if (build)
  1393.    {
  1394.       XColor col(COL_PALEGRAY);
  1395.  
  1396.       SetBackgroundColor(&col);
  1397.  
  1398.       if(lib)
  1399.          dlgHandle = WinLoadDlg(winhandle, winhandle, (PFNWP) DProc, lib->GetModuleHandle(), id, NULL);
  1400.       else
  1401.          dlgHandle = WinLoadDlg(winhandle, winhandle, (PFNWP) DProc, XApplication::GetApplication()->GetResourceLibrary()->GetModuleHandle(), id, NULL);
  1402.       if (dlgHandle == 0)
  1403.       {
  1404.          OOLThrow("could not create window from resources!", 0);
  1405.          return;
  1406.       }
  1407.       WinSetWindowPtr(dlgHandle, 0, this);
  1408. /*******************************
  1409.       BuildChilds(dlgHandle);
  1410. ************************************/
  1411.       SHORT x = 0, y = 0;
  1412.  
  1413.       if (st & FCF_TITLEBAR)
  1414.          y = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
  1415.       if (style & FCF_DLGBORDER)
  1416.       {
  1417.          x = cxDlgFrame;
  1418.          y += cyDlgFrame;
  1419.       }
  1420.       if (st & FCF_SIZEBORDER)
  1421.       {
  1422.          x = cxBorder;
  1423.          y += cyBorder;
  1424.       }
  1425.       if (st & FCF_BORDER)
  1426.       {
  1427.          x = cxSizeBorder;
  1428.          y += cySizeBorder;
  1429.       }
  1430.  
  1431.       x += x;
  1432.  
  1433.       WinQueryWindowPos(dlgHandle, &swp);
  1434.  
  1435.       WinSetWindowPos(dlgHandle, 0, 0, 0, 0, 0, SWP_MOVE | SWP_SHOW);
  1436.       swp.cx += x;
  1437.       swp.cy += y;
  1438.    }
  1439.    else
  1440.    {
  1441.       if (rec)
  1442.       {
  1443.          swp.cx = rec->GetWidth();
  1444.          swp.cy = rec->GetHeight();
  1445.       }
  1446.    }
  1447.  
  1448.    if (st & FRM_CENTER)
  1449.    {
  1450.       if (dlgHandle)
  1451.       {
  1452.          xRight = MAXX / 2 - swp.cx / 2;
  1453.          yBottom = MAXY / 2 - swp.cy / 2;
  1454.       }
  1455.       else
  1456.       {
  1457.          if (rec)
  1458.          {
  1459.             xRight = MAXX / 2 - rec->GetWidth() / 2;
  1460.             yBottom = MAXY / 2 - rec->GetHeight() / 2;
  1461.          }
  1462.       }
  1463.    }
  1464.    else
  1465.    {
  1466.       if (rec)
  1467.       {
  1468.          xRight = rec->GetX();
  1469.          yBottom = rec->GetY();
  1470.       }
  1471.    }
  1472.  
  1473.    ULONG m = SWP_MOVE | SWP_SIZE | SWP_ZORDER;
  1474.  
  1475.    if (st & WIN_VISIBLE)
  1476.       m |= SWP_SHOW;
  1477.    WinSetWindowPos(frame, HWND_TOP, xRight, yBottom, swp.cx, swp.cy, m);
  1478.    XApplication::GetApplication()->AddWindow(this);
  1479. }
  1480.  
  1481.  
  1482. /*@ XFrameWindow::SetSize(const XRect * rect)
  1483. @group size/position/order
  1484. @remarks Set the size and/or position of a window
  1485. @parameters    XRect * theNewSize
  1486. */
  1487. void XFrameWindow::SetSize(const XRect * rect) const
  1488. {
  1489.    WinSetWindowPos(frame, 0, rect->x, rect->y, rect->cx, rect->cy, SWP_SHOW | SWP_MOVE | SWP_SIZE);
  1490. }
  1491.  
  1492.  
  1493. /*@ XFrameWindow::SetSize(SetSize( const ULONG xPos, const ULONG yPos, const ULONG width, const ULONG height)
  1494. @group size/position/order
  1495. @remarks Set the size and/or position of a window
  1496. @parameters
  1497. <t '°' c=2>
  1498. °ULONG °xPosition
  1499. °ULONG °yPosition
  1500. °ULONG °width
  1501. °ULONG °height
  1502. </t>
  1503. */
  1504. void XFrameWindow::SetSize(const ULONG xPos, const ULONG yPos, const ULONG width, const ULONG height) const
  1505. {
  1506.    WinSetWindowPos(frame, 0, xPos, yPos, width, height, SWP_SHOW | SWP_MOVE | SWP_SIZE);
  1507. }
  1508.  
  1509.  
  1510. /*@ XFrameWindow::GetSize(XRect * rect)
  1511. @group size/position/order
  1512. @remarks Get the size and position of a window
  1513. @parameters    XRect * buffer to hold data
  1514. */
  1515. void XFrameWindow::GetSize(XRect * rect) const
  1516. {
  1517.    SWP swp;
  1518.  
  1519.    WinQueryWindowPos(frame, &swp);
  1520.    rect->x = swp.x;
  1521.    rect->y = swp.y;
  1522.    rect->cx = swp.cx;
  1523.    rect->cy = swp.cy;
  1524. }
  1525.  
  1526.  
  1527. /*@ XFrameWindow::GetClientSize(XRect * rect)
  1528. @group size/position/order
  1529. @remarks Query the size of the client area
  1530. @parameters XRect * rect   buffer to hold the data
  1531. */
  1532. void XFrameWindow::GetClientSize(XRect * rect) const
  1533. {
  1534.    XWindow::GetSize(rect);
  1535.    rect->SetX(0);
  1536.    rect->SetY(0);
  1537. }
  1538.  
  1539.  
  1540. /*@ XFrameWindow::GetWindow(const ULONG id)
  1541. @group misc
  1542. @remarks With GetWindow you can get a pointer of a child-window of XFrameWindow.
  1543. Usualy it is used if the XFrameWindow is created with a resource template.<BR>
  1544. Also you can get a pointer to windows which are created dynamicaly if you have specified an
  1545. ID in the constructors of these windows. In this case you don∩t need to store the pointers
  1546. in your program.
  1547. @parameters    ULONG theWindowID      the ID of the client window
  1548. @returns       XWindow * thePointer   the pointer to the window you have asked for. If you
  1549.                                       know the type of the window, you can make a typcast to
  1550.                                       the needed class.
  1551. */
  1552. XWindow * XFrameWindow::GetWindow(const ULONG id)
  1553. {
  1554.    XWindow *win = XWindow::GetWindow(id);
  1555.  
  1556.    if (win)
  1557.       return win;
  1558.    if (clientWindow)
  1559.    {
  1560.       if (WinQueryWindowUShort(clientWindow->winhandle, QWS_ID) == id)
  1561.          return clientWindow;
  1562.    }
  1563.    return NULL;
  1564. }
  1565.  
  1566.  
  1567. /*@ XFrameWindow::QueryForClose()
  1568. @group misc
  1569. @remarks If the user trys to close a XFrameWindow this function is called. If you want
  1570. to check if the window can be closed or not or to perform a security-check (for example
  1571. with XMessageBox), override this function. This function is not called if you destroy
  1572. the window with delete.
  1573. @returns       BOOL canBeClosed    return TRUE if the window can be closed, otherwise return FALSE
  1574. */
  1575.  
  1576.  
  1577. /*@ XFrameWindow::DoCommand()
  1578. @group user input
  1579. @remarks If the user selected a menuitem (from XMenuBar or XPopupMenu) if the
  1580. user pressed a button of a toolbar which is attached to it the framewindow, this function
  1581. is called. To get the ID of the action the user requested, override this function.
  1582. Return TRUE if you have handled the command, otherwise return FALSE.
  1583. @parameters   LONG theCommandID    the ID of the menuitem/toolbar-button
  1584. @returns      BOOL handled
  1585. */
  1586.  
  1587.  
  1588.  
  1589. /*@ XFrameWindow::Draw()
  1590. @group drawing a window
  1591. @remarks This function is called if a window or a part of it must be redrawn.
  1592. If you use a window which is not created from a resource template or you dont∩t
  1593. have set a client with SetClient(), you must override this function and call
  1594. FillBackground().
  1595. */
  1596.