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