1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?> 2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*b1cdbd2cSJim Jagielski<!--*********************************************************** 4*b1cdbd2cSJim Jagielski * 5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 6*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 7*b1cdbd2cSJim Jagielski * distributed with this work for additional information 8*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 11*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 14*b1cdbd2cSJim Jagielski * 15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 20*b1cdbd2cSJim Jagielski * under the License. 21*b1cdbd2cSJim Jagielski * 22*b1cdbd2cSJim Jagielski ***********************************************************--> 23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="InsertColouredText" script:language="StarBasic">' *** 24*b1cdbd2cSJim Jagielski' InsertColouredText basic script 25*b1cdbd2cSJim Jagielski' Uses a user interface to insert text of a specified colour to the 26*b1cdbd2cSJim Jagielski' start and end of a document 27*b1cdbd2cSJim Jagielski' 28*b1cdbd2cSJim Jagielski' author Neil Montgomery 29*b1cdbd2cSJim Jagielski' created August 12, 2002 30*b1cdbd2cSJim Jagielski' *** 31*b1cdbd2cSJim Jagielski 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski' Main subprocedure to start script 34*b1cdbd2cSJim JagielskiSub Main 35*b1cdbd2cSJim Jagielski dialogShow() 36*b1cdbd2cSJim JagielskiEnd Sub 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski' Global reference to the dialog object 40*b1cdbd2cSJim JagielskiDim oDialog as Object 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski' Uses the loadDialog subprocedure to load and execute the dialog box 44*b1cdbd2cSJim JagielskiSub dialogShow 45*b1cdbd2cSJim Jagielski oDialog = loadDialog("Standard","InsertColouredTextDialog") 46*b1cdbd2cSJim Jagielski oDialog.execute() 47*b1cdbd2cSJim JagielskiEnd Sub 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski 50*b1cdbd2cSJim Jagielski' *** 51*b1cdbd2cSJim Jagielski' Loads the dialog from the dialog library 52*b1cdbd2cSJim Jagielski' 53*b1cdbd2cSJim Jagielski' param Libname the library name where dialog is stored 54*b1cdbd2cSJim Jagielski' param DialogName the name of the dialog 55*b1cdbd2cSJim Jagielski' param oLibContainer library container to hold the loaded dialog library (optional) 56*b1cdbd2cSJim Jagielski' return runtime dialog object 57*b1cdbd2cSJim Jagielski' *** 58*b1cdbd2cSJim JagielskiFunction loadDialog(Libname as String, DialogName as String, Optional oLibContainer) 59*b1cdbd2cSJim Jagielski Dim oLib as Object 60*b1cdbd2cSJim Jagielski Dim oLibDialog as Object 61*b1cdbd2cSJim Jagielski Dim oRuntimeDialog as Object 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski ' If the optional oLibContainer is not passed to the function then 64*b1cdbd2cSJim Jagielski ' DialogLibraries is loaded by default 65*b1cdbd2cSJim Jagielski If isMissing(oLibContainer ) then 66*b1cdbd2cSJim Jagielski oLibContainer = DialogLibraries 67*b1cdbd2cSJim Jagielski End If 68*b1cdbd2cSJim Jagielski 69*b1cdbd2cSJim Jagielski ' Loads the specified library, then loads the dialog 70*b1cdbd2cSJim Jagielski oLibContainer.loadLibrary(LibName) 71*b1cdbd2cSJim Jagielski oLib = oLibContainer.getByName(Libname) 72*b1cdbd2cSJim Jagielski oLibDialog = oLib.getByName(DialogName) 73*b1cdbd2cSJim Jagielski oRuntimeDialog = createUnoDialog(oLibDialog) 74*b1cdbd2cSJim Jagielski 75*b1cdbd2cSJim Jagielski ' Returns the runtime dialog object 76*b1cdbd2cSJim Jagielski loadDialog() = oRuntimeDialog 77*b1cdbd2cSJim JagielskiEnd Function 78*b1cdbd2cSJim Jagielski 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim Jagielski 81*b1cdbd2cSJim Jagielski' *** 82*b1cdbd2cSJim Jagielski' Gets the RGB integer values and new text string from the dialog 83*b1cdbd2cSJim Jagielski' then writes the new coloured text to the start and end of the document 84*b1cdbd2cSJim Jagielski' 85*b1cdbd2cSJim Jagielski' *** 86*b1cdbd2cSJim JagielskiSub getFromDialog 87*b1cdbd2cSJim Jagielski Dim oDocument As Object 88*b1cdbd2cSJim Jagielski Dim oText As Object 89*b1cdbd2cSJim Jagielski Dim oCursor As Object 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski ' Create a document object for the current document then create text and 92*b1cdbd2cSJim Jagielski ' cursor objects 93*b1cdbd2cSJim Jagielski oDocument = StarDesktop.ActiveFrame.Controller.Model 94*b1cdbd2cSJim Jagielski oText = oDocument.Text 95*b1cdbd2cSJim Jagielski oCursor = oText.createTextCursor() 96*b1cdbd2cSJim Jagielski 97*b1cdbd2cSJim Jagielski ' Write the coloured text to the start and end of the document 98*b1cdbd2cSJim Jagielski oCursor.gotoStart(false) 99*b1cdbd2cSJim Jagielski oCursor.CharColor = getColor() 100*b1cdbd2cSJim Jagielski oCursor.setString("New text at start: " + getNewText()) 101*b1cdbd2cSJim Jagielski oCursor.gotoEnd(false) 102*b1cdbd2cSJim Jagielski oCursor.CharColor = getColor() 103*b1cdbd2cSJim Jagielski oCursor.setString("New text at end: " + getNewText()) 104*b1cdbd2cSJim JagielskiEnd Sub 105*b1cdbd2cSJim Jagielski 106*b1cdbd2cSJim Jagielski 107*b1cdbd2cSJim Jagielski 108*b1cdbd2cSJim Jagielski' *** 109*b1cdbd2cSJim Jagielski' Reads the RGB integer values from the dialog 110*b1cdbd2cSJim Jagielski' 111*b1cdbd2cSJim Jagielski' returns long representing the RGB value 112*b1cdbd2cSJim Jagielski' *** 113*b1cdbd2cSJim JagielskiFunction getColor() as Long 114*b1cdbd2cSJim Jagielski Dim oRedText as Object 115*b1cdbd2cSJim Jagielski Dim oGreenText as Object 116*b1cdbd2cSJim Jagielski Dim oBlueText as Object 117*b1cdbd2cSJim Jagielski Dim nColor As Long 118*b1cdbd2cSJim Jagielski 119*b1cdbd2cSJim Jagielski ' Get the three RGB values 120*b1cdbd2cSJim Jagielski oRedText = oDialog.GetControl("RedTextBox") 121*b1cdbd2cSJim Jagielski oGreenText = oDialog.GetControl("GreenTextBox") 122*b1cdbd2cSJim Jagielski oBlueText = oDialog.GetControl("BlueTextBox") 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski ' Convert the values to long type and return the value 125*b1cdbd2cSJim Jagielski nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text) 126*b1cdbd2cSJim Jagielski getColor = nColor 127*b1cdbd2cSJim JagielskiEnd Function 128*b1cdbd2cSJim Jagielski 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski 131*b1cdbd2cSJim Jagielski' *** 132*b1cdbd2cSJim Jagielski' Reads the new text from the dialog 133*b1cdbd2cSJim Jagielski' 134*b1cdbd2cSJim Jagielski' returns string the new text 135*b1cdbd2cSJim Jagielski' *** 136*b1cdbd2cSJim JagielskiFunction getNewText() as String 137*b1cdbd2cSJim Jagielski Dim oNewText As Object 138*b1cdbd2cSJim Jagielski Dim sNewText As String 139*b1cdbd2cSJim Jagielski 140*b1cdbd2cSJim Jagielski ' Gets the string from dialog and returns the new text 141*b1cdbd2cSJim Jagielski oNewText = oDialog.GetControl("NewTextBox") 142*b1cdbd2cSJim Jagielski sNewText = oNewText.Text 143*b1cdbd2cSJim Jagielski getNewText = sNewText 144*b1cdbd2cSJim JagielskiEnd Function</script:module> 145