| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> | |
| <!--*********************************************************** | |
| * | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| * | |
| ***********************************************************--> | |
| <script:module xmlns:script="http://openoffice.org/2000/script" script:name="InsertColouredText" script:language="StarBasic">' *** | |
| ' InsertColouredText basic script | |
| ' Uses a user interface to insert text of a specified colour to the | |
| ' start and end of a document | |
| ' | |
| ' author Neil Montgomery | |
| ' created August 12, 2002 | |
| ' *** | |
| ' Main subprocedure to start script | |
| Sub Main | |
| dialogShow() | |
| End Sub | |
| ' Global reference to the dialog object | |
| Dim oDialog as Object | |
| ' Uses the loadDialog subprocedure to load and execute the dialog box | |
| Sub dialogShow | |
| oDialog = loadDialog("Standard","InsertColouredTextDialog") | |
| oDialog.execute() | |
| End Sub | |
| ' *** | |
| ' Loads the dialog from the dialog library | |
| ' | |
| ' param Libname the library name where dialog is stored | |
| ' param DialogName the name of the dialog | |
| ' param oLibContainer library container to hold the loaded dialog library (optional) | |
| ' return runtime dialog object | |
| ' *** | |
| Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer) | |
| Dim oLib as Object | |
| Dim oLibDialog as Object | |
| Dim oRuntimeDialog as Object | |
| ' If the optional oLibContainer is not passed to the function then | |
| ' DialogLibraries is loaded by default | |
| If isMissing(oLibContainer ) then | |
| oLibContainer = DialogLibraries | |
| End If | |
| ' Loads the specified library, then loads the dialog | |
| oLibContainer.loadLibrary(LibName) | |
| oLib = oLibContainer.getByName(Libname) | |
| oLibDialog = oLib.getByName(DialogName) | |
| oRuntimeDialog = createUnoDialog(oLibDialog) | |
| ' Returns the runtime dialog object | |
| loadDialog() = oRuntimeDialog | |
| End Function | |
| ' *** | |
| ' Gets the RGB integer values and new text string from the dialog | |
| ' then writes the new coloured text to the start and end of the document | |
| ' | |
| ' *** | |
| Sub getFromDialog | |
| Dim oDocument As Object | |
| Dim oText As Object | |
| Dim oCursor As Object | |
| ' Create a document object for the current document then create text and | |
| ' cursor objects | |
| oDocument = StarDesktop.ActiveFrame.Controller.Model | |
| oText = oDocument.Text | |
| oCursor = oText.createTextCursor() | |
| ' Write the coloured text to the start and end of the document | |
| oCursor.gotoStart(false) | |
| oCursor.CharColor = getColor() | |
| oCursor.setString("New text at start: " + getNewText()) | |
| oCursor.gotoEnd(false) | |
| oCursor.CharColor = getColor() | |
| oCursor.setString("New text at end: " + getNewText()) | |
| End Sub | |
| ' *** | |
| ' Reads the RGB integer values from the dialog | |
| ' | |
| ' returns long representing the RGB value | |
| ' *** | |
| Function getColor() as Long | |
| Dim oRedText as Object | |
| Dim oGreenText as Object | |
| Dim oBlueText as Object | |
| Dim nColor As Long | |
| ' Get the three RGB values | |
| oRedText = oDialog.GetControl("RedTextBox") | |
| oGreenText = oDialog.GetControl("GreenTextBox") | |
| oBlueText = oDialog.GetControl("BlueTextBox") | |
| ' Convert the values to long type and return the value | |
| nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text) | |
| getColor = nColor | |
| End Function | |
| ' *** | |
| ' Reads the new text from the dialog | |
| ' | |
| ' returns string the new text | |
| ' *** | |
| Function getNewText() as String | |
| Dim oNewText As Object | |
| Dim sNewText As String | |
| ' Gets the string from dialog and returns the new text | |
| oNewText = oDialog.GetControl("NewTextBox") | |
| sNewText = oNewText.Text | |
| getNewText = sNewText | |
| End Function</script:module> |