"
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.
"
Object subclass:#DropObject
instanceVariableNames:'theObject'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
!
DropObject class instanceVariableNames:'DisplayObject'
"
The following class instance variables are inherited by this class:
Object -
"
!
DropObject subclass:#Text
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
privateIn:DropObject
!
DropObject subclass:#Image
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 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'!
new:someThing
"create an instance dependant on something
"
|cls|
someThing isColor ifTrue:[cls := Color
] ifFalse:[someThing isImageOrForm ifTrue:[cls := Image
] ifFalse:[(someThing isKindOf:Filename) ifTrue:[cls := File
] ifFalse:[cls isString ifTrue:[cls := Text
] ifFalse:[
cls := DropObject
]]]].
^ cls new theObject:someThing
!
newColor:aColor
^ Color new theObject:aColor
!
newFile:aFilename
^ File new theObject:aFilename
!
newImage:anImageOrForm
^ Image new theObject:anImageOrForm
!
newText:aTextOrString
^ Text new theObject:aTextOrString
! !
!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::Image fromFile:(self displayObjectName).
^ 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'!
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:'queries'!
displayObject
"return my graphical representation - here a default is returned"
^ self class displayObject
"Modified: 19.4.1997 / 12:52:41 / cg"
! !
!DropObject methodsFor:'testing'!
isColorObject
"return true, if the dropObject represents a color"
^ false
"Modified: 19.4.1997 / 12:52:36 / cg"
!
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"
!
isTextObject
"return true, if the dropObject represents some text"
^ false
"Modified: 19.4.1997 / 12:52:17 / cg"
! !
!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::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::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'!
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
"returns false if file contains non printable characters
"
|stream buff size|
isPrintable isNil ifTrue:[
isPrintable := false.
(info isNil or:[self isDirectory]) ifFalse:[
stream := FileStream readonlyFileNamed:(theObject pathName).
stream isNil ifFalse:[
buff := String new:300.
size := stream nextBytes:300 into:buff.
stream close.
].
1 to:size do:[:i|
(buff at:i) isPrintable ifFalse:[
^ isPrintable
]
].
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 class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libview2/DropObject.st,v 1.4 1997-04-19 13:44:35 cg Exp $'
! !