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