546
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
|
|
14 |
|
395
|
15 |
Object subclass:#DropObject
|
860
|
16 |
instanceVariableNames:'theObject displayObject'
|
395
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
875
|
19 |
category:'Interface-DragAndDrop'
|
395
|
20 |
!
|
|
21 |
|
403
|
22 |
DropObject class instanceVariableNames:'DisplayObject'
|
|
23 |
|
|
24 |
"
|
|
25 |
The following class instance variables are inherited by this class:
|
|
26 |
|
|
27 |
Object -
|
|
28 |
"
|
|
29 |
!
|
|
30 |
|
860
|
31 |
DropObject subclass:#Color
|
395
|
32 |
instanceVariableNames:''
|
|
33 |
classVariableNames:''
|
|
34 |
poolDictionaries:''
|
|
35 |
privateIn:DropObject
|
|
36 |
!
|
|
37 |
|
860
|
38 |
DropObject subclass:#File
|
|
39 |
instanceVariableNames:'info isHtmlFile isImageFile isPrintable'
|
|
40 |
classVariableNames:''
|
|
41 |
poolDictionaries:''
|
|
42 |
privateIn:DropObject
|
|
43 |
!
|
|
44 |
|
395
|
45 |
DropObject subclass:#Image
|
|
46 |
instanceVariableNames:''
|
|
47 |
classVariableNames:''
|
|
48 |
poolDictionaries:''
|
|
49 |
privateIn:DropObject
|
|
50 |
!
|
|
51 |
|
860
|
52 |
DropObject subclass:#Text
|
403
|
53 |
instanceVariableNames:''
|
395
|
54 |
classVariableNames:''
|
|
55 |
poolDictionaries:''
|
|
56 |
privateIn:DropObject
|
|
57 |
!
|
|
58 |
|
546
|
59 |
!DropObject class methodsFor:'documentation'!
|
|
60 |
|
|
61 |
copyright
|
|
62 |
"
|
|
63 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
64 |
All Rights Reserved
|
|
65 |
|
|
66 |
This software is furnished under a license and may be used
|
|
67 |
only in accordance with the terms of that license and with the
|
|
68 |
inclusion of the above copyright notice. This software may not
|
|
69 |
be provided or otherwise made available to, or used by, any
|
|
70 |
other person. No title to or ownership of the software is
|
|
71 |
hereby transferred.
|
|
72 |
"
|
|
73 |
|
|
74 |
|
|
75 |
!
|
|
76 |
|
|
77 |
documentation
|
|
78 |
"
|
|
79 |
instances of myself and subclasses wrap objects which are being
|
|
80 |
dragged (and dropped).
|
|
81 |
Any object can be dragged, but for some often encountered types,
|
|
82 |
specialized subclasses are provided, which react to certain queries.
|
|
83 |
|
|
84 |
[see also:]
|
|
85 |
DragAndDropManager
|
|
86 |
|
|
87 |
[author:]
|
|
88 |
Claus Atzkern
|
|
89 |
"
|
|
90 |
! !
|
395
|
91 |
|
|
92 |
!DropObject class methodsFor:'instance creation'!
|
|
93 |
|
1112
|
94 |
dropObjectClassFor:someThing
|
|
95 |
"given something to drag&drop, return an appropriate
|
|
96 |
dropObject class for it."
|
|
97 |
|
|
98 |
someThing isColor ifTrue:[^ DropObject::Color].
|
|
99 |
someThing isImageOrForm ifTrue:[^ DropObject::Image].
|
|
100 |
(someThing isKindOf:Filename) ifTrue:[^ DropObject::File].
|
|
101 |
someThing isString ifTrue:[^ DropObject::Text].
|
|
102 |
^ self
|
|
103 |
!
|
|
104 |
|
395
|
105 |
new:someThing
|
547
|
106 |
"create an instance on something
|
395
|
107 |
"
|
|
108 |
|cls|
|
|
109 |
|
1112
|
110 |
cls := self dropObjectClassFor:someThing.
|
|
111 |
^ cls new theObject:someThing
|
547
|
112 |
|
|
113 |
"Modified: 19.4.1997 / 17:19:55 / cg"
|
395
|
114 |
!
|
|
115 |
|
|
116 |
newColor:aColor
|
547
|
117 |
"create an instance for a color"
|
|
118 |
|
1112
|
119 |
^ DropObject::Color new theObject:aColor
|
547
|
120 |
|
|
121 |
"Modified: 19.4.1997 / 17:20:17 / cg"
|
395
|
122 |
!
|
|
123 |
|
|
124 |
newFile:aFilename
|
547
|
125 |
"create an instance for a file or directory"
|
|
126 |
|
1112
|
127 |
^ DropObject::File new theObject:aFilename
|
547
|
128 |
|
|
129 |
"Modified: 19.4.1997 / 17:20:28 / cg"
|
395
|
130 |
!
|
|
131 |
|
|
132 |
newImage:anImageOrForm
|
547
|
133 |
"create an instance for an image"
|
|
134 |
|
1112
|
135 |
^ DropObject::Image new theObject:anImageOrForm
|
547
|
136 |
|
|
137 |
"Modified: 19.4.1997 / 17:20:37 / cg"
|
395
|
138 |
!
|
|
139 |
|
|
140 |
newText:aTextOrString
|
547
|
141 |
"create an instance for some text"
|
|
142 |
|
1112
|
143 |
^ DropObject::Text new theObject:aTextOrString
|
547
|
144 |
|
|
145 |
"Modified: 19.4.1997 / 17:20:46 / cg"
|
395
|
146 |
! !
|
|
147 |
|
403
|
148 |
!DropObject class methodsFor:'defaults'!
|
|
149 |
|
|
150 |
displayObject
|
546
|
151 |
"return some object which is shown while dragging;
|
|
152 |
here an image based upon my displayObjectName is returned.
|
|
153 |
Either this method or #displayObjectName is usually redefined
|
|
154 |
in subclasses"
|
403
|
155 |
|
|
156 |
DisplayObject notNil ifTrue:[
|
|
157 |
^ DisplayObject
|
|
158 |
].
|
|
159 |
DisplayObject := Smalltalk::Image fromFile:(self displayObjectName).
|
|
160 |
^ DisplayObject
|
546
|
161 |
|
|
162 |
"Modified: 19.4.1997 / 13:04:05 / cg"
|
|
163 |
!
|
|
164 |
|
|
165 |
displayObject:aDisplayObject
|
|
166 |
"set the object which is shown while dragging;
|
|
167 |
this object must understand #displayOn:x:y: (i.e. the displayObject
|
|
168 |
protocol). The object is kept per class for ALL future drag operations.
|
|
169 |
Useful to change the default images in subclasses."
|
|
170 |
|
|
171 |
DisplayObject := aDisplayObject
|
|
172 |
|
|
173 |
"Modified: 19.4.1997 / 15:42:10 / cg"
|
403
|
174 |
!
|
|
175 |
|
|
176 |
displayObjectName
|
546
|
177 |
"return the name of a bitmap image file, which is used
|
|
178 |
during a drag.
|
|
179 |
Here, a dummy file is returned."
|
|
180 |
|
403
|
181 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/balloon3.xpm'
|
|
182 |
|
546
|
183 |
"Modified: 19.4.1997 / 13:54:13 / cg"
|
403
|
184 |
! !
|
|
185 |
|
395
|
186 |
!DropObject methodsFor:'accessing'!
|
|
187 |
|
860
|
188 |
displayObject
|
|
189 |
"return my graphical representation - here a default is returned"
|
|
190 |
|
|
191 |
^ displayObject ? (self class displayObject)
|
|
192 |
|
|
193 |
|
|
194 |
!
|
|
195 |
|
|
196 |
displayObject:anObject
|
|
197 |
"set my graphical representation"
|
|
198 |
|
|
199 |
displayObject := anObject
|
|
200 |
|
|
201 |
!
|
|
202 |
|
395
|
203 |
theObject
|
546
|
204 |
"return the real object represented by the receiver"
|
395
|
205 |
|
546
|
206 |
^ theObject
|
|
207 |
|
|
208 |
"Modified: 19.4.1997 / 12:53:01 / cg"
|
|
209 |
!
|
395
|
210 |
|
|
211 |
theObject:something
|
546
|
212 |
"set the real object represented by the receiver"
|
395
|
213 |
|
546
|
214 |
theObject := something.
|
|
215 |
|
|
216 |
"Modified: 19.4.1997 / 12:53:10 / cg"
|
|
217 |
! !
|
395
|
218 |
|
|
219 |
!DropObject methodsFor:'testing'!
|
|
220 |
|
|
221 |
isColorObject
|
546
|
222 |
"return true, if the dropObject represents a color"
|
|
223 |
|
395
|
224 |
^ false
|
546
|
225 |
|
|
226 |
"Modified: 19.4.1997 / 12:52:36 / cg"
|
395
|
227 |
!
|
|
228 |
|
|
229 |
isFileObject
|
546
|
230 |
"return true, if the dropObject represents some file or directory"
|
|
231 |
|
395
|
232 |
^ false
|
546
|
233 |
|
|
234 |
"Modified: 19.4.1997 / 12:52:29 / cg"
|
395
|
235 |
!
|
|
236 |
|
|
237 |
isImageObject
|
546
|
238 |
"return true, if the dropObject represents some image"
|
|
239 |
|
395
|
240 |
^ false
|
546
|
241 |
|
|
242 |
"Modified: 19.4.1997 / 12:52:22 / cg"
|
395
|
243 |
!
|
|
244 |
|
|
245 |
isTextObject
|
546
|
246 |
"return true, if the dropObject represents some text"
|
|
247 |
|
395
|
248 |
^ false
|
546
|
249 |
|
|
250 |
"Modified: 19.4.1997 / 12:52:17 / cg"
|
|
251 |
! !
|
|
252 |
|
|
253 |
!DropObject::Color class methodsFor:'defaults'!
|
|
254 |
|
|
255 |
displayObjectName
|
|
256 |
"return the name of a bitmap image file, which is used
|
|
257 |
during a drag."
|
|
258 |
|
|
259 |
^ 'bitmaps/xpmBitmaps/misc_tools/color_wheel.xpm'
|
|
260 |
|
|
261 |
"Modified: 19.4.1997 / 15:38:12 / cg"
|
|
262 |
! !
|
|
263 |
|
|
264 |
!DropObject::Color methodsFor:'testing'!
|
|
265 |
|
|
266 |
isColorObject
|
|
267 |
"return true, if the dropObject represents a color"
|
|
268 |
|
|
269 |
^ true
|
|
270 |
|
|
271 |
"Modified: 19.4.1997 / 12:51:57 / cg"
|
395
|
272 |
! !
|
|
273 |
|
403
|
274 |
!DropObject::File class methodsFor:'defaults'!
|
|
275 |
|
|
276 |
displayObjectName
|
546
|
277 |
"return the name of a bitmap image file, which is used
|
|
278 |
during a drag."
|
403
|
279 |
|
546
|
280 |
^ 'bitmaps/xpmBitmaps/document_images/xfm_file.xpm'
|
403
|
281 |
|
546
|
282 |
"Modified: 19.4.1997 / 15:38:07 / cg"
|
403
|
283 |
! !
|
|
284 |
|
|
285 |
!DropObject::File methodsFor:'accessing'!
|
|
286 |
|
|
287 |
theObject:aPathname
|
546
|
288 |
|f path|
|
403
|
289 |
|
546
|
290 |
f := aPathname asFilename.
|
|
291 |
path := f pathName.
|
|
292 |
info := f info.
|
403
|
293 |
|
546
|
294 |
super theObject:f
|
|
295 |
|
|
296 |
"Modified: 19.4.1997 / 12:49:17 / cg"
|
403
|
297 |
! !
|
|
298 |
|
|
299 |
!DropObject::File methodsFor:'queries'!
|
|
300 |
|
|
301 |
exists
|
546
|
302 |
"returns true if the file or directory exists
|
403
|
303 |
"
|
|
304 |
^ info notNil
|
546
|
305 |
|
|
306 |
"Modified: 19.4.1997 / 12:49:30 / cg"
|
403
|
307 |
!
|
|
308 |
|
|
309 |
isDirectory
|
|
310 |
"checks whether file is a directory
|
|
311 |
"
|
|
312 |
^ (info notNil and:[info type == #directory])
|
|
313 |
!
|
|
314 |
|
|
315 |
isHtmlFile
|
546
|
316 |
"checks whether file is an html file
|
403
|
317 |
"
|
|
318 |
|suffixes pathName|
|
|
319 |
|
|
320 |
isHtmlFile isNil ifTrue:[
|
|
321 |
(info isNil or:[self isDirectory]) ifTrue:[
|
|
322 |
isHtmlFile := false
|
|
323 |
] ifFalse:[
|
|
324 |
pathName := theObject asString.
|
|
325 |
suffixes := #( '.html' '.htm' '.HTML' '.HTM' ).
|
|
326 |
isHtmlFile := (suffixes findFirst:[:el|pathName endsWith:el]) ~~ 0
|
|
327 |
]
|
|
328 |
].
|
|
329 |
^ isHtmlFile
|
546
|
330 |
|
|
331 |
"Modified: 19.4.1997 / 12:49:37 / cg"
|
403
|
332 |
!
|
|
333 |
|
|
334 |
isImageFile
|
546
|
335 |
"returns true if file is an image file
|
403
|
336 |
"
|
546
|
337 |
|pathName|
|
403
|
338 |
|
|
339 |
isImageFile isNil ifTrue:[
|
|
340 |
(info isNil or:[self isDirectory]) ifTrue:[
|
|
341 |
isImageFile := false
|
|
342 |
] ifFalse:[
|
|
343 |
pathName := theObject asString.
|
546
|
344 |
isImageFile := Image isImageFileSuffix:(pathName asFilename suffix).
|
403
|
345 |
]
|
|
346 |
].
|
|
347 |
^ isImageFile
|
|
348 |
|
546
|
349 |
"Modified: 19.4.1997 / 12:50:58 / cg"
|
403
|
350 |
!
|
|
351 |
|
|
352 |
isPrintable
|
|
353 |
"returns false if file contains non printable characters
|
|
354 |
"
|
|
355 |
|stream buff size|
|
|
356 |
|
|
357 |
isPrintable isNil ifTrue:[
|
|
358 |
isPrintable := false.
|
|
359 |
|
|
360 |
(info isNil or:[self isDirectory]) ifFalse:[
|
|
361 |
stream := FileStream readonlyFileNamed:(theObject pathName).
|
|
362 |
|
|
363 |
stream isNil ifFalse:[
|
|
364 |
buff := String new:300.
|
|
365 |
size := stream nextBytes:300 into:buff.
|
|
366 |
stream close.
|
|
367 |
].
|
|
368 |
1 to:size do:[:i|
|
|
369 |
(buff at:i) isPrintable ifFalse:[
|
|
370 |
^ isPrintable
|
|
371 |
]
|
|
372 |
].
|
|
373 |
isPrintable := true
|
|
374 |
]
|
|
375 |
].
|
|
376 |
^ isPrintable
|
|
377 |
! !
|
|
378 |
|
|
379 |
!DropObject::File methodsFor:'testing'!
|
|
380 |
|
|
381 |
isFileObject
|
546
|
382 |
"return true, if the dropObject represents a file- or directory"
|
396
|
383 |
|
|
384 |
^ true
|
|
385 |
|
546
|
386 |
"Modified: 19.4.1997 / 12:51:49 / cg"
|
395
|
387 |
! !
|
|
388 |
|
860
|
389 |
!DropObject::Image class methodsFor:'defaults'!
|
|
390 |
|
|
391 |
displayObjectName
|
|
392 |
"return the name of a bitmap image file, which is used
|
|
393 |
during a drag."
|
|
394 |
|
|
395 |
^ 'bitmaps/xpmBitmaps/misc_tools/picture.xpm'
|
|
396 |
|
|
397 |
"Modified: 19.4.1997 / 15:38:02 / cg"
|
|
398 |
! !
|
|
399 |
|
|
400 |
!DropObject::Image methodsFor:'testing'!
|
|
401 |
|
|
402 |
isImageObject
|
|
403 |
"return true, if the dropObject represents an image"
|
|
404 |
|
|
405 |
^ true
|
|
406 |
|
|
407 |
"Modified: 19.4.1997 / 12:51:28 / cg"
|
|
408 |
! !
|
|
409 |
|
|
410 |
!DropObject::Text class methodsFor:'defaults'!
|
|
411 |
|
|
412 |
displayObjectName
|
|
413 |
^ 'bitmaps/xpmBitmaps/document_images/yellow_file_text_grab.xpm'
|
|
414 |
|
|
415 |
"Modified: 19.4.1997 / 15:40:33 / cg"
|
|
416 |
! !
|
|
417 |
|
|
418 |
!DropObject::Text methodsFor:'testing'!
|
|
419 |
|
|
420 |
isTextObject
|
|
421 |
"return true, if the dropObject represents some text"
|
|
422 |
|
|
423 |
^ true
|
|
424 |
|
|
425 |
"Modified: 19.4.1997 / 12:52:08 / cg"
|
|
426 |
! !
|
|
427 |
|
395
|
428 |
!DropObject class methodsFor:'documentation'!
|
|
429 |
|
|
430 |
version
|
1112
|
431 |
^ '$Header: /cvs/stx/stx/libview2/DropObject.st,v 1.8 1999-02-26 12:25:27 cg Exp $'
|
395
|
432 |
! !
|