ImageView.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 07 Feb 2019 12:16:15 +0000
branchjv
changeset 6065 e880a0b1320b
parent 5430 b073297e25ae
child 5467 fef61bfd9fad
permissions -rw-r--r--
Fix copy & paste in `TerminalView` Fix various copy-paste bugs and weirdnesses, namly: * preserve new lines when copying multi-line contents from terminal view. * preserve cursor position when selecting text both via mouse and via double-click.
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
"
1763
7d6d64622ee4 change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents: 1694
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
7d6d64622ee4 change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents: 1694
diff changeset
    13
4732
b5db158865ca class: ImageView
Stefan Vogel <sv@exept.de>
parents: 4561
diff changeset
    14
"{ NameSpace: Smalltalk }"
b5db158865ca class: ImageView
Stefan Vogel <sv@exept.de>
parents: 4561
diff changeset
    15
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    16
View subclass:#ImageView
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
    17
	instanceVariableNames:'image magnifiedImage adjust magnificationFactor tileMode
5402
ac1a78db1d84 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
    18
		tileOffset lastMousePoint adjustHolder'
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    19
	classVariableNames:'DoNotMagnifyQuery'
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
    20
	poolDictionaries:''
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
    21
	category:'Views-Misc'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    22
!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    23
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
    24
!ImageView class methodsFor:'documentation'!
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    25
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    26
copyright
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    27
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    28
 COPYRIGHT (c) 1993 by Claus Gittinger
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    29
	      All Rights Reserved
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    30
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    31
 This software is furnished under a license and may be used
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    32
 only in accordance with the terms of that license and with the
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    34
 be provided or otherwise made available to, or used by, any
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    35
 other person.  No title to or ownership of the software is
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    36
 hereby transferred.
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    37
"
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    38
!
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    39
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    40
documentation
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    41
"
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    42
    This View knows how to display a (bitmap-)image (or form).
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    43
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    44
    You can display an image with:
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    45
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    46
        ImageView openOn:anImageFileName
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    47
    or:
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    48
        ImageView openOnImage:anImage
47
claus
parents: 46
diff changeset
    49
    or:
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    50
        ImageView new image:anImage
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    51
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    52
    i.e.
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    53
2748
25e0b6b5b411 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
    54
        ImageView openOn:'../../goodies/bitmaps/gifImages/garfield.gif'
25e0b6b5b411 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
    55
        ImageView openOn:'../../goodies/bitmaps/SBrowser.xbm'
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    56
2748
25e0b6b5b411 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
    57
        ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif')
25e0b6b5b411 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2747
diff changeset
    58
        ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/SBrowser.xbm')
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    59
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
    60
    adjust:
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    61
        controls how images are displayed;
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    62
        can be one of:
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    63
            #topLeft    - image is displayed as usual
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    64
            #center     - image is shown centered
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    65
            #fitBig     - big images are shrunk to make it fit the view
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    66
            #fitSmall   - small images are magnified to make it fit the view,
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    67
            #fit        - all images are magnified to fit the view
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
    68
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    69
    [author:]
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    70
        Claus Gittinger
296
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    71
f1007170201e see also
Claus Gittinger <cg@exept.de>
parents: 269
diff changeset
    72
    [see also:]
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
    73
        Image Form
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    74
"
3683
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    75
!
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    76
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    77
examples
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    78
"
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    79
    |top imgView scrView|
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    80
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    81
    top := StandardSystemView new.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    82
    top extent:300@300.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    83
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    84
    imgView := ImageView new.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    85
    imgView image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif').
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    86
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    87
    scrView := HVScrollableView forView:imgView.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    88
    scrView origin:0@0 corner:1.0@1.0.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    89
    top add:scrView.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    90
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    91
    top open.
80466def0fc4 comment
Claus Gittinger <cg@exept.de>
parents: 3659
diff changeset
    92
"
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    93
! !
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
    94
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    95
!ImageView class methodsFor:'initialization'!
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    96
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
    97
initialize
4912
6630a4464c2f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4732
diff changeset
    98
    DoNotMagnifyQuery isNil ifTrue:[
6630a4464c2f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4732
diff changeset
    99
        DoNotMagnifyQuery := QuerySignal new defaultAnswer:false.
6630a4464c2f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4732
diff changeset
   100
    ].
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   101
! !
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   102
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   103
!ImageView class methodsFor:'menu specs'!
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   104
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   105
middleButtonMenu
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   106
    "This resource specification was automatically generated
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   107
     by the MenuEditor of ST/X."
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   108
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   109
    "Do not manually edit this!! If it is corrupted,
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   110
     the MenuEditor may not be able to read the specification."
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   111
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   112
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   113
    "
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   114
     MenuEditor new openOnClass:ImageView andSelector:#middleButtonMenu
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   115
     (Menu new fromLiteralArrayEncoding:(ImageView middleButtonMenu)) startUp
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   116
    "
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   117
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   118
    <resource: #menu>
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   119
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   120
    ^ 
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   121
     #(Menu
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   122
        (
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   123
         (MenuItem
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   124
            label: 'Size to Fit'
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   125
            choice: adjustHolder
5402
ac1a78db1d84 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   126
            choiceValue: fitBig
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   127
          )
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   128
         (MenuItem
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   129
            label: 'Original Size'
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   130
            choice: adjustHolder
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   131
            choiceValue: #topLeft
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   132
          )
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   133
         )
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   134
        nil
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   135
        nil
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   136
      )
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   137
! !
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   138
2511
10537dc4e961 category change
Claus Gittinger <cg@exept.de>
parents: 2501
diff changeset
   139
!ImageView class methodsFor:'queries-plugin'!
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   140
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   141
aspectSelectors
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   142
    ^ #( imageChannel )
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   143
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   144
    "Created: / 11.2.2000 / 00:37:33 / cg"
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   145
! !
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   146
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
   147
!ImageView class methodsFor:'startup'!
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   148
4192
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   149
openOn:anImageOrFileName
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   150
    "startup an image viewer on an image read from a file"
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   151
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   152
    anImageOrFileName isImage ifTrue:[
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   153
        ^ self openOnImage:anImageOrFileName
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   154
    ].
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   155
    ^ self openOnFile:anImageOrFileName
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   156
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   157
    "
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   158
     ImageView openOn:'bitmaps/gifImages/garfield.gif'
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   159
     ImageView openOn:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   160
    "
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   161
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   162
    "Modified: / 31.10.1997 / 16:17:52 / cg"
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   163
!
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   164
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   165
openOnFile:aFileName
47
claus
parents: 46
diff changeset
   166
    "startup an image viewer on an image read from a file"
claus
parents: 46
diff changeset
   167
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   168
    |fn imageView img e|
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   169
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   170
    fn := aFileName asFilename.
47
claus
parents: 46
diff changeset
   171
1970
b7cf91b688d1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
   172
    img := Image fromFile:fn.
47
claus
parents: 46
diff changeset
   173
    img isNil ifTrue:[
2747
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   174
        fn exists ifTrue:[
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   175
            e := 'Unknown or unsupported image format.'
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   176
        ] ifFalse:[
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   177
            e := 'No such image file.'.
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   178
        ].
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   179
        self warn:(self resources string:e).
818a513a64c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2659
diff changeset
   180
        ^ nil
47
claus
parents: 46
diff changeset
   181
    ].
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   182
    imageView := self openOnImage:img.
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   183
    imageView topView label:(fn pathName) iconLabel:(fn baseName).
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   184
    ^ imageView
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   185
47
claus
parents: 46
diff changeset
   186
    "
4558
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   187
     ImageView openOnFile:'../../goodies/bitmaps/gifImages/garfield.gif'
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   188
     ImageView openOnFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'
47
claus
parents: 46
diff changeset
   189
    "
348
58d52a823cca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 324
diff changeset
   190
599
66c4da764a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   191
    "Modified: / 31.10.1997 / 16:17:52 / cg"
47
claus
parents: 46
diff changeset
   192
!
claus
parents: 46
diff changeset
   193
claus
parents: 46
diff changeset
   194
openOnImage:anImage
claus
parents: 46
diff changeset
   195
    "startup an image viewer on an image"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   196
4558
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   197
    |lbl|
47
claus
parents: 46
diff changeset
   198
claus
parents: 46
diff changeset
   199
    anImage isImage ifTrue:[
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   200
        lbl := anImage fileName ? 'an Image'
47
claus
parents: 46
diff changeset
   201
    ] ifFalse:[
3904
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   202
        anImage isNil ifTrue:[
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   203
            lbl := 'an Image'
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   204
        ] ifFalse:[
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   205
            lbl := 'a Form'
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   206
        ]
47
claus
parents: 46
diff changeset
   207
    ].
4558
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   208
    ^ self openOnImage:anImage title:lbl
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   209
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   210
    "
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   211
     ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') title:'garfield'
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   212
     ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') title:'old browser icon'
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   213
    "
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   214
!
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   215
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   216
openOnImage:anImage title:aString
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   217
    "startup an image viewer on an image"
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   218
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   219
    |top v imageView icnW icnH iconView magX magY mag imgWidth imgHeight|
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   220
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   221
    top := StandardSystemView label:aString.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   222
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   223
    v := HVScrollableView for:self in:top.
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   224
    v origin:0@0 extent:1.0@1.0.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   225
    imageView := v scrolledView.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   226
47
claus
parents: 46
diff changeset
   227
    anImage notNil ifTrue:[
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   228
        imageView image:anImage.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   229
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   230
        "define an icon view showing a little version of image.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   231
         Since some window managers cannot handle this correctly (twm),
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   232
         this is only done when running on an IRIS"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   233
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   234
        (true "(OperatingSystem getSystemType = 'iris')"
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   235
        and:[StyleSheet name == #iris]) ifTrue:[
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   236
            iconView := ImageView new.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   237
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   238
            "for now; should somehow get access to preferred iconview extent ..."
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   239
            icnW := 86.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   240
            icnH := 68.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   241
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   242
            imgWidth := anImage width.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   243
            imgHeight := anImage height.
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   244
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   245
            ((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   246
                iconView extent:(imgWidth @ imgHeight).
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   247
                mag := 1 @ 1
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   248
            ] ifFalse:[
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   249
                magX := icnW / imgWidth.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   250
                magY := icnH / imgHeight.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   251
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   252
                "scale image"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   253
"
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   254
                mag := magX @ magY.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   255
"
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   256
                "preserve ratio"
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   257
"
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   258
                mag := (magX min:magY) asPoint.
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   259
"
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   260
" "
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   261
                mag := (magX max:magY) asPoint.
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   262
" "
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   263
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   264
                iconView extent:((anImage width @ anImage height) * mag) rounded.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   265
            ].
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   266
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   267
            top iconView:iconView.
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   268
        ].
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   269
    ].
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   270
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   271
    top open.
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   272
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   273
    iconView notNil ifTrue:[
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   274
        top windowGroup addView:iconView.
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   275
        [
3733
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   276
            iconView image:(anImage magnifiedBy:mag).
f7c401c2b55c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3726
diff changeset
   277
        ] forkAt:4
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
   278
    ].
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   279
    ^ imageView
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   280
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   281
    "
4558
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   282
     ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') title:'garfield'
699f6a043e51 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
   283
     ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm')
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   284
    "
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 348
diff changeset
   285
3904
6e93f6b54377 changed: #openOnImage:
Claus Gittinger <cg@exept.de>
parents: 3884
diff changeset
   286
    "Modified: / 01-06-2010 / 18:31:14 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   287
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   288
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   289
!ImageView methodsFor:'accessing'!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   290
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   291
adjust
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   292
    "get the adjust (how the image is displayed);
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   293
     currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   294
            #topLeft    - image is displayed as usual
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   295
            #center     - image is shown centered
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   296
            #fitBig     - big images are shrunk to make it fit the view
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   297
            #fitSmall   - small images are magnified to make it fit the view,
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   298
            #fit        - all images are magnified to fit the view
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   299
    "
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   300
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   301
    ^ adjust ? #topLeft
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   302
!
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   303
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   304
adjust:layoutSymbol
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   305
    "set the adjust (how the image is displayed);
2375
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   306
     currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
2659
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   307
            #topLeft    - image is displayed as usual
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   308
            #center     - image is shown centered
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   309
            #fitBig     - big images are shrunk to make it fit the view
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   310
            #fitSmall   - small images are magnified to make it fit the view,
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   311
            #fit        - all images are magnified to fit the view
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   312
            #topLeftNoZoom    - image is displayed as usual, and magnification is reset
2375
e0c7852263e4 comment
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   313
    "
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   314
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   315
    |layoutUsed|
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   316
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   317
    layoutUsed := layoutSymbol.
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   318
    layoutUsed == #topLeftNoZoom ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   319
        layoutUsed := #topLeft
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   320
    ].
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   321
    self magnificationFactor ~= 1 ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   322
        self magnificationFactor:1
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   323
    ].
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   324
    
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   325
    adjust ~= layoutUsed ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   326
        adjust := layoutUsed.
5402
ac1a78db1d84 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   327
        adjustHolder notNil ifTrue:[
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   328
            adjustHolder value:layoutUsed withoutNotifying:self
5402
ac1a78db1d84 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   329
        ].    
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   330
2659
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   331
        magnifiedImage := nil.
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   332
        shown ifTrue:[
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   333
            image notNil ifTrue:[
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   334
                self magnificationFactor ~= 1 ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   335
                    self generateMagnifiedImage.
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   336
                ].    
2659
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   337
                self clear.
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   338
                self scrollToTopLeft.
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   339
                self invalidate.
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   340
                self contentsChanged.
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   341
            ]
3af857eb52fb invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents: 2650
diff changeset
   342
        ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   343
    ].
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   344
!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   345
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   346
adjustHolder
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   347
    "get a valeHolder for the adjust (how the image is displayed);
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   348
     currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   349
            #topLeft    - image is displayed as usual
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   350
            #center     - image is shown centered
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   351
            #fitBig     - big images are shrunk to make it fit the view
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   352
            #fitSmall   - small images are magnified to make it fit the view,
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   353
            #fit        - all images are magnified to fit the view
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   354
    "
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   355
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   356
    adjustHolder isNil ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   357
        adjustHolder := self adjust asValue.
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   358
        adjustHolder 
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   359
            onChangeEvaluate:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   360
                self adjust:(adjustHolder value).
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   361
            ]
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   362
    ].        
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   363
    ^ adjustHolder
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   364
!
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   365
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   366
image
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   367
    "return the image"
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   368
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   369
    ^ image
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   370
!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   371
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   372
image:anImage
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   373
    "set the image scrolls as set by adjust
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   374
     - may show a wait cursor, if image dithering may take a while"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   375
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   376
    self image:anImage scroll:true
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   377
!
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   378
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   379
image:anImage scroll:doScroll
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   380
    "set the image possibly scroll as set by adjust
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   381
     - may show a wait cursor, if image dithering may take a while"
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   382
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   383
    self setImage:anImage scroll:doScroll
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   384
!
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   385
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   386
image:anImage scroll:doScroll invalidate:doInvalidate
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   387
    "set the image possibly scroll as set by adjust
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   388
     - may show a wait cursor, if image dithering may take a while"
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   389
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   390
    self setImage:anImage scroll:doScroll invalidate:doInvalidate
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   391
!
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   392
3408
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   393
magnification
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   394
    magnifiedImage isNil ifTrue:[^ 1@1].
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   395
    ^ magnifiedImage extent / image extent
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   396
!
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   397
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   398
magnificationFactor
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   399
    ^ magnificationFactor ? 1
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   400
!
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   401
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   402
magnificationFactor:aNumber
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   403
    magnificationFactor ~= aNumber ifTrue:[
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   404
        magnificationFactor := aNumber.
5403
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   405
        "/    magnificationFactor fractionPart < 0.1 ifTrue:[
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   406
        "/        "magnifying by integer factor is faster"
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   407
        "/        magnificationFactor := magnificationFactor truncated.
c261a6c25100 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   408
        "/    ].
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   409
        magnifiedImage := nil.
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   410
        magnificationFactor = 1 ifTrue:[
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   411
            self contentsChanged.
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   412
        ].    
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   413
        self invalidate.
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   414
    ].
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   415
!
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   416
4066
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   417
model:aValueHolder
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   418
    super model:aValueHolder.
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   419
    self updateFromModel.
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   420
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   421
    "Created: / 25-07-2011 / 15:32:10 / cg"
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   422
!
a2fe2f6cf0c7 added: #model:
Claus Gittinger <cg@exept.de>
parents: 4031
diff changeset
   423
1993
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   424
setImage:anImage
e7c12938af98 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
   425
    "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
   426
4966
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   427
    self setImage:anImage scroll:true invalidate:true
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   428
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   429
    "Modified: / 10.2.2000 / 23:25:51 / cg"
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   430
!
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   431
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   432
setImage:anImage scroll:doScroll
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   433
    "set the image - may show a wait cursor, if image dithering may take a while"
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   434
3710
162a45c5ce34 invalidate when image changes
Claus Gittinger <cg@exept.de>
parents: 3705
diff changeset
   435
    self setImage:anImage scroll:doScroll invalidate:true
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   436
!
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   437
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   438
setImage:anImage scroll:doScroll invalidate:doInvalidate
5398
3c4304d0d819 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5387
diff changeset
   439
    "set the image - may show a wait cursor, if image dithering may take a while"
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   440
4966
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   441
    |oldSize newSize newImageIsSmaller|
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   442
5430
b073297e25ae #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5404
diff changeset
   443
    self assert:(anImage isImage or:[anImage isNil]).
b073297e25ae #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5404
diff changeset
   444
    
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   445
    oldSize := image isNil ifTrue:[0@0] ifFalse:[image extent].
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   446
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   447
    image := anImage.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   448
    magnifiedImage := nil.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   449
    self generateMagnifiedImage.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   450
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   451
    newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent].
4966
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   452
    newImageIsSmaller := ((oldSize x > newSize x) or:[oldSize y > newSize y]).
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   453
5227
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   454
    (newImageIsSmaller and:[ doInvalidate ]) ifTrue:[ self invalidate ].
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   455
    doScroll ifTrue:[ self scrollToTopLeft ].
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   456
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   457
    oldSize ~= newSize ifTrue:[
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   458
        "/ avoid endless loop in case of a resize happening due
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   459
        "/ to scrollBar visibility changes.
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   460
        "/ that QuerySignal suppresses another magnification in sizeChanged:
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   461
        DoNotMagnifyQuery
4966
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   462
            answer:true
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   463
            do:[
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   464
                self contentsChanged.
fd25317b66de #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4912
diff changeset
   465
            ]
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   466
    ].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   467
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   468
    (shown and:[doInvalidate]) ifTrue:[
5268
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   469
        "/ (anImage isNil "or:[newImageIsSmaller]") ifTrue:[
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   470
        "/     self clear.
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   471
        "/ ].
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   472
        self invalidate
2544
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   473
    ].
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   474
    self changed:#image.
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   475
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   476
    "Modified: / 10.2.2000 / 23:25:51 / cg"
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   477
!
bcae3dbd3ccd do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents: 2511
diff changeset
   478
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   479
sizeToFit:aBoolean
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   480
    aBoolean ifTrue:[
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   481
        self adjust:#fitBig
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   482
    ] ifFalse:[
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   483
        self adjust:nil.
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   484
    ]
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   485
!
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   486
2089
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   487
tileMode:aBoolean tileOffset:aPoint
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   488
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   489
    tileMode := aBoolean.
8c0aed9152c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
   490
    tileOffset := aPoint
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   491
! !
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   492
2404
2b7591c982ac category change
Claus Gittinger <cg@exept.de>
parents: 2402
diff changeset
   493
!ImageView methodsFor:'accessing-channels'!
1510
fd0cd6065dc6 catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents: 1327
diff changeset
   494
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   495
imageChannel
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   496
    ^ self model
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   497
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   498
    "Modified: / 31-03-2011 / 10:45:58 / cg"
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   499
!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   500
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   501
imageChannel:aValueHolder
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   502
    self model:aValueHolder.
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   503
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   504
    "Created: / 11-02-2000 / 00:34:33 / cg"
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   505
    "Modified: / 31-03-2011 / 10:46:07 / cg"
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   506
! !
1135
75101bf02c5b send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   507
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   508
!ImageView methodsFor:'change & update'!
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   509
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   510
update:something with:aParameter from:changedObject
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   511
    changedObject == model ifTrue:[
4561
5e11aa6a92d8 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4558
diff changeset
   512
        self updateFromModel.
2786
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   513
        ^ self
1694
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   514
    ].
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   515
    super update:something with:aParameter from:changedObject
668020398028 de-uglified
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   516
4031
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   517
    "Created: / 11-02-2000 / 00:37:02 / cg"
4213ffa8fc14 class definition
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   518
    "Modified: / 31-03-2011 / 10:46:16 / cg"
2786
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   519
!
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   520
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   521
updateFromModel
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   522
    "the model changes, set my image"
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   523
d3b6171aec01 React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents: 2748
diff changeset
   524
    self image:model value.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   525
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   526
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   527
!ImageView methodsFor:'drawing'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   528
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   529
generateMagnifiedImage
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   530
    |doFit innerWidth innerHeight imgWidth imgHeight|
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   531
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   532
    magnifiedImage notNil ifTrue:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   533
        ^ self
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   534
    ].
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   535
    image isNil ifTrue:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   536
        ^ self
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   537
    ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   538
    doFit := false.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   539
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   540
    innerWidth := self innerWidth.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   541
    innerHeight := self innerHeight.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   542
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   543
    imgWidth := image width.
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   544
    imgHeight := image height.
5430
b073297e25ae #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5404
diff changeset
   545
    
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   546
    tileMode ~~ true ifTrue:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   547
        ((imgWidth > innerWidth)
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   548
        or:[imgHeight > innerHeight]) ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   549
            ((adjust == #fit) or:[adjust == #fitBig]) ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   550
                doFit := true
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   551
            ].
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   552
        ] ifFalse:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   553
            ((imgWidth < innerWidth)
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   554
            or:[imgHeight < innerHeight]) ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   555
                ((adjust == #fit) or:[adjust == #fitSmall]) ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   556
                    doFit := true
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   557
                ].
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   558
            ]
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   559
        ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   560
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   561
    doFit ifTrue:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   562
        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
   563
"/        self contentsChanged.
2164
df689a29b5d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2160
diff changeset
   564
    ] ifFalse:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   565
        (magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   566
            magnifiedImage := image magnifiedBy:magnificationFactor.
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   567
        ] ifFalse:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   568
            magnifiedImage := image
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   569
        ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   570
    ].
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   571
    self contentsChanged.
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   572
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   573
    "Modified: / 06-05-2012 / 12:17:23 / cg"
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   574
!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   575
210
1a3b06d71a03 faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents: 207
diff changeset
   576
redrawX:x y:y width:w height:h
5227
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   577
    |xI yI depth shownImage imgWidth imgHeight right bott "rectRight rectBelow"|
11
793044d4bc90 *** empty log message ***
claus
parents: 9
diff changeset
   578
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   579
    image notNil ifTrue:[
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   580
        self generateMagnifiedImage.
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   581
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   582
        shownImage := magnifiedImage ? image.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   583
        imgWidth := shownImage width.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   584
        imgHeight := shownImage height.
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   585
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   586
        adjust == #center ifTrue:[
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   587
            xI := (width - (margin * 2) - imgWidth) // 2.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   588
            yI := (height - (margin * 2) - imgHeight) // 2.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   589
        ] ifFalse:[
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   590
            xI := yI := margin
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   591
        ].
414
0347d494cd61 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   592
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   593
        ((depth := shownImage depth) == 1) ifTrue:[
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   594
            self paint:(shownImage colorFromValue:1)
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   595
                    on:(shownImage colorFromValue:0).
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   596
        ].
1071
981c97fe54de generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents: 677
diff changeset
   597
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   598
        tileMode == true ifTrue:[
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   599
            (tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[
5022
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   600
                (false "depth ~~ 1"
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   601
                or:[shownImage mask notNil]) ifTrue:[
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   602
                    self clearRectangleX:x y:y width:w height:h.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   603
                    0 to:y+h by:tileOffset y do:[:oY |
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   604
                        0 to:x+w by:tileOffset x do:[:oX |
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   605
                            self displayForm:image x:oX y:oY
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   606
                        ]
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   607
                    ].
5022
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   608
                ] ifFalse:[
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   609
                    0 to:y+h by:tileOffset y do:[:oY |
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   610
                        0 to:x+w by:tileOffset x do:[:oX |
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   611
                            self displayOpaqueForm:image x:oX y:oY
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   612
                        ]
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   613
                    ].
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   614
                ].
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   615
            ]
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   616
        ] ifFalse:[
5227
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   617
            "/rectRight := (shownImage width @ 0) corner:(width @ shownImage height).
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   618
            "/rectBelow := 0 @ (shownImage height) corner:(shownImage height @ height).
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   619
            "/(rectRight width > 0 and:[rectRight height > 0]) ifTrue:[ self clearRectangle:rectRight ].
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   620
            "/(rectBelow width > 0 and:[rectBelow height > 0]) ifTrue:[ self clearRectangle:rectBelow ].
14206c682961 #OTHER by mawalch
mawalch
parents: 5226
diff changeset
   621
3726
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   622
            xI > (x+w) ifTrue:[^ self]. "/ no need to draw
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   623
            yI > (y+h) ifTrue:[^ self]. "/ no need to draw
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   624
            (xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   625
            (yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   626
5022
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   627
            (false "depth ~~ 1"
3726
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   628
            or:[shownImage mask notNil]) ifTrue:[
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   629
                self clearRectangleX:x y:y width:w height:h.
3726
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   630
                shownImage displayOn:self x:xI y:yI.
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   631
                "/ self displayForm:shownImage x:xI y:yI
3726
1ef0073283b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3711
diff changeset
   632
            ] ifFalse:[
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   633
                self displayOpaqueForm:shownImage x:xI y:yI
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   634
            ].
430
574a94732ece checkin from browser
Claus Gittinger <cg@exept.de>
parents: 414
diff changeset
   635
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   636
            "/ right of image ?
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   637
            right := x + w - 1.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   638
            right > (xI + imgWidth) ifTrue:[
5022
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   639
                self clearRectangleX:(xI + imgWidth) y:y
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   640
                               width:(right - imgWidth - xI) height:h
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   641
            ].
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   642
            "/ below of image ?
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   643
            bott := y + h - 1.
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   644
            bott > (yI + imgHeight) ifTrue:[
5022
c2e58c679b8e #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4966
diff changeset
   645
                self clearRectangleX:margin y:(yI + imgHeight)
5226
24916b8eff22 #TUNING by mawalch
mawalch
parents: 5022
diff changeset
   646
                               width:w height:(bott - imgHeight - yI)
3659
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   647
            ].
53ec00df6b6c care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents: 3618
diff changeset
   648
        ].
5268
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   649
    ] ifFalse:[
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   650
        self clearRectangleX:x y:y width:w height:h.
b490144a4971 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5227
diff changeset
   651
    ].    
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   652
635
915077fd17ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   653
    "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
   654
    "Modified: / 12.8.1998 / 14:02:28 / cg"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   655
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   656
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   657
!ImageView methodsFor:'event handling'!
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   658
3618
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   659
buttonMotion:state x:x y:y
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   660
    |delta mousePoint|
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   661
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   662
    lastMousePoint notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   663
        mousePoint := (x@y).
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   664
        delta := mousePoint - lastMousePoint.
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   665
        delta ~= (0@0) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   666
            self scrollTo:(self viewOrigin - delta).
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   667
            lastMousePoint := mousePoint.
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   668
        ]
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   669
    ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   670
        super buttonMotion:state x:x y:y
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   671
    ]
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   672
!
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   673
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   674
buttonPress:button x:x y:y
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   675
    button == 1 ifTrue:[
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   676
        "self cursor:(Cursor handGrab). "
3618
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   677
        lastMousePoint := x@y.
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   678
    ].
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   679
    super buttonPress:button x:x y:y
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   680
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   681
    "Modified: / 06-05-2012 / 12:19:39 / cg"
3618
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   682
!
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   683
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   684
buttonRelease:button x:x y:y
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   685
    button == 1 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   686
        lastMousePoint := nil
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   687
    ].
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   688
    super buttonRelease:button x:x y:y
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   689
!
Claus Gittinger <cg@exept.de>
parents: 3408
diff changeset
   690
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   691
mouseWheelZoom:amount
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   692
    "CTRL-wheel action"
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   693
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   694
    |mul|
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   695
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   696
    amount > 0 ifTrue:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   697
        mul := 1.2.
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   698
    ] ifFalse:[
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   699
        mul := 0.8.
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   700
    ].
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   701
    self magnificationFactor:((magnificationFactor ? 1) * mul).
4124
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   702
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   703
    "Created: / 06-05-2012 / 12:18:06 / cg"
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   704
!
bac298acc241 class definition
Claus Gittinger <cg@exept.de>
parents: 4066
diff changeset
   705
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   706
sizeChanged:how
2911
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   707
    (#(fit fitBig fitSmall) includes:adjust) ifTrue:[
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   708
        magnifiedImage notNil ifTrue:[
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   709
            DoNotMagnifyQuery query ifFalse:[
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   710
                self pushEvent:#updateImageAfterSizeChange.
2911
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   711
            ]
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   712
        ].
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   713
    ] ifFalse:[
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   714
        adjust == #center ifTrue:[
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   715
            self clear.
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   716
            self invalidate.
b350e90e9a5b avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
   717
        ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   718
    ].
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   719
    super sizeChanged:how
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   720
!
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   721
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   722
updateImageAfterSizeChange
5399
0dab5e63d3d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5398
diff changeset
   723
    |oldMagnifiedImage|
0dab5e63d3d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5398
diff changeset
   724
    
0dab5e63d3d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5398
diff changeset
   725
    oldMagnifiedImage := magnifiedImage.
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   726
    magnifiedImage := nil.
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   727
    self generateMagnifiedImage.
5400
db097f6162be #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   728
    (oldMagnifiedImage isNil
db097f6162be #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   729
      or:[ magnifiedImage isNil
db097f6162be #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   730
      or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]]
db097f6162be #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   731
    ) ifTrue:[
db097f6162be #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5399
diff changeset
   732
        "/ self clear.
5399
0dab5e63d3d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5398
diff changeset
   733
        self invalidate.
0dab5e63d3d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5398
diff changeset
   734
    ].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   735
! !
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   736
2501
832cbac295b8 method category rename
Claus Gittinger <cg@exept.de>
parents: 2404
diff changeset
   737
!ImageView methodsFor:'initialization & release'!
1327
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   738
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   739
destroy
5404
c327195bfbb4 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   740
    magnifiedImage := nil.
c327195bfbb4 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   741
    "/ image := nil.
1327
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   742
    super destroy.
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   743
! !
ab99aad206dc category change
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   744
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   745
!ImageView methodsFor:'menu'!
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   746
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   747
middleButtonMenu
4263
aacb0c4d8dc0 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
   748
    menuHolder notNil ifTrue:[^ super middleButtonMenu].
4245
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   749
    ^ self class middleButtonMenu
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   750
! !
26b64657e15c class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4192
diff changeset
   751
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   752
!ImageView methodsFor:'queries'!
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   753
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   754
heightOfContents
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   755
    "return the image's height - scrollbar needs this info"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   756
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   757
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   758
    ^ (magnifiedImage ? image) height
89
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   759
!
eec056360d03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   760
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   761
widthOfContents
5387
278d666f9267 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5268
diff changeset
   762
    "return the image's width - scrollbar needs this info"
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   763
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   764
    image isNil ifTrue:[^ 0].
2158
c4389029e303 magnification
Claus Gittinger <cg@exept.de>
parents: 2099
diff changeset
   765
    ^ (magnifiedImage ? image) width
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   766
! !
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   767
3408
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   768
!ImageView methodsFor:'scrolling'!
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   769
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   770
scrollToMakeVisible:aPoint
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   771
    "try to arrange for aPoint to be visible (at the center, if possible)"
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   772
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   773
    |mag pos|
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   774
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   775
    mag := self magnification.
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   776
    pos := aPoint * mag.
3705
a75510393dc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   777
    self scrollTo:(pos - (self extent / 2)) rounded.
3408
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   778
! !
2ca9dff3fdaf +scrollToMakeVisible
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   779
257
0acd4525d53e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
   780
!ImageView class methodsFor:'documentation'!
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   781
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 90
diff changeset
   782
version
4912
6630a4464c2f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4732
diff changeset
   783
    ^ '$Header$'
3884
1da7ee7bcd15 changed: #destroy
Claus Gittinger <cg@exept.de>
parents: 3733
diff changeset
   784
!
1da7ee7bcd15 changed: #destroy
Claus Gittinger <cg@exept.de>
parents: 3733
diff changeset
   785
1da7ee7bcd15 changed: #destroy
Claus Gittinger <cg@exept.de>
parents: 3733
diff changeset
   786
version_CVS
4912
6630a4464c2f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4732
diff changeset
   787
    ^ '$Header$'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   788
! !
2358
68180cd61e53 care for nil image
Claus Gittinger <cg@exept.de>
parents: 2164
diff changeset
   789
4192
17828ed3f930 class: ImageView
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
   790
2160
4c15f05f8bc6 somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   791
ImageView initialize!