made wx[Array]TreeItemId[s] more backwards compatible

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22133 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-07-19 23:12:33 +00:00
parent 69b9f4cca4
commit f888d61444
2 changed files with 43 additions and 24 deletions

View File

@@ -52,8 +52,15 @@ public:
// is this a valid tree item? // is this a valid tree item?
bool IsOk() const { return m_pItem != 0; } bool IsOk() const { return m_pItem != 0; }
// deprecated: only for compatibility // operations
operator wxTreeItemIdValue() const { return m_pItem; } // invalidate the item
void Unset() { m_pItem = 0; }
#if WXWIN_COMPATIBILITY_2_4
// deprecated: only for compatibility, don't work on 64 bit archs
wxTreeItemId(long item) { m_pItem = (wxTreeItemIdValue)item; }
operator long() const { return (long)m_pItem; }
#endif // WXWIN_COMPATIBILITY_2_4
wxTreeItemIdValue m_pItem; wxTreeItemIdValue m_pItem;
}; };
@@ -92,7 +99,14 @@ protected:
wxTreeItemId m_pItem; wxTreeItemId m_pItem;
}; };
WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxTreeItemId, wxArrayTreeItemIds); WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxTreeItemIdValue, wxArrayTreeItemIdsBase);
class WXDLLEXPORT wxArrayTreeItemIds : public wxArrayTreeItemIdsBase
{
public:
void Add(const wxTreeItemId& id)
{ wxArrayTreeItemIdsBase::Add(id.m_pItem); }
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants

View File

@@ -75,8 +75,14 @@
#define TVM_SETTEXTCOLOR (TV_FIRST + 30) #define TVM_SETTEXTCOLOR (TV_FIRST + 30)
#endif #endif
// a macro to hide the cast ugliness // macros to hide the cast ugliness
#define HITEM(item) (HTREEITEM)((item).m_pItem) // --------------------------------
// 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)
// the native control doesn't support multiple selections under MSW and we // 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 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
@@ -569,7 +575,6 @@ void wxTreeCtrl::Init()
m_textCtrl = NULL; m_textCtrl = NULL;
m_hasAnyAttr = false; m_hasAnyAttr = false;
m_dragImage = NULL; m_dragImage = NULL;
m_htSelStart = 0;
m_pVirtualRoot = NULL; m_pVirtualRoot = NULL;
// initialize the global array of events now as it can't be done statically // initialize the global array of events now as it can't be done statically
@@ -1189,21 +1194,21 @@ void wxTreeCtrl::RefreshItem(const wxTreeItemId& item)
wxColour wxTreeCtrl::GetItemTextColour(const wxTreeItemId& item) const wxColour wxTreeCtrl::GetItemTextColour(const wxTreeItemId& item) const
{ {
wxMapTreeAttr::const_iterator it = m_attrs.find(item); wxMapTreeAttr::const_iterator it = m_attrs.find(item.m_pItem);
return it == m_attrs.end() ? wxNullColour : it->second->GetTextColour(); return it == m_attrs.end() ? wxNullColour : it->second->GetTextColour();
} }
wxColour wxTreeCtrl::GetItemBackgroundColour(const wxTreeItemId& item) const wxColour wxTreeCtrl::GetItemBackgroundColour(const wxTreeItemId& item) const
{ {
wxMapTreeAttr::const_iterator it = m_attrs.find(item); wxMapTreeAttr::const_iterator it = m_attrs.find(item.m_pItem);
return it == m_attrs.end() ? wxNullColour : it->second->GetBackgroundColour(); return it == m_attrs.end() ? wxNullColour : it->second->GetBackgroundColour();
} }
wxFont wxTreeCtrl::GetItemFont(const wxTreeItemId& item) const wxFont wxTreeCtrl::GetItemFont(const wxTreeItemId& item) const
{ {
wxMapTreeAttr::const_iterator it = m_attrs.find(item); wxMapTreeAttr::const_iterator it = m_attrs.find(item.m_pItem);
return it == m_attrs.end() ? wxNullFont : it->second->GetFont(); return it == m_attrs.end() ? wxNullFont : it->second->GetFont();
} }
@@ -1212,12 +1217,12 @@ void wxTreeCtrl::SetItemTextColour(const wxTreeItemId& item,
const wxColour& col) const wxColour& col)
{ {
wxTreeItemAttr *attr; wxTreeItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxTreeItemAttr;
} }
else else
@@ -1234,12 +1239,12 @@ void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId& item,
const wxColour& col) const wxColour& col)
{ {
wxTreeItemAttr *attr; wxTreeItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxTreeItemAttr;
} }
else // already in the hash else // already in the hash
@@ -1255,12 +1260,12 @@ void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId& item,
void wxTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font) void wxTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font)
{ {
wxTreeItemAttr *attr; wxTreeItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxTreeItemAttr;
} }
else // already in the hash else // already in the hash
@@ -1346,7 +1351,7 @@ wxTreeItemId wxTreeCtrl::GetRootItem() const
wxTreeItemId wxTreeCtrl::GetSelection() const wxTreeItemId wxTreeCtrl::GetSelection() const
{ {
wxCHECK_MSG( !(m_windowStyle & wxTR_MULTIPLE), NULL, wxCHECK_MSG( !(m_windowStyle & wxTR_MULTIPLE), wxTreeItemId(),
wxT("this only works with single selection controls") ); wxT("this only works with single selection controls") );
return wxTreeItemId(TreeView_GetSelection(GetHwnd())); return wxTreeItemId(TreeView_GetSelection(GetHwnd()));
@@ -1602,7 +1607,7 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
return TVI_ROOT; return TVI_ROOT;
} }
return DoInsertItem(wxTreeItemId(), 0, return DoInsertItem(wxTreeItemId(), wxTreeItemId(),
text, image, selectedImage, data); text, image, selectedImage, data);
} }
@@ -1682,7 +1687,7 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& item)
size_t nCount = children.Count(); size_t nCount = children.Count();
for ( size_t n = 0; n < nCount; n++ ) for ( size_t n = 0; n < nCount; n++ )
{ {
if ( !TreeView_DeleteItem(GetHwnd(), HITEM(children[n])) ) if ( !TreeView_DeleteItem(GetHwnd(), HITEM_PTR(children[n])) )
{ {
wxLogLastError(wxT("TreeView_DeleteItem")); wxLogLastError(wxT("TreeView_DeleteItem"));
} }
@@ -1790,9 +1795,9 @@ void wxTreeCtrl::UnselectAll()
for ( size_t n = 0; n < count; n++ ) for ( size_t n = 0; n < count; n++ )
{ {
#if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
SetItemCheck(selections[n], false); SetItemCheck(HITEM_PTR(selections[n]), false);
#else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
::UnselectItem(GetHwnd(), HITEM(selections[n])); ::UnselectItem(GetHwnd(), HITEM_PTR(selections[n]));
#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
} }
} }
@@ -2106,7 +2111,7 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
::SetFocus(GetHwnd(), htItem); ::SetFocus(GetHwnd(), htItem);
// reset on any click without Shift // reset on any click without Shift
m_htSelStart = 0; m_htSelStart.Unset();
processed = true; processed = true;
} }
@@ -2137,7 +2142,7 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
size_t count = GetSelections(selections); size_t count = GetSelections(selections);
if ( count == 0 || if ( count == 0 ||
count > 1 || count > 1 ||
HITEM(selections[0]) != htItem ) HITEM_PTR(selections[0]) != htItem )
{ {
// clear the previously selected items, if the // clear the previously selected items, if the
// user clicked outside of the present selection. // user clicked outside of the present selection.
@@ -2163,7 +2168,7 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
} }
// reset on any click without Shift // reset on any click without Shift
m_htSelStart = 0; m_htSelStart.Unset();
} }
} }
break; break;
@@ -2239,7 +2244,7 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{ {
// TreeView_GetItemRect() will return false if item is not visible, // TreeView_GetItemRect() will return false if item is not visible,
// which may happen perfectly well // which may happen perfectly well
if ( TreeView_GetItemRect(GetHwnd(), HITEM(selections[n]), if ( TreeView_GetItemRect(GetHwnd(), HITEM_PTR(selections[n]),
&rect, true) ) &rect, true) )
{ {
::InvalidateRect(GetHwnd(), &rect, false); ::InvalidateRect(GetHwnd(), &rect, false);