1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl.
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/stubs/textctrl.h"
15 #include "wx/treebase.h"
16 #include "wx/stubs/treectrl.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
19 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
21 wxTreeCtrl::wxTreeCtrl()
23 m_imageListNormal
= NULL
;
24 m_imageListState
= NULL
;
28 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
29 long style
, const wxValidator
& validator
, const wxString
& name
)
32 SetValidator(validator
);
34 m_imageListNormal
= NULL
;
35 m_imageListState
= NULL
;
38 m_windowStyle
= style
;
42 m_windowId
= (id
== -1) ? NewControlId() : id
;
44 if (parent
) parent
->AddChild(this);
46 // TODO create tree control
51 wxTreeCtrl::~wxTreeCtrl()
60 int wxTreeCtrl::GetCount() const
66 int wxTreeCtrl::GetIndent() const
72 void wxTreeCtrl::SetIndent(int indent
)
77 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
79 if ( which
== wxIMAGE_LIST_NORMAL
)
81 return m_imageListNormal
;
83 else if ( which
== wxIMAGE_LIST_STATE
)
85 return m_imageListState
;
90 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
92 if ( which
== wxIMAGE_LIST_NORMAL
)
94 m_imageListNormal
= imageList
;
96 else if ( which
== wxIMAGE_LIST_STATE
)
98 m_imageListState
= imageList
;
103 long wxTreeCtrl::GetNextItem(long item
, int code
) const
109 bool wxTreeCtrl::ItemHasChildren(long item
) const
115 long wxTreeCtrl::GetChild(long item
) const
121 long wxTreeCtrl::GetItemParent(long item
) const
127 long wxTreeCtrl::GetFirstVisibleItem() const
133 long wxTreeCtrl::GetNextVisibleItem(long item
) const
139 long wxTreeCtrl::GetSelection() const
145 long wxTreeCtrl::GetRootItem() const
151 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
157 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
163 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
167 info
.m_mask
= wxTREE_MASK_STATE
;
168 info
.m_stateMask
= stateMask
;
169 info
.m_itemId
= item
;
177 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
181 info
.m_mask
= wxTREE_MASK_STATE
;
182 info
.m_state
= state
;
183 info
.m_stateMask
= stateMask
;
184 info
.m_itemId
= item
;
186 return SetItem(info
);
189 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
193 info
.m_mask
= wxTREE_MASK_IMAGE
;
194 info
.m_image
= image
;
197 info
.m_selectedImage
= selImage
;
198 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
200 info
.m_itemId
= item
;
202 return SetItem(info
);
205 wxString
wxTreeCtrl::GetItemText(long item
) const
209 info
.m_mask
= wxTREE_MASK_TEXT
;
210 info
.m_itemId
= item
;
217 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
221 info
.m_mask
= wxTREE_MASK_TEXT
;
222 info
.m_itemId
= item
;
228 long wxTreeCtrl::GetItemData(long item
) const
232 info
.m_mask
= wxTREE_MASK_DATA
;
233 info
.m_itemId
= item
;
240 bool wxTreeCtrl::SetItemData(long item
, long data
)
244 info
.m_mask
= wxTREE_MASK_DATA
;
245 info
.m_itemId
= item
;
248 return SetItem(info
);
251 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
257 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
263 bool wxTreeCtrl::DeleteItem(long item
)
269 bool wxTreeCtrl::ExpandItem(long item
, int action
)
274 case wxTREE_EXPAND_EXPAND
:
277 case wxTREE_EXPAND_COLLAPSE
:
280 case wxTREE_EXPAND_COLLAPSE_RESET
:
283 case wxTREE_EXPAND_TOGGLE
:
287 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
290 bool bOk
= FALSE
; // TODO expand item
292 // May not send messages, so emulate them
294 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
295 event
.m_item
.m_itemId
= item
;
296 event
.m_item
.m_mask
=
297 event
.m_item
.m_stateMask
= 0xffff; // get all
298 GetItem(event
.m_item
);
300 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
302 event
.m_code
= action
;
303 event
.SetEventObject(this);
305 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
306 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
307 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
308 GetEventHandler()->ProcessEvent(event
);
310 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
311 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
312 GetEventHandler()->ProcessEvent(event
);
318 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
324 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
329 info
.m_mask
= wxTREE_MASK_TEXT
;
332 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
333 info
.m_image
= image
;
334 if ( selImage
== -1 )
335 info
.m_selectedImage
= image
;
337 info
.m_selectedImage
= selImage
;
340 return InsertItem(parent
, info
, insertAfter
);
343 bool wxTreeCtrl::SelectItem(long item
)
349 bool wxTreeCtrl::ScrollTo(long item
)
355 bool wxTreeCtrl::DeleteAllItems()
361 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
367 // End label editing, optionally cancelling the edit
368 bool wxTreeCtrl::EndEditLabel(bool cancel
)
374 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
380 bool wxTreeCtrl::SortChildren(long item
)
386 bool wxTreeCtrl::EnsureVisible(long item
)
392 // Tree item structure
393 wxTreeItem::wxTreeItem()
400 m_selectedImage
= -1;
406 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
408 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
409 wxCommandEvent(commandType
, id
)