summaryrefslogtreecommitdiffstats
path: root/scripting/examples/basic/InsertColouredText.xba
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /scripting/examples/basic/InsertColouredText.xba
parentInitial commit. (diff)
downloadlibreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.tar.xz
libreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripting/examples/basic/InsertColouredText.xba')
-rw-r--r--scripting/examples/basic/InsertColouredText.xba141
1 files changed, 141 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