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
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TREECTRL_H_
13 #define _WX_TREECTRL_H_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
21 #include "wx/textctrl.h"
22 #include "wx/dynarray.h"
23 #include "wx/treebase.h"
24 #include "wx/hashmap.h"
27 // Cygwin windows.h defines these identifiers
33 class WXDLLEXPORT wxImageList
;
34 class WXDLLEXPORT wxDragImage
;
35 struct WXDLLEXPORT wxTreeViewItem
;
37 #if WXWIN_COMPATIBILITY_2_6
38 // NB: all the following flags are for compatbility only and will be removed in the
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
46 // hash storing attributes for our items
47 WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr
*, wxMapTreeAttr
);
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 class WXDLLEXPORT wxTreeCtrl
: public wxTreeCtrlBase
58 wxTreeCtrl() { Init(); }
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
)
67 Create(parent
, id
, pos
, size
, style
, validator
, name
);
70 virtual ~wxTreeCtrl();
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
);
79 // implement base class pure virtuals
80 // ----------------------------------
82 virtual unsigned int GetCount() const;
84 virtual unsigned int GetIndent() const;
85 virtual void SetIndent(unsigned int indent
);
87 virtual void SetImageList(wxImageList
*imageList
);
88 virtual void SetStateImageList(wxImageList
*imageList
);
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;
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
);
112 // item status inquiries
113 // ---------------------
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;
121 virtual size_t GetChildrenCount(const wxTreeItemId
& item
,
122 bool recursively
= true) const;
127 virtual wxTreeItemId
GetRootItem() const;
128 virtual wxTreeItemId
GetSelection() const;
129 virtual size_t GetSelections(wxArrayTreeItemIds
& selections
) const;
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;
138 virtual wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
139 virtual wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
141 virtual wxTreeItemId
GetFirstVisibleItem() const;
142 virtual wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
143 virtual wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
148 virtual wxTreeItemId
AddRoot(const wxString
& text
,
149 int image
= -1, int selectedImage
= -1,
150 wxTreeItemData
*data
= NULL
);
152 virtual void Delete(const wxTreeItemId
& item
);
153 virtual void DeleteChildren(const wxTreeItemId
& item
);
154 virtual void DeleteAllItems();
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
);
161 virtual void Unselect();
162 virtual void UnselectAll();
163 virtual void SelectItem(const wxTreeItemId
& item
, bool select
= true);
165 virtual void EnsureVisible(const wxTreeItemId
& item
);
166 virtual void ScrollTo(const wxTreeItemId
& item
);
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)
174 DoEndEditLabel(discardChanges
);
177 virtual void SortChildren(const wxTreeItemId
& item
);
179 virtual bool GetBoundingRect(const wxTreeItemId
& item
,
181 bool textOnly
= false) const;
186 #if WXWIN_COMPATIBILITY_2_4
187 // these methods are deprecated and will be removed in future versions of
188 // wxWidgets, they're here for compatibility only, don't use them in new
189 // code (the comments indicate why these methods are now useless and how to
192 // use Expand, Collapse, CollapseAndReset or Toggle
193 wxDEPRECATED( void ExpandItem(const wxTreeItemId
& item
, int action
) );
195 // use Set/GetImageList and Set/GetStateImageList
196 // Use base class GetImageList()
197 wxDEPRECATED( void SetImageList(wxImageList
*imageList
, int) );
199 // use Set/GetItemImage directly
200 wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId
& item
) const );
201 wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId
& item
, int image
) );
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
214 virtual wxVisualAttributes
GetDefaultAttributes() const
216 return GetClassDefaultAttributes(GetWindowVariant());
219 static wxVisualAttributes
220 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
223 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
224 virtual WXLRESULT
MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
225 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
226 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
228 // override some base class virtuals
229 virtual bool SetBackgroundColour(const wxColour
&colour
);
230 virtual bool SetForegroundColour(const wxColour
&colour
);
232 // get/set the check state for the item (only for wxTR_MULTIPLE)
233 bool IsItemChecked(const wxTreeItemId
& item
) const;
234 void SetItemCheck(const wxTreeItemId
& item
, bool check
= true);
236 // set/get the item state.image (state == -1 means cycle to the next one)
237 void SetState(const wxTreeItemId
& node
, int state
);
238 int GetState(const wxTreeItemId
& node
);
241 // SetImageList helper
242 void SetAnyImageList(wxImageList
*imageList
, int which
);
244 // refresh a single item
245 void RefreshItem(const wxTreeItemId
& item
);
248 void DoEndEditLabel(bool discardChanges
= false);
251 // data used only while editing the item label:
252 wxTextCtrl
*m_textCtrl
; // text control in which it is edited
253 wxTreeItemId m_idEdited
; // the item being edited
255 virtual wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
257 const wxString
& text
,
258 int image
, int selectedImage
,
259 wxTreeItemData
*data
);
260 virtual wxTreeItemId
DoInsertAfter(const wxTreeItemId
& parent
,
261 const wxTreeItemId
& idPrevious
,
262 const wxString
& text
,
263 int image
= -1, int selImage
= -1,
264 wxTreeItemData
*data
= NULL
);
265 virtual wxTreeItemId
DoTreeHitTest(const wxPoint
& point
, int& flags
);
268 // the common part of all ctors
272 inline bool DoGetItem(wxTreeViewItem
*tvItem
) const;
273 inline void DoSetItem(wxTreeViewItem
*tvItem
);
275 inline void DoExpand(const wxTreeItemId
& item
, int flag
);
277 int DoGetItemImageFromData(const wxTreeItemId
& item
,
278 wxTreeItemIcon which
) const;
279 void DoSetItemImageFromData(const wxTreeItemId
& item
,
281 wxTreeItemIcon which
) const;
282 void DoSetItemImages(const wxTreeItemId
& item
, int image
, int imageSel
);
284 void DeleteTextCtrl();
286 // support for additional item images which we implement using
287 // wxTreeItemIndirectData technique - see the comments in msw/treectrl.cpp
288 void SetIndirectItemData(const wxTreeItemId
& item
,
289 class wxTreeItemIndirectData
*data
);
290 bool HasIndirectData(const wxTreeItemId
& item
) const;
291 bool IsDataIndirect(wxTreeItemData
*data
) const
292 { return data
&& data
->GetId().m_pItem
== 0; }
294 // the hash storing the items attributes (indexed by item ids)
295 wxMapTreeAttr m_attrs
;
297 // true if the hash above is not empty
301 wxDragImage
*m_dragImage
;
303 // Virtual root item, if wxTR_HIDE_ROOT is set.
304 void* m_pVirtualRoot
;
306 // the starting item for selection with Shift
307 wxTreeItemId m_htSelStart
, m_htClickedItem
;
310 friend class wxTreeItemIndirectData
;
311 friend class wxTreeSortHelper
;
313 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
314 DECLARE_NO_COPY_CLASS(wxTreeCtrl
)
317 #endif // wxUSE_TREECTRL