]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/treelay.h
Trying to hide evidence of my negative programming skills...
[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 class WXDLLEXPORT wxTreeLayout: public wxObject
29 {
30 DECLARE_ABSTRACT_CLASS(wxTreeLayout)
31
32 public:
33 wxTreeLayout();
34
35 // Redefine these
36 virtual void GetChildren(long id, wxList& list) = 0;
37 virtual long GetNextNode(long id) = 0;
38 virtual long GetNodeParent(long id) = 0;
39 virtual long GetNodeX(long id) = 0;
40 virtual long GetNodeY(long id) = 0;
41 virtual void SetNodeX(long id, long x) = 0;
42 virtual void SetNodeY(long id, long y) = 0;
43 virtual void ActivateNode(long id, bool active) = 0;
44 virtual bool NodeActive(long id) = 0;
45
46 // Optional redefinition
47 void Initialize(void);
48 inline virtual void SetNodeName(long WXUNUSED(id), const wxString& WXUNUSED(name)) {}
49 inline virtual wxString GetNodeName(long WXUNUSED(id)) { return wxString(""); }
50 virtual void GetNodeSize(long id, long *x, long *y, wxDC& dc);
51 virtual void Draw(wxDC& dc);
52 virtual void DrawNodes(wxDC& dc);
53 virtual void DrawBranches(wxDC& dc);
54 virtual void DrawNode(long id, wxDC& dc);
55 virtual void DrawBranch(long from, long to, wxDC& dc);
56
57 // Don't redefine
58 virtual void DoLayout(wxDC& dc, long topNode = -1);
59
60 // Accessors -- don't redefine
61 inline void SetTopNode(long id) { m_parentNode = id; }
62 inline long GetTopNode(void) const { return m_parentNode; }
63 inline void SetSpacing(long x, long y) { m_xSpacing = x; m_ySpacing = y; }
64 inline long GetXSpacing(void) const { return m_xSpacing; }
65 inline long GetYSpacing(void) const { return m_ySpacing; }
66 inline void SetMargins(long x, long y) { m_leftMargin = x; m_topMargin = y; }
67 inline long GetTopMargin(void) const { return m_topMargin; }
68 inline long GetLeftMargin(void) const { return m_leftMargin; }
69
70 inline bool GetOrientation(void) const { return m_orientation; }
71 inline void SetOrientation(bool orient) { m_orientation = orient; }
72
73 private:
74 void CalcLayout(long node_id, int level, wxDC& dc);
75
76 // Members
77
78 protected:
79 long m_parentNode;
80 long m_lastY;
81 long m_lastX;
82 long m_xSpacing;
83 long m_ySpacing;
84 long m_topMargin;
85 long m_leftMargin;
86 bool m_orientation; // TRUE for top-to-bottom, FALSE for left-to-right
87 };
88
89 class WXDLLEXPORT wxStoredNode
90 {
91 public:
92 wxString m_name;
93 long m_x, m_y;
94 long m_parentId;
95 bool m_active;
96 long m_clientData;
97 };
98
99 /*
100 * A version of wxTreeLayout with storage for nodes
101 */
102
103 class WXDLLEXPORT wxTreeLayoutStored: public wxTreeLayout
104 {
105 DECLARE_DYNAMIC_CLASS(wxTreeLayoutStored)
106 public:
107 wxTreeLayoutStored(int noNodes = 200);
108 ~wxTreeLayoutStored(void);
109 void Initialize(int n);
110
111 wxString HitTest(wxMouseEvent& event, wxDC& dc);
112 wxStoredNode* GetNode(long id) const;
113 inline int GetNumNodes() const { return m_maxNodes; };
114 inline int GetNodeCount() const { return m_num; };
115
116 virtual void GetChildren(long id, wxList& list);
117 virtual long GetNextNode(long id);
118 virtual long GetNodeParent(long id);
119 virtual long GetNodeX(long id);
120 virtual long GetNodeY(long id);
121 virtual void SetNodeX(long id, long x);
122 virtual void SetNodeY(long id, long y);
123 virtual void SetNodeName(long id, const wxString& name);
124 virtual wxString GetNodeName(long id);
125 virtual void ActivateNode(long id, bool active);
126 virtual bool NodeActive(long id);
127 virtual void SetClientData(long id, long clientData);
128 virtual long GetClientData(long id) const;
129
130 virtual long AddChild(const wxString& name, const wxString& parent = "");
131 virtual long NameToId(const wxString& name);
132
133 // Data members
134 private:
135 wxStoredNode* m_nodes;
136 int m_num;
137 int m_maxNodes;
138 };
139
140 // For backward compatibility
141 #define wxStoredTree wxTreeLayoutStored
142
143 #endif
144 // _WX_TREELAY_H_
145