1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/treectrl.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/treectrl.h"
32 #include "wx/dynarray.h"
35 #include "wx/settings.h"
38 #include "wx/imaglist.h"
40 // macros to hide the cast ugliness
41 // --------------------------------
43 // ptr is the real item id, i.e. wxTreeItemId::m_pItem
44 #define HITEM_PTR(ptr) (HTREEITEM)(ptr)
46 // item here is a wxTreeItemId
47 #define HITEM(item) HITEM_PTR((item).m_pItem)
49 // the native control doesn't support multiple selections under MSW and we
50 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
51 // checkboxes be the selection status (checked == selected) or by really
52 // emulating everything, i.e. intercepting mouse and key events &c. The first
53 // approach is much easier but doesn't work with comctl32.dll < 4.71 and also
55 #define wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE 0
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 // indices in gs_expandEvents table below
88 // handy table for sending events - it has to be initialized during run-time
89 // now so can't be const any more
90 static /* const */ wxEventType gs_expandEvents
[IDX_WHAT_MAX
][IDX_HOW_MAX
];
93 but logically it's a const table with the following entries:
96 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxEVT_COMMAND_TREE_ITEM_COLLAPSING },
97 { wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxEVT_COMMAND_TREE_ITEM_EXPANDING }
101 // ============================================================================
103 // ============================================================================
105 // ----------------------------------------------------------------------------
106 // construction and destruction
107 // ----------------------------------------------------------------------------
109 void wxTreeCtrl::Init()
113 bool wxTreeCtrl::Create(wxWindow
*parent
,
118 const wxValidator
& validator
,
119 const wxString
& name
)
124 wxTreeCtrl::~wxTreeCtrl()
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 /* static */ wxVisualAttributes
133 wxTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
135 wxVisualAttributes attrs
;
141 // simple wrappers which add error checking in debug mode
143 bool wxTreeCtrl::DoGetItem(wxTreeViewItem
* tvItem
) const
148 void wxTreeCtrl::DoSetItem(wxTreeViewItem
* tvItem
)
152 unsigned int wxTreeCtrl::GetCount() const
158 unsigned int wxTreeCtrl::GetIndent() const
163 void wxTreeCtrl::SetIndent(unsigned int indent
)
167 wxImageList
*wxTreeCtrl::GetImageList() const
169 return m_imageListNormal
;
172 wxImageList
*wxTreeCtrl::GetStateImageList() const
174 return m_imageListState
;
177 void wxTreeCtrl::SetAnyImageList(wxImageList
*imageList
, int which
)
181 void wxTreeCtrl::SetImageList(wxImageList
*imageList
)
185 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
)
189 void wxTreeCtrl::AssignImageList(wxImageList
*imageList
)
193 void wxTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
197 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
198 bool recursively
) const
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 bool wxTreeCtrl::SetBackgroundColour(const wxColour
&colour
)
212 bool wxTreeCtrl::SetForegroundColour(const wxColour
&colour
)
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
223 return wxString(wxT(""));
226 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
230 int wxTreeCtrl::DoGetItemImageFromData(const wxTreeItemId
& item
,
231 wxTreeItemIcon which
) const
236 void wxTreeCtrl::DoSetItemImageFromData(const wxTreeItemId
& item
,
238 wxTreeItemIcon which
) const
242 void wxTreeCtrl::DoSetItemImages(const wxTreeItemId
& item
,
248 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
249 wxTreeItemIcon which
) const
254 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
,
255 wxTreeItemIcon which
)
259 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
264 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
268 void wxTreeCtrl::SetIndirectItemData(const wxTreeItemId
& item
,
269 wxTreeItemIndirectData
*data
)
273 bool wxTreeCtrl::HasIndirectData(const wxTreeItemId
& item
) const
278 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
282 void wxTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
286 void wxTreeCtrl::SetItemDropHighlight(const wxTreeItemId
& item
, bool highlight
)
290 void wxTreeCtrl::RefreshItem(const wxTreeItemId
& item
)
294 wxColour
wxTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
299 wxColour
wxTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
304 wxFont
wxTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
309 void wxTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
314 void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
319 void wxTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
323 // ----------------------------------------------------------------------------
325 // ----------------------------------------------------------------------------
327 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
332 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
337 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
342 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
347 bool wxTreeCtrl::IsBold(const wxTreeItemId
& item
) const
352 // ----------------------------------------------------------------------------
354 // ----------------------------------------------------------------------------
356 wxTreeItemId
wxTreeCtrl::GetRootItem() const
358 return wxTreeItemId();
361 wxTreeItemId
wxTreeCtrl::GetSelection() const
366 wxTreeItemId
wxTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
371 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
372 wxTreeItemIdValue
& cookie
) const
377 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
378 wxTreeItemIdValue
& cookie
) const
383 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
388 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
393 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
398 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
403 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
408 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
413 // ----------------------------------------------------------------------------
414 // multiple selections emulation
415 // ----------------------------------------------------------------------------
417 bool wxTreeCtrl::IsItemChecked(const wxTreeItemId
& item
) const
422 void wxTreeCtrl::SetItemCheck(const wxTreeItemId
& item
, bool check
)
426 size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds
& selections
) const
431 // ----------------------------------------------------------------------------
433 // ----------------------------------------------------------------------------
435 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
436 wxTreeItemId hInsertAfter
,
437 const wxString
& text
,
438 int image
, int selectedImage
,
439 wxTreeItemData
*data
)
444 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
445 int image
, int selectedImage
,
446 wxTreeItemData
*data
)
451 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
452 const wxString
& text
,
453 int image
, int selectedImage
,
454 wxTreeItemData
*data
)
459 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
460 const wxTreeItemId
& idPrevious
,
461 const wxString
& text
,
462 int image
, int selectedImage
,
463 wxTreeItemData
*data
)
468 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
470 const wxString
& text
,
471 int image
, int selectedImage
,
472 wxTreeItemData
*data
)
477 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
478 const wxString
& text
,
479 int image
, int selectedImage
,
480 wxTreeItemData
*data
)
485 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
489 // delete all children (but don't delete the item itself)
490 void wxTreeCtrl::DeleteChildren(const wxTreeItemId
& item
)
494 void wxTreeCtrl::DeleteAllItems()
498 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
502 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
506 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
510 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
514 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
518 void wxTreeCtrl::Unselect()
522 void wxTreeCtrl::UnselectAll()
526 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
, bool select
)
530 void wxTreeCtrl::UnselectItem(const wxTreeItemId
& item
)
534 void wxTreeCtrl::ToggleItemSelection(const wxTreeItemId
& item
)
538 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
542 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
546 wxTextCtrl
*wxTreeCtrl::GetEditControl() const
551 void wxTreeCtrl::DeleteTextCtrl()
555 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
556 wxClassInfo
* textControlClass
)
561 // End label editing, optionally cancelling the edit
562 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& WXUNUSED(item
), bool discardChanges
)
566 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
571 bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
578 // ----------------------------------------------------------------------------
580 // ----------------------------------------------------------------------------
583 // this is just a tiny namespace which is friend to wxTreeCtrl and so can use
584 // functions such as IsDataIndirect()
585 class wxTreeSortHelper
588 static int CALLBACK Compare(LPARAM data1, LPARAM data2, LPARAM tree);
591 static wxTreeItemId GetIdFromData(LPARAM lParam)
593 return ((wxTreeItemParam*)lParam)->GetItem();
597 int CALLBACK wxTreeSortHelper::Compare(LPARAM pItem1,
601 wxCHECK_MSG( pItem1 && pItem2, 0,
602 wxT("sorting tree without data doesn't make sense") );
604 wxTreeCtrl *tree = (wxTreeCtrl *)htree;
606 return tree->OnCompareItems(GetIdFromData(tree, pItem1),
607 GetIdFromData(tree, pItem2));
610 int wxTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
611 const wxTreeItemId
& item2
)
613 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
616 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
)
618 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
626 // why do they define INDEXTOSTATEIMAGEMASK but not the inverse?
627 #define STATEIMAGEMASKTOINDEX(state) (((state) & TVIS_STATEIMAGEMASK) >> 12)
629 void wxTreeCtrl::SetState(const wxTreeItemId
& node
, int state
)
633 int wxTreeCtrl::GetState(const wxTreeItemId
& node
)
638 #endif // wxUSE_TREECTRL