Don't show anything in the cells which should be empty in Cocoa wxDVC.
Implement a custom NSTableColumn-derived class to return nil for the cells which shouldn't show anything at all because they are part of a container row. This finally fixes the totally wrong display of the first page of the dataview sample under OS X. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -498,6 +498,9 @@ public:
|
|||||||
wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects);
|
wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects);
|
||||||
wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const;
|
wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const;
|
||||||
|
|
||||||
|
// Cocoa-specific helpers
|
||||||
|
id GetItemAtRow(int row) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxCocoaOutlineDataSource* m_DataSource;
|
wxCocoaOutlineDataSource* m_DataSource;
|
||||||
|
|
||||||
|
@@ -34,6 +34,11 @@
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Classes used locally in dataview.mm
|
// Classes used locally in dataview.mm
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxCustomRendererObject
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@interface wxCustomRendererObject : NSObject <NSCopying>
|
@interface wxCustomRendererObject : NSObject <NSCopying>
|
||||||
{
|
{
|
||||||
@public
|
@public
|
||||||
@@ -77,6 +82,55 @@
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxDVCNSTableColumn: exists only to override NSTableColumn:dataCellForRow:
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@interface wxDVCNSTableColumn : NSTableColumn
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
-(id) dataCellForRow:(NSInteger)row;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxDVCNSTableColumn
|
||||||
|
|
||||||
|
-(id) dataCellForRow:(NSInteger)row
|
||||||
|
{
|
||||||
|
// what we want to do here is to simply return nil for the cells which
|
||||||
|
// shouldn't show anything as otherwise we would show e.g. empty combo box
|
||||||
|
// or progress cells in the columns using the corresponding types even for
|
||||||
|
// the container rows which is wrong
|
||||||
|
|
||||||
|
// half of the problem is just finding the objects we need from the column
|
||||||
|
// pointer which is itself stashed inside wxPointerObject which we use as
|
||||||
|
// our identifier
|
||||||
|
const wxDataViewColumn * const
|
||||||
|
dvCol = static_cast<wxDataViewColumn *>(
|
||||||
|
[(wxPointerObject *)[self identifier] pointer]
|
||||||
|
);
|
||||||
|
|
||||||
|
const wxDataViewCtrl * const dvc = dvCol->GetOwner();
|
||||||
|
const wxCocoaDataViewControl * const
|
||||||
|
peer = static_cast<wxCocoaDataViewControl *>(dvc->GetPeer());
|
||||||
|
|
||||||
|
|
||||||
|
// once we do have everything, simply ask NSOutlineView for the item...
|
||||||
|
const id item = peer->GetItemAtRow(row);
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
// ... and if it succeeded, ask the model whether it has any value
|
||||||
|
wxDataViewItem dvItem([((wxPointerObject*) item) pointer]);
|
||||||
|
|
||||||
|
if ( !dvc->GetModel()->HasValue(dvItem, dvCol->GetModelColumn()) )
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [super dataCellForRow:row];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// local helpers
|
// local helpers
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -196,8 +250,8 @@ NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column)
|
|||||||
|
|
||||||
wxCHECK_MSG( renderer, NULL, "column should have a renderer" );
|
wxCHECK_MSG( renderer, NULL, "column should have a renderer" );
|
||||||
|
|
||||||
NSTableColumn * const nativeColumn(
|
wxDVCNSTableColumn * const nativeColumn(
|
||||||
[[NSTableColumn alloc] initWithIdentifier:
|
[[wxDVCNSTableColumn alloc] initWithIdentifier:
|
||||||
[[[wxPointerObject alloc] initWithPointer:
|
[[[wxPointerObject alloc] initWithPointer:
|
||||||
const_cast<wxDataViewColumn*>(column)]
|
const_cast<wxDataViewColumn*>(column)]
|
||||||
autorelease]]
|
autorelease]]
|
||||||
@@ -558,16 +612,20 @@ outlineView:(NSOutlineView*)outlineView
|
|||||||
objectValueForTableColumn:(NSTableColumn*)tableColumn
|
objectValueForTableColumn:(NSTableColumn*)tableColumn
|
||||||
byItem:(id)item
|
byItem:(id)item
|
||||||
{
|
{
|
||||||
|
wxCHECK_MSG( model, nil, "Valid model in data source does not exist." );
|
||||||
|
|
||||||
wxDataViewColumn* col(static_cast<wxDataViewColumn*>([[tableColumn identifier] pointer]));
|
wxDataViewColumn* col(static_cast<wxDataViewColumn*>([[tableColumn identifier] pointer]));
|
||||||
|
const unsigned colIdx = col->GetModelColumn();
|
||||||
|
|
||||||
wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]);
|
wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]);
|
||||||
|
|
||||||
|
if ( model->HasValue(dataViewItem, colIdx) )
|
||||||
|
{
|
||||||
wxVariant value;
|
wxVariant value;
|
||||||
|
model->GetValue(value,dataViewItem, colIdx);
|
||||||
|
|
||||||
wxCHECK_MSG( model, 0, "Valid model in data source does not exist." );
|
|
||||||
model->GetValue(value,dataViewItem,col->GetModelColumn());
|
|
||||||
col->GetRenderer()->SetValue(value);
|
col->GetRenderer()->SetValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,6 +1094,13 @@ outlineView:(NSOutlineView*)outlineView
|
|||||||
{
|
{
|
||||||
wxCustomRendererObject * const
|
wxCustomRendererObject * const
|
||||||
obj = static_cast<wxCustomRendererObject *>([self objectValue]);
|
obj = static_cast<wxCustomRendererObject *>([self objectValue]);
|
||||||
|
if ( !obj )
|
||||||
|
{
|
||||||
|
// this may happen for the custom cells in container rows: they don't
|
||||||
|
// have any values
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wxDataViewCustomRenderer * const renderer = obj->customRenderer;
|
wxDataViewCustomRenderer * const renderer = obj->customRenderer;
|
||||||
|
|
||||||
// draw its own background:
|
// draw its own background:
|
||||||
@@ -1542,12 +1607,16 @@ item:(id)item
|
|||||||
[[tableColumn identifier] pointer]
|
[[tableColumn identifier] pointer]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
const unsigned colIdx = dvCol->GetModelColumn();
|
||||||
|
|
||||||
|
wxDataViewItem dvItem([static_cast<wxPointerObject *>(item) pointer]);
|
||||||
|
|
||||||
|
if ( !model->HasValue(dvItem, colIdx) )
|
||||||
|
return;
|
||||||
|
|
||||||
wxDataViewRenderer * const renderer = dvCol->GetRenderer();
|
wxDataViewRenderer * const renderer = dvCol->GetRenderer();
|
||||||
wxDataViewRendererNativeData * const data = renderer->GetNativeData();
|
wxDataViewRendererNativeData * const data = renderer->GetNativeData();
|
||||||
|
|
||||||
wxDataViewItem dvItem([static_cast<wxPointerObject *>(item) pointer]);
|
|
||||||
|
|
||||||
// set the font and text colour to use: we need to do it if we had ever
|
// set the font and text colour to use: we need to do it if we had ever
|
||||||
// changed them before, even if this item itself doesn't have any special
|
// changed them before, even if this item itself doesn't have any special
|
||||||
// attributes as otherwise it would reuse the attributes from the previous
|
// attributes as otherwise it would reuse the attributes from the previous
|
||||||
@@ -1556,7 +1625,7 @@ item:(id)item
|
|||||||
NSColor *colText = NULL;
|
NSColor *colText = NULL;
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
wxDataViewItemAttr attr;
|
||||||
if ( model && model->GetAttr(dvItem, dvCol->GetModelColumn(), attr) )
|
if ( model && model->GetAttr(dvItem, colIdx, attr) )
|
||||||
{
|
{
|
||||||
if ( attr.HasFont() )
|
if ( attr.HasFont() )
|
||||||
{
|
{
|
||||||
@@ -2178,6 +2247,11 @@ wxDataObjectComposite* wxCocoaDataViewControl::GetDnDDataObjects(NSData* dataObj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id wxCocoaDataViewControl::GetItemAtRow(int row) const
|
||||||
|
{
|
||||||
|
return [m_OutlineView itemAtRow:row];
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxDataViewRendererNativeData
|
// wxDataViewRendererNativeData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user