Fix crash in wxDataViewProgressRenderer in non-Unicode build.
We can't use the column pointer in wxDataViewProgressRenderer ctor as it's not set yet, so postpone setting the renderer label until later in non-Unicode build which needs the font used by this column to do the conversion to UTF-8. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0cc1991e2a
commit
fdd67a6a50
@ -185,9 +185,17 @@ public:
|
||||
virtual wxSize GetSize() const;
|
||||
|
||||
private:
|
||||
void GTKSetLabel();
|
||||
|
||||
wxString m_label;
|
||||
int m_value;
|
||||
|
||||
#if !wxUSE_UNICODE
|
||||
// Flag used to indicate that we need to set the label because we were
|
||||
// unable to do it in the ctor (see comments there).
|
||||
bool m_needsToSetLabel;
|
||||
#endif // !wxUSE_UNICODE
|
||||
|
||||
protected:
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
|
||||
};
|
||||
|
@ -2459,15 +2459,20 @@ wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
|
||||
{
|
||||
m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
|
||||
|
||||
GValue gvalue = { 0, };
|
||||
g_value_init( &gvalue, G_TYPE_STRING );
|
||||
|
||||
g_value_set_string( &gvalue, wxGTK_CONV_FONT( m_label, GetOwner()->GetOwner()->GetFont() ) );
|
||||
g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
|
||||
g_value_unset( &gvalue );
|
||||
|
||||
SetMode(mode);
|
||||
SetAlignment(align);
|
||||
|
||||
#if !wxUSE_UNICODE
|
||||
// We can't initialize the renderer just yet because we don't have the
|
||||
// pointer to the column that uses this renderer yet and so attempt to
|
||||
// dereference GetOwner() to get the font that is used as a source of
|
||||
// encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
|
||||
// non-Unicode builds would crash. So simply remember to do it later.
|
||||
if ( !m_label.empty() )
|
||||
m_needsToSetLabel = true;
|
||||
else
|
||||
#endif // !wxUSE_UNICODE
|
||||
GTKSetLabel();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -2481,11 +2486,36 @@ wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void wxDataViewProgressRenderer::GTKSetLabel()
|
||||
{
|
||||
GValue gvalue = { 0, };
|
||||
g_value_init( &gvalue, G_TYPE_STRING );
|
||||
|
||||
// Take care to not use GetOwner() here if the label is empty, we can be
|
||||
// called from ctor when GetOwner() is still NULL in this case.
|
||||
g_value_set_string( &gvalue,
|
||||
m_label.empty() ? ""
|
||||
: wxGTK_CONV_FONT(m_label,
|
||||
GetOwner()->GetOwner()->GetFont())
|
||||
);
|
||||
g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
|
||||
g_value_unset( &gvalue );
|
||||
|
||||
#if !wxUSE_UNICODE
|
||||
m_needsToSetLabel = false;
|
||||
#endif // !wxUSE_UNICODE
|
||||
}
|
||||
|
||||
bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
|
||||
{
|
||||
#ifdef __WXGTK26__
|
||||
if (!gtk_check_version(2,6,0))
|
||||
{
|
||||
#if !wxUSE_UNICODE
|
||||
if ( m_needsToSetLabel )
|
||||
GTKSetLabel();
|
||||
#endif // !wxUSE_UNICODE
|
||||
|
||||
gint tmp = (long) value;
|
||||
GValue gvalue = { 0, };
|
||||
g_value_init( &gvalue, G_TYPE_INT );
|
||||
|
Loading…
Reference in New Issue
Block a user