-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
DockingBarToggleMenuItemMorph.class.st
215 lines (181 loc) · 6.98 KB
/
DockingBarToggleMenuItemMorph.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
"
A DockingBarToggleMenuItemMorph is a specialized version of its superclass for DockingBar behavior.
There is a bit of duplication between
DockingBarToggleMenuItemMorph and DockingBarMenuItemMorph because iof single inheritance limit:
DockingBarToggleMenuItemMorph inherits from ToggleMenuItemMorph (and also from DockingBarMenuItemMorph).
One of the problem is that in addition, the use of toggleMenuItem or simple menuItem looks random.
DockingBarMenuItemMorph is created by
add: wordingString icon: aForm help: helpString subMenu: aMenuMorph
and DockingBarToggleMenuItemMorph is created by
add: wordingString font: aFont icon: aForm help: helpString subMenu: aMenuMorph
"
Class {
#name : 'DockingBarToggleMenuItemMorph',
#superclass : 'ToggleMenuItemMorph',
#category : 'Morphic-Widgets-Extra',
#package : 'Morphic-Widgets-Extra'
}
{ #category : 'selecting' }
DockingBarToggleMenuItemMorph >> adjacentTo [
"Adjusted to line up more nicely."
self owner isFloating
ifTrue: [^ {self bounds bottomLeft + (3 @ 3). self bounds bottomRight + (5 @ 3)}].
self owner isAdheringToTop
ifTrue: [^ {self bounds bottomLeft + (5 @ 5)}].
self owner isAdheringToLeft
ifTrue: [^ {self bounds topRight + (5 @ 5)}].
self owner isAdheringToBottom
ifTrue: [^ {self bounds topLeft + (5 @ 5)}].
self owner isAdheringToRight
ifTrue: [^ {self bounds topLeft + (5 @ -5)}].
^ {self bounds bottomLeft + (3 @ 5)}
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> deselectTimeOut: evt [
"Deselect timout. Now really deselect"
owner selectedItem == self
ifTrue: [
evt hand releaseMouseFocus: owner.
owner selectItem: nil event: evt ]
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> drawOn: aCanvas [
| stringColor stringBounds |
stringColor := (isSelected and: [ isEnabled ])
ifTrue: [ aCanvas fillRectangle: self bounds fillStyle: self selectionFillStyle.
color negated ]
ifFalse: [ color ].
stringBounds := bounds.
stringBounds := stringBounds left: stringBounds left + 4.
self hasIcon
ifTrue: [ | toggledIconFormSet |
toggledIconFormSet := self toggledIconFormSet.
aCanvas translucentFormSet: toggledIconFormSet at: stringBounds left @ (self top + ((self height - toggledIconFormSet height) // 2)).
stringBounds := stringBounds left: stringBounds left + toggledIconFormSet width + 2 ].
self hasMarker ifTrue: [ stringBounds := stringBounds left: stringBounds left + self submorphBounds width + 8 ].
stringBounds := stringBounds top: (stringBounds top + stringBounds bottom - self fontToUse height) // 2.
aCanvas
drawString: self contents
in: stringBounds
font: self fontToUse
color: stringColor.
self hasSubMenu
ifTrue: [ | subMenuMarker subMenuMarkerPosition |
subMenuMarker := self subMenuMarker.
subMenuMarkerPosition := (self right - subMenuMarker width) @ ((self top + self bottom - subMenuMarker height) // 2).
subMenuMarkerPosition := subMenuMarkerPosition - (4 @ -1).
aCanvas paintImage: subMenuMarker at: subMenuMarkerPosition ]
]
{ #category : 'private - drawing' }
DockingBarToggleMenuItemMorph >> drawSubMenuMarker: aFormSet on: aCanvas in: aRectangle [
"Draw the submenu marker on the canvas within the given bounds."
|markerRect|
markerRect := aRectangle topRight + (aFormSet width negated @ (aRectangle height - aFormSet height // 2)) extent: aFormSet extent.
markerRect translateBy: -4@1.
self drawIcon: aFormSet on: aCanvas in: markerRect
]
{ #category : 'events' }
DockingBarToggleMenuItemMorph >> mouseDown: evt [
"Handle a mouse down event. Menu items get activated when the mouse is over them."
(evt shiftPressed and: [self isEditable ])
ifTrue: [ ^ super mouseDown: evt ]. "enable label editing"
isSelected
ifTrue: [
evt hand newMouseFocus: nil.
owner selectItem: nil event: evt. ]
ifFalse: [
evt hand newMouseFocus: owner. "Redirect to menu for valid transitions"
owner selectItem: self event: evt. ]
]
{ #category : 'events' }
DockingBarToggleMenuItemMorph >> mouseEnter: evt [
"The mouse entered the receiver"
owner ifNotNil: [owner stayUp ifFalse: [self mouseEnterDragging: evt]].
(owner selectedItem isNotNil
and: [owner selectedItem ~~ self])
ifTrue: [owner selectItem: self event: evt.]
]
{ #category : 'events' }
DockingBarToggleMenuItemMorph >> mouseUp: evt [
"Handle a mouse up event. Menu items get activated when the mouse is over them. Do nothing if we're not in a 'valid menu transition', meaning that the current hand focus must be aimed at the owning menu."
evt hand mouseFocus == owner ifFalse: [^self].
self contentString ifNotNil:[
self contents: self contentString withMarkers: true inverse: true.
self refreshWorld.
(Delay forMilliseconds: 200) wait].
owner rootMenu selectItem: nil event: evt.
self invokeWithEvent: evt
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> noteNewOwner: aMorph [
"I have just been added as a submorph of aMorph"
super noteNewOwner: aMorph.
self updateLayoutInDockingBar
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> ownerChanged [
"The receiver's owner, some kind of a pasteup, has changed its
layout."
super ownerChanged.
self updateLayoutInDockingBar
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> roundedCorners [
"Return a list of those corners to round"
owner isFloating
ifTrue: [^ #(1 4 )].
owner isAdheringToTop
ifTrue: [^ #(1 4 )].
owner isAdheringToBottom
ifTrue: [^ #(2 3 )].
owner isAdheringToLeft
ifTrue: [^ #(1 2 )].
owner isAdheringToRight
ifTrue: [^ #(3 4 )].
^ #(1 2 3 4 )
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> selectionBorderStyle [
"Answer the border style to use with the receiver is the selected element."
^ self theme menuItemInDockingBarSelectedBorderStyleFor: self
]
{ #category : 'private' }
DockingBarToggleMenuItemMorph >> selectionFillStyle [
"Answer the fill style to use with the receiver is the selected element."
^self theme menuItemInDockingBarSelectedFillStyleFor: self
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> stringBoundsToUse [
"Answer the bounds to use when drawing the item text."
^self bounds left: self left + 4
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> subMenuMarkerFormSet [
"private - answer the form set to be used as submenu marker"
owner isFloating
ifTrue: [ ^ self bottomArrowFormSet ].
owner isAdheringToTop
ifTrue: [ ^ self bottomArrowFormSet ].
owner isAdheringToBottom
ifTrue: [ ^ self upArrowFormSet ].
owner isAdheringToLeft
ifTrue: [ ^ self rightArrowFormSet ].
owner isAdheringToRight
ifTrue: [ ^ self leftArrowFormSet ].
^ self rightArrowFormSet
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> updateLayoutInDockingBar [
owner isVertical
ifTrue: [
self hResizing: #spaceFill.
self vResizing: #shrinkWrap]
ifFalse: [
self hResizing: #shrinkWrap.
self vResizing: #spaceFill].
self extent: self minWidth @ self minHeight
]
{ #category : 'accessing' }
DockingBarToggleMenuItemMorph >> wantsRoundedCorners [
^self theme currentSettings preferRoundCorner
]