1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"InsertColouredText" script:
language=
"StarBasic">' ***
21 ' InsertColouredText basic script
22 ' Uses a user interface to insert text of a specified colour to the
23 ' start and end of a document
25 ' author Neil Montgomery
26 ' created August
12,
2002
30 ' Main subprocedure to start script
36 ' Global reference to the dialog object
40 ' Uses the loadDialog subprocedure to load and execute the dialog box
42 oDialog = loadDialog(
"Standard
",
"InsertColouredTextDialog
")
48 ' Loads the dialog from the dialog library
50 ' param Libname the library name where dialog is stored
51 ' param DialogName the name of the dialog
52 ' param oLibContainer library container to hold the loaded dialog library (optional)
53 ' return runtime dialog object
55 Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
57 Dim oLibDialog as Object
58 Dim oRuntimeDialog as Object
60 ' If the optional oLibContainer is not passed to the function then
61 ' DialogLibraries is loaded by default
62 If isMissing(oLibContainer ) then
63 oLibContainer = DialogLibraries
66 ' Loads the specified library, then loads the dialog
67 oLibContainer.loadLibrary(LibName)
68 oLib = oLibContainer.getByName(Libname)
69 oLibDialog = oLib.getByName(DialogName)
70 oRuntimeDialog = createUnoDialog(oLibDialog)
72 ' Returns the runtime dialog object
73 loadDialog() = oRuntimeDialog
79 ' Gets the RGB integer values and new text string from the dialog
80 ' then writes the new coloured text to the start and end of the document
84 Dim oDocument As Object
88 ' Create a document object for the current document then create text and
90 oDocument = StarDesktop.ActiveFrame.Controller.Model
91 oText = oDocument.Text
92 oCursor = oText.createTextCursor()
94 ' Write the coloured text to the start and end of the document
95 oCursor.gotoStart(false)
96 oCursor.CharColor = getColor()
97 oCursor.setString(
"New text at start:
" + getNewText())
98 oCursor.gotoEnd(false)
99 oCursor.CharColor = getColor()
100 oCursor.setString(
"New text at end:
" + getNewText())
106 ' Reads the RGB integer values from the dialog
108 ' returns long representing the RGB value
110 Function getColor() as Long
111 Dim oRedText as Object
112 Dim oGreenText as Object
113 Dim oBlueText as Object
116 ' Get the three RGB values
117 oRedText = oDialog.GetControl(
"RedTextBox
")
118 oGreenText = oDialog.GetControl(
"GreenTextBox
")
119 oBlueText = oDialog.GetControl(
"BlueTextBox
")
121 ' Convert the values to long type and return the value
122 nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text)
129 ' Reads the new text from the dialog
131 ' returns string the new text
133 Function getNewText() as String
134 Dim oNewText As Object
135 Dim sNewText As String
137 ' Gets the string from dialog and returns the new text
138 oNewText = oDialog.GetControl(
"NewTextBox
")
139 sNewText = oNewText.Text
140 getNewText = sNewText
141 End Function
</script:module>