An approach I've been exploring is to hide or show the elements individually. The elements are identified by their ResourceURL (strings), and there are normally five of them
Code: Select all
private:resource/toolbar/standardbar
private:resource/toolbar/findbar
private:resource/toolbar/formatobjectbar
private:resource/menubar/menubar
private:resource/statusbar/statusbar
A macro to hide all of these is
Code: Select all
Sub hideallBars()
Dim doc As Object
Dim frame As Object
Dim lmgr As Object
Dim LayoutElements(4) As String
Dim i As Integer
LayoutElements(0) = "private:resource/toolbar/standardbar"
LayoutElements(1) = "private:resource/toolbar/findbar"
LayoutElements(2) = "private:resource/toolbar/formatobjectbar"
LayoutElements(3) = "private:resource/menubar/menubar"
LayoutElements(4) = "private:resource/statusbar/statusbar"
doc = ThisComponent
frame = doc.CurrentController.Frame
lmgr = frame.LayoutManager
for i = 0 to 4
lmgr.hideElement(LayoutElements(i))
next i
End Sub
And to show them again just change hideElement to showElement.
Code: Select all
Sub showallBars()
Dim doc As Object
Dim frame As Object
Dim lmgr As Object
Dim LayoutElements(4) As String
Dim lElements
Dim i As Integer
LayoutElements(0) = "private:resource/toolbar/standardbar"
LayoutElements(1) = "private:resource/toolbar/findbar"
LayoutElements(2) = "private:resource/toolbar/formatobjectbar"
LayoutElements(3) = "private:resource/menubar/menubar"
LayoutElements(4) = "private:resource/statusbar/statusbar"
doc = ThisComponent
frame = doc.CurrentController.Frame
lmgr = frame.LayoutManager
for i = 0 to 4
lmgr.showElement(LayoutElements(i))
next i
End Sub
Obviously these could be combined into one macro using some kind of hide/show parameter.
A problem here, which I probably haven't explored fully, is that if I run hideallBars, then close Calc even without saving the document via the Close Button or alt+F4, then reopen Calc, all the elements except the menu bar remain hidden, and running showallBars as listed above doesn't restore them. To get them back, one then has to display them individually from the View menu. It is good that the menu bar doesn't remain hidden on reopening, or one would be rather helpless and would have to resort to some drastic steps to restore things.
This version of showallBars seems to fix the close/reopen problem
Code: Select all
Sub ShowAllBars()
Dim doc As Object
Dim frame As Object
Dim lmgr As Object
Dim LayoutElements(4) As String
Dim lElements
Dim hasElement As boolean
Dim i As Integer
Dim j As Integer
LayoutElements(0) = "private:resource/toolbar/standardbar"
LayoutElements(1) = "private:resource/toolbar/findbar"
LayoutElements(2) = "private:resource/toolbar/formatobjectbar"
LayoutElements(3) = "private:resource/menubar/menubar"
LayoutElements(4) = "private:resource/statusbar/statusbar"
doc = ThisComponent
frame = doc.CurrentController.Frame
lmgr = frame.LayoutManager
lElements = lmgr.getElements
for i = 0 to UBound(lElements,1)
MsgBox(lElements(i).ResourceURL)
next i
For i = 0 to 4
j = 0
hasElement = False
do while not hasElement and j <= UBound(lElements,1)
if lElements(j).ResourceURL = LayoutElements(i) then
hasElement = True
else
j = j + 1
endif
loop
if hasElement then
lmgr.showElement(LayoutElements(j))
else
lmgr.createElement(LayoutElements(i))
lmgr.showElement(LayoutElements(i))
endif
next i
End Sub
I haven't dealt with the issues of protected sheets/documents or versions prior to 3.3. Hopefully these won't be big problems.