home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / mdi / mdi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-05  |  4.5 KB  |  163 lines

  1. /***************************************************************************\
  2. * mdi.c - MDI application
  3. *
  4. * Created by Microsoft Corporation, 1989
  5. \***************************************************************************/
  6.  
  7. #define INCL_WINSYS
  8. #define INCL_WINCOMMON
  9. #define INCL_WINMESSAGEMGR
  10. #define INCL_WINPOINTERS
  11. #define INCL_WININPUT
  12. #define INCL_WINMENUS
  13. #define INCL_WINFRAMEMGR
  14. #define INCL_WINWINDOWMGR
  15. #define INCL_WINRECTANGLES
  16. #define INCL_WINHEAP
  17.  
  18. #include <os2.h>
  19. #include "app.h"
  20. #include "appdata.h"
  21. #include "mdi.h"
  22. #include "mdidata.h"
  23.  
  24. VOID MDIDesktopSize(HWND hwnd, MPARAM mp1, MPARAM mp2)
  25. {
  26.     HWND hwndDoc;
  27.     RECTL rclWindow;
  28.     POINTL ptlBorderSize;
  29.     HENUM henum;
  30.     SWP swp;
  31.     ULONG ulStyle;
  32.  
  33.     /*
  34.      * This code keeps maximized MDI windows maximized within the
  35.      * main client window and bottom-left aligns minimized windows.
  36.      */
  37.     WinQueryWindowRect(hwnd, (PRECTL)&rclWindow);
  38.  
  39.     WinSendMsg(hwndMDIFrame, WM_QUERYBORDERSIZE, (MPARAM)&ptlBorderSize,
  40.             0L);
  41.     WinInflateRect(NULL, (PRECTL)&rclWindow, (SHORT)ptlBorderSize.x,
  42.             (SHORT)ptlBorderSize.y);
  43.     rclWindow.yTop += cyTitlebar;
  44.  
  45.     swp.hwndInsertBehind = NULL;
  46.  
  47.     henum = WinBeginEnumWindows(hwnd);
  48.     while (hwndDoc = WinGetNextWindow(henum)) {
  49.         WinLockWindow(hwndDoc, FALSE);
  50.         ulStyle = WinQueryWindowULong(hwndDoc, QWL_STYLE);
  51.         if (ulStyle & WS_MAXIMIZED) {
  52.             swp.hwnd = hwndDoc;
  53.             swp.x = (SHORT)rclWindow.xLeft;
  54.             swp.y = (SHORT)rclWindow.yBottom;
  55.             swp.cx = (SHORT)rclWindow.xRight - (SHORT)rclWindow.xLeft;
  56.             swp.cy = (SHORT)rclWindow.yTop - (SHORT)rclWindow.yBottom;
  57.             swp.fs = SWP_MOVE | SWP_SIZE;
  58.             WinSetMultWindowPos(NULL, (PSWP)&swp, 1);
  59.         } else if (ulStyle & WS_MINIMIZED) {
  60.  
  61.             WinQueryWindowPos(hwndDoc, &swp);
  62.  
  63.             swp.x = 0;
  64.             swp.y = 0;
  65.             swp.fs = SWP_MOVE | SWP_ZORDER;
  66.             swp.hwndInsertBehind = HWND_BOTTOM;
  67.  
  68.        /*
  69.             swp.y -= (SHORT2FROMMP(mp2) - SHORT2FROMMP(mp1));
  70.             swp.fs = SWP_MOVE;
  71.        */
  72.             WinSetMultWindowPos(NULL, (PSWP)&swp, 1);
  73.  
  74.         }
  75.     }
  76.     WinEndEnumWindows(henum);
  77.  
  78.     /*
  79.      * Adjust yNextNewDoc to keep it top-left aligned.
  80.      */
  81.     yNextNewDoc += (SHORT2FROMMP(mp2) - SHORT2FROMMP(mp1));
  82. }
  83.  
  84.  
  85. VOID MDIDesktopSetFocus(HWND hwnd, MPARAM mp2)
  86. {
  87.     HWND hwndTopDoc;
  88.  
  89.     /*
  90.      * If we're getting the focus and there is a document window,
  91.      * set the focus to the top-most document window so the main
  92.      * client window never has the focus.
  93.      */
  94.     if ((SHORT1FROMMP(mp2) != FALSE) &&
  95.             (hwndTopDoc = WinQueryWindow(hwnd, QW_TOP, FALSE))) {
  96.         WinSetFocus(HWND_DESKTOP, hwndTopDoc);
  97.     }
  98. }
  99.  
  100.  
  101. VOID MDIDesktopActivateDoc(SHORT idMenuitem)
  102. {
  103.     register NPDOC npdoc;
  104.  
  105.     npdoc = npdocFirst;
  106.     while (npdoc != NULL) {
  107.         if (npdoc->idMI == (USHORT) idMenuitem) {
  108.             WinSetFocus(HWND_DESKTOP, npdoc->hwndFrame);
  109.  
  110.             /*
  111.              * If the document is minimized then
  112.              * restore it as well.
  113.              */
  114.             if (WinQueryWindowULong(npdoc->hwndFrame, QWL_STYLE) &
  115.                     WS_MINIMIZED) {
  116.                 WinSetWindowPos(npdoc->hwndFrame, NULL,
  117.                         0, 0, 0, 0, SWP_RESTORE);
  118.             }
  119.             break;
  120.         }
  121.         npdoc = npdoc->npdocNext;
  122.     }
  123. }
  124.  
  125. MRESULT EXPENTRY MainFrameWndProc(HWND hwnd, USHORT msg, MPARAM mp1,
  126.         MPARAM mp2)
  127. {
  128.     HWND hwndAppMenu;
  129.     NPDOC npdoc;
  130.  
  131.     switch (msg) {
  132.  
  133.     case WM_NEXTMENU:
  134.         /*
  135.          * Connect child sysmenu with application menus
  136.          */
  137.  
  138.         npdoc=NPDOCFROMCLIENT(WinWindowFromID(hwndActiveDoc, FID_CLIENT));
  139.  
  140.         if (npdoc->fAabSysMenu == TRUE) {
  141.             /* child sysmenu is already in app menu */
  142.             return (*pfnMainFrameWndProc)(hwnd, msg, mp1, mp2);
  143.             }
  144.  
  145. #define hwndCurrent HWNDFROMMP(mp1)
  146.  
  147.         hwndAppMenu=NPDOCFROMCLIENT(WinWindowFromID(hwndActiveDoc, FID_CLIENT))
  148.                         ->hwndMainMenu;
  149.  
  150.         if (((hwndCurrent == hwndSysMenu) && !SHORT1FROMMP(mp2)) ||
  151.                 ((hwndCurrent == hwndAppMenu) && SHORT1FROMMP(mp2))) {
  152.  
  153.             if (hwndActiveDoc)
  154.                 return (WinWindowFromID(hwndActiveDoc, FID_SYSMENU));
  155.         }
  156.  
  157. #undef hwndCurrent
  158.  
  159.         break;
  160.     }
  161.     return (*pfnMainFrameWndProc)(hwnd, msg, mp1, mp2);
  162. }
  163.