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.

580 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. private: bool m_bCanCloseViews;
  126. public: bool CanCloseViews() {return m_bCanCloseViews;}
  127. // object model related methods.
  128. // hand over an automation object - CHANGE to use smart pointers.
  129. SC ScGetMMCDocument(Document **ppDocument);
  130. // Document interface
  131. SC ScSave();
  132. SC ScSaveAs( BSTR bstrFilename);
  133. SC ScClose( BOOL bSaveChanges);
  134. SC ScCreateProperties( PPPROPERTIES ppProperties);
  135. // properties
  136. SC Scget_Views( PPVIEWS ppViews);
  137. SC Scget_SnapIns( PPSNAPINS ppSnapIns);
  138. SC Scget_ActiveView( PPVIEW ppView);
  139. SC Scget_Name( PBSTR pbstrName);
  140. SC Scput_Name( BSTR bstrName);
  141. SC Scget_Location( PBSTR pbstrLocation);
  142. SC Scget_IsSaved( PBOOL pBIsSaved);
  143. SC Scget_Mode( PDOCUMENTMODE pMode);
  144. SC Scput_Mode( DocumentMode mode);
  145. SC Scget_RootNode( PPNODE ppNode);
  146. SC Scget_ScopeNamespace( PPSCOPENAMESPACE ppScopeNamespace);
  147. SC Scget_Application(PPAPPLICATION ppApplication);
  148. // Views interface
  149. SC Scget_Count( PLONG pCount);
  150. SC ScAdd( PNODE pNode, ViewOptions fViewOptions /* = ViewOption_Default*/ );
  151. SC ScItem( long Index, PPVIEW ppView);
  152. // views enumerator
  153. SC ScEnumNext(CAMCViewPosition &pos, PDISPATCH & pDispatch);
  154. SC ScEnumSkip(unsigned long celt, unsigned long& celtSkipped, CAMCViewPosition &pos);
  155. SC ScEnumReset(CAMCViewPosition &pos);
  156. public:
  157. // to iterate through the AMCViews only (not all child views)
  158. // similar to GetNextView and GetFirstViewPosition.
  159. CAMCView * GetNextAMCView(CAMCViewPosition &pos) const;
  160. CAMCViewPosition GetFirstAMCViewPosition() const;
  161. public:
  162. // CXMLObject overrides
  163. DEFINE_XML_TYPE(XML_TAG_MMC_CONSOLE_FILE);
  164. virtual void Persist(CPersistor& persistor);
  165. void PersistFrame(CPersistor& persistor);
  166. void PersistViews(CPersistor& persistor);
  167. SC ScCreateAndLoadView(CPersistor& persistor, int nViewID, const CBookmark& rootNode);
  168. void PersistCustomData (CPersistor &persistor);
  169. IScopeTree* GetScopeTree()
  170. {
  171. return m_spScopeTree;
  172. }
  173. CAMCView* CreateNewView(bool visible, bool bEmitScriptEvents = true);
  174. static CAMCDoc* GetDocument()
  175. {
  176. return m_pDoc;
  177. }
  178. MTNODEID GetMTNodeIDForNewView()
  179. {
  180. return m_MTNodeIDForNewView;
  181. }
  182. void SetMTNodeIDForNewView(MTNODEID id)
  183. {
  184. m_MTNodeIDForNewView = id;
  185. }
  186. int GetViewIDForNewView()
  187. {
  188. return m_ViewIDForNewView;
  189. }
  190. long GetNewWindowOptions()
  191. {
  192. return m_lNewWindowOptions;
  193. }
  194. HELPDOCINFO* GetHelpDocInfo()
  195. {
  196. return &m_HelpDocInfo;
  197. }
  198. void SetNewWindowOptions(long lOptions)
  199. {
  200. m_lNewWindowOptions = lOptions;
  201. }
  202. void SetMode (ProgramMode eMode);
  203. ProgramMode GetMode () const
  204. {
  205. return (m_ConsoleData.GetConsoleMode());
  206. }
  207. bool IsFrameModified () const
  208. {
  209. return (m_fFrameModified);
  210. }
  211. void SetFrameModifiedFlag (bool fFrameModified = TRUE)
  212. {
  213. m_fFrameModified = fFrameModified;
  214. }
  215. // implements CConsoleDocument for document access from node manager
  216. virtual SC ScOnSnapinAdded (PSNAPIN pSnapIn);
  217. virtual SC ScOnSnapinRemoved (PSNAPIN pSnapIn);
  218. virtual SC ScSetHelpCollectionInvalid();
  219. public:
  220. // Implementation
  221. virtual ~CAMCDoc();
  222. #ifdef _DEBUG
  223. virtual void AssertValid() const;
  224. virtual void Dump(CDumpContext& dc) const;
  225. #endif
  226. virtual BOOL DoFileSave();
  227. virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace = TRUE);
  228. virtual HMENU GetDefaultMenu(); // get menu depending on state
  229. SConsoleData* GetConsoleData() { return &m_ConsoleData; }
  230. public:
  231. HRESULT InitNodeManager();
  232. void ShowStatusBar (bool fVisible);
  233. /*
  234. * Custom data stuff
  235. */
  236. private:
  237. bool LoadCustomData (IStorage* pStorage);
  238. bool LoadCustomIconData (IStorage* pStorage);
  239. bool LoadCustomTitleData (IStorage* pStorage);
  240. bool LoadStringTable (IStorage* pStorage);
  241. /*
  242. * Custom icon stuff
  243. */
  244. public:
  245. HICON GetCustomIcon (bool fLarge, CString* pstrIconFile = NULL, int* pnIconIndex = NULL) const;
  246. void SetCustomIcon (LPCTSTR pszIconFile, int nIconIndex);
  247. bool HasCustomIcon () const
  248. { return (m_CustomIcon); }
  249. private:
  250. CPersistableIcon m_CustomIcon;
  251. /*
  252. * Custom title stuff
  253. */
  254. public:
  255. bool HasCustomTitle () const;
  256. CString GetCustomTitle () const;
  257. void SetCustomTitle (CString strNewTitle);
  258. IStringTablePrivate* GetStringTable() const;
  259. private:
  260. CComPtr<IStringTablePrivate> m_spStringTable;
  261. CStringTableString * m_pstrCustomTitle;
  262. /*
  263. * Favorites stuff
  264. */
  265. public:
  266. CFavorites* GetFavorites() { return m_pFavorites; }
  267. private:
  268. bool LoadFavorites();
  269. CFavorites* m_pFavorites;
  270. private:
  271. static CAMCDoc* m_pDoc;
  272. // the one and only document for the application
  273. IScopeTreePtr m_spScopeTree;
  274. // master namespace for document
  275. IPersistStoragePtr m_spScopeTreePersist;
  276. // master namespace IPersistStorage interface
  277. IStoragePtr m_spStorage;
  278. // the currently opened storage
  279. MTNODEID m_MTNodeIDForNewView;
  280. // the node id to be used when creating the next view
  281. int m_ViewIDForNewView;
  282. // the node id to be used when creating the next view
  283. SConsoleData m_ConsoleData;
  284. long m_lNewWindowOptions;
  285. bool m_bReadOnlyDoc;
  286. bool m_fFrameModified;
  287. SaveStatus m_eSaveStatus;
  288. DWORD m_dwFlags;
  289. HELPDOCINFO m_HelpDocInfo;
  290. void ReleaseNodeManager();
  291. bool LoadViews();
  292. bool LoadFrame();
  293. bool LoadAppMode();
  294. bool NodeManagerIsInitialized();
  295. bool NodeManagerIsLoaded();
  296. bool AssertNodeManagerIsInitialized();
  297. bool AssertNodeManagerIsLoaded();
  298. BOOL OnNewDocumentFailed();
  299. void SetConsoleFlag (ConsoleFlags eFlag, bool fSet);
  300. void DeleteHelpFile ();
  301. SC ScGetViewSettingsPersistorStream(IPersistStream **pIPersistStreamViewSettings);
  302. private:
  303. bool GetDocumentMode(DocumentMode* pMode);
  304. bool SetDocumentMode(DocumentMode docMode);
  305. public:
  306. // Is this save called implicitly or is it a result of exiting a modified file?
  307. bool IsExplicitSave() const
  308. { return (0 != (m_dwFlags & EXPLICIT_SAVE)); }
  309. void SetExplicitSave(bool bNewVal)
  310. {
  311. if (bNewVal)
  312. m_dwFlags |= EXPLICIT_SAVE;
  313. else
  314. m_dwFlags &= ~EXPLICIT_SAVE;
  315. }
  316. bool AllowViewCustomization() const
  317. { return ((m_ConsoleData.m_dwFlags & eFlag_PreventViewCustomization) == 0); }
  318. bool IsLogicalReadOnly() const
  319. { return ((m_ConsoleData.m_dwFlags & eFlag_LogicalReadOnly) != 0); }
  320. bool IsPhysicalReadOnly() const
  321. { return (m_bReadOnlyDoc); }
  322. // physical ReadOnly does not apply to user mode - it is not saving to original console
  323. // anyway.
  324. bool IsReadOnly() const
  325. { return ((IsPhysicalReadOnly() && (AMCGetApp()->GetMode() == eMode_Author)) ||
  326. (IsLogicalReadOnly() && (AMCGetApp()->GetMode() != eMode_Author))) ; }
  327. void SetPhysicalReadOnlyFlag (bool fPhysicalReadOnly)
  328. { m_bReadOnlyDoc = fPhysicalReadOnly; }
  329. void SetLogicalReadOnlyFlag (BOOL fLogicalReadOnly)
  330. { SetConsoleFlag (eFlag_LogicalReadOnly, fLogicalReadOnly); }
  331. void AllowViewCustomization (BOOL fAllowCustomization)
  332. { SetConsoleFlag (eFlag_PreventViewCustomization, !fAllowCustomization); }
  333. int GetNumberOfViews();
  334. int GetNumberOfPersistedViews();
  335. private:
  336. //{{AFX_MSG(CAMCDoc)
  337. afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
  338. afx_msg void OnConsoleAddremovesnapin();
  339. afx_msg void OnUpdateConsoleAddremovesnapin(CCmdUI* pCmdUI);
  340. //}}AFX_MSG
  341. DECLARE_MESSAGE_MAP()
  342. private:
  343. DocumentPtr m_sp_Document;
  344. ViewsPtr m_spViews;
  345. };
  346. inline bool CAMCDoc::NodeManagerIsInitialized()
  347. {
  348. return m_spScopeTree != NULL && m_spScopeTreePersist != NULL;
  349. }
  350. inline bool CAMCDoc::NodeManagerIsLoaded()
  351. {
  352. return NodeManagerIsInitialized() && m_spStorage != NULL;
  353. }
  354. inline bool CAMCDoc::AssertNodeManagerIsInitialized()
  355. {
  356. bool const bInited = NodeManagerIsInitialized();
  357. ASSERT(bInited);
  358. return bInited;
  359. }
  360. inline bool CAMCDoc::AssertNodeManagerIsLoaded()
  361. {
  362. bool const bLoaded = NodeManagerIsLoaded();
  363. ASSERT(bLoaded);
  364. return bLoaded;
  365. }
  366. inline BOOL CAMCDoc::OnNewDocumentFailed()
  367. {
  368. ReleaseNodeManager();
  369. return FALSE;
  370. }
  371. inline bool CAMCDoc::GetDocumentMode(DocumentMode* pMode)
  372. {
  373. if (! pMode)
  374. return false;
  375. switch(GetMode())
  376. {
  377. case eMode_Author:
  378. *pMode = DocumentMode_Author;
  379. break;
  380. case eMode_User:
  381. *pMode = DocumentMode_User;
  382. break;
  383. case eMode_User_MDI:
  384. *pMode = DocumentMode_User_MDI;
  385. break;
  386. case eMode_User_SDI:
  387. *pMode = DocumentMode_User_SDI;
  388. break;
  389. default:
  390. ASSERT(FALSE && _T("Unknown program mode"));
  391. return false;
  392. break;
  393. }
  394. return true;
  395. }
  396. inline bool CAMCDoc::SetDocumentMode(DocumentMode docMode)
  397. {
  398. switch(docMode)
  399. {
  400. case DocumentMode_Author:
  401. SetMode(eMode_Author);
  402. break;
  403. case DocumentMode_User:
  404. SetMode(eMode_User);
  405. break;
  406. case DocumentMode_User_SDI:
  407. SetMode(eMode_User_SDI);
  408. break;
  409. case DocumentMode_User_MDI:
  410. SetMode(eMode_User_MDI);
  411. break;
  412. default:
  413. return false; // Unknown mode.
  414. break;
  415. }
  416. return true;
  417. }
  418. //+-------------------------------------------------------------------
  419. //
  420. // Member: CAMCDoc::ScGetViewSettingsPersistorStream
  421. //
  422. // Synopsis: helper to get the IPersistStream interface for
  423. // CViewSettingsPersistor object.
  424. //
  425. // Arguments: [pIPersistStreamViewSettings] - [out]
  426. //
  427. // Returns: SC
  428. //
  429. //--------------------------------------------------------------------
  430. inline SC CAMCDoc::ScGetViewSettingsPersistorStream (/*[out]*/IPersistStream **pIPersistStreamViewSettings)
  431. {
  432. DECLARE_SC(sc, _T("CAMCDoc::ScGetViewSettingsPersistorStream"));
  433. sc = ScCheckPointers(pIPersistStreamViewSettings);
  434. if (sc)
  435. return sc;
  436. sc = ScCheckPointers(m_spScopeTree, E_UNEXPECTED);
  437. if (sc)
  438. return sc;
  439. INodeCallbackPtr spNodeCallback;
  440. sc = m_spScopeTree->QueryNodeCallback(&spNodeCallback);
  441. if (sc)
  442. return sc;
  443. sc = ScCheckPointers(spNodeCallback, E_UNEXPECTED);
  444. if (sc)
  445. return sc;
  446. sc = spNodeCallback->QueryViewSettingsPersistor(pIPersistStreamViewSettings);
  447. if (sc)
  448. return sc;
  449. sc = ScCheckPointers(pIPersistStreamViewSettings, E_UNEXPECTED);
  450. if (sc)
  451. return sc;
  452. return (sc);
  453. }
  454. int DisplayFileOpenError (SC sc, LPCTSTR pszFilename);
  455. /////////////////////////////////////////////////////////////////////////////
  456. #endif // AMCDOC_H__