Implement SortItems for native OS X wxListCtrl to match behavior with other impls, and request an update when an item's data changes.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43839 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1881,6 +1881,8 @@ long wxListCtrl::InsertItem(wxListItem& info)
|
|||||||
info.m_itemId = count;
|
info.m_itemId = count;
|
||||||
|
|
||||||
m_dbImpl->MacInsertItem(info.m_itemId, &info );
|
m_dbImpl->MacInsertItem(info.m_itemId, &info );
|
||||||
|
wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(info.m_itemId);
|
||||||
|
|
||||||
wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
|
wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
|
||||||
event.SetEventObject( this );
|
event.SetEventObject( this );
|
||||||
event.m_itemIndex = info.m_itemId;
|
event.m_itemIndex = info.m_itemId;
|
||||||
@@ -2025,6 +2027,12 @@ bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
|
|||||||
{
|
{
|
||||||
m_compareFunc = fn;
|
m_compareFunc = fn;
|
||||||
m_compareFuncData = data;
|
m_compareFuncData = data;
|
||||||
|
SortDataBrowserContainer( m_dbImpl->GetControlRef(), kDataBrowserNoItem, true);
|
||||||
|
|
||||||
|
// we need to do this after each call, else we get a crash from wxPython when
|
||||||
|
// SortItems is called the second time.
|
||||||
|
m_compareFunc = NULL;
|
||||||
|
m_compareFuncData = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2847,18 +2855,22 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI
|
|||||||
wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
|
wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
|
||||||
wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
|
wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
|
||||||
|
|
||||||
// FIXME: This code causes a crash in wxPython for some reason
|
wxListCtrlCompare func = list->GetCompareFunc();
|
||||||
// and moreover, further testing shows that the column click event
|
if (func != NULL)
|
||||||
// is only sent to the list ctrl after the native control has finished
|
{
|
||||||
// sorting items anyway. So just disable this for now.
|
long item1 = -1;
|
||||||
|
long item2 = -1;
|
||||||
//wxListCtrlCompare func = list->GetCompareFunc();
|
if (item && item->HasColumnInfo(0))
|
||||||
//long item1 = GetLineFromItem(item);
|
item1 = item->GetColumnInfo(0)->GetData();
|
||||||
//long item2 = GetLineFromItem(otherItem);
|
if (otherItem && otherItem->HasColumnInfo(0))
|
||||||
|
item2 = otherItem->GetColumnInfo(0)->GetData();
|
||||||
//if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
|
|
||||||
// return func(item1, item2, list->GetCompareFuncData()) >= 0;
|
if (item1 > -1 && item2 > -1)
|
||||||
|
{
|
||||||
|
int result = func(item1, item2, list->GetCompareFuncData());
|
||||||
|
return result >= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (item->HasColumnInfo(colId))
|
if (item->HasColumnInfo(colId))
|
||||||
itemText = item->GetColumnInfo(colId)->GetText();
|
itemText = item->GetColumnInfo(colId)->GetText();
|
||||||
if (otherItem->HasColumnInfo(colId))
|
if (otherItem->HasColumnInfo(colId))
|
||||||
@@ -2905,8 +2917,19 @@ void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsign
|
|||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
|
wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
|
||||||
|
bool hasInfo = listItem->HasColumnInfo( column );
|
||||||
listItem->SetColumnInfo( column, item );
|
listItem->SetColumnInfo( column, item );
|
||||||
UpdateState(dataItem, item);
|
UpdateState(dataItem, item);
|
||||||
|
|
||||||
|
wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
|
||||||
|
|
||||||
|
// NB: When this call was made before a control was completely shown, it would
|
||||||
|
// update the item prematurely (i.e. no text would be listed) and, on show,
|
||||||
|
// only the sorted column would be refreshed, meaning only first column text labels
|
||||||
|
// would be shown. Making sure not to update items until the control is visible
|
||||||
|
// seems to fix this issue.
|
||||||
|
if (hasInfo && list->IsShown())
|
||||||
|
UpdateItem( wxMacDataBrowserRootContainer, listItem , kMinColumnId + column );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user