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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "treectrl.h"
16 #include "wx/wxprec.h"
18 #include "wx/stubs/textctrl.h"
19 #include "wx/treebase.h"
20 #include "wx/stubs/treectrl.h"
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
24 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
28 wxTreeCtrl::wxTreeCtrl()
30 m_imageListNormal
= NULL
;
31 m_imageListState
= NULL
;
35 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
36 long style
, const wxValidator
& validator
, const wxString
& name
)
39 SetValidator(validator
);
41 m_imageListNormal
= NULL
;
42 m_imageListState
= NULL
;
45 m_windowStyle
= style
;
49 m_windowId
= (id
== -1) ? NewControlId() : id
;
51 if (parent
) parent
->AddChild(this);
53 // TODO create tree control
58 wxTreeCtrl::~wxTreeCtrl()
67 int wxTreeCtrl::GetCount() const
73 int wxTreeCtrl::GetIndent() const
79 void wxTreeCtrl::SetIndent(int indent
)
84 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
86 if ( which
== wxIMAGE_LIST_NORMAL
)
88 return m_imageListNormal
;
90 else if ( which
== wxIMAGE_LIST_STATE
)
92 return m_imageListState
;
97 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
99 if ( which
== wxIMAGE_LIST_NORMAL
)
101 m_imageListNormal
= imageList
;
103 else if ( which
== wxIMAGE_LIST_STATE
)
105 m_imageListState
= imageList
;
110 long wxTreeCtrl::GetNextItem(long item
, int code
) const
116 bool wxTreeCtrl::ItemHasChildren(long item
) const
122 long wxTreeCtrl::GetChild(long item
) const
128 long wxTreeCtrl::GetItemParent(long item
) const
134 long wxTreeCtrl::GetFirstVisibleItem() const
140 long wxTreeCtrl::GetNextVisibleItem(long item
) const
146 long wxTreeCtrl::GetSelection() const
152 long wxTreeCtrl::GetRootItem() const
158 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
164 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
170 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
174 info
.m_mask
= wxTREE_MASK_STATE
;
175 info
.m_stateMask
= stateMask
;
176 info
.m_itemId
= item
;
184 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
188 info
.m_mask
= wxTREE_MASK_STATE
;
189 info
.m_state
= state
;
190 info
.m_stateMask
= stateMask
;
191 info
.m_itemId
= item
;
193 return SetItem(info
);
196 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
200 info
.m_mask
= wxTREE_MASK_IMAGE
;
201 info
.m_image
= image
;
204 info
.m_selectedImage
= selImage
;
205 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
207 info
.m_itemId
= item
;
209 return SetItem(info
);
212 wxString
wxTreeCtrl::GetItemText(long item
) const
216 info
.m_mask
= wxTREE_MASK_TEXT
;
217 info
.m_itemId
= item
;
224 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
228 info
.m_mask
= wxTREE_MASK_TEXT
;
229 info
.m_itemId
= item
;
235 long wxTreeCtrl::GetItemData(long item
) const
239 info
.m_mask
= wxTREE_MASK_DATA
;
240 info
.m_itemId
= item
;
247 bool wxTreeCtrl::SetItemData(long item
, long data
)
251 info
.m_mask
= wxTREE_MASK_DATA
;
252 info
.m_itemId
= item
;
255 return SetItem(info
);
258 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
264 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
270 bool wxTreeCtrl::DeleteItem(long item
)
276 bool wxTreeCtrl::ExpandItem(long item
, int action
)
281 case wxTREE_EXPAND_EXPAND
:
284 case wxTREE_EXPAND_COLLAPSE
:
287 case wxTREE_EXPAND_COLLAPSE_RESET
:
290 case wxTREE_EXPAND_TOGGLE
:
294 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
297 bool bOk
= FALSE
; // TODO expand item
299 // May not send messages, so emulate them
301 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
302 event
.m_item
.m_itemId
= item
;
303 event
.m_item
.m_mask
=
304 event
.m_item
.m_stateMask
= 0xffff; // get all
305 GetItem(event
.m_item
);
307 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
309 event
.m_code
= action
;
310 event
.SetEventObject(this);
312 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
313 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
314 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
315 GetEventHandler()->ProcessEvent(event
);
317 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
318 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
319 GetEventHandler()->ProcessEvent(event
);
325 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
331 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
336 info
.m_mask
= wxTREE_MASK_TEXT
;
339 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
340 info
.m_image
= image
;
341 if ( selImage
== -1 )
342 info
.m_selectedImage
= image
;
344 info
.m_selectedImage
= selImage
;
347 return InsertItem(parent
, info
, insertAfter
);
350 bool wxTreeCtrl::SelectItem(long item
)
356 bool wxTreeCtrl::ScrollTo(long item
)
362 bool wxTreeCtrl::DeleteAllItems()
368 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
374 // End label editing, optionally cancelling the edit
375 bool wxTreeCtrl::EndEditLabel(bool cancel
)
381 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
387 bool wxTreeCtrl::SortChildren(long item
)
393 bool wxTreeCtrl::EnsureVisible(long item
)
399 // Tree item structure
400 wxTreeItem::wxTreeItem()
407 m_selectedImage
= -1;
413 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
415 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
416 wxCommandEvent(commandType
, id
)