using common notification mechanism for selection changes (key or mouse), see #10406

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62133 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-09-25 16:57:08 +00:00
parent b80fdc0299
commit 81eaa4dab2

View File

@@ -34,6 +34,9 @@
class wxListWidgetCocoaImpl; class wxListWidgetCocoaImpl;
@interface wxNSTableDataSource : NSObject @interface wxNSTableDataSource : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSTableViewDataSource>
#endif
{ {
wxListWidgetCocoaImpl* impl; wxListWidgetCocoaImpl* impl;
} }
@@ -54,6 +57,9 @@ class wxListWidgetCocoaImpl;
@end @end
@interface wxNSTableView : NSTableView @interface wxNSTableView : NSTableView
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSTableViewDelegate>
#endif
{ {
} }
@@ -143,7 +149,6 @@ public :
virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ; virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ;
virtual void UpdateLineToEnd( unsigned int n); virtual void UpdateLineToEnd( unsigned int n);
virtual void controlAction(WXWidget slf, void* _cmd, void *sender);
virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender); virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
protected : protected :
wxNSTableView* m_tableView ; wxNSTableView* m_tableView ;
@@ -285,6 +290,33 @@ protected:
} }
} }
- (void) tableViewSelectionDidChange: (NSNotification *) notification
{
wxUnusedVar(notification);
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"));
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
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 );
}
}
@end @end
// //
@@ -466,20 +498,6 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int WXUNUSED(n))
[m_tableView reloadData]; [m_tableView reloadData];
} }
void wxListWidgetCocoaImpl::controlAction(WXWidget WXUNUSED(slf),void* WXUNUSED(_cmd), void *WXUNUSED(sender))
{
wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
int sel = [m_tableView clickedRow];
if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
return;
list->HandleLineEvent( sel, false );
}
void wxListWidgetCocoaImpl::controlDoubleAction(WXWidget WXUNUSED(slf),void* WXUNUSED(_cmd), void *WXUNUSED(sender)) void wxListWidgetCocoaImpl::controlDoubleAction(WXWidget WXUNUSED(slf),void* WXUNUSED(_cmd), void *WXUNUSED(sender))
{ {
wxListBox *list = static_cast<wxListBox*> ( GetWXPeer()); wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
@@ -518,6 +536,7 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
// setting up the true table // setting up the true table
wxNSTableView* tableview = [[wxNSTableView alloc] init]; wxNSTableView* tableview = [[wxNSTableView alloc] init];
[tableview setDelegate:tableview];
// only one multi-select mode available // only one multi-select mode available
if ( (style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE) ) if ( (style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE) )
[tableview setAllowsMultipleSelection:YES]; [tableview setAllowsMultipleSelection:YES];