X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03647350fc7cd141953c72e0284e928847d30f44..a533f0504f8067182cad0c26cbba7074248c8c37:/src/osx/cocoa/listbox.mm diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index e517ba97af..9aced58b09 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -33,7 +33,7 @@ class wxListWidgetCocoaImpl; -@interface wxNSTableDataSource : NSObject +@interface wxNSTableDataSource : NSObject wxOSX_10_6_AND_LATER() { wxListWidgetCocoaImpl* impl; } @@ -53,7 +53,7 @@ class wxListWidgetCocoaImpl; @end -@interface wxNSTableView : NSTableView +@interface wxNSTableView : NSTableView wxOSX_10_6_AND_LATER() { } @@ -143,8 +143,8 @@ public : virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ; virtual void UpdateLineToEnd( unsigned int n); - virtual void controlAction(WXWidget slf, void* _cmd, void *sender); virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender); + protected : wxNSTableView* m_tableView ; @@ -285,6 +285,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 ( 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 // @@ -466,20 +493,6 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int WXUNUSED(n)) [m_tableView reloadData]; } -void wxListWidgetCocoaImpl::controlAction(WXWidget WXUNUSED(slf),void* WXUNUSED(_cmd), void *WXUNUSED(sender)) -{ - wxListBox *list = static_cast ( 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)) { wxListBox *list = static_cast ( GetWXPeer()); @@ -518,6 +531,7 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, // setting up the true table wxNSTableView* tableview = [[wxNSTableView alloc] init]; + [tableview setDelegate:tableview]; // only one multi-select mode available if ( (style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE) ) [tableview setAllowsMultipleSelection:YES];