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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Thu Nov 15, 2018 3:24 am

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: 14898
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 » Thu Nov 15, 2018 8:52 am

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Thu Nov 15, 2018 12:52 pm

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: 14898
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 » Thu Nov 15, 2018 2:10 pm

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Fri Nov 16, 2018 3:11 am

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Fri Nov 16, 2018 7:43 am

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: 14898
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 » Fri Nov 16, 2018 8:59 am

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Fri Nov 16, 2018 1:08 pm

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: 14898
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 » Fri Nov 16, 2018 1:20 pm

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Fri Nov 16, 2018 2:11 pm

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: 14898
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 » Fri Nov 16, 2018 3:05 pm

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: 67
Joined: Tue Jan 16, 2018 1:05 am

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

Post by shawnee » Sat Nov 17, 2018 12:58 am

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: 14898
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 » Sat Nov 17, 2018 7:34 am

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