author | Claus Gittinger <cg@exept.de> |
Tue, 08 Feb 2000 18:59:30 +0100 | |
changeset 1687 | 70888239654f |
parent 1685 | 7755214df380 |
child 1689 | ecb51abe4a6b |
permissions | -rw-r--r-- |
375 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1401 | 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 |
||
14 |
View subclass:#NoteBookView |
|
15 |
instanceVariableNames:'list listHolder foregroundColor selection enabled action useIndex |
|
16 |
direction numberOfLines selectConditionBlock expandSelection |
|
1680 | 17 |
canvas canvasInset canvasFrameLevel canvasHolder halfLightColor |
18 |
halfShadowColor fitLastRow tabModus lastComputedExtent keepCanvas |
|
1682 | 19 |
tabMargin activeForegroundColor drawLightColor edgeStyle' |
20 |
classVariableNames:'DefaultForegroundColor DefaultActiveForegroundColor |
|
21 |
DefaultShadowColor DefaultHalfShadowColor DefaultLightColor |
|
22 |
DefaultHalfLightColor DefaultEdgeStyle' |
|
1401 | 23 |
poolDictionaries:'' |
24 |
category:'Views-Layout' |
|
25 |
! |
|
26 |
||
27 |
Object subclass:#Tab |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
28 |
instanceVariableNames:'label model printableLabel disabledLabel lineNr layout extent |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
29 |
accessCharacter' |
1401 | 30 |
classVariableNames:'' |
31 |
poolDictionaries:'' |
|
32 |
privateIn:NoteBookView |
|
33 |
! |
|
34 |
||
35 |
!NoteBookView class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
39 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
40 |
All Rights Reserved |
|
375 | 41 |
|
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
" |
|
49 |
||
355 | 50 |
! |
51 |
||
52 |
documentation |
|
53 |
" |
|
1401 | 54 |
implements the noteBook. |
55 |
May also be used on its own (without a surrounding noteBook). |
|
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
408 | 59 |
|
60 |
[see also:] |
|
61 |
TabView |
|
355 | 62 |
" |
1401 | 63 |
|
408 | 64 |
! |
355 | 65 |
|
408 | 66 |
examples |
67 |
" |
|
68 |
tabs at top ( default ) |
|
69 |
[exBegin] |
|
1401 | 70 |
|top tab| |
375 | 71 |
|
1401 | 72 |
top := StandardSystemView extent:250@100. |
1683 | 73 |
tab := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
1401 | 74 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
75 |
tab action:[:aName| Transcript showCR:aName]. |
|
408 | 76 |
top open. |
77 |
[exEnd] |
|
78 |
||
79 |
||
80 |
tabs at bottom |
|
81 |
[exBegin] |
|
1401 | 82 |
|top tab| |
375 | 83 |
|
1401 | 84 |
top := StandardSystemView extent:250@100. |
1683 | 85 |
tab := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
1401 | 86 |
tab direction:#bottom. |
87 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
88 |
tab action:[:aName| Transcript showCR:aName]. |
|
375 | 89 |
top open. |
408 | 90 |
[exEnd] |
375 | 91 |
|
408 | 92 |
tabs at left |
93 |
[exBegin] |
|
1401 | 94 |
|top tab| |
375 | 95 |
|
1401 | 96 |
top := StandardSystemView extent:100@200. |
1683 | 97 |
tab := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
1401 | 98 |
tab direction:#left. |
99 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
100 |
tab action:[:aName| Transcript showCR:aName]. |
|
408 | 101 |
top open. |
102 |
[exEnd] |
|
375 | 103 |
|
408 | 104 |
tabs at right |
105 |
[exBegin] |
|
1401 | 106 |
|top tab| |
375 | 107 |
|
1401 | 108 |
top := StandardSystemView extent:100@200. |
1683 | 109 |
tab := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
1401 | 110 |
tab direction:#right. |
111 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
112 |
tab action:[:aName| Transcript showCR:aName]. |
|
375 | 113 |
top open. |
408 | 114 |
[exEnd] |
375 | 115 |
|
116 |
||
408 | 117 |
" |
1401 | 118 |
|
119 |
! ! |
|
120 |
||
121 |
!NoteBookView class methodsFor:'defaults'! |
|
122 |
||
123 |
defaultFont |
|
124 |
^ MenuView defaultFont |
|
1682 | 125 |
! |
126 |
||
127 |
updateStyleCache |
|
128 |
" |
|
129 |
self updateStyleCache |
|
130 |
" |
|
131 |
DefaultForegroundColor := StyleSheet colorAt:#'noteBook.foregroundColor'. |
|
132 |
DefaultForegroundColor isNil ifTrue:[ |
|
133 |
DefaultForegroundColor := StyleSheet colorAt:#'button.foregroundColor'. |
|
134 |
]. |
|
135 |
||
136 |
DefaultActiveForegroundColor := StyleSheet colorAt:#'noteBook.activeForegroundColor'. |
|
137 |
DefaultActiveForegroundColor isNil ifTrue:[ |
|
138 |
DefaultActiveForegroundColor := StyleSheet colorAt:#'button.activeForegroundColor' |
|
139 |
]. |
|
140 |
||
141 |
DefaultLightColor := StyleSheet colorAt:#'noteBook.lightColor'. |
|
142 |
DefaultLightColor isNil ifTrue:[ |
|
143 |
DefaultLightColor := StyleSheet colorAt:'button.lightColor' |
|
144 |
]. |
|
145 |
DefaultHalfLightColor := StyleSheet colorAt:#'noteBook.halfLightColor'. |
|
146 |
DefaultHalfLightColor isNil ifTrue:[ |
|
147 |
DefaultHalfLightColor := StyleSheet colorAt:#'button.halfLightColor' |
|
148 |
]. |
|
149 |
||
150 |
DefaultShadowColor := StyleSheet colorAt:#'noteBook.shadowColor'. |
|
151 |
DefaultShadowColor isNil ifTrue:[ |
|
152 |
DefaultShadowColor := StyleSheet colorAt:'button.shadowColor' |
|
153 |
]. |
|
154 |
DefaultHalfShadowColor := StyleSheet colorAt:#'noteBook.halfShadowColor'. |
|
155 |
DefaultHalfShadowColor isNil ifTrue:[ |
|
156 |
DefaultHalfShadowColor := StyleSheet colorAt:#'button.halfShadowColor' |
|
157 |
]. |
|
158 |
DefaultEdgeStyle := StyleSheet at:#'noteBook.edgeStyle'. |
|
159 |
DefaultEdgeStyle isNil ifTrue:[ |
|
160 |
DefaultEdgeStyle := StyleSheet at:#'button.edgeStyle' |
|
161 |
]. |
|
162 |
||
1683 | 163 |
DefaultEdgeStyle == #softWin95 ifFalse:[ |
1682 | 164 |
DefaultEdgeStyle := nil |
165 |
]. |
|
166 |
||
375 | 167 |
! ! |
168 |
||
169 |
!NoteBookView methodsFor:'accessing'! |
|
355 | 170 |
|
1401 | 171 |
action:oneArgBlock |
172 |
"set the action block to be performed on select; the argument to |
|
173 |
the block is the selected index or nil in case of no selection. |
|
174 |
" |
|
175 |
action := oneArgBlock. |
|
176 |
||
177 |
! |
|
178 |
||
375 | 179 |
canvas |
180 |
^ canvas |
|
181 |
! |
|
182 |
||
183 |
canvas:aCanvas |
|
184 |
"change canvas; the containter view |
|
185 |
" |
|
1401 | 186 |
aCanvas == canvas ifFalse:[ |
187 |
canvas notNil ifTrue:[ |
|
1413 | 188 |
keepCanvas ifTrue:[ |
189 |
canvas unmap. |
|
190 |
] ifFalse:[ |
|
191 |
canvas destroy. |
|
192 |
]. |
|
1401 | 193 |
]. |
194 |
(canvas := aCanvas) notNil ifTrue:[ |
|
195 |
tabModus := false. |
|
1680 | 196 |
self resizeCanvas. |
197 |
||
1549 | 198 |
(keepCanvas not |
199 |
or:[subViews size == 0 |
|
200 |
or:[(subViews includesIdentical:canvas) not]]) |
|
201 |
ifTrue:[ |
|
202 |
self addSubView:canvas. |
|
203 |
]. |
|
1687 | 204 |
realized ifTrue:[ |
205 |
canvas realize. |
|
206 |
]. |
|
1401 | 207 |
] |
208 |
]. |
|
209 |
! |
|
210 |
||
1680 | 211 |
canvasFrameLevel |
212 |
"inset of the canvas relative to my canvas boundery |
|
213 |
" |
|
214 |
^ canvasFrameLevel |
|
215 |
! |
|
216 |
||
217 |
canvasFrameLevel:aFrameLevel |
|
218 |
"inset of the canvas relative to my canvas boundery |
|
219 |
" |
|
220 |
canvasFrameLevel ~~ aFrameLevel ifTrue:[ |
|
221 |
canvasFrameLevel := aFrameLevel. |
|
222 |
self recomputeList. |
|
223 |
self invalidate. |
|
224 |
]. |
|
225 |
||
226 |
! |
|
227 |
||
228 |
canvasInset |
|
229 |
"inset of the canvas relativr to my frame |
|
230 |
" |
|
231 |
^ canvasInset |
|
232 |
! |
|
233 |
||
234 |
canvasInset:anInset |
|
235 |
"inset of the canvas relativr to my frame |
|
236 |
" |
|
237 |
anInset ~~ canvasInset ifTrue:[ |
|
238 |
canvasInset := anInset. |
|
239 |
self recomputeList. |
|
240 |
self invalidate. |
|
241 |
]. |
|
242 |
! |
|
243 |
||
1401 | 244 |
list |
245 |
"return the list of Tabs or Labels |
|
246 |
" |
|
247 |
^ list collect:[:aTab| aTab label ] |
|
248 |
||
249 |
! |
|
375 | 250 |
|
1401 | 251 |
list:aList |
252 |
"set the list |
|
253 |
" |
|
1438
5d710aed8366
oops - instvar name was overwritten
Claus Gittinger <cg@exept.de>
parents:
1433
diff
changeset
|
254 |
|size name| |
1401 | 255 |
|
1433 | 256 |
name := self selection. |
257 |
||
1401 | 258 |
list do:[:aTab| aTab removeDependent:self]. |
259 |
||
260 |
aList notNil ifTrue:[ |
|
261 |
list := aList collect:[:el| Tab label:el on:self]. |
|
262 |
list do:[:aTab| aTab addDependent:self]. |
|
263 |
] ifFalse:[ |
|
264 |
list := #() |
|
265 |
]. |
|
266 |
preferredExtent := nil. |
|
267 |
numberOfLines := nil. |
|
268 |
||
269 |
selection notNil ifTrue:[ |
|
1433 | 270 |
useIndex ifTrue:[ |
271 |
selection > list size ifTrue:[ |
|
272 |
selection := nil. |
|
273 |
self selectionChanged. |
|
274 |
] |
|
275 |
] ifFalse:[ |
|
276 |
selection := list findFirst:[:el| el label = name ]. |
|
277 |
selection == 0 ifTrue:[ |
|
278 |
selection := nil. |
|
279 |
self selectionChanged. |
|
280 |
] |
|
1401 | 281 |
] |
282 |
]. |
|
1680 | 283 |
self recomputeList. |
284 |
self invalidate. |
|
1401 | 285 |
! |
375 | 286 |
|
1401 | 287 |
listIndexOf:something |
288 |
"convert something to an index into list or nil. |
|
289 |
" |
|
290 |
|index| |
|
291 |
||
292 |
something isNil ifTrue:[^ nil ]. |
|
293 |
||
294 |
something isNumber ifTrue:[ |
|
295 |
index := something |
|
296 |
] ifFalse:[ |
|
297 |
index := list findFirst:[:aTab|aTab label = something]. |
|
298 |
index == 0 ifTrue:[ |
|
299 |
index := list findFirst:[:aTab|aTab printableLabel = something] |
|
300 |
] |
|
301 |
]. |
|
302 |
^ (index between:1 and:list size) ifTrue:[index] ifFalse:[nil] |
|
303 |
||
304 |
||
305 |
! |
|
306 |
||
307 |
useIndex |
|
308 |
"use index instead of name |
|
309 |
" |
|
310 |
^ useIndex |
|
311 |
||
312 |
||
313 |
! |
|
314 |
||
315 |
useIndex:aBoolean |
|
316 |
"set/clear the useIndex flag. If set, both actionBlock and change-messages |
|
317 |
are passed the index(indices) of the selection as argument. |
|
318 |
If clear, the value(s) (i.e. the selected string) is passed. |
|
319 |
Default is false." |
|
320 |
||
321 |
useIndex := aBoolean |
|
322 |
||
323 |
||
324 |
! ! |
|
325 |
||
326 |
!NoteBookView methodsFor:'accessing behavior'! |
|
327 |
||
328 |
enabled |
|
329 |
"returns true if tabs are enabled |
|
330 |
" |
|
331 |
^ enabled |
|
332 |
! |
|
333 |
||
334 |
enabled:aState |
|
335 |
"set enabled state |
|
336 |
" |
|
337 |
|state| |
|
338 |
||
339 |
state := aState ? true. |
|
340 |
||
341 |
enabled ~~ state ifTrue:[ |
|
342 |
enabled := state. |
|
343 |
self invalidate. |
|
375 | 344 |
] |
345 |
! |
|
346 |
||
1413 | 347 |
keepCanvas:aBoolean |
348 |
"if false (the default), the previous canvas is destroyed, whenever |
|
349 |
a new canvas is set. |
|
350 |
if true, it is unmapped and kept. |
|
351 |
Set this flag, if the application changes the canvas but wants |
|
352 |
them to be kept for fast switching." |
|
353 |
||
354 |
keepCanvas := aBoolean. |
|
355 |
! |
|
356 |
||
1401 | 357 |
selectConditionBlock |
358 |
"get the conditionBlock; this block is evaluated before a selection |
|
359 |
change is performed; the change will not be done, if the evaluation |
|
360 |
returns false. The argument to the block is the selection index |
|
361 |
" |
|
362 |
^ selectConditionBlock |
|
432 | 363 |
! |
364 |
||
1401 | 365 |
selectConditionBlock:aOneArgBlock |
366 |
"get the conditionBlock; this block is evaluated before a selection |
|
367 |
change is performed; the change will not be done, if the evaluation |
|
368 |
returns false. The argument to the block is the selection index |
|
369 |
" |
|
370 |
selectConditionBlock := aOneArgBlock |
|
432 | 371 |
! ! |
372 |
||
1401 | 373 |
!NoteBookView methodsFor:'accessing channels/holders'! |
432 | 374 |
|
375 | 375 |
canvasHolder |
1401 | 376 |
"get the model, which keeps the canvas, a kind of SimpleView |
377 |
" |
|
375 | 378 |
^ canvasHolder |
355 | 379 |
! |
380 |
||
375 | 381 |
canvasHolder:aValueHolder |
1401 | 382 |
"set the model, which keeps the canvas, a kind of SimpleView |
383 |
" |
|
384 |
canvasHolder removeDependent:self. |
|
385 |
||
386 |
(canvasHolder := aValueHolder) notNil ifTrue:[ |
|
387 |
canvasHolder addDependent:self. |
|
388 |
self canvas:(canvasHolder value) |
|
389 |
] |
|
390 |
||
391 |
||
392 |
! |
|
393 |
||
394 |
listHolder |
|
395 |
"get the model, which keeps the list of Tabs or Labels |
|
396 |
" |
|
397 |
^ listHolder |
|
398 |
! |
|
399 |
||
400 |
listHolder:aValueHolder |
|
401 |
"set the model, which keeps the list of Tabs or Labels |
|
402 |
" |
|
403 |
listHolder removeDependent:self. |
|
404 |
||
405 |
(listHolder := aValueHolder) notNil ifTrue:[ |
|
406 |
listHolder addDependent:self. |
|
407 |
self list:listHolder value. |
|
375 | 408 |
]. |
432 | 409 |
! |
410 |
||
1401 | 411 |
model:aValueHolder |
412 |
"set the model, which keeps the selection |
|
413 |
" |
|
414 |
super model:aValueHolder. |
|
415 |
||
416 |
model notNil ifTrue:[ |
|
417 |
self selection:(model value) |
|
418 |
] |
|
419 |
! ! |
|
420 |
||
421 |
!NoteBookView methodsFor:'accessing dimension'! |
|
422 |
||
423 |
maxTabHeight |
|
424 |
|e y| |
|
425 |
||
426 |
e := self preferredExtent. |
|
427 |
y := self isHorizontal ifTrue:[e y] ifFalse:[e x]. |
|
428 |
^ y - (expandSelection y) |
|
432 | 429 |
! |
430 |
||
1401 | 431 |
preferredExtent |
432 |
"compute max extent x/y based on one line |
|
433 |
" |
|
434 |
|x "{ Class:SmallInteger }" |
|
435 |
y "{ Class:SmallInteger }" |
|
436 |
| |
|
437 |
preferredExtent isNil ifTrue:[ |
|
438 |
y := 0. |
|
439 |
x := 0. |
|
440 |
||
441 |
list notEmpty ifTrue:[ |
|
442 |
list do:[:aTab| |
|
443 |
x := x + aTab preferredExtentX. |
|
444 |
y := y max:(aTab preferredExtentY). |
|
445 |
] |
|
446 |
]. |
|
447 |
y := y + (expandSelection y). |
|
448 |
x := x + (expandSelection x). |
|
449 |
preferredExtent := self isHorizontal ifTrue:[x @ y] ifFalse:[y @ x] |
|
450 |
]. |
|
451 |
^ preferredExtent |
|
452 |
! |
|
453 |
||
454 |
preferredSizeXorY |
|
455 |
"returns preferred size dependant on the current view layout and |
|
456 |
the direction of the tabs |
|
457 |
" |
|
458 |
|e y| |
|
459 |
||
460 |
list isEmpty ifTrue:[^ 0]. |
|
461 |
||
462 |
y := self maxTabHeight. |
|
463 |
e := expandSelection y. |
|
464 |
||
465 |
numberOfLines isNil ifTrue:[ |
|
466 |
self shown ifFalse:[^ y + e ]. |
|
467 |
self recomputeList. |
|
468 |
]. |
|
469 |
^ numberOfLines * y + e |
|
419 | 470 |
! ! |
471 |
||
472 |
!NoteBookView methodsFor:'accessing look'! |
|
473 |
||
1442 | 474 |
activeForegroundColor |
475 |
"get the color to be used for drawing text |
|
476 |
" |
|
477 |
^ activeForegroundColor |
|
478 |
! |
|
479 |
||
1401 | 480 |
backgroundColor |
481 |
"get backgroundColor of the notebook view |
|
419 | 482 |
" |
1401 | 483 |
^ viewBackground |
408 | 484 |
! |
485 |
||
1682 | 486 |
drawLightColor |
487 |
"get the color to be used for lighted edges; bug fix caused by common |
|
488 |
drawEdge |
|
489 |
" |
|
490 |
^ drawLightColor |
|
491 |
! |
|
492 |
||
1401 | 493 |
foregroundColor |
494 |
"get the color to be used for drawing text |
|
419 | 495 |
" |
1401 | 496 |
^ foregroundColor |
497 |
! |
|
498 |
||
499 |
foregroundColor:aColor |
|
500 |
"set the color to be used for drawing text |
|
501 |
" |
|
502 |
aColor ~= foregroundColor ifTrue:[ |
|
503 |
foregroundColor := aColor. |
|
504 |
||
505 |
shown ifTrue:[ |
|
506 |
self invalidate |
|
507 |
] |
|
508 |
] |
|
408 | 509 |
|
419 | 510 |
! |
511 |
||
1401 | 512 |
halfLightColor |
513 |
"get the color to be used for drawing text |
|
419 | 514 |
" |
1401 | 515 |
^ halfLightColor |
516 |
! |
|
517 |
||
518 |
halfShadowColor |
|
519 |
^ halfShadowColor |
|
520 |
! |
|
521 |
||
522 |
shadowColor |
|
523 |
"get the color to be used for shadowed edges |
|
524 |
" |
|
525 |
^ shadowColor |
|
1684 | 526 |
! |
527 |
||
528 |
shadowColor:aColor |
|
529 |
"get the color to be used for shadowed edges |
|
530 |
" |
|
531 |
Transcript showCR:aColor. |
|
532 |
super shadowColor:aColor |
|
533 |
! |
|
534 |
||
535 |
viewBackground:aColor |
|
536 |
"get backgroundColor of the notebook view |
|
537 |
" |
|
538 |
super viewBackground:aColor. |
|
539 |
||
540 |
(edgeStyle isNil and:[viewBackground isColor]) ifTrue:[ |
|
541 |
halfShadowColor := shadowColor. |
|
542 |
halfLightColor := lightColor. |
|
543 |
drawLightColor := lightColor. |
|
544 |
]. |
|
375 | 545 |
! ! |
546 |
||
1401 | 547 |
!NoteBookView methodsFor:'accessing style'! |
548 |
||
549 |
direction |
|
550 |
"returns the direction of tabs as symbol. On default the value is |
|
551 |
set to #top. Valid symbols are: |
|
552 |
#top arrange tabs to be on top of a view |
|
553 |
#bottom arrange tabs to be on bottom of a view |
|
554 |
#left arrange tabs to be on left of a view |
|
555 |
#right arrange tabs to be on right of a view |
|
556 |
" |
|
557 |
^ direction |
|
558 |
||
559 |
! |
|
560 |
||
561 |
direction:aDirection |
|
562 |
"change the direction of tabs. On default the value is set to #top. |
|
563 |
Valid symbols are: |
|
564 |
#top arrange tabs to be on top of a view |
|
565 |
#bottom arrange tabs to be on bottom of a view |
|
566 |
#left arrange tabs to be on left of a view |
|
567 |
#right arrange tabs to be on right of a view |
|
568 |
" |
|
569 |
direction ~~ aDirection ifTrue:[ |
|
570 |
direction := aDirection. |
|
571 |
preferredExtent := nil. |
|
572 |
numberOfLines := nil. |
|
573 |
self invalidate. |
|
574 |
]. |
|
575 |
! |
|
375 | 576 |
|
1401 | 577 |
fitLastRow |
578 |
"in case of true, the last row is expanded to the view size like all |
|
579 |
other raws. In case of false all the tabs in the last raw keep their |
|
580 |
preferred extent (x or y) dependant on the direction. |
|
581 |
" |
|
582 |
^ fitLastRow |
|
583 |
! |
|
584 |
||
585 |
fitLastRow:aBool |
|
586 |
"in case of true, the last row is expanded to the view size like all |
|
587 |
other raws. In case of false all the tabs in the last raw keep their |
|
588 |
preferred extent (x or y) dependant on the direction. |
|
375 | 589 |
" |
1401 | 590 |
fitLastRow := aBool |
591 |
! |
|
592 |
||
593 |
tabModus |
|
594 |
^ tabModus |
|
595 |
! |
|
375 | 596 |
|
1401 | 597 |
tabModus:aBoolean |
598 |
||
599 |
tabModus ~~ aBoolean ifTrue:[ |
|
600 |
(aBoolean and:[canvas notNil]) ifFalse:[ |
|
601 |
tabModus := aBoolean. |
|
602 |
numberOfLines := nil. |
|
603 |
shown ifTrue:[self invalidate] |
|
604 |
] |
|
605 |
] |
|
375 | 606 |
|
607 |
! ! |
|
608 |
||
609 |
!NoteBookView methodsFor:'change & update'! |
|
610 |
||
1401 | 611 |
update:something with:aParameter from:changedObject |
612 |
"one of my models changed its value |
|
613 |
" |
|
614 |
|idx tab| |
|
615 |
||
616 |
changedObject == model ifTrue:[^ self selection:model value]. |
|
617 |
changedObject == listHolder ifTrue:[^ self list:(listHolder value)]. |
|
618 |
changedObject == enableChannel ifTrue:[^ self enabled:enableChannel value]. |
|
1413 | 619 |
changedObject == canvasHolder ifTrue:[^ self canvas:canvasHolder value]. |
1401 | 620 |
|
621 |
(idx := list findFirst:[:aTab| aTab label == changedObject]) ~~ 0 ifTrue:[ |
|
622 |
tab := list at:idx. |
|
623 |
||
624 |
idx == selection ifTrue:[ |
|
625 |
tab isEnabled ifFalse:[ |
|
626 |
^ self selection:nil |
|
627 |
] |
|
628 |
]. |
|
629 |
tab label:(tab label) on:self. |
|
630 |
self invalidateTab:tab |
|
631 |
] |
|
632 |
! ! |
|
633 |
||
634 |
!NoteBookView methodsFor:'drawing'! |
|
635 |
||
636 |
invalidateTab:aTab |
|
637 |
"invalidate a tab |
|
638 |
" |
|
639 |
shown ifTrue:[ |
|
640 |
self invalidate:(self computeLayoutForTab:aTab) |
|
641 |
] |
|
642 |
! |
|
643 |
||
644 |
redrawX:x y:y width:w height:h |
|
645 |
"a region must be redrawn |
|
375 | 646 |
" |
1401 | 647 |
|savClip selTab damage lyt savLyt| |
648 |
||
649 |
self shown ifFalse:[ |
|
650 |
^ self |
|
651 |
]. |
|
652 |
numberOfLines isNil ifTrue:[ |
|
653 |
self recomputeList. |
|
654 |
^ self invalidate |
|
655 |
]. |
|
656 |
selTab := selection notNil ifTrue:[list at:selection] ifFalse:[nil]. |
|
657 |
||
658 |
(selTab notNil and:[selTab lineNr ~~ 1]) ifTrue:[ |
|
659 |
self makeToBaseLine:(selTab lineNr). |
|
660 |
^ self invalidate |
|
661 |
]. |
|
662 |
||
663 |
self paint:(self viewBackground). |
|
664 |
self fillRectangleX:x y:y width:w height:h. |
|
665 |
||
666 |
savClip := clipRect. |
|
667 |
damage := Rectangle left:x top:y width:w height:h. |
|
668 |
self clippingRectangle:damage. |
|
669 |
||
670 |
list notEmpty ifTrue:[ |
|
671 |
numberOfLines to:1 by:-1 do:[:aLnNr| |
|
672 |
list reverseDo:[:aTab| |
|
673 |
( aTab lineNr == aLnNr |
|
674 |
and:[aTab ~~ selTab |
|
675 |
and:[aTab intersects:damage]] |
|
676 |
) ifTrue:[ |
|
677 |
aTab redrawAt:direction selected:false on:self |
|
678 |
] |
|
679 |
] |
|
680 |
] |
|
681 |
] ifFalse:[ |
|
682 |
selTab := nil |
|
683 |
]. |
|
684 |
||
685 |
tabModus ifFalse:[ |
|
686 |
lyt := self computeBorderLayout. |
|
1682 | 687 |
self drawEdgesForX:lyt left |
688 |
y:lyt top |
|
689 |
width:lyt width |
|
690 |
height:lyt height |
|
1685 | 691 |
level:canvasFrameLevel |
1682 | 692 |
shadow:shadowColor |
693 |
light:lightColor |
|
694 |
halfShadow:halfShadowColor |
|
695 |
halfLight:halfLightColor |
|
696 |
style:edgeStyle |
|
1401 | 697 |
]. |
698 |
||
699 |
selTab notNil ifTrue:[ |
|
700 |
lyt := self computeLayoutForTab:selTab. |
|
701 |
||
702 |
(lyt intersects:damage) ifTrue:[ |
|
703 |
savLyt := selTab layout. |
|
704 |
selTab layout:lyt. |
|
705 |
selTab redrawAt:direction selected:true on:self. |
|
1659 | 706 |
|
707 |
(self hasFocus and:[styleSheet name == #win95]) ifTrue:[ |
|
708 |
selTab drawWin95FocusFrameOn:self |
|
709 |
]. |
|
1401 | 710 |
selTab layout:savLyt. |
711 |
] |
|
712 |
]. |
|
713 |
self clippingRectangle:savClip |
|
714 |
! ! |
|
715 |
||
716 |
!NoteBookView methodsFor:'event handling'! |
|
717 |
||
718 |
buttonPress:button x:x y:y |
|
719 |
"a button is pressed; find tab under point and set the selection |
|
720 |
" |
|
721 |
|idx| |
|
722 |
||
723 |
(enabled and:[list notEmpty]) ifTrue:[ |
|
724 |
idx := list findFirst:[:aTab| aTab containsPointX:x y:y ]. |
|
375 | 725 |
|
1407 | 726 |
(idx ~~ 0 and:[idx ~~ selection and:[(list at:idx) isEnabled]]) ifTrue:[ |
1401 | 727 |
self selection:idx |
728 |
] |
|
729 |
] |
|
730 |
! |
|
731 |
||
732 |
keyPress:aKey x:x y:y |
|
733 |
"selection might change; look for corresponding list entry |
|
734 |
" |
|
1659 | 735 |
<resource: #keyboard (#CursorRight #CursorLeft #CursorUp #CursorDown)> |
1407 | 736 |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
737 |
|sensor size index n key| |
1401 | 738 |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
739 |
(enabled and:[(size := list size) ~~ 0]) ifFalse:[ |
1657
061c167ce3db
if disabled; call super keyPress:x:y to handle focusSequence
ca
parents:
1549
diff
changeset
|
740 |
^ super keyPress:aKey x:x y:y |
1401 | 741 |
]. |
742 |
||
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
743 |
(self processAccessCharacter:aKey) ifTrue:[ |
1407 | 744 |
^ self |
745 |
]. |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
746 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
747 |
(self processShortcutKey:aKey) ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
748 |
^ self |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
749 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
750 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
751 |
(size > 1 and:[aKey isSymbol and:[aKey startsWith:'Cursor']]) ifFalse:[ |
1659 | 752 |
^ super keyPress:aKey x:x y:y |
753 |
]. |
|
1407 | 754 |
|
1659 | 755 |
self isHorizontal ifTrue:[ |
756 |
(aKey == #CursorRight or:[aKey == #CursorLeft]) ifFalse:[ |
|
757 |
^ self |
|
758 |
]. |
|
759 |
key := aKey. |
|
760 |
] ifFalse:[ |
|
761 |
aKey == #CursorUp ifTrue:[key := #CursorLeft] |
|
762 |
ifFalse:[aKey == #CursorDown ifTrue:[key := #CursorRight] |
|
763 |
ifFalse:[ ^ self]]. |
|
1401 | 764 |
]. |
765 |
||
1407 | 766 |
(sensor := self sensor) notNil ifTrue:[ |
767 |
n := 1 + (sensor compressKeyPressEventsWithKey:aKey). |
|
768 |
n := (n \\ size) max:1. |
|
769 |
||
1659 | 770 |
key == #CursorRight ifTrue:[ |
1407 | 771 |
index := selection ? 1. |
772 |
[ (index := index + 1) > size ifTrue:[index := 1]. |
|
773 |
(self isSelectable:index) ifTrue:[n := n - 1]. |
|
774 |
n ~~ 0 |
|
775 |
] whileTrue. |
|
776 |
] ifFalse:[ |
|
777 |
index := selection ? size. |
|
778 |
[ (index := index - 1) == 0 ifTrue:[index := size]. |
|
779 |
(self isSelectable:index) ifTrue:[n := n -1]. |
|
780 |
n ~~ 0 |
|
781 |
] whileTrue. |
|
782 |
]. |
|
783 |
self selection:index |
|
784 |
] |
|
1401 | 785 |
! |
786 |
||
1677 | 787 |
processShortcutKeyEvent:event |
788 |
^ self processShortcutKey:(event key) |
|
789 |
! |
|
790 |
||
1401 | 791 |
sizeChanged:how |
792 |
"size of view changed |
|
793 |
" |
|
794 |
super sizeChanged:how. |
|
795 |
||
796 |
list notEmpty ifTrue:[ |
|
1403 | 797 |
lastComputedExtent ~= self extent ifTrue:[ |
798 |
numberOfLines := nil. |
|
799 |
] |
|
1680 | 800 |
]. |
801 |
shown ifTrue:[self invalidate]. |
|
802 |
self resizeCanvas. |
|
1401 | 803 |
! ! |
804 |
||
1659 | 805 |
!NoteBookView methodsFor:'focus handling'! |
806 |
||
807 |
showFocus:explicit |
|
808 |
"got the keyboard focus |
|
809 |
" |
|
810 |
|tab| |
|
811 |
||
812 |
styleSheet name == #win95 ifTrue:[ |
|
813 |
(tab := self selectedTab) notNil ifTrue:[ |
|
814 |
self invalidateTab:tab |
|
815 |
] |
|
816 |
] ifFalse:[ |
|
817 |
super showFocus:explicit |
|
818 |
] |
|
819 |
||
820 |
! |
|
821 |
||
822 |
showNoFocus:explicit |
|
823 |
"lost the keyboard focus |
|
824 |
" |
|
825 |
|tab| |
|
826 |
||
827 |
styleSheet name == #win95 ifTrue:[ |
|
828 |
(tab := self selectedTab) notNil ifTrue:[ |
|
829 |
self invalidateTab:tab |
|
830 |
] |
|
831 |
] ifFalse:[ |
|
832 |
super showNoFocus:explicit |
|
833 |
] |
|
834 |
! ! |
|
835 |
||
1687 | 836 |
!NoteBookView methodsFor:'initialization & release'! |
1401 | 837 |
|
838 |
destroy |
|
839 |
"remove dependencies |
|
840 |
" |
|
841 |
list removeDependent:self. |
|
842 |
||
843 |
listHolder removeDependent:self. |
|
844 |
enableChannel removeDependent:self. |
|
845 |
canvasHolder removeDependent:self. |
|
846 |
||
847 |
super destroy. |
|
848 |
! |
|
849 |
||
850 |
initStyle |
|
851 |
"setup style attributes |
|
852 |
" |
|
1442 | 853 |
|clr| |
854 |
||
1401 | 855 |
super initStyle. |
1682 | 856 |
tabModus := false. |
857 |
edgeStyle := DefaultEdgeStyle. |
|
1442 | 858 |
|
1401 | 859 |
self font:self class defaultFont. |
1682 | 860 |
drawLightColor := Color veryLightGray onDevice:device. |
1442 | 861 |
|
1682 | 862 |
clr := DefaultForegroundColor ? Black. |
863 |
foregroundColor := clr onDevice:device. |
|
864 |
||
865 |
clr := DefaultForegroundColor ? foregroundColor. |
|
866 |
activeForegroundColor := clr onDevice:device. |
|
867 |
||
868 |
clr := DefaultShadowColor ? Black. |
|
869 |
shadowColor := clr onDevice:device. |
|
870 |
||
871 |
clr := DefaultLightColor ? White. |
|
872 |
lightColor := clr onDevice:device. |
|
1442 | 873 |
|
1682 | 874 |
edgeStyle isNil ifTrue:[ |
875 |
halfShadowColor := shadowColor. |
|
876 |
halfLightColor := lightColor. |
|
877 |
drawLightColor := lightColor. |
|
878 |
] ifFalse:[ |
|
879 |
||
880 |
(clr := DefaultHalfShadowColor) isNil ifTrue:[ |
|
881 |
clr := shadowColor lightened |
|
1442 | 882 |
]. |
1682 | 883 |
halfShadowColor := clr onDevice:device. |
884 |
||
885 |
(clr := DefaultHalfLightColor) isNil ifTrue:[ |
|
886 |
clr := lightColor darkened. |
|
887 |
]. |
|
888 |
halfLightColor := clr onDevice:device. |
|
889 |
||
890 |
edgeStyle == #soft ifTrue:[ |
|
891 |
drawLightColor := halfShadowColor |
|
892 |
] ifFalse:[ |
|
893 |
drawLightColor := Color veryLightGray onDevice:device. |
|
894 |
] |
|
1442 | 895 |
]. |
896 |
||
897 |
||
1401 | 898 |
! |
899 |
||
900 |
initialize |
|
901 |
"setup default attributes |
|
902 |
" |
|
903 |
super initialize. |
|
904 |
||
905 |
self cursor:Cursor hand. |
|
906 |
||
1680 | 907 |
list := #(). |
908 |
useIndex := true. |
|
909 |
direction := #top. |
|
910 |
fitLastRow := true. |
|
911 |
enabled := true. |
|
1685 | 912 |
expandSelection := StyleSheet at:#'noteBook.expandSelection' default:8@8. |
913 |
canvasInset := StyleSheet at:#'noteBook.canvasInset' default:1@1. |
|
914 |
canvasFrameLevel := StyleSheet at:#'noteBook.canvasFrameLevel' default:2. |
|
915 |
tabMargin := StyleSheet at:#'noteBook.canvasTabMargin' default:2. |
|
1680 | 916 |
keepCanvas := false. |
1401 | 917 |
|
918 |
self lineWidth:0. |
|
919 |
||
920 |
canvas notNil ifTrue:[ |
|
921 |
canvas := canvas in:self. |
|
922 |
]. |
|
375 | 923 |
|
1403 | 924 |
! |
925 |
||
926 |
realize |
|
927 |
||
928 |
(canvas notNil and:[numberOfLines isNil]) ifTrue:[ |
|
929 |
self recomputeList |
|
930 |
]. |
|
931 |
super realize. |
|
1401 | 932 |
! ! |
933 |
||
934 |
!NoteBookView methodsFor:'layout'! |
|
935 |
||
936 |
computeBorderLayout |
|
937 |
|xL yT xR yB tab| |
|
938 |
||
939 |
tab := list detect:[:aTab| aTab lineNr == 1] ifNone:nil. |
|
940 |
xL := 0. |
|
941 |
yT := 0. |
|
942 |
xR := width. |
|
943 |
yB := height. |
|
944 |
||
945 |
tab notNil ifTrue:[ |
|
946 |
direction == #top ifTrue:[yT := tab layout bottom] |
|
947 |
ifFalse:[direction == #bottom ifTrue:[yB := tab layout top] |
|
948 |
ifFalse:[direction == #left ifTrue:[xL := tab layout right] |
|
949 |
ifFalse:[xR := tab layout left]]] |
|
950 |
]. |
|
951 |
^ Rectangle left:xL top:yT right:xR bottom:yB |
|
952 |
||
953 |
! |
|
954 |
||
955 |
computeLayoutForTab:aTab |
|
956 |
"calculate extent of a tab |
|
957 |
" |
|
958 |
|layout x y w h level| |
|
959 |
||
960 |
layout := aTab layout. |
|
1658 | 961 |
|
962 |
self selectedTab == aTab ifFalse:[ |
|
963 |
^ layout |
|
964 |
]. |
|
1401 | 965 |
|
1680 | 966 |
level := canvasFrameLevel abs. |
1658 | 967 |
layout := layout copy. |
968 |
w := expandSelection x. |
|
969 |
h := expandSelection y. |
|
970 |
x := w // 2. |
|
971 |
y := h // 2. |
|
972 |
||
973 |
(direction == #top or:[direction == #bottom]) ifTrue:[ |
|
974 |
layout setLeft:(layout left - x). |
|
975 |
layout width:(layout width + w). |
|
976 |
layout height:(layout height + y + level). |
|
1401 | 977 |
|
1658 | 978 |
direction == #top ifTrue:[ |
979 |
layout setTop:(layout top - y). |
|
375 | 980 |
] ifFalse:[ |
1658 | 981 |
layout setTop:(layout top - level). |
982 |
]. |
|
983 |
^ layout |
|
1401 | 984 |
]. |
1658 | 985 |
|
986 |
layout setTop:(layout top - x). |
|
987 |
layout height:(layout height + w). |
|
988 |
layout width:(layout width + y + level). |
|
989 |
||
990 |
direction == #left ifTrue:[ |
|
991 |
layout setLeft:(layout left - y). |
|
992 |
] ifFalse:[ |
|
993 |
layout setLeft:(layout left - level) |
|
994 |
]. |
|
995 |
||
996 |
^ layout |
|
1401 | 997 |
! |
998 |
||
999 |
makeToBaseLine:aLnNr |
|
1000 |
|layout1 layoutN topN top1 leftN left1 |
|
1001 |
nr "{ Class:SmallInteger }" |
|
1002 |
| |
|
1003 |
nr := list findFirst:[:aTab| aTab lineNr == 1]. |
|
1004 |
layout1 := (list at:nr) layout. |
|
1005 |
||
1006 |
nr := list findFirst:[:aTab| aTab lineNr == aLnNr]. |
|
1007 |
layoutN := (list at:nr) layout. |
|
1008 |
||
1009 |
self isHorizontal ifTrue:[ |
|
1010 |
top1 := layout1 top. |
|
1011 |
topN := layoutN top. |
|
1012 |
||
1013 |
list do:[:el| |
|
1014 |
(nr := el lineNr) == 1 ifTrue:[ |
|
1015 |
el layout setTop:topN. el lineNr:aLnNr |
|
1016 |
] ifFalse:[ |
|
1017 |
nr == aLnNr ifTrue:[ |
|
1018 |
el layout setTop:top1. el lineNr:1 |
|
1019 |
] |
|
1020 |
] |
|
375 | 1021 |
] |
1022 |
] ifFalse:[ |
|
1401 | 1023 |
left1 := layout1 left. |
1024 |
leftN := layoutN left. |
|
1025 |
||
1026 |
list do:[:el| |
|
1027 |
(nr := el lineNr) == 1 ifTrue:[ |
|
1028 |
el layout setLeft:leftN. el lineNr:aLnNr |
|
1029 |
] ifFalse:[ |
|
1030 |
nr == aLnNr ifTrue:[ |
|
1031 |
el layout setLeft:left1. el lineNr:1 |
|
1032 |
] |
|
1033 |
] |
|
1034 |
] |
|
1035 |
] |
|
1036 |
||
1037 |
! |
|
1038 |
||
1039 |
recomputeList |
|
1040 |
"recompute list |
|
1041 |
" |
|
1042 |
numberOfLines := 1. |
|
1403 | 1043 |
lastComputedExtent := self extent. |
1401 | 1044 |
|
1680 | 1045 |
list size ~~ 0 ifTrue:[ |
1401 | 1046 |
self isHorizontal ifTrue:[ |
1047 |
self recomputeListHorizontal |
|
1048 |
] ifFalse:[ |
|
1049 |
self recomputeListVertical |
|
1050 |
] |
|
1051 |
]. |
|
1680 | 1052 |
self resizeCanvas. |
1401 | 1053 |
! |
1054 |
||
1055 |
recomputeListHorizontal |
|
1056 |
"recompute list |
|
1057 |
" |
|
1058 |
|layout lastLyt checkDir |
|
1059 |
xLeft "{ Class:SmallInteger }" |
|
1060 |
yTop "{ Class:SmallInteger }" |
|
1061 |
tabWidth "{ Class:SmallInteger }" |
|
1062 |
tabHeight "{ Class:SmallInteger }" |
|
1063 |
lineWidth "{ Class:SmallInteger }" |
|
1064 |
startX "{ Class:SmallInteger }" |
|
1065 |
delta "{ Class:SmallInteger }" |
|
1066 |
first "{ Class:SmallInteger }" |
|
1067 |
last "{ Class:SmallInteger }" |
|
1068 |
| |
|
1680 | 1069 |
startX := expandSelection x // 2 + canvasFrameLevel abs - 2. |
1401 | 1070 |
lineWidth := self width - startX. |
1071 |
tabHeight := self maxTabHeight. |
|
1072 |
xLeft := startX. |
|
1680 | 1073 |
yTop := expandSelection y // 2 + tabMargin. |
1401 | 1074 |
|
1075 |
checkDir := canvas isNil ifTrue:[#top] ifFalse:[#bottom]. |
|
1076 |
||
1077 |
direction == #bottom ifTrue:[ |
|
1078 |
yTop := self height - tabHeight - yTop |
|
1079 |
]. |
|
1080 |
||
1081 |
list do:[:aTab| |
|
1082 |
tabWidth := aTab preferredExtentX. |
|
1083 |
||
1084 |
(xLeft + tabWidth > lineWidth and:[xLeft ~~ startX]) ifTrue:[ |
|
1085 |
numberOfLines := numberOfLines + 1. |
|
1086 |
xLeft := startX. |
|
1087 |
]. |
|
1088 |
aTab lineNr:numberOfLines. |
|
1089 |
aTab layout:(Rectangle left:xLeft top:yTop width:tabWidth height:tabHeight). |
|
1090 |
xLeft := xLeft + tabWidth |
|
1091 |
]. |
|
1092 |
||
1093 |
numberOfLines ~~ 1 ifTrue:[ |
|
1094 |
last := numberOfLines. |
|
1095 |
delta := direction == #bottom ifFalse:[tabHeight] |
|
1096 |
ifTrue:[tabHeight negated]. |
|
1097 |
||
1098 |
list reverseDo:[:aTab| |
|
1099 |
aTab lineNr ~~ last ifTrue:[ |
|
1100 |
last := aTab lineNr. |
|
1101 |
yTop := yTop + delta |
|
1102 |
]. |
|
1103 |
aTab layout setTop:yTop |
|
1104 |
] |
|
1105 |
]. |
|
1106 |
tabModus ifTrue:[ |
|
1107 |
layout := (list at:1) layout. |
|
1108 |
delta := direction == #top ifTrue:[self height - layout bottom] |
|
1109 |
ifFalse:[layout top negated]. |
|
1110 |
||
1111 |
list do:[:aTab| aTab layout setTop:(aTab layout top + delta)]. |
|
1112 |
]. |
|
1113 |
||
1114 |
"/ FIT LINES |
|
1115 |
(numberOfLines ~~ 1 or:[fitLastRow]) ifFalse:[ |
|
1116 |
^ self |
|
1117 |
]. |
|
1118 |
||
1119 |
first := 1. |
|
1120 |
||
1121 |
1 to:numberOfLines do:[:aLnNr| |
|
1122 |
last := list findLast:[:t|t lineNr == aLnNr]. |
|
1123 |
lastLyt := (list at:last) layout. |
|
1124 |
||
1125 |
(delta := lineWidth - lastLyt right) ~~ 0 ifTrue:[ |
|
1126 |
xLeft := startX. |
|
1127 |
delta := delta // (last - first + 1). |
|
1128 |
||
1129 |
delta ~~ 0 ifTrue:[ |
|
1130 |
list from:first to:last do:[:aTab| |
|
1131 |
layout := aTab layout. |
|
1132 |
tabWidth := layout width + delta. |
|
1133 |
layout setLeft:xLeft. |
|
1134 |
layout width:tabWidth. |
|
1135 |
xLeft := xLeft + tabWidth. |
|
1136 |
] |
|
1137 |
]. |
|
1138 |
lastLyt width:(lineWidth - lastLyt left) |
|
1139 |
]. |
|
1140 |
first := last + 1. |
|
1141 |
] |
|
1142 |
||
1143 |
! |
|
1144 |
||
1145 |
recomputeListVertical |
|
1146 |
"recompute list |
|
1147 |
" |
|
1148 |
|layout lastLyt |
|
1149 |
xTop "{ Class:SmallInteger }" |
|
1150 |
yTop "{ Class:SmallInteger }" |
|
1151 |
tabWidth "{ Class:SmallInteger }" |
|
1152 |
tabHeight "{ Class:SmallInteger }" |
|
1153 |
lineHeight "{ Class:SmallInteger }" |
|
1154 |
startY "{ Class:SmallInteger }" |
|
1155 |
delta "{ Class:SmallInteger }" |
|
1156 |
first "{ Class:SmallInteger }" |
|
1157 |
last "{ Class:SmallInteger }" |
|
1158 |
| |
|
1680 | 1159 |
startY := expandSelection x // 2 + canvasFrameLevel abs - 2. |
1401 | 1160 |
lineHeight := self height - startY. |
1161 |
tabHeight := self maxTabHeight. |
|
1162 |
yTop := startY. |
|
1680 | 1163 |
xTop := expandSelection y // 2 + tabMargin. |
1401 | 1164 |
|
1165 |
direction == #right ifTrue:[ |
|
1166 |
xTop := self width - tabHeight - xTop |
|
1167 |
]. |
|
1168 |
||
1169 |
list do:[:aTab| |
|
1170 |
tabWidth := aTab preferredExtentX. |
|
1171 |
||
1172 |
(yTop + tabWidth > lineHeight and:[yTop ~~ startY])ifTrue:[ |
|
1173 |
numberOfLines := numberOfLines + 1. |
|
1174 |
yTop := startY. |
|
1175 |
]. |
|
1176 |
aTab lineNr:numberOfLines. |
|
1177 |
aTab layout:(Rectangle left:xTop top:yTop width:tabHeight height:tabWidth). |
|
1178 |
yTop := yTop + tabWidth |
|
1179 |
]. |
|
1180 |
numberOfLines ~~ 1 ifTrue:[ |
|
1181 |
last := numberOfLines. |
|
1182 |
delta := direction == #left ifTrue:[tabHeight] ifFalse:[tabHeight negated]. |
|
1183 |
||
1184 |
list reverseDo:[:aTab| |
|
1185 |
aTab lineNr ~~ last ifTrue:[ |
|
1186 |
last := aTab lineNr. |
|
1187 |
xTop := xTop + delta |
|
1188 |
]. |
|
1189 |
aTab layout setLeft:xTop |
|
1190 |
] |
|
1191 |
]. |
|
1192 |
tabModus ifTrue:[ |
|
1193 |
layout := (list at:1) layout. |
|
1194 |
delta := direction == #left ifTrue:[self width - layout right] |
|
1195 |
ifFalse:[layout left negated]. |
|
1196 |
||
1197 |
list do:[:aTab| aTab layout setLeft:(aTab layout left + delta)]. |
|
1198 |
]. |
|
1199 |
||
1200 |
"/ FIT LINES |
|
1201 |
(numberOfLines ~~ 1 or:[fitLastRow]) ifFalse:[ |
|
1202 |
^ self |
|
1203 |
]. |
|
1204 |
||
1205 |
first := 1. |
|
1206 |
||
1207 |
1 to:numberOfLines do:[:aLnNr| |
|
1208 |
last := list findLast:[:t|t lineNr == aLnNr]. |
|
1209 |
lastLyt := (list at:last) layout. |
|
1210 |
||
1211 |
(delta := lineHeight - lastLyt bottom) ~~ 0 ifTrue:[ |
|
1212 |
yTop := startY. |
|
1213 |
delta := delta // (last - first + 1). |
|
1214 |
||
1215 |
delta ~~ 0 ifTrue:[ |
|
1216 |
list from:first to:last do:[:aTab| |
|
1217 |
layout := aTab layout. |
|
1218 |
tabWidth := layout height + delta. |
|
1219 |
layout setTop:yTop. |
|
1220 |
layout height:tabWidth. |
|
1221 |
yTop := yTop + tabWidth. |
|
1222 |
] |
|
1223 |
]. |
|
1224 |
lastLyt height:(lineHeight - lastLyt top) |
|
1225 |
]. |
|
1226 |
first := last + 1. |
|
1227 |
] |
|
1680 | 1228 |
! |
1229 |
||
1230 |
resizeCanvas |
|
1231 |
|layout| |
|
1232 |
||
1233 |
canvas notNil ifTrue:[ |
|
1234 |
layout := self computeBorderLayout insetBy:(canvasInset + canvasFrameLevel abs). |
|
1687 | 1235 |
canvas layout:layout. |
1680 | 1236 |
] |
1237 |
||
1401 | 1238 |
! ! |
1239 |
||
1240 |
!NoteBookView methodsFor:'obsolete'! |
|
1241 |
||
1242 |
labels |
|
1243 |
"return the list of labels |
|
1244 |
" |
|
1245 |
^ self list |
|
1246 |
! |
|
1247 |
||
1248 |
labels:aListOfLabels |
|
1249 |
"set the list of labels |
|
1250 |
" |
|
1251 |
^ self list:aListOfLabels |
|
1252 |
! |
|
1253 |
||
1254 |
labelsHolder |
|
1255 |
"get the model, which keeps the list of Tabs or Labels |
|
1256 |
" |
|
1257 |
^ self listHolder |
|
1258 |
! |
|
1259 |
||
1260 |
labelsHolder:aValueHolder |
|
1261 |
"set the model, which keeps the list of Tabs or Labels |
|
1262 |
" |
|
1263 |
self listHolder:aValueHolder. |
|
1264 |
! |
|
1265 |
||
1266 |
moveSelectedRow |
|
1267 |
^ true |
|
1268 |
! |
|
1269 |
||
1270 |
moveSelectedRow:something |
|
1271 |
! |
|
1272 |
||
1273 |
oneTabPerLine |
|
1274 |
^ false |
|
1275 |
! |
|
1276 |
||
1277 |
oneTabPerLine:something |
|
1278 |
! |
|
1279 |
||
1280 |
tabWidget |
|
1281 |
^ nil |
|
1282 |
! |
|
1283 |
||
1284 |
tabWidget:something |
|
1285 |
! ! |
|
1286 |
||
1287 |
!NoteBookView methodsFor:'private'! |
|
1288 |
||
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1289 |
processAccessCharacter:aKey |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1290 |
"a character is pressed; check for tab identified y the character |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1291 |
select the tab and return true or if no tab detected return false |
1401 | 1292 |
" |
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1293 |
|j size char blck| |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1294 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1295 |
(aKey isCharacter and:[(size := list size) ~~ 0]) ifFalse:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1296 |
^ false |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1297 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1298 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1299 |
size == selection ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1300 |
size == 1 ifTrue:[^ false]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1301 |
j := 1 |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1302 |
] ifFalse:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1303 |
j := selection isNil ifTrue:[1] ifFalse:[selection + 1] |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1304 |
]. |
1401 | 1305 |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1306 |
char := aKey asLowercase. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1307 |
blck := [:i| ((list at:i) accessCharacter == char and:[self isSelectable:i]) ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1308 |
self selection:i. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1309 |
^ true |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1310 |
] |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1311 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1312 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1313 |
j to:size do:blck. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1314 |
1 to:(j-1) do:blck. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1315 |
^ false |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1316 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1317 |
! |
1401 | 1318 |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1319 |
processShortcutKey:aKey |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1320 |
"if there is a short-key for that character, process it |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1321 |
and return true. Otherwise, return false. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1322 |
" |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1323 |
|j k size rawKey blck| |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1324 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1325 |
(size := list size) == 0 ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1326 |
^ false |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1327 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1328 |
rawKey := device keyboardMap keyAtValue:aKey ifAbsent:aKey. |
1401 | 1329 |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1330 |
size == selection ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1331 |
size == 1 ifTrue:[^ false]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1332 |
j := 1 |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1333 |
] ifFalse:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1334 |
j := selection isNil ifTrue:[1] ifFalse:[selection + 1] |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1335 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1336 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1337 |
blck := [:i| k := (list at:i) shortcutKey. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1338 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1339 |
(k notNil and:[(self isSelectable:i) and:[(k == aKey or:[k == rawKey])]]) ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1340 |
self selection:i. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1341 |
^ true |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1342 |
] |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1343 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1344 |
|
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1345 |
j to:size do:blck. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1346 |
1 to:(j-1) do:blck. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1347 |
^ false |
1401 | 1348 |
! ! |
1349 |
||
1350 |
!NoteBookView methodsFor:'queries'! |
|
1351 |
||
1352 |
isEnabled |
|
1353 |
"returns enabled state |
|
1354 |
" |
|
1355 |
^ enabled |
|
1356 |
! |
|
1357 |
||
1358 |
isFirstTabInLine:aTab |
|
1359 |
|idx tab| |
|
1360 |
||
1361 |
idx := list identityIndexOf:aTab. |
|
1362 |
tab := list at:(idx - 1) ifAbsent:nil. |
|
1363 |
^ (tab isNil or:[tab lineNr ~~ aTab lineNr]) |
|
1364 |
! |
|
1365 |
||
1366 |
isHorizontal |
|
1367 |
"returns true in case of direction is #top or #bottom |
|
1368 |
" |
|
1369 |
^ (direction == #top or:[direction == #bottom]) |
|
1370 |
||
1371 |
! |
|
1372 |
||
1373 |
isLastTabInLine:aTab |
|
1374 |
|index tab| |
|
1375 |
||
1376 |
index := list identityIndexOf:aTab. |
|
1377 |
tab := list at:(index + 1) ifAbsent:nil. |
|
1378 |
^ (tab isNil or:[tab lineNr ~~ aTab lineNr]) |
|
1379 |
! ! |
|
1380 |
||
1381 |
!NoteBookView methodsFor:'selection'! |
|
375 | 1382 |
|
1401 | 1383 |
isSelectable:anIndex |
1384 |
"returns true if tab at an index is selectable |
|
1385 |
" |
|
1386 |
(anIndex notNil and:[anIndex between:1 and:list size]) ifTrue:[ |
|
1387 |
(list at:anIndex) isEnabled ifTrue:[ |
|
1388 |
^ selectConditionBlock isNil ifTrue:[true] |
|
1389 |
ifFalse:[selectConditionBlock value:anIndex] |
|
1390 |
] |
|
1391 |
]. |
|
1392 |
^ false |
|
1393 |
! |
|
1394 |
||
1395 |
selectedTab |
|
1396 |
"returns the selected tab ot nil |
|
1397 |
" |
|
1398 |
^ selection notNil ifTrue:[list at:selection] ifFalse:[nil] |
|
1399 |
! |
|
1400 |
||
1401 |
selection |
|
1402 |
"return the selection or nil |
|
1403 |
" |
|
1404 |
selection isNil ifTrue:[ |
|
1405 |
^ useIndex ifTrue:[0] ifFalse:[nil] |
|
1406 |
]. |
|
1407 |
^ useIndex ifTrue:[selection] ifFalse:[(list at:selection) label] |
|
1408 |
! |
|
1409 |
||
1410 |
selection:anIndexOrNil |
|
1411 |
"change the selection to index or nil. The model and/or actionBlock is notified |
|
1412 |
" |
|
1413 |
|oldSel| |
|
1414 |
||
1407 | 1415 |
anIndexOrNil ~~ selection ifTrue:[ |
1416 |
oldSel := selection. |
|
1417 |
self setSelection:anIndexOrNil. |
|
1418 |
oldSel ~~ selection ifTrue:[self selectionChanged] |
|
1419 |
] |
|
1401 | 1420 |
! |
1421 |
||
1422 |
selectionChanged |
|
1423 |
"selection has changed; raise notification |
|
1424 |
" |
|
1425 |
|sel| |
|
1426 |
||
1427 |
sel := self selection. |
|
1428 |
||
1429 |
model notNil ifTrue:[model value:sel]. |
|
1430 |
action notNil ifTrue:[action value:sel] |
|
1431 |
||
1432 |
! |
|
1433 |
||
1434 |
setSelection:anIndexOrNil |
|
1435 |
"change the selection to index or nil. No notifications are raised |
|
1436 |
" |
|
1437 |
|newSel lnNr| |
|
1438 |
||
1439 |
newSel := self listIndexOf:anIndexOrNil. |
|
1440 |
||
1441 |
(newSel notNil and:[(self isSelectable:newSel) not]) ifTrue:[ |
|
1442 |
newSel := nil |
|
1443 |
]. |
|
1444 |
selection == newSel ifTrue:[^ self]. |
|
1445 |
||
1446 |
(shown and:[numberOfLines notNil]) ifFalse:[ |
|
1447 |
selection := newSel. |
|
1448 |
self invalidate |
|
1449 |
] ifTrue:[ |
|
1450 |
selection notNil ifTrue:[self invalidateTab:(list at:selection)]. |
|
1451 |
selection := newSel. |
|
1452 |
selection notNil ifTrue:[self invalidateTab:(list at:selection)]. |
|
1453 |
] |
|
1454 |
! ! |
|
1455 |
||
1456 |
!NoteBookView::Tab class methodsFor:'instance creation'! |
|
1457 |
||
1458 |
label:aLabel on:aGC |
|
1459 |
^ self basicNew label:aLabel on:aGC |
|
1460 |
||
1461 |
||
1462 |
! ! |
|
1463 |
||
1464 |
!NoteBookView::Tab methodsFor:'accessing'! |
|
1465 |
||
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1466 |
accessCharacter |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1467 |
^ accessCharacter |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1468 |
! |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1469 |
|
1401 | 1470 |
label |
1471 |
"returns my original label |
|
1472 |
" |
|
1473 |
^ label |
|
1474 |
||
1475 |
||
1476 |
! |
|
1477 |
||
1478 |
label:aLabel on:aGC |
|
1479 |
"initialize attributes |
|
1480 |
" |
|
1677 | 1481 |
label := aLabel. |
1482 |
model := (aLabel isKindOf:TabItem) ifTrue:[aLabel] ifFalse:[nil]. |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1483 |
accessCharacter := nil. |
1677 | 1484 |
printableLabel := model notNil ifTrue:[model rawLabel] ifFalse:[aLabel]. |
1401 | 1485 |
|
1486 |
printableLabel notNil ifTrue:[ |
|
1487 |
printableLabel isImageOrForm ifTrue:[ |
|
1488 |
printableLabel := printableLabel onDevice:(aGC device) |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1489 |
] ifFalse:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1490 |
printableLabel isString ifTrue:[ |
1677 | 1491 |
printableLabel := self resolveDisplayStringFor:printableLabel |
1492 |
] ifFalse:[ |
|
1493 |
printableLabel class == LabelAndIcon ifTrue:[ |
|
1494 |
printableLabel string:(self resolveDisplayStringFor:(printableLabel string)) |
|
1495 |
] |
|
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1496 |
]. |
375 | 1497 |
] |
1401 | 1498 |
] ifFalse:[ |
1499 |
printableLabel := '' |
|
1500 |
]. |
|
1501 |
extent := (printableLabel widthOn:aGC) @ (printableLabel heightOn:aGC). |
|
1502 |
||
1503 |
! |
|
1504 |
||
1505 |
lineNr |
|
1506 |
"get the line number |
|
1507 |
" |
|
1508 |
^ lineNr |
|
1509 |
||
1510 |
! |
|
1511 |
||
1512 |
lineNr:aLineNr |
|
1513 |
"set the line number |
|
1514 |
" |
|
1515 |
lineNr := aLineNr |
|
1516 |
||
1517 |
! |
|
1518 |
||
1519 |
printableLabel |
|
1520 |
"get my printable label |
|
1521 |
" |
|
1522 |
^ printableLabel |
|
1523 |
||
1524 |
! |
|
1525 |
||
1672
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1526 |
shortcutKey |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1527 |
"get the key to press to select the tab item from the keyboard |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1528 |
" |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1529 |
model notNil ifTrue:[ |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1530 |
^ model shortcutKey |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1531 |
]. |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1532 |
^ nil |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1533 |
! |
31dcb579f88a
support accelerator and accessCharacter (position or &)
ca
parents:
1663
diff
changeset
|
1534 |
|
1401 | 1535 |
string |
1536 |
"access the printable string used for steping through a list |
|
1537 |
searching for an entry starting with a character. |
|
1538 |
" |
|
1539 |
^ printableLabel perform:#string ifNotUnderstood:nil |
|
1540 |
||
1541 |
! ! |
|
1542 |
||
1543 |
!NoteBookView::Tab methodsFor:'accessing dimensions'! |
|
1544 |
||
1545 |
extent |
|
1546 |
"returns the extent of the label |
|
1547 |
" |
|
1548 |
^ extent |
|
1549 |
||
1550 |
||
1551 |
! |
|
1552 |
||
1553 |
layout |
|
1554 |
"get the tab's layout |
|
1555 |
" |
|
1556 |
^ layout |
|
1557 |
||
1558 |
||
1559 |
! |
|
1560 |
||
1561 |
layout:aLayout |
|
1562 |
"set the tab's layout |
|
1563 |
" |
|
1564 |
layout := aLayout |
|
1565 |
||
1566 |
||
1567 |
! |
|
1568 |
||
1569 |
preferredExtentX |
|
1570 |
"returns my preferred extent x |
|
1571 |
" |
|
1572 |
^ 4 + extent x |
|
1573 |
||
1574 |
||
1575 |
! |
|
1576 |
||
1577 |
preferredExtentY |
|
1578 |
"returns my preferred extent y |
|
1579 |
" |
|
1580 |
^ 4 + extent y |
|
1581 |
||
1582 |
||
1583 |
! ! |
|
1584 |
||
1585 |
!NoteBookView::Tab methodsFor:'accessing mvc'! |
|
1586 |
||
1587 |
addDependent:aGC |
|
1588 |
"make the noteBook be a dependent of the tab model |
|
1589 |
" |
|
1590 |
model notNil ifTrue:[model addDependent:aGC] |
|
1591 |
||
1592 |
||
1593 |
! |
|
1594 |
||
1595 |
removeDependent:aGC |
|
1596 |
"make the noteBook be independent of the tab model |
|
1597 |
" |
|
1598 |
model notNil ifTrue:[model removeDependent:aGC] |
|
1599 |
||
1600 |
||
1601 |
! ! |
|
1602 |
||
1603 |
!NoteBookView::Tab methodsFor:'drawing'! |
|
1604 |
||
1605 |
drawAtBottomOn:aGC selected:isSelected |
|
1606 |
"redraw tab at bottom of view |
|
1607 |
" |
|
1608 |
|yT "{ Class:SmallInteger }" |
|
1609 |
xL "{ Class:SmallInteger }" |
|
1610 |
xR "{ Class:SmallInteger }" |
|
1611 |
yB "{ Class:SmallInteger }" |
|
1612 |
| |
|
1613 |
xL := layout left. |
|
1614 |
yT := layout top. |
|
1615 |
xR := layout right - 1. |
|
1616 |
yB := layout bottom - 1. |
|
1617 |
||
1682 | 1618 |
aGC paint:(aGC halfLightColor). |
1619 |
aGC displayLineFromX:xL+1 y:yB-1 toX:xL+1 y:yT. |
|
1620 |
||
1621 |
aGC paint:(aGC drawLightColor). |
|
1622 |
aGC displayLineFromX:xL y:yB-2 toX:xL y:yT. |
|
1401 | 1623 |
|
1624 |
aGC paint:(aGC shadowColor). |
|
1658 | 1625 |
aGC displayLineFromX:xL+2 y:yB toX:xR-2 y:yB. |
1401 | 1626 |
aGC displayLineFromX:xR y:yT toX:xR y:yB-2. |
1627 |
aGC displayPointX:xR-1 y:yB-1. |
|
1628 |
||
1682 | 1629 |
aGC paint:(aGC halfShadowColor). |
1658 | 1630 |
aGC displayLineFromX:xR-1 y:yT toX:xR-1 y:yB-2. |
1401 | 1631 |
aGC displayLineFromX:xL+2 y:yB-1 toX:xR-2 y:yB-1. |
1632 |
aGC displayPointX:xR-2 y:yB-2. |
|
1633 |
||
1634 |
isSelected ifTrue:[ |
|
1635 |
(aGC isLastTabInLine:self) ifFalse:[aGC displayPointX:xR y:yT]. |
|
1636 |
(aGC isFirstTabInLine:self) ifFalse:[aGC displayPointX:xL y:yT]. |
|
1637 |
] |
|
1638 |
||
1639 |
||
1640 |
||
1641 |
||
1642 |
||
1643 |
||
1644 |
||
1682 | 1645 |
|
1401 | 1646 |
! |
1647 |
||
1648 |
drawAtLeftOn:aGC selected:isSelected |
|
1649 |
"redraw tab at left of view |
|
1650 |
" |
|
1651 |
|yT "{ Class:SmallInteger }" |
|
1652 |
xL "{ Class:SmallInteger }" |
|
1653 |
xR "{ Class:SmallInteger }" |
|
1654 |
yB "{ Class:SmallInteger }" |
|
1655 |
| |
|
1656 |
xL := layout left. |
|
1657 |
yT := layout top. |
|
1658 |
xR := layout right - 1. |
|
1659 |
yB := layout bottom - 1. |
|
1660 |
||
1661 |
aGC paint:(aGC shadowColor). |
|
1682 | 1662 |
aGC displayLineFromX:xR y:yB toX:xL+2 y:yB. |
1663 |
||
1664 |
aGC paint:(aGC halfShadowColor). |
|
1401 | 1665 |
aGC displayLineFromX:xR y:yB-1 toX:xL+1 y:yB-1. |
1666 |
||
1682 | 1667 |
aGC paint:(aGC drawLightColor). |
1401 | 1668 |
aGC displayLineFromX:xL+2 y:yT toX:xR y:yT. |
1682 | 1669 |
aGC displayLineFromX:xL y:yT+2 toX:xL y:yB-2. |
1670 |
aGC displayPointX:xL+1 y:yT+1. |
|
1671 |
||
1672 |
aGC paint:(aGC halfLightColor). |
|
1401 | 1673 |
aGC displayLineFromX:xL+1 y:yT+2 toX:xL+1 y:yB-2. |
1682 | 1674 |
aGC displayLineFromX:xL+2 y:yT+1 toX:xR y:yT+1. |
1401 | 1675 |
|
1676 |
||
1677 |
(aGC isLastTabInLine:self) ifFalse:[aGC displayPointX:xR y:yB]. |
|
1678 |
(aGC isFirstTabInLine:self) ifFalse:[aGC displayPointX:xR y:yT]. |
|
1679 |
||
1680 |
||
1681 |
||
1682 | 1682 |
|
1683 |
||
1401 | 1684 |
! |
1685 |
||
1686 |
drawAtRightOn:aGC selected:isSelected |
|
1687 |
"redraw tab at right of view |
|
1688 |
" |
|
1689 |
|yT "{ Class:SmallInteger }" |
|
1690 |
xL "{ Class:SmallInteger }" |
|
1691 |
xR "{ Class:SmallInteger }" |
|
1692 |
yB "{ Class:SmallInteger }" |
|
1693 |
| |
|
1694 |
xL := layout left. |
|
1695 |
yT := layout top. |
|
1696 |
xR := layout right - 1. |
|
1697 |
yB := layout bottom - 1. |
|
1698 |
||
1682 | 1699 |
aGC paint:(aGC drawLightColor). |
1401 | 1700 |
aGC displayLineFromX:xL y:yT toX:xR-2 y:yT. |
1682 | 1701 |
|
1702 |
aGC paint:(aGC halfLightColor). |
|
1401 | 1703 |
aGC displayLineFromX:xL y:yT+1 toX:xR-2 y:yT+1. |
1704 |
||
1705 |
aGC paint:(aGC shadowColor). |
|
1706 |
aGC displayLineFromX:xR-2 y:yB toX:xL y:yB. |
|
1707 |
aGC displayLineFromX:xR y:yT+2 toX:xR y:yB-2. |
|
1708 |
aGC displayPointX:xR-1 y:yB-1. |
|
1682 | 1709 |
|
1710 |
aGC paint:(aGC halfShadowColor). |
|
1401 | 1711 |
aGC displayLineFromX:xR-2 y:yB-1 toX:xL y:yB-1. |
1712 |
aGC displayLineFromX:xR-1 y:yT+1 toX:xR-1 y:yB-2. |
|
1713 |
||
1714 |
isSelected ifFalse:[^ self]. |
|
1715 |
||
1716 |
(aGC isLastTabInLine:self) ifFalse:[aGC displayPointX:xL y:yB]. |
|
1717 |
||
1718 |
(aGC isFirstTabInLine:self) ifFalse:[ |
|
1719 |
aGC displayPointX:xL y:yT+1. |
|
1720 |
aGC displayPointX:xL y:yT |
|
355 | 1721 |
]. |
375 | 1722 |
|
1723 |
||
1724 |
||
1682 | 1725 |
|
1726 |
||
375 | 1727 |
! |
1728 |
||
1401 | 1729 |
drawAtTopOn:aGC selected:isSelected |
1730 |
"redraw tab at top of view |
|
375 | 1731 |
" |
1407 | 1732 |
| |
1733 |
yT "{ Class:SmallInteger }" |
|
1401 | 1734 |
xL "{ Class:SmallInteger }" |
1735 |
xR "{ Class:SmallInteger }" |
|
1736 |
yB "{ Class:SmallInteger }" |
|
1737 |
| |
|
1738 |
xL := layout left. |
|
1739 |
yT := layout top. |
|
1740 |
xR := layout right - 1. |
|
1741 |
yB := layout bottom - 1. |
|
1742 |
||
1743 |
aGC paint:(aGC shadowColor). |
|
1744 |
aGC displayLineFromX:xR y:yB toX:xR y:yT+2. |
|
1682 | 1745 |
|
1746 |
aGC paint:(aGC halfShadowColor). |
|
1401 | 1747 |
aGC displayLineFromX:xR-1 y:yB toX:xR-1 y:yT+1. |
1748 |
||
1682 | 1749 |
aGC paint:(aGC drawLightColor). |
1401 | 1750 |
aGC displayLineFromX:xL+2 y:yT toX:xR-2 y:yT. |
1751 |
aGC displayLineFromX:xL y:yB toX:xL y:yT+2. |
|
1682 | 1752 |
aGC displayPointX:xL+1 y:yT+1. |
1753 |
||
1754 |
aGC paint:(aGC halfLightColor). |
|
1401 | 1755 |
aGC displayLineFromX:xL+2 y:yT+1 toX:xR-2 y:yT+1. |
1682 | 1756 |
aGC displayLineFromX:xL+1 y:yB toX:xL+1 y:yT+2. |
1401 | 1757 |
|
1758 |
isSelected ifFalse:[^ self]. |
|
1759 |
(aGC isLastTabInLine:self) ifFalse:[aGC displayPointX:xR y:yB]. |
|
1760 |
(aGC isFirstTabInLine:self) ifFalse:[aGC displayPointX:xL y:yB]. |
|
1761 |
||
1762 |
||
1763 |
||
1764 |
||
1682 | 1765 |
|
1766 |
||
1401 | 1767 |
! |
1768 |
||
1659 | 1769 |
drawWin95FocusFrameOn:aGC |
1770 |
||
1771 |
"/aGC notNil ifTrue:[^ self]. |
|
1772 |
||
1773 |
aGC displayDottedRectangleX:(layout left + 4) |
|
1774 |
y:(layout top + 4) |
|
1775 |
width:(layout width - 8) |
|
1776 |
height:(layout height - 8). |
|
1777 |
! |
|
1778 |
||
1401 | 1779 |
redrawAt:aDirection selected:isSelected on:aGC |
1780 |
"redraw tab |
|
1781 |
" |
|
1782 |
|dispObj fgColor |
|
1783 |
y "{ Class:SmallInteger }" |
|
1784 |
x "{ Class:SmallInteger }" |
|
1785 |
| |
|
1786 |
||
1787 |
isSelected ifTrue:[ |
|
1788 |
aGC paint:(aGC backgroundColor). |
|
1789 |
layout displayFilledOn:aGC. |
|
1790 |
]. |
|
1791 |
aDirection == #top ifTrue:[self drawAtTopOn:aGC selected:isSelected] |
|
1792 |
ifFalse:[aDirection == #bottom ifTrue:[self drawAtBottomOn:aGC selected:isSelected] |
|
1793 |
ifFalse:[aDirection == #right ifTrue:[self drawAtRightOn:aGC selected:isSelected] |
|
1659 | 1794 |
ifFalse:[ self drawAtLeftOn:aGC selected:isSelected]]]. |
1401 | 1795 |
|
1796 |
"/ REDRAW LABEL |
|
1797 |
(aGC isEnabled and:[self isEnabled]) ifTrue:[ |
|
1798 |
dispObj := printableLabel. |
|
1799 |
fgColor := aGC foregroundColor. |
|
1800 |
||
1801 |
model notNil ifTrue:[ |
|
1802 |
fgColor := model foregroundColor ? fgColor |
|
1803 |
] |
|
1804 |
] ifFalse:[ |
|
1682 | 1805 |
fgColor := aGC drawLightColor. |
1401 | 1806 |
|
1807 |
(dispObj := disabledLabel) isNil ifTrue:[ |
|
1808 |
(dispObj := printableLabel) isImageOrForm ifTrue:[ |
|
1809 |
disabledLabel := printableLabel lightened onDevice:(aGC device) |
|
375 | 1810 |
] |
1401 | 1811 |
] |
1812 |
]. |
|
1442 | 1813 |
|
1814 |
isSelected ifTrue:[ |
|
1815 |
fgColor := aGC activeForegroundColor. |
|
1816 |
]. |
|
1817 |
||
1401 | 1818 |
aGC paint:fgColor. |
1659 | 1819 |
|
1401 | 1820 |
(aDirection == #top or:[aDirection == #bottom]) ifTrue:[ |
1659 | 1821 |
x := layout left + (layout width - extent x // 2). |
1822 |
y := layout top + (layout height - extent y // 2). |
|
1401 | 1823 |
|
1659 | 1824 |
aDirection == #bottom ifTrue:[y := y - 1] ifFalse:[y := y + 1]. |
1401 | 1825 |
|
1826 |
dispObj isImageOrForm ifFalse:[ |
|
1827 |
y := y + aGC font ascent |
|
1683 | 1828 |
]. |
1829 |
dispObj displayOn:aGC x:x y:y |
|
1401 | 1830 |
] ifFalse:[ |
1659 | 1831 |
x := layout left + (layout width - extent y // 2). |
1832 |
y := layout top + (layout height - extent x // 2). |
|
1401 | 1833 |
|
1683 | 1834 |
aDirection == #left ifTrue:[ |
1835 |
x := x + 1. |
|
1836 |
] ifFalse:[ |
|
1837 |
x := x - 1. |
|
1838 |
]. |
|
375 | 1839 |
|
1401 | 1840 |
dispObj isImageOrForm ifFalse:[ |
1663 | 1841 |
|
1842 |
dispObj isString ifTrue:[ |
|
1843 |
x := x + aGC font descent. |
|
1844 |
]. |
|
1401 | 1845 |
"/ workaround for a bug in display-with-angle, |
1846 |
"/ iff displayed string is a labelAndIcon. |
|
1847 |
"/ (In this case, display is always opaque, and the current |
|
1848 |
"/ backgroundPaint color is used to fill the underlying rectangle) |
|
1849 |
"/ |
|
1663 | 1850 |
aGC paint:fgColor. |
1851 |
aGC backgroundPaint:aGC backgroundColor. |
|
1683 | 1852 |
aGC displayString:dispObj x:x y:y angle:90. |
1663 | 1853 |
] ifTrue:[ |
1854 |
(dispObj rotated:90) displayOn:aGC x:x y:y. |
|
1401 | 1855 |
] |
1683 | 1856 |
] |
375 | 1857 |
! ! |
1858 |
||
1677 | 1859 |
!NoteBookView::Tab methodsFor:'private'! |
1860 |
||
1861 |
resolveDisplayStringFor:aString |
|
1862 |
|string size rest pos idx| |
|
1863 |
||
1864 |
size := aString size. |
|
1865 |
string := aString. |
|
1866 |
pos := 0. |
|
1867 |
||
1868 |
size > 1 ifTrue:[ |
|
1869 |
(model notNil and:[(pos := model accessCharacterPosition) ~~ 0]) ifTrue:[ |
|
1870 |
pos > size ifTrue:[pos := 0] |
|
1871 |
] ifFalse:[ |
|
1872 |
idx := 1. |
|
1873 |
||
1874 |
[((idx := string indexOf:$& startingAt:idx) ~~ 0 and:[idx < size])] whileTrue:[ |
|
1875 |
rest := string copyFrom:(idx+1). |
|
1876 |
||
1877 |
idx == 1 ifTrue:[string := rest] |
|
1878 |
ifFalse:[string := (string copyFrom:1 to:(idx-1)), rest]. |
|
1879 |
||
1880 |
(string at:idx) == $& ifTrue:[idx := idx + 1] |
|
1881 |
ifFalse:[pos := idx]. |
|
1882 |
size := size - 1. |
|
1883 |
] |
|
1884 |
] |
|
1885 |
]. |
|
1886 |
size ~~ 0 ifTrue:[ |
|
1887 |
pos == 0 ifTrue:[ |
|
1888 |
pos := 1 |
|
1889 |
] ifFalse:[ |
|
1890 |
string isText ifFalse:[ |
|
1891 |
string := Text string:string |
|
1892 |
]. |
|
1893 |
string emphasisAt:pos add:#underline |
|
1894 |
]. |
|
1895 |
accessCharacter := (string at:pos) asLowercase |
|
1896 |
] ifFalse:[ |
|
1897 |
accessCharacter := nil |
|
1898 |
]. |
|
1899 |
^ string |
|
1900 |
! ! |
|
1901 |
||
1401 | 1902 |
!NoteBookView::Tab methodsFor:'testing'! |
375 | 1903 |
|
1401 | 1904 |
containsPointX:x y:y |
1905 |
"return true, if the point defined by x@y is contained in the tab. |
|
375 | 1906 |
" |
1401 | 1907 |
^ layout notNil ifTrue:[layout containsPointX:x y:y] |
1908 |
ifFalse:[false]. |
|
1909 |
||
1910 |
||
375 | 1911 |
! |
1912 |
||
1401 | 1913 |
intersects:aRectangle |
1914 |
"return true, if the intersection between the argument, aRectangle |
|
1915 |
and the tab is not empty |
|
375 | 1916 |
" |
1401 | 1917 |
^ layout notNil ifTrue:[layout intersects:aRectangle] |
1918 |
ifFalse:[false]. |
|
375 | 1919 |
|
432 | 1920 |
|
1401 | 1921 |
! |
432 | 1922 |
|
1401 | 1923 |
isEnabled |
1924 |
"returne true if no model exists or the model is enabled |
|
1925 |
" |
|
1926 |
^ (model isNil or:[model isEnabled]) |
|
375 | 1927 |
|
355 | 1928 |
|
386 | 1929 |
! ! |
1930 |
||
355 | 1931 |
!NoteBookView class methodsFor:'documentation'! |
1932 |
||
1933 |
version |
|
1687 | 1934 |
^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.35 2000-02-08 17:59:30 cg Exp $' |
355 | 1935 |
! ! |