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