X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a680f9a170175cfc8d0dbd6b8bf5299033cdb802..ce22ac4592fccaedd8324e7a8f08b510748827e4:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 4aa5c5ec8f..c6bd87b086 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -29,6 +29,8 @@ #include "wx/treectrl.h" #ifndef WX_PRECOMP + #include "wx/msw/wrapcctl.h" // include "properly" + #include "wx/msw/missing.h" #include "wx/dynarray.h" #include "wx/log.h" #include "wx/app.h" @@ -37,11 +39,6 @@ #include "wx/msw/private.h" -// include "properly" -#include "wx/msw/wrapcctl.h" - -#include "wx/msw/missing.h" - // Set this to 1 to be _absolutely_ sure that repainting will work for all // comctl32.dll versions #define wxUSE_COMCTL32_SAFELY 0 @@ -293,9 +290,9 @@ class wxTreeItemParam { public: wxTreeItemParam() - : m_item((long int)0), - m_data(NULL) { + m_data = NULL; + for ( size_t n = 0; n < WXSIZEOF(m_images); n++ ) { m_images[n] = -1; @@ -451,16 +448,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 +932,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 +986,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 +1006,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 +1568,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 +1673,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 +1802,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)); } @@ -2050,7 +2056,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara GetBoundingRect(event.m_item, ItemRect, false); // If the point is inside the bounding rectangle, use it as the click position. // This should be the case for WM_CONTEXTMENU as the result of a right-click - if (ItemRect.Inside(MenuPoint)) + if (ItemRect.Contains(MenuPoint)) { event.m_pointDrag = MenuPoint; }