Difference between revisions of "Documentation/DevGuide/Basic/Accessing the UNO API"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
Line 7: Line 7:
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Basic/{{SUBPAGENAME}}}}  
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Basic/{{SUBPAGENAME}}}}  
 
  {{DISPLAYTITLE:Accessing the UNO API}}
 
  {{DISPLAYTITLE:Accessing the UNO API}}
In [[Documentation/DevGuide/ProUNO/Basic/OpenOffice.org Basic|OpenOffice.org Basic]], the interaction between Basic and UNO is described on an elementary level. This section describes the interface between Basic and the UNO API at the level of the {{AOo}} application.  
+
In [[Documentation/DevGuide/ProUNO/Basic/OpenOffice.org Basic|OpenOffice Basic]], the interaction between Basic and UNO is described on an elementary level. This section describes the interface between Basic and the UNO API at the level of the {{AOo}} application.  
  
 
This is realized by two predefined Basic properties:
 
This is realized by two predefined Basic properties:
Line 22: Line 22:
 
Example:
 
Example:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
   MsgBox StarDesktop.Dbg_SupportedInterfaces
 
   MsgBox StarDesktop.Dbg_SupportedInterfaces
 
    
 
    
Line 30: Line 30:
 
   oDesktop = CreateUnoService( "com.sun.star.frame.Desktop" )
 
   oDesktop = CreateUnoService( "com.sun.star.frame.Desktop" )
 
   MsgBox oDesktop.Dbg_SupportedInterfaces
 
   MsgBox oDesktop.Dbg_SupportedInterfaces
</source>
+
</syntaxhighlight>
  
 
The displayed message box differs slightly because <code>Dbg_SupportedInterfaces</code> displays "StarDesktop" as an object type of the desktop object in the first case and "com.sun.star.frame.Desktop" in the second. But the two objects are the same.
 
The displayed message box differs slightly because <code>Dbg_SupportedInterfaces</code> displays "StarDesktop" as an object type of the desktop object in the first case and "com.sun.star.frame.Desktop" in the second. But the two objects are the same.
Line 40: Line 40:
 
Basic module in a {{AOo}} document:
 
Basic module in a {{AOo}} document:
  
<source lang="oobas">
+
<syntaxhighlight lang="oobas">
 
   Sub Main
 
   Sub Main
 
       MsgBox ThisComponent.Dbg_SupportedInterfaces
 
       MsgBox ThisComponent.Dbg_SupportedInterfaces
 
   End Sub
 
   End Sub
</source>
+
</syntaxhighlight>
  
The execution of this Basic routine shows different results for a Text, Spreadsheet and Presentation document. Depending on the document type, a different set of interfaces are supported by the object. A portion of the interfaces are common to all these document types representing the general functionality that documents of any type offer. In particular, all {{PRODUCTNAME}} documents support the <idl>com.sun.star.document.OfficeDocument</idl> service, including the interfaces <idl>com.sun.star.frame.XStorable</idl> and <idl>com.sun.star.view.XPrintable</idl>. Another interface is <idl>com.sun.star.frame.XModel</idl>.
+
The execution of this Basic routine shows different results for a Text, Spreadsheet and Presentation document. Depending on the document type, a different set of interfaces are supported by the object. A portion of the interfaces are common to all these document types representing the general functionality that documents of any type offer. In particular, all {{AOo}} documents support the <idl>com.sun.star.document.OfficeDocument</idl> service, including the interfaces <idl>com.sun.star.frame.XStorable</idl> and <idl>com.sun.star.view.XPrintable</idl>. Another interface is <idl>com.sun.star.frame.XModel</idl>.
  
 
The following list shows the interfaces supported by all document types:
 
The following list shows the interfaces supported by all document types:
Line 66: Line 66:
 
* <idl>com.sun.star.view.XPrintable</idl>
 
* <idl>com.sun.star.view.XPrintable</idl>
  
For more information about the functionality of these interfaces, see [[Documentation/DevGuide/OfficeDev/Frame-Controller-Model Paradigm in OpenOffice.org|Frame-Controller-Model Paradigm in OpenOffice.org]]. This section also goes into detail about the general document API.
+
For more information about the functionality of these interfaces, see [[Documentation/DevGuide/OfficeDev/Frame-Controller-Model Paradigm in OpenOffice.org|Frame-Controller-Model Paradigm in Apache OpenOffice]]. This section also goes into detail about the general document API.
  
 
In addition to the common services or interfaces, each document type supports specific services or interfaces. The following list outlines the supported services and important interfaces:
 
In addition to the common services or interfaces, each document type supports specific services or interfaces. The following list outlines the supported services and important interfaces:
Line 73: Line 73:
  
 
* The service <idl>com.sun.star.text.TextDocument</idl> supports the interface <idl>com.sun.star.text.XTextDocument</idl>.  
 
* The service <idl>com.sun.star.text.TextDocument</idl> supports the interface <idl>com.sun.star.text.XTextDocument</idl>.  
* Several interfaces, especially from the [https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/module-ix.html com.sun.star.text] package.
+
* Several interfaces, especially from the <idlmodule>com.sun.star.text</idlmodule> package.
  
 
A Spreadsheet document supports:
 
A Spreadsheet document supports:
Line 79: Line 79:
 
* The service <idl>com.sun.star.sheet.SpreadsheetDocument</idl>,
 
* The service <idl>com.sun.star.sheet.SpreadsheetDocument</idl>,
 
* The service <idl>com.sun.star.sheet.SpreadsheetDocumentSettings</idl>.
 
* The service <idl>com.sun.star.sheet.SpreadsheetDocumentSettings</idl>.
* Several other interfaces, especially from the [https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/module-ix.html com.sun.star.sheet] package.
+
* Several other interfaces, especially from the <idlmodule>com.sun.star.sheet</idlmodule> package.
  
 
Presentation and Drawing documents support:
 
Presentation and Drawing documents support:
  
 
* The service <idl>com.sun.star.drawing.DrawingDocument</idl>.
 
* The service <idl>com.sun.star.drawing.DrawingDocument</idl>.
* Several other interfaces, especially from the [https://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/module-ix.html com.sun.star.drawing] package.
+
* Several other interfaces, especially from the <idlmodule>com.sun.star.drawing</idlmodule> package.
  
 
The usage of these services and interfaces is explained in the document type specific chapters [[Documentation/DevGuide/Text/Text Documents|Text Documents]], [[Documentation/DevGuide/Spreadsheets/Spreadsheet Documents|Spreadsheet Documents]] and [[Documentation/DevGuide/Drawings/Drawing Documents and Presentation Documents|Drawing Documents and Presentation Documents]].
 
The usage of these services and interfaces is explained in the document type specific chapters [[Documentation/DevGuide/Text/Text Documents|Text Documents]], [[Documentation/DevGuide/Spreadsheets/Spreadsheet Documents|Spreadsheet Documents]] and [[Documentation/DevGuide/Drawings/Drawing Documents and Presentation Documents|Drawing Documents and Presentation Documents]].
Line 92: Line 92:
 
=== ThisDatabaseDocument===
 
=== ThisDatabaseDocument===
  
The property <code>ThisDatabaseDocument</code>, introduced since {{OOo}} 3.1, is only used from a Basic code which is embedded in a Base document. It refers to the Base document model.
+
The property <code>ThisDatabaseDocument</code>, introduced since OpenOffice.org 3.1, is only used from a Basic code which is embedded in a Base document. It refers to the Base document model.
  
 
Typically, when a macro is started by an event from a Form of the Base document, <code>ThisDatabaseDocument</code> represents the Base document, whereas <code>ThisComponent</code> refers to the Form document.
 
Typically, when a macro is started by an event from a Form of the Base document, <code>ThisDatabaseDocument</code> represents the Base document, whereas <code>ThisComponent</code> refers to the Form document.

Latest revision as of 21:06, 20 December 2020



In OpenOffice Basic, the interaction between Basic and UNO is described on an elementary level. This section describes the interface between Basic and the UNO API at the level of the Apache OpenOffice application.

This is realized by two predefined Basic properties:

  • StarDesktop
  • ThisComponent

The property StarDesktop gives access to the global Apache OpenOffice application API while the property ThisComponent accesses the document related API.

StarDesktop

The property StarDesktop is a shortcut for the service com.sun.star.frame.Desktop.

Example:

  MsgBox StarDesktop.Dbg_SupportedInterfaces
 
  ' is the same as
 
  Dim oDesktop
  oDesktop = CreateUnoService( "com.sun.star.frame.Desktop" )
  MsgBox oDesktop.Dbg_SupportedInterfaces

The displayed message box differs slightly because Dbg_SupportedInterfaces displays "StarDesktop" as an object type of the desktop object in the first case and "com.sun.star.frame.Desktop" in the second. But the two objects are the same.

ThisComponent

The property ThisComponent is used from document Basic, where it represents the document the Basic belongs to. The type of object accessed by ThisComponent depends on the document type. The following example shows the differences.

Basic module in a Apache OpenOffice document:

  Sub Main
      MsgBox ThisComponent.Dbg_SupportedInterfaces
  End Sub

The execution of this Basic routine shows different results for a Text, Spreadsheet and Presentation document. Depending on the document type, a different set of interfaces are supported by the object. A portion of the interfaces are common to all these document types representing the general functionality that documents of any type offer. In particular, all Apache OpenOffice documents support the com.sun.star.document.OfficeDocument service, including the interfaces com.sun.star.frame.XStorable and com.sun.star.view.XPrintable. Another interface is com.sun.star.frame.XModel.

The following list shows the interfaces supported by all document types:

For more information about the functionality of these interfaces, see Frame-Controller-Model Paradigm in Apache OpenOffice. This section also goes into detail about the general document API.

In addition to the common services or interfaces, each document type supports specific services or interfaces. The following list outlines the supported services and important interfaces:

A Text document supports:

A Spreadsheet document supports:

Presentation and Drawing documents support:

The usage of these services and interfaces is explained in the document type specific chapters Text Documents, Spreadsheet Documents and Drawing Documents and Presentation Documents.

As previously mentioned, ThisComponent is used from document Basic, but it is also possible to use it from application Basic. In an application wide Basic module, ThisComponent is identical to the current component that can also be accessed through StarDesktop.CurrentComponent. The only difference between the two is that if the BasicIDE is active, StarDesktop.CurrentComponent refers to the BasicIDE itself while ThisComponent always refers to the component that was active before the BasicIDE became the top window.

ThisDatabaseDocument

The property ThisDatabaseDocument, introduced since OpenOffice.org 3.1, is only used from a Basic code which is embedded in a Base document. It refers to the Base document model.

Typically, when a macro is started by an event from a Form of the Base document, ThisDatabaseDocument represents the Base document, whereas ThisComponent refers to the Form document.


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages