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">' *** 24' InsertColouredText basic script 25' Uses a user interface to insert text of a specified colour to the 26' start and end of a document 27' 28' author Neil Montgomery 29' created August 12, 2002 30' *** 31 32 33' Main subprocedure to start script 34Sub Main 35 dialogShow() 36End Sub 37 38 39' Global reference to the dialog object 40Dim oDialog as Object 41 42 43' Uses the loadDialog subprocedure to load and execute the dialog box 44Sub dialogShow 45 oDialog = loadDialog("Standard","InsertColouredTextDialog") 46 oDialog.execute() 47End Sub 48 49 50' *** 51' Loads the dialog from the dialog library 52' 53' param Libname the library name where dialog is stored 54' param DialogName the name of the dialog 55' param oLibContainer library container to hold the loaded dialog library (optional) 56' return runtime dialog object 57' *** 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 ' If the optional oLibContainer is not passed to the function then 64 ' DialogLibraries is loaded by default 65 If isMissing(oLibContainer ) then 66 oLibContainer = DialogLibraries 67 End If 68 69 ' 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 ' Returns the runtime dialog object 76 loadDialog() = oRuntimeDialog 77End Function 78 79 80 81' *** 82' Gets the RGB integer values and new text string from the dialog 83' then writes the new coloured text to the start and end of the document 84' 85' *** 86Sub getFromDialog 87 Dim oDocument As Object 88 Dim oText As Object 89 Dim oCursor As Object 90 91 ' Create a document object for the current document then create text and 92 ' cursor objects 93 oDocument = StarDesktop.ActiveFrame.Controller.Model 94 oText = oDocument.Text 95 oCursor = oText.createTextCursor() 96 97 ' Write the coloured text to the start and end of the document 98 oCursor.gotoStart(false) 99 oCursor.CharColor = getColor() 100 oCursor.setString("New text at start: " + getNewText()) 101 oCursor.gotoEnd(false) 102 oCursor.CharColor = getColor() 103 oCursor.setString("New text at end: " + getNewText()) 104End Sub 105 106 107 108' *** 109' Reads the RGB integer values from the dialog 110' 111' returns long representing the RGB value 112' *** 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 ' Get the three RGB values 120 oRedText = oDialog.GetControl("RedTextBox") 121 oGreenText = oDialog.GetControl("GreenTextBox") 122 oBlueText = oDialog.GetControl("BlueTextBox") 123 124 ' 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' *** 132' Reads the new text from the dialog 133' 134' returns string the new text 135' *** 136Function getNewText() as String 137 Dim oNewText As Object 138 Dim sNewText As String 139 140 ' Gets the string from dialog and returns the new text 141 oNewText = oDialog.GetControl("NewTextBox") 142 sNewText = oNewText.Text 143 getNewText = sNewText 144End Function</script:module> 145