Contingut

# Servei SFWidgets.Toolbar

The Toolbar service allows to retrieve information related to the toolbars available for a specific document window. With this service it is possible to:

- Activar o desactivar la visibilitat de barres d'eines específiques.

- Access information about the buttons available in each toolbar.

Cada aplicació del LibreOffice compta amb el seu propi conjunt de barres d'eines disponibles. Aquest servei gestiona tant les barres d'eines integrades com les personalitzades.

The status bar and the menu bar are not considered toolbars in the context of this service.

## Invocació del servei

Before using the Toolbar service the ScriptForge library needs to be loaded or imported:

• Per a carregar macros BASIC cal fer servir la biblioteca ScriptForge mitjançant aquesta expressió:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
• Els scripts Python requereixen una importació del mòdul scriptforge:
from scriptforge import CreateScriptService

The Toolbar service is invoked using the Toolbars method, which is available in SFDocuments.Document service.

##### En Basic

The example below gets an Array with the names of the toolbars available in the current document.

        oDoc = CreateScriptService("Document", ThisComponent)
        arrToolbars = oDoc.Toolbars()
        MsgBox SF_String.Represent(arrToolbars)

Use the Toolbars method without arguments to retrieve an array with available toolbar names.

The example below toggles the visibility of the Standard toolbar:

        oDoc = CreateScriptService("Document", ThisComponent)
        toolbar = oDoc.Toolbars("standardbar")
        toolbar.Visible = Not toolbar.Visible

##### En Python

        bas = CreateScriptService("Basic")
        doc = CreateScriptService("Document", bas.ThisComponent)
        arr_toolbars = doc.Toolbars()
        bas.MsgBox(repr(toolbars))

        bas = CreateScriptService("Basic")
        doc = CreateScriptService("Document", bas.ThisComponent)
        toolbar = doc.Toolbars("standardbar")
        toolbar.Visible = not toolbar.Visible

## Propietats

Nom | Només de lectura | Tipus | Descripció
--- | --- | --- | ---
BuiltIn | Sí | Boolean | Returns True when the toolbar is part of the set of standard toolbars shipped with LibreOffice.
Docked | Sí | Boolean | Returns True when the toolbar is active in the window and docked.
HasGlobalScope | Sí | Boolean | Returns True when the toolbar is available in all documents of the same type.
Name | Sí | String | Retorna el nom de la barra d'eines.
ResourceURL | Sí | String | Returns the resource URL of the toolbar, in the form private:toolbar/toolbar_name.
Visible | No | Boolean | Returns True when the toolbar is active and visible in the document window.
XUIElement | Sí | UNO Object | Returns the com.sun.star.ui.XUIElement UNO object that represents the toolbar.

Llista de mètodes del servei Toolbar
ToolbarButtons |  |

## ToolbarButtons

Returns an Array containing the names of all toolbar buttons when called without arguments.

Provide the name of a toolbar button as argument to obtain a ToolbarButton service instance.

### Sintaxi:

svc.ToolbarButtons(opt buttonname: str): any

### Paràmetres:

buttonname: The name of a toolbar button in the current toolbar.

### Exemple:

The example below returns the command executed when the button New is clicked in the Standard toolbar:

##### En Basic

          oToolbar = oDoc.Toolbars("standardbar")
          oToolbarButton = oToolbar.ToolbarButtons("New")
          MsgBox oToolbarButton.OnClick

##### En Python

          toolbar = doc.Toolbars("standardbar")
          toolbar_button = toolbar.ToolbarButtons("New")
          bas.MsgBox(toolbar_button.OnClick)

Inactive toolbars do not have buttons. Therefore, calling the ToolbarButtons method will make the toolbar visible.

Totes les rutines o identificadors bàsics de ScriptForge que tenen el prefix de guió baix "_" estan reservats per a ús intern. No estan pensats per utilitzar-los en macros de Basic o scripts de Python.

Temes relacionats

Servei SFWidgets.ToolbarButton