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
8 ' author Neil Montgomery
9 ' created August
12,
2002
13 ' Main subprocedure to start script
19 ' Global reference to the dialog object
23 ' Uses the loadDialog subprocedure to load and execute the dialog box
25 oDialog = loadDialog(
"Standard
",
"InsertColouredTextDialog
")
31 ' Loads the dialog from the dialog library
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
38 Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
40 Dim oLibDialog as Object
41 Dim oRuntimeDialog as Object
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
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)
55 ' Returns the runtime dialog object
56 loadDialog() = oRuntimeDialog
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
67 Dim oDocument As Object
71 ' Create a document object for the current document then create text and
73 oDocument = StarDesktop.ActiveFrame.Controller.Model
74 oText = oDocument.Text
75 oCursor = oText.createTextCursor()
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())
89 ' Reads the RGB integer values from the dialog
91 ' returns long representing the RGB value
93 Function getColor() as Long
94 Dim oRedText as Object
95 Dim oGreenText as Object
96 Dim oBlueText as Object
99 ' Get the three RGB values
100 oRedText = oDialog.GetControl(
"RedTextBox
")
101 oGreenText = oDialog.GetControl(
"GreenTextBox
")
102 oBlueText = oDialog.GetControl(
"BlueTextBox
")
104 ' Convert the values to long type and return the value
105 nColor = RGB(oRedText.Text,oGreenText.Text,oBlueText.Text)
112 ' Reads the new text from the dialog
114 ' returns string the new text
116 Function getNewText() as String
117 Dim oNewText As Object
118 Dim sNewText As String
120 ' Gets the string from dialog and returns the new text
121 oNewText = oDialog.GetControl(
"NewTextBox
")
122 sNewText = oNewText.Text
123 getNewText = sNewText
124 End Function
</script:module>