-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathNewMenuBar.cls
More file actions
301 lines (198 loc) · 7.96 KB
/
NewMenuBar.cls
File metadata and controls
301 lines (198 loc) · 7.96 KB
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "NewMenuBar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'--------------------------------------------------------------------------------
' Component : NewMenuBar
' Project : ViDock
'
' Description: The Menu Bar object. Manages the App Menu items
'
'--------------------------------------------------------------------------------
Option Explicit
Private Const BUTTON_TEXT_GAP As Long = 10
Private m_textPath As GDIPGraphicPath
Private m_items As Collection
Private m_graphics As GDIPGraphics
Private m_dimensions As gdiplus.RECTL
Private m_menuOver As GDIPImage
Private m_menuBitmap As GDIPBitmap
Private m_menuBackground As GDIPImage
Private m_buttonSlices As Collection
Private m_hoveredItem As MenuItem
Private m_windowTitle As String
Private m_rootItem As MenuItem
Private m_targethWnd As Long
Private m_bgFinderMargin As MARGIN
Public HostForm As Form
Private WithEvents m_listMenu As ListMenu
Attribute m_listMenu.VB_VarHelpID = -1
Public Event onChanged()
Public Function Update()
If GetWindowTextByhWnd(m_targethWnd) <> m_windowTitle Then
PopulateFromhWnd m_targethWnd
End If
End Function
Public Function ResetSelector()
Set m_hoveredItem = Nothing
ReDraw
End Function
Public Property Let Background(newBackground As GDIPImage)
Set m_menuBackground = newBackground
ReDraw
'RaiseEvent onChanged
End Property
Public Property Get Image() As GDIPImage
Set Image = m_menuBitmap.Image
End Property
Public Property Get Dimensions() As gdiplus.RECTL
Dimensions = m_dimensions
End Property
Public Property Let Dimensions(newDimensions As gdiplus.RECTL)
m_dimensions = newDimensions
m_menuBitmap.CreateFromSizeFormat newDimensions.Width, newDimensions.Height, GDIPlusWrapper.Format32bppArgb
Set m_graphics = New GDIPGraphics
m_graphics.FromImage m_menuBitmap.Image
m_graphics.TextRenderingHint = TextRenderingHintClearTypeGridFit
m_graphics.SmoothingMode = SmoothingModeHighQuality
m_graphics.PixelOffsetMode = PixelOffsetModeHighQuality
'm_graphics.CompositingQuality = CompositingQualityHighQuality
m_graphics.InterpolationMode = InterpolationModeNearestNeighbor
End Property
Public Function MouseDown(Button As Integer, X As Single, Y As Single)
If HostForm Is Nothing Then
LogError 0, "MouseDown", "NewMenuBar", "HostForm unitialized!"
Exit Function
End If
If m_hoveredItem Is Nothing Then
Exit Function
End If
'm_listMenu.closeMe
m_listMenu.ShowList m_hoveredItem.Children, HostForm.Top + ((m_dimensions.Top + m_dimensions.Height - m_bgFinderMargin.Height) * Screen.TwipsPerPixelY), (HostForm.Left / Screen.TwipsPerPixelX) + m_dimensions.Left + m_hoveredItem.Left - BUTTON_TEXT_GAP, vbPopupMenuLeftAlign, False
End Function
Public Function MouseMove(Position As POINTS)
Dim newItem As MenuItem
Set newItem = GetSelectedItem(Position.X)
If newItem Is Nothing Then
Exit Function
End If
If newItem Is m_hoveredItem Then
Exit Function
End If
If newItem Is m_rootItem Then
Exit Function
End If
Set m_hoveredItem = newItem
If Not m_listMenu Is Nothing Then
If m_listMenu.Visible Then
m_listMenu.ShowList m_hoveredItem.Children, HostForm.Top + ((m_dimensions.Top + m_dimensions.Height - m_bgFinderMargin.Height) * Screen.TwipsPerPixelY), (HostForm.Left / Screen.TwipsPerPixelX) + m_dimensions.Left + m_hoveredItem.Left - BUTTON_TEXT_GAP, vbPopupMenuLeftAlign, False
End If
End If
ReDraw
RaiseEvent onChanged
End Function
Public Sub MouseLeft()
If m_listMenu.Visible Then
m_listMenu.Hide
End If
Debug.Print "MenuBar::MouseLeft"
End Sub
Private Function GetSelectedItem(ByVal X As Long) As MenuItem
Dim thisItem As MenuItem
For Each thisItem In m_items
If X > thisItem.Left And X < thisItem.Left + thisItem.Width Then
Set GetSelectedItem = thisItem
Exit For
End If
Next
End Function
Public Function PopulateFromhWnd(ByVal hWnd As Long)
Set m_items = New Collection
m_targethWnd = hWnd
m_windowTitle = GetWindowTextByhWnd(m_targethWnd)
m_rootItem.Caption = m_windowTitle
m_items.Add m_rootItem
PopulateMenuFromHandle m_items, GetMenu(hWnd), hWnd
ReDraw
End Function
Public Function PopulateFromTest()
If m_graphics Is Nothing Then
Debug.Print "PopulateFromTest:: No graphics object!"
Exit Function
End If
Dim thisItem As New MenuItem
thisItem.Caption = "File"
m_items.Add thisItem
Set thisItem = New MenuItem
m_items.Add thisItem
thisItem.Caption = "Edit"
Set thisItem = New MenuItem
m_items.Add thisItem
thisItem.Caption = "View"
Set thisItem = New MenuItem
m_items.Add thisItem
thisItem.Caption = "Find"
ReDraw
End Function
Private Function PositionItems()
Dim thisItem As MenuItem
Dim xPosition As Long
xPosition = MENU_MARGIN_X
For Each thisItem In m_items
If thisItem Is m_rootItem Then
thisItem.Width = m_graphics.MeasureStringWidth(thisItem.Caption, FontHelper.AppDefaultFont(FontStyleBold))
Else
thisItem.Width = m_graphics.MeasureStringWidth(thisItem.Caption, FontHelper.AppDefaultFont)
End If
thisItem.Left = xPosition
xPosition = xPosition + thisItem.Width + ITEM_MARGIN_X
Next
End Function
Private Function ReDraw()
PositionItems
Dim thisItem As MenuItem
Set m_textPath = New GDIPGraphicPath
m_graphics.Clear
'm_graphics.DrawImage m_menuBackground, 0, 0, m_dimensions.Width, m_dimensions.Height
m_graphics.DrawImage m_menuBackground, 0, 0, CSng(m_dimensions.Width), CSng(m_dimensions.Height)
For Each thisItem In m_items
If thisItem Is m_rootItem Then
m_graphics.DrawString thisItem.Caption, FontHelper.AppDefaultFont(FontStyleBold), GetBlackBrush, CreatePointF(thisItem.Left, MENU_MARGIN_Y)
ElseIf thisItem Is m_hoveredItem Then
MenuListHelper.DrawButton m_buttonSlices, ButtonOver, m_graphics, CreateRectL(m_dimensions.Height, thisItem.Width + (BUTTON_TEXT_GAP * 2), thisItem.Left - BUTTON_TEXT_GAP, 0)
m_graphics.DrawString thisItem.Caption, FontHelper.AppDefaultFont, GetWhiteBrush, CreatePointF(thisItem.Left, MENU_MARGIN_Y)
Else
MenuListHelper.DrawButton m_buttonSlices, ButtonUnpressed, m_graphics, CreateRectL(m_dimensions.Height, thisItem.Width, thisItem.Left, 0)
m_graphics.DrawString thisItem.Caption, FontHelper.AppDefaultFont, GetBlackBrush, CreatePointF(thisItem.Left, MENU_MARGIN_Y)
End If
'm_textPath.AddString thisItem.Caption, FontHelper.AppFontFamily, FontStyleRegular, FontHelper.AppDefaultFont.Size, CreateRectF(thisItem.Left, m_dimensions.Top, 20, m_dimensions.Width), 0
Next
RaiseEvent onChanged
End Function
Private Sub Class_Initialize()
Set m_textPath = New GDIPGraphicPath
Set m_items = New Collection
Set m_menuBitmap = New GDIPBitmap
Set m_graphics = New GDIPGraphics
Set m_menuOver = New GDIPImage
Set m_listMenu = New ListMenu
Set m_rootItem = New MenuItem
Set m_buttonSlices = MenuListHelper.CreateButtonFromXML("menubar_states", m_menuOver)
Set m_bgFinderMargin = GetMargin("bgfinder_shadow")
End Sub
Private Sub Class_Terminate()
Unload m_listMenu
End Sub
Private Sub m_listMenu_onClosed()
Set m_hoveredItem = Nothing
ReDraw
End Sub