/
Morph.class.st
6790 lines (5512 loc) · 200 KB
/
Morph.class.st
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
"
A Morph (from the Greek ""shape"" or ""form"") is an interactive graphical object. General information on the Morphic system can be found at http://minnow.cc.gatech.edu/squeak/30.
Morphs exist in a tree, rooted at a World (generally a PasteUpMorph). The morphs owned by a morph are its submorphs. Morphs are drawn recursively; if a Morph has no owner it never gets drawn. To hide a Morph and its submorphs, set its #visible property to false using the #visible: method.
The World (screen) coordinate system is used for most coordinates, but can be changed if there is a TransformMorph somewhere in the owner chain.
My instance variables have accessor methods (e.g., #bounds, #bounds:). Most users should use the accessor methods instead of using the instance variables directly.
Structure:
instance var Type Description
bounds Rectangle A Rectangle indicating my position and a size that will enclose me.
owner Morph My parent Morph, or nil for the top-level Morph, which is a
or nil world, typically a PasteUpMorph.
submorphs Array My child Morphs.
fullBounds Rectangle A Rectangle minimally enclosing me and my submorphs.
color Color My primary color. Subclasses can use this in different ways.
extension MorphExtension Allows extra properties to be stored without adding a
or nil storage burden to all morphs.
By default, Morphs do not position their submorphs. Morphs may position their submorphs directly or use a LayoutPolicy to automatically control their submorph positioning.
Although Morph has some support for BorderStyle, most users should use BorderedMorph if they want borders.
"
Class {
#name : #Morph,
#superclass : #Object,
#instVars : [
'bounds',
'owner',
'submorphs',
'fullBounds',
'color',
'extension'
],
#classVars : [
'CmdGesturesEnabled',
'CycleHalosBothDirections',
'DefaultYellowButtonMenuEnabled',
'EmptyArray',
'EventDispatcher',
'HalosEnabled',
'ShortcutsHandler'
],
#classInstVars : [
'announcer'
],
#category : #'Morphic-Core-Kernel'
}
{ #category : #accessing }
Morph class >> announcer [
^ announcer ifNil: [ announcer := Announcer new ].
]
{ #category : #settings }
Morph class >> cmdGesturesEnabled [
^ CmdGesturesEnabled ifNil: [CmdGesturesEnabled := true]
]
{ #category : #settings }
Morph class >> cmdGesturesEnabled: aBoolean [
CmdGesturesEnabled := aBoolean
]
{ #category : #settings }
Morph class >> cycleHalosBothDirections [
^ CycleHalosBothDirections ifNil: [ CycleHalosBothDirections := false ].
]
{ #category : #settings }
Morph class >> cycleHalosBothDirections: aBoolean [
CycleHalosBothDirections := aBoolean.
]
{ #category : #accessing }
Morph class >> defaultEventDispatcher [
^ EventDispatcher ifNil: [ EventDispatcher := MorphicEventDispatcher new ]
]
{ #category : #settings }
Morph class >> defaultYellowButtonMenuEnabled [
^ DefaultYellowButtonMenuEnabled ifNil: [DefaultYellowButtonMenuEnabled := false]
]
{ #category : #settings }
Morph class >> defaultYellowButtonMenuEnabled: aBoolean [
DefaultYellowButtonMenuEnabled := aBoolean
]
{ #category : #settings }
Morph class >> halosEnabled [
^ HalosEnabled ifNil: [ HalosEnabled := true ]
]
{ #category : #settings }
Morph class >> halosEnabled: aBoolean [
HalosEnabled := aBoolean
]
{ #category : #'class initialization' }
Morph class >> initialize [
"Morph initialize"
"this empty array object is shared by all morphs with no submorphs:"
EmptyArray := Array new.
]
{ #category : #settings }
Morph class >> morphNavigationShortcutsOn: aBuilder [
"Basic, general navigation shortcut among morphs. #MorphNoCtrl will not work for TextMorphs."
<keymap>
(aBuilder shortcut: #navigateFocusForwardCtrl)
category: #MorphFocusCtrlNavigation
default: Character tab ctrl asKeyCombination
do: [ :target :morph :event | morph navigateFocusForward ].
(aBuilder shortcut: #navigateFocusBackwardCtrl)
category: #MorphFocusCtrlNavigation
default: Character tab shift ctrl asKeyCombination
do: [ :target :morph :event | morph navigateFocusBackward ].
(aBuilder shortcut: #navigateFocusForward)
category: #MorphFocusNavigation
default: Character tab asKeyCombination
do: [ :target :morph :event | morph navigateFocusForward ].
(aBuilder shortcut: #navigateFocusBackward)
category: #MorphFocusNavigation
default: Character tab shift asKeyCombination
do: [ :target :morph :event | morph navigateFocusBackward ]
]
{ #category : #misc }
Morph class >> morphsUnknownToTheirOwners [
"Return a list of all morphs (other than HandMorphs) whose owners do not contain them in their submorph lists"
"Morph morphsUnknownToTheirOwners"
| problemMorphs |
problemMorphs := OrderedCollection new.
self allSubInstances
do: [ :m |
| itsOwner |
(m isHandMorph not and: [ (itsOwner := m owner) notNil and: [ (itsOwner submorphs includes: m) not ] ])
ifTrue: [ problemMorphs add: m ] ].
^ problemMorphs
]
{ #category : #'instance creation' }
Morph class >> newBounds: bounds [
^ self new privateBounds: bounds
]
{ #category : #'instance creation' }
Morph class >> newBounds: bounds color: color [
^ (self new privateBounds: bounds) privateColor: color
]
{ #category : #'instance creation' }
Morph class >> newSticky [
^ self new beSticky
]
{ #category : #misc }
Morph class >> obtainArrowheadFor: aPrompt defaultValue: defaultPoint [
"Allow the user to supply a point to serve as an arrowhead size. Answer nil if we fail to get a good point"
| result |
result := UIManager default request: aPrompt initialAnswer: defaultPoint asString.
result isEmptyOrNil ifTrue: [^ nil].
^ [(Point readFrom: result readStream)]
on: Error do: [:ex | nil].
]
{ #category : #shortcuts }
Morph class >> shortcutsHandler [
^ ShortcutsHandler
]
{ #category : #shortcuts }
Morph class >> shortcutsHandler: anObject [
ShortcutsHandler := anObject
]
{ #category : #'dropping/grabbing' }
Morph >> aboutToBeGrabbedBy: aHand [
"The receiver is being grabbed by a hand.
Perform necessary adjustments (if any) and return the actual morph
that should be added to the hand."
self formerOwner: owner.
self formerPosition: self position.
^self "Grab me"
]
{ #category : #layout }
Morph >> acceptDroppingMorph: aMorph event: evt [
"This message is sent when a morph is dropped onto a morph that has agreed to accept the dropped morph by responding 'true' to the wantsDroppedMorph:Event: message. This default implementation just adds the given morph to the receiver."
| layout |
layout := self layoutPolicy.
layout ifNil:[^self addMorph: aMorph].
self privateAddMorph: aMorph
atIndex: (layout indexForInserting: aMorph at: evt position in: self).
]
{ #category : #updating }
Morph >> actAsExecutor [
"Prepare the receiver to act as executor for any resources associated with it"
self breakDependents
]
{ #category : #'events-accessing' }
Morph >> actionMap [
"Answer an action map"
^self updateableActionMap
]
{ #category : #structure }
Morph >> activeHand [
| world |
world := self world ifNil: [^ ActiveHand ].
^ world activeHand ifNil: [ ^ ActiveHand ]
]
{ #category : #menus }
Morph >> addAddHandMenuItemsForHalo: aMenu hand: aHandMorph [
"The former charter of this method was to add halo menu items that pertained specifically to the hand. Over time this charter has withered, and most morphs reimplement this method simply to add their morph-specific menu items. So in the latest round, all other implementors in the standard image have been removed. However, this is left here as a hook for the benefit of existing code in client uses."
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector after: delayTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: #() after: delayTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector at: scheduledTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: #() at: scheduledTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector with: arg1 after: delayTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: (Array with: arg1) after: delayTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector with: arg1 at: scheduledTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: (Array with: arg1) at: scheduledTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector with: arg1 with: arg2 after: delayTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: (Array with: arg1 with: arg2) after: delayTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector with: arg1 with: arg2 at: scheduledTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: (Array with: arg1 with: arg2) at: scheduledTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector withArguments: args after: delayTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
^self addAlarm: aSelector withArguments: args at: Time millisecondClockValue + delayTime
]
{ #category : #'events-alarms' }
Morph >> addAlarm: aSelector withArguments: args at: scheduledTime [
"Add an alarm (that is an action to be executed once) with the given set of parameters"
| scheduler |
scheduler := self alarmScheduler.
scheduler ifNotNil:[scheduler addAlarm: aSelector withArguments: args for: self at: scheduledTime].
]
{ #category : #'submorphs-add/remove' }
Morph >> addAllMorphs: aCollection [
^self privateAddAllMorphs: aCollection atIndex: submorphs size
]
{ #category : #'submorphs-add/remove' }
Morph >> addAllMorphs: aCollection after: anotherMorph [
^self privateAddAllMorphs: aCollection
atIndex: (submorphs indexOf: anotherMorph ifAbsent: [submorphs size])
]
{ #category : #menu }
Morph >> addBorderStyleMenuItems: aMenu hand: aHandMorph [
"Probably one could offer border-style items even if it's not a borderedMorph, so this remains a loose end for the moment"
]
{ #category : #'layout-menu' }
Morph >> addCellLayoutMenuItems: aMenu hand: aHand [
"Cell (e.g., child) related items"
| menu sub |
menu := UIManager default newMenuIn: self for: self.
menu addUpdating: #hasDisableTableLayoutString selector: #changeDisableTableLayout.
menu addLine.
sub := UIManager default newMenuIn: self for: self.
#(#rigid #shrinkWrap #spaceFill)
do: [ :sym |
sub
addUpdating: #hResizingString:
target: self
selector: #hResizing:
argumentList: (Array with: sym) ].
menu add: 'horizontal resizing' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#rigid #shrinkWrap #spaceFill)
do: [ :sym |
sub
addUpdating: #vResizingString:
target: self
selector: #vResizing:
argumentList: (Array with: sym) ].
menu add: 'vertical resizing' subMenu: sub.
aMenu ifNotNil: [ aMenu add: 'child layout' subMenu: menu ].
^ menu
]
{ #category : #menus }
Morph >> addCustomHaloMenuItems: aMenu hand: aHandMorph [
"Add morph-specific items to the given menu which was invoked by the given hand from the halo. To get started, we defer to the counterpart method used with the option-menu, but in time we can have separate menu choices for halo-menus and for option-menus"
self addCustomMenuItems: aMenu hand: aHandMorph
]
{ #category : #menus }
Morph >> addCustomMenuItems: aCustomMenu hand: aHandMorph [
"Add morph-specific items to the given menu which was invoked by the given hand. This method provides is invoked both from the halo-menu and from the control-menu regimes."
]
{ #category : #'debug and other' }
Morph >> addDebuggingItemsTo: aMenu hand: aHandMorph [
aMenu add: 'debug...' subMenu: (self buildDebugMenu: aHandMorph).
aMenu lastItem icon: (self iconNamed: #smallDebugIcon)
]
{ #category : #updating }
Morph >> addDependent: anObject [
self announcer
when: MorphChanged , MorphChangedWithArguments
send: #handleUpdate:
to: anObject.
^ anObject
]
{ #category : #'drop shadows' }
Morph >> addDropShadow [
self hasDropShadow ifTrue:[^self].
self changed.
self hasDropShadow: true.
self shadowOffset: 3@3.
self layoutChanged.
self changed.
]
{ #category : #'drop shadows' }
Morph >> addDropShadowMenuItems: aMenu hand: aHand [
| menu |
menu := UIManager default newMenuIn: self for: self.
menu
addUpdating: #hasDropShadowString
selector: #toggleDropShadow.
menu addLine.
menu add: 'shadow color...' target: self selector: #changeShadowColor.
menu add: 'shadow offset...' target: self selector: #setShadowOffset:.
aMenu add: 'drop shadow' subMenu: menu.
]
{ #category : #'meta-actions' }
Morph >> addEmbeddingMenuItemsTo: aMenu hand: aHandMorph [
"Construct a menu offerring embed targets for the receiver. If the incoming menu is is not degenerate, add the constructed menu as a submenu; in any case, answer the embed-target menu"
| menu potentialEmbeddingTargets |
potentialEmbeddingTargets := self potentialEmbeddingTargets.
potentialEmbeddingTargets size > 1
ifFalse: [ ^ self ].
menu := UIManager default newMenuIn: self for: self.
potentialEmbeddingTargets
reverseDo: [ :m |
menu
add: m class name asString
target: m
selector: #addMorphFrontFromWorldPosition:
argument: self topRendererOrSelf.
menu lastItem icon: (m iconOrThumbnailOfSize: 16).
self owner == m
ifTrue: [ menu lastItem emphasis: 1 ] ].
aMenu add: 'embed into' subMenu: menu.
^ menu
]
{ #category : #menus }
Morph >> addExportMenuItems: aMenu hand: aHandMorph [
"Add export items to the menu"
aMenu
ifNotNil: [ | aSubMenu |
aSubMenu := UIManager default newMenuIn: self for: self.
aSubMenu add: 'BMP file' selector: #exportAsBMP.
aSubMenu add: 'GIF file' selector: #exportAsGIF.
aSubMenu add: 'JPEG file' selector: #exportAsJPEG.
aSubMenu add: 'PNG file' selector: #exportAsPNG.
aMenu
add: 'export...'
icon: (self iconNamed: #smallExportIcon)
subMenu: aSubMenu.
aMenu lastItem
icon: (self iconNamed: #smallExportIcon) ]
]
{ #category : #menus }
Morph >> addFillStyleMenuItems: aMenu hand: aHand [
"Add the items for changing the current fill style of the Morph"
| menu |
menu := UIManager default newMenuIn: self for: self.
self fillStyle addFillStyleMenuItems: menu hand: aHand from: self.
menu addLine.
menu add: 'solid fill' selector: #useSolidFill.
menu add: 'gradient fill' selector: #useGradientFill.
menu add: 'bitmap fill' selector: #useBitmapFill.
menu add: 'default fill' selector: #useDefaultFill.
aMenu add: 'fill style' subMenu: menu.
]
{ #category : #'rotate scale and flex' }
Morph >> addFlexShell [
"Wrap a rotating and scaling shell around this morph."
| oldHalo flexMorph myWorld anIndex |
myWorld := self world.
oldHalo := self halo.
anIndex := self owner submorphIndexOf: self.
self owner addMorph: (flexMorph := self newTransformationMorph asFlexOf: self)
asElementNumber: anIndex.
self transferStateToRenderer: flexMorph.
oldHalo ifNotNil: [oldHalo setTarget: flexMorph].
myWorld ifNotNil: [myWorld startSteppingSubmorphsOf: flexMorph].
^ flexMorph
]
{ #category : #'halos and balloon help' }
Morph >> addHalo [
"Invoke a halo programatically (e.g., not from a meta gesture)"
^self addHalo: nil
]
{ #category : #'halos and balloon help' }
Morph >> addHalo: evt from: formerHaloOwner [
"Transfer a halo from the former halo owner to the receiver"
^self addHalo: evt
]
{ #category : #menus }
Morph >> addHaloActionsTo: aMenu [
"Add items to aMenu representing actions requestable via halo"
| subMenu |
subMenu := UIManager default newMenuIn: self for: self.
subMenu
buildTitle: [ :menuTitle | menuTitle
bigTitle: self externalName
];
add: 'delete' selector: #dismissViaHalo.
subMenu balloonTextForLastItem: 'Delete this object -- warning -- can be destructive!' translated.
self maybeAddCollapseItemTo: subMenu.
subMenu add: 'grab' selector: #openInHand.
subMenu balloonTextForLastItem: 'Pick this object up -- warning, since this removes it from its container, it can have adverse effects.' translated.
subMenu addLine.
subMenu add: 'resize' selector: #resizeFromMenu.
subMenu balloonTextForLastItem: 'Change the size of this object' translated.
subMenu add: 'duplicate' selector: #maybeDuplicateMorph.
subMenu balloonTextForLastItem: 'Hand me a copy of this object'.
subMenu addLine.
subMenu add: 'set color' target: self renderedMorph selector: #changeColor.
subMenu balloonTextForLastItem: 'Change the color of this object'.
subMenu addLine.
subMenu add: 'inspect' target: self selector: #inspect.
subMenu balloonTextForLastItem: 'Open an Inspector on this object'.
aMenu add: 'halo actions...' subMenu: subMenu
]
{ #category : #'layout-menu' }
Morph >> addLayoutMenuItems: topMenu hand: aHand [
| aMenu |
aMenu := UIManager default newMenuIn: self for: self.
aMenu addUpdating: #hasNoLayoutString selector: #changeNoLayout.
aMenu addUpdating: #hasProportionalLayoutString selector: #changeProportionalLayout.
aMenu addUpdating: #hasTableLayoutString selector: #changeTableLayout.
aMenu addLine.
aMenu add: 'change layout inset...' selector: #changeLayoutInset:.
aMenu addLine.
self addCellLayoutMenuItems: aMenu hand: aHand.
self addTableLayoutMenuItems: aMenu hand: aHand.
topMenu ifNotNil: [ topMenu add: 'layout' subMenu: aMenu ].
^aMenu
]
{ #category : #menus }
Morph >> addMiscExtrasTo: aMenu [
"Add a submenu of miscellaneous extra items to the menu."
| subMenu |
self isWorldMorph
ifTrue: [ ^ self ].
subMenu := UIManager default newMenuIn: self for: self.
self renderedMorph isSystemWindow
ifFalse: [ subMenu add: 'put in a window' selector: #embedInWindow ].
subMenu add: 'adhere to edge...' selector: #adhereToEdge.
aMenu add: 'extras...' subMenu: subMenu
]
{ #category : #menu }
Morph >> addModelYellowButtonItemsTo: aCustomMenu event: evt [
"Give my models a chance to add their context-menu items to
aCustomMenu."
self model
ifNotNil: [:mod |
mod
addModelYellowButtonMenuItemsTo: aCustomMenu
forMorph: self
hand: evt hand]
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: aMorph [
self addMorphFront: aMorph.
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: newMorph after: aMorph [
"Add the given morph as one of my submorphs, inserting it after anotherMorph"
^self privateAddMorph: newMorph atIndex: (submorphs indexOf: aMorph)+1
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: aMorph asElementNumber: aNumber [
"Add the given morph so that it becomes the aNumber'th element of my submorph list. If aMorph is already one of my submorphs, reposition it"
(submorphs includes: aMorph) ifTrue:
[aMorph privateDelete].
(aNumber <= submorphs size)
ifTrue:
[self addMorph: aMorph inFrontOf: (submorphs at: aNumber)]
ifFalse:
[self addMorphBack: aMorph]
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: newMorph behind: aMorph [
"Add a morph to the list of submorphs behind the specified morph"
^self privateAddMorph: newMorph atIndex: (submorphs indexOf: aMorph) + 1.
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: aMorph fullFrame: aLayoutFrame [
aMorph layoutFrame: aLayoutFrame asLayoutFrame.
aMorph hResizing: #spaceFill; vResizing: #spaceFill.
self addMorph: aMorph.
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorph: newMorph inFrontOf: aMorph [
"Add a morph to the list of submorphs in front of the specified morph"
^self privateAddMorph: newMorph atIndex: ((submorphs indexOf: aMorph) max: 1).
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorphBack: aMorph [
^self privateAddMorph: aMorph atIndex: submorphs size+1
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorphCentered: aMorph [
aMorph position: bounds center - (aMorph extent // 2).
self addMorphFront: aMorph.
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorphFront: aMorph [
^self privateAddMorph: aMorph atIndex: 1
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorphFront: aMorph fromWorldPosition: wp [
self addMorphFront: aMorph.
aMorph position: (self transformFromWorld globalPointToLocal: wp)
]
{ #category : #'submorphs-add/remove' }
Morph >> addMorphFrontFromWorldPosition: aMorph [
^self addMorphFront: aMorph fromWorldPosition: aMorph positionInWorld.
]
{ #category : #'wiw support' }
Morph >> addMorphInFrontOfLayer: aMorph [
| targetLayer |
targetLayer := aMorph morphicLayerNumber.
submorphs do: [ :each | | layerHere |
each == aMorph ifTrue: [^self].
layerHere := each morphicLayerNumber.
"the <= is the difference - it insures we go to the front of our layer"
targetLayer <= layerHere ifTrue: [
^self addMorph: aMorph inFrontOf: each
].
].
self addMorphBack: aMorph.
]
{ #category : #'wiw support' }
Morph >> addMorphInLayer: aMorph [
submorphs do: [ :each |
each == aMorph ifTrue: [^self].
aMorph morphicLayerNumber < each morphicLayerNumber ifTrue: [
^self addMorph: aMorph inFrontOf: each
].
].
self addMorphBack: aMorph
]
{ #category : #menu }
Morph >> addMyYellowButtonMenuItemsToSubmorphMenus [
"Answer true if I have items to add to the context menus of my submorphs"
^true
]
{ #category : #menu }
Morph >> addNestedYellowButtonItemsTo: aMenu event: evt [
"Add items to aMenu starting with me and proceeding down
through my submorph chain,
letting any submorphs that include the event position
contribute their items to the bottom of the menu, separated by
a line."
| underMouse submenu |
self addYellowButtonMenuItemsTo: aMenu event: evt.
underMouse := self submorphThat: [ :each | each containsPoint: evt position ] ifNone: [ ^ self ].
(underMouse addMyYellowButtonMenuItemsToSubmorphMenus and: [ underMouse hasYellowButtonMenu ])
ifFalse: [ ^ self ].
aMenu addLine.
submenu := UIManager default newMenuIn: underMouse for: underMouse.
underMouse addNestedYellowButtonItemsTo: submenu event: evt.
aMenu add: underMouse externalName icon: (underMouse iconOrThumbnailOfSize: 16) subMenu: submenu
]
{ #category : #'halos and balloon help' }
Morph >> addOptionalHandlesTo: aHalo box: box [
]
{ #category : #menus }
Morph >> addStandardHaloMenuItemsTo: aMenu hand: aHandMorph [
"Add standard halo items to the menu"
aMenu add: 'send to back' selector: #goBehind.
aMenu add: 'bring to front' selector: #comeToFront.
self addEmbeddingMenuItemsTo: aMenu hand: aHandMorph.
aMenu addLine.
self addFillStyleMenuItems: aMenu hand: aHandMorph.
self addBorderStyleMenuItems: aMenu hand: aHandMorph.
self addDropShadowMenuItems: aMenu hand: aHandMorph.
self addLayoutMenuItems: aMenu hand: aHandMorph.
self addHaloActionsTo: aMenu.
owner isTextMorph
ifTrue: [ self addTextAnchorMenuItems: aMenu hand: aHandMorph ].
aMenu addLine.
self addToggleItemsToHaloMenu: aMenu.
aMenu addLine.
self addExportMenuItems: aMenu hand: aHandMorph.
self addMiscExtrasTo: aMenu.
self addDebuggingItemsTo: aMenu hand: aHandMorph.
aMenu addLine.
aMenu defaultTarget: aHandMorph
]
{ #category : #'layout-menu' }
Morph >> addTableLayoutMenuItems: aMenu hand: aHand [
| menu sub |
menu := UIManager default newMenuIn: self for: self.
menu addUpdating: #hasReverseCellsString selector: #changeReverseCells.
menu addUpdating: #hasClipLayoutCellsString selector: #changeClipLayoutCells.
menu addUpdating: #hasRubberBandCellsString selector: #changeRubberBandCells.
menu addLine.
menu add: 'change cell inset...' selector: #changeCellInset:.
menu add: 'change min cell size...' selector: #changeMinCellSize:.
menu add: 'change max cell size...' selector: #changeMaxCellSize:.
menu addLine.
sub := UIManager default newMenuIn: self for: self.
#(#leftToRight #rightToLeft #topToBottom #bottomToTop)
do: [ :sym |
sub
addUpdating: #listDirectionString:
target: self
selector: #changeListDirection:
argumentList: (Array with: sym) ].
menu add: 'list direction' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#none #leftToRight #rightToLeft #topToBottom #bottomToTop)
do: [ :sym |
sub
addUpdating: #wrapDirectionString:
target: self
selector: #wrapDirection:
argumentList: (Array with: sym) ].
menu add: 'wrap direction' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#center #topLeft #topRight #bottomLeft #bottomRight #topCenter #leftCenter #rightCenter #bottomCenter)
do: [ :sym |
sub
addUpdating: #cellPositioningString:
target: self
selector: #cellPositioning:
argumentList: (Array with: sym) ].
menu add: 'cell positioning' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#topLeft #bottomRight #center #justified)
do: [ :sym |
sub
addUpdating: #listCenteringString:
target: self
selector: #listCentering:
argumentList: (Array with: sym) ].
menu add: 'list centering' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#topLeft #bottomRight #center #justified)
do: [ :sym |
sub
addUpdating: #wrapCenteringString:
target: self
selector: #wrapCentering:
argumentList: (Array with: sym) ].
menu add: 'wrap centering' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#none #equal)
do: [ :sym |
sub
addUpdating: #listSpacingString:
target: self
selector: #listSpacing:
argumentList: (Array with: sym) ].
menu add: 'list spacing' subMenu: sub.
sub := UIManager default newMenuIn: self for: self.
#(#none #localRect #localSquare #globalRect #globalSquare)
do: [ :sym |
sub
addUpdating: #cellSpacingString:
target: self
selector: #cellSpacing:
argumentList: (Array with: sym) ].
menu add: 'cell spacing' subMenu: sub.
aMenu ifNotNil: [ aMenu add: 'table layout' subMenu: menu ].
^ menu
]
{ #category : #'text-anchor' }
Morph >> addTextAnchorMenuItems: topMenu hand: aHand [
| aMenu |
aMenu := UIManager default newMenuIn: self for: self.
aMenu addUpdating: #hasInlineAnchorString selector: #changeInlineAnchor.
aMenu addUpdating: #hasParagraphAnchorString selector: #changeParagraphAnchor.
aMenu addUpdating: #hasDocumentAnchorString selector: #changeDocumentAnchor.
topMenu ifNotNil: [ topMenu add: 'text anchor' subMenu: aMenu ].
^aMenu
]
{ #category : #menu }
Morph >> addTitleForHaloMenu: aMenu [
aMenu buildTitle: [ :menuTitle | menuTitle
bigTitle: self externalName;
icon: (self iconOrThumbnailOfSize: 18);
cellInset: 3
]
]
{ #category : #menus }
Morph >> addToggleItemsToHaloMenu: aMenu [
"Add standard true/false-checkbox items to the memu"
#(#(#resistsRemovalString #toggleResistsRemoval 'whether I should be reistant to easy deletion via the pink X handle' true) #(#stickinessString #toggleStickiness 'whether I should be resistant to a drag done by mousing down on me' true) #(#lockedString #lockUnlockMorph 'when "locked", I am inert to all user interactions' true) #(#hasClipSubmorphsString #changeClipSubmorphs 'whether the parts of objects within me that are outside my bounds should be masked.' false) #(#hasDirectionHandlesString #changeDirectionHandles 'whether direction handles are shown with the halo' false) #(#hasDragAndDropEnabledString #changeDragAndDrop 'whether I am open to having objects dropped into me' false))
do: [ :each |
aMenu addUpdating: each first selector: each second.
aMenu balloonTextForLastItem: each third translated ].
self couldHaveRoundedCorners
ifFalse: [ ^ self ].
aMenu addUpdating: #roundedCornersString selector: #toggleCornerRounding.
aMenu balloonTextForLastItem: 'whether my corners should be rounded' translated
]
{ #category : #utilities }
Morph >> addTransparentSpacerOfSize: aPoint [
self addMorphBack: (self transparentSpacerOfSize: aPoint)
]
{ #category : #menu }
Morph >> addYellowButtonMenuItemsTo: aMenu event: evt [
"Populate aMenu with appropriate menu items for a
yellow-button (context menu) click."
aMenu defaultTarget: self.
self defaultYellowButtonMenuEnabled ifFalse: [^ self].
"aMenu addStayUpItem."
self addModelYellowButtonItemsTo: aMenu event: evt.
self cmdGesturesEnabled ifTrue: [
aMenu addLine.
aMenu add: 'inspect' selector: #inspect].
aMenu addLine.
self isWorldMorph ifFalse: [aMenu add: 'delete' selector: #delete].
self world selectedObject == self
ifTrue: [aMenu add: 'halo off' selector: #removeHalo]
ifFalse: [aMenu add: 'halo on' selector: #addHalo].
(self isWorldMorph
or: [self wantsToBeTopmost])
ifFalse: [
aMenu addLine.
aMenu add: 'send to back' selector: #goBehind.
aMenu add: 'bring to front' selector: #comeToFront.
self addEmbeddingMenuItemsTo: aMenu hand: evt hand].
self isWorldMorph ifFalse: [
self isFullOnScreen ifFalse: [aMenu add: 'move onscreen' selector: #goHome]].
self addLayoutMenuItems: aMenu hand: evt hand.
(owner notNil
and: [owner isTextMorph])
ifTrue: [self addTextAnchorMenuItems: aMenu hand: evt hand].
self isWorldMorph ifFalse: [
aMenu addLine.
self addToggleItemsToHaloMenu: aMenu].
aMenu addLine.
self isWorldMorph
ifFalse: [aMenu add: 'copy to paste buffer' selector: #copyToPasteBuffer:].
(self allStringsAfter: nil) isEmpty ifFalse: [aMenu add: 'copy text' selector: #clipText].
self addExportMenuItems: aMenu hand: evt hand.
aMenu addLine.
aMenu add: 'adhere to edge...' selector: #adhereToEdge.
self addCustomMenuItems: aMenu hand: evt hand
]
{ #category : #'change reporting' }
Morph >> addedMorph: aMorph [
"Notify the receiver that the given morph was just added."
]
{ #category : #menus }
Morph >> adhereToEdge [
| menu |
menu := UIManager default newMenuIn: self for: self.
#(top right bottom left - center - topLeft topRight bottomRight bottomLeft - none)
do: [:each |
each == #-
ifTrue: [menu addLine]
ifFalse: [menu add: each asString selector: #setToAdhereToEdge: argument: each]].
menu popUpEvent: self currentEvent in: self world
]
{ #category : #menus }
Morph >> adhereToEdge: edgeSymbol [
| edgeMessage |
(owner isNil or: [owner isHandMorph]) ifTrue: [^self].
(owner class canUnderstand: edgeSymbol) ifFalse: [^self].
(self class canUnderstand: ( edgeMessage := (edgeSymbol , ':') asSymbol ))
ifFalse: [^self].
self perform: edgeMessage
withArguments: (Array with: (owner perform: edgeSymbol))
]
{ #category : #layout }
Morph >> adjustLayoutBounds [
"Adjust the receivers bounds depending on the resizing strategy imposed"
| hFit vFit box myExtent extent |
hFit := self hResizing.
vFit := self vResizing.
(hFit == #shrinkWrap or: [ vFit == #shrinkWrap ])
ifFalse: [ ^ self ]. "not needed"
box := self layoutBounds.
myExtent := box extent.
extent := self submorphBounds corner - box origin.
hFit == #shrinkWrap
ifTrue: [ myExtent := extent x @ myExtent y ].
vFit == #shrinkWrap
ifTrue: [ myExtent := myExtent x @ extent y ]. "Make sure we don't get smaller than minWidth/minHeight"
myExtent x < self minWidth
ifTrue: [ myExtent := (myExtent x max: self minWidth - self bounds width + self layoutBounds width) @ myExtent y ].
myExtent y < self minHeight
ifTrue: [ myExtent := myExtent x @ (myExtent y max: self minHeight - self bounds height + self layoutBounds height) ].
self layoutBounds: (box origin extent: myExtent)
]
{ #category : #menus }
Morph >> adjustedCenter [
"Provides a hook for objects to provide a reference point other than the receiver's center,for the purpose of centering a submorph under special circumstances, such as BalloonMorph"
^ self center
]
{ #category : #menus }
Morph >> adjustedCenter: c [
"Set the receiver's position based on the #adjustedCenter protocol for adhereToEdge. By default this simply sets the receiver's center. Though there are (at its inception anyway) no other implementors of this method, it is required in use with the #adhereToEdge when the centering of a submorph is to be with reference to a rectangle other than the receiver's center."
self center: c
]
{ #category : #accessing }
Morph >> adoptPaneColor: paneColor [
self submorphsDo:[:m| m adoptPaneColor: paneColor].
]
{ #category : #'events-alarms' }
Morph >> alarmScheduler [
"Return the scheduler being responsible for triggering alarms"
^self world
]
{ #category : #geometry }
Morph >> align: aPoint1 with: aPoint2 [
"Translate by aPoint2 - aPoint1."
^ self position: self position + (aPoint2 - aPoint1)
]
{ #category : #'submorphs-accessing' }
Morph >> allMorphs [
"Return a collection containing all morphs in this composite morph (including the receiver)."
| all |
all := (Array new: submorphs size) writeStream.
self allMorphsDo: [:m | all nextPut: m].
^ all contents
]
{ #category : #'submorphs-accessing' }
Morph >> allMorphsDo: aBlock [
"Evaluate the given block for all morphs in this composite morph (including the receiver)."
submorphs do: [:m | m allMorphsDo: aBlock].
aBlock value: self
]
{ #category : #'submorphs-accessing' }
Morph >> allMorphsInto: aSet [
"Return a set of all submorphs. Don't forget the hidden ones. Consider only objects that are in memory (see allNonSubmorphMorphs)."
submorphs do: [:m | m allMorphsInto: aSet].
self allNonSubmorphMorphs do: [:m |
(aSet includes: m) ifFalse: ["Stop infinite recursion"
m allMorphsInto: aSet]].
aSet add: self.