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.

179 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: favorite.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // favorite.h
  11. #ifndef _FAVORITE_H_
  12. #define _FAVORITE_H_
  13. #include "treeobsv.h"
  14. #include "tstring.h"
  15. #include "imageid.h"
  16. /*
  17. * Define/include the stuff we need for WTL::CImageList. We need prototypes
  18. * for IsolationAwareImageList_Read and IsolationAwareImageList_Write here
  19. * because commctrl.h only declares them if __IStream_INTERFACE_DEFINED__
  20. * is defined. __IStream_INTERFACE_DEFINED__ is defined by objidl.h, which
  21. * we can't include before including afx.h because it ends up including
  22. * windows.h, which afx.h expects to include itself. Ugh.
  23. */
  24. HIMAGELIST WINAPI IsolationAwareImageList_Read(LPSTREAM pstm);
  25. BOOL WINAPI IsolationAwareImageList_Write(HIMAGELIST himl,LPSTREAM pstm);
  26. #define _WTL_NO_AUTOMATIC_NAMESPACE
  27. #include "atlapp.h"
  28. #include "atlctrls.h"
  29. class CFavorites;
  30. class CFavObject;
  31. class CMemento;
  32. // Extra spacing for favorite tree views
  33. #define FAVVIEW_ITEM_SPACING 4
  34. #define LAST_FAVORITE ((CFavObject*)TREEID_LAST)
  35. //
  36. // CFavObject - class for favorite groups and items.
  37. //
  38. class CFavObject : public CXMLObject
  39. {
  40. friend CFavorites;
  41. private:
  42. CFavObject(bool bIsGroup);
  43. ~CFavObject();
  44. public:
  45. LPCTSTR GetName() { return m_strName.data(); }
  46. CFavObject* GetParent() { return m_pFavParent; }
  47. CFavObject* GetNext() { return m_pFavNext; }
  48. CFavObject* GetChild() { return m_pFavChild;}
  49. BOOL IsGroup() {return m_bIsGroup;}
  50. DWORD GetChildCount();
  51. int GetImage();
  52. int GetOpenImage();
  53. void AddChild(CFavObject* pFav, CFavObject* pFavPrev = LAST_FAVORITE);
  54. void RemoveChild(CFavObject* pFavRemove);
  55. CMemento* GetMemento() {return &m_memento; }
  56. void SetMemento(CMemento &memento) {m_memento = memento; }
  57. LPCTSTR GetPath() { return m_strPath.data(); }
  58. void SetPath(LPCTSTR szPath);
  59. protected:
  60. void SetNext (CFavObject* pFav) { m_pFavNext = pFav; }
  61. void SetChild (CFavObject* pFav) { m_pFavChild = pFav; }
  62. void SetParent(CFavObject* pFav) { m_pFavParent = pFav; }
  63. CFavObject* m_pFavParent;
  64. CFavObject* m_pFavNext;
  65. CFavObject* m_pFavChild;
  66. public:
  67. // pseudo-CSerialObject methods. The real version number is saved with the containing object, for efficiency.
  68. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  69. DEFINE_XML_TYPE(XML_TAG_FAVORITES_ENTRY);
  70. virtual void Persist(CPersistor &persistor);
  71. friend class CFavoriteXMLList;
  72. // these are persisted
  73. protected:
  74. bool m_bIsGroup;
  75. CStringTableString m_strName;
  76. CStringTableString m_strPath;
  77. CMemento m_memento;
  78. };
  79. /*****************************************************************\
  80. | CLASS: CFavoriteXMLList
  81. | DESCR: implements persisting of linked list as a collection
  82. \*****************************************************************/
  83. class CFavoriteXMLList : public XMLListCollectionBase
  84. {
  85. CFavObject * &m_rpRoot;
  86. CFavObject * m_Parent;
  87. public:
  88. CFavoriteXMLList(CFavObject * &rpRoot, CFavObject *Parent) : m_rpRoot(rpRoot), m_Parent(Parent) {}
  89. // PersistItself should be called instead of CPersistor's Persist method
  90. // implements "softer" loading algorythm
  91. bool PersistItself(CPersistor& persistor);
  92. protected:
  93. virtual void Persist(CPersistor& persistor);
  94. virtual void OnNewElement(CPersistor& persistor);
  95. DEFINE_XML_TYPE(XML_TAG_FAVORITES_LIST);
  96. };
  97. class CFavorites : public CTreeSource,
  98. public EventSourceImpl<CTreeObserver>,
  99. public CSerialObject,
  100. public CXMLObject
  101. {
  102. public:
  103. CFavorites();
  104. ~CFavorites();
  105. // CTreeSource methods
  106. STDMETHOD_(TREEITEMID, GetRootItem) ();
  107. STDMETHOD_(TREEITEMID, GetParentItem) (TREEITEMID tid);
  108. STDMETHOD_(TREEITEMID, GetChildItem) (TREEITEMID tid);
  109. STDMETHOD_(TREEITEMID, GetNextSiblingItem) (TREEITEMID tid);
  110. STDMETHOD_(LPARAM, GetItemParam) (TREEITEMID tid);
  111. STDMETHOD_(void, GetItemName) (TREEITEMID tid, LPTSTR pszName, int cchMaxName);
  112. STDMETHOD_(void, GetItemPath) (TREEITEMID tid, LPTSTR pszPath, int cchMaxName);
  113. STDMETHOD_(int, GetItemImage) (TREEITEMID tid);
  114. STDMETHOD_(int, GetItemOpenImage) (TREEITEMID tid);
  115. STDMETHOD_(BOOL, IsFolderItem) (TREEITEMID tid);
  116. // CFavorites methods
  117. HRESULT AddToFavorites(LPCTSTR szName, LPCTSTR szPath, CMemento &memento, CWnd* pwndHost);
  118. HRESULT OrganizeFavorites(CWnd* pwndHost);
  119. HRESULT AddFavorite(TREEITEMID tidParent, LPCTSTR strName, CFavObject** ppFavRet = NULL);
  120. HRESULT AddGroup (TREEITEMID tidParent, LPCTSTR strName, CFavObject** ppFavRet = NULL);
  121. HRESULT DeleteItem (TREEITEMID tidRemove);
  122. HRESULT MoveItem (TREEITEMID tid, TREEITEMID tidNewParent, TREEITEMID tidPrev);
  123. HRESULT SetItemName(TREEITEMID tid, LPCTSTR pszName);
  124. HRESULT GetMemento (TREEITEMID tid, CMemento* pmemento);
  125. CFavObject* FavObjFromTID(TREEITEMID tid) { return reinterpret_cast<CFavObject*>(tid); }
  126. TREEITEMID TIDFromFavObj(CFavObject* pFav) { return reinterpret_cast<TREEITEMID>(pFav); }
  127. bool IsEmpty();
  128. CImageList* GetImageList();
  129. protected:
  130. // CSerialObject methods
  131. virtual UINT GetVersion() {return 1;}
  132. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  133. DEFINE_XML_TYPE(XML_TAG_FAVORITES_LIST);
  134. virtual void Persist(CPersistor &persistor);
  135. private:
  136. /*
  137. * Theming: use WTL::CImageList instead of MFC's CImageList so we can
  138. * insure a theme-correct imagelist will be created.
  139. */
  140. WTL::CImageList m_ImageList;
  141. // these get persisted
  142. private:
  143. CFavObject* m_pFavRoot;
  144. };
  145. #endif //_FAVORITE_H_