X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ffad7b0dd2907634d93daacfb54d503c6f7a4ad4..ab52bac815bed0189bb0ba3b52a15e093c354533:/src/osx/cocoa/listbox.mm diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 270d3ba4df..ded09fb1e6 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" @@ -54,14 +55,8 @@ class wxListWidgetCocoaImpl; @interface wxNSTableView : NSTableView { - wxListWidgetCocoaImpl* impl; } -- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation; -- (wxListWidgetCocoaImpl*) implementation; -- (void)clickedAction: (id) sender; -- (void)doubleClickedAction: (id) sender; - @end // @@ -147,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(WXWidget slf, void* _cmd, void *sender); protected : wxNSTableView* m_tableView ; @@ -211,7 +209,7 @@ public : virtual wxString GetStringValue() const { if ( [value isKindOfClass:[NSString class]] ) - return wxCFStringRef( (CFStringRef) [value retain] ).AsString(); + return wxCFStringRef::AsString( (NSString*) value ); return wxEmptyString; } @@ -241,6 +239,7 @@ protected: - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { + wxUnusedVar(aTableView); if ( impl ) return impl->ListGetCount(); return 0; @@ -250,6 +249,7 @@ protected: objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { + wxUnusedVar(aTableView); wxNSTableColumn* tablecol = (wxNSTableColumn *)aTableColumn; wxListBox* lb = dynamic_cast(impl->GetWXPeer()); wxCocoaTableColumn* col = [tablecol column]; @@ -263,6 +263,7 @@ protected: setObjectValue:(id)value forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { + wxUnusedVar(aTableView); wxNSTableColumn* tablecol = (wxNSTableColumn *)aTableColumn; wxListBox* lb = dynamic_cast(impl->GetWXPeer()); wxCocoaTableColumn* col = [tablecol column]; @@ -274,55 +275,13 @@ protected: @implementation wxNSTableView -- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation -{ - impl = theImplementation; -} - -- (wxListWidgetCocoaImpl*) implementation -{ - return impl; -} - -- (id) init ++ (void)initialize { - [super init]; - impl = NULL; - [self setTarget: self]; - [self setAction: @selector(clickedAction:)]; - [self setDoubleAction: @selector(doubleClickedAction:)]; - return self; -} - -- (void) clickedAction: (id) sender -{ - if ( impl ) + static BOOL initialized = NO; + if (!initialized) { - wxListBox *list = static_cast ( impl->GetWXPeer()); - wxCHECK_RET( list != NULL , wxT("Listbox expected")); - - wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() ); - - int sel = [self 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) doubleClickedAction: (id) sender -{ - if ( impl ) - { - wxListBox *list = static_cast ( impl->GetWXPeer()); - wxCHECK_RET( list != NULL , wxT("Listbox expected")); - - int sel = [self clickedRow]; - if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?) - return; - - list->HandleLineEvent( sel, true ); + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); } } @@ -335,6 +294,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() @@ -352,8 +312,8 @@ unsigned int wxListWidgetCocoaImpl::ListGetCount() const // columns // -wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, - wxAlignment just, int defaultWidth) +wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const wxString& WXUNUSED(title), bool editable, + wxAlignment WXUNUSED(just), int defaultWidth) { wxNSTableColumn* col1 = [[wxNSTableColumn alloc] init]; [col1 setEditable:editable]; @@ -369,8 +329,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]; @@ -379,8 +348,8 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const return wxcol; } -wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, - wxAlignment just, int defaultWidth ) +wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , const wxString& WXUNUSED(title), bool editable, + wxAlignment WXUNUSED(just), int defaultWidth ) { wxNSTableColumn* col1 = [[wxNSTableColumn alloc] init]; [col1 setEditable:editable]; @@ -403,8 +372,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]; @@ -418,31 +389,12 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , con // inserting / removing lines // -void wxListWidgetCocoaImpl::ListInsert( unsigned int n ) +void wxListWidgetCocoaImpl::ListInsert( unsigned int WXUNUSED(n) ) { -#if 0 - { - wxListBoxCocoaLine* line = new wxListBoxCocoaLine(); - line->SetLabel(items[i]); - if ( m_items.size() <= n+i ) - m_items.push_back( line ); - else - m_items.insert(m_items.begin()+n, line); -/* - NSMutableDictionary* line = [[NSMutableDictionary alloc] init]; - [line setObject:wxCFStringRef(items[i]).AsNSString() forKey:column1]; - NSMutableArray* array = [m_dataSource items]; - if ( [array count] <= n+i ) - [array addObject:line]; - else - [array insertObject:line atIndex:n]; -*/ - } -#endif [m_tableView reloadData]; } -void wxListWidgetCocoaImpl::ListDelete( unsigned int n ) +void wxListWidgetCocoaImpl::ListDelete( unsigned int WXUNUSED(n) ) { [m_tableView reloadData]; } @@ -502,29 +454,54 @@ void wxListWidgetCocoaImpl::ListScrollTo( unsigned int n ) } -void wxListWidgetCocoaImpl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) +void wxListWidgetCocoaImpl::UpdateLine( unsigned int WXUNUSED(n), wxListWidgetColumn* WXUNUSED(col) ) { // TODO optimize [m_tableView reloadData]; } -void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n) +void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int WXUNUSED(n)) { // TODO optimize [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()); + 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 wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, - wxWindowMac* parent, - wxWindowID id, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size, long style, - long extraStyle) + long WXUNUSED(extraStyle)) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSScrollView* scrollview = [[NSScrollView alloc] initWithFrame:r]; @@ -537,13 +514,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]; @@ -551,16 +525,27 @@ 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]; + [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; } -int wxListBox::DoListHitTest(const wxPoint& inpoint) const +int wxListBox::DoListHitTest(const wxPoint& WXUNUSED(inpoint)) const { #if wxOSX_USE_CARBON OSStatus err;