Drag and Drop question 
Author Message
 Drag and Drop question

Hi all,

I want to add #drag and #drop behaviour to Playground class, I want to move
a Square (or Triangle) in a drag and drop session, but I can't. at the

Any help ?


Best Regards
Bruno Brasesco.

Tue, 07 Oct 2003 06:45:23 GMT  
 Drag and Drop question

> I want to add #drag and #drop behaviour to Playground class, I want to
> a Square (or Triangle) in a drag and drop session, but I can't. at the
> moment.

In the case you describe, it might be best to use a MouseTracker, hit
testing at the beginning and end, and somehow acting on the resulting
objects when the drag is completed.

Re Dolphin's formalized drag and drop, there is some info on the Wiki, and
you can look at BugOff in the following:


One warning about the enclosed version of BugOff - do NOT drag from
development tools to a BugOffShell, well, you can, but, don't save your
image after you do it.  I have an updated version that fixes this problem,
but, haven't had time to package it yet.

Have a good one,


Wilhelm K. Schwab, Ph.D.

Tue, 07 Oct 2003 08:50:20 GMT  
 Drag and Drop question


> I want to add #drag and #drop behaviour to Playground class, I want to
> a Square (or Triangle) in a drag and drop session, but I can't. at the
> moment.

I wrote a longish post on drag&drop some time ago.  It's in Ian's
archive dated 4th Match 2000.  I hope it helps.

Drop me a line if you can't find it.

    -- chris

Fri, 10 Oct 2003 18:53:30 GMT  
 Drag and Drop question

> Drop me a line if you can't find it.

Chris I can't find that mail. And it is not in Deja news.

Best Regards
Bruno Brasesco

Fri, 10 Oct 2003 23:20:57 GMT  
 Drag and Drop question

> Chris I can't find that mail. And it is not in Deja news.

(BTW.  Ian Bartholomew's news-group archive at http://www.iandb.org.uk/
is an excellent resource for any Dolphin programmer, I strongly recommed
you download it)

I've mailed you a copy of my post to you directly, but there's some
other stuff I want to add here.

In that post, I talked about how to connect up the D&D operations in a
Presenter, so I was assuming that the View was already doing it's part
of the job -- which is true when you are using the standard View

What I hadn't really noticed is that you are attempting to add D&D to
the Playground app, which uses a custom View, so there is some more work
to be done to get D&D working.

I haven't done much messing around with custom Views -- in fact I wrote
my first only last week -- but it doesn't *seem* to be too difficult.  I
used the MoenTreeView as a guide to put together the following.  If
anyone knows of anything I've missed or done wrong/poorly then please
tell us!

We'll have to add a couple of methods: Playground>>onLeftButtonPressed:
and Playgound>>requestDragObjects:, and copy #dragDetect: from

First, we need to start a drag-drop session when someone attempts to
drag one of the objects out of the playgound.  That is accomplished by
adding a method like:

onLeftButtonPressed: aMouseEvent
    | target |
    target := shapes at: 1 ifAbsent: [nil].  "just to demo, pick a shape
at random"
    (self isDragSource and: [target notNil and: [self dragDetect:
        ifTrue: [self onBegin: aMouseEvent button drag: target].
    ^ super onLeftButtonPressed: aMouseEvent.

Here, I just choose an object to drag at random.  A (much!) better
version would probably do something like picking the object under the
mouse, or the "current selection" if Playgound had a concept of

I'm using #dragDetect: here to see if the user is begining a drag
operation.  I've just copied MoenTreeView>>dragDetect: into Playgound.
(If anyone at OA is reading, would it be a good idea to move dragDetect:
up into View ?  It seems generally usefull)

That object is used to start a drag-drop session.  The session responds
by asking the View (and in turn the Presenter) to fill in its details.
It sends #requestDragObjects: to the View, so we need to add a second
method like:

requestDragObjects: session
    | target |
    target := session suggestedSource.
    target isNil ifFalse: [session addDragObject:
(InternalDragDropObject object: target)].
    ^ super requestDragObjects: session.

This is expected to initialise the set of drag-objects in the session
with the View's best guess at what's appropriate (the Presenter will get
a chance to modify it more intelligently later, as I described in my
earlier post).

I'm having to do something rather odd in the above code, and I'm not
sure if that's because I'm missing something, or there's a flaw in the
design of this part of the D&D system.  The View is expected to fill in
the drag objects (remember that there may be more than one, in general),
but #requestDragObjects: doesn't have enough information to be able to
do that properly in this case.  If Playgound had a concept of a
"current-selection" (as ListViews, and MoenTreeView, etc, do) then it'd
be natural to add any selected shapes to the sesssion.  But since it
doesn't have that concept, the proper thing to do would probably be to
add the object under the mouse.  Unfortunately, at this point we don't
know where the mouse was when the user started the operation.  What I
have done is to use the #suggestedSource of the D&D session (which was
set earlier when I did #self onBegin:drag:).  It's more than a little
hacky, but I don't know of a better approach.  Perhaps the ideal would
be to add a "current-selection" concept to Playgound.

That's it!  Of course you also have to do the other stuff I talked about
in my previous post too.  (And don't forget to turn on the #isDragSource
aspect of the Playgound instance).

Some things I don't know, but would like to:

How to do right-mouse dragging.  As far as I can tell from the comments
in the image, OA themselves don't yet know how to detect right-drag from
custom views.

How to make the drag operation use an image derived from the dragged
Shape rather than the its icon.  It'd be nice if there was some way to
make the Shape paint itself as required to implement this.

> Bruno Brasesco

    -- chris

Sun, 12 Oct 2003 19:41:52 GMT  
 [ 5 post ] 

 Relevant Pages 

1. simple drag and drop question

2. Drag and Drop question - CW2.003

3. Simple Drag and Drop Question.

4. Drag n Drop Question

5. VX-REXX: Drag and Drop Question

6. grab/drag&drop questions

7. Drag and Drop - How to get what was dropped onto

8. Drag & Drop Question

9. Newbie drag & drop questions

10. Question about Drag & Drop

11. VX-REXX: Drag-drop question

12. Dr Dialog Question drag and Drop


Powered by phpBB® Forum Software