1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/treectrl.cpp
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/stubs/textctrl.h"
13 #include "wx/treebase.h"
14 #include "wx/stubs/treectrl.h"
16 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
17 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
19 wxTreeCtrl::wxTreeCtrl()
21 m_imageListNormal
= NULL
;
22 m_imageListState
= NULL
;
26 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
27 long style
, const wxValidator
& validator
, const wxString
& name
)
30 SetValidator(validator
);
32 m_imageListNormal
= NULL
;
33 m_imageListState
= NULL
;
36 m_windowStyle
= style
;
40 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
42 if (parent
) parent
->AddChild(this);
44 // TODO create tree control
49 wxTreeCtrl::~wxTreeCtrl()
58 size_t wxTreeCtrl::GetCount() const
64 int wxTreeCtrl::GetIndent() const
70 void wxTreeCtrl::SetIndent(int indent
)
75 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
77 if ( which
== wxIMAGE_LIST_NORMAL
)
79 return m_imageListNormal
;
81 else if ( which
== wxIMAGE_LIST_STATE
)
83 return m_imageListState
;
88 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
90 if ( which
== wxIMAGE_LIST_NORMAL
)
92 m_imageListNormal
= imageList
;
94 else if ( which
== wxIMAGE_LIST_STATE
)
96 m_imageListState
= imageList
;
101 long wxTreeCtrl::GetNextItem(long item
, int code
) const
107 bool wxTreeCtrl::ItemHasChildren(long item
) const
113 long wxTreeCtrl::GetChild(long item
) const
119 long wxTreeCtrl::GetItemParent(long item
) const
125 long wxTreeCtrl::GetFirstVisibleItem() const
131 long wxTreeCtrl::GetNextVisibleItem(long item
) const
137 long wxTreeCtrl::GetSelection() const
143 long wxTreeCtrl::GetRootItem() const
149 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
155 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
161 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
165 info
.m_mask
= wxTREE_MASK_STATE
;
166 info
.m_stateMask
= stateMask
;
167 info
.m_itemId
= item
;
175 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
179 info
.m_mask
= wxTREE_MASK_STATE
;
180 info
.m_state
= state
;
181 info
.m_stateMask
= stateMask
;
182 info
.m_itemId
= item
;
184 return SetItem(info
);
187 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
191 info
.m_mask
= wxTREE_MASK_IMAGE
;
192 info
.m_image
= image
;
195 info
.m_selectedImage
= selImage
;
196 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
198 info
.m_itemId
= item
;
200 return SetItem(info
);
203 wxString
wxTreeCtrl::GetItemText(long item
) const
207 info
.m_mask
= wxTREE_MASK_TEXT
;
208 info
.m_itemId
= item
;
211 return wxEmptyString
;
215 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
219 info
.m_mask
= wxTREE_MASK_TEXT
;
220 info
.m_itemId
= item
;
226 long wxTreeCtrl::GetItemData(long item
) const
230 info
.m_mask
= wxTREE_MASK_DATA
;
231 info
.m_itemId
= item
;
238 bool wxTreeCtrl::SetItemData(long item
, long data
)
242 info
.m_mask
= wxTREE_MASK_DATA
;
243 info
.m_itemId
= item
;
246 return SetItem(info
);
249 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
255 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
261 bool wxTreeCtrl::DeleteItem(long item
)
267 bool wxTreeCtrl::ExpandItem(long item
, int action
)
272 case wxTREE_EXPAND_EXPAND
:
275 case wxTREE_EXPAND_COLLAPSE
:
278 case wxTREE_EXPAND_COLLAPSE_RESET
:
281 case wxTREE_EXPAND_TOGGLE
:
285 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
288 bool bOk
= false; // TODO expand item
290 // May not send messages, so emulate them
292 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
293 event
.m_item
.m_itemId
= item
;
294 event
.m_item
.m_mask
=
295 event
.m_item
.m_stateMask
= 0xffff; // get all
296 GetItem(event
.m_item
);
298 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
300 event
.m_code
= action
;
301 event
.SetEventObject(this);
303 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
304 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
305 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
306 GetEventHandler()->ProcessEvent(event
);
308 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
309 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
310 GetEventHandler()->ProcessEvent(event
);
316 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
322 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
327 info
.m_mask
= wxTREE_MASK_TEXT
;
330 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
331 info
.m_image
= image
;
332 if ( selImage
== -1 )
333 info
.m_selectedImage
= image
;
335 info
.m_selectedImage
= selImage
;
338 return InsertItem(parent
, info
, insertAfter
);
341 bool wxTreeCtrl::SelectItem(long item
)
347 bool wxTreeCtrl::ScrollTo(long item
)
353 bool wxTreeCtrl::DeleteAllItems()
359 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
365 // End label editing, optionally cancelling the edit
366 bool wxTreeCtrl::EndEditLabel(bool cancel
)
372 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
378 bool wxTreeCtrl::SortChildren(long item
)
384 bool wxTreeCtrl::EnsureVisible(long item
)
390 // Tree item structure
391 wxTreeItem::wxTreeItem()
398 m_selectedImage
= -1;
404 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
406 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
407 wxCommandEvent(commandType
, id
)