Custom renderer fails on OSX

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Custom renderer fails on OSX

Post by ONEEYEMAN »

Hi,
I wrote a following code:

Code: Select all

SortColumnRenderer::SortColumnRenderer(wxCheckBoxState state, wxDataViewCellMode mode, int align)
    : wxDataViewCustomRenderer( GetDefaultType(), mode, align )
{
    m_toggle = true;
    m_allow3rdStateForUser = false;
}

bool SortColumnRenderer::SetValue(const wxVariant& value)
{
    m_toggle = value.GetBool();
    return true;
}

bool SortColumnRenderer::GetValue(wxVariant& value) const
{
    value = value;
    return true;
}

wxSize SortColumnRenderer::GetSize() const
{
    wxSize size = GetCheckSize();
    size.x += MARGIN_CHECK_ICON;

    const wxSize sizeText = GetTextExtent( _( "Ascending" ) );
    if( sizeText.y > size.y )
        size.y = sizeText.y;
    size.x += sizeText.x;
    return size;
}
#ifdef __WXMSW__
wxString SortColumnRenderer::GetAccessibleDescription() const
{
    /* TRANSLATORS: Checkbox state name */
    return m_toggle ? _("Sort Ascending")
        /* TRANSLATORS: Checkbox state name */
        : _("Sort descendending");
}
#endif
bool SortColumnRenderer::Render(wxRect cell, wxDC* dc, int state)
{
    // Draw the checkbox first.
    int flags = 0;
    if( m_toggle )
        flags |= wxCONTROL_CHECKED;
    if( GetMode() != wxDATAVIEW_CELL_ACTIVATABLE || !( GetOwner()->GetOwner()->IsEnabled() && GetEnabled() ) )
        flags |= wxCONTROL_DISABLED;

    if( state & wxDATAVIEW_CELL_PRELIT )
        flags |= wxCONTROL_CURRENT;

    const wxSize sizeCheck = GetCheckSize();
    wxRect rectCheck( cell.GetPosition(), sizeCheck );
    rectCheck = rectCheck.CentreIn( cell, wxVERTICAL );

    wxRendererNative::Get().DrawCheckBox( GetView(), *dc, rectCheck, flags );
    // Then the icon, if any.
    int xoffset = sizeCheck.x + MARGIN_CHECK_ICON;
    // Finally the text.
    RenderText( _( "Ascending" ), xoffset, cell, dc, state );
    return true;
}

bool SortColumnRenderer::ActivateCell (const wxRect& cell, wxDataViewModel *model, const wxDataViewItem & item, unsigned int col, const wxMouseEvent *mouseEvent)
{
    if( mouseEvent )
    {
        if( !wxRect( GetCheckSize() ).Contains( mouseEvent->GetPosition() ) )
            return false;
    }
    model->ChangeValue( !m_toggle, item, col );
    wxVariant temp;
    model->GetValue( temp, item, 0 );
    wxCommandEvent event( wxEVT_CHANGE_QUERY );
    event.SetEventObject( GetView()->GetParent() );
    event.SetInt( CHANGEFIELD );
    event.SetString( temp.GetString() );
    wxWindow *win = GetView()->GetParent()->GetParent()->GetParent();
    GetView()->GetParent()->GetParent()->GetParent()->GetEventHandler()->ProcessEvent( event );
    return true;
}

wxIMPLEMENT_CLASS(SortColumnRenderer, wxDataViewRenderer);

        m_sortDest = new wxDataViewListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE | wxDV_NO_HEADER );
        m_sortDest->AppendTextColumn( "", wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_LEFT );
        m_sortDest->AppendColumn( new wxDataViewColumn( "", new SortColumnRenderer, 1, wxDVC_DEFAULT_WIDTH, wxALIGN_RIGHT ) );
Initially the wxDVLC is empty.
The data comes in from another wxDVLC thru the DnD.

All this works fine on both Windows and *nix/GTK. I can drag the string from one wxDVLC to another. Everything is drawn and I can toggle the checkbox.

This is not the case on OSX/Cocoa.

When I run the code there the text in the first column is not visible and the checkbox is not togglable.
Trying to debug I don't see the code ending up in the "ActivateCell()" code.

Can anyone supply an idea on how to debug this?

Thank you.

P.S.: Attached is a screenshot from the OSX execution. I will also attach the results from the execution on Windows.
Attachments
DVLC_issue.PNG
DVLC_issue.PNG (3.65 KiB) Viewed 12678 times
Screen Shot 2020-02-07 at 9.49.01 PM.png
Screen Shot 2020-02-07 at 9.49.01 PM.png (15.15 KiB) Viewed 12680 times
Post Reply