don't crash when EnsureVisible() is called for the hidden root item

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40856 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-08-26 22:26:53 +00:00
parent 23c2b62bb4
commit 0228081ff2
2 changed files with 24 additions and 11 deletions

View File

@ -9,8 +9,8 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TREECTRL_H_
#define _WX_TREECTRL_H_
#ifndef _WX_MSW_TREECTRL_H_
#define _WX_MSW_TREECTRL_H_
// ----------------------------------------------------------------------------
// headers
@ -280,6 +280,11 @@ private:
void DeleteTextCtrl();
// return true if the item is the hidden root one (i.e. it's the root item
// and the tree has wxTR_HIDE_ROOT style)
bool IsHiddenRoot(const wxTreeItemId& item) const;
// the hash storing the items attributes (indexed by item ids)
wxMapTreeAttr m_attrs;
@ -305,5 +310,4 @@ private:
#endif // wxUSE_TREECTRL
#endif
// _WX_TREECTRL_H_
#endif // _WX_MSW_TREECTRL_H_

View File

@ -451,16 +451,18 @@ public:
virtual bool OnVisit(const wxTreeItemId& item)
{
const wxTreeCtrl * const tree = GetTree();
// can't visit a virtual node.
if ( (GetTree()->GetRootItem() == item) && (GetTree()->GetWindowStyle() & wxTR_HIDE_ROOT))
if ( (tree->GetRootItem() == item) && tree->HasFlag(wxTR_HIDE_ROOT) )
{
return true;
}
#if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
if ( GetTree()->IsItemChecked(item) )
if ( tree->IsItemChecked(item) )
#else
if ( ::IsItemSelected(GetHwndOf(GetTree()), HITEM(item)) )
if ( ::IsItemSelected(GetHwndOf(tree), HITEM(item)) )
#endif
{
m_selections.Add(item);
@ -933,6 +935,11 @@ bool wxTreeCtrl::SetForegroundColour(const wxColour &colour)
// Item access
// ----------------------------------------------------------------------------
bool wxTreeCtrl::IsHiddenRoot(const wxTreeItemId& item) const
{
return HITEM(item) == TVI_ROOT && HasFlag(wxTR_HIDE_ROOT);
}
wxString wxTreeCtrl::GetItemText(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxEmptyString, wxT("invalid tree item") );
@ -982,7 +989,7 @@ int wxTreeCtrl::GetItemImage(const wxTreeItemId& item,
{
wxCHECK_MSG( item.IsOk(), -1, wxT("invalid tree item") );
if ( (HITEM(item) == TVI_ROOT) && (m_windowStyle & wxTR_HIDE_ROOT) )
if ( IsHiddenRoot(item) )
{
// no images for hidden root item
return -1;
@ -1002,7 +1009,7 @@ void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image,
wxT("invalid image index"));
if ( (HITEM(item) == TVI_ROOT) && (m_windowStyle & wxTR_HIDE_ROOT) )
if ( IsHiddenRoot(item) )
{
// no images for hidden root item
return;
@ -1564,7 +1571,7 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
wxTreeItemData *data)
{
if ( m_windowStyle & wxTR_HIDE_ROOT )
if ( HasFlag(wxTR_HIDE_ROOT) )
{
// create a virtual root item, the parent for all the others
wxTreeItemParam *param = new wxTreeItemParam;
@ -1669,7 +1676,7 @@ void wxTreeCtrl::DoExpand(const wxTreeItemId& item, int flag)
wxT("Unknown flag in wxTreeCtrl::DoExpand") );
// A hidden root can be neither expanded nor collapsed.
wxCHECK_RET( !(m_windowStyle & wxTR_HIDE_ROOT) || (HITEM(item) != TVI_ROOT),
wxCHECK_RET( !IsHiddenRoot(item),
wxT("Can't expand/collapse hidden root node!") );
// TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
@ -1798,6 +1805,8 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
{
wxCHECK_RET( !IsHiddenRoot(item), _T("can't show hidden root item") );
// no error return
TreeView_EnsureVisible(GetHwnd(), HITEM(item));
}