summaryrefslogtreecommitdiffstats
path: root/scripting/examples/basic
diff options
context:
space:
mode:
Diffstat (limited to 'scripting/examples/basic')
-rw-r--r--scripting/examples/basic/InsertColouredText.xba141
-rw-r--r--scripting/examples/basic/InsertColouredTextDialog.xdl34
-rw-r--r--scripting/examples/basic/SearchAndReplace.xba126
-rw-r--r--scripting/examples/basic/SearchAndReplaceDialog.xdl30
-rw-r--r--scripting/examples/basic/dialog.xlb6
-rw-r--r--scripting/examples/basic/script.xlb6
6 files changed, 343 insertions, 0 deletions
diff --git a/scripting/examples/basic/InsertColouredText.xba b/scripting/examples/basic/InsertColouredText.xba
new file mode 100644
index 000000000..e97b5dfd8
--- /dev/null
+++ b/scripting/examples/basic/InsertColouredText.xba
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<script:module xmlns:script="http://openoffice.org/2000/script" script:name="InsertColouredText" script:language="StarBasic">&apos; ***
+&apos; InsertColouredText basic script
+&apos; Uses a user interface to insert text of a specified colour to the
+&apos; start and end of a document
+&apos;
+&apos; author Neil Montgomery
+&apos; created August 12, 2002
+&apos; ***
+
+
+&apos; Main subprocedure to start script
+Sub Main
+ dialogShow()
+End Sub
+
+
+&apos; Global reference to the dialog object
+Dim oDialog as Object
+
+
+&apos; Uses the loadDialog subprocedure to load and execute the dialog box
+Sub dialogShow
+ oDialog = loadDialog(&quot;Standard&quot;,&quot;InsertColouredTextDialog&quot;)
+ oDialog.execute()
+End Sub
+
+
+&apos; ***
+&apos; Loads the dialog from the dialog library
+&apos;
+&apos; param Libname the library name where dialog is stored
+&apos; param DialogName the name of the dialog
+&apos; param oLibContainer library container to hold the loaded dialog library (optional)
+&apos; return runtime dialog object
+&apos; ***
+Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
+ Dim oLib as Object
+ Dim oLibDialog as Object
+ Dim oRuntimeDialog as Object
+
+ &apos; If the optional oLibContainer is not passed to the function then
+ &apos; DialogLibraries is loaded by default
+ If isMissing(oLibContainer ) then
+ oLibContainer = DialogLibraries
+ End If
+
+ &apos; Loads the specified library, then loads the dialog
+ oLibContainer.loadLibrary(LibName)
+ oLib = oLibContainer.getByName(Libname)
+ oLibDialog = oLib.getByName(DialogName)
+ oRuntimeDialog = createUnoDialog(oLibDialog)
+
+ &apos; Returns the runtime dialog object
+ loadDialog() = oRuntimeDialog
+End Function
+
+
+
+&apos; ***
+&apos; Gets the RGB integer values and new text string from the dialog
+&apos; then writes the new coloured text to the start and end of the document
+&apos;
+&apos; ***
+Sub getFromDialog
+ Dim oDocument As Object
+ Dim oText As Object
+ Dim oCursor As Object
+
+ &apos; Create a document object for the current document then create text and
+ &apos; cursor objects
+ oDocument = StarDesktop.ActiveFrame.Controller.Model
+ oText = oDocument.Text
+ oCursor = oText.createTextCursor()
+
+ &apos; Write the coloured text to the start and end of the document
+ oCursor.gotoStart(false)
+ oCursor.CharColor = getColor()
+ oCursor.setString(&quot;New text at start: &quot; + getNewText())
+ oCursor.gotoEnd(false)
+ oCursor.CharColor = getColor()
+ oCursor.setString(&quot;New text at end: &quot; + getNewText())
+End Sub
+
+
+
+&apos; ***
+&apos; Reads the RGB integer values from the dialog
+&apos;
+&apos; returns long representing the RGB value
+&apos; ***
+Function getColor() as Long
+ Dim oRedText as Object
+ Dim oGreenText as Object
+ Dim oBlueText as Object
+ Dim nColor As Long
+
+ &apos; Get the three RGB values
+ oRedText = oDialog.GetControl(&quot;RedTextBox&quot;)
+ oGreenText = oDialog.GetControl(&quot;GreenTextBox&quot;)
+ oBlueText = oDialog.GetControl(&quot;BlueTextBox&quot;)
+
+ &apos; Convert the values to long type and return the value
+ nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text)
+ getColor = nColor
+End Function
+
+
+
+&apos; ***
+&apos; Reads the new text from the dialog
+&apos;
+&apos; returns string the new text
+&apos; ***
+Function getNewText() as String
+ Dim oNewText As Object
+ Dim sNewText As String
+
+ &apos; Gets the string from dialog and returns the new text
+ oNewText = oDialog.GetControl(&quot;NewTextBox&quot;)
+ sNewText = oNewText.Text
+ getNewText = sNewText
+End Function</script:module> \ No newline at end of file
diff --git a/scripting/examples/basic/InsertColouredTextDialog.xdl b/scripting/examples/basic/InsertColouredTextDialog.xdl
new file mode 100644
index 000000000..2fa7768bc
--- /dev/null
+++ b/scripting/examples/basic/InsertColouredTextDialog.xdl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="InsertColouredTextDialog" dlg:left="113" dlg:top="112" dlg:width="178" dlg:height="138" dlg:closeable="true" dlg:moveable="true">
+ <dlg:bulletinboard>
+ <dlg:textfield dlg:id="RedTextBox" dlg:tab-index="0" dlg:left="37" dlg:top="26" dlg:width="20" dlg:height="17"/>
+ <dlg:textfield dlg:id="GreenTextBox" dlg:tab-index="1" dlg:left="73" dlg:top="26" dlg:width="20" dlg:height="17"/>
+ <dlg:textfield dlg:id="BlueTextBox" dlg:tab-index="2" dlg:left="109" dlg:top="26" dlg:width="20" dlg:height="17"/>
+ <dlg:textfield dlg:id="NewTextBox" dlg:tab-index="3" dlg:left="57" dlg:top="67" dlg:width="57" dlg:height="15"/>
+ <dlg:button dlg:id="CommandButton1" dlg:tab-index="4" dlg:left="49" dlg:top="97" dlg:width="75" dlg:height="15" dlg:value="Insert New Coloured Text">
+ <script:event script:event-name="on-mousedown" script:location="application" script:macro-name="Standard.InsertColouredText.getFromDialog" script:language="StarBasic"/>
+ </dlg:button>
+ <dlg:text dlg:id="Label1" dlg:tab-index="5" dlg:left="44" dlg:top="12" dlg:width="7" dlg:height="10" dlg:value="R"/>
+ <dlg:text dlg:id="Label2" dlg:tab-index="6" dlg:left="78" dlg:top="12" dlg:width="7" dlg:height="10" dlg:value="G"/>
+ <dlg:text dlg:id="Label3" dlg:tab-index="7" dlg:left="114" dlg:top="12" dlg:width="7" dlg:height="10" dlg:value="B"/>
+ <dlg:text dlg:id="Label4" dlg:tab-index="8" dlg:left="71" dlg:top="56" dlg:width="26" dlg:height="8" dlg:value="New Text"/>
+ </dlg:bulletinboard>
+</dlg:window> \ No newline at end of file
diff --git a/scripting/examples/basic/SearchAndReplace.xba b/scripting/examples/basic/SearchAndReplace.xba
new file mode 100644
index 000000000..24c61d8e9
--- /dev/null
+++ b/scripting/examples/basic/SearchAndReplace.xba
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SearchAndReplace" script:language="StarBasic">&apos; ***
+&apos; SearchAndReplace basic script
+&apos; Uses a user interface to search and replace the specified strings
+&apos;
+&apos; author Neil Montgomery
+&apos; created August 12, 2002
+&apos; ***
+
+
+&apos; Main subprocedure to start script
+Sub Main
+ dialogShow()
+End Sub
+
+
+&apos; Global reference to the dialog object
+Dim oDialog as Object
+
+
+&apos; Uses the loadDialog subprocedure to load and execute the dialog box
+Sub dialogShow
+ oDialog = loadDialog(&quot;Standard&quot;,&quot;SearchAndReplaceDialog&quot;)
+ oDialog.execute()
+End Sub
+
+
+
+&apos; ***
+&apos; Loads the dialog from the dialog library
+&apos;
+&apos; param Libname the library name where dialog is stored
+&apos; param DialogName the name of the dialog
+&apos; param oLibContainer library container to hold the loaded dialog library (optional)
+&apos; return runtime dialog object
+&apos; ***
+Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
+ Dim oLib as Object
+ Dim oLibDialog as Object
+ Dim oRuntimeDialog as Object
+
+ If isMissing(oLibContainer ) then
+ oLibContainer = DialogLibraries
+ End If
+ oLibContainer.loadLibrary(LibName)
+ oLib = oLibContainer.getByName(Libname)
+ oLibDialog = oLib.getByName(DialogName)
+ oRuntimeDialog = createUnoDialog(oLibDialog)
+ loadDialog() = oRuntimeDialog
+End Function
+
+
+
+&apos; ***
+&apos; Creates a connection to the current document.
+&apos; Gets the search and replace keys from the dialog and replaces all
+&apos; instances of the search key with the replace key.
+&apos;
+&apos; ***
+Sub getInfoFromDialog
+ Dim oDocument As Object
+ Dim oSearch As Object
+ Dim oFound As Object
+ Dim oFoundCursor As Object
+ Dim oSearchText as Object
+ Dim oReplaceText as Object
+
+ &apos; Create a document object for the current document then create text and
+ &apos; cursor objects
+ oDocument = StarDesktop.ActiveFrame.Controller.Model
+ oSearch = oDocument.createSearchDescriptor
+
+ &apos; Replace all instances of the search string with the replace string
+ oSearch.SearchString = getSearchKey()
+ oSearch.ReplaceString = getReplaceKey()
+ oDocument.replaceAll(oSearch)
+End Sub
+
+
+&apos; ***
+&apos; Gets the search key string from the dialog
+&apos;
+&apos; returns string representing the search key
+&apos; ***
+Function getSearchKey() as String
+ Dim sSearch As String
+
+ &apos; Get the search key from the dialog
+ oSearchText = oDialog.GetControl(&quot;SearchKeyTextBox&quot;)
+ sSearch = oSearchText.Text
+ getSearchKey = sSearch
+End Function
+
+
+
+&apos; ***
+&apos; Gets the replace key string from the dialog
+&apos;
+&apos; returns string representing the replace key
+&apos; ***
+Function getReplaceKey() as String
+ Dim sReplace As String
+
+ &apos; Get the replace key from the dialog
+ oReplaceText = oDialog.GetControl(&quot;ReplaceKeyTextBox&quot;)
+ sReplace = oReplaceText.Text
+ getReplaceKey = sReplace
+End Function</script:module>
diff --git a/scripting/examples/basic/SearchAndReplaceDialog.xdl b/scripting/examples/basic/SearchAndReplaceDialog.xdl
new file mode 100644
index 000000000..9503dbf57
--- /dev/null
+++ b/scripting/examples/basic/SearchAndReplaceDialog.xdl
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="SearchAndReplaceDialog" dlg:left="113" dlg:top="112" dlg:width="178" dlg:height="138" dlg:closeable="true" dlg:moveable="true">
+ <dlg:bulletinboard>
+ <dlg:textfield dlg:id="SearchKeyTextBox" dlg:tab-index="0" dlg:left="28" dlg:top="31" dlg:width="53" dlg:height="13"/>
+ <dlg:textfield dlg:id="ReplaceKeyTextBox" dlg:tab-index="1" dlg:left="102" dlg:top="31" dlg:width="51" dlg:height="13"/>
+ <dlg:button dlg:id="CommandButton1" dlg:tab-index="2" dlg:left="59" dlg:top="79" dlg:width="62" dlg:height="13" dlg:value="Search And Replace">
+ <script:event script:event-name="on-mousedown" script:location="application" script:macro-name="Standard.SearchAndReplace.getInfoFromDialog" script:language="StarBasic"/>
+ </dlg:button>
+ <dlg:text dlg:id="Label1" dlg:tab-index="3" dlg:left="37" dlg:top="20" dlg:width="33" dlg:height="8" dlg:value="Search Key"/>
+ <dlg:text dlg:id="Label2" dlg:tab-index="4" dlg:left="109" dlg:top="20" dlg:width="35" dlg:height="8" dlg:value="Replace Key"/>
+ </dlg:bulletinboard>
+</dlg:window> \ No newline at end of file
diff --git a/scripting/examples/basic/dialog.xlb b/scripting/examples/basic/dialog.xlb
new file mode 100644
index 000000000..95dc3a123
--- /dev/null
+++ b/scripting/examples/basic/dialog.xlb
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="Standard" library:readonly="false" library:passwordprotected="false">
+ <library:element library:name="InsertColouredTextDialog"/>
+ <library:element library:name="SearchAndReplaceDialog"/>
+</library:library>
diff --git a/scripting/examples/basic/script.xlb b/scripting/examples/basic/script.xlb
new file mode 100644
index 000000000..fa7dd6103
--- /dev/null
+++ b/scripting/examples/basic/script.xlb
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="Standard" library:readonly="false" library:passwordprotected="false">
+ <library:element library:name="InsertColouredText"/>
+ <library:element library:name="SearchAndReplace"/>
+</library:library>