]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/msw/treectrl.h | |
3 | // Purpose: wxTreeCtrl class | |
4 | // Author: Julian Smart | |
5 | // Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98 | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_MSW_TREECTRL_H_ | |
13 | #define _WX_MSW_TREECTRL_H_ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #if wxUSE_TREECTRL | |
20 | ||
21 | #include "wx/textctrl.h" | |
22 | #include "wx/dynarray.h" | |
23 | #include "wx/treebase.h" | |
24 | #include "wx/hashmap.h" | |
25 | ||
26 | #ifdef __GNUWIN32__ | |
27 | // Cygwin windows.h defines these identifiers | |
28 | #undef GetFirstChild | |
29 | #undef GetNextSibling | |
30 | #endif // Cygwin | |
31 | ||
32 | // fwd decl | |
33 | class WXDLLIMPEXP_FWD_CORE wxImageList; | |
34 | class WXDLLIMPEXP_FWD_CORE wxDragImage; | |
35 | struct WXDLLIMPEXP_FWD_CORE wxTreeViewItem; | |
36 | ||
37 | #if WXWIN_COMPATIBILITY_2_6 | |
38 | // NB: all the following flags are for compatbility only and will be removed in the | |
39 | // next versions | |
40 | // flags for deprecated InsertItem() variant (their values are the same as of | |
41 | // TVI_FIRST and TVI_LAST) | |
42 | #define wxTREE_INSERT_FIRST 0xFFFF0001 | |
43 | #define wxTREE_INSERT_LAST 0xFFFF0002 | |
44 | #endif | |
45 | ||
46 | // hash storing attributes for our items | |
47 | WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr); | |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // wxTreeCtrl | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | class WXDLLIMPEXP_CORE wxTreeCtrl : public wxTreeCtrlBase | |
54 | { | |
55 | public: | |
56 | // creation | |
57 | // -------- | |
58 | wxTreeCtrl() { Init(); } | |
59 | ||
60 | wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, | |
61 | const wxPoint& pos = wxDefaultPosition, | |
62 | const wxSize& size = wxDefaultSize, | |
63 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
64 | const wxValidator& validator = wxDefaultValidator, | |
65 | const wxString& name = wxTreeCtrlNameStr) | |
66 | { | |
67 | Create(parent, id, pos, size, style, validator, name); | |
68 | } | |
69 | ||
70 | virtual ~wxTreeCtrl(); | |
71 | ||
72 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, | |
73 | const wxPoint& pos = wxDefaultPosition, | |
74 | const wxSize& size = wxDefaultSize, | |
75 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
76 | const wxValidator& validator = wxDefaultValidator, | |
77 | const wxString& name = wxTreeCtrlNameStr); | |
78 | ||
79 | // implement base class pure virtuals | |
80 | // ---------------------------------- | |
81 | ||
82 | virtual unsigned int GetCount() const; | |
83 | ||
84 | virtual unsigned int GetIndent() const; | |
85 | virtual void SetIndent(unsigned int indent); | |
86 | ||
87 | virtual void SetImageList(wxImageList *imageList); | |
88 | virtual void SetStateImageList(wxImageList *imageList); | |
89 | ||
90 | virtual wxString GetItemText(const wxTreeItemId& item) const; | |
91 | virtual int GetItemImage(const wxTreeItemId& item, | |
92 | wxTreeItemIcon which = wxTreeItemIcon_Normal) const; | |
93 | virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const; | |
94 | virtual wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
95 | virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
96 | virtual wxFont GetItemFont(const wxTreeItemId& item) const; | |
97 | ||
98 | virtual void SetItemText(const wxTreeItemId& item, const wxString& text); | |
99 | virtual void SetItemImage(const wxTreeItemId& item, int image, | |
100 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
101 | virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
102 | virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true); | |
103 | virtual void SetItemBold(const wxTreeItemId& item, bool bold = true); | |
104 | virtual void SetItemDropHighlight(const wxTreeItemId& item, | |
105 | bool highlight = true); | |
106 | virtual void SetItemTextColour(const wxTreeItemId& item, | |
107 | const wxColour& col); | |
108 | virtual void SetItemBackgroundColour(const wxTreeItemId& item, | |
109 | const wxColour& col); | |
110 | virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
111 | ||
112 | // item status inquiries | |
113 | // --------------------- | |
114 | ||
115 | virtual bool IsVisible(const wxTreeItemId& item) const; | |
116 | virtual bool ItemHasChildren(const wxTreeItemId& item) const; | |
117 | virtual bool IsExpanded(const wxTreeItemId& item) const; | |
118 | virtual bool IsSelected(const wxTreeItemId& item) const; | |
119 | virtual bool IsBold(const wxTreeItemId& item) const; | |
120 | ||
121 | virtual size_t GetChildrenCount(const wxTreeItemId& item, | |
122 | bool recursively = true) const; | |
123 | ||
124 | // navigation | |
125 | // ---------- | |
126 | ||
127 | virtual wxTreeItemId GetRootItem() const; | |
128 | virtual wxTreeItemId GetSelection() const; | |
129 | virtual size_t GetSelections(wxArrayTreeItemIds& selections) const; | |
130 | ||
131 | virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const; | |
132 | virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, | |
133 | wxTreeItemIdValue& cookie) const; | |
134 | virtual wxTreeItemId GetNextChild(const wxTreeItemId& item, | |
135 | wxTreeItemIdValue& cookie) const; | |
136 | virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
137 | ||
138 | virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
139 | virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
140 | ||
141 | virtual wxTreeItemId GetFirstVisibleItem() const; | |
142 | virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
143 | virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
144 | ||
145 | // operations | |
146 | // ---------- | |
147 | ||
148 | virtual wxTreeItemId AddRoot(const wxString& text, | |
149 | int image = -1, int selectedImage = -1, | |
150 | wxTreeItemData *data = NULL); | |
151 | ||
152 | virtual void Delete(const wxTreeItemId& item); | |
153 | virtual void DeleteChildren(const wxTreeItemId& item); | |
154 | virtual void DeleteAllItems(); | |
155 | ||
156 | virtual void Expand(const wxTreeItemId& item); | |
157 | virtual void Collapse(const wxTreeItemId& item); | |
158 | virtual void CollapseAndReset(const wxTreeItemId& item); | |
159 | virtual void Toggle(const wxTreeItemId& item); | |
160 | ||
161 | virtual void Unselect(); | |
162 | virtual void UnselectAll(); | |
163 | virtual void SelectItem(const wxTreeItemId& item, bool select = true); | |
164 | ||
165 | virtual void EnsureVisible(const wxTreeItemId& item); | |
166 | virtual void ScrollTo(const wxTreeItemId& item); | |
167 | ||
168 | virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, | |
169 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
170 | virtual wxTextCtrl *GetEditControl() const; | |
171 | virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item), | |
172 | bool discardChanges = false) | |
173 | { | |
174 | DoEndEditLabel(discardChanges); | |
175 | } | |
176 | ||
177 | virtual void SortChildren(const wxTreeItemId& item); | |
178 | ||
179 | virtual bool GetBoundingRect(const wxTreeItemId& item, | |
180 | wxRect& rect, | |
181 | bool textOnly = false) const; | |
182 | ||
183 | // implementation | |
184 | // -------------- | |
185 | ||
186 | virtual wxVisualAttributes GetDefaultAttributes() const | |
187 | { | |
188 | return GetClassDefaultAttributes(GetWindowVariant()); | |
189 | } | |
190 | ||
191 | static wxVisualAttributes | |
192 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
193 | ||
194 | ||
195 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
196 | virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
197 | virtual bool MSWCommand(WXUINT param, WXWORD id); | |
198 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); | |
199 | virtual bool MSWShouldPreProcessMessage(WXMSG* msg); | |
200 | ||
201 | // override some base class virtuals | |
202 | virtual bool SetBackgroundColour(const wxColour &colour); | |
203 | virtual bool SetForegroundColour(const wxColour &colour); | |
204 | ||
205 | // returns true if the platform should explicitly apply a theme border | |
206 | virtual bool CanApplyThemeBorder() const { return false; } | |
207 | ||
208 | protected: | |
209 | // SetImageList helper | |
210 | void SetAnyImageList(wxImageList *imageList, int which); | |
211 | ||
212 | // refresh a single item | |
213 | void RefreshItem(const wxTreeItemId& item); | |
214 | ||
215 | // end edit label | |
216 | void DoEndEditLabel(bool discardChanges = false); | |
217 | ||
218 | virtual int DoGetItemState(const wxTreeItemId& item) const; | |
219 | virtual void DoSetItemState(const wxTreeItemId& item, int state); | |
220 | ||
221 | virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent, | |
222 | size_t pos, | |
223 | const wxString& text, | |
224 | int image, int selectedImage, | |
225 | wxTreeItemData *data); | |
226 | virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent, | |
227 | const wxTreeItemId& idPrevious, | |
228 | const wxString& text, | |
229 | int image = -1, int selImage = -1, | |
230 | wxTreeItemData *data = NULL); | |
231 | virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const; | |
232 | ||
233 | // obtain the user data for the lParam member of TV_ITEM | |
234 | class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const; | |
235 | ||
236 | ||
237 | // data used only while editing the item label: | |
238 | wxTextCtrl *m_textCtrl; // text control in which it is edited | |
239 | wxTreeItemId m_idEdited; // the item being edited | |
240 | ||
241 | private: | |
242 | // the common part of all ctors | |
243 | void Init(); | |
244 | ||
245 | // helper functions | |
246 | bool DoGetItem(wxTreeViewItem *tvItem) const; | |
247 | void DoSetItem(wxTreeViewItem *tvItem); | |
248 | ||
249 | void DoExpand(const wxTreeItemId& item, int flag); | |
250 | ||
251 | void DeleteTextCtrl(); | |
252 | ||
253 | // return true if the item is the hidden root one (i.e. it's the root item | |
254 | // and the tree has wxTR_HIDE_ROOT style) | |
255 | bool IsHiddenRoot(const wxTreeItemId& item) const; | |
256 | ||
257 | ||
258 | // the hash storing the items attributes (indexed by item ids) | |
259 | wxMapTreeAttr m_attrs; | |
260 | ||
261 | // true if the hash above is not empty | |
262 | bool m_hasAnyAttr; | |
263 | ||
264 | #if wxUSE_DRAGIMAGE | |
265 | // used for dragging | |
266 | wxDragImage *m_dragImage; | |
267 | #endif | |
268 | ||
269 | // Virtual root item, if wxTR_HIDE_ROOT is set. | |
270 | void* m_pVirtualRoot; | |
271 | ||
272 | // the starting item for selection with Shift | |
273 | wxTreeItemId m_htSelStart, m_htClickedItem; | |
274 | wxPoint m_ptClick; | |
275 | ||
276 | friend class wxTreeItemIndirectData; | |
277 | friend class wxTreeSortHelper; | |
278 | ||
279 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
280 | wxDECLARE_NO_COPY_CLASS(wxTreeCtrl); | |
281 | }; | |
282 | ||
283 | #endif // wxUSE_TREECTRL | |
284 | ||
285 | #endif // _WX_MSW_TREECTRL_H_ |