Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
6.1 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Matrix Array
  4. //
  5. //------------------------------------------------------------------------
  6. #ifndef _MTXARRAY_H_
  7. #define _MTXARRAY_H_
  8. #include "iface.h" // for APPCMD_*
  9. #include "worker.h"
  10. #include "setupenum.h" // for COCSetup* classes
  11. #include "simpdata.h" // for OLEDB
  12. // Areas that this control can enumerate
  13. // Warning: Please do not change these numbers, they are also used
  14. // as array indexes.
  15. #define ENUM_INSTALLED 0 // installed apps
  16. #define ENUM_PUBLISHED 1 // published apps
  17. #define ENUM_CATEGORIES 2 // published categories
  18. #define ENUM_OCSETUP 3 // Optional components selected during setup
  19. #define ENUM_UNKNOWN 0xffffffff
  20. // Sort indexes
  21. #define SORT_NA (-1) // n/a
  22. #define SORT_NAME 0 // sort by name
  23. #define SORT_SIZE 1 // sort by size
  24. #define SORT_TIMESUSED 2 // sort by frequency of use
  25. #define SORT_LASTUSED 3 // sort by last used date
  26. typedef struct tagAPPFIELDS
  27. {
  28. LPWSTR pszLabel;
  29. DWORD dwSort; // can be SORT_*
  30. DWORD dwStruct; // IFS_*
  31. VARTYPE vt; // field type
  32. DWORD ibOffset; // offset into structure designated by dwStruct
  33. } APPFIELDS;
  34. // REARCHITECT: (dli) We should have just one base CAppData class and installed, published,
  35. // categories and OCSetup should derives from it.
  36. // CAppData
  37. class CAppData : public IAppData
  38. {
  39. public:
  40. // *** IUnknown ***
  41. STDMETHOD_(ULONG, AddRef) (void);
  42. STDMETHOD_(ULONG, Release) (void);
  43. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppvObj);
  44. // *** IAppData ***
  45. STDMETHOD(DoCommand) (HWND hwndParent, APPCMD appcmd);
  46. STDMETHOD(ReadSlowData) (void);
  47. STDMETHOD(GetVariant) (DB_LORDINAL iField, VARIANT * pvar);
  48. STDMETHOD(SetMtxParent) (IMtxArray * pmtxParent);
  49. STDMETHOD_(APPINFODATA *, GetDataPtr)(void);
  50. STDMETHOD_(SLOWAPPINFO *, GetSlowDataPtr)(void);
  51. STDMETHOD(GetFrequencyOfUse)(LPWSTR pszBuf, int cchBuf);
  52. STDMETHOD(SetNameDupe) (BOOL bDupe) {_bNameDupe = bDupe; return S_OK;};
  53. // Overloaded constructors
  54. CAppData(IInstalledApp* pia, APPINFODATA* paid, PSLOWAPPINFO psai);
  55. CAppData(IPublishedApp* ppa, APPINFODATA* paid, PUBAPPINFO * ppai);
  56. CAppData(SHELLAPPCATEGORY * psac);
  57. CAppData(COCSetupApp * pocsa, APPINFODATA* paid);
  58. ~CAppData();
  59. private:
  60. HRESULT _GetInstField(DB_LORDINAL iField, VARIANT * pvar);
  61. HRESULT _GetPubField(DB_LORDINAL iField, VARIANT * pvar);
  62. HRESULT _GetSetupField(DB_LORDINAL iField, VARIANT * pvar);
  63. HRESULT _GetCatField(DB_LORDINAL iField, VARIANT * pvar);
  64. LPTSTR _BuildSupportInfo(void);
  65. LPTSTR _BuildPropertiesHTML(void);
  66. void _GetIconHTML(LPTSTR pszIconHTML, UINT cch);
  67. HRESULT _VariantFromData(const APPFIELDS * pfield, LPVOID pvData, VARIANT * pvar);
  68. DWORD _GetCapability();
  69. HRESULT _GetDiskSize(LPTSTR pszBuf, int cchBuf);
  70. HRESULT _GetLastUsed(LPTSTR pszBuf, int cchBuf);
  71. DWORD _GetSortIndex(void);
  72. void _MassageSlowAppInfo(void);
  73. LONG _cRef;
  74. union
  75. {
  76. IInstalledApp* _pia;
  77. IPublishedApp* _ppa;
  78. SHELLAPPCATEGORY * _psac;
  79. COCSetupApp * _pocsa;
  80. };
  81. APPINFODATA _ai;
  82. PUBAPPINFO _pai; // Published app specific info
  83. SLOWAPPINFO _aiSlow;
  84. IMtxArray * _pmtxParent;
  85. DWORD _dwEnum; // Can be ENUM_*
  86. BOOL _bNameDupe; // Has a duplicate name with other apps
  87. CRITICAL_SECTION _cs; // NOTE: only used for Installed Apps.
  88. BOOL _fCsInitialized; // Was the critical section initialized
  89. };
  90. // EnumAppItems callback
  91. typedef void (CALLBACK *ENUMAPPITEMSCB)(IAppData * pappdata, LPARAM lParam);
  92. HRESULT EnumAppItems(DWORD dwEnum, LPCWSTR pszCategory, IShellAppManager * pam, ENUMAPPITEMSCB pfnCallback, LPARAM lpContext);
  93. //------------------------------------------------------------------------
  94. //
  95. // Matrix Array
  96. //
  97. // This object maintains the array of data. It knows how to map
  98. // ordinal row/column references to the actual records and fields
  99. // kept in the array. The base class supplies all the necessary
  100. // methods as virtuals, and derived classes allow for arrays of:
  101. //
  102. // - installed apps
  103. // - published apps
  104. // - publishing categories
  105. //
  106. //------------------------------------------------------------------------
  107. class CMtxArray2 : public IMtxArray,
  108. public CWorkerThread
  109. {
  110. public:
  111. // *** IUnknown ***
  112. virtual STDMETHODIMP_(ULONG) AddRef (void) {return CWorkerThread::AddRef();};
  113. virtual STDMETHODIMP_(ULONG) Release (void) {return CWorkerThread::Release();};
  114. virtual STDMETHODIMP QueryInterface (REFIID riid, LPVOID * ppvObj);
  115. // *** IMtxArray ***
  116. STDMETHOD(Initialize) (DWORD dwEnum);
  117. STDMETHOD(AddItem) (IAppData * pappdata, DBROWCOUNT * piRow);
  118. STDMETHOD(DeleteItems) (DBROWCOUNT iRow, DBROWCOUNT cRows);
  119. STDMETHOD(GetAppData) (DBROWCOUNT iRow, IAppData ** ppappdata);
  120. STDMETHOD(GetItemCount) (DBROWCOUNT * pcItems);
  121. STDMETHOD(GetFieldCount) (DB_LORDINAL * pcFields);
  122. STDMETHOD(GetFieldName) (DB_LORDINAL iField, VARIANT * pvar);
  123. STDMETHOD(GetSortIndex) (DWORD * pdwSort);
  124. STDMETHOD(SortItems) (void);
  125. STDMETHOD(SetSortCriteria) (LPCWSTR pszSortField);
  126. STDMETHOD_(int,CompareItems)(IAppData * pappdata1, IAppData * pappdata2);
  127. STDMETHOD(MarkDupEntries) (void);
  128. // *** IARPWorker methods *** (override)
  129. STDMETHOD(KillWT) (void);
  130. CMtxArray2();
  131. ~CMtxArray2();
  132. static int s_SortItemsCallbackWrapper(LPVOID pv1, LPVOID pv2, LPARAM lParam);
  133. protected:
  134. HRESULT _DeleteItem(DBROWCOUNT idpa);
  135. HRESULT _CreateArray(void);
  136. DWORD _ThreadStartProc();
  137. void _Lock(void);
  138. void _Unlock(void);
  139. CRITICAL_SECTION _cs;
  140. DEBUG_CODE( LONG _cRefLock; )
  141. HDPA _hdpa; // the data is here
  142. DWORD _dwEnum;
  143. DWORD _dwSort; // can be SORT_*
  144. };
  145. HRESULT CMtxArray_CreateInstance(REFIID riid, LPVOID * ppvObj);
  146. #endif // _MTXARRAY_H_