Difference between revisions of "Documentation/DevGuide/FirstSteps/Common Types"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(18 intermediate revisions by 6 users not shown)
Line 4: Line 4:
 
|PrevPage=Documentation/DevGuide/FirstSteps/Example: Working with a Spreadsheet Document
 
|PrevPage=Documentation/DevGuide/FirstSteps/Example: Working with a Spreadsheet Document
 
|NextPage=Documentation/DevGuide/FirstSteps/Struct
 
|NextPage=Documentation/DevGuide/FirstSteps/Struct
}}
+
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/FirstSteps/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Common Types}}
 
{{DISPLAYTITLE:Common Types}}
Until now, literals and common Java types for method parameters and return values have been used as if the {{PRODUCTNAME}} API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to [[Documentation/APIGuide/ProUNO/Professional UNO|Professional UNO]] for detailed information about type mappings.  
+
Until now, literals and common Java types for method parameters and return values have been used as if the {{AOo}} API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to [[Documentation/DevGuide/ProUNO/Professional UNO|Professional UNO]] for detailed information about type mappings.  
  
 
===Basic Types===
 
===Basic Types===
The basic UNO types (where the term “basic” has nothing to do with {{PRODUCTNAME}} Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and {{PRODUCTNAME}} Basic types.  
+
The basic UNO types (where the term “basic” has nothing to do with {{AOo}} Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and {{AOo}} Basic types.  
  
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
Line 39: Line 40:
 
|char          ||16-bit Unicode character type (more precisely: UTF-16 code units)-||char||sal_Unicode||-
 
|char          ||16-bit Unicode character type (more precisely: UTF-16 code units)-||char||sal_Unicode||-
 
|}
 
|}
There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in [[Documentation/APIGuide/ProUNO/UNO Language Bindings|UNO Language Bindings]].
+
There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in [[Documentation/DevGuide/ProUNO/UNO Language Bindings|UNO Language Bindings]].
  
 
===Strings===
 
===Strings===
Line 54: Line 55:
 
In C++, native <code>char</code> strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function <code>createFromAscii()</code> in the <code>rtl::OUString</code> class:
 
In C++, native <code>char</code> strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function <code>createFromAscii()</code> in the <code>rtl::OUString</code> class:
  
 +
<syntaxhighlight lang="cpp">
 
   //C++
 
   //C++
 
   static OUString createFromAscii( const sal_Char * value ) throw();  
 
   static OUString createFromAscii( const sal_Char * value ) throw();  
 +
</syntaxhighlight>
  
 
In Basic, Basic strings are mapped to UNO strings transparently.
 
In Basic, Basic strings are mapped to UNO strings transparently.
  
 
===Enum Types and Groups of Constants===
 
===Enum Types and Groups of Constants===
The {{PRODUCTNAME}} API uses many enumeration types (called enums) and groups of constants (called constant groups). ''Enums'' are used to list every plausible value in a certain context. The ''constant'' groups define possible values for properties, parameters, return values and struct members.
+
The {{AOo}} API uses many enumeration types (called enums) and groups of constants (called constant groups). ''Enums'' are used to list every plausible value in a certain context. The ''constant'' groups define possible values for properties, parameters, return values and struct members.
For example, there is an enum [http://api.openoffice.org/docs/common/ref/com/sun/star/table/CellVertJustify.html com.sun.star.table.CellVertJustify] that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property [http://api.openoffice.org/docs/common/ref/com/sun/star/table/CellProperties.html#VertJustify com.sun.star.table.CellProperties:VertJustify]. The possible values for this property are, according to <code>CellVertJustify</code>, the values <code>STANDARD</code>, <code>TOP</code>, <code>CENTER</code> and <code>BOTTOM</code>.
+
For example, there is an enum <idl>com.sun.star.table.CellVertJustify</idl> that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property <idlm>com.sun.star.table.CellProperties:VertJustify</idlm>. The possible values for this property are, according to <code>CellVertJustify</code>, the values <code>STANDARD</code>, <code>TOP</code>, <code>CENTER</code> and <code>BOTTOM</code>.
  
 +
<syntaxhighlight lang="java">
 
   // adjust a cell content to the upper cell border
 
   // adjust a cell content to the upper cell border
 
   // The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
 
   // The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
Line 69: Line 73:
 
    
 
    
 
   xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);
 
   xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);
 +
</syntaxhighlight>
  
{{PRODUCTNAME}} Basic understands enumeration types and constant groups. Their usage is straightforward:
+
{{AOo}} Basic understands enumeration types and constant groups. Their usage is straightforward:
  
   '{{PRODUCTNAME}} Basic
+
<syntaxhighlight lang="oobas">
 +
   'OpenOffice Basic
 
   oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP
 
   oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP
 +
</syntaxhighlight>
  
 
In C++ enums and constant groups are used with the scope operator <code>::</code>
 
In C++ enums and constant groups are used with the scope operator <code>::</code>
  
 +
<syntaxhighlight lang="cpp">
 
   //C++
 
   //C++
 
   rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
 
   rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
 
           ::com::sun::star::table::CellVertJustify.TOP);
 
           ::com::sun::star::table::CellVertJustify.TOP);
 +
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: First Steps]]
+
 
 +
[[Category:Documentation/Developer's Guide/First Steps]]

Latest revision as of 15:47, 15 February 2021



Until now, literals and common Java types for method parameters and return values have been used as if the Apache OpenOffice API was made for Java. However, it is important to understand that UNO is designed to be language independent and therefore has its own set of types which have to be mapped to the proper types for your language binding. The type mappings are briefly described in this section. Refer to Professional UNO for detailed information about type mappings.

Basic Types

The basic UNO types (where the term “basic” has nothing to do with Apache OpenOffice Basic) occur as members of structs, as method return types or method parameters. The following table shows the basic UNO types and, if available, their exact mappings to Java, C++, and Apache OpenOffice Basic types.

UNO Type description Java C++ Basic
void empty type, used only as method return type and in any void void -
boolean Boolean type; true and false boolean sal_Bool Boolean
byte signed 8-bit integer type byte sal_Int8 Integer
short signed 16-bit integer type short sal_Int16 Integer
unsigned short unsigned 16-bit integer type (deprecated) - sal_uInt16 -
long signed 32-bit integer type int sal_Int32 Long
unsigned long unsigned 32-bit integer type (deprecated) - sal_uInt32 -
hyper signed 64-bit integer type long sal_Int64 -
unsigned hyper unsigned 64-bit integer type (deprecated) - sal_uInt64 -
float IEC 60559 single precision floating point type float float (if appropriate) Single
double IEC 60559 double precision floating point type double double (if appropriate) Double
char 16-bit Unicode character type (more precisely: UTF-16 code units)- char sal_Unicode -

There are special conditions for types that do not have an exact mapping in this table. Check for details about these types in the corresponding sections about type mappings in UNO Language Bindings.

Strings

UNO considers strings to be simple types, but since they need special treatment in some environments, we discuss them separately here.

UNO Description Java C++ Basic
string Unicode string type (more precisely: strings of Unicode scalar values) java.lang.­String rtl::OUString String

In Java, use UNO strings as if they were native java.lang.String objects. In C++, native char strings must be converted to UNO Unicode strings by means of SAL conversion functions, usually the function createFromAscii() in the rtl::OUString class:

  //C++
  static OUString createFromAscii( const sal_Char * value ) throw();

In Basic, Basic strings are mapped to UNO strings transparently.

Enum Types and Groups of Constants

The Apache OpenOffice API uses many enumeration types (called enums) and groups of constants (called constant groups). Enums are used to list every plausible value in a certain context. The constant groups define possible values for properties, parameters, return values and struct members. For example, there is an enum com.sun.star.table.CellVertJustify that describes the possible values for the vertical adjustment of table cell content. The vertical adjustment of table cells is determined by their property VertJustify. The possible values for this property are, according to CellVertJustify, the values STANDARD, TOP, CENTER and BOTTOM.

  // adjust a cell content to the upper cell border
  // The service com.sun.star.table.Cell includes the service com.sun.star.table.CellProperties
  // and therefore has a property VertJustify that controls the vertical cell adjustment
  // we have to use the XPropertySet interface of our Cell to set it
 
  xCellProps.setPropertyValue("VertJustify", com.sun.star.table.CellVertJustify.TOP);

Apache OpenOffice Basic understands enumeration types and constant groups. Their usage is straightforward:

  'OpenOffice Basic
  oCellProps.VertJustify = com.sun.star.table.CellVertJustify.TOP

In C++ enums and constant groups are used with the scope operator ::

  //C++
  rCellProps->setPropertyValue(OUString::createFromAscii( "VertJustify"),
          ::com::sun::star::table::CellVertJustify.TOP);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages