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.

578 lines
15 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: amcdoc.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // AMCDoc.h : interface of the CAMCDoc class
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef AMCDOC_H__
  14. #define AMCDOC_H__
  15. #include "mmcdata.h"
  16. #include "amc.h" // for AMCGetApp
  17. #include "picon.h" // for CPersistableIcon
  18. #include "tstring.h" // for CStringTableStringBase
  19. #include "condoc.h"
  20. #define EXPLICIT_SAVE 0x1
  21. class CAMCView;
  22. class ViewSettings;
  23. class CMasterStringTable;
  24. class CFavorites;
  25. class CMMCDocument;
  26. struct Document;
  27. /*+-------------------------------------------------------------------------*
  28. * CStringTableString
  29. *
  30. *
  31. *--------------------------------------------------------------------------*/
  32. class CStringTableString : public CStringTableStringBase
  33. {
  34. typedef CStringTableStringBase BaseClass;
  35. public:
  36. CStringTableString (IStringTablePrivate* pstp)
  37. : BaseClass (pstp) {}
  38. CStringTableString (const CStringTableString& other)
  39. : BaseClass (other) {}
  40. CStringTableString (const tstring& str)
  41. : BaseClass (GetStringTable(), str) {}
  42. CStringTableString& operator= (const CStringTableString& other)
  43. { BaseClass::operator=(other); return (*this); }
  44. CStringTableString& operator= (const tstring& str)
  45. { BaseClass::operator=(str); return (*this); }
  46. CStringTableString& operator= (LPCTSTR psz)
  47. { BaseClass::operator=(psz); return (*this); }
  48. private:
  49. IStringTablePrivate* GetStringTable() const;
  50. };
  51. /*+-------------------------------------------------------------------------*
  52. * CAMCViewPosition
  53. *
  54. * This class abstracts a POSITION. It can be used to iterate through a
  55. * CAMCDoc's CAMCView objects using GetFirstAMCViewPosition and
  56. * GetNextAMCView.
  57. *
  58. * It exists to guard against using GetFirstViewPosition with GetNextAMCView
  59. * or GetFirstAMCViewPosition with GetNextView.
  60. *--------------------------------------------------------------------------*/
  61. class CAMCViewPosition
  62. {
  63. public:
  64. CAMCViewPosition() : m_pos(NULL)
  65. {}
  66. POSITION& GetPosition () // returns non-const reference
  67. { return (m_pos); }
  68. void SetPosition (POSITION pos)
  69. { m_pos = pos; }
  70. /*
  71. * for comparison to NULL
  72. */
  73. bool operator==(int null) const
  74. {
  75. ASSERT (null == 0); // *only* support comparison to NULL
  76. return (m_pos == NULL);
  77. }
  78. bool operator!=(int null) const
  79. {
  80. ASSERT (null == 0); // *only* support comparison to NULL
  81. return (m_pos != NULL);
  82. }
  83. private:
  84. POSITION m_pos;
  85. };
  86. /*+-------------------------------------------------------------------------*
  87. * class CAMCDoc
  88. *
  89. *
  90. *--------------------------------------------------------------------------*/
  91. class CAMCDoc :
  92. public CDocument,
  93. public CTiedObject,
  94. public CXMLObject,
  95. public CConsoleDocument,
  96. public CConsoleFilePersistor,
  97. public CEventSource<CAMCDocumentObserver>
  98. {
  99. enum SaveStatus
  100. {
  101. eStat_Failed,
  102. eStat_Succeeded,
  103. eStat_Cancelled
  104. };
  105. protected: // create from serialization only
  106. CAMCDoc();
  107. DECLARE_DYNCREATE(CAMCDoc)
  108. // Attributes
  109. public:
  110. virtual BOOL IsModified();
  111. // Operations
  112. public:
  113. // Overrides
  114. // ClassWizard generated virtual function overrides
  115. //{{AFX_VIRTUAL(CAMCDoc)
  116. public:
  117. virtual BOOL OnNewDocument();
  118. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  119. SC ScOnOpenDocument(LPCTSTR lpszPathName); // SC version of the above method.
  120. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  121. virtual void DeleteContents();
  122. virtual void OnCloseDocument();
  123. virtual BOOL SaveModified();
  124. //}}AFX_VIRTUAL
  125. // object model related methods.
  126. // hand over an automation object - CHANGE to use smart pointers.
  127. SC ScGetMMCDocument(Document **ppDocument);
  128. // Document interface
  129. SC ScSave();
  130. SC ScSaveAs( BSTR bstrFilename);
  131. SC ScClose( BOOL bSaveChanges);
  132. SC ScCreateProperties( PPPROPERTIES ppProperties);
  133. // properties
  134. SC Scget_Views( PPVIEWS ppViews);
  135. SC Scget_SnapIns( PPSNAPINS ppSnapIns);
  136. SC Scget_ActiveView( PPVIEW ppView);
  137. SC Scget_Name( PBSTR pbstrName);
  138. SC Scput_Name( BSTR bstrName);
  139. SC Scget_Location( PBSTR pbstrLocation);
  140. SC Scget_IsSaved( PBOOL pBIsSaved);
  141. SC Scget_Mode( PDOCUMENTMODE pMode);
  142. SC Scput_Mode( DocumentMode mode);
  143. SC Scget_RootNode( PPNODE ppNode);
  144. SC Scget_ScopeNamespace( PPSCOPENAMESPACE ppScopeNamespace);
  145. SC Scget_Application(PPAPPLICATION ppApplication);
  146. // Views interface
  147. SC Scget_Count( PLONG pCount);
  148. SC ScAdd( PNODE pNode, ViewOptions fViewOptions /* = ViewOption_Default*/ );
  149. SC ScItem( long Index, PPVIEW ppView);
  150. // views enumerator
  151. SC ScEnumNext(CAMCViewPosition &pos, PDISPATCH & pDispatch);
  152. SC ScEnumSkip(unsigned long celt, unsigned long& celtSkipped, CAMCViewPosition &pos);
  153. SC ScEnumReset(CAMCViewPosition &pos);
  154. public:
  155. // to iterate through the AMCViews only (not all child views)
  156. // similar to GetNextView and GetFirstViewPosition.
  157. CAMCView * GetNextAMCView(CAMCViewPosition &pos) const;
  158. CAMCViewPosition GetFirstAMCViewPosition() const;
  159. public:
  160. // CXMLObject overrides
  161. DEFINE_XML_TYPE(XML_TAG_MMC_CONSOLE_FILE);
  162. virtual void Persist(CPersistor& persistor);
  163. void PersistFrame(CPersistor& persistor);
  164. void PersistViews(CPersistor& persistor);
  165. SC ScCreateAndLoadView(CPersistor& persistor, int nViewID, const CBookmark& rootNode);
  166. void PersistCustomData (CPersistor &persistor);
  167. IScopeTree* GetScopeTree()
  168. {
  169. return m_spScopeTree;
  170. }
  171. CAMCView* CreateNewView(bool visible, bool bEmitScriptEvents = true);
  172. static CAMCDoc* GetDocument()
  173. {
  174. return m_pDoc;
  175. }
  176. MTNODEID GetMTNodeIDForNewView()
  177. {
  178. return m_MTNodeIDForNewView;
  179. }
  180. void SetMTNodeIDForNewView(MTNODEID id)
  181. {
  182. m_MTNodeIDForNewView = id;
  183. }
  184. int GetViewIDForNewView()
  185. {
  186. return m_ViewIDForNewView;
  187. }
  188. long GetNewWindowOptions()
  189. {
  190. return m_lNewWindowOptions;
  191. }
  192. HELPDOCINFO* GetHelpDocInfo()
  193. {
  194. return &m_HelpDocInfo;
  195. }
  196. void SetNewWindowOptions(long lOptions)
  197. {
  198. m_lNewWindowOptions = lOptions;
  199. }
  200. void SetMode (ProgramMode eMode);
  201. ProgramMode GetMode () const
  202. {
  203. return (m_ConsoleData.GetConsoleMode());
  204. }
  205. bool IsFrameModified () const
  206. {
  207. return (m_fFrameModified);
  208. }
  209. void SetFrameModifiedFlag (bool fFrameModified = TRUE)
  210. {
  211. m_fFrameModified = fFrameModified;
  212. }
  213. // implements CConsoleDocument for document access from node manager
  214. virtual SC ScOnSnapinAdded (PSNAPIN pSnapIn);
  215. virtual SC ScOnSnapinRemoved (PSNAPIN pSnapIn);
  216. virtual SC ScSetHelpCollectionInvalid();
  217. public:
  218. // Implementation
  219. virtual ~CAMCDoc();
  220. #ifdef _DEBUG
  221. virtual void AssertValid() const;
  222. virtual void Dump(CDumpContext& dc) const;
  223. #endif
  224. virtual BOOL DoFileSave();
  225. virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace = TRUE);
  226. virtual HMENU GetDefaultMenu(); // get menu depending on state
  227. SConsoleData* GetConsoleData() { return &m_ConsoleData; }
  228. public:
  229. HRESULT InitNodeManager();
  230. void ShowStatusBar (bool fVisible);
  231. /*
  232. * Custom data stuff
  233. */
  234. private:
  235. bool LoadCustomData (IStorage* pStorage);
  236. bool LoadCustomIconData (IStorage* pStorage);
  237. bool LoadCustomTitleData (IStorage* pStorage);
  238. bool LoadStringTable (IStorage* pStorage);
  239. /*
  240. * Custom icon stuff
  241. */
  242. public:
  243. HICON GetCustomIcon (bool fLarge, CString* pstrIconFile = NULL, int* pnIconIndex = NULL) const;
  244. void SetCustomIcon (LPCTSTR pszIconFile, int nIconIndex);
  245. bool HasCustomIcon () const
  246. { return (m_CustomIcon); }
  247. private:
  248. CPersistableIcon m_CustomIcon;
  249. /*
  250. * Custom title stuff
  251. */
  252. public:
  253. bool HasCustomTitle () const;
  254. CString GetCustomTitle () const;
  255. void SetCustomTitle (CString strNewTitle);
  256. IStringTablePrivate* GetStringTable() const;
  257. private:
  258. CComPtr<IStringTablePrivate> m_spStringTable;
  259. CStringTableString * m_pstrCustomTitle;
  260. /*
  261. * Favorites stuff
  262. */
  263. public:
  264. CFavorites* GetFavorites() { return m_pFavorites; }
  265. private:
  266. bool LoadFavorites();
  267. CFavorites* m_pFavorites;
  268. private:
  269. static CAMCDoc* m_pDoc;
  270. // the one and only document for the application
  271. IScopeTreePtr m_spScopeTree;
  272. // master namespace for document
  273. IPersistStoragePtr m_spScopeTreePersist;
  274. // master namespace IPersistStorage interface
  275. IStoragePtr m_spStorage;
  276. // the currently opened storage
  277. MTNODEID m_MTNodeIDForNewView;
  278. // the node id to be used when creating the next view
  279. int m_ViewIDForNewView;
  280. // the node id to be used when creating the next view
  281. SConsoleData m_ConsoleData;
  282. long m_lNewWindowOptions;
  283. bool m_bReadOnlyDoc;
  284. bool m_fFrameModified;
  285. SaveStatus m_eSaveStatus;
  286. DWORD m_dwFlags;
  287. HELPDOCINFO m_HelpDocInfo;
  288. void ReleaseNodeManager();
  289. bool LoadViews();
  290. bool LoadFrame();
  291. bool LoadAppMode();
  292. bool NodeManagerIsInitialized();
  293. bool NodeManagerIsLoaded();
  294. bool AssertNodeManagerIsInitialized();
  295. bool AssertNodeManagerIsLoaded();
  296. BOOL OnNewDocumentFailed();
  297. void SetConsoleFlag (ConsoleFlags eFlag, bool fSet);
  298. void DeleteHelpFile ();
  299. SC ScGetViewSettingsPersistorStream(IPersistStream **pIPersistStreamViewSettings);
  300. private:
  301. bool GetDocumentMode(DocumentMode* pMode);
  302. bool SetDocumentMode(DocumentMode docMode);
  303. public:
  304. // Is this save called implicitly or is it a result of exiting a modified file?
  305. bool IsExplicitSave() const
  306. { return (0 != (m_dwFlags & EXPLICIT_SAVE)); }
  307. void SetExplicitSave(bool bNewVal)
  308. {
  309. if (bNewVal)
  310. m_dwFlags |= EXPLICIT_SAVE;
  311. else
  312. m_dwFlags &= ~EXPLICIT_SAVE;
  313. }
  314. bool AllowViewCustomization() const
  315. { return ((m_ConsoleData.m_dwFlags & eFlag_PreventViewCustomization) == 0); }
  316. bool IsLogicalReadOnly() const
  317. { return ((m_ConsoleData.m_dwFlags & eFlag_LogicalReadOnly) != 0); }
  318. bool IsPhysicalReadOnly() const
  319. { return (m_bReadOnlyDoc); }
  320. // physical ReadOnly does not apply to user mode - it is not saving to original console
  321. // anyway.
  322. bool IsReadOnly() const
  323. { return ((IsPhysicalReadOnly() && (AMCGetApp()->GetMode() == eMode_Author)) ||
  324. (IsLogicalReadOnly() && (AMCGetApp()->GetMode() != eMode_Author))) ; }
  325. void SetPhysicalReadOnlyFlag (bool fPhysicalReadOnly)
  326. { m_bReadOnlyDoc = fPhysicalReadOnly; }
  327. void SetLogicalReadOnlyFlag (BOOL fLogicalReadOnly)
  328. { SetConsoleFlag (eFlag_LogicalReadOnly, fLogicalReadOnly); }
  329. void AllowViewCustomization (BOOL fAllowCustomization)
  330. { SetConsoleFlag (eFlag_PreventViewCustomization, !fAllowCustomization); }
  331. int GetNumberOfViews();
  332. int GetNumberOfPersistedViews();
  333. private:
  334. //{{AFX_MSG(CAMCDoc)
  335. afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
  336. afx_msg void OnConsoleAddremovesnapin();
  337. afx_msg void OnUpdateConsoleAddremovesnapin(CCmdUI* pCmdUI);
  338. //}}AFX_MSG
  339. DECLARE_MESSAGE_MAP()
  340. private:
  341. DocumentPtr m_sp_Document;
  342. ViewsPtr m_spViews;
  343. };
  344. inline bool CAMCDoc::NodeManagerIsInitialized()
  345. {
  346. return m_spScopeTree != NULL && m_spScopeTreePersist != NULL;
  347. }
  348. inline bool CAMCDoc::NodeManagerIsLoaded()
  349. {
  350. return NodeManagerIsInitialized() && m_spStorage != NULL;
  351. }
  352. inline bool CAMCDoc::AssertNodeManagerIsInitialized()
  353. {
  354. bool const bInited = NodeManagerIsInitialized();
  355. ASSERT(bInited);
  356. return bInited;
  357. }
  358. inline bool CAMCDoc::AssertNodeManagerIsLoaded()
  359. {
  360. bool const bLoaded = NodeManagerIsLoaded();
  361. ASSERT(bLoaded);
  362. return bLoaded;
  363. }
  364. inline BOOL CAMCDoc::OnNewDocumentFailed()
  365. {
  366. ReleaseNodeManager();
  367. return FALSE;
  368. }
  369. inline bool CAMCDoc::GetDocumentMode(DocumentMode* pMode)
  370. {
  371. if (! pMode)
  372. return false;
  373. switch(GetMode())
  374. {
  375. case eMode_Author:
  376. *pMode = DocumentMode_Author;
  377. break;
  378. case eMode_User:
  379. *pMode = DocumentMode_User;
  380. break;
  381. case eMode_User_MDI:
  382. *pMode = DocumentMode_User_MDI;
  383. break;
  384. case eMode_User_SDI:
  385. *pMode = DocumentMode_User_SDI;
  386. break;
  387. default:
  388. ASSERT(FALSE && _T("Unknown program mode"));
  389. return false;
  390. break;
  391. }
  392. return true;
  393. }
  394. inline bool CAMCDoc::SetDocumentMode(DocumentMode docMode)
  395. {
  396. switch(docMode)
  397. {
  398. case DocumentMode_Author:
  399. SetMode(eMode_Author);
  400. break;
  401. case DocumentMode_User:
  402. SetMode(eMode_User);
  403. break;
  404. case DocumentMode_User_SDI:
  405. SetMode(eMode_User_SDI);
  406. break;
  407. case DocumentMode_User_MDI:
  408. SetMode(eMode_User_MDI);
  409. break;
  410. default:
  411. return false; // Unknown mode.
  412. break;
  413. }
  414. return true;
  415. }
  416. //+-------------------------------------------------------------------
  417. //
  418. // Member: CAMCDoc::ScGetViewSettingsPersistorStream
  419. //
  420. // Synopsis: helper to get the IPersistStream interface for
  421. // CViewSettingsPersistor object.
  422. //
  423. // Arguments: [pIPersistStreamViewSettings] - [out]
  424. //
  425. // Returns: SC
  426. //
  427. //--------------------------------------------------------------------
  428. inline SC CAMCDoc::ScGetViewSettingsPersistorStream (/*[out]*/IPersistStream **pIPersistStreamViewSettings)
  429. {
  430. DECLARE_SC(sc, _T("CAMCDoc::ScGetViewSettingsPersistorStream"));
  431. sc = ScCheckPointers(pIPersistStreamViewSettings);
  432. if (sc)
  433. return sc;
  434. sc = ScCheckPointers(m_spScopeTree, E_UNEXPECTED);
  435. if (sc)
  436. return sc;
  437. INodeCallbackPtr spNodeCallback;
  438. sc = m_spScopeTree->QueryNodeCallback(&spNodeCallback);
  439. if (sc)
  440. return sc;
  441. sc = ScCheckPointers(spNodeCallback, E_UNEXPECTED);
  442. if (sc)
  443. return sc;
  444. sc = spNodeCallback->QueryViewSettingsPersistor(pIPersistStreamViewSettings);
  445. if (sc)
  446. return sc;
  447. sc = ScCheckPointers(pIPersistStreamViewSettings, E_UNEXPECTED);
  448. if (sc)
  449. return sc;
  450. return (sc);
  451. }
  452. int DisplayFileOpenError (SC sc, LPCTSTR pszFilename);
  453. /////////////////////////////////////////////////////////////////////////////
  454. #endif // AMCDOC_H__