ext.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //-------------------------------------------------------------------------//
  2. // ext.h : CShellExt decl
  3. //-------------------------------------------------------------------------//
  4. #ifndef __SHELLEXT_H_
  5. #define __SHELLEXT_H_
  6. #include "resource.h"       // resource symbols
  7. #include "prioritylst.h"
  8. #include "shdocext.h"      // CLSID_ShDocPropExt
  9. #include "ptserver.h"      // PROPERTYITEM, etc.
  10. class CPage0;
  11. interface IPropertyServer;
  12. extern const TCHAR szEXTENSION_SETTINGS_REGKEY[];
  13. extern const TCHAR szUIMODE_REGVAL[];
  14. //-------------------------------------------------------------------------//
  15. //  Error context identifiers
  16. enum ERROR_CONTEXT
  17. {
  18.     ERRCTX_ALL,
  19.     ERRCTX_ACQUIRE,
  20.     ERRCTX_PERSIST_APPLY,
  21.     ERRCTX_PERSIST_OK,
  22. };
  23. typedef struct _TARGET
  24. {
  25.     VARIANT  varFile;
  26.     FILETIME ftAccess;
  27. } TARGET;
  28. //  Helper to restore access time to a specified target.
  29. HRESULT _RestoreAccessTime( const TARGET& t ) ;
  30. //-------------------------------------------------------------------------//
  31. //  class CFileList - collection of property source specifiers
  32. typedef TPriorityList<TARGET> CFileListBase;
  33. class CFileList : public CFileListBase
  34. //-------------------------------------------------------------------------//
  35. {
  36. public:
  37.     CFileList() : CFileListBase( 4 /*block size*/ )  {}
  38.     virtual void OnFreeElement( TARGET& t ) {
  39.         VariantClear( &t.varFile );
  40.     }
  41. };
  42. //-------------------------------------------------------------------------//
  43. //  Property attribute array indices; must be zero-based and consecutive,
  44. //  grouped by FMTIDs.
  45. enum BASICPROPERTY
  46. {
  47.     //  FMTID_SummaryInformation
  48.     BASICPROP_TITLE = 0,
  49.     BASICPROP_SUBJECT,
  50.     BASICPROP_AUTHOR,
  51.     BASICPROP_KEYWORDS,
  52.     BASICPROP_COMMENTS,
  53.     //  FMTID_DocSummaryInformation
  54.     BASICPROP_CATEGORY,
  55.     BASICPROP_COUNT,  // placeholder
  56. };
  57. #define BASICPROP_SUMMARYINFO_FIRST       BASICPROP_TITLE
  58. #define BASICPROP_SUMMARYINFO_LAST        BASICPROP_COMMENTS
  59. #define BASICPROP_DOCSUMMARYINFO_FIRST    BASICPROP_CATEGORY
  60. #define BASICPROP_DOCSUMMARYINFO_LAST     BASICPROP_CATEGORY
  61. //-------------------------------------------------------------------------//
  62. class CBasicPropertySource  // basic property block.
  63. //-------------------------------------------------------------------------//
  64. {
  65. public:
  66.     CBasicPropertySource();
  67.     ~CBasicPropertySource() { Free(); }
  68.     HRESULT Acquire( const VARIANT* pvarSource );
  69.     HRESULT Persist();
  70.     int     Compare( BASICPROPERTY nProp, CBasicPropertySource* pOther );
  71.     BSTR    MakeDisplayString( BASICPROPERTY nProp );
  72.     void    Free();
  73.     HRESULT SetPropertyValue( BASICPROPERTY nProp, IN BSTR bstrValue );
  74.     void    SetDirty( BASICPROPERTY nProp, BOOL bDirty );
  75. protected:
  76.     VARIANT               _varSource;
  77.     IBasicPropertyServer* _pbps;
  78.     BASICPROPITEM*        _rgItems;
  79. };
  80. //-------------------------------------------------------------------------//
  81. //  BUGBUG: until DocSummaryInformation propids are defined in a public header...
  82. #define PIDDSI_CATEGORY 0x00000002
  83. //-------------------------------------------------------------------------//
  84. //  class CShellExt - shell extension object, CLSID_
  85. class ATL_NO_VTABLE CShellExt : 
  86. public CComObjectRootEx<CComSingleThreadModel>,
  87. public CComCoClass<CShellExt, &CLSID_ShDocPropExt>,
  88.     public IShellExtInit,
  89. public IShellPropSheetExt
  90. //-------------------------------------------------------------------------//
  91. {
  92. public:
  93. //  IShellExtInit methods
  94.     HRESULT STDMETHODCALLTYPE Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID );
  95. //  IShellPropSheetExt methods
  96.     HRESULT STDMETHODCALLTYPE AddPages( LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam );
  97.     HRESULT STDMETHODCALLTYPE ReplacePage( UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplacePage, LPARAM lParam );
  98. //  Implementation:
  99. public:
  100. CShellExt();
  101.     virtual ~CShellExt();
  102.     BOOL        HasAdvancedProperties() { return m_fAdvancedProperties; }
  103.     BOOL        HasBasicProperties() { return m_fBasicProperties; }
  104.     CFileList&  FileList()   { return m_filelist; }
  105.     BOOL        GetBasicPropFromIDC( UINT nIDC, BASICPROPERTY* pnProp ) const;
  106.     BOOL        GetBasicPropInfo( BASICPROPERTY nProp, OUT const FMTID*& pFmtid, OUT PROPID& nPropID, OUT VARTYPE& vt );
  107.     static BOOL GetBasicPropInfo( REFFMTID fmtid, OUT int&, OUT int&, OUT int& );
  108.     UINT        ReadOnlyCount() const;
  109.     BOOL        IsCompositeMismatch( BASICPROPERTY nProp ) const;
  110.     BOOL        IsDirty( BASICPROPERTY nProp ) const;
  111.     BOOL        IsDirty() const;
  112.     void        SetDirty( BASICPROPERTY nProp, BOOL bDirty );
  113.     void        SetDirty( BOOL bDirty );
  114.     void        ChangeNotify( LONG wEventID );
  115.     void        RestoreAccessTimes();
  116.     int         DisplayError( HWND hwndOwner, UINT nIDCaption, ERROR_CONTEXT errctx, HRESULT hr );
  117.     void        CacheUIValue( HWND hwndPage, BASICPROPERTY nProp );
  118.     void        CacheUIValues( HWND hwndPage );
  119.     void        UncacheUIValue( HWND hwndPage, BASICPROPERTY nProp );
  120.     void        UncacheUIValues( HWND hwndPage );
  121.     int         GetMaxPropertyTextLength( HWND hwndPage );
  122.     BOOL        GetPropertyText( HWND hwndPage, BASICPROPERTY nProp, LPTSTR pszBuf, int cchBuf );
  123.     void        SetPropertyText( HWND hwndDlg, BASICPROPERTY nProp, LPCTSTR pszText );
  124.     STDMETHOD( Persist )();
  125.     void        FinalRelease();
  126. protected:
  127.     static HRESULT 
  128.                 FilterFileFindData(LPCTSTR, WIN32_FIND_DATA*);
  129.     BOOL        IsSourceSupported( LPTSTR pszPath, BOOL bAdvanced, OUT OPTIONAL LPCLSID pclsid = NULL );
  130.     void        CacheDisplayText( BASICPROPERTY nProp, LPCTSTR pszText );
  131.     STDMETHOD( Acquire )();
  132. public:
  133.     DECLARE_REGISTRY_RESOURCEID( IDR_SHELLEXT )
  134.     BEGIN_COM_MAP(CShellExt)
  135.     COM_INTERFACE_ENTRY(IShellExtInit)
  136.     COM_INTERFACE_ENTRY(IShellPropSheetExt)
  137.     END_COM_MAP()
  138. //  Data
  139. protected:
  140.     CFileList             m_filelist;
  141.     CBasicPropertySource* m_rgBasicSrc;        // array of basic property sources
  142.     CPage0*               m_pPage0;
  143.     BSTR             m_rgbstrDisplay[BASICPROP_COUNT]; // cached display text
  144.     ULONG            m_rgvarFlags[BASICPROP_COUNT]; // attributes of cached values
  145.     UINT             m_cReadOnly;              // count of read-only property sources
  146.     BOOL             m_rgbDirty[BASICPROP_COUNT];  // dirty flags
  147.     BOOL             m_fAdvancedProperties;               // 'Advanced' button enabled
  148.     BOOL             m_fBasicProperties;                  // 'Basic' button enabled
  149. };
  150. //-------------------------------------------------------------------------//
  151. inline BOOL CShellExt::IsDirty( BASICPROPERTY nProp ) const   {
  152.     return m_rgbDirty[nProp];
  153. }
  154. //-------------------------------------------------------------------------//
  155. inline BOOL CShellExt::IsDirty() const  {
  156.     for( int i=0; i<BASICPROP_COUNT; i++ )
  157.         if( IsDirty( (BASICPROPERTY)i ) )
  158.             return TRUE;
  159.     return FALSE;
  160. }
  161. //-------------------------------------------------------------------------//
  162. //  Sets or clears dirty flags
  163. inline void CShellExt::SetDirty( BOOL bDirty )  {
  164.     for( int i=0; i<BASICPROP_COUNT; i++ )
  165.         SetDirty( (BASICPROPERTY)i, bDirty );
  166. }
  167. inline UINT CShellExt::ReadOnlyCount() const {
  168.     return m_cReadOnly;
  169. }
  170. #endif //__SHELLEXT_H_