Page 1 of 1

Reorder column, Resize column events

Posted: Sun Jan 24, 2016 12:03 pm
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.

Re: Reorder column, Resize column events

Posted: Sun Jan 24, 2016 12:43 pm
by doublemax
Try wxEVT_HEADER_END_RESIZE and wxEVT_HEADER_END_REORDER.
http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html

Re: Reorder column, Resize column events

Posted: Mon Jan 25, 2016 11:15 am
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)

Re: Reorder column, Resize column events

Posted: Mon Jan 25, 2016 1:01 pm
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

Re: Reorder column, Resize column events

Posted: Mon Jan 25, 2016 2:16 pm
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.

Re: Reorder column, Resize column events

Posted: Mon Jan 25, 2016 2:23 pm
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.