Reorder column, Resize column events

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Anil8753
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sat Jan 16, 2016 5:57 am
Location: India

Reorder column, Resize column events

Post by Anil8753 »

I have a wxDataViewCtrl. I am performing the following actions:

Reorder column using mouse drag&drop
Resize column using mouse drag&drop

Here I want to get notify above actions via wx events. My requirement is to record all above actions by the user so that while next launch of application can restore the user customization.

I did not find any wxDataViewEvent for this purpose, that I can handle.

I found only wxEVT_DATAVIEW_COLUMN_REORDERED and this is also not getting fired on windows.

Please help me out.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax »

Try wxEVT_HEADER_END_RESIZE and wxEVT_HEADER_END_REORDER.
http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html
Use the source, Luke!
Anil8753
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sat Jan 16, 2016 5:57 am
Location: India

Re: Reorder column, Resize column events

Post by Anil8753 »

Thanks :)

GetMainWindow() API is there to get associated main window. There is no API available to get the associated wxHeaderCtrl from the wxDataViewCtrl.

I used the following trick :(

Code: Select all

    wxWindowList childWinList = m_pDataViewCtrl->GetChildren();

    for (const auto& win : childWinList)
    {
        wxHeaderCtrl* pHeaderWin = dynamic_cast<wxHeaderCtrl*>(win);

        if (pHeaderWin)
        {
            pHeaderWin->Bind(wxEVT_HEADER_END_RESIZE, &JobListCtrlEventHandler::OnColumnResized, this);
            pHeaderWin->Bind(wxEVT_HEADER_END_REORDER, &JobListCtrlEventHandler::OnColumnReordered, this);
        }
    }

I know this is not good, but I didn't find other good way to get wxHeaderCtrl window.

One more issue is:

wxEVT_HEADER_END_REORDER event is fired before the actual update in UI.

When I use wxDataViewCtrl::GetColumn(unsigned int) API to get the column, it gives me the non-updated column. Is there any way to get notify after UI update after reordering (on both Windows and Mac)
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax »

I know this is not good, but I didn't find other good way to get wxHeaderCtrl window.
wxHeaderCtrlEvent derives from wxCommandEvent, this means it propagates upwards in the window hierarchy. I think you could have caught the event at wxDataViewCtrl level.
wxEVT_HEADER_END_REORDER event is fired before the actual update in UI.
That is because the event can be Veto()ed, in that case the reordering would not happen. You can use wxEvtHandler::CallAfter() to call any other method asynchronously when the current event processing is done.
http://docs.wxwidgets.org/trunk/classwx ... 50b3719519
Use the source, Luke!
Anil8753
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sat Jan 16, 2016 5:57 am
Location: India

Re: Reorder column, Resize column events

Post by Anil8753 »

1. I am not able to catch the wxHeaderCtrl events in wxDataViewCtrl. So has to stick to my hack. :(

2. Tried second one, working :)
I got another solution. I handled the wxIdleEvent of wxHeaderCtrl, This also processed after wxEVT_HEADER_END_RESIZE and wxEVT_HEADER_END_REORDER are processed.

What I did is:

Code: Select all

void DataViewCtrl::OnColumnReordered(wxHeaderCtrlEvent& evt)
{
    m_colsDirty = true;
    evt.Skip();
}

void DataViewCtrl::OnHeaderIdle(wxIdleEvent& evt)
{
    if (m_colsDirty)
    {
        // My code goes here ...

        m_colsDirty = false;
    }

    evt.Skip();
}

Now I got two ways to solve it. Could please suggest me, which one is reliable.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax »

Now I got two ways to solve it. Could please suggest me, which one is reliable.
The CallAfter() version has the advantage that the method is called only when needed, while the IDLE processing happens all the time. But i think either solution is fine.
Use the source, Luke!
Post Reply