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
& wxVALIDATOR_PARAM(validator
), 
  35     m_imageListNormal 
= NULL
; 
  36     m_imageListState 
= NULL
; 
  41     SetValidator(validator
); 
  45     m_windowStyle 
= style
; 
  47     m_windowId 
= (id 
== wxID_ANY
) ? NewControlId() : id
; 
  50         parent
->AddChild(this); 
  52     // TODO: create tree control 
  57 wxTreeCtrl::~wxTreeCtrl() 
  63 unsigned 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 
) 
  83         return m_imageListNormal
; 
  84     else if ( which 
== wxIMAGE_LIST_STATE 
) 
  85         return m_imageListState
; 
  90 void wxTreeCtrl::SetImageList(wxImageList 
*imageList
, int which
) 
  92     if ( which 
== wxIMAGE_LIST_NORMAL 
) 
  93         m_imageListNormal 
= imageList
; 
  94     else if ( which 
== wxIMAGE_LIST_STATE 
) 
  95         m_imageListState 
= imageList
; 
 100 long wxTreeCtrl::GetNextItem(long item
, int code
) const 
 106 bool wxTreeCtrl::ItemHasChildren(long item
) const 
 112 long wxTreeCtrl::GetChild(long item
) const 
 118 long wxTreeCtrl::GetItemParent(long item
) const 
 124 long wxTreeCtrl::GetFirstVisibleItem() const 
 130 long wxTreeCtrl::GetNextVisibleItem(long item
) const 
 136 long wxTreeCtrl::GetSelection() const 
 142 long wxTreeCtrl::GetRootItem() const 
 148 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const 
 154 bool wxTreeCtrl::SetItem(wxTreeItem
& info
) 
 160 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const 
 164     info
.m_mask 
= wxTREE_MASK_STATE
; 
 165     info
.m_stateMask 
= stateMask
; 
 166     info
.m_itemId 
= item
; 
 174 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
) 
 178     info
.m_mask 
= wxTREE_MASK_STATE
; 
 179     info
.m_state 
= state
; 
 180     info
.m_stateMask 
= stateMask
; 
 181     info
.m_itemId 
= item
; 
 183     return SetItem(info
); 
 186 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
) 
 190     info
.m_mask 
= wxTREE_MASK_IMAGE
; 
 191     info
.m_image 
= image
; 
 194         info
.m_selectedImage 
= selImage
; 
 195         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
; 
 216 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
) 
 220     info
.m_mask 
= wxTREE_MASK_TEXT
; 
 221     info
.m_itemId 
= item
; 
 227 long wxTreeCtrl::GetItemData(long item
) const 
 231     info
.m_mask 
= wxTREE_MASK_DATA
; 
 232     info
.m_itemId 
= item
; 
 240 bool wxTreeCtrl::SetItemData(long item
, long data
) 
 244     info
.m_mask 
= wxTREE_MASK_DATA
; 
 245     info
.m_itemId 
= item
; 
 248     return SetItem(info
); 
 251 bool wxTreeCtrl::GetItemRect(long item
, wxRect
& rect
, bool textOnly
) const 
 257 wxTextCtrl 
* wxTreeCtrl::GetEditControl() const 
 263 bool wxTreeCtrl::DeleteItem(long item
) 
 269 bool wxTreeCtrl::ExpandItem(long item
, int action
) 
 274     case wxTREE_EXPAND_EXPAND
: 
 277     case wxTREE_EXPAND_COLLAPSE
: 
 280     case wxTREE_EXPAND_COLLAPSE_RESET
: 
 283     case wxTREE_EXPAND_TOGGLE
: 
 287         wxFAIL_MSG(wxT("unknown action in wxTreeCtrl::ExpandItem"); 
 293     // 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 
= event
.m_item
.m_stateMask 
= 0xFFFF; // get all 
 299         GetItem(event
.m_item
); 
 301         bool bIsExpanded 
= (event
.m_item
.m_state 
& wxTREE_STATE_EXPANDED
) != 0; 
 303         event
.m_code 
= action
; 
 304         event
.SetEventObject(this); 
 306         // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded 
 309             ? wxEVT_COMMAND_TREE_ITEM_EXPANDING
 
 310             : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
); 
 311         HandleWindowEvent(event
); 
 315             ? wxEVT_COMMAND_TREE_ITEM_EXPANDED
 
 316             : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
); 
 317         HandleWindowEvent(event
); 
 323 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
) 
 329 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, 
 330     int image
, int selImage
, long insertAfter
) 
 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
)