Implement support for wxCB_SORT in wxOSX wxComboBox

Insert the item at the correct location when this style is specified.

Closes https://github.com/wxWidgets/wxWidgets/pull/1438
This commit is contained in:
oneeyeman1 2019-07-23 00:10:43 -05:00 committed by Vadim Zeitlin
parent fb2c17c193
commit ab7ba98dbc
2 changed files with 18 additions and 3 deletions

View File

@ -38,8 +38,7 @@
allows the user to choose from the list of options but doesn't allow
to enter a value not present in the list.
@style{wxCB_SORT}
Sorts the entries in the list alphabetically. Notice that this style
is not currently implemented in wxOSX.
Sorts the entries in the list alphabetically.
@style{wxTE_PROCESS_ENTER}
The control will generate the event @c wxEVT_TEXT_ENTER that can be
handled by the program. Otherwise, i.e. either if this style not

View File

@ -264,7 +264,23 @@ int wxNSComboBoxControl::GetNumberOfItems() const
void wxNSComboBoxControl::InsertItem(int pos, const wxString& item)
{
[m_comboBox insertItemWithObjectValue:wxCFStringRef( item , m_wxPeer->GetFont().GetEncoding() ).AsNSString() atIndex:pos];
wxCFStringRef itemLabel( item, m_wxPeer->GetFont().GetEncoding() );
NSString* const cocoaStr = itemLabel.AsNSString();
if ( m_wxPeer->HasFlag(wxCB_SORT) )
{
NSArray* const objectValues = m_comboBox.objectValues;
pos = [objectValues indexOfObject: cocoaStr
inSortedRange: NSMakeRange(0, objectValues.count)
options: NSBinarySearchingInsertionIndex
usingComparator: ^(id obj1, id obj2)
{
return [obj1 caseInsensitiveCompare: obj2];
}];
}
[m_comboBox insertItemWithObjectValue:cocoaStr atIndex:pos];
}
void wxNSComboBoxControl::RemoveItem(int pos)