2620
|
1 |
"{ Package: 'stx:goodies' }"
|
|
2 |
|
|
3 |
View subclass:#CharacterSetView
|
2623
|
4 |
instanceVariableNames:'codePageHolder selectedCodePointHolder'
|
2620
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Collections-Text-Encodings'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!CharacterSetView class methodsFor:'startup'!
|
|
12 |
|
2623
|
13 |
open
|
|
14 |
self openOn:View defaultFont
|
|
15 |
|
|
16 |
"
|
|
17 |
self open
|
|
18 |
"
|
|
19 |
!
|
|
20 |
|
2620
|
21 |
openOn:aFont
|
2625
|
22 |
^ self
|
|
23 |
openOn:aFont
|
|
24 |
label:aFont printString
|
|
25 |
clickLabel:'Click on glyph to see its codePoint.'
|
|
26 |
|
|
27 |
"
|
|
28 |
self openOn:(View defaultFont).
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
openOn:aFont label:viewLabel clickLabel:clickLabel
|
2623
|
33 |
|top panel v bNext bPrev bFirst bLast rangeLabel codePointLabel
|
2624
|
34 |
first last next prev enable update updateCodePoint w h|
|
2620
|
35 |
|
|
36 |
top := StandardSystemView new.
|
2625
|
37 |
top label:viewLabel.
|
2622
|
38 |
|
2620
|
39 |
v := self origin:0.0@0.0 corner:1.0@1.0 in:top.
|
2622
|
40 |
v topInset:25.
|
2620
|
41 |
v font:aFont.
|
2622
|
42 |
|
|
43 |
panel := HorizontalPanelView in:top.
|
|
44 |
panel origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
|
|
45 |
panel bottomInset:-25.
|
|
46 |
panel horizontalLayout:#left.
|
|
47 |
|
|
48 |
"/ actions
|
2623
|
49 |
updateCodePoint := [
|
|
50 |
|selectedCodePoint|
|
|
51 |
|
|
52 |
selectedCodePoint := v selectedCodePoint.
|
|
53 |
selectedCodePoint isNil ifTrue:[
|
2625
|
54 |
codePointLabel label:clickLabel
|
2623
|
55 |
] ifFalse:[
|
|
56 |
codePointLabel label:('Selected: u%1'
|
|
57 |
bindWith:((selectedCodePoint printStringRadix:16) leftPaddedTo:4 with:$0)).
|
|
58 |
].
|
|
59 |
codePointLabel repairDamage.
|
|
60 |
].
|
|
61 |
|
2622
|
62 |
update := [
|
2623
|
63 |
|uOffs selectedCodePoint|
|
2622
|
64 |
|
|
65 |
uOffs := v codePage * 16r0100.
|
2623
|
66 |
rangeLabel label:('u%1 ... u%2'
|
2622
|
67 |
bindWith:((uOffs printStringRadix:16) leftPaddedTo:4 with:$0)
|
|
68 |
with:(((uOffs + 16rFF) printStringRadix:16) leftPaddedTo:4 with:$0)).
|
2623
|
69 |
rangeLabel repairDamage.
|
2622
|
70 |
].
|
|
71 |
|
|
72 |
enable := [
|
|
73 |
v codePage > 0 ifTrue:[
|
2623
|
74 |
bPrev enable.
|
|
75 |
bFirst enable.
|
2622
|
76 |
] ifFalse:[
|
2623
|
77 |
bPrev disable.
|
|
78 |
bFirst disable.
|
2622
|
79 |
].
|
|
80 |
v codePage < 16rFF ifTrue:[
|
2623
|
81 |
bNext enable.
|
|
82 |
bLast enable.
|
2622
|
83 |
] ifFalse:[
|
2623
|
84 |
bNext disable.
|
|
85 |
bLast disable.
|
2622
|
86 |
].
|
|
87 |
].
|
|
88 |
|
|
89 |
next := [
|
|
90 |
v codePage:(v codePage + 1).
|
|
91 |
enable value.
|
|
92 |
update value.
|
|
93 |
].
|
|
94 |
|
|
95 |
prev := [
|
|
96 |
v codePage:(v codePage - 1).
|
|
97 |
enable value.
|
|
98 |
update value.
|
|
99 |
].
|
|
100 |
|
2623
|
101 |
first := [
|
|
102 |
v codePage:0.
|
|
103 |
enable value.
|
|
104 |
update value.
|
|
105 |
].
|
2622
|
106 |
|
2623
|
107 |
last := [
|
|
108 |
v codePage:16rFF.
|
|
109 |
enable value.
|
|
110 |
update value.
|
|
111 |
].
|
2622
|
112 |
|
2623
|
113 |
|
|
114 |
bFirst := Button label:(ToolbarIconLibrary start16x16Icon) in:panel.
|
|
115 |
bFirst action:first.
|
|
116 |
|
|
117 |
bPrev := Button label:(ToolbarIconLibrary back16x16Icon) in:panel.
|
2622
|
118 |
bPrev controller beTriggerOnDown.
|
|
119 |
bPrev action:prev.
|
|
120 |
bPrev disable.
|
|
121 |
bPrev autoRepeat:true.
|
|
122 |
|
2623
|
123 |
bNext := Button label:(ToolbarIconLibrary forward16x16Icon) in:panel.
|
|
124 |
bNext controller beTriggerOnDown.
|
|
125 |
bNext action:next.
|
|
126 |
bNext autoRepeat:true.
|
|
127 |
|
|
128 |
bLast := Button label:(ToolbarIconLibrary finish16x16Icon) in:panel.
|
|
129 |
bLast action:last.
|
|
130 |
|
|
131 |
rangeLabel := Label label:'RangeStart .. RangeStop' in:panel.
|
2626
|
132 |
codePointLabel := Label label:clickLabel in:panel.
|
2624
|
133 |
codePointLabel foregroundColor:(Color blue).
|
|
134 |
|
2622
|
135 |
update value.
|
|
136 |
|
2623
|
137 |
v selectedCodePointHolder onChangeEvaluate:updateCodePoint.
|
|
138 |
|
2624
|
139 |
w := v preferredExtent x max:(panel preferredExtent x).
|
|
140 |
h := v preferredExtent y + (panel preferredExtent y).
|
|
141 |
top extent:(w @ h).
|
|
142 |
|
2620
|
143 |
top open.
|
2623
|
144 |
^ v
|
2620
|
145 |
|
|
146 |
"
|
|
147 |
self openOn:(View defaultFont).
|
|
148 |
"
|
|
149 |
! !
|
|
150 |
|
2622
|
151 |
!CharacterSetView methodsFor:'accessing'!
|
|
152 |
|
|
153 |
codePage
|
2623
|
154 |
^ codePageHolder value
|
2622
|
155 |
!
|
|
156 |
|
|
157 |
codePage:pageNr
|
2623
|
158 |
codePageHolder value:pageNr.
|
|
159 |
!
|
|
160 |
|
|
161 |
codePageHolder
|
|
162 |
^ codePageHolder
|
|
163 |
!
|
2622
|
164 |
|
2623
|
165 |
selectedCodePoint
|
|
166 |
^ selectedCodePointHolder value
|
|
167 |
!
|
|
168 |
|
|
169 |
selectedCodePointHolder
|
|
170 |
^ selectedCodePointHolder
|
2622
|
171 |
! !
|
|
172 |
|
2620
|
173 |
!CharacterSetView methodsFor:'drawing'!
|
|
174 |
|
|
175 |
redraw
|
2624
|
176 |
|wCol hRow dY|
|
2620
|
177 |
|
|
178 |
wCol := width / 16.
|
|
179 |
hRow := height / 16.
|
|
180 |
|
|
181 |
0 to:16 do:[:col |
|
|
182 |
|x|
|
|
183 |
|
|
184 |
x := (col * wCol) rounded asInteger.
|
|
185 |
self displayLineFromX:x y:0 toX:x y:height-1.
|
|
186 |
].
|
|
187 |
|
|
188 |
0 to:15 do:[:row |
|
|
189 |
|y|
|
|
190 |
|
|
191 |
y := (row * hRow) rounded asInteger.
|
|
192 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
193 |
].
|
|
194 |
|
2624
|
195 |
dY := (hRow - (font height)) // 2 + (font ascent).
|
2620
|
196 |
|
|
197 |
0 to:15 do:[:row |
|
2626
|
198 |
|y0 y1 y rowBase|
|
2620
|
199 |
|
|
200 |
rowBase := row * 16r10.
|
2623
|
201 |
y := y0 := row * hRow.
|
2626
|
202 |
y := y rounded asInteger.
|
2624
|
203 |
y := y + dY.
|
2626
|
204 |
|
|
205 |
y1 := (row+1) * hRow.
|
|
206 |
y1 := y1 rounded asInteger.
|
|
207 |
|
2620
|
208 |
0 to:15 do:[:col |
|
2626
|
209 |
|x0 x1 x codePoint s|
|
2620
|
210 |
|
|
211 |
codePoint := rowBase + col.
|
2623
|
212 |
s := (Character value:(self codePage * 16r100) + codePoint) asString.
|
2620
|
213 |
|
2623
|
214 |
x := x0 := (col * wCol) rounded asInteger.
|
2626
|
215 |
x := x rounded asInteger.
|
2620
|
216 |
x := x + (wCol / 2).
|
2626
|
217 |
x := x - ((font widthOf:s) // 2).
|
|
218 |
|
|
219 |
x1 := ((col+1) * wCol) rounded asInteger.
|
|
220 |
x1 := x1 rounded asInteger.
|
2623
|
221 |
|
|
222 |
codePoint == self selectedCodePoint ifTrue:[
|
2624
|
223 |
self paint:(Color red).
|
2626
|
224 |
self fillRectangle:((x0+1)@(y0+1) corner:(x1)@(y1)).
|
2624
|
225 |
self paint:(Color white).
|
2623
|
226 |
self displayString:s x:x y:y.
|
|
227 |
self paint:(Color black).
|
|
228 |
] ifFalse:[
|
|
229 |
self displayString:s x:x y:y.
|
|
230 |
].
|
2620
|
231 |
].
|
|
232 |
].
|
|
233 |
|
|
234 |
"
|
|
235 |
(self extent:300@600) open
|
|
236 |
"
|
|
237 |
!
|
|
238 |
|
|
239 |
sizeChanged:how
|
|
240 |
self clear.
|
|
241 |
self redraw.
|
|
242 |
! !
|
|
243 |
|
2623
|
244 |
!CharacterSetView methodsFor:'event handling'!
|
|
245 |
|
|
246 |
buttonPress:button x:x y:y
|
|
247 |
|wCol hRow row col code|
|
|
248 |
|
|
249 |
wCol := width / 16.
|
|
250 |
hRow := height / 16.
|
|
251 |
|
|
252 |
row := y // hRow.
|
|
253 |
col := x // wCol.
|
|
254 |
|
|
255 |
code := (self codePage*16r0100) + (row * 16) + col.
|
|
256 |
selectedCodePointHolder value:code.
|
|
257 |
!
|
|
258 |
|
|
259 |
codePageChanged
|
|
260 |
realized ifTrue:[
|
|
261 |
self clear.
|
|
262 |
self redraw.
|
|
263 |
].
|
|
264 |
!
|
|
265 |
|
|
266 |
selectedCodePointChanged
|
|
267 |
realized ifTrue:[
|
|
268 |
self clear.
|
|
269 |
self redraw.
|
|
270 |
].
|
|
271 |
! !
|
|
272 |
|
2622
|
273 |
!CharacterSetView methodsFor:'initialization'!
|
|
274 |
|
|
275 |
initialize
|
|
276 |
super initialize.
|
2623
|
277 |
codePageHolder := 0 asValue.
|
|
278 |
codePageHolder onChangeSend:#codePageChanged to:self.
|
|
279 |
|
|
280 |
selectedCodePointHolder := ValueHolder new.
|
|
281 |
selectedCodePointHolder onChangeSend:#selectedCodePointChanged to:self.
|
2622
|
282 |
! !
|
|
283 |
|
2624
|
284 |
!CharacterSetView methodsFor:'queries'!
|
|
285 |
|
|
286 |
preferredExtent
|
|
287 |
preferredExtent notNil ifTrue:[
|
|
288 |
^ preferredExtent
|
|
289 |
].
|
|
290 |
|
|
291 |
^ ((4 + font width + 4) * 16)
|
|
292 |
@
|
|
293 |
((4 + font height + 4) * 16)
|
|
294 |
! !
|
|
295 |
|
2620
|
296 |
!CharacterSetView class methodsFor:'documentation'!
|
|
297 |
|
|
298 |
version
|
2626
|
299 |
^ '$Header: /cvs/stx/stx/libwidg2/CharacterSetView.st,v 1.6 2004-02-12 14:58:27 cg Exp $'
|
2620
|
300 |
! !
|