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