ImageView.st
author Claus Gittinger <cg@exept.de>
Tue, 24 Feb 2004 11:35:43 +0100
changeset 2650 f41da3ee2446
parent 2544 bcae3dbd3ccd
child 2659 3af857eb52fb
permissions -rw-r--r--
*** empty log message ***
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
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    44
	ImageView openOn:anImageFileName
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    45
    or:
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    46
	ImageView openOnImage:anImage
47
claus
parents: 46
diff changeset
    47
    or:
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    52
	ImageView openOn:'bitmaps/gifImages/garfield.gif'
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    53
	ImageView openOn:'bitmaps/SBrowser.xbm'
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    54
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    55
	ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif')
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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:     
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    59
	controls how images are displayed;
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    60
	can be one of:
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    61
	    #topLeft    - image is displayed as usual
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    62
	    #center     - image is shown centered
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    63
	    #fitBig     - big images are shrunk to make it fit the view
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    64
	    #fitSmall   - small images are magnified to make it fit the view,
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    65
	    #fit        - all images are magnified to fit the view
2158
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:]
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
    68
	Claus Gittinger
296
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:]
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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
2511
10537dc4e961 category change
Claus Gittinger <cg@exept.de>
parents: 2501
diff changeset
    81
!ImageView class methodsFor:'queries-plugin'!
1694
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:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   100
	fn exists ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   101
	    e := 'unknown/unsupported image format'
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   102
	] ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   103
	    e := 'no such image'.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   104
	].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   105
	self warn:e.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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'
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   116
     ImageView openOn:'bitmaps/xpmBitmaps/misc_icons/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:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   128
	lbl := 'an Image'
47
claus
parents: 46
diff changeset
   129
    ] ifFalse:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   139
	imageView image:anImage.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   140
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   141
	"define an icon view showing a little version of image.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   142
	 Since some window managers cannot handle this correctly (twm),
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   143
	 this is only done when running on an IRIS"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   144
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   145
	(true "(OperatingSystem getSystemType = 'iris')" 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   146
	and:[StyleSheet name == #iris]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   147
	    iconView := ImageView new.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   148
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   149
	    "for now; should somehow get access to preferred iconview extent ..."
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   150
	    icnW := 86.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   151
	    icnH := 68.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   152
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   153
	    imgWidth := anImage width.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   154
	    imgHeight := anImage height.
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   155
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   156
	    ((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   157
		iconView extent:(imgWidth @ imgHeight).
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   158
		mag := 1 @ 1
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   159
	    ] ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   160
		magX := icnW / imgWidth.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   161
		magY := icnH / imgHeight.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   162
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   163
		"scale image"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   164
"
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   165
		mag := magX @ magY.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   166
"
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   167
		"preserve ratio"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   168
" 
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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
" "
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   175
		iconView extent:((anImage width @ anImage height) * mag) rounded.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   176
	    ].
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   177
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   178
	    top iconView:iconView.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   185
	top windowGroup addView:iconView.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   186
	[ 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   187
	    iconView image:(anImage magnifiedBy:mag).
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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:
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   205
	    #topLeft    - image is displayed as usual
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   206
	    #center     - image is shown centered
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   207
	    #fitBig     - big images are shrunk to make it fit the view
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   208
	    #fitSmall   - small images are magnified to make it fit the view,
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   209
	    #fit        - all images are magnified to fit the view
2375
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:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   213
	adjust := layoutSymbol.
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   214
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   215
	magnifiedImage := nil.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   216
	self shown ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   217
	    image notNil ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   218
		self generateMagnifiedImage.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   219
		self clear.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   220
		self scrollToTopLeft.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   221
		self invalidate.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   222
		self contentsChanged.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   223
	    ]
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
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
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   237
    self image:anImage scroll:true
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   238
!
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   239
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   240
image:anImage scroll:doScroll
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   241
    "set the image - show a wait cursor, since image dithering may take a while"
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   242
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   243
    self setImage:anImage scroll:doScroll
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   244
!
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   245
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   246
setImage:anImage
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   247
    "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
   248
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   249
    |oldSize newSize|
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   250
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   251
    oldSize := image ifNil:[0@0] ifNotNil:[image extent].
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   252
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   253
    image := anImage.
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   254
    magnifiedImage := nil.
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   255
    self generateMagnifiedImage.
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   256
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   257
    newSize := image ifNil:[0@0] ifNotNil:[(magnifiedImage ? image) extent].
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   258
    self scrollToTopLeft.
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   259
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   260
    oldSize ~= newSize ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   261
	"/ avoid endless loop in case of a resize happening due
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   262
	"/ to scrollBar visibility changes.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   263
	"/ that QuerySignal suppresses another magnification in sizeChanged: 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   264
	DoNotMagnifyQuery answer:true
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   265
	do:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   266
	    self contentsChanged.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   267
	]
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   268
    ].
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
    shown ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   271
	self clear.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   272
	self invalidate
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   273
    ].
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   274
    self changed:#image.
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   275
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   276
    "Modified: / 10.2.2000 / 23:25:51 / cg"
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   277
!
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   278
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   279
setImage:anImage scroll:doScroll
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   280
    "set the image - show a wait cursor, since image dithering may take a while"
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   281
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   282
    |oldSize newSize|
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   283
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   284
    oldSize := image ifNil:[0@0] ifNotNil:[image extent].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   285
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   286
    image := anImage.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   287
    magnifiedImage := nil.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   288
    self generateMagnifiedImage.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   289
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   290
    newSize := image ifNil:[0@0] ifNotNil:[(magnifiedImage ? image) extent].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   291
    doScroll ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   292
	self scrollToTopLeft.
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   293
    ].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   294
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   295
    oldSize ~= newSize ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   296
	"/ avoid endless loop in case of a resize happening due
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   297
	"/ to scrollBar visibility changes.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   298
	"/ that QuerySignal suppresses another magnification in sizeChanged: 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   299
	DoNotMagnifyQuery answer:true
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   300
	do:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   301
	    self contentsChanged.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   302
	]
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   303
    ].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   304
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   305
    shown ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   306
	self clear.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   307
	self invalidate
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   308
    ].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   309
    self changed:#image.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   310
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   311
    "Modified: / 10.2.2000 / 23:25:51 / cg"
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   312
!
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   313
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   314
tileMode:aBoolean tileOffset:aPoint
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   315
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   316
    tileMode := aBoolean.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   317
    tileOffset := aPoint
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   318
! !
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   319
2404
2b7591c982ac category change
Claus Gittinger <cg@exept.de>
parents: 2402
diff changeset
   320
!ImageView methodsFor:'accessing-channels'!
1510
fd0cd6065dc6 catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents: 1327
diff changeset
   321
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   322
imageChannel
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   323
    imageChannel isNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   324
	imageChannel := ValueHolder new.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   325
	imageChannel addDependent:self.
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   326
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   327
    ^ imageChannel
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   328
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   329
    "Created: / 11.2.2000 / 00:34:44 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   330
!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   331
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   332
imageChannel:aValueHolder
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   333
    imageChannel notNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   334
	imageChannel removeDependent:self.
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   335
    ].
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   336
    imageChannel := aValueHolder.
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   337
    imageChannel notNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   338
	imageChannel addDependent:self.
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   339
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   340
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   341
    "Created: / 11.2.2000 / 00:34:33 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   342
! !
1135
75101bf02c5b send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   343
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   344
!ImageView methodsFor:'change & update'!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   345
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   346
update:something with:aParameter from:changedObject
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   347
    something == imageChannel ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   348
	self image:(imageChannel value).
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   349
	^ self
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   350
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   351
    super update:something with:aParameter from:changedObject
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   352
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   353
    "Created: / 11.2.2000 / 00:37:02 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   354
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   355
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   356
!ImageView methodsFor:'drawing'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   357
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   358
generateMagnifiedImage
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   359
    |doFit innerWidth innerHeight imgWidth imgHeight|
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   360
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   361
    magnifiedImage notNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   362
	^ self
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   363
    ].
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   364
    image isNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   365
	^ self
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   366
    ].
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   367
        
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   368
    doFit := false.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   369
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   370
    innerWidth := self innerWidth.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   371
    innerHeight := self innerHeight.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   372
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   373
    imgWidth := image width.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   374
    imgHeight := image height.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   375
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   376
    tileMode ~~ true ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   377
	((imgWidth > innerWidth)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   378
	or:[imgHeight > innerHeight]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   379
	    ((adjust == #fit) or:[adjust == #fitBig]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   380
		doFit := true
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   381
	    ].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   382
	] ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   383
	    ((imgWidth < innerWidth)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   384
	    or:[imgHeight < innerHeight]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   385
		((adjust == #fit) or:[adjust == #fitSmall]) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   386
		    doFit := true
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   387
		].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   388
	    ]
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   389
	].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   390
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   391
    doFit ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   392
	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
   393
"/        self contentsChanged.
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   394
    ] ifFalse:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   395
	magnifiedImage := image
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   396
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   397
!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   398
210
1a3b06d71a03 faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents: 207
diff changeset
   399
redrawX:x y:y width:w height:h
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   400
    |xI yI depth shownImage imgWidth imgHeight right bott|
11
793044d4bc90 *** empty log message ***
claus
parents: 9
diff changeset
   401
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   402
    image notNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   403
	self generateMagnifiedImage.
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   404
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   405
	shownImage := magnifiedImage ? image.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   406
	imgWidth := shownImage width.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   407
	imgHeight := shownImage height.
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   408
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   409
	adjust == #center ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   410
	    xI := (width - (margin * 2) - imgWidth) // 2.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   411
	    yI := (height - (margin * 2) - imgHeight) // 2.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   412
	] ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   413
	    xI := yI := margin
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   414
	].
414
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   415
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   416
	((depth := shownImage depth) == 1) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   417
	    self paint:(shownImage colorFromValue:1)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   418
		    on:(shownImage colorFromValue:0).
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   419
	].
1071
981c97fe54de generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents: 677
diff changeset
   420
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   421
	tileMode == true ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   422
	    (depth == 1
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   423
	    and:[image mask isNil]) ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   424
		self clearRectangleX:x y:y width:w height:h.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   425
		0 to:y+h by:tileOffset y do:[:oY |
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   426
		    0 to:x+w by:tileOffset x do:[:oX |
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   427
			self displayForm:image x:oX y:oY 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   428
		    ]
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   429
		].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   430
	    ] ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   431
		0 to:y+h by:tileOffset y do:[:oY |
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   432
		    0 to:x+w by:tileOffset x do:[:oX |
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   433
			self displayOpaqueForm:image x:oX y:oY 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   434
		    ]
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   435
		].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   436
	    ].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   437
	] ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   438
	    (depth == 1
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   439
	    and:[shownImage mask isNil]) ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   440
		self clearRectangleX:x y:y width:w height:h.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   441
		self displayForm:shownImage x:xI y:yI 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   442
	    ] ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   443
		self displayOpaqueForm:shownImage x:xI y:yI 
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   444
	    ].
430
574a94732ece checkin from browser
Claus Gittinger <cg@exept.de>
parents: 414
diff changeset
   445
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   446
	    "/ right of image ?
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   447
	    right := x + w - 1.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   448
	    right > (xI + imgWidth) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   449
		self clearRectangleX:(xI + imgWidth)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   450
				   y:y
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   451
			       width:(right - imgWidth - xI)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   452
			      height:h  
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   453
	    ].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   454
	    "/ below of image ?
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   455
	    bott := y + h - 1.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   456
	    bott > (yI + imgHeight) ifTrue:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   457
		self clearRectangleX:margin
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   458
				   y:(yI + imgHeight)
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   459
			       width:w
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   460
			      height:(bott - imgHeight - yI)  
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   461
	    ].
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   462
	].
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   463
    ]
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   464
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   465
    "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
   466
    "Modified: / 12.8.1998 / 14:02:28 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   467
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   468
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   469
!ImageView methodsFor:'event handling'!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   470
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   471
sizeChanged:how
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   472
    magnifiedImage notNil ifTrue:[
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   473
	DoNotMagnifyQuery query ifFalse:[
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   474
	    magnifiedImage := nil.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   475
	    self generateMagnifiedImage.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   476
	    self clear.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   477
	    self invalidate.
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   478
	]
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   479
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   480
    super sizeChanged:how
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   481
! !
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   482
2501
832cbac295b8 method category rename
Claus Gittinger <cg@exept.de>
parents: 2404
diff changeset
   483
!ImageView methodsFor:'initialization & release'!
1327
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   484
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   485
destroy
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   486
    image := nil.
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   487
    super destroy.
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   488
! !
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   489
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   490
!ImageView methodsFor:'queries'!
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   491
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   492
heightOfContents
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   493
    "return the images height - scrollbar needs this info"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   494
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   495
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   496
    ^ (magnifiedImage ? image) height
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   497
!
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   498
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   499
widthOfContents
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   500
    "return the images width - scrollbar needs this info"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   501
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   502
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   503
    ^ (magnifiedImage ? image) width
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   504
! !
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   505
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
   506
!ImageView class methodsFor:'documentation'!
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   507
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   508
version
2650
f41da3ee2446 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2544
diff changeset
   509
    ^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.58 2004-02-24 10:35:43 cg Exp $'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   510
! !
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   511
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   512
ImageView initialize!