diff --git a/interface/wx/combobox.h b/interface/wx/combobox.h index 7c67126551..7c2d4314d6 100644 --- a/interface/wx/combobox.h +++ b/interface/wx/combobox.h @@ -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 diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index 84fd62cb2a..71aa165d44 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -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)