]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/treectrl.h
Mention wxGTK wxAnimation implementation limitations in the docs.
[wxWidgets.git] / include / wx / msw / treectrl.h
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 virtual wxTreeItemId GetFocusedItem() const;
131
132 virtual void ClearFocusedItem();
133 virtual void SetFocusedItem(const wxTreeItemId& item);
134
135
136 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
137 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
138 wxTreeItemIdValue& cookie) const;
139 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
140 wxTreeItemIdValue& cookie) const;
141 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
142
143 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
144 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
145
146 virtual wxTreeItemId GetFirstVisibleItem() const;
147 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
148 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
149
150 // operations
151 // ----------
152
153 virtual wxTreeItemId AddRoot(const wxString& text,
154 int image = -1, int selectedImage = -1,
155 wxTreeItemData *data = NULL);
156
157 virtual void Delete(const wxTreeItemId& item);
158 virtual void DeleteChildren(const wxTreeItemId& item);
159 virtual void DeleteAllItems();
160
161 virtual void Expand(const wxTreeItemId& item);
162 virtual void Collapse(const wxTreeItemId& item);
163 virtual void CollapseAndReset(const wxTreeItemId& item);
164 virtual void Toggle(const wxTreeItemId& item);
165
166 virtual void Unselect();
167 virtual void UnselectAll();
168 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
169 virtual void SelectChildren(const wxTreeItemId& parent);
170
171 virtual void EnsureVisible(const wxTreeItemId& item);
172 virtual void ScrollTo(const wxTreeItemId& item);
173
174 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
175 wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl));
176 virtual wxTextCtrl *GetEditControl() const;
177 virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
178 bool discardChanges = false)
179 {
180 DoEndEditLabel(discardChanges);
181 }
182
183 virtual void SortChildren(const wxTreeItemId& item);
184
185 virtual bool GetBoundingRect(const wxTreeItemId& item,
186 wxRect& rect,
187 bool textOnly = false) const;
188
189 // implementation
190 // --------------
191
192 virtual wxVisualAttributes GetDefaultAttributes() const
193 {
194 return GetClassDefaultAttributes(GetWindowVariant());
195 }
196
197 static wxVisualAttributes
198 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
199
200
201 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
202 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
203 virtual bool MSWCommand(WXUINT param, WXWORD id);
204 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
205 virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
206
207 // override some base class virtuals
208 virtual bool SetBackgroundColour(const wxColour &colour);
209 virtual bool SetForegroundColour(const wxColour &colour);
210
211 // returns true if the platform should explicitly apply a theme border
212 virtual bool CanApplyThemeBorder() const { return false; }
213
214 protected:
215 // SetImageList helper
216 void SetAnyImageList(wxImageList *imageList, int which);
217
218 // refresh a single item
219 void RefreshItem(const wxTreeItemId& item);
220
221 // end edit label
222 void DoEndEditLabel(bool discardChanges = false);
223
224 virtual int DoGetItemState(const wxTreeItemId& item) const;
225 virtual void DoSetItemState(const wxTreeItemId& item, int state);
226
227 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
228 size_t pos,
229 const wxString& text,
230 int image, int selectedImage,
231 wxTreeItemData *data);
232 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
233 const wxTreeItemId& idPrevious,
234 const wxString& text,
235 int image = -1, int selImage = -1,
236 wxTreeItemData *data = NULL);
237 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
238
239 // obtain the user data for the lParam member of TV_ITEM
240 class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const;
241
242 // update the event to include the items client data and pass it to
243 // HandleWindowEvent(), return true if it processed it
244 bool HandleTreeEvent(wxTreeEvent& event) const;
245
246 // pass the event to HandleTreeEvent() and return true if the event was
247 // either unprocessed or not vetoed
248 bool IsTreeEventAllowed(wxTreeEvent& event) const
249 {
250 return !HandleTreeEvent(event) || event.IsAllowed();
251 }
252
253 // generate a wxEVT_KEY_DOWN event from the specified WPARAM/LPARAM values
254 // having the same meaning as for WM_KEYDOWN, return true if it was
255 // processed
256 bool MSWHandleTreeKeyDownEvent(WXWPARAM wParam, WXLPARAM lParam);
257
258 // handle a key event in a multi-selection control, should be only called
259 // for keys which can be used to change the selection
260 //
261 // return true if the key was processed, false otherwise
262 bool MSWHandleSelectionKey(unsigned vkey);
263
264
265 // data used only while editing the item label:
266 wxTextCtrl *m_textCtrl; // text control in which it is edited
267 wxTreeItemId m_idEdited; // the item being edited
268
269 private:
270 // the common part of all ctors
271 void Init();
272
273 // helper functions
274 bool DoGetItem(wxTreeViewItem *tvItem) const;
275 void DoSetItem(wxTreeViewItem *tvItem);
276
277 void DoExpand(const wxTreeItemId& item, int flag);
278
279 void DoSelectItem(const wxTreeItemId& item, bool select = true);
280 void DoUnselectItem(const wxTreeItemId& item);
281 void DoToggleItemSelection(const wxTreeItemId& item);
282
283 void DoUnselectAll();
284 void DoSelectChildren(const wxTreeItemId& parent);
285
286 void DeleteTextCtrl();
287
288 // return true if the item is the hidden root one (i.e. it's the root item
289 // and the tree has wxTR_HIDE_ROOT style)
290 bool IsHiddenRoot(const wxTreeItemId& item) const;
291
292
293 // check if the given flags (taken from TV_HITTESTINFO structure)
294 // indicate a position "on item": this is less trivial than just checking
295 // for TVHT_ONITEM because we consider that points to the left and right of
296 // item text are also "on item" when wxTR_FULL_ROW_HIGHLIGHT is used as the
297 // item visually spans the entire breadth of the window then
298 bool MSWIsOnItem(unsigned flags) const;
299
300
301 // the hash storing the items attributes (indexed by item ids)
302 wxMapTreeAttr m_attrs;
303
304 // true if the hash above is not empty
305 bool m_hasAnyAttr;
306
307 #if wxUSE_DRAGIMAGE
308 // used for dragging
309 wxDragImage *m_dragImage;
310 #endif
311
312 // Virtual root item, if wxTR_HIDE_ROOT is set.
313 void* m_pVirtualRoot;
314
315 // the starting item for selection with Shift
316 wxTreeItemId m_htSelStart, m_htClickedItem;
317 wxPoint m_ptClick;
318
319 // whether dragging has started
320 bool m_dragStarted;
321
322 // whether focus was lost between subsequent clicks of a single item
323 bool m_focusLost;
324
325 // set when we are changing selection ourselves (only used in multi
326 // selection mode)
327 bool m_changingSelection;
328
329 // whether we need to trigger a state image click event
330 bool m_triggerStateImageClick;
331
332 // whether we need to deselect other items on mouse up
333 bool m_mouseUpDeselect;
334
335 friend class wxTreeItemIndirectData;
336 friend class wxTreeSortHelper;
337
338 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
339 wxDECLARE_NO_COPY_CLASS(wxTreeCtrl);
340 };
341
342 #endif // wxUSE_TREECTRL
343
344 #endif // _WX_MSW_TREECTRL_H_