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.

1843 lines
44 KiB

  1. /*
  2. * d o c . c p p
  3. *
  4. * Purpose:
  5. *
  6. * History
  7. *
  8. * Copyright (C) Microsoft Corp. 1995, 1996.
  9. */
  10. #include <pch.hxx>
  11. #include <resource.h>
  12. #include <strconst.h>
  13. #ifdef PLUSPACK
  14. #include "htmlsp.h"
  15. #endif //PLUSPACK
  16. #include "demand.h"
  17. #include "dllmain.h"
  18. #include "msoert.h"
  19. #include "doc.h"
  20. #include "htiframe.h" //ITargetFrame2
  21. #include "htiface.h" //ITargetFramePriv
  22. #include "body.h"
  23. #include "util.h"
  24. #include "oleutil.h"
  25. #include "triutil.h"
  26. //+---------------------------------------------------------------
  27. //
  28. // Member: Constructor
  29. //
  30. // Synopsis:
  31. //
  32. //---------------------------------------------------------------
  33. CDoc::CDoc(IUnknown *pUnkOuter) : CPrivateUnknown(pUnkOuter)
  34. {
  35. m_ulState = OS_PASSIVE;
  36. m_hwndParent = NULL;
  37. m_pClientSite = NULL;
  38. m_pIPSite = NULL;
  39. m_lpszAppName = NULL;
  40. m_pInPlaceFrame=NULL;
  41. m_pInPlaceUIWindow=NULL;
  42. m_pBodyObj=NULL;
  43. m_pTypeInfo=NULL;
  44. DllAddRef();
  45. }
  46. //+---------------------------------------------------------------
  47. //
  48. // Member: Destructor
  49. //
  50. // Synopsis:
  51. //
  52. //---------------------------------------------------------------
  53. CDoc::~CDoc()
  54. {
  55. DllRelease();
  56. SafeMemFree(m_lpszAppName);
  57. SafeRelease(m_pClientSite);
  58. }
  59. //+---------------------------------------------------------------
  60. //
  61. // Member: PrivateQueryInterface
  62. //
  63. // Synopsis:
  64. //
  65. //---------------------------------------------------------------
  66. HRESULT CDoc::PrivateQueryInterface(REFIID riid, LPVOID *lplpObj)
  67. {
  68. TraceCall("CDoc::PrivateQueryInterface");
  69. if(!lplpObj)
  70. return E_INVALIDARG;
  71. *lplpObj = NULL;
  72. if (IsEqualIID(riid, IID_IOleObject))
  73. *lplpObj = (LPVOID)(IOleObject *)this;
  74. else if (IsEqualIID(riid, IID_IOleDocument))
  75. *lplpObj = (LPVOID)(IOleDocument *)this;
  76. else if (IsEqualIID(riid, IID_IOleDocumentView))
  77. *lplpObj = (LPVOID)(IOleDocumentView *)this;
  78. else if (IsEqualIID(riid, IID_IOleCommandTarget))
  79. *lplpObj = (LPVOID)(IOleCommandTarget *)this;
  80. else if (IsEqualIID(riid, IID_IServiceProvider))
  81. *lplpObj = (LPVOID)(IServiceProvider *)this;
  82. else if (IsEqualIID(riid, IID_IOleInPlaceObject))
  83. *lplpObj = (LPVOID)(IOleInPlaceObject *)this;
  84. else if (IsEqualIID(riid, IID_IOleInPlaceActiveObject))
  85. *lplpObj = (LPVOID)(IOleInPlaceActiveObject *)this;
  86. else if (IsEqualIID(riid, IID_IPersistStreamInit))
  87. *lplpObj = (LPVOID)(IPersistStreamInit *)this;
  88. else if (IsEqualIID(riid, IID_IPersistMoniker))
  89. *lplpObj = (LPVOID)(IPersistMoniker *)this;
  90. else if (IsEqualIID(riid, IID_IDispatch))
  91. *lplpObj = (LPVOID)(IDispatch *)this;
  92. else if (IsEqualIID(riid, IID_IMimeEdit))
  93. *lplpObj = (LPVOID)(IMimeEdit *)this;
  94. else if (IsEqualIID(riid, IID_IQuickActivate))
  95. *lplpObj = (LPVOID)(IQuickActivate *)this;
  96. #ifdef OFFICE_BINDER
  97. else if (IsEqualIID(riid, IID_IPersistStorage))
  98. *lplpObj = (LPVOID)(IPersistStorage *)this;
  99. #endif
  100. else if (IsEqualIID(riid, IID_IPersistMime))
  101. *lplpObj = (LPVOID)(IPersistMime *)this;
  102. else if (IsEqualIID(riid, IID_IPersistFile))
  103. *lplpObj = (LPVOID)(IPersistFile *)this;
  104. else
  105. {
  106. //DebugPrintInterface(riid, "CDoc::{not supported}=");
  107. return E_NOINTERFACE;
  108. }
  109. AddRef();
  110. return NOERROR;
  111. }
  112. //+---------------------------------------------------------------
  113. //
  114. // Member: GetClassID
  115. //
  116. // Synopsis:
  117. //
  118. //---------------------------------------------------------------
  119. HRESULT CDoc::GetClassID(CLSID *pClassID)
  120. {
  121. TraceCall("CDoc::GetClassID");
  122. *pClassID = CLSID_MimeEdit;
  123. return NOERROR;
  124. }
  125. // *** IPersistMime ***
  126. //+---------------------------------------------------------------
  127. //
  128. // Member: Load
  129. //
  130. // Synopsis:
  131. //
  132. //---------------------------------------------------------------
  133. HRESULT CDoc::Load(IMimeMessage *pMsg)
  134. {
  135. TraceCall("CDoc::Load");
  136. return m_pBodyObj ? m_pBodyObj->Load(pMsg) : TraceResult(E_UNEXPECTED);
  137. }
  138. //+---------------------------------------------------------------
  139. //
  140. // Member: Save
  141. //
  142. // Synopsis:
  143. //
  144. //---------------------------------------------------------------
  145. HRESULT CDoc::Save(IMimeMessage *pMsg, DWORD dwFlags)
  146. {
  147. IPersistMime *pPM;
  148. HRESULT hr;
  149. TraceCall("CDoc::Save");
  150. if (!m_pBodyObj)
  151. return TraceResult(E_UNEXPECTED);
  152. hr = m_pBodyObj->QueryInterface(IID_IPersistMime, (LPVOID *)&pPM);
  153. if (!FAILED(hr))
  154. {
  155. hr = pPM->Save(pMsg, dwFlags);
  156. pPM->Release();
  157. }
  158. return hr;
  159. }
  160. // *** IPersistStreamInit ***
  161. //+---------------------------------------------------------------
  162. //
  163. // Member: IsDirty
  164. //
  165. // Synopsis:
  166. //
  167. //---------------------------------------------------------------
  168. HRESULT CDoc::IsDirty()
  169. {
  170. TraceCall("CDoc::IsDirty");
  171. return m_pBodyObj?m_pBodyObj->IsDirty():TraceResult(E_UNEXPECTED);
  172. }
  173. //+---------------------------------------------------------------
  174. //
  175. // Member: Load
  176. //
  177. // Synopsis:
  178. //
  179. //---------------------------------------------------------------
  180. HRESULT CDoc::Load(LPSTREAM pstm)
  181. {
  182. TraceCall("CDoc::Load");
  183. return m_pBodyObj?m_pBodyObj->LoadStream(pstm):TraceResult(E_UNEXPECTED);
  184. }
  185. //+---------------------------------------------------------------
  186. //
  187. // Member: Save
  188. //
  189. // Synopsis:
  190. //
  191. //---------------------------------------------------------------
  192. HRESULT CDoc::Save(LPSTREAM pstm, BOOL fClearDirty)
  193. {
  194. TraceCall("CDoc::Save");
  195. return S_OK;
  196. }
  197. //+---------------------------------------------------------------
  198. //
  199. // Member: GetSizeMax
  200. //
  201. // Synopsis:
  202. //
  203. //---------------------------------------------------------------
  204. HRESULT CDoc::GetSizeMax(ULARGE_INTEGER * pCbSize)
  205. {
  206. TraceCall("CDoc::GetSizeMax");
  207. return E_NOTIMPL;
  208. }
  209. //+---------------------------------------------------------------
  210. //
  211. // Member: InitNew
  212. //
  213. // Synopsis:
  214. //
  215. //---------------------------------------------------------------
  216. HRESULT CDoc::InitNew()
  217. {
  218. TraceCall("CDoc::InitNew");
  219. if (m_pBodyObj)
  220. return m_pBodyObj->UnloadAll();
  221. return S_OK;
  222. }
  223. // *** IOleDocument ***
  224. //+---------------------------------------------------------------
  225. //
  226. // Member: CreateView
  227. //
  228. // Synopsis:
  229. //
  230. //---------------------------------------------------------------
  231. HRESULT CDoc::CreateView(IOleInPlaceSite *pIPSite, IStream *pstm, DWORD dwReserved, IOleDocumentView **ppView)
  232. {
  233. HRESULT hr;
  234. TraceCall("CDoc::CreateView");
  235. if (pIPSite == NULL || ppView == NULL)
  236. return TraceResult(E_INVALIDARG);
  237. if (m_pClientSite == NULL)
  238. return TraceResult(E_FAIL);
  239. hr = SetInPlaceSite(pIPSite);
  240. if (FAILED(hr))
  241. {
  242. TraceResult(hr);
  243. goto error;
  244. }
  245. hr = PrivateQueryInterface(IID_IOleDocumentView, (void **)ppView);
  246. if (FAILED(hr))
  247. {
  248. TraceResult(hr);
  249. goto error;
  250. }
  251. error:
  252. return hr;
  253. }
  254. //+---------------------------------------------------------------
  255. //
  256. // Member: GetDocMiscStatus
  257. //
  258. // Synopsis:
  259. //
  260. //---------------------------------------------------------------
  261. HRESULT CDoc::GetDocMiscStatus(DWORD *pdwStatus)
  262. {
  263. TraceCall("CDoc::GetDocMiscStatus");
  264. *pdwStatus = DOCMISC_CANTOPENEDIT | DOCMISC_NOFILESUPPORT;
  265. return S_OK;
  266. }
  267. //+---------------------------------------------------------------
  268. //
  269. // Member: EnumViews
  270. //
  271. // Synopsis:
  272. //
  273. //---------------------------------------------------------------
  274. HRESULT CDoc::EnumViews(IEnumOleDocumentViews **ppEnum, IOleDocumentView **ppView)
  275. {
  276. TraceCall("CDoc::EnumViews");
  277. HRESULT hr = S_OK;
  278. if (ppEnum == NULL || ppView == NULL)
  279. return TraceResult(E_INVALIDARG);
  280. *ppEnum = NULL;
  281. return PrivateQueryInterface(IID_IOleDocumentView, (void **)ppView);
  282. }
  283. // *** IOleDocumentView ***
  284. //+---------------------------------------------------------------
  285. //
  286. // Member: SetInPlaceSite
  287. //
  288. // Synopsis:
  289. //
  290. //---------------------------------------------------------------
  291. HRESULT CDoc::SetInPlaceSite(IOleInPlaceSite *pIPSite)
  292. {
  293. TraceCall("CDoc::SetInPlaceSite");
  294. // destroys the docobj and detaches from the current client site
  295. // replaces the client site pointer read for a ::Show
  296. DeactivateInPlace();
  297. ReplaceInterface(m_pIPSite, pIPSite);
  298. return S_OK;
  299. }
  300. //+---------------------------------------------------------------
  301. //
  302. // Member: GetInPlaceSite
  303. //
  304. // Synopsis:
  305. //
  306. //---------------------------------------------------------------
  307. HRESULT CDoc::GetInPlaceSite(IOleInPlaceSite **ppIPSite)
  308. {
  309. TraceCall("CDoc::GetInPlaceSite");
  310. if (!ppIPSite)
  311. return E_INVALIDARG;
  312. if (*ppIPSite=m_pIPSite)
  313. {
  314. m_pIPSite->AddRef();
  315. return S_OK;
  316. }
  317. else
  318. return E_FAIL;
  319. }
  320. //+---------------------------------------------------------------
  321. //
  322. // Member: GetDocument
  323. //
  324. // Synopsis:
  325. //
  326. //---------------------------------------------------------------
  327. HRESULT CDoc::GetDocument(IUnknown **ppunk)
  328. {
  329. TraceCall("CDoc::GetDocument");
  330. if (ppunk==NULL)
  331. return E_INVALIDARG;
  332. *ppunk = (IOleDocument *)this;
  333. (*ppunk)->AddRef();
  334. return S_OK;
  335. }
  336. //+---------------------------------------------------------------
  337. //
  338. // Member: SetRect
  339. //
  340. // Synopsis:
  341. //
  342. //---------------------------------------------------------------
  343. HRESULT CDoc::SetRect(LPRECT prcView)
  344. {
  345. if (m_pBodyObj)
  346. m_pBodyObj->SetRect(prcView);
  347. return S_OK;
  348. }
  349. //+---------------------------------------------------------------
  350. //
  351. // Member: GetRect
  352. //
  353. // Synopsis:
  354. //
  355. //---------------------------------------------------------------
  356. HRESULT CDoc::GetRect(LPRECT prcView)
  357. {
  358. TraceCall("CDoc::GetRect");
  359. if (m_pBodyObj)
  360. m_pBodyObj->GetRect(prcView);
  361. return S_OK;
  362. }
  363. //+---------------------------------------------------------------
  364. //
  365. // Member: SetRectComplex
  366. //
  367. // Synopsis:
  368. //
  369. //---------------------------------------------------------------
  370. HRESULT CDoc::SetRectComplex(LPRECT prcView, LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
  371. {
  372. TraceCall("CDoc::SetRectComplex");
  373. return E_NOTIMPL;
  374. }
  375. //+---------------------------------------------------------------
  376. //
  377. // Member: Show
  378. //
  379. // Synopsis:
  380. //
  381. //---------------------------------------------------------------
  382. HRESULT CDoc::Show(BOOL fShow)
  383. {
  384. HRESULT hr;
  385. TraceCall("CDoc::Show");
  386. hr = ActivateInPlace();
  387. if (FAILED(hr))
  388. {
  389. TraceResult(hr);
  390. goto error;
  391. }
  392. error:
  393. return hr;
  394. }
  395. //+---------------------------------------------------------------
  396. //
  397. // Member: UIActivate
  398. //
  399. // Synopsis:
  400. //
  401. //---------------------------------------------------------------
  402. HRESULT CDoc::UIActivate(BOOL fUIActivate)
  403. {
  404. HRESULT hr=S_OK;
  405. TraceCall("CDoc::UIActivate");
  406. #ifdef OFFICE_BINDER
  407. if (fUIActivate)
  408. {
  409. hr = ActivateInPlace();
  410. }
  411. #endif
  412. if (m_pBodyObj)
  413. return m_pBodyObj->UIActivate(fUIActivate);
  414. return hr;
  415. }
  416. //+---------------------------------------------------------------
  417. //
  418. // Member: Open
  419. //
  420. // Synopsis:
  421. //
  422. //---------------------------------------------------------------
  423. HRESULT CDoc::Open()
  424. {
  425. TraceCall("CDoc::Open");
  426. // no single instance View|Frame supported
  427. return E_NOTIMPL;
  428. }
  429. //+---------------------------------------------------------------
  430. //
  431. // Member: CloseView
  432. //
  433. // Synopsis:
  434. //
  435. //---------------------------------------------------------------
  436. HRESULT CDoc::CloseView(DWORD dwReserved)
  437. {
  438. TraceCall("CDoc::CloseView");
  439. // to close the view, set the Site to NULL
  440. SetInPlaceSite(NULL);
  441. return S_OK;
  442. }
  443. //+---------------------------------------------------------------
  444. //
  445. // Member: SaveViewState
  446. //
  447. // Synopsis:
  448. //
  449. //---------------------------------------------------------------
  450. HRESULT CDoc::SaveViewState(LPSTREAM pstm)
  451. {
  452. TraceCall("CDoc::SaveViewState");
  453. return S_OK; // we don't keep view state
  454. }
  455. //+---------------------------------------------------------------
  456. //
  457. // Member: ApplyViewState
  458. //
  459. // Synopsis:
  460. //
  461. //---------------------------------------------------------------
  462. HRESULT CDoc::ApplyViewState(LPSTREAM pstm)
  463. {
  464. TraceCall("CDoc::ApplyViewState");
  465. return S_OK;
  466. }
  467. //+---------------------------------------------------------------
  468. //
  469. // Member: Clone
  470. //
  471. // Synopsis:
  472. //
  473. //---------------------------------------------------------------
  474. HRESULT CDoc::Clone(IOleInPlaceSite *pIPSiteNew, IOleDocumentView **ppViewNew)
  475. {
  476. TraceCall("CDoc::Clone");
  477. return E_NOTIMPL;
  478. }
  479. // *** IOleObject ***
  480. //+---------------------------------------------------------------
  481. //
  482. // Member: SetClientSite
  483. //
  484. // Synopsis:
  485. //
  486. //---------------------------------------------------------------
  487. HRESULT CDoc::SetClientSite(IOleClientSite *pClientSite)
  488. {
  489. TraceCall("CDoc::SetClientSite");
  490. if (m_pClientSite && pClientSite)
  491. {
  492. // don't allow them to change the client site
  493. TraceInfo("Host attempt to change client-site fefused");
  494. return E_INVALIDARG;
  495. }
  496. ReplaceInterface(m_pClientSite, pClientSite);
  497. return S_OK;
  498. }
  499. //+---------------------------------------------------------------
  500. //
  501. // Member: GetClientSite
  502. //
  503. // Synopsis:
  504. //
  505. //---------------------------------------------------------------
  506. HRESULT CDoc::GetClientSite(IOleClientSite **ppClientSite)
  507. {
  508. TraceCall("CDoc::GetClientSite");
  509. if (!ppClientSite)
  510. return E_INVALIDARG;
  511. if (*ppClientSite=m_pClientSite)
  512. {
  513. m_pClientSite->AddRef();
  514. return S_OK;
  515. }
  516. else
  517. return E_FAIL;
  518. }
  519. //+---------------------------------------------------------------
  520. //
  521. // Member: SetHostNames
  522. //
  523. // Synopsis:
  524. //
  525. //---------------------------------------------------------------
  526. HRESULT CDoc::SetHostNames(LPCOLESTR szContainerAppW, LPCOLESTR szContainerObjW)
  527. {
  528. TraceCall("CDoc::SetHostNames");
  529. SafeMemFree(m_lpszAppName);
  530. if (szContainerAppW)
  531. m_lpszAppName = PszToANSI(CP_ACP, szContainerAppW);
  532. return S_OK;
  533. }
  534. //+---------------------------------------------------------------
  535. //
  536. // Member: Close
  537. //
  538. // Synopsis:
  539. //
  540. //---------------------------------------------------------------
  541. HRESULT CDoc::Close(DWORD dwSaveOption)
  542. {
  543. HRESULT hr = S_OK;
  544. BOOL fSave;
  545. int id;
  546. TCHAR szTitle[MAX_PATH];
  547. TraceCall("CDoc::Close");
  548. // if our object is dirty then we should save it, depending on the
  549. // save options
  550. if (m_pClientSite &&
  551. m_pBodyObj &&
  552. m_pBodyObj->IsDirty()==S_OK)
  553. {
  554. switch(dwSaveOption)
  555. {
  556. case OLECLOSE_SAVEIFDIRTY:
  557. fSave = TRUE;
  558. break;
  559. case OLECLOSE_NOSAVE:
  560. fSave = FALSE;
  561. break;
  562. case OLECLOSE_PROMPTSAVE:
  563. {
  564. if(m_ulState != OS_UIACTIVE)
  565. {
  566. // if we're not UI active, then don't prompt
  567. fSave=TRUE;
  568. break;
  569. }
  570. GetHostName(szTitle, sizeof(szTitle)/sizeof(TCHAR));
  571. id = AthMessageBox(m_hwndParent, szTitle, MAKEINTRESOURCE(idsSaveModifiedObject), NULL, MB_YESNOCANCEL);
  572. if (id == 0)
  573. return TraceResult(E_OUTOFMEMORY);
  574. else if (id == IDCANCEL)
  575. return TraceResult(OLE_E_PROMPTSAVECANCELLED);
  576. fSave=(id == IDYES);
  577. }
  578. break;
  579. default:
  580. return TraceResult(E_INVALIDARG);
  581. }
  582. if (fSave)
  583. hr = m_pClientSite->SaveObject();
  584. }
  585. if (hr==S_OK)
  586. hr = DeactivateInPlace();
  587. return hr;
  588. }
  589. //+---------------------------------------------------------------
  590. //
  591. // Member: SetMoniker
  592. //
  593. // Synopsis:
  594. //
  595. //---------------------------------------------------------------
  596. HRESULT CDoc::SetMoniker(DWORD dwWhichMoniker, IMoniker *pmk)
  597. {
  598. TraceCall("CDoc::SetMoniker");
  599. return E_NOTIMPL;
  600. }
  601. //+---------------------------------------------------------------
  602. //
  603. // Member: GetMoniker
  604. //
  605. // Synopsis:
  606. //
  607. //---------------------------------------------------------------
  608. HRESULT CDoc::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
  609. {
  610. TraceCall("CDoc::GetMoniker");
  611. return E_NOTIMPL;
  612. }
  613. //+---------------------------------------------------------------
  614. //
  615. // Member: InitFromData
  616. //
  617. // Synopsis:
  618. //
  619. //---------------------------------------------------------------
  620. HRESULT CDoc::InitFromData(IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved)
  621. {
  622. TraceCall("CDoc::InitFromData");
  623. return E_NOTIMPL;
  624. }
  625. //+---------------------------------------------------------------
  626. //
  627. // Member: GetClipboardData
  628. //
  629. // Synopsis:
  630. //
  631. //---------------------------------------------------------------
  632. HRESULT CDoc::GetClipboardData(DWORD dwReserved, IDataObject **ppDataObject)
  633. {
  634. TraceCall("CDoc::GetClipboardData");
  635. if (ppDataObject == NULL)
  636. return TraceResult(E_INVALIDARG);
  637. *ppDataObject = NULL;
  638. return TraceResult(E_NOTIMPL);
  639. }
  640. //+---------------------------------------------------------------
  641. //
  642. // Member: DoVerb
  643. //
  644. // Synopsis:
  645. //
  646. //---------------------------------------------------------------
  647. HRESULT CDoc::DoVerb(LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
  648. {
  649. TraceCall("CDoc::DoVerb");
  650. switch (iVerb)
  651. {
  652. case OLEIVERB_SHOW:
  653. case OLEIVERB_PRIMARY:
  654. return DoShow(pActiveSite, hwndParent, lprcPosRect);;
  655. case OLEIVERB_INPLACEACTIVATE:
  656. return Show(TRUE);
  657. }
  658. return OLEOBJ_S_INVALIDVERB;
  659. }
  660. //+---------------------------------------------------------------
  661. //
  662. // Member: EnumVerbs
  663. //
  664. // Synopsis:
  665. //
  666. //---------------------------------------------------------------
  667. HRESULT CDoc::EnumVerbs(IEnumOLEVERB **ppEnumOleVerb)
  668. {
  669. TraceCall("CDoc::EnumVerbs");
  670. return E_NOTIMPL;
  671. }
  672. //+---------------------------------------------------------------
  673. //
  674. // Member: Update
  675. //
  676. // Synopsis:
  677. //
  678. //---------------------------------------------------------------
  679. HRESULT CDoc::Update()
  680. {
  681. TraceCall("CDoc::Update");
  682. return S_OK;
  683. }
  684. //+---------------------------------------------------------------
  685. //
  686. // Member: IsUpToDate
  687. //
  688. // Synopsis:
  689. //
  690. //---------------------------------------------------------------
  691. HRESULT CDoc::IsUpToDate()
  692. {
  693. TraceCall("CDoc::IsUpToDate");
  694. return S_OK;
  695. }
  696. //+---------------------------------------------------------------
  697. //
  698. // Member: GetUserClassID
  699. //
  700. // Synopsis:
  701. //
  702. //---------------------------------------------------------------
  703. HRESULT CDoc::GetUserClassID(CLSID *pCLSID)
  704. {
  705. TraceCall("CDoc::GetUserClassID");
  706. if (pCLSID==NULL)
  707. return TraceResult(E_INVALIDARG);
  708. *pCLSID = CLSID_MimeEdit;
  709. return S_OK;
  710. }
  711. //+---------------------------------------------------------------
  712. //
  713. // Member: GetUserType
  714. //
  715. // Synopsis:
  716. //
  717. //---------------------------------------------------------------
  718. HRESULT CDoc::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
  719. {
  720. TCHAR szRes[CCHMAX_STRINGRES];
  721. int ids;
  722. TraceCall("CDoc::GetUserType");
  723. if (pszUserType==NULL)
  724. return TraceResult(E_INVALIDARG);
  725. *pszUserType = NULL;
  726. switch (dwFormOfType)
  727. {
  728. case USERCLASSTYPE_APPNAME:
  729. ids = idsUserTypeApp;
  730. break;
  731. case USERCLASSTYPE_SHORT:
  732. ids = idsUserTypeShort;
  733. break;
  734. case USERCLASSTYPE_FULL:
  735. ids = idsUserTypeFull;
  736. break;
  737. default:
  738. return TraceResult(E_INVALIDARG);
  739. }
  740. if (!LoadString(g_hLocRes, ids, szRes, sizeof(szRes)/sizeof(TCHAR)))
  741. return TraceResult(E_OUTOFMEMORY);
  742. *pszUserType = PszToUnicode(CP_ACP, szRes);
  743. return *pszUserType ? S_OK : TraceResult(E_OUTOFMEMORY);
  744. }
  745. //+---------------------------------------------------------------
  746. //
  747. // Member: SetExtent
  748. //
  749. // Synopsis:
  750. //
  751. //---------------------------------------------------------------
  752. HRESULT CDoc::SetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  753. {
  754. TraceCall("CDoc::SetExtent");
  755. return E_NOTIMPL;
  756. }
  757. //+---------------------------------------------------------------
  758. //
  759. // Member: GetExtent
  760. //
  761. // Synopsis:
  762. //
  763. //---------------------------------------------------------------
  764. HRESULT CDoc::GetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  765. {
  766. TraceCall("CDoc::GetExtent");
  767. return E_NOTIMPL;
  768. }
  769. //+---------------------------------------------------------------
  770. //
  771. // Member: Advise
  772. //
  773. // Synopsis:
  774. //
  775. //---------------------------------------------------------------
  776. HRESULT CDoc::Advise(IAdviseSink *pAdvSink, DWORD *pdwConnection)
  777. {
  778. TraceCall("CDoc::Advise");
  779. return S_OK;
  780. }
  781. //+---------------------------------------------------------------
  782. //
  783. // Member: Unadvise
  784. //
  785. // Synopsis:
  786. //
  787. //---------------------------------------------------------------
  788. HRESULT CDoc::Unadvise(DWORD dwConnection)
  789. {
  790. TraceCall("CDoc::Unadvise");
  791. return E_NOTIMPL;
  792. }
  793. //+---------------------------------------------------------------
  794. //
  795. // Member: EnumAdvise
  796. //
  797. // Synopsis:
  798. //
  799. //---------------------------------------------------------------
  800. HRESULT CDoc::EnumAdvise(IEnumSTATDATA **ppenumAdvise)
  801. {
  802. TraceCall("CDoc::EnumAdvise");
  803. return E_NOTIMPL;
  804. }
  805. //+---------------------------------------------------------------
  806. //
  807. // Member: GetMiscStatus
  808. //
  809. // Synopsis:
  810. //
  811. //---------------------------------------------------------------
  812. HRESULT CDoc::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
  813. {
  814. TraceCall("CDoc::GetMiscStatus");
  815. if (pdwStatus==NULL)
  816. return E_INVALIDARG;
  817. *pdwStatus = OLEMISC_INSIDEOUT; // BUGBUG: not sure what to set here
  818. return S_OK;
  819. }
  820. //+---------------------------------------------------------------
  821. //
  822. // Member: SetColorScheme
  823. //
  824. // Synopsis:
  825. //
  826. //---------------------------------------------------------------
  827. HRESULT CDoc::SetColorScheme(LOGPALETTE *pLogpal)
  828. {
  829. TraceCall("CDoc::SetColorScheme");
  830. return E_NOTIMPL;
  831. }
  832. // *** IOleInPlaceObject ***
  833. //+---------------------------------------------------------------
  834. //
  835. // Member: InPlaceDeactivate
  836. //
  837. // Synopsis:
  838. //
  839. //---------------------------------------------------------------
  840. HRESULT CDoc::InPlaceDeactivate()
  841. {
  842. TraceCall("CDoc::InPlaceDeactivate");
  843. return DeactivateInPlace();
  844. }
  845. //+---------------------------------------------------------------
  846. //
  847. // Member: UIDeactivate
  848. //
  849. // Synopsis:
  850. //
  851. //---------------------------------------------------------------
  852. HRESULT CDoc::UIDeactivate()
  853. {
  854. TraceCall("CDoc::UIDeactivate");
  855. if (m_pBodyObj)
  856. m_pBodyObj->UIActivate(FALSE);
  857. return S_OK;
  858. }
  859. //+---------------------------------------------------------------
  860. //
  861. // Member: SetObjectRects
  862. //
  863. // Synopsis:
  864. //
  865. //---------------------------------------------------------------
  866. HRESULT CDoc::SetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
  867. {
  868. TraceCall("CDoc::SetObjectRects");
  869. return SetRect((LPRECT)lprcPosRect);
  870. }
  871. //+---------------------------------------------------------------
  872. //
  873. // Member: ReactivateAndUndo
  874. //
  875. // Synopsis:
  876. //
  877. //---------------------------------------------------------------
  878. HRESULT CDoc::ReactivateAndUndo()
  879. {
  880. TraceCall("CDoc::ReactivateAndUndo");
  881. return S_OK;
  882. }
  883. //+---------------------------------------------------------------
  884. //
  885. // Member: GetWindow
  886. //
  887. // Synopsis:
  888. //
  889. //---------------------------------------------------------------
  890. HRESULT CDoc::GetWindow(HWND *phwnd)
  891. {
  892. TraceCall("CDoc::GetWindow");
  893. if (phwnd==NULL)
  894. return E_INVALIDARG;
  895. return m_pBodyObj?m_pBodyObj->GetWindow(phwnd):E_FAIL;
  896. }
  897. //+---------------------------------------------------------------
  898. //
  899. // Member: ContextSensitiveHelp
  900. //
  901. // Synopsis:
  902. //
  903. //---------------------------------------------------------------
  904. HRESULT CDoc::ContextSensitiveHelp(BOOL fEnterMode)
  905. {
  906. TraceCall("CDoc::ContextSensitiveHelp");
  907. return E_NOTIMPL;
  908. }
  909. //+---------------------------------------------------------------
  910. //
  911. // Member: TranslateAccelerator
  912. //
  913. // Synopsis:
  914. //
  915. //---------------------------------------------------------------
  916. HRESULT CDoc::TranslateAccelerator(LPMSG lpmsg)
  917. {
  918. return m_pBodyObj ? m_pBodyObj->PrivateTranslateAccelerator(lpmsg) : S_FALSE;
  919. }
  920. //+---------------------------------------------------------------
  921. //
  922. // Member: OnFrameWindowActivate
  923. //
  924. // Synopsis:
  925. //
  926. //---------------------------------------------------------------
  927. HRESULT CDoc::OnFrameWindowActivate(BOOL fActivate)
  928. {
  929. TraceCall("CDoc::OnFrameWindowActivate");
  930. if (m_pBodyObj)
  931. m_pBodyObj->OnFrameActivate(fActivate);
  932. return S_OK;
  933. }
  934. //+---------------------------------------------------------------
  935. //
  936. // Member: OnDocWindowActivate
  937. //
  938. // Synopsis:
  939. //
  940. //---------------------------------------------------------------
  941. HRESULT CDoc::OnDocWindowActivate(BOOL fActivate)
  942. {
  943. TraceCall("CDoc::OnDocWindowActivate");
  944. return S_OK;
  945. }
  946. //+---------------------------------------------------------------
  947. //
  948. // Member: ResizeBorder
  949. //
  950. // Synopsis:
  951. //
  952. //---------------------------------------------------------------
  953. HRESULT CDoc::ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
  954. {
  955. TraceCall("CDoc::ResizeBorder");
  956. return S_OK;
  957. }
  958. //+---------------------------------------------------------------
  959. //
  960. // Member: EnableModeless
  961. //
  962. // Synopsis:
  963. //
  964. //---------------------------------------------------------------
  965. HRESULT CDoc::EnableModeless(BOOL fEnable)
  966. {
  967. TraceCall("CDoc::EnableModeless");
  968. return S_OK;
  969. }
  970. //+---------------------------------------------------------------
  971. //
  972. // Member: QueryStatus
  973. //
  974. // Synopsis:
  975. //
  976. //---------------------------------------------------------------
  977. HRESULT CDoc::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
  978. {
  979. TraceCall("CDoc::QueryStatus");
  980. if (m_pBodyObj==NULL)
  981. return TraceResult(E_UNEXPECTED);
  982. return m_pBodyObj->PrivateQueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
  983. }
  984. //+---------------------------------------------------------------
  985. //
  986. // Member: Exec
  987. //
  988. // Synopsis:
  989. //
  990. //---------------------------------------------------------------
  991. HRESULT CDoc::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
  992. {
  993. HRESULT hr=E_FAIL;
  994. TraceCall("CDoc::Exec");
  995. if (m_pBodyObj==NULL)
  996. return TraceResult(E_UNEXPECTED);
  997. return m_pBodyObj->PrivateExec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
  998. }
  999. //+---------------------------------------------------------------
  1000. //
  1001. // Member: QueryService
  1002. //
  1003. // Synopsis:
  1004. //
  1005. //---------------------------------------------------------------
  1006. HRESULT CDoc::QueryService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
  1007. {
  1008. TraceCall("CDoc::QueryService");
  1009. if (m_pBodyObj==NULL)
  1010. return TraceResult(E_UNEXPECTED);
  1011. return m_pBodyObj->PrivateQueryService(guidService, riid, ppvObject);
  1012. }
  1013. //+---------------------------------------------------------------
  1014. //
  1015. // Member: CDoc::DoShow
  1016. //
  1017. // Synopsis: response to IOleObject::DoVerb for showing object
  1018. //
  1019. //---------------------------------------------------------------
  1020. HRESULT CDoc::DoShow(IOleClientSite *pActiveSite, HWND hwndParent, LPCRECT lprcPosRect)
  1021. {
  1022. HRESULT hr;
  1023. TraceCall("CDoc::DoShow");
  1024. if (m_ulState >= OS_INPLACE) // if we're already running return S_OK
  1025. return S_OK;
  1026. if (!IsWindow(hwndParent))
  1027. return OLEOBJ_S_INVALIDHWND;
  1028. if (pActiveSite == NULL)
  1029. return E_INVALIDARG;
  1030. ReplaceInterface(m_pClientSite, pActiveSite);
  1031. m_hwndParent = hwndParent;
  1032. return ActivateView();
  1033. }
  1034. //+---------------------------------------------------------------
  1035. //
  1036. // Member: CDoc::ActivateView
  1037. //
  1038. // Synopsis: Activate an IOleDocumentView
  1039. //
  1040. //---------------------------------------------------------------
  1041. HRESULT CDoc::ActivateView()
  1042. {
  1043. HRESULT hr;
  1044. IOleDocumentSite *pDocSite;
  1045. TraceCall("CDoc::ActivateView");
  1046. Assert(m_ulState < OS_INPLACE);
  1047. Assert(m_pClientSite);
  1048. if (!FAILED(hr = m_pClientSite->QueryInterface(IID_IOleDocumentSite, (void **)&pDocSite)))
  1049. {
  1050. hr = pDocSite->ActivateMe((IOleDocumentView *)this);
  1051. pDocSite->Release();
  1052. }
  1053. return hr;
  1054. }
  1055. HRESULT CDoc::Load(BOOL fFullyAvailable, IMoniker *pMoniker, IBindCtx *pBindCtx, DWORD grfMode)
  1056. {
  1057. return m_pBodyObj->Load(fFullyAvailable, pMoniker, pBindCtx, grfMode);
  1058. }
  1059. HRESULT CDoc::GetCurMoniker(IMoniker **ppMoniker)
  1060. {
  1061. return m_pBodyObj->GetCurMoniker(ppMoniker);
  1062. }
  1063. HRESULT CDoc::Save(IMoniker *pMoniker, IBindCtx *pBindCtx, BOOL fRemember)
  1064. {
  1065. return m_pBodyObj->Save(pMoniker, pBindCtx, fRemember);
  1066. }
  1067. HRESULT CDoc::SaveCompleted(IMoniker *pMoniker, IBindCtx *pBindCtx)
  1068. {
  1069. return m_pBodyObj->SaveCompleted(pMoniker, pBindCtx);
  1070. }
  1071. //+---------------------------------------------------------------
  1072. //
  1073. // Member: ActivateInPlace
  1074. //
  1075. // Synopsis: In place activates the object using the std. inplace
  1076. // activation protocol to create the inplace window.
  1077. //
  1078. //---------------------------------------------------------------
  1079. HRESULT CDoc::ActivateInPlace()
  1080. {
  1081. HRESULT hr;
  1082. HWND hwndSite;
  1083. RECT rcPos,
  1084. rcClip;
  1085. OLEINPLACEFRAMEINFO rFrameInfo;
  1086. TraceCall("CDoc::ActivateInPlace");
  1087. if (!m_pClientSite)
  1088. return TraceResult(E_UNEXPECTED);
  1089. if (m_ulState >= OS_INPLACE) // if we're already running return S_OK
  1090. return S_OK;
  1091. // If we don't already have an inplace site, query for one. Note. we don't yet support
  1092. // negotiation for a windowless site. We may want to add this code.
  1093. if (!m_pIPSite)
  1094. m_pClientSite->QueryInterface(IID_IOleInPlaceSite, (void **)&m_pIPSite);
  1095. if (!m_pIPSite)
  1096. return TraceResult(E_FAIL);
  1097. if (m_pIPSite->CanInPlaceActivate() != S_OK)
  1098. {
  1099. TraceInfo("Container refused In-Place activation!");
  1100. return TraceResult(E_FAIL);
  1101. }
  1102. Assert(m_pInPlaceFrame==NULL && m_pInPlaceUIWindow==NULL);
  1103. rFrameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  1104. ZeroMemory(&rcPos, sizeof(RECT));
  1105. ZeroMemory(&rcClip, sizeof(RECT));
  1106. hr = m_pIPSite->GetWindowContext(&m_pInPlaceFrame, &m_pInPlaceUIWindow, &rcPos, &rcClip, &rFrameInfo);
  1107. if (FAILED(hr))
  1108. {
  1109. TraceResult(hr);
  1110. goto error;
  1111. }
  1112. hr = m_pIPSite->GetWindow(&hwndSite);
  1113. if (FAILED(hr))
  1114. {
  1115. TraceResult(hr);
  1116. goto error;
  1117. }
  1118. hr = AttachWin(hwndSite, &rcPos);
  1119. if (FAILED(hr))
  1120. {
  1121. TraceResult(hr);
  1122. goto error;
  1123. }
  1124. // Notify our container that we are going in-place active.
  1125. m_ulState = OS_INPLACE;
  1126. m_pIPSite->OnInPlaceActivate();
  1127. if (m_pInPlaceFrame)
  1128. m_pInPlaceFrame->SetActiveObject((IOleInPlaceActiveObject *)this, NULL);
  1129. if (m_pInPlaceUIWindow)
  1130. m_pInPlaceUIWindow->SetActiveObject((IOleInPlaceActiveObject *)this, NULL);
  1131. error:
  1132. return hr;
  1133. }
  1134. //+---------------------------------------------------------------
  1135. //
  1136. // Member: AttachWin
  1137. //
  1138. // Synopsis:
  1139. //
  1140. //---------------------------------------------------------------
  1141. HRESULT CDoc::AttachWin(HWND hwndParent, LPRECT lprcPos)
  1142. {
  1143. HRESULT hr;
  1144. DWORD dwFlags=MEBF_OUTERCLIENTEDGE|MEBF_FORMATBARSEP;
  1145. VARIANTARG va;
  1146. IOleCommandTarget *pCmdTarget;
  1147. BODYHOSTINFO rHostInfo;
  1148. TraceCall("CDoc::AttachWin");
  1149. if (!IsWindow(hwndParent) || lprcPos == NULL)
  1150. return TraceResult(E_INVALIDARG);
  1151. // get border flags from host before we create the body, so we can fix the client edges
  1152. if (m_pClientSite &&
  1153. m_pClientSite->QueryInterface(IID_IOleCommandTarget, (LPVOID *)&pCmdTarget)==S_OK)
  1154. {
  1155. if (pCmdTarget->Exec(&CMDSETID_MimeEditHost, MEHOSTCMDID_BORDERFLAGS, 0, NULL, &va)==S_OK && va.vt==VT_I4)
  1156. dwFlags = va.lVal;
  1157. pCmdTarget->Release();
  1158. }
  1159. rHostInfo.pInPlaceSite = m_pIPSite;
  1160. rHostInfo.pInPlaceFrame = m_pInPlaceFrame;
  1161. rHostInfo.pDoc = (IOleInPlaceActiveObject *)this;
  1162. hr = CreateBodyObject(hwndParent, dwFlags, lprcPos, &rHostInfo, &m_pBodyObj);
  1163. if (FAILED(hr))
  1164. {
  1165. TraceResult(hr);
  1166. goto error;
  1167. }
  1168. error:
  1169. return hr;
  1170. }
  1171. //+---------------------------------------------------------------
  1172. //
  1173. // Member: DeactivateInPlace
  1174. //
  1175. // Synopsis:
  1176. //
  1177. //---------------------------------------------------------------
  1178. HRESULT CDoc::DeactivateInPlace()
  1179. {
  1180. TraceCall("CDoc::DeactivateInPlace");
  1181. if (m_pBodyObj)
  1182. {
  1183. m_pBodyObj->Close();
  1184. m_pBodyObj->Release();
  1185. m_pBodyObj=NULL;
  1186. }
  1187. // Notify our container that we're in-place deactivating
  1188. if (m_ulState == OS_INPLACE)
  1189. {
  1190. // The container may reenter us, so need to remember that
  1191. // we've done almost all the transition to OS_RUNNING
  1192. m_ulState = OS_RUNNING;
  1193. // Errors from this notification are ignored (in the function
  1194. // which calls this one); we don't allow our container to stop
  1195. // us from in-place deactivating
  1196. if (m_pIPSite)
  1197. m_pIPSite->OnInPlaceDeactivate();
  1198. }
  1199. SafeRelease(m_pIPSite);
  1200. SafeRelease(m_pInPlaceFrame);
  1201. SafeRelease(m_pInPlaceUIWindow);
  1202. return S_OK;
  1203. }
  1204. //+---------------------------------------------------------------
  1205. //
  1206. // Member: ActivateUI
  1207. //
  1208. // Synopsis:
  1209. //
  1210. //---------------------------------------------------------------
  1211. HRESULT CDoc::ActivateUI()
  1212. {
  1213. HRESULT hr;
  1214. TraceCall("CDoc::ActivateUI");
  1215. if (!m_pIPSite)
  1216. return TraceResult(E_UNEXPECTED);
  1217. m_ulState = OS_UIACTIVE;
  1218. if (FAILED(hr=m_pIPSite->OnUIActivate()))
  1219. {
  1220. // If the container fails the OnUIActivate call, then we
  1221. // give up and stay IPA
  1222. if (m_ulState == OS_UIACTIVE)
  1223. m_ulState = OS_INPLACE;
  1224. }
  1225. return hr;
  1226. }
  1227. //+---------------------------------------------------------------
  1228. //
  1229. // Member: DeactivateUI
  1230. //
  1231. // Synopsis:
  1232. //
  1233. //---------------------------------------------------------------
  1234. HRESULT CDoc::DeactivateUI()
  1235. {
  1236. TraceCall("CDoc::DectivateInPlace");
  1237. if (!m_pIPSite)
  1238. return TraceResult(E_UNEXPECTED);
  1239. m_ulState = OS_INPLACE;
  1240. m_pIPSite->OnUIDeactivate(FALSE);
  1241. return S_OK;
  1242. }
  1243. //+---------------------------------------------------------------
  1244. //
  1245. // Member: GetHostName
  1246. //
  1247. // Synopsis:
  1248. //
  1249. //---------------------------------------------------------------
  1250. HRESULT CDoc::GetHostName(LPSTR szTitle, ULONG cch)
  1251. {
  1252. TraceCall("CDoc::GetHostName");
  1253. *szTitle = 0;
  1254. if (m_lpszAppName)
  1255. {
  1256. StrCpyN(szTitle, m_lpszAppName, cch);
  1257. }
  1258. else
  1259. {
  1260. SideAssert(LoadString(g_hLocRes, idsAppName, szTitle, cch));
  1261. }
  1262. return S_OK;
  1263. }
  1264. #ifdef OFFICE_BINDER
  1265. HRESULT CDoc::InitNew(IStorage *pStg)
  1266. {
  1267. return S_OK;
  1268. }
  1269. HRESULT CDoc::Load(IStorage *pStg)
  1270. {
  1271. return S_OK;
  1272. }
  1273. HRESULT CDoc::Save(IStorage *pStgSave, BOOL fSameAsLoad)
  1274. {
  1275. return S_OK;
  1276. }
  1277. HRESULT CDoc::SaveCompleted(IStorage *pStgNew)
  1278. {
  1279. return S_OK;
  1280. }
  1281. HRESULT CDoc::HandsOffStorage()
  1282. {
  1283. return S_OK;
  1284. }
  1285. #endif
  1286. HRESULT CDoc::GetTypeInfoCount(UINT *pctinfo)
  1287. {
  1288. *pctinfo = 1;
  1289. return S_OK;
  1290. }
  1291. HRESULT CDoc::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  1292. {
  1293. HRESULT hr;
  1294. *pptinfo = NULL;
  1295. if (itinfo)
  1296. return DISP_E_BADINDEX;
  1297. hr = EnsureTypeLibrary();
  1298. if (FAILED(hr))
  1299. goto error;
  1300. m_pTypeInfo->AddRef();
  1301. *pptinfo = m_pTypeInfo;
  1302. error:
  1303. return hr;
  1304. }
  1305. HRESULT CDoc::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
  1306. {
  1307. HRESULT hr;
  1308. hr = EnsureTypeLibrary();
  1309. if (FAILED(hr))
  1310. goto error;
  1311. hr = DispGetIDsOfNames(m_pTypeInfo, rgszNames, cNames, rgdispid);
  1312. error:
  1313. return hr;
  1314. }
  1315. HRESULT CDoc::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr)
  1316. {
  1317. HRESULT hr;
  1318. hr = EnsureTypeLibrary();
  1319. if (FAILED(hr))
  1320. goto error;
  1321. hr = DispInvoke((IDispatch *)this, m_pTypeInfo, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
  1322. error:
  1323. return hr;
  1324. }
  1325. // *** IQuickActivate ***
  1326. //+---------------------------------------------------------------
  1327. //
  1328. // Member: QuickActivate
  1329. //
  1330. // Synopsis:
  1331. //
  1332. //---------------------------------------------------------------
  1333. HRESULT CDoc::QuickActivate(QACONTAINER *pQaContainer, QACONTROL *pQaControl)
  1334. {
  1335. TraceCall("CDoc::QuickActivate");
  1336. if (pQaControl == NULL || pQaContainer == NULL)
  1337. return E_INVALIDARG;
  1338. pQaControl->cbSize = sizeof(QACONTROL);
  1339. pQaControl->dwMiscStatus = OLEMISC_INSIDEOUT|OLEMISC_ACTIVATEWHENVISIBLE;
  1340. pQaControl->dwViewStatus = 0;
  1341. pQaControl->dwEventCookie = 0;
  1342. pQaControl->dwPropNotifyCookie = 0;
  1343. pQaControl->dwPointerActivationPolicy = 0;
  1344. if (m_pClientSite || pQaContainer->pClientSite==NULL)
  1345. return E_FAIL;
  1346. m_pClientSite = pQaContainer->pClientSite;
  1347. m_pClientSite ->AddRef();
  1348. return S_OK;
  1349. }
  1350. //+---------------------------------------------------------------
  1351. //
  1352. // Member: SetContentExtent
  1353. //
  1354. // Synopsis:
  1355. //
  1356. //---------------------------------------------------------------
  1357. HRESULT CDoc::SetContentExtent(LPSIZEL pSizel)
  1358. {
  1359. TraceCall("CDoc::SetContentExtent");
  1360. return S_OK;
  1361. }
  1362. //+---------------------------------------------------------------
  1363. //
  1364. // Member: GetContentExtent
  1365. //
  1366. // Synopsis:
  1367. //
  1368. //---------------------------------------------------------------
  1369. HRESULT CDoc::GetContentExtent(LPSIZEL pSizel)
  1370. {
  1371. TraceCall("CDoc::GetContentExtent");
  1372. return S_OK;
  1373. }
  1374. HRESULT CDoc::EnsureTypeLibrary()
  1375. {
  1376. HRESULT hr;
  1377. ITypeLib *pTypeLib;
  1378. TraceCall("EnsureTypeLibrary()");
  1379. if (m_pTypeInfo)
  1380. return S_OK;
  1381. hr = GetTypeLibrary(&pTypeLib);
  1382. if (!FAILED(hr))
  1383. {
  1384. hr = pTypeLib->GetTypeInfoOfGuid(IID_IMimeEdit, &m_pTypeInfo);
  1385. pTypeLib->Release();
  1386. }
  1387. return hr;
  1388. }
  1389. HRESULT CDoc::get_src(BSTR *pbstr)
  1390. {
  1391. *pbstr = NULL;
  1392. return E_NOTIMPL;
  1393. }
  1394. HRESULT CDoc::put_src(BSTR bstr)
  1395. {
  1396. IMoniker *pmk;
  1397. HRESULT hr;
  1398. IMimeMessage *pMsg;
  1399. IPersistMoniker *pPMK;
  1400. if (CreateURLMoniker(NULL, bstr, &pmk))
  1401. return E_FAIL;
  1402. hr = CoCreateInstance(CLSID_IMimeMessage, NULL, CLSCTX_INPROC_SERVER, IID_IMimeMessage, (LPVOID *)&pMsg);
  1403. if (!FAILED(hr))
  1404. {
  1405. hr = pMsg->QueryInterface(IID_IPersistMoniker, (LPVOID *)&pPMK);
  1406. if (!FAILED(hr))
  1407. {
  1408. hr=pPMK->Load(TRUE, pmk, NULL, STGM_READWRITE);
  1409. if (!FAILED(hr))
  1410. {
  1411. hr = Load(pMsg);
  1412. }
  1413. pPMK->Release();
  1414. }
  1415. pMsg->Release();
  1416. }
  1417. return hr;
  1418. }
  1419. HRESULT CDoc::put_header(LONG lStyle)
  1420. {
  1421. VARIANTARG va;
  1422. va.vt = VT_I4;
  1423. va.lVal = lStyle;
  1424. return m_pBodyObj?m_pBodyObj->PrivateExec(&CMDSETID_MimeEdit, MECMDID_STYLE, OLECMDEXECOPT_DODEFAULT, &va, NULL):E_FAIL;
  1425. }
  1426. HRESULT CDoc::put_editMode(VARIANT_BOOL b)
  1427. {
  1428. VARIANTARG va;
  1429. va.vt = VT_BOOL;
  1430. va.boolVal = b;
  1431. return m_pBodyObj?m_pBodyObj->PrivateExec(&CMDSETID_MimeEdit, MECMDID_EDITMODE, OLECMDEXECOPT_DODEFAULT, &va, NULL):E_FAIL;
  1432. }
  1433. HRESULT CDoc::get_editMode(VARIANT_BOOL *pbool)
  1434. {
  1435. VARIANTARG va;
  1436. TraceCall("CDoc::get_editMode");
  1437. if (m_pBodyObj &&
  1438. m_pBodyObj->PrivateExec(&CMDSETID_MimeEdit, MECMDID_EDITMODE, OLECMDEXECOPT_DODEFAULT, NULL, &va)==S_OK)
  1439. {
  1440. Assert(va.vt == VT_BOOL);
  1441. *pbool = va.boolVal;
  1442. return S_OK;
  1443. }
  1444. return TraceResult(E_FAIL);
  1445. }
  1446. HRESULT CDoc::get_messageSource(BSTR *pbstr)
  1447. {
  1448. IMimeMessage *pMsg;
  1449. IStream *pstm;
  1450. HRESULT hr=E_FAIL;
  1451. if (MimeOleCreateMessage(NULL, &pMsg)==S_OK)
  1452. {
  1453. if (!FAILED(Save(pMsg, MECD_HTML|MECD_PLAINTEXT|MECD_ENCODEIMAGES|MECD_ENCODESOUNDS)) &&
  1454. pMsg->Commit(0)==S_OK &&
  1455. pMsg->GetMessageSource(&pstm, 0)==S_OK)
  1456. {
  1457. hr = HrIStreamToBSTR(GetACP(), pstm, pbstr);
  1458. pstm->Release();
  1459. }
  1460. pMsg->Release();
  1461. }
  1462. return hr;
  1463. }
  1464. HRESULT CDoc::get_text(BSTR *pbstr)
  1465. {
  1466. IStream *pstm;
  1467. *pbstr = NULL;
  1468. if (GetBodyStream(m_pBodyObj->GetDoc(), FALSE, &pstm)==S_OK)
  1469. {
  1470. HrIStreamToBSTR(NULL, pstm, pbstr);
  1471. pstm->Release();
  1472. }
  1473. return S_OK;
  1474. }
  1475. HRESULT CDoc::get_html(BSTR *pbstr)
  1476. {
  1477. // BUGBUGBUG: hack for HOTMAIL page demo
  1478. IStream *pstm;
  1479. HCHARSET hCharset;
  1480. *pbstr = NULL;
  1481. MimeOleGetCodePageCharset(1252, CHARSET_BODY, &hCharset);
  1482. m_pBodyObj->SetCharset(hCharset);
  1483. if (GetBodyStream(m_pBodyObj->GetDoc(), TRUE, &pstm)==S_OK)
  1484. {
  1485. HrIStreamToBSTR(NULL, pstm, pbstr);
  1486. pstm->Release();
  1487. }
  1488. return S_OK;
  1489. // BUGBUGBUG: hack for HOTMAIL page demo
  1490. }
  1491. HRESULT CDoc::get_doc(IDispatch **ppDoc)
  1492. {
  1493. *ppDoc = 0;
  1494. if (m_pBodyObj)
  1495. (m_pBodyObj->GetDoc())->QueryInterface(IID_IDispatch, (LPVOID *)ppDoc);
  1496. return S_OK;
  1497. }
  1498. HRESULT CDoc::get_header(LONG *plStyle)
  1499. {
  1500. VARIANTARG va;
  1501. HRESULT hr;
  1502. if (!m_pBodyObj)
  1503. return E_FAIL;
  1504. hr = m_pBodyObj->PrivateExec(&CMDSETID_MimeEdit, MECMDID_STYLE, OLECMDEXECOPT_DODEFAULT, NULL, &va);
  1505. *plStyle = va.lVal;
  1506. return hr;
  1507. }
  1508. HRESULT CDoc::clear()
  1509. {
  1510. if (m_pBodyObj)
  1511. m_pBodyObj->UnloadAll();
  1512. return S_OK;
  1513. }
  1514. HRESULT CDoc::Load(LPCOLESTR pszFileName, DWORD dwMode)
  1515. {
  1516. HRESULT hr;
  1517. IMimeMessage *pMsg;
  1518. IPersistFile *pPF;
  1519. hr = CoCreateInstance(CLSID_IMimeMessage, NULL, CLSCTX_INPROC_SERVER, IID_IMimeMessage, (LPVOID *)&pMsg);
  1520. if (!FAILED(hr))
  1521. {
  1522. hr = pMsg->QueryInterface(IID_IPersistFile, (LPVOID *)&pPF);
  1523. if (!FAILED(hr))
  1524. {
  1525. hr = pPF->Load(pszFileName, dwMode);
  1526. if (!FAILED(hr))
  1527. {
  1528. hr = Load(pMsg);
  1529. }
  1530. pPF->Release();
  1531. }
  1532. pMsg->Release();
  1533. }
  1534. return hr;
  1535. }
  1536. HRESULT CDoc::Save(LPCOLESTR pszFileName, BOOL fRemember)
  1537. {
  1538. return E_NOTIMPL;
  1539. }
  1540. HRESULT CDoc::SaveCompleted(LPCOLESTR pszFileName)
  1541. {
  1542. return S_OK;
  1543. }
  1544. HRESULT CDoc::GetCurFile(LPOLESTR * ppszFileName)
  1545. {
  1546. return E_NOTIMPL;
  1547. }