author | Claus Gittinger <cg@exept.de> |
Wed, 01 Dec 1999 21:25:19 +0100 | |
changeset 1278 | 0fc24ae3a3e3 |
parent 1277 | ad8a630c9acd |
child 1292 | 632e22649e4b |
permissions | -rw-r--r-- |
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 |
||
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
31 |
DropObject subclass:#Text |
395 | 32 |
instanceVariableNames:'' |
33 |
classVariableNames:'' |
|
34 |
poolDictionaries:'' |
|
35 |
privateIn:DropObject |
|
36 |
! |
|
37 |
||
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
38 |
DropObject subclass:#Color |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
39 |
instanceVariableNames:'' |
860 | 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 |
||
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
52 |
DropObject subclass:#File |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
53 |
instanceVariableNames:'info isHtmlFile isImageFile isPrintable' |
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 |
]. |
|
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
159 |
DisplayObject := Smalltalk bitmapFromFileNamed:(self displayObjectName) forClass:self. |
403 | 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 |
||
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
253 |
!DropObject::Text class methodsFor:'defaults'! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
254 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
255 |
displayObjectName |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
256 |
^ 'bitmaps/xpmBitmaps/document_images/yellow_file_text_grab.xpm' |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
257 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
258 |
"Modified: 19.4.1997 / 15:40:33 / cg" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
259 |
! ! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
260 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
261 |
!DropObject::Text methodsFor:'testing'! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
262 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
263 |
isTextObject |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
264 |
"return true, if the dropObject represents some text" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
265 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
266 |
^ true |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
267 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
268 |
"Modified: 19.4.1997 / 12:52:08 / cg" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
269 |
! ! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
270 |
|
546 | 271 |
!DropObject::Color class methodsFor:'defaults'! |
272 |
||
273 |
displayObjectName |
|
274 |
"return the name of a bitmap image file, which is used |
|
275 |
during a drag." |
|
276 |
||
277 |
^ 'bitmaps/xpmBitmaps/misc_tools/color_wheel.xpm' |
|
278 |
||
279 |
"Modified: 19.4.1997 / 15:38:12 / cg" |
|
280 |
! ! |
|
281 |
||
282 |
!DropObject::Color methodsFor:'testing'! |
|
283 |
||
284 |
isColorObject |
|
285 |
"return true, if the dropObject represents a color" |
|
286 |
||
287 |
^ true |
|
288 |
||
289 |
"Modified: 19.4.1997 / 12:51:57 / cg" |
|
395 | 290 |
! ! |
291 |
||
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
292 |
!DropObject::Image class methodsFor:'defaults'! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
293 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
294 |
displayObjectName |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
295 |
"return the name of a bitmap image file, which is used |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
296 |
during a drag." |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
297 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
298 |
^ 'bitmaps/xpmBitmaps/misc_tools/picture.xpm' |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
299 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
300 |
"Modified: 19.4.1997 / 15:38:02 / cg" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
301 |
! ! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
302 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
303 |
!DropObject::Image methodsFor:'testing'! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
304 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
305 |
isImageObject |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
306 |
"return true, if the dropObject represents an image" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
307 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
308 |
^ true |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
309 |
|
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
310 |
"Modified: 19.4.1997 / 12:51:28 / cg" |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
311 |
! ! |
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
312 |
|
403 | 313 |
!DropObject::File class methodsFor:'defaults'! |
314 |
||
315 |
displayObjectName |
|
546 | 316 |
"return the name of a bitmap image file, which is used |
317 |
during a drag." |
|
403 | 318 |
|
546 | 319 |
^ 'bitmaps/xpmBitmaps/document_images/xfm_file.xpm' |
403 | 320 |
|
546 | 321 |
"Modified: 19.4.1997 / 15:38:07 / cg" |
403 | 322 |
! ! |
323 |
||
324 |
!DropObject::File methodsFor:'accessing'! |
|
325 |
||
326 |
theObject:aPathname |
|
546 | 327 |
|f path| |
403 | 328 |
|
546 | 329 |
f := aPathname asFilename. |
330 |
path := f pathName. |
|
331 |
info := f info. |
|
403 | 332 |
|
546 | 333 |
super theObject:f |
334 |
||
335 |
"Modified: 19.4.1997 / 12:49:17 / cg" |
|
403 | 336 |
! ! |
337 |
||
338 |
!DropObject::File methodsFor:'queries'! |
|
339 |
||
340 |
exists |
|
546 | 341 |
"returns true if the file or directory exists |
403 | 342 |
" |
343 |
^ info notNil |
|
546 | 344 |
|
345 |
"Modified: 19.4.1997 / 12:49:30 / cg" |
|
403 | 346 |
! |
347 |
||
348 |
isDirectory |
|
349 |
"checks whether file is a directory |
|
350 |
" |
|
351 |
^ (info notNil and:[info type == #directory]) |
|
352 |
! |
|
353 |
||
354 |
isHtmlFile |
|
546 | 355 |
"checks whether file is an html file |
403 | 356 |
" |
357 |
|suffixes pathName| |
|
358 |
||
359 |
isHtmlFile isNil ifTrue:[ |
|
360 |
(info isNil or:[self isDirectory]) ifTrue:[ |
|
361 |
isHtmlFile := false |
|
362 |
] ifFalse:[ |
|
363 |
pathName := theObject asString. |
|
364 |
suffixes := #( '.html' '.htm' '.HTML' '.HTM' ). |
|
365 |
isHtmlFile := (suffixes findFirst:[:el|pathName endsWith:el]) ~~ 0 |
|
366 |
] |
|
367 |
]. |
|
368 |
^ isHtmlFile |
|
546 | 369 |
|
370 |
"Modified: 19.4.1997 / 12:49:37 / cg" |
|
403 | 371 |
! |
372 |
||
373 |
isImageFile |
|
546 | 374 |
"returns true if file is an image file |
403 | 375 |
" |
546 | 376 |
|pathName| |
403 | 377 |
|
378 |
isImageFile isNil ifTrue:[ |
|
379 |
(info isNil or:[self isDirectory]) ifTrue:[ |
|
380 |
isImageFile := false |
|
381 |
] ifFalse:[ |
|
382 |
pathName := theObject asString. |
|
546 | 383 |
isImageFile := Image isImageFileSuffix:(pathName asFilename suffix). |
403 | 384 |
] |
385 |
]. |
|
386 |
^ isImageFile |
|
387 |
||
546 | 388 |
"Modified: 19.4.1997 / 12:50:58 / cg" |
403 | 389 |
! |
390 |
||
391 |
isPrintable |
|
392 |
"returns false if file contains non printable characters |
|
393 |
" |
|
394 |
|stream buff size| |
|
395 |
||
396 |
isPrintable isNil ifTrue:[ |
|
397 |
isPrintable := false. |
|
398 |
||
399 |
(info isNil or:[self isDirectory]) ifFalse:[ |
|
400 |
stream := FileStream readonlyFileNamed:(theObject pathName). |
|
401 |
||
402 |
stream isNil ifFalse:[ |
|
403 |
buff := String new:300. |
|
404 |
size := stream nextBytes:300 into:buff. |
|
405 |
stream close. |
|
406 |
]. |
|
407 |
1 to:size do:[:i| |
|
408 |
(buff at:i) isPrintable ifFalse:[ |
|
409 |
^ isPrintable |
|
410 |
] |
|
411 |
]. |
|
412 |
isPrintable := true |
|
413 |
] |
|
414 |
]. |
|
415 |
^ isPrintable |
|
416 |
! ! |
|
417 |
||
418 |
!DropObject::File methodsFor:'testing'! |
|
419 |
||
420 |
isFileObject |
|
546 | 421 |
"return true, if the dropObject represents a file- or directory" |
396 | 422 |
|
423 |
^ true |
|
424 |
||
546 | 425 |
"Modified: 19.4.1997 / 12:51:49 / cg" |
395 | 426 |
! ! |
427 |
||
428 |
!DropObject class methodsFor:'documentation'! |
|
429 |
||
430 |
version |
|
1277
ad8a630c9acd
try bitmaps in package directory
Claus Gittinger <cg@exept.de>
parents:
1112
diff
changeset
|
431 |
^ '$Header: /cvs/stx/stx/libview2/DropObject.st,v 1.9 1999-12-01 20:17:58 cg Exp $' |
395 | 432 |
! ! |