wizards/Package_sfdocuments.mk | 1 wizards/source/scriptforge/SF_Exception.xba | 14 wizards/source/scriptforge/SF_PythonHelper.xba | 1 wizards/source/scriptforge/SF_Root.xba | 24 wizards/source/scriptforge/SF_Utils.xba | 5 wizards/source/scriptforge/po/ScriptForge.pot | 54 + wizards/source/scriptforge/po/en.po | 54 + wizards/source/scriptforge/po/fr.po | 214 +++--- wizards/source/scriptforge/python/scriptforge.py | 45 + wizards/source/scriptforge/python/scriptforge.pyi | 181 ++++- wizards/source/scriptforge/script.xlb | 32 - wizards/source/sfdocuments/SF_Calc.xba | 334 ++++++++-- wizards/source/sfdocuments/SF_Chart.xba | 216 +----- wizards/source/sfdocuments/SF_Document.xba | 54 + wizards/source/sfdocuments/SF_Shape.xba | 686 ++++++++++++++++++++++ wizards/source/sfdocuments/script.xlb | 1 16 files changed, 1460 insertions(+), 456 deletions(-)
New commits: commit 2a3eb41c0379373448e436d18a87a6b51eb54862 Author: Jean-Pierre Ledure <[email protected]> AuthorDate: Wed Nov 12 17:42:14 2025 +0100 Commit: Jean-Pierre Ledure <[email protected]> CommitDate: Thu Nov 13 10:04:58 2025 +0100 ScriptForge (SFDocuments) new Shape service The new "Shape" service is focused on the description of shapes/images/drawing objects stored in documents. In the actual release only shapes in Calc sheets are considered. A Shape instance is created from either: - calc.CreateShapeFromFile(shapename, imagefile, range, aslink) => the shape is loaded in the sheet and anchored to the given range. The shape may or not be embedded in the document. - calc.Shapes(sheetname, shapename) Next methods are available: - shape.Anchor(anchortype, cell) => define the anchor type and the cell to which the shape has to be anchored. - shape.ExportToFile(filename, imagetype, overwrite) => save the shape as an image file to a specified location. - shape.Pick() => select the shape (NB "Select" is a reserved word in Basic, hence "Pick") - shape.Resize(xpos, ypos, width, height) => change position and/or size. - shape.Rotate(angle, pivot) => rotate the shape using a given pivot point (x, y) with a given angle. The shape.XShape property gives a direct access to its com.sun.star.drawing.XShape UNO representation. The pre-existing SF_Chart service is functionally unchanged. However it is now implemented as a subclass of the new SF_Shape service. Compatibility with previous releases is preserved. The implementation required a few changes in the error messages. Hence also in their translations. All the functions are available for both Basic and Python user scripts. The documentation should include: - a revision of the Calc and Chart help pages - the creation of an additional Shape page Change-Id: Ib67f5e755e3112961aadeffc3188b2cdf9aca613 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193906 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <[email protected]> diff --git a/wizards/Package_sfdocuments.mk b/wizards/Package_sfdocuments.mk index 4dcebfc84140..01b5fb46633b 100644 --- a/wizards/Package_sfdocuments.mk +++ b/wizards/Package_sfdocuments.mk @@ -29,6 +29,7 @@ $(eval $(call gb_Package_add_files,wizards_basicsrvsfdocuments,$(LIBO_SHARE_FOLD SF_FormControl.xba \ SF_FormDocument.xba \ SF_Register.xba \ + SF_Shape.xba \ SF_Writer.xba \ __License.xba \ dialog.xlb \ diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba index afc35fcb3acd..313c70dd4825 100644 --- a/wizards/source/scriptforge/SF_Exception.xba +++ b/wizards/source/scriptforge/SF_Exception.xba @@ -117,8 +117,9 @@ Const OFFSETADDRESSERROR = "OFFSETADDRESSERROR" Const DUPLICATECHARTERROR = "DUPLICATECHARTERROR" Const RANGEEXPORTERROR = "RANGEEXPORTERROR" -' SF_Chart -Const CHARTEXPORTERROR = "CHARTEXPORTERROR" +' SF_SHAPE +Const DUPLICATESHAPEERROR = "DUPLICATESHAPEERROR" +Const SHAPEEXPORTERROR = "SHAPEEXPORTERROR" ' SF_Form Const FORMDEADERROR = "FORMDEADERROR" @@ -1074,14 +1075,19 @@ Try: sMessage = sLocation _ & " " & " " & " " & .GetText("VALIDATEERROR", pvArgs(0)) _ & " " & " " & .GetText("DUPLICATECHART", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3), pvArgs(4), pvArgs(5)) + Case DUPLICATESHAPEERROR ' SF_Calc.CreateShapeFromFile(shape, ShapeName, sheet, SheetName, Document, file) + pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) + sMessage = sLocation _ + & " " & " " & " " & .GetText("VALIDATEERROR", pvArgs(0)) _ + & " " & " " & .GetText("DUPLICATESHAPE", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3), pvArgs(4), pvArgs(5)) Case RANGEEXPORTERROR ' SF_Calc.ExportRangeToFile(Arg1Name, FileName, Arg2, Overwrite) pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) sMessage = sLocation _ & " " & " " & .GetText("RANGEEXPORT", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) - Case CHARTEXPORTERROR ' SF_Chart.ExportToFile(Arg1Name, FileName, Arg2, Overwrite) + Case SHAPEEXPORTERROR ' SF_Shape.ExportToFile(Arg1Name, FileName, Arg2, Overwrite) pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) sMessage = sLocation _ - & " " & " " & .GetText("CHARTEXPORT", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) + & " " & " " & .GetText("SHAPEEXPORT", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) Case FORMDEADERROR ' SF_Form._IsStillAlive(FormName, DocumentName) sMessage = sLocation _ & " " & " " & .GetText("FORMDEAD", pvArgs(0), pvArgs(1)) diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba index 06048c3b598a..562f223ed828 100644 --- a/wizards/source/scriptforge/SF_PythonHelper.xba +++ b/wizards/source/scriptforge/SF_PythonHelper.xba @@ -859,6 +859,7 @@ Try: Case "SetArray" : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1)) Case "SetFormula" : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1)) Case "SetValue" : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1)) + Case "Shapes" : vReturn = vBasicObject.Shapes(vArgs(0), vArgs(1)) Case "Styles" : vReturn = vBasicObject.Styles(vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5)) Case "Toolbars" : vReturn = vBasicObject.Toolbars(vArgs(0)) End Select diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index f0db856873c8..5e2f0591592d 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -79,6 +79,7 @@ Private ConfigurationProvider _ Private PackageProvider As Object ' com.sun.star.comp.deployment.PackageInformationProvider Private MailService As Object ' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail Private GraphicExportFilter As Object ' com.sun.star.drawing.GraphicExportFilter +Private GraphicProvider As Object ' com.sun.star.graphic.GraphicProvider Private Toolkit As Object ' com.sun.star.awt.Toolkit Private ModuleUIConfigurationManagerSupplier _ As Object ' com.sun.star.ui.ModuleUIConfigurationManagerSupplier @@ -152,6 +153,7 @@ Private Sub Class_Initialize() Set PackageProvider = Nothing Set MailService = Nothing Set GraphicExportFilter = Nothing + Set GraphicProvider = Nothing Set Toolkit = Nothing Set ModuleUIConfigurationManagerSupplier = Nothing Set TransientDocument = Nothing @@ -879,6 +881,20 @@ Try: & "%5: An identifier " _ & "%6: A file name" _ ) + ' SF_Calc.CreateShapeFromFile + .AddText( Context := "DUPLICATESHAPE" _ + , MsgId := "A shape with the same name exists already in the sheet. " _ + & "« %1 » = %2 " _ + & "« %3 » = %4 " _ + & "« %5 » = %6 " _ + , Comment := "SF_Calc CreateShapeFromFile " _ + & "%1: An identifier " _ + & "%2: A string " _ + & "%3: An identifier " _ + & "%4: A string " _ + & "%5: An identifier " _ + & "%6: A file name" _ + ) ' SF_Calc.ExportRangeToFile .AddText( Context := "RANGEEXPORT" _ , MsgId := "The given range could not be exported. " _ @@ -891,13 +907,13 @@ Try: & "%3: An identifier " _ & "%4: True or False " _ ) - ' SF_Chart.ExportToFile - .AddText( Context := "CHARTEXPORT" _ - , MsgId := "The chart could not be exported. " _ + ' SF_Shape.ExportToFile + .AddText( Context := "SHAPEEXPORT" _ + , MsgId := "The shape could not be exported. " _ & "Either the destination file must not be overwritten, or it has a read-only attribute set. " _ & "%1 = '%2' " _ & "%3 = %4" _ - , Comment := "SF_Chart.ExportToFile error message " _ + , Comment := "SF_Shape.ExportToFile error message " _ & "%1: An identifier " _ & "%2: A file name " _ & "%3: An identifier " _ diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba index 3a11ea3f20d6..edc07568329c 100644 --- a/wizards/source/scriptforge/SF_Utils.xba +++ b/wizards/source/scriptforge/SF_Utils.xba @@ -403,6 +403,11 @@ Dim oDefaultContext As Object Set .GraphicExportFilter = CreateUnoService("com.sun.star.drawing.GraphicExportFilter") End If Set _GetUNOService = .GraphicExportFilter + Case "GraphicProvider" + If IsEmpty(.GraphicProvider) Or IsNull(.GraphicProvider) Then + Set .GraphicProvider = CreateUnoService("com.sun.star.graphic.GraphicProvider") + End If + Set _GetUNOService = .GraphicProvider 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 0072162a7c62..b60dc9f4a9f8 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 " "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI " -"POT-Creation-Date: 2025-08-04 11:05:34 " +"POT-Creation-Date: 2025-11-12 16:40:58 " "PO-Revision-Date: YYYY-MM-DD HH:MM:SS " "Last-Translator: FULL NAME <EMAIL@ADDRESS> " "Language-Team: LANGUAGE <EMAIL@ADDRESS> " @@ -165,23 +165,6 @@ msgid "" "function does not exist or its arguments are invalid." 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. " -"Either the destination file must not be overwritten, or it has a " -"read-only attribute set. " -" " -"%1 = '%2' " -"%3 = %4" -msgstr "" - #. SF_DialogControl property setting #. %1: An identifier #. %2: An identifier @@ -416,6 +399,24 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_Calc CreateShapeFromFile +#. %1: An identifier +#. %2: A string +#. %3: An identifier +#. %4: A string +#. %5: An identifier +#. %6: A file name +#, kde-format +msgctxt "DUPLICATESHAPE" +msgid "" +"A shape with the same name exists already in the sheet. " +" " +"« %1 » = %2 " +"« %3 » = %4 " +"« %5 » = %6 " +"" +msgstr "" + #. SF_Calc InsertSheet #. %1: An identifier #. %2: A string @@ -781,6 +782,23 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_Shape.ExportToFile error message +#. %1: An identifier +#. %2: A file name +#. %3: An identifier +#. %4: True or False +#. +#, kde-format +msgctxt "SHAPEEXPORT" +msgid "" +"The shape could not be exported. " +"Either the destination file must not be overwritten, or it has a " +"read-only attribute set. " +" " +"%1 = '%2' " +"%3 = %4" +msgstr "" + #. SF_Database can't interpret SQL statement #. %1: The statement #, kde-format diff --git a/wizards/source/scriptforge/po/en.po b/wizards/source/scriptforge/po/en.po index 0072162a7c62..b60dc9f4a9f8 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 " "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI " -"POT-Creation-Date: 2025-08-04 11:05:34 " +"POT-Creation-Date: 2025-11-12 16:40:58 " "PO-Revision-Date: YYYY-MM-DD HH:MM:SS " "Last-Translator: FULL NAME <EMAIL@ADDRESS> " "Language-Team: LANGUAGE <EMAIL@ADDRESS> " @@ -165,23 +165,6 @@ msgid "" "function does not exist or its arguments are invalid." 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. " -"Either the destination file must not be overwritten, or it has a " -"read-only attribute set. " -" " -"%1 = '%2' " -"%3 = %4" -msgstr "" - #. SF_DialogControl property setting #. %1: An identifier #. %2: An identifier @@ -416,6 +399,24 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_Calc CreateShapeFromFile +#. %1: An identifier +#. %2: A string +#. %3: An identifier +#. %4: A string +#. %5: An identifier +#. %6: A file name +#, kde-format +msgctxt "DUPLICATESHAPE" +msgid "" +"A shape with the same name exists already in the sheet. " +" " +"« %1 » = %2 " +"« %3 » = %4 " +"« %5 » = %6 " +"" +msgstr "" + #. SF_Calc InsertSheet #. %1: An identifier #. %2: A string @@ -781,6 +782,23 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_Shape.ExportToFile error message +#. %1: An identifier +#. %2: A file name +#. %3: An identifier +#. %4: True or False +#. +#, kde-format +msgctxt "SHAPEEXPORT" +msgid "" +"The shape could not be exported. " +"Either the destination file must not be overwritten, or it has a " +"read-only attribute set. " +" " +"%1 = '%2' " +"%3 = %4" +msgstr "" + #. SF_Database can't interpret SQL statement #. %1: The statement #, kde-format diff --git a/wizards/source/scriptforge/po/fr.po b/wizards/source/scriptforge/po/fr.po index 275b50928f4b..8c4ed190dd06 100644 --- a/wizards/source/scriptforge/po/fr.po +++ b/wizards/source/scriptforge/po/fr.po @@ -16,7 +16,7 @@ msgstr "" "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?" "product=LibreOffice&bug_status=UNCONFIRMED&component=UI " "POT-Creation-Date: 2025-01-11 13:09:17 " -"PO-Revision-Date: 2025-01-12 16:42+0100 " +"PO-Revision-Date: 2025-11-12 16:55+0100 " "Last-Translator: Jean-Pierre Ledure " "Language-Team: LANGUAGE <EMAIL@ADDRESS> " "Language: fr " @@ -24,7 +24,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8 " "Content-Transfer-Encoding: 8bit " "Plural-Forms: nplurals=2; plural=(n > 1); " -"X-Generator: Poedit 3.0.1 " +"X-Generator: Poedit 3.4.2 " "X-Accelerator-Marker: ~ " #. SF_Array.ExtractColumn (...) error message @@ -57,8 +57,8 @@ msgid "" " « From » = %2 " " « UpTo » = %3" msgstr "" -"Les indices fournis pour la zone à trancher ne rentrent pas dans les limites " -"de la matrice. " +"Les indices fournis pour la zone à trancher ne rentrent pas dans les limites de " +"la matrice. " " " " « Array_1D » = %1 " " « From » = %2 " @@ -111,8 +111,8 @@ msgid "" "The opening of the Base document failed. " "Something must be wrong with some arguments. " " " -"Either the file does not exist, or the file is not registered under the " -"given name. " +"Either the file does not exist, or the file is not registered under the given " +"name. " " " "%1 = '%2' " "%3 = '%4'" @@ -120,8 +120,8 @@ msgstr "" "L'ouverture du document Base a échoué. " "Un des arguments doit être erroné. " " " -"Soit le fichier n'existe pas, soit le fichier n'est pas enregistré sous le " -"nom fourni. " +"Soit le fichier n'existe pas, soit le fichier n'est pas enregistré sous le nom " +"fourni. " " " "%1 = '%2' " "%3 = '%4'" @@ -190,16 +190,16 @@ msgstr "" #, kde-format msgctxt "CALCFORMNOTFOUND" msgid "" -"The requested form could not be found in the Calc sheet. The given index is " -"off-limits. " +"The requested form could not be found in the Calc sheet. The given index is off-" +"limits. " " " "The concerned Calc document is '%3'. " " " "The name of the sheet = '%2' " "The index = %1." msgstr "" -"Le formulaire recherché est introuvable dans la feuille Calc. L'indice " -"fourni est hors-limites. " +"Le formulaire recherché est introuvable dans la feuille Calc. L'indice fourni " +"est hors-limites. " " " "Le document Calc concerné est '%3'. " " " @@ -211,29 +211,29 @@ msgstr "" #, kde-format msgctxt "CALCFUNC" msgid "" -"The Calc '%1' function encountered an error. Either the given function does " -"not exist or its arguments are invalid." +"The Calc '%1' function encountered an error. Either the given function does not " +"exist or its arguments are invalid." msgstr "" "La fonction Calc '%1' a rencontré une erreur. Soit la fonction n'existe pas, " "soit les arguments fournis sont invalides." -#. SF_Chart.ExportToFile error message +#. SF_Shape.ExportToFile error message #. %1: An identifier #. %2: A file name #. %3: An identifier #. %4: True or False #. #, kde-format -msgctxt "CHARTEXPORT" +msgctxt "SHAPEEXPORT" msgid "" -"The chart could not be exported. " +"The shape could not be exported. " "Either the destination file must not be overwritten, or it has a read-only " "attribute set. " " " "%1 = '%2' " "%3 = %4" msgstr "" -"Le graphique n'a pas pu être exporté. " +"La forme n'a pas pu être exportée. " "Soit le fichier de destination ne peut pas être écrasé, soit il comporte " "l'attribut lecture seule. " " " @@ -249,12 +249,11 @@ msgstr "" msgctxt "CONTROLTYPE" msgid "" "The control '%1' in dialog '%2' is of type '%3'. " -"The property or method '%4' is not applicable on that type of dialog " -"controls." +"The property or method '%4' is not applicable on that type of dialog controls." msgstr "" "Le contrôle '%1' dans le dialogue '%2' est du type '%3'. " -"La propriété ou la méthode '%4' n'est pas applicable pour ce type de " -"contrôles de dialogue." +"La propriété ou la méthode '%4' n'est pas applicable pour ce type de contrôles " +"de dialogue." #. SF_Array.ImportFromCSVFile error message #. %1: a file name @@ -336,8 +335,7 @@ msgstr "" #, kde-format msgctxt "DIALOGNOTFOUND" msgid "" -"The requested dialog could not be located in the given container or " -"library. " +"The requested dialog could not be located in the given container or library. " "« %1 » = %2 " "« %3 » = %4 " "« %5 » = %6 " @@ -418,8 +416,8 @@ msgid "" "The opening of the document failed. " "Something must be wrong with some arguments. " " " -"Either the file does not exist, or the password is wrong, or the given " -"filter is invalid. " +"Either the file does not exist, or the password is wrong, or the given filter " +"is invalid. " " " "%1 = '%2' " "%3 = '%4' " @@ -428,8 +426,8 @@ msgstr "" "L'ouverture du document a échoué. " "Un des arguments doit être erroné. " " " -"Soit le fichier n'existe pas, soit le mot de passe n'est pas valable, soit " -"le filtre fourni est invalide. " +"Soit le fichier n'existe pas, soit le mot de passe n'est pas valable, soit le " +"filtre fourni est invalide. " " " "%1 = '%2' " "%3 = '%4' " @@ -441,8 +439,8 @@ msgstr "" #, kde-format msgctxt "DOCUMENTREADONLY" msgid "" -"You tried to edit a document which is not modifiable. The document has not " -"been changed. " +"You tried to edit a document which is not modifiable. The document has not been " +"changed. " " " "« %1 » = %2" msgstr "" @@ -465,9 +463,9 @@ msgid "" "%1 = '%2'" msgstr "" "Le document n'a pas pu être enregistré. " -"Soit le document a été ouvert en lecture seule, soit le fichier de " -"destination comporte l'attribut lecture seule, soit le fichier de " -"destination est indéfini. " +"Soit le document a été ouvert en lecture seule, soit le fichier de destination " +"comporte l'attribut lecture seule, soit le fichier de destination est " +"indéfini. " " " "%1 = '%2'" @@ -482,8 +480,8 @@ msgstr "" msgctxt "DOCUMENTSAVEAS" msgid "" "The document could not be saved. " -"Either the document must not be overwritten, or the destination file has a " -"read-only attribute set, or the given filter is invalid. " +"Either the document must not be overwritten, or the destination file has a read-" +"only attribute set, or the given filter is invalid. " " " "%1 = '%2' " "%3 = %4 " @@ -547,12 +545,34 @@ msgid "" " " "« %1 » = %2" msgstr "" -"L'insertion d'une nouvelle clé dans le dictionnaire a échoué parce que la " -"clé existe déjà. " +"L'insertion d'une nouvelle clé dans le dictionnaire a échoué parce que la clé " +"existe déjà. " "Notez que la comparaison entre clés n'est PAS sensible à la casse. " " " "« %1 » = %2" +#. SF_Calc CreateShapeFromFile +#. %1: An identifier +#. %2: A string +#. %3: An identifier +#. %4: A string +#. %5: An identifier +#. %6: A file name +#, kde-format +msgctxt "DUPLICATESHAPE" +msgid "" +"A shape with the same name exists already in the sheet. " +" " +"« %1 » = %2 " +"« %3 » = %4 " +"« %5 » = %6 " +msgstr "" +"Une forme portant le même nom est déjà présente dans la feuille. " +" " +"« %1 » = %2 " +"« %3 » = %4 " +"« %5 » = %6 " + #. SF_Calc InsertSheet #. %1: An identifier #. %2: A string @@ -576,13 +596,13 @@ msgstr "" #, kde-format msgctxt "ENDOFFILE" msgid "" -"The requested file read operation could not be completed because an " -"unexpected end-of-file was encountered. " +"The requested file read operation could not be completed because an unexpected " +"end-of-file was encountered. " " " "File name = '%1'" msgstr "" -"L'opération de lecture du fichier a échoué suite à la survenance " -"inattendue de la fin du fichier. " +"L'opération de lecture du fichier a échoué suite à la survenance inattendue de " +"la fin du fichier. " " " "Nom du fichier = '%1'" @@ -628,8 +648,8 @@ msgstr "" #, kde-format msgctxt "FILENOTOPEN" msgid "" -"The requested file operation could not be executed because the file was " -"closed previously. " +"The requested file operation could not be executed because the file was closed " +"previously. " " " "File name = '%1'" msgstr "" @@ -644,8 +664,8 @@ msgstr "" #, kde-format msgctxt "FILEOPENMODE" msgid "" -"The requested file operation could not be executed because it is " -"incompatible with the mode in which the file was opened. " +"The requested file operation could not be executed because it is incompatible " +"with the mode in which the file was opened. " " " "File name = '%1' " "Open mode = %2" @@ -683,8 +703,8 @@ msgid "" " " "« %1 » = %2" msgstr "" -"« %1 » contient le nom d'un fichier ou d'un répertoire existant. " -"L'opération est rejetée. " +"« %1 » contient le nom d'un fichier ou d'un répertoire existant. L'opération " +"est rejetée. " " " "« %1 » = %2" @@ -700,21 +720,21 @@ msgid "" "The property or method '%4' is not applicable on that type of form controls." msgstr "" "Le contrôle '%1' dans le formulaire '%2' est du type '%3'. " -"La propriété ou la méthode '%4' n'est pas applicable pour ce type de " -"contrôles de formulaire." +"La propriété ou la méthode '%4' n'est pas applicable pour ce type de contrôles " +"de formulaire." #. SF_Dialog._IsStillAlive error message #. %1: An identifier%2: A file name #, kde-format msgctxt "FORMDEAD" msgid "" -"The requested action could not be executed because the form is not open or " -"the document was closed inadvertently. " +"The requested action could not be executed because the form is not open or the " +"document was closed inadvertently. " " " "The concerned form is '%1' in document '%2'." msgstr "" -"L'action demandée n'a pas pu se faire, soit parce que le formulaire n'est " -"pas ouvert, soit suite à la fermeture du document. " +"L'action demandée n'a pas pu se faire, soit parce que le formulaire n'est pas " +"ouvert, soit suite à la fermeture du document. " " " "Le formulaire concerné est '%1' contenu dans le document '%2'." @@ -741,8 +761,8 @@ msgid "" "The insertion or the update of an entry into a dictionary failed because the " "given key contains only spaces." msgstr "" -"L'insertion ou la mise à jour d'une entrée du dictionnaire a échoué parce " -"que la clé fournie ne contient que des espaces." +"L'insertion ou la mise à jour d'une entrée du dictionnaire a échoué parce que " +"la clé fournie ne contient que des espaces." #. Logfile record #, kde-format @@ -760,12 +780,12 @@ msgstr "Souhaitez-vous recevoir davantage d'informations sur la méthode '%1' ?" #. SF_Dataset can't read field values or store field updates msgctxt "NOCURRENTRECORD" msgid "" -"A database record could not be retrieved, inserted or updated by the " -"database system. " +"A database record could not be retrieved, inserted or updated by the database " +"system. " "The current record could not be determined." msgstr "" -"Un enregistrement de la base de données n'a pas pu être retrouvé, inséré " -"ou mis à jour par son système de gestion. " +"Un enregistrement de la base de données n'a pas pu être retrouvé, inséré ou mis " +"à jour par son système de gestion. " "L'enregistrement courant n'a pu être déterminé." #. SF_FileSystem copy/move/delete error message @@ -779,9 +799,8 @@ msgid "" " " "« %1 » = %2" msgstr "" -"Lorsque « %1 » contient des caractères de remplacement, au moins un fichier " -"ou répertoire doit correspondre au filtre. Autrement l'opération est " -"rejetée. " +"Lorsque « %1 » contient des caractères de remplacement, au moins un fichier ou " +"répertoire doit correspondre au filtre. Autrement l'opération est rejetée. " " " "« %1 » = %2" @@ -857,8 +876,8 @@ msgid "" "« %9 » = %10 " "« %11 » = %12" msgstr "" -"La plage de cellules calculée tombe en-dehors des limites de la feuille ou " -"est dénuée de sens. " +"La plage de cellules calculée tombe en-dehors des limites de la feuille ou est " +"dénuée de sens. " " " "« %1 » = %2 " "« %3 » = %4 " @@ -878,8 +897,8 @@ msgid "" " " "« %1 » = %2" msgstr "" -"Vous avez tenté de créer un nouveau fichier qui existe déjà. Son écrasement " -"a été refusé. " +"Vous avez tenté de créer un nouveau fichier qui existe déjà. Son écrasement a " +"été refusé. " " " "« %1 » = %2" @@ -899,8 +918,8 @@ msgid "" " %3 : « %4 » " " %5 : « %6 »" msgstr "" -"Le Gestionnaire de Pages n'a pas pu être mis en place à cause de " -"l'incohérence des arguments. " +"Le Gestionnaire de Pages n'a pas pu être mis en place à cause de l'incohérence " +"des arguments. " " " " %1 : « %2 » " " %3 : « %4 » " @@ -908,8 +927,7 @@ msgstr "" #. SF_Exception.PythonShell error messageAPSO: to leave unchanged msgctxt "PYTHONSHELL" -msgid "" -"The APSO extension could not be located in your LibreOffice installation." +msgid "The APSO extension could not be located in your LibreOffice installation." msgstr "" "L'extension APSO n'a pas pu être localisée dans votre installation de " "LibreOffice." @@ -948,8 +966,8 @@ msgid "" " " "« %1 » = %2" msgstr "" -"Copier ou déplacer un fichier vers une destination accessible en lecture " -"seule, ainsi que supprimer un tel fichier ou répertoire sont interdits. " +"Copier ou déplacer un fichier vers une destination accessible en lecture seule, " +"ainsi que supprimer un tel fichier ou répertoire sont interdits. " " " "« %1 » = %2" @@ -971,8 +989,8 @@ msgid "" "Field value : « %2 » " "Field type : « %3 »" msgstr "" -"Un enregistrement n'a pas pu être inséré ou modifié par le système de " -"gestion de la base de données. " +"Un enregistrement n'a pas pu être inséré ou modifié par le système de gestion " +"de la base de données. " "Causes possibles : " "- le champ ciblé n'est pas modifiable " "- une valeur [NULL] a été fournie, ce qui est interdit pour le champ " @@ -1026,8 +1044,8 @@ msgstr "" "La bibliothèque '%3' et ses services n'ont pas pu être chargés. " "La raison en est inconnue. " "Cependant, la vérification de la fonction '%3.SF_Services." -"RegisterScriptServices()' et de ses valeurs de retour peut être un bon point " -"de départ pour investiguer. " +"RegisterScriptServices()' et de ses valeurs de retour peut être un bon point de " +"départ pour investiguer. " " " "« %1 » = %2" @@ -1036,14 +1054,13 @@ msgstr "" #, kde-format msgctxt "SQLSYNTAX" msgid "" -"An SQL statement could not be interpreted or executed by the database " -"system. " +"An SQL statement could not be interpreted or executed by the database system. " "Check its syntax, table and/or field names, ... " " " "SQL Statement : « %1 »" msgstr "" -"Une instruction SQL n'a pas pu être interprétée ou exécutée par le système " -"de gestion de la base de données. " +"Une instruction SQL n'a pas pu être interprétée ou exécutée par le système de " +"gestion de la base de données. " "Vérifiez sa syntaxe, les noms de tables et de champs, ... " " " "L'instruction SQL : « %1 »" @@ -1055,8 +1072,7 @@ msgstr "" #, kde-format msgctxt "SQLSYNTAX2" msgid "" -"An SQL statement could not be interpreted or executed by the database " -"system. " +"An SQL statement could not be interpreted or executed by the database system. " "Check its syntax, table and/or field names, ... " " " "SQL Statement : « %1 » " @@ -1064,8 +1080,8 @@ msgid "" " « %2 » " " « %3 »" msgstr "" -"Une instruction SQL n'a pas pu être interprétée ou exécutée par le système " -"de gestion de la base de données. " +"Une instruction SQL n'a pas pu être interprétée ou exécutée par le système de " +"gestion de la base de données. " "Vérifiez sa syntaxe, les noms de tables et de champs, ... " " " "L'instruction SQL : « %1 » " @@ -1103,8 +1119,7 @@ msgid "" "The control '%1' in dialog '%2' is not a multiline text field. " "The requested method could not be executed." msgstr "" -"Le contrôle '%1' dans le dialogue '%2' n'est pas un champ texte multi-" -"lignes. " +"Le contrôle '%1' dans le dialogue '%2' n'est pas un champ texte multi-lignes. " "La méthode demandée n'a pas été executée." #. SFUnitTest could not locate the library gven as argument @@ -1243,8 +1258,7 @@ msgstr " « %1 » doit comporter exactement %2 dimension(s)." msgctxt "VALIDATEERROR" msgid "A serious error has been detected in your code on argument : « %1 »." msgstr "" -"Une erreur grave a été détectée dans votre code concernant l'argument : « %1 " -"»." +"Une erreur grave a été détectée dans votre code concernant l'argument : « %1 »." #. SF_Utils._ValidateFile error message #. %1: Wrong argument name @@ -1266,11 +1280,11 @@ msgstr " « %1 » doit être un nom de fichier ou de répertoire valide." #, kde-format msgctxt "VALIDATEFILESYS" msgid "" -" « %1 » must be a valid file or folder name expressed in the " -"operating system native notation." +" « %1 » must be a valid file or folder name expressed in the operating " +"system native notation." msgstr "" -" « %1 » doit être un nom de fichier ou de répertoire valide exprimé " -"dans la notation propre au système d'exploitation." +" « %1 » doit être un nom de fichier ou de répertoire valide exprimé dans " +"la notation propre au système d'exploitation." #. SF_Utils._ValidateFile error message #. %1: Wrong argument name @@ -1281,8 +1295,8 @@ msgid "" " « %1 » must be a valid file or folder name expressed in the portable " "URL notation." msgstr "" -" « %1 » doit être un nom de fichier ou de répertoire valide exprimé " -"dans la notation portable dite URL." +" « %1 » doit être un nom de fichier ou de répertoire valide exprimé dans " +"la notation portable dite URL." #. SF_Utils._Validate error message #. %1: Wrong argument name @@ -1337,11 +1351,11 @@ msgstr " « %1 » admet seulement une des valeurs suivantes : %2" #, kde-format msgctxt "VALIDATEWILDCARD" msgid "" -" « %1 » may contain one or more wildcard characters (?, *) in its " -"last path component only." +" « %1 » may contain one or more wildcard characters (?, *) in its last " +"path component only." msgstr "" -" « %1 » peut contenir un ou plusieurs caractères de remplacement (?, " -"*) exclusivement dans la dernière composante de son chemin complet." +" « %1 » peut contenir un ou plusieurs caractères de remplacement (?, *) " +"exclusivement dans la dernière composante de son chemin complet." #. SF_Utils.Validate error message msgctxt "VALIDATIONRULES" @@ -1354,8 +1368,8 @@ msgstr " Règles de validation :" #, kde-format msgctxt "WRITERFORMNOTFOUND" msgid "" -"The requested form could not be found in the Writer document. The given " -"index is off-limits. " +"The requested form could not be found in the Writer document. The given index " +"is off-limits. " " " "The concerned Writer document is '%2'. " " " diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 93d53787b5a5..f92b20f29047 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -2647,6 +2647,9 @@ class SFDocuments: return self.ExecMethod(self.vbMethod, 'CreatePivotTable', pivottablename, sourcerange, targetcell, datafields, rowfields, columnfields, filterbutton, rowtotals, columntotals) + def CreateShapeFromFile(self, shapename, imagefile, range = '~.~', aslink = False): + return self.ExecMethod(self.vbMethod, 'CreateShapeFromFile', shapename, imagefile, range, aslink) + def DAvg(self, range): return self.ExecMethod(self.vbMethod, 'DAvg', range) @@ -2746,6 +2749,9 @@ class SFDocuments: def SetValue(self, targetrange, value): return self.ExecMethod(self.vbMethod + self.flgArrayArg, 'SetValue', targetrange, value) + def Shapes(self, sheetname, shapename = ''): + return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Shapes', sheetname, shapename) + def ShiftDown(self, range, wholerow = False, rows = 0): return self.ExecMethod(self.vbMethod, 'ShiftDown', range, wholerow, rows) @@ -2777,10 +2783,39 @@ class SFDocuments: servicesynonyms = () serviceproperties = dict() + # ######################################################################### + # SF_Shape CLASS + # ######################################################################### + class SF_Shape(SFServices): + """ + The SF_Shape module is focused on the description of shapes/images/drawing objects stored in documents. + In the actual release only shapes in Calc sheets are considered. + """ + # Mandatory class properties for service registration + serviceimplementation = 'basic' + servicename = 'SFDocuments.Shape' + servicesynonyms = () + serviceproperties = dict(XRectangle = 1, XShape = 0) + + def Anchor(self, anchortype, cell = '~.A1'): + return self.ExecMethod(self.vbMethod, 'Anchor', anchortype, cell) + + def ExportToFile(self, filename, imagetype = 'png', overwrite = False): + return self.ExecMethod(self.vbMethod, 'ExportToFile', filename, imagetype, overwrite) + + def Pick(self): + return self.ExecMethod(self.vbMethod, 'Pick') + + def Resize(self, xpos = -1, ypos = -1, width = -1, height = -1): + return self.ExecMethod(self.vbMethod, 'Resize', xpos, ypos, width, height) + + def Rotate(self, angle, pivot = ''): + return self.ExecMethod(self.vbMethod, 'Rotate', angle, pivot) + # ######################################################################### # SF_Chart CLASS # ######################################################################### - class SF_Chart(SFServices): + class SF_Chart(SF_Shape, SFServices): """ The SF_Chart module is focused on the description of chart documents stored in Calc sheets. @@ -2793,15 +2828,9 @@ class SFDocuments: servicesynonyms = () serviceproperties = dict(ChartType = 2, Deep = 2, Dim3D = 2, Exploded = 2, Filled = 2, Legend = 2, Percent = 2, Stacked = 2, Title = 2, - XChartObj = 0, XDiagram = 0, XShape = 0, XTableChart = 0, + XChartObj = 0, XDiagram = 0, XRectangle = 1, XShape = 0, XTableChart = 0, XTitle = 2, YTitle = 2) - def ExportToFile(self, filename, imagetype = 'png', overwrite = False): - return self.ExecMethod(self.vbMethod, 'ExportToFile', filename, imagetype, overwrite) - - def Resize(self, xpos = -1, ypos = -1, width = -1, height = -1): - return self.ExecMethod(self.vbMethod, 'Resize', xpos, ypos, width, height) - # ######################################################################### # SF_Form CLASS # ######################################################################### diff --git a/wizards/source/scriptforge/python/scriptforge.pyi b/wizards/source/scriptforge/python/scriptforge.pyi index c7616a6d1667..948528644c31 100644 --- a/wizards/source/scriptforge/python/scriptforge.pyi +++ b/wizards/source/scriptforge/python/scriptforge.pyi @@ -80,6 +80,7 @@ DOCUMENT = SFDocuments.SF_Document BASE = SFDocuments.SF_Base CALC = SFDocuments.SF_Calc CALCREFERENCE = SFDocuments.SF_CalcReference +SHAPE = SFDocuments.SF_Shape CHART = SFDocuments.SF_Chart FORM = SFDocuments.SF_Form FORMCONTROL = SFDocuments.SF_FormControl @@ -5758,6 +5759,30 @@ class SFDocuments: """ ... + def CreateShapeFromFile(self, + shapename: str, + imagefile: FILE, + range: RANGE = ..., + aslink: bool = ...) -> SHAPE | None: + """ + Insert a new shape in a Calc sheet from a disk file containing its image. + The shape will be positioned on, anchored to the given range, + and sized according to the image original size. + Args + ``shapename``: the user-defined name of the new shape. + + ``imagefile``: the input file in the ``FileSystem`` notation. + + ``range``: the top-left position of the new shape. + It may be a cell range, but only the top-left cell will be considered. + The default is the top-left cell of the current selection. + + ``aslink``: When ``True`` (default = ``False``), the file is not embedded in the document. + Returns + A new SF_Shape class instance or None. + """ + ... + def DAvg(self, range: RANGE) -> float: """ Get the number of the numeric values stored in the given range, excluding values from filtered @@ -6409,6 +6434,23 @@ class SFDocuments: A string representing the modified area as a range of cells. """ ... + + def Shapes(self, sheetname: SHEETNAME, shapename: str = ...) -> SHAPE | tuple[str, ...]: + """ + Depending on the parameters provided this method will return: + + - A tuple with the names of all the shapes contained in a given sheet (if the ``shapename`` argument is absent). + - A ``SFDocuments.Shape`` service instance representing the shape specified as argument. + + Args + ``sheetname``: the name of the sheet, as a string, from which the shape(s) will be retrieved. + + ``shapename``: the name corresponding to a shape stored in the specified sheet. + If this argument is absent, the method will return a list with the names of all shapes available + in the sheet. + """ + ... + def ShiftDown(self, range: RANGE, wholerow: bool = ..., rows: int = ...) -> RANGE: """ Moves a given range of cells downwards by inserting empty rows. @@ -6544,6 +6586,104 @@ class SFDocuments: The SF_CalcReference class has as unique role to hold sheet and range references. """ + # ######################################################################### + # SF_Shape CLASS + # ######################################################################### + class SF_Shape(SFServices): + """ + The SF_Shape module is focused on the description of shapes/images/drawing objects stored in documents. + In the actual release only shapes in Calc sheets are considered. + """ + + XRectangle: UNO + """ A com.sun.star.awt.XRectangle object delimiting the shape. Distances are expressed in 1/100th mm. """ + XShape: UNO + """ Returns the ``com.sun.star.drawing.XShape`` object representing the shape. """ + + def Anchor(self, + anchortype: Literal['CELL', 'CELLRESIZE', 'PAGE'], + cell: RANGE = ... + ) -> bool: + """ + Define the anchor type and the cell to which the shape has to be anchored. + Args + ``ancortype``: 'CELL' = the shape is anchored "to cell", + 'CELLRESIZE' = the shape is anchored "to cell (resize with cell)", + 'PAGE' = the shape is anchored to the sheet. + + ``cell``: a unique cell or a cell range in the sheet where the shape is located. + Only the top-left cell of a range will be considered. + The argument is ignored and may be omitted when ``anchortype`` = 'PAGE'. + Returns + ``True`` when successful. + """ + ... + + def ExportToFile(self, + filename: FILE, + imagetype: Literal['gif', 'jpeg', 'png', 'svg', 'tiff'] = ..., + overwrite: bool = ... + ) -> bool: + """ + Saves the shape as an image file in a specified location. + Args + ``filename``: identifies the path and file name where the image will be saved. + It must follow the notation defined in ``SF_FileSystem.FileNaming``. + + ``imagetype``: the name of the image type to be created. + The following values are accepted: ``gif, jpeg, png`` (default), ``svg`` and ``tiff``. + + ``overwrite``: specifies if the destination file may be overwritten. Defaults to ``False``. + Returns + ``True`` if the image file could be successfully created. + """ + ... + + def Pick(self) -> bool: + """ + Make the actual shape the current selection. + This allows to execute thereafter a menu command on the shape. + Returns + `True`` when successful. + """ + ... + + def Resize(self, xpos: int = ..., ypos: int = ..., width: int = ..., height: int = ...) -> bool: + """ + Changes the position of the shape in the current sheet and modifies its width and height. + Args + ``xpos``: specify the new ``X`` position of the chart. + + ``ypos``: specify the new ``Y`` position of the chart. + + ``width``: specify the new width of the chart. + + ``height``: specify the new height of the chart. + Returns + ``True`` if repositioning/resizing was successful. + Note + - All arguments are provided as integer values that correspond to ``1/100`` of a millimeter. + - Omitted arguments leave the corresponding actual values unchanged. + - Negative arguments are ignored. + """ + ... + + def Rotate(self, angle: int | float, pivot: str | tuple[int, int] = ...) -> bool: + """ + Rotate the shape using a given pivot point with a given angle. + Args + ``angle``: specify the magnitude of the rotation, expressed in degrees. + An angle may be positive or negative. Positive means counterclockwise. + It is to be understood as absolute vs. the usual X-axis orientation. + + ``pivot``: specify the point about which the rotation will take place. It can be + - either an array (x, y) being the coordinates of the pivot point in 1/100 mm. The origin (0, 0) is the top-left corner of the sheet where the shape is located. + - or, when the intent is to use the shape's natural pivot points, a string combining 2 of next uppercase characters (other characters are ignored): L(eft), R(ight), C(enter) and T(op), B(ottom), M(iddle). Default = 'CM'. + Returns + ``True`` when successful. + """ + ... + # ######################################################################### # SF_Chart CLASS # ######################################################################### @@ -6553,6 +6693,7 @@ class SFDocuments: stored in Calc sheets. With this service, many chart types and chart characteristics available in the user interface can be read or modified. + Charts are a special type of shapes. The "Chart" service is a subclass of the "Shape" service. """ ChartType: Literal['Pie', 'Bar', 'Donut', 'Column', 'Area', 'Line', 'XY', 'Bubble', 'Net'] @@ -6595,46 +6736,6 @@ class SFDocuments: """ Returns the ``com.sun.star.table.XTableChart`` object representing the data being displayed in the chart. """ - def ExportToFile(self, - filename: FILE, - imagetype: Literal['gif', 'jpeg', 'png', 'svg', 'tiff'] = ..., - overwrite: bool = ... - ) -> bool: - """ - Saves the chart as an image file in a specified location. - Args - ``filename``: identifies the path and file name where the image will be saved. - It must follow the notation defined in ``SF_FileSystem.FileNaming``. - - ``imagetype``: the name of the image type to be created. - The following values are accepted: ``gif, jpeg, png`` (default), ``svg`` and ``tiff``. - - ``overwrite``: specifies if the destination file can be overwritten. Defaults to ``False``. - Returns - ``True`` if the image file could be successfully created. - """ - ... - - def Resize(self, xpos: int = ..., ypos: int = ..., width: int = ..., height: int = ...) -> bool: - """ - Changes the position of the chart in the current sheet and modifies its width and height. - Args - ``xpos``: specify the new ``X`` position of the chart. - - ``ypos``: specify the new ``Y`` position of the chart. - - ``width``: specify the new width of the chart. - - ``height``: specify the new height of the chart. - Returns - ``True`` if repositioning/resizing was successful. - Note - - All arguments are provided as integer values that correspond to ``1/100`` of a millimeter. - - Omitted arguments leave the corresponding actual values unchanged. - - Negative arguments are ignored. - """ - ... - # ######################################################################### # SF_Form CLASS # ######################################################################### diff --git a/wizards/source/scriptforge/script.xlb b/wizards/source/scriptforge/script.xlb index a77ee4a07d5b..68efd282406a 100644 --- a/wizards/source/scriptforge/script.xlb +++ b/wizards/source/scriptforge/script.xlb @@ -1,24 +1,24 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="_CodingConventions"/> - <library:element library:name="SF_Session"/> - <library:element library:name="SF_Dictionary"/> - <library:element library:name="SF_Exception"/> - <library:element library:name="SF_UI"/> - <library:element library:name="SF_Services"/> - <library:element library:name="SF_PythonHelper"/> - <library:element library:name="SF_Platform"/> - <library:element library:name="SF_Array"/> - <library:element library:name="SF_TextStream"/> - <library:element library:name="SF_Utils"/> - <library:element library:name="SF_String"/> - <library:element library:name="_ModuleModel"/> + <library:element library:name="__License"/> + <library:element library:name="SF_Root"/> <library:element library:name="SF_SharedMemory"/> <library:element library:name="SF_L10N"/> <library:element library:name="SF_Region"/> - <library:element library:name="SF_Root"/> - <library:element library:name="__License"/> - <library:element library:name="SF_FileSystem"/> <library:element library:name="SF_Timer"/> + <library:element library:name="SF_FileSystem"/> + <library:element library:name="SF_Services"/> + <library:element library:name="SF_UI"/> + <library:element library:name="SF_Exception"/> + <library:element library:name="SF_Dictionary"/> + <library:element library:name="SF_Session"/> + <library:element library:name="_CodingConventions"/> + <library:element library:name="_ModuleModel"/> + <library:element library:name="SF_String"/> + <library:element library:name="SF_Utils"/> + <library:element library:name="SF_TextStream"/> + <library:element library:name="SF_Array"/> + <library:element library:name="SF_Platform"/> + <library:element library:name="SF_PythonHelper"/> </library:library> \ No newline at end of file diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index f3d16d6c96b7..fbec5e4873a1 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -102,6 +102,7 @@ Private Const DUPLICATESHEETERROR = "DUPLICATESHEETERROR" Private Const OFFSETADDRESSERROR = "OFFSETADDRESSERROR" Private Const CALCFORMNOTFOUNDERROR = "CALCFORMNOTFOUNDERROR" Private Const DUPLICATECHARTERROR = "DUPLICATECHARTERROR" +Private Const DUPLICATESHAPEERROR = "DUPLICATESHAPEERROR" Private Const RANGEEXPORTERROR = "RANGEEXPORTERROR" REM ============================================================= PRIVATE MEMBERS @@ -480,7 +481,7 @@ Public Function AlignRange(Optional ByVal TargetRange As Variant _ ''' Alignment: a string combining 1 or 2 of next characters (other characters are ignored): ''' L align Left ''' R align Right -''' C Center gorizontally +''' C Center horizontally ''' B align Bottom ''' M center vertically (Middle) ''' T align Top @@ -641,84 +642,9 @@ Public Function Charts(Optional ByVal SheetName As Variant _ ''' 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, True) Then GoTo Finally - End If + Charts = _Shapes(SheetName, ChartName, _IsChart := True) -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 ----------------------------------------------------------------------------- @@ -1457,7 +1383,7 @@ Try: ' 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 user-defined and internal names match ChartName + oChart.[_Super]._Shape.Name = ChartName ' Both user-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: @@ -1669,6 +1595,112 @@ Catch: GoTo Finally End Function ' SFDocuments.SF_Calc.CreatePivotTable +REM ----------------------------------------------------------------------------- +Public Function CreateShapeFromFile(Optional ByVal ShapeName As Variant _ + , Optional ByVal ImageFile As Variant _ + , Optional ByVal Range As Variant _ + , Optional AsLink As Variant _ + ) As Variant +''' Return a new Shape/image class instance +''' - positioned on and anchored to the given range +''' - sized according to the image original size +''' Args: +''' ShapeName: The user-defined name of the new Shape +''' ImageFile: The input file in the SF_FileSystem notation +''' Range: The top-left position of the new shape. +''' May be a cell range, but only the top-left cell will be considered +''' Default = top-left cell of the current selection +''' AsLink: When True (default = False), the file is not embedded in the document +''' Returns: +''' A new Shape service instance or Nothing when failed +''' Exceptions: +''' DUPLICATESHAPEERROR A Shape with the same name exists already in the given sheet +''' UNKNOWNFILEERROR The image file could not be located in the file system +''' Examples: +''' Dim oShape As Object +''' Set oShape = oDoc.CreateShapeFromFile("myShape", "C:\Image.png", "~.D5", AsLink := True) + +Dim oShape As Object ' Return value +Dim oXShape As Object ' com.sun.star.comp.sc.ScShapeObj +Dim vShapes As Variant ' List of pre-existing shapes +Dim oDrawPage As Object ' com.sun.star.drawing.XDrawPage +Dim oProvider As Object ' com.sun.star.graphic.GraphicProvider +Dim oRange As _Address ' A parsed range +Dim oPosition As New com.sun.star.awt.Point ' Shape target position +Dim oSize As New com.sun.star.awt.Size ' Shape target size +Dim FSO As Object : Set FSO = ScriptForge.SF_FileSystem +Dim sImageFile As String ' Alias of ImageFile + +Const cstThisSub = "SFDocuments.Calc.CreateShapeFromFile" +Const cstSubArgs = "ShapeName, ImageFile, [Range=""~.~""], [AsLink=False]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + Set oShape = Nothing + +Check: + If IsMissing(Range) Or IsEmpty(Range) Then Range = "~.~" + If IsMissing(AsLink) Or IsEmpty(AsLink) Then AsLink = False + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not _IsStillAlive(True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(ShapeName, "ShapeName", V_STRING) Then GoTo Finally + If Not ScriptForge.SF_Utils._ValidateFile(ImageFile, "ImageFile") Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Range, "Range", V_STRING) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(AsLink, "AsLink", ScriptForge.V_BOOLEAN) Then GoTo Finally + End If + + ' Does the input file exist ? + If Not FSO.FileExists(ImageFile) Then GoTo CatchNotExists + sImageFile = FSO._ConvertToUrl(ImageFile) + + ' Is the range a valid address ? + Set oRange = _ParseAddress(Range) + + ' No names conflict ? + vShapes = Shapes(oRange.SheetName) + If ScriptForge.SF_Array.Contains(vShapes, ShapeName, CaseSensitive := True) Then GoTo CatchDuplicate + +Try: + ' Initialize the new shape + Set oDrawPage = oRange.XSpreadsheet.getDrawPage() + Set oPosition = oRange.XCellRange.Position + + Set oProvider = ScriptForge.SF_Utils._GetUnoService("GraphicProvider") + Set oXShape = _Component.createInstance("com.sun.star.drawing.GraphicObjectShape") + With oXShape + .Name = ShapeName + .Graphic = oProvider.queryGraphic(Array( _ + ScriptForge.SF_Utils._MakePropertyValue("URL", sImageFile) _ + , ScriptForge.SF_Utils._MakePropertyValue("LoadAsLink", AsLink) _ + )) + .setPosition(oPosition) + End With + oDrawPage.add(oXShape) + + ' Size according to original image size + oSize.Width = CLng(oXShape.Graphic.Size100thMM.Width) + oSize.Height = CLng(oXShape.Graphic.Size100thMM.Height) + oXShape.setSize(oSize) + + ' Anchor the image to the top-left cell of the range + oXShape.Anchor = oRange.XCellRange.getCellByPosition(0, 0) + + ' Create the Shape and get the corresponding Shape instance + Set oShape = Shapes(oRange.SheetName, ShapeName) + +Finally: + Set CreateShapeFromFile = oShape + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +CatchDuplicate: + ScriptForge.SF_Exception.RaiseFatal(DUPLICATESHAPEERROR, "ShapeName", ShapeName, "SheetName", oRange.SheetName, "Document", [_Super]._FileIdent()) + GoTo Finally +CatchNotExists: + ScriptForge.SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "ImageFile", ImageFile) + GoTo Finally +End Function ' SFDocuments.SF_Calc.CreateShapeFromFile + REM ----------------------------------------------------------------------------- Public Function DAvg(Optional ByVal Range As Variant) As Double ''' Get the average of the numeric values stored in the given range @@ -2698,6 +2730,7 @@ Public Function Methods() As Variant , "CopyToCell" _ , "CopyToRange" _ , "CreateChart" _ + , "CreateShapeFromFile" _ , "DAvg" _ , "DCount" _ , "DecorateFont" _ @@ -2727,6 +2760,7 @@ Public Function Methods() As Variant , "SetCellStyle" _ , "SetFormula" _ , "SetValue" _ + , "Shapes" _ , "ShiftDown" _ , "ShiftLeft" _ , "ShiftRight" _ @@ -3712,6 +3746,26 @@ Catch: GoTo Finally End Function ' SFDocuments.SF_Calc.SetValue +REM ----------------------------------------------------------------------------- +Public Function Shapes(Optional ByVal SheetName As Variant _ + , Optional ByVal ShapeName As Variant _ + ) As Variant +''' Return either the list of shapes present in the given sheet or a shape object +''' Args: +''' SheetName: The name of an existing sheet +''' ShapeName: The user-defined name of the targeted shape or the zero-length string +''' Returns: +''' When ShapeName = "", return the list of the shapes present in the sheet, +''' otherwise, return a new shape service instance +''' Examples: +''' Dim oShape As Object +''' Set oShape = oDoc.Shapes("SheetX", "myShape") + +Try: + Shapes = _Shapes(SheetName, ShapeName, _IsChart := False) + +End Function ' SFDocuments.SF_Calc.Shapes + REM ----------------------------------------------------------------------------- Public Function ShiftDown(Optional ByVal Range As Variant _ , Optional ByVal WholeRow As Variant _ @@ -5385,10 +5439,10 @@ Try: Set oXRange = _ParseAddress(psRange).XCellRange ' Initialize the range area - With oRect + With oRect ' All units in 1/100mm .X = oXRange.Position.X .Y = oXRange.Position.Y - .Width = oXRange.Size.Width ' Size is in 1/100mm + .Width = oXRange.Size.Width .Height = oXRange.Size.Height End With @@ -5461,6 +5515,126 @@ Finally: Exit Sub End Sub ' SFDocuments.SF_Calc._RestoreSelections +REM ----------------------------------------------------------------------------- +Public Function _Shapes(Optional ByVal SheetName As Variant _ + , Optional ByVal ShapeName As Variant _ + , Optional ByVal _IsChart As Variant _ + ) As Variant +''' Return either the list of shapes present in the given sheet or a shape object +''' Args: +''' SheetName: The name of an existing sheet +''' ShapeName: The user-defined name of the targeted shape or the zero-length string +''' _IsChart: When True , only shapes containing a chart are considered, +''' when False (default), all shapes are considered, except those containing a chart +''' Returns: +''' When ShapeName = "", return the list of the shapes present in the sheet, +''' otherwise, return a new shape or chart service instance + +Dim vShapes As Variant ' Return value when array of shape/chart names +Dim oChart As Object ' A new chart instance +Dim oShape As Object ' A new shape instance. Is the superclass of a chart instance when _IsChart = True +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 sShapeName As String ' Some shape/chart name +Dim lCount As Long ' Counter for shapes among all drawing objects +Static oSession As Object ' Session service +Dim i As Long +Const cstChartShape = "com.sun.star.drawing.OLE2Shape" + +Dim cstThisSub As String : cstThisSub = "SFDocuments.Calc." & Iif(_IsChart, "Charts", "Shapes") +Dim cstSubArgs As String : cstSubArgs = "SheetName, [" & Iif(_IsChart, "ChartName", "ShapeName") & "=""""]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + vShapes = Array() + +Check: + If IsMissing(ShapeName) Or IsEmpty(ShapeName) Then ShapeName = "" + 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(ShapeName, Iif(_IsChart, "ChartName", "ShapeName"), V_STRING) Then GoTo Finally + End If + +Try: + ' Because the user can change it constantly, the list of valid shapes has to be rebuilt at each time + Set oSheet = _Component.getSheets.getByName(SheetName) + Set oDrawPage = oSheet.getDrawPage() + vShapes = Array() + lCount = -1 + + ' Explore shapes starting from the sheet draw page + For i = 0 To oDrawPage.Count - 1 + + Set oShape = Nothing + Set oChart = Nothing + + Set oNextShape = oDrawPage.getByIndex(i) + sShapeName = oNextShape.Name ' User-defined name + If Len(sShapeName) = 0 Then + If IsNull(oSession) Then Set oSession = CreateScriptService("ScriptForge.Session") + If oSession.HasUnoProperty(oNextShape, "PersistName") Then sShapeName = oNextShape.PersistName ' Internal name + End If + + ' Make anyway a SF_Shape instance, when name fits + If Len(ShapeName) > 0 And Len(sShapeName) > 0 And ShapeName = sShapeName Then + Set oShape = New SF_Shape + With oShape + Set .[Me] = oShape + Set .[_Parent] = [Me] + ._SheetName = SheetName + ._DrawIndex = i + ._ShapeName = ShapeName + Set ._Shape = oNextShape + ._IsChart = _IsChart + ._Initialize() + End With + + ' Retain charts only + If _IsChart And oNextShape.supportsService(cstChartShape) Then + Set oChart = New SF_Chart + With oChart + Set .[Me] = oChart + Set .[_Parent] = [Me] + ._SheetName = SheetName + ._ChartName = ShapeName + ._PersistentName = oNextShape.PersistName + Set ._Chart = oSheet.getCharts().getByName(._PersistentName) + Set ._ChartObject = ._Chart.EmbeddedObject + Set ._Diagram = ._ChartObject.Diagram + End With + ' Make the SF_Shape superclass: a chart is a subclass of a shape + Set oChart.[_Super] = oShape + End If + Exit For + + End If + + ' Build stack of shape names when shape or chart not found + If IsNull(oShape) And Len(sShapeName) > 0 Then + lCount = lCount + 1 + If UBound(vShapes) < 0 Then + vShapes = Array(sShapeName) + Else + ReDim Preserve vShapes(0 To UBound(vShapes) + 1) + vShapes(lCount) = sShapeName + End If + End If + Next i + + ' Raise error when shape/chart not found + If Len(ShapeName) > 0 And IsNull(oShape) Then + If Not ScriptForge.SF_Utils._Validate(ShapeName, Iif(_IsChart, "ChartName", "ShapeName"), V_STRING, vShapes, True) Then GoTo Finally + End If + +Finally: + If Len(ShapeName) = 0 Then _Shapes = vShapes Else Set _Shapes = Iif(_IsChart, oChart, oShape) + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDocuments.SF_Calc._Shapes + REM ----------------------------------------------------------------------------- Private Function _ValidateSheet(Optional ByRef pvSheetName As Variant _ , Optional ByVal psArgName As String _ diff --git a/wizards/source/sfdocuments/SF_Chart.xba b/wizards/source/sfdocuments/SF_Chart.xba index 0538fb8af758..e559f23f1011 100644 --- a/wizards/source/sfdocuments/SF_Chart.xba +++ b/wizards/source/sfdocuments/SF_Chart.xba @@ -46,15 +46,14 @@ REM ============================================================= PRIVATE MEMBER Private [Me] As Object Private [_Parent] As Object ' Parent Calc document +Private [_Super] As Object ' The SF_Shape superclass instance 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 @@ -68,13 +67,12 @@ REM ---------------------------------------------------------------------------- Private Sub Class_Initialize() Set [Me] = Nothing Set [_Parent] = Nothing + Set [_Super] = Nothing ObjectType = "CHART" ServiceName = "SFDocuments.Chart" _SheetName = "" - _DrawIndex = -1 _ChartName = "" _PersistentName = "" - Set _Shape = Nothing Set _Chart = Nothing Set _ChartObject = Nothing Set _Diagram = Nothing @@ -87,6 +85,7 @@ End Sub ' SFDocuments.SF_Chart Destructor REM ----------------------------------------------------------------------------- Public Function Dispose() As Variant + If Not IsNull([_Super]) Then [_Super].Dispose() Call Class_Terminate() Set Dispose = Nothing End Function ' SFDocuments.SF_Chart Explicit Destructor @@ -238,113 +237,23 @@ End Property ' SFDocuments.SF_Chart.YTitle (let) REM ----------------------------------------------------------------------------- Property Get XChartObj() As Variant ''' com.sun.star.lang.XComponent - ScChartObj - ChartType = _PropertyGet("XChartObj") + XChartObj = _PropertyGet("XChartObj") End Property ' SFDocuments.SF_Chart.XChartObj (get) REM ----------------------------------------------------------------------------- Property Get XDiagram() As Variant ''' com.sun.star.chart.XDiagram - ChartType = _PropertyGet("XDiagram") + XDiagram = _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") + XTableChart = _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 @@ -381,9 +290,8 @@ REM ---------------------------------------------------------------------------- Public Function Methods() As Variant ''' Return the list of public methods of the Chart service as an array + ' Methods are in the SF_Shape superclass Methods = Array( _ - "ExportToFile" _ - , "Resize" _ ) End Function ' SFDocuments.SF_Chart.Methods @@ -404,6 +312,7 @@ Public Function Properties() As Variant , "Title" _ , "XChartObj" _ , "XDiagram" _ + , "XRectangle" _ , "XShape" _ , "XTableChart" _ , "XTitle" _ @@ -412,71 +321,6 @@ Public Function Properties() As Variant 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 Boolean -''' 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 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 _ @@ -509,6 +353,44 @@ Catch: GoTo Finally End Function ' SFDocuments.SF_Chart.SetProperty +REM ======================================================= SUPERCLASS PROPERTIES + +REM ----------------------------------------------------------------------------- +Property Get XRectangle() As Variant + XRectangle = [_Super].GetProperty("XRectangle") +End Property ' SFDocuments.SF_Chart.XRectangle + +REM ----------------------------------------------------------------------------- +Property Get XShape() As Variant + XShape = [_Super].GetProperty("XShape") +End Property ' SFDocuments.SF_Chart.XShape + +REM ========================================================== SUPERCLASS METHODS + +REM ----------------------------------------------------------------------------- +Public Function ExportToFile(Optional ByVal FileName As Variant _ + , Optional ByVal ImageType As Variant _ + , Optional ByVal Overwrite As Variant _ + ) As Boolean + ExportToFile = [_Super].ExportToFile(FileName, ImageType, Overwrite) +End Function ' SFDocuments.SF_Chart.ExportToFile + +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 Boolean + Resize = [_Super].Resize(XPos, YPos, Width, Height) +End Function ' SFDocuments.SF_Chart.Resize + +REM ----------------------------------------------------------------------------- +Public Function Rotate(Optional ByVal Angle As Variant _ + , Optional ByRef Pivot As Variant _ + ) As Boolean + Rotate = [_Super].Rotate(Angle, Pivot) +End Function ' SFDocuments.SF_Chart.Rotate + REM =========================================================== PRIVATE FUNCTIONS REM ----------------------------------------------------------------------------- @@ -612,8 +494,6 @@ Const cstSubArgs = "" Set _PropertyGet = _ChartObject Case UCase("XDiagram") Set _PropertyGet = _Diagram - Case UCase("XShape") - Set _PropertyGet = _Shape Case UCase("XTableChart") Set _PropertyGet = _Chart Case Else @@ -804,9 +684,9 @@ Private Function _Repr() As String ''' Convert the Chart instance to a readable string, typically for debugging purposes (DebugPrint ...) ''' Args: ''' Return: -''' "[Chart]: Name - Type +''' "[Chart]: Name - Type" - _Repr = "[Chart]: " & ChartName & " - " & ChartType + _Repr = "[Chart]: " & _ChartName & " - " & ChartType End Function ' SFDocuments.SF_Chart._Repr diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba index aa05a67581a6..1b8822ddf77f 100644 --- a/wizards/source/sfdocuments/SF_Document.xba +++ b/wizards/source/sfdocuments/SF_Document.xba @@ -1750,6 +1750,60 @@ End Function ' SFDocuments.SF_Document.XStyle REM =========================================================== PRIVATE FUNCTIONS +REM ----------------------------------------------------------------------------- +Public Function _ConvertRectangle(ByRef poRect As Object _ + , ByVal piTargetUnit As Integer _ + ) As Object +''' Convert the X, Y, Width, Height dimensions expressed in 1/100mm units to a Rectangle expressed in pixels, +''' or vice-versa +''' Args: +''' poRect: a com.sun.star.awt.Rectangle +''' piTargetUnit: a A com.sun.star.util.MeasureUnit constant +''' Only PIXEL and MM_100TH are admitted. +''' Returns: +''' A com.sun.star.awt.Rectangle object after conversion of the position and size +''' Negative input values are not converted but set to zero + +Dim oComp As Object ' Component window com.sun.star.awt.XWindow +Dim oPoint As New com.sun.star.awt.Point ' The input position +Dim oSize As New com.sun.star.awt.Size ' The input size +Dim oRect As New com.sun.star.awt.Rectangle ' Return value + +Try: + Set oComp = _Component.CurrentController.ComponentWindow + + With poRect + ' Point part + If .X > 0 Then oPoint.X = .X Else oPoint.X = 0 + If .Y > 0 Then oPoint.Y = .Y Else oPoint.Y = 0 + If piTargetUnit = com.sun.star.util.MeasureUnit.MM_100TH Then + Set oPoint = oComp.convertPointToLogic(oPoint, piTargetUnit) + Else + Set oPoint = oComp.convertPointToPixel(oPoint, com.sun.star.util.MeasureUnit.MM_100TH) + End If + + ' Size part + If .Width > 0 Then oSize.Width = .Width Else oSize.Width = 0 + If .Height > 0 Then oSize.Height = .Height Else oSize.Height = 0 + If piTargetUnit = com.sun.star.util.MeasureUnit.MM_100TH Then + Set oSize = oComp.convertSizeToLogic(oSize, piTargetUnit) + Else + Set oSize = oComp.convertSizeToPixel(oSize, com.sun.star.util.MeasureUnit.MM_100TH) + End If + End With + + With oRect + .X = oPoint.X + .Y = oPoint.Y + .Width = oSize.Width + .Height = oSize.Height + End With + +Finally: + Set _ConvertRectangle = oRect + Exit Function +End Function ' SFDocuments.SF_Document._ConvertRectangle + REM ----------------------------------------------------------------------------- Private Function _FileIdent() As String ''' Returns a file identification from the information that is currently available diff --git a/wizards/source/sfdocuments/SF_Shape.xba b/wizards/source/sfdocuments/SF_Shape.xba new file mode 100644 index 000000000000..52b52d8219b7 --- /dev/null +++ b/wizards/source/sfdocuments/SF_Shape.xba @@ -0,0 +1,686 @@ +<?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_Shape" 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_Shape +''' ======== +''' +''' The SF_Shape module is focused on the description of shapes/images/drawing objects +''' stored in documents. +''' In the actual release only shapes in Calc sheets are considered. +''' Charts are a special type of shapes. The "Chart" service is a subclass of the actual service. +''' +''' Definitions +''' Shapes 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 Shape name is the name given by the user. +''' Only when there is no user name, the internal name may be used instead. +''' The name of a shape must be unique within the sheet where it is located. +''' +''' Service invocation from the "Calc" service +''' Either make a new Shape +''' calc.CreateShapeFromFile(ShapeName, SheetName, ImageFile, AsLink := False) +''' or select an existing one within a given sheet +''' calc.Shapes(SheetName, ShapeName) +''' +''' Detailed user documentation: +''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_shape.html?DbPAR=BASIC +''' +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +REM ================================================================== EXCEPTIONS + +Private Const SHAPEEXPORTERROR = "SHAPEEXPORTERROR" + +REM ============================================================= PRIVATE MEMBERS + +Private [Me] As Object +Private [_Parent] As Object ' Parent Calc document +Private ObjectType As String ' Must be SHAPE +Private ServiceName As String + +' Shape description +Private _SheetName As String ' Name of the Calc sheet containing the Shape +Private _DrawIndex As Long ' Index of the Shape in the sheet's draw page +Private _ShapeName As String ' User name +Private _PersistentName As String ' Internal name +Private _Shape As Object ' com.sun.star.drawing.XShape +Private _XPos As Long ' Initial X position +Private _YPos As Long ' Initial Y position +Private _IsChart As Boolean ' When True, instance is a superclass of a chart instance + +REM ============================================================ MODULE CONSTANTS + + +REM ====================================================== CONSTRUCTOR/DESTRUCTOR + +REM ----------------------------------------------------------------------------- +Private Sub Class_Initialize() + Set [Me] = Nothing + Set [_Parent] = Nothing + ObjectType = "SHAPE" + ServiceName = "SFDocuments.Shape" + _SheetName = "" + _DrawIndex = -1 + _ShapeName = "" + _PersistentName = "" + Set _Shape = Nothing + _XPos = -1 + _YPos = -1 + _IsChart = False +End Sub ' SFDocuments.SF_Shape Constructor + +REM ----------------------------------------------------------------------------- +Private Sub Class_Terminate() + Call Class_Initialize() +End Sub ' SFDocuments.SF_Shape Destructor + +REM ----------------------------------------------------------------------------- +Public Function Dispose() As Variant + Call Class_Terminate() + Set Dispose = Nothing +End Function ' SFDocuments.SF_Shape Explicit Destructor + +REM ================================================================== PROPERTIES + +REM ----------------------------------------------------------------------------- +Property Get XRectangle() As Variant +''' A com.sun.star.awt.XRectangle object. Distances are expressed in 1/100th mm. + XRectangle = _PropertyGet("XRectangle") +End Property ' SFDocuments.SF_Shape.XRectangle (get) + +REM ----------------------------------------------------------------------------- +Property Get XShape() As Variant +''' com.sun.star.drawing.XShape + XShape = _PropertyGet("XShape") +End Property ' SFDocuments.SF_Shape.XShape (get) + +REM ===================================================================== METHODS + +REM ----------------------------------------------------------------------------- +Public Function Anchor(Optional ByVal AnchorType As Variant _ + , Optional ByVal Cell As Variant _ + ) As Boolean +''' Define the anchor type and the cell to which the shape has to be anchored. +''' Args: +''' AnchorType: next strings are accepted, +''' CELL: the shape is anchored "to cell" +''' CELLRESIZE: the shape is anchored "to cell (resize with cell)" +''' PAGE: the shape is anchored to the sheet +''' Cell: a unique cell or a cell range in the sheet where the shape is located. +''' Only the top-left cell of a range will be considered. +''' The argument is ignored and may be omitted when AnchorType = "PAGE" +''' Returns: +''' True when successful +''' Examples: +''' oShape.Anchor("CELL", Cell := "B6") + +Dim bAnchor As Boolean ' Return value +Dim oCell As Object ' Alias of cell argument +Dim oPosition As New com.sun.star.awt.Point ' Position of shape when anchor type is "PAGE" + +Const cstThisSub = "SFDocuments.Shape.Anchor" +Const cstSubArgs = "AnchorType=""CELL""|""CELLRESIZE""|""PAGE"", [Cell]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bAnchor = False + +Check: + If IsMissing(Cell) Or IsEmpty(Cell) Then Cell = "~.A1" + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not [_Parent]._IsStillAlive() Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(AnchorType, "AnchorType", V_STRING, Array("CELL", "CELLRESIZE", "PAGE")) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Cell, "Cell", V_STRING) Then GoTo Finally + End If + +Try: + Set oCell = [_Parent]._ParseAddress(Cell) + With _Shape + Select Case UCase(AnchorType) + Case "CELL", "CELLRESIZE" + .Anchor = oCell.XCellRange.getCellByPosition(0, 0) + .ResizeWithCell = ( UCase(AnchorType) = "CELLRESIZE" ) + bAnchor = True + Case "PAGE" + Set oPosition = .getPosition() + .Anchor = oCell.XSpreadsheet + .ResizeWithCell = False + .setposition(oPosition) ' Restore the initial position (if not, position = A1) + bAnchor = True + Case Else + End Select + End With + +Finally: + Anchor = bAnchor + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SF_Documents.SF_Shape.Anchor + +REM ----------------------------------------------------------------------------- +Public Function ExportToFile(Optional ByVal FileName As Variant _ + , Optional ByVal ImageType As Variant _ + , Optional ByVal Overwrite As Variant _ + ) As Boolean +''' Store the shape 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: +''' SHAPEEXPORTERROR The destination has its readonly attribute set or overwriting rejected +''' Examples: +''' oShape.ExportToFile("C:\Me\Shape2.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.Shape.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 -e ... etc. - the rest is truncated
