Use string column identifiers with NSTableColumns in wxDataViewCtrl.

Starting with OS X 10.7 the column identifiers used in NSOutlineView must be
of type NSString, so convert the code to use string identifiers instead of
wxPointerObject.

Closes #13661.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69996 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-12-13 21:08:17 +00:00
parent d86b82bb2c
commit fc672a2aba

View File

@ -156,11 +156,46 @@ inline wxDataViewItem wxDataViewItemFromMaybeNilItem(id item)
{ {
} }
// Get the identifier we use for the specified column. This should be used
// for finding columns from identifier only, to initialize the identifier
// of a new column use initWithColumnPointer below instead.
+(NSString*) identifierForColumnPointer:(const wxDataViewColumn*)column;
// Initialize the column with the given pointer to the associated
// wxDataViewColumn. This pointer can later be retrieved using
// getColumnPointer.
-(id) initWithColumnPointer:(const wxDataViewColumn*)column;
// Retrieve the associated column.
-(wxDataViewColumn*) getColumnPointer;
-(id) dataCellForRow:(NSInteger)row; -(id) dataCellForRow:(NSInteger)row;
@end @end
@implementation wxDVCNSTableColumn @implementation wxDVCNSTableColumn
+(NSString*) identifierForColumnPointer:(const wxDataViewColumn*)column
{
// Starting from OS X 10.7 the column identifier must be an NSString and
// not just some arbitrary object, so we serialize the pointer into the
// string. Notice the use of NSInteger which is big enough to store a
// pointer in both 32 and 64 bit builds.
return [NSString stringWithFormat:@"%lu", reinterpret_cast<NSUInteger>(column)];
}
-(id) initWithColumnPointer:(const wxDataViewColumn*)column
{
[self initWithIdentifier: [wxDVCNSTableColumn identifierForColumnPointer:column]];
return self;
}
-(wxDataViewColumn*) getColumnPointer
{
// The case to NSString is needed for OS X < 10.7.
return reinterpret_cast<wxDataViewColumn*>(
[static_cast<NSString*>([self identifier]) integerValue]);
}
-(id) dataCellForRow:(NSInteger)row -(id) dataCellForRow:(NSInteger)row
{ {
// what we want to do here is to simply return nil for the cells which // what we want to do here is to simply return nil for the cells which
@ -168,13 +203,7 @@ inline wxDataViewItem wxDataViewItemFromMaybeNilItem(id item)
// or progress cells in the columns using the corresponding types even for // or progress cells in the columns using the corresponding types even for
// the container rows which is wrong // the container rows which is wrong
// half of the problem is just finding the objects we need from the column const wxDataViewColumn * const dvCol = [self getColumnPointer];
// 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 wxDataViewCtrl * const dvc = dvCol->GetOwner();
const wxCocoaDataViewControl * const const wxCocoaDataViewControl * const
@ -316,10 +345,7 @@ NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column)
wxCHECK_MSG( renderer, NULL, "column should have a renderer" ); wxCHECK_MSG( renderer, NULL, "column should have a renderer" );
wxDVCNSTableColumn * const nativeColumn( wxDVCNSTableColumn * const nativeColumn(
[[wxDVCNSTableColumn alloc] initWithIdentifier: [[wxDVCNSTableColumn alloc] initWithColumnPointer: column]
[[[wxPointerObject alloc] initWithPointer:
const_cast<wxDataViewColumn*>(column)]
autorelease]]
); );
// setting the size related parameters: // setting the size related parameters:
@ -664,7 +690,8 @@ outlineView:(NSOutlineView*)outlineView
wxCHECK_MSG( model, nil, "Valid model in data source does not exist." ); wxCHECK_MSG( model, nil, "Valid model in data source does not exist." );
wxDataViewColumn* col(static_cast<wxDataViewColumn*>([(wxPointerObject*)[tableColumn identifier] pointer])); wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
const unsigned colIdx = col->GetModelColumn(); const unsigned colIdx = col->GetModelColumn();
wxDataViewItem dataViewItem(wxDataViewItemFromItem(item)); wxDataViewItem dataViewItem(wxDataViewItemFromItem(item));
@ -687,7 +714,8 @@ outlineView:(NSOutlineView*)outlineView
{ {
wxUnusedVar(outlineView); wxUnusedVar(outlineView);
wxDataViewColumn* col(static_cast<wxDataViewColumn*>([(wxPointerObject*)[tableColumn identifier] pointer])); wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
col->GetRenderer()-> col->GetRenderer()->
OSXOnCellChanged(object, wxDataViewItemFromItem(item), col->GetModelColumn()); OSXOnCellChanged(object, wxDataViewItemFromItem(item), col->GetModelColumn());
@ -1624,7 +1652,8 @@ outlineView:(NSOutlineView*)outlineView
// //
-(void) outlineView:(NSOutlineView*)outlineView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn -(void) outlineView:(NSOutlineView*)outlineView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn
{ {
wxDataViewColumn* const col(static_cast<wxDataViewColumn*>([(wxPointerObject*)[tableColumn identifier] pointer])); wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
@ -1719,7 +1748,8 @@ outlineView:(NSOutlineView*)outlineView
wxDataViewCtrl * const dvc = implementation->GetDataViewCtrl(); wxDataViewCtrl * const dvc = implementation->GetDataViewCtrl();
wxDataViewModel * const model = dvc->GetModel(); wxDataViewModel * const model = dvc->GetModel();
wxDataViewColumn* const dvCol(static_cast<wxDataViewColumn*>([(wxPointerObject*)[tableColumn identifier] pointer])); wxDataViewColumn* const
dvCol([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
const unsigned colIdx = dvCol->GetModelColumn(); const unsigned colIdx = dvCol->GetModelColumn();
wxDataViewItem dvItem(wxDataViewItemFromItem(item)); wxDataViewItem dvItem(wxDataViewItemFromItem(item));
@ -1756,7 +1786,10 @@ outlineView:(NSOutlineView*)outlineView
{ {
int const newColumnPosition = [[[notification userInfo] objectForKey:@"NSNewColumn"] intValue]; int const newColumnPosition = [[[notification userInfo] objectForKey:@"NSNewColumn"] intValue];
wxDataViewColumn* const col(static_cast<wxDataViewColumn*>([(wxPointerObject*)[[[self tableColumns] objectAtIndex:newColumnPosition] identifier] pointer])); NSTableColumn*
tableColumn = [[self tableColumns] objectAtIndex:newColumnPosition];
wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
@ -1823,9 +1856,10 @@ outlineView:(NSOutlineView*)outlineView
currentlyEditedColumn = [self editedColumn]; currentlyEditedColumn = [self editedColumn];
currentlyEditedRow = [self editedRow]; currentlyEditedRow = [self editedRow];
wxDataViewColumn* const col = NSTableColumn*
static_cast<wxDataViewColumn*>( tableColumn = [[self tableColumns] objectAtIndex:currentlyEditedColumn];
[(wxPointerObject*)[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
@ -1861,9 +1895,10 @@ outlineView:(NSOutlineView*)outlineView
// been sent the last edited column/row are valid: // been sent the last edited column/row are valid:
if ( currentlyEditedColumn != -1 && currentlyEditedRow != -1 ) if ( currentlyEditedColumn != -1 && currentlyEditedRow != -1 )
{ {
wxDataViewColumn* const col = NSTableColumn*
static_cast<wxDataViewColumn*>( tableColumn = [[self tableColumns] objectAtIndex:currentlyEditedColumn];
[(wxPointerObject*)[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); wxDataViewColumn* const
col([static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer]);
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
@ -1965,7 +2000,7 @@ bool wxCocoaDataViewControl::DeleteColumn(wxDataViewColumn* columnPtr)
[m_OutlineView setOutlineTableColumn:nil]; // due to a bug this does not work [m_OutlineView setOutlineTableColumn:nil]; // due to a bug this does not work
[m_OutlineView removeTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; // due to a confirmed bug #6555162 the deletion does not work for [m_OutlineView removeTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; // due to a confirmed bug #6555162 the deletion does not work for
// outline table columns (... and there is no workaround) // outline table columns (... and there is no workaround)
return (([m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:columnPtr] autorelease]]) == -1); return (([m_OutlineView columnWithIdentifier:[wxDVCNSTableColumn identifierForColumnPointer:columnPtr]]) == -1);
} }
void wxCocoaDataViewControl::DoSetExpanderColumn(const wxDataViewColumn *columnPtr) void wxCocoaDataViewControl::DoSetExpanderColumn(const wxDataViewColumn *columnPtr)
@ -1975,12 +2010,13 @@ void wxCocoaDataViewControl::DoSetExpanderColumn(const wxDataViewColumn *columnP
wxDataViewColumn* wxCocoaDataViewControl::GetColumn(unsigned int pos) const wxDataViewColumn* wxCocoaDataViewControl::GetColumn(unsigned int pos) const
{ {
return static_cast<wxDataViewColumn*>([(wxPointerObject*)[[[m_OutlineView tableColumns] objectAtIndex:pos] identifier] pointer]); NSTableColumn* tableColumn = [[m_OutlineView tableColumns] objectAtIndex:pos];
return [static_cast<wxDVCNSTableColumn*>(tableColumn) getColumnPointer];
} }
int wxCocoaDataViewControl::GetColumnPosition(const wxDataViewColumn *columnPtr) const int wxCocoaDataViewControl::GetColumnPosition(const wxDataViewColumn *columnPtr) const
{ {
return [m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:const_cast<wxDataViewColumn*>(columnPtr)] autorelease]]; return [m_OutlineView columnWithIdentifier:[wxDVCNSTableColumn identifierForColumnPointer:columnPtr]];
} }
bool wxCocoaDataViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) bool wxCocoaDataViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr)
@ -2324,7 +2360,7 @@ wxDataViewColumn* wxCocoaDataViewControl::GetSortingColumn() const
for (UInt32 i=0; i<noOfColumns; ++i) for (UInt32 i=0; i<noOfColumns; ++i)
if ([[columns objectAtIndex:i] sortDescriptorPrototype] != nil) if ([[columns objectAtIndex:i] sortDescriptorPrototype] != nil)
return static_cast<wxDataViewColumn*>([(wxPointerObject*)[[columns objectAtIndex:i] identifier] pointer]); return GetColumn(i);
return NULL; return NULL;
} }
@ -2359,7 +2395,7 @@ void wxCocoaDataViewControl::HitTest(const wxPoint& point, wxDataViewItem& item,
indexRow = [m_OutlineView rowAtPoint: nativePoint]; indexRow = [m_OutlineView rowAtPoint: nativePoint];
if ((indexColumn >= 0) && (indexRow >= 0)) if ((indexColumn >= 0) && (indexRow >= 0))
{ {
columnPtr = static_cast<wxDataViewColumn*>([(wxPointerObject*)[[[m_OutlineView tableColumns] objectAtIndex:indexColumn] identifier] pointer]); columnPtr = GetColumn(indexColumn);
item = wxDataViewItem([[m_OutlineView itemAtRow:indexRow] pointer]); item = wxDataViewItem([[m_OutlineView itemAtRow:indexRow] pointer]);
} }
else else