]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/treectrl.h
Reuse wxMessageOutputStderr for wxLogStderr implementation.
[wxWidgets.git] / include / wx / msw / treectrl.h
CommitLineData
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
fb1a4789
VZ
33class WXDLLIMPEXP_FWD_CORE wxImageList;
34class WXDLLIMPEXP_FWD_CORE wxDragImage;
b5dbe15d 35struct WXDLLIMPEXP_FWD_CORE 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 47WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
ee4b2721 48
08b7c251
VZ
49// ----------------------------------------------------------------------------
50// wxTreeCtrl
51// ----------------------------------------------------------------------------
ee4b2721 52
53a2db12 53class WXDLLIMPEXP_CORE wxTreeCtrl : public wxTreeCtrlBase
2bda0e17 54{
092bddef 55public:
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;
3c01c595 130 virtual wxTreeItemId GetFocusedItem() const;
8cee4a30 131
5708ae18
VZ
132 virtual void ClearFocusedItem();
133 virtual void SetFocusedItem(const wxTreeItemId& item);
134
135
8cee4a30
VZ
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;
08b7c251 149
092bddef
VZ
150 // operations
151 // ----------
08b7c251 152
a78955e3 153 virtual wxTreeItemId AddRoot(const wxString& text,
08b7c251
VZ
154 int image = -1, int selectedImage = -1,
155 wxTreeItemData *data = NULL);
156
8cee4a30
VZ
157 virtual void Delete(const wxTreeItemId& item);
158 virtual void DeleteChildren(const wxTreeItemId& item);
159 virtual void DeleteAllItems();
08b7c251 160
8cee4a30
VZ
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);
08b7c251 165
8cee4a30
VZ
166 virtual void Unselect();
167 virtual void UnselectAll();
168 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
5cb3a695 169 virtual void SelectChildren(const wxTreeItemId& parent);
2ef31e80 170
8cee4a30
VZ
171 virtual void EnsureVisible(const wxTreeItemId& item);
172 virtual void ScrollTo(const wxTreeItemId& item);
173
174 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
b19b28c8 175 wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl));
8cee4a30
VZ
176 virtual wxTextCtrl *GetEditControl() const;
177 virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
178 bool discardChanges = false)
d35dce3a
VZ
179 {
180 DoEndEditLabel(discardChanges);
181 }
08b7c251 182
8cee4a30
VZ
183 virtual void SortChildren(const wxTreeItemId& item);
184
185 virtual bool GetBoundingRect(const wxTreeItemId& item,
186 wxRect& rect,
187 bool textOnly = false) const;
08b7c251 188
08b7c251
VZ
189 // implementation
190 // --------------
3f7bc32b 191
39c7a53c
VZ
192 virtual wxVisualAttributes GetDefaultAttributes() const
193 {
194 return GetClassDefaultAttributes(GetWindowVariant());
195 }
196
197 static wxVisualAttributes
198 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
199
200
c140b7e7 201 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fbd8ac52 202 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fd3f686c 203 virtual bool MSWCommand(WXUINT param, WXWORD id);
a23fd0e1 204 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
90c6edd7 205 virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
08b7c251 206
bb448552
VZ
207 // override some base class virtuals
208 virtual bool SetBackgroundColour(const wxColour &colour);
209 virtual bool SetForegroundColour(const wxColour &colour);
210
a047aff2
JS
211 // returns true if the platform should explicitly apply a theme border
212 virtual bool CanApplyThemeBorder() const { return false; }
213
2bda0e17 214protected:
6754c300
VZ
215 // Implement "update locking" in a custom way for this control.
216 virtual void DoFreeze();
217 virtual void DoThaw();
218
4e1e8dc5
VZ
219 virtual void DoSetSize(int x, int y,
220 int width, int height,
221 int sizeFlags = wxSIZE_AUTO);
222
08b7c251
VZ
223 // SetImageList helper
224 void SetAnyImageList(wxImageList *imageList, int which);
225
d00407b2
VZ
226 // refresh a single item
227 void RefreshItem(const wxTreeItemId& item);
228
d35dce3a
VZ
229 // end edit label
230 void DoEndEditLabel(bool discardChanges = false);
231
03966fcb
RR
232 virtual int DoGetItemState(const wxTreeItemId& item) const;
233 virtual void DoSetItemState(const wxTreeItemId& item, int state);
234
8cee4a30
VZ
235 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
236 size_t pos,
237 const wxString& text,
238 int image, int selectedImage,
239 wxTreeItemData *data);
240 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
241 const wxTreeItemId& idPrevious,
242 const wxString& text,
243 int image = -1, int selImage = -1,
244 wxTreeItemData *data = NULL);
be0e5d69 245 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
08b7c251 246
4523ebb3
VZ
247 // obtain the user data for the lParam member of TV_ITEM
248 class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const;
249
c7d9c476
VZ
250 // update the event to include the items client data and pass it to
251 // HandleWindowEvent(), return true if it processed it
252 bool HandleTreeEvent(wxTreeEvent& event) const;
253
254 // pass the event to HandleTreeEvent() and return true if the event was
255 // either unprocessed or not vetoed
256 bool IsTreeEventAllowed(wxTreeEvent& event) const
257 {
258 return !HandleTreeEvent(event) || event.IsAllowed();
259 }
260
aa8166dd
VZ
261 // generate a wxEVT_KEY_DOWN event from the specified WPARAM/LPARAM values
262 // having the same meaning as for WM_KEYDOWN, return true if it was
263 // processed
264 bool MSWHandleTreeKeyDownEvent(WXWPARAM wParam, WXLPARAM lParam);
265
266 // handle a key event in a multi-selection control, should be only called
267 // for keys which can be used to change the selection
c7d9c476
VZ
268 //
269 // return true if the key was processed, false otherwise
25f701e6 270 bool MSWHandleSelectionKey(unsigned vkey);
c7d9c476 271
4523ebb3
VZ
272
273 // data used only while editing the item label:
274 wxTextCtrl *m_textCtrl; // text control in which it is edited
275 wxTreeItemId m_idEdited; // the item being edited
276
6f02a879
VZ
277private:
278 // the common part of all ctors
279 void Init();
280
ae322a48 281 // helper functions
ffdbfc4a
PC
282 bool DoGetItem(wxTreeViewItem *tvItem) const;
283 void DoSetItem(wxTreeViewItem *tvItem);
6f02a879 284
ffdbfc4a 285 void DoExpand(const wxTreeItemId& item, int flag);
6f02a879 286
7dac12ef
VZ
287 void DoSelectItem(const wxTreeItemId& item, bool select = true);
288 void DoUnselectItem(const wxTreeItemId& item);
289 void DoToggleItemSelection(const wxTreeItemId& item);
290
c7d9c476 291 void DoUnselectAll();
5cb3a695 292 void DoSelectChildren(const wxTreeItemId& parent);
c7d9c476 293
08b7c251 294 void DeleteTextCtrl();
092bddef 295
0228081f
VZ
296 // return true if the item is the hidden root one (i.e. it's the root item
297 // and the tree has wxTR_HIDE_ROOT style)
298 bool IsHiddenRoot(const wxTreeItemId& item) const;
299
300
3c8cbc12
VZ
301 // check if the given flags (taken from TV_HITTESTINFO structure)
302 // indicate a position "on item": this is less trivial than just checking
303 // for TVHT_ONITEM because we consider that points to the left and right of
304 // item text are also "on item" when wxTR_FULL_ROW_HIGHLIGHT is used as the
305 // item visually spans the entire breadth of the window then
306 bool MSWIsOnItem(unsigned flags) const;
307
308
ee4b2721
VZ
309 // the hash storing the items attributes (indexed by item ids)
310 wxMapTreeAttr m_attrs;
696e1ea0 311
dabbc6a5 312 // true if the hash above is not empty
696e1ea0
VZ
313 bool m_hasAnyAttr;
314
68d9be05 315#if wxUSE_DRAGIMAGE
23f681ec
VZ
316 // used for dragging
317 wxDragImage *m_dragImage;
68d9be05 318#endif
23f681ec 319
a9c1265f
VZ
320 // Virtual root item, if wxTR_HIDE_ROOT is set.
321 void* m_pVirtualRoot;
322
3f7bc32b 323 // the starting item for selection with Shift
e3ad5702
JS
324 wxTreeItemId m_htSelStart, m_htClickedItem;
325 wxPoint m_ptClick;
3f7bc32b 326
c7d9c476
VZ
327 // whether dragging has started
328 bool m_dragStarted;
329
330 // whether focus was lost between subsequent clicks of a single item
331 bool m_focusLost;
332
7dac12ef
VZ
333 // set when we are changing selection ourselves (only used in multi
334 // selection mode)
335 bool m_changingSelection;
336
c7d9c476
VZ
337 // whether we need to trigger a state image click event
338 bool m_triggerStateImageClick;
339
d301c440
VZ
340 // whether we need to deselect other items on mouse up
341 bool m_mouseUpDeselect;
342
4e1e8dc5
VZ
343 // The size to restore the control to when it is thawed, see DoThaw().
344 wxSize m_thawnSize;
345
502a2b18
VZ
346 friend class wxTreeItemIndirectData;
347 friend class wxTreeSortHelper;
348
092bddef 349 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
c0c133e1 350 wxDECLARE_NO_COPY_CLASS(wxTreeCtrl);
2bda0e17
KB
351};
352
1e6feb95
VZ
353#endif // wxUSE_TREECTRL
354
0228081f 355#endif // _WX_MSW_TREECTRL_H_