-
Notifications
You must be signed in to change notification settings - Fork 11
/
Brazil.ns
7582 lines (7238 loc) · 258 KB
/
Brazil.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Newspeak3
'Brazil'
class Brazil usingPlatform: platform = (
(* Brazil is Newspeak's multi-platform logical UI and layout framework. It provides the familiar widgets ('visuals') such as Labels, Buttons, and ListBoxes, and containers for combining visuals and managing their layout. Unlike a typical widget framework, Brazil does not implement the actual widgets. Instead it functions as a 'logical UI' layer that builds and manages the equivalent 'physical UI' made of native artifacts of the host platform.
Brazil was designed and implemented by Vassili Bykov in 2007, with a mapping to Morphic as the first supported platform. A Windows mapping was implemented in 2008. Brazil is indeed named after the movie.
Copyright 2007-2012 Cadence Design Systems, Inc.
Copyright 2009 Ryan Macnak and other contributors.
Licensed under the Apache License, Version 2.0 (the ''License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 *)
|
(* module state *)
private defaultFontMapperS
private theDesktopS
private lastVisitedDirectoryS
(* imports *)
private Map = platform collections Map.
private List = platform collections List.
private IdentityMap = platform collections IdentityMap.
private WeakArray = platform collections WeakArray.
public (* bogus *) Color = platform graphics Color.
private Rectangle = platform graphics Rectangle.
private SeqCltnReadStream = platform streams SeqCltnReadStream.
private Transcript = platform streams TempTranscript new. (* for SpyingWrapper, InformationRetriever *)
private Duct = platform ducts Duct.
private Holder = platform ducts Holder.
private SmallInteger = platform squeak SmallInteger.
private GradientFillStyle = platform squeak GradientFillStyle.
private FileDirectory = platform squeak FileDirectory.
private DosFileDirectory = platform squeak DosFileDirectory.
private TimeStamp = platform squeak TimeStamp.
private ZeroDivide = platform squeak ZeroDivide.
private MorphicFontMapper = platform squeak MorphicFontMapper.
private WorldState = platform squeak WorldState.
private World = platform squeak World.
private NewspeakGlobalState = platform squeak NewspeakGlobalState.
private MorphicAgentFactory = platform squeak MorphicAgentFactory.
private BrazilMappingForWin32 = platform namespace BrazilMappingForWin32.
(* public interfacing *)
public plumbing = PlumbingClasses new.
public areas = AreaClasses new. (* uses plumbing *)
public abilities = AbilityClasses new.
public manipulation = ManipulationClasses new.
public mapping = MappingClasses new.
public menus = MenuClasses new.
public text = TextClasses new.
public visuals = VisualClasses new. (* uses plumbing, areas, containers,visuals, but hooked up with postInit *)
public widgets = WidgetClasses new. (* uses visuals *)
public containers = ContainerClasses new. (* uses visual,widgets,plmbing,areas *)
public tools = ToolClasses new. (* uses containers, widgets, areas *)
|visuals postInit) (
class AbilityClasses = (
(* *** EXPERIMENTAL/WORK IN PROGRESS: This code is not yet used by the core system, and may be significantly revised or removed *** This module implements and manages Abilities. Abilities are low-level input event interpreters that translate sequences of events such as mouse presse, releases and moves, into higher-level gestures such as button clicks and drag attempts. *)
|
(* private Dictionary = platform Collections Dictionary.
private OrderedCollection = platform Collections OrderedCollection.
clickability = Clickability new.
draggability = Draggability new.
clickabilityAndDraggability = ClickabilityAndDraggability new. *)
|) (
class Ability = (
(* This is the abstract superclass of abilities. Any ability is attached to the owner, which is the source of the low-level events it interprets. The owner is often a Visual *)
|
owner
|) (
atttachTo: newOwner = (
owner:: newOwner
)
detachFrom: presumedOwner = (
(* A subclass may reimplement this to do the real detaching, provided the presumedOwner is the same as the current owner. *)
)
) : (
)
class Clickability = Mousability (
(* Clickability translates low-level events into click gestures. A click gesture follows the standard behavior of push buttons, where a button is clicked on a mouse up event that occurs within the button's bounds after a prior mouse down event within the bounds. Moving the mouse outside the bounds and then releasing the mouse button effectively cancels the click in progress. *)
|
clickResponse
pressResponse
releaseResponse
|) (
defineBehavior = (
| normal down outside |
normal:: behavior newState.
down:: behavior newState.
outside:: behavior newState.
normal
exitAction: [owner grabMouse];
entryAction: [owner releaseMouse];
on: #mouseDown do:
[[invokePressResponse]
ensure: [down enter]].
down
on: #mouseUp do:
[[invokeReleaseResponse.
invokeClickResponse]
ensure: [normal enter]];
on: #mouseMove do:
[hasMouse ifFalse:
[[invokeReleaseResponse]
ensure: [outside enter]]].
outside
on: #mouseUp do:
[[invokeReleaseResponse]
ensure: [normal enter]];
on: #mouseMove do:
[hasMouse ifTrue:
[[invokePressResponse]
ensure: [down enter]]].
)
hasMouse = (
^owner localBounds containsPoint: owner mousePoint
)
invokeClickResponse = (
clickResponse ifNotNil: [:it | it value]
)
invokePressResponse = (
pressResponse ifNotNil: [:it | it value]
)
invokeReleaseResponse = (
releaseResponse ifNotNil: [:it | it value]
)
resetResponses = (
clickResponse: nil.
pressResponse: nil.
releaseResponse: nil.
)
) : (
)
class ClickabilityAndDraggability = Mousability (
(* This class aggregates the two other abilities by becoming the owner of their instances and coordinating their actions and requests. *)
|
mouseGrabLevel ::= 0.
|) (
attachClickability = (
clickability attachTo: self.
clickability
pressResponse: [respondToPress];
releaseResponse: [respondToRelease];
clickResponse: [respondToClick]
)
attachDraggability = (
draggability attachTo: self.
)
attachTo: newOwner = (
super attachTo: newOwner.
mouseGrabLevel:: 0.
attachClickability.
attachDraggability.
)
public grabMouse = (
mouseGrabLevel: mouseGrabLevel + 1.
mouseGrabLevel = 1 ifTrue: [owner grabMouse].
)
public releaseMouse = (
mouseGrabLevel: mouseGrabLevel - 1.
mouseGrabLevel = 0 ifTrue: [owner releaseMouse].
)
resetResponses = (
clickability detachFrom: self.
draggability detachFrom: self.
)
respondToMouseDownLeft = (
clickability respondToMouseDownLeft.
draggability respondToMouseDownLeft.
)
respondToMouseEntry = (
clickability respondToMouseEntry.
draggability respondToMouseEntry.
)
respondToMouseExit = (
clickability respondToMouseExit.
draggability respondToMouseExit.
)
respondToMouseMove = (
clickability respondToMouseMove.
draggability respondToMouseMove.
)
respondToMouseUpLeft = (
clickability respondToMouseUpLeft.
draggability respondToMouseUpLeft.
)
) : (
)
class Draggability = Mousability (
(* Draggability is the ability of a visual to initiate a drag once the mouse button has been pressed over it and then the mouse moved further than a certain threshold distance. *)
|
dragStartResponse
dragContinueResponse
dropResponse
|) (
defineBehavior = (
| normalState activatedState draggingState downPoint |
normalState:: behavior newState.
activatedState:: behavior newState.
draggingState:: behavior newState.
normalState
entryAction: [owner releaseMouse];
exitAction: [owner grabMouse];
on: #mouseDown do:
[downPoint:: owner mousePoint.
activatedState enter].
activatedState
on: #mouseMove do:
[(is: owner mousePoint beyondDragThresholdFrom: downPoint)
ifTrue: [draggingState enter]];
on: #mouseUp do:
[normalState enter].
draggingState
entryAction: [invokeDragStartResponse];
on: #mouseMove do:
[invokeDragContinueResponse];
on: #mouseUp do:
[invokeDropResponse.
normalState enter].
)
dragThreshold ^<Number> = (
^5
)
invokeDragContinueResponse = (
dragContinueResponse ifNotNil: [:it | it value]
)
invokeDragStartResponse = (
dragStartResponse ifNotNil: [:it | it value]
)
invokeDropResponse = (
dropResponse ifNotNil: [:it | it value]
)
is: point1 beyondDragThresholdFrom: point2 = (
^(point1 x - point2 x) abs > dragThreshold or:
[(point1 y - point2 y) abs > dragThreshold]
)
resetResponses = (
dragStartResponse: nil.
dragContinueResponse: nil.
dropResponse: nil.
)
) : (
)
class FSM = (
(* Finite state machines are used by abilities to describe the interpretation of input they perform. *)
|
protected states = List new.
protected initialState
protected currentState
|) (
class State = (
|
eventResponses = Map new.
entryAction
exitAction
|) (
enter = (
enterState: self
)
enterState: newCurrentState = (
outer FSM enterState: newCurrentState
)
on: event <Symbol> do: action <Block> = (
^eventResponses at: event put: action
)
processEvent: event <Symbol> = (
(eventResponses at: event ifAbsent: [^self]) value
)
respondToEntry = (
entryAction ifNotNil: [:it | it value]
)
respondToExit = (
exitAction ifNotNil: [:it | it value]
)
) : (
)
enterState: newCurrentState = (
currentState = newCurrentState ifFalse:
[currentState respondToExit.
currentState:: newCurrentState.
currentState respondToEntry].
)
newState = (
(* Create a new state associated with this machine. The first state created is the initial state. *)
| state |
state:: State new.
states add: state.
initialState isNil ifTrue: [setInitialState: state].
^state
)
processEvent: event <Symbol> = (
currentState processEvent: event
)
reset = (
currentState: initialState
)
setInitialState: state = (
initialState:: state.
currentState:: state
)
) : (
)
class Mousability = (
|
protected behavior = FSM new.
|defineBehavior) (
attachTo: newOwner = (
super attachTo: newOwner.
behavior reset.
owner
mouseDownLeftResponse: [respondToMouseDownLeft];
mouseUpLeftResponse: [respondToMouseUpLeft];
mouseMoveResponse: [respondToMouseMove];
mouseEntryResponse: [respondToMouseEntry];
mouseExitResponse: [respondToMouseExit]
)
defineBehavior = (
subclassResponsibility
)
detachFrom: presumedOwner = (
presumedOwner == owner ifTrue:
[owner
mouseDownLeftResponse: nil;
mouseUpLeftResponse: nil;
mouseMoveResponse: nil;
mouseEntryResponse: nil;
mouseExitResponse: nil.
resetResponses.
owner:: nil]
)
resetResponses = (
(* No responses here; subclasses with responses should redefine this to nil them all out. *)
)
respondToMouseDownLeft = (
behavior processEvent: #mouseDown
)
respondToMouseEntry = (
behavior processEvent: #mouseEntry
)
respondToMouseExit = (
behavior processEvent: #mouseExit
)
respondToMouseMove = (
behavior processEvent: #mouseMove
)
respondToMouseUpLeft = (
behavior processEvent: #mouseUp
)
) : (
)
) : (
)
class AreaClasses = (
(* The former category Brazil-Areas *)
|
private MessageRecorder = plumbing MessageRecorder.
|) (
public class Anchor = Area (
(* An Anchor is an Area that dictates the placement but not the size of its visual within the parent. The visual is always as large as it wants to be.
The position of the visual is determined using a fraction/offset scheme similar to that used by Frame. Each of the dimensions of the parent is multiplied by the corresponding fraction, and the the offset is added to obtain the anchor position within the current bounds of the parent. For example, an Anchor with the following set of parameters:
xFraction = 0.5; xOffset = 10
yFraction = 0; yOffset = 20
is positioned at the location 100 @ 20 inside a parent visual of size 200 @ 200, and at the location 150 @ 20 inside a parent of size 300 @ 300.
An additional pair of fraction values, anchor fractions, defines what point of the child is positioned at the anchor location. If the anchor fractions are 0 and 0 it is the top left. If the fractions are 1 and 1, it is the bottom right.
A number of methods of the 'initialize-release' protocol, such as #beCentered or #offset:, cover the common usage scenarios. Refer to those methods for further configuration examples. *)
|
xFractionS
xOffsetS
yFractionS
yOffsetS
xAnchorFractionS
yAnchorFractionS
cachedSuggestedParentExtent
public lastSuggestedExtentKnownToParent
|) (
anchorPosition: newOrigin <Point> = (
(* Configure the receiver so that its visual's top left corner is positioned at the specified offset from the parent's top left corner. *)
xFractionS:: 0.
xOffsetS:: newOrigin x.
yFractionS:: 0.
yOffsetS:: newOrigin y.
flushLayoutCaches.
requestBoundsUpdate
)
public beBottomCenter = (
(* Configure the receiver to position its visual so that the center of its bottom side is at the center of the bottom side of the visual's parent. *)
xFractionS: 0.5.
yFractionS: 1.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.5.
yAnchorFractionS: 1.
flushLayoutCaches.
requestBoundsUpdate
)
public beBottomLeft = (
(* Configure the receiver to position its visual so that its bottom left corner is at the bottom left corner of the visual's parent. *)
xFractionS: 0.
yFractionS: 1.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.
yAnchorFractionS: 1.
flushLayoutCaches.
requestBoundsUpdate
)
public beBottomRight = (
(* Configure the receiver to position its visual so that its bottom right corner is at the bottom right corner of the visual's parent. *)
xFractionS: 1.
yFractionS: 1.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 1.
yAnchorFractionS: 1.
flushLayoutCaches.
requestBoundsUpdate
)
public beCentered = (
(* Configure the receiver to position its visual so that its center is at the center of the visual's parent. *)
xFractionS: 0.5.
yFractionS: 0.5.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.5.
yAnchorFractionS: 0.5.
flushLayoutCaches.
requestBoundsUpdate
)
public beLeftCenter = (
(* Configure the receiver to position its visual so that the center of its left side is at the center of the left side of the visual's parent. *)
xFractionS: 0.
yFractionS: 0.5.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.
yAnchorFractionS: 0.5.
flushLayoutCaches.
requestBoundsUpdate
)
public beRightCenter = (
(* Configure the receiver to position its visual so that the center of its right side is at the center of the right side of the visual's parent. *)
xFractionS: 1.
yFractionS: 0.5.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 1.
yAnchorFractionS: 0.5.
flushLayoutCaches.
requestBoundsUpdate
)
public beTopCenter = (
(* Configure the receiver to position its visual so that the center of its top side is at the center of the top side of the visual's parent. *)
xFractionS: 0.5.
yFractionS: 0.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.5.
yAnchorFractionS: 0.
flushLayoutCaches.
requestBoundsUpdate
)
public beTopLeft = (
(* Configure the receiver to position its visual so that its top left corner is at the top left corner of the visual's parent. *)
xFractionS: 0.
yFractionS: 0.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 0.
yAnchorFractionS: 0.
flushLayoutCaches.
requestBoundsUpdate
)
public beTopRight = (
(* Configure the receiver to position its visual so that its top right corner is at the top right corner of the visual's parent. *)
xFractionS: 1.
yFractionS: 0.
xOffsetS: 0.
yOffsetS: 0.
xAnchorFractionS: 1.
yAnchorFractionS: 0.
flushLayoutCaches.
requestBoundsUpdate
)
public boundsWithin: referenceBounds <Rectangle> ^<Rectangle> = (
| parentOrigin parentExtent width height naturalExtent anchorX anchorY |
parentExtent: referenceBounds extent.
width: parentExtent x.
height: parentExtent y.
naturalExtent: visual naturalExtent.
anchorX:: (width * xFraction) + xOffset - (naturalExtent x * xAnchorFraction).
anchorY:: (height * yFraction) + yOffset - (naturalExtent y * yAnchorFraction).
^Rectangle
origin: anchorX rounded @ anchorY rounded + referenceBounds origin
extent: naturalExtent
)
computeSuggestedParentExtent ^<Point> = (
(* Answer the minimum extent the parent should have in order for the visual of this area to appear fully visible. In the general case this value depends both on the natural extent of the visual and on the parameters of the area. *)
| naturalExtent |
naturalExtent:: visual naturalExtent.
^(suggestedParentSizeForFraction: xFraction
offset: xOffset
size: naturalExtent x
anchorFraction: xAnchorFraction)
@ (suggestedParentSizeForFraction: yFraction
offset: yOffset
size: naturalExtent y
anchorFraction: yAnchorFraction)
)
public copyConfigurationFromAnchor: another <Anchor> = (
xFraction:: another xFraction.
xOffset:: another yOffset.
yFraction:: another yFraction.
yOffset:: another yOffset.
)
public copyConfigurationTo: another <Area> = (
another copyConfigurationFromAnchor: self
)
public flushLayoutCaches = (
cachedSuggestedParentExtent: nil
)
public isRelative ^<Boolean> = (
(* True if the final bounds depend on the size of the parent. *)
^xFraction ~= 0
or: [yFraction ~= 0]
)
public isSqueezing ^<Boolean> = (
^false
)
public isVisualSquishy ^<Boolean> = (
^false (* no matter what the visual is, an anchored one has no chance to exhibit its squishiness *)
)
mayAccommodateVisualsNaturalHeightChange ^<Boolean> = (
^true (* An anchor is accommodating by definition. *)
)
mayAccommodateVisualsNaturalWidthChange ^<Boolean> = (
^true (* An anchor is accommodating by definition. *)
)
public origin: newOrigin <Point> = (
(* Configure the receiver so that its visual's top left corner is positioned at the specified offset from the parent's top left corner. *)
xFractionS:: 0.
xOffsetS:: newOrigin x.
yFractionS:: 0.
yOffsetS:: newOrigin y.
xAnchorFractionS: 0.
yAnchorFractionS: 0.
flushLayoutCaches.
requestBoundsUpdate
)
public resetLastSuggestedExtentKnownToParent = (
lastSuggestedExtentKnownToParent:: -1 @ -1
(* we need a value that's a legal Point but cannot equal any legal extent *)
)
public suggestedParentExtent ^<Point> = (
(* Answer the minimum extent the parent should have in order for the visual of this area to appear fully visible. In the general case this value depends both on the natural extent of the visual and on the parameters of the area. *)
cachedSuggestedParentExtent == nil ifTrue:
[cachedSuggestedParentExtent: computeSuggestedParentExtent].
^cachedSuggestedParentExtent
)
public suggestedParentHeightForWidth: width <Number> = (
^suggestedParentExtent y
)
public suggestedParentSizeForFraction: fraction <Number> offset: offset <Number> size: size <Number> anchorFraction: anchorFraction <Number> = (
(* Used internally by #suggestedParentExtent to compute the suggested parent's size given all the relevant layout parameters along one of the axes. The suggested size is the minimum size of the parent such that the entire child will appear unobscured inside it. *)
| size1 size2 |
size1:: fraction ~= 1
ifTrue: [(1 - anchorFraction) * size + offset / (1 - fraction)]
ifFalse: [0].
size2:: fraction ~= 0
ifTrue: [anchorFraction * size - offset / fraction]
ifFalse: [0].
^size1 rounded max: size2 rounded
)
public visual: aVisual = (
super visual: aVisual.
resetLastSuggestedExtentKnownToParent.
xFraction: 0.
yFraction: 0.
xOffset: 0.
yOffset: 0.
xAnchorFraction: 0.
yAnchorFraction: 0.
)
public xAnchorFraction ^<Number> = (
^xAnchorFractionS
)
public xAnchorFraction: fraction <Number> = (
xAnchorFractionS:: fraction.
flushLayoutCaches.
requestBoundsUpdate
)
public xFraction ^<Number> = (
^xFractionS
)
public xFraction: fraction <Number> = (
xFractionS:: fraction.
flushLayoutCaches.
requestBoundsUpdate
)
public xOffset ^<Number> = (
^xOffsetS
)
public xOffset: offset <Number> = (
xOffsetS:: offset.
flushLayoutCaches.
requestBoundsUpdate
)
public yAnchorFraction ^<Number> = (
^yAnchorFractionS
)
public yAnchorFraction: fraction <Number> = (
yAnchorFractionS:: fraction.
flushLayoutCaches.
requestBoundsUpdate
)
public yFraction ^<Number> = (
^yFractionS
)
public yFraction: fraction <Number> = (
yFractionS:: fraction.
flushLayoutCaches.
requestBoundsUpdate
)
public yOffset ^<Number> = (
^yOffsetS
)
public yOffset: offset <Number> = (
yOffsetS:: offset.
flushLayoutCaches.
requestBoundsUpdate
)
) : (
public visual: aVisual <Visual> = (
^self new visual: aVisual; yourself
)
)
class Area = (
(* An Area is an object associated with a visual to capture the visual's position properties. The Area class itself is abstract.
When a visual is added to a parent, the visual automatically installs an area most appropriate for the particular parent.
Slots:
visualS <Visual> The visual this area is attached to. *)
|
visualS
|) (
public copyConfigurationFromAnchor: anchor <Anchor> = (
(* No configuration here; nothing to copy to. *)
)
public copyConfigurationFromFrame: frame <Frame> = (
(* No configuration here; nothing to copy to. *)
)
public copyConfigurationTo: another <Position> = (
(* No configuration; nothing to copy. *)
)
public flushLayoutCaches = (
(* Subclasses that cache state in order to speed things up must redefine this method to discard the cached data when requested. *)
)
public isFuture = (
^false
)
public isSqueezing ^<Boolean> = (
(* This method complements the one named the same in Visual, since some areas may override the squeezing behavior of their parents. *)
^visual parent isSqueezing
)
public isVisualSquishy ^<Boolean> = (
(* When containers compute their squishiness, they rely on this method to determine if the combination of a child's squishiness together with the area settings would in fact make the parent squishy. *)
subclassResponsibility
)
mayAccommodateVisualsNaturalHeightChange ^<Boolean> = (
^visual parent mayAccommodateNaturalHeightChangeOf: visual
)
mayAccommodateVisualsNaturalWidthChange ^<Boolean> = (
^visual parent mayAccommodateNaturalWidthChangeOf: visual
)
requestBoundsUpdate = (
(visual area == self and: [visual updateLockLevel < 1]) ifTrue:
[visual parent
child: visual
requestsBoundsUpdateUsing:
[:newBounds | visual occupyBounds: newBounds]]
)
public species = (
^super class
)
public visual = (
^visualS
)
public visual: aVisual <Visual> = (
visualS:: aVisual
)
public visualRequestsBoundsUpdateUsing: aBlock = (
(* An area receives this message when the visual wants to receive a bounds update, meaning its natural extent has changed. A subclass may redefine this method to filter requests in cases when the area dictates a fixed size of the child and therefore the child's natural extent is known to have no effect on the parent. NOTE that the area must invoke the block with the final bounds of the visual, regardless of whether they have changed or not. *)
visual parent
child: visual
requestsBoundsUpdateUsing: aBlock
)
) : (
public visual: aVisual <Visual> = (
^self new visual: aVisual; yourself
)
)
public class CellWidthEqualizer = (|
cellsX ::= List new.
indexX
cachedNaturalExtentX
|) (
public commonNaturalWidth = (
^cellsX
inject: 0
into:
[:max :each |
max max: each visual naturalExtent x]
)
equalize: collection at: index = (
indexX:: index.
collection do:
[:each | | visual |
visual:: each at: index.
visual areaClass: WidthEqualizingRowCell.
cellsX add: visual area.
visual area equalizer: self].
)
public equalizeRowElements: visuals = (
visuals do:
[:each |
each areaClass: WidthEqualizingRowCell.
cellsX add: each area.
each area equalizer: self].
)
) : (
public equalize: collection at: index = (
^self new equalize: collection at: index
)
public equalizeRowElements: visuals = (
^self new equalizeRowElements: visuals
)
)
public class ColumnCell = SequenceCell (
(* An area used for elements of a Column. *)
) (
public height = (
^principalSize
)
public height: pixels <Integer> = (
principalSize:: pixels
)
public isSqueezing ^<Boolean> = (
^imposesSize not and: [super isSqueezing]
)
public isVisualSquishy ^<Boolean> = (
^imposesSize not and: [visual isSquishy]
)
mayAccommodateVisualsNaturalHeightChange ^<Boolean> = (
^imposesSize not and:
[visual parent mayAccommodateNaturalHeightChangeOf: visual]
)
public minimumHeight ^<Number> = (
^minimumSize
)
public minimumHeight: newValue <Number> = (
minimumSize: newValue
)
public naturalExtent = (
^visual naturalExtent x @ (minimumSize max: height)
)
public naturalHeightForWidth: size <Number> ^<Number> = (
(* Answer the size the visual should take along the principal axis within a parent of the given size along the orthogonal axis. *)
^principalSizeS ifNil: [visual naturalHeightForWidth: size]
)
naturalOrthogonalSize = (
^visual naturalExtent x
)
naturalPrincipalSize = (
^visual naturalExtent y
)
) : (
public visual: aVisual <Visual> = (
^self new visual: aVisual; yourself
)
)
public class Frame = Area (|
leftFractionS
leftOffsetS
topFractionS
topOffsetS
rightFractionS
rightOffsetS
bottomFractionS
bottomOffsetS
public lastSuggestedExtentKnownToParent
|) (
public bottomFraction = (
^bottomFractionS
)
public bottomFraction: fraction <Number> = (
bottomFractionS:: fraction.
requestBoundsUpdate
)
public bottomOffset = (
^bottomOffsetS
)
public bottomOffset: offset <Integer> = (
bottomOffsetS:: offset.
requestBoundsUpdate
)
public bounds: aRectangle = (
(* Occupy the given rectangle; no elasticity. *)
self
offsetsLeft: aRectangle left
top: aRectangle top
right: aRectangle right
bottom: aRectangle bottom
)
public boundsWithin: compositionBounds <Rectangle> = (
| parentOrigin parentExtent width height left top right bottom |
parentOrigin:: compositionBounds origin.
parentExtent:: compositionBounds extent.
width:: parentExtent x.
height:: parentExtent y.
left:: (width * leftFraction) rounded + leftOffset.
top:: (height * topFraction) rounded + topOffset.
right:: (width * rightFraction) rounded + rightOffset.
bottom:: (height * bottomFraction) rounded + bottomOffset.
^Rectangle
origin: left @ top + parentOrigin
corner: right @ bottom + parentOrigin
)
public copyConfigurationFromFrame: another <Frame> = (
leftFraction:: another leftFraction.
leftOffset:: another leftOffset.
topFraction:: another topFraction.
topOffset:: another topOffset.
rightFraction:: another rightFraction.
rightOffset:: another rightOffset.
bottomFraction:: another bottomFraction.
bottomOffset:: another bottomOffset
)
public copyConfigurationTo: another <Position> = (
another copyConfigurationFromFrame: self
)
extent: newExtent <Point> = (
rightOffsetS:: leftOffsetS + newExtent x.
bottomOffsetS:: topOffsetS + newExtent y.
requestBoundsUpdate
)
fractionsLeft: left top: top right: right bottom: bottom = (
self
leftFraction: left
offset: 0
topFraction: top
offset: 0
rightFraction: right
offset: 0
bottomFraction: bottom
offset: 0
)
public fullyCoverParent = (
(* Be elastic by fully covering the parent and resizing with it. *)
padding: 0
)
public isElastic ^<Boolean> = (
(* A frame is elastic if the bounds it computes for its visual depend on the size of the parent. *)
^leftFraction ~= 0
or: [topFraction ~= 0
or: [rightFraction ~= 0
or: [bottomFraction ~= 0]]]
)
public isElasticX ^<Boolean> = (
(* True if the final bounds along the X axis depend on the size of the parent. *)
^rightFraction ~= 0 or: [leftFraction ~= 0]
)
public isElasticY ^<Boolean> = (
(* True if the final bounds along the Y axis depend on the size of the parent. *)
^bottomFraction ~= 0 or: [topFraction ~= 0]
)
public isFramedByParent ^<Boolean> = (
(* This is an even stronger condition than isElastic: a Frame with the four sides rigidly attached to the corresponding sides of the parent. *)
^leftFraction = 0
and: [topFraction = 0
and: [rightFraction = 1
and: [bottomFraction = 1]]]
)
public isSqueezing ^<Boolean> = (
(* The parent will only be able to exhibit its squeezing behavior if the frame is able to grow vertically. *)
^super isSqueezing and: [isElasticY]
)
public isVisualSquishy ^<Boolean> = (
(* A squishy visual contained by a frame can only manifest its squishiness if the frame allows it to grow vertically. *)
^isElasticY and:
[visual isSquishy]
)
public isZero ^<Boolean> = (
^isElastic not
and: [leftOffset = 0
and: [rightOffset = 0
and: [topOffset = 0
and: [bottomOffset = 0]]]]
)
public leftFraction = (
^leftFractionS
)
public leftFraction: fraction <Number> = (
leftFractionS:: fraction.
requestBoundsUpdate
)
public leftFraction: lf offset: lo
topFraction: tf offset: to
rightFraction: rf offset: ro
bottomFraction: bf offset: bo = (
leftFractionS:: lf.
leftOffsetS:: lo.
topFractionS:: tf.
topOffsetS:: to.
rightFractionS:: rf.
rightOffsetS:: ro.
bottomFractionS:: bf.
bottomOffsetS:: bo.
requestBoundsUpdate
)
public leftOffset = (
^leftOffsetS
)
public leftOffset: offset <Integer> = (
leftOffsetS:: offset.
requestBoundsUpdate
)
mayAccommodateVisualsNaturalHeightChange ^<Boolean> = (
^isElasticY and: [super mayAccommodateVisualsNaturalHeightChange]
)
mayAccommodateVisualsNaturalWidthChange ^<Boolean> = (
^isElasticX and: [super mayAccommodateVisualsNaturalWidthChange]
)
offsetsLeft: left top: top right: right bottom: bottom = (
self
leftFraction: 0
offset: left
topFraction: 0
offset: top
rightFraction: 0
offset: right
bottomFraction: 0
offset: bottom
)
padding: padding <Integer | Point> = (
(* Set up the receiver so that its visual fully covers its parent and padded according to the argument. The argument is either the number of pixels to leave on all sides of the parent or a Point with separate settings used for for the left/right and top/bottom sides. *)
padding isInteger
ifTrue:
[offsetsLeft: padding
top: padding
right: padding negated
bottom: padding negated]
ifFalse:
[offsetsLeft: padding x
top: padding y
right: padding x negated
bottom: padding y negated.].
rightFraction: 1.
bottomFraction: 1
)
public resetLastSuggestedExtentKnownToParent = (
lastSuggestedExtentKnownToParent:: -1 @ -1
(* we need a value that's a legal Point but cannot equal any legal extent *)
)
public rightFraction = (
^rightFractionS
)
public rightFraction: fraction <Number> = (
rightFractionS:: fraction.
requestBoundsUpdate