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.

641 lines
16 KiB

  1. //**********************************************************************
  2. // File name: IOIPF.CPP
  3. //
  4. // Implementation file for COleInPlaceFrame
  5. //
  6. // Functions:
  7. //
  8. // See IOIPF.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. // COleInPlaceFrame::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. // E_NOINTERFACE - The interface is not supported
  40. //
  41. // Function Calls:
  42. // Function Location
  43. //
  44. // TestDebugOut Windows API
  45. // CSimpleApp::QueryInterface APP.CPP
  46. //
  47. //
  48. //********************************************************************
  49. STDMETHODIMP COleInPlaceFrame::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  50. {
  51. TestDebugOut(TEXT("In IOIPF::QueryInterface\r\n"));
  52. // delegate to the application Object
  53. return m_pApp->QueryInterface(riid, ppvObj);
  54. }
  55. //**********************************************************************
  56. //
  57. // COleInPlaceFrame::AddRef
  58. //
  59. // Purpose:
  60. //
  61. // Increments the reference count of the CSimpleApp. Since
  62. // COleInPlaceFrame is a nested class of CSimpleApp, we don't need an
  63. // extra reference count for COleInPlaceFrame. We can safely use the
  64. // reference count of CSimpleApp.
  65. //
  66. // Parameters:
  67. //
  68. // None
  69. //
  70. // Return Value:
  71. //
  72. // ULONG - The new reference count of the CSimpleApp
  73. //
  74. // Function Calls:
  75. // Function Location
  76. //
  77. // TestDebugOut Windows API
  78. // CSimpleApp::AddRef APP.CPP
  79. //
  80. //
  81. //********************************************************************
  82. STDMETHODIMP_(ULONG) COleInPlaceFrame::AddRef()
  83. {
  84. TestDebugOut(TEXT("In IOIPF::AddRef\r\n"));
  85. // delegate to the application Object
  86. return m_pApp->AddRef();
  87. }
  88. //**********************************************************************
  89. //
  90. // COleInPlaceFrame::Release
  91. //
  92. // Purpose:
  93. //
  94. // Decrements the reference count of the CSimpleApp. Since
  95. // COleInPlaceFrame is a nested class of CSimpleApp, we don't need an
  96. // extra reference count for COleInPlaceFrame. We can safely use the
  97. // reference count of CSimpleApp.
  98. //
  99. // Parameters:
  100. //
  101. // None
  102. //
  103. // Return Value:
  104. //
  105. // ULONG - The new reference count of CSimpleApp.
  106. //
  107. // Function Calls:
  108. // Function Location
  109. //
  110. // TestDebugOut Windows API
  111. // CSimpleApp::Release APP.CPP
  112. //
  113. //
  114. //********************************************************************
  115. STDMETHODIMP_(ULONG) COleInPlaceFrame::Release()
  116. {
  117. TestDebugOut(TEXT("In IOIPF::Release\r\n"));
  118. // delegate to the document object
  119. return m_pApp->Release();
  120. }
  121. //**********************************************************************
  122. //
  123. // COleInPlaceFrame::GetWindow
  124. //
  125. // Purpose:
  126. //
  127. // Returns the frame window handle
  128. //
  129. // Parameters:
  130. //
  131. // HWND FAR* lphwnd - Location to return the window 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 COleInPlaceFrame::GetWindow (HWND FAR* lphwnd)
  146. {
  147. TestDebugOut(TEXT("In IOIPF::GetWindow\r\n"));
  148. *lphwnd = m_pApp->m_hAppWnd;
  149. return ResultFromScode(S_OK);
  150. }
  151. //**********************************************************************
  152. //
  153. // COleInPlaceFrame::ContextSensitiveHelp
  154. //
  155. // Purpose:
  156. //
  157. // Used in implementing Context sensitive help
  158. //
  159. // Parameters:
  160. //
  161. // BOOL fEnterMode - TRUE if starting 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 in the OLE toolkit.
  176. //
  177. //********************************************************************
  178. STDMETHODIMP COleInPlaceFrame::ContextSensitiveHelp (BOOL fEnterMode)
  179. {
  180. TestDebugOut(TEXT("In IOIPF::ContextSensitiveHelp\r\n"));
  181. m_pApp->m_fMenuMode = fEnterMode;
  182. return ResultFromScode(S_OK);
  183. }
  184. //**********************************************************************
  185. //
  186. // COleInPlaceFrame::GetBorder
  187. //
  188. // Purpose:
  189. //
  190. // Returns the outermost border that frame adornments can be attached
  191. // during InPlace Activation.
  192. //
  193. // Parameters:
  194. //
  195. // LPRECT lprectBorder - return parameter to contain the outermost
  196. // rect for frame adornments
  197. //
  198. // Return Value:
  199. //
  200. // S_OK
  201. //
  202. // Function Calls:
  203. // Function Location
  204. //
  205. // TestDebugOut Windows API
  206. // GetClientRect Windows API
  207. // CopyRect Windows API
  208. // ResultFromScode OLE API
  209. //
  210. //
  211. //********************************************************************
  212. STDMETHODIMP COleInPlaceFrame::GetBorder (LPRECT lprectBorder)
  213. {
  214. RECT rect;
  215. TestDebugOut(TEXT("In IOIPF::GetBorder\r\n"));
  216. // get the rect for the entire frame.
  217. GetClientRect(m_pApp->m_hAppWnd, &rect);
  218. CopyRect(lprectBorder, &rect);
  219. return ResultFromScode(S_OK);
  220. }
  221. //**********************************************************************
  222. //
  223. // COleInPlaceFrame::RequestBorderSpace
  224. //
  225. // Purpose:
  226. //
  227. // Approves/Denies requests for border space during InPlace
  228. // negotiation.
  229. //
  230. // Parameters:
  231. //
  232. // LPCBORDERWIDTHS lpborderwidths - The width in pixels needed on
  233. // each side of the frame.
  234. //
  235. // Return Value:
  236. //
  237. // S_OK
  238. //
  239. // Function Calls:
  240. // Function Location
  241. //
  242. // TestDebugOut Windows API
  243. // ResultFromScode OLE API
  244. //
  245. // Comments:
  246. //
  247. // This implementation doesn't care about how much border space
  248. // is used. It always returns S_OK.
  249. //
  250. //********************************************************************
  251. STDMETHODIMP COleInPlaceFrame::RequestBorderSpace (LPCBORDERWIDTHS
  252. lpborderwidths)
  253. {
  254. TestDebugOut(TEXT("In IOIPF::RequestBorderSpace\r\n"));
  255. // always approve the request
  256. return ResultFromScode(S_OK);
  257. }
  258. //**********************************************************************
  259. //
  260. // COleInPlaceFrame::SetBorderSpace
  261. //
  262. // Purpose:
  263. //
  264. // The object calls this method when it is actually going to
  265. // start using the border space.
  266. //
  267. // Parameters:
  268. //
  269. // LPCBORDERWIDTHS lpborderwidths - Border space actually being used
  270. // by the object
  271. //
  272. // Return Value:
  273. //
  274. // S_OK
  275. //
  276. // Function Calls:
  277. // Function Location
  278. //
  279. // CSimpleApp::AddFrameLevelTools APP.CPP
  280. // TestDebugOut Windows API
  281. // GetClientRect Windows API
  282. // MoveWindow Windows API
  283. // ResultFromScode Windows API
  284. //
  285. // Comments:
  286. //
  287. // This routine could be a little smarter and check to see if
  288. // the object is requesting the entire client area of the
  289. // window.
  290. //
  291. //********************************************************************
  292. STDMETHODIMP COleInPlaceFrame::SetBorderSpace (LPCBORDERWIDTHS lpborderwidths)
  293. {
  294. TestDebugOut(TEXT("In IOIPF::SetBorderSpace\r\n"));
  295. if (lpborderwidths == NULL)
  296. m_pApp->AddFrameLevelTools();
  297. else
  298. {
  299. RECT rect;
  300. GetClientRect(m_pApp->m_hAppWnd, &rect);
  301. MoveWindow( m_pApp->m_lpDoc->m_hDocWnd,
  302. rect.left + lpborderwidths->left,
  303. rect.top + lpborderwidths->top,
  304. rect.right - lpborderwidths->right - lpborderwidths->left,
  305. rect.bottom - lpborderwidths->bottom - lpborderwidths->top,
  306. TRUE);
  307. }
  308. return ResultFromScode(S_OK);
  309. }
  310. //**********************************************************************
  311. //
  312. // COleInPlaceFrame::SetActiveObject
  313. //
  314. // Purpose:
  315. // install the object being activated in-place
  316. //
  317. //
  318. // Parameters:
  319. //
  320. // LPOLEINPLACEACTIVEOBJECT lpActiveObject - Pointer to the
  321. // objects
  322. // IOleInPlaceActiveObject
  323. // interface
  324. //
  325. // LPCOLESTR lpszObjName - Name of the object
  326. //
  327. // Return Value:
  328. //
  329. // S_OK
  330. //
  331. // Function Calls:
  332. // Function Location
  333. //
  334. // TestDebugOut Windows API
  335. // IOleInPlaceActiveObject::AddRef Object
  336. // IOleInPlaceActiveObject::Release Object
  337. // ResultFromScode OLE API
  338. //
  339. //
  340. //********************************************************************
  341. STDMETHODIMP COleInPlaceFrame::SetActiveObject (LPOLEINPLACEACTIVEOBJECT
  342. lpActiveObject, LPCOLESTR lpszObjName)
  343. {
  344. TestDebugOut(TEXT("In IOIPF::SetActiveObject\r\n"));
  345. // AddRef() it and save it...
  346. if (lpActiveObject)
  347. {
  348. lpActiveObject->AddRef();
  349. lpActiveObject->GetWindow(&m_pApp->m_hwndUIActiveObj);
  350. if (m_pApp->m_hwndUIActiveObj)
  351. SendMessage(m_pApp->m_hwndUIActiveObj, WM_QUERYNEWPALETTE, 0, 0L);
  352. }
  353. else
  354. {
  355. if (m_pApp->m_lpDoc->m_lpActiveObject)
  356. m_pApp->m_lpDoc->m_lpActiveObject->Release();
  357. m_pApp->m_hwndUIActiveObj = NULL;
  358. }
  359. // in an MDI app, this method really shouldn't be called,
  360. // this method associated with the doc is called instead.
  361. m_pApp->m_lpDoc->m_lpActiveObject = lpActiveObject;
  362. // should set window title here
  363. return ResultFromScode(S_OK);
  364. }
  365. //**********************************************************************
  366. //
  367. // COleInPlaceFrame::InsertMenus
  368. //
  369. // Purpose:
  370. //
  371. // Inserts the container menu into the combined menu
  372. //
  373. // Parameters:
  374. //
  375. // HMENU hmenuShared - Menu Handle to be set.
  376. // LPOLEMENUGROUPWIDTHS lpMenuWidths - Width of menus
  377. //
  378. // Return Value:
  379. // S_OK
  380. //
  381. // Function Calls:
  382. // Function Location
  383. //
  384. // TestDebugOut Windows API
  385. // AppendMenu Windows API
  386. // ResultFromScode OLE API
  387. //
  388. //
  389. //********************************************************************
  390. STDMETHODIMP COleInPlaceFrame::InsertMenus (HMENU hmenuShared,
  391. LPOLEMENUGROUPWIDTHS lpMenuWidths)
  392. {
  393. TestDebugOut(TEXT("In IOIPF::InsertMenus\r\n"));
  394. AppendMenu(hmenuShared, MF_BYPOSITION | MF_POPUP,
  395. (UINT) m_pApp->m_lpDoc->m_hFileMenu, TEXT("&File"));
  396. AppendMenu(hmenuShared, MF_BYPOSITION | MF_POPUP,
  397. (UINT) m_pApp->m_lpDoc->m_hHelpMenu, TEXT("&Other"));
  398. lpMenuWidths->width[0] = 1;
  399. lpMenuWidths->width[2] = 0;
  400. lpMenuWidths->width[4] = 1;
  401. return ResultFromScode(S_OK);
  402. }
  403. //**********************************************************************
  404. //
  405. // COleInPlaceFrame::SetMenu
  406. //
  407. // Purpose:
  408. //
  409. // Sets the application menu to the combined menu
  410. //
  411. // Parameters:
  412. //
  413. // HMENU hmenuShared - The combined menu
  414. //
  415. // HOLEMENU holemenu - Used by OLE
  416. //
  417. // HWND hwndActiveObject - Used by OLE
  418. //
  419. // Return Value:
  420. //
  421. // S_OK - if menu was correctly installed
  422. // E_FAIL - otherwise
  423. //
  424. // Function Calls:
  425. // Function Location
  426. //
  427. // TestDebugOut Windows API
  428. // SetMenu Windows API
  429. // OleSetMenuDescriptor OLE API
  430. //
  431. //
  432. //********************************************************************
  433. STDMETHODIMP COleInPlaceFrame::SetMenu (HMENU hmenuShared, HOLEMENU holemenu,
  434. HWND hwndActiveObject)
  435. {
  436. TestDebugOut(TEXT("In IOIPF::SetMenu\r\n"));
  437. HMENU hMenu = m_pApp->m_lpDoc->m_hMainMenu;
  438. if (holemenu)
  439. hMenu = hmenuShared;
  440. // call the windows api, not this method
  441. ::SetMenu (m_pApp->m_hAppWnd, hMenu);
  442. HRESULT hRes = OleSetMenuDescriptor(holemenu, m_pApp->m_hAppWnd,
  443. hwndActiveObject, this,
  444. m_pApp->m_lpDoc->m_lpActiveObject);
  445. return hRes;
  446. }
  447. //**********************************************************************
  448. //
  449. // COleInPlaceFrame::RemoveMenus
  450. //
  451. // Purpose:
  452. //
  453. // Removes the container menus from the combined menu
  454. //
  455. // Parameters:
  456. //
  457. // HMENU hmenuShared - Handle to the combined menu.
  458. //
  459. // Return Value:
  460. //
  461. // S_OK
  462. //
  463. // Function Calls:
  464. // Function Location
  465. //
  466. // TestDebugOut Windows API
  467. // GetMenuItemCount Windows API
  468. // RemoveMenu Windows API
  469. // ResultFromScode OLE API
  470. //
  471. //
  472. //********************************************************************
  473. STDMETHODIMP COleInPlaceFrame::RemoveMenus (HMENU hmenuShared)
  474. {
  475. int retval;
  476. TestDebugOut(TEXT("In IOIPF::RemoveMenus\r\n"));
  477. while ((retval = GetMenuItemCount(hmenuShared)) && (retval != -1))
  478. RemoveMenu(hmenuShared, 0, MF_BYPOSITION);
  479. return ResultFromScode(S_OK);
  480. }
  481. //**********************************************************************
  482. //
  483. // COleInPlaceFrame::SetStatusText
  484. //
  485. // Purpose:
  486. //
  487. // Not Implemented
  488. //
  489. // Parameters:
  490. //
  491. // LPCOLESTR lpszStatusText - character string containing the message
  492. //
  493. // Return Value:
  494. //
  495. // E_FAIL
  496. //
  497. // Function Calls:
  498. // Function Location
  499. //
  500. // TestDebugOut Windows API
  501. //
  502. // Comments:
  503. //
  504. // This function is not implemented due to the fact
  505. // that this application does not have a status bar.
  506. //
  507. //********************************************************************
  508. STDMETHODIMP COleInPlaceFrame::SetStatusText (LPCOLESTR lpszStatusText)
  509. {
  510. TestDebugOut(TEXT("In IOIPF::SetStatusText\r\n"));
  511. return ResultFromScode(E_FAIL);
  512. }
  513. //**********************************************************************
  514. //
  515. // COleInPlaceFrame::EnableModeless
  516. //
  517. // Purpose:
  518. //
  519. // Enables/Disables container modeless dialogs
  520. //
  521. // Parameters:
  522. //
  523. // BOOL fEnable - Enable/Disable
  524. //
  525. // Return Value:
  526. //
  527. // S_OK
  528. //
  529. // Function Calls:
  530. // Function Location
  531. //
  532. // TestDebugOut Windows API
  533. //
  534. // Comments:
  535. //
  536. // There are no modeless dialogs in this application, so the
  537. // implementation of this method is trivial.
  538. //
  539. //********************************************************************
  540. STDMETHODIMP COleInPlaceFrame::EnableModeless (BOOL fEnable)
  541. {
  542. TestDebugOut(TEXT("In IOIPF::EnableModeless\r\n"));
  543. return ResultFromScode(S_OK);
  544. }
  545. //**********************************************************************
  546. //
  547. // COleInPlaceFrame::TranslateAccelerator
  548. //
  549. // Purpose:
  550. //
  551. // Not Implemented
  552. //
  553. // Parameters:
  554. //
  555. // LPMSG lpmsg - structure containing keystroke message
  556. // WORD wID - identifier value corresponding to the keystroke
  557. //
  558. // Return Value:
  559. //
  560. // S_FALSE
  561. //
  562. // Function Calls:
  563. // Function Location
  564. //
  565. // TestDebugOut Windows API
  566. //
  567. //
  568. //********************************************************************
  569. STDMETHODIMP COleInPlaceFrame::TranslateAccelerator (LPMSG lpmsg, WORD wID)
  570. {
  571. TestDebugOut(TEXT("In IOIPF::TranslateAccelerator\r\n"));
  572. return ::TranslateAccelerator(m_pApp->m_hAppWnd, m_pApp->m_hAccel, lpmsg)
  573. ? ResultFromScode(S_OK)
  574. : ResultFromScode(S_FALSE);
  575. }