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