Source code of Windows XP (NT5)
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.

615 lines
15 KiB

  1. //**********************************************************************
  2. // File name: IOIPS.CPP
  3. //
  4. // Implementation file for COleInPlaceSite
  5. //
  6. // Functions:
  7. //
  8. // See IOIPS.H for class Definition
  9. //
  10. // Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "iocs.h"
  14. #include "ias.h"
  15. #include "ioipf.h"
  16. #include "ioips.h"
  17. #include "app.h"
  18. #include "site.h"
  19. #include "doc.h"
  20. //**********************************************************************
  21. //
  22. // COleInPlaceSite::QueryInterface
  23. //
  24. // Purpose:
  25. //
  26. // Used for interface negotiation
  27. //
  28. // Parameters:
  29. //
  30. // REFIID riid - A reference to the interface that is
  31. // being queried.
  32. //
  33. // LPVOID FAR* ppvObj - An out parameter to return a pointer to
  34. // the interface.
  35. //
  36. // Return Value:
  37. //
  38. // S_OK - The interface is supported.
  39. // S_FALSE - The interface is not supported
  40. //
  41. // Function Calls:
  42. // Function Location
  43. //
  44. // TestDebugOut Windows API
  45. // CSimpleSite::QueryInterface SITE.CPP
  46. //
  47. //
  48. //********************************************************************
  49. STDMETHODIMP COleInPlaceSite::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  50. {
  51. TestDebugOut(TEXT("In IOIPS::QueryInterface\r\n"));
  52. // delegate to the container Site
  53. return m_pSite->QueryInterface(riid, ppvObj);
  54. }
  55. //**********************************************************************
  56. //
  57. // COleInPlaceSite::AddRef
  58. //
  59. // Purpose:
  60. //
  61. // Increments the reference count of the CSimpleSite. Since
  62. // COleInPlaceSite is a nested class of CSimpleSite, we don't need an
  63. // extra reference count for COleInPlaceSite. We can safely use the
  64. // reference count of CSimpleSite.
  65. //
  66. // Parameters:
  67. //
  68. // None
  69. //
  70. // Return Value:
  71. //
  72. // ULONG - The new reference count of CSimpleSite
  73. //
  74. // Function Calls:
  75. // Function Location
  76. //
  77. // TestDebugOut Windows API
  78. // CSimpleSite::QueryInterface SITE.CPP
  79. //
  80. //
  81. //********************************************************************
  82. STDMETHODIMP_(ULONG) COleInPlaceSite::AddRef()
  83. {
  84. TestDebugOut(TEXT("In IOIPS::AddRef\r\n"));
  85. // delegate to the container Site
  86. return m_pSite->AddRef();
  87. }
  88. //**********************************************************************
  89. //
  90. // COleInPlaceSite::Release
  91. //
  92. // Purpose:
  93. //
  94. // Decrements the reference count of the CSimpleSite. Since
  95. // COleInPlaceSite is a nested class of CSimpleSite, we don't need an
  96. // extra reference count for COleInPlaceSite. We can safely use the
  97. // reference count of CSimpleSite.
  98. //
  99. // Parameters:
  100. //
  101. // None
  102. //
  103. // Return Value:
  104. //
  105. // ULONG - The new reference count of CSimpleSite
  106. //
  107. // Function Calls:
  108. // Function Location
  109. //
  110. // TestDebugOut Windows API
  111. // CSimpleSite::Release SITE.CPP
  112. //
  113. //
  114. //********************************************************************
  115. STDMETHODIMP_(ULONG) COleInPlaceSite::Release()
  116. {
  117. TestDebugOut(TEXT("In IOIPS::Release\r\n"));
  118. // delegate to the container Site
  119. return m_pSite->Release();
  120. }
  121. //**********************************************************************
  122. //
  123. // COleInPlaceSite::GetWindow
  124. //
  125. // Purpose:
  126. //
  127. // Returns the Window Handle of the client site
  128. //
  129. // Parameters:
  130. //
  131. // HWND FAR* lphwnd - place to return the handle
  132. //
  133. // Return Value:
  134. //
  135. // S_OK
  136. //
  137. // Function Calls:
  138. // Function Location
  139. //
  140. // TestDebugOut Windows API
  141. // ResultFromScode OLE API
  142. //
  143. //
  144. //********************************************************************
  145. STDMETHODIMP COleInPlaceSite::GetWindow (HWND FAR* lphwnd)
  146. {
  147. TestDebugOut(TEXT("In IOIPS::GetWindow\r\n"));
  148. // return the handle to our editing window.
  149. *lphwnd = m_pSite->m_lpDoc->m_hDocWnd;
  150. return ResultFromScode(S_OK);
  151. }
  152. //**********************************************************************
  153. //
  154. // COleInPlaceSite::ContextSensitiveHelp
  155. //
  156. // Purpose:
  157. // set/reset context sensitive help mode
  158. //
  159. // Parameters:
  160. //
  161. // BOOL fEnterMode - TRUE for entering Context Sensitive help mode
  162. //
  163. // Return Value:
  164. //
  165. // S_OK
  166. //
  167. // Function Calls:
  168. // Function Location
  169. //
  170. // TestDebugOut Windows API
  171. // ResultFromScode OLE API
  172. //
  173. // Comments:
  174. //
  175. // Be sure to read the technotes included with the OLE toolkit.
  176. //
  177. //********************************************************************
  178. STDMETHODIMP COleInPlaceSite::ContextSensitiveHelp (BOOL fEnterMode)
  179. {
  180. TestDebugOut(TEXT("In IOIPS::ContextSensitiveHelp\r\n"));
  181. if (m_pSite->m_lpDoc->m_lpApp->m_fCSHMode != fEnterMode)
  182. m_pSite->m_lpDoc->m_lpApp->m_fCSHMode = fEnterMode;
  183. return ResultFromScode(S_OK);
  184. }
  185. //**********************************************************************
  186. //
  187. // COleInPlaceSite::CanInPlaceActivate
  188. //
  189. // Purpose:
  190. //
  191. // Object calls to find out if the container can InPlace activate
  192. //
  193. // Parameters:
  194. //
  195. // None
  196. //
  197. // Return Value:
  198. //
  199. // S_OK
  200. //
  201. // Function Calls:
  202. // Function Location
  203. //
  204. // TestDebugOut Windows API
  205. // ResultFromScode OLE API
  206. //
  207. //
  208. //********************************************************************
  209. STDMETHODIMP COleInPlaceSite::CanInPlaceActivate ()
  210. {
  211. TestDebugOut(TEXT("In IOIPS::CanInPlaceActivate\r\n"));
  212. // return S_OK to indicate we can in-place activate
  213. return ResultFromScode(S_OK);
  214. }
  215. //**********************************************************************
  216. //
  217. // COleInPlaceSite::OnInPlaceActivate
  218. //
  219. // Purpose:
  220. //
  221. // Called by the object on InPlace Activation
  222. //
  223. // Parameters:
  224. //
  225. // None
  226. //
  227. // Return Value:
  228. //
  229. // S_OK - if the interface can be found
  230. // E_FAIL - otherwise
  231. //
  232. // Function Calls:
  233. // Function Location
  234. //
  235. // TestDebugOut Windows API
  236. // ResultFromScode OLE API
  237. // IOleObject::QueryInterface Object
  238. //
  239. //
  240. //********************************************************************
  241. STDMETHODIMP COleInPlaceSite::OnInPlaceActivate ()
  242. {
  243. HRESULT hrErr;
  244. TestDebugOut(TEXT("In IOIPS::OnInPlaceActivate\r\n"));
  245. hrErr = m_pSite->m_lpOleObject->QueryInterface(
  246. IID_IOleInPlaceObject, (LPVOID FAR *)&m_pSite->m_lpInPlaceObject);
  247. if (hrErr != NOERROR)
  248. return ResultFromScode(E_FAIL);
  249. // return S_OK to indicate we can in-place activate.
  250. return ResultFromScode(S_OK);
  251. }
  252. //**********************************************************************
  253. //
  254. // COleInPlaceSite::OnUIActivate
  255. //
  256. // Purpose:
  257. //
  258. // Object calls this method when it displays it's UI.
  259. //
  260. // Parameters:
  261. //
  262. // None.
  263. //
  264. // Return Value:
  265. //
  266. // S_OK
  267. //
  268. // Function Calls:
  269. // Function Location
  270. //
  271. // TestDebugOut Windows API
  272. // ResultFromScode OLE API
  273. // IOleInPlaceObject::GetWindow Object
  274. //
  275. //
  276. //********************************************************************
  277. STDMETHODIMP COleInPlaceSite::OnUIActivate ()
  278. {
  279. TestDebugOut(TEXT("In IOIPS::OnUIActivate\r\n"));
  280. m_pSite->m_lpDoc->m_fAddMyUI=FALSE;
  281. m_pSite->m_lpDoc->m_fInPlaceActive = TRUE;
  282. m_pSite->m_fInPlaceActive = TRUE;
  283. m_pSite->m_lpInPlaceObject->GetWindow((HWND FAR*)&m_pSite->m_hwndIPObj);
  284. // return S_OK to continue in-place activation
  285. return ResultFromScode(S_OK);
  286. }
  287. //**********************************************************************
  288. //
  289. // COleInPlaceSite::GetWindowContext
  290. //
  291. // Purpose:
  292. //
  293. // Called by the object to get information for InPlace Negotiation.
  294. //
  295. // Parameters:
  296. //
  297. // LPOLEINPLACEFRAME FAR* lplpFrame - Location to return a pointer
  298. // to IOleInPlaceFrame.
  299. //
  300. // LPOLEINPLACEUIWINDOW FAR* lplpDoc - Location to return a pointer
  301. // to IOleInPlaceUIWindow.
  302. //
  303. // LPRECT lprcPosRect - The rect that the object
  304. // occupies
  305. //
  306. // LPRECT lprcClipRect - The clipping rect
  307. //
  308. // LPOLEINPLACEFRAMEINFO lpFrameInfo - Pointer to FRAMEINFO
  309. //
  310. //
  311. // Return Value:
  312. //
  313. // S_OK
  314. //
  315. // Function Calls:
  316. // Function Location
  317. //
  318. // COleInPlaceFrame::AddRef IOIPF.CPP
  319. // CSimpleSite::GetObjRect SITE.CPP
  320. // TestDebugOut Windows API
  321. // CopyRect Windows API
  322. // GetClientRect Windows API
  323. // ResultFromScode OLE API
  324. //
  325. //
  326. //********************************************************************
  327. STDMETHODIMP COleInPlaceSite::GetWindowContext (
  328. LPOLEINPLACEFRAME FAR* lplpFrame,
  329. LPOLEINPLACEUIWINDOW FAR* lplpDoc,
  330. LPRECT lprcPosRect,
  331. LPRECT lprcClipRect,
  332. LPOLEINPLACEFRAMEINFO lpFrameInfo)
  333. {
  334. RECT rect;
  335. TestDebugOut(TEXT("In IOIPS::GetWindowContext\r\n"));
  336. // the frame is associated with the application object.
  337. // need to AddRef() it...
  338. m_pSite->m_lpDoc->m_lpApp->m_OleInPlaceFrame.AddRef();
  339. *lplpFrame = &m_pSite->m_lpDoc->m_lpApp->m_OleInPlaceFrame;
  340. *lplpDoc = NULL; // must be NULL, cause we're SDI.
  341. // get the size of the object in pixels
  342. m_pSite->GetObjRect(&rect);
  343. // Copy this to the passed buffer
  344. CopyRect(lprcPosRect, &rect);
  345. // fill the clipping region
  346. GetClientRect(m_pSite->m_lpDoc->m_hDocWnd, &rect);
  347. CopyRect(lprcClipRect, &rect);
  348. // fill the FRAMEINFO
  349. if (sizeof(OLEINPLACEFRAMEINFO) != lpFrameInfo->cb)
  350. {
  351. TestDebugOut(TEXT("WARNING IOIPS::GetWindowContext "
  352. "lpFrameInfo->cb size may be incorrect\r\n"));
  353. }
  354. lpFrameInfo->fMDIApp = FALSE;
  355. lpFrameInfo->hwndFrame = m_pSite->m_lpDoc->m_lpApp->m_hAppWnd;
  356. lpFrameInfo->haccel = m_pSite->m_lpDoc->m_lpApp->m_hAccel;
  357. lpFrameInfo->cAccelEntries = SIMPCNTR_ACCEL_CNT;
  358. return ResultFromScode(S_OK);
  359. }
  360. //**********************************************************************
  361. //
  362. // COleInPlaceSite::Scroll
  363. //
  364. // Purpose:
  365. //
  366. // Not Implemented
  367. //
  368. // Parameters:
  369. //
  370. // SIZE scrollExtent - number of pixels scrolled in X and Y direction
  371. //
  372. // Return Value:
  373. //
  374. // E_FAIL
  375. //
  376. // Function Calls:
  377. // Function Location
  378. //
  379. // TestDebugOut Windows API
  380. //
  381. //
  382. //********************************************************************
  383. STDMETHODIMP COleInPlaceSite::Scroll (SIZE scrollExtent)
  384. {
  385. TestDebugOut(TEXT("In IOIPS::Scroll\r\n"));
  386. return ResultFromScode(E_FAIL);
  387. }
  388. //**********************************************************************
  389. //
  390. // COleInPlaceSite::OnUIDeactivate
  391. //
  392. // Purpose:
  393. //
  394. // Called by the object when its UI goes away
  395. //
  396. // Parameters:
  397. //
  398. // BOOL fUndoable
  399. //
  400. // Return Value:
  401. //
  402. // S_OK
  403. //
  404. // Function Calls:
  405. // Function Location
  406. //
  407. // TestDebugOut Windows API
  408. // CSimpleAPP::QueryNewPalette APP.CPP
  409. // CSimpleAPP::AddFrameLevelUI APP.CPP
  410. // ResultFromScode OLE API
  411. //
  412. //
  413. //********************************************************************
  414. STDMETHODIMP COleInPlaceSite::OnUIDeactivate (BOOL fUndoable)
  415. {
  416. TestDebugOut(TEXT("In IOIPS::OnUIDeactivate\r\n"));
  417. // need to clear this flag first
  418. m_pSite->m_lpDoc->m_fInPlaceActive = FALSE;
  419. m_pSite->m_fInPlaceActive = FALSE;
  420. m_pSite->m_lpDoc->m_lpApp->QueryNewPalette();
  421. m_pSite->m_lpDoc->m_lpApp->AddFrameLevelUI();
  422. return ResultFromScode(S_OK);
  423. }
  424. //**********************************************************************
  425. //
  426. // COleInPlaceSite::OnInPlaceDeactivate
  427. //
  428. // Purpose:
  429. //
  430. // Called when the inplace session is over
  431. //
  432. // Parameters:
  433. //
  434. // None
  435. //
  436. // Return Value:
  437. //
  438. // S_OK
  439. //
  440. // Function Calls:
  441. // Function Location
  442. //
  443. // TestDebugOut Windows API
  444. // ResultFromScode OLE API
  445. // IOleInPlaceObject::Release Object
  446. //
  447. //
  448. //********************************************************************
  449. STDMETHODIMP COleInPlaceSite::OnInPlaceDeactivate ()
  450. {
  451. TestDebugOut(TEXT("In IOIPS::OnInPlaceDeactivate\r\n"));
  452. if (m_pSite->m_lpInPlaceObject)
  453. {
  454. m_pSite->m_lpInPlaceObject->Release();
  455. m_pSite->m_lpInPlaceObject = NULL;
  456. }
  457. return ResultFromScode(S_OK);
  458. }
  459. //**********************************************************************
  460. //
  461. // COleInPlaceSite::DiscardUndoState
  462. //
  463. // Purpose:
  464. //
  465. // Not Implemented
  466. //
  467. // Parameters:
  468. //
  469. // None
  470. //
  471. // Return Value:
  472. //
  473. // E_FAIL
  474. //
  475. // Function Calls:
  476. // Function Location
  477. //
  478. // TestDebugOut Windows API
  479. //
  480. //
  481. //********************************************************************
  482. STDMETHODIMP COleInPlaceSite::DiscardUndoState ()
  483. {
  484. TestDebugOut(TEXT("In IOIPS::DiscardUndoState\r\n"));
  485. return ResultFromScode(E_FAIL);
  486. }
  487. //**********************************************************************
  488. //
  489. // COleInPlaceSite::DeactivateAndUndo
  490. //
  491. // Purpose:
  492. //
  493. // Not Implemented
  494. //
  495. // Parameters:
  496. //
  497. // None
  498. //
  499. // Return Value:
  500. //
  501. // E_FAIL
  502. //
  503. // Function Calls:
  504. // Function Location
  505. //
  506. // TestDebugOut Windows API
  507. //
  508. //
  509. //********************************************************************
  510. STDMETHODIMP COleInPlaceSite::DeactivateAndUndo ()
  511. {
  512. TestDebugOut(TEXT("In IOIPS::DeactivateAndUndo\r\n"));
  513. return ResultFromScode(E_FAIL);
  514. }
  515. //**********************************************************************
  516. //
  517. // COleInPlaceSite::OnPosRectChange
  518. //
  519. // Purpose:
  520. //
  521. // The object calls this method when it's size changes during an
  522. // InPlace Session
  523. //
  524. // Parameters:
  525. //
  526. // LPCRECT lprcPosRect - The new object rect
  527. //
  528. // Return Value:
  529. //
  530. // S_OK
  531. //
  532. // Function Calls:
  533. // Function Location
  534. //
  535. // TestDebugOut Windows API
  536. // GetClientRect Windows API
  537. // IOleObject::GetExtent Object
  538. // IOleInPlaceObject::SetObjectRects Object
  539. // ResultFromScode OLE API
  540. //
  541. //
  542. //********************************************************************
  543. STDMETHODIMP COleInPlaceSite::OnPosRectChange (LPCRECT lprcPosRect)
  544. {
  545. TestDebugOut(TEXT("In IOIPS::OnPosRectChange\r\n"));
  546. // update the size in the document object
  547. // NOTE: here we must call IOleObject::GetExtent to get actual extents
  548. // of the running object. IViewObject2::GetExtent returns the
  549. // last cached extents.
  550. m_pSite->m_lpOleObject->GetExtent(DVASPECT_CONTENT, &m_pSite->m_sizel);
  551. RECT rect;
  552. GetClientRect(m_pSite->m_lpDoc->m_hDocWnd, &rect);
  553. // tell the object its new size
  554. m_pSite->m_lpInPlaceObject->SetObjectRects(lprcPosRect, &rect);
  555. return ResultFromScode(S_OK);
  556. }
  557.