From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- scripting/examples/basic/InsertColouredText.xba | 141 +++++++++++++++++++++ .../examples/basic/InsertColouredTextDialog.xdl | 34 +++++ scripting/examples/basic/SearchAndReplace.xba | 126 ++++++++++++++++++ .../examples/basic/SearchAndReplaceDialog.xdl | 30 +++++ scripting/examples/basic/dialog.xlb | 6 + scripting/examples/basic/script.xlb | 6 + 6 files changed, 343 insertions(+) create mode 100644 scripting/examples/basic/InsertColouredText.xba create mode 100644 scripting/examples/basic/InsertColouredTextDialog.xdl create mode 100644 scripting/examples/basic/SearchAndReplace.xba create mode 100644 scripting/examples/basic/SearchAndReplaceDialog.xdl create mode 100644 scripting/examples/basic/dialog.xlb create mode 100644 scripting/examples/basic/script.xlb (limited to 'scripting/examples/basic') diff --git a/scripting/examples/basic/InsertColouredText.xba b/scripting/examples/basic/InsertColouredText.xba new file mode 100644 index 000000000..e97b5dfd8 --- /dev/null +++ b/scripting/examples/basic/InsertColouredText.xba @@ -0,0 +1,141 @@ + + + +' *** +' 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 \ No newline at end of file diff --git a/scripting/examples/basic/InsertColouredTextDialog.xdl b/scripting/examples/basic/InsertColouredTextDialog.xdl new file mode 100644 index 000000000..2fa7768bc --- /dev/null +++ b/scripting/examples/basic/InsertColouredTextDialog.xdl @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripting/examples/basic/SearchAndReplace.xba b/scripting/examples/basic/SearchAndReplace.xba new file mode 100644 index 000000000..24c61d8e9 --- /dev/null +++ b/scripting/examples/basic/SearchAndReplace.xba @@ -0,0 +1,126 @@ + + + +' *** +' SearchAndReplace basic script +' Uses a user interface to search and replace the specified strings +' +' 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","SearchAndReplaceDialog") + 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 isMissing(oLibContainer ) then + oLibContainer = DialogLibraries + End If + oLibContainer.loadLibrary(LibName) + oLib = oLibContainer.getByName(Libname) + oLibDialog = oLib.getByName(DialogName) + oRuntimeDialog = createUnoDialog(oLibDialog) + loadDialog() = oRuntimeDialog +End Function + + + +' *** +' Creates a connection to the current document. +' Gets the search and replace keys from the dialog and replaces all +' instances of the search key with the replace key. +' +' *** +Sub getInfoFromDialog + Dim oDocument As Object + Dim oSearch As Object + Dim oFound As Object + Dim oFoundCursor As Object + Dim oSearchText as Object + Dim oReplaceText as Object + + ' Create a document object for the current document then create text and + ' cursor objects + oDocument = StarDesktop.ActiveFrame.Controller.Model + oSearch = oDocument.createSearchDescriptor + + ' Replace all instances of the search string with the replace string + oSearch.SearchString = getSearchKey() + oSearch.ReplaceString = getReplaceKey() + oDocument.replaceAll(oSearch) +End Sub + + +' *** +' Gets the search key string from the dialog +' +' returns string representing the search key +' *** +Function getSearchKey() as String + Dim sSearch As String + + ' Get the search key from the dialog + oSearchText = oDialog.GetControl("SearchKeyTextBox") + sSearch = oSearchText.Text + getSearchKey = sSearch +End Function + + + +' *** +' Gets the replace key string from the dialog +' +' returns string representing the replace key +' *** +Function getReplaceKey() as String + Dim sReplace As String + + ' Get the replace key from the dialog + oReplaceText = oDialog.GetControl("ReplaceKeyTextBox") + sReplace = oReplaceText.Text + getReplaceKey = sReplace +End Function diff --git a/scripting/examples/basic/SearchAndReplaceDialog.xdl b/scripting/examples/basic/SearchAndReplaceDialog.xdl new file mode 100644 index 000000000..9503dbf57 --- /dev/null +++ b/scripting/examples/basic/SearchAndReplaceDialog.xdl @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripting/examples/basic/dialog.xlb b/scripting/examples/basic/dialog.xlb new file mode 100644 index 000000000..95dc3a123 --- /dev/null +++ b/scripting/examples/basic/dialog.xlb @@ -0,0 +1,6 @@ + + + + + + diff --git a/scripting/examples/basic/script.xlb b/scripting/examples/basic/script.xlb new file mode 100644 index 000000000..fa7dd6103 --- /dev/null +++ b/scripting/examples/basic/script.xlb @@ -0,0 +1,6 @@ + + + + + + -- cgit v1.2.3