|
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 Scroller subclass:#HorizontalScroller |
|
14 instanceVariableNames:'' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'Views-Interactors' |
|
18 ! |
|
19 |
|
20 HorizontalScroller comment:' |
|
21 |
|
22 COPYRIGHT (c) 1989-93 by Claus Gittinger |
|
23 All Rights Reserved |
|
24 |
|
25 the scroller part of a horizontal scrollbar |
|
26 |
|
27 %W% %E% |
|
28 written spring/summer 89 by claus |
|
29 '! |
|
30 |
|
31 !HorizontalScroller methodsFor:'initialization'! |
|
32 |
|
33 initialize |
|
34 super initialize. |
|
35 moveDirection := #x |
|
36 ! ! |
|
37 |
|
38 !HorizontalScroller methodsFor:'accessing'! |
|
39 |
|
40 thumbOrigin:newOrigin |
|
41 "set the thumbs origin (in percent)" |
|
42 |
|
43 |realNewOrigin oldFrame oldLeft oldRight thumbLeft thumbRight |
|
44 tH tW delta top| |
|
45 |
|
46 ((newOrigin + thumbHeight) > 100) ifTrue:[ |
|
47 realNewOrigin := 100 - thumbHeight |
|
48 ] ifFalse: [ |
|
49 realNewOrigin := newOrigin |
|
50 ]. |
|
51 (realNewOrigin > 100) ifTrue:[ |
|
52 realNewOrigin := 100 |
|
53 ] ifFalse: [ |
|
54 (realNewOrigin < 0) ifTrue:[ |
|
55 realNewOrigin := 0 |
|
56 ] |
|
57 ]. |
|
58 (realNewOrigin = thumbOrigin) ifFalse:[ |
|
59 oldFrame := thumbFrame. |
|
60 thumbOrigin := realNewOrigin. |
|
61 self computeThumbFrame. |
|
62 (thumbHeight = 100) ifTrue:[^ self]. |
|
63 |
|
64 shown ifTrue:[ |
|
65 (thumbFrame ~~ oldFrame) ifTrue:[ |
|
66 tH := thumbFrame height. |
|
67 tW := thumbFrame width. |
|
68 oldLeft := oldFrame left. |
|
69 oldRight := oldLeft + tW. |
|
70 |
|
71 thumbLeft := thumbFrame left. |
|
72 thumbRight := thumbLeft + tW. |
|
73 |
|
74 top := thumbFrame top. |
|
75 |
|
76 (oldRight >= width) ifTrue:[ |
|
77 "cannot copy - thumb was behind end" |
|
78 self drawThumbBackgroundInX:oldLeft y:top |
|
79 width:(width - oldLeft" - 1") height:tH. |
|
80 self drawThumb. |
|
81 ^ self |
|
82 ]. |
|
83 |
|
84 self copyFrom:self x:oldLeft y:top |
|
85 toX:thumbLeft y:top |
|
86 width:tW height:tH. |
|
87 |
|
88 oldLeft > thumbLeft ifTrue:[ |
|
89 delta := oldLeft - thumbLeft. |
|
90 oldLeft > thumbRight ifTrue:[ |
|
91 self drawThumbBackgroundInX:oldLeft y:top |
|
92 width:(tW + 1) height:tH |
|
93 ] ifFalse:[ |
|
94 self drawThumbBackgroundInX:thumbRight y:top |
|
95 width:delta height:tH |
|
96 ] |
|
97 ] ifFalse:[ |
|
98 delta := thumbLeft - oldLeft. |
|
99 oldRight < thumbLeft ifTrue:[ |
|
100 self drawThumbBackgroundInX:oldLeft y:top |
|
101 width:tW + 1 height:tH |
|
102 ] ifFalse:[ |
|
103 self drawThumbBackgroundInX:oldLeft y:top |
|
104 width:delta height:tH |
|
105 ] |
|
106 ]. |
|
107 "View3D ifTrue:[ " |
|
108 self waitForExpose |
|
109 "] " |
|
110 ] |
|
111 ] |
|
112 ] |
|
113 ! |
|
114 |
|
115 setThumbFor:aView |
|
116 "get contents and size info from aView and adjust thumb" |
|
117 |
|
118 |percentHeight percentOrigin totalWidth| |
|
119 |
|
120 aView isNil ifTrue:[ |
|
121 totalWidth := 0 |
|
122 ] ifFalse:[ |
|
123 totalWidth := aView widthOfContents |
|
124 ]. |
|
125 (totalWidth = 0) ifTrue:[ |
|
126 percentHeight := 100. |
|
127 percentOrigin := 100 |
|
128 ] ifFalse:[ |
|
129 percentHeight := (aView innerWidth) * 100 // totalWidth. |
|
130 percentOrigin := (aView xOriginOfContents) * 100 // totalWidth |
|
131 ]. |
|
132 (percentHeight = thumbHeight) ifTrue:[ |
|
133 self thumbOrigin:percentOrigin |
|
134 ] ifFalse:[ |
|
135 (percentOrigin = thumbOrigin) ifTrue:[ |
|
136 self thumbHeight:percentHeight |
|
137 ] ifFalse:[ |
|
138 self thumbOrigin:percentOrigin thumbHeight:percentHeight |
|
139 ] |
|
140 ] |
|
141 ! |
|
142 |
|
143 setThumbHeightFor:aView |
|
144 "get contents and size info from aView and adjust thumb height" |
|
145 |
|
146 |percent totalWidth| |
|
147 |
|
148 totalWidth := aView widthOfContents. |
|
149 (totalWidth = 0) ifTrue:[ |
|
150 percent := 100 |
|
151 ] ifFalse:[ |
|
152 percent := (aView innerWidth) * 100 // totalWidth |
|
153 ]. |
|
154 self thumbHeight:percent |
|
155 ! |
|
156 |
|
157 setThumbOriginFor:aView |
|
158 "get contents and size info from aView and adjust thumb origin" |
|
159 |
|
160 |percent totalWidth| |
|
161 |
|
162 totalWidth := aView widthOfContents. |
|
163 (totalWidth = 0) ifTrue:[ |
|
164 percent := 100 |
|
165 ] ifFalse:[ |
|
166 percent := (aView xOriginOfContents) * 100 // totalWidth |
|
167 ]. |
|
168 self thumbOrigin:percent |
|
169 ! ! |