From 8e70ef3aec40d31a619fad6e5eb1d9a6609d5858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sat, 8 Oct 2016 18:26:10 +0200 Subject: [PATCH] OS X: Fix wxDataViewBitmapRenderer autosizing wxDataViewCtrl code expects, quite reasonably, that NSCell's cellSize: will behave as documented and return the minimal size for image cells too. Unfortunately, that's not the case. A cell created as NSImageCell, which seems to exists for exactly this purpose, will always return the size as (0,0), regardless of whether it has any image set or not an regardless of its size. On the other hand, a cell created with NSCell.imageCell constructor sizes itself correctly, but is not a NSImageCell instance and somehow interferes with other wxDataViewCtrl rendering, presumably due to its special status. The simplest fix to make the sizing work correctly therefore seems to be to specialize NSImageCell and implement its (trivial) cellSize: method. --- include/wx/osx/cocoa/dataview.h | 11 +++++++++++ src/osx/cocoa/dataview.mm | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index f3d613d19d..d7cca628b0 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -350,6 +350,17 @@ private: -(NSSize) cellSize; @end +// ============================================================================ +// wxImageCell: used for bitmap renderer +// ============================================================================ + +@interface wxImageCell : NSImageCell +{ +} + + -(NSSize) cellSize; +@end + // ============================================================================ // wxImageTextCell // ============================================================================ diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 6fd76e988f..257687338e 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1226,6 +1226,21 @@ outlineView:(NSOutlineView*)outlineView @end +// ============================================================================ +// wxImageTextCell +// ============================================================================ +@implementation wxImageCell + +-(NSSize) cellSize +{ + if ([self image] != nil) + return [[self image] size]; + else + return NSZeroSize; +} + +@end + // ============================================================================ // wxImageTextCell // ============================================================================ @@ -2804,10 +2819,7 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(const wxString& varianttype, int align) : wxDataViewRenderer(varianttype,mode,align) { - NSImageCell* cell; - - - cell = [[NSImageCell alloc] init]; + NSCell* cell = [[wxImageCell alloc] init]; SetNativeData(new wxDataViewRendererNativeData(cell)); [cell release]; }