Page 1 of 1

Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Thu Nov 15, 2018 3:24 am
by shawnee
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!

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Thu Nov 15, 2018 8:52 am
by doublemax
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.

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Thu Nov 15, 2018 12:52 pm
by shawnee
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.
Hi doublemax,

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?

Posted: Thu Nov 15, 2018 2:10 pm
by doublemax
I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
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.

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Fri Nov 16, 2018 3:11 am
by shawnee
doublemax wrote:
I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
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.
It's settled down. thank you doublemax!

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Fri Nov 16, 2018 7:43 am
by shawnee
doublemax wrote:
I tried dragging operation on toolbutton, it would not trigger single clicking event on this toolbutton.
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.
Hi doublemax,

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?

Posted: Fri Nov 16, 2018 8:59 am
by doublemax
If some of toolbuttons couldn't do drag on wxToolBar, how to cancel the dragging?
I'm not 100% sure i understand what you mean. Can you use wxToolBar::FindToolForPosition() to identify the tool you clicked on?

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Fri Nov 16, 2018 1:08 pm
by shawnee
doublemax wrote:
If some of toolbuttons couldn't do drag on wxToolBar, how to cancel the dragging?
I'm not 100% sure i understand what you mean. Can you use wxToolBar::FindToolForPosition() to identify the tool you clicked on?
I bind event like this:

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);
        }
    }
}
I mean some of toolbutton I don't want dragging on it. Can I block the dragging for those of toolbutton?

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Fri Nov 16, 2018 1:20 pm
by doublemax

Code: Select all

int wxItemid = base->GetId();
You have identified the toolbutton here. If it's a button that should not be draggable, just do nothing.

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?

Posted: Fri Nov 16, 2018 2:11 pm
by shawnee
doublemax wrote:

Code: Select all

int wxItemid = base->GetId();
You have identified the toolbutton here. If it's a button that should not be draggable, just do nothing.

BTW: You should call event.Skip() if you don't start a dragging operation, so that the default event handling takes place.
event.Skip() works, but the toolbutton that not to be draggable still keeps press-down status. :(

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Fri Nov 16, 2018 3:05 pm
by doublemax
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?

Posted: Sat Nov 17, 2018 12:58 am
by shawnee
doublemax wrote:If the button should still work when clicked, i can't think of any way to avoid that.
Is it possible to cancel/kill the mouse dragging status when do dragging on not be draggable toolbutotn?

Re: Is it possible to do drag&drop on toolbutton of wxToolBar?

Posted: Sat Nov 17, 2018 7:34 am
by doublemax
Is it possible to cancel/kill the mouse dragging status when do dragging on not be draggable toolbutotn?
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.