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