Leaked source code of windows server 2003
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.

2814 lines
77 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLCTL_H__
  11. #define __ATLCTL_H__
  12. #ifndef __cplusplus
  13. #error ATL requires C++ compilation (use a .cpp suffix)
  14. #endif
  15. #include <atlwin.h>
  16. #include <objsafe.h>
  17. #include <urlmon.h>
  18. #pragma comment(lib, "gdi32.lib")
  19. #pragma comment(lib, "urlmon.lib")
  20. ATLAPI_(void) AtlHiMetricToPixel(const SIZEL * lpSizeInHiMetric, LPSIZEL lpSizeInPix);
  21. ATLAPI_(void) AtlPixelToHiMetric(const SIZEL * lpSizeInPix, LPSIZEL lpSizeInHiMetric);
  22. ATLAPI_(HDC) AtlCreateTargetDC(HDC hdc, DVTARGETDEVICE* ptd);
  23. // Include GUIDs for the new stock property dialogs contained in the dll MSStkProp.DLL
  24. #include "msstkppg.h"
  25. #define CLSID_MSStockFont CLSID_StockFontPage
  26. #define CLSID_MSStockColor CLSID_StockColorPage
  27. #define CLSID_MSStockPicture CLSID_StockPicturePage
  28. #ifndef ATL_NO_NAMESPACE
  29. namespace ATL
  30. {
  31. #endif
  32. #pragma pack(push, _ATL_PACKING)
  33. // Forward declarations
  34. //
  35. class ATL_NO_VTABLE CComControlBase;
  36. template <class T> class CComControl;
  37. class CComDispatchDriver;
  38. struct ATL_PROPMAP_ENTRY
  39. {
  40. LPCOLESTR szDesc;
  41. DISPID dispid;
  42. const CLSID* pclsidPropPage;
  43. const IID* piidDispatch;
  44. };
  45. struct ATL_DRAWINFO
  46. {
  47. UINT cbSize;
  48. DWORD dwDrawAspect;
  49. LONG lindex;
  50. DVTARGETDEVICE* ptd;
  51. HDC hicTargetDev;
  52. HDC hdcDraw;
  53. LPCRECTL prcBounds; //Rectangle in which to draw
  54. LPCRECTL prcWBounds; //WindowOrg and Ext if metafile
  55. BOOL bOptimize;
  56. BOOL bZoomed;
  57. BOOL bRectInHimetric;
  58. SIZEL ZoomNum; //ZoomX = ZoomNum.cx/ZoomNum.cy
  59. SIZEL ZoomDen;
  60. };
  61. //////////////////////////////////////////////////////////////////////////////
  62. // CComDispatchDriver / Specialization of CComQIPtr<IDispatch, IID_IDispatch>
  63. class CComDispatchDriver
  64. {
  65. public:
  66. CComDispatchDriver()
  67. {
  68. p = NULL;
  69. }
  70. CComDispatchDriver(IDispatch* lp)
  71. {
  72. if ((p = lp) != NULL)
  73. p->AddRef();
  74. }
  75. CComDispatchDriver(IUnknown* lp)
  76. {
  77. p=NULL;
  78. if (lp != NULL)
  79. lp->QueryInterface(IID_IDispatch, (void **)&p);
  80. }
  81. ~CComDispatchDriver() { if (p) p->Release(); }
  82. void Release() {if (p) p->Release(); p=NULL;}
  83. operator IDispatch*() {return p;}
  84. IDispatch& operator*() {_ASSERTE(p!=NULL); return *p; }
  85. IDispatch** operator&() {_ASSERTE(p==NULL); return &p; }
  86. IDispatch* operator->() {_ASSERTE(p!=NULL); return p; }
  87. IDispatch* operator=(IDispatch* lp){return (IDispatch*)AtlComPtrAssign((IUnknown**)&p, lp);}
  88. IDispatch* operator=(IUnknown* lp)
  89. {
  90. return (IDispatch*)AtlComQIPtrAssign((IUnknown**)&p, lp, IID_IDispatch);
  91. }
  92. BOOL operator!(){return (p == NULL) ? TRUE : FALSE;}
  93. HRESULT GetProperty(DISPID dwDispID, VARIANT* pVar)
  94. {
  95. _ASSERTE(p);
  96. return GetProperty(p, dwDispID, pVar);
  97. }
  98. HRESULT PutProperty(DISPID dwDispID, VARIANT* pVar)
  99. {
  100. _ASSERTE(p);
  101. return PutProperty(p, dwDispID, pVar);
  102. }
  103. static HRESULT GetProperty(IDispatch* pDisp, DISPID dwDispID, VARIANT* pVar);
  104. static HRESULT PutProperty(IDispatch* pDisp, DISPID dwDispID, VARIANT* pVar);
  105. IDispatch* p;
  106. };
  107. //////////////////////////////////////////////////////////////////////////////
  108. // CFirePropNotifyEvent
  109. class CFirePropNotifyEvent
  110. {
  111. public:
  112. static HRESULT FireOnRequestEdit(IUnknown* pUnk, DISPID dispID);
  113. static HRESULT FireOnChanged(IUnknown* pUnk, DISPID dispID);
  114. };
  115. //////////////////////////////////////////////////////////////////////////////
  116. // CFakeFirePropNotifyEvent
  117. class CFakeFirePropNotifyEvent
  118. {
  119. public:
  120. static HRESULT FireOnRequestEdit(IUnknown* /*pUnk*/, DISPID /*dispID*/)
  121. {
  122. return S_OK;
  123. }
  124. static HRESULT FireOnChanged(IUnknown* /*pUnk*/, DISPID /*dispID*/)
  125. {
  126. return S_OK;
  127. }
  128. };
  129. typedef CFakeFirePropNotifyEvent _ATL_PROP_NOTIFY_EVENT_CLASS;
  130. //////////////////////////////////////////////////////////////////////////////
  131. // CComControl
  132. class ATL_NO_VTABLE CComControlBase
  133. {
  134. public:
  135. CComControlBase(HWND& h) : m_hWndCD(h)
  136. {
  137. memset(this, 0, sizeof(CComControlBase));
  138. m_phWndCD = &h;
  139. m_sizeExtent.cx = 2*2540;
  140. m_sizeExtent.cy = 2*2540;
  141. m_sizeNatural = m_sizeExtent;
  142. }
  143. ~CComControlBase()
  144. {
  145. if (m_hWndCD != NULL)
  146. ::DestroyWindow(m_hWndCD);
  147. ATLTRACE(_T("Control Destroyed\n"));
  148. }
  149. // methods
  150. public:
  151. // Control helper functions can go here
  152. // non-virtuals only please
  153. void SetDirty(BOOL bDirty)
  154. {
  155. m_bRequiresSave = bDirty;
  156. }
  157. BOOL GetDirty()
  158. {
  159. return m_bRequiresSave ? TRUE : FALSE;
  160. }
  161. void GetZoomInfo(ATL_DRAWINFO& di);
  162. HRESULT SendOnRename(IMoniker *pmk)
  163. {
  164. HRESULT hRes = S_OK;
  165. if (m_spOleAdviseHolder)
  166. hRes = m_spOleAdviseHolder->SendOnRename(pmk);
  167. return hRes;
  168. }
  169. HRESULT SendOnSave()
  170. {
  171. HRESULT hRes = S_OK;
  172. if (m_spOleAdviseHolder)
  173. hRes = m_spOleAdviseHolder->SendOnSave();
  174. return hRes;
  175. }
  176. HRESULT SendOnClose()
  177. {
  178. HRESULT hRes = S_OK;
  179. if (m_spOleAdviseHolder)
  180. hRes = m_spOleAdviseHolder->SendOnClose();
  181. return hRes;
  182. }
  183. HRESULT SendOnDataChange(DWORD advf = 0);
  184. HRESULT SendOnViewChange(DWORD dwAspect, LONG lindex = -1)
  185. {
  186. if (m_spAdviseSink)
  187. m_spAdviseSink->OnViewChange(dwAspect, lindex);
  188. return S_OK;
  189. }
  190. LRESULT OnSetFocus(UINT /* nMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* bHandled */)
  191. {
  192. CComQIPtr <IOleControlSite, &IID_IOleControlSite> spSite(m_spClientSite);
  193. if (m_bInPlaceActive && spSite)
  194. spSite->OnFocus(TRUE);
  195. return 0;
  196. }
  197. LRESULT OnKillFocus(UINT /* nMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* bHandled */)
  198. {
  199. CComQIPtr <IOleControlSite, &IID_IOleControlSite> spSite(m_spClientSite);
  200. if (m_bInPlaceActive && spSite)
  201. spSite->OnFocus(FALSE);
  202. return 0;
  203. }
  204. LRESULT OnGetDlgCode(UINT /* nMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* bHandled */)
  205. {
  206. return 0;
  207. }
  208. HRESULT GetAmbientProperty(DISPID dispid, VARIANT& var)
  209. {
  210. HRESULT hRes = E_FAIL;
  211. if (m_spAmbientDispatch.p != NULL)
  212. hRes = m_spAmbientDispatch.GetProperty(dispid, &var);
  213. return hRes;
  214. }
  215. HRESULT GetAmbientAppearance(short& nAppearance)
  216. {
  217. CComVariant var;
  218. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_APPEARANCE, var);
  219. _ASSERTE(var.vt == VT_I2 || FAILED(hRes));
  220. if (SUCCEEDED(hRes))
  221. nAppearance = var.iVal;
  222. return hRes;
  223. }
  224. HRESULT GetAmbientBackColor(OLE_COLOR& BackColor)
  225. {
  226. CComVariant var;
  227. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_BACKCOLOR, var);
  228. _ASSERTE(var.vt == VT_I4 || FAILED(hRes));
  229. if (SUCCEEDED(hRes))
  230. BackColor = var.lVal;
  231. return hRes;
  232. }
  233. HRESULT GetAmbientDisplayName(BSTR& bstrDisplayName)
  234. {
  235. CComVariant var;
  236. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_DISPLAYNAME, var);
  237. _ASSERTE(var.vt == VT_BSTR || FAILED(hRes));
  238. if (SUCCEEDED(hRes))
  239. {
  240. if (var.vt != VT_BSTR)
  241. return E_FAIL;
  242. bstrDisplayName = var.bstrVal;
  243. var.vt = VT_EMPTY;
  244. var.bstrVal = NULL;
  245. }
  246. return hRes;
  247. }
  248. HRESULT GetAmbientFont(IFont** ppFont)
  249. {
  250. // caller MUST Release the font!
  251. if (ppFont == NULL)
  252. return E_POINTER;
  253. CComVariant var;
  254. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_FONT, var);
  255. _ASSERTE((var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH) || FAILED(hRes));
  256. if (SUCCEEDED(hRes) && var.pdispVal)
  257. {
  258. if (var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH)
  259. hRes = var.pdispVal->QueryInterface(IID_IFont, (void**)ppFont);
  260. else
  261. hRes = DISP_E_BADVARTYPE;
  262. }
  263. return hRes;
  264. }
  265. HRESULT GetAmbientForeColor(OLE_COLOR& ForeColor)
  266. {
  267. CComVariant var;
  268. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_FORECOLOR, var);
  269. _ASSERTE(var.vt == VT_I4 || FAILED(hRes));
  270. if (SUCCEEDED(hRes))
  271. ForeColor = var.lVal;
  272. return hRes;
  273. }
  274. HRESULT GetAmbientLocaleID(LCID& lcid)
  275. {
  276. CComVariant var;
  277. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_LOCALEID, var);
  278. _ASSERTE(var.vt == VT_I4 || FAILED(hRes));
  279. if (SUCCEEDED(hRes))
  280. lcid = var.lVal;
  281. return hRes;
  282. }
  283. HRESULT GetAmbientScaleUnits(BSTR& bstrScaleUnits)
  284. {
  285. CComVariant var;
  286. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SCALEUNITS, var);
  287. _ASSERTE(var.vt == VT_BSTR || FAILED(hRes));
  288. if (SUCCEEDED(hRes))
  289. {
  290. if (var.vt != VT_BSTR)
  291. return E_FAIL;
  292. bstrScaleUnits = var.bstrVal;
  293. var.vt = VT_EMPTY;
  294. var.bstrVal = NULL;
  295. }
  296. return hRes;
  297. }
  298. HRESULT GetAmbientTextAlign(short& nTextAlign)
  299. {
  300. CComVariant var;
  301. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_TEXTALIGN, var);
  302. _ASSERTE(var.vt == VT_I2 || FAILED(hRes));
  303. if (SUCCEEDED(hRes))
  304. nTextAlign = var.iVal;
  305. return hRes;
  306. }
  307. HRESULT GetAmbientUserMode(BOOL& bUserMode)
  308. {
  309. CComVariant var;
  310. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_USERMODE, var);
  311. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  312. if (SUCCEEDED(hRes))
  313. bUserMode = var.boolVal;
  314. return hRes;
  315. }
  316. HRESULT GetAmbientUIDead(BOOL& bUIDead)
  317. {
  318. CComVariant var;
  319. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_UIDEAD, var);
  320. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  321. if (SUCCEEDED(hRes))
  322. bUIDead = var.boolVal;
  323. return hRes;
  324. }
  325. HRESULT GetAmbientShowGrabHandles(BOOL& bShowGrabHandles)
  326. {
  327. CComVariant var;
  328. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SHOWGRABHANDLES, var);
  329. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  330. if (SUCCEEDED(hRes))
  331. bShowGrabHandles = var.boolVal;
  332. return hRes;
  333. }
  334. HRESULT GetAmbientShowHatching(BOOL& bShowHatching)
  335. {
  336. CComVariant var;
  337. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SHOWHATCHING, var);
  338. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  339. if (SUCCEEDED(hRes))
  340. bShowHatching = var.boolVal;
  341. return hRes;
  342. }
  343. HRESULT GetAmbientMessageReflect(BOOL& bMessageReflect)
  344. {
  345. CComVariant var;
  346. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_MESSAGEREFLECT, var);
  347. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  348. if (SUCCEEDED(hRes))
  349. bMessageReflect = var.boolVal;
  350. return hRes;
  351. }
  352. HRESULT GetAmbientAutoClip(BOOL& bAutoClip)
  353. {
  354. CComVariant var;
  355. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_AUTOCLIP, var);
  356. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  357. if (SUCCEEDED(hRes))
  358. bAutoClip = var.boolVal;
  359. return hRes;
  360. }
  361. HRESULT GetAmbientDisplayAsDefault(BOOL& bDisplaysDefault)
  362. {
  363. CComVariant var;
  364. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_DISPLAYASDEFAULT, var);
  365. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  366. if (SUCCEEDED(hRes))
  367. bDisplaysDefault = var.boolVal;
  368. return hRes;
  369. }
  370. HRESULT GetAmbientSupportsMnemonics(BOOL& bSupportMnemonics)
  371. {
  372. CComVariant var;
  373. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SUPPORTSMNEMONICS, var);
  374. _ASSERTE(var.vt == VT_BOOL || FAILED(hRes));
  375. if (SUCCEEDED(hRes))
  376. bSupportMnemonics = var.boolVal;
  377. return hRes;
  378. }
  379. HRESULT GetAmbientPalette(HPALETTE& hPalette)
  380. {
  381. CComVariant var;
  382. HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_PALETTE, var);
  383. _ASSERTE(var.vt == VT_INT_PTR || FAILED(hRes));
  384. if (SUCCEEDED(hRes))
  385. hPalette = reinterpret_cast<HPALETTE>(var.byref);
  386. return hRes;
  387. }
  388. BOOL DoesVerbUIActivate(LONG iVerb)
  389. {
  390. BOOL b = FALSE;
  391. switch (iVerb)
  392. {
  393. case OLEIVERB_UIACTIVATE:
  394. case OLEIVERB_PRIMARY:
  395. b = TRUE;
  396. break;
  397. }
  398. // if no ambient dispatch then in old style OLE container
  399. if (DoesVerbActivate(iVerb) && m_spAmbientDispatch.p == NULL)
  400. b = TRUE;
  401. return b;
  402. }
  403. BOOL DoesVerbActivate(LONG iVerb)
  404. {
  405. BOOL b = FALSE;
  406. switch (iVerb)
  407. {
  408. case OLEIVERB_UIACTIVATE:
  409. case OLEIVERB_PRIMARY:
  410. case OLEIVERB_SHOW:
  411. case OLEIVERB_INPLACEACTIVATE:
  412. b = TRUE;
  413. break;
  414. }
  415. return b;
  416. }
  417. BOOL SetControlFocus(BOOL bGrab);
  418. HRESULT IQuickActivate_QuickActivate(QACONTAINER *pQACont,
  419. QACONTROL *pQACtrl);
  420. HRESULT IPersistPropertyBag_Load(LPPROPERTYBAG pPropBag,
  421. LPERRORLOG pErrorLog, ATL_PROPMAP_ENTRY* pMap);
  422. HRESULT IPersistPropertyBag_Save(LPPROPERTYBAG pPropBag,
  423. BOOL fClearDirty, BOOL fSaveAllProperties, ATL_PROPMAP_ENTRY* pMap);
  424. HRESULT ISpecifyPropertyPages_GetPages(CAUUID* pPages,
  425. ATL_PROPMAP_ENTRY* pMap);
  426. HRESULT DoVerbProperties(LPCRECT /* prcPosRect */, HWND hwndParent);
  427. HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect = NULL);
  428. HRESULT IPersistStreamInit_Load(LPSTREAM pStm, ATL_PROPMAP_ENTRY* pMap);
  429. HRESULT IPersistStreamInit_Save(LPSTREAM pStm, BOOL /* fClearDirty */,
  430. ATL_PROPMAP_ENTRY* pMap);
  431. HRESULT IOleObject_SetClientSite(IOleClientSite *pClientSite);
  432. HRESULT IOleObject_GetClientSite(IOleClientSite **ppClientSite);
  433. HRESULT IOleObject_Advise(IAdviseSink *pAdvSink, DWORD *pdwConnection);
  434. HRESULT IOleObject_Close(DWORD dwSaveOption);
  435. HRESULT IOleObject_SetExtent(DWORD dwDrawAspect, SIZEL *psizel);
  436. HRESULT IOleInPlaceObject_InPlaceDeactivate(void);
  437. HRESULT IOleInPlaceObject_UIDeactivate(void);
  438. HRESULT IOleInPlaceObject_SetObjectRects(LPCRECT prcPos,LPCRECT prcClip);
  439. HRESULT IViewObject_Draw(DWORD dwDrawAspect, LONG lindex, void *pvAspect,
  440. DVTARGETDEVICE *ptd, HDC hicTargetDev, HDC hdcDraw,
  441. LPCRECTL prcBounds, LPCRECTL prcWBounds);
  442. HRESULT IDataObject_GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium);
  443. HRESULT FireViewChange();
  444. LRESULT OnPaint(UINT /* nMsg */, WPARAM /* wParam */, LPARAM /* lParam */,
  445. BOOL& /* lResult */);
  446. virtual HWND CreateControlWindow(HWND hWndParent, RECT& rcPos) = 0;
  447. virtual HRESULT ControlQueryInterface(const IID& iid, void** ppv) = 0;
  448. virtual HRESULT OnDrawAdvanced(ATL_DRAWINFO& di);
  449. virtual HRESULT OnDraw(ATL_DRAWINFO& di)
  450. {
  451. return S_OK;
  452. }
  453. // Attributes
  454. public:
  455. CComPtr<IOleInPlaceSiteWindowless> m_spInPlaceSite;
  456. CComPtr<IDataAdviseHolder> m_spDataAdviseHolder;
  457. CComPtr<IOleAdviseHolder> m_spOleAdviseHolder;
  458. CComPtr<IOleClientSite> m_spClientSite;
  459. CComPtr<IAdviseSink> m_spAdviseSink;
  460. CComDispatchDriver m_spAmbientDispatch;
  461. SIZE m_sizeNatural; //unscaled size in himetric
  462. SIZE m_sizeExtent; //current extents in himetric
  463. RECT m_rcPos; // position in pixels
  464. union
  465. {
  466. HWND& m_hWndCD;
  467. HWND* m_phWndCD;
  468. };
  469. union
  470. {
  471. // m_nFreezeEvents is the only one actually used
  472. int m_nFreezeEvents; // count of freezes versus thaws
  473. // These are here to make stock properties work
  474. IPictureDisp* m_pMouseIcon;
  475. IPictureDisp* m_pPicture;
  476. IFontDisp* m_pFont;
  477. OLE_COLOR m_clrBackColor;
  478. OLE_COLOR m_clrBorderColor;
  479. OLE_COLOR m_clrFillColor;
  480. OLE_COLOR m_clrForeColor;
  481. BSTR m_bstrText;
  482. BSTR m_bstrCaption;
  483. BOOL m_bValid;
  484. BOOL m_bTabStop;
  485. BOOL m_bBorderVisible;
  486. BOOL m_bEnabled;
  487. long m_nBackStyle;
  488. long m_nBorderStyle;
  489. long m_nBorderWidth;
  490. long m_nDrawMode;
  491. long m_nDrawStyle;
  492. long m_nDrawWidth;
  493. long m_nFillStyle;
  494. long m_nAppearance;
  495. long m_nMousePointer;
  496. long m_nReadyState;
  497. };
  498. unsigned m_bNegotiatedWnd:1;
  499. unsigned m_bWndLess:1;
  500. unsigned m_bInPlaceActive:1;
  501. unsigned m_bUIActive:1;
  502. unsigned m_bUsingWindowRgn:1;
  503. unsigned m_bInPlaceSiteEx:1;
  504. unsigned m_bWindowOnly:1;
  505. unsigned m_bRequiresSave:1;
  506. unsigned m_bWasOnceWindowless:1;
  507. unsigned m_bAutoSize:1; //SetExtent fails if size doesn't match existing
  508. unsigned m_bRecomposeOnResize:1; //implies OLEMISC_RECOMPOSEONRESIZE
  509. unsigned m_bResizeNatural:1; //resize natural extent on SetExtent
  510. unsigned m_bDrawFromNatural:1; //instead of m_sizeExtent
  511. unsigned m_bDrawGetDataInHimetric:1; //instead of pixels
  512. };
  513. template <class T>
  514. class ATL_NO_VTABLE CComControl : public CComControlBase, public CWindowImpl<T>
  515. {
  516. public:
  517. CComControl() : CComControlBase(m_hWnd) {}
  518. HRESULT FireOnRequestEdit(DISPID dispID)
  519. {
  520. T* pT = static_cast<T*>(this);
  521. return T::__ATL_PROP_NOTIFY_EVENT_CLASS::FireOnRequestEdit(pT->GetUnknown(), dispID);
  522. }
  523. HRESULT FireOnChanged(DISPID dispID)
  524. {
  525. T* pT = static_cast<T*>(this);
  526. return T::__ATL_PROP_NOTIFY_EVENT_CLASS::FireOnChanged(pT->GetUnknown(), dispID);
  527. }
  528. virtual HRESULT ControlQueryInterface(const IID& iid, void** ppv)
  529. {
  530. T* pT = static_cast<T*>(this);
  531. return pT->_InternalQueryInterface(iid, ppv);
  532. }
  533. virtual HWND CreateControlWindow(HWND hWndParent, RECT& rcPos)
  534. {
  535. T* pT = static_cast<T*>(this);
  536. return pT->Create(hWndParent, rcPos);
  537. }
  538. };
  539. // Forward declarations
  540. //
  541. template <class T> class IPersistImpl;
  542. template <class T> class IPersistStreamInitImpl;
  543. template <class T> class IPersistStorageImpl;
  544. template <class T> class IPersistPropertyBagImpl;
  545. template <class T> class IOleControlImpl;
  546. template <class T> class IRunnableObjectImpl;
  547. template <class T> class IQuickActivateImpl;
  548. template <class T> class IOleObjectImpl;
  549. template <class T> class IPropertyPageImpl;
  550. template <class T> class IPropertyPage2Impl;
  551. template <class T> class IPerPropertyBrowsingImpl;
  552. template <class T> class IViewObjectExImpl;
  553. template <class T> class IOleWindowImpl;
  554. template <class T> class ISpecifyPropertyPagesImpl;
  555. template <class T> class IPointerInactiveImpl;
  556. template <class T, class CDV> class IPropertyNotifySinkCP;
  557. template <class T> class IBindStatusCallbackImpl;
  558. template <class T> class CBindStatusCallback;
  559. //////////////////////////////////////////////////////////////////////////////
  560. // IPersistImpl
  561. template <class T>
  562. class ATL_NO_VTABLE IPersistImpl
  563. {
  564. public:
  565. // IUnknown
  566. //
  567. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  568. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPersistImpl)
  569. // IPersist
  570. STDMETHOD(GetClassID)(CLSID *pClassID)
  571. {
  572. ATLTRACE(_T("IPersistImpl::GetClassID\n"));
  573. if (pClassID == NULL)
  574. return E_POINTER;
  575. T* pT = static_cast<T*>(this);
  576. *pClassID = pT->GetObjectCLSID();
  577. return S_OK;
  578. }
  579. };
  580. #define BEGIN_PROPERTY_MAP(theClass) \
  581. typedef _ATL_PROP_NOTIFY_EVENT_CLASS __ATL_PROP_NOTIFY_EVENT_CLASS; \
  582. static ATL_PROPMAP_ENTRY* GetPropertyMap()\
  583. {\
  584. static ATL_PROPMAP_ENTRY pPropMap[] = \
  585. {
  586. #define PROP_ENTRY(szDesc, dispid, clsid) \
  587. {OLESTR(szDesc), dispid, &clsid, &IID_IDispatch},
  588. #define PROP_ENTRY_EX(szDesc, dispid, clsid, iidDispatch) \
  589. {OLESTR(szDesc), dispid, &clsid, &iidDispatch},
  590. #define PROP_PAGE(clsid) \
  591. {NULL, NULL, &clsid, &IID_NULL},
  592. #define END_PROPERTY_MAP() \
  593. {NULL, 0, NULL, &IID_NULL} \
  594. }; \
  595. return pPropMap; \
  596. }
  597. //////////////////////////////////////////////////////////////////////////////
  598. // IPersistStreamInitImpl
  599. template <class T>
  600. class ATL_NO_VTABLE IPersistStreamInitImpl
  601. {
  602. public:
  603. // IUnknown
  604. //
  605. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  606. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPersistStreamInitImpl)
  607. #if _MSC_VER >= 1200
  608. #pragma warning( push )
  609. #pragma warning( disable: 4189 )
  610. #endif
  611. // IPersist
  612. STDMETHOD(GetClassID)(CLSID *pClassID)
  613. {
  614. ATLTRACE(_T("IPersistStreamInitImpl::GetClassID\n"));
  615. if (pClassID == NULL)
  616. return E_POINTER;
  617. T* pT = static_cast<T*>(this);
  618. if (!pClassID)
  619. return E_POINTER;
  620. *pClassID = pT->GetObjectCLSID();
  621. return S_OK;
  622. }
  623. #if _MSC_VER >= 1200
  624. #pragma warning( pop )
  625. #endif
  626. // IPersistStream
  627. STDMETHOD(IsDirty)()
  628. {
  629. ATLTRACE(_T("IPersistStreamInitImpl::IsDirty\n"));
  630. T* pT = static_cast<T*>(this);
  631. return (pT->m_bRequiresSave) ? S_OK : S_FALSE;
  632. }
  633. STDMETHOD(Load)(LPSTREAM pStm)
  634. {
  635. ATLTRACE(_T("IPersistStreamInitImpl::Load\n"));
  636. T* pT = static_cast<T*>(this);
  637. return pT->IPersistStreamInit_Load(pStm, T::GetPropertyMap());
  638. }
  639. STDMETHOD(Save)(LPSTREAM pStm, BOOL fClearDirty)
  640. {
  641. T* pT = static_cast<T*>(this);
  642. ATLTRACE(_T("IPersistStreamInitImpl::Save\n"));
  643. return pT->IPersistStreamInit_Save(pStm, fClearDirty, T::GetPropertyMap());
  644. }
  645. STDMETHOD(GetSizeMax)(ULARGE_INTEGER FAR* /* pcbSize */)
  646. {
  647. ATLTRACENOTIMPL(_T("IPersistStreamInitImpl::GetSizeMax"));
  648. }
  649. // IPersistStreamInit
  650. STDMETHOD(InitNew)()
  651. {
  652. T* pT = static_cast<T*>(this);
  653. ATLTRACE(_T("IPersistStreamInitImpl::InitNew\n"));
  654. pT->SendOnDataChange();
  655. return S_OK;
  656. }
  657. };
  658. //////////////////////////////////////////////////////////////////////////////
  659. // IPersistStorageImpl
  660. template <class T>
  661. class ATL_NO_VTABLE IPersistStorageImpl
  662. {
  663. public:
  664. // IUnknown
  665. //
  666. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  667. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPersistStorageImpl)
  668. // IPersist
  669. STDMETHOD(GetClassID)(CLSID *pClassID)
  670. {
  671. ATLTRACE(_T("IPersistStorageImpl::GetClassID\n"));
  672. T* pT = static_cast<T*>(this);
  673. if (pClassID == NULL)
  674. return E_POINTER;
  675. *pClassID = pT->GetObjectCLSID();
  676. return S_OK;
  677. }
  678. // IPersistStorage
  679. STDMETHOD(IsDirty)(void)
  680. {
  681. ATLTRACE(_T("IPersistStorageImpl::IsDirty\n"));
  682. T* pT = static_cast<T*>(this);
  683. CComPtr<IPersistStreamInit> p;
  684. p.p = IPSI_GetIPersistStreamInit();
  685. return (p != NULL) ? p->IsDirty() : E_FAIL;
  686. }
  687. STDMETHOD(InitNew)(IStorage*)
  688. {
  689. ATLTRACE(_T("IPersistStorageImpl::InitNew\n"));
  690. T* pT = static_cast<T*>(this);
  691. CComPtr<IPersistStreamInit> p;
  692. p.p = IPSI_GetIPersistStreamInit();
  693. return (p != NULL) ? p->InitNew() : E_FAIL;
  694. }
  695. STDMETHOD(Load)(IStorage* pStorage)
  696. {
  697. ATLTRACE(_T("IPersistStorageImpl::Load\n"));
  698. T* pT = static_cast<T*>(this);
  699. CComPtr<IPersistStreamInit> p;
  700. p.p = IPSI_GetIPersistStreamInit();
  701. HRESULT hr = E_FAIL;
  702. if (p != NULL)
  703. {
  704. CComPtr<IStream> spStream;
  705. hr = pStorage->OpenStream(OLESTR("Contents"), NULL,
  706. STGM_DIRECT | STGM_SHARE_EXCLUSIVE, 0, &spStream);
  707. if (SUCCEEDED(hr))
  708. hr = p->Load(spStream);
  709. }
  710. return hr;
  711. }
  712. STDMETHOD(Save)(IStorage* pStorage, BOOL fSameAsLoad)
  713. {
  714. ATLTRACE(_T("IPersistStorageImpl::Save\n"));
  715. T* pT = static_cast<T*>(this);
  716. CComPtr<IPersistStreamInit> p;
  717. p.p = IPSI_GetIPersistStreamInit();
  718. HRESULT hr = E_FAIL;
  719. if (p != NULL)
  720. {
  721. CComPtr<IStream> spStream;
  722. static LPCOLESTR vszContents = OLESTR("Contents");
  723. hr = pStorage->CreateStream(vszContents,
  724. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  725. 0, 0, &spStream);
  726. if (SUCCEEDED(hr))
  727. hr = p->Save(spStream, fSameAsLoad);
  728. }
  729. return hr;
  730. }
  731. STDMETHOD(SaveCompleted)(IStorage* /* pStorage */)
  732. {
  733. ATLTRACE(_T("IPersistStorageImpl::SaveCompleted\n"));
  734. return S_OK;
  735. }
  736. STDMETHOD(HandsOffStorage)(void)
  737. {
  738. ATLTRACE(_T("IPersistStorageImpl::HandsOffStorage\n"));
  739. return S_OK;
  740. }
  741. private:
  742. IPersistStreamInit* IPSI_GetIPersistStreamInit();
  743. };
  744. template <class T>
  745. IPersistStreamInit* IPersistStorageImpl<T>::IPSI_GetIPersistStreamInit()
  746. {
  747. T* pT = static_cast<T*>(this);
  748. IPersistStreamInit* p;
  749. if (FAILED(pT->GetUnknown()->QueryInterface(IID_IPersistStreamInit, (void**)&p)))
  750. pT->_InternalQueryInterface(IID_IPersistStreamInit, (void**)&p);
  751. return p;
  752. }
  753. //////////////////////////////////////////////////////////////////////////////
  754. // IPersistPropertyBagImpl
  755. template <class T>
  756. class ATL_NO_VTABLE IPersistPropertyBagImpl
  757. {
  758. public:
  759. // IUnknown
  760. //
  761. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  762. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPersistPropertyBagImpl)
  763. // IPersist
  764. STDMETHOD(GetClassID)(CLSID *pClassID)
  765. {
  766. ATLTRACE(_T("IPersistPropertyBagImpl::GetClassID\n"));
  767. T* pT = static_cast<T*>(this);
  768. if (pClassID == NULL)
  769. return E_POINTER;
  770. *pClassID = pT->GetObjectCLSID();
  771. return S_OK;
  772. }
  773. // IPersistPropertyBag
  774. //
  775. STDMETHOD(InitNew)()
  776. {
  777. ATLTRACE(_T("IPersistPropertyBagImpl::InitNew\n"));
  778. return S_OK;
  779. }
  780. STDMETHOD(Load)(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
  781. {
  782. ATLTRACE(_T("IPersistPropertyBagImpl::Load\n"));
  783. T* pT = static_cast<T*>(this);
  784. ATL_PROPMAP_ENTRY* pMap = T::GetPropertyMap();
  785. _ASSERTE(pMap != NULL);
  786. return pT->IPersistPropertyBag_Load(pPropBag, pErrorLog, pMap);
  787. }
  788. STDMETHOD(Save)(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties)
  789. {
  790. ATLTRACE(_T("IPersistPropertyBagImpl::Save\n"));
  791. T* pT = static_cast<T*>(this);
  792. ATL_PROPMAP_ENTRY* pMap = T::GetPropertyMap();
  793. _ASSERTE(pMap != NULL);
  794. return pT->IPersistPropertyBag_Save(pPropBag, fClearDirty, fSaveAllProperties, pMap);
  795. }
  796. };
  797. //////////////////////////////////////////////////////////////////////////////
  798. // IOleControlImpl
  799. template <class T>
  800. class ATL_NO_VTABLE IOleControlImpl
  801. {
  802. public:
  803. // IUnknown
  804. //
  805. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  806. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleControlImpl)
  807. // IOleControl methods
  808. //
  809. STDMETHOD(GetControlInfo)(LPCONTROLINFO /* pCI */)
  810. {
  811. ATLTRACENOTIMPL(_T("IOleControlImpl::GetControlInfo"));
  812. }
  813. STDMETHOD(OnMnemonic)(LPMSG /* pMsg */)
  814. {
  815. ATLTRACENOTIMPL(_T("IOleControlImpl::OnMnemonic"));
  816. }
  817. STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
  818. {
  819. dispid;
  820. ATLTRACE(_T("IOleControlImpl::OnAmbientPropertyChange\n"));
  821. ATLTRACE(_T(" -- DISPID = %d (%d)\n"), dispid);
  822. return S_OK;
  823. }
  824. STDMETHOD(FreezeEvents)(BOOL bFreeze)
  825. {
  826. T* pT = static_cast<T*>(this);
  827. ATLTRACE(_T("IOleControlImpl::FreezeEvents\n"));
  828. if (bFreeze)
  829. pT->m_nFreezeEvents++;
  830. else
  831. pT->m_nFreezeEvents--;
  832. return S_OK;
  833. }
  834. };
  835. //////////////////////////////////////////////////////////////////////////////
  836. // IQuickActivateImpl
  837. template <class T>
  838. class ATL_NO_VTABLE IQuickActivateImpl
  839. {
  840. public:
  841. // IUnknown
  842. //
  843. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  844. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IQuickActivateImpl)
  845. // IQuickActivate
  846. //
  847. STDMETHOD(QuickActivate)(QACONTAINER *pQACont, QACONTROL *pQACtrl)
  848. {
  849. T* pT = static_cast<T*>(this);
  850. ATLTRACE(_T("IQuickActivateImpl::QuickActivate\n"));
  851. return pT->IQuickActivate_QuickActivate(pQACont, pQACtrl);
  852. }
  853. STDMETHOD(SetContentExtent)(LPSIZEL pSize)
  854. {
  855. T* pT = static_cast<T*>(this);
  856. ATLTRACE(_T("IQuickActivateImpl::SetContentExtent\n"));
  857. return pT->IOleObjectImpl<T>::SetExtent(DVASPECT_CONTENT, pSize);
  858. }
  859. STDMETHOD(GetContentExtent)(LPSIZEL pSize)
  860. {
  861. T* pT = static_cast<T*>(this);
  862. ATLTRACE(_T("IQuickActivateImpl::GetContentExtent\n"));
  863. return pT->IOleObjectImpl<T>::GetExtent(DVASPECT_CONTENT, pSize);
  864. }
  865. };
  866. //////////////////////////////////////////////////////////////////////////////
  867. // IOleObjectImpl
  868. template <class T>
  869. class ATL_NO_VTABLE IOleObjectImpl
  870. {
  871. public:
  872. // IUnknown
  873. //
  874. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  875. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleObjectImpl)
  876. // IOleObject
  877. //
  878. STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
  879. {
  880. T* pT = static_cast<T*>(this);
  881. ATLTRACE(_T("IOleObjectImpl::SetClientSite\n"));
  882. return pT->IOleObject_SetClientSite(pClientSite);
  883. }
  884. STDMETHOD(GetClientSite)(IOleClientSite **ppClientSite)
  885. {
  886. T* pT = static_cast<T*>(this);
  887. ATLTRACE(_T("IOleObjectImpl::GetClientSite\n"));
  888. return pT->IOleObject_GetClientSite(ppClientSite);
  889. }
  890. STDMETHOD(SetHostNames)(LPCOLESTR /* szContainerApp */, LPCOLESTR /* szContainerObj */)
  891. {
  892. ATLTRACE(_T("IOleObjectImpl::SetHostNames\n"));
  893. return S_OK;
  894. }
  895. STDMETHOD(Close)(DWORD dwSaveOption)
  896. {
  897. T* pT = static_cast<T*>(this);
  898. ATLTRACE(_T("IOleObjectImpl::Close\n"));
  899. return pT->IOleObject_Close(dwSaveOption);
  900. }
  901. STDMETHOD(SetMoniker)(DWORD /* dwWhichMoniker */, IMoniker* /* pmk */)
  902. {
  903. ATLTRACENOTIMPL(_T("IOleObjectImpl::SetMoniker"));
  904. }
  905. STDMETHOD(GetMoniker)(DWORD /* dwAssign */, DWORD /* dwWhichMoniker */, IMoniker** /* ppmk */)
  906. {
  907. ATLTRACENOTIMPL(_T("IOleObjectImpl::GetMoniker"));
  908. }
  909. STDMETHOD(InitFromData)(IDataObject* /* pDataObject */, BOOL /* fCreation */, DWORD /* dwReserved */)
  910. {
  911. ATLTRACENOTIMPL(_T("IOleObjectImpl::InitFromData"));
  912. }
  913. STDMETHOD(GetClipboardData)(DWORD /* dwReserved */, IDataObject** /* ppDataObject */)
  914. {
  915. ATLTRACENOTIMPL(_T("IOleObjectImpl::GetClipboardData"));
  916. }
  917. // Helpers for DoVerb - Over-rideable in user class
  918. HRESULT DoVerbPrimary(LPCRECT prcPosRect, HWND hwndParent)
  919. {
  920. T* pT = static_cast<T*>(this);
  921. BOOL bDesignMode = FALSE;
  922. CComVariant var;
  923. // if container doesn't support this property
  924. // don't allow design mode
  925. HRESULT hRes = pT->GetAmbientProperty(DISPID_AMBIENT_USERMODE, var);
  926. if (SUCCEEDED(hRes) && var.vt == VT_BOOL && !var.boolVal)
  927. bDesignMode = TRUE;
  928. if (bDesignMode)
  929. return pT->DoVerbProperties(prcPosRect, hwndParent);
  930. else
  931. return pT->DoVerbInPlaceActivate(prcPosRect, hwndParent);
  932. }
  933. HRESULT DoVerbShow(LPCRECT prcPosRect, HWND /* hwndParent */)
  934. {
  935. T* pT = static_cast<T*>(this);
  936. return pT->InPlaceActivate(OLEIVERB_SHOW, prcPosRect);
  937. }
  938. HRESULT DoVerbInPlaceActivate(LPCRECT prcPosRect, HWND /* hwndParent */)
  939. {
  940. T* pT = static_cast<T*>(this);
  941. return pT->InPlaceActivate(OLEIVERB_INPLACEACTIVATE, prcPosRect);
  942. }
  943. HRESULT DoVerbUIActivate(LPCRECT prcPosRect, HWND /* hwndParent */)
  944. {
  945. T* pT = static_cast<T*>(this);
  946. return pT->InPlaceActivate(OLEIVERB_UIACTIVATE, prcPosRect);
  947. }
  948. HRESULT DoVerbHide(LPCRECT /* prcPosRect */, HWND /* hwndParent */)
  949. {
  950. T* pT = static_cast<T*>(this);
  951. pT->UIDeactivate();
  952. if (pT->m_hWnd)
  953. pT->ShowWindow(SW_HIDE);
  954. return S_OK;
  955. }
  956. HRESULT DoVerbOpen(LPCRECT /* prcPosRect */, HWND /* hwndParent */)
  957. {
  958. return S_OK;
  959. }
  960. HRESULT DoVerbDiscardUndo(LPCRECT /* prcPosRect */, HWND /* hwndParent */)
  961. {
  962. return S_OK;
  963. }
  964. STDMETHOD(DoVerb)(LONG iVerb, LPMSG /* lpmsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */,
  965. HWND hwndParent, LPCRECT lprcPosRect)
  966. {
  967. T* pT = static_cast<T*>(this);
  968. ATLTRACE(_T("IOleObjectImpl::DoVerb\n"));
  969. _ASSERTE(pT->m_spClientSite);
  970. HRESULT hr = E_NOTIMPL;
  971. switch (iVerb)
  972. {
  973. case OLEIVERB_PRIMARY:
  974. hr = pT->DoVerbPrimary(lprcPosRect, hwndParent);
  975. break;
  976. case OLEIVERB_SHOW:
  977. hr = pT->DoVerbShow(lprcPosRect, hwndParent);
  978. break;
  979. case OLEIVERB_INPLACEACTIVATE:
  980. hr = pT->DoVerbInPlaceActivate(lprcPosRect, hwndParent);
  981. break;
  982. case OLEIVERB_UIACTIVATE:
  983. hr = pT->DoVerbUIActivate(lprcPosRect, hwndParent);
  984. break;
  985. case OLEIVERB_HIDE:
  986. hr = pT->DoVerbHide(lprcPosRect, hwndParent);
  987. break;
  988. case OLEIVERB_OPEN:
  989. hr = pT->DoVerbOpen(lprcPosRect, hwndParent);
  990. break;
  991. case OLEIVERB_DISCARDUNDOSTATE:
  992. hr = pT->DoVerbDiscardUndo(lprcPosRect, hwndParent);
  993. break;
  994. case OLEIVERB_PROPERTIES:
  995. hr = pT->DoVerbProperties(lprcPosRect, hwndParent);
  996. }
  997. return hr;
  998. }
  999. STDMETHOD(EnumVerbs)(IEnumOLEVERB **ppEnumOleVerb)
  1000. {
  1001. ATLTRACE(_T("IOleObjectImpl::EnumVerbs\n"));
  1002. _ASSERTE(ppEnumOleVerb);
  1003. if (!ppEnumOleVerb)
  1004. return E_POINTER;
  1005. return OleRegEnumVerbs(T::GetObjectCLSID(), ppEnumOleVerb);
  1006. }
  1007. STDMETHOD(Update)(void)
  1008. {
  1009. ATLTRACE(_T("IOleObjectImpl::Update\n"));
  1010. return S_OK;
  1011. }
  1012. STDMETHOD(IsUpToDate)(void)
  1013. {
  1014. ATLTRACE(_T("IOleObjectImpl::IsUpToDate\n"));
  1015. return S_OK;
  1016. }
  1017. STDMETHOD(GetUserClassID)(CLSID *pClsid)
  1018. {
  1019. ATLTRACE(_T("IOleObjectImpl::GetUserClassID\n"));
  1020. _ASSERTE(pClsid);
  1021. if (!pClsid)
  1022. return E_POINTER;
  1023. *pClsid = T::GetObjectCLSID();
  1024. return S_OK;
  1025. }
  1026. STDMETHOD(GetUserType)(DWORD dwFormOfType, LPOLESTR *pszUserType)
  1027. {
  1028. ATLTRACE(_T("IOleObjectImpl::GetUserType\n"));
  1029. return OleRegGetUserType(T::GetObjectCLSID(), dwFormOfType, pszUserType);
  1030. }
  1031. STDMETHOD(SetExtent)(DWORD dwDrawAspect, SIZEL *psizel)
  1032. {
  1033. T* pT = static_cast<T*>(this);
  1034. ATLTRACE(_T("IOleObjectImpl::SetExtent\n"));
  1035. return pT->IOleObject_SetExtent(dwDrawAspect, psizel);
  1036. }
  1037. STDMETHOD(GetExtent)(DWORD dwDrawAspect, SIZEL *psizel)
  1038. {
  1039. T* pT = static_cast<T*>(this);
  1040. ATLTRACE(_T("IOleObjectImpl::GetExtent\n"));
  1041. if (dwDrawAspect != DVASPECT_CONTENT)
  1042. return E_FAIL;
  1043. if (psizel == NULL)
  1044. return E_POINTER;
  1045. *psizel = pT->m_sizeExtent;
  1046. return S_OK;
  1047. }
  1048. STDMETHOD(Advise)(IAdviseSink *pAdvSink, DWORD *pdwConnection)
  1049. {
  1050. T* pT = static_cast<T*>(this);
  1051. ATLTRACE(_T("IOleObjectImpl::Advise\n"));
  1052. return pT->IOleObject_Advise(pAdvSink, pdwConnection);
  1053. }
  1054. STDMETHOD(Unadvise)(DWORD dwConnection)
  1055. {
  1056. T* pT = static_cast<T*>(this);
  1057. ATLTRACE(_T("IOleObjectImpl::Unadvise\n"));
  1058. HRESULT hRes = E_FAIL;
  1059. if (pT->m_spOleAdviseHolder != NULL)
  1060. hRes = pT->m_spOleAdviseHolder->Unadvise(dwConnection);
  1061. return hRes;
  1062. }
  1063. STDMETHOD(EnumAdvise)(IEnumSTATDATA **ppenumAdvise)
  1064. {
  1065. T* pT = static_cast<T*>(this);
  1066. ATLTRACE(_T("IOleObjectImpl::EnumAdvise\n"));
  1067. HRESULT hRes = E_FAIL;
  1068. if (pT->m_spOleAdviseHolder != NULL)
  1069. hRes = pT->m_spOleAdviseHolder->EnumAdvise(ppenumAdvise);
  1070. return hRes;
  1071. }
  1072. STDMETHOD(GetMiscStatus)(DWORD dwAspect, DWORD *pdwStatus)
  1073. {
  1074. ATLTRACE(_T("IOleObjectImpl::GetMiscStatus\n"));
  1075. return OleRegGetMiscStatus(T::GetObjectCLSID(), dwAspect, pdwStatus);
  1076. }
  1077. STDMETHOD(SetColorScheme)(LOGPALETTE* /* pLogpal */)
  1078. {
  1079. ATLTRACENOTIMPL(_T("IOleObjectImpl::SetColorScheme"));
  1080. }
  1081. };
  1082. //local struct used for implementation
  1083. #pragma pack(push, 1)
  1084. struct _ATL_DLGTEMPLATEEX
  1085. {
  1086. WORD dlgVer;
  1087. WORD signature;
  1088. DWORD helpID;
  1089. DWORD exStyle;
  1090. DWORD style;
  1091. WORD cDlgItems;
  1092. short x;
  1093. short y;
  1094. short cx;
  1095. short cy;
  1096. };
  1097. #pragma pack(pop)
  1098. //////////////////////////////////////////////////////////////////////////////
  1099. // IPropertyPageImpl
  1100. template <class T>
  1101. class ATL_NO_VTABLE IPropertyPageImpl
  1102. {
  1103. public:
  1104. // IUnknown
  1105. //
  1106. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1107. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleControlImpl)
  1108. void SetDirty(BOOL bDirty)
  1109. {
  1110. T* pT = static_cast<T*>(this);
  1111. if (!pT->m_bDirty && bDirty)
  1112. pT->m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY | PROPPAGESTATUS_VALIDATE);
  1113. pT->m_bDirty = bDirty;
  1114. }
  1115. IPropertyPageImpl()
  1116. {
  1117. T* pT = static_cast<T*>(this);
  1118. pT->m_pPageSite = NULL;
  1119. pT->m_size.cx = 0;
  1120. pT->m_size.cy = 0;
  1121. pT->m_dwTitleID = 0;
  1122. pT->m_dwHelpFileID = 0;
  1123. pT->m_dwDocStringID = 0;
  1124. pT->m_dwHelpContext = 0;
  1125. pT->m_ppUnk = NULL;
  1126. pT->m_nObjects = 0;
  1127. pT->m_bDirty = FALSE;
  1128. pT->m_hWnd = NULL;
  1129. }
  1130. ~IPropertyPageImpl()
  1131. {
  1132. T* pT = static_cast<T*>(this);
  1133. if (pT->m_pPageSite != NULL)
  1134. pT->m_pPageSite->Release();
  1135. for (UINT i = 0; i < m_nObjects; i++)
  1136. pT->m_ppUnk[i]->Release();
  1137. delete[] pT->m_ppUnk;
  1138. }
  1139. // IPropertyPage
  1140. //
  1141. STDMETHOD(SetPageSite)(IPropertyPageSite *pPageSite)
  1142. {
  1143. T* pT = static_cast<T*>(this);
  1144. ATLTRACE(_T("IPropertyPageImpl::SetPageSite\n"));
  1145. if (!pPageSite && pT->m_pPageSite)
  1146. {
  1147. pT->m_pPageSite->Release();
  1148. return S_OK;
  1149. }
  1150. if (!pPageSite && !pT->m_pPageSite)
  1151. return S_OK;
  1152. if (pPageSite && pT->m_pPageSite)
  1153. {
  1154. ATLTRACE(_T("Error : setting page site again with non NULL value\n"));
  1155. return E_UNEXPECTED;
  1156. }
  1157. pT->m_pPageSite = pPageSite;
  1158. pT->m_pPageSite->AddRef();
  1159. return S_OK;
  1160. }
  1161. STDMETHOD(Activate)(HWND hWndParent, LPCRECT pRect, BOOL /* bModal */)
  1162. {
  1163. T* pT = static_cast<T*>(this);
  1164. ATLTRACE(_T("IPropertyPageImpl::Activate\n"));
  1165. if (pRect == NULL)
  1166. {
  1167. ATLTRACE(_T("Error : Passed a NULL rect\n"));
  1168. return E_POINTER;
  1169. }
  1170. pT->m_hWnd = pT->Create(hWndParent);
  1171. Move(pRect);
  1172. m_size.cx = pRect->right - pRect->left;
  1173. m_size.cy = pRect->bottom - pRect->top;
  1174. return S_OK;
  1175. }
  1176. STDMETHOD(Deactivate)( void)
  1177. {
  1178. T* pT = static_cast<T*>(this);
  1179. ATLTRACE(_T("IPropertyPageImpl::Deactivate\n"));
  1180. if (pT->m_hWnd)
  1181. {
  1182. ATLTRACE(_T("Destroying Dialog\n"));
  1183. if (::IsWindow(pT->m_hWnd))
  1184. pT->DestroyWindow();
  1185. pT->m_hWnd = NULL;
  1186. }
  1187. return S_OK;
  1188. }
  1189. STDMETHOD(GetPageInfo)(PROPPAGEINFO *pPageInfo)
  1190. {
  1191. T* pT = static_cast<T*>(this);
  1192. ATLTRACE(_T("IPropertyPageImpl::GetPageInfo\n"));
  1193. if (pPageInfo == NULL)
  1194. {
  1195. ATLTRACE(_T("Error : PROPPAGEINFO passed == NULL\n"));
  1196. return E_POINTER;
  1197. }
  1198. HRSRC hRsrc = FindResource(_Module.GetResourceInstance(),
  1199. MAKEINTRESOURCE(T::IDD), RT_DIALOG);
  1200. if (hRsrc == NULL)
  1201. {
  1202. ATLTRACE(_T("Could not find resource template\n"));
  1203. return E_UNEXPECTED;
  1204. }
  1205. HGLOBAL hGlob = LoadResource(_Module.GetResourceInstance(), hRsrc);
  1206. DLGTEMPLATE* pTemp = (DLGTEMPLATE*)LockResource(hGlob);
  1207. if (pTemp == NULL)
  1208. {
  1209. ATLTRACE(_T("Could not load resource template\n"));
  1210. return E_UNEXPECTED;
  1211. }
  1212. pT->GetDialogSize(pTemp, &m_size);
  1213. pPageInfo->cb = sizeof(PROPPAGEINFO);
  1214. pPageInfo->pszTitle = LoadStringHelper(pT->m_dwTitleID);
  1215. pPageInfo->size = m_size;
  1216. pPageInfo->pszHelpFile = LoadStringHelper(pT->m_dwHelpFileID);
  1217. pPageInfo->pszDocString = LoadStringHelper(pT->m_dwDocStringID);
  1218. pPageInfo->dwHelpContext = pT->m_dwHelpContext;
  1219. return S_OK;
  1220. }
  1221. STDMETHOD(SetObjects)(ULONG nObjects, IUnknown **ppUnk)
  1222. {
  1223. T* pT = static_cast<T*>(this);
  1224. ATLTRACE(_T("IPropertyPageImpl::SetObjects\n"));
  1225. if (ppUnk == NULL)
  1226. return E_POINTER;
  1227. if (pT->m_ppUnk != NULL && pT->m_nObjects > 0)
  1228. {
  1229. for (UINT iObj = 0; iObj < pT->m_nObjects; iObj++)
  1230. pT->m_ppUnk[iObj]->Release();
  1231. delete [] pT->m_ppUnk;
  1232. }
  1233. pT->m_ppUnk = NULL;
  1234. ATLTRY(pT->m_ppUnk = new IUnknown*[nObjects]);
  1235. if (pT->m_ppUnk == NULL)
  1236. return E_OUTOFMEMORY;
  1237. for (UINT i = 0; i < nObjects; i++)
  1238. {
  1239. ppUnk[i]->AddRef();
  1240. pT->m_ppUnk[i] = ppUnk[i];
  1241. }
  1242. pT->m_nObjects = nObjects;
  1243. return S_OK;
  1244. }
  1245. STDMETHOD(Show)(UINT nCmdShow)
  1246. {
  1247. T* pT = static_cast<T*>(this);
  1248. ATLTRACE(_T("IPropertyPageImpl::Show\n"));
  1249. if (pT->m_hWnd == NULL)
  1250. return E_UNEXPECTED;
  1251. ShowWindow(pT->m_hWnd, nCmdShow);
  1252. return S_OK;
  1253. }
  1254. STDMETHOD(Move)(LPCRECT pRect)
  1255. {
  1256. T* pT = static_cast<T*>(this);
  1257. ATLTRACE(_T("IPropertyPageImpl::Move\n"));
  1258. if (pT->m_hWnd == NULL)
  1259. return E_UNEXPECTED;
  1260. if (pRect == NULL)
  1261. return E_POINTER;
  1262. MoveWindow(pT->m_hWnd, pRect->left, pRect->top, pRect->right - pRect->left,
  1263. pRect->bottom - pRect->top, TRUE);
  1264. return S_OK;
  1265. }
  1266. STDMETHOD(IsPageDirty)(void)
  1267. {
  1268. T* pT = static_cast<T*>(this);
  1269. ATLTRACE(_T("IPropertyPageImpl::IsPageDirty\n"));
  1270. return pT->m_bDirty ? S_OK : S_FALSE;
  1271. }
  1272. STDMETHOD(Apply)(void)
  1273. {
  1274. T* pT = static_cast<T*>(this);
  1275. ATLTRACE(_T("IPropertyPageImpl::Apply\n"));
  1276. return S_OK;
  1277. }
  1278. STDMETHOD(Help)(LPCOLESTR pszHelpDir)
  1279. {
  1280. T* pT = static_cast<T*>(this);
  1281. USES_CONVERSION_EX;
  1282. ATLTRACE(_T("IPropertyPageImpl::Help\n"));
  1283. LPCTSTR lpszFName = NULL;
  1284. if (pszHelpDir != NULL)
  1285. {
  1286. lpszFName = OLE2CT_EX(pszHelpDir, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
  1287. #ifndef _UNICODE
  1288. if (lpszFName == NULL)
  1289. {
  1290. return E_OUTOFMEMORY;
  1291. }
  1292. #endif // _UNICODE
  1293. }
  1294. WinHelp(pT->m_hWnd, lpszFName, HELP_CONTEXTPOPUP, NULL);
  1295. return S_OK;
  1296. }
  1297. STDMETHOD(TranslateAccelerator)(MSG *pMsg)
  1298. {
  1299. T* pT = static_cast<T*>(this);
  1300. ATLTRACE(_T("IPropertyPageImpl::TranslateAccelerator\n"));
  1301. if ((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
  1302. (pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
  1303. return S_FALSE;
  1304. return (IsDialogMessage(pT->m_hWnd, pMsg)) ? S_OK : S_FALSE;
  1305. }
  1306. IPropertyPageSite* m_pPageSite;
  1307. IUnknown** m_ppUnk;
  1308. ULONG m_nObjects;
  1309. SIZE m_size;
  1310. UINT m_dwTitleID;
  1311. UINT m_dwHelpFileID;
  1312. UINT m_dwDocStringID;
  1313. DWORD m_dwHelpContext;
  1314. BOOL m_bDirty;
  1315. //methods
  1316. public:
  1317. BEGIN_MSG_MAP(IPropertyPageImpl<T>)
  1318. MESSAGE_HANDLER(WM_STYLECHANGING, OnStyleChange)
  1319. END_MSG_MAP()
  1320. LRESULT OnStyleChange(UINT, WPARAM wParam, LPARAM lParam, BOOL&)
  1321. {
  1322. if (wParam == GWL_EXSTYLE)
  1323. {
  1324. if (lParam == NULL)
  1325. return 0;
  1326. LPSTYLESTRUCT lpss = (LPSTYLESTRUCT) lParam;
  1327. lpss->styleNew |= WS_EX_CONTROLPARENT;
  1328. return 0;
  1329. }
  1330. return 1;
  1331. }
  1332. LPOLESTR LoadStringHelper(UINT idRes)
  1333. {
  1334. USES_CONVERSION_EX;
  1335. TCHAR szTemp[_MAX_PATH];
  1336. LPOLESTR sz = (LPOLESTR)CoTaskMemAlloc(_MAX_PATH*sizeof(OLECHAR));
  1337. if (sz == NULL)
  1338. return NULL;
  1339. sz[0] = NULL;
  1340. if (LoadString(_Module.GetResourceInstance(), idRes, szTemp, _MAX_PATH))
  1341. {
  1342. LPOLESTR lpszStr = T2OLE_EX(szTemp, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
  1343. #ifndef _UNICODE
  1344. if(lpszStr == NULL)
  1345. return NULL;
  1346. #endif // _UNICODE
  1347. ocscpy(sz, lpszStr);
  1348. }
  1349. else
  1350. {
  1351. ATLTRACE(_T("Error : Failed to load string from res\n"));
  1352. }
  1353. return sz;
  1354. }
  1355. void GetDialogSize(const DLGTEMPLATE* pTemplate, SIZE* pSize)
  1356. {
  1357. // If the dialog has a font we use it otherwise we default
  1358. // to the system font.
  1359. if (HasFont(pTemplate))
  1360. {
  1361. TCHAR szFace[LF_FACESIZE];
  1362. WORD wFontSize = 0;
  1363. GetFont(pTemplate, szFace, &wFontSize);
  1364. GetSizeInDialogUnits(pTemplate, pSize);
  1365. ConvertDialogUnitsToPixels(szFace, wFontSize, pSize);
  1366. }
  1367. else
  1368. {
  1369. GetSizeInDialogUnits(pTemplate, pSize);
  1370. LONG nDlgBaseUnits = GetDialogBaseUnits();
  1371. pSize->cx = MulDiv(pSize->cx, LOWORD(nDlgBaseUnits), 4);
  1372. pSize->cy = MulDiv(pSize->cy, HIWORD(nDlgBaseUnits), 8);
  1373. }
  1374. }
  1375. static void ConvertDialogUnitsToPixels(LPCTSTR pszFontFace, WORD wFontSize, SIZE* pSizePixel)
  1376. {
  1377. // Attempt to create the font to be used in the dialog box
  1378. UINT cxSysChar, cySysChar;
  1379. LOGFONT lf;
  1380. HDC hDC = ::GetDC(NULL);
  1381. int cxDlg = pSizePixel->cx;
  1382. int cyDlg = pSizePixel->cy;
  1383. ZeroMemory(&lf, sizeof(LOGFONT));
  1384. lf.lfHeight = -MulDiv(wFontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  1385. lf.lfWeight = FW_NORMAL;
  1386. lf.lfCharSet = DEFAULT_CHARSET;
  1387. lstrcpyn(lf.lfFaceName, pszFontFace, sizeof lf.lfFaceName / sizeof lf.lfFaceName[0]);
  1388. HFONT hNewFont = CreateFontIndirect(&lf);
  1389. if (hNewFont != NULL)
  1390. {
  1391. TEXTMETRIC tm;
  1392. SIZE size;
  1393. HFONT hFontOld = (HFONT)SelectObject(hDC, hNewFont);
  1394. GetTextMetrics(hDC, &tm);
  1395. cySysChar = tm.tmHeight + tm.tmExternalLeading;
  1396. ::GetTextExtentPoint(hDC,
  1397. _T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52,
  1398. &size);
  1399. cxSysChar = (size.cx + 26) / 52;
  1400. SelectObject(hDC, hFontOld);
  1401. DeleteObject(hNewFont);
  1402. }
  1403. else
  1404. {
  1405. // Could not create the font so just use the system's values
  1406. cxSysChar = LOWORD(GetDialogBaseUnits());
  1407. cySysChar = HIWORD(GetDialogBaseUnits());
  1408. }
  1409. ::ReleaseDC(NULL, hDC);
  1410. // Translate dialog units to pixels
  1411. pSizePixel->cx = MulDiv(cxDlg, cxSysChar, 4);
  1412. pSizePixel->cy = MulDiv(cyDlg, cySysChar, 8);
  1413. }
  1414. static BOOL IsDialogEx(const DLGTEMPLATE* pTemplate)
  1415. {
  1416. return ((_ATL_DLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF;
  1417. }
  1418. static BOOL HasFont(const DLGTEMPLATE* pTemplate)
  1419. {
  1420. return (DS_SETFONT &
  1421. (IsDialogEx(pTemplate) ?
  1422. ((_ATL_DLGTEMPLATEEX*)pTemplate)->style : pTemplate->style));
  1423. }
  1424. static BYTE* GetFontSizeField(const DLGTEMPLATE* pTemplate)
  1425. {
  1426. BOOL bDialogEx = IsDialogEx(pTemplate);
  1427. WORD* pw;
  1428. if (bDialogEx)
  1429. pw = (WORD*)((_ATL_DLGTEMPLATEEX*)pTemplate + 1);
  1430. else
  1431. pw = (WORD*)(pTemplate + 1);
  1432. if (*pw == (WORD)-1) // Skip menu name string or ordinal
  1433. pw += 2; // WORDs
  1434. else
  1435. while(*pw++);
  1436. if (*pw == (WORD)-1) // Skip class name string or ordinal
  1437. pw += 2; // WORDs
  1438. else
  1439. while(*pw++);
  1440. while (*pw++); // Skip caption string
  1441. return (BYTE*)pw;
  1442. }
  1443. static BOOL GetFont(const DLGTEMPLATE* pTemplate, TCHAR* pszFace, WORD* pFontSize)
  1444. {
  1445. USES_CONVERSION_EX;
  1446. if (!HasFont(pTemplate) || pFontSize == NULL)
  1447. return FALSE;
  1448. BYTE* pb = GetFontSizeField(pTemplate);
  1449. *pFontSize = *(WORD*)pb;
  1450. // Skip over font attributes to get to the font name
  1451. pb += sizeof(WORD) * (IsDialogEx(pTemplate) ? 3 : 1);
  1452. LPCTSTR szT = W2T_EX((WCHAR*)pb, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
  1453. if (NULL == szT)
  1454. {
  1455. return FALSE;
  1456. }
  1457. _tcsncpy(pszFace, szT, LF_FACESIZE);
  1458. if (_tcslen(szT) >= LF_FACESIZE)
  1459. { // NUL not appended
  1460. pszFace[LF_FACESIZE-1] = _T('\0');
  1461. }
  1462. return TRUE;
  1463. }
  1464. static void GetSizeInDialogUnits(const DLGTEMPLATE* pTemplate, SIZE* pSize)
  1465. {
  1466. if (IsDialogEx(pTemplate))
  1467. {
  1468. pSize->cx = ((_ATL_DLGTEMPLATEEX*)pTemplate)->cx;
  1469. pSize->cy = ((_ATL_DLGTEMPLATEEX*)pTemplate)->cy;
  1470. }
  1471. else
  1472. {
  1473. pSize->cx = pTemplate->cx;
  1474. pSize->cy = pTemplate->cy;
  1475. }
  1476. }
  1477. };
  1478. //////////////////////////////////////////////////////////////////////////////
  1479. // IPropertyPage2Impl
  1480. template <class T>
  1481. class ATL_NO_VTABLE IPropertyPage2Impl : public IPropertyPageImpl<T>
  1482. {
  1483. public:
  1484. STDMETHOD(EditProperty)(DISPID dispID)
  1485. {
  1486. ATLTRACENOTIMPL(_T("IPropertyPage2Impl::EditProperty\n"));
  1487. }
  1488. };
  1489. //////////////////////////////////////////////////////////////////////////////
  1490. // IPerPropertyBrowsingImpl
  1491. template <class T>
  1492. class ATL_NO_VTABLE IPerPropertyBrowsingImpl
  1493. {
  1494. public:
  1495. // IUnknown
  1496. //
  1497. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1498. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPerPropertyBrowsingImpl)
  1499. STDMETHOD(GetDisplayString)(DISPID dispID,BSTR *pBstr)
  1500. {
  1501. ATLTRACE(_T("IPerPropertyBrowsingImpl::GetDisplayString\n"));
  1502. T* pT = static_cast<T*>(this);
  1503. CComVariant var;
  1504. if (FAILED(CComDispatchDriver::GetProperty(pT, dispID, &var)))
  1505. {
  1506. *pBstr = NULL;
  1507. return S_FALSE;
  1508. }
  1509. BSTR bstrTemp = var.bstrVal;
  1510. if (var.vt != VT_BSTR)
  1511. {
  1512. CComVariant varDest;
  1513. if (FAILED(::VariantChangeType(&varDest, &var, VARIANT_NOVALUEPROP, VT_BSTR)))
  1514. {
  1515. *pBstr = NULL;
  1516. return S_FALSE;
  1517. }
  1518. bstrTemp = varDest.bstrVal;
  1519. }
  1520. *pBstr = SysAllocString(bstrTemp);
  1521. if (*pBstr == NULL)
  1522. return E_OUTOFMEMORY;
  1523. return S_OK;
  1524. }
  1525. STDMETHOD(MapPropertyToPage)(DISPID dispID, CLSID *pClsid)
  1526. {
  1527. ATLTRACE(_T("IPerPropertyBrowsingImpl::MapPropertyToPage\n"));
  1528. T* pT = static_cast<T*>(this);
  1529. ATL_PROPMAP_ENTRY* pMap = T::GetPropertyMap();
  1530. _ASSERTE(pMap != NULL);
  1531. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++)
  1532. {
  1533. if (pMap[i].szDesc == NULL)
  1534. continue;
  1535. if (pMap[i].dispid == dispID)
  1536. {
  1537. _ASSERTE(pMap[i].pclsidPropPage != NULL);
  1538. *pClsid = *(pMap[i].pclsidPropPage);
  1539. return S_OK;
  1540. }
  1541. }
  1542. *pClsid = CLSID_NULL;
  1543. return E_INVALIDARG;
  1544. }
  1545. STDMETHOD(GetPredefinedStrings)(DISPID dispID, CALPOLESTR *pCaStringsOut,CADWORD *pCaCookiesOut)
  1546. {
  1547. dispID;
  1548. ATLTRACE(_T("IPerPropertyBrowsingImpl::GetPredefinedStrings\n"));
  1549. if (pCaStringsOut == NULL || pCaCookiesOut == NULL)
  1550. return E_POINTER;
  1551. pCaStringsOut->cElems = 0;
  1552. pCaStringsOut->pElems = NULL;
  1553. pCaCookiesOut->cElems = 0;
  1554. pCaCookiesOut->pElems = NULL;
  1555. return S_OK;
  1556. }
  1557. STDMETHOD(GetPredefinedValue)(DISPID /*dispID*/, DWORD /*dwCookie*/, VARIANT* /*pVarOut*/)
  1558. {
  1559. ATLTRACENOTIMPL(_T("IPerPropertyBrowsingImpl::GetPredefinedValue"));
  1560. }
  1561. };
  1562. //////////////////////////////////////////////////////////////////////////////
  1563. // IViewObjectExImpl
  1564. template <class T>
  1565. class ATL_NO_VTABLE IViewObjectExImpl
  1566. {
  1567. public:
  1568. // IUnknown
  1569. //
  1570. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1571. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IViewObjectExImpl)
  1572. // IViewObject
  1573. //
  1574. STDMETHOD(Draw)(DWORD dwDrawAspect, LONG lindex, void *pvAspect,
  1575. DVTARGETDEVICE *ptd, HDC hicTargetDev, HDC hdcDraw,
  1576. LPCRECTL prcBounds, LPCRECTL prcWBounds,
  1577. BOOL (__stdcall * /*pfnContinue*/)(DWORD_PTR dwContinue),
  1578. DWORD_PTR /*dwContinue*/)
  1579. {
  1580. T* pT = static_cast<T*>(this);
  1581. ATLTRACE(_T("IViewObjectExImpl::Draw\n"));
  1582. return pT->IViewObject_Draw(dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, hdcDraw,
  1583. prcBounds, prcWBounds);
  1584. }
  1585. STDMETHOD(GetColorSet)(DWORD /* dwDrawAspect */,LONG /* lindex */, void* /* pvAspect */, DVTARGETDEVICE* /* ptd */, HDC /* hicTargetDev */, LOGPALETTE** /* ppColorSet */)
  1586. {
  1587. ATLTRACENOTIMPL(_T("IViewObjectExImpl::GetColorSet"));
  1588. }
  1589. STDMETHOD(Freeze)(DWORD /* dwDrawAspect */, LONG /* lindex */, void* /* pvAspect */,DWORD* /* pdwFreeze */)
  1590. {
  1591. ATLTRACENOTIMPL(_T("IViewObjectExImpl::Freeze"));
  1592. }
  1593. STDMETHOD(Unfreeze)(DWORD /* dwFreeze */)
  1594. {
  1595. ATLTRACENOTIMPL(_T("IViewObjectExImpl::Unfreeze"));
  1596. }
  1597. STDMETHOD(SetAdvise)(DWORD /* aspects */, DWORD /* advf */, IAdviseSink* pAdvSink)
  1598. {
  1599. T* pT = static_cast<T*>(this);
  1600. ATLTRACE(_T("IViewObjectExImpl::SetAdvise\n"));
  1601. pT->m_spAdviseSink = pAdvSink;
  1602. return S_OK;
  1603. }
  1604. STDMETHOD(GetAdvise)(DWORD* /* pAspects */, DWORD* /* pAdvf */, IAdviseSink** ppAdvSink)
  1605. {
  1606. T* pT = static_cast<T*>(this);
  1607. ATLTRACE(_T("IViewObjectExImpl::GetAdvise\n"));
  1608. if (ppAdvSink != NULL)
  1609. {
  1610. *ppAdvSink = pT->m_spAdviseSink;
  1611. if (pT->m_spAdviseSink)
  1612. pT->m_spAdviseSink.p->AddRef();
  1613. }
  1614. return S_OK;
  1615. }
  1616. // IViewObject2
  1617. //
  1618. STDMETHOD(GetExtent)(DWORD /* dwDrawAspect */, LONG /* lindex */, DVTARGETDEVICE* /* ptd */, LPSIZEL lpsizel)
  1619. {
  1620. T* pT = static_cast<T*>(this);
  1621. ATLTRACE(_T("IViewObjectExImpl::GetExtent\n"));
  1622. if (lpsizel == NULL)
  1623. return E_INVALIDARG;
  1624. *lpsizel = pT->m_sizeExtent;
  1625. return S_OK;
  1626. }
  1627. // IViewObjectEx
  1628. //
  1629. STDMETHOD(GetRect)(DWORD /* dwAspect */, LPRECTL /* pRect */)
  1630. {
  1631. ATLTRACENOTIMPL(_T("IViewObjectExImpl::GetRect"));
  1632. }
  1633. STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
  1634. {
  1635. ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
  1636. if (pdwStatus == NULL)
  1637. return E_INVALIDARG;
  1638. *pdwStatus =
  1639. // VIEWSTATUS_DVASPECTOPAQUE | VIEWSTATUS_DVASPECTTRANSPARENT |
  1640. // VIEWSTATUS_SOLIDBKGND |
  1641. VIEWSTATUS_OPAQUE;
  1642. return S_OK;
  1643. }
  1644. STDMETHOD(QueryHitPoint)(DWORD dwAspect, LPCRECT pRectBounds, POINT ptlLoc, LONG /* lCloseHint */, DWORD *pHitResult)
  1645. {
  1646. ATLTRACE(_T("IViewObjectExImpl::QueryHitPoint\n"));
  1647. if (pHitResult == NULL)
  1648. return E_INVALIDARG;
  1649. if (dwAspect == DVASPECT_CONTENT)
  1650. {
  1651. *pHitResult = PtInRect(pRectBounds, ptlLoc) ? HITRESULT_HIT : HITRESULT_OUTSIDE;
  1652. return S_OK;
  1653. }
  1654. ATLTRACE(_T("Wrong DVASPECT\n"));
  1655. return E_FAIL;
  1656. }
  1657. STDMETHOD(QueryHitRect)(DWORD dwAspect, LPCRECT pRectBounds, LPCRECT prcLoc, LONG /* lCloseHint */, DWORD* pHitResult)
  1658. {
  1659. ATLTRACE(_T("IViewObjectExImpl::QueryHitRect\n"));
  1660. if (pHitResult == NULL)
  1661. return E_INVALIDARG;
  1662. if (dwAspect == DVASPECT_CONTENT)
  1663. {
  1664. RECT rc;
  1665. *pHitResult = UnionRect(&rc, pRectBounds, prcLoc) ? HITRESULT_HIT : HITRESULT_OUTSIDE;
  1666. return S_OK;
  1667. }
  1668. ATLTRACE(_T("Wrong DVASPECT\n"));
  1669. return E_FAIL;
  1670. }
  1671. STDMETHOD(GetNaturalExtent)(DWORD dwAspect, LONG /* lindex */, DVTARGETDEVICE* /* ptd */, HDC /* hicTargetDev */, DVEXTENTINFO* pExtentInfo , LPSIZEL psizel)
  1672. {
  1673. T* pT = static_cast<T*>(this);
  1674. ATLTRACE(_T("IViewObjectExImpl::GetNaturalExtent\n"));
  1675. if (psizel == NULL)
  1676. return E_INVALIDARG;
  1677. HRESULT hRes = E_FAIL;
  1678. if (dwAspect == DVASPECT_CONTENT)
  1679. {
  1680. if (pExtentInfo->dwExtentMode == DVEXTENT_CONTENT)
  1681. {
  1682. *psizel = pT->m_sizeNatural;
  1683. hRes = S_OK;
  1684. }
  1685. }
  1686. return hRes;
  1687. }
  1688. public:
  1689. };
  1690. //////////////////////////////////////////////////////////////////////////////
  1691. // IOleInPlaceObjectWindowlessImpl
  1692. //
  1693. template <class T>
  1694. class ATL_NO_VTABLE IOleInPlaceObjectWindowlessImpl
  1695. {
  1696. public:
  1697. // IUnknown
  1698. //
  1699. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1700. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleInPlaceObjectWindowlessImpl)
  1701. // IOleWindow
  1702. //
  1703. // Change IOleInPlaceActiveObject::GetWindow as well
  1704. STDMETHOD(GetWindow)(HWND* phwnd)
  1705. {
  1706. ATLTRACE(_T("IOleInPlaceObjectWindowlessImpl::GetWindow\n"));
  1707. T* pT = static_cast<T*>(this);
  1708. HRESULT hRes = E_POINTER;
  1709. if (pT->m_bWasOnceWindowless)
  1710. return E_FAIL;
  1711. if (phwnd != NULL)
  1712. {
  1713. *phwnd = pT->m_hWnd;
  1714. hRes = (*phwnd == NULL) ? E_UNEXPECTED : S_OK;
  1715. }
  1716. return hRes;
  1717. }
  1718. STDMETHOD(ContextSensitiveHelp)(BOOL /* fEnterMode */)
  1719. {
  1720. ATLTRACENOTIMPL(_T("IOleInPlaceObjectWindowlessImpl::ContextSensitiveHelp"));
  1721. }
  1722. // IOleInPlaceObject
  1723. //
  1724. STDMETHOD(InPlaceDeactivate)(void)
  1725. {
  1726. T* pT = static_cast<T*>(this);
  1727. ATLTRACE(_T("IOleInPlaceObjectWindowlessImpl::InPlaceDeactivate\n"));
  1728. return pT->IOleInPlaceObject_InPlaceDeactivate();
  1729. }
  1730. STDMETHOD(UIDeactivate)(void)
  1731. {
  1732. T* pT = static_cast<T*>(this);
  1733. ATLTRACE(_T("IOleInPlaceObjectWindowlessImpl::UIDeactivate\n"));
  1734. return pT->IOleInPlaceObject_UIDeactivate();
  1735. }
  1736. STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
  1737. {
  1738. T* pT = static_cast<T*>(this);
  1739. ATLTRACE(_T("IOleInPlaceObjectWindowlessImpl::SetObjectRects\n"));
  1740. return pT->IOleInPlaceObject_SetObjectRects(prcPos, prcClip);
  1741. }
  1742. STDMETHOD(ReactivateAndUndo)(void)
  1743. {
  1744. ATLTRACENOTIMPL(_T("IOleInPlaceObjectWindowlessImpl::ReactivateAndUndo"));
  1745. }
  1746. // IOleInPlaceObjectWindowless
  1747. //
  1748. STDMETHOD(OnWindowMessage)(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
  1749. {
  1750. ATLTRACE(_T("IOleInPlaceObjectWindowlessImpl::OnWindowMessage\n"));
  1751. T* pT = static_cast<T*>(this);
  1752. return (pT->ProcessWindowMessage(pT->m_hWnd, msg, wParam, lParam, *plResult)) ? S_OK : S_FALSE;
  1753. }
  1754. STDMETHOD(GetDropTarget)(IDropTarget** /* ppDropTarget */)
  1755. {
  1756. ATLTRACENOTIMPL(_T("IOleInPlaceObjectWindowlessImpl::GetDropTarget"));
  1757. }
  1758. };
  1759. //////////////////////////////////////////////////////////////////////////////
  1760. // IOleInPlaceActiveObjectImpl
  1761. //
  1762. template <class T>
  1763. class ATL_NO_VTABLE IOleInPlaceActiveObjectImpl
  1764. {
  1765. public:
  1766. // IUnknown
  1767. //
  1768. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1769. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleInPlaceActiveObjectImpl)
  1770. // IOleWindow
  1771. //
  1772. // Change IOleInPlaceObjectWindowless::GetWindow as well
  1773. STDMETHOD(GetWindow)(HWND *phwnd)
  1774. {
  1775. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::GetWindow\n"));
  1776. T* pT = static_cast<T*>(this);
  1777. HRESULT hRes = E_POINTER;
  1778. if (pT->m_bWasOnceWindowless)
  1779. return E_FAIL;
  1780. if (phwnd != NULL)
  1781. {
  1782. *phwnd = pT->m_hWnd;
  1783. hRes = (*phwnd == NULL) ? E_UNEXPECTED : S_OK;
  1784. }
  1785. return hRes;
  1786. }
  1787. STDMETHOD(ContextSensitiveHelp)(BOOL /* fEnterMode */)
  1788. {
  1789. ATLTRACENOTIMPL(_T("IOleInPlaceActiveObjectImpl::ContextSensitiveHelp"));
  1790. }
  1791. // IOleInPlaceActiveObject
  1792. //
  1793. STDMETHOD(TranslateAccelerator)(LPMSG /* lpmsg */)
  1794. {
  1795. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::TranslateAccelerator\n"));
  1796. return E_NOTIMPL;
  1797. }
  1798. STDMETHOD(OnFrameWindowActivate)(BOOL /* fActivate */)
  1799. {
  1800. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::OnFrameWindowActivate\n"));
  1801. return S_OK;
  1802. }
  1803. STDMETHOD(OnDocWindowActivate)(BOOL /* fActivate */)
  1804. {
  1805. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::OnDocWindowActivate\n"));
  1806. return S_OK;
  1807. }
  1808. STDMETHOD(ResizeBorder)(LPCRECT /* prcBorder */, IOleInPlaceUIWindow* /* pUIWindow */, BOOL /* fFrameWindow */)
  1809. {
  1810. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::ResizeBorder\n"));
  1811. return S_OK;
  1812. }
  1813. STDMETHOD(EnableModeless)(BOOL /* fEnable */)
  1814. {
  1815. ATLTRACE(_T("IOleInPlaceActiveObjectImpl::EnableModeless\n"));
  1816. return S_OK;
  1817. }
  1818. };
  1819. //////////////////////////////////////////////////////////////////////////////
  1820. // ISpecifyPropertyPagesImpl
  1821. template <class T>
  1822. class ATL_NO_VTABLE ISpecifyPropertyPagesImpl
  1823. {
  1824. public:
  1825. // IUnknown
  1826. //
  1827. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1828. _ATL_DEBUG_ADDREF_RELEASE_IMPL(ISpecifyPropertyPagesImpl)
  1829. // ISpecifyPropertyPages
  1830. //
  1831. STDMETHOD(GetPages)(CAUUID* pPages)
  1832. {
  1833. ATLTRACE(_T("ISpecifyPropertyPagesImpl::GetPages\n"));
  1834. T* pT = static_cast<T*>(this);
  1835. ATL_PROPMAP_ENTRY* pMap = T::GetPropertyMap();
  1836. return pT->ISpecifyPropertyPages_GetPages(pPages, pMap);
  1837. }
  1838. };
  1839. //////////////////////////////////////////////////////////////////////////////
  1840. // IPointerInactiveImpl
  1841. template <class T>
  1842. class ATL_NO_VTABLE IPointerInactiveImpl
  1843. {
  1844. public:
  1845. // IUnknown
  1846. //
  1847. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1848. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IPointerInactiveImpl)
  1849. // IPointerInactive
  1850. //
  1851. STDMETHOD(GetActivationPolicy)(DWORD *pdwPolicy)
  1852. {
  1853. ATLTRACENOTIMPL(_T("IPointerInactiveImpl::GetActivationPolicy"));
  1854. }
  1855. STDMETHOD(OnInactiveMouseMove)(LPCRECT pRectBounds, long x, long y, DWORD dwMouseMsg)
  1856. {
  1857. ATLTRACENOTIMPL(_T("IPointerInactiveImpl::OnInactiveMouseMove"));
  1858. }
  1859. STDMETHOD(OnInactiveSetCursor)(LPCRECT pRectBounds, long x, long y, DWORD dwMouseMsg, BOOL fSetAlways)
  1860. {
  1861. ATLTRACENOTIMPL(_T("IPointerInactiveImpl::OnInactiveSetCursor"));
  1862. }
  1863. };
  1864. //////////////////////////////////////////////////////////////////////////////
  1865. // IRunnableObjectImpl
  1866. template <class T>
  1867. class ATL_NO_VTABLE IRunnableObjectImpl
  1868. {
  1869. public:
  1870. // IUnknown
  1871. //
  1872. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1873. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IRunnableObjectImpl)
  1874. // IRunnableObject
  1875. //
  1876. STDMETHOD(GetRunningClass)(LPCLSID lpClsid)
  1877. {
  1878. ATLTRACE(_T("IRunnableObjectImpl::GetRunningClass\n"));
  1879. if (lpClsid == NULL)
  1880. return E_POINTER;
  1881. T* pT = static_cast<T*>(this);
  1882. *lpClsid = GUID_NULL;
  1883. return E_UNEXPECTED;
  1884. }
  1885. STDMETHOD(Run)(LPBINDCTX)
  1886. {
  1887. ATLTRACE(_T("IRunnableObjectImpl::Run\n"));
  1888. return S_OK;
  1889. }
  1890. virtual BOOL STDMETHODCALLTYPE IsRunning()
  1891. {
  1892. ATLTRACE(_T("IRunnableObjectImpl::IsRunning\n"));
  1893. return TRUE;
  1894. }
  1895. STDMETHOD(LockRunning)(BOOL /*fLock*/, BOOL /*fLastUnlockCloses*/)
  1896. {
  1897. ATLTRACE(_T("IRunnableObjectImpl::LockRunning\n"));
  1898. return S_OK;
  1899. }
  1900. STDMETHOD(SetContainedObject)(BOOL /*fContained*/)
  1901. {
  1902. ATLTRACE(_T("IRunnableObjectImpl::SetContainedObject\n"));
  1903. return S_OK;
  1904. }
  1905. };
  1906. //////////////////////////////////////////////////////////////////////////////
  1907. // IDataObjectImpl
  1908. template <class T>
  1909. class ATL_NO_VTABLE IDataObjectImpl
  1910. {
  1911. public:
  1912. // IUnknown
  1913. //
  1914. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  1915. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IDataObjectImpl)
  1916. // IDataObject
  1917. //
  1918. STDMETHOD(GetData)(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
  1919. {
  1920. ATLTRACE(_T("IDataObjectImpl::GetData\n"));
  1921. T* pT = (T*) this;
  1922. return pT->IDataObject_GetData(pformatetcIn, pmedium);
  1923. }
  1924. STDMETHOD(GetDataHere)(FORMATETC* /* pformatetc */, STGMEDIUM* /* pmedium */)
  1925. {
  1926. ATLTRACENOTIMPL(_T("IDataObjectImpl::GetDataHere"));
  1927. }
  1928. STDMETHOD(QueryGetData)(FORMATETC* /* pformatetc */)
  1929. {
  1930. ATLTRACENOTIMPL(_T("IDataObjectImpl::QueryGetData"));
  1931. }
  1932. STDMETHOD(GetCanonicalFormatEtc)(FORMATETC* /* pformatectIn */,FORMATETC* /* pformatetcOut */)
  1933. {
  1934. ATLTRACENOTIMPL(_T("IDataObjectImpl::GetCanonicalFormatEtc"));
  1935. }
  1936. STDMETHOD(SetData)(FORMATETC* /* pformatetc */, STGMEDIUM* /* pmedium */, BOOL /* fRelease */)
  1937. {
  1938. ATLTRACENOTIMPL(_T("IDataObjectImpl::SetData"));
  1939. }
  1940. STDMETHOD(EnumFormatEtc)(DWORD /* dwDirection */, IEnumFORMATETC** /* ppenumFormatEtc */)
  1941. {
  1942. ATLTRACENOTIMPL(_T("IDataObjectImpl::EnumFormatEtc"));
  1943. }
  1944. STDMETHOD(DAdvise)(FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink,
  1945. DWORD *pdwConnection)
  1946. {
  1947. ATLTRACE(_T("IDataObjectImpl::DAdvise\n"));
  1948. T* pT = static_cast<T*>(this);
  1949. HRESULT hr = S_OK;
  1950. if (pT->m_spDataAdviseHolder == NULL)
  1951. hr = CreateDataAdviseHolder(&pT->m_spDataAdviseHolder);
  1952. if (hr == S_OK)
  1953. hr = pT->m_spDataAdviseHolder->Advise((IDataObject*)this, pformatetc, advf, pAdvSink, pdwConnection);
  1954. return hr;
  1955. }
  1956. STDMETHOD(DUnadvise)(DWORD dwConnection)
  1957. {
  1958. ATLTRACE(_T("IDataObjectImpl::DUnadvise\n"));
  1959. T* pT = static_cast<T*>(this);
  1960. HRESULT hr = S_OK;
  1961. if (pT->m_spDataAdviseHolder == NULL)
  1962. hr = OLE_E_NOCONNECTION;
  1963. else
  1964. hr = pT->m_spDataAdviseHolder->Unadvise(dwConnection);
  1965. return hr;
  1966. }
  1967. STDMETHOD(EnumDAdvise)(IEnumSTATDATA **ppenumAdvise)
  1968. {
  1969. ATLTRACE(_T("IDataObjectImpl::EnumDAdvise\n"));
  1970. T* pT = static_cast<T*>(this);
  1971. HRESULT hr = E_FAIL;
  1972. if (pT->m_spDataAdviseHolder != NULL)
  1973. hr = pT->m_spDataAdviseHolder->EnumAdvise(ppenumAdvise);
  1974. return hr;
  1975. }
  1976. };
  1977. //////////////////////////////////////////////////////////////////////////////
  1978. // IPropertyNotifySinkCP
  1979. template <class T, class CDV = CComDynamicUnkArray >
  1980. class ATL_NO_VTABLE IPropertyNotifySinkCP :
  1981. public IConnectionPointImpl<T, &IID_IPropertyNotifySink, CDV>
  1982. {
  1983. public:
  1984. typedef CFirePropNotifyEvent _ATL_PROP_NOTIFY_EVENT_CLASS;
  1985. };
  1986. //////////////////////////////////////////////////////////////////////////////
  1987. // IObjectSafety
  1988. //
  1989. template <class T>
  1990. class ATL_NO_VTABLE IObjectSafetyImpl
  1991. {
  1992. public:
  1993. IObjectSafetyImpl()
  1994. {
  1995. m_dwSafety = 0;
  1996. }
  1997. // IUnknown
  1998. //
  1999. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  2000. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IObjectSafetyImpl)
  2001. // IObjectSafety
  2002. //
  2003. STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
  2004. {
  2005. ATLTRACE(_T("IObjectSafetyImpl::GetInterfaceSafetyOptions\n"));
  2006. if (pdwSupportedOptions == NULL || pdwEnabledOptions == NULL)
  2007. return E_POINTER;
  2008. HRESULT hr = S_OK;
  2009. if (riid == IID_IDispatch)
  2010. {
  2011. *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  2012. *pdwEnabledOptions = m_dwSafety & INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  2013. }
  2014. else
  2015. {
  2016. *pdwSupportedOptions = 0;
  2017. *pdwEnabledOptions = 0;
  2018. hr = E_NOINTERFACE;
  2019. }
  2020. return hr;
  2021. }
  2022. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
  2023. {
  2024. ATLTRACE(_T("IObjectSafetyImpl::SetInterfaceSafetyOptions\n"));
  2025. // If we're being asked to set our safe for scripting option then oblige
  2026. if (riid == IID_IDispatch)
  2027. {
  2028. // Store our current safety level to return in GetInterfaceSafetyOptions
  2029. m_dwSafety = dwEnabledOptions & dwOptionSetMask;
  2030. return S_OK;
  2031. }
  2032. return E_NOINTERFACE;
  2033. }
  2034. DWORD m_dwSafety;
  2035. };
  2036. template <class T>
  2037. class ATL_NO_VTABLE IOleLinkImpl
  2038. {
  2039. // IUnknown
  2040. //
  2041. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  2042. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IOleLinkImpl)
  2043. STDMETHOD(SetUpdateOptions)(DWORD /* dwUpdateOpt */)
  2044. {
  2045. ATLTRACENOTIMPL(_T("IOleLinkImpl::SetUpdateOptions"));
  2046. }
  2047. STDMETHOD(GetUpdateOptions)(DWORD* /* pdwUpdateOpt */)
  2048. {
  2049. ATLTRACENOTIMPL(_T("IOleLinkImpl::GetUpdateOptions"));
  2050. }
  2051. STDMETHOD(SetSourceMoniker)(IMoniker* /* pmk */, REFCLSID /* rclsid */)
  2052. {
  2053. ATLTRACENOTIMPL(_T("IOleLinkImpl::SetSourceMoniker"));
  2054. }
  2055. STDMETHOD(GetSourceMoniker)(IMoniker** /* ppmk */)
  2056. {
  2057. ATLTRACENOTIMPL(_T("IOleLinkImpl::GetSourceMoniker"));
  2058. };
  2059. STDMETHOD(SetSourceDisplayName)(LPCOLESTR /* pszStatusText */)
  2060. {
  2061. ATLTRACENOTIMPL(_T("IOleLinkImpl::SetSourceDisplayName"));
  2062. }
  2063. STDMETHOD(GetSourceDisplayName)(LPOLESTR *ppszDisplayName)
  2064. {
  2065. ATLTRACE(_T("IOleLink::GetSourceDisplayName\n"));
  2066. if (ppszDisplayName == NULL)
  2067. return E_POINTER;
  2068. *ppszDisplayName = NULL;
  2069. return E_FAIL;
  2070. }
  2071. STDMETHOD(BindToSource)(DWORD /* bindflags */, IBindCtx* /* pbc */)
  2072. {
  2073. ATLTRACENOTIMPL(_T("IOleLinkImpl::BindToSource\n"));
  2074. };
  2075. STDMETHOD(BindIfRunning)()
  2076. {
  2077. ATLTRACE(_T("IOleLinkImpl::BindIfRunning\n"));
  2078. return S_OK;
  2079. };
  2080. STDMETHOD(GetBoundSource)(IUnknown** /* ppunk */)
  2081. {
  2082. ATLTRACENOTIMPL(_T("IOleLinkImpl::GetBoundSource"));
  2083. };
  2084. STDMETHOD(UnbindSource)()
  2085. {
  2086. ATLTRACENOTIMPL(_T("IOleLinkImpl::UnbindSource"));
  2087. };
  2088. STDMETHOD(Update)(IBindCtx* /* pbc */)
  2089. {
  2090. ATLTRACENOTIMPL(_T("IOleLinkImpl::Update"));
  2091. };
  2092. };
  2093. template <class T>
  2094. class ATL_NO_VTABLE IBindStatusCallbackImpl
  2095. {
  2096. public:
  2097. // IUnknown
  2098. //
  2099. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  2100. _ATL_DEBUG_ADDREF_RELEASE_IMPL(IBindStatusCallbackImpl)
  2101. // IBindStatusCallback
  2102. //
  2103. STDMETHOD(OnStartBinding)(DWORD /* dwReserved */, IBinding *pBinding)
  2104. {
  2105. ATLTRACE(_T("IBindStatusCallbackImpl::OnStartBinding\n"));
  2106. return S_OK;
  2107. }
  2108. STDMETHOD(GetPriority)(LONG* /* pnPriority */)
  2109. {
  2110. ATLTRACENOTIMPL(_T("IBindStatusCallbackImpl::GetPriority"));
  2111. }
  2112. STDMETHOD(OnLowResource)(DWORD /* reserved */)
  2113. {
  2114. ATLTRACE(_T("IBindStatusCallbackImpl::OnLowResource\n"));
  2115. return S_OK;
  2116. }
  2117. STDMETHOD(OnProgress)(ULONG /* ulProgress */, ULONG /* ulProgressMax */, ULONG /* ulStatusCode */, LPCWSTR /* szStatusText */)
  2118. {
  2119. ATLTRACE(_T("IBindStatusCallbackImpl::OnProgress\n"));
  2120. return S_OK;
  2121. }
  2122. STDMETHOD(OnStopBinding)(HRESULT /* hresult */, LPCWSTR /* szError */)
  2123. {
  2124. ATLTRACE(_T("IBindStatusCallbackImpl::OnStopBinding\n"));
  2125. return S_OK;
  2126. }
  2127. STDMETHOD(GetBindInfo)(DWORD* /* pgrfBINDF */, BINDINFO* /* pBindInfo */)
  2128. {
  2129. ATLTRACE(_T("IBindStatusCallbackImpl::GetBindInfo\n"));
  2130. return S_OK;
  2131. }
  2132. STDMETHOD(OnDataAvailable)(DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
  2133. {
  2134. ATLTRACE(_T("IBindStatusCallbackImpl::OnDataAvailable\n"));
  2135. return S_OK;
  2136. }
  2137. STDMETHOD(OnObjectAvailable)(REFIID /* riid */, IUnknown* /* punk */)
  2138. {
  2139. ATLTRACE(_T("IBindStatusCallbackImpl::OnObjectAvailable\n"));
  2140. return S_OK;
  2141. }
  2142. };
  2143. template <class T>
  2144. class ATL_NO_VTABLE CBindStatusCallback :
  2145. public CComObjectRootEx<typename T::_ThreadModel::ThreadModelNoCS>,
  2146. public IBindStatusCallbackImpl<T>
  2147. {
  2148. typedef void (T::*ATL_PDATAAVAILABLE)(CBindStatusCallback<T>* pbsc, BYTE* pBytes, DWORD dwSize);
  2149. public:
  2150. BEGIN_COM_MAP(CBindStatusCallback<T>)
  2151. COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback, IBindStatusCallbackImpl<T>)
  2152. END_COM_MAP()
  2153. CBindStatusCallback()
  2154. {
  2155. m_pT = NULL;
  2156. m_pFunc = NULL;
  2157. }
  2158. ~CBindStatusCallback()
  2159. {
  2160. ATLTRACE(_T("~CBindStatusCallback\n"));
  2161. }
  2162. STDMETHOD(OnStartBinding)(DWORD dwReserved, IBinding *pBinding)
  2163. {
  2164. ATLTRACE(_T("CBindStatusCallback::OnStartBinding\n"));
  2165. m_spBinding = pBinding;
  2166. return S_OK;
  2167. }
  2168. STDMETHOD(GetPriority)(LONG *pnPriority)
  2169. {
  2170. ATLTRACENOTIMPL(_T("CBindStatusCallback::GetPriority"));
  2171. }
  2172. STDMETHOD(OnLowResource)(DWORD reserved)
  2173. {
  2174. ATLTRACENOTIMPL(_T("CBindStatusCallback::OnLowResource"));
  2175. }
  2176. STDMETHOD(OnProgress)(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
  2177. {
  2178. ATLTRACENOTIMPL(_T("CBindStatusCallback::OnProgress"));
  2179. }
  2180. STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR szError)
  2181. {
  2182. ATLTRACE(_T("CBindStatusCallback::OnStopBinding\n"));
  2183. m_spBinding.Release();
  2184. m_spBindCtx.Release();
  2185. m_spMoniker.Release();
  2186. return S_OK;
  2187. }
  2188. STDMETHOD(GetBindInfo)(DWORD *pgrfBINDF, BINDINFO *pbindInfo)
  2189. {
  2190. ATLTRACE(_T("CBindStatusCallback::GetBindInfo\n"));
  2191. if (pbindInfo==NULL || pbindInfo->cbSize==0 || pgrfBINDF==NULL)
  2192. return E_INVALIDARG;
  2193. *pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE |
  2194. BINDF_GETNEWESTVERSION | BINDF_NOWRITECACHE;
  2195. ULONG cbSize = pbindInfo->cbSize; // remember incoming cbSize
  2196. memset(pbindInfo, 0, cbSize); // zero out structure
  2197. pbindInfo->cbSize = cbSize; // restore cbSize
  2198. pbindInfo->dwBindVerb = BINDVERB_GET; // set verb
  2199. return S_OK;
  2200. }
  2201. STDMETHOD(OnDataAvailable)(DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
  2202. {
  2203. ATLTRACE(_T("CBindStatusCallback::OnDataAvailable\n"));
  2204. HRESULT hr = S_OK;
  2205. if (pstgmed == NULL)
  2206. return E_INVALIDARG;
  2207. // Get the Stream passed
  2208. if (BSCF_FIRSTDATANOTIFICATION & grfBSCF)
  2209. {
  2210. if (!m_spStream && pstgmed->tymed == TYMED_ISTREAM)
  2211. m_spStream = pstgmed->pstm;
  2212. }
  2213. DWORD dwRead = dwSize - m_dwTotalRead; // Minimum amount available that hasn't been read
  2214. DWORD dwActuallyRead = 0; // Placeholder for amount read during this pull
  2215. // If there is some data to be read then go ahead and read them
  2216. if (m_spStream)
  2217. {
  2218. if (dwRead > 0)
  2219. {
  2220. BYTE* pBytes = NULL;
  2221. ATLTRY(pBytes = new BYTE[dwRead + 1]);
  2222. if (pBytes == NULL)
  2223. return S_FALSE;
  2224. hr = m_spStream->Read(pBytes, dwRead, &dwActuallyRead);
  2225. if (SUCCEEDED(hr))
  2226. {
  2227. pBytes[dwActuallyRead] = 0;
  2228. if (dwActuallyRead>0)
  2229. {
  2230. (m_pT->*m_pFunc)(this, pBytes, dwActuallyRead);
  2231. m_dwTotalRead += dwActuallyRead;
  2232. }
  2233. }
  2234. delete[] pBytes;
  2235. }
  2236. }
  2237. if (BSCF_LASTDATANOTIFICATION & grfBSCF)
  2238. m_spStream.Release();
  2239. return hr;
  2240. }
  2241. STDMETHOD(OnObjectAvailable)(REFIID riid, IUnknown *punk)
  2242. {
  2243. ATLTRACENOTIMPL(_T("CBindStatusCallback::OnObjectAvailable"));
  2244. }
  2245. HRESULT _StartAsyncDownload(BSTR bstrURL, IUnknown* pUnkContainer, BOOL bRelative)
  2246. {
  2247. m_dwTotalRead = 0;
  2248. m_dwAvailableToRead = 0;
  2249. HRESULT hr = S_OK;
  2250. CComQIPtr<IServiceProvider, &IID_IServiceProvider> spServiceProvider(pUnkContainer);
  2251. CComPtr<IBindHost> spBindHost;
  2252. CComPtr<IStream> spStream;
  2253. if (spServiceProvider)
  2254. spServiceProvider->QueryService(SID_IBindHost, IID_IBindHost, (void**)&spBindHost);
  2255. if (spBindHost == NULL)
  2256. {
  2257. if (bRelative)
  2258. return E_NOINTERFACE; // relative asked for, but no IBindHost
  2259. hr = CreateURLMoniker(NULL, bstrURL, &m_spMoniker);
  2260. if (SUCCEEDED(hr))
  2261. hr = CreateBindCtx(0, &m_spBindCtx);
  2262. if (SUCCEEDED(hr))
  2263. hr = RegisterBindStatusCallback(m_spBindCtx, reinterpret_cast<IBindStatusCallback*>(static_cast<IBindStatusCallbackImpl<T>*>(this)), 0, 0L);
  2264. else
  2265. m_spMoniker.Release();
  2266. if (SUCCEEDED(hr))
  2267. hr = m_spMoniker->BindToStorage(m_spBindCtx, 0, IID_IStream, (void**)&spStream);
  2268. }
  2269. else
  2270. {
  2271. hr = CreateBindCtx(0, &m_spBindCtx);
  2272. if (SUCCEEDED(hr))
  2273. hr = RegisterBindStatusCallback(m_spBindCtx, reinterpret_cast<IBindStatusCallback*>(static_cast<IBindStatusCallbackImpl<T>*>(this)), 0, 0L);
  2274. if (SUCCEEDED(hr))
  2275. {
  2276. if (bRelative)
  2277. hr = spBindHost->CreateMoniker(bstrURL, m_spBindCtx, &m_spMoniker, 0);
  2278. else
  2279. hr = CreateURLMoniker(NULL, bstrURL, &m_spMoniker);
  2280. }
  2281. if (SUCCEEDED(hr))
  2282. {
  2283. hr = spBindHost->MonikerBindToStorage(m_spMoniker, NULL, reinterpret_cast<IBindStatusCallback*>(static_cast<IBindStatusCallbackImpl<T>*>(this)), IID_IStream, (void**)&spStream);
  2284. ATLTRACE(_T("Bound"));
  2285. }
  2286. }
  2287. return hr;
  2288. }
  2289. HRESULT StartAsyncDownload(T* pT, ATL_PDATAAVAILABLE pFunc, BSTR bstrURL, IUnknown* pUnkContainer = NULL, BOOL bRelative = FALSE)
  2290. {
  2291. m_pT = pT;
  2292. m_pFunc = pFunc;
  2293. return _StartAsyncDownload(bstrURL, pUnkContainer, bRelative);
  2294. }
  2295. static HRESULT Download(T* pT, ATL_PDATAAVAILABLE pFunc, BSTR bstrURL, IUnknown* pUnkContainer = NULL, BOOL bRelative = FALSE)
  2296. {
  2297. CComObject<CBindStatusCallback<T> > *pbsc;
  2298. HRESULT hRes = CComObject<CBindStatusCallback<T> >::CreateInstance(&pbsc);
  2299. if (FAILED(hRes))
  2300. return hRes;
  2301. return pbsc->StartAsyncDownload(pT, pFunc, bstrURL, pUnkContainer, bRelative);
  2302. }
  2303. CComPtr<IMoniker> m_spMoniker;
  2304. CComPtr<IBindCtx> m_spBindCtx;
  2305. CComPtr<IBinding> m_spBinding;
  2306. CComPtr<IStream> m_spStream;
  2307. T* m_pT;
  2308. ATL_PDATAAVAILABLE m_pFunc;
  2309. DWORD m_dwTotalRead;
  2310. DWORD m_dwAvailableToRead;
  2311. };
  2312. #define IMPLEMENT_STOCKPROP(type, fname, pname, dispid) \
  2313. HRESULT STDMETHODCALLTYPE put_##fname(type pname) \
  2314. { \
  2315. T* pT = (T*) this; \
  2316. if (pT->FireOnRequestEdit(dispid) == S_FALSE) \
  2317. return S_FALSE; \
  2318. pT->m_##pname = pname; \
  2319. pT->m_bRequiresSave = TRUE; \
  2320. pT->FireOnChanged(dispid); \
  2321. pT->FireViewChange(); \
  2322. return S_OK; \
  2323. } \
  2324. HRESULT STDMETHODCALLTYPE get_##fname(type* p##pname) \
  2325. { \
  2326. T* pT = (T*) this; \
  2327. *p##pname = pT->m_##pname; \
  2328. return S_OK; \
  2329. }
  2330. #define IMPLEMENT_BOOL_STOCKPROP(fname, pname, dispid) \
  2331. HRESULT STDMETHODCALLTYPE put_##fname(VARIANT_BOOL pname) \
  2332. { \
  2333. T* pT = (T*) this; \
  2334. if (pT->FireOnRequestEdit(dispid) == S_FALSE) \
  2335. return S_FALSE; \
  2336. pT->m_##pname = pname; \
  2337. pT->m_bRequiresSave = TRUE; \
  2338. pT->FireOnChanged(dispid); \
  2339. pT->FireViewChange(); \
  2340. return S_OK; \
  2341. } \
  2342. HRESULT STDMETHODCALLTYPE get_##fname(VARIANT_BOOL* p##pname) \
  2343. { \
  2344. T* pT = (T*) this; \
  2345. *p##pname = pT->m_##pname ? VARIANT_TRUE : VARIANT_FALSE; \
  2346. return S_OK; \
  2347. }
  2348. #define IMPLEMENT_BSTR_STOCKPROP(fname, pname, dispid) \
  2349. HRESULT STDMETHODCALLTYPE put_##fname(BSTR pname) \
  2350. { \
  2351. T* pT = (T*) this; \
  2352. if (pT->FireOnRequestEdit(dispid) == S_FALSE) \
  2353. return S_FALSE; \
  2354. *(&(pT->m_##pname)) = SysAllocString(pname); \
  2355. pT->m_bRequiresSave = TRUE; \
  2356. pT->FireOnChanged(dispid); \
  2357. pT->FireViewChange(); \
  2358. return S_OK; \
  2359. } \
  2360. HRESULT STDMETHODCALLTYPE get_##fname(BSTR* p##pname) \
  2361. { \
  2362. T* pT = (T*) this; \
  2363. *p##pname = SysAllocString(pT->m_##pname); \
  2364. return S_OK; \
  2365. }
  2366. template < class T, class InterfaceName, const IID* piid, const GUID* plibid>
  2367. class ATL_NO_VTABLE CStockPropImpl : public IDispatchImpl< InterfaceName, piid, plibid >
  2368. {
  2369. public:
  2370. // Font
  2371. HRESULT STDMETHODCALLTYPE put_Font(IFontDisp* pFont)
  2372. {
  2373. T* pT = (T*) this;
  2374. if (pT->FireOnRequestEdit(DISPID_FONT) == S_FALSE)
  2375. return S_FALSE;
  2376. pT->m_pFont = 0;
  2377. if (pFont)
  2378. {
  2379. CComQIPtr<IFont, &IID_IFont> p(pFont);
  2380. if (p)
  2381. {
  2382. CComPtr<IFont> pFont;
  2383. p->Clone(&pFont);
  2384. if (pFont)
  2385. pFont->QueryInterface(IID_IFontDisp, (void**) &pT->m_pFont);
  2386. }
  2387. }
  2388. pT->m_bRequiresSave = TRUE;
  2389. pT->FireOnChanged(DISPID_FONT);
  2390. pT->FireViewChange();
  2391. return S_OK;
  2392. }
  2393. HRESULT STDMETHODCALLTYPE putref_Font(IFontDisp* pFont)
  2394. {
  2395. T* pT = (T*) this;
  2396. if (pT->FireOnRequestEdit(DISPID_FONT) == S_FALSE)
  2397. return S_FALSE;
  2398. pT->m_pFont = pFont;
  2399. pT->m_bRequiresSave = TRUE;
  2400. pT->FireOnChanged(DISPID_FONT);
  2401. pT->FireViewChange();
  2402. return S_OK;
  2403. }
  2404. HRESULT STDMETHODCALLTYPE get_Font(IFontDisp** ppFont)
  2405. {
  2406. T* pT = (T*) this;
  2407. *ppFont = pT->m_pFont;
  2408. if (*ppFont != NULL)
  2409. (*ppFont)->AddRef();
  2410. return S_OK;
  2411. }
  2412. // Picture
  2413. HRESULT STDMETHODCALLTYPE put_Picture(IPictureDisp* pPicture)
  2414. {
  2415. T* pT = (T*) this;
  2416. if (pT->FireOnRequestEdit(DISPID_PICTURE) == S_FALSE)
  2417. return S_FALSE;
  2418. pT->m_pPicture = 0;
  2419. if (pPicture)
  2420. {
  2421. CComQIPtr<IPersistStream, &IID_IPersistStream> p(pPicture);
  2422. if (p)
  2423. {
  2424. ULARGE_INTEGER l;
  2425. p->GetSizeMax(&l);
  2426. HGLOBAL hGlob = GlobalAlloc(GHND, l.LowPart);
  2427. if (hGlob)
  2428. {
  2429. CComPtr<IStream> spStream;
  2430. CreateStreamOnHGlobal(hGlob, TRUE, &spStream);
  2431. if (spStream)
  2432. {
  2433. if (SUCCEEDED(p->Save(spStream, FALSE)))
  2434. {
  2435. LARGE_INTEGER l;
  2436. l.QuadPart = 0;
  2437. spStream->Seek(l, STREAM_SEEK_SET, NULL);
  2438. OleLoadPicture(spStream, l.LowPart, FALSE, IID_IPictureDisp, (void**)&pT->m_pPicture);
  2439. }
  2440. spStream.Release();
  2441. }
  2442. GlobalFree(hGlob);
  2443. }
  2444. }
  2445. }
  2446. pT->m_bRequiresSave = TRUE;
  2447. pT->FireOnChanged(DISPID_PICTURE);
  2448. pT->FireViewChange();
  2449. return S_OK;
  2450. }
  2451. HRESULT STDMETHODCALLTYPE putref_Picture(IPictureDisp* pPicture)
  2452. {
  2453. T* pT = (T*) this;
  2454. if (pT->FireOnRequestEdit(DISPID_PICTURE) == S_FALSE)
  2455. return S_FALSE;
  2456. pT->m_pPicture = pPicture;
  2457. pT->m_bRequiresSave = TRUE;
  2458. pT->FireOnChanged(DISPID_PICTURE);
  2459. pT->FireViewChange();
  2460. return S_OK;
  2461. }
  2462. HRESULT STDMETHODCALLTYPE get_Picture(IPictureDisp** ppPicture)
  2463. {
  2464. T* pT = (T*) this;
  2465. *ppPicture = pT->m_pPicture;
  2466. if (*ppPicture != NULL)
  2467. (*ppPicture)->AddRef();
  2468. return S_OK;
  2469. }
  2470. // MouseIcon
  2471. HRESULT STDMETHODCALLTYPE put_MouseIcon(IPictureDisp* pPicture)
  2472. {
  2473. T* pT = (T*) this;
  2474. if (pT->FireOnRequestEdit(DISPID_MOUSEICON) == S_FALSE)
  2475. return S_FALSE;
  2476. pT->m_pMouseIcon = 0;
  2477. if (pPicture)
  2478. {
  2479. CComQIPtr<IPersistStream, &IID_IPersistStream> p(pPicture);
  2480. if (p)
  2481. {
  2482. ULARGE_INTEGER l;
  2483. p->GetSizeMax(&l);
  2484. HGLOBAL hGlob = GlobalAlloc(GHND, l.LowPart);
  2485. if (hGlob)
  2486. {
  2487. CComPtr<IStream> spStream;
  2488. CreateStreamOnHGlobal(hGlob, TRUE, &spStream);
  2489. if (spStream)
  2490. {
  2491. if (SUCCEEDED(p->Save(spStream, FALSE)))
  2492. {
  2493. LARGE_INTEGER l;
  2494. l.QuadPart = 0;
  2495. spStream->Seek(l, STREAM_SEEK_SET, NULL);
  2496. OleLoadPicture(spStream, l.LowPart, FALSE, IID_IPictureDisp, (void**)&pT->m_pMouseIcon);
  2497. }
  2498. spStream.Release();
  2499. }
  2500. GlobalFree(hGlob);
  2501. }
  2502. }
  2503. }
  2504. pT->m_bRequiresSave = TRUE;
  2505. pT->FireOnChanged(DISPID_MOUSEICON);
  2506. pT->FireViewChange();
  2507. return S_OK;
  2508. }
  2509. HRESULT STDMETHODCALLTYPE putref_MouseIcon(IPictureDisp* pPicture)
  2510. {
  2511. T* pT = (T*) this;
  2512. if (pT->FireOnRequestEdit(DISPID_MOUSEICON) == S_FALSE)
  2513. return S_FALSE;
  2514. pT->m_pMouseIcon = pPicture;
  2515. pT->m_bRequiresSave = TRUE;
  2516. pT->FireOnChanged(DISPID_MOUSEICON);
  2517. pT->FireViewChange();
  2518. return S_OK;
  2519. }
  2520. HRESULT STDMETHODCALLTYPE get_MouseIcon(IPictureDisp** ppPicture)
  2521. {
  2522. T* pT = (T*) this;
  2523. *ppPicture = pT->m_pMouseIcon;
  2524. if (*ppPicture != NULL)
  2525. (*ppPicture)->AddRef();
  2526. return S_OK;
  2527. }
  2528. IMPLEMENT_STOCKPROP(OLE_COLOR, BackColor, clrBackColor, DISPID_BACKCOLOR)
  2529. IMPLEMENT_STOCKPROP(OLE_COLOR, BorderColor, clrBorderColor, DISPID_BORDERCOLOR)
  2530. IMPLEMENT_STOCKPROP(OLE_COLOR, FillColor, clrFillColor, DISPID_FILLCOLOR)
  2531. IMPLEMENT_STOCKPROP(OLE_COLOR, ForeColor, clrForeColor, DISPID_FORECOLOR)
  2532. IMPLEMENT_BOOL_STOCKPROP(AutoSize, bAutoSize, DISPID_AUTOSIZE)
  2533. IMPLEMENT_BOOL_STOCKPROP(Valid, bValid, DISPID_VALID)
  2534. IMPLEMENT_BOOL_STOCKPROP(Enabled, bEnabled, DISPID_ENABLED)
  2535. IMPLEMENT_BOOL_STOCKPROP(TabStop, bTabStop, DISPID_TABSTOP)
  2536. IMPLEMENT_BOOL_STOCKPROP(BorderVisible, bBorderVisible, DISPID_BORDERVISIBLE)
  2537. IMPLEMENT_BSTR_STOCKPROP(Text, bstrText, DISPID_TEXT)
  2538. IMPLEMENT_BSTR_STOCKPROP(Caption, bstrCaption, DISPID_CAPTION)
  2539. HRESULT STDMETHODCALLTYPE put_Window(LONG /*hWnd*/)
  2540. {
  2541. return E_FAIL;
  2542. }
  2543. HRESULT STDMETHODCALLTYPE get_Window(LONG* phWnd)
  2544. {
  2545. T* pT = (T*) this;
  2546. *phWnd = (LONG)(LONG_PTR)pT->m_hWnd;
  2547. return S_OK;
  2548. }
  2549. IMPLEMENT_STOCKPROP(long, BackStyle, nBackStyle, DISPID_BACKSTYLE)
  2550. IMPLEMENT_STOCKPROP(long, BorderStyle, nBorderStyle, DISPID_BORDERSTYLE)
  2551. IMPLEMENT_STOCKPROP(long, BorderWidth, nBorderWidth, DISPID_BORDERWIDTH)
  2552. IMPLEMENT_STOCKPROP(long, DrawMode, nDrawMode, DISPID_DRAWMODE)
  2553. IMPLEMENT_STOCKPROP(long, DrawStyle, nDrawStyle, DISPID_DRAWSTYLE)
  2554. IMPLEMENT_STOCKPROP(long, DrawWidth, nDrawWidth, DISPID_DRAWWIDTH)
  2555. IMPLEMENT_STOCKPROP(long, FillStyle, nFillStyle, DISPID_FILLSTYLE)
  2556. IMPLEMENT_STOCKPROP(long, Appearance, nAppearance, DISPID_APPEARANCE)
  2557. IMPLEMENT_STOCKPROP(long, MousePointer, nMousePointer, DISPID_MOUSEPOINTER)
  2558. IMPLEMENT_STOCKPROP(long, ReadyState, nReadyState, DISPID_READYSTATE)
  2559. };
  2560. #ifndef ATL_NO_NAMESPACE
  2561. }; //namespace ATL
  2562. #endif
  2563. #endif // __ATLCTL_H__