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.

508 lines
12 KiB

  1. //**********************************************************************
  2. // File name: HLP_DOC.CXX
  3. //
  4. // Implementation file for CSimpleDoc.
  5. //
  6. // Functions:
  7. //
  8. // See DOC.H for Class Definition
  9. //
  10. // Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include <headers.cxx>
  13. #pragma hdrstop
  14. #include "hlp_iocs.hxx"
  15. #include "hlp_ias.hxx"
  16. #include "hlp_app.hxx"
  17. #include "hlp_site.hxx"
  18. #include "hlp_doc.hxx"
  19. //**********************************************************************
  20. //
  21. // CSimpleDoc::Create
  22. //
  23. // Purpose:
  24. //
  25. // Creation for the CSimpleDoc Class
  26. //
  27. // Parameters:
  28. //
  29. // CSimpleApp FAR * lpApp - Pointer to the CSimpleApp Class
  30. //
  31. // LPRECT lpRect - Client area rect of "frame" window
  32. //
  33. // HWND hWnd - Window Handle of "frame" window
  34. //
  35. // Return Value:
  36. //
  37. // None
  38. //
  39. // Function Calls:
  40. // Function Location
  41. //
  42. // StgCreateDocfile OLE API
  43. // CreateWindow Windows API
  44. // ShowWindow Windows API
  45. // UpdateWindow Windows API
  46. //
  47. // Comments:
  48. //
  49. // This routine was added so that failure could be returned
  50. // from object creation.
  51. //
  52. //********************************************************************
  53. CSimpleDoc FAR * CSimpleDoc::Create()
  54. {
  55. CSimpleDoc FAR * lpTemp = new CSimpleDoc();
  56. if (!lpTemp)
  57. return NULL;
  58. // create storage for the doc.
  59. HRESULT hErr = StgCreateDocfile (NULL, STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE,
  60. 0, &lpTemp->m_lpStorage);
  61. if (hErr != NOERROR)
  62. goto error;
  63. // we will add one ref count on our document. later in CSimpleDoc::Close
  64. // we will release this ref count. when the document's ref count goes
  65. // to 0, the document will be deleted.
  66. lpTemp->AddRef();
  67. return (lpTemp);
  68. error:
  69. delete (lpTemp);
  70. return NULL;
  71. }
  72. //**********************************************************************
  73. //
  74. // CSimpleDoc::Close
  75. //
  76. // Purpose:
  77. //
  78. // Close CSimpleDoc object.
  79. // when the document's reference count goes to 0, the document
  80. // will be destroyed.
  81. //
  82. // Parameters:
  83. //
  84. //
  85. // Return Value:
  86. //
  87. // None
  88. //
  89. // Function Calls:
  90. // Function Location
  91. //
  92. // RevokeDragDrop OLE API
  93. // CoLockObjectExternal OLE API
  94. // OleFlushClipboard OLE API
  95. // ShowWindow Windows API
  96. //
  97. // Comments:
  98. //
  99. //********************************************************************
  100. void CSimpleDoc::Close(void)
  101. {
  102. DEBUGOUT(L"In CSimpleDoc::Close\r\n");
  103. ShowWindow(m_hDocWnd, SW_HIDE); // Hide the window
  104. // Close the OLE object in our document
  105. if (m_lpSite)
  106. m_lpSite->CloseOleObject();
  107. // Release the ref count added in CSimpleDoc::Create. this will make
  108. // the document's ref count go to 0, and the document will be deleted.
  109. Release();
  110. }
  111. //**********************************************************************
  112. //
  113. // CSimpleDoc::CSimpleDoc
  114. //
  115. // Purpose:
  116. //
  117. // Constructor for the CSimpleDoc Class
  118. //
  119. // Parameters:
  120. //
  121. // CSimpleApp FAR * lpApp - Pointer to the CSimpleApp Class
  122. //
  123. // HWND hWnd - Window Handle of "frame" window
  124. //
  125. // Return Value:
  126. //
  127. // None
  128. //
  129. // Function Calls:
  130. // Function Location
  131. //
  132. // GetMenu Windows API
  133. // GetSubMenu Windows API
  134. //
  135. // Comments:
  136. //
  137. //********************************************************************
  138. CSimpleDoc::CSimpleDoc()
  139. {
  140. }
  141. //**********************************************************************
  142. //
  143. // CSimpleDoc::~CSimpleDoc
  144. //
  145. // Purpose:
  146. //
  147. // Destructor for CSimpleDoc
  148. //
  149. // Parameters:
  150. //
  151. // None
  152. //
  153. // Return Value:
  154. //
  155. // None
  156. //
  157. // Function Calls:
  158. // Function Location
  159. //
  160. // CSimpleSite::Release SITE.CPP
  161. // IStorage::Release OLE API
  162. //
  163. // Comments:
  164. //
  165. //********************************************************************
  166. CSimpleDoc::~CSimpleDoc()
  167. {
  168. DEBUGOUT(L"In CSimpleDoc's Destructor\r\n");
  169. // Release all pointers we hold to the OLE object. also release
  170. // the ref count added in CSimpleSite::Create. this will make
  171. // the Site's ref count go to 0, and the Site will be deleted.
  172. if (m_lpSite) {
  173. m_lpSite->UnloadOleObject();
  174. m_lpSite->Release();
  175. m_lpSite = NULL;
  176. }
  177. // Release the Storage
  178. if (m_lpStorage) {
  179. m_lpStorage->Release();
  180. m_lpStorage = NULL;
  181. }
  182. // if the edit menu was modified, remove the menu item and
  183. // destroy the popup if it exists
  184. if (m_fModifiedMenu)
  185. {
  186. int nCount = GetMenuItemCount(m_lpApp->m_hEditMenu);
  187. RemoveMenu(m_lpApp->m_hEditMenu, nCount-1, MF_BYPOSITION);
  188. if (m_lpApp->m_hCascadeMenu)
  189. DestroyMenu(m_lpApp->m_hCascadeMenu);
  190. }
  191. DestroyWindow(m_hDocWnd);
  192. }
  193. //**********************************************************************
  194. //
  195. // CSimpleDoc::QueryInterface
  196. //
  197. // Purpose:
  198. //
  199. // Return a pointer to a requested interface
  200. //
  201. // Parameters:
  202. //
  203. // REFIID riid - ID of interface to be returned
  204. // LPVOID FAR* ppvObj - Location to return the interface
  205. //
  206. // Return Value:
  207. //
  208. // S_FALSE - Always
  209. //
  210. // Function Calls:
  211. // Function Location
  212. //
  213. // ResultFromScode OLE API
  214. //
  215. // Comments:
  216. //
  217. // In this implementation, there are no doc level interfaces.
  218. // In an MDI application, there would be an IOleInPlaceUIWindow
  219. // associated with the document to provide document level tool
  220. // space negotiation.
  221. //
  222. //********************************************************************
  223. STDMETHODIMP CSimpleDoc::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  224. {
  225. DEBUGOUT(L"In CSimpleDoc::QueryInterface\r\n");
  226. *ppvObj = NULL; // must set out pointer parameters to NULL
  227. // Not a supported interface
  228. return ResultFromScode(E_NOINTERFACE);
  229. }
  230. //**********************************************************************
  231. //
  232. // CSimpleDoc::AddRef
  233. //
  234. // Purpose:
  235. //
  236. // Increments the document reference count
  237. //
  238. // Parameters:
  239. //
  240. // None
  241. //
  242. // Return Value:
  243. //
  244. // UINT - The current reference count on the document
  245. //
  246. // Function Calls:
  247. // Function Location
  248. //
  249. // CSimpleApp::AddRef APP.CPP
  250. //
  251. // Comments:
  252. //
  253. //********************************************************************
  254. STDMETHODIMP_(ULONG) CSimpleDoc::AddRef()
  255. {
  256. DEBUGOUT(L"In CSimpleDoc::AddRef\r\n");
  257. return ++m_nCount;
  258. }
  259. //**********************************************************************
  260. //
  261. // CSimpleDoc::Release
  262. //
  263. // Purpose:
  264. //
  265. // Decrements the document reference count
  266. //
  267. // Parameters:
  268. //
  269. // None
  270. //
  271. // Return Value:
  272. //
  273. // UINT - The current reference count on the document
  274. //
  275. // Function Calls:
  276. // Function Location
  277. //
  278. //
  279. // Comments:
  280. //
  281. //********************************************************************
  282. STDMETHODIMP_(ULONG) CSimpleDoc::Release()
  283. {
  284. DEBUGOUT(L"In CSimpleDoc::Release\r\n");
  285. if (--m_nCount == 0) {
  286. delete this;
  287. return 0;
  288. }
  289. return m_nCount;
  290. }
  291. //**********************************************************************
  292. //
  293. // CSimpleDoc::InsertObject
  294. //
  295. // Purpose:
  296. //
  297. // Inserts a new object to this document
  298. //
  299. // Parameters:
  300. //
  301. // None
  302. //
  303. // Return Value:
  304. //
  305. // None
  306. //
  307. // Function Calls:
  308. // Function Location
  309. //
  310. // CSimpleSite::CSimpleSite SITE.CPP
  311. // CSimpleSite::InitObject SITE.CPP
  312. // memset C Runtime
  313. // OleUIInsertObject OUTLUI function
  314. // CSimpleDoc::DisableInsertObject DOC.CPP
  315. //
  316. // Comments:
  317. //
  318. // This implementation only allows one object to be inserted
  319. // into a document. Once the object has been inserted, then
  320. // the Insert Object menu choice is greyed out, to prevent
  321. // the user from inserting another.
  322. //
  323. //********************************************************************
  324. void CSimpleDoc::InsertObject()
  325. {
  326. #if 0
  327. m_lpSite = CSimpleSite::Create(this);
  328. iret = OleUIInsertObject(&io);
  329. if (iret == OLEUI_OK)
  330. {
  331. m_lpSite->InitObject((BOOL)(io.dwFlags & IOF_SELECTCREATENEW));
  332. // disable Insert Object menu item
  333. DisableInsertObject();
  334. }
  335. else
  336. {
  337. m_lpSite->Release();
  338. m_lpSite = NULL;
  339. m_lpStorage->Revert();
  340. }
  341. #endif
  342. }
  343. //**********************************************************************
  344. //
  345. // CSimpleDoc::lResizeDoc
  346. //
  347. // Purpose:
  348. //
  349. // Resizes the document
  350. //
  351. // Parameters:
  352. //
  353. // LPRECT lpRect - The size of the client are of the "frame"
  354. // Window.
  355. //
  356. // Return Value:
  357. //
  358. // NULL
  359. //
  360. // Function Calls:
  361. // Function Location
  362. //
  363. // IOleInPlaceActiveObject::ResizeBorder Object
  364. // MoveWindow Windows API
  365. //
  366. // Comments:
  367. //
  368. //********************************************************************
  369. long CSimpleDoc::lResizeDoc(LPRECT lpRect)
  370. {
  371. // if we are InPlace, then call ResizeBorder on the object, otherwise
  372. // just move the document window.
  373. //if (m_fInPlaceActive)
  374. //m_lpActiveObject->ResizeBorder(lpRect, &m_lpApp->m_OleInPlaceFrame, TRUE);
  375. //else
  376. MoveWindow(m_hDocWnd, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, TRUE);
  377. return NULL;
  378. }
  379. //**********************************************************************
  380. //
  381. // CSimpleDoc::lAddVerbs
  382. //
  383. // Purpose:
  384. //
  385. // Adds the objects verbs to the edit menu.
  386. //
  387. // Parameters:
  388. //
  389. // None
  390. //
  391. // Return Value:
  392. //
  393. // NULL
  394. //
  395. // Function Calls:
  396. // Function Location
  397. //
  398. // GetMenuItemCount Windows API
  399. // OleUIAddVerbMenu OUTLUI function
  400. //
  401. // Comments:
  402. //
  403. //********************************************************************
  404. long CSimpleDoc::lAddVerbs(void)
  405. {
  406. #if 0
  407. // m_fModifiedMenu is TRUE if the menu has already been modified
  408. // once. Since we only support one obect every time the application
  409. // is run, then once the menu is modified, it doesn't have
  410. // to be done again.
  411. if (m_lpSite && !m_fInPlaceActive && !m_fModifiedMenu)
  412. {
  413. int nCount = GetMenuItemCount(m_lpApp->m_hEditMenu);
  414. OleUIAddVerbMenu ( m_lpSite->m_lpOleObject,
  415. NULL,
  416. m_lpApp->m_hEditMenu,
  417. nCount + 1,
  418. IDM_VERB0,
  419. 0, // no maximum verb IDM enforced
  420. FALSE,
  421. 0,
  422. &m_lpApp->m_hCascadeMenu);
  423. m_fModifiedMenu = TRUE;
  424. }
  425. #endif
  426. return (NULL);
  427. }
  428. //**********************************************************************
  429. //
  430. // CSimpleDoc::PaintDoc
  431. //
  432. // Purpose:
  433. //
  434. // Paints the Document
  435. //
  436. // Parameters:
  437. //
  438. // HDC hDC - hDC of the document Window
  439. //
  440. // Return Value:
  441. //
  442. // None
  443. //
  444. // Function Calls:
  445. // Function Location
  446. //
  447. // CSimpleSite::PaintObj SITE.CPP
  448. //
  449. // Comments:
  450. //
  451. //********************************************************************
  452. void CSimpleDoc::PaintDoc (HDC hDC)
  453. {
  454. // if we supported multiple objects, then we would enumerate
  455. // the objects and call paint on each of them from here.
  456. if (m_lpSite)
  457. m_lpSite->PaintObj(hDC);
  458. }