/
cwRibbon.cls
162 lines (136 loc) · 5.31 KB
/
cwRibbon.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cwRibbon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Event SelectionChanged(ActiveEntry As cwRibbonEntry)
Private Alpha As Single, dx As Single, dy As Single
Private mCurrentEntryIndex As Long, mCaptionsHeight As Single
Private WithEvents W As cWidgetBase
Attribute W.VB_VarHelpID = -1
Private Sub Class_Initialize()
Set W = Cairo.WidgetBase
W.ForwardFocus = True
mCurrentEntryIndex = -1
mCaptionsHeight = 20
End Sub
Public Property Get Widget() As cWidgetBase
Set Widget = W
End Property
Public Property Get Widgets() As cWidgets
Set Widgets = W.Widgets
End Property
Public Sub AddEntry(Caption As String, IconResourceKey As String, AssociatedWidget As Object)
Dim Key As String, NewRibbonEntry As New cwRibbonEntry
NewRibbonEntry.Caption = Caption
NewRibbonEntry.Widget.ImageKey = IconResourceKey
Key = Widgets.Count \ 2 & "_RibbEntry"
Widgets.Add NewRibbonEntry, Key, EntriesCount * 150, 2, 150, mCaptionsHeight
Widgets.Add AssociatedWidget, Key & "Assoc", 2, mCaptionsHeight, W.Width, W.Height - mCaptionsHeight, False
AdjustEntries
End Sub
Private Sub AdjustEntries()
Dim i As Long, y As Single, yy As Single, WEntry As cWidgetBase
If Widgets.Count = 0 Then Exit Sub
W.LockRefresh = True
y = mCaptionsHeight
For i = 0 To mCurrentEntryIndex
'the cwRibbon-Entry
Set WEntry = Widgets(2 * i + 1).Widget
' WEntry.Move -1, y, W.Width, mAccEntryHeight
' y = y + mAccEntryHeight
'the associated Widget
Set WEntry = Widgets(2 * i + 2).Widget
If i < mCurrentEntryIndex Then WEntry.Visible = False
Next i
' yy = W.ScaleHeight - (Widgets.Count \ 2 - mCurrentEntryIndex - 1) * mAccEntryHeight
If Not WEntry Is Nothing Then
' WEntry.Move -1, y - 1, W.Width, yy - y + 2
WEntry.Visible = True
WEntry.SetFocus
End If
y = yy
For i = mCurrentEntryIndex + 1 To Widgets.Count \ 2 - 1
'the cwAccordeon-Entry
Set WEntry = Widgets(2 * i + 1).Widget
' WEntry.Move 0, y + 1, W.Width, mAccEntryHeight
' y = y + mAccEntryHeight
'the associated Widget
Set WEntry = Widgets(2 * i + 2).Widget
WEntry.Visible = False
Next i
W.LockRefresh = False
End Sub
Public Property Get EntriesCount() As Long
EntriesCount = Widgets.Count \ 2
End Property
Public Function EntryByIndex(ByVal EntryIndexZeroBased As Long) As cwRibbonEntry
If EntryIndexZeroBased < 0 Or EntryIndexZeroBased >= EntriesCount Then Exit Function
Set EntryByIndex = Widgets(EntryIndexZeroBased * 2 + 1)
End Function
Public Property Get CurrentEntry() As cwRibbonEntry
If EntriesCount = 0 Then Exit Property
Set CurrentEntry = Widgets(CurrentEntryIndex * 2 + 1)
End Property
Public Property Get CurrentEntryIndex() As Long
CurrentEntryIndex = mCurrentEntryIndex
End Property
Public Property Let CurrentEntryIndex(ByVal NewValue As Long)
If NewValue < -1 Or NewValue >= EntriesCount Then Exit Property
If mCurrentEntryIndex = NewValue Then Exit Property
mCurrentEntryIndex = NewValue
RaiseEvent SelectionChanged(CurrentEntry)
AdjustEntries
End Property
Private Sub W_BubblingEvent(Sender As Object, EventName As String, P1 As Variant, P2 As Variant, P3 As Variant, P4 As Variant, P5 As Variant, P6 As Variant, P7 As Variant)
Static FocusChange As Boolean
If TypeOf Sender Is cwRibbonEntry Then
Select Case EventName
Case "W_LostFocus": If Not CurrentEntry Is Sender Then FocusChange = True
Case "W_Click": CurrentEntryIndex = Split(Sender.Widget.Key, "_")(0)
Case "W_KeyPress"
If P1 = vbKeySpace Or P1 = vbKeyReturn Then CurrentEntryIndex = Split(Sender.Widget.Key, "_")(0)
End Select
ElseIf Not CurrentEntry Is Nothing Then
If Sender Is CurrentEntry.AssociatedWidget Then
If EventName = "W_KeyDown" Then
If Not (P1 = vbKeyTab And P2 = vbShiftMask) Then Exit Sub
If FocusChange Then FocusChange = False: Exit Sub
If CurrentEntryIndex <= 0 Then W.SetFocus Else EntryByIndex(CurrentEntryIndex - 1).Widget.SetFocus
End If
End If
End If
End Sub
Private Sub W_Resize()
AdjustEntries
End Sub
Private Sub W_Paint(CC As cCairoContext, ByVal xAbs As Single, ByVal yAbs As Single, ByVal dx_Aligned As Single, ByVal dy_Aligned As Single, UserObj As Object)
dx = dx_Aligned
dy = dy_Aligned
Alpha = W.AlphaInherited
Draw CC
End Sub
Private Sub Draw(CC As cCairoContext)
Dim i As Long, Pat As cCairoPattern, dyy As Single, TextShadowColor As Long
'the Caption-Background
Set Pat = Cairo.CreateLinearPattern(0, 0, 0, dy)
CC.SetLineWidth 0
Pat.AddColorStop 0, W.BackColor, Alpha, 1.09
Pat.AddColorStop 0.95, W.BackColor, Alpha, 0.93
Pat.AddColorStop 1, W.BackColor, Alpha, 1.3
CC.Rectangle 0, 0, dx, dy, True
CC.Fill , Pat
CC.SetLineWidth 1, True
CC.DrawLine 0, dy - 1, dx, dy - 1, True
CC.SetSourceColor W.BorderColor, Alpha * 0.9
CC.Stroke
End Sub