]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/treelay.h
Rewrote wxToolBar another time.
[wxWidgets.git] / include / wx / generic / treelay.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: treelay.h
3 // Purpose: wxTreeLayout class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 7/4/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TREELAY_H_
13 #define _WX_TREELAY_H_
14
15 #ifdef __GNUG__
16 #pragma interface "wxtree.h"
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/object.h"
21 class wxList;
22 class wxDC;
23 class wxMouseEvent;
24 #endif
25
26 #include "wx/string.h"
27
28 #if wxUSE_TREELAYOUT
29
30 class WXDLLEXPORT wxTreeLayout: public wxObject
31 {
32 DECLARE_ABSTRACT_CLASS(wxTreeLayout)
33
34 public:
35 wxTreeLayout();
36 virtual ~wxTreeLayout() { }
37
38 // Redefine these
39 virtual void GetChildren(long id, wxList& list) = 0;
40 virtual long GetNextNode(long id) = 0;
41 virtual long GetNodeParent(long id) = 0;
42 virtual long GetNodeX(long id) = 0;
43 virtual long GetNodeY(long id) = 0;
44 virtual void SetNodeX(long id, long x) = 0;
45 virtual void SetNodeY(long id, long y) = 0;
46 virtual void ActivateNode(long id, bool active) = 0;
47 virtual bool NodeActive(long id) = 0;
48
49 // Optional redefinition
50 void Initialize(void);
51 inline virtual void SetNodeName(long WXUNUSED(id), const wxString& WXUNUSED(name)) {}
52 inline virtual wxString GetNodeName(long WXUNUSED(id)) { return wxString(""); }
53 virtual void GetNodeSize(long id, long *x, long *y, wxDC& dc);
54 virtual void Draw(wxDC& dc);
55 virtual void DrawNodes(wxDC& dc);
56 virtual void DrawBranches(wxDC& dc);
57 virtual void DrawNode(long id, wxDC& dc);
58 virtual void DrawBranch(long from, long to, wxDC& dc);
59
60 // Don't redefine
61 virtual void DoLayout(wxDC& dc, long topNode = -1);
62
63 // Accessors -- don't redefine
64 inline void SetTopNode(long id) { m_parentNode = id; }
65 inline long GetTopNode(void) const { return m_parentNode; }
66 inline void SetSpacing(long x, long y) { m_xSpacing = x; m_ySpacing = y; }
67 inline long GetXSpacing(void) const { return m_xSpacing; }
68 inline long GetYSpacing(void) const { return m_ySpacing; }
69 inline void SetMargins(long x, long y) { m_leftMargin = x; m_topMargin = y; }
70 inline long GetTopMargin(void) const { return m_topMargin; }
71 inline long GetLeftMargin(void) const { return m_leftMargin; }
72
73 inline bool GetOrientation(void) const { return m_orientation; }
74 inline void SetOrientation(bool orient) { m_orientation = orient; }
75
76 private:
77 void CalcLayout(long node_id, int level, wxDC& dc);
78
79 // Members
80
81 protected:
82 long m_parentNode;
83 long m_lastY;
84 long m_lastX;
85 long m_xSpacing;
86 long m_ySpacing;
87 long m_topMargin;
88 long m_leftMargin;
89 bool m_orientation; // TRUE for top-to-bottom, FALSE for left-to-right
90 };
91
92 class WXDLLEXPORT wxStoredNode
93 {
94 public:
95 wxString m_name;
96 long m_x, m_y;
97 long m_parentId;
98 bool m_active;
99 long m_clientData;
100 };
101
102 /*
103 * A version of wxTreeLayout with storage for nodes
104 */
105
106 class WXDLLEXPORT wxTreeLayoutStored: public wxTreeLayout
107 {
108 DECLARE_DYNAMIC_CLASS(wxTreeLayoutStored)
109 public:
110 wxTreeLayoutStored(int noNodes = 200);
111 virtual ~wxTreeLayoutStored(void);
112 void Initialize(int n);
113
114 wxString HitTest(wxMouseEvent& event, wxDC& dc);
115 wxStoredNode* GetNode(long id) const;
116 inline int GetNumNodes() const { return m_maxNodes; };
117 inline int GetNodeCount() const { return m_num; };
118
119 virtual void GetChildren(long id, wxList& list);
120 virtual long GetNextNode(long id);
121 virtual long GetNodeParent(long id);
122 virtual long GetNodeX(long id);
123 virtual long GetNodeY(long id);
124 virtual void SetNodeX(long id, long x);
125 virtual void SetNodeY(long id, long y);
126 virtual void SetNodeName(long id, const wxString& name);
127 virtual wxString GetNodeName(long id);
128 virtual void ActivateNode(long id, bool active);
129 virtual bool NodeActive(long id);
130 virtual void SetClientData(long id, long clientData);
131 virtual long GetClientData(long id) const;
132
133 virtual long AddChild(const wxString& name, const wxString& parent = "");
134 virtual long NameToId(const wxString& name);
135
136 // Data members
137 private:
138 wxStoredNode* m_nodes;
139 int m_num;
140 int m_maxNodes;
141 };
142
143 // For backward compatibility
144 #define wxStoredTree wxTreeLayoutStored
145
146 #endif
147 // wxUSE_TREELAYOUT
148
149 #endif
150 // _WX_TREELAY_H_
151