/
PasteUpMorph.class.st
1078 lines (871 loc) · 31.2 KB
/
PasteUpMorph.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 whose submorphs comprise a paste-up of rectangular subparts which ""show through"". Anything called a 'Playfield' is a PasteUpMorph.
Facilities commonly needed on pages of graphical presentations and on simulation playfields, such as the painting of new objects, turtle trails, gradient fills, background paintings, parts-bin behavior, collision-detection, etc., are (or will be) provided.
"
Class {
#name : #PasteUpMorph,
#superclass : #BorderedMorph,
#instVars : [
'backgroundMorph',
'worldState',
'griddingOn'
],
#classVars : [
'ShouldShowWorldMenu',
'ShouldSwapMenuOpenerButtons',
'WindowEventHandler',
'WorldAnnouncer'
],
#category : #'Morphic-Core-Worlds'
}
{ #category : #'initialize-release' }
PasteUpMorph class >> initialize [
ShouldSwapMenuOpenerButtons := false.
self shouldShowWorldMenu: true
]
{ #category : #acessing }
PasteUpMorph class >> isMenuOpenByLeftClick [
"Truth table:
swap isMac methodReturn
0 0 1
0 1 1
1 0 0
1 1 1
"
^ self shouldSwapMenuOpenerButtons ==> [ Smalltalk os isMacOS ]
]
{ #category : #accessing }
PasteUpMorph class >> shouldShowWorldMenu [
^ ShouldShowWorldMenu
]
{ #category : #accessing }
PasteUpMorph class >> shouldShowWorldMenu: anObject [
ShouldShowWorldMenu := anObject
]
{ #category : #settings }
PasteUpMorph class >> shouldShowWorldMenuSettingOn: aBuilder [
<systemsettings>
(aBuilder setting: #shouldShowWorldMenu)
target: self;
default: true;
parent: #morphic;
label: 'Show world menu';
description: 'Whether the World''s world menu should be shown or not on a click in the World.'
]
{ #category : #acessing }
PasteUpMorph class >> shouldSwapMenuOpenerButtons [
^ ShouldSwapMenuOpenerButtons
]
{ #category : #acessing }
PasteUpMorph class >> shouldSwapMenuOpenerButtons: aBoolean [
^ ShouldSwapMenuOpenerButtons := aBoolean
]
{ #category : #settings }
PasteUpMorph class >> shouldSwapMenuOpenerButtonsSetting: aBuilder [
<systemsettings>
(aBuilder setting: #shouldSwapMenuOpenerButtons)
label: 'Invert right and left click on world menu in Linux and Windows';
parent: #desktopSettings;
target: self;
getSelector: #shouldSwapMenuOpenerButtons;
setSelector: #shouldSwapMenuOpenerButtons:;
description:
'If checked the behaviour of the world menu is changed only under linuex and window. The main menu will appear on right click instead of left click.';
default: false
]
{ #category : #'event handling' }
PasteUpMorph >> acceptDroppingMorph: dropped event: evt [
"The supplied morph, known to be acceptable to the receiver, is now to be assimilated; the precipitating event is supplied"
| aMorph |
aMorph := self morphToDropFrom: dropped.
super acceptDroppingMorph: aMorph event: evt.
aMorph
submorphsDo: [ :m |
(m isKindOf: HaloMorph)
ifTrue: [ m delete ] ].
self bringTopmostsToFront
]
{ #category : #'world state' }
PasteUpMorph >> addMorph: aMorph centeredNear: aPoint [
"Add the given morph to this world, attempting to keep its center as close to the given point possible while also keeping the it entirely within the bounds of this world."
| trialRect delta |
trialRect := Rectangle center: aPoint extent: aMorph fullBounds extent.
delta := trialRect amountToTranslateWithin: bounds.
aMorph position: trialRect origin + delta.
self addMorph: aMorph.
]
{ #category : #'submorphs-add/remove' }
PasteUpMorph >> addMorphFront: aMorph [
^self addMorphInFrontOfLayer: aMorph
]
{ #category : #'wiw support' }
PasteUpMorph >> addMorphInLayer: aMorph [
super addMorphInLayer: aMorph.
aMorph wantsToBeTopmost ifFalse:[self bringTopmostsToFront].
]
{ #category : #'menu & halo' }
PasteUpMorph >> addWorldHaloMenuItemsTo: aMenu hand: aHandMorph [
"Add standard halo items to the menu, given that the receiver is a World"
self addFillStyleMenuItems: aMenu hand: aHandMorph.
self addLayoutMenuItems: aMenu hand: aHandMorph.
aMenu addLine.
self addWorldToggleItemsToHaloMenu: aMenu.
aMenu addLine.
self addExportMenuItems: aMenu hand: aHandMorph.
self addMiscExtrasTo: aMenu.
self addDebuggingItemsTo: aMenu hand: aHandMorph.
aMenu addLine.
aMenu defaultTarget: aHandMorph.
]
{ #category : #'menu & halo' }
PasteUpMorph >> addWorldToggleItemsToHaloMenu: aMenu [
"Add toggle items for the world to the halo menu"
#(
(hasDragAndDropEnabledString changeDragAndDrop 'whether I am open to having objects dropped into me')
(roundedCornersString toggleCornerRounding 'whether the world should have rounded corners')) do:
[:trip | aMenu addUpdating: trip first selector: trip second.
aMenu balloonTextForLastItem: trip third]
]
{ #category : #accessing }
PasteUpMorph >> backgroundMorph [
"Answer the background morph if any."
^backgroundMorph
]
{ #category : #accessing }
PasteUpMorph >> backgroundMorph: aMorph [
"Set the background morph.
Probably best if locked prior to adding."
self backgroundMorph ifNotNil: [ self backgroundMorph delete ].
backgroundMorph := aMorph.
aMorph
ifNotNil: [ aMorph bounds: self bounds.
self addMorphBack: aMorph
]
]
{ #category : #viewing }
PasteUpMorph >> bringTopmostsToFront [
submorphs
select:[:m| m wantsToBeTopmost]
thenDo:[:m| self addMorphInLayer: m].
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> bringWindowsFullOnscreen [
"Make ever SystemWindow on the desktop be totally on-screen, whenever possible."
| r |
bounds
allAreasOutsideList: ( self taskbars collect: [ :t | t bounds ] )
do: [ :e |
r
ifNil: [ r := e ]
ifNotNil: [ r area > e area
ifTrue: [ r ]
ifFalse: [ e ]
]
].
( self windowsSatisfying: [ :w | true ] )
do: [ :aWindow |
aWindow right: ( aWindow right min: r right ).
aWindow bottom: ( aWindow bottom min: r bottom ).
aWindow left: ( aWindow left max: r left ).
aWindow top: ( aWindow top max: r top )
]
]
{ #category : #'session management' }
PasteUpMorph >> checkSession [
"do nothing"
]
{ #category : #stepping }
PasteUpMorph >> cleanseOtherworldlySteppers [
"If the current project is a morphic one, then remove from its steplist
those morphs that are not really in the world"
"Utilities cleanseOtherworldlySteppers"
| old delta |
old := self currentWorld stepListSize.
self currentWorld steppingMorphsNotInWorld
do: [:m | m delete].
self currentWorld cleanseStepList.
(delta := old - self currentWorld stepListSize) > 0
ifTrue: [ self crTrace: delta asString , ' morphs removed from steplist' ]
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> closeAllUnchangedWindows [
(self windowsSatisfying: [:w | w model canDiscardEdits])
do: [:w | w delete]
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> closeAllWindowsDiscardingChanges [
self currentWorld systemWindows do: [:w | [w delete] valueSupplyingAnswer: false]
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> closeUnchangedWindows [
"Present a menu of window titles for all windows with changes,
and activate the one that gets chosen."
(self confirm:
'Do you really want to close all windows
except those with unaccepted edits?' translated)
ifFalse: [^ self].
self closeAllUnchangedWindows.
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> collapseAll [
"Collapse all windows"
(self windowsSatisfying: [:w | w isCollapsed not])
reverseDo: [:w | w collapseOrExpand. self displayWorld].
self collapseNonWindows
]
{ #category : #'world menu' }
PasteUpMorph >> collapseNonWindows [
self nonWindows reject: [:m | m isSticky] thenDo: [:m | m collapse]
]
{ #category : #'world menu' }
PasteUpMorph >> commandKeySelectors [
"Answer my command-key table"
| aDict |
aDict := self valueOfProperty: #commandKeySelectors ifAbsentPut: [self initializeDesktopCommandKeySelectors].
^ aDict
]
{ #category : #'menu & halo' }
PasteUpMorph >> contentsMenu: aMenu [
"Build the menu used from PopUpContentsMenu:"
(self submorphs asSortedCollection: [:w1 :w2 | w1 class name caseInsensitiveLessOrEqual: w2 class name]) do:
[:w | aMenu add: w class name target: w selector: #comeToFront ].
^ aMenu
]
{ #category : #'menu & halo' }
PasteUpMorph >> contentsMenuTitle [
^ 'Contents' translated
]
{ #category : #cursor }
PasteUpMorph >> currentCursor [
^ worldState currentCursor
]
{ #category : #cursor }
PasteUpMorph >> currentCursor: aCursor [
^ worldState currentCursor: aCursor
]
{ #category : #accessing }
PasteUpMorph >> currentWindow [
"Answer the top window or nil"
^ self class environment at: #SystemWindow ifPresent: [:systemWindow | systemWindow topWindow]
]
{ #category : #initialization }
PasteUpMorph >> defaultBorderColor [
"answer the default border color/fill style for the receiver"
^ Color
r: 0.861
g: 1.0
b: 0.722
]
{ #category : #initialization }
PasteUpMorph >> defaultBorderWidth [
"answer the default border width for the receiver"
^ 1
]
{ #category : #initialization }
PasteUpMorph >> defaultColor [
"answer the default color/fill style for the receiver"
^ Color
r: 0.8
g: 1.0
b: 0.6
]
{ #category : #'halos and balloon help' }
PasteUpMorph >> defersHaloOnClickTo: aSubMorph [
"If a cmd-click on aSubMorph would make it a preferred recipient of the halo, answer true"
^ true
]
{ #category : #'world menu' }
PasteUpMorph >> discoveredWorldMenu [
^ owner discoveredWorldMenu
]
{ #category : #'world menu' }
PasteUpMorph >> dispatchCommandKeyInWorld: aChar event: evt [
"Dispatch the desktop command key if possible. Answer whether handled"
| aMessageSend |
aMessageSend := self commandKeySelectors at: aChar ifAbsent: [^ false].
aMessageSend selector numArgs = 0
ifTrue:
[aMessageSend value]
ifFalse:
[aMessageSend valueWithArguments: (Array with: evt)].
^ true
]
{ #category : #'menu & halo' }
PasteUpMorph >> dispatchKeystroke: anEvent [
anEvent keyCharacter == Character tab
ifTrue: [
self tabAmongFields
ifTrue: [ ^ self tabHitWithEvent: anEvent ] ]
]
{ #category : #drawing }
PasteUpMorph >> drawBackgroundSketchOn: aCanvas [
backgroundMorph ifNil: [ ^ self ].
self clipSubmorphs
ifTrue: [ aCanvas clipBy: self clippingBounds during: [ :canvas | canvas fullDrawMorph: backgroundMorph ] ]
ifFalse: [ aCanvas fullDrawMorph: backgroundMorph ]
]
{ #category : #drawing }
PasteUpMorph >> drawGridOn: aCanvas [
(self griddingOn and: [ self gridVisible ])
ifTrue: [
aCanvas
fillRectangle: self bounds
fillStyle:
(self
gridFormOrigin: self gridOrigin
grid: self gridModulus
background: nil
line: Color lightGray) ]
]
{ #category : #drawing }
PasteUpMorph >> drawOn: aCanvas [
"Draw in order:
- background color
- grid, if any
- background sketch, if any
Later (in drawSubmorphsOn:) I will skip drawing the background sketch."
super drawOn: aCanvas.
self drawGridOn: aCanvas.
self drawBackgroundSketchOn: aCanvas
]
{ #category : #drawing }
PasteUpMorph >> drawSubmorphsOn: aCanvas [
"Display submorphs back to front, but skip my background sketch."
| drawBlock |
submorphs isEmpty
ifTrue: [ ^ self ].
drawBlock := [ :canvas |
submorphs
reverseDo: [ :m |
m ~~ backgroundMorph
ifTrue: [ canvas fullDrawMorph: m ] ] ].
self clipSubmorphs
ifTrue: [ aCanvas clipBy: (aCanvas clipRect intersect: self clippingBounds ifNone: [ ^ self ]) during: drawBlock ]
ifFalse: [ drawBlock value: aCanvas ]
]
{ #category : #'dropping/grabbing' }
PasteUpMorph >> dropEnabled [
"Get this morph's ability to add and remove morphs via drag-n-drop."
^ (self valueOfProperty: #dropEnabled) ~~ false
]
{ #category : #'event handling' }
PasteUpMorph >> dropFiles: anEvent [
"Handle a number of dropped files from the OS.
TODO:
- use a more general mechanism for figuring out what to do with the file (perhaps even offering a choice from a menu)
- remember the resource location or (when in browser) even the actual file handle"
| numFiles |
numFiles := anEvent contents.
1 to: numFiles do: [ :i |
| aFileReference handler |
aFileReference := anEvent requestDropReference: i.
handler := ExternalDropHandler
lookupExternalDropHandler: aFileReference.
handler
ifNotNil: [ handler handle: aFileReference in: self dropEvent: anEvent ] ]
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> expandAll [
"Expand all windows"
(self windowsSatisfying: [:w | w isCollapsed])
reverseDo: [:w | w collapseOrExpand. self displayWorld]
]
{ #category : #'Morphic-Base-Windows' }
PasteUpMorph >> findWindow: evt [
"Present a menu names of windows and naked morphs, and activate the one that gets chosen. Collapsed windows appear below line, expand if chosen; naked morphs appear below second line; if any of them has been given an explicit name, that is what's shown, else the class-name of the morph shows; if a naked morph is chosen, bring it to front and have it don a halo."
| menu expanded collapsed nakedMorphs |
menu := UIManager default newMenuIn: self for: self.
expanded := self windowsSatisfying: [:w | w isCollapsed not].
collapsed := self windowsSatisfying: [:w | w isCollapsed].
nakedMorphs := self submorphsSatisfying:[:m | m isSystemWindow not].
(expanded isEmpty and: [collapsed isEmpty and: [nakedMorphs isEmpty]]) ifTrue: [^ self inform: 'No morph in world'].
(expanded asSortedCollection: [:w1 :w2 | w1 label caseInsensitiveLessOrEqual: w2 label]) do:
[:w | menu add: w label target: w selector: #activateAndForceLabelToShow.
w model canDiscardEdits ifFalse: [menu lastItem color: Color red]].
(expanded isEmpty or: [ collapsed isEmpty and: [ nakedMorphs isEmpty ]]) ifFalse: [menu addLine].
(collapsed asSortedCollection: [:w1 :w2 | w1 label caseInsensitiveLessOrEqual: w2 label]) do:
[:w | menu add: w label target: w selector: #collapseOrExpand.
w model canDiscardEdits ifFalse: [menu lastItem color: Color red]].
nakedMorphs isEmpty ifFalse: [menu addLine].
(nakedMorphs asSortedCollection: [:w1 :w2 | w1 class name caseInsensitiveLessOrEqual: w2 class name]) do:
[:w | menu add: w class name target: w selector: #comeToFrontAndAddHalo].
menu addTitle: 'find window'.
menu popUpEvent: evt in: self.
]
{ #category : #'world state' }
PasteUpMorph >> flashRects: rectangleList color: aColor [
"For testing. Flashes the given list of rectangles on the Display so you can watch incremental redisplay at work."
"Details: Uses two reverses so that the display is restored to its original state. This is necessary when in deferred update mode."
| blt |
blt := (BitBlt toForm: Display)
sourceForm: nil;
sourceOrigin: 0@0;
clipRect: self viewBox;
combinationRule: Form reverse.
rectangleList do: [:r | | screenRect |
screenRect := r translateBy: self viewBox origin.
blt destRect: screenRect; copyBits.
Display forceToScreen: screenRect; forceDisplayUpdate.
(Delay forMilliseconds: 15) wait.
blt destRect: screenRect; copyBits.
Display forceToScreen: screenRect; forceDisplayUpdate].
]
{ #category : #drawing }
PasteUpMorph >> gridFormOrigin: origin grid: smallGrid background: backColor line: lineColor [
| bigGrid gridForm gridOrigin |
gridOrigin := origin \\ smallGrid.
bigGrid := (smallGrid asPoint x) @ (smallGrid asPoint y).
gridForm := Form extent: bigGrid depth: Display depth.
backColor ifNotNil: [gridForm fillWithColor: backColor].
gridOrigin x to: gridForm width by: smallGrid x do:
[:x | gridForm fill: (x@0 extent: 1@gridForm height) fillColor: lineColor].
gridOrigin y to: gridForm height by: smallGrid y do:
[:y | gridForm fill: (0@y extent: gridForm width@1) fillColor: lineColor].
^ InfiniteForm with: gridForm
]
{ #category : #gridding }
PasteUpMorph >> gridModulus [
^ self gridSpec extent
]
{ #category : #gridding }
PasteUpMorph >> gridModulus: newModulus [
self gridSpecPut: (self gridOrigin extent: newModulus).
self changed
]
{ #category : #gridding }
PasteUpMorph >> gridOrigin [
^ self gridSpec origin
]
{ #category : #gridding }
PasteUpMorph >> gridOrigin: newOrigin [
^ self gridSpecPut: (newOrigin extent: self gridModulus)
]
{ #category : #gridding }
PasteUpMorph >> gridSpec [
"Gridding rectangle provides origin and modulus"
^ self valueOfProperty: #gridSpec ifAbsent: [0@0 extent: 8@8]
]
{ #category : #gridding }
PasteUpMorph >> gridSpecPut: newSpec [
"Gridding rectangle provides origin and modulus"
^ self setProperty: #gridSpec toValue: newSpec
]
{ #category : #gridding }
PasteUpMorph >> gridVisible [
^ self hasProperty: #gridVisible
]
{ #category : #gridding }
PasteUpMorph >> gridVisibleOnOff [
self setProperty: #gridVisible toValue: self gridVisible not.
self changed
]
{ #category : #gridding }
PasteUpMorph >> gridVisibleString [
"Answer a string to be used in a menu offering the opportunity
to show or hide the grid"
^ (self gridVisible
ifTrue: ['<yes>']
ifFalse: ['<no>'])
, 'show grid when gridding' translated
]
{ #category : #gridding }
PasteUpMorph >> griddingOn [
^ griddingOn ifNil: [false]
]
{ #category : #gridding }
PasteUpMorph >> griddingOnOff [
griddingOn := self griddingOn not.
self changed
]
{ #category : #gridding }
PasteUpMorph >> griddingString [
"Answer a string to use in a menu offering the user the
opportunity to start or stop using gridding"
^ (self griddingOn
ifTrue: ['<yes>']
ifFalse: ['<no>'])
, 'use gridding' translated
]
{ #category : #'world state' }
PasteUpMorph >> handleFatalDrawingError: errMsg [
"Handle a fatal drawing error."
Display deferUpdates: false. "Just in case"
self primitiveError: errMsg.
"Hm... we should jump into a 'safe' worldState here, but how do we find it?!"
]
{ #category : #recategorized }
PasteUpMorph >> handlerForMouseDown: anEvent [
"If we have a modal dialog then answer nil otherwise as usual.."
^(self hasProperty: #submorphLockStates)
ifFalse: [super handlerForMouseDown: anEvent]
]
{ #category : #'event handling' }
PasteUpMorph >> handlesKeyboard: evt [
^ true "handle all not handled events"
]
{ #category : #'event handling' }
PasteUpMorph >> handlesMouseDown: evt [
^true
]
{ #category : #thumbnail }
PasteUpMorph >> icon [
^ self iconNamed: #homeIcon
]
{ #category : #initialization }
PasteUpMorph >> initialize [
"initialize the state of the receiver"
super initialize.
self enableDragNDrop.
self clipSubmorphs: true
]
{ #category : #'world menu' }
PasteUpMorph >> initializeDesktopCommandKeySelectors [
"Provide the starting settings for desktop command key selectors. Answer the dictionary."
"ActiveWorld initializeDesktopCommandKeySelectors"
| dict |
dict := IdentityDictionary new.
self defaultDesktopCommandKeyTriplets do:
[:trip | | messageSend |
messageSend := MessageSend receiver: trip second selector: trip third.
dict at: trip first put: messageSend].
self setProperty: #commandKeySelectors toValue: dict.
^ dict
]
{ #category : #'world menu' }
PasteUpMorph >> invokeWorldMenu: evt [
"Put up the world menu, triggered by the passed-in event."
| menu |
"If the user does not want a world menu, do not invoke it."
self class shouldShowWorldMenu ifFalse: [ ^ self ].
self bringTopmostsToFront.
"put up screen menu"
(menu := self worldMenu) popUpEvent: evt in: self.
^ menu
]
{ #category : #'world menu' }
PasteUpMorph >> invokeWorldMenuFromEscapeKey [
self invokeWorldMenu: ActiveEvent
]
{ #category : #cursor }
PasteUpMorph >> isCursorOwner [
^ false
]
{ #category : #testing }
PasteUpMorph >> isEasySelecting [
"This is to isolate easySelection predicate.
Selectors in holders make no sense so we are limiting easy
selection to the worldMorph.
It would also make sense in playfield so feel free to adjust this
predicate. Selection can always be forced by using the shift
before mouse down."
^ false
]
{ #category : #'event handling' }
PasteUpMorph >> keyStroke: anEvent [
"A keystroke has been made. Service event handlers and, if it's a keystroke presented to the world, dispatch it to #unfocusedKeystroke:"
super keyStroke: anEvent. "Give event handlers a chance"
self selectedObject ifNotNil: [ :selected | selected moveOrResizeFromKeystroke: anEvent ].
self dispatchKeystroke: anEvent
]
{ #category : #'world menu' }
PasteUpMorph >> keyboardNavigationHandler [
"Answer the receiver's existing keyboardNavigationHandler, or nil if none."
| aHandler |
aHandler := self valueOfProperty: #keyboardNavigationHandler ifAbsent: [^ nil].
(aHandler hasProperty: #moribund) ifTrue: "got clobbered in another project"
[self removeProperty: #keyboardNavigationHandler.
^ nil].
^ aHandler
]
{ #category : #'world menu' }
PasteUpMorph >> keyboardNavigationHandler: aHandler [
"Set the receiver's keyboard navigation handler as indicated. A nil argument means to remove the handler"
aHandler
ifNil:
[self removeProperty: #keyboardNavigationHandler]
ifNotNil:
[self setProperty: #keyboardNavigationHandler toValue: aHandler]
]
{ #category : #'world menu' }
PasteUpMorph >> lastKeystroke [
"Answer the last keystroke fielded by the receiver"
^ self valueOfProperty: #lastKeystroke ifAbsent: ['']
]
{ #category : #'world menu' }
PasteUpMorph >> lastKeystroke: aString [
"Remember the last keystroke fielded by the receiver"
^ self setProperty: #lastKeystroke toValue: aString
]
{ #category : #accessing }
PasteUpMorph >> modalWindow: aMorph [
(self valueOfProperty: #modalWindow) ifNotNil: [ :morph | morph delete ].
self setProperty: #modalWindow toValue: aMorph.
aMorph ifNotNil: [ self when: #aboutToLeaveWorld send: #removeModalWindow to: self ]
]
{ #category : #'Morphic-Base-Basic' }
PasteUpMorph >> morphToDropFrom: aMorph [
"Given a morph being carried by the hand, which the hand is about to drop, answer the actual morph to be deposited. Normally this would be just the morph itself, but several unusual cases arise, which this method is designed to service."
^aMorph
]
{ #category : #'event handling' }
PasteUpMorph >> morphToGrab: event [
"Return the morph to grab from a mouse down event. If none, return nil."
self submorphsDo:[:m|
((m rejectsEvent: event) not and:[m fullContainsPoint: event cursorPoint]) ifTrue:[^m].
].
^nil
]
{ #category : #'submorphs-accessing' }
PasteUpMorph >> morphsInFrontOf: someMorph overlapping: aRectangle do: aBlock [
"Include hands if the receiver is the World"
self handsDo:[:m|
m == someMorph ifTrue:["Try getting out quickly"
owner ifNil:[^self].
^owner morphsInFrontOf: self overlapping: aRectangle do: aBlock].
"The hand only overlaps if it's not the hardware cursor"
m needsToBeDrawn ifTrue:[
(m fullBoundsInWorld intersects: aRectangle)
ifTrue:[aBlock value: m]]].
^super morphsInFrontOf: someMorph overlapping: aRectangle do: aBlock
]
{ #category : #'dropping/grabbing' }
PasteUpMorph >> mouseDown: evt [
"Handle a mouse down event."
| grabbedMorph handHadHalos |
(self class isMenuOpenByLeftClick
ifTrue: [ evt yellowButtonPressed "left click" ]
ifFalse: [ evt redButtonPressed "right click" ])
ifTrue: [ ^ self popUpContentsMenu: evt ].
grabbedMorph := self morphToGrab: evt.
grabbedMorph
ifNotNil: [
grabbedMorph isSticky
ifTrue: [ ^ self ].
^ evt hand grabMorph: grabbedMorph ].
(super handlesMouseDown: evt)
ifTrue: [ ^ super mouseDown: evt ].
handHadHalos := evt hand halo notNil.
evt hand removeHalo. "shake off halos"
evt hand releaseKeyboardFocus. "shake of keyboard foci"
(evt shiftPressed not and: [ self isWorldMorph not and: [ self wantsEasySelection not ] ])
ifTrue: [
evt wasHandled: false.
^ self ]. "explicitly ignore the event if we're not the world and we'll not select,
so that we could be picked up if need be"
(evt shiftPressed or: [ self wantsEasySelection ])
ifTrue: [
| clickSelector |
evt shiftPressed
ifTrue: [ clickSelector := #popUpContentsMenu: ]
ifFalse: [ clickSelector := #invokeWorldMenu: ].
evt hand
waitForClicksOrDrag: self
event: evt
selectors:
{clickSelector.
nil.
nil.
#dragThroughOnDesktop:}
threshold: 5 ]
ifFalse: [ self invokeWorldMenu: evt ] "We'll select on drag, let's decide what to do on click" "We wont select, just bring world menu if I'm the world"
]
{ #category : #'world menu' }
PasteUpMorph >> nonWindows [
^ (self submorphs select: [:m | (m isSystemWindow) not and: [m wantsToBeTopmost not]])
]
{ #category : #accessing }
PasteUpMorph >> osWindow [
^ nil
]
{ #category : #'menu & halo' }
PasteUpMorph >> popUpContentsMenu: evt [
"Present a menu names of windows and naked morphs, and activate the one that gets chosen. Collapsed windows appear below line, expand if chosen; naked morphs appear below second line; if any of them has been given an explicit name, that is what's shown, else the class-name of the morph shows; if a naked morph is chosen, bring it to front and have it don a halo."
| menu |
menu := UIManager default newMenuIn: self for: self.
self contentsMenu: menu.
menu buildTitle: [ :titleMorph |
titleMorph bigTitle: self contentsMenuTitle
];
popUpEvent: evt in: (self world ifNil: [self]).
]
{ #category : #'dropping/grabbing' }
PasteUpMorph >> positionNear: aPoint forExtent: anExtent adjustmentSuggestion: adjustmentPoint [
"Compute a plausible positioning for adding a subpart of size anExtent, somewhere near aPoint, using adjustmentPoint as the unit of adjustment"
| adjustedPosition |
adjustedPosition := aPoint.
[((self morphsAt: (adjustedPosition + (anExtent // 2))) size > 1) and: "that 1 is self here"
[bounds containsPoint: adjustedPosition]]
whileTrue:
[adjustedPosition := adjustedPosition + adjustmentPoint].
^ adjustedPosition
]
{ #category : #private }
PasteUpMorph >> privateRemoveMorph: aMorph [
backgroundMorph == aMorph ifTrue: [ backgroundMorph := nil ].
^super privateRemoveMorph: aMorph.
]
{ #category : #caching }
PasteUpMorph >> releaseCachedState [
super releaseCachedState.
self removeModalWindow.
]
{ #category : #accessing }
PasteUpMorph >> removeModalWindow [
self modalWindow: nil
]
{ #category : #'dropping/grabbing' }
PasteUpMorph >> repelsMorph: aMorph event: ev [
(aMorph wantsToBeDroppedInto: self) ifFalse: [^ false].
self dropEnabled ifFalse: [^ true].
(self wantsDroppedMorph: aMorph event: ev) ifFalse: [^ true].
^ super repelsMorph: aMorph event: ev "consults #repelling flag"
]
{ #category : #recategorized }
PasteUpMorph >> resizeBackgroundMorph [
"Resize the background morph to fit the world."
self backgroundMorph ifNotNil: [ self backgroundMorph extent: self extent ]
]
{ #category : #options }
PasteUpMorph >> resizeToFit [
^self vResizing == #shrinkWrap
]
{ #category : #options }
PasteUpMorph >> resizeToFitString [
"Answer a string, to be used in a self-updating menu, to
represent whether the receiver is currently using resize-to-fit
or not"
^ (self resizeToFit
ifTrue: ['<yes>']
ifFalse: ['<no>'])
, 'resize to fit' translated
]
{ #category : #'world state' }
PasteUpMorph >> restoreDisplay [
self currentWorld restoreMorphicDisplay. "I don't actually expect this to be called"
]
{ #category : #'world state' }
PasteUpMorph >> restoreMainDockingBarDisplay [
"Restore the display of docking bars"
self dockingBars
do: [:each | each updateBounds]
]
{ #category : #gridding }
PasteUpMorph >> setGridSpec [
"Gridding rectangle provides origin and modulus"
| response result |
response := UIManager default
request: 'New grid origin (usually 0@0):' translated
initialAnswer: self gridOrigin printString.
response isEmpty ifTrue: [^ self].
result := [self class compiler evaluate: response] ifErrorDo: [^ self].
(result isPoint and: [(result >= (0@0))])
ifTrue: [self gridOrigin: result]
ifFalse: [self inform: ('Must be a Point with coordinates (for example 10@10)' translated )].
response := UIManager default
request: 'New grid spacing:' translated
initialAnswer: self gridModulus printString.
response isEmptyOrNil ifTrue: [^ self].
result := [self class compiler evaluate: response] ifErrorDo: [^ self].
(result isPoint and: [(result > (0@0)) ])
ifTrue: [self gridModulus: result]
ifFalse: [self inform: ('Must be a Point with coordinates (for example 10@10)' translated )].
]
{ #category : #'wiw support' }
PasteUpMorph >> shouldGetStepsFrom: aWorld [
(self isWorldMorph and: [owner notNil])
ifTrue: [ ^self outermostWorldMorph == aWorld ].
^super shouldGetStepsFrom: aWorld
]
{ #category : #stepping }
PasteUpMorph >> startStepping: aMorph [
"Add the given morph to the step list. Do nothing if it is already being stepped."
^self startStepping: aMorph at: Time millisecondClockValue selector: #stepAt: arguments: nil stepTime: nil
]
{ #category : #'world state' }
PasteUpMorph >> startSteppingSubmorphsOf: aMorph [
"Ensure that all submorphs of the given morph that want to be stepped are added to the step list. Typically used after adding a morph to the world."
aMorph allMorphsDo: [:m |
m wantsSteps ifTrue: [m arrangeToStartSteppingIn: m world].
]
]
{ #category : #'project state' }
PasteUpMorph >> steppingMorphsNotInWorld [
| all |
all := self allMorphs.
^ self listOfSteppingMorphs reject: [ :m | all includes: m ] "self currentWorld steppingMorphsNotInWorld do: [:m | m delete]"
]
{ #category : #options }
PasteUpMorph >> toggleResizeToFit [
"Toggle whether the receiver is set to resize-to-fit"
self vResizeToFit: self resizeToFit not
]
{ #category : #accessing }
PasteUpMorph >> useRoundedCorners [
"Somewhat special cased because we do have to fill Display for this"
super useRoundedCorners.
self == self currentWorld ifTrue:[Display bits primFill: 0]. "done so that we *don't* get a flash"
]
{ #category : #'project state' }
PasteUpMorph >> viewBox: newViewBox [
"I am now displayed within newViewBox; react."
super position: newViewBox topLeft.
fullBounds := bounds := newViewBox.