1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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/wxprec.h"
14 #include "wx/stubs/textctrl.h"
15 #include "wx/treebase.h"
16 #include "wx/stubs/treectrl.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
20 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
23 wxTreeCtrl::wxTreeCtrl()
25 m_imageListNormal
= NULL
;
26 m_imageListState
= NULL
;
30 bool wxTreeCtrl::Create(wxWindow
*parent
,
31 wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
32 long style
, const wxValidator
& validator
, const wxString
& name
)
34 m_imageListNormal
= NULL
;
35 m_imageListState
= NULL
;
39 SetValidator(validator
);
42 m_windowStyle
= style
;
44 m_windowId
= (id
== wxID_ANY
) ? NewControlId() : id
;
47 parent
->AddChild(this);
49 // TODO: create tree control
54 wxTreeCtrl::~wxTreeCtrl()
60 unsigned 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
)
80 return m_imageListNormal
;
81 else if ( which
== wxIMAGE_LIST_STATE
)
82 return m_imageListState
;
87 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
89 if ( which
== wxIMAGE_LIST_NORMAL
)
90 m_imageListNormal
= imageList
;
91 else if ( which
== wxIMAGE_LIST_STATE
)
92 m_imageListState
= imageList
;
97 long wxTreeCtrl::GetNextItem(long item
, int code
) const
103 bool wxTreeCtrl::ItemHasChildren(long item
) const
109 long wxTreeCtrl::GetChild(long item
) const
115 long wxTreeCtrl::GetItemParent(long item
) const
121 long wxTreeCtrl::GetFirstVisibleItem() const
127 long wxTreeCtrl::GetNextVisibleItem(long item
) const
133 long wxTreeCtrl::GetSelection() const
139 long wxTreeCtrl::GetRootItem() const
145 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
151 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
157 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
161 info
.m_mask
= wxTREE_MASK_STATE
;
162 info
.m_stateMask
= stateMask
;
163 info
.m_itemId
= item
;
171 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
175 info
.m_mask
= wxTREE_MASK_STATE
;
176 info
.m_state
= state
;
177 info
.m_stateMask
= stateMask
;
178 info
.m_itemId
= item
;
180 return SetItem(info
);
183 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
187 info
.m_mask
= wxTREE_MASK_IMAGE
;
188 info
.m_image
= image
;
191 info
.m_selectedImage
= selImage
;
192 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
195 info
.m_itemId
= item
;
197 return SetItem(info
);
200 wxString
wxTreeCtrl::GetItemText(long item
) const
204 info
.m_mask
= wxTREE_MASK_TEXT
;
205 info
.m_itemId
= item
;
208 return wxEmptyString
;
213 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
217 info
.m_mask
= wxTREE_MASK_TEXT
;
218 info
.m_itemId
= item
;
224 long wxTreeCtrl::GetItemData(long item
) const
228 info
.m_mask
= wxTREE_MASK_DATA
;
229 info
.m_itemId
= item
;
237 bool wxTreeCtrl::SetItemData(long item
, long data
)
241 info
.m_mask
= wxTREE_MASK_DATA
;
242 info
.m_itemId
= item
;
245 return SetItem(info
);
248 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const
254 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
260 bool wxTreeCtrl::DeleteItem(long item
)
266 bool wxTreeCtrl::ExpandItem(long item
, int action
)
271 case wxTREE_EXPAND_EXPAND
:
274 case wxTREE_EXPAND_COLLAPSE
:
277 case wxTREE_EXPAND_COLLAPSE_RESET
:
280 case wxTREE_EXPAND_TOGGLE
:
284 wxFAIL_MSG(wxT("unknown action in wxTreeCtrl::ExpandItem");
290 // May not send messages, so emulate them
293 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
294 event
.m_item
.m_itemId
= item
;
295 event
.m_item
.m_mask
= 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
306 ? wxEVT_COMMAND_TREE_ITEM_EXPANDING
307 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
308 GetEventHandler()->ProcessEvent(event
);
312 ? 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
,
327 int image
, int selImage
, long insertAfter
)
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
)