diff options
author | RMZeroFour <ritobroto04@gmail.com> | 2024-09-06 18:47:34 +0530 |
---|---|---|
committer | Hossein <hossein@libreoffice.org> | 2024-09-18 08:11:26 +0200 |
commit | b4289da0b4074a219aec899814378c71952e934a (patch) | |
tree | c6bcc2ef8fa68f886219ec6cb345a7f4f094dff2 /odk/examples/dotnet/WriterDemo | |
parent | c3c7b48fa9d4fd5b8f28033ca7453151df9d5f7f (diff) |
.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 <hossein@libreoffice.org>
Diffstat (limited to 'odk/examples/dotnet/WriterDemo')
-rw-r--r-- | odk/examples/dotnet/WriterDemo/csharp/Makefile | 75 | ||||
-rw-r--r-- | odk/examples/dotnet/WriterDemo/csharp/WriterDemo.cs | 144 | ||||
-rw-r--r-- | odk/examples/dotnet/WriterDemo/fsharp/Makefile | 75 | ||||
-rw-r--r-- | odk/examples/dotnet/WriterDemo/fsharp/WriterDemo.fs | 139 | ||||
-rw-r--r-- | odk/examples/dotnet/WriterDemo/vbasic/Makefile | 75 | ||||
-rw-r--r-- | odk/examples/dotnet/WriterDemo/vbasic/WriterDemo.vb | 145 |
6 files changed, 653 insertions, 0 deletions
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) "<Project Sdk=\"Microsoft.NET.Sdk\">" > $@ + $(ECHO) " <PropertyGroup>" >> $@ + $(ECHO) " <AssemblyName>$(APP_NAME)</AssemblyName>" >> $@ + $(ECHO) " <TargetFramework>net8.0</TargetFramework>" >> $@ + $(ECHO) " <OutputType>exe</OutputType>" >> $@ + $(ECHO) " <PublishSingleFile>true</PublishSingleFile>" >> $@ + $(ECHO) " <SelfContained>false</SelfContained>" >> $@ + $(ECHO) " <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>" >> $@ + $(ECHO) " <RestoreAdditionalProjectSources>$(LO_NUPKG_DIR)</RestoreAdditionalProjectSources>" >> $@ + $(ECHO) " </PropertyGroup>" >> $@ + $(ECHO) " <ItemGroup>" >> $@ + $(ECHO) " <PackageReference Include=\"$(LO_NUPKG_ID)\" Version=\"$(LO_NUPKG_VERSION)\" />" >> $@ + $(ECHO) " <Compile Include=\"$(APP_SRC_DIR)/*.$(APP_LANG)\" />" >> $@ + $(ECHO) " </ItemGroup>" >> $@ + $(ECHO) "</Project>" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(<D) + $(COPY) $(<D)/$(APP_EXE_NAME) $@ + +.PHONY: $(APP_NAME) +$(APP_NAME) : $(APP_EXE_FILE) + $(ECHO) -------------------------------------------------------- + $(ECHO) Use the following commands to run the example: + $(ECHO) $(MAKE) run OR $(MAKE) $(APP_NAME).run + $(ECHO) + $(ECHO) And the following commands to clean the example: + $(ECHO) $(MAKE) clean OR $(MAKE) $(APP_NAME).clean + $(ECHO) -------------------------------------------------------- + +.PHONY: $(APP_NAME).run run +$(APP_NAME).run run : $(APP_EXE_FILE) + cd $(<D) && ./$(<F) + +.PHONY: $(APP_NAME).clean clean +$(APP_NAME).clean clean : + -$(DELRECURSIVE) $(APP_MISC_DIR) + -$(DEL) $(APP_EXE_FILE) diff --git a/odk/examples/dotnet/WriterDemo/csharp/WriterDemo.cs b/odk/examples/dotnet/WriterDemo/csharp/WriterDemo.cs new file mode 100644 index 000000000000..de99e2029477 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/csharp/WriterDemo.cs @@ -0,0 +1,144 @@ +/* + * 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.awt; +using com.sun.star.beans; +using com.sun.star.bridge; +using com.sun.star.container; +using com.sun.star.drawing; +using com.sun.star.frame; +using com.sun.star.lang; +using com.sun.star.text; +using com.sun.star.table; +using com.sun.star.uno; + +// Connect to a running office +XComponentContext context = NativeBootstrap.bootstrap(); +// Create a service manager of the remote office +XMultiComponentFactory factory = context.getServiceManager(); + +// Create the Desktop +XDesktop desktop = Desktop.create(context); + +// Open a new empty writer document +XComponentLoader componentLoader = desktop.query<XComponentLoader>(); +XComponent component = componentLoader.loadComponentFromURL( + "private:factory/swriter", "_blank", 0, Array.Empty<PropertyValue>()); + +XTextDocument textDocument = component.query<XTextDocument>(); + +// Create a text object +XText text = textDocument.getText(); +XSimpleText simpleText = text.query<XSimpleText>(); + +// 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<XMultiServiceFactory>().createInstance("com.sun.star.text.TextTable"); +XTextTable textTable = textTableI.query<XTextTable>(); +textTable.initialize(4, 4); +text.insertTextContent(cursor, textTable, false); + +// Set the table background color +XPropertySet tablePropertySet = textTableI.query<XPropertySet>(); +tablePropertySet.setPropertyValue("BackTransparent", new Any(false)); +tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF)); + +// Get first row +XTableRows tableRows = textTable.getRows(); +Any rowAny = tableRows.query<XIndexAccess>().getByIndex(0); + +// Set a different background color for the first row +XPropertySet firstRowPropertySet = rowAny.cast<XPropertySet>(); +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 <A2:C2>"); + +textTable.getCellByName("A3").setValue(21.5); +textTable.getCellByName("B3").setValue(615.3); +textTable.getCellByName("C3").setValue(-315.7); +textTable.getCellByName("D3").setFormula("sum <A3:C3>"); + +textTable.getCellByName("A4").setValue(121.5); +textTable.getCellByName("B4").setValue(-615.3); +textTable.getCellByName("C4").setValue(415.7); +textTable.getCellByName("D4").setFormula("sum <A4:C4>"); + +// Change the CharColor and add a Shadow +XPropertySet cursorPropertySet = cursor.query<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\n", false); + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false); + +// Create a TextFrame. +IQueryInterface textFrameI = textDocument.query<XMultiServiceFactory>().createInstance("com.sun.star.text.TextFrame"); +XTextFrame textFrame = textFrameI.query<XTextFrame>(); + +// Set the size of the frame +Size size = new Size(15000, 400); +textFrame.query<XShape>().setSize(size); + +// Set anchortype +XPropertySet framePropertySet = textFrame.query<XPropertySet>(); +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<XSimpleText>(); + +// 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<XSimpleText>(); + 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) "<Project Sdk=\"Microsoft.NET.Sdk\">" > $@ + $(ECHO) " <PropertyGroup>" >> $@ + $(ECHO) " <AssemblyName>$(APP_NAME)</AssemblyName>" >> $@ + $(ECHO) " <TargetFramework>net8.0</TargetFramework>" >> $@ + $(ECHO) " <OutputType>exe</OutputType>" >> $@ + $(ECHO) " <PublishSingleFile>true</PublishSingleFile>" >> $@ + $(ECHO) " <SelfContained>false</SelfContained>" >> $@ + $(ECHO) " <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>" >> $@ + $(ECHO) " <RestoreAdditionalProjectSources>$(LO_NUPKG_DIR)</RestoreAdditionalProjectSources>" >> $@ + $(ECHO) " </PropertyGroup>" >> $@ + $(ECHO) " <ItemGroup>" >> $@ + $(ECHO) " <PackageReference Include=\"$(LO_NUPKG_ID)\" Version=\"$(LO_NUPKG_VERSION)\" />" >> $@ + $(ECHO) " <Compile Include=\"$(APP_SRC_DIR)/*.$(APP_LANG)\" />" >> $@ + $(ECHO) " </ItemGroup>" >> $@ + $(ECHO) "</Project>" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(<D) + $(COPY) $(<D)/$(APP_EXE_NAME) $@ + +.PHONY: $(APP_NAME) +$(APP_NAME) : $(APP_EXE_FILE) + $(ECHO) -------------------------------------------------------- + $(ECHO) Use the following commands to run the example: + $(ECHO) $(MAKE) run OR $(MAKE) $(APP_NAME).run + $(ECHO) + $(ECHO) And the following commands to clean the example: + $(ECHO) $(MAKE) clean OR $(MAKE) $(APP_NAME).clean + $(ECHO) -------------------------------------------------------- + +.PHONY: $(APP_NAME).run run +$(APP_NAME).run run : $(APP_EXE_FILE) + cd $(<D) && ./$(<F) + +.PHONY: $(APP_NAME).clean clean +$(APP_NAME).clean clean : + -$(DELRECURSIVE) $(APP_MISC_DIR) + -$(DEL) $(APP_EXE_FILE) diff --git a/odk/examples/dotnet/WriterDemo/fsharp/WriterDemo.fs b/odk/examples/dotnet/WriterDemo/fsharp/WriterDemo.fs new file mode 100644 index 000000000000..e486dbece220 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/fsharp/WriterDemo.fs @@ -0,0 +1,139 @@ +// 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/. + +open System +open com.sun.star.awt +open com.sun.star.beans +open com.sun.star.bridge +open com.sun.star.container +open com.sun.star.drawing +open com.sun.star.frame +open com.sun.star.lang +open com.sun.star.text +open com.sun.star.table +open com.sun.star.uno + +let InsertIntoCell (cellName: string, text: string, textTable: XTextTable) = + let cell = textTable.getCellByName(cellName) + let simpleText = cell.query<XSimpleText>() + 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<XComponentLoader>() +let component_ = componentLoader.loadComponentFromURL( + "private:factory/swriter", "_blank", 0, [||]) + +let textDocument = component_.query<XTextDocument>() + +// Create a text object +let text = textDocument.getText() +let simpleText = text.query<XSimpleText>() + +// 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<XMultiServiceFactory>().createInstance("com.sun.star.text.TextTable") +let textTable = textTableI.query<XTextTable>() +textTable.initialize(4, 4) +text.insertTextContent(cursor, textTable, false) + +// Set the table background color +let tablePropertySet = textTableI.query<XPropertySet>() +tablePropertySet.setPropertyValue("BackTransparent", new Any(false)) +tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF)) + +// Get first row +let tableRows = textTable.getRows() +let rowAny = tableRows.query<XIndexAccess>().getByIndex(0) + +// Set a different background color for the first row +let firstRowPropertySet = rowAny.cast<XPropertySet>() +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 <A2:C2>") + +textTable.getCellByName("A3").setValue(21.5) +textTable.getCellByName("B3").setValue(615.3) +textTable.getCellByName("C3").setValue(-315.7) +textTable.getCellByName("D3").setFormula("sum <A3:C3>") + +textTable.getCellByName("A4").setValue(121.5) +textTable.getCellByName("B4").setValue(-615.3) +textTable.getCellByName("C4").setValue(415.7) +textTable.getCellByName("D4").setFormula("sum <A4:C4>") + +// Change the CharColor and add a Shadow +let cursorPropertySet = cursor.query<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" + Environment.NewLine, false) + +// Create a paragraph break +simpleText.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false) + +// Create a TextFrame. +let textFrameI = textDocument.query<XMultiServiceFactory>().createInstance("com.sun.star.text.TextFrame") +let textFrame = textFrameI.query<XTextFrame>() + +// Set the size of the frame +let size = Size(15000, 400) +textFrame.query<XShape>().setSize(size) + +// Set anchortype +let framePropertySet = textFrame.query<XPropertySet>() +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<XSimpleText>() + +// 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) "<Project Sdk=\"Microsoft.NET.Sdk\">" > $@ + $(ECHO) " <PropertyGroup>" >> $@ + $(ECHO) " <AssemblyName>$(APP_NAME)</AssemblyName>" >> $@ + $(ECHO) " <TargetFramework>net8.0</TargetFramework>" >> $@ + $(ECHO) " <OutputType>exe</OutputType>" >> $@ + $(ECHO) " <PublishSingleFile>true</PublishSingleFile>" >> $@ + $(ECHO) " <SelfContained>false</SelfContained>" >> $@ + $(ECHO) " <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>" >> $@ + $(ECHO) " <RestoreAdditionalProjectSources>$(LO_NUPKG_DIR)</RestoreAdditionalProjectSources>" >> $@ + $(ECHO) " </PropertyGroup>" >> $@ + $(ECHO) " <ItemGroup>" >> $@ + $(ECHO) " <PackageReference Include=\"$(LO_NUPKG_ID)\" Version=\"$(LO_NUPKG_VERSION)\" />" >> $@ + $(ECHO) " <Compile Include=\"$(APP_SRC_DIR)/*.$(APP_LANG)\" />" >> $@ + $(ECHO) " </ItemGroup>" >> $@ + $(ECHO) "</Project>" >> $@ + $(ECHOLINE) >> $@ + +$(APP_EXE_FILE) : $(APP_PROJ_FILE) + -$(MKDIR) $(@D) + $(SDK_DOTNET) publish $< $(DOTNET_FLAGS) -o $(<D) + $(COPY) $(<D)/$(APP_EXE_NAME) $@ + +.PHONY: $(APP_NAME) +$(APP_NAME) : $(APP_EXE_FILE) + $(ECHO) -------------------------------------------------------- + $(ECHO) Use the following commands to run the example: + $(ECHO) $(MAKE) run OR $(MAKE) $(APP_NAME).run + $(ECHO) + $(ECHO) And the following commands to clean the example: + $(ECHO) $(MAKE) clean OR $(MAKE) $(APP_NAME).clean + $(ECHO) -------------------------------------------------------- + +.PHONY: $(APP_NAME).run run +$(APP_NAME).run run : $(APP_EXE_FILE) + cd $(<D) && ./$(<F) + +.PHONY: $(APP_NAME).clean clean +$(APP_NAME).clean clean : + -$(DELRECURSIVE) $(APP_MISC_DIR) + -$(DEL) $(APP_EXE_FILE) diff --git a/odk/examples/dotnet/WriterDemo/vbasic/WriterDemo.vb b/odk/examples/dotnet/WriterDemo/vbasic/WriterDemo.vb new file mode 100644 index 000000000000..be9b076f47e0 --- /dev/null +++ b/odk/examples/dotnet/WriterDemo/vbasic/WriterDemo.vb @@ -0,0 +1,145 @@ +' 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/. + +Imports System + +Imports com.sun.star.awt +Imports com.sun.star.beans +Imports com.sun.star.bridge +Imports com.sun.star.container +Imports com.sun.star.drawing +Imports com.sun.star.frame +Imports com.sun.star.lang +Imports com.sun.star.text +Imports com.sun.star.table +Imports com.sun.star.uno + +Module WriterDemo + Sub Main() + ' Connect to a running office + Dim context As XComponentContext = NativeBootstrap.bootstrap() + ' Create a service manager of the remote office + Dim factory As XMultiComponentFactory = context.getServiceManager() + + ' Create the Desktop + Dim desktop_ As XDesktop = Desktop.create(context) + + ' Open a new empty writer document + Dim componentLoader As XComponentLoader = desktop_.query(Of XComponentLoader)() + Dim component As XComponent = componentLoader.loadComponentFromURL( + "private:factory/swriter", "_blank", 0, Array.Empty(Of PropertyValue)()) + + Dim textDocument As XTextDocument = component.query(Of XTextDocument)() + + ' Create a text object + Dim text As XText = textDocument.getText() + Dim simpleText As XSimpleText = text.query(Of XSimpleText)() + + ' Create a cursor object + Dim cursor As XTextCursor = simpleText.createTextCursor() + + ' Inserting some Text + text.insertString(cursor, "The first line in the newly created text document." & vbLf, False) + + ' Create instance of a text table with 4 columns and 4 rows + Dim textTableI As IQueryInterface = textDocument.query(Of XMultiServiceFactory)().createInstance("com.sun.star.text.TextTable") + Dim textTable As XTextTable = textTableI.query(Of XTextTable)() + textTable.initialize(4, 4) + text.insertTextContent(cursor, textTable, False) + + ' Set the table background color + Dim tablePropertySet As XPropertySet = textTableI.query(Of XPropertySet)() + tablePropertySet.setPropertyValue("BackTransparent", New Any(False)) + tablePropertySet.setPropertyValue("BackColor", New Any(&HCCCCFF)) + + ' Get first row + Dim tableRows As XTableRows = textTable.getRows() + Dim rowAny As Any = tableRows.query(Of XIndexAccess)().getByIndex(0) + + ' Set a different background color for the first row + Dim firstRowPropertySet As XPropertySet = rowAny.cast(Of XPropertySet)() + firstRowPropertySet.setPropertyValue("BackTransparent", New Any(False)) + firstRowPropertySet.setPropertyValue("BackColor", New Any(&H6666AA)) + + ' 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 <A2:C2>") + + textTable.getCellByName("A3").setValue(21.5) + textTable.getCellByName("B3").setValue(615.3) + textTable.getCellByName("C3").setValue(-315.7) + textTable.getCellByName("D3").setFormula("sum <A3:C3>") + + textTable.getCellByName("A4").setValue(121.5) + textTable.getCellByName("B4").setValue(-615.3) + textTable.getCellByName("C4").setValue(415.7) + textTable.getCellByName("D4").setFormula("sum <A4:C4>") + + ' 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 |