home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / taman002.zip / TASKMANA.ZIP / src / kModuleContainer.cpp < prev    next >
C/C++ Source or Header  |  2000-04-29  |  13KB  |  434 lines

  1. /* $Id: kModuleContainer.cpp,v 1.1 2000/04/29 19:06:34 stknut Exp $
  2.  *
  3.  * kModuleContainer - generic module container.
  4.  *
  5.  * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  6.  *
  7.  */
  8.  
  9. /*******************************************************************************
  10. *   Defined Constants And Macros                                               *
  11. *******************************************************************************/
  12. #define INCL_WIN
  13. #define INCL_GPI
  14. #define INCL_BASE
  15.  
  16.  
  17. /*******************************************************************************
  18. *   Header Files                                                               *
  19. *******************************************************************************/
  20. #include <os2.h>
  21. #ifdef USE_KLIB
  22.     #include <kAssert.h>
  23.     #include <kLog.h>
  24.     #include <kHeap.h>
  25. #else
  26.     #include <malloc.h>
  27. #endif
  28. #include <memory.h>
  29. #include <string.h>
  30. #include <stddef.h>
  31. #include <stdio.h>
  32.  
  33. #include "kBase.h"
  34. #include "kError.h"
  35. #include "kDlgBase.h"
  36. #include "kMenuBase.h"
  37. #include "kClickDlg.h"
  38. #include "kContainer.h"
  39. #include "kNotebookBase.h"
  40. #include "kNotebookPageBase.h"
  41.  
  42. #include "kQuerySysState.h"
  43. #include "kDetailBase.h"
  44. #include "kModuleRecord.h"
  45. #include "kModuleContainer.h"
  46. #include "kObjectRecord.h"
  47. #include "kObjectContainer.h"
  48. #include "kModuleDetails.h"
  49. #include "kTaskMgr.h"
  50. #include "kTaskMgr_defs.h"
  51.  
  52.  
  53. /**
  54.  * Updates the content of the container if ALL modules are to be included. (hMTE = 0xFFFF)
  55.  * @returns   success indicator.
  56.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  57.  */
  58. BOOL   kModuleContainer::kInsertAllModules()
  59. {
  60.     qsLrec_t *      pCur;
  61.     int             c;
  62.  
  63.     ASSERT(hMTE == 0xFFFF);
  64.  
  65.     /*
  66.      * Loop thru all MTE records and count them
  67.      */
  68.     #if 0
  69.     for (c = 0, pCur = QSGetMteFirstData(); pCur != NULL; pCur = (qsLrec_t*)pCur->pNextRec)
  70.         c++;
  71.     #else
  72.     c = 0;
  73.     pCur = QSGetMteFirstData();
  74.     while (pCur != NULL)
  75.         {
  76.         c++;
  77.         /*
  78.          * Bug detected in OS/2 FP13. Probably a problem which occurs
  79.          * in _LDRSysMteInfo when qsCheckCache is calle before writing
  80.          * object info. The result is that the cache flushed and the
  81.          * attempt of updating the qsLrec_t next and object pointer is
  82.          * not done. This used to work earlier and on Aurora AFAIK.
  83.          *
  84.          * The fix for this problem is to check if the pObjInfo is NULL
  85.          * while the number of objects isn't 0 and correct this. pNextRec
  86.          * will also be NULL at this time. This will be have to corrected
  87.          * before we exit the loop or moves to the next record.
  88.          * There is also a nasty alignment of the object info... Hope
  89.          * I got it right. (This aligment seems new to FP13.)
  90.          */
  91.         if (pCur->pObjInfo == NULL /*&& pCur->pNextRec == NULL*/ && pCur->ctObj != 0)
  92.             {
  93.             pCur->pObjInfo = (qsLObjrec_t*)(
  94.                 (char*)pCur
  95.                 + ((sizeof(qsLrec_t)                     /* size of the lib record */
  96.                    + pCur->ctImpMod * sizeof(short)    /* size of the array of imported modules */
  97.                    + strlen((char*)pCur->pName) + 1    /* size of the filename */
  98.                    + 3) & ~3UL));                          /* the size is align on 4 bytes boundrary */
  99.             pCur->pNextRec = (qsLrec_t*)((char*)pCur->pObjInfo
  100.                                          + sizeof(qsLObjrec_t) * pCur->ctObj);
  101.             }
  102.  
  103.         /* next */
  104.         pCur = (qsLrec_t*)pCur->pNextRec;
  105.         }
  106.  
  107.     #endif
  108.  
  109.     if (c > 0)
  110.     {
  111.         kModuleRecord  *pCurCnrRec, *pCnrRec;
  112.  
  113.         /*
  114.          * Allocate container records for all the MTEs
  115.          */
  116.         pCurCnrRec = pCnrRec = (kModuleRecord*)allocMiniRec(sizeof(kModuleRecord), c);
  117.         if (pCurCnrRec == NULL)
  118.             return FALSE;               /* FIXME: complain about this! */
  119.  
  120.         /*
  121.          * Loop thru the list of processes and update the container.
  122.          */
  123.         pCur = QSGetMteFirstData();
  124.         while (pCur != NULL)
  125.         {
  126.             /*
  127.              * Init and set the record.
  128.              */
  129.             pCurCnrRec->init();
  130.             pCurCnrRec->set(pCur);
  131.  
  132.  
  133.             /* next */
  134.             pCur = (qsLrec_t*)pCur->pNextRec;
  135.             pCurCnrRec = (kModuleRecord*)pCurCnrRec->getNext();
  136.         }
  137.  
  138.         /*
  139.          * Insert the record at bottom of the container.
  140.          */
  141.         return insertAtTop(pCnrRec, c);
  142.     }
  143.  
  144.  
  145.     return TRUE;
  146.  
  147. }
  148.  
  149.  
  150.  
  151.  
  152. /**
  153.  * Inserts the imported module info into the container for it.
  154.  * @returns   success indicator.
  155.  * @param     pMteRec  Pointer to the mte record for the module
  156.  */
  157. BOOL kModuleContainer::kInsertImpModules()
  158. {
  159.     qsLrec_t *pMteRec;
  160.  
  161.     ASSERT(hMTE < 0xFFFF);
  162.  
  163.     /* Find the module indentified by hMTE */
  164.     pMteRec = QSGetMteData(hMTE);
  165.     if (pMteRec != NULL)
  166.     {
  167.         int c = (int)pMteRec->ctImpMod;
  168.         int i;
  169.  
  170.         /* Are there any at all? */
  171.         if (c > 0)
  172.         {
  173.             kModuleRecord * pCnrRec,
  174.                           * pCurCnrRec;
  175.             PUSHORT         pahmte = (PUSHORT)((int)pMteRec + sizeof(qsLrec_t));
  176.  
  177.             /*
  178.              * Allocate container records.
  179.              */
  180.             pCurCnrRec = pCnrRec = (kModuleRecord*)allocMiniRec(sizeof(kModuleRecord), c);
  181.             if (pCurCnrRec == NULL)
  182.                 return FALSE;               /* FIXME - complain about this! */
  183.  
  184.             /*
  185.              * Fill the records with data.
  186.              */
  187.             for (i = 0; i < c; i++, pCurCnrRec = (kModuleRecord*)pCurCnrRec->getNext())
  188.             {
  189.                 qsLrec_t *pMteImpRec;
  190.  
  191.                 /*
  192.                  * Initiate record.
  193.                  */
  194.                 pCurCnrRec->init();
  195.  
  196.                 /*
  197.                  * Get Mte record.
  198.                  */
  199.                 pMteImpRec = QSGetMteData(pahmte[i]);
  200.                 if (pMteImpRec != NULL)
  201.                     pCurCnrRec->set(pMteImpRec);
  202.                 else
  203.                     pCurCnrRec->set(pahmte[i]);
  204.             }
  205.  
  206.             /*
  207.              * Insert records
  208.              */
  209.             return insertAtTop(pCnrRec, c);
  210.         }
  211.     }
  212.     else
  213.         return FALSE;
  214.  
  215.     return TRUE;
  216. }
  217.  
  218.  
  219. /**
  220.  * Menu is closing. Remove emphasis.
  221.  * @param     usMenuId  Menu id.
  222.  * @param     hwndMnu   Handle to menu window.
  223.  */
  224. VOID kModuleContainer::menuEnd(USHORT usMenuId, HWND hwndMnu)
  225. {
  226.     setRecordEmphasis(pCurRecord, FALSE, CRA_SOURCE);
  227.     hwndMnu = hwndMnu;
  228.     usMenuId = usMenuId;
  229. }
  230.  
  231.  
  232. /**
  233.  * Command events.
  234.  * @param     usCmd     Control id which send/posted the message.
  235.  * @param     usSource  Source id.
  236.  * @param     fPointer  Mouse pointer flag.
  237.  * @remark    dismisses the dialog if DID_OK or DID_CANCEL.
  238.  */
  239. VOID  kModuleContainer::command(USHORT usCmd, USHORT usSource, BOOL fPointer)
  240. {
  241.     switch (usCmd)
  242.     {
  243.         case IDM_CNR_MOD_DETAILS:
  244.             if (pCurRecord)
  245.             {
  246.                 try
  247.                 {
  248.                     new kModuleDetails(pCurRecord->gethMte(), hwndCnr)->show();
  249.                 }
  250.                 catch(kError err)
  251.                 {
  252.                     err.logError();
  253.                     err.showError(kTaskMgr::pszErrorTitle);
  254.                 }
  255.             }
  256.             break;
  257.  
  258.         case IDM_CNR_MOD_ALL_REFRESH:
  259.             update();
  260.             break;
  261.  
  262.         case IDM_CNR_MOD_ALL_SORT_HMTE:
  263.         case IDM_CNR_MOD_ALL_SORT_TYPE:
  264.         case IDM_CNR_MOD_ALL_SORT_IMPMODS:
  265.         case IDM_CNR_MOD_ALL_SORT_OBJECTS:
  266.         case IDM_CNR_MOD_ALL_SORT_NAME:
  267.             if (usSortId != usCmd)
  268.             {
  269.                 usSortId = usCmd;
  270.                 pMenuCnrAll->checkMenuItem(IDM_CNR_MOD_ALL_SORT_HMTE   , usCmd == IDM_CNR_MOD_ALL_SORT_HMTE);
  271.                 pMenuCnrAll->checkMenuItem(IDM_CNR_MOD_ALL_SORT_TYPE   , usCmd == IDM_CNR_MOD_ALL_SORT_TYPE);
  272.                 pMenuCnrAll->checkMenuItem(IDM_CNR_MOD_ALL_SORT_IMPMODS, usCmd == IDM_CNR_MOD_ALL_SORT_IMPMODS);
  273.                 pMenuCnrAll->checkMenuItem(IDM_CNR_MOD_ALL_SORT_OBJECTS, usCmd == IDM_CNR_MOD_ALL_SORT_OBJECTS);
  274.                 pMenuCnrAll->checkMenuItem(IDM_CNR_MOD_ALL_SORT_NAME   , usCmd == IDM_CNR_MOD_ALL_SORT_NAME);
  275.  
  276.                 /* resort container */
  277.                 enableSorting();
  278.             }
  279.             else
  280.             {
  281.                 usSortId = 0xFFFF;
  282.                 disableSorting();
  283.                 pMenuCnrAll->checkMenuItem(usCmd, FALSE);
  284.             }
  285.             break;
  286.  
  287.     }
  288.  
  289.     usSource = usSource;
  290.     fPointer = fPointer;
  291. }
  292.  
  293.  
  294. /**
  295.  * Record sort callback function - compares two records.
  296.  * @returns   >  0  when pRecord1  >  pRecord2
  297.  *            <  0  when pRecord1  <  pRecord2
  298.  *            == 0  when pRecord1 ==  pRecord2
  299.  * @param     pRecord1  Pointer to first record.
  300.  * @param     pRecord2  Pointer to second record.
  301.  */
  302. SHORT  kModuleContainer::sortCallBack(kCnrMiniRecord *pRecord1, kCnrMiniRecord *pRecord2)
  303. {
  304.     kModuleRecord * pRec1 = (kModuleRecord *)pRecord1;
  305.     kModuleRecord * pRec2 = (kModuleRecord *)pRecord2;
  306.  
  307.     if (pRec1 != NULL && pRec2 != NULL)
  308.     {
  309.         int iTmp = 1;
  310.         switch (usSortId)
  311.         {
  312.             case IDM_CNR_MOD_ALL_SORT_HMTE:
  313.                 iTmp = pRec1->gethMte() - pRec2->gethMte();
  314.                 break;
  315.  
  316.             case IDM_CNR_MOD_ALL_SORT_TYPE:
  317.                 iTmp = strcmp(pRec1->getType(), pRec2->getType());
  318.                 break;
  319.  
  320.             case IDM_CNR_MOD_ALL_SORT_IMPMODS:
  321.                 iTmp = strcmp(pRec1->getImpMods(), pRec2->getImpMods());
  322.                 break;
  323.  
  324.             case IDM_CNR_MOD_ALL_SORT_OBJECTS:
  325.                 iTmp = strcmp(pRec1->getObjects(), pRec2->getObjects());
  326.                 break;
  327.  
  328.             case IDM_CNR_MOD_ALL_SORT_NAME:
  329.                 iTmp = strcmp(pRec1->getName(), pRec2->getName());
  330.                 break;
  331.         }
  332.         return (SHORT)((iTmp > 0) ? 1 : (iTmp < 0) ? -1 : 0);
  333.     }
  334.     return 1;
  335. }
  336.  
  337.  
  338.  
  339. /**
  340.  * Constructor.
  341.  * @returns
  342.  * @param     hwndDlg   Handle to dialog window.
  343.  * @param     ulCnrId   ID of the container dialog item in hwndDlg.
  344.  * @param     hMte      hMTE = 0xFFFF:  View all modules
  345.  *                      hMTE < 0xFFFF: View dependants of this module
  346.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  347.  */
  348. kModuleContainer::kModuleContainer(HWND hwndDlg, ULONG ulCnrId, USHORT hMTE/* = 0xFFFF*/) throw(kError)
  349.     : kDetailCnr(WinWindowFromID(hwndDlg, ulCnrId),
  350.                  0,
  351.                  hMTE == 0xFFFF ? "Executable Module Overview" : "Imported Modules",
  352.                  kModuleRecord::cFieldInfo,
  353.                  (PFIELDINFO)&kModuleRecord::aFieldInfo[0]),
  354.     hMTE(hMTE), pCurRecord(NULL)
  355. {
  356.     /*
  357.      * Create menus.
  358.      */
  359.     pMenuModule = new kMenuBase(IDM_CNR_MODULE, NULLHANDLE, hwndCnr, TRUE);
  360.     pMenuCnrAll = new kMenuBase(IDM_CNR_MODULE_ALL, NULLHANDLE, hwndCnr, TRUE);
  361. }
  362.  
  363.  
  364. /**
  365.  * Destructor.
  366.  */
  367. kModuleContainer::~kModuleContainer()
  368. {
  369.     if (pMenuModule != NULL)
  370.         delete pMenuModule;
  371.     if (pMenuCnrAll != NULL)
  372.         delete pMenuCnrAll;
  373. }
  374.  
  375.  
  376. /**
  377.  * Displays the popup menu for the container.
  378.  * @param     usId     Container id.
  379.  * @param     pRecord  Pointer to the record which is selected by either the key
  380.  */
  381. VOID kModuleContainer::cnrContextMenu(USHORT usId, PRECORDCORE pRecord)
  382. {
  383.     if (pMenuModule && pMenuCnrAll)
  384.     {
  385.         pCurRecord = (kModuleRecord*)pRecord;
  386.         setRecordEmphasis(pCurRecord, TRUE, CRA_SOURCE);
  387.         if (pRecord != NULL)
  388.             pMenuModule->popup();
  389.         else
  390.             pMenuCnrAll->popup();
  391.     }
  392.     usId = usId;
  393. }
  394.  
  395.  
  396. /**
  397.  * Enter or double click on record in the container.
  398.  * This action will bring up the detail dialog for the record.
  399.  */
  400. VOID kModuleContainer::cnrEnter(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, ULONG fKey)
  401. {
  402.     if (pRecord != NULL)
  403.     {
  404.         pCurRecord = (kModuleRecord*)pRecord;
  405.         command(IDM_CNR_MOD_DETAILS, 0, 0);
  406.     }
  407.     usId = usId;
  408.     fKey = fKey;
  409.     hwndCnr = hwndCnr;
  410. }
  411.  
  412.  
  413.  
  414. /**
  415.  * Updates the contents of the container.
  416.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  417.  */
  418. VOID  kModuleContainer::update()
  419. {
  420.     /*
  421.      * Delete all records in the container!
  422.      */
  423.     removeAllRecords();
  424.  
  425.     /*
  426.      * Insert records
  427.      */
  428.     if (hMTE == 0xFFFF)
  429.         kInsertAllModules();
  430.     else
  431.         kInsertImpModules();
  432. }
  433.  
  434.