Skip to content

Commit e6ee952

Browse files
committed
Mac compatibility layer for stdRibbon
1 parent 90cc203 commit e6ee952

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,5 @@ Before `08/07/2021` a change log was not kept. We have retrospectively gone back
359359
- 2025-07-12 `stdImage` FEATURE - Added a `FindAll()` function which returns a collection of all found images.
360360
- 2025-08-08 `stdRibbon` FEATURE - Added `stdRibbon` which allows for the ribbon to be hidden or shown.
361361
- 2025-08-18 `stdRibbon` FEATURE - `stdRibbon` now supports Word. Additionally state detection is more robust.
362-
- 2025-09-25 `stdRibbon` FIX - Fix infinite recursion issue, now we error when state hasn't changed.
362+
- 2025-09-25 `stdRibbon` FIX - Fix infinite recursion issue, now we error when state hasn't changed.
363+
- 2025-09-30 `stdRibbon` FIX - Mac compatibility layer for stdRibbon. Also fixed a bug related to the above change.

src/stdRibbon.cls

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Attribute VB_Creatable = False
88
Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = False
1010

11+
#Const isWindows = Mac = 0
12+
1113
Public Enum ERibbonState
1214
RibbonNullState
1315
RibbonFullScreenMode
@@ -32,19 +34,43 @@ Public Property Get State() As ERibbonState
3234
Dim appProtectedView as Boolean: appProtectedView = Not Application.ActiveProtectedViewWindow Is Nothing
3335
Dim oApp as Object: Set oApp = Application 'Latebound to avoid compile errors
3436

37+
3538
Dim xlDisplayFullScreen as Boolean
3639
Dim wdReadMode as Boolean
3740
Dim wdViewFullScreen as Boolean
3841
Dim wdProtectedViewMode as Boolean
42+
Dim genRibbonNotVisible as Boolean
43+
Dim genRibbonHidden as Boolean
44+
Dim genRibbonMinimized as Boolean
45+
46+
3947
select case Application.Name
4048
case "Microsoft Excel"
41-
xlDisplayFullScreen = oApp.DisplayFullScreen
49+
#If isWindows then
50+
xlDisplayFullScreen = oApp.DisplayFullScreen
51+
genRibbonNotVisible = Not Application.CommandBars("Ribbon").Visible
52+
genRibbonHidden = Application.CommandBars.GetPressedMso("HideRibbon")
53+
genRibbonMinimized = Application.CommandBars.GetPressedMso("MinimizeRibbon")
54+
#Else
55+
'None of these are supported on Mac
56+
'Note: Application.DisplayFullScreen is supported on Mac, but doesn't hide the ribbon!
57+
#End If
4258
case "Microsoft Word"
43-
If Not appProtectedView Then
44-
wdViewFullScreen = oApp.ActiveWindow.View.FullScreen
45-
wdReadMode = oApp.ActiveWindow.View.ReadingLayout
46-
end if
59+
#If isWindows then
60+
If Not appProtectedView Then
61+
wdViewFullScreen = oApp.ActiveWindow.View.FullScreen
62+
wdReadMode = oApp.ActiveWindow.View.ReadingLayout
63+
end if
64+
genRibbonNotVisible = Not Application.CommandBars("Ribbon").Visible
65+
genRibbonHidden = Application.CommandBars.GetPressedMso("HideRibbon")
66+
genRibbonMinimized = Application.CommandBars.GetPressedMso("MinimizeRibbon")
67+
#Else
68+
'Only Ribbon Minimized is supported on Mac
69+
genRibbonMinimized = Application.CommandBars.GetPressedMso("MinimizeRibbon")
70+
#End If
4771
end select
72+
73+
4874

4975
'In this mode state is reversable
5076
select case true
@@ -56,11 +82,11 @@ Public Property Get State() As ERibbonState
5682
State = WordViewFullScreenMode
5783
case wdReadMode
5884
State = WordViewReadMode
59-
case Not Application.CommandBars("Ribbon").Visible
85+
case genRibbonNotVisible
6086
State = RibbonNotVisible
61-
case Application.CommandBars.GetPressedMso("MinimizeRibbon")
87+
case genRibbonMinimized
6288
State = RibbonShowTabsOnly
63-
Case Application.CommandBars.GetPressedMso("HideRibbon")
89+
Case genRibbonHidden
6490
State = RibbonFullScreenMode
6591
Case Else
6692
State = RibbonAlwaysShowRibbon
@@ -94,12 +120,23 @@ Public Property Let State(v As ERibbonState)
94120
Case RibbonFullScreenMode
95121
Call Application.CommandBars.ExecuteMso("HideRibbon")
96122
Case RibbonShowTabsOnly
97-
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
123+
#If isWindows then
124+
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
125+
#Else
126+
'On Mac, it seems MinimizeRibbon is asynchronous, so we need to wait for it to finish
127+
Dim macMinimizeRibbon as Boolean
128+
macMinimizeRibbon = Application.CommandBars.GetPressedMso("MinimizeRibbon")
129+
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
130+
Do While macMinimizeRibbon = Application.CommandBars.GetPressedMso("MinimizeRibbon")
131+
'For some god forsaken reason, DoEvents does not work here... Need to use macscript delays.
132+
Call MacScript("delay 0")
133+
Loop
134+
#End If
98135
End Select
99136
DoEvents
100137

101138
'Check if state has changed and if not error.
102-
If State = iCurrentState then Err.Raise 1, "stdRibbon#State[Let]", "Ribbon state has not changed away from " & v
139+
If (State = iCurrentState) And (iCurrentState <> RibbonAlwaysShowRibbon) then Err.Raise 1, "stdRibbon#State[Let]", "Ribbon state has not changed away from " & v
103140

104141
'Recursively change state to `RibbonAlwaysShowRibbon`
105142
If iCurrentState <> RibbonAlwaysShowRibbon Then State = RibbonAlwaysShowRibbon
@@ -125,6 +162,16 @@ Public Property Let State(v As ERibbonState)
125162
Case RibbonFullScreenMode
126163
Call Application.CommandBars.ExecuteMso("HideRibbon")
127164
Case RibbonShowTabsOnly
128-
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
165+
#If isWindows then
166+
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
167+
#Else
168+
'On Mac, it seems MinimizeRibbon is asynchronous, so we need to wait for it to finish
169+
macMinimizeRibbon = Application.CommandBars.GetPressedMso("MinimizeRibbon")
170+
Call Application.CommandBars.ExecuteMso("MinimizeRibbon")
171+
Do While macMinimizeRibbon = Application.CommandBars.GetPressedMso("MinimizeRibbon")
172+
'For some god forsaken reason, DoEvents does not work here... Need to use macscript delays.
173+
Call MacScript("delay 0")
174+
Loop
175+
#End If
129176
End Select
130177
End Property

0 commit comments

Comments
 (0)