From 43c1baf1bd59ab36b53364a3aa5a28cb08578308 Mon Sep 17 00:00:00 2001 From: Hartwig Wiesmann Date: Sat, 3 Feb 2018 21:03:49 +0100 Subject: [PATCH] Fix wxDataViewColumn::SetSortOrder() under macOS Don't check if we already sort by the column in SetSortOrder() as this meant the sort order couldn't be changed programmatically at all. Closes #15405. --- docs/changes.txt | 1 + src/osx/cocoa/dataview.mm | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 99680a7aac..5fe6a0ba0b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -282,6 +282,7 @@ wxOSX: - Fix selecting RGB bitmaps (with no alpha channel) into wxMemoryDC. - Fix updating radio groups when menu item is inserted/removed from wxMenu. - Allow changing alignment styles after wxTextCtrl creation (Andreas Falkenhahn). +- Fix wxDataViewColumn::SetSortOrder() (hartwigw). wxQt diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index c48c9c976e..e160b1ad92 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -3513,23 +3513,27 @@ void wxDataViewColumn::SetSortable(bool sortable) void wxDataViewColumn::SetSortOrder(bool ascending) { - if (m_ascending != ascending) + NSTableColumn* const tableColumn = m_NativeDataPtr->GetNativeColumnPtr(); + NSTableView* tableView = [tableColumn tableView]; + + wxCHECK_RET( tableView, wxS("Column has to be associated with a table view when the sorting order is set") ); + + if ( (m_ascending != ascending) || ([tableColumn sortDescriptorPrototype] == nil) ) { m_ascending = ascending; - if (IsSortKey()) - { - // change sorting order: - NSArray* sortDescriptors; - NSSortDescriptor* sortDescriptor; - NSTableColumn* tableColumn; - tableColumn = m_NativeDataPtr->GetNativeColumnPtr(); - sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[[tableColumn sortDescriptorPrototype] key] ascending:m_ascending]; - sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; - [tableColumn setSortDescriptorPrototype:sortDescriptor]; - [[tableColumn tableView] setSortDescriptors:sortDescriptors]; - [sortDescriptor release]; - } + // change sorting order for the native implementation (this will + // trigger a call to outlineView:sortDescriptorsDidChange: where the + // wxWidget's sort descriptors are going to be set): + NSSortDescriptor* const + sortDescriptor = [[NSSortDescriptor alloc] + initWithKey:[NSString stringWithFormat:@"%ld",(long)[tableView columnWithIdentifier:[tableColumn identifier]]] + ascending:m_ascending]; + + NSArray* sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; + [tableColumn setSortDescriptorPrototype:sortDescriptor]; + [tableView setSortDescriptors:sortDescriptors]; + [sortDescriptor release]; } }