ScrView.st
changeset 0 e6a541c1c0eb
child 3 9d7eefb5e69f
equal deleted inserted replaced
-1:000000000000 0:e6a541c1c0eb
       
     1 "
       
     2  COPYRIGHT (c) 1989-93 by Claus Gittinger
       
     3               All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 View subclass:#ScrollableView
       
    14        instanceVariableNames:'scrolledView scrollBar helpView innerMargin'
       
    15        classVariableNames:''
       
    16        poolDictionaries:''
       
    17        category:'Views-Basic'
       
    18 !
       
    19 
       
    20 ScrollableView comment:'
       
    21 
       
    22 COPYRIGHT (c) 1989-93 by Claus Gittinger
       
    23               All Rights Reserved
       
    24 a view containing a scrollbar and some other (slave-)view
       
    25 
       
    26 %W% %E%
       
    27 
       
    28 written spring 89 by claus
       
    29 '!
       
    30 
       
    31 !ScrollableView class methodsFor:'instance creation'!
       
    32 
       
    33 in:aView
       
    34     ^ self for:nil in:aView
       
    35 !
       
    36 
       
    37 for:aViewClass
       
    38     ^ self for:aViewClass in:nil
       
    39 !
       
    40 
       
    41 for:aViewClass in:aView
       
    42     |newView|
       
    43 
       
    44     newView := self basicNew.
       
    45     aView notNil ifTrue:[
       
    46         newView device:(aView device).
       
    47         aView addSubView:newView
       
    48     ] ifFalse:[
       
    49         newView device:Display
       
    50     ].
       
    51     newView initializeFor:aViewClass.
       
    52     ^ newView
       
    53 ! !
       
    54 
       
    55 !ScrollableView methodsFor:'initialization'!
       
    56 
       
    57 initialize
       
    58     ^ self initializeFor:nil
       
    59 !
       
    60 
       
    61 initializeFor:aViewClass
       
    62     |negativeOffset twoMargins halfMargin|
       
    63 
       
    64     super initialize.
       
    65 
       
    66     innerMargin := ViewSpacing.
       
    67     negativeOffset := borderWidth negated.
       
    68 
       
    69     "create the scrollbar"
       
    70 
       
    71     scrollBar := ScrollBar in:self.
       
    72     scrollBar thumbOrigin:0 thumbHeight:100.
       
    73     scrollBar scrollAction:[:position | 
       
    74         scrolledView scrollVerticalToPercent:position
       
    75     ].
       
    76     scrollBar scrollUpAction:[scrolledView scrollUp].
       
    77     scrollBar scrollDownAction:[scrolledView scrollDown].
       
    78 
       
    79     "create the subview"
       
    80     self is3D ifTrue:[
       
    81         twoMargins := innerMargin * 2.
       
    82         halfMargin := innerMargin // 2.
       
    83 
       
    84         scrollBar origin:(halfMargin @ halfMargin)
       
    85                   extent:[scrollBar extent x @ (height - innerMargin)].
       
    86 
       
    87         helpView := View in:self.
       
    88         helpView origin:((scrollBar origin x + scrollBar width + innerMargin)
       
    89                           @
       
    90                          halfMargin)
       
    91                  extent:[(width - scrollBar width - twoMargins) @ (height - innerMargin)].
       
    92 
       
    93         aViewClass notNil ifTrue:[
       
    94             scrolledView := aViewClass in:helpView.
       
    95             scrolledView origin:(helpView level abs @ helpView level abs)
       
    96                          extent:[(helpView width - helpView level abs - helpView level abs)
       
    97                                  @
       
    98                                  (helpView height - helpView level abs - helpView level abs)].
       
    99             helpView viewBackground:(scrolledView viewBackground).
       
   100             scrolledView level:-1
       
   101         ]
       
   102     ] ifFalse:[
       
   103         (style == #mswindows) ifTrue:[
       
   104             scrollBar origin:[width - scrollBar extent x 
       
   105                                     - scrollBar borderWidth
       
   106                               @
       
   107                               negativeOffset]
       
   108         ] ifFalse:[
       
   109             scrollBar origin:(negativeOffset @ negativeOffset)
       
   110         ].
       
   111         scrollBar extent:[scrollBar extent x @ (height "+ (scrollBar borderWidth * 1)")].
       
   112 
       
   113         aViewClass notNil ifTrue:[
       
   114             scrolledView := aViewClass in:self.
       
   115             (style == #mswindows) ifTrue:[
       
   116                 scrolledView origin:scrolledView borderWidth negated
       
   117                                     @
       
   118                                     scrolledView borderWidth negated
       
   119             ] ifFalse:[
       
   120                 scrolledView origin:((scrollBar width + scrollBar borderWidth
       
   121                                                       - scrolledView borderWidth) 
       
   122                                     @ 
       
   123                                     scrolledView borderWidth negated)
       
   124             ].
       
   125             scrolledView extent:[(width - scrollBar width
       
   126                                    - scrolledView borderWidth) 
       
   127                                  @ 
       
   128                                  (height + (scrollBar borderWidth))
       
   129                                 ]
       
   130         ].
       
   131     ].
       
   132     scrolledView notNil ifTrue:[
       
   133         scrolledView
       
   134             originChangeAction:[:aView | scrollBar setThumbOriginFor:aView].
       
   135         scrolledView
       
   136             contentsChangeAction:[:aView | scrollBar setThumbFor:aView]
       
   137     ]
       
   138 !
       
   139 
       
   140 realize
       
   141     super realize.
       
   142     "since scrolledview may have done something to its contents
       
   143      during init-time we had no chance yet to catch contents-
       
   144      changes; do it now
       
   145     "
       
   146     scrollBar setThumbFor:scrolledView
       
   147 ! !
       
   148 
       
   149 !ScrollableView methodsFor:'accessing'!
       
   150 
       
   151 scrollBar
       
   152     "return the scrollbar"
       
   153 
       
   154     ^ scrollBar
       
   155 !
       
   156 
       
   157 scrolledView
       
   158     "return the scrolled view"
       
   159 
       
   160     ^ scrolledView
       
   161 !
       
   162 
       
   163 scrolledView:aView
       
   164     |m m2 b|
       
   165 
       
   166     scrolledView notNil ifTrue:[
       
   167         self error:'can only scroll one view'
       
   168     ].
       
   169     scrolledView := aView.
       
   170 
       
   171     b := scrolledView borderWidth.
       
   172     self is3D ifTrue:[
       
   173 	m := helpView margin.
       
   174 	m2 := m * 2.
       
   175 
       
   176         helpView addSubView:scrolledView.
       
   177         scrolledView origin:(m @ m)
       
   178                      extent:[(helpView width - m2) @ (helpView height - m2)].
       
   179         scrolledView superViewChangedSize.
       
   180         helpView viewBackground:(scrolledView viewBackground).
       
   181         scrolledView level:-1
       
   182     ] ifFalse:[
       
   183         self addSubView:scrolledView.
       
   184         scrolledView origin:((scrollBar width + scrollBar borderWidth - b) @ b negated)
       
   185                      extent:[(width - scrollBar width - b) @ (height + scrollBar borderWidth)
       
   186                             ].
       
   187         scrolledView superViewChangedSize.
       
   188     ].
       
   189     scrolledView
       
   190         originChangeAction:[:aView | scrollBar setThumbOriginFor:aView].
       
   191     scrolledView
       
   192         contentsChangeAction:[:aView | scrollBar setThumbFor:aView].
       
   193 
       
   194     realized ifTrue:[scrolledView realize]
       
   195 ! !
       
   196 
       
   197 !ScrollableView methodsFor:'slave-view messages'!
       
   198 
       
   199 cursor
       
   200     scrolledView isNil ifTrue:[
       
   201         ^ super cursor
       
   202     ].
       
   203     ^ scrolledView cursor
       
   204 !
       
   205 
       
   206 cursor:aCursor
       
   207     "I have the same cursor as my scrolledView"
       
   208 
       
   209     scrolledView cursor:aCursor.
       
   210     super cursor:aCursor
       
   211 !
       
   212 
       
   213 leftButtonMenu
       
   214     ^ scrolledView leftButtonMenu
       
   215 !
       
   216 
       
   217 leftButtonMenu:aMenu
       
   218     "pass on leftbuttonmenu to scrolledView"
       
   219 
       
   220     scrolledView leftButtonMenu:aMenu
       
   221 !
       
   222 
       
   223 middleButtonMenu
       
   224     ^ scrolledView middleButtonMenu
       
   225 !
       
   226 
       
   227 middleButtonMenu:aMenu
       
   228     "pass on middlebuttonmenu to scrolledView"
       
   229 
       
   230     scrolledView middleButtonMenu:aMenu
       
   231 !
       
   232 
       
   233 rightButtonMenu
       
   234     ^ scrolledView rightButtonMenu
       
   235 !
       
   236 
       
   237 rightButtonMenu:aMenu
       
   238     "pass on rightbuttonmenu to scrolledView"
       
   239 
       
   240     scrolledView rightButtonMenu:aMenu
       
   241 !
       
   242 
       
   243 doesNotUnderstand:aMessage
       
   244     "this is funny: all message we do not understand, are passed
       
   245      on to the scrolledView - so we do not have to care for all
       
   246      possible messages ...(thanks to the Message class)"
       
   247 
       
   248      scrolledView isNil ifFalse:[
       
   249          ^ scrolledView perform:(aMessage selector)
       
   250                   withArguments:(aMessage arguments)
       
   251      ]
       
   252 ! !
       
   253 
       
   254 !ScrollableView methodsFor:'event processing'!
       
   255 
       
   256 sizeChanged:how
       
   257     super sizeChanged:how.
       
   258     scrollBar setThumbFor:scrolledView
       
   259 ! !