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.

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