From b4289da0b4074a219aec899814378c71952e934a Mon Sep 17 00:00:00 2001 From: RMZeroFour Date: Fri, 6 Sep 2024 18:47:34 +0530 Subject: [PATCH] .NET Bindings: Ported examples for Native bridge This patch include the following SDK examples ported to .NET to test the new Native bridge: - FirstLoadComponent - HelloTextTableShape - PathSettings - PathSubstitution - TerminationTest - WriterDemo The examples include VB.NET and F# as well to test support for non-C# .NET languages. Change-Id: I044df4777c7c091241d5b4284f4b6ee6c5de74f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172778 Tested-by: Jenkins Reviewed-by: Hossein --- odk/CustomTarget_build-examples_java.mk | 2 +- odk/Package_examples.mk | 21 +- .../csharp/FirstLoadComponent.cs | 99 ++++++ .../FirstLoadComponent/csharp/Makefile | 75 +++++ .../csharp/HelloTextTableShape.cs | 300 ++++++++++++++++++ .../HelloTextTableShape/csharp/Makefile | 75 +++++ .../OfficeDev/PathSettings/csharp/Makefile | 75 +++++ .../PathSettings/csharp/PathSettingsTest.cs | 95 ++++++ .../PathSettings/{ => java}/Makefile | 2 +- .../{ => java}/PathSettingsTest.java | 0 .../PathSubstitution/csharp/Makefile | 75 +++++ .../csharp/PathSubstitutionTest.cs | 77 +++++ .../OfficeDev/TerminationTest/csharp/Makefile | 75 +++++ .../csharp/TerminateListener.cs | 40 +++ .../TerminationTest/csharp/TerminationTest.cs | 57 ++++ .../dotnet/WriterDemo/csharp/Makefile | 75 +++++ .../dotnet/WriterDemo/csharp/WriterDemo.cs | 144 +++++++++ .../dotnet/WriterDemo/fsharp/Makefile | 75 +++++ .../dotnet/WriterDemo/fsharp/WriterDemo.fs | 139 ++++++++ .../dotnet/WriterDemo/vbasic/Makefile | 75 +++++ .../dotnet/WriterDemo/vbasic/WriterDemo.vb | 145 +++++++++ 21 files changed, 1717 insertions(+), 4 deletions(-) create mode 100644 odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/FirstLoadComponent.cs create mode 100644 odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/Makefile create mode 100644 odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/HelloTextTableShape.cs create mode 100644 odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/Makefile create mode 100644 odk/examples/DevelopersGuide/OfficeDev/PathSettings/csharp/Makefile create mode 100644 odk/examples/DevelopersGuide/OfficeDev/PathSettings/csharp/PathSettingsTest.cs rename odk/examples/DevelopersGuide/OfficeDev/PathSettings/{ => java}/Makefile (99%) rename odk/examples/DevelopersGuide/OfficeDev/PathSettings/{ => java}/PathSettingsTest.java (100%) create mode 100644 odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/csharp/Makefile create mode 100644 odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/csharp/PathSubstitutionTest.cs create mode 100644 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/Makefile create mode 100644 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminateListener.cs create mode 100644 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminationTest.cs create mode 100644 odk/examples/dotnet/WriterDemo/csharp/Makefile create mode 100644 odk/examples/dotnet/WriterDemo/csharp/WriterDemo.cs create mode 100644 odk/examples/dotnet/WriterDemo/fsharp/Makefile create mode 100644 odk/examples/dotnet/WriterDemo/fsharp/WriterDemo.fs create mode 100644 odk/examples/dotnet/WriterDemo/vbasic/Makefile create mode 100644 odk/examples/dotnet/WriterDemo/vbasic/WriterDemo.vb diff --git a/odk/CustomTarget_build-examples_java.mk b/odk/CustomTarget_build-examples_java.mk index cec90d4066ad..b9e942e5a6d4 100644 --- a/odk/CustomTarget_build-examples_java.mk +++ b/odk/CustomTarget_build-examples_java.mk @@ -33,7 +33,7 @@ my_example_dirs_java = \ DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection \ DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java \ DevelopersGuide/OfficeDev/Linguistic \ - DevelopersGuide/OfficeDev/PathSettings \ + DevelopersGuide/OfficeDev/PathSettings/java \ DevelopersGuide/OfficeDev/PathSubstitution/java \ DevelopersGuide/OfficeDev/TerminationTest/java \ DevelopersGuide/ProfUNO/InterprocessConn \ diff --git a/odk/Package_examples.mk b/odk/Package_examples.mk index b2f2ba90244c..82fc78c93c2e 100644 --- a/odk/Package_examples.mk +++ b/odk/Package_examples.mk @@ -189,6 +189,8 @@ $(eval $(call gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples, DevelopersGuide/FirstSteps/FirstUnoContact/python/FirstUnoContact.py \ DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx \ DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/Makefile \ + DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/FirstLoadComponent.cs \ + DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/Makefile \ DevelopersGuide/FirstSteps/FirstLoadComponent/java/FirstLoadComponent.java \ DevelopersGuide/FirstSteps/FirstLoadComponent/java/Makefile \ DevelopersGuide/FirstSteps/FirstLoadComponent/basic/FirstLoadComponent.bas \ @@ -196,6 +198,8 @@ $(eval $(call gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples, DevelopersGuide/FirstSteps/FirstLoadComponent/python/DualComponentLoader.py \ DevelopersGuide/FirstSteps/HelloTextTableShape/cxx/HelloTextTableShape.cxx \ DevelopersGuide/FirstSteps/HelloTextTableShape/cxx/Makefile \ + DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/HelloTextTableShape.cs \ + DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/Makefile \ DevelopersGuide/FirstSteps/HelloTextTableShape/java/HelloTextTableShape.java \ DevelopersGuide/FirstSteps/HelloTextTableShape/java/Makefile \ DevelopersGuide/FirstSteps/HelloTextTableShape/basic/HelloTextTableShape.bas \ @@ -324,13 +328,20 @@ $(eval $(call gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples, DevelopersGuide/OfficeDev/MenuElement.java \ DevelopersGuide/OfficeDev/Number_Formats.java \ DevelopersGuide/OfficeDev/OfficeConnect.java \ - DevelopersGuide/OfficeDev/PathSettings/Makefile \ - DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java \ + DevelopersGuide/OfficeDev/PathSettings/csharp/Makefile \ + DevelopersGuide/OfficeDev/PathSettings/csharp/PathSettingsTest.cs \ + DevelopersGuide/OfficeDev/PathSettings/java/Makefile \ + DevelopersGuide/OfficeDev/PathSettings/java/PathSettingsTest.java \ + DevelopersGuide/OfficeDev/PathSubstitution/csharp/Makefile \ + DevelopersGuide/OfficeDev/PathSubstitution/csharp/PathSubstitutionTest.cs \ DevelopersGuide/OfficeDev/PathSubstitution/java/Makefile \ DevelopersGuide/OfficeDev/PathSubstitution/java/PathSubstitutionTest.java \ DevelopersGuide/OfficeDev/PathSubstitution/python/path_substitution_test.py \ DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile \ DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx \ + DevelopersGuide/OfficeDev/TerminationTest/csharp/Makefile \ + DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminateListener.cs \ + DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminationTest.cs \ DevelopersGuide/OfficeDev/TerminationTest/java/Makefile \ DevelopersGuide/OfficeDev/TerminationTest/java/TerminateListener.java \ DevelopersGuide/OfficeDev/TerminationTest/java/TerminationTest.java \ @@ -466,6 +477,12 @@ $(eval $(call gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples, cpp/counter/countermain.cxx \ cpp/remoteclient/Makefile \ cpp/remoteclient/remoteclient.cxx \ + dotnet/WriterDemo/csharp/Makefile \ + dotnet/WriterDemo/csharp/WriterDemo.cs \ + dotnet/WriterDemo/fsharp/Makefile \ + dotnet/WriterDemo/fsharp/WriterDemo.fs \ + dotnet/WriterDemo/vbasic/Makefile \ + dotnet/WriterDemo/vbasic/WriterDemo.vb \ java/DocumentHandling/DocumentConverter.java \ java/DocumentHandling/DocumentLoader.java \ java/DocumentHandling/DocumentPrinter.java \ diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/FirstLoadComponent.cs b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/FirstLoadComponent.cs new file mode 100644 index 000000000000..9205d030a642 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/FirstLoadComponent.cs @@ -0,0 +1,99 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System; + +using com.sun.star.beans; +using com.sun.star.container; +using com.sun.star.frame; +using com.sun.star.lang; +using com.sun.star.sheet; +using com.sun.star.table; +using com.sun.star.uno; + +try +{ + XComponentContext xContext = NativeBootstrap.bootstrap(); + if (xContext is null) + Console.Error.WriteLine("Could not bootstrap office"); + + XMultiComponentFactory xServiceManager = xContext.getServiceManager(); + + IQueryInterface desktop = xServiceManager + .createInstanceWithContext("com.sun.star.frame.Desktop", xContext); + XComponentLoader xComponentLoader = desktop.query(); + + PropertyValue[] loadProps = Array.Empty(); + XComponent xSpreadsheetComponent = xComponentLoader + .loadComponentFromURL("private:factory/scalc", "_blank", 0, loadProps); + + XSpreadsheetDocument xSpreadsheetDocument = xSpreadsheetComponent + .query(); + + XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets(); + xSpreadsheets.insertNewByName("MySheet", 0); + Type elemType = xSpreadsheets.getElementType(); + Console.WriteLine(elemType.FullName); + + Any sheet = xSpreadsheets.getByName("MySheet"); + XSpreadsheet xSpreadsheet = sheet.castOrDefault(); + + XCell xCell = xSpreadsheet.getCellByPosition(0, 0); + xCell.setValue(21); + xCell = xSpreadsheet.getCellByPosition(0, 1); + xCell.setValue(21); + xCell = xSpreadsheet.getCellByPosition(0, 2); + xCell.setFormula("=sum(A1:A2)"); + + XPropertySet xCellProps = xCell.query(); + xCellProps.setPropertyValue("CellStyle", new Any("Result")); + + XModel xSpreadsheetModel = xSpreadsheetComponent.query(); + XController xSpreadsheetController = xSpreadsheetModel.getCurrentController(); + XSpreadsheetView xSpreadsheetView = xSpreadsheetController.query(); + xSpreadsheetView.setActiveSheet(xSpreadsheet); + + // Example usage of enum values + xCellProps.setPropertyValue("VertJustify", new Any(CellVertJustify.TOP)); + + // Example usage of PropertyValue structs + loadProps = new PropertyValue[1] + { + new PropertyValue() + { + Name = "AsTemplate", + Value = new Any(true), + } + }; + + // Uncomment to load a Calc file as template + //xSpreadsheetComponent = xComponentLoader.loadComponentFromURL( + // "file:///c:/temp/DataAnalysys.ods", "_blank", 0, loadProps); + + // Example usage of XEnumerationAccess + XCellRangesQuery xCellQuery = sheet.castOrDefault(); + XSheetCellRanges xFormulaCells = xCellQuery.queryContentCells(CellFlags.FORMULA); + XEnumerationAccess xFormulas = xFormulaCells.getCells(); + XEnumeration xFormulaEnum = xFormulas.createEnumeration(); + + while (xFormulaEnum.hasMoreElements()) + { + Any formulaCell = xFormulaEnum.nextElement(); + xCell = formulaCell.castOrDefault(); + XCellAddressable xCellAddress = xCell.query(); + Console.WriteLine($"Formula cell in column {xCellAddress.getCellAddress().Column}, row {xCellAddress.getCellAddress().Row} contains {xCell.getFormula()}"); + } + + return 0; +} +catch (UnoException e) +{ + Console.Error.WriteLine(e.Message); + + return 1; +} \ No newline at end of file diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/Makefile b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/Makefile new file mode 100644 index 000000000000..2cd58d246ac7 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/Makefile @@ -0,0 +1,75 @@ +# Builds the FirstLoadComponent example of the Developers Guide. + +PRJ = ../../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = FirstLoadComponent +APP_LANG = cs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $((); + XText xText = xTextDocument.getText(); + + ManipulateText(xText); + + // Get the internal service factory of the document + XMultiServiceFactory xWriterFactory = xTextDocument.query(); + + // Insert a TextTable, and manipulate the text content of the cell + XTextContent xTextContentTable = xWriterFactory.createInstance("com.sun.star.text.TextTable").query(); + xText.insertTextContent(xText.getEnd(), xTextContentTable, false); + + XCellRange xCellRange = xTextContentTable.query(); + XCell xCell = xCellRange.getCellByPosition(0, 1); + XText xCellText = xCell.query(); + + ManipulateText(xCellText); + ManipulateTable(xCellRange); + + XShape xWriterShape = xWriterFactory.createInstance("com.sun.star.drawing.RectangleShape").query(); + xWriterShape.setSize(new Size(10000, 10000)); + XTextContent xTextContentShape = xWriterShape.query(); + + xText.insertTextContent(xText.getEnd(), xTextContentShape, false); + + // Wrap the text inside the shape + XPropertySet xShapeProps = xWriterShape.query(); + xShapeProps.setPropertyValue("TextContourFrame", new Any(true)); + + XText xShapeText = xWriterShape.query(); + + ManipulateText(xShapeText); + ManipulateShape(xWriterShape); + + // Create and name a bookmark + IQueryInterface bookmark = xWriterFactory.createInstance("com.sun.star.text.Bookmark"); + XNamed xNamed = bookmark.query(); + xNamed.setName("MyUniqueBookmarkName"); + + // Insert the bookmark at the end of the document + XTextContent xTextContent = bookmark.query(); + xText.insertTextContent(xText.getEnd(), xTextContent, false); + + // Get all bookmarks from the XBookmarksSupplier + XBookmarksSupplier xBookmarksSupplier = xWriterComponent.query(); + XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); + XTextContent xFoundBookmark = xNamedBookmarks.getByName("MyUniqueBookmarkName").cast(); + XTextRange xFound = xFoundBookmark.getAnchor(); + xFound.setString(" The throat mike, glued to her neck, " + + "looked as much as possible like an analgesic dermadisk."); + + // Get all tables from the XTextTablesSupplier + XTextTablesSupplier xTablesSupplier = xWriterComponent.query(); + XNameAccess xNamedTables = xTablesSupplier.getTextTables(); + XIndexAccess xIndexedTables = xNamedTables.query(); + + // Get the tables + XPropertySet xTableProps = null; + for (int i = 0; i < xIndexedTables.getCount(); i++) + { + xTableProps = xIndexedTables.getByIndex(i).cast(); + xTableProps.setPropertyValue("BackColor", new Any(0xC8FFB9)); + } +} + +void UseCalc() +{ + // Create a new Calc document, and manipulate text in a cell + XComponent xCalcComponent = NewDocComponent("scalc"); + XSpreadsheetDocument xCalcDocument = xCalcComponent.query(); + XSpreadsheetDocument xSpreadsheetDocument = xCalcDocument.query(); + + XIndexAccess xIndexedSheets = xSpreadsheetDocument.getSheets().query(); + XCellRange xSpreadsheetCells = xIndexedSheets.getByIndex(0).cast(); + + // Get cell A2 from the first sheet + XCell xCell = xSpreadsheetCells.getCellByPosition(0, 1); + XText xCellText = xCell.query(); + + XPropertySet xCellProps = xCell.query(); + xCellProps.setPropertyValue("IsTextWrapped", new Any(true)); + + ManipulateText(xCellText); + ManipulateTable(xSpreadsheetCells); + + // Get the internal service factory of the document + XMultiServiceFactory xCalcFactory = xCalcDocument.query(); + XDrawPageSupplier xDrawPageSupplier = xIndexedSheets.getByIndex(0).cast(); + XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage(); + + // Create and insert a RectangleShape, and manipulate its shape text + XShape xCalcShape = xCalcFactory.createInstance("com.sun.star.drawing.RectangleShape").query(); + xCalcShape.setSize(new Size(10000, 10000)); + xCalcShape.setPosition(new Point(7000, 3000)); + xDrawPage.add(xCalcShape); + + // Wrap the text inside the shape + XPropertySet xShapeProps = xCalcShape.query(); + xShapeProps.setPropertyValue("TextContourFrame", new Any(true)); + + XText xShapeText = xCalcShape.query(); + ManipulateText(xShapeText); + ManipulateShape(xCalcShape); +} + +void UseDraw() +{ + // Create a new Draw document, and insert a rectangle + XComponent xDrawComponent = NewDocComponent("sdraw"); + XDrawPagesSupplier xDrawPagesSupplier = xDrawComponent.query(); + + XIndexAccess xIndexedDrawPages = xDrawPagesSupplier.getDrawPages(); + XDrawPage xDrawPage = xIndexedDrawPages.getByIndex(0).cast(); + + // Get the internal service factory of the document + XMultiServiceFactory xDrawFactory = xDrawComponent.query(); + XShape xDrawShape = xDrawFactory.createInstance("com.sun.star.drawing.RectangleShape").query(); + xDrawShape.setSize(new Size(10000, 20000)); + xDrawShape.setPosition(new Point(5000, 5000)); + xDrawPage.add(xDrawShape); + + // Wrap the text inside the shape + XPropertySet xShapeProps = xDrawShape.query(); + xShapeProps.setPropertyValue("TextContourFrame", new Any(true)); + + XText xShapeText = xDrawShape.query(); + ManipulateText(xShapeText); + ManipulateShape(xDrawShape); +} + +void ManipulateText(XText xText) +{ + // Set the entire text at once + xText.setString("He lay flat on the brown, pine-needled floor of the forest, " + + "his chin on his folded arms, and high overhead the wind blew in the tops " + + "of the pine trees."); + + // Create a text cursor for selecting and formatting + XTextCursor xTextCursor = xText.createTextCursor(); + XPropertySet xCursorProps = xTextCursor.query(); + + // Use the cursor to select "He lay", and apply bold and italic formatting + xTextCursor.gotoStart(false); + xTextCursor.goRight(6, true); + + xCursorProps.setPropertyValue("CharPosture", new Any(FontSlant.ITALIC)); + xCursorProps.setPropertyValue("CharWeight", new Any(FontWeight.BOLD)); + + xTextCursor.gotoEnd(false); + xText.insertString(xTextCursor.getStart(), + " The mountainside sloped gently where he lay; " + + "but below it was steep and he could see the dark of the oiled road " + + "winding through the pass. There was a stream alongside the road " + + "and far down the pass he saw a mill beside the stream and the falling water " + + "of the dam, white in the summer sunlight.", false); + xText.insertString(xTextCursor.getStart(), "\n \"Is that the mill?\" he asked.", false); +} + +void ManipulateTable(XCellRange xCellRange) +{ + // Set column titles and a cell value + XCell xCell = xCellRange.getCellByPosition(0, 0); + XText xCellText = xCell.query(); + xCellText.setString("Quotation"); + + xCell = xCellRange.getCellByPosition(1, 0); + xCellText = xCell.query(); + xCellText.setString("Year"); + + xCell = xCellRange.getCellByPosition(1, 1); + xCell.setValue(1940); + + XCellRange xSelectedCells = xCellRange.getCellRangeByName("A1:B1"); + XPropertySet xCellProps = xSelectedCells.query(); + + string backColorPropertyName = null; + XPropertySet xTableProps = null; + + // Format the table headers and borders + XServiceInfo xServiceInfo = xCellRange.query(); + if (xServiceInfo.supportsService("com.sun.star.sheet.Spreadsheet")) + { + backColorPropertyName = "CellBackColor"; + xSelectedCells = xCellRange.getCellRangeByName("A1:B2"); + xTableProps = xSelectedCells.query(); + } + else if (xServiceInfo.supportsService("com.sun.star.text.TextTable")) + { + backColorPropertyName = "BackColor"; + xTableProps = xCellRange.query(); + } + // Set cell background color + xCellProps.setPropertyValue(backColorPropertyName, new Any(0x99CCFF)); + + // Set table borders (blue line, width 10) + BorderLine theLine = new BorderLine() + { + Color = 0x000099, + OuterLineWidth = 10, + }; + + // Use the above defined line for all borders and enable them + TableBorder bord = new TableBorder() + { + VerticalLine = theLine, + HorizontalLine = theLine, + LeftLine = theLine, + RightLine = theLine, + TopLine = theLine, + BottomLine = theLine, + + IsVerticalLineValid = true, + IsHorizontalLineValid = true, + IsLeftLineValid = true, + IsRightLineValid = true, + IsTopLineValid = true, + IsBottomLineValid = true, + }; + xTableProps.setPropertyValue("TableBorder", new Any(bord)); + + bord = xTableProps.getPropertyValue("TableBorder").cast(); + Console.WriteLine(bord.TopLine.Color); +} + +void ManipulateShape(XShape xShape) +{ + XPropertySet xShapeProps = xShape.query(); + xShapeProps.setPropertyValue("FillColor", new Any(0x99CCFF)); + xShapeProps.setPropertyValue("LineColor", new Any(0x000099)); + xShapeProps.setPropertyValue("RotateAngle", new Any(3000)); + xShapeProps.setPropertyValue("TextLeftDistance", new Any(0)); + xShapeProps.setPropertyValue("TextRightDistance", new Any(0)); + xShapeProps.setPropertyValue("TextUpperDistance", new Any(0)); + xShapeProps.setPropertyValue("TextLowerDistance", new Any(0)); +} + +XComponent NewDocComponent(string docType) +{ + XMultiComponentFactory xRemoteServiceManager = GetRemoteServiceManager(); + + XComponentLoader xComponentLoader = xRemoteServiceManager + .createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext) + .query(); + + string loadUrl = $"private:factory/{docType}"; + return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, new PropertyValue[0]); +} + +XMultiComponentFactory GetRemoteServiceManager() +{ + if (xRemoteContext == null && xRemoteServiceManager == null) + { + xRemoteContext = NativeBootstrap.bootstrap(); + Console.WriteLine("Connected to a running office ..."); + + xRemoteServiceManager = xRemoteContext.getServiceManager(); + } + return xRemoteServiceManager; +} \ No newline at end of file diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/Makefile b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/Makefile new file mode 100644 index 000000000000..b30bfb7afcbd --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/Makefile @@ -0,0 +1,75 @@ +# Builds the HelloTextTableShape example of the Developers Guide. + +PRJ = ../../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = HelloTextTableShape +APP_LANG = cs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $((); + Console.WriteLine($"Property = {prop} | Path = {value}"); + } + catch (UnknownPropertyException) + { + Console.Error.WriteLine($"UnknownPropertyException was thrown while accessing {prop}"); + } + catch (WrappedTargetException) + { + Console.Error.WriteLine($"WrappedTargetException was thrown while accessing {prop}"); + } + } + + // Try to modify the work path property. + // After running this example you should see the new value of "My Documents" + // in the Paths tab, accessible via "Tools - Options - LibreOffice - Paths". + // The change can be reverted through the Paths tab as well. + try + { + pathSettings.setPropertyValue("Work", new Any("$(temp)")); + string value = pathSettings.getPropertyValue("Work").cast(); + Console.WriteLine("Note: The example changes your current work path setting!"); + Console.WriteLine($"The work path should now be {value}"); + } + catch (UnknownPropertyException) + { + Console.Error.WriteLine("UnknownPropertyException was thrown while setting Work path"); + } + catch (WrappedTargetException) + { + Console.Error.WriteLine("WrappedTargetException was thrown while setting Work path"); + } + catch (PropertyVetoException) + { + Console.Error.WriteLine("PropertyVetoException was thrown while setting Work path"); + } + catch (IllegalArgumentException) + { + Console.Error.WriteLine("IllegalArgumentException was thrown while setting Work path"); + } + } +} diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/java/Makefile similarity index 99% rename from odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile rename to odk/examples/DevelopersGuide/OfficeDev/PathSettings/java/Makefile index bc55266efb84..631f32a8a40f 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile +++ b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/java/Makefile @@ -34,7 +34,7 @@ # Builds the OfficeDevPathSettingsTest example of the Developers Guide. -PRJ=../../../.. +PRJ=../../../../.. SETTINGS=$(PRJ)/settings include $(SETTINGS)/settings.mk diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/java/PathSettingsTest.java similarity index 100% rename from odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java rename to odk/examples/DevelopersGuide/OfficeDev/PathSettings/java/PathSettingsTest.java diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/csharp/Makefile b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/csharp/Makefile new file mode 100644 index 000000000000..363c4ca92587 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/csharp/Makefile @@ -0,0 +1,75 @@ +# Builds the PathSubstitutionTest example of the Developers Guide. + +PRJ = ../../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = PathSubstitutionTest +APP_LANG = cs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $((); + WorkWithPathVariables(pathSubst); + + return 0; +} +catch (Exception e) +{ + Console.Error.WriteLine(e); + + return 1; +} + +void WorkWithPathVariables(XStringSubstitution pathSubst) +{ + if (pathSubst != null) + { + foreach (string pathVar in predefinedPathVariables) + { + try + { + string value = pathSubst.getSubstituteVariableValue(pathVar); + Console.WriteLine($"Property = {pathVar} | Path = {value}"); + } + catch (NoSuchElementException) + { + Console.Error.WriteLine($"NoSuchElementException has been thrown accessing {pathVar}"); + } + } + + try + { + // Check the resubstitution function + // Use $(home) as starting point and extend the path + string value = pathSubst.getSubstituteVariableValue(predefinedPathVariables[0]); + value += "/test"; + + Console.WriteLine($"Path = {value}"); + string resub = pathSubst.reSubstituteVariables(value); + Console.WriteLine($"Resubstituted Path = {resub}"); + } + catch (NoSuchElementException) + { + Console.Error.WriteLine($"NoSuchElementException has been thrown accessing {predefinedPathVariables[0]}"); + } + } +} diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/Makefile b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/Makefile new file mode 100644 index 000000000000..76d685fd3dcc --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/Makefile @@ -0,0 +1,75 @@ +# Builds the TerminationTest example of the Developers Guide. + +PRJ = ../../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = TerminationTest +APP_LANG = cs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $( GetType().FullName; + + public bool supportsService(string serviceName) => serviceName == "com.sun.star.frame.XTerminateListener"; + + public string[] getSupportedServiceNames() => new[] { "com.sun.star.frame.XTerminateListener" }; +} diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminationTest.cs b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminationTest.cs new file mode 100644 index 000000000000..2829514b104a --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/csharp/TerminationTest.cs @@ -0,0 +1,57 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System; + +using com.sun.star.frame; +using com.sun.star.lang; +using com.sun.star.uno; + +public class Program +{ + public static bool atWork = false; + + private static int Main() + { + try + { + // Connect to a new instance of the Office + XComponentContext context = NativeBootstrap.bootstrap(); + Console.WriteLine("Connected to a running office..."); + + // Get a reference to the Desktop service + XDesktop2 desktop = Desktop.create(context); + + // Create our termination request listener, and register it + TerminateListener listener = new TerminateListener(); + desktop.addTerminateListener(listener); + + // Try to terminate while we are at work. + atWork = true; + bool terminated = desktop.terminate(); + Console.WriteLine("The Office {0}", terminated + ? "has been terminated" + : "is still running, we are at work"); + + // Try to terminate when we are NOT at work. + atWork = false; + terminated = desktop.terminate(); + Console.WriteLine("The Office {0}", terminated + ? "has been terminated" + : "is still running. Something else prevents termination, such as the quickstarter."); + + return 0; + } + catch (Exception ex) + { + Console.Error.WriteLine(ex); + + return 1; + } + } +} \ No newline at end of file diff --git a/odk/examples/dotnet/WriterDemo/csharp/Makefile b/odk/examples/dotnet/WriterDemo/csharp/Makefile new file mode 100644 index 000000000000..28992ec130d4 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/csharp/Makefile @@ -0,0 +1,75 @@ +# Builds the WriterDemo example of the Developers Guide. + +PRJ = ../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = WriterDemo +APP_LANG = cs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $((); +XComponent component = componentLoader.loadComponentFromURL( + "private:factory/swriter", "_blank", 0, Array.Empty()); + +XTextDocument textDocument = component.query(); + +// Create a text object +XText text = textDocument.getText(); +XSimpleText simpleText = text.query(); + +// Create a cursor object +XTextCursor cursor = simpleText.createTextCursor(); + +// Inserting some Text +text.insertString(cursor, "The first line in the newly created text document.\n", false); + +// Create instance of a text table with 4 columns and 4 rows +IQueryInterface textTableI = textDocument.query().createInstance("com.sun.star.text.TextTable"); +XTextTable textTable = textTableI.query(); +textTable.initialize(4, 4); +text.insertTextContent(cursor, textTable, false); + +// Set the table background color +XPropertySet tablePropertySet = textTableI.query(); +tablePropertySet.setPropertyValue("BackTransparent", new Any(false)); +tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF)); + +// Get first row +XTableRows tableRows = textTable.getRows(); +Any rowAny = tableRows.query().getByIndex(0); + +// Set a different background color for the first row +XPropertySet firstRowPropertySet = rowAny.cast(); +firstRowPropertySet.setPropertyValue("BackTransparent", new Any(false)); +firstRowPropertySet.setPropertyValue("BackColor", new Any(0x6666AA)); + +// Fill the first table row +InsertIntoCell("A1", "FirstColumn", textTable); +InsertIntoCell("B1", "SecondColumn", textTable); +InsertIntoCell("C1", "ThirdColumn", textTable); +InsertIntoCell("D1", "SUM", textTable); + +// Fill the remaining rows +textTable.getCellByName("A2").setValue(22.5); +textTable.getCellByName("B2").setValue(5615.3); +textTable.getCellByName("C2").setValue(-2315.7); +textTable.getCellByName("D2").setFormula("sum "); + +textTable.getCellByName("A3").setValue(21.5); +textTable.getCellByName("B3").setValue(615.3); +textTable.getCellByName("C3").setValue(-315.7); +textTable.getCellByName("D3").setFormula("sum "); + +textTable.getCellByName("A4").setValue(121.5); +textTable.getCellByName("B4").setValue(-615.3); +textTable.getCellByName("C4").setValue(415.7); +textTable.getCellByName("D4").setFormula("sum "); + +// Change the CharColor and add a Shadow +XPropertySet cursorPropertySet = cursor.query(); +cursorPropertySet.setPropertyValue("CharColor", new Any(255)); +cursorPropertySet.setPropertyValue("CharShadowed", new Any(true)); + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false); + +// Inserting colored Text. +simpleText.insertString(cursor, " This is a colored Text - blue with shadow\n", false); + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false); + +// Create a TextFrame. +IQueryInterface textFrameI = textDocument.query().createInstance("com.sun.star.text.TextFrame"); +XTextFrame textFrame = textFrameI.query(); + +// Set the size of the frame +Size size = new Size(15000, 400); +textFrame.query().setSize(size); + +// Set anchortype +XPropertySet framePropertySet = textFrame.query(); +framePropertySet.setPropertyValue("AnchorType", new Any(TextContentAnchorType.AS_CHARACTER)); + +// Insert the frame +text.insertTextContent(cursor, textFrame, false); + +// Get the text object of the frame +XText frameText = textFrame.getText(); +XSimpleText frameSimpleText = frameText.query(); + +// Create a cursor object +XTextCursor frameCursor = frameSimpleText.createTextCursor(); + +// Inserting some Text +frameSimpleText.insertString(frameCursor, "The first line in the newly created text frame.", false); +frameSimpleText.insertString(frameCursor, "\nWith this second line the height of the frame raises.", false); + +// Create a paragraph break +simpleText.insertControlCharacter(frameCursor, ControlCharacter.PARAGRAPH_BREAK, false); + +// Change the CharColor and add a Shadow +cursorPropertySet.setPropertyValue("CharColor", new Any(65536)); +cursorPropertySet.setPropertyValue("CharShadowed", new Any(false)); + +// Insert another string +text.insertString(cursor, "\n That's all for now !!", false); + +void InsertIntoCell(string cellName, string text, XTextTable textTable) +{ + XCell cell = textTable.getCellByName(cellName); + XSimpleText simpleText = cell.query(); + simpleText.setString(text); +} \ No newline at end of file diff --git a/odk/examples/dotnet/WriterDemo/fsharp/Makefile b/odk/examples/dotnet/WriterDemo/fsharp/Makefile new file mode 100644 index 000000000000..d3aaad0c6499 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/fsharp/Makefile @@ -0,0 +1,75 @@ +# Builds the WriterDemo example of the Developers Guide. + +PRJ = ../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = WriterDemo +APP_LANG = fs + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(() + simpleText.setString(text) + +// Connect to a running office +let context = NativeBootstrap.bootstrap() +// Create a service manager of the remote office +let factory = context.getServiceManager() + +// Create the Desktop +let desktop = Desktop.create(context) + +// Open a new empty writer document +let componentLoader = desktop.query() +let component_ = componentLoader.loadComponentFromURL( + "private:factory/swriter", "_blank", 0, [||]) + +let textDocument = component_.query() + +// Create a text object +let text = textDocument.getText() +let simpleText = text.query() + +// Create a cursor object +let cursor = simpleText.createTextCursor() + +// Inserting some Text +text.insertString(cursor, "The first line in the newly created text document." + Environment.NewLine, false) + +// Create instance of a text table with 4 columns and 4 rows +let textTableI = textDocument.query().createInstance("com.sun.star.text.TextTable") +let textTable = textTableI.query() +textTable.initialize(4, 4) +text.insertTextContent(cursor, textTable, false) + +// Set the table background color +let tablePropertySet = textTableI.query() +tablePropertySet.setPropertyValue("BackTransparent", new Any(false)) +tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF)) + +// Get first row +let tableRows = textTable.getRows() +let rowAny = tableRows.query().getByIndex(0) + +// Set a different background color for the first row +let firstRowPropertySet = rowAny.cast() +firstRowPropertySet.setPropertyValue("BackTransparent", new Any(false)) +firstRowPropertySet.setPropertyValue("BackColor", new Any(0x6666AA)) + +// Fill the first table row +InsertIntoCell("A1", "FirstColumn", textTable) +InsertIntoCell("B1", "SecondColumn", textTable) +InsertIntoCell("C1", "ThirdColumn", textTable) +InsertIntoCell("D1", "SUM", textTable) + +// Fill the remaining rows +textTable.getCellByName("A2").setValue(22.5) +textTable.getCellByName("B2").setValue(5615.3) +textTable.getCellByName("C2").setValue(-2315.7) +textTable.getCellByName("D2").setFormula("sum ") + +textTable.getCellByName("A3").setValue(21.5) +textTable.getCellByName("B3").setValue(615.3) +textTable.getCellByName("C3").setValue(-315.7) +textTable.getCellByName("D3").setFormula("sum ") + +textTable.getCellByName("A4").setValue(121.5) +textTable.getCellByName("B4").setValue(-615.3) +textTable.getCellByName("C4").setValue(415.7) +textTable.getCellByName("D4").setFormula("sum ") + +// Change the CharColor and add a Shadow +let cursorPropertySet = cursor.query() +cursorPropertySet.setPropertyValue("CharColor", new Any(255)) +cursorPropertySet.setPropertyValue("CharShadowed", new Any(true)) + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false) + +// Inserting colored Text. +simpleText.insertString(cursor, " This is a colored Text - blue with shadow" + Environment.NewLine, false) + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false) + +// Create a TextFrame. +let textFrameI = textDocument.query().createInstance("com.sun.star.text.TextFrame") +let textFrame = textFrameI.query() + +// Set the size of the frame +let size = Size(15000, 400) +textFrame.query().setSize(size) + +// Set anchortype +let framePropertySet = textFrame.query() +framePropertySet.setPropertyValue("AnchorType", new Any(TextContentAnchorType.AS_CHARACTER)) + +// Insert the frame +text.insertTextContent(cursor, textFrame, false) + +// Get the text object of the frame +let frameText = textFrame.getText() +let frameSimpleText = frameText.query() + +// Create a cursor object +let frameCursor = frameSimpleText.createTextCursor() + +// Inserting some Text +frameSimpleText.insertString(frameCursor, "The first line in the newly created text frame.", false) +frameSimpleText.insertString(frameCursor, Environment.NewLine + "With this second line the height of the frame raises.", false) + +// Create a paragraph break +simpleText.insertControlCharacter(frameCursor, ControlCharacter.PARAGRAPH_BREAK, false) + +// Change the CharColor and add a Shadow +cursorPropertySet.setPropertyValue("CharColor", new Any(65536)) +cursorPropertySet.setPropertyValue("CharShadowed", new Any(false)) + +// Insert another string +text.insertString(cursor, Environment.NewLine + " That's all for now !!", false) diff --git a/odk/examples/dotnet/WriterDemo/vbasic/Makefile b/odk/examples/dotnet/WriterDemo/vbasic/Makefile new file mode 100644 index 000000000000..01014c71a820 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/vbasic/Makefile @@ -0,0 +1,75 @@ +# Builds the WriterDemo example of the Developers Guide. + +PRJ = ../../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Settings +APP_NAME = WriterDemo +APP_LANG = vb + +APP_SRC_DIR = $(subst /,$(PS),$(CURDIR)) +APP_BIN_DIR = $(subst /,$(PS),$(OUT_BIN)) +APP_MISC_DIR = $(subst /,$(PS),$(OUT_MISC)/$(APP_NAME)) + +APP_PROJ_NAME = $(APP_NAME).$(APP_LANG)proj +APP_PROJ_FILE = $(APP_MISC_DIR)/$(APP_PROJ_NAME) + +APP_EXE_NAME = $(APP_NAME)$(EXE_EXT) +APP_EXE_FILE = $(APP_BIN_DIR)/$(APP_EXE_NAME) + +DOTNET_FLAGS = -c Release +LO_NUPKG_ID = LibreOffice.Bindings +LO_NUPKG_VERSION = 0.1.0 +LO_NUPKG_DIR = $(abspath $(PRJ)/dotnet) + +# Targets +.PHONY: ALL +ALL : $(APP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(APP_PROJ_FILE) : + -$(MKDIR) $(@D) + $(ECHO) "" > $@ + $(ECHO) " " >> $@ + $(ECHO) " $(APP_NAME)" >> $@ + $(ECHO) " net8.0" >> $@ + $(ECHO) " exe" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " false" >> $@ + $(ECHO) " true" >> $@ + $(ECHO) " $(LO_NUPKG_DIR)" >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) " " >> $@ + $(ECHO) "" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(") + + textTable.getCellByName("A3").setValue(21.5) + textTable.getCellByName("B3").setValue(615.3) + textTable.getCellByName("C3").setValue(-315.7) + textTable.getCellByName("D3").setFormula("sum ") + + textTable.getCellByName("A4").setValue(121.5) + textTable.getCellByName("B4").setValue(-615.3) + textTable.getCellByName("C4").setValue(415.7) + textTable.getCellByName("D4").setFormula("sum ") + + ' Change the CharColor and add a Shadow + Dim cursorPropertySet As XPropertySet = cursor.query(Of XPropertySet)() + cursorPropertySet.setPropertyValue("CharColor", New Any(255)) + cursorPropertySet.setPropertyValue("CharShadowed", New Any(True)) + + ' Create a paragraph break + simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, False) + + ' Inserting colored Text. + simpleText.insertString(cursor, " This is a colored Text - blue with shadow" & vbLf, False) + + ' Create a paragraph break + simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, False) + + ' Create a TextFrame. + Dim textFrameI As IQueryInterface = textDocument.query(Of XMultiServiceFactory)().createInstance("com.sun.star.text.TextFrame") + Dim textFrame As XTextFrame = textFrameI.query(Of XTextFrame)() + + ' Set the size of the frame + Dim size As Size = New Size(15000, 400) + textFrame.query(Of XShape)().setSize(size) + + ' Set anchortype + Dim framePropertySet As XPropertySet = textFrame.query(Of XPropertySet)() + framePropertySet.setPropertyValue("AnchorType", New Any(TextContentAnchorType.AS_CHARACTER)) + + ' Insert the frame + text.insertTextContent(cursor, textFrame, False) + + ' Get the text object of the frame + Dim frameText As XText = textFrame.getText() + Dim frameSimpleText As XSimpleText = frameText.query(Of XSimpleText)() + + ' Create a cursor object + Dim frameCursor As XTextCursor = frameSimpleText.createTextCursor() + + ' Inserting some Text + frameSimpleText.insertString(frameCursor, "The first line in the newly created text frame.", False) + frameSimpleText.insertString(frameCursor, vbLf & "With this second line the height of the frame raises.", False) + + ' Create a paragraph break + simpleText.insertControlCharacter(frameCursor, ControlCharacter.PARAGRAPH_BREAK, False) + + ' Change the CharColor and add a Shadow + cursorPropertySet.setPropertyValue("CharColor", New Any(65536)) + cursorPropertySet.setPropertyValue("CharShadowed", New Any(False)) + + ' Insert another string + text.insertString(cursor, vbLf & " That's all for now !!", False) + End Sub + + Private Sub InsertIntoCell(cellName As String, text As String, textTable As XTextTable) + Dim cell As XCell = textTable.getCellByName(cellName) + Dim simpleText As XSimpleText = cell.query(Of XSimpleText)() + simpleText.setString(text) + End Sub +End Module \ No newline at end of file