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; }
|
bool MacGetBlockEvents() const { return m_blockEvents; }
|
||||||
|
|
||||||
virtual void HandleLineEvent( unsigned int n, bool doubleClick );
|
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:
|
protected:
|
||||||
// callback for derived classes which may have to insert additional data
|
// callback for derived classes which may have to insert additional data
|
||||||
// at a certain line - which cannot be predetermined for sorted list data
|
// at a certain line - which cannot be predetermined for sorted list data
|
||||||
|
@@ -297,23 +297,33 @@ protected:
|
|||||||
|
|
||||||
int row = [self selectedRow];
|
int row = [self selectedRow];
|
||||||
|
|
||||||
if (row == -1)
|
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
|
||||||
{
|
wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
|
||||||
// no row selected
|
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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
|
// 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;
|
return;
|
||||||
|
}
|
||||||
if ( !list->MacGetBlockEvents() )
|
if ( !list->DoChangeSingleSelection(row) )
|
||||||
list->HandleLineEvent( row, false );
|
return ;
|
||||||
|
list->HandleLineEvent( row, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFont:(NSFont *)aFont
|
- (void)setFont:(NSFont *)aFont
|
||||||
|
Reference in New Issue
Block a user