Leaked source code of windows server 2003
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.

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