X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..037f9d3ba3a4c2b7835cf876398d65bbf4965605:/src/osx/cocoa/listbox.mm diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 2d43f9827f..45f1126bf4 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -14,6 +14,7 @@ #if wxUSE_LISTBOX #include "wx/listbox.h" +#include "wx/dnd.h" #ifndef WX_PRECOMP #include "wx/log.h" @@ -41,8 +42,8 @@ class wxListWidgetCocoaImpl; objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; -- (id)tableView:(NSTableView *)aTableView - setObjectValue:(NSTableColumn *)aTableColumn +- (void)tableView:(NSTableView *)aTableView + setObjectValue:(id)value forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView; @@ -54,12 +55,8 @@ class wxListWidgetCocoaImpl; @interface wxNSTableView : NSTableView { - wxListWidgetCocoaImpl* impl; } -- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation; -- (wxListWidgetCocoaImpl*) implementation; - @end // @@ -145,6 +142,9 @@ 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(void* _cmd); protected : wxNSTableView* m_tableView ; @@ -272,17 +272,16 @@ protected: @implementation wxNSTableView -- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation -{ - impl = theImplementation; -} - -- (wxListWidgetCocoaImpl*) implementation ++ (void)initialize { - return impl; + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); + } } - @end // @@ -292,6 +291,7 @@ protected: wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) : wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data) { + InstallEventHandler( tableview ); } wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl() @@ -326,8 +326,17 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const { [col1 setMaxWidth:defaultWidth]; [col1 setMinWidth:defaultWidth]; + [col1 setWidth:defaultWidth]; } - + else + { + [col1 setMaxWidth:1000]; + [col1 setMinWidth:10]; + // temporary hack, because I cannot get the automatic column resizing + // to work properly + [col1 setWidth:1000]; + } + [col1 setResizingMask: NSTableColumnAutoresizingMask]; wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable ); [col1 setColumn:wxcol]; @@ -360,8 +369,10 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , con { [col1 setMaxWidth:defaultWidth]; [col1 setMinWidth:defaultWidth]; + [col1 setWidth:defaultWidth]; } + [col1 setResizingMask: NSTableColumnNoResizing]; wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable ); [col1 setColumn:wxcol]; @@ -428,17 +439,27 @@ void wxListWidgetCocoaImpl::ListSetSelection( unsigned int n, bool select, bool int wxListWidgetCocoaImpl::ListGetSelection() const { - return 0; + return [m_tableView selectedRow]; } int wxListWidgetCocoaImpl::ListGetSelections( wxArrayInt& aSelections ) const { - return 0; + aSelections.Empty(); + + int count = ListGetCount(); + + for ( int i = 0; i < count; ++i) + { + if ([m_tableView isRowSelected:count]) + aSelections.Add(i); + } + + return aSelections.Count(); } bool wxListWidgetCocoaImpl::ListIsSelected( unsigned int n ) const { - return false; + return [m_tableView isRowSelected:n]; } // display @@ -461,6 +482,31 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n) [m_tableView reloadData]; } +void wxListWidgetCocoaImpl::controlAction(WXWidget slf,void* _cmd, void *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(void* _cmd) +{ + wxListBox *list = static_cast ( GetWXPeer()); + wxCHECK_RET( list != NULL , wxT("Listbox expected")); + + 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, true ); +} // accessing content @@ -473,8 +519,6 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, long style, long extraStyle) { - NSView* superv = (wxpeer->GetParent()->GetHandle() ); - NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSScrollView* scrollview = [[NSScrollView alloc] initWithFrame:r]; @@ -486,13 +530,10 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, [scrollview setHasHorizontalScroller:YES]; [scrollview setAutohidesScrollers: ((style & wxLB_ALWAYS_SB) ? NO : YES)]; - + // setting up the true table wxNSTableView* tableview = [[wxNSTableView alloc] init]; - [scrollview setDocumentView:tableview]; - [tableview release]; - // only one multi-select mode available if ( (style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE) ) [tableview setAllowsMultipleSelection:YES]; @@ -500,12 +541,22 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, // simple listboxes have no header row [tableview setHeaderView:nil]; - [tableview setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle]; + if ( style & wxLB_HSCROLL ) + [tableview setColumnAutoresizingStyle:NSTableViewNoColumnAutoresizing]; + else + [tableview setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle]; + wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init]; [tableview setDataSource:ds]; - [superv addSubview:scrollview]; + [scrollview setDocumentView:tableview]; + [tableview release]; + wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds ); - [tableview setImplementation:c]; + + // temporary hook for dnd + [tableview registerForDraggedTypes:[NSArray arrayWithObjects: + NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]]; + [ds setImplementation:c]; return c; }