wizards/Package_sfdocuments.mk | 1 wizards/source/scriptforge/SF_Exception.xba | 15 wizards/source/scriptforge/SF_PythonHelper.xba | 1 wizards/source/scriptforge/SF_Root.xba | 28 wizards/source/scriptforge/SF_String.xba | 2 wizards/source/scriptforge/SF_Utils.xba | 5 wizards/source/scriptforge/po/ScriptForge.pot | 37 + wizards/source/scriptforge/po/en.po | 37 + wizards/source/scriptforge/python/scriptforge.py | 31 wizards/source/sfdocuments/SF_Calc.xba | 175 ++++ wizards/source/sfdocuments/SF_Chart.xba | 815 +++++++++++++++++++++++ wizards/source/sfdocuments/SF_FormControl.xba | 3 wizards/source/sfdocuments/script.xlb | 1 13 files changed, 1145 insertions(+), 6 deletions(-)
New commits: commit ef08207a290c0dc537c698ec3389779a27085c04 Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Sun Aug 1 17:36:03 2021 +0200 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Mon Aug 2 10:45:37 2021 +0200 ScriptForge - (SF_Chart) new service to manage Calc charts New methods in the SF_Calc service: Charts(), to list charts or to instantiate a chart service CreateChart, to create a new chart in a given Calc sheet The SF_Chart service has next properties to parameter the type and the characteristics of the (new or pre-existing) chart ChartType, Deep, Dim3d, Exploded, Filled, Legend, Percent, Stacked, Title, XTitle, YTitle Next methods are available: Resize, to move and resize the chart shape ExportToFile, to export the chart as a graphical object Supported: gif, jpeg, png, svg and tiff New error messages in SF_Root and SF_Exception. Corresponding labels are integrated in the POT file Full support under Basic and Python Review of make file of the SFDocuments library Change-Id: Id8db3098ff24fbf2efcbdd9c6dcd4f02ff5972af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119824 Tested-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> diff --git a/wizards/Package_sfdocuments.mk b/wizards/Package_sfdocuments.mk index 39211afa88cf..bec0d11f5a9a 100644 --- a/wizards/Package_sfdocuments.mk +++ b/wizards/Package_sfdocuments.mk @@ -22,6 +22,7 @@ $(eval $(call gb_Package_Package,wizards_basicsrvsfdocuments,$(SRCDIR)/wizards/s $(eval $(call gb_Package_add_files,wizards_basicsrvsfdocuments,$(LIBO_SHARE_FOLDER)/basic/SFDocuments,\ SF_Base.xba \ SF_Calc.xba \ + SF_Chart.xba \ SF_Document.xba \ SF_Form.xba \ SF_FormControl.xba \ diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba index aa654de67463..57ac5090d6a9 100644 --- a/wizards/source/scriptforge/SF_Exception.xba +++ b/wizards/source/scriptforge/SF_Exception.xba @@ -106,6 +106,10 @@ Const DBCONNECTERROR = "DBCONNECTERROR" Const CALCADDRESSERROR = "CALCADDRESSERROR" Const DUPLICATESHEETERROR = "DUPLICATESHEETERROR" Const OFFSETADDRESSERROR = "OFFSETADDRESSERROR" +Const DUPLICATECHARTERROR = "DUPLICATECHARTERROR" + +' SF_Chart +Const CHARTEXPORTERROR = "CHARTEXPORTERROR" ' SF_Form Const FORMDEADERROR = "FORMDEADERROR" @@ -950,7 +954,7 @@ Try: & "\n" & "\n" & "\n" & .GetText("VALIDATEERROR", pvArgs(0)) _ & "\n" & "\n" & .GetText("CALCADDRESS" & Iif(pvArgs(0) = "Sheet", "1", "2"), pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) Case DUPLICATESHEETERROR ' SF_Calc.InsertSheet(arg, SheetName, Document) - pvArgs(0) = _RightCase(pvArgs(2)) : pvArgs(0) = _RightCase(pvArgs(2)) + pvArgs(0) = _RightCase(pvArgs(0)) sMessage = sLocation _ & "\n" & "\n" & "\n" & .GetText("VALIDATEERROR", pvArgs(0)) _ & "\n" & "\n" & .GetText("DUPLICATESHEET", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) @@ -960,6 +964,15 @@ Try: sMessage = sLocation _ & "\n" & "\n" & .GetText("OFFSETADDRESS", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3), pvArgs(4) _ , pvArgs(5), pvArgs(6), pvArgs(7), pvArgs(8), pvArgs(9), pvArgs(10), pvArgs(11)) + Case DUPLICATECHARTERROR ' SF_Calc.CreateChart(chart, ChartName, sheet, SheetName, Document, file) + pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) + sMessage = sLocation _ + & "\n" & "\n" & "\n" & .GetText("VALIDATEERROR", pvArgs(0)) _ + & "\n" & "\n" & .GetText("DUPLICATECHART", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3), pvArgs(4), pvArgs(5)) + Case CHARTEXPORTERROR ' SF_Chart.ExportToFile(Arg1Name, FileName, Arg2, Overwrite) + pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) + sMessage = sLocation _ + & "\n" & "\n" & .GetText("CHARTEXPORT", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) Case FORMDEADERROR ' SF_Form._IsStillAlive(FormName, DocumentName) sMessage = sLocation _ & "\n" & "\n" & .GetText("FORMDEAD", pvArgs(0), pvArgs(1)) diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba index 2addd1eca678..62ce902b2091 100644 --- a/wizards/source/scriptforge/SF_PythonHelper.xba +++ b/wizards/source/scriptforge/SF_PythonHelper.xba @@ -773,6 +773,7 @@ Try: End Select Case "SFDocuments.Calc" Select Case Script + Case "Charts" : vReturn = vBasicObject.Charts(vArgs(0), vArgs(1)) Case "Forms" : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1)) Case "GetFormula" : vReturn = vBasicObject.GetFormula(vArgs(0)) Case "GetValue" : vReturn = vBasicObject.GetValue(vArgs(0)) diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index f435bcec6f1f..131f2eb90d56 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -73,6 +73,7 @@ Private ConfigurationProvider _ As Object ' com.sun.star.configuration.ConfigurationProvider Private MailService As Object ' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail Private TreeDataModel As Object ' com.sun.star.awt.tree.MutableTreeDataModel +Private GraphicExportFilter As Object ' com.sun.star.drawing.GraphicExportFilter ' Specific persistent services objects or properties Private FileSystemNaming As String ' If "SYS", file and folder naming is based on operating system notation @@ -135,6 +136,7 @@ Private Sub Class_Initialize() Set ConfigurationProvider = Nothing Set MailService = Nothing Set TreeDataModel = Nothing + Set GraphicExportFilter = Nothing OSName = "" SFDialogs = Empty SFForms = Empty @@ -822,6 +824,32 @@ Try: & "%11: An identifier\n" _ & "%12: A file name" _ ) + ' SF_Calc.CreateChart + .AddText( Context := "DUPLICATECHART" _ + , MsgId := "A chart with the same name exists already in the sheet.\n\n" _ + & "« %1 » = %2\n" _ + & "« %3 » = %4\n" _ + & "« %5 » = %6\n" _ + , Comment := "SF_Calc CreateChart\n" _ + & "%1: An identifier\n" _ + & "%2: A string\n" _ + & "%3: An identifier\n" _ + & "%4: A string\n" _ + & "%5: An identifier\n" _ + & "%6: A file name" _ + ) + ' SF_Chart.ExportToFile + .AddText( Context := "CHARTEXPORT" _ + , MsgId := "The chart could not be exported.\n" _ + & "Either the destination file must not be overwritten, or it has a read-only attribute set.\n\n" _ + & "%1 = '%2'\n" _ + & "%3 = %4" _ + , Comment := "SF_Chart.ExportToFile error message\n" _ + & "%1: An identifier\n" _ + & "%2: A file name\n" _ + & "%3: An identifier\n" _ + & "%4: True or False\n" _ + ) ' SF_Form._IsStillAlive .AddText( Context := "FORMDEAD" _ , MsgId := "The requested action could not be executed because the form is not open or the document was closed inadvertently.\n\n" _ diff --git a/wizards/source/scriptforge/SF_String.xba b/wizards/source/scriptforge/SF_String.xba index 6eb78b67ce0c..28145ab42750 100644 --- a/wizards/source/scriptforge/SF_String.xba +++ b/wizards/source/scriptforge/SF_String.xba @@ -2712,7 +2712,7 @@ Dim i As Long sChar = Mid(sString, lPos, 1) If Not SF_String.IsPrintable(sChar) Then lAsc = Asc(sChar) - sChar = "\x" & Iif(lAsc < 255, Right("00" & Hex(lAsc, 2)), Right("0000" & Hex(lAsc, 4))) + sChar = "\x" & Iif(lAsc < 255, Right("00" & Hex(lAsc), 2), Right("0000" & Hex(lAsc), 4)) If lPos < Len(sString) Then sString = Left(sString, lPos - 1) & sChar & Mid(sString, lPos + 1) Else diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba index 2f2044cafcc8..99ee224cc79f 100644 --- a/wizards/source/scriptforge/SF_Utils.xba +++ b/wizards/source/scriptforge/SF_Utils.xba @@ -358,6 +358,11 @@ Dim vNodePath As Variant Set .FunctionAccess = CreateUnoService("com.sun.star.sheet.FunctionAccess") End If Set _GetUNOService = .FunctionAccess + Case "GraphicExportFilter" + If IsEmpty(.GraphicExportFilter) Or IsNull(.GraphicExportFilter) Then + Set .GraphicExportFilter = CreateUnoService("com.sun.star.drawing.GraphicExportFilter") + End If + Set _GetUNOService = .GraphicExportFilter Case "Introspection" If IsEmpty(.Introspection) Or IsNull(.Introspection) Then Set .Introspection = CreateUnoService("com.sun.star.beans.Introspection") diff --git a/wizards/source/scriptforge/po/ScriptForge.pot b/wizards/source/scriptforge/po/ScriptForge.pot index 5bb44f2d1d6e..cd5abaf03367 100644 --- a/wizards/source/scriptforge/po/ScriptForge.pot +++ b/wizards/source/scriptforge/po/ScriptForge.pot @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" -"POT-Creation-Date: 2021-06-19 16:57:15\n" +"POT-Creation-Date: 2021-07-30 13:10:57\n" "PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" @@ -737,6 +737,41 @@ msgid "" "« %11 » = %12" msgstr "" +#. SF_Calc CreateChart +#. %1: An identifier +#. %2: A string +#. %3: An identifier +#. %4: A string +#. %5: An identifier +#. %6: A file name +#, kde-format +msgctxt "DUPLICATECHART" +msgid "" +"A chart with the same name exists already in the sheet.\n" +"\n" +"« %1 » = %2\n" +"« %3 » = %4\n" +"« %5 » = %6\n" +"" +msgstr "" + +#. SF_Chart.ExportToFile error message +#. %1: An identifier +#. %2: A file name +#. %3: An identifier +#. %4: True or False +#. +#, kde-format +msgctxt "CHARTEXPORT" +msgid "" +"The chart could not be exported.\n" +"Either the destination file must not be overwritten, or it has a " +"read-only attribute set.\n" +"\n" +"%1 = '%2'\n" +"%3 = %4" +msgstr "" + #. SF_Dialog._IsStillAlive error message #. %1: An identifier%2: A file name #, kde-format diff --git a/wizards/source/scriptforge/po/en.po b/wizards/source/scriptforge/po/en.po index 5bb44f2d1d6e..cd5abaf03367 100644 --- a/wizards/source/scriptforge/po/en.po +++ b/wizards/source/scriptforge/po/en.po @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" -"POT-Creation-Date: 2021-06-19 16:57:15\n" +"POT-Creation-Date: 2021-07-30 13:10:57\n" "PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" @@ -737,6 +737,41 @@ msgid "" "« %11 » = %12" msgstr "" +#. SF_Calc CreateChart +#. %1: An identifier +#. %2: A string +#. %3: An identifier +#. %4: A string +#. %5: An identifier +#. %6: A file name +#, kde-format +msgctxt "DUPLICATECHART" +msgid "" +"A chart with the same name exists already in the sheet.\n" +"\n" +"« %1 » = %2\n" +"« %3 » = %4\n" +"« %5 » = %6\n" +"" +msgstr "" + +#. SF_Chart.ExportToFile error message +#. %1: An identifier +#. %2: A file name +#. %3: An identifier +#. %4: True or False +#. +#, kde-format +msgctxt "CHARTEXPORT" +msgid "" +"The chart could not be exported.\n" +"Either the destination file must not be overwritten, or it has a " +"read-only attribute set.\n" +"\n" +"%1 = '%2'\n" +"%3 = %4" +msgstr "" + #. SF_Dialog._IsStillAlive error message #. %1: An identifier%2: A file name #, kde-format diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index fbc98cc1e2b6..23b505a36ef7 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1892,6 +1892,9 @@ class SFDocuments: def Activate(self, sheetname = ''): return self.ExecMethod(self.vbMethod, 'Activate', sheetname) + def Charts(self, sheetname, chartname = ''): + return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Charts', sheetname, chartname) + def ClearAll(self, range): return self.ExecMethod(self.vbMethod, 'ClearAll', range) @@ -1920,6 +1923,9 @@ class SFDocuments: else sourcerange) return self.ExecMethod(self.vbMethod + self.flgObject, 'CopyToRange', range, destinationrange) + def CreateChart(self, chartname, sheetname, range, columnheader = False, rowheader = False): + return self.ExecMethod(self.vbMethod, 'CreateChart', chartname, sheetname, range, columnheader, rowheader) + def DAvg(self, range): return self.ExecMethod(self.vbMethod, 'DAvg', range) @@ -2008,6 +2014,31 @@ class SFDocuments: servicesynonyms = () serviceproperties = dict() + # ######################################################################### + # SF_Chart CLASS + # ######################################################################### + class SF_Chart(SFServices): + """ + The SF_Chart module is focused on the description of chart documents + stored in Calc sheets. + With this service, many chart types and chart characteristics available + in the user interface can be read or modified. + """ + # Mandatory class properties for service registration + serviceimplementation = 'basic' + servicename = 'SFDocuments.Chart' + servicesynonyms = () + serviceproperties = dict(ChartType = True, Deep = True, Dim3D = True, Exploded = True, Filled = True, + Legend = True, Percent = True, Stacked = True, Title = True, + XChartObj = False, XDiagram = False, XShape = False, XTableChart = False, + XTitle = True, YTitle = True) + + def Resize(self, xpos = -1, ypos = -1, width = -1, height = -1): + return self.ExecMethod(self.vbMethod, 'Resize', xpos, ypos, width, height) + + def ExportToFile(self, filename, imagetype = 'png', overwrite = False): + return self.ExecMethod(self.vbMethod, 'ExportToFile', filename, imagetype, overwrite) + # ######################################################################### # SF_Form CLASS # ######################################################################### diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index b5a491915ceb..c7b1e0fd5081 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -84,6 +84,7 @@ Private Const CALCADDRESSERROR = "CALCADDRESSERROR" Private Const DUPLICATESHEETERROR = "DUPLICATESHEETERROR" Private Const OFFSETADDRESSERROR = "OFFSETADDRESSERROR" Private Const CALCFORMNOTFOUNDERROR = "CALCFORMNOTFOUNDERROR" +Private Const DUPLICATECHARTERROR = "DUPLICATECHARTERROR" REM ============================================================= PRIVATE MEMBERS @@ -307,6 +308,101 @@ Catch: GoTo Finally End Function ' SFDocuments.SF_Calc.Activate +REM ----------------------------------------------------------------------------- +Public Function Charts(Optional ByVal SheetName As Variant _ + , Optional ByVal ChartName As Variant _ + ) As Variant +''' Return either the list of charts present in the given sheet or a chart object +''' Args: +''' SheetName: The name of an existing sheet +''' ChartName: The user-defined name of the targeted chart or the zero-length string +''' Returns: +''' When ChartName = "", return the list of the charts present in the sheet, +''' otherwise, return a new chart service instance +''' Examples: +''' Dim oChart As Object +''' Set oChart = oDoc.Charts("SheetX", "myChart") + +Dim vCharts As Variant ' Return value when array of chart names +Dim oChart As Object ' Return value when new chart instance +Dim oSheet As Object ' Alias of SheetName as reference +Dim oDrawPage As Object ' com.sun.star.drawing.XDrawPage +Dim oNextShape As Object ' com.sun.star.drawing.XShape +Dim sChartName As String ' Some chart name +Dim lCount As Long ' Counter for charts among all drawing objects +Dim i As Long +Const cstChartShape = "com.sun.star.drawing.OLE2Shape" + +Const cstThisSub = "SFDocuments.Calc.Charts" +Const cstSubArgs = "SheetName, [ChartName=""""]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + vCharts = Array() + +Check: + If IsMissing(ChartName) Or IsEmpty(ChartName) Then ChartName = "" + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not _IsStillAlive(True) Then GoTo Finally + If Not _ValidateSheet(SheetName, "SheetName", , True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(ChartName, "ChartName", V_STRING) Then GoTo Finally + End If + +Try: + ' Because the user can change it constantly, the list of valid charts has to be rebuilt at each time + ' Explore charts starting from the draw page + Set oSheet = _Component.getSheets.getByName(SheetName) + Set oDrawPage = oSheet.getDrawPage() + vCharts = Array() + Set oChart = Nothing + lCount = -1 + For i = 0 To oDrawPage.Count - 1 + Set oNextShape = oDrawPage.getByIndex(i) + if oNextShape.supportsService(cstChartShape) Then ' Ignore other shapes + sChartName = oNextShape.Name ' User-defined name + If Len(sChartName) = 0 Then sChartName = oNextShape.PersistName ' Internal name + ' Is chart found ? + If Len(ChartName) > 0 Then + If ChartName = sChartName Then + Set oChart = New SF_Chart + With oChart + Set .[Me] = oChart + Set .[_Parent] = [Me] + ._SheetName = SheetName + ._DrawIndex = i + ._ChartName = ChartName + ._PersistentName = oNextShape.PersistName + Set ._Shape = oNextShape + Set ._Chart = oSheet.getCharts().getByName(._PersistentName) + Set ._ChartObject = ._Chart.EmbeddedObject + Set ._Diagram = ._ChartObject.Diagram + End With + Exit For + End If + End If + ' Build stack of chart names + lCount = lCount + 1 + If UBound(vCharts) < 0 Then + vCharts = Array(sChartName) + Else + ReDim Preserve vCharts(0 To UBound(vCharts) + 1) + vCharts(lCount) = sChartName + End If + End If + Next i + + ' Raise error when chart not found + If Len(ChartName) > 0 And IsNull(oChart) Then + If Not ScriptForge.SF_Utils._Validate(ChartName, "ChartName", V_STRING, vCharts) Then GoTo Finally + End If + +Finally: + If Len(ChartName) = 0 Then Charts = vCharts Else Set Charts = oChart + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDocuments.SF_Calc.Charts + REM ----------------------------------------------------------------------------- Public Sub ClearAll(Optional ByVal Range As Variant) As String ''' Clear entirely the given range @@ -772,6 +868,83 @@ Catch: GoTo Finally End Function ' SFDocuments.SF_Calc.CopyToRange +REM ----------------------------------------------------------------------------- +Public Function CreateChart(Optional ByVal ChartName As Variant _ + , Optional ByVal SheetName As Variant _ + , Optional ByVal Range As Variant _ + , Optional ColumnHeader As Variant _ + , Optional RowHeader As Variant _ + ) As Variant +''' Return a new chart instance initialized with default values +''' Args: +''' ChartName: The user-defined name of the new chart +''' SheetName: The name of an existing sheet +''' Range: the cell or the range as a string that should be drawn +''' ColumnHeader: when True, the topmost row of the range will be used to set labels for the category axis or the legend. +''' Default = False +''' RowHeader: when True, the leftmost column of the range will be used to set labels for the category axis or the legend. +''' Default = False +''' Returns: +''' A new chart service instance +''' Exceptions: +''' DUPLICATECHARTERROR A chart with the same name exists already in the given sheet +''' Examples: +''' Dim oChart As Object +''' Set oChart = oDoc.CreateChart("myChart", "SheetX", "A1:C8", ColumnHeader := True) + +Dim oChart As Object ' Return value +Dim vCharts As Variant ' List of pre-existing charts +Dim oSheet As Object ' Alias of SheetName as reference +Dim oRange As Object ' Alias of Range +Dim oRectangle as new com.sun.star.awt.Rectangle ' Simple shape + +Const cstThisSub = "SFDocuments.Calc.CreateChart" +Const cstSubArgs = "ChartName, SheetName, Range, [ColumnHeader=False], [RowHeader=False]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + Set oChart = Nothing + +Check: + If IsMissing(RowHeader) Or IsEmpty(RowHeader) Then Rowheader = False + If IsMissing(ColumnHeader) Or IsEmpty(ColumnHeader) Then ColumnHeader = False + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not _IsStillAlive(True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(ChartName, "ChartName", V_STRING) Then GoTo Finally + If Not _ValidateSheet(SheetName, "SheetName", , True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Range, "Range", V_STRING) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(ColumnHeader, "ColumnHeader", ScriptForge.V_BOOLEAN) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(RowHeader, "RowHeader", ScriptForge.V_BOOLEAN) Then GoTo Finally + End If + + vCharts = Charts(SheetName) + If ScriptForge.SF_Array.Contains(vCharts, ChartName, CaseSensitive := True) Then GoTo CatchDuplicate + +Try: + ' The rectangular shape receives arbitrary values. User can Resize() it later + With oRectangle + .X = 0 : .Y = 0 + .Width = 8000 : .Height = 6000 + End With + ' Initialize sheet and range + Set oSheet = _Component.getSheets.getByName(SheetName) + Set oRange = _ParseAddress(Range) + ' Create the chart and get ihe corresponding chart instance + oSheet.getCharts.addNewByName(ChartName, oRectangle, Array(oRange.XCellRange.RangeAddress), ColumnHeader, RowHeader) + Set oChart = Charts(SheetName, ChartName) + oChart._Shape.Name = ChartName ' Both used-defined and internal names match ChartName + oChart._Diagram.Wall.FillColor = RGB(255, 255, 255) ' Align on background color set by the user interface by default + +Finally: + Set CreateChart = oChart + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +CatchDuplicate: + ScriptForge.SF_Exception.RaiseFatal(DUPLICATECHARTERROR, "ChartName", ChartName, "SheetName", SheetName, "Document", [_Super]._FileIdent()) + GoTo Finally +End Function ' SFDocuments.SF_Calc.CreateChart + REM ----------------------------------------------------------------------------- Public Function DAvg(Optional ByVal Range As Variant) As Double ''' Get the average of the numeric values stored in the given range @@ -1671,7 +1844,7 @@ Check: End If Try: - _Component.getSheets.RemoveByName(SheetName) + _Component.getSheets.RemoveByName(SheetName) bRemove = True Finally: diff --git a/wizards/source/sfdocuments/SF_Chart.xba b/wizards/source/sfdocuments/SF_Chart.xba new file mode 100644 index 000000000000..7a9d9740cbb8 --- /dev/null +++ b/wizards/source/sfdocuments/SF_Chart.xba @@ -0,0 +1,815 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> +<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Chart" script:language="StarBasic" script:moduleType="normal">REM ======================================================================================================================= +REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. === +REM === The SFDocuments library is one of the associated libraries. === +REM === Full documentation is available on https://help.libreoffice.org/ === +REM ======================================================================================================================= + +Option Compatible +Option ClassModule + +Option Explicit + +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +''' SF_Chart +''' ======== +''' +''' The SF_Chart module is focused on the description of chart documents +''' stored in Calc sheets. +''' With this service, many chart types and chart characteristics available +''' in the user interface can be read or modified. +''' +''' Definitions +''' Charts have 2 distinct names: +''' - an internal name, given by the LibreOffice application +''' - an optional user-defined name +''' In the scope of the ScriptForge libraries, the chart name is the name given by the user. +''' Only when there is no user name, the internal name may be used instead. +''' +''' Service invocation from the "Calc" service +''' Either make a new chart +''' calc.CreateChart(ChartName, SheetName, "SheetX.A1:C8") +''' or select an existing one +''' calc.Charts(SheetName, ChartName) +''' +''' Detailed user documentation: +''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_chart.html?DbPAR=BASIC +''' +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +REM ================================================================== EXCEPTIONS + +Private Const CHARTEXPORTERROR = "CHARTEXPORTERROR" + +REM ============================================================= PRIVATE MEMBERS + +Private [Me] As Object +Private [_Parent] As Object ' Parent Calc document +Private ObjectType As String ' Must be CHART +Private ServiceName As String + +' Chart description +Private _SheetName As String ' Name of the Calc sheet containing the chart +Private _DrawIndex As Long ' Index of the chart in the sheet's draw page +Private _ChartName As String ' User name +Private _PersistentName As String ' Internal name +Private _Shape As Object ' com.sun.star.drawing.XShape +Private _Chart As Object ' com.sun.star.table.XTableChart +Private _ChartObject As Object ' com.sun.star.lang.XComponent - ScChartObj +Private _Diagram As Object ' com.sun.star.chart.XDiagram + +REM ============================================================ MODULE CONSTANTS + + +REM ====================================================== CONSTRUCTOR/DESTRUCTOR + +REM ----------------------------------------------------------------------------- +Private Sub Class_Initialize() + Set [Me] = Nothing + Set [_Parent] = Nothing + ObjectType = "CHART" + ServiceName = "SFDocuments.Chart" + _SheetName = "" + _DrawIndex = -1 + _ChartName = "" + _PersistentName = "" + Set _Shape = Nothing + Set _Chart = Nothing + Set _ChartObject = Nothing + Set _Diagram = Nothing +End Sub ' SFDocuments.SF_Chart Constructor + +REM ----------------------------------------------------------------------------- +Private Sub Class_Terminate() + Call Class_Initialize() +End Sub ' SFDocuments.SF_Chart Destructor + +REM ----------------------------------------------------------------------------- +Public Function Dispose() As Variant + Call Class_Terminate() + Set Dispose = Nothing +End Function ' SFDocuments.SF_Chart Explicit Destructor + +REM ================================================================== PROPERTIES + +REM ----------------------------------------------------------------------------- +Property Get ChartType() As Variant +''' The ChartType property specifies the type of chart as a string among next values: +''' Pie, Bar, Donut, Column, Area, Line, XY, Bubble, Net + ChartType = _PropertyGet("ChartType") +End Property ' SFDocuments.SF_Chart.ChartType (get) + +REM ----------------------------------------------------------------------------- +Property Let ChartType(Optional ByVal pvChartType As Variant) +''' Set the updatable property ChartType + _PropertySet("ChartType", pvChartType) +End Property ' SFDocuments.SF_Chart.ChartType (let) + +REM ----------------------------------------------------------------------------- +Property Get Deep() As Variant +''' If True, determines that in a three-dimensional bar chart the bars of each series are arranged behind each other in the z-direction. +''' If False the arrangement of bars is like in two-dimensional bar charts. +''' Bar and Column chart types only + Deep = _PropertyGet("Deep") +End Property ' SFDocuments.SF_Chart.Deep (get) + +REM ----------------------------------------------------------------------------- +Property Let Deep(Optional ByVal pvDeep As Variant) +''' Set the updatable property Deep + _PropertySet("Deep", pvDeep) +End Property ' SFDocuments.SF_Chart.Deep (let) + +REM ----------------------------------------------------------------------------- +Property Get Dim3D() As Variant +''' The Dim3D property specifies if the chart is displayed with 3D elements +''' String or Boolean +''' When String, must be 1 of next values: Bar, Cylinder, Cone or Pyramid +''' When Boolean True, Bar is assumed; when False, no 3D to be applied + Dim3D = _PropertyGet("Dim3D") +End Property ' SFDocuments.SF_Chart.Dim3D (get) + +REM ----------------------------------------------------------------------------- +Property Let Dim3D(Optional ByVal pvDim3D As Variant) +''' Set the updatable property Dim3D + _PropertySet("Dim3D", pvDim3D) +End Property ' SFDocuments.SF_Chart.Dim3D (let) + +REM ----------------------------------------------------------------------------- +Property Get Exploded() As Variant +''' the offset by which pie segments in a PieDiagram are dragged outside from the center. +''' This value is given in percent of the radius. + Exploded = _PropertyGet("Exploded") +End Property ' SFDocuments.SF_Chart.Exploded (get)_ChartObject + +REM ----------------------------------------------------------------------------- +Property Let Exploded(Optional ByVal pvExploded As Variant) +''' Set the updatable property Exploded + _PropertySet("Exploded", pvExploded) +End Property ' SFDocuments.SF_Chart.Exploded (let) + +REM ----------------------------------------------------------------------------- +Property Get Filled() As Variant +''' When True, the Net diagram is said of FilledNet type +''' Net chart type only + Filled = _PropertyGet("Filled") +End Property ' SFDocuments.SF_Chart.Filled (get) + +REM ----------------------------------------------------------------------------- +Property Let Filled(Optional ByVal pvFilled As Variant) +''' Set the updatable property Filled + _PropertySet("Filled", pvFilled) +End Property ' SFDocuments.SF_Chart.Filled (let) + +REM ----------------------------------------------------------------------------- +Property Get Legend() As Variant +''' Specifies if the chart has a legend + Legend = _PropertyGet("Legend") +End Property ' SFDocuments.SF_Chart.Legend (get) + +REM ----------------------------------------------------------------------------- +Property Let Legend(Optional ByVal pvLegend As Variant) +''' Set the updatable property Legend + _PropertySet("Legend", pvLegend) +End Property ' SFDocuments.SF_Chart.Legend (let) + +REM ----------------------------------------------------------------------------- +Property Get Percent() As Variant +''' When True, the series of the diagram are stacked and each category sums up to 100%. +''' Area, Bar, Bubble, Column and Net chart types only_ChartObject + Percent = _PropertyGet("Percent") +End Property ' SFDocuments.SF_Chart.Percent (get) + +REM ----------------------------------------------------------------------------- +Property Let Percent(Optional ByVal pvPercent As Variant) +''' Set the updatable property Percent + _PropertySet("Percent", pvPercent) +End Property ' SFDocuments.SF_Chart.Percent (let) + +REM ----------------------------------------------------------------------------- +Property Get Stacked() As Variant +''' When True, the series of the diagram are stacked. +''' Area, Bar, Bubble, Column and Net chart types only + Stacked = _PropertyGet("Stacked") +End Property ' SFDocuments.SF_Chart.Stacked (get) + +REM ----------------------------------------------------------------------------- +Property Let Stacked(Optional ByVal pvStacked As Variant) +''' Set the updatable property Stacked + _PropertySet("Stacked", pvStacked) +End Property ' SFDocuments.SF_Chart.Stacked (let) + +REM ----------------------------------------------------------------------------- +Property Get Title() As Variant +''' Specifies the main title of the chart + Title = _PropertyGet("Title") +End Property ' SFDocuments.SF_Chart.Title (get) + +REM ----------------------------------------------------------------------------- +Property Let Title(Optional ByVal pvTitle As Variant) +''' Set the updatable property Title + _PropertySet("Title", pvTitle) +End Property ' SFDocuments.SF_Chart.Title (let) + +REM ----------------------------------------------------------------------------- +Property Get XTitle() As Variant +''' Specifies the main XTitle of the chart + XTitle = _PropertyGet("XTitle") +End Property ' SFDocuments.SF_Chart.XTitle (get) + +REM ----------------------------------------------------------------------------- +Property Let XTitle(Optional ByVal pvXTitle As Variant) +''' Set the updatable property XTitle + _PropertySet("XTitle", pvXTitle) +End Property ' SFDocuments.SF_Chart.XTitle (let) + +REM ----------------------------------------------------------------------------- +Property Get YTitle() As Variant +''' Specifies the main YTitle of the chart + YTitle = _PropertyGet("YTitle") +End Property ' SFDocuments.SF_Chart.YTitle (get) + +REM ----------------------------------------------------------------------------- +Property Let YTitle(Optional ByVal pvYTitle As Variant) +''' Set the updatable property YTitle + _PropertySet("YTitle", pvYTitle) +End Property ' SFDocuments.SF_Chart.YTitle (let) + +REM ----------------------------------------------------------------------------- +Property Get XChartObj() As Variant +''' com.sun.star.lang.XComponent - ScChartObj + ChartType = _PropertyGet("XChartObj") +End Property ' SFDocuments.SF_Chart.XChartObj (get) + +REM ----------------------------------------------------------------------------- +Property Get XDiagram() As Variant +''' com.sun.star.chart.XDiagram + ChartType = _PropertyGet("XDiagram") +End Property ' SFDocuments.SF_Chart.XDiagram (get) + +REM ----------------------------------------------------------------------------- +Property Get XShape() As Variant +''' com.sun.star.drawing.XShape + ChartType = _PropertyGet("XShape") +End Property ' SFDocuments.SF_Chart.XShape (get) + +REM ----------------------------------------------------------------------------- +Property Get XTableChart() As Variant +''' com.sun.star.table.XTableChart + ChartType = _PropertyGet("XTableChart") +End Property ' SFDocuments.SF_Chart.XTableChart (get) + +REM ===================================================================== METHODS + +REM ----------------------------------------------------------------------------- +Public Function ExportToFile(Optional ByVal FileName As Variant _ + , Optional ByVal ImageType As Variant _ + , Optional ByVal Overwrite As Variant _ + ) As Boolean +''' Store the chart as an image to the given file location +''' Args: +''' FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation +''' ImageType: the name of the targeted image type +''' Allowed values: gif, jpeg, png (default), svg and tiff +''' Overwrite: True if the destination file may be overwritten (default = False) +''' Returns: +''' False if the document could not be saved +''' Exceptions: +''' CHARTEXPORTERROR The destination has its readonly attribute set or overwriting rejected +''' Examples: +''' oChart.ExportToFile("C:\Me\Chart2.gif", ImageType := "gif", Overwrite := True) + +Dim bSaved As Boolean ' return value +Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess +Dim sFile As String ' Alias of FileName +Dim vStoreArguments As Variant ' Array of com.sun.star.beans.PropertyValue +Dim FSO As Object ' SF_FileSystem +Dim oExport As Object ' com.sun.star.drawing.GraphicExportFilter +Dim vImageTypes As Variant ' Array of permitted image types +Dim vMimeTypes As Variant ' Array of corresponding mime types in the same order as vImageTypes + +Const cstImageTypes = "gif,jpeg,png,svg,tiff" +Const cstMimeTypes = "image/gif,image/jpeg,image/png,image/svg+xml,image/tiff" + +Const cstThisSub = "SFDocuments.Chart.ExportToFile" +Const cstSubArgs = "FileName, [ImageType=""png""|""gif""|""jpeg""|""svg""|""tiff""], [Overwrite=False]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError + bSaved = False + +Check: + If IsMissing(ImageType) Or IsEmpty(ImageType) Then ImageType = "png" + If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False + + vImageTypes = Split(cstImageTypes, ",") + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not [_Parent]._IsStillAlive() Then GoTo Finally + If Not ScriptForge.SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(ImageType, "ImageType", V_STRING, vImageTypes) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Overwrite, "Overwrite", ScriptForge.V_BOOLEAN) Then GoTo Finally + End If + + ' Check destination file overwriting + Set FSO = CreateScriptService("FileSystem") + sFile = FSO._ConvertToUrl(FileName) + If FSO.FileExists(FileName) Then + If Overwrite = False Then GoTo CatchError + Set oSfa = ScriptForge.SF_Utils._GetUNOService("FileAccess") + If oSfa.isReadonly(sFile) Then GoTo CatchError + End If + +Try: + ' Setup arguments + vMimeTypes = Split(cstMimeTypes, ",") + vStoreArguments = Array( _ + ScriptForge.SF_Utils._MakePropertyValue("URL", sFile) _ + , ScriptForge.SF_Utils._MakePropertyValue("MediaType" _ + , vMimeTypes(ScriptForge.SF_Array.IndexOf(vImageTypes, ImageType, CaseSensitive := False))) _ + ) + ' Export with the com.sun.star.drawing.GraphicExportFilter UNO service + Set oExport = ScriptForge.SF_Utils._GetUNOService("GraphicExportFilter") + With oExport + .setSourceDocument(_Shape) + .filter(vStoreArguments) + End With + bSaved = True + +Finally: + ExportToFile = bSaved + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +CatchError: + ScriptForge.SF_Exception.RaiseFatal(CHARTEXPORTERROR, "FileName", FileName, "Overwrite", Overwrite) + GoTo Finally +End Function ' SFDocuments.SF_Chart.ExportToFile + +REM ----------------------------------------------------------------------------- +Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant +''' Return the actual value of the given property +''' Args: +''' PropertyName: the name of the property as a string +''' Returns: +''' The actual value of the property +''' If the property does not exist, returns Null +''' Exceptions: +''' ARGUMENTERROR The property does not exist + +Const cstThisSub = "SFDocuments.Chart.GetProperty" +Const cstSubArgs = "" + + If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + GetProperty = Null + +Check: + If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch + End If + +Try: + GetProperty = _PropertyGet(PropertyName) + +Finally: + SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDocuments.SF_Chart.GetProperty + +REM ----------------------------------------------------------------------------- +Public Function Methods() As Variant +''' Return the list of public methods of the Chart service as an array + + Methods = Array( _ + "ExportToFile" _ + , "Resize" _ + ) + +End Function ' SFDocuments.SF_Chart.Methods + +REM ----------------------------------------------------------------------------- +Public Function Properties() As Variant +''' Return the list or properties of the Chart class as an array + + Properties = Array( _ + "ChartType" _ + , "Deep" _ + , "Dim3D" _ + , "Exploded" _ + , "Filled" _ + , "Legend" _ + , "Percent" _ + , "Stacked" _ + , "Title" _ + , "XChartObj" _ + , "XDiagram" _ + , "XShape" _ + , "XTableChart" _ + , "XTitle" _ + , "YTitle" _ + ) + +End Function ' SFDocuments.SF_Chart.Properties + +REM ----------------------------------------------------------------------------- +Public Function Resize(Optional ByVal XPos As Variant _ + , Optional ByVal YPos As Variant _ + , Optional ByVal Width As Variant _ + , Optional ByVal Height As Variant _ + ) As String +''' Move the topleft corner of a chart to new coordinates and/or modify its dimensions +''' All distances are expressed in 1/100th mm +''' Args: +''' XPos : the vertical distance from the topleft corner +''' YPos : the horizontal distance from the topleft corner +''' Width : the horizontal width of the shape containing the chart +''' Height : the vertical height of the shape containing the chart +''' Negative or missing arguments are left unchanged +''' Returns: +''' True when successful +''' Examples: +''' oChart.Resize(1000, 2000, Height = 6000) ' Width is not changed + +Dim bResize As Boolean ' Return value +Dim oAddress As Object ' Alias of Range +Dim oPosition As Object ' com.sun.star.awt.Point +Dim oSize As Object ' com.sun.star.awt.Size +Const cstThisSub = "SFDocuments.Chart.Resize" +Const cstSubArgs = "[XPos], [YPos], [Width], [Height]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bResize = False + +Check: + If IsMissing(XPos) Or IsEmpty(XPos) Then XPos = -1 + If IsMissing(YPos) Or IsEmpty(YPos) Then YPos = -1 + If IsMissing(Height) Or IsEmpty(Height) Then Height = -1 + If IsMissing(Width) Or IsEmpty(Width) Then Width = -1 + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not [_Parent]._IsStillAlive() Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(XPos, "XPos", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(YPos, "YPos", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Width, "Width", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Height, "Height", ScriptForge.V_NUMERIC) Then GoTo Finally + End If + +Try: + With _Shape + ' Get the current values + Set oPosition = .Position + Set oSize = .Size + ' Modify relevant elements + If XPos >= 0 Then oPosition.X = CLng(XPos) + If YPos >= 0 Then oPosition.Y = CLng(YPos) + If Width > 0 Then oSize.Width = CLng(Width) + If Height > 0 Then oSize.Height = CLng(Height) + ' Rewrite + .setPosition(oPosition) + .setSize(oSize) + End With + bResize = True + +Finally: + Resize = bResize + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SF_Documents.SF_Chart.Resize + +REM ----------------------------------------------------------------------------- +Public Function SetProperty(Optional ByVal PropertyName As Variant _ + , Optional ByRef Value As Variant _ + ) As Boolean +''' Set a new value to the given property +''' Args: +''' PropertyName: the name of the property as a string +''' Value: its new value +''' Exceptions +''' ARGUMENTERROR The property does not exist + +Const cstThisSub = "SFDocuments.Chart.SetProperty" +Const cstSubArgs = "PropertyName, Value" + + If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + SetProperty = False + +Check: + If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch + End If + +Try: + SetProperty = _PropertySet(PropertyName, Value) + +Finally: + SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDocuments.SF_Chart.SetProperty + +REM =========================================================== PRIVATE FUNCTIONS + +REM ----------------------------------------------------------------------------- +Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant +''' Return the value of the named property +''' Args: +''' psProperty: the name of the property + +Static oSession As Object ' Alias of SF_Session +Dim vData As Variant ' Data points array of values + +Dim cstThisSub As String +Const cstSubArgs = "" + + cstThisSub = "SFDocuments.Chart.get" & psProperty + SF_Utils._EnterFunction(cstThisSub, cstSubArgs) + If Not [_Parent]._IsStillAlive() Then GoTo Finally + + If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session") + Select Case UCase(psProperty) + Case UCase("ChartType") + With _Diagram + Select Case .DiagramType + Case "com.sun.star.chart.BarDiagram" + If .Vertical Then _PropertyGet = "Bar" Else _PropertyGet = "Column" + Case "com.sun.star.chart.PieDiagram" + _PropertyGet = "Pie" + Case "com.sun.star.chart.DonutDiagram" + _PropertyGet = "Donut" + Case "com.sun.star.chart.AreaDiagram" + _PropertyGet = "Area" + Case "com.sun.star.chart.LineDiagram" + _PropertyGet = "Line" + Case "com.sun.star.chart.XYDiagram" + _PropertyGet = "XY" + Case "com.sun.star.chart.BubbleDiagram" + _PropertyGet = "Bubble" + Case "com.sun.star.chart.NetDiagram", "com.sun.star.chart.FilledNetDiagram" + _PropertyGet = "Net" + Case Else + _PropertyGet = "" + End Select + End With + Case UCase("Deep") + If oSession.HasUnoProperty(_Diagram, "Deep") Then _PropertyGet = _Diagram.Deep Else _PropertyGet = False + Case UCase("Dim3D") + If oSession.HasUnoProperty(_Diagram, "Dim3D") Then + If _Diagram.Dim3D Then + If oSession.HasUnoProperty(_Diagram, "SolidType") Then + Select Case _Diagram.SolidType + Case com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID : _PropertyGet = "Bar" + Case com.sun.star.chart.ChartSolidType.CYLINDER : _PropertyGet = "Cylinder" + Case com.sun.star.chart.ChartSolidType.CONE : _PropertyGet = "Cone" + Case com.sun.star.chart.ChartSolidType.PYRAMID : _PropertyGet = "Pyramid" + End Select + Else + _PropertyGet = _Diagram.Dim3D + End If + Else + _PropertyGet = False + End If + Else + _PropertyGet = False + End If + Case UCase("Exploded") + If oSession.HasUnoProperty(_ChartObject, "Data") Then + ' All data points are presumed exploded with the same coefficient. Determine the (0, 0)th + With _ChartObject + vData = .Data.Data + _PropertyGet = 0 + If IsArray(vData) Then + If UBound(vData) >= 0 Then + If IsArray(vData(0)) Then + If UBound(vData(0)) >= 0 Then _PropertyGet = _Diagram.getDataPointProperties(0, 0).SegmentOffset + End If + End If + End If + End With + End If + Case UCase("Filled") + _PropertyGet = ( _Diagram.DiagramType = "com.sun.star.chart.FilledNetDiagram" ) + Case UCase("Legend") + If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _PropertyGet = _ChartObject.HasLegend Else _PropertyGet = False + Case UCase("Percent") + If oSession.HasUnoProperty(_Diagram, "Percent") Then _PropertyGet = _Diagram.Percent Else _PropertyGet = False + Case UCase("Stacked") + If oSession.HasUnoProperty(_Diagram, "Stacked") Then _PropertyGet = _Diagram.Stacked Else _PropertyGet = False + Case UCase("Title") + If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then + If _ChartObject.HasMainTitle Then _PropertyGet = _ChartObject.Title.String Else _PropertyGet = "" + End If + Case UCase("XTitle") + If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then + If _Diagram.HasXAxisTitle Then _PropertyGet = _Diagram.XAxisTitle.String Else _PropertyGet = "" + End If + Case UCase("YTitle") + If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then + If _Diagram.HasYAxisTitle Then _PropertyGet = _Diagram.YAxisTitle.String Else _PropertyGet = "" + End If + Case UCase("XChartObj") + Set _PropertGet = _ChartObject + Case UCase("XDiagram") + Set _PropertyGet = _Diagram + Case UCase("XShape") + Set _PropertyGet = _Shape + Case UCase("XTableChart") + Set _PropertyGet = _Chart + Case Else + _PropertyGet = Null + End Select + +Finally: + SF_Utils._ExitFunction(cstThisSub) + Exit Function +End Function ' SFDocuments.SF_Chart._PropertyGet + +REM ----------------------------------------------------------------------------- +Private Function _PropertySet(Optional ByVal psProperty As String _ + , Optional ByVal pvValue As Variant _ + ) As Boolean +''' Set the new value of the named property +''' Args: +''' psProperty: the name of the property +''' pvValue: the new value of the given property + +Dim bSet As Boolean ' Return value +Static oSession As Object ' Alias of SF_Session +Dim sChartType As String ' Diagram type +Dim bDim3D As Boolean ' Alias of Dim3D property of diagram +Dim bVertical As Boolean ' When True, chart type is a bar, not a column +Dim vData As Variant ' Data points array of values +Dim i As Long, j As Long +Const cstChart = "com.sun.star.chart." + +Dim cstThisSub As String +Const cstSubArgs = "Value" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bSet = False + + cstThisSub = "SFDocuments.Chart.set" & psProperty + ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) + If Not [_Parent]._IsStillAlive() Then GoTo Catch + + bSet = True + If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session") + Select Case UCase(psProperty) + Case UCase("ChartType") + If Not ScriptForge.SF_Utils._Validate(pvValue, "ChartType", V_STRING _ + , Array("Bar", "Column", "Pie", "Donut", "Area", "Line", "XY", "Bubble", "Net") _ + ) Then GoTo Finally + With _Diagram + ' Specify the targeted chart type + Select Case UCase(pvValue) + Case "BAR", "COLUMN" : sChartType = cstChart & "BarDiagram" + Case "PIE" : sChartType = cstChart & "PieDiagram" + Case "DONUT" : sChartType = cstChart & "DonutDiagram" + Case "AREA" : sChartType = cstChart & "AreaDiagram" + Case "LINE" : sChartType = cstChart & "LineDiagram" + Case "XY" : sChartType = cstChart & "XYDiagram" + Case "BUBBLE" : sChartType = cstChart & "BubbleDiagram" + Case "NET" : sChartType = cstChart & "NetDiagram" + End Select + ' If there is no change, do nothing + If sChartType <> .DiagramType Then + ' Some combinations old type => new type require the cancellation of 3D graphs + bDim3D = .Dim3D + .Dim3D = False + _ChartObject.createInstance(sChartType) + Set _Diagram = _ChartObject.Diagram + .Dim3D = bDim3D + End If + If UCase(pvValue) = "BAR" Or UCase(pvValue) = "COLUMN" Then .Vertical = ( UCase(pvValue) = "BAR" ) + End With + Case UCase("Deep") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Deep", ScriptForge.V_BOOLEAN) Then GoTo Finally + If oSession.HasUnoProperty(_Diagram, "Deep") Then _Diagram.Deep = pvValue + Case UCase("Dim3D") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Dim3D", Array(ScriptForge.V_Boolean, V_STRING) _ + , Array(False, True, "Bar", "Cylinder", "Cone", "Pyramid") _ + ) Then GoTo Finally + With _Diagram + If oSession.HasUnoProperty(_Diagram, "Dim3D") Then + If _Diagram.DiagramType = "com.sun.star.chart.BubbleDiagram" Then + .Dim3D = False ' Force False value to avoid empty graph + ElseIf VarType(pvValue) = V_STRING Then + bVertical = .Vertical + .Dim3D = True + .Vertical = bVertical + If oSession.HasUnoProperty(_Diagram, "SolidType") Then + If .DiagramType = cstChart & "BarDiagram" Then + Select Case UCase(pvValue) + Case "BAR" : .SolidType = com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID + Case "CYLINDER" : .SolidType = com.sun.star.chart.ChartSolidType.CYLINDER + Case "CONE" : .SolidType = com.sun.star.chart.ChartSolidType.CONE + Case "PYRAMID" : .SolidType = com.sun.star.chart.ChartSolidType.PYRAMID + End Select + Else + .SolidType = 0 + End If + End If + Else ' Boolean + If oSession.HasUnoProperty(_Diagram, "SolidType") Then .SolidType = 0 + .Dim3D = pvValue + End If + End If + End With + Case UCase("Exploded") + If oSession.HasUnoProperty(_ChartObject, "Data") And _Diagram.DiagramType <> "com.sun.star.chart.BubbleDiagram" Then + ' All data points are presumed exploded with the same coefficient + If Not ScriptForge.SF_Utils._Validate(pvValue, "Exploded", ScriptForge.V_NUMERIC) Then GoTo Finally + With _ChartObject + vData = .Data.Data + If IsArray(vData) Then + For i = 0 To UBound(vData) + If IsArray(vData(i)) Then + For j = 0 To UBound(vData(i)) + _Diagram.getDataPointProperties(i, j).SegmentOffset = CLng(pvValue) + Next j + End If + Next i + End If + End With + End If + Case UCase("Filled") + ' Flipflop between NetDiagram and FilledNetDiagram + If Not ScriptForge.SF_Utils._Validate(pvValue, "Filled", ScriptForge.V_BOOLEAN) Then GoTo Finally + With _Diagram + ' Specify the targeted chart type + sChartType = cstChart & Iif(pvValue, "Filled", "") & "NetDiagram" + ' If there is no change, do nothing + If sChartType <> .DiagramType then + ' Do not apply if the chart type not = "Net" + If (pvValue And .DiagramType = cstChart & "NetDiagram") _ + Or (Not pvValue And .DiagramType = cstChart & "FilledNetDiagram") Then + ' Some combinations old type => new type require the cancellation of 3D graphs + bDim3D = .Dim3D + .Dim3D = False + _ChartObject.createInstance(sChartType) + Set _Diagram = _ChartObject.Diagram + .Dim3D = bDim3D + End If + End If + End With + Case UCase("Legend") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Legend", ScriptForge.V_BOOLEAN) Then GoTo Finally + If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _ChartObject.HasLegend = pvValue + Case UCase("Percent") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Percent", ScriptForge.V_BOOLEAN) Then GoTo Finally + If oSession.HasUnoProperty(_Diagram, "Percent") Then + _Diagram.Stacked = pvValue + _Diagram.Percent = pvValue + End If + Case UCase("Stacked") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Stacked", ScriptForge.V_BOOLEAN) Then GoTo Finally + If oSession.HasUnoProperty(_Diagram, "Stacked") Then + _Diagram.Stacked = pvValue + If Not pvValue Then _Diagram.Percent = False + End If + Case UCase("Title") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Title", V_STRING) Then GoTo Finally + If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then + _ChartObject.HasMainTitle = ( Len(pvValue) > 0 ) + If Len(pvValue) > 0 Then _ChartObject.Title.String = pvValue + End If + Case UCase("XTitle") + If Not ScriptForge.SF_Utils._Validate(pvValue, "XTitle", V_STRING) Then GoTo Finally + If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then + _Diagram.HasXAxisTitle = ( Len(pvValue) > 0 ) + If Len(pvValue) > 0 Then _Diagram.XAxisTitle.String = pvValue + End If + Case UCase("YTitle") + If Not ScriptForge.SF_Utils._Validate(pvValue, "YTitle", V_STRING) Then GoTo Finally + If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then + _Diagram.HasYAxisTitle = ( Len(pvValue) > 0 ) + If Len(pvValue) > 0 Then _Diagram.YAxisTitle.String = pvValue + End If + Case Else + bSet = False + End Select + +Finally: + _PropertySet = bSet + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + bSet = False + GoTo Finally +End Function ' SFDocuments.SF_FormControl._PropertySet + +REM ----------------------------------------------------------------------------- +Private Function _Repr() As String +''' Convert the Chart instance to a readable string, typically for debugging purposes (DebugPrint ...) +''' Args: +''' Return: +''' "[Chart]: Name - Type + + _Repr = "[Chart]: " & ChartName & " - " & ChartType + +End Function ' SFDocuments.SF_Chart._Repr + +REM ============================================ END OF SFDOCUMENTS.SF_CHART +</script:module> \ No newline at end of file diff --git a/wizards/source/sfdocuments/SF_FormControl.xba b/wizards/source/sfdocuments/SF_FormControl.xba index f08506d36226..ac120772e175 100644 --- a/wizards/source/sfdocuments/SF_FormControl.xba +++ b/wizards/source/sfdocuments/SF_FormControl.xba @@ -960,7 +960,7 @@ Const cstSubArgs = "PropertyName, Value" Check: If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then - If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch + If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch End If Try: @@ -1866,6 +1866,7 @@ Finally: ScriptForge.SF_Utils._ExitFunction(cstThisSub) Exit Function Catch: + bSet = False GoTo Finally CatchType: If Len(_ParentForm._FormDocumentName) > 0 Then sFormName = _ParentForm._FormDocumentName & "." Else sFormName = "" diff --git a/wizards/source/sfdocuments/script.xlb b/wizards/source/sfdocuments/script.xlb index 881ef70e0f6b..0663d7b64e6a 100644 --- a/wizards/source/sfdocuments/script.xlb +++ b/wizards/source/sfdocuments/script.xlb @@ -9,4 +9,5 @@ <library:element library:name="SF_Form"/> <library:element library:name="SF_FormControl"/> <library:element library:name="SF_Writer"/> + <library:element library:name="SF_Chart"/> </library:library> \ No newline at end of file