home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / ctlimpl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  13.8 KB  |  453 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef __CTLIMPL_H__
  12. #define __CTLIMPL_H__
  13.  
  14. // MFC data definition for data exported from the runtime DLL
  15.  
  16. #undef AFX_DATA
  17. #define AFX_DATA AFX_OLE_DATA
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Codes for COleControl::SendAdvise
  21. //......Code.........................Method called
  22. #define OBJECTCODE_SAVED          0  //IOleAdviseHolder::SendOnSave
  23. #define OBJECTCODE_CLOSED         1  //IOleAdviseHolder::SendOnClose
  24. #define OBJECTCODE_RENAMED        2  //IOleAdviseHolder::SendOnRename
  25. #define OBJECTCODE_SAVEOBJECT     3  //IOleClientSite::SaveObject
  26. #define OBJECTCODE_DATACHANGED    4  //IDataAdviseHolder::SendOnDataChange
  27. #define OBJECTCODE_SHOWWINDOW     5  //IOleClientSite::OnShowWindow(TRUE)
  28. #define OBJECTCODE_HIDEWINDOW     6  //IOleClientSite::OnShowWindow(FALSE)
  29. #define OBJECTCODE_SHOWOBJECT     7  //IOleClientSite::ShowObject
  30. #define OBJECTCODE_VIEWCHANGED    8  //IOleAdviseHolder::SendOnViewChange
  31.  
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Typedefs
  35.  
  36. typedef LPVOID* LPLPVOID;
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Functions
  40.  
  41. LPSTREAM AFXAPI _AfxGetArchiveStream(CArchive& ar, CArchiveStream& stm);
  42. CLIPFORMAT AFXAPI _AfxGetClipboardFormatConvertVBX();
  43. CLIPFORMAT AFXAPI _AfxGetClipboardFormatPersistPropset();
  44. BOOL AFXAPI _AfxOleMatchPropsetClipFormat(CLIPFORMAT cfFormat, LPCLSID lpFmtID);
  45. BOOL AFXAPI _AfxCopyPropValue(VARTYPE vtProp, void* pvDest, const void * pvSrc);
  46. BOOL AFXAPI _AfxPeekAtClassIDInStream(LPSTREAM pstm, LPCLSID lpClassID);
  47. BOOL AFXAPI _AfxIsSamePropValue(VARTYPE vtProp, const void* pv1, const void* pv2);
  48. BOOL AFXAPI _AfxIsSameFont(CFontHolder& font, const FONTDESC* pFontDesc,
  49.     LPFONTDISP pFontDispAmbient);
  50. BOOL AFXAPI _AfxIsSameUnknownObject(REFIID iid, LPUNKNOWN pUnk1, LPUNKNOWN pUnk2);
  51. BOOL AFXAPI _AfxInitBlob(HGLOBAL* phDst, void* pvSrc);
  52. BOOL AFXAPI _AfxCopyBlob(HGLOBAL* phDst, HGLOBAL hSrc);
  53. LPFONT AFXAPI _AfxCreateFontFromStream(LPSTREAM);
  54. BOOL AFXAPI _AfxTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew);
  55. void AFXAPI _AfxXformSizeInPixelsToHimetric(HDC, LPSIZEL, LPSIZEL);
  56. void AFXAPI _AfxXformSizeInHimetricToPixels(HDC, LPSIZEL, LPSIZEL);
  57. void AFXAPI _AfxDrawBorders(CDC* pDC, CRect& rc, BOOL bBorder, BOOL bClientEdge);
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // _AFXCTL_ADVISE_INFO - Information about an advise sink
  61.  
  62. struct _AFXCTL_ADVISE_INFO
  63. {
  64.     DWORD m_dwAspects;
  65.     DWORD m_dwAdvf;
  66.     LPADVISESINK m_pAdvSink;
  67.  
  68.     _AFXCTL_ADVISE_INFO() : m_dwAspects(0), m_dwAdvf(0), m_pAdvSink(NULL) {}
  69. };
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // _AFXCTL_AMBIENT_CACHE - cache of common ambient property values
  73.  
  74. class _AFXCTL_AMBIENT_CACHE : public CNoTrackObject
  75. {
  76. // Constructor
  77. public:
  78.     _AFXCTL_AMBIENT_CACHE();
  79.  
  80. // Attributes
  81.     BOOL m_bValid;
  82.     DWORD m_dwAmbientFlags;
  83.     OLE_COLOR m_colorFore;
  84.     OLE_COLOR m_colorBack;
  85.     IFont* m_pFont;
  86.     void* m_pReserved;
  87.     DWORD m_dwAppearance;
  88.  
  89. // Operations
  90.     void Cache(QACONTAINER* pQAContainer);
  91. };
  92.  
  93. EXTERN_THREAD_LOCAL(_AFXCTL_AMBIENT_CACHE, _afxAmbientCache)
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CControlFrameWnd - used for a control's "open" (non-in-place) state.
  97.  
  98. class CControlFrameWnd : public CWnd
  99. {
  100. public:
  101.     CControlFrameWnd(COleControl* pCtrl);
  102.     virtual BOOL Create(LPCTSTR pszTitle);
  103.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  104.  
  105. protected:
  106.     virtual void PostNcDestroy();
  107.  
  108.     COleControl* m_pCtrl;
  109.  
  110.     //{{AFX_MSG(CControlFrameWnd)
  111.     afx_msg void OnClose();
  112.     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  113.     //}}AFX_MSG
  114.     DECLARE_MESSAGE_MAP()
  115. };
  116.  
  117.  
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CReflectorWnd - reflects window messages to a subclassed control.
  120.  
  121. class CReflectorWnd : public CWnd
  122. {
  123. public:
  124.     CReflectorWnd() : m_pCtrl(NULL) { }
  125.  
  126.     BOOL Create(const CRect& rect, HWND hWndParent);
  127.     void SetControl(COleControl* pCtrl);
  128.  
  129. protected:
  130.     virtual LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  131.     virtual void PostNcDestroy();
  132.  
  133.     COleControl* m_pCtrl;
  134. };
  135.  
  136.  
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CParkingWnd - "parking space" for not-yet-activated subclassed controls
  139.  
  140. class CParkingWnd : public CWnd
  141. {
  142. public:
  143.     CParkingWnd()
  144.         { AfxDeferRegisterClass(AFX_WNDOLECONTROL_REG);
  145.           CreateEx(WS_EX_NOPARENTNOTIFY|WS_EX_TOOLWINDOW,
  146.             AFX_WNDOLECONTROL, NULL, WS_VISIBLE|WS_CHILD,
  147.             -1000, -1000, 1, 1, ::GetDesktopWindow(), 0); }
  148.     virtual LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  149.  
  150. protected:
  151.     CMapPtrToPtr m_idMap;
  152. };
  153.  
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. //  Property sets
  157.  
  158. typedef struct tagSECTIONHEADER
  159. {
  160.     DWORD       cbSection ;
  161.     DWORD       cProperties ;  // Number of props.
  162. } SECTIONHEADER, *LPSECTIONHEADER ;
  163.  
  164. typedef struct tagPROPERTYIDOFFSET
  165. {
  166.     DWORD       propertyID;
  167.     DWORD       dwOffset;
  168. } PROPERTYIDOFFSET, *LPPROPERTYIDOFFSET;
  169.  
  170. typedef struct tagPROPHEADER
  171. {
  172.     WORD        wByteOrder ;    // Always 0xFFFE
  173.     WORD        wFormat ;       // Always 0
  174.     DWORD       dwOSVer ;       // System version
  175.     CLSID       clsID ;         // Application CLSID
  176.     DWORD       cSections ;     // Number of sections (must be at least 1)
  177. } PROPHEADER, *LPPROPHEADER ;
  178.  
  179. typedef struct tagFORMATIDOFFSET
  180. {
  181.     GUID        formatID;
  182.     DWORD       dwOffset;
  183. } FORMATIDOFFSET, *LPFORMATIDOFFSET;
  184.  
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CProperty
  188.  
  189. class CProperty
  190. {
  191.     friend class CPropertySet ;
  192.     friend class CPropertySection ;
  193.  
  194. public:
  195. // Construction
  196.     CProperty( void ) ;
  197.     CProperty( DWORD dwID, const LPVOID pValue, DWORD dwType ) ;
  198.  
  199. // Attributes
  200.     BOOL    Set( DWORD dwID, const LPVOID pValue, DWORD dwType ) ;
  201.     BOOL    Set( const LPVOID pValue, DWORD dwType ) ;
  202.     BOOL    Set( const LPVOID pValue ) ;
  203.     LPVOID  Get( DWORD* pcb ) ;     // Returns pointer to actual value
  204.     LPVOID  Get( void ) ;           // Returns pointer to actual value
  205.     DWORD   GetType( void ) ;       // Returns property type
  206.     void    SetType( DWORD dwType ) ;
  207.     DWORD   GetID( void ) ;
  208.     void    SetID( DWORD dwPropID ) ;
  209.  
  210.     LPVOID  GetRawValue( void ) ;   // Returns pointer internal value (may
  211.                                     // include size information)
  212. // Operations
  213.     BOOL    WriteToStream( IStream* pIStream ) ;
  214.     BOOL    ReadFromStream( IStream* pIStream ) ;
  215.  
  216. private:
  217.     DWORD       m_dwPropID ;
  218.     DWORD       m_dwType ;
  219.     LPVOID      m_pValue ;
  220.  
  221.     LPVOID  AllocValue(ULONG cb);
  222.     void    FreeValue();
  223.  
  224. public:
  225.     ~CProperty() ;
  226. } ;
  227.  
  228.  
  229. /////////////////////////////////////////////////////////////////////////////
  230. // CPropertySection
  231.  
  232. class CPropertySection
  233. {
  234.     friend class CPropertySet ;
  235.     friend class CProperty ;
  236.  
  237. public:
  238. // Construction
  239.     CPropertySection( void ) ;
  240.     CPropertySection( CLSID FormatID ) ;
  241.  
  242. // Attributes
  243.     CLSID   GetFormatID( void ) ;
  244.     void    SetFormatID( CLSID FormatID ) ;
  245.  
  246.     BOOL    Set( DWORD dwPropID, LPVOID pValue, DWORD dwType ) ;
  247.     BOOL    Set( DWORD dwPropID, LPVOID pValue ) ;
  248.     LPVOID  Get( DWORD dwPropID, DWORD* pcb ) ;
  249.     LPVOID  Get( DWORD dwPropID ) ;
  250.     void    Remove( DWORD dwPropID ) ;
  251.     void    RemoveAll() ;
  252.  
  253.     CProperty* GetProperty( DWORD dwPropID ) ;
  254.     void AddProperty( CProperty* pProp ) ;
  255.  
  256.     DWORD   GetSize( void ) ;
  257.     DWORD   GetCount( void ) ;
  258.     CPtrList* GetList( void ) ;
  259.  
  260.     BOOL    GetID( LPCTSTR pszName, DWORD* pdwPropID ) ;
  261.     BOOL    SetName( DWORD dwPropID, LPCTSTR pszName ) ;
  262.  
  263.     BOOL    SetSectionName( LPCTSTR pszName );
  264.     LPCTSTR GetSectionName( void );
  265.  
  266. // Operations
  267.     BOOL    WriteToStream( IStream* pIStream ) ;
  268.     BOOL    ReadFromStream( IStream* pIStream, LARGE_INTEGER liPropSet ) ;
  269.     BOOL    WriteNameDictToStream( IStream* pIStream ) ;
  270.     BOOL    ReadNameDictFromStream( IStream* pIStream ) ;
  271.  
  272. private:
  273. // Implementation
  274.     CLSID           m_FormatID ;
  275.     SECTIONHEADER   m_SH ;
  276.     // List of properties (CProperty)
  277.     CPtrList         m_PropList ;
  278.     // Dictionary of property names
  279.     CMapStringToPtr m_NameDict ;
  280.     CString         m_strSectionName;
  281.  
  282. public:
  283.     ~CPropertySection();
  284. } ;
  285.  
  286.  
  287. /////////////////////////////////////////////////////////////////////////////
  288. // CPropertySet
  289.  
  290. class CPropertySet
  291. {
  292.     friend class CPropertySection ;
  293.     friend class CProperty ;
  294.  
  295. public:
  296. // Construction
  297.     CPropertySet( void ) ;
  298.     CPropertySet( CLSID clsID )  ;
  299.  
  300. // Attributes
  301.     BOOL    Set( CLSID FormatID, DWORD dwPropID, LPVOID pValue, DWORD dwType ) ;
  302.     BOOL    Set( CLSID FormatID, DWORD dwPropID, LPVOID pValue ) ;
  303.     LPVOID  Get( CLSID FormatID, DWORD dwPropID, DWORD* pcb ) ;
  304.     LPVOID  Get( CLSID FormatID, DWORD dwPropID ) ;
  305.     void    Remove( CLSID FormatID, DWORD dwPropID ) ;
  306.     void    Remove( CLSID FormatID ) ;
  307.     void    RemoveAll( ) ;
  308.  
  309.     CProperty* GetProperty( CLSID FormatID, DWORD dwPropID ) ;
  310.     void AddProperty( CLSID FormatID, CProperty* pProp ) ;
  311.     CPropertySection* GetSection( CLSID FormatID ) ;
  312.     CPropertySection* AddSection( CLSID FormatID ) ;
  313.     void AddSection( CPropertySection* psect ) ;
  314.  
  315.     WORD    GetByteOrder( void ) ;
  316.     WORD    GetFormatVersion( void ) ;
  317.     void    SetFormatVersion( WORD wFmtVersion ) ;
  318.     DWORD   GetOSVersion( void ) ;
  319.     void    SetOSVersion( DWORD dwOSVer ) ;
  320.     CLSID   GetClassID( void ) ;
  321.     void    SetClassID( CLSID clsid ) ;
  322.     DWORD   GetCount( void ) ;
  323.     CPtrList* GetList( void ) ;
  324.  
  325. // Operations
  326.     BOOL    WriteToStream( IStream* pIStream ) ;
  327.     BOOL    ReadFromStream( IStream* pIStream ) ;
  328.  
  329. // Implementation
  330. private:
  331.     PROPHEADER      m_PH ;
  332.     CPtrList         m_SectionList ;
  333.  
  334. public:
  335.     ~CPropertySet();
  336. } ;
  337.  
  338.  
  339. /////////////////////////////////////////////////////////////////////////////
  340. // CArchivePropExchange - for persistence in an archive.
  341.  
  342. class CArchivePropExchange : public CPropExchange
  343. {
  344. // Constructors
  345. public:
  346.     CArchivePropExchange(CArchive& ar);
  347.  
  348. // Operations
  349.     virtual BOOL ExchangeProp(LPCTSTR pszPropName, VARTYPE vtProp,
  350.                 void* pvProp, const void* pvDefault = NULL);
  351.     virtual BOOL ExchangeBlobProp(LPCTSTR pszPropName, HGLOBAL* phBlob,
  352.                 HGLOBAL hBlobDefault = NULL);
  353.     virtual BOOL ExchangeFontProp(LPCTSTR pszPropName, CFontHolder& font,
  354.                 const FONTDESC* pFontDesc, LPFONTDISP pFontDispAmbient);
  355.     virtual BOOL ExchangePersistentProp(LPCTSTR pszPropName,
  356.                 LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault);
  357.  
  358. // Implementation
  359. protected:
  360.     CArchive& m_ar;
  361. };
  362.  
  363.  
  364. /////////////////////////////////////////////////////////////////////////////
  365. // CResetPropExchange - for resetting property state to defaults.
  366.  
  367. class CResetPropExchange : public CPropExchange
  368. {
  369. // Constructors
  370. public:
  371.     CResetPropExchange(void);
  372.  
  373. // Operations
  374.     virtual BOOL ExchangeProp(LPCTSTR pszPropName, VARTYPE vtProp,
  375.                 void* pvProp, const void* pvDefault = NULL);
  376.     virtual BOOL ExchangeBlobProp(LPCTSTR pszPropName, HGLOBAL* phBlob,
  377.                 HGLOBAL hBlobDefault = NULL);
  378.     virtual BOOL ExchangeFontProp(LPCTSTR pszPropName, CFontHolder& font,
  379.                 const FONTDESC* pFontDesc, LPFONTDISP pFontDispAmbient);
  380.     virtual BOOL ExchangePersistentProp(LPCTSTR pszPropName,
  381.                 LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault);
  382. };
  383.  
  384.  
  385. /////////////////////////////////////////////////////////////////////////////
  386. // CPropsetPropExchange - for persistence in a property set.
  387.  
  388. class CPropsetPropExchange : public CPropExchange
  389. {
  390. // Constructors
  391. public:
  392.     CPropsetPropExchange(CPropertySection& psec, LPSTORAGE lpStorage,
  393.         BOOL bLoading);
  394.  
  395. // Operations
  396.     virtual BOOL ExchangeProp(LPCTSTR pszPropName, VARTYPE vtProp,
  397.                 void* pvProp, const void* pvDefault = NULL);
  398.     virtual BOOL ExchangeBlobProp(LPCTSTR pszPropName, HGLOBAL* phBlob,
  399.                 HGLOBAL hBlobDefault = NULL);
  400.     virtual BOOL ExchangeFontProp(LPCTSTR pszPropName, CFontHolder& font,
  401.                 const FONTDESC* pFontDesc, LPFONTDISP pFontDispAmbient);
  402.     virtual BOOL ExchangePersistentProp(LPCTSTR pszPropName,
  403.                 LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault);
  404.  
  405. // Implementation
  406.     CPropertySection& m_psec;
  407.     LPSTORAGE m_lpStorage;
  408.     DWORD m_dwPropID;
  409. };
  410.  
  411. /////////////////////////////////////////////////////////////////////////////
  412. // CAsyncPropExchange - for launching asynchronous downloads set.
  413.  
  414. class CAsyncPropExchange : public CPropExchange
  415. {
  416. // Constructors
  417. public:
  418.     CAsyncPropExchange(DWORD dwVersion);
  419.  
  420. // Operations
  421. public:
  422.     virtual BOOL ExchangeVersion(DWORD& dwVersionLoaded,
  423.         DWORD dwVersionDefault, BOOL bConvert);
  424.  
  425.     virtual BOOL ExchangeProp(LPCTSTR pszPropName, VARTYPE vtProp,
  426.                 void* pvProp, const void* pvDefault = NULL);
  427.     virtual BOOL ExchangeBlobProp(LPCTSTR pszPropName, HGLOBAL* phBlob,
  428.                 HGLOBAL hBlobDefault = NULL);
  429.     virtual BOOL ExchangeFontProp(LPCTSTR pszPropName, CFontHolder& font,
  430.                 const FONTDESC* pFontDesc,
  431.                 LPFONTDISP pFontDispAmbient);
  432.     virtual BOOL ExchangePersistentProp(LPCTSTR pszPropName,
  433.                 LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault);
  434. };
  435.  
  436.  
  437. /////////////////////////////////////////////////////////////////////////////
  438. // COleDispatchExceptionEx - dispatch exception that includes an SCODE
  439.  
  440. class COleDispatchExceptionEx : public COleDispatchException
  441. {
  442. public:
  443.     COleDispatchExceptionEx(LPCTSTR lpszDescription, UINT nHelpID, SCODE sc);
  444. };
  445.  
  446. /////////////////////////////////////////////////////////////////////////////
  447. // Reset MFC data definitions
  448.  
  449. #undef AFX_DATA
  450. #define AFX_DATA
  451.  
  452. #endif  //__CTLIMPL_H__
  453.