1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl.
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "treectrl.h"
16 #include "wx/stubs/textctrl.h"
17 #include "wx/treebase.h"
18 #include "wx/stubs/treectrl.h"
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
22 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
26 wxTreeCtrl::wxTreeCtrl()
28 m_imageListNormal
= NULL
;
29 m_imageListState
= NULL
;
33 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
34 long style
, const wxValidator
& validator
, const wxString
& name
)
37 SetValidator(validator
);
39 m_imageListNormal
= NULL
;
40 m_imageListState
= NULL
;
43 m_windowStyle
= style
;
47 m_windowId
= (id
== -1) ? NewControlId() : id
;
49 if (parent
) parent
->AddChild(this);
51 // TODO create tree control
56 wxTreeCtrl::~wxTreeCtrl()
65 int wxTreeCtrl::GetCount() const
71 int wxTreeCtrl::GetIndent() const
77 void wxTreeCtrl::SetIndent(int indent
)
82 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
84 if ( which
== wxIMAGE_LIST_NORMAL
)
86 return m_imageListNormal
;
88 else if ( which
== wxIMAGE_LIST_STATE
)
90 return m_imageListState
;
95 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
97 if ( which
== wxIMAGE_LIST_NORMAL
)
99 m_imageListNormal
= imageList
;
101 else if ( which
== wxIMAGE_LIST_STATE
)
103 m_imageListState
= imageList
;
108 long wxTreeCtrl::GetNextItem(long item
, int code
) const
114 bool wxTreeCtrl::ItemHasChildren(long item
) const
120 long wxTreeCtrl::GetChild(long item
) const
126 long wxTreeCtrl::GetParent(long item
) const
132 long wxTreeCtrl::GetFirstVisibleItem() const
138 long wxTreeCtrl::GetNextVisibleItem(long item
) const
144 long wxTreeCtrl::GetSelection() const
150 long wxTreeCtrl::GetRootItem() const
156 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
162 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
168 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
172 info
.m_mask
= wxTREE_MASK_STATE
;
173 info
.m_stateMask
= stateMask
;
174 info
.m_itemId
= item
;
182 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
186 info
.m_mask
= wxTREE_MASK_STATE
;
187 info
.m_state
= state
;
188 info
.m_stateMask
= stateMask
;
189 info
.m_itemId
= item
;
191 return SetItem(info
);
194 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
198 info
.m_mask
= wxTREE_MASK_IMAGE
;
199 info
.m_image
= image
;
202 info
.m_selectedImage
= selImage
;
203 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
205 info
.m_itemId
= item
;
207 return SetItem(info
);
210 wxString
wxTreeCtrl::GetItemText(long item
) const
214 info
.m_mask
= wxTREE_MASK_TEXT
;
215 info
.m_itemId
= item
;
222 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
226 info
.m_mask
= wxTREE_MASK_TEXT
;
227 info
.m_itemId
= item
;
233 long wxTreeCtrl::GetItemData(long item
) const
237 info
.m_mask
= wxTREE_MASK_DATA
;
238 info
.m_itemId
= item
;
245 bool wxTreeCtrl::SetItemData(long item
, long data
)
249 info
.m_mask
= wxTREE_MASK_DATA
;
250 info
.m_itemId
= item
;
253 return SetItem(info
);
256 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
262 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
268 bool wxTreeCtrl::DeleteItem(long item
)
274 bool wxTreeCtrl::ExpandItem(long item
, int action
)
279 case wxTREE_EXPAND_EXPAND
:
282 case wxTREE_EXPAND_COLLAPSE
:
285 case wxTREE_EXPAND_COLLAPSE_RESET
:
288 case wxTREE_EXPAND_TOGGLE
:
292 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
295 bool bOk
= FALSE
; // TODO expand item
297 // May not send messages, so emulate them
299 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
300 event
.m_item
.m_itemId
= item
;
301 event
.m_item
.m_mask
=
302 event
.m_item
.m_stateMask
= 0xffff; // get all
303 GetItem(event
.m_item
);
305 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
307 event
.m_code
= action
;
308 event
.SetEventObject(this);
310 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
311 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
312 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
313 GetEventHandler()->ProcessEvent(event
);
315 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
316 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
317 GetEventHandler()->ProcessEvent(event
);
323 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
329 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
334 info
.m_mask
= wxTREE_MASK_TEXT
;
337 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
338 info
.m_image
= image
;
339 if ( selImage
== -1 )
340 info
.m_selectedImage
= image
;
342 info
.m_selectedImage
= selImage
;
345 return InsertItem(parent
, info
, insertAfter
);
348 bool wxTreeCtrl::SelectItem(long item
)
354 bool wxTreeCtrl::ScrollTo(long item
)
360 bool wxTreeCtrl::DeleteAllItems()
366 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
372 // End label editing, optionally cancelling the edit
373 bool wxTreeCtrl::EndEditLabel(bool cancel
)
379 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
385 bool wxTreeCtrl::SortChildren(long item
)
391 bool wxTreeCtrl::EnsureVisible(long item
)
397 // Tree item structure
398 wxTreeItem::wxTreeItem()
405 m_selectedImage
= -1;
411 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
413 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
414 wxCommandEvent(commandType
, id
)