]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/treectrl.h
Make wxComboCtrlBase::Set*groundColour() methods public.
[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 6// Created: 01/02/97
371a5b4e 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
0228081f
VZ
11#ifndef _WX_MSW_TREECTRL_H_
12#define _WX_MSW_TREECTRL_H_
2bda0e17 13
08b7c251
VZ
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
d427503c 17
1e6feb95
VZ
18#if wxUSE_TREECTRL
19
ad5c34f3 20#include "wx/textctrl.h"
2899e223 21#include "wx/dynarray.h"
484523cf 22#include "wx/treebase.h"
ee4b2721 23#include "wx/hashmap.h"
2bda0e17 24
d427503c
VZ
25#ifdef __GNUWIN32__
26 // Cygwin windows.h defines these identifiers
27 #undef GetFirstChild
28 #undef GetNextSibling
29#endif // Cygwin
30
08b7c251 31// fwd decl
fb1a4789
VZ
32class WXDLLIMPEXP_FWD_CORE wxImageList;
33class WXDLLIMPEXP_FWD_CORE wxDragImage;
b5dbe15d 34struct WXDLLIMPEXP_FWD_CORE wxTreeViewItem;
08b7c251 35
989ab1e5
WS
36#if WXWIN_COMPATIBILITY_2_6
37 // NB: all the following flags are for compatbility only and will be removed in the
38 // next versions
39 // flags for deprecated InsertItem() variant (their values are the same as of
40 // TVI_FIRST and TVI_LAST)
41 #define wxTREE_INSERT_FIRST 0xFFFF0001
42 #define wxTREE_INSERT_LAST 0xFFFF0002
43#endif
2bda0e17 44
ee4b2721 45// hash storing attributes for our items
3f5c62f9 46WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
ee4b2721 47
08b7c251
VZ
48// ----------------------------------------------------------------------------
49// wxTreeCtrl
50// ----------------------------------------------------------------------------
ee4b2721 51
53a2db12 52class WXDLLIMPEXP_CORE wxTreeCtrl : public wxTreeCtrlBase
2bda0e17 53{
092bddef 54public:
092bddef
VZ
55 // creation
56 // --------
08b7c251
VZ
57 wxTreeCtrl() { Init(); }
58
dabbc6a5 59 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
08b7c251
VZ
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
63 const wxValidator& validator = wxDefaultValidator,
2b5f62a0 64 const wxString& name = wxTreeCtrlNameStr)
092bddef
VZ
65 {
66 Create(parent, id, pos, size, style, validator, name);
67 }
08b7c251
VZ
68
69 virtual ~wxTreeCtrl();
70
dabbc6a5 71 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
092bddef
VZ
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize,
08b7c251 74 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
092bddef 75 const wxValidator& validator = wxDefaultValidator,
2b5f62a0 76 const wxString& name = wxTreeCtrlNameStr);
08b7c251 77
8cee4a30
VZ
78 // implement base class pure virtuals
79 // ----------------------------------
08b7c251 80
027d45e8 81 virtual unsigned int GetCount() const;
08b7c251 82
8cee4a30
VZ
83 virtual unsigned int GetIndent() const;
84 virtual void SetIndent(unsigned int indent);
08b7c251 85
8cee4a30
VZ
86 virtual void SetImageList(wxImageList *imageList);
87 virtual void SetStateImageList(wxImageList *imageList);
08b7c251 88
8cee4a30 89 virtual wxString GetItemText(const wxTreeItemId& item) const;
a78955e3 90 virtual int GetItemImage(const wxTreeItemId& item,
8cee4a30
VZ
91 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
92 virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
93 virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
94 virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
95 virtual wxFont GetItemFont(const wxTreeItemId& item) const;
2b5f62a0 96
8cee4a30 97 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
a78955e3 98 virtual void SetItemImage(const wxTreeItemId& item, int image,
74b31181 99 wxTreeItemIcon which = wxTreeItemIcon_Normal);
8cee4a30
VZ
100 virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
101 virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
102 virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
103 virtual void SetItemDropHighlight(const wxTreeItemId& item,
104 bool highlight = true);
105 virtual void SetItemTextColour(const wxTreeItemId& item,
106 const wxColour& col);
107 virtual void SetItemBackgroundColour(const wxTreeItemId& item,
108 const wxColour& col);
109 virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
9ec64fa7 110
08b7c251
VZ
111 // item status inquiries
112 // ---------------------
113
8cee4a30
VZ
114 virtual bool IsVisible(const wxTreeItemId& item) const;
115 virtual bool ItemHasChildren(const wxTreeItemId& item) const;
116 virtual bool IsExpanded(const wxTreeItemId& item) const;
117 virtual bool IsSelected(const wxTreeItemId& item) const;
118 virtual bool IsBold(const wxTreeItemId& item) const;
119
120 virtual size_t GetChildrenCount(const wxTreeItemId& item,
121 bool recursively = true) const;
4832f7c0 122
08b7c251
VZ
123 // navigation
124 // ----------
125
8cee4a30
VZ
126 virtual wxTreeItemId GetRootItem() const;
127 virtual wxTreeItemId GetSelection() const;
128 virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
3c01c595 129 virtual wxTreeItemId GetFocusedItem() const;
8cee4a30 130
5708ae18
VZ
131 virtual void ClearFocusedItem();
132 virtual void SetFocusedItem(const wxTreeItemId& item);
133
134
8cee4a30
VZ
135 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
136 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
137 wxTreeItemIdValue& cookie) const;
138 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
139 wxTreeItemIdValue& cookie) const;
140 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
141
142 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
143 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
144
145 virtual wxTreeItemId GetFirstVisibleItem() const;
146 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
147 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
08b7c251 148
092bddef
VZ
149 // operations
150 // ----------
08b7c251 151
a78955e3 152 virtual wxTreeItemId AddRoot(const wxString& text,
08b7c251
VZ
153 int image = -1, int selectedImage = -1,
154 wxTreeItemData *data = NULL);
155
8cee4a30
VZ
156 virtual void Delete(const wxTreeItemId& item);
157 virtual void DeleteChildren(const wxTreeItemId& item);
158 virtual void DeleteAllItems();
08b7c251 159
8cee4a30
VZ
160 virtual void Expand(const wxTreeItemId& item);
161 virtual void Collapse(const wxTreeItemId& item);
162 virtual void CollapseAndReset(const wxTreeItemId& item);
163 virtual void Toggle(const wxTreeItemId& item);
08b7c251 164
8cee4a30
VZ
165 virtual void Unselect();
166 virtual void UnselectAll();
167 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
5cb3a695 168 virtual void SelectChildren(const wxTreeItemId& parent);
2ef31e80 169
8cee4a30
VZ
170 virtual void EnsureVisible(const wxTreeItemId& item);
171 virtual void ScrollTo(const wxTreeItemId& item);
172
173 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
b19b28c8 174 wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl));
8cee4a30
VZ
175 virtual wxTextCtrl *GetEditControl() const;
176 virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
177 bool discardChanges = false)
d35dce3a
VZ
178 {
179 DoEndEditLabel(discardChanges);
180 }
08b7c251 181
8cee4a30
VZ
182 virtual void SortChildren(const wxTreeItemId& item);
183
184 virtual bool GetBoundingRect(const wxTreeItemId& item,
185 wxRect& rect,
186 bool textOnly = false) const;
08b7c251 187
08b7c251
VZ
188 // implementation
189 // --------------
3f7bc32b 190
39c7a53c
VZ
191 virtual wxVisualAttributes GetDefaultAttributes() const
192 {
193 return GetClassDefaultAttributes(GetWindowVariant());
194 }
195
196 static wxVisualAttributes
197 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
198
199
c140b7e7 200 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fbd8ac52 201 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fd3f686c 202 virtual bool MSWCommand(WXUINT param, WXWORD id);
a23fd0e1 203 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
90c6edd7 204 virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
08b7c251 205
bb448552
VZ
206 // override some base class virtuals
207 virtual bool SetBackgroundColour(const wxColour &colour);
208 virtual bool SetForegroundColour(const wxColour &colour);
209
a047aff2
JS
210 // returns true if the platform should explicitly apply a theme border
211 virtual bool CanApplyThemeBorder() const { return false; }
212
2bda0e17 213protected:
6754c300
VZ
214 // Implement "update locking" in a custom way for this control.
215 virtual void DoFreeze();
216 virtual void DoThaw();
217
4e1e8dc5
VZ
218 virtual void DoSetSize(int x, int y,
219 int width, int height,
220 int sizeFlags = wxSIZE_AUTO);
221
08b7c251
VZ
222 // SetImageList helper
223 void SetAnyImageList(wxImageList *imageList, int which);
224
d00407b2
VZ
225 // refresh a single item
226 void RefreshItem(const wxTreeItemId& item);
227
d35dce3a
VZ
228 // end edit label
229 void DoEndEditLabel(bool discardChanges = false);
230
03966fcb
RR
231 virtual int DoGetItemState(const wxTreeItemId& item) const;
232 virtual void DoSetItemState(const wxTreeItemId& item, int state);
233
8cee4a30
VZ
234 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
235 size_t pos,
236 const wxString& text,
237 int image, int selectedImage,
238 wxTreeItemData *data);
239 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
240 const wxTreeItemId& idPrevious,
241 const wxString& text,
242 int image = -1, int selImage = -1,
243 wxTreeItemData *data = NULL);
be0e5d69 244 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
08b7c251 245
4523ebb3
VZ
246 // obtain the user data for the lParam member of TV_ITEM
247 class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const;
248
c7d9c476
VZ
249 // update the event to include the items client data and pass it to
250 // HandleWindowEvent(), return true if it processed it
251 bool HandleTreeEvent(wxTreeEvent& event) const;
252
253 // pass the event to HandleTreeEvent() and return true if the event was
254 // either unprocessed or not vetoed
255 bool IsTreeEventAllowed(wxTreeEvent& event) const
256 {
257 return !HandleTreeEvent(event) || event.IsAllowed();
258 }
259
aa8166dd
VZ
260 // generate a wxEVT_KEY_DOWN event from the specified WPARAM/LPARAM values
261 // having the same meaning as for WM_KEYDOWN, return true if it was
262 // processed
263 bool MSWHandleTreeKeyDownEvent(WXWPARAM wParam, WXLPARAM lParam);
264
265 // handle a key event in a multi-selection control, should be only called
266 // for keys which can be used to change the selection
c7d9c476
VZ
267 //
268 // return true if the key was processed, false otherwise
25f701e6 269 bool MSWHandleSelectionKey(unsigned vkey);
c7d9c476 270
4523ebb3
VZ
271
272 // data used only while editing the item label:
273 wxTextCtrl *m_textCtrl; // text control in which it is edited
274 wxTreeItemId m_idEdited; // the item being edited
275
6f02a879
VZ
276private:
277 // the common part of all ctors
278 void Init();
279
ae322a48 280 // helper functions
ffdbfc4a
PC
281 bool DoGetItem(wxTreeViewItem *tvItem) const;
282 void DoSetItem(wxTreeViewItem *tvItem);
6f02a879 283
ffdbfc4a 284 void DoExpand(const wxTreeItemId& item, int flag);
6f02a879 285
7dac12ef
VZ
286 void DoSelectItem(const wxTreeItemId& item, bool select = true);
287 void DoUnselectItem(const wxTreeItemId& item);
288 void DoToggleItemSelection(const wxTreeItemId& item);
289
c7d9c476 290 void DoUnselectAll();
5cb3a695 291 void DoSelectChildren(const wxTreeItemId& parent);
c7d9c476 292
08b7c251 293 void DeleteTextCtrl();
092bddef 294
0228081f
VZ
295 // return true if the item is the hidden root one (i.e. it's the root item
296 // and the tree has wxTR_HIDE_ROOT style)
297 bool IsHiddenRoot(const wxTreeItemId& item) const;
298
299
3c8cbc12
VZ
300 // check if the given flags (taken from TV_HITTESTINFO structure)
301 // indicate a position "on item": this is less trivial than just checking
302 // for TVHT_ONITEM because we consider that points to the left and right of
303 // item text are also "on item" when wxTR_FULL_ROW_HIGHLIGHT is used as the
304 // item visually spans the entire breadth of the window then
305 bool MSWIsOnItem(unsigned flags) const;
306
307
ee4b2721
VZ
308 // the hash storing the items attributes (indexed by item ids)
309 wxMapTreeAttr m_attrs;
696e1ea0 310
dabbc6a5 311 // true if the hash above is not empty
696e1ea0
VZ
312 bool m_hasAnyAttr;
313
68d9be05 314#if wxUSE_DRAGIMAGE
23f681ec
VZ
315 // used for dragging
316 wxDragImage *m_dragImage;
68d9be05 317#endif
23f681ec 318
a9c1265f
VZ
319 // Virtual root item, if wxTR_HIDE_ROOT is set.
320 void* m_pVirtualRoot;
321
3f7bc32b 322 // the starting item for selection with Shift
e3ad5702
JS
323 wxTreeItemId m_htSelStart, m_htClickedItem;
324 wxPoint m_ptClick;
3f7bc32b 325
c7d9c476
VZ
326 // whether dragging has started
327 bool m_dragStarted;
328
329 // whether focus was lost between subsequent clicks of a single item
330 bool m_focusLost;
331
7dac12ef
VZ
332 // set when we are changing selection ourselves (only used in multi
333 // selection mode)
334 bool m_changingSelection;
335
c7d9c476
VZ
336 // whether we need to trigger a state image click event
337 bool m_triggerStateImageClick;
338
d301c440
VZ
339 // whether we need to deselect other items on mouse up
340 bool m_mouseUpDeselect;
341
4e1e8dc5
VZ
342 // The size to restore the control to when it is thawed, see DoThaw().
343 wxSize m_thawnSize;
344
502a2b18
VZ
345 friend class wxTreeItemIndirectData;
346 friend class wxTreeSortHelper;
347
092bddef 348 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
c0c133e1 349 wxDECLARE_NO_COPY_CLASS(wxTreeCtrl);
2bda0e17
KB
350};
351
1e6feb95
VZ
352#endif // wxUSE_TREECTRL
353
0228081f 354#endif // _WX_MSW_TREECTRL_H_