home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwplascr.zip / XWPL0208.ZIP / src / startshut / winlist.c < prev   
C/C++ Source or Header  |  2002-06-02  |  20KB  |  533 lines

  1.  
  2. /*
  3.  *@@sourcefile winlist.c:
  4.  *      debug code to show the complete window (switch) list in
  5.  *      a PM container window.
  6.  *
  7.  *@@header "startshut\shutdown.h"
  8.  */
  9.  
  10. /*
  11.  *      Copyright (C) 2000 Ulrich Möller.
  12.  *      This file is part of the XWorkplace source package.
  13.  *      XWorkplace is free software; you can redistribute it and/or modify
  14.  *      it under the terms of the GNU General Public License as published
  15.  *      by the Free Software Foundation, in version 2 as it comes in the
  16.  *      "COPYING" file of the XWorkplace main distribution.
  17.  *      This program is distributed in the hope that it will be useful,
  18.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  *      GNU General Public License for more details.
  21.  */
  22.  
  23. #pragma strings(readonly)
  24.  
  25. /*
  26.  *  Suggested #include order:
  27.  *  1)  os2.h
  28.  *  2)  C library headers
  29.  *  3)  setup.h (code generation and debugging options)
  30.  *  4)  headers in helpers\
  31.  *  5)  at least one SOM implementation header (*.ih)
  32.  *  6)  dlgids.h, headers in shared\ (as needed)
  33.  *  7)  headers in implementation dirs (e.g. filesys\, as needed)
  34.  *  8)  #pragma hdrstop and then more SOM headers which crash with precompiled headers
  35.  */
  36.  
  37. #define INCL_DOSPROCESS
  38. #define INCL_DOSSEMAPHORES
  39. #define INCL_DOSEXCEPTIONS
  40. #define INCL_DOSERRORS
  41.  
  42. #define INCL_WINWINDOWMGR
  43. #define INCL_WINFRAMEMGR
  44. #define INCL_WINSWITCHLIST
  45. #define INCL_WINMENUS
  46. #define INCL_WINSTDCNR
  47. #define INCL_WINSYS
  48. #include <os2.h>
  49.  
  50. // C library headers
  51. #include <stdio.h>              // needed for except.h
  52. #include <setjmp.h>             // needed for except.h
  53. #include <assert.h>             // needed for except.h
  54. #include <stdarg.h>
  55.  
  56. // generic headers
  57. #include "setup.h"                      // code generation and debugging options
  58.  
  59. // headers in /helpers
  60. #include "helpers\cnrh.h"
  61. #include "helpers\except.h"
  62. #include "helpers\stringh.h"
  63. #include "helpers\winh.h"
  64.  
  65. // SOM headers which don't crash with prec. header files
  66. #include "xfobj.ih"
  67.  
  68. // XWorkplace implementation headers
  69. #include "shared\kernel.h"              // XWorkplace Kernel
  70. #include "startshut\shutdown.h"         // XWorkplace eXtended Shutdown
  71.  
  72. // other SOM headers
  73. #pragma hdrstop
  74.  
  75. /*
  76.  *@@ WINLISTRECORD:
  77.  *
  78.  *@@added V0.9.4 (2000-07-15) [umoeller]
  79.  */
  80.  
  81. typedef struct _WINLISTRECORD
  82. {
  83.     RECORDCORE  recc;
  84.  
  85.     ULONG       ulIndex;
  86.  
  87.     HSWITCH     hSwitch;
  88.  
  89.     CHAR        szSwTitle[200];
  90.     PSZ         pszSwTitle;         // points to szSwTitle
  91.  
  92.     CHAR        szWinTitle[200];
  93.     PSZ         pszWinTitle;        // points to szWinTitle
  94.  
  95.     CHAR        szObject[30];
  96.     PSZ         pszObject;
  97.  
  98.     HWND        hwnd;
  99.     CHAR        szHWND[20];
  100.     PSZ         pszHWND;
  101.  
  102.     CHAR        szWinClass[30];
  103.     PSZ         pszWinClass;
  104.  
  105.     HPROGRAM    hPgm;
  106.     PID         pid;
  107.     ULONG       sid;
  108.     ULONG       ulVisibility;
  109.  
  110.     PSZ         pszObjectTitle;
  111.  
  112.     HAPP        happObject;
  113.     CHAR        szHAPP[30];
  114.     PSZ         pszHAPP;            // points to szHAPP
  115.  
  116.     CHAR        szClosable[30];
  117.     PSZ         pszClosable;        // points to szClosable
  118.  
  119.     ULONG       uid;                // V0.9.19 (2002-04-02) [umoeller]
  120.     CHAR        szUid[30];
  121.     PSZ         pszUid;             // points to szUid;
  122.  
  123. } WINLISTRECORD, *PWINLISTRECORD;
  124.  
  125. #define ID_WINLISTCNR       1001
  126.  
  127. /*
  128.  *@@ winlCreateRecords:
  129.  *
  130.  *@@added V0.9.4 (2000-07-15) [umoeller]
  131.  */
  132.  
  133. ULONG winlCreateRecords(HWND hwndCnr)
  134. {
  135.     PSWBLOCK        pSwBlock   = NULL;         // Pointer to information returned
  136.     ULONG           ul; /*
  137.                     cbItems    = 0,            // Number of items in list
  138.                     ulBufSize  = 0;            // Size of buffer for information
  139.        */
  140.     HAB             hab = WinQueryAnchorBlock(hwndCnr);
  141.  
  142.     PWINLISTRECORD  pFirstRec = NULL,
  143.                     precThis = NULL;
  144.     ULONG           ulIndex = 0;
  145.  
  146.     SHUTDOWNCONSTS  SDConsts;
  147.  
  148.     // get all the tasklist entries into a buffer
  149.     /* cbItems = WinQuerySwitchList(hab, NULL, 0);
  150.     ulBufSize = (cbItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  151.     pSwBlock = (PSWBLOCK)malloc(ulBufSize);
  152.     cbItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize); */
  153.  
  154.     if (pSwBlock = winhQuerySwitchList(hab))
  155.     {
  156.         xsdGetShutdownConsts(&SDConsts);
  157.  
  158.         // allocate records
  159.         pFirstRec = (PWINLISTRECORD)cnrhAllocRecords(hwndCnr,
  160.                                                      sizeof(WINLISTRECORD),
  161.                                                      pSwBlock->cswentry);
  162.         if (pFirstRec)
  163.         {
  164.             precThis = pFirstRec;
  165.  
  166.             // loop through all the tasklist entries
  167.             for (ul = 0;
  168.                  (ul < pSwBlock->cswentry) && (precThis);
  169.                  ul++)
  170.             {
  171.                 WPObject    *pObject;
  172.                 LONG        lClosable;
  173.  
  174.                 precThis->ulIndex = ulIndex++;
  175.  
  176.                 precThis->hSwitch = pSwBlock->aswentry[ul].hswitch;
  177.  
  178.                 precThis->hwnd = pSwBlock->aswentry[ul].swctl.hwnd;
  179.                 sprintf(precThis->szHWND, "0x%lX", pSwBlock->aswentry[ul].swctl.hwnd);
  180.                 precThis->pszHWND = precThis->szHWND;
  181.  
  182.                 if (precThis->hwnd)
  183.                     WinQueryClassName(precThis->hwnd,
  184.                                       sizeof(precThis->szWinClass),
  185.                                       precThis->szWinClass);
  186.                 precThis->pszWinClass = precThis->szWinClass;
  187.  
  188.                 precThis->hPgm = pSwBlock->aswentry[ul].swctl.hprog;
  189.                 precThis->pid = pSwBlock->aswentry[ul].swctl.idProcess;
  190.                 precThis->sid = pSwBlock->aswentry[ul].swctl.idSession;
  191.                 precThis->ulVisibility = pSwBlock->aswentry[ul].swctl.uchVisibility;
  192.  
  193.                 strhncpy0(precThis->szSwTitle,
  194.                           pSwBlock->aswentry[ul].swctl.szSwtitle,
  195.                           sizeof(precThis->szSwTitle));
  196.                 precThis->pszSwTitle = precThis->szSwTitle;
  197.  
  198.                 WinQueryWindowText(pSwBlock->aswentry[ul].swctl.hwnd,
  199.                                    sizeof(precThis->szWinTitle),
  200.                                    precThis->szWinTitle);
  201.                 precThis->pszWinTitle = precThis->szWinTitle;
  202.  
  203.                 lClosable = xsdIsClosable(hab,
  204.                                           &SDConsts,
  205.                                           &pSwBlock->aswentry[ul],
  206.                                           &pObject,
  207.                                           &precThis->uid);
  208.                 sprintf(precThis->szClosable, "%d", lClosable);
  209.                 precThis->pszClosable = precThis->szClosable;
  210.  
  211.                 sprintf(precThis->szObject, "0x%lX", pObject);
  212.                 precThis->pszObject = precThis->szObject;
  213.  
  214.                 sprintf(precThis->szUid, "%d", precThis->uid);
  215.                 precThis->pszUid = precThis->szUid;
  216.  
  217.                 if (pObject)
  218.                 {
  219.                     PVIEWITEM pvi;
  220.  
  221.                     precThis->pszObjectTitle = _wpQueryTitle(pObject);
  222.  
  223.                     if (pvi = _wpFindViewItem(pObject,
  224.                                               VIEW_RUNNING,
  225.                                               NULL))
  226.                     {
  227.                         precThis->happObject = pvi->handle;
  228.                         sprintf(precThis->szHAPP, "%lX", pvi->handle);
  229.                         precThis->pszHAPP = precThis->szHAPP;
  230.                     }
  231.                 }
  232.  
  233.                 precThis = (PWINLISTRECORD)precThis->recc.preccNextRecord;
  234.             }
  235.         }
  236.  
  237.         cnrhInsertRecords(hwndCnr,
  238.                           NULL,         // parent
  239.                           (PRECORDCORE)pFirstRec,
  240.                           TRUE,
  241.                           NULL,
  242.                           CRA_RECORDREADONLY,
  243.                           ulIndex);
  244.  
  245.         free(pSwBlock);
  246.     }
  247.  
  248.     return (ulIndex);
  249. }
  250.  
  251. /*
  252.  *@@ winl_fnwpWinList:
  253.  *
  254.  *@@added V0.9.4 (2000-07-15) [umoeller]
  255.  */
  256.  
  257. MRESULT EXPENTRY winl_fnwpWinList(HWND hwndClient, ULONG msg, MPARAM mp1, MPARAM mp2)
  258. {
  259.     MRESULT mrc = 0;
  260.  
  261.     switch (msg)
  262.     {
  263.         case WM_CREATE:
  264.         {
  265.             TRY_LOUD(excpt1)
  266.             {
  267.                 // PCREATESTRUCT pcs = (PCREATESTRUCT)mp2;
  268.                 HWND hwndCnr;
  269.                 hwndCnr = WinCreateWindow(hwndClient,        // parent
  270.                                           WC_CONTAINER,
  271.                                           "",
  272.                                           WS_VISIBLE | CCS_MINIICONS | CCS_READONLY | CCS_SINGLESEL,
  273.                                           0, 0, 0, 0,
  274.                                           hwndClient,        // owner
  275.                                           HWND_TOP,
  276.                                           ID_WINLISTCNR,
  277.                                           NULL, NULL);
  278.                 if (hwndCnr)
  279.                 {
  280.                     XFIELDINFO      xfi[22];
  281.                     PFIELDINFO      pfi = NULL;
  282.                     PWINLISTRECORD  pMemRecordFirst;
  283.                     int             i = 0;
  284.  
  285.                     ULONG           ulTotalItems = 0,
  286.                                     ulAllocatedItems = 0,
  287.                                     ulFreedItems = 0;
  288.                     ULONG           ulTotalBytes = 0,
  289.                                     ulAllocatedBytes = 0,
  290.                                     ulFreedBytes = 0;
  291.  
  292.                     // set up cnr details view
  293.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, ulIndex);
  294.                     xfi[i].pszColumnTitle = "i";
  295.                     xfi[i].ulDataType = CFA_ULONG;
  296.                     xfi[i++].ulOrientation = CFA_RIGHT;
  297.  
  298.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, hSwitch);
  299.                     xfi[i].pszColumnTitle = "hSw";
  300.                     xfi[i].ulDataType = CFA_ULONG;
  301.                     xfi[i++].ulOrientation = CFA_RIGHT;
  302.  
  303.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszSwTitle);
  304.                     xfi[i].pszColumnTitle = "Switch title";
  305.                     xfi[i].ulDataType = CFA_STRING;
  306.                     xfi[i++].ulOrientation = CFA_LEFT;
  307.  
  308.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszWinTitle);
  309.                     xfi[i].pszColumnTitle = "Win title";
  310.                     xfi[i].ulDataType = CFA_STRING;
  311.                     xfi[i++].ulOrientation = CFA_LEFT;
  312.  
  313.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszHWND);
  314.                     xfi[i].pszColumnTitle = "hwnd";
  315.                     xfi[i].ulDataType = CFA_STRING;
  316.                     xfi[i++].ulOrientation = CFA_RIGHT;
  317.  
  318.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszWinClass);
  319.                     xfi[i].pszColumnTitle = "Class";
  320.                     xfi[i].ulDataType = CFA_STRING;
  321.                     xfi[i++].ulOrientation = CFA_LEFT;
  322.  
  323.                     /* xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, hPgm);
  324.                     xfi[i].pszColumnTitle = "hPgm";
  325.                     xfi[i].ulDataType = CFA_ULONG;
  326.                     xfi[i++].ulOrientation = CFA_RIGHT; */
  327.  
  328.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pid);
  329.                     xfi[i].pszColumnTitle = "pid";
  330.                     xfi[i].ulDataType = CFA_ULONG;
  331.                     xfi[i++].ulOrientation = CFA_RIGHT;
  332.  
  333.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, sid);
  334.                     xfi[i].pszColumnTitle = "sid";
  335.                     xfi[i].ulDataType = CFA_ULONG;
  336.                     xfi[i++].ulOrientation = CFA_RIGHT;
  337.  
  338.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, ulVisibility);
  339.                     xfi[i].pszColumnTitle = "Vis";
  340.                     xfi[i].ulDataType = CFA_ULONG;
  341.                     xfi[i++].ulOrientation = CFA_RIGHT;
  342.  
  343.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszClosable);
  344.                     xfi[i].pszColumnTitle = "Close";
  345.                     xfi[i].ulDataType = CFA_STRING;
  346.                     xfi[i++].ulOrientation = CFA_RIGHT;
  347.  
  348.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszObject);
  349.                     xfi[i].pszColumnTitle = "Obj";
  350.                     xfi[i].ulDataType = CFA_STRING;
  351.                     xfi[i++].ulOrientation = CFA_RIGHT;
  352.  
  353.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszObjectTitle);
  354.                     xfi[i].pszColumnTitle = "Obj Title";
  355.                     xfi[i].ulDataType = CFA_STRING;
  356.                     xfi[i++].ulOrientation = CFA_RIGHT;
  357.  
  358.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszUid);
  359.                     xfi[i].pszColumnTitle = "uid";
  360.                     xfi[i].ulDataType = CFA_STRING;
  361.                     xfi[i++].ulOrientation = CFA_RIGHT;
  362.  
  363.                     xfi[i].ulFieldOffset = FIELDOFFSET(WINLISTRECORD, pszHAPP);
  364.                     xfi[i].pszColumnTitle = "HAPP";
  365.                     xfi[i].ulDataType = CFA_STRING;
  366.                     xfi[i++].ulOrientation = CFA_RIGHT;
  367.  
  368.                     pfi = cnrhSetFieldInfos(hwndCnr,
  369.                                             &xfi[0],
  370.                                             i,             // array item count
  371.                                             TRUE,          // no draw lines
  372.                                             3);            // return column
  373.  
  374.                     {
  375.                         PSZ pszFont = "9.WarpSans";
  376.                         WinSetPresParam(hwndCnr,
  377.                                         PP_FONTNAMESIZE,
  378.                                         strlen(pszFont),
  379.                                         pszFont);
  380.                     }
  381.  
  382.                     winlCreateRecords(hwndCnr);
  383.  
  384.                     BEGIN_CNRINFO()
  385.                     {
  386.                         cnrhSetView(CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES
  387.                                         | CA_DRAWICON
  388.                                     /* | CA_CONTAINERTITLE | CA_TITLEREADONLY
  389.                                         | CA_TITLESEPARATOR | CA_TITLELEFT*/ );
  390.                         cnrhSetSplitBarAfter(pfi);
  391.                         cnrhSetSplitBarPos(250);
  392.                     } END_CNRINFO(hwndCnr);
  393.  
  394.                     WinSetFocus(HWND_DESKTOP, hwndCnr);
  395.                 }
  396.             }
  397.             CATCH(excpt1) {} END_CATCH();
  398.  
  399.             mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);
  400.         }
  401.         break;
  402.  
  403.         case WM_WINDOWPOSCHANGED:
  404.         {
  405.             PSWP pswp = (PSWP)mp1;
  406.             mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);
  407.             if (pswp->fl & SWP_SIZE)
  408.             {
  409.                 WinSetWindowPos(WinWindowFromID(hwndClient, ID_WINLISTCNR), // cnr
  410.                                 HWND_TOP,
  411.                                 0, 0, pswp->cx, pswp->cy,
  412.                                 SWP_SIZE | SWP_MOVE | SWP_SHOW);
  413.             }
  414.         }
  415.         break;
  416.  
  417.         case WM_CONTROL:
  418.         {
  419.             USHORT usItemID = SHORT1FROMMP(mp1),
  420.                    usNotifyCode = SHORT2FROMMP(mp1);
  421.             if (usItemID == ID_WINLISTCNR)       // cnr
  422.             {
  423.                 switch (usNotifyCode)
  424.                 {
  425.                     // V0.9.16 (2002-01-13) [umoeller]
  426.                     case CN_ENTER:
  427.                     {
  428.                         PNOTIFYRECORDENTER pnre = (PNOTIFYRECORDENTER)mp2;
  429.                         PWINLISTRECORD prec;
  430.                         if (prec = (PWINLISTRECORD)pnre->pRecord)
  431.                             WinSwitchToProgram(prec->hSwitch);
  432.                     }
  433.                     break;
  434.  
  435.                     case CN_CONTEXTMENU:
  436.                     {
  437.                         PWINLISTRECORD precc = (PWINLISTRECORD)mp2;
  438.                         if (precc == NULL)
  439.                         {
  440.                             // whitespace
  441.                             HWND hwndMenu = WinCreateMenu(HWND_DESKTOP,
  442.                                                           NULL); // no menu template
  443.                             winhInsertMenuItem(hwndMenu,
  444.                                                MIT_END,
  445.                                                1001,
  446.                                                "Sort by index",
  447.                                                MIS_TEXT, 0);
  448.                             winhInsertMenuItem(hwndMenu,
  449.                                                MIT_END,
  450.                                                1002,
  451.                                                "Sort by source file",
  452.                                                MIS_TEXT, 0);
  453.                             cnrhShowContextMenu(WinWindowFromID(hwndClient, ID_WINLISTCNR),
  454.                                                 NULL,       // record
  455.                                                 hwndMenu,
  456.                                                 hwndClient);
  457.                         }
  458.                     }
  459.                 }
  460.             }
  461.         }
  462.         break;
  463.  
  464.         case WM_COMMAND:
  465. /*             switch (SHORT1FROMMP(mp1))
  466.             {
  467.                 case 1001:  // sort by index
  468.                     WinSendMsg(WinWindowFromID(hwndClient, ID_WINLISTCNR),
  469.                                CM_SORTRECORD,
  470.                                (MPARAM)mnu_fnCompareIndex,
  471.                                0);
  472.                 break;
  473.  
  474.                 case 1002:  // sort by source file
  475.                     WinSendMsg(WinWindowFromID(hwndClient, ID_WINLISTCNR),
  476.                                CM_SORTRECORD,
  477.                                (MPARAM)mnu_fnCompareSourceFile,
  478.                                0);
  479.                 break;
  480.             } */
  481.         break;
  482.  
  483.         case WM_CLOSE:
  484.             WinDestroyWindow(WinWindowFromID(hwndClient, ID_WINLISTCNR));
  485.             WinDestroyWindow(WinQueryWindow(hwndClient, QW_PARENT));
  486.         break;
  487.  
  488.         default:
  489.             mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);
  490.     }
  491.  
  492.     return mrc;
  493. }
  494.  
  495. /*
  496.  *@@ winlCreateWinListWindow:
  497.  *
  498.  *@@added V0.9.4 (2000-07-15) [umoeller]
  499.  */
  500.  
  501. HWND winlCreateWinListWindow(VOID)
  502. {
  503.     HWND hwndFrame = NULLHANDLE;
  504.  
  505.     ULONG flStyle = FCF_TITLEBAR | FCF_SYSMENU | FCF_HIDEMAX
  506.                     | FCF_SIZEBORDER | FCF_SHELLPOSITION
  507.                     | FCF_NOBYTEALIGN | FCF_TASKLIST;
  508.     if (WinRegisterClass(WinQueryAnchorBlock(HWND_DESKTOP),
  509.                          "XWPWinList",
  510.                          winl_fnwpWinList, 0L, 0))
  511.     {
  512.         HWND hwndClient;
  513.         if (hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  514.                                            0L,
  515.                                            &flStyle,
  516.                                            "XWPWinList",
  517.                                            "Window List",
  518.                                            0L,
  519.                                            NULLHANDLE,     // resource
  520.                                            0,
  521.                                            &hwndClient))
  522.         {
  523.             WinSetWindowPos(hwndFrame,
  524.                             HWND_TOP,
  525.                             0, 0, 0, 0,
  526.                             SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE);
  527.         }
  528.     }
  529.  
  530.     return (hwndFrame);
  531. }
  532.  
  533.