wxDataViewCtrl HitTest problem Topic is solved

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
TsysarAndrew
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Jun 03, 2018 7:34 am

wxDataViewCtrl HitTest problem

Post by TsysarAndrew »

I've implemented a drag and drop operation in the wxTreeListCtrl, but I'm not sure if it's correct. When the method wxTreeListCtrl->GetDataView()->HitTest() was called, it returned the element following the element under the cursor. So I adjusted the Y coordinate with wxRendererNative. Could you tell me if I'm done the right thing for this task?

my code:

Code: Select all

wxDragResult DnDCommand::OnData(wxCoord x, wxCoord y, wxDragResult def)
{
   .......
    wxDataViewItem viewItem;
    wxDataViewColumn* viewColumn = m_pOwner->GetDataView()->GetColumn(0); //m_pOwner - pointer to wxTreeListCtrl

    wxPoint cursorPoint = wxPoint(x, y);
    cursorPoint.y = cursorPoint.y - wxRendererNative::Get().GetHeaderButtonHeight(m_pOwner);
    m_pOwner->GetDataView()->HitTest(cursorPoint, viewItem, viewColumn);
    .......
   
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl HitTest problem

Post by doublemax »

It's hard to imagine (but of course not impossible) that the HitTest method would have such a simple bug.

Are you sure the coordinates are client coordinates for the correct window and not relative to another one?
Use the source, Luke!
TsysarAndrew
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Jun 03, 2018 7:34 am

Re: wxDataViewCtrl HitTest problem

Post by TsysarAndrew »

I have only one form in the project. "Drag and drop" is organized only in one wxTreeListCtrl. I think that this situation may be due to the fact that the column header is accepted as the "first displayed element", but did not find a way to hide the header in order to test this hypothesis.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl HitTest problem

Post by doublemax »

but did not find a way to hide the header in order to test this hypothesis.
Add the wxTL_NO_HEADER style flag.

Can you provide a minimal, compilable sample?
Use the source, Luke!
TsysarAndrew
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Jun 03, 2018 7:34 am

Re: wxDataViewCtrl HitTest problem

Post by TsysarAndrew »

TsysarAndrew wrote: this hypothesis.
It's look like true. In the archive there is a simplified and "dirty" project that demonstrates this problem. I use Code::Block 16.01 and wxWidgets-3.1.0.

Lines 74 and 75 of the TestHitTestMain.cpp file are describe the initialization options wxTreeListCtrl with and without header. In the files TreeListCtrlWithHeader.gif and TreeListCtrlWithoutHeader.gif the are outputs of this project on my system is shown.

Returning to the original question, please tell me if the modification in line 137 of the TestHitTestMain.cpp file is correct?
Attachments
TestHitTest.zip
(76.78 KiB) Downloaded 46 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl HitTest problem

Post by doublemax »

This should fix it.

Code: Select all

//TreeListCtrl->SetDropTarget(dropTarget);
TreeListCtrl->GetDataView()->GetMainWindow()->SetDropTarget(dropTarget);
Use the source, Luke!
TsysarAndrew
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Jun 03, 2018 7:34 am

Re: wxDataViewCtrl HitTest problem

Post by TsysarAndrew »

Yes, it's work! Thank you.
But how you do it? Could you tell in a few words the algorithm for solving such problems? I have little experience with wxWidgets, and it seems to me that I will face similar problems in the future.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl HitTest problem

Post by doublemax »

There is no general plan how to solve these kind of problems. And this was a very specific one.

wxTreeListCtrl uses wxDataViewControl which is a composite control that consists of several sub-windows. The problem was that the drop event handler got coordinates from the wxTreeListCtrl , because that's where you assigned the drop targer. But wxDVC needed the coordinates of the subwindow that displays the actual items.

FWIW, i think this is a bug in wxDataViewControl, IMHO it should perform the necessary coordinate transformation. When i have some more time, i might take a closer look and open a bug report, if it really turns out to be a bug.
Use the source, Luke!
Post Reply