home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CLASS.ZIP / 1.CC next >
Text File  |  1993-02-20  |  9KB  |  333 lines

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