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