//
wxDataViewRendererNativeData(void) : m_Object(NULL), m_ColumnCell(NULL)
{
+ Init();
}
wxDataViewRendererNativeData(NSCell* initColumnCell) : m_Object(NULL), m_ColumnCell([initColumnCell retain])
{
+ Init();
}
wxDataViewRendererNativeData(NSCell* initColumnCell, id initObject) : m_Object([initObject retain]), m_ColumnCell([initColumnCell retain])
{
+ Init();
}
+
~wxDataViewRendererNativeData()
{
[m_ColumnCell release];
[m_Object release];
+
+ [m_origFont release];
+ [m_origTextColour release];
}
//
m_Object = newObject;
}
-protected:
+ // The original cell font and text colour stored here are NULL by default and
+ // are only initialized to the values retrieved from the cell when we change
+ // them from wxCocoaOutlineView:willDisplayCell:forTableColumn:item: which
+ // calls our SaveOriginalXXX() methods before changing the cell attributes.
+ //
+ // This allows us to avoid doing anything for the columns without any
+ // attributes but still be able to restore the correct attributes for the
+ // ones that do.
+ NSFont *GetOriginalFont() const { return m_origFont; }
+ NSColor *GetOriginalTextColour() const { return m_origTextColour; }
+
+ void SaveOriginalFont(NSFont *font)
+ {
+ m_origFont = [font retain];
+ }
+
+ void SaveOriginalTextColour(NSColor *textColour)
+ {
+ m_origTextColour = [textColour retain];
+ }
+
private:
-//
-// variables
-//
+ void Init()
+ {
+ m_origFont = NULL;
+ m_origTextColour = NULL;
+ }
+
id m_Item; // item NOT owned by renderer
id m_Object; // object that can be used by renderer for storing special data (owned by renderer)
NSCell* m_ItemCell; // item's cell is NOT owned by renderer
NSTableColumn* m_TableColumnPtr; // column NOT owned by renderer
+
+ // we own those if they're non-NULL
+ NSFont *m_origFont;
+ NSColor *m_origTextColour;
};
// ============================================================================
}
else if (col==2)
{
- if (row >= m_array.GetCount())
- variant = "plain";
- else
- variant = "blue/green/red";
+ static const char *labels[5] =
+ {
+ "blue", "green", "red", "bold cyan", "default",
+ };
+
+ variant = labels[row % 5];
}
}
if (col != 2)
return false;
- if (row < m_array.GetCount())
+ // do what the labels defined above hint at
+ switch ( row % 5 )
{
- attr.SetColour( (row%3) == 0 ? *wxBLUE :
- ((row%3) == 1 ? *wxGREEN : *wxRED) );
- attr.SetItalic( (row%10) == 5 );
+ case 0:
+ attr.SetColour(*wxBLUE);
+ break;
+
+ case 1:
+ attr.SetColour(*wxGREEN);
+ break;
+
+ case 2:
+ attr.SetColour(*wxRED);
+ break;
+
+ case 3:
+ attr.SetColour(*wxCYAN);
+ attr.SetBold(true);
+ break;
+
+ case 4:
+ return false;
}
return true;
)
);
+ 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
+ // cell rendered using the same renderer
+ NSFont *font = NULL;
+ NSColor *colText = NULL;
+
wxDataViewItemAttr attr;
if ( model && model->GetAttr(dvItem, dvCol->GetModelColumn(), attr) )
{
if ( attr.HasFont() )
{
- // FIXME: using wxFont methods here doesn't work for some reason
- NSFontManager * const fm = [NSFontManager sharedFontManager];
- NSFont *font = [cell font];
+ font = data->GetOriginalFont();
+ if ( !font )
+ {
+ // this is the first time we're setting the font, remember the
+ // original one before changing it
+ font = [cell font];
+ data->SaveOriginalFont(font);
+ }
+
if ( font )
{
+ // FIXME: using wxFont methods here doesn't work for some reason
+ NSFontManager * const fm = [NSFontManager sharedFontManager];
if ( attr.GetBold() )
font = [fm convertFont:font toHaveTrait:NSBoldFontMask];
if ( attr.GetItalic() )
font = [fm convertFont:font toHaveTrait:NSItalicFontMask];
-
- [cell setFont:font];
}
//else: can't change font if the cell doesn't have any
}
- // we can set font for any cell but only NSTextFieldCell provides a
- // method for setting text colour so check that this method is
- // available before using it
- if ( attr.HasColour() &&
- [cell respondsToSelector:@selector(setTextColor:)] )
+ if ( attr.HasColour() )
{
- const wxColour& c = attr.GetColour();
- [cell setTextColor:[NSColor colorWithDeviceRed:c.Red()
- green:c.Green()
- blue:c.Blue()
- alpha:c.Alpha()]];
+ // we can set font for any cell but only NSTextFieldCell provides
+ // a method for setting text colour so check that this method is
+ // available before using it
+ if ( [cell respondsToSelector:@selector(setTextColor:)] &&
+ [cell respondsToSelector:@selector(textColor)] )
+ {
+ if ( !data->GetOriginalTextColour() )
+ {
+ data->SaveOriginalTextColour([cell textColor]);
+ }
+
+ const wxColour& c = attr.GetColour();
+ colText = [NSColor colorWithDeviceRed:c.Red()
+ green:c.Green()
+ blue:c.Blue()
+ alpha:c.Alpha()];
+ }
}
}
- wxDataViewRenderer * const renderer = dvCol->GetRenderer();
- wxDataViewRendererNativeData * const data = renderer->GetNativeData();
+ if ( !font )
+ font = data->GetOriginalFont();
+ if ( !colText )
+ colText = data->GetOriginalTextColour();
+
+ if ( font )
+ [cell setFont:font];
+
+ if ( colText )
+ [cell setTextColor:colText];
data->SetColumnPtr(tableColumn);
data->SetItem(item);