[Solved] Macro to Open a Toolbar I just created?

Creating a macro - Writing a Script - Using the API

[Solved] Macro to Open a Toolbar I just created?

Postby alf50 » Mon Sep 17, 2012 11:24 pm

How do I write a Macro to Open a Toolbar I just created?

I found some Macro Code to do this, but it does not show the format of the "sURL" variable that points to the Toolbar?

The name of the ToolBar is "Controls". It is located in my "Timer.ods" Application, which is sitting in my Documents Folder, but when I set the sURL to "Controls", or "Timer.ods.Toolbars.Controls" Nothing happens. What am I doing wrong?

The Macro is shown below:

Code: Select all   Expand viewCollapse view
Sub ToggleToolbarVisible(oDoc, sURL, prepinac)
  Dim oLayout
  oLayout = oDoc.CurrentController.getFrame().LayoutManager
  Select Case prepinac
    Case 0  rem --- hide toolbar
      oLayout.hideElement(sURL)
    Case 1  rem --- show toolbar
      oLayout.showElement(sURL)
    Case 2  rem --- switch toolbar
      If oLayout.isElementVisible(sURL) Then
        oLayout.hideElement(sURL)
      Else
        oLayout.showElement(sURL)
      End If
  End Select
End Sub
Last edited by alf50 on Wed Sep 19, 2012 12:47 am, edited 1 time in total.
OpenOffice 4.1.5 on Mac El Capitan(10.11.6) and MS Windows10
alf50
 
Posts: 102
Joined: Sun Jun 13, 2010 2:55 pm

Re: Macro to Open a Toolbar I just created?

Postby kingfisher » Tue Sep 18, 2012 10:19 am

I use an url like this:

Code: Select all   Expand viewCollapse view
sUrl = "private:resource/toolbar/standardbar"


If the tool bar is not visible, you may have to create it before trying to make it visible.
Apache OpenOffice 4.1.6 on PCLinuxOS
User avatar
kingfisher
Volunteer
 
Posts: 2120
Joined: Tue Nov 20, 2007 10:53 am

Re: Macro to Open a Toolbar I just created?

Postby hanya » Tue Sep 18, 2012 11:01 am

User created toolbar has randomized internal resource id and it should be specified to do something with it.
It can be taken from UI settings stored in the document as follows:
Code: Select all   Expand viewCollapse view
Sub ToolbarTest
  oDoc = ThisComponent
  sResId = FindToolbar(oDoc, "Controls")
  if not isnull(sResId) then
    oManager = oDoc.getCurrentController().getFrame().LayoutManager
    oManager.createElement(sResId)
    oManager.showElement(sResId)
  end if
End Sub

Function FindToolbar(oDoc, sName As String)
  oManager = oDoc.getUIConfigurationManager()
  aElements = oManager.getUIElementsInfo(_
       com.sun.star.ui.UIElementType.TOOLBAR)
  itemset = nothing
  for i = 0 to ubound(aElements) step 1
    a = aElements(i)
    if GetPropertyValueByName(a, "UIName") = sName then
      itemset = a
      exit for
    end if
  next
  if not isnull(itemset) then
    FindToolbar = GetPropertyValueByName(itemset, "ResourceURL")
  else
    FindToolbar = nothing
  end if
End Function

Function GetPropertyValueByName(aElements, sName) As Variant
  found = nothing
  for i = 0 to ubound(aElements) step 1
    if aElements(i).Name = sName then
      found = aElements(i).Value
    end if
  next
  GetPropertyValueByName = found
End Function
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests