"
COPYRIGHT (c) 1997 by eXept Software AG
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:#DropObject
instanceVariableNames:'theObject displayObject'
classVariableNames:''
poolDictionaries:''
category:'Interface-DragAndDrop'
!
DropObject class instanceVariableNames:'DisplayObject'
"
No other class instance variables are inherited by this class.
"
!
DropObject subclass:#Class
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#Color
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#File
instanceVariableNames:'info isHtmlFile isImageFile isPrintable'
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject::File subclass:#FileInArchive
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#Image
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#Method
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#Text
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
!DropObject class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1997 by eXept Software AG
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
"
instances of myself and subclasses wrap objects which are being
dragged (and dropped).
Any object can be dragged, but for some often encountered types,
specialized subclasses are provided, which react to certain queries.
[see also:]
DragAndDropManager
[author:]
Claus Atzkern
"
! !
!DropObject class methodsFor:'instance creation'!
dropObjectClassFor:someThing
"given something to drag&drop, return an appropriate
dropObject class for it."
someThing isColor ifTrue:[^ DropObject::Color].
someThing isImageOrForm ifTrue:[^ DropObject::Image].
(someThing isKindOf:Filename) ifTrue:[^ DropObject::File].
someThing isString ifTrue:[^ DropObject::Text].
someThing isBehavior ifTrue:[^ DropObject::Class].
someThing isMethod ifTrue:[^ DropObject::Method].
^ self
!
new:someThing
"create an instance on something
"
|cls|
cls := self dropObjectClassFor:someThing.
^ self newInstanceOf:cls for:someThing
"Modified: 19.4.1997 / 17:19:55 / cg"
!
newClass:aClass
"create an instance for a class (dragging a class from a browser)"
^ self newInstanceOf:DropObject::Class for:aClass
!
newColor:aColor
"create an instance for a color (dragging a color from a bitmap editor)"
^ self newInstanceOf:DropObject::Color for:aColor
"Modified: 19.4.1997 / 17:20:17 / cg"
!
newFile:aFilename
"create an instance for a file or directory (dragging a file in a fileBrowser)"
^ self newInstanceOf:DropObject::File for:aFilename
!
newFileInArchive:aFilename
"create an instance for a file or directory contained inside an archive
(dragging a file from an archive shown in a fileBrowser)"
^ self newInstanceOf:DropObject::FileInArchive for:aFilename
!
newImage:anImageOrForm
"create an instance for an image"
^ self newInstanceOf:DropObject::Image for:anImageOrForm
"Modified: 19.4.1997 / 17:20:37 / cg"
!
newInstanceOf:aClass for:someThing
"create an instance on something
"
^ aClass new theObject:someThing
"Modified: 19.4.1997 / 17:19:55 / cg"
!
newMethod:aMethod
"create an instance for a method (dragging a method in a browser)"
^ self newInstanceOf:DropObject::Method for:aMethod
!
newText:aTextOrString
"create an instance for some text (dragging some text from an editor)"
^ self newInstanceOf:DropObject::Text for:aTextOrString
"Modified: 19.4.1997 / 17:20:46 / cg"
! !
!DropObject class methodsFor:'defaults'!
displayObject
"return some object which is shown while dragging;
here an image based upon my displayObjectName is returned.
Either this method or #displayObjectName is usually redefined
in subclasses"
DisplayObject notNil ifTrue:[
^ DisplayObject
].
DisplayObject := Smalltalk imageFromFileNamed:(self displayObjectName) forClass:self.
^ DisplayObject
"Modified: 19.4.1997 / 13:04:05 / cg"
!
displayObject:aDisplayObject
"set the object which is shown while dragging;
this object must understand #displayOn:x:y: (i.e. the displayObject
protocol). The object is kept per class for ALL future drag operations.
Useful to change the default images in subclasses."
DisplayObject := aDisplayObject
"Modified: 19.4.1997 / 15:42:10 / cg"
!
displayObjectName
"return the name of a bitmap image file, which is used
during a drag.
Here, a dummy file is returned."
^ 'bitmaps/xpmBitmaps/plain_pixmaps/balloon3.xpm'
"Modified: 19.4.1997 / 13:54:13 / cg"
! !
!DropObject methodsFor:'accessing'!
displayObject
"return my graphical representation - here a default is returned"
^ displayObject ? (self class displayObject)
!
displayObject:anObject
"set my graphical representation"
displayObject := anObject
!
theObject
"return the real object represented by the receiver"
^ theObject
"Modified: 19.4.1997 / 12:53:01 / cg"
!
theObject:something
"set the real object represented by the receiver"
theObject := something.
"Modified: 19.4.1997 / 12:53:10 / cg"
! !
!DropObject methodsFor:'testing'!
isClassObject
"return true, if the dropObject represents some class"
^ false
!
isColorObject
"return true, if the dropObject represents a color"
^ false
"Modified: 19.4.1997 / 12:52:36 / cg"
!
isFileInArchive
^ false
!
isFileObject
"return true, if the dropObject represents some file or directory"
^ false
"Modified: 19.4.1997 / 12:52:29 / cg"
!
isImageObject
"return true, if the dropObject represents some image"
^ false
"Modified: 19.4.1997 / 12:52:22 / cg"
!
isMethodObject
"return true, if the dropObject represents some method"
^ false
!
isTextObject
"return true, if the dropObject represents some text"
^ false
"Modified: 19.4.1997 / 12:52:17 / cg"
! !
!DropObject::Class methodsFor:'testing'!
isClassObject
"return true, if the dropObject represents a class"
^ true
! !
!DropObject::Color class methodsFor:'defaults'!
displayObjectName
"return the name of a bitmap image file, which is used
during a drag."
^ 'bitmaps/xpmBitmaps/misc_tools/color_wheel.xpm'
"Modified: 19.4.1997 / 15:38:12 / cg"
! !
!DropObject::Color methodsFor:'testing'!
isColorObject
"return true, if the dropObject represents a color"
^ true
"Modified: 19.4.1997 / 12:51:57 / cg"
! !
!DropObject::File class methodsFor:'defaults'!
displayObjectName
"return the name of a bitmap image file, which is used
during a drag."
^ 'bitmaps/xpmBitmaps/document_images/xfm_file.xpm'
"Modified: 19.4.1997 / 15:38:07 / cg"
! !
!DropObject::File methodsFor:'accessing'!
theObject:aPathname
|f path|
f := aPathname asFilename.
path := f pathName.
info := f info.
super theObject:f
"Modified: 19.4.1997 / 12:49:17 / cg"
! !
!DropObject::File methodsFor:'queries'!
asFilename
^ theObject asString asFilename
"Created: / 13-10-2006 / 17:22:24 / cg"
!
exists
"returns true if the file or directory exists
"
^ info notNil
"Modified: 19.4.1997 / 12:49:30 / cg"
!
isDirectory
"checks whether file is a directory
"
^ (info notNil and:[info type == #directory])
!
isHtmlFile
"checks whether file is an html file
"
|suffixes pathName|
isHtmlFile isNil ifTrue:[
(info isNil or:[self isDirectory]) ifTrue:[
isHtmlFile := false
] ifFalse:[
pathName := theObject asString.
suffixes := #( '.html' '.htm' '.HTML' '.HTM' ).
isHtmlFile := (suffixes findFirst:[:el|pathName endsWith:el]) ~~ 0
]
].
^ isHtmlFile
"Modified: 19.4.1997 / 12:49:37 / cg"
!
isImageFile
"returns true if file is an image file
"
|pathName|
isImageFile isNil ifTrue:[
(info isNil or:[self isDirectory]) ifTrue:[
isImageFile := false
] ifFalse:[
pathName := theObject asString.
isImageFile := Image isImageFileSuffix:(pathName asFilename suffix).
]
].
^ isImageFile
"Modified: 19.4.1997 / 12:50:58 / cg"
!
isPrintable
"return false if file contains nonprintable characters"
|stream buff size|
isPrintable isNil ifTrue:[
isPrintable := false.
(info isNil or:[ self isDirectory ]) ifFalse:[
stream := theObject readStreamOrNil.
stream notNil ifTrue:[
buff := String new:300.
size := stream nextBytes:300 into:buff.
stream close.
1 to:size do:[:i |
(buff at:i) isPrintable ifFalse:[
^ false
]
].
].
isPrintable := true
]
].
^ isPrintable
! !
!DropObject::File methodsFor:'testing'!
isFileObject
"return true, if the dropObject represents a file- or directory"
^ true
"Modified: 19.4.1997 / 12:51:49 / cg"
! !
!DropObject::FileInArchive methodsFor:'testing'!
isFileInArchive
^ true
! !
!DropObject::Image class methodsFor:'defaults'!
displayObjectName
"return the name of a bitmap image file, which is used
during a drag."
^ 'bitmaps/xpmBitmaps/misc_tools/picture.xpm'
"Modified: 19.4.1997 / 15:38:02 / cg"
! !
!DropObject::Image methodsFor:'testing'!
isImageObject
"return true, if the dropObject represents an image"
^ true
"Modified: 19.4.1997 / 12:51:28 / cg"
! !
!DropObject::Method methodsFor:'testing'!
isMethodObject
"return true, if the dropObject represents a method"
^ true
! !
!DropObject::Text class methodsFor:'defaults'!
displayObjectName
^ 'bitmaps/xpmBitmaps/document_images/yellow_file_text_grab.xpm'
"Modified: 19.4.1997 / 15:40:33 / cg"
! !
!DropObject::Text methodsFor:'testing'!
isTextObject
"return true, if the dropObject represents some text"
^ true
"Modified: 19.4.1997 / 12:52:08 / cg"
! !
!DropObject class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libview2/DropObject.st,v 1.16 2006-10-13 15:45:04 cg Exp $'
! !