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