blob: 9decaeb5104791f5bc2e63d2e5ec843e3aa6c202 [file] [log] [blame]
<?xml version="1.0"?>
<!--
$RCSfile: Writer.InsertAnAnnotationField.snip,v $
last change: $Revision: 1.1 $ $Author: tomsontom $ $Date: 2008/10/20 11:29:28 $
(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.
Public Documentation License Notice:
The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html
The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.
The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.
The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.
All Rights Reserved.
-->
<snippet language="ooRexx" application="Writer">
<keywords>
<keyword>insert</keyword>
<keyword>note</keyword>
<keyword>field</keyword>
<keyword>annotation</keyword>
</keywords>
<authors>
<author id="1" initial="true" email="" copyright="Josef Frysak">Josef Frysak</author>
</authors>
<question heading="Insert an annotation field">How to insert a Note Field?
</question>
<answer>
<p>With the documents &quot;XMultiServiceFactory&quot; interface create a new</p>
<p>&quot;TextField.Annotation&quot; object. Set the author and as well as the content</p>
<p>of the note field by accessing and changing the objects properties. Next</p>
<p>create a &quot;Date&quot; structure and enter the date of creation. Apply the</p>
<p>&quot;Date&quot; structure as &quot;date&quot; property to the note object too. Finally add</p>
<p>the note object to the document, by using the &quot;insertTextContent&quot;</p>
<p>function.</p>
<p>For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf.</p>
<listing>-- try to get a script context, will be .nil, if script was not invoked by OOo
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext &lt;&gt; .nil) then
do
-- invoked by OOo as a macro
-- get context
x_ComponentContext = x_ScriptContext~getComponentContext
-- get desktop (an XDesktop)
x_Desktop = x_ScriptContext~getDesktop
-- get current document
x_Document = x_ScriptContext~getDocument
end
else
do
-- called from outside of OOo, create a connection
-- connect to Open Office and get component context
x_ComponentContext = UNO.connect()
-- create a desktop service and its interface
service = &quot;{%see com.sun.star.frame.Desktop}&quot;
s_Desktop = x_ComponentContext~getServiceManager~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}~createInstance(service)
x_Desktop = s_Desktop~{%see com.sun.star.frame.XDesktop%XDesktop}
-- get the last active document
x_Document = x_Desktop~getCurrentComponent()
end
-- get the text of the current document
x_TextDocument = x_Document~{%see com.sun.star.text.XTextDocument%XTextDocument}
x_Text = x_TextDocument~getText
-- get the current cursor position
s_CurrentController = x_TextDocument~getCurrentController()
x_TextViewCursorSupplier = s_CurrentController~{%see com.sun.star.text.XTextViewCursorSupplier%XTextViewCursorSupplier}
x_CurrentCursor = x_TextViewCursorSupplier~getViewCursor()
-- get current text cursor
x_TextCursor = x_Text~createTextCursorByRange(x_CurrentCursor~getStart())
-- create a factory to create a note object
x_MultiServiceFactory = x_Document~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
s_Annotation = x_MultiServiceFactory~createInstance(&quot;{%see com.sun.star.text.TextField.Annotation}&quot;)
-- get access to the note object properties and fill them
x_AnnotationProperties = s_Annotation~{%see com.sun.star.beans.XPropertySet%XPropertySet}
x_AnnotationProperties~setPropertyValue(&quot;Author&quot;, &quot;JF&quot;)
x_AnnotationProperties~setPropertyValue(&quot;Content&quot;, &quot;Thats right, Mr. Pitonyak&quot;)
-- get current date from rexx and parse, year month and day
currentdate = DATE(&quot;S&quot;,,,&quot;/&quot;)
PARSE VAR currentdate year &quot;/&quot; month &quot;/&quot; day
-- create date object and set its date properties, then add the date object
-- to the note object
date = .bsf~new(&quot;{%see com.sun.star.util.Date}&quot;)
date~bsf.setFieldValue(&quot;Day&quot;, day)
date~bsf.setFieldValue(&quot;Month&quot;, month)
date~bsf.setFieldValue(&quot;Year&quot;, year)
x_AnnotationProperties~setPropertyValue(&quot;Date&quot;, date)
-- finally insert the note object into the text
x_TextContent = s_Annotation~{%see com.sun.star.text.XTextContent%XTextContent}
x_Text~insertTextContent(x_TextCursor, x_TextContent, .true)
::requires UNO.CLS</listing>
</answer>
<versions>
<version number="2.4.1" status="tested"/>
</versions>
<operating-systems>
<operating-system name="All"/>
</operating-systems>
<changelog>
<change author-id="1" date="2008-10-14">Initial version</change>
</changelog>
</snippet>