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