ctlimpl.h 14 KB

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