1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl.
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "treectrl.h"
16 #include "wx/stubs/textctrl.h"
17 #include "wx/stubs/treectrl.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
21 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
25 wxTreeCtrl::wxTreeCtrl()
27 m_imageListNormal
= NULL
;
28 m_imageListState
= NULL
;
32 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
33 long style
, const wxValidator
& validator
, const wxString
& name
)
36 SetValidator(validator
);
38 m_imageListNormal
= NULL
;
39 m_imageListState
= NULL
;
42 m_windowStyle
= style
;
46 m_windowId
= (id
== -1) ? NewControlId() : id
;
48 if (parent
) parent
->AddChild(this);
50 // TODO create tree control
55 wxTreeCtrl::~wxTreeCtrl()
64 int wxTreeCtrl::GetCount() const
70 int wxTreeCtrl::GetIndent() const
76 void wxTreeCtrl::SetIndent(int indent
)
81 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
83 if ( which
== wxIMAGE_LIST_NORMAL
)
85 return m_imageListNormal
;
87 else if ( which
== wxIMAGE_LIST_STATE
)
89 return m_imageListState
;
94 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
96 if ( which
== wxIMAGE_LIST_NORMAL
)
98 m_imageListNormal
= imageList
;
100 else if ( which
== wxIMAGE_LIST_STATE
)
102 m_imageListState
= imageList
;
107 long wxTreeCtrl::GetNextItem(long item
, int code
) const
113 bool wxTreeCtrl::ItemHasChildren(long item
) const
119 long wxTreeCtrl::GetChild(long item
) const
125 long wxTreeCtrl::GetParent(long item
) const
131 long wxTreeCtrl::GetFirstVisibleItem() const
137 long wxTreeCtrl::GetNextVisibleItem(long item
) const
143 long wxTreeCtrl::GetSelection() const
149 long wxTreeCtrl::GetRootItem() const
155 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
161 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
167 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
171 info
.m_mask
= wxTREE_MASK_STATE
;
172 info
.m_stateMask
= stateMask
;
173 info
.m_itemId
= item
;
181 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
185 info
.m_mask
= wxTREE_MASK_STATE
;
186 info
.m_state
= state
;
187 info
.m_stateMask
= stateMask
;
188 info
.m_itemId
= item
;
190 return SetItem(info
);
193 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
197 info
.m_mask
= wxTREE_MASK_IMAGE
;
198 info
.m_image
= image
;
201 info
.m_selectedImage
= selImage
;
202 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
204 info
.m_itemId
= item
;
206 return SetItem(info
);
209 wxString
wxTreeCtrl::GetItemText(long item
) const
213 info
.m_mask
= wxTREE_MASK_TEXT
;
214 info
.m_itemId
= item
;
221 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
225 info
.m_mask
= wxTREE_MASK_TEXT
;
226 info
.m_itemId
= item
;
232 long wxTreeCtrl::GetItemData(long item
) const
236 info
.m_mask
= wxTREE_MASK_DATA
;
237 info
.m_itemId
= item
;
244 bool wxTreeCtrl::SetItemData(long item
, long data
)
248 info
.m_mask
= wxTREE_MASK_DATA
;
249 info
.m_itemId
= item
;
252 return SetItem(info
);
255 bool wxTreeCtrl::GetItemRect(long item
, wxRectangle
& rect
, bool textOnly
) const
261 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
267 bool wxTreeCtrl::DeleteItem(long item
)
273 bool wxTreeCtrl::ExpandItem(long item
, int action
)
278 case wxTREE_EXPAND_EXPAND
:
281 case wxTREE_EXPAND_COLLAPSE
:
284 case wxTREE_EXPAND_COLLAPSE_RESET
:
287 case wxTREE_EXPAND_TOGGLE
:
291 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
294 bool bOk
= FALSE
; // TODO expand item
296 // May not send messages, so emulate them
298 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
299 event
.m_item
.m_itemId
= item
;
300 event
.m_item
.m_mask
=
301 event
.m_item
.m_stateMask
= 0xffff; // get all
302 GetItem(event
.m_item
);
304 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
306 event
.m_code
= action
;
307 event
.SetEventObject(this);
309 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
310 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
311 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
312 GetEventHandler()->ProcessEvent(event
);
314 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
315 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
316 GetEventHandler()->ProcessEvent(event
);
322 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
328 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
333 info
.m_mask
= wxTREE_MASK_TEXT
;
336 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
337 info
.m_image
= image
;
338 if ( selImage
== -1 )
339 info
.m_selectedImage
= image
;
341 info
.m_selectedImage
= selImage
;
344 return InsertItem(parent
, info
, insertAfter
);
347 bool wxTreeCtrl::SelectItem(long item
)
353 bool wxTreeCtrl::ScrollTo(long item
)
359 bool wxTreeCtrl::DeleteAllItems()
365 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
371 // End label editing, optionally cancelling the edit
372 bool wxTreeCtrl::EndEditLabel(bool cancel
)
378 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
384 bool wxTreeCtrl::SortChildren(long item
)
390 bool wxTreeCtrl::EnsureVisible(long item
)
396 // Tree item structure
397 wxTreeItem::wxTreeItem()
404 m_selectedImage
= -1;
410 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
412 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
413 wxCommandEvent(commandType
, id
)