// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "treectrl.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// macros to hide the cast ugliness
// --------------------------------
-// ptr is the real item id, i.e. wxTreeItemId::m_pItem
-#define HITEM_PTR(ptr) (HTREEITEM)(ptr)
-
-// item here is a wxTreeItemId
-#define HITEM(item) HITEM_PTR((item).m_pItem)
+// get HTREEITEM from wxTreeItemId
+#define HITEM(item) ((HTREEITEM)(((item).m_pItem)))
// the native control doesn't support multiple selections under MSW and we
// have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
void wxTreeCtrl::Init()
{
- m_imageListNormal = NULL;
- m_imageListState = NULL;
- m_ownsImageListNormal = m_ownsImageListState = false;
m_textCtrl = NULL;
m_hasAnyAttr = false;
m_dragImage = NULL;
// delete user data to prevent memory leaks
// also deletes hidden root node storage.
DeleteAllItems();
-
- if (m_ownsImageListNormal) delete m_imageListNormal;
- if (m_ownsImageListState) delete m_imageListState;
}
// ----------------------------------------------------------------------------
TreeView_SetIndent(GetHwnd(), indent);
}
-wxImageList *wxTreeCtrl::GetImageList() const
-{
- return m_imageListNormal;
-}
-
-wxImageList *wxTreeCtrl::GetStateImageList() const
-{
- return m_imageListState;
-}
-
void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
{
// no error return
m_ownsImageListState = false;
}
-void wxTreeCtrl::AssignImageList(wxImageList *imageList)
-{
- SetImageList(imageList);
- m_ownsImageListNormal = true;
-}
-
-void wxTreeCtrl::AssignStateImageList(wxImageList *imageList)
-{
- SetStateImageList(imageList);
- m_ownsImageListState = true;
-}
-
size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
bool recursively) const
{
// Usual operations
// ----------------------------------------------------------------------------
-wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
- wxTreeItemId hInsertAfter,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent,
+ const wxTreeItemId& hInsertAfter,
+ const wxString& text,
+ int image, int selectedImage,
+ wxTreeItemData *data)
{
wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
wxTreeItemId(),
int image, int selImage,
long insertAfter)
{
- return DoInsertItem(parent, wxTreeItemId((void *)insertAfter), text,
- image, selImage, NULL);
+ return DoInsertAfter(parent,
+ wxTreeItemId(wxUIntToPtr(insertAfter)),
+ text,
+ image,
+ selImage,
+ NULL);
}
wxImageList *wxTreeCtrl::GetImageList(int) const
return TVI_ROOT;
}
- return DoInsertItem(wxTreeItemId(), wxTreeItemId(),
- text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, TVI_FIRST,
- text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
- const wxTreeItemId& idPrevious,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, idPrevious, text, image, selectedImage, data);
+ return DoInsertAfter(wxTreeItemId(), wxTreeItemId(),
+ text, image, selectedImage, data);
}
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
- size_t index,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
+ size_t index,
+ const wxString& text,
+ int image, int selectedImage,
+ wxTreeItemData *data)
{
- // find the item from index
- wxTreeItemIdValue cookie;
- wxTreeItemId idPrev, idCur = GetFirstChild(parent, cookie);
- while ( index != 0 && idCur.IsOk() )
+ wxTreeItemId idPrev;
+ if ( index == (size_t)-1 )
{
- index--;
-
- idPrev = idCur;
- idCur = GetNextChild(parent, cookie);
+ // special value: append to the end
+ idPrev = TVI_LAST;
}
+ else // find the item from index
+ {
+ wxTreeItemIdValue cookie;
+ wxTreeItemId idCur = GetFirstChild(parent, cookie);
+ while ( index != 0 && idCur.IsOk() )
+ {
+ index--;
- // assert, not check: if the index is invalid, we will append the item
- // to the end
- wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+ idPrev = idCur;
+ idCur = GetNextChild(parent, cookie);
+ }
- return DoInsertItem(parent, idPrev, text, image, selectedImage, data);
-}
+ // assert, not check: if the index is invalid, we will append the item
+ // to the end
+ wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+ }
-wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, TVI_LAST,
- text, image, selectedImage, data);
+ return DoInsertAfter(parent, idPrev, text, image, selectedImage, data);
}
void wxTreeCtrl::Delete(const wxTreeItemId& item)
size_t nCount = children.Count();
for ( size_t n = 0; n < nCount; n++ )
{
- if ( !TreeView_DeleteItem(GetHwnd(), HITEM_PTR(children[n])) )
+ if ( !TreeView_DeleteItem(GetHwnd(), HITEM(children[n])) )
{
wxLogLastError(wxT("TreeView_DeleteItem"));
}
for ( size_t n = 0; n < count; n++ )
{
#if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
- SetItemCheck(HITEM_PTR(selections[n]), false);
+ SetItemCheck(HITEM(selections[n]), false);
#else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
- ::UnselectItem(GetHwnd(), HITEM_PTR(selections[n]));
+ ::UnselectItem(GetHwnd(), HITEM(selections[n]));
#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
}
DeleteTextCtrl();
}
-wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxTreeCtrl::DoHitTest(const wxPoint& point, int& flags)
{
TV_HITTESTINFO hitTestInfo;
hitTestInfo.pt.x = (int)point.x;
size_t count = GetSelections(selections);
if ( count == 0 ||
count > 1 ||
- HITEM_PTR(selections[0]) != htItem )
+ HITEM(selections[0]) != htItem )
{
// clear the previously selected items, if the
// user clicked outside of the present selection.
{
// TreeView_GetItemRect() will return false if item is not visible,
// which may happen perfectly well
- if ( TreeView_GetItemRect(GetHwnd(), HITEM_PTR(selections[n]),
+ if ( TreeView_GetItemRect(GetHwnd(), HITEM(selections[n]),
&rect, TRUE) )
{
::InvalidateRect(GetHwnd(), &rect, FALSE);
return STATEIMAGEMASKTOINDEX(tvi.state);
}
-#if WXWIN_COMPATIBILITY_2_2
-
-wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const
-{
- return GetItemParent( item );
-}
-
-#endif // WXWIN_COMPATIBILITY_2_2
-
#endif // wxUSE_TREECTRL