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:
Vadim Zeitlin 2009-10-24 01:03:36 +00:00
parent b372f20e7e
commit eda34276d6
2 changed files with 87 additions and 10 deletions

View File

@ -498,6 +498,9 @@ public:
wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects);
wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const;
// Cocoa-specific helpers
id GetItemAtRow(int row) const;
private:
wxCocoaOutlineDataSource* m_DataSource;

View File

@ -34,6 +34,11 @@
// ============================================================================
// Classes used locally in dataview.mm
// ============================================================================
// ----------------------------------------------------------------------------
// wxCustomRendererObject
// ----------------------------------------------------------------------------
@interface wxCustomRendererObject : NSObject <NSCopying>
{
@public
@ -77,6 +82,55 @@
}
@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
// ============================================================================
@ -196,8 +250,8 @@ NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column)
wxCHECK_MSG( renderer, NULL, "column should have a renderer" );
NSTableColumn * const nativeColumn(
[[NSTableColumn alloc] initWithIdentifier:
wxDVCNSTableColumn * const nativeColumn(
[[wxDVCNSTableColumn alloc] initWithIdentifier:
[[[wxPointerObject alloc] initWithPointer:
const_cast<wxDataViewColumn*>(column)]
autorelease]]
@ -558,16 +612,20 @@ outlineView:(NSOutlineView*)outlineView
objectValueForTableColumn:(NSTableColumn*)tableColumn
byItem:(id)item
{
wxCHECK_MSG( model, nil, "Valid model in data source does not exist." );
wxDataViewColumn* col(static_cast<wxDataViewColumn*>([[tableColumn identifier] pointer]));
const unsigned colIdx = col->GetModelColumn();
wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]);
wxVariant value;
if ( model->HasValue(dataViewItem, colIdx) )
{
wxVariant value;
model->GetValue(value,dataViewItem, colIdx);
col->GetRenderer()->SetValue(value);
}
wxCHECK_MSG( model, 0, "Valid model in data source does not exist." );
model->GetValue(value,dataViewItem,col->GetModelColumn());
col->GetRenderer()->SetValue(value);
return nil;
}
@ -1036,6 +1094,13 @@ outlineView:(NSOutlineView*)outlineView
{
wxCustomRendererObject * const
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;
// draw its own background:
@ -1542,12 +1607,16 @@ item:(id)item
[[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();
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
// changed them before, even if this item itself doesn't have any special
// attributes as otherwise it would reuse the attributes from the previous
@ -1556,7 +1625,7 @@ item:(id)item
NSColor *colText = NULL;
wxDataViewItemAttr attr;
if ( model && model->GetAttr(dvItem, dvCol->GetModelColumn(), attr) )
if ( model && model->GetAttr(dvItem, colIdx, attr) )
{
if ( attr.HasFont() )
{
@ -2178,6 +2247,11 @@ wxDataObjectComposite* wxCocoaDataViewControl::GetDnDDataObjects(NSData* dataObj
}
}
id wxCocoaDataViewControl::GetItemAtRow(int row) const
{
return [m_OutlineView itemAtRow:row];
}
// ----------------------------------------------------------------------------
// wxDataViewRendererNativeData
// ----------------------------------------------------------------------------