1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl.
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
21 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
23 wxTreeCtrl::wxTreeCtrl()
25 m_imageListNormal
= NULL
;
26 m_imageListState
= NULL
;
30 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
31 long style
, const wxValidator
& validator
, const wxString
& name
)
34 SetValidator(validator
);
36 m_imageListNormal
= NULL
;
37 m_imageListState
= NULL
;
40 m_windowStyle
= style
;
44 m_windowId
= (id
== -1) ? NewControlId() : id
;
46 if (parent
) parent
->AddChild(this);
48 // TODO create tree control
53 wxTreeCtrl::~wxTreeCtrl()
62 int wxTreeCtrl::GetCount() const
68 int wxTreeCtrl::GetIndent() const
74 void wxTreeCtrl::SetIndent(int indent
)
79 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
81 if ( which
== wxIMAGE_LIST_NORMAL
)
83 return m_imageListNormal
;
85 else if ( which
== wxIMAGE_LIST_STATE
)
87 return m_imageListState
;
92 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
94 if ( which
== wxIMAGE_LIST_NORMAL
)
96 m_imageListNormal
= imageList
;
98 else if ( which
== wxIMAGE_LIST_STATE
)
100 m_imageListState
= imageList
;
105 long wxTreeCtrl::GetNextItem(long item
, int code
) const
111 bool wxTreeCtrl::ItemHasChildren(long item
) const
117 long wxTreeCtrl::GetChild(long item
) const
123 long wxTreeCtrl::GetItemParent(long item
) const
129 long wxTreeCtrl::GetFirstVisibleItem() const
135 long wxTreeCtrl::GetNextVisibleItem(long item
) const
141 long wxTreeCtrl::GetSelection() const
147 long wxTreeCtrl::GetRootItem() const
153 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
159 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
165 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
169 info
.m_mask
= wxTREE_MASK_STATE
;
170 info
.m_stateMask
= stateMask
;
171 info
.m_itemId
= item
;
179 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
183 info
.m_mask
= wxTREE_MASK_STATE
;
184 info
.m_state
= state
;
185 info
.m_stateMask
= stateMask
;
186 info
.m_itemId
= item
;
188 return SetItem(info
);
191 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
195 info
.m_mask
= wxTREE_MASK_IMAGE
;
196 info
.m_image
= image
;
199 info
.m_selectedImage
= selImage
;
200 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
202 info
.m_itemId
= item
;
204 return SetItem(info
);
207 wxString
wxTreeCtrl::GetItemText(long item
) const
211 info
.m_mask
= wxTREE_MASK_TEXT
;
212 info
.m_itemId
= item
;
219 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
223 info
.m_mask
= wxTREE_MASK_TEXT
;
224 info
.m_itemId
= item
;
230 long wxTreeCtrl::GetItemData(long item
) const
234 info
.m_mask
= wxTREE_MASK_DATA
;
235 info
.m_itemId
= item
;
242 bool wxTreeCtrl::SetItemData(long item
, long data
)
246 info
.m_mask
= wxTREE_MASK_DATA
;
247 info
.m_itemId
= item
;
250 return SetItem(info
);
253 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
259 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
265 bool wxTreeCtrl::DeleteItem(long item
)
271 bool wxTreeCtrl::ExpandItem(long item
, int action
)
276 case wxTREE_EXPAND_EXPAND
:
279 case wxTREE_EXPAND_COLLAPSE
:
282 case wxTREE_EXPAND_COLLAPSE_RESET
:
285 case wxTREE_EXPAND_TOGGLE
:
289 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
292 bool bOk
= FALSE
; // TODO expand item
294 // May not send messages, so emulate them
296 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
297 event
.m_item
.m_itemId
= item
;
298 event
.m_item
.m_mask
=
299 event
.m_item
.m_stateMask
= 0xffff; // get all
300 GetItem(event
.m_item
);
302 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
304 event
.m_code
= action
;
305 event
.SetEventObject(this);
307 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
308 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
309 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
310 GetEventHandler()->ProcessEvent(event
);
312 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
313 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
314 GetEventHandler()->ProcessEvent(event
);
320 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
326 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
331 info
.m_mask
= wxTREE_MASK_TEXT
;
334 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
335 info
.m_image
= image
;
336 if ( selImage
== -1 )
337 info
.m_selectedImage
= image
;
339 info
.m_selectedImage
= selImage
;
342 return InsertItem(parent
, info
, insertAfter
);
345 bool wxTreeCtrl::SelectItem(long item
)
351 bool wxTreeCtrl::ScrollTo(long item
)
357 bool wxTreeCtrl::DeleteAllItems()
363 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
369 // End label editing, optionally cancelling the edit
370 bool wxTreeCtrl::EndEditLabel(bool cancel
)
376 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
382 bool wxTreeCtrl::SortChildren(long item
)
388 bool wxTreeCtrl::EnsureVisible(long item
)
394 // Tree item structure
395 wxTreeItem::wxTreeItem()
402 m_selectedImage
= -1;
408 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
410 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
411 wxCommandEvent(commandType
, id
)