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.

1270 lines
32 KiB

  1. /*
  2. * d o c h o s t . c p p
  3. *
  4. * Purpose:
  5. * basic implementation of a docobject host. Used by the body class to
  6. * host Trident and/or MSHTML
  7. *
  8. * History
  9. * August '96: brettm - created
  10. *
  11. * Copyright (C) Microsoft Corp. 1995, 1996.
  12. */
  13. #include <pch.hxx>
  14. #include "dllmain.h"
  15. #include "strconst.h"
  16. #include "msoert.h"
  17. #include "dochost.h"
  18. #include "oleutil.h"
  19. ASSERTDATA
  20. /*
  21. * m a c r o s
  22. */
  23. /*
  24. * c o n s t a n t s
  25. */
  26. /*
  27. * t y p e d e f s
  28. */
  29. /*
  30. * g l o b a l s
  31. */
  32. /*
  33. * f u n c t i o n p r o t y p e s
  34. */
  35. /*
  36. * f u n c t i o n s
  37. */
  38. //+---------------------------------------------------------------
  39. //
  40. // Member: CDocHost
  41. //
  42. // Synopsis:
  43. //
  44. //---------------------------------------------------------------
  45. CDocHost::CDocHost()
  46. {
  47. /*
  48. Not initialised
  49. Member: Initialised In:
  50. --------------------+---------------------------
  51. */
  52. m_cRef=1;
  53. m_hwnd=0;
  54. m_pDocView=0;
  55. m_lpOleObj=0;
  56. m_pCmdTarget=0;
  57. m_hwndDocObj=NULL;
  58. m_fUIActive=FALSE;
  59. m_fFocus=FALSE;
  60. m_fDownloading=FALSE;
  61. m_fCycleFocus=FALSE;
  62. m_pInPlaceActiveObj = NULL;
  63. m_dwFrameWidth = 0;
  64. m_dwFrameHeight = 0;
  65. }
  66. //+---------------------------------------------------------------
  67. //
  68. // Member:
  69. //
  70. // Synopsis:
  71. //
  72. //---------------------------------------------------------------
  73. CDocHost::~CDocHost()
  74. {
  75. // These should all get feed up when we get a WM_DESTROY and close the docobj
  76. Assert(m_lpOleObj==NULL);
  77. Assert(m_pDocView==NULL);
  78. Assert(m_pInPlaceActiveObj==NULL);
  79. Assert(m_pCmdTarget==NULL);
  80. }
  81. //+---------------------------------------------------------------
  82. //
  83. // Member: AddRef
  84. //
  85. // Synopsis:
  86. //
  87. //---------------------------------------------------------------
  88. ULONG CDocHost::AddRef()
  89. {
  90. TraceCall("CDocHost::AddRef");
  91. //TraceInfo(_MSG("CDocHost::AddRef: cRef==%d", m_cRef+1));
  92. return ++m_cRef;
  93. }
  94. //+---------------------------------------------------------------
  95. //
  96. // Member: Release
  97. //
  98. // Synopsis:
  99. //
  100. //---------------------------------------------------------------
  101. ULONG CDocHost::Release()
  102. {
  103. TraceCall("CDocHost::Release");
  104. //TraceInfo(_MSG("CDocHost::Release: cRef==%d", m_cRef-1));
  105. if (--m_cRef==0)
  106. {
  107. delete this;
  108. return 0;
  109. }
  110. return m_cRef;
  111. }
  112. //+---------------------------------------------------------------
  113. //
  114. // Member: QueryInterface
  115. //
  116. // Synopsis:
  117. //
  118. //---------------------------------------------------------------
  119. HRESULT CDocHost::QueryInterface(REFIID riid, LPVOID *lplpObj)
  120. {
  121. TraceCall("CDocHost::QueryInterface");
  122. if(!lplpObj)
  123. return E_INVALIDARG;
  124. *lplpObj = NULL; // set to NULL, in case we fail.
  125. //DebugPrintInterface(riid, "CDocHost");
  126. if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  127. *lplpObj = (LPVOID)(IOleInPlaceUIWindow *)this;
  128. else if (IsEqualIID(riid, IID_IOleInPlaceSite))
  129. *lplpObj = (LPVOID)(LPOLEINPLACESITE)this;
  130. else if (IsEqualIID(riid, IID_IOleClientSite))
  131. *lplpObj = (LPVOID)(LPOLECLIENTSITE)this;
  132. else if (IsEqualIID(riid, IID_IOleControlSite))
  133. *lplpObj = (LPVOID)(IOleControlSite *)this;
  134. else if (IsEqualIID(riid, IID_IAdviseSink))
  135. *lplpObj = (LPVOID)(LPADVISESINK)this;
  136. else if (IsEqualIID(riid, IID_IOleDocumentSite))
  137. *lplpObj = (LPVOID)(LPOLEDOCUMENTSITE)this;
  138. else if (IsEqualIID(riid, IID_IOleCommandTarget))
  139. *lplpObj = (LPVOID)(LPOLECOMMANDTARGET)this;
  140. else if (IsEqualIID(riid, IID_IServiceProvider))
  141. *lplpObj = (LPVOID)(LPSERVICEPROVIDER)this;
  142. else
  143. return E_NOINTERFACE;
  144. AddRef();
  145. return NOERROR;
  146. }
  147. //+---------------------------------------------------------------
  148. //
  149. // Member: ExtWndProc
  150. //
  151. // Synopsis:
  152. //
  153. //---------------------------------------------------------------
  154. LRESULT CALLBACK CDocHost::ExtWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  155. {
  156. LPDOCHOST pDocHost;
  157. if(msg==WM_CREATE)
  158. {
  159. pDocHost=(CDocHost *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  160. if(!pDocHost)
  161. return -1;
  162. if(FAILED(pDocHost->OnCreate(hwnd)))
  163. return -1;
  164. }
  165. pDocHost = (LPDOCHOST)GetWndThisPtr(hwnd);
  166. if(pDocHost)
  167. return pDocHost->WndProc(hwnd, msg, wParam, lParam);
  168. else
  169. return DefWindowProc(hwnd, msg, wParam, lParam);
  170. }
  171. //+---------------------------------------------------------------
  172. //
  173. // Member: WndProc
  174. //
  175. // Synopsis:
  176. //
  177. //---------------------------------------------------------------
  178. LRESULT CDocHost::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  179. {
  180. switch(msg)
  181. {
  182. case WM_SETFOCUS:
  183. if(m_pDocView)
  184. m_pDocView->UIActivate(TRUE);
  185. break;
  186. case WM_SIZE:
  187. WMSize(LOWORD(lParam), HIWORD(lParam));
  188. return 0;
  189. case WM_CLOSE:
  190. return 0; // prevent alt-f4's
  191. case WM_DESTROY:
  192. OnDestroy();
  193. break;
  194. case WM_NCDESTROY:
  195. OnNCDestroy();
  196. break;
  197. case WM_WININICHANGE:
  198. case WM_DISPLAYCHANGE:
  199. case WM_SYSCOLORCHANGE:
  200. case WM_QUERYNEWPALETTE:
  201. case WM_PALETTECHANGED:
  202. if (m_hwndDocObj)
  203. return SendMessage(m_hwndDocObj, msg, wParam, lParam);
  204. break;
  205. case WM_USER + 1:
  206. // Hook for testing automation
  207. // copy the contents of trident onto the clipboard.
  208. return CmdSelectAllCopy(m_pCmdTarget);
  209. }
  210. return DefWindowProc(hwnd, msg, wParam, lParam);
  211. }
  212. //+---------------------------------------------------------------
  213. //
  214. // Member: OnNCDestroy
  215. //
  216. // Synopsis:
  217. //
  218. //+---------------------------------------------------------------
  219. //
  220. // Member: OnNCDestroy
  221. //
  222. // Synopsis:
  223. //
  224. //---------------------------------------------------------------
  225. HRESULT CDocHost::OnNCDestroy()
  226. {
  227. TraceCall("CDocHost::OnNCDestroy");
  228. SetWindowLongPtr(m_hwnd, GWLP_USERDATA, NULL);
  229. m_hwnd = NULL;
  230. Release();
  231. return S_OK;
  232. }
  233. //+---------------------------------------------------------------
  234. //
  235. // Member: OnDestroy
  236. //
  237. // Synopsis:
  238. //
  239. //---------------------------------------------------------------
  240. HRESULT CDocHost::OnDestroy()
  241. {
  242. TraceCall("CDocHost::OnDestroy");
  243. return CloseDocObj();
  244. }
  245. //+---------------------------------------------------------------
  246. //
  247. // Member: OnCreate
  248. //
  249. // Synopsis:
  250. //
  251. //---------------------------------------------------------------
  252. HRESULT CDocHost::OnCreate(HWND hwnd)
  253. {
  254. TraceCall("CDocHost::OnCreate");
  255. m_hwnd = hwnd;
  256. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LPARAM)this);
  257. AddRef();
  258. return S_OK;
  259. }
  260. //+---------------------------------------------------------------
  261. //
  262. // Member: CreateDocObj
  263. //
  264. // Synopsis:
  265. //
  266. //---------------------------------------------------------------
  267. HRESULT CDocHost::CreateDocObj(LPCLSID pCLSID)
  268. {
  269. HRESULT hr=NOERROR;
  270. TraceCall("CDocHost::CreateDocObj");
  271. if(!pCLSID)
  272. return E_INVALIDARG;
  273. Assert(!m_lpOleObj);
  274. Assert(!m_pDocView);
  275. Assert(!m_pCmdTarget);
  276. hr = CoCreateInstance(*pCLSID, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
  277. IID_IOleObject, (LPVOID *)&m_lpOleObj);
  278. if (FAILED(hr))
  279. {
  280. TraceResult(hr);
  281. goto error;
  282. }
  283. hr = m_lpOleObj->SetClientSite((LPOLECLIENTSITE)this);
  284. if (FAILED(hr))
  285. {
  286. TraceResult(hr);
  287. goto error;
  288. }
  289. hr = m_lpOleObj->QueryInterface(IID_IOleCommandTarget, (LPVOID *)&m_pCmdTarget);
  290. if (FAILED(hr))
  291. {
  292. TraceResult(hr);
  293. goto error;
  294. }
  295. hr = HrInitNew(m_lpOleObj);
  296. if (FAILED(hr))
  297. {
  298. TraceResult(hr);
  299. goto error;
  300. }
  301. error:
  302. return hr;
  303. }
  304. //+---------------------------------------------------------------
  305. //
  306. // Member: Show
  307. //
  308. // Synopsis:
  309. //
  310. //---------------------------------------------------------------
  311. HRESULT CDocHost::Show()
  312. {
  313. RECT rc;
  314. HRESULT hr;
  315. TraceCall("CDocHost::Show");
  316. GetClientRect(m_hwnd, &rc);
  317. GetDocObjSize(&rc);
  318. hr=m_lpOleObj->DoVerb(OLEIVERB_SHOW, NULL, (LPOLECLIENTSITE)this, 0, m_hwnd, &rc);
  319. if(FAILED(hr))
  320. goto error;
  321. error:
  322. return hr;
  323. }
  324. //+---------------------------------------------------------------
  325. //
  326. // Member: CloseDocObj
  327. //
  328. // Synopsis:
  329. //
  330. //---------------------------------------------------------------
  331. HRESULT CDocHost::CloseDocObj()
  332. {
  333. LPOLEINPLACEOBJECT pInPlaceObj=0;
  334. TraceCall("CDocHost::CloseDocObj");
  335. SafeRelease(m_pCmdTarget);
  336. if(m_pDocView)
  337. {
  338. m_pDocView->UIActivate(FALSE);
  339. m_pDocView->CloseView(0);
  340. m_pDocView->SetInPlaceSite(NULL);
  341. m_pDocView->Release();
  342. m_pDocView=NULL;
  343. }
  344. if (m_lpOleObj)
  345. {
  346. // deactivate the docobj
  347. if (!FAILED(m_lpOleObj->QueryInterface(IID_IOleInPlaceObject, (LPVOID*)&pInPlaceObj)))
  348. {
  349. pInPlaceObj->InPlaceDeactivate();
  350. pInPlaceObj->Release();
  351. }
  352. // close the ole object, but blow off changes as we have either extracted
  353. // them ourselves or don't care.
  354. m_lpOleObj->Close(OLECLOSE_NOSAVE);
  355. #ifdef DEBUG
  356. ULONG uRef;
  357. uRef=
  358. #endif
  359. m_lpOleObj->Release();
  360. m_lpOleObj=NULL;
  361. AssertSz(uRef==0, "We leaked a docobject!");
  362. }
  363. m_fDownloading=FALSE;
  364. m_fFocus=FALSE;
  365. m_fUIActive=FALSE;
  366. return NOERROR;
  367. }
  368. //+---------------------------------------------------------------
  369. //
  370. // Member: Init
  371. //
  372. // Synopsis:
  373. //
  374. //---------------------------------------------------------------
  375. HRESULT CDocHost::Init(HWND hwndParent, BOOL fBorder, LPRECT prc)
  376. {
  377. HRESULT hr=S_OK;
  378. HWND hwnd;
  379. WNDCLASSW wc;
  380. TraceCall("CDocHost::Init");
  381. if(!IsWindow(hwndParent))
  382. return E_INVALIDARG;
  383. if (!GetClassInfoWrapW(g_hLocRes, c_wszDocHostWndClass, &wc))
  384. {
  385. ZeroMemory(&wc, sizeof(WNDCLASS));
  386. wc.lpfnWndProc = CDocHost::ExtWndProc;
  387. wc.hInstance = g_hLocRes;
  388. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  389. wc.lpszClassName = c_wszDocHostWndClass;
  390. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  391. wc.style = CS_DBLCLKS;
  392. if(!RegisterClassWrapW(&wc))
  393. return E_OUTOFMEMORY;
  394. }
  395. hwnd=CreateWindowExWrapW(WS_EX_NOPARENTNOTIFY|(fBorder?WS_EX_CLIENTEDGE:0),
  396. c_wszDocHostWndClass,
  397. NULL,
  398. WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_CHILD|WS_TABSTOP|WS_VISIBLE,
  399. prc->left,
  400. prc->right,
  401. prc->right-prc->left,
  402. prc->bottom-prc->top,
  403. hwndParent,
  404. NULL,
  405. g_hLocRes,
  406. (LPVOID)this);
  407. if(!hwnd)
  408. {
  409. hr=E_OUTOFMEMORY;
  410. goto error;
  411. }
  412. SetWindowPos(m_hwnd, NULL, prc->left, prc->top, prc->right-prc->left, prc->bottom-prc->top, SWP_NOZORDER);
  413. error:
  414. return hr;
  415. }
  416. // *** IOleWindow ***
  417. //+---------------------------------------------------------------
  418. //
  419. // Member: GetWindow
  420. //
  421. // Synopsis:
  422. //
  423. //---------------------------------------------------------------
  424. HRESULT CDocHost::GetWindow(HWND *phwnd)
  425. {
  426. TraceCall("CDocHost::GetWindow");
  427. *phwnd=m_hwnd;
  428. return NOERROR;
  429. }
  430. //+---------------------------------------------------------------
  431. //
  432. // Member: ContextSensitiveHelp
  433. //
  434. // Synopsis:
  435. //
  436. //---------------------------------------------------------------
  437. HRESULT CDocHost::ContextSensitiveHelp(BOOL fEnterMode)
  438. {
  439. TraceCall("CDocHost::ContextSensitiveHelp");
  440. return E_NOTIMPL;
  441. }
  442. // *** IOleInPlaceUIWindow methods ***
  443. //+---------------------------------------------------------------
  444. //
  445. // Member: GetBorder
  446. //
  447. // Synopsis:
  448. //
  449. //---------------------------------------------------------------
  450. HRESULT CDocHost::GetBorder(LPRECT lprectBorder)
  451. {
  452. TraceCall("CDocHost::GetBorder");
  453. return E_NOTIMPL;
  454. }
  455. //+---------------------------------------------------------------
  456. //
  457. // Member: RequestBorderSpace
  458. //
  459. // Synopsis:
  460. //
  461. //---------------------------------------------------------------
  462. HRESULT CDocHost::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths)
  463. {
  464. TraceCall("CDocHost::RequestBorderSpace");
  465. return NOERROR;
  466. }
  467. //+---------------------------------------------------------------
  468. //
  469. // Member: SetBorderSpace
  470. //
  471. // Synopsis:
  472. //
  473. //---------------------------------------------------------------
  474. HRESULT CDocHost::SetBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  475. {
  476. TraceCall("CDocHost::IOleInPlaceUIWindow::SetBorderSpace");
  477. return NOERROR;
  478. }
  479. //+---------------------------------------------------------------
  480. //
  481. // Member: SetActiveObject
  482. //
  483. // Synopsis:
  484. //
  485. //---------------------------------------------------------------
  486. HRESULT CDocHost::SetActiveObject(IOleInPlaceActiveObject * pActiveObject, LPCOLESTR lpszObjName)
  487. {
  488. TraceCall("CDocHost::IOleInPlaceUIWindow::SetActiveObject");
  489. ReplaceInterface(m_pInPlaceActiveObj, pActiveObject);
  490. return S_OK;
  491. }
  492. // *** IOleInPlaceFrame methods ***
  493. //+---------------------------------------------------------------
  494. //
  495. // Member: CDocHost::InsertMenus
  496. //
  497. // Synopsis:
  498. //
  499. //---------------------------------------------------------------
  500. HRESULT CDocHost::InsertMenus(HMENU, LPOLEMENUGROUPWIDTHS)
  501. {
  502. TraceCall("CDocHost::InsertMenus");
  503. return E_NOTIMPL;
  504. }
  505. //+---------------------------------------------------------------
  506. //
  507. // Member: CDocHost::SetMenu
  508. //
  509. // Synopsis:
  510. //
  511. //---------------------------------------------------------------
  512. HRESULT CDocHost::SetMenu(HMENU, HOLEMENU, HWND)
  513. {
  514. TraceCall("CDocHost::SetMenu");
  515. return E_NOTIMPL;
  516. }
  517. //+---------------------------------------------------------------
  518. //
  519. // Member: CDocHost::RemoveMenus
  520. //
  521. // Synopsis:
  522. //
  523. //---------------------------------------------------------------
  524. HRESULT CDocHost::RemoveMenus(HMENU)
  525. {
  526. TraceCall("CDocHost::RemoveMenus");
  527. return E_NOTIMPL;
  528. }
  529. //+---------------------------------------------------------------
  530. //
  531. // Member: CDocHost::SetStatusText
  532. //
  533. // Synopsis:
  534. //
  535. //---------------------------------------------------------------
  536. HRESULT CDocHost::SetStatusText(LPCOLESTR pszW)
  537. {
  538. TraceCall("CDocHost::SetStatusText");
  539. return S_OK;
  540. }
  541. //+---------------------------------------------------------------
  542. //
  543. // Member: CDocHost::EnableModeless
  544. //
  545. // Synopsis:
  546. //
  547. //---------------------------------------------------------------
  548. HRESULT CDocHost::EnableModeless(BOOL fEnable)
  549. {
  550. TraceCall("CDocHost::EnableModeless");
  551. return E_NOTIMPL;
  552. }
  553. //+---------------------------------------------------------------
  554. //
  555. // Member: CDocHost::TranslateAccelerator
  556. //
  557. // Synopsis:
  558. //
  559. //---------------------------------------------------------------
  560. HRESULT CDocHost::TranslateAccelerator(LPMSG, WORD)
  561. {
  562. TraceCall("CDocHost::TranslateAccelerator");
  563. return E_NOTIMPL;
  564. }
  565. // **** IOleInPlaceSite methods ****
  566. //+---------------------------------------------------------------
  567. //
  568. // Member: CanInPlaceActivate
  569. //
  570. // Synopsis:
  571. //
  572. //---------------------------------------------------------------
  573. HRESULT CDocHost::CanInPlaceActivate()
  574. {
  575. TraceCall("CDocHost::IOleInPlaceSite::CanInPlaceActivate");
  576. return NOERROR;
  577. }
  578. //+---------------------------------------------------------------
  579. //
  580. // Member: OnInPlaceActivate
  581. //
  582. // Synopsis:
  583. //
  584. //---------------------------------------------------------------
  585. HRESULT CDocHost::OnInPlaceActivate()
  586. {
  587. LPOLEINPLACEACTIVEOBJECT pInPlaceActive;
  588. TraceCall("CDocHost::OnInPlaceActivate");
  589. Assert(m_lpOleObj);
  590. if (m_lpOleObj->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID *)&pInPlaceActive)==S_OK)
  591. {
  592. SideAssert((pInPlaceActive->GetWindow(&m_hwndDocObj)==NOERROR)&& IsWindow(m_hwndDocObj));
  593. pInPlaceActive->Release();
  594. }
  595. return NOERROR;
  596. }
  597. //+---------------------------------------------------------------
  598. //
  599. // Member: OnUIActivate
  600. //
  601. // Synopsis:
  602. //
  603. //---------------------------------------------------------------
  604. HRESULT CDocHost::OnUIActivate()
  605. {
  606. TraceCall("CDocHost::OnUIActivate");
  607. m_fUIActive=TRUE;
  608. return NOERROR;
  609. }
  610. //+---------------------------------------------------------------
  611. //
  612. // Member: GetWindowContext
  613. //
  614. // Synopsis:
  615. //
  616. //---------------------------------------------------------------
  617. HRESULT CDocHost::GetWindowContext( IOleInPlaceFrame **ppFrame,
  618. IOleInPlaceUIWindow **ppDoc,
  619. LPRECT lprcPosRect,
  620. LPRECT lprcClipRect,
  621. LPOLEINPLACEFRAMEINFO lpFrameInfo)
  622. {
  623. TraceCall("CDocHost::IOleInPlaceSite::GetWindowContext");
  624. *ppFrame = (LPOLEINPLACEFRAME)this;
  625. AddRef();
  626. *ppDoc = NULL;
  627. GetClientRect(m_hwnd, lprcPosRect);
  628. GetDocObjSize(lprcPosRect);
  629. *lprcClipRect = *lprcPosRect;
  630. lpFrameInfo->fMDIApp = FALSE;
  631. lpFrameInfo->hwndFrame = m_hwnd;
  632. lpFrameInfo->haccel = NULL;
  633. lpFrameInfo->cAccelEntries = 0;
  634. return NOERROR;
  635. }
  636. //+---------------------------------------------------------------
  637. //
  638. // Member: Scroll
  639. //
  640. // Synopsis:
  641. //
  642. //---------------------------------------------------------------
  643. HRESULT CDocHost::Scroll(SIZE scrollExtent)
  644. {
  645. // the docobject consumes the entireview, so scroll requests
  646. // are meaningless. Return NOERROR to indicate that they're scolled
  647. // into view.
  648. TraceCall("CDocHost::IOleInPlaceSite::Scroll");
  649. return NOERROR;
  650. }
  651. //+---------------------------------------------------------------
  652. //
  653. // Member: OnUIDeactivate
  654. //
  655. // Synopsis:
  656. //
  657. //---------------------------------------------------------------
  658. HRESULT CDocHost::OnUIDeactivate(BOOL fUndoable)
  659. {
  660. TraceCall("CDocHost::OnUIDeactivate");
  661. m_fUIActive=FALSE;
  662. return S_OK;
  663. }
  664. //+---------------------------------------------------------------
  665. //
  666. // Member: OnInPlaceDeactivate
  667. //
  668. // Synopsis:
  669. //
  670. //---------------------------------------------------------------
  671. HRESULT CDocHost::OnInPlaceDeactivate()
  672. {
  673. TraceCall("CDocHost::OnInPlaceDeactivate");
  674. return S_OK;
  675. }
  676. //+---------------------------------------------------------------
  677. //
  678. // Member: DiscardUndoState
  679. //
  680. // Synopsis:
  681. //
  682. //---------------------------------------------------------------
  683. HRESULT CDocHost::DiscardUndoState()
  684. {
  685. TraceCall("CDocHost::IOleInPlaceSite::DiscardUndoState");
  686. return E_NOTIMPL;
  687. }
  688. //+---------------------------------------------------------------
  689. //
  690. // Member: DeactivateAndUndo
  691. //
  692. // Synopsis:
  693. //
  694. //---------------------------------------------------------------
  695. HRESULT CDocHost::DeactivateAndUndo()
  696. {
  697. TraceCall("CDocHost::IOleInPlaceSite::DeactivateAndUndo");
  698. return E_NOTIMPL;
  699. }
  700. //+---------------------------------------------------------------
  701. //
  702. // Member: OnPosRectChange
  703. //
  704. // Synopsis:
  705. //
  706. //---------------------------------------------------------------
  707. HRESULT CDocHost::OnPosRectChange(LPCRECT lprcPosRect)
  708. {
  709. TraceCall("CDocHost::IOleInPlaceSite::OnPosRectChange");
  710. return E_NOTIMPL;
  711. }
  712. // IOleClientSite methods.
  713. //+---------------------------------------------------------------
  714. //
  715. // Member: SaveObject
  716. //
  717. // Synopsis:
  718. //
  719. //---------------------------------------------------------------
  720. HRESULT CDocHost::SaveObject()
  721. {
  722. TraceCall("CDocHost::IOleClientSite::SaveObject");
  723. return E_NOTIMPL;
  724. }
  725. //+---------------------------------------------------------------
  726. //
  727. // Member: GetMoniker
  728. //
  729. // Synopsis:
  730. //
  731. //---------------------------------------------------------------
  732. HRESULT CDocHost::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppmnk)
  733. {
  734. TraceCall("CDocHost::IOleClientSite::GetMoniker");
  735. return E_NOTIMPL;
  736. }
  737. //+---------------------------------------------------------------
  738. //
  739. // Member: GetContainer
  740. //
  741. // Synopsis:
  742. //
  743. //---------------------------------------------------------------
  744. HRESULT CDocHost::GetContainer(LPOLECONTAINER *ppCont)
  745. {
  746. TraceCall("CDocHost::IOleClientSite::GetContainer");
  747. if(ppCont)
  748. *ppCont=NULL;
  749. return E_NOINTERFACE;
  750. }
  751. //+---------------------------------------------------------------
  752. //
  753. // Member: ShowObject
  754. //
  755. // Synopsis:
  756. //
  757. //---------------------------------------------------------------
  758. HRESULT CDocHost::ShowObject()
  759. {
  760. // always shown.
  761. // $TODO: do we need to restore the browser here if it is
  762. // minimised?
  763. TraceCall("CDocHost::IOleClientSite::ShowObject");
  764. return NOERROR;
  765. }
  766. //+---------------------------------------------------------------
  767. //
  768. // Member: OnShowWindow
  769. //
  770. // Synopsis:
  771. //
  772. //---------------------------------------------------------------
  773. HRESULT CDocHost::OnShowWindow(BOOL fShow)
  774. {
  775. TraceCall("CDocHost::IOleClientSite::OnShowWindow");
  776. return E_NOTIMPL;
  777. }
  778. //+---------------------------------------------------------------
  779. //
  780. // Member: RequestNewObjectLayout
  781. //
  782. // Synopsis:
  783. //
  784. //---------------------------------------------------------------
  785. HRESULT CDocHost::RequestNewObjectLayout()
  786. {
  787. TraceCall("CDocHost::IOleClientSite::RequestNewObjectLayout");
  788. return E_NOTIMPL;
  789. }
  790. // IOleDocumentSite
  791. //+---------------------------------------------------------------
  792. //
  793. // Member: ActivateMe
  794. //
  795. // Synopsis:
  796. //
  797. //---------------------------------------------------------------
  798. HRESULT CDocHost::ActivateMe(LPOLEDOCUMENTVIEW pViewToActivate)
  799. {
  800. TraceCall("CDocHost::IOleDocumentSite::ActivateMe");
  801. return CreateDocView();
  802. }
  803. //+---------------------------------------------------------------
  804. //
  805. // Member: CreateDocView
  806. //
  807. // Synopsis:
  808. //
  809. //---------------------------------------------------------------
  810. HRESULT CDocHost::CreateDocView()
  811. {
  812. HRESULT hr;
  813. LPOLEDOCUMENT pOleDoc=NULL;
  814. TraceCall("CDocHost::CreateDocView");
  815. AssertSz(!m_pDocView, "why is this still set??");
  816. AssertSz(m_lpOleObj, "uh? no docobject at this point?");
  817. hr=OleRun(m_lpOleObj);
  818. if(FAILED(hr))
  819. goto error;
  820. hr=m_lpOleObj->QueryInterface(IID_IOleDocument, (LPVOID*)&pOleDoc);
  821. if(FAILED(hr))
  822. goto error;
  823. hr=pOleDoc->CreateView(this, NULL,0,&m_pDocView);
  824. if(FAILED(hr))
  825. goto error;
  826. hr=m_pDocView->SetInPlaceSite(this);
  827. if(FAILED(hr))
  828. goto error;
  829. hr=m_pDocView->Show(TRUE);
  830. if(FAILED(hr))
  831. goto error;
  832. error:
  833. ReleaseObj(pOleDoc);
  834. return hr;
  835. }
  836. //+---------------------------------------------------------------
  837. //
  838. // Member: QueryStatus
  839. //
  840. // Synopsis:
  841. //
  842. //---------------------------------------------------------------
  843. HRESULT CDocHost::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pCmdText)
  844. {
  845. ULONG ul;
  846. TraceCall("CDocHost::CDocHost::QueryStatus");
  847. if (!rgCmds)
  848. return E_INVALIDARG;
  849. if (pguidCmdGroup == NULL)
  850. {
  851. TraceInfo("IOleCmdTarget::QueryStatus - std group");
  852. DebugPrintCmdIdBlock(cCmds, rgCmds);
  853. for (ul=0;ul<cCmds; ul++)
  854. {
  855. switch (rgCmds[ul].cmdID)
  856. {
  857. case OLECMDID_OPEN:
  858. case OLECMDID_SAVE:
  859. case OLECMDID_PRINT:
  860. rgCmds[ul].cmdf = MSOCMDF_ENABLED;
  861. break;
  862. default:
  863. rgCmds[ul].cmdf = 0;
  864. break;
  865. }
  866. }
  867. /* for now we deal only with status text*/
  868. if (pCmdText)
  869. {
  870. if (!(pCmdText->cmdtextf & OLECMDTEXTF_STATUS))
  871. {
  872. pCmdText->cmdtextf = OLECMDTEXTF_NONE;// is this needed?
  873. pCmdText->cwActual = 0;
  874. return NOERROR;
  875. }
  876. }
  877. return NOERROR;
  878. }
  879. TraceInfo("IOleCmdTarget::QueryStatus - unknown group");
  880. return OLECMDERR_E_UNKNOWNGROUP;
  881. }
  882. //+---------------------------------------------------------------
  883. //
  884. // Member: Exec
  885. //
  886. // Synopsis:
  887. //
  888. //---------------------------------------------------------------
  889. HRESULT CDocHost::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG *pvaIn, VARIANTARG *pvaOut)
  890. {
  891. TraceCall("CDocHost::Exec");
  892. if (pguidCmdGroup == NULL)
  893. {
  894. switch(nCmdID)
  895. {
  896. case OLECMDID_SETDOWNLOADSTATE:
  897. if(pvaIn->vt==VT_I4)
  898. {
  899. m_fDownloading=pvaIn->lVal;
  900. return S_OK;
  901. }
  902. break;
  903. case OLECMDID_UPDATECOMMANDS:
  904. OnUpdateCommands();
  905. break;
  906. case OLECMDID_SETPROGRESSPOS:
  907. // when done downloading trident now hits us with a
  908. // setprogresspos == -1 to indicate we should remove the "Done"
  909. if (pvaIn->lVal == -1)
  910. SetStatusText(NULL);
  911. return S_OK;
  912. case OLECMDID_SETPROGRESSTEXT:
  913. if(pvaIn->vt == (VT_BSTR))
  914. SetStatusText((LPCOLESTR)pvaIn->bstrVal);
  915. return S_OK;
  916. default:
  917. return OLECMDERR_E_NOTSUPPORTED;
  918. }
  919. }
  920. return OLECMDERR_E_UNKNOWNGROUP;
  921. }
  922. //+---------------------------------------------------------------
  923. //
  924. // Member: WMSize
  925. //
  926. // Synopsis:
  927. //
  928. //---------------------------------------------------------------
  929. void CDocHost::WMSize(int cxBody, int cyBody)
  930. {
  931. RECT rc={0};
  932. TraceCall("CDocHost::WMSize");
  933. if(m_pDocView)
  934. {
  935. rc.bottom=cyBody;
  936. rc.right=cxBody;
  937. // give the subclass a chance to override the size of the
  938. // docobj
  939. GetDocObjSize(&rc);
  940. #ifndef WIN16 //Trident RECTL
  941. m_pDocView->SetRect(&rc);
  942. #else
  943. RECTL rc2 = { rc.left, rc.top, rc.right, rc.bottom };
  944. m_pDocView->SetRect((LPRECT)&rc2);
  945. #endif
  946. }
  947. }
  948. //+---------------------------------------------------------------
  949. //
  950. // Member: QueryService
  951. //
  952. // Synopsis:
  953. //
  954. //---------------------------------------------------------------
  955. HRESULT CDocHost::QueryService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
  956. {
  957. TraceCall("CDocHost::QueryService");
  958. //DebugPrintInterface((REFIID)riid, "CDocHost::QueryService");
  959. return E_UNEXPECTED;
  960. }
  961. // *** IOleControlSite ***
  962. //+---------------------------------------------------------------
  963. //
  964. // Member: OnControlInfoChanged
  965. //
  966. // Synopsis:
  967. //
  968. //---------------------------------------------------------------
  969. HRESULT CDocHost::OnControlInfoChanged()
  970. {
  971. TraceCall("CDocHost::OnControlInfoChanged");
  972. return E_NOTIMPL;
  973. }
  974. //+---------------------------------------------------------------
  975. //
  976. // Member: LockInPlaceActive
  977. //
  978. // Synopsis:
  979. //
  980. //---------------------------------------------------------------
  981. HRESULT CDocHost::LockInPlaceActive(BOOL fLock)
  982. {
  983. TraceCall("CDocHost::LockInPlaceActive");
  984. return E_NOTIMPL;
  985. }
  986. //+---------------------------------------------------------------
  987. //
  988. // Member: GetExtendedControl
  989. //
  990. // Synopsis:
  991. //
  992. //---------------------------------------------------------------
  993. HRESULT CDocHost::GetExtendedControl(LPDISPATCH *ppDisp)
  994. {
  995. TraceCall("CDocHost::GetExtendedControl");
  996. if (ppDisp)
  997. *ppDisp=NULL;
  998. return E_NOTIMPL;
  999. }
  1000. //+---------------------------------------------------------------
  1001. //
  1002. // Member: TransformCoords
  1003. //
  1004. // Synopsis:
  1005. //
  1006. //---------------------------------------------------------------
  1007. HRESULT CDocHost::TransformCoords(POINTL *pPtlHimetric, POINTF *pPtfContainer,DWORD dwFlags)
  1008. {
  1009. TraceCall("CDocHost::TransformCoords");
  1010. return E_NOTIMPL;
  1011. }
  1012. //+---------------------------------------------------------------
  1013. //
  1014. // Member: TranslateAccelerator
  1015. //
  1016. // Synopsis:
  1017. //
  1018. // this is a little trippy, so bear with me. When we get a tab, and trident is UIActive we always pass it off to them
  1019. // if it tabs off the end of its internal tab order (a list of urls for instance) then we get hit with a VK_TAB in our
  1020. // IOleControlSite::TranslateAccel. If so then we set m_fCycleFocus to TRUE and return S_OK to indicate we took the tab
  1021. // tridents IOIPAO::TranslateAccel returns S_OK to indicate it snagged the TAB, we then detect if we set cyclefocus to true
  1022. // there and if so, we return S_FALSE from CBody::HrTranslateAccel to indicate to the browser that we didn't take it and it
  1023. // move the focus on
  1024. //
  1025. //---------------------------------------------------------------
  1026. HRESULT CDocHost::TranslateAccelerator(LPMSG lpMsg, DWORD grfModifiers)
  1027. {
  1028. TraceCall("CDocHost::TranslateAccelerator");
  1029. if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_TAB)
  1030. {
  1031. m_fCycleFocus=TRUE;
  1032. return S_OK;
  1033. }
  1034. return E_NOTIMPL;
  1035. }
  1036. //+---------------------------------------------------------------
  1037. //
  1038. // Member: OnFocus
  1039. //
  1040. // Synopsis:
  1041. //
  1042. //---------------------------------------------------------------
  1043. HRESULT CDocHost::OnFocus(BOOL fGotFocus)
  1044. {
  1045. TraceCall("CDocHost::OnFocus");
  1046. m_fFocus = fGotFocus;
  1047. // the docobj has focus now, be sure to send a notification
  1048. // to the parent of the dochost so that in the case of the
  1049. // mailview, it can call OnViewActivate
  1050. #if 0
  1051. // BUGBUG needed here??
  1052. NMHDR nmhdr;
  1053. nmhdr.hwndFrom = m_hwnd;
  1054. nmhdr.idFrom = GetDlgCtrlID(m_hwnd);
  1055. nmhdr.code = m_fFocus ? NM_SETFOCUS : NM_KILLFOCUS;
  1056. SendMessage(GetParent(m_hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
  1057. #endif
  1058. return S_OK;
  1059. }
  1060. //+---------------------------------------------------------------
  1061. //
  1062. // Member: ShowPropertyFrame
  1063. //
  1064. // Synopsis:
  1065. //
  1066. //---------------------------------------------------------------
  1067. HRESULT CDocHost::ShowPropertyFrame(void)
  1068. {
  1069. TraceCall("CDocHost::ShowPropertyFrame");
  1070. return E_NOTIMPL;
  1071. }
  1072. //+---------------------------------------------------------------
  1073. //
  1074. // Member: OnUpdateCommands
  1075. //
  1076. // Synopsis:
  1077. //
  1078. //---------------------------------------------------------------
  1079. HRESULT CDocHost::OnUpdateCommands()
  1080. {
  1081. TraceCall("CDocHost::OnUpdateCommands");
  1082. return S_OK;
  1083. }