Highlight wxListCtrl row at dnd Topic is solved
Highlight wxListCtrl row at dnd
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
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
Re: Highlight wxListCtrl row at dnd
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.I tried to use wxDropsource->GiveFeedback() but it didnt worked
Use the source, Luke!
Re: Highlight wxListCtrl row at dnd
Actually at the moment im abit helpless :/
Thats what im doin in my OnDragInit
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.
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 );
With best regards.
Re: Highlight wxListCtrl row at dnd
You have to derive your own class from wxDropSource and override GetFeedback.
Use the source, Luke!
Re: Highlight wxListCtrl row at dnd
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
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
Re: Highlight wxListCtrl row at dnd
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
- 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!
Re: Highlight wxListCtrl row at dnd
I think im to stupid for it. maybe you find my stupidness
or maybe its to late
the main question is, what i did wrong that it dont override the wxDropSource::GetFeedback
does the hittest just returns just the "start" dragitem ?
with best regards
or maybe its to late
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;
};
with best regards
Re: Highlight wxListCtrl row at dnd
Code: Select all
virtual bool OnGiveFeedback(wxDragResult effect)
The method gets called every time the mouse position changes during the drag operation.does the hittest just returns just the "start" dragitem ?
Use the source, Luke!
Re: Highlight wxListCtrl row at dnd
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
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
Re: Highlight wxListCtrl row at dnd
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!
Re: Highlight wxListCtrl row at dnd
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.
With best regards
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.
With best regards