1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="InsertColouredText" script:language="StarBasic">&apos; ***
4&apos; InsertColouredText basic script
5&apos; Uses a user interface to insert text of a specified colour to the
6&apos; start and end of a document
7&apos;
8&apos; author	Neil Montgomery
9&apos; created	August 12, 2002
10&apos; ***
11
12
13&apos; Main subprocedure to start script
14Sub Main
15 dialogShow()
16End Sub
17
18
19&apos; Global reference to the dialog object
20Dim oDialog as Object
21
22
23&apos; Uses the loadDialog subprocedure to load and execute the dialog box
24Sub dialogShow
25 oDialog = loadDialog(&quot;Standard&quot;,&quot;InsertColouredTextDialog&quot;)
26 oDialog.execute()
27End Sub
28
29
30&apos; ***
31&apos; Loads the dialog from the dialog library
32&apos;
33&apos; param	Libname 	the library name where dialog is stored
34&apos; param  DialogName	the name of the dialog
35&apos; param 	oLibContainer	library container to hold the loaded dialog library (optional)
36&apos; return	runtime dialog object
37&apos; ***
38Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
39 Dim oLib as Object
40 Dim oLibDialog as Object
41 Dim oRuntimeDialog as Object
42
43 &apos; If the optional oLibContainer is not passed to the function then
44 &apos; DialogLibraries is loaded by default
45 If isMissing(oLibContainer ) then
46  oLibContainer = DialogLibraries
47 End If
48
49 &apos; Loads the specified library, then loads the dialog
50 oLibContainer.loadLibrary(LibName)
51 oLib = oLibContainer.getByName(Libname)
52 oLibDialog = oLib.getByName(DialogName)
53 oRuntimeDialog = createUnoDialog(oLibDialog)
54
55 &apos; Returns the runtime dialog object
56 loadDialog() = oRuntimeDialog
57End Function
58
59
60
61&apos; ***
62&apos; Gets the RGB integer values and new text string from the dialog
63&apos; then writes the new coloured text to the start and end of the document
64&apos;
65&apos; ***
66Sub getFromDialog
67 Dim oDocument As Object
68 Dim oText As Object
69 Dim oCursor As Object
70
71 &apos; Create a document object for the current document then create text and
72 &apos; cursor objects
73 oDocument = StarDesktop.ActiveFrame.Controller.Model
74 oText = oDocument.Text
75 oCursor = oText.createTextCursor()
76
77 &apos; Write the coloured text to the start and end of the document
78 oCursor.gotoStart(false)
79 oCursor.CharColor = getColor()
80 oCursor.setString(&quot;New text at start: &quot; + getNewText())
81 oCursor.gotoEnd(false)
82 oCursor.CharColor = getColor()
83 oCursor.setString(&quot;New text at end: &quot; + getNewText())
84End Sub
85
86
87
88&apos; ***
89&apos; Reads the RGB integer values from the dialog
90&apos;
91&apos; returns   long  representing the RGB value
92&apos; ***
93Function getColor() as Long
94 Dim oRedText as Object
95 Dim oGreenText as Object
96 Dim oBlueText as Object
97 Dim nColor As Long
98
99 &apos; Get the three RGB values
100 oRedText = oDialog.GetControl(&quot;RedTextBox&quot;)
101 oGreenText = oDialog.GetControl(&quot;GreenTextBox&quot;)
102 oBlueText = oDialog.GetControl(&quot;BlueTextBox&quot;)
103
104 &apos; Convert the values to long type and return the value
105 nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text)
106 getColor = nColor
107End Function
108
109
110
111&apos; ***
112&apos; Reads the new text from the dialog
113&apos;
114&apos; returns   string  the new text
115&apos; ***
116Function getNewText() as String
117 Dim oNewText As Object
118 Dim sNewText As String
119
120 &apos; Gets the string from dialog and returns the new text
121 oNewText = oDialog.GetControl(&quot;NewTextBox&quot;)
122 sNewText = oNewText.Text
123 getNewText = sNewText
124End Function</script:module>