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_MSW_TREECTRL_H_
13 #define _WX_MSW_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 WXDLLIMPEXP_FWD_CORE wxImageList
;
34 class WXDLLIMPEXP_FWD_CORE wxDragImage
;
35 struct WXDLLIMPEXP_FWD_CORE 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 WXDLLIMPEXP_CORE 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;
130 virtual wxTreeItemId
GetFocusedItem() const;
132 virtual wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
133 virtual wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
,
134 wxTreeItemIdValue
& cookie
) const;
135 virtual wxTreeItemId
GetNextChild(const wxTreeItemId
& item
,
136 wxTreeItemIdValue
& cookie
) const;
137 virtual wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
139 virtual wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
140 virtual wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
142 virtual wxTreeItemId
GetFirstVisibleItem() const;
143 virtual wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
144 virtual wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
149 virtual wxTreeItemId
AddRoot(const wxString
& text
,
150 int image
= -1, int selectedImage
= -1,
151 wxTreeItemData
*data
= NULL
);
153 virtual void Delete(const wxTreeItemId
& item
);
154 virtual void DeleteChildren(const wxTreeItemId
& item
);
155 virtual void DeleteAllItems();
157 virtual void Expand(const wxTreeItemId
& item
);
158 virtual void Collapse(const wxTreeItemId
& item
);
159 virtual void CollapseAndReset(const wxTreeItemId
& item
);
160 virtual void Toggle(const wxTreeItemId
& item
);
162 virtual void Unselect();
163 virtual void UnselectAll();
164 virtual void SelectItem(const wxTreeItemId
& item
, bool select
= true);
166 virtual void EnsureVisible(const wxTreeItemId
& item
);
167 virtual void ScrollTo(const wxTreeItemId
& item
);
169 virtual wxTextCtrl
*EditLabel(const wxTreeItemId
& item
,
170 wxClassInfo
* textCtrlClass
= CLASSINFO(wxTextCtrl
));
171 virtual wxTextCtrl
*GetEditControl() const;
172 virtual void EndEditLabel(const wxTreeItemId
& WXUNUSED(item
),
173 bool discardChanges
= false)
175 DoEndEditLabel(discardChanges
);
178 virtual void SortChildren(const wxTreeItemId
& item
);
180 virtual bool GetBoundingRect(const wxTreeItemId
& item
,
182 bool textOnly
= false) const;
187 virtual wxVisualAttributes
GetDefaultAttributes() const
189 return GetClassDefaultAttributes(GetWindowVariant());
192 static wxVisualAttributes
193 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
196 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
197 virtual WXLRESULT
MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
198 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
199 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
200 virtual bool MSWShouldPreProcessMessage(WXMSG
* msg
);
202 // override some base class virtuals
203 virtual bool SetBackgroundColour(const wxColour
&colour
);
204 virtual bool SetForegroundColour(const wxColour
&colour
);
206 // returns true if the platform should explicitly apply a theme border
207 virtual bool CanApplyThemeBorder() const { return false; }
210 // SetImageList helper
211 void SetAnyImageList(wxImageList
*imageList
, int which
);
213 // refresh a single item
214 void RefreshItem(const wxTreeItemId
& item
);
217 void DoEndEditLabel(bool discardChanges
= false);
219 virtual int DoGetItemState(const wxTreeItemId
& item
) const;
220 virtual void DoSetItemState(const wxTreeItemId
& item
, int state
);
222 virtual wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
224 const wxString
& text
,
225 int image
, int selectedImage
,
226 wxTreeItemData
*data
);
227 virtual wxTreeItemId
DoInsertAfter(const wxTreeItemId
& parent
,
228 const wxTreeItemId
& idPrevious
,
229 const wxString
& text
,
230 int image
= -1, int selImage
= -1,
231 wxTreeItemData
*data
= NULL
);
232 virtual wxTreeItemId
DoTreeHitTest(const wxPoint
& point
, int& flags
) const;
234 // obtain the user data for the lParam member of TV_ITEM
235 class wxTreeItemParam
*GetItemParam(const wxTreeItemId
& item
) const;
237 // update the event to include the items client data and pass it to
238 // HandleWindowEvent(), return true if it processed it
239 bool HandleTreeEvent(wxTreeEvent
& event
) const;
241 // pass the event to HandleTreeEvent() and return true if the event was
242 // either unprocessed or not vetoed
243 bool IsTreeEventAllowed(wxTreeEvent
& event
) const
245 return !HandleTreeEvent(event
) || event
.IsAllowed();
248 // generate a wxEVT_KEY_DOWN event from the specified WPARAM/LPARAM values
249 // having the same meaning as for WM_KEYDOWN, return true if it was
251 bool MSWHandleTreeKeyDownEvent(WXWPARAM wParam
, WXLPARAM lParam
);
253 // handle a key event in a multi-selection control, should be only called
254 // for keys which can be used to change the selection
256 // return true if the key was processed, false otherwise
257 bool MSWHandleSelectionKey(unsigned vkey
);
260 // data used only while editing the item label:
261 wxTextCtrl
*m_textCtrl
; // text control in which it is edited
262 wxTreeItemId m_idEdited
; // the item being edited
265 // the common part of all ctors
269 bool DoGetItem(wxTreeViewItem
*tvItem
) const;
270 void DoSetItem(wxTreeViewItem
*tvItem
);
272 void DoExpand(const wxTreeItemId
& item
, int flag
);
274 void DoSelectItem(const wxTreeItemId
& item
, bool select
= true);
275 void DoUnselectItem(const wxTreeItemId
& item
);
276 void DoToggleItemSelection(const wxTreeItemId
& item
);
278 void DoUnselectAll();
280 void DeleteTextCtrl();
282 // return true if the item is the hidden root one (i.e. it's the root item
283 // and the tree has wxTR_HIDE_ROOT style)
284 bool IsHiddenRoot(const wxTreeItemId
& item
) const;
286 // clears/sets the currently focused item
287 void ClearFocusedItem();
288 void SetFocusedItem(const wxTreeItemId
& item
);
290 // the hash storing the items attributes (indexed by item ids)
291 wxMapTreeAttr m_attrs
;
293 // true if the hash above is not empty
298 wxDragImage
*m_dragImage
;
301 // Virtual root item, if wxTR_HIDE_ROOT is set.
302 void* m_pVirtualRoot
;
304 // the starting item for selection with Shift
305 wxTreeItemId m_htSelStart
, m_htClickedItem
;
308 // whether dragging has started
311 // whether focus was lost between subsequent clicks of a single item
314 // set when we are changing selection ourselves (only used in multi
316 bool m_changingSelection
;
318 // whether we need to trigger a state image click event
319 bool m_triggerStateImageClick
;
321 // whether we need to deselect other items on mouse up
322 bool m_mouseUpDeselect
;
324 friend class wxTreeItemIndirectData
;
325 friend class wxTreeSortHelper
;
327 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
328 wxDECLARE_NO_COPY_CLASS(wxTreeCtrl
);
331 #endif // wxUSE_TREECTRL
333 #endif // _WX_MSW_TREECTRL_H_