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.
This commit is contained in:
Václav Slavík
2016-10-08 18:26:10 +02:00
parent 8ad375592c
commit 8e70ef3aec
2 changed files with 27 additions and 4 deletions

View File

@@ -350,6 +350,17 @@ private:
-(NSSize) cellSize;
@end
// ============================================================================
// wxImageCell: used for bitmap renderer
// ============================================================================
@interface wxImageCell : NSImageCell
{
}
-(NSSize) cellSize;
@end
// ============================================================================
// wxImageTextCell
// ============================================================================

View File

@@ -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];
}