home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / hierwiz / template / svritem.h < prev    next >
C/C++ Source or Header  |  1998-03-05  |  4KB  |  147 lines

  1. // svrdoc.h : interface of the CServerNode class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // QuickHelp and/or WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #ifndef _SVRITEM_H
  14. #define _SVRITEM_H
  15.  
  16. #define CX_MARGIN   8
  17. #define CY_MARGIN   4
  18.  
  19. #define CX_INDENT   12
  20. #define CX_BACKDENT 5
  21. #define CY_SEPARATOR 4
  22.  
  23. class CServerDoc;
  24. class CServerItem;
  25.  
  26. // in this example a CServerNode represents a node in a graph
  27. class CServerNode : public CObject
  28. {
  29.     DECLARE_SERIAL(CServerNode);
  30.  
  31. // Constructors
  32. public:
  33.     CServerNode(CServerDoc* pServerDoc = NULL);
  34.     static CServerNode* CreateRootNode(CServerDoc* pDoc);
  35.     void InitRootNode();
  36.  
  37.     // create from parent node
  38.     CServerNode* CreateChildNode(LPCTSTR lpszDescription);
  39.     CServerNode* PromptNewChildNode();  // create with user interface
  40.  
  41. // Attributes
  42.     CString     m_strDescription;       // node description/caption
  43.     CString     m_strLinkKey;           // link node if different from caption
  44.     CServerItem* m_pServerItem;         // pointer to active item (may be NULL)
  45.     CObList     m_listChild;            // list of children
  46.     BOOL        m_bHideChildren;
  47.     CServerDoc* m_pDocument;            // back pointer to document
  48.  
  49.     enum EShape
  50.     {
  51.         shapeRect,
  52.         shapeRound,
  53.         shapeOval,
  54.         shapeMax
  55.     } m_shape;      // shape to draw
  56.  
  57.     CServerDoc* GetDocument() const // return type-safe container
  58.         { return (CServerDoc*)m_pDocument; }
  59.     BOOL HasChildren() const
  60.         { return m_listChild.GetCount() != 0; }
  61.     BOOL IsChild(const CServerNode* pPotentialChild) const;
  62.     // for popup context sensitive menus (in IDR_POPUPS)
  63.     int GetPopupMenuIndex()
  64.         { return 0; }   // 0 for simple menu
  65.     CServerNode* GetNext(CServerNode *pItem, BOOL bInit = TRUE);
  66.     CServerNode* GetPrev(CServerNode *pItem, BOOL bInit = TRUE);
  67.     const CString& GetItemName();
  68.     void UpdateItemName();
  69.  
  70. // Operations
  71.     // bounding rect helpers
  72.     void CalcNodeSize(CDC* pDC, CSize& sizeNode);
  73.  
  74. $$IF(WANTS_TEXTVIEW)
  75.     // Text view display helpers
  76.     BOOL GetNodeText(CString *strBuf, int TAB) ;
  77.     int GetTreeText(CString * strBuf, int TAB) ;
  78. $$ENDIF
  79.     // drawing helpers
  80.     BOOL Draw(CDC* pDC, CPoint pt, BOOL bSelected, CSize sizeNode);
  81.     BOOL FindAndDelete(CServerNode *pItem);
  82.         // find pItem, remove it and all of its children
  83.     void DeleteChildNodes();    // remove all child nodes from a given node
  84.     CServerNode* FindNode(LPCTSTR pszItemName);
  85.  
  86.     // recursive bounding rect and drawing helpers
  87.     void CalcBounding(CDC* pDC, CPoint& ptStart, CSize& sizeMax);
  88.     int DrawTree(CDC* pDC, CPoint ptStart, CServerNode* pItemSel);
  89.  
  90.     // simple UI helpers
  91.     BOOL PromptChangeNode();
  92.  
  93.     virtual void Serialize(CArchive& ar);        // for native data
  94.  
  95. // Implementation
  96. public:
  97.     ~CServerNode();
  98.  
  99. protected:
  100.     void SaveAsText(CArchive& ar, int nLevel);
  101.  
  102.     friend class CServerItem;   // CServerItem is an extension of a CServerNode
  103. };
  104.  
  105.  
  106. // CServerItem represents the OLE glue to a CServerNode.  Such items
  107. //  are only allocated as necessary.
  108.  
  109. class CServerItem : public COleServerItem
  110. {
  111. // Constructors
  112. public:
  113.     CServerItem(CServerDoc* pDoc, CServerNode* pNode);
  114.  
  115. // Attributes
  116.     CServerNode* m_pServerNode;     // back pointer to node (may be NULL)
  117.  
  118.     CServerDoc* GetDocument() const // return type-safe container
  119.         { return (CServerDoc*)COleServerItem::GetDocument(); }
  120.  
  121. // Overridables
  122. protected:
  123.     virtual void Serialize(CArchive& ar);   // called for clipboard save
  124.  
  125.     virtual BOOL OnDraw(CDC* pDC, CSize& rSize);
  126.     virtual BOOL OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize);
  127.     virtual void OnOpen();      // select the node when a link is shown
  128.  
  129.     virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  130.     virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  131.         LPPOINT pptOffset, LPSIZE pSize);
  132.  
  133. // Implementation
  134. public:
  135.     ~CServerItem();
  136.  
  137. protected:
  138.     // GetNativeClipboardData called by overrided OnGetClipboardData
  139.     void GetNativeClipboardData(COleDataSource *pDataSource);
  140.  
  141.     friend class CServerNode;   // CServerNode is an extension of CServerItem
  142. };
  143.  
  144. #endif
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147.