DropTarget.st
author Claus Gittinger <cg@exept.de>
Fri, 14 Dec 2001 11:51:34 +0100
changeset 1550 b58979898957
parent 873 c5cd8f56dc6e
child 1822 ceeb17948f5d
permissions -rw-r--r--
use new #perform:withOptionalArg

"
 COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"


"{ Package: 'stx:libview2' }"

Object subclass:#DropTarget
	instanceVariableNames:'receiver enterSelector leaveSelector overSelector dropSelector
		canDropSelector argument'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-DragAndDrop'
!

!DropTarget class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

!

documentation
"
    this class keeps the current target of the drop operation; the object respoonsible
    for the widget under the current mouse position.

    receiver        <Object>        receiver to which the requests are sent. the
                                    widget or an application.

    argument        <Object>        user defined argument

    enterSelector   <Symbol>        send the first time to the drop target when entering
                                    the widget.

    leaveSelector   <Symbol>        send the last time to the drop target when leaving
                                    the widget.

    overSelector    <Symbol>        send all the time to the drop target when moveing the
                                    mouse over the widget.

    dropSelector    <Symbol>        send to the drop target to drop the collection of
                                    objects.

    canDropSelector <Symbol>        send to the drop target to ask if the context could
                                    be dropped.

    [see also:]
        DragAndDropManager
        DropSource
        DropContext

    [author:]
        Claus Atzkern
"

! !

!DropTarget class methodsFor:'instance creation'!

receiver:aReceiver
    ^ self new receiver:aReceiver
!

receiver:aReceiver argument:anArgument

    ^ self new receiver:aReceiver
               argument:anArgument.
!

receiver:aReceiver argument:anArgument dropSelector:aSelector

    ^ self new receiver:aReceiver
               argument:anArgument
           dropSelector:aSelector
        canDropSelector:nil
!

receiver:aReceiver argument:anArgument dropSelector:s1 canDropSelector:s2

    ^ self new receiver:aReceiver
               argument:anArgument
           dropSelector:s1
        canDropSelector:s2
! !

!DropTarget methodsFor:'accessing'!

argument
    "returns the user defined argument; this argument is used for a drop action
     with two arguments, the context and the argument
    "
    ^ argument
!

argument:something
    "set the user defined argument; this argument is used for a drop action
     with two arguments, the context and the argument
    "
    ^ something
!

canDropSelector
    "selector called to get a feedback if context is droppable.
     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    ^ canDropSelector
!

canDropSelector:something
    "selector called to get a feedback if context is droppable.
     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    canDropSelector := something.
!

dropSelector
    "selector called to drop a collection of draggable objects.
     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    ^ dropSelector
!

dropSelector:something
    "selector called to drop a collection of draggable objects.

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    dropSelector := something.
!

enterSelector
    "send the first time to the drop target when entering the widget.

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    ^ enterSelector
!

enterSelector:something
    "send the first time to the drop target when entering the widget.

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    enterSelector := something.
!

leaveSelector
    "send the last time to the drop target when leaving the widget.

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    ^ leaveSelector
!

leaveSelector:something
    "send the last time to the drop target when leaving the widget.

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    leaveSelector := something.
!

overSelector
    "send all the time to the drop target when moveing the mouse over the widget

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    ^ overSelector
!

overSelector:something
    "send all the time to the drop target when moveing the mouse over the widget

     the arguments to the selector are:
        0       nothing
        1       aDropContext
        2       aDropContext and the argument
    "
    overSelector := something.
!

receiver
    "receiver to which the requests are sent. a widget or an application ...
    "
    ^ receiver
!

receiver:something
    "receiver to which the requests are sent. a widget or an application ...
    "
    receiver := something.
! !

!DropTarget methodsFor:'actions'!

drop:aContext
    "send when the mouse button is released within the current widget.
    "
    self perform:dropSelector withContext:aContext
!

enter:aContext
    "send the first time, when entering the widget
    "
    self perform:enterSelector withContext:aContext
!

leave:aContext
    "send the last time, when leaving the widget
    "
    self perform:leaveSelector withContext:aContext
!

over:aContext
    "send all the time, when moveing the mouse over the widget
    "
    self perform:overSelector withContext:aContext

! !

!DropTarget methodsFor:'instance creation'!

receiver:aReceiver argument:anArgument
    "set the receiver and an user defined argument
    "
    receiver := aReceiver.
    argument := anArgument.
!

receiver:aReceiver argument:anArgument dropSelector:s1 canDropSelector:s2
    "set the receiver and an user defined argument
    "
    receiver        := aReceiver.
    argument        := anArgument.
    dropSelector    := s1.
    canDropSelector := s2.
! !

!DropTarget methodsFor:'private'!

perform:aSelector withContext:aContext
    "perform the selector
    "
    aSelector notNil ifTrue:[
        ^ receiver perform:aSelector withOptionalArgument:aContext and:argument
    ]
! !

!DropTarget methodsFor:'queries'!

canDrop:aContext
    "send to the receiver to ask if the context is droppable
    "
    canDropSelector notNil ifTrue:[
        ^ receiver perform:canDropSelector withOptionalArgument:aContext and:argument
    ].
    ^ true
! !

!DropTarget class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/DropTarget.st,v 1.2 2001-12-14 10:51:34 cg Exp $'
! !