1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "treectrl.h"
16 #include "wx/treectrl.h"
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
20 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
24 wxTreeCtrl::wxTreeCtrl()
26 m_imageListNormal
= NULL
;
27 m_imageListState
= NULL
;
31 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
32 long style
, const wxValidator
& validator
, const wxString
& name
)
35 SetValidator(validator
);
37 m_imageListNormal
= NULL
;
38 m_imageListState
= NULL
;
41 m_windowStyle
= style
;
45 m_windowId
= (id
== -1) ? NewControlId() : id
;
47 if (parent
) parent
->AddChild(this);
49 // TODO create tree control
54 wxTreeCtrl::~wxTreeCtrl()
63 int wxTreeCtrl::GetCount() const
69 int wxTreeCtrl::GetIndent() const
75 void wxTreeCtrl::SetIndent(int indent
)
80 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
82 if ( which
== wxIMAGE_LIST_NORMAL
)
84 return m_imageListNormal
;
86 else if ( which
== wxIMAGE_LIST_STATE
)
88 return m_imageListState
;
93 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
95 if ( which
== wxIMAGE_LIST_NORMAL
)
97 m_imageListNormal
= imageList
;
99 else if ( which
== wxIMAGE_LIST_STATE
)
101 m_imageListState
= imageList
;
106 long wxTreeCtrl::GetNextItem(long item
, int code
) const
112 bool wxTreeCtrl::ItemHasChildren(long item
) const
118 long wxTreeCtrl::GetChild(long item
) const
124 long wxTreeCtrl::GetParent(long item
) const
130 long wxTreeCtrl::GetFirstVisibleItem() const
136 long wxTreeCtrl::GetNextVisibleItem(long item
) const
142 long wxTreeCtrl::GetSelection() const
148 long wxTreeCtrl::GetRootItem() const
154 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
160 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
166 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
170 info
.m_mask
= wxTREE_MASK_STATE
;
171 info
.m_stateMask
= stateMask
;
172 info
.m_itemId
= item
;
180 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
184 info
.m_mask
= wxTREE_MASK_STATE
;
185 info
.m_state
= state
;
186 info
.m_stateMask
= stateMask
;
187 info
.m_itemId
= item
;
189 return SetItem(info
);
192 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
196 info
.m_mask
= wxTREE_MASK_IMAGE
;
197 info
.m_image
= image
;
200 info
.m_selectedImage
= selImage
;
201 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
203 info
.m_itemId
= item
;
205 return SetItem(info
);
208 wxString
wxTreeCtrl::GetItemText(long item
) const
212 info
.m_mask
= wxTREE_MASK_TEXT
;
213 info
.m_itemId
= item
;
220 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
224 info
.m_mask
= wxTREE_MASK_TEXT
;
225 info
.m_itemId
= item
;
231 long wxTreeCtrl::GetItemData(long item
) const
235 info
.m_mask
= wxTREE_MASK_DATA
;
236 info
.m_itemId
= item
;
243 bool wxTreeCtrl::SetItemData(long item
, long data
)
247 info
.m_mask
= wxTREE_MASK_DATA
;
248 info
.m_itemId
= item
;
251 return SetItem(info
);
254 bool wxTreeCtrl::GetItemRect(long item
, wxRectangle
& rect
, bool textOnly
) const
260 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
266 bool wxTreeCtrl::DeleteItem(long item
)
272 bool wxTreeCtrl::ExpandItem(long item
, int action
)
277 case wxTREE_EXPAND_EXPAND
:
280 case wxTREE_EXPAND_COLLAPSE
:
283 case wxTREE_EXPAND_COLLAPSE_RESET
:
284 mswAction
= TVE_COLLAPSERESET
;
287 case wxTREE_EXPAND_TOGGLE
:
288 mswAction
= TVE_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
)