Fix selection event generation in wxMac wxListBox
Prevents deselecting the selected item in single-selection listbox. Also generate correct events in the multi-selection case by reusing the existing wxListBoxBase::CalcAndSendEvent() method. Closes #15603.
This commit is contained in:
@@ -125,6 +125,12 @@ public:
|
||||
bool MacGetBlockEvents() const { return m_blockEvents; }
|
||||
|
||||
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]; }
|
||||
|
||||
protected:
|
||||
// callback for derived classes which may have to insert additional data
|
||||
// at a certain line - which cannot be predetermined for sorted list data
|
||||
|
@@ -297,24 +297,34 @@ protected:
|
||||
|
||||
int row = [self selectedRow];
|
||||
|
||||
if (row == -1)
|
||||
{
|
||||
// no row selected
|
||||
}
|
||||
else
|
||||
{
|
||||
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
|
||||
wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
|
||||
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
|
||||
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
|
||||
wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
|
||||
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
|
||||
|
||||
if ((row < 0) || (row > (int) list->GetCount())) // OS X can select an item below the last item
|
||||
return;
|
||||
|
||||
if ( !list->MacGetBlockEvents() )
|
||||
list->HandleLineEvent( row, false );
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFont:(NSFont *)aFont
|
||||
{
|
||||
|
Reference in New Issue
Block a user