ScrollableView.st
changeset 814 5b80bc44f52b
parent 799 64f8700489a4
child 819 32ac89843fa8
equal deleted inserted replaced
813:7168eda47e3b 814:5b80bc44f52b
   541     "set the view to scroll"
   541     "set the view to scroll"
   542 
   542 
   543     |halfMargin twoMargins isOpenwin|
   543     |halfMargin twoMargins isOpenwin|
   544 
   544 
   545     scrolledView notNil ifTrue:[
   545     scrolledView notNil ifTrue:[
   546 	scrolledView destroy.
   546         scrolledView destroy.
   547 	scrolledView := nil.
   547         scrolledView := nil.
   548     ].
   548     ].
   549     scrolledView := aView.
   549     scrolledView := aView.
   550 
   550 
   551 "/    ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
   551 "/    ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
   552     styleSheet is3D ifTrue:[
   552     styleSheet is3D ifTrue:[
   553 	"3D look"
   553         "3D look"
   554 
   554 
   555 	isOpenwin := styleSheet name = #openwin.
   555         isOpenwin := styleSheet name = #openwin.
   556 
   556 
   557 	twoMargins := innerMargin * 2.
   557         twoMargins := innerMargin * 2.
   558 	halfMargin := innerMargin // 2.
   558         halfMargin := innerMargin // 2.
   559 
   559 
   560 	isOpenwin ifTrue:[
   560         isOpenwin ifTrue:[
   561 	    scrolledView level:0.
   561             scrolledView level:0.
   562 	    scrolledView borderWidth:1
   562             scrolledView borderWidth:1
   563 	] ifFalse:[
   563         ] ifFalse:[
   564 	    scrolledView level:DefaultScrolledViewLevel.
   564             scrolledView level:DefaultScrolledViewLevel.
   565 "/            scrolledView level:-1
   565 "/            scrolledView level:-1
   566 	].
   566         ].
   567 
   567 
   568 	(scrollBarPosition == #right) ifTrue:[
   568         (scrollBarPosition == #right) ifTrue:[
   569 	    scrolledView 
   569             scrolledView 
   570 		origin:halfMargin asPoint
   570                 origin:halfMargin asPoint
   571 		extent:[(width - 
   571                 extent:[(width - 
   572 			 scrollBar width - 
   572                          scrollBar width - 
   573 			 twoMargins) 
   573                          twoMargins) 
   574 			@ 
   574                         @ 
   575 			(height - innerMargin)
   575                         (height - innerMargin)
   576 		       ].
   576                        ].
   577 	] ifFalse:[
   577         ] ifFalse:[
   578 	    scrolledView 
   578             scrolledView 
   579 		origin:((scrollBar origin x 
   579                 origin:((scrollBar origin x 
   580 			 + scrollBar width 
   580                          + scrollBar width 
   581 			 + innerMargin)
   581                          + innerMargin)
   582 			@
   582                         @
   583 			halfMargin)
   583                         halfMargin)
   584 		extent:[(width 
   584                 extent:[(width 
   585 			 - scrollBar width 
   585                          - scrollBar width 
   586 			 - twoMargins) 
   586                          - twoMargins) 
   587 			@ 
   587                         @ 
   588 			(height - innerMargin)
   588                         (height - innerMargin)
   589 		       ].
   589                        ].
   590 	]
   590         ]
   591     ] ifFalse:[
   591     ] ifFalse:[
   592 	"non 3D look"
   592         "non 3D look"
   593 	(scrollBarPosition == #right) ifTrue:[
   593         (scrollBarPosition == #right) ifTrue:[
   594 	    scrolledView 
   594             scrolledView 
   595 		origin:scrolledView borderWidth negated asPoint
   595                 origin:scrolledView borderWidth negated asPoint
   596 	] ifFalse:[
   596         ] ifFalse:[
   597 	    scrolledView 
   597             scrolledView 
   598 		origin:((scrollBar width 
   598                 origin:((scrollBar width 
   599 			 + scrollBar borderWidth 
   599                          + scrollBar borderWidth 
   600 			 - scrolledView borderWidth) 
   600                          - scrolledView borderWidth) 
   601 			@ 
   601                         @ 
   602 			scrolledView borderWidth negated)
   602                         scrolledView borderWidth negated)
   603 	].
   603         ].
   604 	scrolledView 
   604         scrolledView 
   605 	    extent:[
   605             extent:[
   606 		    (width 
   606                     (width 
   607 		     - scrollBar width 
   607                      - scrollBar width 
   608 		     - scrolledView borderWidth) 
   608                      - scrolledView borderWidth) 
   609 		    @ 
   609                     @ 
   610 		    (height + (scrollBar borderWidth))
   610                     (height + (scrollBar borderWidth))
   611 		   ]
   611                    ]
   612     ].
   612     ].
   613 
   613 
   614     super addSubView:scrolledView.
   614     super addSubView:scrolledView.
   615     self setScrollActions.
   615     self setScrollActions.
   616 
   616 
   617     "
       
   618      pass my keyboard input (and other subviews input) 
       
   619      to the scrolled view ...
       
   620     "
       
   621     self delegate:(KeyboardForwarder toView:scrolledView).
       
   622 
       
   623     realized ifTrue:[
   617     realized ifTrue:[
   624 	self sizeChanged:nil.
   618         self sizeChanged:nil.
   625 	scrolledView realize
   619         scrolledView realize
   626     ].
   620     ].
       
   621 
       
   622     "Modified: 1.8.1996 / 12:44:27 / cg"
   627 ! !
   623 ! !
   628 
   624 
   629 !ScrollableView methodsFor:'changes '!
   625 !ScrollableView methodsFor:'changes '!
   630 
   626 
   631 update:something with:argument from:changedObject
   627 update:something with:argument from:changedObject
   719 
   715 
   720     isOpenWin ifTrue:[self level:0].
   716     isOpenWin ifTrue:[self level:0].
   721     is3D := styleSheet is3D.
   717     is3D := styleSheet is3D.
   722 
   718 
   723     isST80 ifTrue:[
   719     isST80 ifTrue:[
   724 	innerMargin := 0
   720         innerMargin := 0
   725     ] ifFalse:[
   721     ] ifFalse:[
   726 	is3D ifTrue:[
   722         is3D ifTrue:[
   727 	    innerMargin := ViewSpacing.
   723             innerMargin := ViewSpacing.
   728 	] ifFalse:[
   724         ] ifFalse:[
   729 	    innerMargin := 0    
   725             innerMargin := 0    
   730 	]
   726         ]
   731     ].
   727     ].
   732     negativeOffset := borderWidth negated.
   728     negativeOffset := borderWidth negated.
   733 
   729 
   734     "create the scrollbar"
   730     "create the scrollbar"
   735 
   731 
   736     isST80 ifTrue:[
   732     isST80 ifTrue:[
   737 	cls := ScrollBar
   733         cls := ScrollBar
   738     ] ifFalse:[
   734     ] ifFalse:[
   739 	cls := miniV ifTrue:[MiniScroller] ifFalse:[ScrollBar].
   735         cls := miniV ifTrue:[MiniScroller] ifFalse:[ScrollBar].
   740     ].
   736     ].
   741 
   737 
   742     scrollBar := cls in:self.
   738     scrollBar := cls in:self.
   743     scrollBar thumbOrigin:0 thumbHeight:100.
   739     scrollBar thumbOrigin:0 thumbHeight:100.
   744 
   740 
   745     extra := 0.
   741     extra := 0.
   746 
   742 
   747     "create the subview"
   743     "create the subview"
   748     is3D ifTrue:[
   744     is3D ifTrue:[
   749 	twoMargins := innerMargin * 2.
   745         twoMargins := innerMargin * 2.
   750 	halfMargin := innerMargin // 2.
   746         halfMargin := innerMargin // 2.
   751 
   747 
   752 	aViewClass notNil ifTrue:[
   748         aViewClass notNil ifTrue:[
   753 	    scrolledView := aViewClass in:self.
   749             scrolledView := aViewClass in:self.
   754 	    isOpenWin ifTrue:[
   750             isOpenWin ifTrue:[
   755 		lvl := 0.
   751                 lvl := 0.
   756 		"/ scrolledView level:0.
   752                 "/ scrolledView level:0.
   757 		scrolledView borderWidth:1.
   753                 scrolledView borderWidth:1.
   758 	    ] ifFalse:[
   754             ] ifFalse:[
   759 		lvl := DefaultScrolledViewLevel.
   755                 lvl := DefaultScrolledViewLevel.
   760 "/                isST80 ifTrue:[
   756 "/                isST80 ifTrue:[
   761 "/                    "/ scrolledView level:1.
   757 "/                    "/ scrolledView level:1.
   762 "/                    lvl := 1.
   758 "/                    lvl := 1.
   763 "/                ] ifFalse:[
   759 "/                ] ifFalse:[
   764 "/                    "/ scrolledView level:-1
   760 "/                    "/ scrolledView level:-1
   765 "/                     lvl := -1
   761 "/                     lvl := -1
   766 "/                ]
   762 "/                ]
   767 	    ].
   763             ].
   768 	    scrolledView level:lvl.
   764             scrolledView level:lvl.
   769 	    extra := scrolledView borderWidth * 2.
   765             extra := scrolledView borderWidth * 2.
   770 	].
   766         ].
   771 
   767 
   772 	scrollBar extent:[scrollBar extent x
   768         scrollBar extent:[scrollBar extent x
   773 			  @ 
   769                           @ 
   774 			  (height - innerMargin "new:" + extra)].
   770                           (height - innerMargin "new:" + extra)].
   775 	scrolledView notNil ifTrue:[
   771         scrolledView notNil ifTrue:[
   776 	    scrolledView
   772             scrolledView
   777 		extent:[(width 
   773                 extent:[(width 
   778 			 - scrollBar width 
   774                          - scrollBar width 
   779 			 - twoMargins) 
   775                          - twoMargins) 
   780 			@ 
   776                         @ 
   781 			(height - innerMargin)].
   777                         (height - innerMargin)].
   782 	].
   778         ].
   783 
   779 
   784 	(scrollBarPosition == #right) ifTrue:[
   780         (scrollBarPosition == #right) ifTrue:[
   785 	    scrollBar origin:[width - scrollBar extent x 
   781             scrollBar origin:[width - scrollBar extent x 
   786 				    - (scrollBar borderWidth * 2)
   782                                     - (scrollBar borderWidth * 2)
   787 				    - halfMargin
   783                                     - halfMargin
   788 			      @
   784                               @
   789 			      halfMargin].
   785                               halfMargin].
   790 
   786 
   791 	    scrolledView notNil ifTrue:[
   787             scrolledView notNil ifTrue:[
   792 		scrolledView origin:halfMargin asPoint
   788                 scrolledView origin:halfMargin asPoint
   793 		]
   789                 ]
   794 	] ifFalse:[
   790         ] ifFalse:[
   795 	    scrollBar origin:halfMargin asPoint.
   791             scrollBar origin:halfMargin asPoint.
   796 
   792 
   797 	    scrolledView notNil ifTrue:[
   793             scrolledView notNil ifTrue:[
   798 		scrolledView origin:((scrollBar origin x + scrollBar width + innerMargin)
   794                 scrolledView origin:((scrollBar origin x + scrollBar width + innerMargin)
   799 				     @
   795                                      @
   800 				     halfMargin)
   796                                      halfMargin)
   801 	    ]
   797             ]
   802 	].
   798         ].
   803     ] ifFalse:[
   799     ] ifFalse:[
   804 	(scrollBarPosition == #right) ifTrue:[
   800         (scrollBarPosition == #right) ifTrue:[
   805 	    scrollBar origin:[width - scrollBar extent x 
   801             scrollBar origin:[width - scrollBar extent x 
   806 				    - scrollBar borderWidth
   802                                     - scrollBar borderWidth
   807 			      @
   803                               @
   808 			      negativeOffset]
   804                               negativeOffset]
   809 	] ifFalse:[
   805         ] ifFalse:[
   810 	    scrollBar origin:negativeOffset asPoint
   806             scrollBar origin:negativeOffset asPoint
   811 	].
   807         ].
   812 	scrollBar extent:[scrollBar extent x 
   808         scrollBar extent:[scrollBar extent x 
   813 			  @ 
   809                           @ 
   814 			  (height "+ (scrollBar borderWidth * 1)")].
   810                           (height "+ (scrollBar borderWidth * 1)")].
   815 
   811 
   816 	aViewClass notNil ifTrue:[
   812         aViewClass notNil ifTrue:[
   817 	    scrolledView := aViewClass in:self.
   813             scrolledView := aViewClass in:self.
   818 	    (scrollBarPosition == #right) ifTrue:[
   814             (scrollBarPosition == #right) ifTrue:[
   819 		scrolledView origin:scrolledView borderWidth negated asPoint
   815                 scrolledView origin:scrolledView borderWidth negated asPoint
   820 	    ] ifFalse:[
   816             ] ifFalse:[
   821 		scrolledView origin:((scrollBar width + 
   817                 scrolledView origin:((scrollBar width + 
   822 				      scrollBar borderWidth - 
   818                                       scrollBar borderWidth - 
   823 				      scrolledView borderWidth) 
   819                                       scrolledView borderWidth) 
   824 				    @ 
   820                                     @ 
   825 				    scrolledView borderWidth negated)
   821                                     scrolledView borderWidth negated)
   826 	    ].
   822             ].
   827 	    scrolledView extent:[(width - scrollBar width - scrolledView borderWidth) 
   823             scrolledView extent:[(width - scrollBar width - scrolledView borderWidth) 
   828 				 @ 
   824                                  @ 
   829 				 (height + (scrollBar borderWidth))
   825                                  (height + (scrollBar borderWidth))
   830 				]
   826                                 ]
   831 	].
   827         ].
   832     ].
   828     ].
   833     scrolledView notNil ifTrue:[
   829     scrolledView notNil ifTrue:[
   834 	self setScrollActions.
   830         self setScrollActions.
   835 	"
       
   836 	 pass my keyboard input (and other subviews input) 
       
   837 	 to the scrolled view ...
       
   838 	"
       
   839 	self delegate:(KeyboardForwarder toView:scrolledView).
       
   840     ]
   831     ]
       
   832 
       
   833     "Modified: 1.8.1996 / 12:44:32 / cg"
   841 !
   834 !
   842 
   835 
   843 realize
   836 realize
   844     super realize.
   837     super realize.
   845 
   838 
   864       Consider this as a kludge."
   857       Consider this as a kludge."
   865 
   858 
   866     lockUpdates := false.
   859     lockUpdates := false.
   867 
   860 
   868     scrollBar scrollAction:[:position |
   861     scrollBar scrollAction:[:position |
   869 	lockUpdates := true.
   862         lockUpdates := true.
   870 	scrolledView scrollVerticalToPercent:position.
   863         scrolledView scrollVerticalToPercent:position.
   871 	lockUpdates := false
   864         lockUpdates := false
   872     ].
   865     ].
   873     scrollBar scrollUpAction:[scrolledView scrollUp].
   866     scrollBar scrollUpAction:[scrolledView scrollUp].
   874     scrollBar scrollDownAction:[scrolledView scrollDown].
   867     scrollBar scrollDownAction:[scrolledView scrollDown].
   875 
   868 
   876     scrolledView addDependent:self.
   869     scrolledView addDependent:self.
       
   870 
       
   871     "
       
   872      pass my keyboard input (and other subviews input) 
       
   873      to the scrolled view ...
       
   874     "
       
   875     self delegate:(KeyboardForwarder toView:scrolledView).
       
   876 
       
   877     "Modified: 1.8.1996 / 12:44:21 / cg"
   877 ! !
   878 ! !
   878 
   879 
   879 !ScrollableView methodsFor:'queries'!
   880 !ScrollableView methodsFor:'queries'!
   880 
   881 
   881 preferredExtent
   882 preferredExtent
   983 ! !
   984 ! !
   984 
   985 
   985 !ScrollableView  class methodsFor:'documentation'!
   986 !ScrollableView  class methodsFor:'documentation'!
   986 
   987 
   987 version
   988 version
   988     ^ '$Header: /cvs/stx/stx/libwidg/ScrollableView.st,v 1.37 1996-07-19 18:55:12 cg Exp $'
   989     ^ '$Header: /cvs/stx/stx/libwidg/ScrollableView.st,v 1.38 1996-08-01 16:25:33 cg Exp $'
   989 ! !
   990 ! !