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.

688 lines
16 KiB

  1. //**********************************************************************
  2. // File name: DOC.CPP
  3. //
  4. // Implementation file for CSimpSvrDoc.
  5. //
  6. // Functions:
  7. //
  8. // See DOC.H for Class Definition
  9. //
  10. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "obj.h"
  14. #include "app.h"
  15. #include "doc.h"
  16. //**********************************************************************
  17. //
  18. // CSimpSvrDoc::Create
  19. //
  20. // Purpose:
  21. //
  22. // Creation for the CSimpSvrDoc Class
  23. //
  24. // Parameters:
  25. //
  26. // CSimpSvrApp FAR * lpApp - Pointer to the CSimpSvrApp Class
  27. //
  28. // LPRECT lpRect - Client area rect of "frame" window
  29. //
  30. // HWND hWnd - Window Handle of "frame" window
  31. //
  32. // Return Value:
  33. //
  34. // None
  35. //
  36. // Function Calls:
  37. // Function Location
  38. //
  39. // StgCreateDocfile OLE API
  40. // CreateWindow Windows API
  41. // ShowWindow Windows API
  42. // UpdateWindow Windows API
  43. // CSimpSvrDoc::CSimpSvrDoc DOC.CPP
  44. // CreateHatchWindow OLE2UI
  45. //
  46. // Comments:
  47. //
  48. // This routine was added so that failure could be returned
  49. // from object creation.
  50. //
  51. //********************************************************************
  52. CSimpSvrDoc FAR * CSimpSvrDoc::Create(CSimpSvrApp FAR *lpApp, LPRECT lpRect,HWND hWnd)
  53. {
  54. CSimpSvrDoc FAR * lpTemp = new CSimpSvrDoc(lpApp, hWnd);
  55. if (!lpTemp)
  56. return NULL;
  57. // create the document Window
  58. lpTemp->m_hDocWnd = CreateWindow(
  59. TEXT("DocWClass"),
  60. NULL,
  61. WS_CHILD | WS_CLIPSIBLINGS,
  62. lpRect->left,
  63. lpRect->top,
  64. lpRect->right,
  65. lpRect->bottom,
  66. hWnd,
  67. NULL,
  68. lpApp->GethInst(),
  69. NULL);
  70. if (!lpTemp->m_hDocWnd)
  71. goto error;
  72. lpTemp->ShowDocWnd();
  73. lpTemp->m_hHatchWnd = CreateHatchWindow( lpTemp->m_hDocWnd, lpApp->GethInst());
  74. lpTemp->HideHatchWnd();
  75. return (lpTemp);
  76. error:
  77. delete (lpTemp);
  78. return NULL;
  79. }
  80. //**********************************************************************
  81. //
  82. // CSimpSvrDoc::CSimpSvrDoc
  83. //
  84. // Purpose:
  85. //
  86. // Constructor for the CSimpSvrDoc Class
  87. //
  88. // Parameters:
  89. //
  90. // CSimpSvrApp FAR * lpApp - Pointer to the CSimpSvrApp Class
  91. //
  92. // HWND hWnd - Window Handle of "frame" window
  93. //
  94. // Return Value:
  95. //
  96. // None
  97. //
  98. // Function Calls:
  99. // Function Location
  100. //
  101. // TestDebugOut Windows API
  102. // GetMenu Windows API
  103. // GetSubMenu Windows API
  104. //
  105. // Comments:
  106. //
  107. //********************************************************************
  108. CSimpSvrDoc::CSimpSvrDoc(CSimpSvrApp FAR * lpApp,HWND hWnd)
  109. {
  110. TestDebugOut(TEXT("In CSimpSvrDoc's Constructor\r\n"));
  111. m_lpApp = lpApp;
  112. m_nCount = 0;
  113. m_lpObj = NULL;
  114. // set up menu handles
  115. m_hMainMenu = GetMenu(hWnd);
  116. m_hColorMenu = GetSubMenu(m_hMainMenu, 1);
  117. m_hHelpMenu = GetSubMenu(m_hMainMenu, 2);
  118. }
  119. //**********************************************************************
  120. //
  121. // CSimpSvrDoc::~CSimpSvrDoc
  122. //
  123. // Purpose:
  124. //
  125. // Destructor for CSimpSvrDoc
  126. //
  127. // Parameters:
  128. //
  129. // None
  130. //
  131. // Return Value:
  132. //
  133. // None
  134. //
  135. // Function Calls:
  136. // Function Location
  137. //
  138. // TestDebugOut Windows API
  139. // DestroyWindow Windows API
  140. // CSimpSvrApp::ClearDoc APP.CPP
  141. //
  142. // Comments:
  143. //
  144. //********************************************************************
  145. CSimpSvrDoc::~CSimpSvrDoc()
  146. {
  147. TestDebugOut(TEXT("In CSimpSvrDoc's Destructor\r\n"));
  148. // Clear the Doc object pointer so that the SimpSvrApp won't be able
  149. // to access invalid objects. (same for the SimpSvrObj)
  150. if (m_lpApp)
  151. m_lpApp->ClearDoc();
  152. if (m_lpObj)
  153. m_lpObj->ClearDoc();
  154. DestroyWindow(m_hHatchWnd);
  155. DestroyWindow(m_hDocWnd);
  156. }
  157. //**********************************************************************
  158. //
  159. // CSimpSvrDoc::QueryInterface
  160. //
  161. // Purpose:
  162. //
  163. // Return a pointer to a requested interface
  164. //
  165. // Parameters:
  166. //
  167. // REFIID riid - ID of interface to be returned
  168. // LPVOID FAR* ppvObj - Location to return the interface
  169. //
  170. // Return Value:
  171. //
  172. // E_NOINTERFACE - Always
  173. //
  174. // Function Calls:
  175. // Function Location
  176. //
  177. // TestDebugOut Windows API
  178. // CSimpSvrApp::QueryInterface APP.CPP
  179. //
  180. // Comments:
  181. //
  182. // Since the document could contain multiple objects, all
  183. // interfaces except those associated with the document should
  184. // be returned. In this implementation, there are no doc level
  185. // interfaces.
  186. //
  187. //********************************************************************
  188. STDMETHODIMP CSimpSvrDoc::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  189. {
  190. TestDebugOut(TEXT("In CSimpSvrDoc::QueryInterface\r\n"));
  191. SCODE sc = E_NOINTERFACE;
  192. if (IsEqualIID(riid, IID_IUnknown))
  193. {
  194. AddRef();
  195. *ppvObj = this;
  196. sc = S_OK;
  197. }
  198. return ResultFromScode(sc);
  199. }
  200. //**********************************************************************
  201. //
  202. // CSimpSvrDoc::AddRef
  203. //
  204. // Purpose:
  205. //
  206. // Increments the document level reference count
  207. //
  208. // Parameters:
  209. //
  210. // None
  211. //
  212. // Return Value:
  213. //
  214. // UINT - The current reference count on the document
  215. //
  216. // Function Calls:
  217. // Function Location
  218. //
  219. // TestDebugOut Windows API
  220. // CSimpSvrApp::AddRef APP.CPP
  221. //
  222. // Comments:
  223. //
  224. // The reference count at this level reflects the total ref.
  225. // count of all interfaces on all objects contained within
  226. // this document. Note that it also "trickles up" the
  227. // ref count to the app level.
  228. //
  229. //********************************************************************
  230. STDMETHODIMP_(ULONG) CSimpSvrDoc::AddRef()
  231. {
  232. TestDebugOut(TEXT("In CSimpSvrDoc::AddRef\r\n"));
  233. // AddRef the app, but return the doc count
  234. m_lpApp->AddRef();
  235. return ++m_nCount;
  236. }
  237. //**********************************************************************
  238. //
  239. // CSimpSvrDoc::Release
  240. //
  241. // Purpose:
  242. //
  243. // Decrements the document level reference count
  244. //
  245. // Parameters:
  246. //
  247. // None
  248. //
  249. // Return Value:
  250. //
  251. // UINT - The current reference count on the document
  252. //
  253. // Function Calls:
  254. // Function Location
  255. //
  256. // TestDebugOut Windows API
  257. // CSimpSvrApp::Release APP.CPP
  258. //
  259. // Comments:
  260. //
  261. // The reference count at this level reflects the total ref.
  262. // count of all interfaces on all objects contained within
  263. // this document. Note that it also "trickles up" the
  264. // ref count to the app level.
  265. //
  266. //********************************************************************
  267. STDMETHODIMP_(ULONG) CSimpSvrDoc::Release()
  268. {
  269. TestDebugOut(TEXT("In CSimpSvrDoc::Release\r\n"));
  270. // Release the app, but return the app count
  271. m_lpApp->Release();
  272. if (--m_nCount== 0)
  273. {
  274. delete this;
  275. return(0);
  276. }
  277. return m_nCount;
  278. }
  279. //**********************************************************************
  280. //
  281. // CSimpSvrDoc::lResizeDoc
  282. //
  283. // Purpose:
  284. //
  285. // Resizes the document
  286. //
  287. // Parameters:
  288. //
  289. // LPRECT lpRect - The size of the client are of the "frame"
  290. // Window.
  291. //
  292. // Return Value:
  293. //
  294. // NULL
  295. //
  296. // Function Calls:
  297. // Function Location
  298. //
  299. // MoveWindow Windows API
  300. //
  301. //
  302. //********************************************************************
  303. long CSimpSvrDoc::lResizeDoc(LPRECT lpRect)
  304. {
  305. MoveWindow(m_hDocWnd, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, TRUE);
  306. return NULL;
  307. }
  308. //**********************************************************************
  309. //
  310. // CSimpSvrDoc::PaintDoc
  311. //
  312. // Purpose:
  313. //
  314. // Paints the Document
  315. //
  316. // Parameters:
  317. //
  318. // HDC hDC - hDC of the document Window
  319. //
  320. // Return Value:
  321. //
  322. // None
  323. //
  324. // Function Calls:
  325. // Function Location
  326. //
  327. // CSimpSvrObj::Draw OBJ.CPP
  328. // CSimpSvrObj::GetDataAdviseHolder OBJ.H
  329. // CSimpSvrObj::GetDataObject OBJ.H
  330. // CSimpAppObj::IsStartedByOle APP.CPP
  331. // IDataAdviseHolder::SendOnDataChange OLE API
  332. //
  333. //
  334. //********************************************************************
  335. void CSimpSvrDoc::PaintDoc (HDC hDC)
  336. {
  337. // if the object hasn't been created yet, then don't draw
  338. if (m_lpObj)
  339. m_lpObj->Draw(hDC,FALSE);
  340. else
  341. return;
  342. // Sending a data change every time we paint, but only if we
  343. // were started by OLE
  344. if (m_lpApp->IsStartedByOle())
  345. m_lpObj->SendOnDataChange( );
  346. }
  347. //**********************************************************************
  348. //
  349. // CSimpSvrDoc::CreateObject
  350. //
  351. // Purpose:
  352. // Handles the creation of a SimpSvrObj.
  353. //
  354. // Parameters:
  355. //
  356. //
  357. // Return Value:
  358. //
  359. // S_OK if the function succeeds, otherwise E_FAIL
  360. //
  361. // Function Calls:
  362. // Function Location
  363. //
  364. // CSimpSvrObj::CSimpSvrObj OBJ.CPP
  365. // CSimpSvrOjb::QueryInterface OBJ.CPP
  366. //
  367. //
  368. //********************************************************************
  369. HRESULT CSimpSvrDoc::CreateObject(REFIID riid, LPVOID FAR *ppvObject)
  370. {
  371. SCODE sc = E_FAIL;
  372. m_lpObj = new CSimpSvrObj(this);
  373. if (m_lpObj)
  374. {
  375. m_lpObj->QueryInterface(riid, ppvObject);
  376. sc = S_OK;
  377. }
  378. return ResultFromScode(sc);
  379. }
  380. //**********************************************************************
  381. //
  382. // CSimpSvrDoc::Close
  383. //
  384. // Purpose:
  385. //
  386. // Closes the object
  387. //
  388. // Parameters:
  389. //
  390. // None
  391. //
  392. // Return Value:
  393. //
  394. // None
  395. //
  396. // Function Calls:
  397. // Function Location
  398. //
  399. // TestDebugOut Windows API
  400. // CSimpSvrObj::AddRef OBJ.CPP
  401. // CSimpSvrObj::Release OBJ.CPP
  402. // CSimpSvrObj::IsInPlaceActive OBJ.H
  403. // CSimpSvrObj::GetOleInPlaceObject OBJ.H
  404. // CSimpSvrObj::ClearOleClientSite OBJ.H
  405. // CSimpSvrObj::GetDataAdviseHolder OBJ.H
  406. // CSimpSvrObj::GetOleClientSite OBJ.H
  407. // CSimpSvrObj::ClearDataAdviseHolder OBJ.H
  408. // CSimpSvrObj::GetOleAdviseHolder OBJ.H
  409. // CSimpSvrObj::ClearOleAdviseHolder OBJ.H
  410. // IOleInPlaceObject::InPlaceDeactivate Container
  411. // IOleClientSite::SaveObject Container
  412. // IOleClientSite::OnShowWindow Container
  413. // IOleClientSite::Release Container
  414. // IDataAdviseHolder::SendOnDataChange OLE
  415. // IDataAdviseHolder::Release OLE
  416. // IOleAdviseHolder::SendOnClose OLE
  417. // IOleAdviseHolder::Release OLE
  418. //
  419. //
  420. //********************************************************************
  421. void CSimpSvrDoc::Close()
  422. {
  423. TestDebugOut(TEXT("In CSimpSvrDoc::Close() \r\n"));
  424. m_lpObj->AddRef(); // hold object alive
  425. // if the object is currently inplace active, then deactivate
  426. if (m_lpObj->IsInPlaceActive())
  427. m_lpObj->GetOleInPlaceObject()->InPlaceDeactivate();
  428. // unregister from the ROT...
  429. if (m_lpObj->GetRotRegister())
  430. {
  431. LPRUNNINGOBJECTTABLE lpRot;
  432. if (GetRunningObjectTable (0, &lpRot) == NOERROR )
  433. {
  434. lpRot->Revoke(m_lpObj->GetRotRegister());
  435. lpRot->Release();
  436. }
  437. }
  438. // if we have a clientsite, instruct it to save the object
  439. if (m_lpObj->GetOleClientSite())
  440. {
  441. m_lpObj->GetOleClientSite()->SaveObject();
  442. m_lpObj->GetOleClientSite()->OnShowWindow(FALSE);
  443. }
  444. // Do a final SendOnDataChange for those containers that have specified the
  445. // ADF_DATAONSTOP flag.
  446. if (m_lpObj->GetDataAdviseHolder())
  447. {
  448. m_lpObj->GetDataAdviseHolder()->SendOnDataChange( m_lpObj->GetDataObject(), 0, ADVF_DATAONSTOP);
  449. }
  450. // Tell the container that we are shutting down.
  451. if (m_lpObj->GetOleAdviseHolder())
  452. {
  453. m_lpObj->GetOleAdviseHolder()->SendOnClose();
  454. }
  455. // release our streams and storage
  456. m_lpObj->GetPersistStorage()->ReleaseStreamsAndStorage();
  457. // Disconnect the object. NOTE: This call should not do anything
  458. // unless the container has cause a GP Fault or some other problem
  459. // has occured...
  460. TestDebugOut(TEXT("*** Before CoDisconnectObject *** \r\n"));
  461. CoDisconnectObject((LPUNKNOWN)m_lpObj, 0);
  462. TestDebugOut(TEXT("*** After CoDisconnectObject *** \r\n"));
  463. m_lpObj->Release(); // let object close
  464. }
  465. //**********************************************************************
  466. //
  467. // CSimpSvrDoc::SetStatusText
  468. //
  469. // Purpose:
  470. //
  471. // Sets the Container's status bar text
  472. //
  473. // Parameters:
  474. //
  475. // None
  476. //
  477. // Return Value:
  478. //
  479. // None
  480. //
  481. // Function Calls:
  482. // Function Location
  483. //
  484. // CSimpSvrObj::IsInPlaceActive OBJ.CPP
  485. // IOleInPlaceFrame::SetStatusText Container
  486. //
  487. // Comments:
  488. //
  489. // Even though there is no status line in this sample, this
  490. // method must be called on WM_MENUSELECT to clear the last
  491. // message in the status line.
  492. //
  493. //********************************************************************
  494. void CSimpSvrDoc::SetStatusText()
  495. {
  496. if (m_lpObj->IsInPlaceActive())
  497. m_lpObj->GetInPlaceFrame()->SetStatusText(OLESTR("\0"));
  498. }
  499. //**********************************************************************
  500. //
  501. // CSimpSvrDoc::ShowDocWnd
  502. //
  503. // Purpose:
  504. //
  505. // Shows the Document Window
  506. //
  507. // Parameters:
  508. //
  509. // None
  510. //
  511. // Return Value:
  512. //
  513. // None
  514. //
  515. // Function Calls:
  516. // Function Location
  517. //
  518. // ShowWindow Windows API
  519. // UpdateWindow Windows API
  520. //
  521. // Comments:
  522. //
  523. //********************************************************************
  524. void CSimpSvrDoc::ShowDocWnd()
  525. {
  526. ShowWindow(m_hDocWnd, SW_SHOWNORMAL); // Show the window
  527. UpdateWindow(m_hDocWnd); // Sends WM_PAINT message
  528. }
  529. //**********************************************************************
  530. //
  531. // CSimpSvrDoc::ShowHatchWnd
  532. //
  533. // Purpose:
  534. //
  535. // Shows the hatch Window
  536. //
  537. // Parameters:
  538. //
  539. // None
  540. //
  541. // Return Value:
  542. //
  543. // None
  544. //
  545. // Function Calls:
  546. // Function Location
  547. //
  548. // ShowWindow Windows API
  549. //
  550. // Comments:
  551. //
  552. //********************************************************************
  553. void CSimpSvrDoc::ShowHatchWnd()
  554. {
  555. ShowWindow(m_hHatchWnd, SW_SHOW);
  556. }
  557. //**********************************************************************
  558. //
  559. // CSimpSvrDoc::HideDocWnd
  560. //
  561. // Purpose:
  562. //
  563. // Hides the DocumentWindow
  564. //
  565. // Parameters:
  566. //
  567. // None
  568. //
  569. // Return Value:
  570. //
  571. // None
  572. //
  573. // Function Calls:
  574. // Function Location
  575. //
  576. // ShowWindow Windows API
  577. //
  578. // Comments:
  579. //
  580. //********************************************************************
  581. void CSimpSvrDoc::HideDocWnd()
  582. {
  583. ShowWindow(m_hDocWnd, SW_HIDE);
  584. }
  585. //**********************************************************************
  586. //
  587. // CSimpSvrDoc::HideHatchWnd
  588. //
  589. // Purpose:
  590. //
  591. // Hides the Hatch Window
  592. //
  593. // Parameters:
  594. //
  595. // None
  596. //
  597. // Return Value:
  598. //
  599. // None
  600. //
  601. // Function Calls:
  602. // Function Location
  603. //
  604. // ShowWindow Windows API
  605. //
  606. // Comments:
  607. //
  608. //********************************************************************
  609. void CSimpSvrDoc::HideHatchWnd()
  610. {
  611. ShowWindow(m_hHatchWnd, SW_HIDE);
  612. }