Is it possible to do drag&drop on toolbutton of wxToolBar? Topic is solved
Is it possible to do drag&drop on toolbutton of wxToolBar?
Hi, All,
I'd like to do drag&drap on toolbutton. I want to drag a toolbutton and drop it to other window.
Can I do this? I checked document, it seems there is no drag&drop message event for wxToolBar.
Thanks!
I'd like to do drag&drap on toolbutton. I want to drag a toolbutton and drop it to other window.
Can I do this? I checked document, it seems there is no drag&drop message event for wxToolBar.
Thanks!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
As wxToolBar derives from wxWindow, it should work as a drop target (wxWindow::SetDropTarget). Then you could use wxToolBar::FindToolForPosition() to find the button where the drop happened.
But i can't think of any way to start a drag from a toolbar button if a click on that button should also work.
Personal note: IMHO both things would be bad GUI design.
But i can't think of any way to start a drag from a toolbar button if a click on that button should also work.
Personal note: IMHO both things would be bad GUI design.
Use the source, Luke!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
Hi doublemax,doublemax wrote:As wxToolBar derives from wxWindow, it should work as a drop target (wxWindow::SetDropTarget). Then you could use wxToolBar::FindToolForPosition() to find the button where the drop happened.
But i can't think of any way to start a drag from a toolbar button if a click on that button should also work.
Personal note: IMHO both things would be bad GUI design.
I used wxToolBar in my app is not in general context, like as the main toolbar. I used it just as a ordinary widgets to cooperate with 3D graphics window. Also, it locates the bottom of graphics window instead of the top of main frame.
So I want to drag a toolbutton, which is stand for a opened model, into a graphics window and display this model.
I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton. I think doing drag on toolbutton is reasonable and realizable. How do you think?
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
It will not trigger a dedicated drag event, but if you catch generic mouse events and check wxMouseEvent::Dragging() it should be possible to start a drag operation from there.I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
Use the source, Luke!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
It's settled down. thank you doublemax!doublemax wrote:It will not trigger a dedicated drag event, but if you catch generic mouse events and check wxMouseEvent::Dragging() it should be possible to start a drag operation from there.I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
Hi doublemax,doublemax wrote:It will not trigger a dedicated drag event, but if you catch generic mouse events and check wxMouseEvent::Dragging() it should be possible to start a drag operation from there.I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
If some of toolbuttons couldn't do drag on wxToolBar, how to cancel the dragging?
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
I'm not 100% sure i understand what you mean. Can you use wxToolBar::FindToolForPosition() to identify the tool you clicked on?If some of toolbuttons couldn't do drag on wxToolBar, how to cancel the dragging?
Use the source, Luke!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
I bind event like this:doublemax wrote:I'm not 100% sure i understand what you mean. Can you use wxToolBar::FindToolForPosition() to identify the tool you clicked on?If some of toolbuttons couldn't do drag on wxToolBar, how to cancel the dragging?
Code: Select all
wxToolBar * PToolbar = new wxToolBar (...)
PToolbar->Bind(wxEVT_MOTION, &ModelBar::OnMouseCallback, this, PToolbar ->GetId());
void wxModelBar::OnMouseCallback(wxMouseEvent& evt) {
if (evt.Dragging() && evt.LeftIsDown()) {
wxPoint pt = evt.GetPosition();
wxToolBarToolBase* base = this->PToolbar->FindToolForPosition(pt.x, pt.y);
if (base) {
int wxItemid = base->GetId();
this->prepareDragging(wxItemid);
}
}
}
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
Code: Select all
int wxItemid = base->GetId();
BTW: You should call event.Skip() if you don't start a dragging operation, so that the default event handling takes place.
Use the source, Luke!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
event.Skip() works, but the toolbutton that not to be draggable still keeps press-down status.doublemax wrote:You have identified the toolbutton here. If it's a button that should not be draggable, just do nothing.Code: Select all
int wxItemid = base->GetId();
BTW: You should call event.Skip() if you don't start a dragging operation, so that the default event handling takes place.
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
If the button should still work when clicked, i can't think of any way to avoid that.
Use the source, Luke!
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
Is it possible to cancel/kill the mouse dragging status when do dragging on not be draggable toolbutotn?doublemax wrote:If the button should still work when clicked, i can't think of any way to avoid that.
Re: Is it possible to do drag&drop on toolbutton of wxToolBar?
The dragging flag only means that the mouse was moved while the mouse button was pressed. It will be reset when you release the mouse button.Is it possible to cancel/kill the mouse dragging status when do dragging on not be draggable toolbutotn?
Use the source, Luke!