ImageView.st
author Claus Gittinger <cg@exept.de>
Tue, 10 Dec 2002 11:46:23 +0100
changeset 2402 4425948481b4
parent 2375 e0c7852263e4
child 2404 2b7591c982ac
permissions -rw-r--r--
category change
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     1
"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
     3
	      All Rights Reserved
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     4
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    11
"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    12
1763
7d6d64622ee4 change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents: 1694
diff changeset
    13
"{ Package: 'stx:libwidg2' }"
7d6d64622ee4 change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents: 1694
diff changeset
    14
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    15
View subclass:#ImageView
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    16
	instanceVariableNames:'image magnifiedImage adjust imageChannel tileMode tileOffset'
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    17
	classVariableNames:'DoNotMagnifyQuery'
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
    18
	poolDictionaries:''
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
    19
	category:'Views-Misc'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    20
!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    21
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
    22
!ImageView class methodsFor:'documentation'!
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    23
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    24
copyright
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    25
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    27
	      All Rights Reserved
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    28
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    29
 This software is furnished under a license and may be used
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    30
 only in accordance with the terms of that license and with the
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    32
 be provided or otherwise made available to, or used by, any
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    33
 other person.  No title to or ownership of the software is
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    34
 hereby transferred.
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    35
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    36
!
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    37
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    38
documentation
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    39
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    40
    This View knows how to display an image (or form).
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    41
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    42
    You can display an image with:
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    43
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    44
        ImageView openOn:anImageFileName
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    45
    or:
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    46
        ImageView openOnImage:anImage
47
claus
parents: 46
diff changeset
    47
    or:
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    48
        ImageView new image:anImage
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    49
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    50
    i.e.
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    51
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
    52
        ImageView openOn:'bitmaps/gifImages/garfield.gif'
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    53
        ImageView openOn:'bitmaps/SBrowser.xbm'
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    54
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
    55
        ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif')
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    56
        ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm')
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    57
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    58
    adjust:     
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    59
        controls how images are displayed;
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    60
        can be one of:
2375
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
    61
            #topLeft    - image is displayed as usual
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    62
            #center     - image is shown centered
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    63
            #fitBig     - big images are shrunk to make it fit the view
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    64
            #fitSmall   - small images are magnified to make it fit the view,
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    65
            #fit        - all images are magnified to fit the view
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    66
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    67
    [author:]
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    68
        Claus Gittinger
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    69
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    70
    [see also:]
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    71
        Image Form
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    72
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    73
! !
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    74
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    75
!ImageView class methodsFor:'initialization'!
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    76
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    77
initialize
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    78
    DoNotMagnifyQuery := QuerySignal new defaultAnswer:false.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    79
! !
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    80
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    81
!ImageView class methodsFor:'queries - plugin'!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    82
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    83
aspectSelectors
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    84
    ^ #( imageChannel )
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    85
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    86
    "Created: / 11.2.2000 / 00:37:33 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    87
! !
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
    88
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
    89
!ImageView class methodsFor:'startup'!
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    90
11
793044d4bc90 *** empty log message ***
claus
parents: 9
diff changeset
    91
openOn:aFileName
47
claus
parents: 46
diff changeset
    92
    "startup an image viewer on an image read from a file"
claus
parents: 46
diff changeset
    93
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
    94
    |fn imageView img e|
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
    95
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
    96
    fn := aFileName asFilename.
47
claus
parents: 46
diff changeset
    97
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
    98
    img := Image fromFile:fn.
47
claus
parents: 46
diff changeset
    99
    img isNil ifTrue:[
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   100
        fn exists ifTrue:[
348
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   101
            e := 'unknown/unsupported image format'
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   102
        ] ifFalse:[
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   103
            e := 'no such image'.
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   104
        ].
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   105
        self warn:e.
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   106
        ^ nil
47
claus
parents: 46
diff changeset
   107
    ].
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   108
    imageView := self openOnImage:img.
47
claus
parents: 46
diff changeset
   109
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   110
    imageView topView label:fn pathName iconLabel:(fn baseName).
47
claus
parents: 46
diff changeset
   111
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   112
    ^ imageView
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   113
47
claus
parents: 46
diff changeset
   114
    "
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   115
     ImageView openOn:'bitmaps/gifImages/garfield.gif'
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   116
     ImageView openOn:'bitmaps/xpmBitmaps/BOOK.xpm'
47
claus
parents: 46
diff changeset
   117
    "
348
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   118
599
66c4da764a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   119
    "Modified: / 31.10.1997 / 16:17:52 / cg"
47
claus
parents: 46
diff changeset
   120
!
claus
parents: 46
diff changeset
   121
claus
parents: 46
diff changeset
   122
openOnImage:anImage
claus
parents: 46
diff changeset
   123
    "startup an image viewer on an image"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   124
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   125
    |top v imageView icnW icnH iconView magX magY mag lbl imgWidth imgHeight|
47
claus
parents: 46
diff changeset
   126
claus
parents: 46
diff changeset
   127
    anImage isImage ifTrue:[
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   128
        lbl := 'an Image'
47
claus
parents: 46
diff changeset
   129
    ] ifFalse:[
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   130
        lbl := 'a Form'
47
claus
parents: 46
diff changeset
   131
    ].
claus
parents: 46
diff changeset
   132
    top := StandardSystemView label:lbl.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   133
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   134
    v := HVScrollableView for:self in:top.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   135
    v origin:0@0 extent:1.0@1.0. 
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   136
    imageView := v scrolledView.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   137
47
claus
parents: 46
diff changeset
   138
    anImage notNil ifTrue:[
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   139
        imageView image:anImage.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   140
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   141
        "define an icon view showing a little version of image.
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   142
         Since some window managers cannot handle this correctly (twm),
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   143
         this is only done when running on an IRIS"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   144
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   145
        (true "(OperatingSystem getSystemType = 'iris')" 
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   146
        and:[StyleSheet name == #iris]) ifTrue:[
599
66c4da764a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   147
            iconView := ImageView new.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   148
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   149
            "for now; should somehow get access to preferred iconview extent ..."
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   150
            icnW := 86.
599
66c4da764a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   151
            icnH := 68.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   152
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   153
            imgWidth := anImage width.
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   154
            imgHeight := anImage height.
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   155
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   156
            ((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   157
                iconView extent:(imgWidth @ imgHeight).
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   158
                mag := 1 @ 1
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   159
            ] ifFalse:[
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   160
                magX := icnW / imgWidth.
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   161
                magY := icnH / imgHeight.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   162
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   163
                "scale image"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   164
"
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   165
                mag := magX @ magY.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   166
"
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   167
                "preserve ratio"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   168
" 
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   169
                mag := (magX min:magY) asPoint.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   170
" 
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   171
" "
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   172
                mag := (magX max:magY) asPoint.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   173
" "
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   174
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   175
                iconView extent:((anImage width @ anImage height) * mag) rounded.
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   176
            ].
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   177
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   178
            top iconView:iconView.
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   179
        ].
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   180
    ].
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   181
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   182
    top open.
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   183
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   184
    iconView notNil ifTrue:[
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   185
        top windowGroup addView:iconView.
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   186
        [ 
2099
64402b3555eb Do not use obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 2092
diff changeset
   187
            iconView image:(anImage magnifiedBy:mag).
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   188
        ] forkAt:4
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   189
    ].
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   190
    ^ imageView
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   191
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   192
    "
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   193
     ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif')
47
claus
parents: 46
diff changeset
   194
     ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm')
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   195
    "
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   196
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   197
    "Modified: / 18.12.1997 / 11:46:19 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   198
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   199
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   200
!ImageView methodsFor:'accessing'!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   201
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   202
adjust:layoutSymbol
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   203
    "set the adjust (how the image is displayed);
2375
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   204
     currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   205
            #topLeft    - image is displayed as usual
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   206
            #center     - image is shown centered
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   207
            #fitBig     - big images are shrunk to make it fit the view
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   208
            #fitSmall   - small images are magnified to make it fit the view,
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   209
            #fit        - all images are magnified to fit the view
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   210
    "
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   211
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   212
    adjust ~= layoutSymbol ifTrue:[
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   213
        adjust := layoutSymbol.
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   214
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   215
        magnifiedImage := nil.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   216
        self shown ifTrue:[
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   217
            image notNil ifTrue:[
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   218
                self generateMagnifiedImage.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   219
                self clear.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   220
                self scrollToTopLeft.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   221
                self invalidate.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   222
                self contentsChanged.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   223
            ]
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   224
        ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   225
    ].
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   226
!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   227
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   228
image
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   229
    "return the image"
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   230
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   231
    ^ image
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   232
!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   233
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   234
image:anImage
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   235
    "set the image - show a wait cursor, since image dithering may take a while"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   236
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   237
"/    image ~= anImage ifTrue:[
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   238
        self setImage:anImage
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   239
"/    ]
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   240
!
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   241
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   242
setImage:anImage
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   243
    "set the image - show a wait cursor, since image dithering may take a while"
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   244
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   245
    |oldSize newSize|
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   246
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   247
    oldSize := image ifNil:[0@0] ifNotNil:[image extent].
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   248
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   249
    image := anImage.
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   250
    magnifiedImage := nil.
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   251
    self generateMagnifiedImage.
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   252
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   253
    newSize := image ifNil:[0@0] ifNotNil:[(magnifiedImage ? image) extent].
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   254
    self scrollToTopLeft.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   255
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   256
    oldSize ~= newSize ifTrue:[
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   257
        "/ avoid endless loop in case of a resize happening due
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   258
        "/ to scrollBar visibility changes.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   259
        "/ that QuerySignal suppresses another magnification in sizeChanged: 
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   260
        DoNotMagnifyQuery answer:true
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   261
        do:[
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   262
            self contentsChanged.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   263
        ]
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   264
    ].
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   265
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   266
    shown ifTrue:[
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   267
        self clear.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   268
        self invalidate
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   269
    ].
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   270
    self changed:#image.
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   271
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   272
    "Modified: / 10.2.2000 / 23:25:51 / cg"
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   273
!
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   274
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   275
tileMode:aBoolean tileOffset:aPoint
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   276
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   277
    tileMode := aBoolean.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   278
    tileOffset := aPoint
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   279
! !
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   280
2402
4425948481b4 category change
Claus Gittinger <cg@exept.de>
parents: 2375
diff changeset
   281
!ImageView methodsFor:'accessing - channels'!
1510
fd0cd6065dc6 catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents: 1327
diff changeset
   282
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   283
imageChannel
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   284
    imageChannel isNil ifTrue:[
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   285
        imageChannel := ValueHolder new.
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   286
        imageChannel addDependent:self.
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   287
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   288
    ^ imageChannel
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   289
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   290
    "Created: / 11.2.2000 / 00:34:44 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   291
!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   292
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   293
imageChannel:aValueHolder
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   294
    imageChannel notNil ifTrue:[
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   295
        imageChannel removeDependent:self.
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   296
    ].
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   297
    imageChannel := aValueHolder.
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   298
    imageChannel notNil ifTrue:[
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   299
        imageChannel addDependent:self.
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   300
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   301
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   302
    "Created: / 11.2.2000 / 00:34:33 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   303
! !
1135
75101bf02c5b send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   304
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   305
!ImageView methodsFor:'change & update'!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   306
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   307
update:something with:aParameter from:changedObject
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   308
    something == imageChannel ifTrue:[
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   309
        self image:(imageChannel value).
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   310
        ^ self
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   311
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   312
    super update:something with:aParameter from:changedObject
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   313
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   314
    "Created: / 11.2.2000 / 00:37:02 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   315
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   316
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   317
!ImageView methodsFor:'drawing'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   318
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   319
generateMagnifiedImage
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   320
    |doFit innerWidth innerHeight imgWidth imgHeight|
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   321
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   322
    magnifiedImage notNil ifTrue:[
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   323
        ^ self
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   324
    ].
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   325
    image isNil ifTrue:[
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   326
        ^ self
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   327
    ].
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   328
        
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   329
    doFit := false.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   330
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   331
    innerWidth := self innerWidth.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   332
    innerHeight := self innerHeight.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   333
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   334
    imgWidth := image width.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   335
    imgHeight := image height.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   336
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   337
    tileMode ~~ true ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   338
        ((imgWidth > innerWidth)
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   339
        or:[imgHeight > innerHeight]) ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   340
            ((adjust == #fit) or:[adjust == #fitBig]) ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   341
                doFit := true
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   342
            ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   343
        ] ifFalse:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   344
            ((imgWidth < innerWidth)
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   345
            or:[imgHeight < innerHeight]) ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   346
                ((adjust == #fit) or:[adjust == #fitSmall]) ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   347
                    doFit := true
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   348
                ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   349
            ]
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   350
        ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   351
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   352
    doFit ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   353
        magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight).
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   354
"/        self contentsChanged.
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   355
    ] ifFalse:[
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   356
        magnifiedImage := image
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   357
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   358
!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   359
210
1a3b06d71a03 faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents: 207
diff changeset
   360
redrawX:x y:y width:w height:h
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   361
    |xI yI depth shownImage imgWidth imgHeight right bott|
11
793044d4bc90 *** empty log message ***
claus
parents: 9
diff changeset
   362
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   363
    image notNil ifTrue:[
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   364
        self generateMagnifiedImage.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   365
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   366
        shownImage := magnifiedImage ? image.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   367
        imgWidth := shownImage width.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   368
        imgHeight := shownImage height.
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   369
414
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   370
        adjust == #center ifTrue:[
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   371
            xI := (width - (margin * 2) - imgWidth) // 2.
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   372
            yI := (height - (margin * 2) - imgHeight) // 2.
414
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   373
        ] ifFalse:[
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   374
            xI := yI := margin
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   375
        ].
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   376
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   377
        ((depth := shownImage depth) == 1) ifTrue:[
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   378
            self paint:(shownImage colorFromValue:1)
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   379
                    on:(shownImage colorFromValue:0).
1510
fd0cd6065dc6 catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents: 1327
diff changeset
   380
        ].
1071
981c97fe54de generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents: 677
diff changeset
   381
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   382
        tileMode == true ifTrue:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   383
            (depth == 1
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   384
            and:[image mask isNil]) ifFalse:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   385
                self clearRectangleX:x y:y width:w height:h.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   386
                0 to:y+h by:tileOffset y do:[:oY |
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   387
                    0 to:x+w by:tileOffset x do:[:oX |
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   388
                        self displayForm:image x:oX y:oY 
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   389
                    ]
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   390
                ].
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   391
            ] ifTrue:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   392
                0 to:y+h by:tileOffset y do:[:oY |
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   393
                    0 to:x+w by:tileOffset x do:[:oX |
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   394
                        self displayOpaqueForm:image x:oX y:oY 
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   395
                    ]
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   396
                ].
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   397
            ].
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   398
        ] ifFalse:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   399
            (depth == 1
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   400
            and:[shownImage mask isNil]) ifFalse:[
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   401
                self clearRectangleX:x y:y width:w height:h.
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   402
                self displayForm:shownImage x:xI y:yI 
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   403
            ] ifTrue:[
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   404
                self displayOpaqueForm:shownImage x:xI y:yI 
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   405
            ].
430
574a94732ece checkin from browser
Claus Gittinger <cg@exept.de>
parents: 414
diff changeset
   406
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   407
            "/ right of image ?
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   408
            right := x + w - 1.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   409
            right > (xI + imgWidth) ifTrue:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   410
                self clearRectangleX:(xI + imgWidth)
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   411
                                   y:y
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   412
                               width:(right - imgWidth - xI)
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   413
                              height:h  
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   414
            ].
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   415
            "/ below of image ?
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   416
            bott := y + h - 1.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   417
            bott > (yI + imgHeight) ifTrue:[
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   418
                self clearRectangleX:margin
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   419
                                   y:(yI + imgHeight)
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   420
                               width:w
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   421
                              height:(bott - imgHeight - yI)  
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   422
            ].
430
574a94732ece checkin from browser
Claus Gittinger <cg@exept.de>
parents: 414
diff changeset
   423
        ].
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   424
    ]
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   425
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   426
    "Created: / 11.7.1996 / 21:02:12 / cg"
1071
981c97fe54de generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents: 677
diff changeset
   427
    "Modified: / 12.8.1998 / 14:02:28 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   428
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   429
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   430
!ImageView methodsFor:'event handling'!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   431
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   432
sizeChanged:how
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   433
    magnifiedImage notNil ifTrue:[
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   434
        DoNotMagnifyQuery query ifFalse:[
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   435
            magnifiedImage := nil.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   436
            self generateMagnifiedImage.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   437
            self clear.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   438
            self invalidate.
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   439
        ]
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   440
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   441
    super sizeChanged:how
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   442
! !
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   443
1327
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   444
!ImageView methodsFor:'initialize / release'!
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   445
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   446
destroy
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   447
    image := nil.
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   448
    super destroy.
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   449
! !
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   450
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   451
!ImageView methodsFor:'queries'!
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   452
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   453
heightOfContents
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   454
    "return the images height - scrollbar needs this info"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   455
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   456
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   457
    ^ (magnifiedImage ? image) height
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   458
!
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   459
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   460
widthOfContents
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   461
    "return the images width - scrollbar needs this info"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   462
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   463
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   464
    ^ (magnifiedImage ? image) width
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   465
! !
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   466
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
   467
!ImageView class methodsFor:'documentation'!
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   468
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   469
version
2402
4425948481b4 category change
Claus Gittinger <cg@exept.de>
parents: 2375
diff changeset
   470
    ^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.53 2002-12-10 10:46:23 cg Exp $'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   471
! !
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   472
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   473
ImageView initialize!