1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="InsertColouredText" script:language="StarBasic">&apos; ***
24&apos; InsertColouredText basic script
25&apos; Uses a user interface to insert text of a specified colour to the
26&apos; start and end of a document
27&apos;
28&apos; author	Neil Montgomery
29&apos; created	August 12, 2002
30&apos; ***
31
32
33&apos; Main subprocedure to start script
34Sub Main
35 dialogShow()
36End Sub
37
38
39&apos; Global reference to the dialog object
40Dim oDialog as Object
41
42
43&apos; Uses the loadDialog subprocedure to load and execute the dialog box
44Sub dialogShow
45 oDialog = loadDialog(&quot;Standard&quot;,&quot;InsertColouredTextDialog&quot;)
46 oDialog.execute()
47End Sub
48
49
50&apos; ***
51&apos; Loads the dialog from the dialog library
52&apos;
53&apos; param	Libname 	the library name where dialog is stored
54&apos; param  DialogName	the name of the dialog
55&apos; param 	oLibContainer	library container to hold the loaded dialog library (optional)
56&apos; return	runtime dialog object
57&apos; ***
58Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
59 Dim oLib as Object
60 Dim oLibDialog as Object
61 Dim oRuntimeDialog as Object
62
63 &apos; If the optional oLibContainer is not passed to the function then
64 &apos; DialogLibraries is loaded by default
65 If isMissing(oLibContainer ) then
66  oLibContainer = DialogLibraries
67 End If
68
69 &apos; Loads the specified library, then loads the dialog
70 oLibContainer.loadLibrary(LibName)
71 oLib = oLibContainer.getByName(Libname)
72 oLibDialog = oLib.getByName(DialogName)
73 oRuntimeDialog = createUnoDialog(oLibDialog)
74
75 &apos; Returns the runtime dialog object
76 loadDialog() = oRuntimeDialog
77End Function
78
79
80
81&apos; ***
82&apos; Gets the RGB integer values and new text string from the dialog
83&apos; then writes the new coloured text to the start and end of the document
84&apos;
85&apos; ***
86Sub getFromDialog
87 Dim oDocument As Object
88 Dim oText As Object
89 Dim oCursor As Object
90
91 &apos; Create a document object for the current document then create text and
92 &apos; cursor objects
93 oDocument = StarDesktop.ActiveFrame.Controller.Model
94 oText = oDocument.Text
95 oCursor = oText.createTextCursor()
96
97 &apos; Write the coloured text to the start and end of the document
98 oCursor.gotoStart(false)
99 oCursor.CharColor = getColor()
100 oCursor.setString(&quot;New text at start: &quot; + getNewText())
101 oCursor.gotoEnd(false)
102 oCursor.CharColor = getColor()
103 oCursor.setString(&quot;New text at end: &quot; + getNewText())
104End Sub
105
106
107
108&apos; ***
109&apos; Reads the RGB integer values from the dialog
110&apos;
111&apos; returns   long  representing the RGB value
112&apos; ***
113Function getColor() as Long
114 Dim oRedText as Object
115 Dim oGreenText as Object
116 Dim oBlueText as Object
117 Dim nColor As Long
118
119 &apos; Get the three RGB values
120 oRedText = oDialog.GetControl(&quot;RedTextBox&quot;)
121 oGreenText = oDialog.GetControl(&quot;GreenTextBox&quot;)
122 oBlueText = oDialog.GetControl(&quot;BlueTextBox&quot;)
123
124 &apos; Convert the values to long type and return the value
125 nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text)
126 getColor = nColor
127End Function
128
129
130
131&apos; ***
132&apos; Reads the new text from the dialog
133&apos;
134&apos; returns   string  the new text
135&apos; ***
136Function getNewText() as String
137 Dim oNewText As Object
138 Dim sNewText As String
139
140 &apos; Gets the string from dialog and returns the new text
141 oNewText = oDialog.GetControl(&quot;NewTextBox&quot;)
142 sNewText = oNewText.Text
143 getNewText = sNewText
144End Function</script:module>
145