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()];
|
[GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()];
|
||||||
return true;
|
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]];
|
[((NSPopUpButtonCell*) GetNativeData()->GetItemCell()) selectItemWithTitle:[[wxCFStringRef(GetValue().GetString()).AsNSString() retain] autorelease]];
|
||||||
return true;
|
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,10 +2942,9 @@ wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype,
|
|||||||
|
|
||||||
bool wxDataViewDateRenderer::MacRender()
|
bool wxDataViewDateRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
if (!GetValue().GetDateTime().IsValid())
|
||||||
{
|
return true;
|
||||||
if (GetValue().GetDateTime().IsValid())
|
|
||||||
{
|
|
||||||
// -- find best fitting style to show the date --
|
// -- find best fitting style to show the date --
|
||||||
// as the style should be identical for all cells a reference 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;
|
// instead of the actual cell's date value is used for all cells;
|
||||||
@@ -2992,14 +2988,8 @@ bool wxDataViewDateRenderer::MacRender()
|
|||||||
// a conversion from the local to UTC timezone when adding the
|
// a conversion from the local to UTC timezone when adding the
|
||||||
// seconds to 1970-01-01 UTC:
|
// seconds to 1970-01-01 UTC:
|
||||||
[GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]];
|
[GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]];
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Date renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -3036,8 +3026,6 @@ wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(const wxString& variantty
|
|||||||
|
|
||||||
bool wxDataViewIconTextRenderer::MacRender()
|
bool wxDataViewIconTextRenderer::MacRender()
|
||||||
{
|
{
|
||||||
if (GetValue().GetType() == GetVariantType())
|
|
||||||
{
|
|
||||||
wxDataViewIconText iconText;
|
wxDataViewIconText iconText;
|
||||||
|
|
||||||
wxImageTextCell* cell;
|
wxImageTextCell* cell;
|
||||||
@@ -3050,12 +3038,6 @@ bool wxDataViewIconTextRenderer::MacRender()
|
|||||||
[cell setImage:nil];
|
[cell setImage:nil];
|
||||||
[cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]];
|
[cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]];
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG(wxString("Icon & text renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()];
|
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
||||||
return true;
|
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()];
|
[GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()];
|
||||||
return true;
|
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