/
Morph.extension.st
179 lines (141 loc) · 5.09 KB
/
Morph.extension.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
Extension { #name : #Morph }
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> activate [
"Mark the receiver and submorphs as active (foreground)."
self submorphsDo: [:m | m activate]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> collapse [
CollapsedMorph new beReplacementFor: self
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> containingWindow [
"Answer a window that contains the receiver"
^ self ownerThatIsA: SystemWindow
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> dialogWindow [
"Answer the receiver's dialog window."
^self ownerThatIsA: DialogWindow
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> embedInWindow [
| window worldToUse |
worldToUse := self world. "I'm assuming we are already in a world"
window := (SystemWindow labelled: self defaultLabel) model: nil.
window bounds: ((self position - ((0@window labelHeight) + window borderWidth))
corner: self bottomRight + window borderWidth).
window addMorph: self frame: (0@0 extent: 1@1).
window updatePaneColors.
worldToUse addMorph: window.
window activate
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> embeddedInMorphicWindowLabeled: labelString [
| window |
window := (SystemWindow labelled: labelString) model: nil.
window setStripeColorsFrom: (self theme windowColorFor: self).
window addMorph: self frame: (0@0 extent: 1@1).
^ window
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> isInSystemWindow [
"answer if the receiver is in a system window"
^ owner isMorph and:[owner isSystemWindow or:[owner isInSystemWindow]]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> isWindowActive: aSystemWindow [
"Answer whether the given window is active.
Implement in morphs that are designed to embed system windows.
Delegate to owner."
^self owner ifNil: [true] ifNotNil: [:o | o isWindowActive: aSystemWindow]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> nextMorphAcrossInWindow [
"Answer the next morph in the window. Traverse
from the receiver to its next sibling or owner's next sibling etc."
^self submorphAfter ifNil: [
(self owner ifNil: [^self]) nextMorphAcrossInWindow]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> nextMorphInWindow [
"Answer the next morph in the window. Traverse
from the receiver to its first child or next sibling or owner's next sibling etc."
^self hasSubmorphs
ifTrue: [self submorphs first]
ifFalse: [self nextMorphAcrossInWindow]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> nextMorphWantingFocus [
"Answer the next morph that wants keyboard focus."
|m|
m := self nextMorphInWindow ifNil: [^nil].
[m = self or: [m wantsKeyboardFocusNavigation]]
whileFalse: [m := m nextMorphInWindow].
^m wantsKeyboardFocusNavigation
ifTrue: [m]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> openInWindow [
^self openInWindowLabeled: self defaultLabel
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> openInWindowLabeled: aString [
^self openInWindowLabeled: aString inWorld: self currentWorld
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> openInWindowLabeled: aString inWorld: aWorld [
"Changed to include the inset margin in the bound calculation."
^ self wrappedInWindow
setLabel: aString;
openInWorld: aWorld
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> previousMorphInWindow [
"Answer the next morph in the window. Traverse
from the receiver to its previous sibling's last submorph (recursive)
or owner's previous sibling's last submorph (recursive) etc."
^self submorphBefore notNil
ifTrue: [self submorphBefore lastSubmorphRecursive]
ifFalse: [self owner]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> previousMorphWantingFocus [
"Answer the previous morph that wants keyboard focus."
|m|
m := self previousMorphInWindow ifNil: [^nil].
[m = self or: [m wantsKeyboardFocusNavigation]]
whileFalse: [m := m previousMorphInWindow ifNil: [^nil]].
^m wantsKeyboardFocusNavigation
ifTrue: [m]
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> shadowMargins [
"Answer the margins of my shadow"
|left right top bottom deltaX deltaY|
left := right := top := bottom := 0.
(deltaX := self shadowOffset x) < 0 ifTrue: [ left := deltaX] ifFalse: [right := deltaX ].
(deltaY := self shadowOffset x) < 0 ifTrue: [ top := deltaY] ifFalse: [bottom := deltaY ].
^Margin left: left right: right top: top bottom: bottom
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> window [
"Answer the receiver's window."
^self ownerThatIsA: SystemWindow
]
{ #category : #'*Morphic-Widgets-Windows' }
Morph >> wrappedInWindow [
"Changed to include the inset margin in the bound calculation."
| window extent |
window := SystemWindow new.
window
addMorph: self frame: (0@0 extent: 1@1);
updatePaneColors.
" calculate extent after adding in case any size related attributes were changed. Use
fullBounds in order to trigger re-layout of layout morphs"
extent := self fullBounds extent +
(window borderWidth@window labelHeight) + window borderWidth +
(window class borderWidth * 2 @ (window class borderWidth + 1)). "include inset margin"
window extent: extent.
^ window
]