Refactor type checks in wxOSX wxDVC implementation.
Check the type in one place only, before calling MacRender() instead of doing it in each and every implementation of it. Also replace wxFAIL_MSG() with wxLogDebug() as the former resulted in a crash due to assert reentrancy, as usual when asserting inside a wxEVT_PAINT handler which is constantly called all the time, and so wasn't particularly useful. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78295 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1766,6 +1766,21 @@ outlineView:(NSOutlineView*)outlineView
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wxDataViewRenderer * const renderer = dvCol->GetRenderer();
|
wxDataViewRenderer * const renderer = dvCol->GetRenderer();
|
||||||
|
|
||||||
|
wxVariant value;
|
||||||
|
model->GetValue(value, dvItem, colIdx);
|
||||||
|
|
||||||
|
if ( value.GetType() != renderer->GetVariantType() )
|
||||||
|
{
|
||||||
|
wxLogDebug("Wrong type returned from the model: "
|
||||||
|
"%s required but actual type is %s",
|
||||||
|
renderer->GetVariantType(),
|
||||||
|
value.GetType());
|
||||||
|
|
||||||
|
// we can't use the value of wrong type
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wxDataViewRendererNativeData * const data = renderer->GetNativeData();
|
wxDataViewRendererNativeData * const data = renderer->GetNativeData();
|
||||||
|
|
||||||
// let the renderer know about what it's going to render next
|
// let the renderer know about what it's going to render next
|
||||||
@@ -2793,16 +2808,8 @@ wxDataViewTextRenderer::wxDataViewTextRenderer(const wxString& varianttype,
|
|||||||
|
|
||||||
bool wxDataViewTextRenderer::MacRender()
|
bool wxDataViewTextRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
[GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()];
|
||||||
{
|
return true;
|
||||||
[GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Text renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -2844,8 +2851,6 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(const wxString& varianttype,
|
|||||||
// In all other cases the method returns 'false'.
|
// In all other cases the method returns 'false'.
|
||||||
bool wxDataViewBitmapRenderer::MacRender()
|
bool wxDataViewBitmapRenderer::MacRender()
|
||||||
{
|
{
|
||||||
wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString("Bitmap renderer cannot render value; value type: ") << GetValue().GetType());
|
|
||||||
|
|
||||||
wxBitmap bitmap;
|
wxBitmap bitmap;
|
||||||
|
|
||||||
bitmap << GetValue();
|
bitmap << GetValue();
|
||||||
@@ -2905,16 +2910,8 @@ wxDataViewChoiceRenderer::OSXOnCellChanged(NSObject *value,
|
|||||||
|
|
||||||
bool wxDataViewChoiceRenderer::MacRender()
|
bool wxDataViewChoiceRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
[((NSPopUpButtonCell*) GetNativeData()->GetItemCell()) selectItemWithTitle:[[wxCFStringRef(GetValue().GetString()).AsNSString() retain] autorelease]];
|
||||||
{
|
return true;
|
||||||
[((NSPopUpButtonCell*) GetNativeData()->GetItemCell()) selectItemWithTitle:[[wxCFStringRef(GetValue().GetString()).AsNSString() retain] autorelease]];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Choice renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxDataViewChoiceRenderer,wxDataViewRenderer)
|
IMPLEMENT_CLASS(wxDataViewChoiceRenderer,wxDataViewRenderer)
|
||||||
@@ -2945,61 +2942,54 @@ wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype,
|
|||||||
|
|
||||||
bool wxDataViewDateRenderer::MacRender()
|
bool wxDataViewDateRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
if (!GetValue().GetDateTime().IsValid())
|
||||||
{
|
|
||||||
if (GetValue().GetDateTime().IsValid())
|
|
||||||
{
|
|
||||||
// -- find best fitting style to show the date --
|
|
||||||
// as the style should be identical for all cells a reference date
|
|
||||||
// instead of the actual cell's date value is used for all cells;
|
|
||||||
// this reference date is stored in the renderer's native data
|
|
||||||
// section for speed purposes; otherwise, the reference date's
|
|
||||||
// string has to be recalculated for each item that may become
|
|
||||||
// timewise long if a lot of rows using dates exist; the algorithm
|
|
||||||
// has the preference to display as much information as possible
|
|
||||||
// in the first instance; but as this is often impossible due to
|
|
||||||
// space restrictions the style is shortened per loop; finally, if
|
|
||||||
// the shortest time and date format does not fit into the cell
|
|
||||||
// the time part is dropped; remark: the time part itself is not
|
|
||||||
// modified per iteration loop and only uses the short style,
|
|
||||||
// means that only the hours and minutes are being shown
|
|
||||||
|
|
||||||
// GetObject() returns a date for testing the size of a date object
|
|
||||||
[GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()];
|
|
||||||
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterShortStyle];
|
|
||||||
for (int dateFormatterStyle=4; dateFormatterStyle>0; --dateFormatterStyle)
|
|
||||||
{
|
|
||||||
[[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle];
|
|
||||||
if (dateFormatterStyle == 1)
|
|
||||||
{
|
|
||||||
// if the shortest style for displaying the date and time
|
|
||||||
// is too long to be fully visible remove the time part of
|
|
||||||
// the date:
|
|
||||||
if ([GetNativeData()->GetItemCell() cellSize].width > [GetNativeData()->GetColumnPtr() width])
|
|
||||||
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterNoStyle];
|
|
||||||
{
|
|
||||||
// basically not necessary as the loop would end anyway
|
|
||||||
// but let's save the last comparison
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ([GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// set data (the style is set by the previous loop); on OSX the
|
|
||||||
// date has to be specified with respect to UTC; in wxWidgets the
|
|
||||||
// date is always entered in the local timezone; so, we have to do
|
|
||||||
// a conversion from the local to UTC timezone when adding the
|
|
||||||
// seconds to 1970-01-01 UTC:
|
|
||||||
[GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]];
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
else
|
// -- find best fitting style to show the date --
|
||||||
|
// as the style should be identical for all cells a reference date
|
||||||
|
// instead of the actual cell's date value is used for all cells;
|
||||||
|
// this reference date is stored in the renderer's native data
|
||||||
|
// section for speed purposes; otherwise, the reference date's
|
||||||
|
// string has to be recalculated for each item that may become
|
||||||
|
// timewise long if a lot of rows using dates exist; the algorithm
|
||||||
|
// has the preference to display as much information as possible
|
||||||
|
// in the first instance; but as this is often impossible due to
|
||||||
|
// space restrictions the style is shortened per loop; finally, if
|
||||||
|
// the shortest time and date format does not fit into the cell
|
||||||
|
// the time part is dropped; remark: the time part itself is not
|
||||||
|
// modified per iteration loop and only uses the short style,
|
||||||
|
// means that only the hours and minutes are being shown
|
||||||
|
|
||||||
|
// GetObject() returns a date for testing the size of a date object
|
||||||
|
[GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()];
|
||||||
|
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterShortStyle];
|
||||||
|
for (int dateFormatterStyle=4; dateFormatterStyle>0; --dateFormatterStyle)
|
||||||
{
|
{
|
||||||
wxFAIL_MSG(wxString("Date renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
[[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle];
|
||||||
return false;
|
if (dateFormatterStyle == 1)
|
||||||
|
{
|
||||||
|
// if the shortest style for displaying the date and time
|
||||||
|
// is too long to be fully visible remove the time part of
|
||||||
|
// the date:
|
||||||
|
if ([GetNativeData()->GetItemCell() cellSize].width > [GetNativeData()->GetColumnPtr() width])
|
||||||
|
[[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterNoStyle];
|
||||||
|
{
|
||||||
|
// basically not necessary as the loop would end anyway
|
||||||
|
// but let's save the last comparison
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ([GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
// set data (the style is set by the previous loop); on OSX the
|
||||||
|
// date has to be specified with respect to UTC; in wxWidgets the
|
||||||
|
// date is always entered in the local timezone; so, we have to do
|
||||||
|
// a conversion from the local to UTC timezone when adding the
|
||||||
|
// seconds to 1970-01-01 UTC:
|
||||||
|
[GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]];
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -3036,26 +3026,18 @@ wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(const wxString& variantty
|
|||||||
|
|
||||||
bool wxDataViewIconTextRenderer::MacRender()
|
bool wxDataViewIconTextRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
wxDataViewIconText iconText;
|
||||||
{
|
|
||||||
wxDataViewIconText iconText;
|
|
||||||
|
|
||||||
wxImageTextCell* cell;
|
wxImageTextCell* cell;
|
||||||
|
|
||||||
cell = (wxImageTextCell*) GetNativeData()->GetItemCell();
|
cell = (wxImageTextCell*) GetNativeData()->GetItemCell();
|
||||||
iconText << GetValue();
|
iconText << GetValue();
|
||||||
if (iconText.GetIcon().IsOk())
|
if (iconText.GetIcon().IsOk())
|
||||||
[cell setImage:[[wxBitmap(iconText.GetIcon()).GetNSImage() retain] autorelease]];
|
[cell setImage:[[wxBitmap(iconText.GetIcon()).GetNSImage() retain] autorelease]];
|
||||||
else
|
|
||||||
[cell setImage:nil];
|
|
||||||
[cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
[cell setImage:nil];
|
||||||
wxFAIL_MSG(wxString("Icon & text renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
[cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]];
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -3096,16 +3078,8 @@ wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype,
|
|||||||
|
|
||||||
bool wxDataViewToggleRenderer::MacRender()
|
bool wxDataViewToggleRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
||||||
{
|
return true;
|
||||||
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Toggle renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -3145,16 +3119,8 @@ wxDataViewProgressRenderer::wxDataViewProgressRenderer(const wxString& label,
|
|||||||
|
|
||||||
bool wxDataViewProgressRenderer::MacRender()
|
bool wxDataViewProgressRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
||||||
{
|
return true;
|
||||||
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Progress renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user