home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mandlcpp.zip / pmprocess.cpp < prev    next >
C/C++ Source or Header  |  1993-06-23  |  8KB  |  357 lines

  1. #include "PMProcess.h"
  2. #ifdef INCLUDESOURCE
  3. #include "process.cc"
  4. #endif
  5.  
  6.  
  7. static _syscall MRESULT pMProcessWindowProc(HWND hwnd,
  8.     ULONG msg,
  9.     MPARAM mp1,
  10.     MPARAM mp2)
  11. {    windowTree *pWindow;
  12.     MRESULT ret;
  13.  
  14.     if (!(pWindow = (windowTree*)WinQueryWindowPtr(hwnd, 0)))
  15.         return WinDefWindowProc(hwnd, msg, mp1, mp2);
  16.     if (ret = pWindow->windowProc(msg, mp1, mp2))
  17.         return ret;
  18.     return WinDefWindowProc(hwnd, msg, mp1, mp2);
  19. }
  20.  
  21.  
  22. windowTree::windowTree(pmMsgThread *pMsgThreadNew, int idResource, char *pTitle)
  23.     :tree(&pMsgThreadNew->structTreeWindows), chainThreads()
  24. {    frameFlags = (FCF_STANDARD) & ~(FCF_ICON | FCF_ACCELTABLE | FCF_MENU);
  25.     windowStyle = WS_VISIBLE;
  26.     classStyle = CS_SIZEREDRAW;
  27.     /*| CS_CLIPSIBLINGS | CS_PARENTCLIP | CS_CLIPCHILDREN */
  28.     pWindowClassName = "PMProcessClassName";
  29.     pMsgThread = pMsgThreadNew;
  30.     pTitelBarText = pTitle;
  31.     resourceId = idResource;
  32.     //pParentWindow = (windowTree*)0;
  33.     //pMsgThread->pWindowTree = this;
  34. }
  35.  
  36.  
  37. windowTree::windowTree(windowTree *pParent, int idResource, char *pTitle)
  38.     :tree(pParent), chainThreads()
  39. {    frameFlags = (FCF_STANDARD) & ~(FCF_ICON | FCF_ACCELTABLE | FCF_MENU);
  40.     windowStyle = WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  41.     classStyle = CS_SIZEREDRAW | CS_CLIPSIBLINGS | CS_PARENTCLIP | CS_CLIPCHILDREN;
  42.     pWindowClassName = "PMProcessClassName";
  43.     pMsgThread = pParent->pMsgThread;
  44.     pTitelBarText = pTitle;
  45.     resourceId = idResource;
  46.     //pParentWindow = pParent;
  47. }
  48.  
  49.  
  50. MRESULT windowTree::windowProc(ULONG msg, MPARAM mp1, MPARAM mp2)
  51. {    switch (msg)
  52.     {    case WM_CLOSE:
  53.             return WMClose(mp1, mp2);
  54.         case WM_PAINT:
  55.             return WMPaint(mp1, mp2);
  56.         case WM_DESTROY:
  57.             return WMDestroy(mp1, mp2);
  58.         case WM_FOCUSCHANGE:
  59.             return WMFocusChange(mp1, mp2);
  60.         default:
  61.             return (MRESULT)FALSE;
  62.     }
  63. }
  64.  
  65.  
  66. MRESULT windowTree::WMDestroy(MPARAM mp1, MPARAM mp2)
  67. {    (void)mp1;
  68.     (void)mp2;
  69.     delete this;
  70.     return (MRESULT)FALSE;
  71. }
  72.  
  73.  
  74. MRESULT windowTree::WMClose(MPARAM mp1, MPARAM mp2)
  75. {    (void)mp1;
  76.     (void)mp2;
  77.     if (canCloseHierarchy())
  78.     {    WinDestroyWindow(hwndFrame);
  79.         return (MRESULT)TRUE;
  80.     }
  81.     else
  82.         return (MRESULT)TRUE;
  83. }
  84.  
  85.  
  86. MRESULT windowTree::WMFocusChange(MPARAM mp1, MPARAM mp2)
  87. {       (void)mp1;
  88.     if (bFocus = SHORT1FROMMP(mp2))
  89.         chainThreads.foreach(
  90.             idForeachPmWindowThreadSetForegroundPriority,
  91.             (void*)0);
  92.     else
  93.         chainThreads.foreach(
  94.             idForeachPmWindowThreadSetBackgroundPriority,
  95.             (void*)0);
  96.     return (MRESULT)FALSE;
  97. }
  98.  
  99.  
  100. MRESULT processWindow::WMClose(MPARAM mp1, MPARAM mp2)
  101. {    (void)mp1;
  102.     (void)mp2;
  103.     if (canCloseHierarchy())
  104.     {       if (pMsgThread->structTreeWindows.iNumberOfElements == 1)
  105.         {    //WinDestroyWindow(hwndFrame);
  106.             return (MRESULT)FALSE;
  107.         }
  108.         else
  109.         {    WinDestroyWindow(hwndFrame);
  110.             return (MRESULT)TRUE;
  111.         }
  112.     }
  113.     else
  114.         return (MRESULT)TRUE;
  115. }
  116.  
  117.  
  118. Boolean windowTree::create(void)
  119. {    if (!WinRegisterClass(pMsgThread->hab, (unsigned char*)pWindowClassName,
  120.        pMProcessWindowProc, classStyle, sizeof(this)))
  121.         return FALSE;
  122.     hwndFrame = WinCreateStdWindow(
  123.        getParentWindow() ? getParentWindow()->hwndClient : HWND_DESKTOP,
  124.        windowStyle, &frameFlags, (unsigned char*)pWindowClassName,
  125.        (unsigned char*)pTitelBarText, 0, (HMODULE)0L,
  126.        resourceId, &hwndClient);
  127. #ifdef DEBUG
  128.     if (!hwndFrame)
  129.         fprintf(stderr, "Fehler bei `WinCreateStdWindow' = %x\n",
  130.            WinGetLastError(pMsgThread->hab));
  131. #endif DEBUG
  132.     hWindowDC = WinOpenWindowDC(hwndClient);
  133.     WinSetWindowPtr(hwndClient, 0, this);
  134.     WinSetWindowPos(hwndFrame,
  135.         HWND_TOP,
  136.         100, 100, 200, 200,
  137.         SWP_ACTIVATE | SWP_ZORDER | SWP_SHOW);
  138.     return TRUE;
  139. }
  140.  
  141.  
  142. Boolean windowTree::initPost(void)
  143. {    return TRUE;
  144. }
  145.  
  146.  
  147. MRESULT windowTree::WMPaint(MPARAM mp1, MPARAM mp2)
  148. {    RECTL structRectl;
  149.     HPS hps;
  150.  
  151.     (void)mp1;
  152.     (void)mp2;
  153.     hps = WinBeginPaint(hwndClient, (HPS)0, &structRectl);
  154.     doPaint(hps, &structRectl);
  155.     WinEndPaint(hps);
  156.     return (MRESULT)TRUE;
  157. }
  158.  
  159.  
  160. void windowTree::doPaint(HPS hps, RECTL *pStructRectl)
  161. {    (void)hps;
  162.     (void)pStructRectl;
  163. }
  164.  
  165.  
  166. int windowTree::toBeCalledPre(unsigned int iMsg, void *pDummy)
  167. {    switch (iMsg)
  168.     {    case idForeachWindowTreeWinDestroyWindow:
  169.         case idForeachWindowTreeCallInit:
  170.         case idForeachWindowTreeCallDestructAll:
  171.             return 0;
  172.         case idForeachWindowTreeCanClose:
  173.             if (!canClose())
  174.                 return -1;
  175.             else
  176.                 return 0;
  177.         default:
  178.             return tree::toBeCalledPre(iMsg, pDummy);
  179.     }
  180. }
  181.  
  182.  
  183. int windowTree::toBeCalledPost(unsigned int iMsg, void *pDummy)
  184. {    switch (iMsg)
  185.     {    case idForeachWindowTreeWinDestroyWindow:
  186.             if (hwndFrame)
  187.                 WinDestroyWindow(hwndFrame);
  188.             return 0;
  189.         case idForeachWindowTreeCallInit:
  190.             if (!init())
  191.             {    delete this;
  192.                 return -1;
  193.             }
  194.             ++*(unsigned int*)pDummy;
  195.             return 0;
  196.         case idForeachWindowTreeCallDestructAll:
  197.             if ((*(unsigned int*)pDummy)--)
  198.             {    destructAll();
  199.                 return 0;
  200.             }
  201.             else
  202.                 return -1;
  203.         case idForeachWindowTreeCanClose:
  204.             return 0;
  205.         default:
  206.             return tree::toBeCalledPost(iMsg, pDummy);
  207.     }
  208. }
  209.  
  210.  
  211. Boolean windowTree::canClose(void)
  212. {    return TRUE;
  213. }
  214.  
  215.  
  216. windowTree::~windowTree(void)
  217. {    foreach(idForeachWindowTreeWinDestroyWindow, (void*)0);
  218.     WinSetWindowPtr(hwndFrame, 0, 0);
  219. }
  220.  
  221.  
  222. pmThread::pmThread(pmProcess *pProcess, chain *pParent)
  223.     :thread(pProcess, pParent)
  224. {    hab = WinInitialize(0);
  225. }
  226.  
  227.  
  228. pmThread::pmThread(pmProcess *pProcess):thread(FALSE, pProcess)
  229. {    hab = WinInitialize(0);
  230. }
  231.  
  232.  
  233. pmThread::~pmThread(void)
  234. {    if (hab)
  235.         WinTerminate(hab);
  236. }
  237.  
  238.  
  239. pmWindowThread::pmWindowThread(windowTree *pWindowNew)
  240.     :pmThread((pmProcess*)pWindowNew->pMsgThread->pProcess
  241.     ->getChainMember(idGetChainPmProcessThis),
  242.     &pWindowNew->chainThreads)
  243. {    pWindow = pWindowNew;
  244.     iClassF = PRTYC_REGULAR;
  245.     iValueF = 0;
  246.     iClassB = PRTYC_IDLETIME;
  247.     iValueB = 0;
  248. }
  249.  
  250.  
  251. Boolean pmWindowThread::initPre(void)
  252. {    if (pWindow->bFocus)
  253.         toBeCalledForeachElement(
  254.             idForeachPmWindowThreadSetForegroundPriority,
  255.             (void*)0);
  256.     else
  257.         toBeCalledForeachElement(
  258.             idForeachPmWindowThreadSetBackgroundPriority,
  259.             (void*)0);
  260.     return pmThread::initPre();
  261. }
  262.  
  263.  
  264. int pmWindowThread::toBeCalledForeachElement(unsigned int iMsg, void *pDummy)
  265. {          switch (iMsg)
  266.     {    default:
  267.             return pmThread::toBeCalledForeachElement(iMsg, pDummy);
  268.         case idForeachPmWindowThreadSetBackgroundPriority:
  269.             DosSetPriority(PRTYS_THREAD,
  270.                 iClassB,
  271.                 iValueB - pTIB->tib_ptib2->tib2_ulpri,
  272.                 pTIB->tib_ptib2->tib2_ultid);
  273.             return 0;
  274.         case idForeachPmWindowThreadSetForegroundPriority:
  275.             DosSetPriority(PRTYS_THREAD,
  276.                 iClassF,
  277.                 iValueF - pTIB->tib_ptib2->tib2_ulpri,
  278.                 pTIB->tib_ptib2->tib2_ultid);
  279.             return 0;
  280.     }
  281. }
  282.  
  283. pmMsgThread::pmMsgThread(pmProcess *pProcess):pmThread(pProcess),
  284.     structTreeWindows((tree*)0)
  285. {    hmq = WinCreateMsgQueue(hab, 0);
  286. }
  287.  
  288.  
  289. Boolean pmMsgThread::create(void)
  290. {    processWindow *pWindowTree;    // in this class only one window
  291.                     // will be opened
  292.     if (!(pWindowTree
  293.        = new processWindow(this, 0, "")))
  294.         return FALSE;
  295.     else
  296.         if (!pWindowTree->isSuccessfull())
  297.         {    delete pWindowTree;
  298.             return FALSE;
  299.         }
  300.     return TRUE;
  301. }
  302.  
  303.  
  304. void pmMsgThread::destruct()
  305. {    structTreeWindows.foreach(idForeachWindowTreeWinDestroyWindow,
  306.         (void*)0);
  307. }
  308.  
  309.  
  310. Boolean pmMsgThread::initPost(void)
  311. {       unsigned int iNumber = 0;
  312.  
  313.     structTreeWindows.foreach(idForeachWindowTreeCallInit, (void*)&iNumber);
  314.     if (iNumber != structTreeWindows.iNumberOfElements)
  315.     {    structTreeWindows.foreach(idForeachWindowTreeCallDestructAll,
  316.             (void*)&iNumber);
  317.         return FALSE;
  318.     }
  319.     return TRUE;
  320. }
  321.  
  322.  
  323. void pmMsgThread::doSomething(void)
  324. {    QMSG qmsg;
  325.  
  326.     while (WinGetMsg(hab, &qmsg, 0, 0, 0))
  327.         WinDispatchMsg(hab, &qmsg);
  328. }
  329.  
  330.  
  331. void pmMsgThread::destructPre(void)
  332. {       unsigned int iNumber = structTreeWindows.iNumberOfElements;
  333.  
  334.     structTreeWindows.foreach(idForeachWindowTreeCallDestructAll,
  335.         (void*)&iNumber);
  336. }
  337.  
  338.  
  339. pmMsgThread::~pmMsgThread(void)
  340. {    if (hmq)
  341.         WinDestroyMsgQueue(hmq);
  342. }
  343.  
  344.  
  345. Boolean pmProcess::create(void)
  346. {    if (!(pProcessThread = new pmMsgThread(this)))
  347.         return FALSE;
  348.     else
  349.         if (pProcessThread->isSuccessfull())
  350.             return TRUE;
  351.         else
  352.         {    delete pProcessThread;
  353.             pProcessThread = (thread*)0;
  354.             return FALSE;
  355.         }
  356. }
  357.