Highlight wxListCtrl row at dnd 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
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Highlight wxListCtrl row at dnd

Post by Argon »

Hi again.
Im using wxWidgets 2.9.2.
I have a wxListCtrl with Drag&Drop in it. So the dnd is used only in this wxListCtrl.
Is there a way to highlight the row (more like the rowborder) where my droptarget could be?
So its easier for the user to see where they drop the Listitem.
I tried to use wxDropsource->GiveFeedback() but it didnt worked.
I found something with wxDropTarget.>OnDragOver(). But i dont use wxDropTarget.
I hope its understandable what i mean :)

With best regards
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Highlight wxListCtrl row at dnd

Post by doublemax »

I tried to use wxDropsource->GiveFeedback() but it didnt worked
What didn't work? Because that's the way to go. Inside that method you could use wxListCtrl::HitTest to get the item under the mouse and then e.g. set the focus to that item.
Use the source, Luke!
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Re: Highlight wxListCtrl row at dnd

Post by Argon »

Actually at the moment im abit helpless :/

Thats what im doin in my OnDragInit

Code: Select all

wxListCtrl->SetDropTarget(new DnDclass(this));

const wxPoint& pt = event.m_pointDrag;

wxPoint elementPos((int)pt.x,(int)pt.y);

int flag = wxLIST_HITTEST_ONITEM;

long itemId = wxListCtrl->HitTest( elementPos , flag );

wxTextDataObject textData(itemId);
wxDropSource dragSource( wxListCtrl );

//somewhere here dragSource.GetFeedback() ?

dragSource.SetData( textData );
dragSource.DoDragDrop( true );
	
Do i have to override the complete DragSource::GetFeedback method extra? or is there a "short" way of just setting something in the " dragSource.GetFeedback() " ?

With best regards.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Highlight wxListCtrl row at dnd

Post by doublemax »

You have to derive your own class from wxDropSource and override GetFeedback.
Use the source, Luke!
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Re: Highlight wxListCtrl row at dnd

Post by Argon »

Ok. Made my own class. But how i set the wxdragresult Effect to an own ui effect like wxlistctrl.setitemstate?
You might got some sample? The sample i found just use Standart effects like wxDRAG_move.
I feel abit dump right now because i cant find any documentation about how to change it.

With best Regards
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Highlight wxListCtrl row at dnd

Post by doublemax »

Unfortunately i don't have a working sample.

- pass wxListCtrl pointer to your wxDropSource class and store it
- inside GetFeedback():
use wxGetMousePosition() to get mouse position in screen coordinates
convert to client coordinates using wxWindow::ScreenToClient() with the listctrl pointer
get item under mouse with wxListCtrl::HitTest
SetFocus to item
Use the source, Luke!
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Re: Highlight wxListCtrl row at dnd

Post by Argon »

I think im to stupid for it. maybe you find my stupidness :?
or maybe its to late #-o

the main question is, what i did wrong that it dont override the wxDropSource::GetFeedback

Code: Select all

class DropSource : public wxDropSource
{
public:
	DropSource(MyFrame *drops) { m_drops = drops; }
	
	virtual bool OnGiveFeedback(wxDragResult effect)
	{
		wxPoint mouseposition = wxGetMousePosition();
		
		int flag = wxLIST_HITTEST_ONITEM;

		wxPoint screentoclientposition= m_drops->wxListCtrl->ScreenToClient(mouseposition);
		long dlong = m_drops->mlc_dest->HitTest(screentoclientposition, flag);

			m_drops->wxListCtrl->SetItemState(dlong, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
			//m_drops->wxListCtrl->SetItemState(dlong, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);

	return TRUE;
	}

private:
    MyFrame *m_drops;
};
does the hittest just returns just the "start" dragitem ?

with best regards
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Highlight wxListCtrl row at dnd

Post by doublemax »

Code: Select all

virtual bool OnGiveFeedback(wxDragResult effect)
This should be "GiveFeedback", not "OnGiveFeedback".
does the hittest just returns just the "start" dragitem ?
The method gets called every time the mouse position changes during the drag operation.
Use the source, Luke!
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Re: Highlight wxListCtrl row at dnd

Post by Argon »

I tried it with just givefeedback with the same Result. It doesnt get called. :?
Then maybe my call is broken. In my ondraginit function i still use wxDropSource dropsource(wxlistctrl) and dropsource.GetFeedback(effect).
Does this Sound right?

With best regards
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Highlight wxListCtrl row at dnd

Post by doublemax »

Here's a working sample. You do need to set a wxDropTarget, otherwise dragging over the wxListCtrl is not registered.
Attachments
minimal.cpp
(9.1 KiB) Downloaded 148 times
Use the source, Luke!
Argon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Oct 27, 2017 9:11 pm

Re: Highlight wxListCtrl row at dnd

Post by Argon »

Thanks doublemax.

I saw my fault. I still initialized my dropSource with the standart wxDropsource and not with my new class. well and some other little faults.

I would like to thank you for your work and effort. =D>

With best regards
Post Reply