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