Is it possible to do drag&drop on toolbutton of wxToolBar? 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
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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.
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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.
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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?
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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.
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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. :(
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

If the button should still work when clicked, i can't think of any way to avoid that.
Use the source, Luke!
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

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

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post 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.
Use the source, Luke!
Post Reply