X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f4c24d3da4e0b4a85ce4a5503cf401b4bdb021a5..3f7564f229450a9c036141878ee75cc09078a945:/src/osx/cocoa/listbox.mm?ds=sidebyside diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 79389e8306..199363d247 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: listbox.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -33,10 +33,7 @@ class wxListWidgetCocoaImpl; -@interface wxNSTableDataSource : NSObject -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - -#endif +@interface wxNSTableDataSource : NSObject wxOSX_10_6_AND_LATER() { wxListWidgetCocoaImpl* impl; } @@ -56,10 +53,7 @@ class wxListWidgetCocoaImpl; @end -@interface wxNSTableView : NSTableView -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - -#endif +@interface wxNSTableView : NSTableView wxOSX_10_6_AND_LATER() { } @@ -141,6 +135,7 @@ public : // accessing content virtual unsigned int ListGetCount() const ; + virtual int DoListHitTest( const wxPoint& inpoint ) const; int ListGetColumnType( int col ) { @@ -150,8 +145,8 @@ public : virtual void UpdateLineToEnd( unsigned int n); virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender); - virtual bool DoHandleKeyEvent(NSEvent *event); + protected : wxNSTableView* m_tableView ; @@ -166,7 +161,7 @@ protected : - (id) init { - [super init]; + self = [super init]; column = nil; return self; } @@ -229,7 +224,7 @@ protected: - (id) init { - [super init]; + self = [super init]; impl = nil; return self; } @@ -319,6 +314,24 @@ protected: } +- (void)setFont:(NSFont *)aFont +{ + NSArray *tableColumns = [self tableColumns]; + unsigned int columnIndex = [tableColumns count]; + while (columnIndex--) + [[(NSTableColumn *)[tableColumns objectAtIndex:columnIndex] dataCell] setFont:aFont]; + + [self setRowHeight:[gNSLayoutManager defaultLineHeightForFont:aFont]+2]; +} + +- (void) setControlSize:(NSControlSize) size +{ + NSArray *tableColumns = [self tableColumns]; + unsigned int columnIndex = [tableColumns count]; + while (columnIndex--) + [[(NSTableColumn *)[tableColumns objectAtIndex:columnIndex] dataCell] setControlSize:size]; +} + @end // @@ -374,6 +387,11 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const [col1 setWidth:1000]; } [col1 setResizingMask: NSTableColumnAutoresizingMask]; + + wxListBox *list = static_cast ( GetWXPeer()); + if ( list != NULL ) + [[col1 dataCell] setFont:list->GetFont().OSXGetNSFont()]; + wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable ); [col1 setColumn:wxcol]; @@ -393,6 +411,39 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , con [checkbox setTitle:@""]; [checkbox setButtonType:NSSwitchButton]; [col1 setDataCell:checkbox] ; + + wxListBox *list = static_cast ( GetWXPeer()); + if ( list != NULL ) + { + NSControlSize size = NSRegularControlSize; + + switch ( list->GetWindowVariant() ) + { + case wxWINDOW_VARIANT_NORMAL : + size = NSRegularControlSize; + break ; + + case wxWINDOW_VARIANT_SMALL : + size = NSSmallControlSize; + break ; + + case wxWINDOW_VARIANT_MINI : + size = NSMiniControlSize; + break ; + + case wxWINDOW_VARIANT_LARGE : + size = NSRegularControlSize; + break ; + + default: + break ; + } + + [[col1 dataCell] setControlSize:size]; + // although there is no text, it may help to get the correct vertical layout + [[col1 dataCell] setFont:list->GetFont().OSXGetNSFont()]; + } + [checkbox release]; unsigned formerColCount = [m_tableView numberOfColumns]; @@ -449,7 +500,8 @@ void wxListWidgetCocoaImpl::ListSetSelection( unsigned int n, bool select, bool { // TODO if ( select ) - [m_tableView selectRow: n byExtendingSelection:multi]; + [m_tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:n] + byExtendingSelection:multi]; else [m_tableView deselectRow: n]; @@ -468,7 +520,7 @@ int wxListWidgetCocoaImpl::ListGetSelections( wxArrayInt& aSelections ) const for ( int i = 0; i < count; ++i) { - if ([m_tableView isRowSelected:count]) + if ([m_tableView isRowSelected:i]) aSelections.Add(i); } @@ -512,18 +564,6 @@ void wxListWidgetCocoaImpl::controlDoubleAction(WXWidget WXUNUSED(slf),void* WXU list->HandleLineEvent( sel, true ); } -bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) -{ - wxKeyEvent wxevent(wxEVT_KEY_DOWN); - SetupKeyEvent( wxevent, event ); - wxevent.SetEventObject(GetWXPeer()); - bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent); - - // no interpretKeyEvents here, but rerouting to native keyhandling - - return result; -} - // accessing content @@ -571,115 +611,21 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds ); // temporary hook for dnd - [tableview registerForDraggedTypes:[NSArray arrayWithObjects: - NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]]; + // [tableview registerForDraggedTypes:[NSArray arrayWithObjects: + // NSStringPboardType, NSFilenamesPboardType, (NSString*) kPasteboardTypeFileURLPromise, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]]; [ds setImplementation:c]; return c; } -int wxListBox::DoListHitTest(const wxPoint& WXUNUSED(inpoint)) const -{ -#if wxOSX_USE_CARBON - OSStatus err; - - // There are few reasons why this is complicated: - // 1) There is no native HitTest function for Mac - // 2) GetDataBrowserItemPartBounds only works on visible items - // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight - // because what it returns is basically inaccurate in the context - // of the coordinates we want here, but we use this as a guess - // for where the first visible item lies - - wxPoint point = inpoint; - - // get column property ID (req. for call to itempartbounds) - DataBrowserTableViewColumnID colId = 0; - err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); - wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty")); - - // OK, first we need to find the first visible item we have - - // this will be the "low" for our binary search. There is no real - // easy way around this, as we will need to do a SLOW linear search - // until we find a visible item, but we can do a cheap calculation - // via the row height to speed things up a bit - UInt32 scrollx, scrolly; - err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly); - wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition")); - - UInt16 height; - err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height); - wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight")); - - // these indices are 0-based, as usual, so we need to add 1 to them when - // passing them to data browser functions which use 1-based indices - int low = scrolly / height, - high = GetCount() - 1; - - // search for the first visible item (note that the scroll guess above - // is the low bounds of where the item might lie so we only use that as a - // starting point - we should reach it within 1 or 2 iterations of the loop) - while ( low <= high ) - { - Rect bounds; - err = GetDataBrowserItemPartBounds( - m_peer->GetControlRef(), low + 1, colId, - kDataBrowserPropertyEnclosingPart, - &bounds); // note +1 to translate to Mac ID - if ( err == noErr ) - break; - - // errDataBrowserItemNotFound is expected as it simply means that the - // item is not currently visible -- but other errors are not - wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND, - wxT("Unexpected error from GetDataBrowserItemPartBounds") ); - - low++; - } - - // NOW do a binary search for where the item lies, searching low again if - // we hit an item that isn't visible - while ( low <= high ) - { - int mid = (low + high) / 2; - - Rect bounds; - err = GetDataBrowserItemPartBounds( - m_peer->GetControlRef(), mid + 1, colId, - kDataBrowserPropertyEnclosingPart, - &bounds); //note +1 to trans to mac id - wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound, - wxNOT_FOUND, - wxT("Unexpected error from GetDataBrowserItemPartBounds") ); - - if ( err == errDataBrowserItemNotFound ) - { - // item not visible, attempt to find a visible one - // search lower - high = mid - 1; - } - else // visible item, do actual hitttest - { - // if point is within the bounds, return this item (since we assume - // all x coords of items are equal we only test the x coord in - // equality) - if ((point.x >= bounds.left && point.x <= bounds.right) && - (point.y >= bounds.top && point.y <= bounds.bottom) ) - { - // found! - return mid; - } - - if ( point.y < bounds.top ) - // index(bounds) greater then key(point) - high = mid - 1; - else - // index(bounds) less then key(point) - low = mid + 1; - } - } -#endif - return wxNOT_FOUND; +int wxListWidgetCocoaImpl::DoListHitTest(const wxPoint& inpoint) const +{ + // translate inpoint to listpoint via scrollview + NSPoint p = wxToNSPoint( m_osxView, inpoint ); + p = [m_osxView convertPoint:p toView:m_tableView]; + // hittest using new point + NSInteger i = [m_tableView rowAtPoint:p]; + return i; } #endif // wxUSE_LISTBOX