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.

1057 lines
25 KiB

  1. //**********************************************************************
  2. // File name: obj.cpp
  3. //
  4. // Implementation file for the CSimpSvrApp Class
  5. //
  6. // Functions:
  7. //
  8. // See obj.h for a list of member functions.
  9. //
  10. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "obj.h"
  14. #include "ioo.h"
  15. #include "ido.h"
  16. #include "ips.h"
  17. #include "icf.h"
  18. #include "ioipao.h"
  19. #include "ioipo.h"
  20. #include "app.h"
  21. #include "doc.h"
  22. //**********************************************************************
  23. //
  24. // CSimpSvrObj::QueryInterface
  25. //
  26. // Purpose:
  27. //
  28. // Used for interface negotiation at the "Object" level.
  29. //
  30. // Parameters:
  31. //
  32. // REFIID riid - A reference to the interface that is
  33. // being queried.
  34. //
  35. // LPVOID FAR* ppvObj - An out parameter to return a pointer to
  36. // the interface.
  37. //
  38. // Return Value:
  39. //
  40. // S_OK - The interface is supported.
  41. // E_NOINTERFACE - The interface is not supported
  42. //
  43. // Function Calls:
  44. // Function Location
  45. //
  46. // TestDebugOut Windows API
  47. // ResultFromScode OLE API
  48. // IUnknown::AddRef OBJ.CPP, IOO.CPP, IDO.CPP, IPS.CPP
  49. // IOIPO.CPP, IOIPAO.CPP
  50. //
  51. // Comments:
  52. //
  53. //
  54. //********************************************************************
  55. STDMETHODIMP CSimpSvrObj::QueryInterface ( REFIID riid, LPVOID FAR* ppvObj)
  56. {
  57. TestDebugOut("In CSimpSvrObj::QueryInterface\r\n");
  58. SCODE sc = S_OK;
  59. if (riid == IID_IUnknown)
  60. *ppvObj = this;
  61. else if (riid == IID_IOleObject)
  62. *ppvObj = &m_OleObject;
  63. else if (riid == IID_IDataObject)
  64. *ppvObj = &m_DataObject;
  65. else if ( (riid == IID_IPersistStorage) || (riid == IID_IPersist) )
  66. *ppvObj = &m_PersistStorage;
  67. else if (riid == IID_IOleInPlaceObject)
  68. *ppvObj = &m_OleInPlaceObject;
  69. else if (riid == IID_IOleInPlaceActiveObject)
  70. *ppvObj = &m_OleInPlaceActiveObject;
  71. else if (riid == IID_IExternalConnection)
  72. *ppvObj = &m_ExternalConnection;
  73. else
  74. {
  75. *ppvObj = NULL;
  76. sc = E_NOINTERFACE;
  77. }
  78. if (*ppvObj)
  79. ((LPUNKNOWN)*ppvObj)->AddRef();
  80. return ResultFromScode( sc );
  81. };
  82. //**********************************************************************
  83. //
  84. // CSimpSvrObj::AddRef
  85. //
  86. // Purpose:
  87. //
  88. // Adds to the reference count at the Object level.
  89. //
  90. // Parameters:
  91. //
  92. // None
  93. //
  94. // Return Value:
  95. //
  96. // ULONG - The new reference count of the Object.
  97. //
  98. // Function Calls:
  99. // Function Location
  100. //
  101. // TestDebugOut Windows API
  102. //
  103. // Comments:
  104. //
  105. // Due to the reference counting model that is used in this
  106. // implementation, this reference count is the sum of the
  107. // reference counts on all interfaces
  108. //
  109. //********************************************************************
  110. STDMETHODIMP_(ULONG) CSimpSvrObj::AddRef ()
  111. {
  112. TestDebugOut("In CSimpSvrObj::AddRef\r\n");
  113. m_lpDoc->AddRef();
  114. return ++m_nCount;
  115. };
  116. //**********************************************************************
  117. //
  118. // CSimpSvrObj::Release
  119. //
  120. // Purpose:
  121. //
  122. // Decrements the reference count at this level
  123. //
  124. // Parameters:
  125. //
  126. // None
  127. //
  128. // Return Value:
  129. //
  130. // ULONG - The new reference count of the object.
  131. //
  132. // Function Calls:
  133. // Function Location
  134. //
  135. // TestDebugOut Windows API
  136. //
  137. // Comments:
  138. //
  139. // Due to the reference counting model that is used in this
  140. // implementation, this reference count is the sum of the
  141. // reference counts on all interfaces
  142. //
  143. //********************************************************************
  144. STDMETHODIMP_(ULONG) CSimpSvrObj::Release ()
  145. {
  146. TestDebugOut("In CSimpSvrObj::Release\r\n");
  147. m_lpDoc->Release();
  148. if (--m_nCount == 0) {
  149. delete this;
  150. return 0;
  151. }
  152. return m_nCount;
  153. };
  154. //**********************************************************************
  155. //
  156. // CSimpSvrObj::CSimpSvrObj
  157. //
  158. // Purpose:
  159. //
  160. // Constructor for CSimpSvrObj
  161. //
  162. // Parameters:
  163. //
  164. // CSimpSvrDoc FAR * lpSimpSvrDoc - ptr to the doc object
  165. //
  166. // Return Value:
  167. //
  168. // None
  169. //
  170. // Function Calls:
  171. // Function Location
  172. //
  173. //
  174. // Comments:
  175. //
  176. //
  177. //********************************************************************
  178. #pragma warning (disable : 4355) // "this" used in base initializer list warning. This
  179. // can be disabled because we are not using "this" in
  180. // the constructor for these objects, rather we are
  181. // just storing it for future use...
  182. CSimpSvrObj::CSimpSvrObj(CSimpSvrDoc FAR * lpSimpSvrDoc) : m_OleObject(this),
  183. m_DataObject(this),
  184. m_PersistStorage(this),
  185. m_OleInPlaceActiveObject(this),
  186. m_OleInPlaceObject(this),
  187. m_ExternalConnection(this)
  188. #pragma warning (default : 4355) // Turn the warning back on
  189. {
  190. m_lpDoc = lpSimpSvrDoc;
  191. m_nCount = 0;
  192. m_fInPlaceActive = FALSE;
  193. m_fInPlaceVisible = FALSE;
  194. m_fUIActive = FALSE;
  195. m_hmenuShared = NULL;
  196. m_hOleMenu = NULL;
  197. m_dwRegister = 0;
  198. m_lpFrame = NULL;
  199. m_lpCntrDoc = NULL;
  200. m_lpStorage = NULL;
  201. m_lpColorStm = NULL;
  202. m_lpSizeStm = NULL;
  203. m_lpOleClientSite = NULL;
  204. m_lpOleAdviseHolder = NULL;
  205. m_lpDataAdviseHolder = NULL;
  206. m_lpIPSite = NULL;
  207. m_red = 128;
  208. m_green = 0;
  209. m_blue = 0;
  210. m_size.x = 100;
  211. m_size.y = 100;
  212. m_xOffset = 0;
  213. m_yOffset = 0;
  214. m_scale = 1;
  215. m_fSaveWithSameAsLoad = FALSE;
  216. m_fNoScribbleMode = FALSE;
  217. }
  218. //**********************************************************************
  219. //
  220. // CSimpSvrObj::~CSimpSvrObj
  221. //
  222. // Purpose:
  223. //
  224. // Destructor for CSimpSvrObj
  225. //
  226. // Parameters:
  227. //
  228. // None
  229. //
  230. // Return Value:
  231. //
  232. //
  233. //
  234. // Function Calls:
  235. // Function Location
  236. //
  237. // TestDebugOut Windows API
  238. // PostMessage Windows API
  239. // CSimpSvrDoc::GetApp DOC.H
  240. // CSimpSvrDoc::GethAppWnd DOC.H
  241. // CSimpSvrDoc::ClearObj DOC.H
  242. // CSimpSvrApp::IsStartedByOle APP.CPP
  243. //
  244. // Comments:
  245. //
  246. //
  247. //********************************************************************
  248. CSimpSvrObj::~CSimpSvrObj()
  249. {
  250. TestDebugOut("In CSimpSvrObj's Destructor \r\n");
  251. // if we were started by ole, post ourselves a close message
  252. if (m_lpDoc->GetApp()->IsStartedByOle())
  253. PostMessage(m_lpDoc->GethAppWnd(), WM_SYSCOMMAND, SC_CLOSE, 0L);
  254. // clear the OBJ ptr in the doc class
  255. m_lpDoc->ClearObj();
  256. }
  257. //**********************************************************************
  258. //
  259. // CSimpSvrObj::Draw
  260. //
  261. // Purpose:
  262. //
  263. // Draws the object into an arbitrary DC
  264. //
  265. // Parameters:
  266. //
  267. // HDC hDC - DC to draw into
  268. //
  269. // Return Value:
  270. //
  271. // NONE
  272. //
  273. // Function Calls:
  274. // Function Location
  275. //
  276. // TestDebugOut Windows API
  277. // CreateBrushIndirect Windows API
  278. // SelectObject Windows API
  279. // Rectangle Windows API
  280. // DeleteObject Windows API
  281. //
  282. // Comments:
  283. //
  284. //
  285. //********************************************************************
  286. void CSimpSvrObj::Draw (HDC hDC, BOOL m_fMeta)
  287. {
  288. LOGBRUSH lb;
  289. TestDebugOut("In CSimpSvrObj::Draw\r\n");
  290. char szBuffer[255];
  291. wsprintf(szBuffer,"Drawing Scale %3d\r\n",m_scale);
  292. TestDebugOut(szBuffer);
  293. if (!m_fMeta)
  294. {
  295. SetMapMode(hDC, MM_ANISOTROPIC);
  296. SetWindowOrg(hDC, (int)(m_xOffset/m_scale), (int)(m_yOffset/m_scale));
  297. SetWindowExt(hDC, m_size.x, m_size.y);
  298. SetViewportExt(hDC, (int)(m_size.x*m_scale), (int)(m_size.y*m_scale));
  299. }
  300. // fill out a LOGBRUSH
  301. lb.lbStyle = BS_SOLID;
  302. lb.lbColor = RGB(m_red, m_green, m_blue);
  303. lb.lbHatch = 0;
  304. // create the brush
  305. HBRUSH hBrush = CreateBrushIndirect(&lb);
  306. // select the brush
  307. HBRUSH hOldBrush = SelectObject(hDC, hBrush);
  308. HPEN hPen = CreatePen(PS_INSIDEFRAME, 6, RGB(0, 0, 0));
  309. HPEN hOldPen = SelectObject(hDC, hPen);
  310. // draw the rectangle
  311. Rectangle (hDC, 0, 0, m_size.x, m_size.y);
  312. // restore the pen
  313. hPen = SelectObject(hDC, hOldPen);
  314. // free the pen
  315. DeleteObject(hPen);
  316. // restore the old brush
  317. hBrush = SelectObject(hDC, hOldBrush);
  318. // free the brush
  319. DeleteObject(hBrush);
  320. }
  321. //**********************************************************************
  322. //
  323. // CSimpSvrObj::GetMetaFilePict
  324. //
  325. // Purpose:
  326. //
  327. // Returns a handle to a metafile representation of the object.
  328. //
  329. // Parameters:
  330. //
  331. // None
  332. //
  333. // Return Value:
  334. //
  335. // Handle to the metafile.
  336. //
  337. // Function Calls:
  338. // Function Location
  339. //
  340. // TestDebugOut Windows API
  341. // GlobalAlloc Windows API
  342. // GlobalLock Windows API
  343. // SetWindowOrg Windows API
  344. // SetWindowExt Windows API
  345. // CreateMetaFile Windows API
  346. // CloseMetaFile Windows API
  347. // GlobalUnlock Windows API
  348. // XformWidthInPixelsToHimetric OLE2UI
  349. // XformHeightInPixelsToHimetric OLE2UI
  350. // CSimpSvrObj::Draw OBJ.CPP
  351. //
  352. // Comments:
  353. //
  354. //
  355. //********************************************************************
  356. HANDLE CSimpSvrObj::GetMetaFilePict()
  357. {
  358. HANDLE hMFP;
  359. METAFILEPICT FAR * lpMFP;
  360. POINT pt;
  361. TestDebugOut("In CSimpSvrObj::GetMetaFilePict\r\n");
  362. // allocate the memory for the METAFILEPICT structure
  363. hMFP = GlobalAlloc (GMEM_SHARE | GHND, sizeof (METAFILEPICT) );
  364. lpMFP = (METAFILEPICT FAR*) GlobalLock(hMFP);
  365. // get the size of the object in HIMETRIC
  366. pt.x = XformWidthInPixelsToHimetric(NULL, m_size.x);
  367. pt.y = XformHeightInPixelsToHimetric(NULL, m_size.y);
  368. // fill out the METAFILEPICT structure
  369. lpMFP->mm = MM_ANISOTROPIC;
  370. lpMFP->xExt = pt.x;
  371. lpMFP->yExt = pt.y;
  372. // Create the metafile
  373. HDC hDC = CreateMetaFile(NULL);
  374. SetWindowOrg (hDC, 0, 0);
  375. SetWindowExt (hDC, m_size.x,
  376. m_size.y);
  377. Draw(hDC);
  378. lpMFP->hMF = CloseMetaFile(hDC);
  379. // unlock the metafilepict
  380. GlobalUnlock(hMFP);
  381. return hMFP;
  382. }
  383. //**********************************************************************
  384. //
  385. // CSimpSvrObj::SaveToStorage
  386. //
  387. // Purpose:
  388. //
  389. // Saves the object to the passed storage
  390. //
  391. // Parameters:
  392. //
  393. // LPSTORAGE lpStg - Storage in which to save the object
  394. //
  395. // Return Value:
  396. //
  397. // None
  398. //
  399. // Function Calls:
  400. // Function Location
  401. //
  402. // TestDebugOut Windows API
  403. // IStorage::CreateStream OLE
  404. // IStream::Write OLE
  405. // IStream::Release OLE
  406. //
  407. // Comments:
  408. //
  409. // A real app will want to do better error checking / returning
  410. //
  411. //********************************************************************
  412. void CSimpSvrObj::SaveToStorage (LPSTORAGE lpStg, BOOL fSameAsLoad)
  413. {
  414. TestDebugOut("In CSimpSvrObj::SaveToStorage\r\n");
  415. LPSTREAM lpTempColor, lpTempSize;
  416. if (!fSameAsLoad)
  417. m_PersistStorage.CreateStreams( lpStg, &lpTempColor, &lpTempSize);
  418. else
  419. {
  420. lpTempColor = m_lpColorStm;
  421. lpTempColor->AddRef();
  422. lpTempSize = m_lpSizeStm;
  423. lpTempSize->AddRef();
  424. }
  425. ULARGE_INTEGER uli;
  426. uli.LowPart = 0;
  427. uli.HighPart = 0;
  428. lpTempColor->SetSize(uli);
  429. lpTempSize->SetSize(uli);
  430. LARGE_INTEGER li;
  431. li.LowPart = 0;
  432. li.HighPart = 0;
  433. lpTempColor->Seek(li, STREAM_SEEK_SET, NULL);
  434. lpTempSize->Seek(li, STREAM_SEEK_SET, NULL);
  435. // write the colors to the stream
  436. lpTempColor->Write(&m_red, sizeof(m_red), NULL);
  437. lpTempColor->Write(&m_green, sizeof(m_green), NULL);
  438. lpTempColor->Write(&m_blue, sizeof(m_blue), NULL);
  439. // write the size to the stream
  440. lpTempSize->Write(&m_size, sizeof(m_size), NULL);
  441. lpTempColor->Release();
  442. lpTempSize->Release();
  443. }
  444. //**********************************************************************
  445. //
  446. // CSimpSvrObj::LoadFromStorage
  447. //
  448. // Purpose:
  449. //
  450. // Loads the object from the passed storage
  451. //
  452. // Parameters:
  453. //
  454. // LPSTORAGE lpStg - Storage in which to load the object from
  455. //
  456. // Return Value:
  457. //
  458. // None.
  459. //
  460. // Function Calls:
  461. // Function Location
  462. //
  463. // TestDebugOut Windows API
  464. // IStorage::OpenStream OLE
  465. // IStream::Read OLE
  466. // IStream::Release OLE
  467. //
  468. // Comments:
  469. //
  470. //
  471. //********************************************************************
  472. void CSimpSvrObj::LoadFromStorage ()
  473. {
  474. TestDebugOut("In CSimpSvrObj::LoadFromStorage\r\n");
  475. // Read the colors
  476. m_lpColorStm->Read(&m_red, sizeof(m_red), NULL);
  477. m_lpColorStm->Read(&m_green, sizeof(m_green), NULL);
  478. m_lpColorStm->Read(&m_blue, sizeof(m_blue), NULL);
  479. // read the size
  480. m_lpSizeStm->Read(&m_size, sizeof(m_size), NULL);
  481. }
  482. //**********************************************************************
  483. //
  484. // CSimpSvrObj::DoInPlaceActivate
  485. //
  486. // Purpose:
  487. //
  488. // Does the inplace activation for the object
  489. //
  490. // Parameters:
  491. //
  492. // LONG lVerb - Verb that caused this function to be called
  493. //
  494. // Return Value:
  495. //
  496. // TRUE/FALSE depending on success or failure.
  497. //
  498. // Function Calls:
  499. // Function Location
  500. //
  501. // IOleClientSite::QueryInterface Container
  502. // IOleClientSite::ShowObject Container
  503. // IOleInPlaceSite::CanInPlaceActivate Container
  504. // IOleInPlaceSite::Release Container
  505. // IOleInPlaceSite::OnInPlaceActivate Container
  506. // IOleInPlaceSite::GetWindow Container
  507. // IOleInPlaceSite::GetWindowContext Container
  508. // IOleInPlaceSite::OnUIActivate Container
  509. // IOleInPlaceSite::Release Container
  510. // IOleInPlaceFrame::SetActiveObject Container
  511. // IOleInPlaceUIWindow::SetActiveObject Container
  512. // TestDebugOut Windows API
  513. // ShowWindow Windows API
  514. // SetParent Windows API
  515. // IntersectRect Windows API
  516. // OffsetRect Windows API
  517. // MoveWindow Windows API
  518. // CopyRect Windows API
  519. // SetFocus Windows API
  520. // SetHatchWindowSize OLE2UI
  521. // CSimpSvrObj::AssembleMenus OBJ.CPP
  522. // CSimpSvrObj::AddFrameLevelUI OBJ.CPP
  523. //
  524. //
  525. // Comments:
  526. //
  527. // Be sure to read TECHNOTES.WRI included with the OLE SDK
  528. // for details on implementing inplace activation.
  529. //
  530. //********************************************************************
  531. BOOL CSimpSvrObj::DoInPlaceActivate (LONG lVerb)
  532. {
  533. BOOL retval = FALSE;
  534. RECT posRect, clipRect;
  535. TestDebugOut("In CSimpSvrObj::DoInPlaceActivate\r\n");
  536. // if not currently in place active
  537. if (!m_fInPlaceActive)
  538. {
  539. // get the inplace site
  540. if (m_lpOleClientSite->QueryInterface(IID_IOleInPlaceSite,
  541. (LPVOID FAR *)&m_lpIPSite) != NOERROR)
  542. goto error;
  543. // if the inplace site could not be obtained, or refuses to inplace
  544. // activate then goto error.
  545. if (m_lpIPSite == NULL || m_lpIPSite->CanInPlaceActivate() != NOERROR)
  546. {
  547. if (m_lpIPSite)
  548. m_lpIPSite->Release();
  549. m_lpIPSite = NULL;
  550. goto error;
  551. }
  552. // tell the site that we are activating.
  553. m_lpIPSite->OnInPlaceActivate();
  554. m_fInPlaceActive = TRUE;
  555. }
  556. // if not currently inplace visibl
  557. if (!m_fInPlaceVisible)
  558. {
  559. m_fInPlaceVisible = TRUE;
  560. // get the window handle of the site
  561. m_lpIPSite->GetWindow(&m_hWndParent);
  562. // get window context from the container
  563. m_lpIPSite->GetWindowContext ( &m_lpFrame,
  564. &m_lpCntrDoc,
  565. &posRect,
  566. &clipRect,
  567. &m_FrameInfo);
  568. // show the hatch window
  569. m_lpDoc->ShowHatchWnd();
  570. // Set the parenting
  571. SetParent (m_lpDoc->GethHatchWnd(), m_hWndParent);
  572. SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethHatchWnd());
  573. // tell the client site to show the object
  574. m_lpOleClientSite->ShowObject();
  575. RECT resRect;
  576. // figure out the "real" size of the object
  577. IntersectRect(&resRect, &posRect, &clipRect);
  578. CopyRect(&m_posRect, &posRect);
  579. POINT pt;
  580. // adjust our hatch window size
  581. SetHatchWindowSize ( m_lpDoc->GethHatchWnd(),
  582. &resRect,
  583. &posRect,
  584. &pt);
  585. // calculate the actual object rect inside the hatchwnd.
  586. OffsetRect (&resRect, pt.x, pt.y);
  587. // move the object window
  588. MoveWindow(m_lpDoc->GethDocWnd(),
  589. resRect.left,
  590. resRect.top,
  591. resRect.right - resRect.left,
  592. resRect.bottom - resRect.top,
  593. FALSE);
  594. // create the combined window
  595. AssembleMenus();
  596. }
  597. // if not UIActive
  598. if (!m_fUIActive)
  599. {
  600. m_fUIActive = TRUE;
  601. // tell the inplace site that we are activating
  602. m_lpIPSite->OnUIActivate();
  603. // set the focus to our object window
  604. SetFocus(m_lpDoc->GethDocWnd());
  605. // set the active object on the frame
  606. m_lpFrame->SetActiveObject(&m_OleInPlaceActiveObject, "Simple OLE 2.0 Server");
  607. // set the active object on the Doc, if available.
  608. if (m_lpCntrDoc)
  609. m_lpCntrDoc->SetActiveObject(&m_OleInPlaceActiveObject, "Simple OLE 2.0 Server");
  610. // add the frame level UI.
  611. AddFrameLevelUI();
  612. }
  613. retval = TRUE;
  614. error:
  615. return retval;
  616. }
  617. //**********************************************************************
  618. //
  619. // CSimpSvrObj::AssembleMenus
  620. //
  621. // Purpose:
  622. //
  623. // Creates the combined menus used during inplace activation.
  624. //
  625. // Parameters:
  626. //
  627. // None
  628. //
  629. // Return Value:
  630. //
  631. // None
  632. //
  633. // Function Calls:
  634. // Function Location
  635. //
  636. // TestDebugOut Windows API
  637. // CreateMenu Windows API
  638. // IOleInPlaceFrame::InsertMenus Container
  639. // InsertMenu Windows API
  640. // DestroyMenu Windows API
  641. // OleCreateMenuDescriptor OLE API
  642. //
  643. // Comments:
  644. //
  645. //
  646. //********************************************************************
  647. void CSimpSvrObj::AssembleMenus()
  648. {
  649. TestDebugOut("In CSimpSvrObj::AssembleMenus\r\n");
  650. OLEMENUGROUPWIDTHS menugroupwidths;
  651. m_hmenuShared = NULL;
  652. // Create the menu resource
  653. m_hmenuShared = CreateMenu();
  654. // have the contaner insert its menus
  655. if (m_lpFrame->InsertMenus (m_hmenuShared, &menugroupwidths) == NOERROR)
  656. {
  657. int nFirstGroup = (int) menugroupwidths.width[0];
  658. // insert the server menus
  659. InsertMenu( m_hmenuShared, nFirstGroup, MF_BYPOSITION | MF_POPUP, m_lpDoc->GetApp()->GetColorMenu(), "&Color");
  660. menugroupwidths.width[1] = 1;
  661. menugroupwidths.width[3] = 0;
  662. menugroupwidths.width[5] = 0;
  663. }
  664. else
  665. {
  666. // Destroy the menu resource
  667. DestroyMenu(m_hmenuShared);
  668. m_hmenuShared = NULL;
  669. }
  670. // tell OLE to create the menu descriptor
  671. m_hOleMenu = OleCreateMenuDescriptor(m_hmenuShared, &menugroupwidths);
  672. }
  673. //**********************************************************************
  674. //
  675. // CSimpSvrObj::AddFrameLevelUI
  676. //
  677. // Purpose:
  678. //
  679. // Adds the Frame level user interface
  680. //
  681. // Parameters:
  682. //
  683. // None
  684. //
  685. // Return Value:
  686. //
  687. // None
  688. //
  689. // Function Calls:
  690. // Function Location
  691. //
  692. // TestDebugOut Windows API
  693. // IOleInPlaceFrame::SetMenu Container
  694. // IOleInPlaceFrame::SetBorderSpace Container
  695. // IOleInPlaceUIWindow::SetBorderSpace Container
  696. // CSimpSvrDoc::GethDocWnd DOC.H
  697. //
  698. // Comments:
  699. //
  700. //
  701. //********************************************************************
  702. void CSimpSvrObj::AddFrameLevelUI()
  703. {
  704. TestDebugOut("In CSimpSvrObj::AddFrameLevelUI\r\n");
  705. // add the combined menu
  706. m_lpFrame->SetMenu(m_hmenuShared, m_hOleMenu, m_lpDoc->GethDocWnd());
  707. // do hatched border
  708. SetParent (m_lpDoc->GethHatchWnd(), m_hWndParent);
  709. SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethHatchWnd());
  710. // set the border space. Normally we would negotiate for toolbar
  711. // space at this point. Since this server doesn't have a toolbar,
  712. // this isn't needed...
  713. if (m_lpFrame)
  714. m_lpFrame->SetBorderSpace(NULL);
  715. if (m_lpCntrDoc)
  716. m_lpCntrDoc->SetBorderSpace(NULL);
  717. }
  718. //**********************************************************************
  719. //
  720. // CSimpSvrObj::DoInPlaceHide
  721. //
  722. // Purpose:
  723. //
  724. // Hides the object while inplace actvie
  725. //
  726. // Parameters:
  727. //
  728. // None
  729. //
  730. // Return Value:
  731. //
  732. // None
  733. //
  734. // Function Calls:
  735. // Function Location
  736. //
  737. // TestDebugOut Windows API
  738. // SetParent Windows API
  739. // CSimpSvrDoc::GethDocWnd DOC.H
  740. // CSimpSvrDoc::GethAppWnd DOC.H
  741. // CSimpSvrDoc::GethHatchWnd DOC.H
  742. // CSimpSvrObj::DisassembleMenus OBJ.CPP
  743. // IOleInPlaceFrame::Release Container
  744. // IOleInPlaceUIWindow::Release Container
  745. //
  746. //
  747. // Comments:
  748. //
  749. // Be sure to read TECHNOTES.WRI included with the OLE SDK
  750. // for details on implementing inplace activation.
  751. //
  752. //********************************************************************
  753. void CSimpSvrObj::DoInPlaceHide()
  754. {
  755. TestDebugOut("In CSimpSvrObj::DoInPlaceHide\r\n");
  756. // if we aren't inplace visible, then this routine is a NOP,
  757. if (!m_fInPlaceVisible)
  758. return;
  759. m_fInPlaceVisible = FALSE;
  760. // change the parenting
  761. SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethAppWnd());
  762. SetParent (m_lpDoc->GethHatchWnd(),m_lpDoc->GethDocWnd());
  763. // rip down the combined menus
  764. DisassembleMenus();
  765. // release the inplace frame
  766. m_lpFrame->Release();
  767. m_lpFrame = NULL; // only holding one ref. to frame.
  768. // release the UIWindow if it is there.
  769. if (m_lpCntrDoc)
  770. m_lpCntrDoc->Release();
  771. m_lpCntrDoc = NULL;
  772. }
  773. //**********************************************************************
  774. //
  775. // CSimpSvrObj::DisassembleMenus
  776. //
  777. // Purpose:
  778. //
  779. // Disassembles the combined menus used in inplace activation
  780. //
  781. // Parameters:
  782. //
  783. // None
  784. //
  785. // Return Value:
  786. //
  787. // None
  788. //
  789. // Function Calls:
  790. // Function Location
  791. //
  792. // TestDebugOut Windows API
  793. // OleDestroyMenuDescriptor OLE API
  794. // RemoveMenu Windows API
  795. // IOleInPlaceFrame::RemoveMenus Container
  796. // DestroyMenu Windows API
  797. //
  798. // Comments:
  799. //
  800. // Be sure to read TECHNOTES.WRI included with the OLE SDK
  801. // for details on implementing inplace activation.
  802. //
  803. //********************************************************************
  804. void CSimpSvrObj::DisassembleMenus()
  805. {
  806. // destroy the menu descriptor
  807. OleDestroyMenuDescriptor(m_hOleMenu);
  808. if (m_hmenuShared)
  809. {
  810. // remove the menus that we added
  811. RemoveMenu( m_hmenuShared, 1, MF_BYPOSITION);
  812. // have the container remove its menus
  813. m_lpFrame->RemoveMenus(m_hmenuShared);
  814. // Destroy the menu resource
  815. DestroyMenu(m_hmenuShared);
  816. m_hmenuShared = NULL;
  817. }
  818. }
  819. //**********************************************************************
  820. //
  821. // CSimpSvrObj::SendOnDataChange
  822. //
  823. // Purpose:
  824. //
  825. // Uses the data advise holder to send a data change, then updates
  826. // the ROT to note the time of change.
  827. //
  828. // Parameters:
  829. //
  830. // None
  831. //
  832. // Return Value:
  833. //
  834. // None
  835. //
  836. // Function Calls:
  837. // Function Location
  838. //
  839. // IDataAdviseHolder::SendOnDataChange OLE API
  840. // GetRunningObjectTable OLE API
  841. // CoFileTimeNow OLE API
  842. // IRunningObjectTable::NoteChangeTime OLE API
  843. //
  844. // Comments:
  845. //
  846. //
  847. //********************************************************************
  848. void CSimpSvrObj::SendOnDataChange()
  849. {
  850. if (m_lpDataAdviseHolder)
  851. m_lpDataAdviseHolder->SendOnDataChange( (LPDATAOBJECT)&m_DataObject, 0, 0);
  852. LPRUNNINGOBJECTTABLE lpRot;
  853. GetRunningObjectTable(0, &lpRot);
  854. if ( lpRot && m_dwRegister)
  855. {
  856. FILETIME ft;
  857. CoFileTimeNow(&ft);
  858. lpRot->NoteChangeTime(m_dwRegister, &ft);
  859. lpRot->Release();
  860. }
  861. }
  862. //**********************************************************************
  863. //
  864. // CSimpSvrObj::DeactivateUI
  865. //
  866. // Purpose:
  867. //
  868. // Breaks down the inplace ui
  869. //
  870. // Parameters:
  871. //
  872. // None
  873. //
  874. // Return Value:
  875. //
  876. // None
  877. //
  878. // Function Calls:
  879. // Function Location
  880. //
  881. // SetParent Windows API
  882. // IOleInPlaceUIWindow::SetActiveObject Container
  883. // IOleInPlaceFrame::SetActiveObject Container
  884. // IOleInPlaceSite::UIDeactivate Container
  885. //
  886. // Comments:
  887. //
  888. //
  889. //********************************************************************
  890. void CSimpSvrObj::DeactivateUI()
  891. {
  892. // if not UI active, or no pointer to IOleInPlaceFrame, then
  893. // return NOERROR
  894. if (!(m_fUIActive || m_lpFrame))
  895. return;
  896. else
  897. {
  898. m_fUIActive = FALSE;
  899. // remove hatching
  900. SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethAppWnd());
  901. SetParent (m_lpDoc->GethHatchWnd(),m_lpDoc->GethDocWnd());
  902. // if in an MDI container, call SetActiveObject on the DOC.
  903. if (m_lpCntrDoc)
  904. m_lpCntrDoc->SetActiveObject(NULL, NULL);
  905. m_lpFrame->SetActiveObject(NULL, NULL);
  906. // tell the container that our UI is going away.
  907. if (m_lpIPSite)
  908. m_lpIPSite->OnUIDeactivate(FALSE);
  909. }
  910. }
  911.