Get rid of wxListCtrl::m_count in wxMSW.
This simplifies the code and fixes the bug with GetItemCount() returning wrong (old) value in wxEVT_LIST_INSERT_ITEM event handler as m_count wasn't updated by then yet. Closes #3793.
This commit is contained in:
@@ -156,6 +156,7 @@ wxMSW:
|
|||||||
- Fix reading of not NUL-terminated strings using wxRegKey (Steffen Olszewski).
|
- Fix reading of not NUL-terminated strings using wxRegKey (Steffen Olszewski).
|
||||||
- Fix unexpected change in MDI children order after showing a file dialog.
|
- Fix unexpected change in MDI children order after showing a file dialog.
|
||||||
- Don't send events for already selected radio popup menu items (Kinaou Hervé).
|
- Don't send events for already selected radio popup menu items (Kinaou Hervé).
|
||||||
|
- wxListCtrl::GetItemCount() in wxEVT_LIST_INSERT_ITEM is no longer off by 1.
|
||||||
|
|
||||||
wxOSX/Cocoa:
|
wxOSX/Cocoa:
|
||||||
|
|
||||||
|
@@ -409,8 +409,6 @@ protected:
|
|||||||
|
|
||||||
int m_colCount; // Windows doesn't have GetColumnCount so must
|
int m_colCount; // Windows doesn't have GetColumnCount so must
|
||||||
// keep track of inserted/deleted columns
|
// keep track of inserted/deleted columns
|
||||||
long m_count; // Keep track of item count to save calls to
|
|
||||||
// ListView_GetItemCount
|
|
||||||
|
|
||||||
// all wxMSWListItemData objects we use
|
// all wxMSWListItemData objects we use
|
||||||
wxVector<wxMSWListItemData *> m_internalData;
|
wxVector<wxMSWListItemData *> m_internalData;
|
||||||
|
@@ -248,7 +248,6 @@ void wxListCtrl::Init()
|
|||||||
m_ownsImageListState = false;
|
m_ownsImageListState = false;
|
||||||
|
|
||||||
m_colCount = 0;
|
m_colCount = 0;
|
||||||
m_count = 0;
|
|
||||||
m_textCtrl = NULL;
|
m_textCtrl = NULL;
|
||||||
|
|
||||||
m_hasAnyAttr = false;
|
m_hasAnyAttr = false;
|
||||||
@@ -1145,7 +1144,7 @@ bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
|
|||||||
// Gets the number of items in the list control
|
// Gets the number of items in the list control
|
||||||
int wxListCtrl::GetItemCount() const
|
int wxListCtrl::GetItemCount() const
|
||||||
{
|
{
|
||||||
return m_count;
|
return GetHwnd() ? ListView_GetItemCount(GetHwnd()) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxListCtrl::GetItemSpacing() const
|
wxSize wxListCtrl::GetItemSpacing() const
|
||||||
@@ -1382,10 +1381,6 @@ bool wxListCtrl::DeleteItem(long item)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_count--;
|
|
||||||
wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
|
|
||||||
wxT("m_count should match ListView_GetItemCount"));
|
|
||||||
|
|
||||||
// the virtual list control doesn't refresh itself correctly, help it
|
// the virtual list control doesn't refresh itself correctly, help it
|
||||||
if ( IsVirtual() )
|
if ( IsVirtual() )
|
||||||
{
|
{
|
||||||
@@ -1711,16 +1706,7 @@ long wxListCtrl::InsertItem(const wxListItem& info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const long rv = ListView_InsertItem(GetHwnd(), & item);
|
return ListView_InsertItem(GetHwnd(), &item);
|
||||||
|
|
||||||
// failing to insert the item is really unexpected
|
|
||||||
wxCHECK_MSG( rv != -1, rv, "failed to insert an item in wxListCtrl" );
|
|
||||||
|
|
||||||
m_count++;
|
|
||||||
wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
|
|
||||||
wxT("m_count should match ListView_GetItemCount"));
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long wxListCtrl::InsertItem(long index, const wxString& label)
|
long wxListCtrl::InsertItem(long index, const wxString& label)
|
||||||
@@ -2171,16 +2157,8 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LVN_DELETEITEM:
|
case LVN_DELETEITEM:
|
||||||
if ( m_count == 0 )
|
|
||||||
{
|
|
||||||
// this should be prevented by the post-processing code
|
|
||||||
// below, but "just in case"
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
eventType = wxEVT_LIST_DELETE_ITEM;
|
eventType = wxEVT_LIST_DELETE_ITEM;
|
||||||
event.m_itemIndex = iItem;
|
event.m_itemIndex = iItem;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LVN_INSERTITEM:
|
case LVN_INSERTITEM:
|
||||||
@@ -2576,9 +2554,6 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
|||||||
// the user should have access to it in OnDeleteAllItems() handler)
|
// the user should have access to it in OnDeleteAllItems() handler)
|
||||||
FreeAllInternalData();
|
FreeAllInternalData();
|
||||||
|
|
||||||
// the control is empty now, synchronize the cached number of items
|
|
||||||
// with the real one
|
|
||||||
m_count = 0;
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case LVN_DELETEITEM:
|
case LVN_DELETEITEM:
|
||||||
@@ -3102,9 +3077,6 @@ void wxListCtrl::SetItemCount(long count)
|
|||||||
{
|
{
|
||||||
wxLogLastError(wxT("ListView_SetItemCount"));
|
wxLogLastError(wxT("ListView_SetItemCount"));
|
||||||
}
|
}
|
||||||
m_count = count;
|
|
||||||
wxASSERT_MSG( m_count == ListView_GetItemCount(GetHwnd()),
|
|
||||||
wxT("m_count should match ListView_GetItemCount"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListCtrl::RefreshItem(long item)
|
void wxListCtrl::RefreshItem(long item)
|
||||||
|
Reference in New Issue
Block a user