]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3f7bc32b | 2 | // Name: wx/msw/treectrl.h |
2bda0e17 KB |
3 | // Purpose: wxTreeCtrl class |
4 | // Author: Julian Smart | |
08b7c251 | 5 | // Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98 |
2bda0e17 KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
371a5b4e | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
0228081f VZ |
12 | #ifndef _WX_MSW_TREECTRL_H_ |
13 | #define _WX_MSW_TREECTRL_H_ | |
2bda0e17 | 14 | |
08b7c251 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
d427503c | 18 | |
1e6feb95 VZ |
19 | #if wxUSE_TREECTRL |
20 | ||
ad5c34f3 | 21 | #include "wx/textctrl.h" |
2899e223 | 22 | #include "wx/dynarray.h" |
484523cf | 23 | #include "wx/treebase.h" |
ee4b2721 | 24 | #include "wx/hashmap.h" |
2bda0e17 | 25 | |
d427503c VZ |
26 | #ifdef __GNUWIN32__ |
27 | // Cygwin windows.h defines these identifiers | |
28 | #undef GetFirstChild | |
29 | #undef GetNextSibling | |
30 | #endif // Cygwin | |
31 | ||
08b7c251 | 32 | // fwd decl |
06e38c8e | 33 | class WXDLLEXPORT wxImageList; |
23f681ec | 34 | class WXDLLEXPORT wxDragImage; |
06e38c8e | 35 | struct WXDLLEXPORT wxTreeViewItem; |
08b7c251 | 36 | |
989ab1e5 WS |
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 | |
2bda0e17 | 45 | |
ee4b2721 | 46 | // hash storing attributes for our items |
3f5c62f9 | 47 | WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr); |
ee4b2721 | 48 | |
08b7c251 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // wxTreeCtrl | |
51 | // ---------------------------------------------------------------------------- | |
ee4b2721 | 52 | |
8cee4a30 | 53 | class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase |
2bda0e17 | 54 | { |
092bddef | 55 | public: |
092bddef VZ |
56 | // creation |
57 | // -------- | |
08b7c251 VZ |
58 | wxTreeCtrl() { Init(); } |
59 | ||
dabbc6a5 | 60 | wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, |
08b7c251 VZ |
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, | |
2b5f62a0 | 65 | const wxString& name = wxTreeCtrlNameStr) |
092bddef VZ |
66 | { |
67 | Create(parent, id, pos, size, style, validator, name); | |
68 | } | |
08b7c251 VZ |
69 | |
70 | virtual ~wxTreeCtrl(); | |
71 | ||
dabbc6a5 | 72 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, |
092bddef VZ |
73 | const wxPoint& pos = wxDefaultPosition, |
74 | const wxSize& size = wxDefaultSize, | |
08b7c251 | 75 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, |
092bddef | 76 | const wxValidator& validator = wxDefaultValidator, |
2b5f62a0 | 77 | const wxString& name = wxTreeCtrlNameStr); |
08b7c251 | 78 | |
8cee4a30 VZ |
79 | // implement base class pure virtuals |
80 | // ---------------------------------- | |
08b7c251 | 81 | |
027d45e8 | 82 | virtual unsigned int GetCount() const; |
08b7c251 | 83 | |
8cee4a30 VZ |
84 | virtual unsigned int GetIndent() const; |
85 | virtual void SetIndent(unsigned int indent); | |
08b7c251 | 86 | |
8cee4a30 VZ |
87 | virtual void SetImageList(wxImageList *imageList); |
88 | virtual void SetStateImageList(wxImageList *imageList); | |
08b7c251 | 89 | |
8cee4a30 | 90 | virtual wxString GetItemText(const wxTreeItemId& item) const; |
a78955e3 | 91 | virtual int GetItemImage(const wxTreeItemId& item, |
8cee4a30 VZ |
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; | |
2b5f62a0 | 97 | |
8cee4a30 | 98 | virtual void SetItemText(const wxTreeItemId& item, const wxString& text); |
a78955e3 | 99 | virtual void SetItemImage(const wxTreeItemId& item, int image, |
74b31181 | 100 | wxTreeItemIcon which = wxTreeItemIcon_Normal); |
8cee4a30 VZ |
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); | |
9ec64fa7 | 111 | |
08b7c251 VZ |
112 | // item status inquiries |
113 | // --------------------- | |
114 | ||
8cee4a30 VZ |
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; | |
4832f7c0 | 123 | |
08b7c251 VZ |
124 | // navigation |
125 | // ---------- | |
126 | ||
8cee4a30 VZ |
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; | |
08b7c251 | 144 | |
092bddef VZ |
145 | // operations |
146 | // ---------- | |
08b7c251 | 147 | |
a78955e3 | 148 | virtual wxTreeItemId AddRoot(const wxString& text, |
08b7c251 VZ |
149 | int image = -1, int selectedImage = -1, |
150 | wxTreeItemData *data = NULL); | |
151 | ||
8cee4a30 VZ |
152 | virtual void Delete(const wxTreeItemId& item); |
153 | virtual void DeleteChildren(const wxTreeItemId& item); | |
154 | virtual void DeleteAllItems(); | |
08b7c251 | 155 | |
8cee4a30 VZ |
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); | |
08b7c251 | 160 | |
8cee4a30 VZ |
161 | virtual void Unselect(); |
162 | virtual void UnselectAll(); | |
163 | virtual void SelectItem(const wxTreeItemId& item, bool select = true); | |
2ef31e80 | 164 | |
8cee4a30 VZ |
165 | virtual void EnsureVisible(const wxTreeItemId& item); |
166 | virtual void ScrollTo(const wxTreeItemId& item); | |
167 | ||
168 | virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, | |
08b7c251 | 169 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); |
8cee4a30 VZ |
170 | virtual wxTextCtrl *GetEditControl() const; |
171 | virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item), | |
172 | bool discardChanges = false) | |
d35dce3a VZ |
173 | { |
174 | DoEndEditLabel(discardChanges); | |
175 | } | |
08b7c251 | 176 | |
8cee4a30 VZ |
177 | virtual void SortChildren(const wxTreeItemId& item); |
178 | ||
179 | virtual bool GetBoundingRect(const wxTreeItemId& item, | |
180 | wxRect& rect, | |
181 | bool textOnly = false) const; | |
08b7c251 | 182 | |
08b7c251 VZ |
183 | // deprecated |
184 | // ---------- | |
185 | ||
ee4b2721 | 186 | #if WXWIN_COMPATIBILITY_2_4 |
08b7c251 | 187 | // these methods are deprecated and will be removed in future versions of |
77ffb593 | 188 | // wxWidgets, they're here for compatibility only, don't use them in new |
08b7c251 VZ |
189 | // code (the comments indicate why these methods are now useless and how to |
190 | // replace them) | |
191 | ||
192 | // use Expand, Collapse, CollapseAndReset or Toggle | |
ee4b2721 | 193 | wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) ); |
08b7c251 | 194 | |
08b7c251 | 195 | // use Set/GetImageList and Set/GetStateImageList |
bb0d2f03 | 196 | // Use base class GetImageList() |
a6fb8636 | 197 | wxDEPRECATED( void SetImageList(wxImageList *imageList, int) ); |
08b7c251 | 198 | |
989ab1e5 | 199 | // use Set/GetItemImage directly |
a6fb8636 WS |
200 | wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const ); |
201 | wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) ); | |
74b31181 | 202 | |
ee4b2721 VZ |
203 | // use the versions taking wxTreeItemIdValue cookies |
204 | wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item, | |
205 | long& cookie) const ); | |
206 | wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item, | |
207 | long& cookie) const ); | |
208 | #endif // WXWIN_COMPATIBILITY_2_4 | |
209 | ||
d4864e97 | 210 | |
08b7c251 VZ |
211 | // implementation |
212 | // -------------- | |
3f7bc32b | 213 | |
39c7a53c VZ |
214 | virtual wxVisualAttributes GetDefaultAttributes() const |
215 | { | |
216 | return GetClassDefaultAttributes(GetWindowVariant()); | |
217 | } | |
218 | ||
219 | static wxVisualAttributes | |
220 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
221 | ||
222 | ||
c140b7e7 | 223 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); |
fbd8ac52 | 224 | virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); |
fd3f686c | 225 | virtual bool MSWCommand(WXUINT param, WXWORD id); |
a23fd0e1 | 226 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); |
90c6edd7 | 227 | virtual bool MSWShouldPreProcessMessage(WXMSG* msg); |
08b7c251 | 228 | |
bb448552 VZ |
229 | // override some base class virtuals |
230 | virtual bool SetBackgroundColour(const wxColour &colour); | |
231 | virtual bool SetForegroundColour(const wxColour &colour); | |
232 | ||
9dfbf520 VZ |
233 | // get/set the check state for the item (only for wxTR_MULTIPLE) |
234 | bool IsItemChecked(const wxTreeItemId& item) const; | |
dabbc6a5 | 235 | void SetItemCheck(const wxTreeItemId& item, bool check = true); |
9dfbf520 | 236 | |
8a000b6b VZ |
237 | // set/get the item state.image (state == -1 means cycle to the next one) |
238 | void SetState(const wxTreeItemId& node, int state); | |
239 | int GetState(const wxTreeItemId& node); | |
240 | ||
2bda0e17 | 241 | protected: |
08b7c251 VZ |
242 | // SetImageList helper |
243 | void SetAnyImageList(wxImageList *imageList, int which); | |
244 | ||
d00407b2 VZ |
245 | // refresh a single item |
246 | void RefreshItem(const wxTreeItemId& item); | |
247 | ||
d35dce3a VZ |
248 | // end edit label |
249 | void DoEndEditLabel(bool discardChanges = false); | |
250 | ||
8cee4a30 VZ |
251 | virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent, |
252 | size_t pos, | |
253 | const wxString& text, | |
254 | int image, int selectedImage, | |
255 | wxTreeItemData *data); | |
256 | virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent, | |
257 | const wxTreeItemId& idPrevious, | |
258 | const wxString& text, | |
259 | int image = -1, int selImage = -1, | |
260 | wxTreeItemData *data = NULL); | |
be0e5d69 | 261 | virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const; |
08b7c251 | 262 | |
4523ebb3 VZ |
263 | // obtain the user data for the lParam member of TV_ITEM |
264 | class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const; | |
265 | ||
266 | ||
267 | // data used only while editing the item label: | |
268 | wxTextCtrl *m_textCtrl; // text control in which it is edited | |
269 | wxTreeItemId m_idEdited; // the item being edited | |
270 | ||
6f02a879 VZ |
271 | private: |
272 | // the common part of all ctors | |
273 | void Init(); | |
274 | ||
275 | // helper functions | |
276 | inline bool DoGetItem(wxTreeViewItem *tvItem) const; | |
277 | inline void DoSetItem(wxTreeViewItem *tvItem); | |
278 | ||
279 | inline void DoExpand(const wxTreeItemId& item, int flag); | |
280 | ||
08b7c251 | 281 | void DeleteTextCtrl(); |
092bddef | 282 | |
0228081f VZ |
283 | // return true if the item is the hidden root one (i.e. it's the root item |
284 | // and the tree has wxTR_HIDE_ROOT style) | |
285 | bool IsHiddenRoot(const wxTreeItemId& item) const; | |
286 | ||
287 | ||
ee4b2721 VZ |
288 | // the hash storing the items attributes (indexed by item ids) |
289 | wxMapTreeAttr m_attrs; | |
696e1ea0 | 290 | |
dabbc6a5 | 291 | // true if the hash above is not empty |
696e1ea0 VZ |
292 | bool m_hasAnyAttr; |
293 | ||
23f681ec VZ |
294 | // used for dragging |
295 | wxDragImage *m_dragImage; | |
296 | ||
a9c1265f VZ |
297 | // Virtual root item, if wxTR_HIDE_ROOT is set. |
298 | void* m_pVirtualRoot; | |
299 | ||
3f7bc32b | 300 | // the starting item for selection with Shift |
e3ad5702 JS |
301 | wxTreeItemId m_htSelStart, m_htClickedItem; |
302 | wxPoint m_ptClick; | |
3f7bc32b | 303 | |
502a2b18 VZ |
304 | friend class wxTreeItemIndirectData; |
305 | friend class wxTreeSortHelper; | |
306 | ||
092bddef | 307 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) |
22f3361e | 308 | DECLARE_NO_COPY_CLASS(wxTreeCtrl) |
2bda0e17 KB |
309 | }; |
310 | ||
1e6feb95 VZ |
311 | #endif // wxUSE_TREECTRL |
312 | ||
0228081f | 313 | #endif // _WX_MSW_TREECTRL_H_ |