Skip to content

Commit ea31b2b

Browse files
committed
Add stdRibbon null state and protected view mode
1 parent efe3dee commit ea31b2b

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

src/WIP/stdCallableScheduler.bas

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Attribute VB_Name = "stdCallableScheduler"
2+
3+
Private scheduledCallbacks As Collection
4+
5+
'Schedule a callback after a number of seconds
6+
'@param cb - The callback to schedule
7+
'@param seconds - The number of seconds to wait before calling the callback
8+
Public Function ScheduleCallback(ByVal cb As stdICallable, ByVal seconds As Long) as Long
9+
if scheduledCallbacks is nothing Then Set scheduledCallbacks = New Collection
10+
Dim onTime As Date: onTime = Now() + TimeSerial(0, 0, 5)
11+
Call scheduledCallbacks.Add(Array(cb, onTime))
12+
Call Application.onTime(onTime, "protCallScheduledCallbacks")
13+
ScheduleCallback = scheduledCallbacks.Count
14+
End Sub
15+
16+
'Call all scheduled callbacks
17+
'@protected
18+
Public Sub protCallScheduledCallbacks()
19+
Dim i As Long
20+
For i = scheduledCallbacks.Count To 1 Step -1
21+
Dim cb As stdICallable: Set cb = scheduledCallbacks(i)(0)
22+
Dim onTime As Date: onTime = scheduledCallbacks(i)(1)
23+
If onTime < Now() Then
24+
Call scheduledCallbacks.Remove(i)
25+
Call cb.Run()
26+
End If
27+
Next
28+
End Sub

src/WIP/stdICallableScheduler.bas

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Attribute VB_Name = "stdCallableScheduler"
2+
3+
Private scheduledCallbacks As Collection
4+
5+
'Schedule a callback after a number of seconds
6+
'@param cb - The callback to schedule
7+
'@param seconds - The number of seconds to wait before calling the callback
8+
Public Sub ScheduleCallback(ByVal cb As stdICallable, ByVal seconds As Long)
9+
With stdError.getSentry("stdCallableScheduler#ScheduleCallback")
10+
On Error GoTo stdErrorWrapper_ErrorOccurred:
11+
if scheduledCallbacks is nothing Then Set scheduledCallbacks = New Collection
12+
Dim onTime As Date: onTime = Now() + TimeSerial(0, 0, seconds)
13+
Call scheduledCallbacks.Add(Array(cb, onTime))
14+
Call Application.onTime(onTime, "protCallScheduledCallbacks")
15+
Exit Sub
16+
stdErrorWrapper_ErrorOccurred:
17+
Call stdError.Raise(Err.description)
18+
End With
19+
End Sub
20+
21+
'Call all scheduled callbacks
22+
'@protected
23+
Public Sub protCallScheduledCallbacks()
24+
With stdError.getSentry("stdCallableScheduler#protCallScheduledCallbacks")
25+
On Error GoTo stdErrorWrapper_ErrorOccurred:
26+
Dim i As Long
27+
For i = scheduledCallbacks.Count To 1 Step -1
28+
Dim cb As stdICallable: Set cb = scheduledCallbacks(i)(0)
29+
Dim onTime As Date: onTime = scheduledCallbacks(i)(1)
30+
If onTime <= Now() Then
31+
Call scheduledCallbacks.Remove(i)
32+
Call cb.Run()
33+
End If
34+
Next
35+
Exit Sub
36+
stdErrorWrapper_ErrorOccurred:
37+
Call stdError.Raise(Err.description)
38+
End With
39+
End Sub

src/stdRibbon.cls

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = False
1010

1111
Public Enum ERibbonState
12+
RibbonNullState
1213
RibbonFullScreenMode
1314
RibbonShowTabsOnly
1415
RibbonAlwaysShowRibbon
1516
RibbonNotVisible
17+
RibbonProtectedViewMode
1618
ExcelApplicationDisplayFullScreenMode
1719
WordViewFullScreenMode
1820
WordViewReadMode
21+
1922
End Enum
2023

2124
'Get/Set the ribbon's state. The ribbon itself comes with the following options:
@@ -26,21 +29,27 @@ End Enum
2629
'And a state where the application is in full screen mode, thus hiding the ribbon
2730
'This Get/Set property helps cleanly reset the state to a necessary one
2831
Public Property Get State() As ERibbonState
32+
Dim appProtectedView as Boolean: appProtectedView = Not Application.ActiveProtectedViewWindow Is Nothing
2933
Dim oApp as Object: Set oApp = Application 'Latebound to avoid compile errors
3034

3135
Dim xlDisplayFullScreen as Boolean
3236
Dim wdReadMode as Boolean
3337
Dim wdViewFullScreen as Boolean
38+
Dim wdProtectedViewMode as Boolean
3439
select case Application.Name
3540
case "Microsoft Excel"
3641
xlDisplayFullScreen = oApp.DisplayFullScreen
3742
case "Microsoft Word"
38-
wdViewFullScreen = oApp.ActiveWindow.View.FullScreen
39-
wdReadMode = oApp.ActiveWindow.View.ReadingLayout
43+
If Not appProtectedView Then
44+
wdViewFullScreen = oApp.ActiveWindow.View.FullScreen
45+
wdReadMode = oApp.ActiveWindow.View.ReadingLayout
46+
end if
4047
end select
4148

4249
'In this mode state is reversable
4350
select case true
51+
case appProtectedView
52+
State = RibbonProtectedViewMode
4453
case xlDisplayFullScreen
4554
State = ExcelApplicationDisplayFullScreenMode
4655
case wdViewFullScreen
@@ -65,6 +74,8 @@ Public Property Let State(v As ERibbonState)
6574
Select Case State
6675
Case RibbonAlwaysShowRibbon
6776
'Do nothing
77+
case RibbonProtectedViewMode
78+
Call Application.ActiveProtectedViewWindow.Edit
6879
case WordViewFullScreenMode
6980
if Application.Name <> "Microsoft Word" then Err.Raise 1, "stdRibbon#State[Let]", "WordViewFullScreenMode found in non Word Application. This should never happen."
7081
oApp.ActiveWindow.View.FullScreen = False
@@ -89,6 +100,8 @@ Public Property Let State(v As ERibbonState)
89100
Select Case v
90101
Case RibbonAlwaysShowRibbon
91102
Exit Property
103+
Case RibbonProtectedViewMode
104+
Err.Raise 1, "stdRibbon#State[Let]", "WordProtectedViewMode can only be entered by opening a document in Protected View"
92105
case WordViewFullScreenMode
93106
if Application.Name <> "Microsoft Word" then Err.Raise 1, "stdRibbon#State[Let]", "WordViewReadMode is only supported in Word"
94107
oApp.ActiveWindow.View.FullScreen = true

0 commit comments

Comments
 (0)