diff --git a/include/wx/osx/listbox.h b/include/wx/osx/listbox.h index f716bf1ae8..2b84ad463c 100644 --- a/include/wx/osx/listbox.h +++ b/include/wx/osx/listbox.h @@ -126,10 +126,8 @@ public: virtual void HandleLineEvent( unsigned int n, bool doubleClick ); - // These are called by wxNSTableView - using wxListBoxBase::DoChangeSingleSelection; - using wxListBoxBase::CalcAndSendEvent; - int GetOldSelection() const { return m_oldSelections.empty() ? wxNOT_FOUND : m_oldSelections[0]; } + // This is called by wxNSTableView + void MacHandleSelectionChange(int row); protected: // callback for derived classes which may have to insert additional data diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 1fe0d48499..d8847e5ae3 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -301,29 +301,7 @@ protected: wxListBox* const list = wxDynamicCast(impl->GetWXPeer(), wxListBox); wxCHECK_RET( list != NULL , "Associated control should be a wxListBox" ); - // Correct notification events for multiselection list, like in Carbon version - if (list->HasMultipleSelection() && !list->MacGetBlockEvents()) - { - list->CalcAndSendEvent(); - return; - } - - if ( !list->MacGetBlockEvents() ) - { - // OS X can select an item below the last item. In that case keep the old selection because - // in wxWidgets API there is no notification event for removing the selection from a single-selection list box. - // Otherwise call DoChangeSingleSelection so GetOldSelection() will return the correct value if row < 0 later. - if ((row < 0) || (row > (int) list->GetCount())) - { - int oldsel = list->GetOldSelection(); - if (oldsel >= 0) - list->SetSelection(oldsel); - return; - } - if ( !list->DoChangeSingleSelection(row) ) - return ; - list->HandleLineEvent( row, false ); - } + list->MacHandleSelectionChange(row); } - (void)setFont:(NSFont *)aFont diff --git a/src/osx/listbox_osx.cpp b/src/osx/listbox_osx.cpp index f824848ec0..75b1ad9750 100644 --- a/src/osx/listbox_osx.cpp +++ b/src/osx/listbox_osx.cpp @@ -420,6 +420,36 @@ void wxListBox::HandleLineEvent( unsigned int n, bool doubleClick ) HandleWindowEvent(event); } +void wxListBox::MacHandleSelectionChange(int row) +{ + // Correct notification events for multiselection list, like in Carbon version + if ( HasMultipleSelection() && !MacGetBlockEvents() ) + { + CalcAndSendEvent(); + return; + } + + if ( !MacGetBlockEvents() ) + { + // OS X can select an item below the last item. In that case keep the old selection because + // in wxWidgets API there is no notification event for removing the selection from a single-selection list box. + // Otherwise call DoChangeSingleSelection so GetOldSelection() will return the correct value if row < 0 later. + if ((row < 0) || (row > (int) GetCount())) + { + if ( !m_oldSelections.empty() ) + { + const int oldsel = m_oldSelections[0]; + if (oldsel >= 0) + SetSelection(oldsel); + } + return; + } + if ( !DoChangeSingleSelection(row) ) + return ; + HandleLineEvent( row, false ); + } +} + // // common list cell value operations //