diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /odk/examples/DevelopersGuide/FirstSteps | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/DevelopersGuide/FirstSteps')
17 files changed, 2012 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/basic/FirstLoadComponent.bas b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/basic/FirstLoadComponent.bas new file mode 100644 index 0000000000..e11b91b235 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/basic/FirstLoadComponent.bas @@ -0,0 +1,41 @@ +' +' 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/. +' + +Sub Main + desktop = createUnoService("com.sun.star.frame.Desktop") + Dim args() + spreadsheet_component = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, args()) + + spreadsheets = spreadsheet_component.getSheets() + spreadsheets.insertNewByName("MySheet", 0) + elem_type = spreadsheets.getElementType() + Msgbox(elem_type.Name) + sheet = spreadsheets.getByName("MySheet") + cell = sheet.getCellByPosition(0, 0) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 1) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 2) + cell.setFormula("=sum(A1:A2)") + + cell.setPropertyValue("CellStyle", "Result") + + spreadsheet_controller = spreadsheet_component.getCurrentController() + spreadsheet_controller.setActiveSheet(sheet) + cell.setPropertyValue("VertJustify", "com.sun.star.table.CellVertJustify.TOP") + formula_cells = sheet.queryContentCells(com.sun.star.sheet.CellFlags.FORMULA) + formulas = formula_cells.getCells() + formula_enum = formulas.createEnumeration() + + Do while formula_enum.hasMoreElements() + formula_cell = formula_enum.nextElement() + Msgbox("Formula cell in column " + formula_cell.getCellAddress().Column + _ + ", row " + formula_cell.getCellAddress().Row + _ + " contains " + cell.getFormula()) + Loop +End Sub diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx new file mode 100644 index 0000000000..9ac650ad49 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <iostream> +#include <sal/main.h> +#include <cppuhelper/bootstrap.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/sheet/CellFlags.hpp> +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace rtl; +using namespace cppu; +using namespace css::uno; +using namespace css::lang; +using namespace css::frame; +using namespace css::container; +using namespace css::sheet; +using namespace css::beans; +using namespace css::table; + +SAL_IMPLEMENT_MAIN() +{ + try + { + Reference<XComponentContext> xRemoteContext = bootstrap(); + if (!xRemoteContext.is()) + { + std::cerr << "ERROR: Could not bootstrap default Office.\n"; + return 1; + } + + Reference<XMultiComponentFactory> xRemoteServiceManager + = xRemoteContext->getServiceManager(); + + Reference<XInterface> desktop = xRemoteServiceManager->createInstanceWithContext( + "com.sun.star.frame.Desktop", xRemoteContext); + Reference<XComponentLoader> xComponentLoader + = Reference<XComponentLoader>(desktop, UNO_QUERY); + + Sequence<PropertyValue> loadProps(0); + Reference<XComponent> xSpreadsheetComponent = xComponentLoader->loadComponentFromURL( + "private:factory/scalc", "_blank", 0, loadProps); + + Reference<XSpreadsheetDocument> xSpreadsheetDocument(xSpreadsheetComponent, UNO_QUERY); + Reference<XSpreadsheets> xSpreadsheets = xSpreadsheetDocument->getSheets(); + xSpreadsheets->insertNewByName("MySheet", (sal_Int16)0); + Type elemType = xSpreadsheets->getElementType(); + + std::cout << elemType.getTypeName() << std::endl; + Any sheet = xSpreadsheets->getByName("MySheet"); + Reference<XSpreadsheet> xSpreadsheet(sheet, UNO_QUERY); + + Reference<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)"); + + Reference<XPropertySet> xCellProps(xCell, UNO_QUERY); + xCellProps->setPropertyValue("CellStyle", Any(OUString("Result"))); + + Reference<XModel> xSpreadsheetModel(xSpreadsheetComponent, UNO_QUERY); + Reference<XController> xSpreadsheetController = xSpreadsheetModel->getCurrentController(); + Reference<XSpreadsheetView> xSpreadsheetView(xSpreadsheetController, UNO_QUERY); + xSpreadsheetView->setActiveSheet(xSpreadsheet); + + // ********************************************************* + // example for use of enum types + xCellProps->setPropertyValue("VertJustify", Any(CellVertJustify_TOP)); + + // ********************************************************* + // example for a sequence of PropertyValue structs + // create an array with one PropertyValue struct, it contains + // references only + loadProps.realloc(1); + + // instantiate PropertyValue struct and set its member fields + PropertyValue asTemplate; + asTemplate.Name = "AsTemplate"; + asTemplate.Value = makeAny(true); + + // assign PropertyValue struct to array of references for PropertyValue + // structs + loadProps[0] = asTemplate; + + // load calc file as a template + // xSpreadsheetComponent = xComponentLoader->loadComponentFromURL( + // "file:///c:/temp/DataAnalysys.ods", "_blank", 0, loadProps); + + // ********************************************************* + // example for use of XEnumerationAccess + Reference<XCellRangesQuery> xCellQuery(sheet, UNO_QUERY); + Reference<XSheetCellRanges> xFormulaCells + = xCellQuery->queryContentCells((sal_Int16)CellFlags::FORMULA); + Reference<XEnumerationAccess> xFormulas = xFormulaCells->getCells(); + Reference<XEnumeration> xFormulaEnum = xFormulas->createEnumeration(); + + while (xFormulaEnum->hasMoreElements()) + { + Reference<XCell> formulaCell(xFormulaEnum->nextElement(), UNO_QUERY); + Reference<XCellAddressable> xCellAddress(formulaCell, UNO_QUERY); + if (xCellAddress.is()) + { + std::cout << "Formula cell in column " << xCellAddress->getCellAddress().Column + << ", row " << xCellAddress->getCellAddress().Row << " contains " + << formulaCell->getFormula() << std::endl; + } + } + } + catch (RuntimeException& e) + { + std::cerr << e.Message << "\n"; + return 1; + } + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/Makefile b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/Makefile new file mode 100644 index 0000000000..47df3bdc4f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/Makefile @@ -0,0 +1,100 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the FirstLoadComponent example of the SDK. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +APP_NAME=FirstLoadComponent + +OUT_APP_INC = $(OUT_INC)/$(APP_NAME) +OUT_APP_GEN = $(OUT_MISC)/$(APP_NAME) +OUT_APP_OBJ=$(OUT_OBJ)/$(APP_NAME) + +CXXFILES = FirstLoadComponent.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + FirstLoadComponent + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_APP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_BIN)/_$(APP_NAME)$(EXE_EXT) : $(OUT_APP_OBJ)/$(APP_NAME).$(OBJ_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_APP_GEN)) +ifeq "$(OS)" "WIN" + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_APP_GEN)/$(basename $(@F)).map \ + $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) +else + $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $< \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STDC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS_BIN) $@ +endif +endif + +$(OUT_BIN)/$(APP_NAME)$(EXE_EXT) : $(OUT_BIN)/_$(APP_NAME)$(EXE_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(COPY) $(subst /,$(PS),$(BIN_DIR)/unoapploader$(EXE_EXT)) $(subst /,$(PS),$@) +# workaround for touch problem under Windows with full qualified paths + make -t $@ + +FirstLoadComponent : $(OUT_BIN)/$(APP_NAME)$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) FirstLoadComponent.run + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/FirstLoadComponent$(EXE_EXT) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_OBJ)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/*FirstLoadComponent*)) diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/FirstLoadComponent.java b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/FirstLoadComponent.java new file mode 100644 index 0000000000..70e531df3d --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/FirstLoadComponent.java @@ -0,0 +1,162 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.sheet.XCellAddressable; +import com.sun.star.sheet.XCellRangesQuery; +import com.sun.star.sheet.XSheetCellRanges; +import com.sun.star.sheet.XSpreadsheet; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.sheet.XSpreadsheetView; +import com.sun.star.sheet.XSpreadsheets; +import com.sun.star.table.XCell; +import com.sun.star.uno.UnoRuntime; + +public class FirstLoadComponent { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + // get the remote office component context + XComponentContext xRemoteContext = Bootstrap.bootstrap(); + if (xRemoteContext == null) { + System.err.println("ERROR: Could not bootstrap default Office."); + } + + XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager(); + + Object desktop = xRemoteServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", xRemoteContext); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); + + PropertyValue[] loadProps = new PropertyValue[0]; + XComponent xSpreadsheetComponent = xComponentLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, loadProps); + + XSpreadsheetDocument xSpreadsheetDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, + xSpreadsheetComponent); + + XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets(); + xSpreadsheets.insertNewByName("MySheet", (short)0); + com.sun.star.uno.Type elemType = xSpreadsheets.getElementType(); + + System.out.println(elemType.getTypeName()); + Object sheet = xSpreadsheets.getByName("MySheet"); + XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface( + XSpreadsheet.class, sheet); + + 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 = UnoRuntime.queryInterface( + XPropertySet.class, xCell); + xCellProps.setPropertyValue("CellStyle", "Result"); + + XModel xSpreadsheetModel = UnoRuntime.queryInterface( + XModel.class, xSpreadsheetComponent); + XController xSpreadsheetController = xSpreadsheetModel.getCurrentController(); + XSpreadsheetView xSpreadsheetView = UnoRuntime.queryInterface(XSpreadsheetView.class, + xSpreadsheetController); + xSpreadsheetView.setActiveSheet(xSpreadsheet); + + // ********************************************************* + // example for use of enum types + xCellProps.setPropertyValue("VertJustify", + com.sun.star.table.CellVertJustify.TOP); + + + // ********************************************************* + // example for a sequence of PropertyValue structs + // create an array with one PropertyValue struct, it contains + // references only + loadProps = new PropertyValue[1]; + + // instantiate PropertyValue struct and set its member fields + PropertyValue asTemplate = new PropertyValue(); + asTemplate.Name = "AsTemplate"; + asTemplate.Value = Boolean.TRUE; + + // assign PropertyValue struct to array of references for PropertyValue + // structs + loadProps[0] = asTemplate; + + // load calc file as template + //xSpreadsheetComponent = xComponentLoader.loadComponentFromURL( + // "file:///c:/temp/DataAnalysys.ods", "_blank", 0, loadProps); + + // ********************************************************* + // example for use of XEnumerationAccess + XCellRangesQuery xCellQuery = UnoRuntime.queryInterface(XCellRangesQuery.class, sheet); + XSheetCellRanges xFormulaCells = xCellQuery.queryContentCells( + (short)com.sun.star.sheet.CellFlags.FORMULA); + XEnumerationAccess xFormulas = xFormulaCells.getCells(); + XEnumeration xFormulaEnum = xFormulas.createEnumeration(); + + while (xFormulaEnum.hasMoreElements()) { + Object formulaCell = xFormulaEnum.nextElement(); + xCell = UnoRuntime.queryInterface(XCell.class, formulaCell); + XCellAddressable xCellAddress = UnoRuntime.queryInterface(XCellAddressable.class, xCell); + System.out.println("Formula cell in column " + + xCellAddress.getCellAddress().Column + + ", row " + xCellAddress.getCellAddress().Row + + " contains " + xCell.getFormula()); + } + + } + catch (java.lang.Exception e){ + e.printStackTrace(); + } + finally { + System.exit( 0 ); + } + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/Makefile b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/Makefile new file mode 100644 index 0000000000..091c9bcda3 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/java/Makefile @@ -0,0 +1,92 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the FirstSteps examples of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +EXAMPLE_NAME=FirstLoadComponent +OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME) + +APP_NAME=FirstLoadComponent +APP_JAR=$(OUT_APP_CLASS)/$(APP_NAME).jar + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(OUT_APP_CLASS)) + + +# Targets +.PHONY: ALL +ALL : \ + $(EXAMPLE_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_CLASS)/%.class : %.java + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $< + +$(OUT_APP_CLASS)/%.mf : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo Main-Class: com.sun.star.lib.loader.Loader> $@ + $(ECHOLINE)>> $@ + @echo Name: com/sun/star/lib/loader/Loader.class>> $@ + @echo Application-Class: $*>> $@ + +$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class + +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES) + +$(APP_JAR) : $(OUT_APP_CLASS)/$(APP_NAME).mf $(OUT_APP_CLASS)/$(APP_NAME).class + +$(EXAMPLE_NAME) : $(APP_JAR) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) $(APP_NAME).run + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_APP_CLASS)/%.jar + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS)) diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py new file mode 100755 index 0000000000..a5d93d799f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/python/FirstLoadComponent.py @@ -0,0 +1,62 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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/. +# + +import uno +import officehelper +import sys +import traceback +from com.sun.star.sheet.CellFlags import FORMULA + + +def main(): + try: + remote_context = officehelper.bootstrap() + if remote_context is None: + print("ERROR: Could not bootstrap default Office.") + sys.exit(1) + srv_mgr = remote_context.getServiceManager() + desktop = srv_mgr.createInstanceWithContext("com.sun.star.frame.Desktop", remote_context) + spreadsheet_component = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, tuple()) + spreadsheets = spreadsheet_component.getSheets() + spreadsheets.insertNewByName("MySheet", 0) + elem_type = spreadsheets.getElementType() + print(elem_type) + sheet = spreadsheets.getByName("MySheet") + cell = sheet.getCellByPosition(0, 0) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 1) + cell.setValue(21) + cell = sheet.getCellByPosition(0, 2) + cell.setFormula("=sum(A1:A2)") + + cell.setPropertyValue("CellStyle", "Result") + + spreadsheet_controller = spreadsheet_component.getCurrentController() + spreadsheet_controller.setActiveSheet(sheet) + cell.setPropertyValue("VertJustify", "com.sun.star.table.CellVertJustify.TOP") + formula_cells = sheet.queryContentCells(FORMULA) + formulas = formula_cells.getCells() + formula_enum = formulas.createEnumeration() + + while formula_enum.hasMoreElements(): + formula_cell = formula_enum.nextElement() + print("Formula cell in column " + str(formula_cell.getCellAddress().Column) + + ", row " + str(formula_cell.getCellAddress().Row) + + " contains " + cell.getFormula()) + + except Exception as e: + print(e) + traceback.print_exc() + sys.exit(1) + + +if __name__ == "__main__": + main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/basic/FirstUnoContact.bas b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/basic/FirstUnoContact.bas new file mode 100644 index 0000000000..ba8f542d83 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/basic/FirstUnoContact.bas @@ -0,0 +1,17 @@ +' +' 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/. +' + +Sub Main + Set oContext = GetDefaultContext() + MsgBox "Connected to a running office..." + Set oServiceManager=oContext.GetServiceManager() + If IsNull(oServiceManager) Then + bAvailable = "not " + End If + MsgBox "ServiceManager is " + bAvailable + "available" +End Sub
\ No newline at end of file diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/FirstUnoContact.cxx b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/FirstUnoContact.cxx new file mode 100644 index 0000000000..a19bfbb023 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/FirstUnoContact.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; + * fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <cppuhelper/bootstrap.hxx> +#include <cstddef> +#include <iostream> +#include <sal/main.h> + +SAL_IMPLEMENT_MAIN() +{ + try + { + css::uno::Reference<css::uno::XComponentContext> xContext(cppu::bootstrap()); + std::cout << "Connected to a running office ..." << std::endl; + css::uno::Reference<css::lang::XMultiComponentFactory> xMCF = xContext->getServiceManager(); + std::string available = xMCF != NULL ? "available" : "not available"; + std::cout << "remote ServiceManager is " + available << std::endl; + } + catch (css::uno::Exception& e) + { + std::cout << e.Message << std::endl; + return 1; + } + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s + * cinkeys+=0=break: */ diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/Makefile b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/Makefile new file mode 100644 index 0000000000..a996044c60 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/cxx/Makefile @@ -0,0 +1,100 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the FirstUnoContact example of the SDK. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +APP_NAME=FirstUnoContact + +OUT_APP_INC = $(OUT_INC)/$(APP_NAME) +OUT_APP_GEN = $(OUT_MISC)/$(APP_NAME) +OUT_APP_OBJ=$(OUT_OBJ)/$(APP_NAME) + +CXXFILES = FirstUnoContact.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + FirstUnoContact + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_APP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_BIN)/_$(APP_NAME)$(EXE_EXT) : $(OUT_APP_OBJ)/$(APP_NAME).$(OBJ_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_APP_GEN)) +ifeq "$(OS)" "WIN" + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_APP_GEN)/$(basename $(@F)).map \ + $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) +else + $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $< \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STDC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS_BIN) $@ +endif +endif + +$(OUT_BIN)/$(APP_NAME)$(EXE_EXT) : $(OUT_BIN)/_$(APP_NAME)$(EXE_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(COPY) $(subst /,$(PS),$(BIN_DIR)/unoapploader$(EXE_EXT)) $(subst /,$(PS),$@) +# workaround for touch problem under Windows with full qualified paths + make -t $@ + +FirstUnoContact : $(OUT_BIN)/$(APP_NAME)$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) FirstUnoContact.run + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/FirstUnoContact$(EXE_EXT) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_OBJ)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/*FirstUnoContact*)) diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/FirstUnoContact.java b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/FirstUnoContact.java new file mode 100644 index 0000000000..9f4de1a6e6 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/FirstUnoContact.java @@ -0,0 +1,61 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +public class FirstUnoContact { + + public static void main(String[] args) { + try { + // get the remote office component context + com.sun.star.uno.XComponentContext xContext = + com.sun.star.comp.helper.Bootstrap.bootstrap(); + + System.out.println("Connected to a running office ..."); + + com.sun.star.lang.XMultiComponentFactory xMCF = + xContext.getServiceManager(); + + String available = (xMCF != null ? "available" : "not available"); + System.out.println( "remote ServiceManager is " + available ); + } + catch (java.lang.Exception e){ + e.printStackTrace(); + } + finally { + System.exit(0); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/Makefile b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/Makefile new file mode 100644 index 0000000000..eae7d4452f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/Makefile @@ -0,0 +1,92 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the FirstSteps examples of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +EXAMPLE_NAME=FirstUnoContact +OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME) + +APP_NAME=FirstUnoContact +APP_JAR=$(OUT_APP_CLASS)/$(APP_NAME).jar + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(OUT_APP_CLASS)) + + +# Targets +.PHONY: ALL +ALL : \ + $(EXAMPLE_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_CLASS)/%.class : %.java + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $< + +$(OUT_APP_CLASS)/%.mf : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo Main-Class: com.sun.star.lib.loader.Loader> $@ + $(ECHOLINE)>> $@ + @echo Name: com/sun/star/lib/loader/Loader.class>> $@ + @echo Application-Class: $*>> $@ + +$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class + +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES) + +$(APP_JAR) : $(OUT_APP_CLASS)/$(APP_NAME).mf $(OUT_APP_CLASS)/$(APP_NAME).class + +$(EXAMPLE_NAME) : $(APP_JAR) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) $(APP_NAME).run + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_APP_CLASS)/%.jar + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS)) diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/build.xml b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/build.xml new file mode 100644 index 0000000000..ec0eba70ad --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/java/build.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<project basedir="." default="all" name="FirstUnoContact"> + + <property environment="env"/> + <property name="OFFICE_HOME" value="${env.OFFICE_HOME}"/> + <property name="OO_SDK_HOME" value="${env.OO_SDK_HOME}"/> + + <target name="init"> + <property name="OUTDIR" value="${OO_SDK_HOME}/WINExample.out/class/FirstUnoContact"/> + </target> + + <path id="office.class.path"> + <filelist dir="${OFFICE_HOME}/program/classes" + files="libreoffice.jar"/> + </path> + + <fileset id="bootstrap.glue.code" dir="${OO_SDK_HOME}/classes"> + <patternset> + <include name="com/sun/star/lib/loader/*.class"/> + </patternset> + </fileset> + + <target name="compile" depends="init"> + <mkdir dir="${OUTDIR}"/> + <javac debug="true" deprecation="true" destdir="${OUTDIR}" srcdir="."> + <classpath refid="office.class.path"/> + </javac> + </target> + + <target name="jar" depends="init,compile"> + <jar basedir="${OUTDIR}" compress="true" + jarfile="${OUTDIR}/FirstUnoContact.jar"> + <exclude name="**/*.java"/> + <exclude name="*.jar"/> + <fileset refid="bootstrap.glue.code"/> + <manifest> + <attribute name="Main-Class" value="com.sun.star.lib.loader.Loader"/> + <section name="com/sun/star/lib/loader/Loader.class"> + <attribute name="Application-Class" value="FirstUnoContact"/> + </section> + </manifest> + </jar> + </target> + + <target name="all" description="Build everything." depends="init,compile,jar"> + <echo message="Application built. FirstUnoContact!"/> + </target> + + <target name="run" description="Try running it." depends="init,all"> + <java jar="${OUTDIR}/FirstUnoContact.jar" failonerror="true" fork="true"> + </java> + </target> + + <target name="clean" description="Clean all build products." depends="init"> + <delete> + <fileset dir="${OUTDIR}"> + <include name="**/*.class"/> + </fileset> + </delete> + <delete file="${OUTDIR}/FirstUnoContact.jar"/> + </target> + +</project> diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/python/FirstUnoContact.py b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/python/FirstUnoContact.py new file mode 100644 index 0000000000..06cd0bc5a7 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/python/FirstUnoContact.py @@ -0,0 +1,24 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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/. +# + +import uno +import officehelper + +try: + xContext = officehelper.bootstrap() + print("Connected to a running office ...") + xMCF = xContext.getServiceManager() + available = "not available" if xMCF is None else "available" + print("remote ServiceManager is " + available) + +except Exception as e: + print(e) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: + diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/basic/HelloTextTableShape.bas b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/basic/HelloTextTableShape.bas new file mode 100644 index 0000000000..96d75a445f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/basic/HelloTextTableShape.bas @@ -0,0 +1,223 @@ +' +' 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/. +' + +Function new_doc_component(doc_type As String) + load_url = "private:factory/" & doc_type + desktop = createUnoService("com.sun.star.frame.Desktop") + Set new_doc_component = desktop.loadComponentFromURL(load_url, "_blank", 0, Array()) +End Function + +Sub use_documents + use_writer() + use_calc() + use_draw() +End Sub + +Sub use_writer + Set doc = new_doc_component("swriter") + Set xtext = doc.Text + manipulateText(xtext) + + ' insert TextTable and get cell text, then manipulate text in cell + Set table = doc.createInstance("com.sun.star.text.TextTable") + xtext.insertTextContent(xtext.End, table, False) + + xcell = table.getCellByPosition(0, 1) + manipulateText(xcell.getText()) + manipulateTable(table) + + ' insert RectangleShape and get shape text, then manipulate text + Set writer_shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + + Dim Point As New com.sun.star.awt.Point + Dim Size As New com.sun.star.awt.Size + Size.Width= 10000 + Size.Height= 10000 + writer_shape.setSize(Size) + xtext.insertTextContent(xtext.End, writer_shape, False) + ' wrap text inside shape + writer_shape.TextContourFrame = True + + manipulateText(writer_shape) + manipulateShape(writer_shape) + + bookmark = doc.createInstance("com.sun.star.text.Bookmark") + bookmark.Name = "MyUniqueBookmarkName" + ' insert the bookmark at the end of the document + xtext.insertTextContent(xtext.End, bookmark, False) + + ' Query the added bookmark and set a string + found_bookmark = doc.Bookmarks.getByName("MyUniqueBookmarkName") + found_bookmark.Anchor.String = _ + "The throat mike, glued to her neck, " +_ + "looked as much as possible like an analgesic dermadisk." _ + + Set text_table = doc.TextTables + For i = 0 To text_table.getCount() - 1 + text_table.getByIndex(i).BackColor = &HC8FFB9 + Next +End Sub + +Sub use_calc + doc = new_doc_component("scalc") + sheet = doc.Sheets(0) + + ' get cell A2 in first sheet + cell = sheet.getCellByPosition(1, 0) + cell.IsTextWrapped = True + + manipulateText(cell.getText()) + manipulateTable(sheet) + + ' create and insert RectangleShape and get shape text, + ' then manipulate text + shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + + Dim Point As New com.sun.star.awt.Point + Dim Size As New com.sun.star.awt.Size + + shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + Point.X = 7000 + Point.Y = 3000 + Size.Width= 10000 + Size.Height= 10000 + shape.setSize(Size) + shape.setPosition(Point) + + shape.TextContourFrame = True + sheet.DrawPage.add(shape) + + manipulateText(shape) + manipulateShape(shape) +End Sub + +Sub use_draw + doc = new_doc_component("sdraw") + + Dim Point As New com.sun.star.awt.Point + Dim Size As New com.sun.star.awt.Size + + draw_shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + Point.X = 5000 + Point.Y = 5000 + Size.Width= 10000 + Size.Height= 10000 + draw_shape.setSize(Size) + draw_shape.setPosition(Point) + doc.DrawPages(0).add(draw_shape) + + ' wrap text inside shape + draw_shape.TextContourFrame = True + + manipulateText(draw_shape) + manipulateShape(draw_shape) +End Sub + +Sub manipulateText(xtext As Object) + ' Insert text content + + 'param xtext: object that implements com.sun.star.text.XText interface. + + ' simply set whole text as one string + xtext.String = "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 text cursor for selecting and formatting + text_cursor = xtext.createTextCursor() + ' use cursor to select "He lay" and apply bold italic + text_cursor.gotoStart(False) + text_cursor.goRight(6, True) + ' from CharacterProperties + text_cursor.CharPosture = com.sun.star.awt.FontSlant.ITALIC + text_cursor.CharWeight = 150 + + ' add more text at the end of the text using insertString + text_cursor.gotoEnd(False) + content = _ + " 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." + + xtext.insertString(text_cursor, content, False) + ' after insertString the cursor is behind the inserted text, + ' insert more text + content = CHR$(10) & " ""Is that the mill?"" he asked." + xtext.insertString(text_cursor, content, False) +End Sub + +Sub manipulateTable(xcellrange As Object) + 'Format a table area + + ':param xcellrange: object that implements com.sun.star.table.XCellRange interface. + + ' enter column titles and a cell value + xcellrange.getCellByPosition(0, 0).SetString("Quotation") + xcellrange.getCellByPosition(0, 1).SetString("Year") + xcellrange.getCellByPosition(1, 1).SetValue(1940) + + ' format table headers and table borders + ' we need to distinguish text and sheet tables: + ' property name for cell colors is different in text and sheet cells + ' we want to apply TableBorder to whole text table, but only to sheet + ' cells with content + + background_color = &H99CCFF + + ' create description for blue line, width 10 + Dim border_line As New com.sun.star.table.BorderLine + border_line.Color = &H000099 + border_line.OuterLineWidth = 10 + ' apply line description to all border lines and make them valid + Dim border As New com.sun.star.table.TableBorder + border.VerticalLine = border_line + border.HorizontalLine = border_line + border.LeftLine = border_line + border.RightLine = border_line + border.TopLine = border_line + border.BottomLine = border_line + border.IsVerticalLineValid = True + border.IsHorizontalLineValid = True + border.IsLeftLineValid = True + border.IsRightLineValid = True + border.IsTopLineValid = True + border.IsBottomLineValid = True + + + If xcellrange.supportsService("com.sun.star.sheet.Spreadsheet") Then + selected_cells = xcellrange.getCellRangeByName("A1:B2") + selected_cells.CellBackColor = background_color + selected_cells.TableBorder = border +' Print selected_cells.TableBorder.TopLine.Color + ElseIf xcellrange.supportsService("com.sun.star.text.TextTable") Then + selected_cells = xcellrange.getCellRangeByName("A1:B1") + selected_cells.BackColor = background_color + xcellrange.TableBorder = border +' Print xcellrange.TableBorder.TopLine.Color + End If +End Sub + +Sub manipulateShape(xshape As Object) + 'Format a shape + 'param xshape: object that implements com.sun.star.drawing.XShape interface. + + xshape.FillColor = &H99CCFF + xshape.LineColor = &H000099 + xshape.RotateAngle = 3000 + + xshape.TextLeftDistance = 0 + xshape.TextRightDistance = 0 + xshape.TextUpperDistance = 0 + xshape.TextLowerDistance = 0 +End Sub + +Sub Main + use_documents() +End Sub
\ No newline at end of file diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/HelloTextTableShape.java b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/HelloTextTableShape.java new file mode 100644 index 0000000000..66bb2d8d64 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/HelloTextTableShape.java @@ -0,0 +1,439 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +import com.sun.star.lang.XComponent; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.PropertyValue; +import com.sun.star.text.XTextDocument; +import com.sun.star.text.XText; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextContent; +import com.sun.star.table.XCellRange; +import com.sun.star.table.XCell; +import com.sun.star.table.TableBorder; +import com.sun.star.table.BorderLine; +import com.sun.star.drawing.XShape; +import com.sun.star.awt.Size; +import com.sun.star.awt.Point; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.container.XIndexAccess; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.drawing.XDrawPageSupplier; +import com.sun.star.drawing.XDrawPage; + +public class HelloTextTableShape { + + private XComponentContext xRemoteContext = null; + private XMultiComponentFactory xRemoteServiceManager = null; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + HelloTextTableShape helloTextTableShape1 = new HelloTextTableShape(); + try { + helloTextTableShape1.useDocuments(); + } + catch (java.lang.Exception e){ + System.err.println(e.getMessage()); + e.printStackTrace(); + } + finally { + System.exit(0); + } + + } + + protected void useDocuments() throws java.lang.Exception { + useWriter(); + useCalc(); + useDraw(); + } + + protected void useWriter() throws java.lang.Exception { + try { + // create new writer document and get text, then manipulate text + XComponent xWriterComponent = newDocComponent("swriter"); + XTextDocument xTextDocument = UnoRuntime.queryInterface( + XTextDocument.class, xWriterComponent); + XText xText = xTextDocument.getText(); + + manipulateText(xText); + + // get internal service factory of the document + XMultiServiceFactory xWriterFactory = UnoRuntime.queryInterface( + XMultiServiceFactory.class, xWriterComponent); + + // insert TextTable and get cell text, then manipulate text in cell + Object table = xWriterFactory.createInstance("com.sun.star.text.TextTable"); + XTextContent xTextContentTable = UnoRuntime.queryInterface( + XTextContent.class, table); + + xText.insertTextContent(xText.getEnd(), xTextContentTable, false); + + XCellRange xCellRange = UnoRuntime.queryInterface( + XCellRange.class, table); + XCell xCell = xCellRange.getCellByPosition(0, 1); + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); + + manipulateText(xCellText); + manipulateTable(xCellRange); + + // insert RectangleShape and get shape text, then manipulate text + Object writerShape = xWriterFactory.createInstance( + "com.sun.star.drawing.RectangleShape"); + XShape xWriterShape = UnoRuntime.queryInterface( + XShape.class, writerShape); + xWriterShape.setSize(new Size(10000, 10000)); + XTextContent xTextContentShape = UnoRuntime.queryInterface( + XTextContent.class, writerShape); + + xText.insertTextContent(xText.getEnd(), xTextContentShape, false); + + XPropertySet xShapeProps = UnoRuntime.queryInterface( + XPropertySet.class, writerShape); + // wrap text inside shape + xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE); + + + XText xShapeText = UnoRuntime.queryInterface(XText.class, writerShape); + + manipulateText(xShapeText); + manipulateShape(xWriterShape); + +/* more code snippets used in the manual: + + Object bookmark = xWriterFactory.createInstance ( "com.sun.star.text.Bookmark" ); + // name the bookmark + XNamed xNamed = (XNamed) UnoRuntime.queryInterface ( + XNamed.class, bookmark ); + xNamed.setName("MyUniqueBookmarkName"); + + // get XTextContent interface and insert it at the end of the document + XTextContent xTextContent = (XTextContent) UnoRuntime.queryInterface ( + XTextContent.class, bookmark ); + //mxDocText.insertTextContent ( mxDocText.getEnd(), xTextContent, false ); + xText.insertTextContent ( xText.getEnd(), xTextContent, false ); + + //query BookmarksSupplier + XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)UnoRuntime.queryInterface( + XBookmarksSupplier.class, xWriterComponent); + XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); + Object foundBookmark = xNamedBookmarks.getByName("MyUniqueBookmarkName"); + XTextContent xFoundBookmark = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, foundBookmark); + XTextRange xFound = xFoundBookmark.getAnchor(); + xFound.setString(" The throat mike, glued to her neck, " + + "looked as much as possible like an analgesic dermadisk."); + + + + + // first query the XTextTablesSupplier interface from our document + XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface( + XTextTablesSupplier.class, xWriterComponent); + // get the tables collection + XNameAccess xNamedTables = xTablesSupplier.getTextTables(); + + // now query the XIndexAccess from the tables collection + XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess.class, xNamedTables); + + // we need properties + XPropertySet xTableProps = null; + + // get the tables + for (int i = 0; i < xIndexedTables.getCount(); i++) { + //Object table = xIndexedTables.getByIndex(i); + table = xIndexedTables.getByIndex(i); + xTableProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, table); + xTableProps.setPropertyValue("BackColor", Integer.valueOf(0xC8FFB9)); + } + */ + } + catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 + xRemoteContext = null; + throw e; + } + + } + + protected void useCalc() throws java.lang.Exception { + try { + // create new calc document and manipulate cell text + XComponent xCalcComponent = newDocComponent("scalc"); + XSpreadsheetDocument xSpreadsheetDocument = + UnoRuntime.queryInterface( + XSpreadsheetDocument .class, xCalcComponent); + Object sheets = xSpreadsheetDocument.getSheets(); + XIndexAccess xIndexedSheets = UnoRuntime.queryInterface( + XIndexAccess.class, sheets); + Object sheet = xIndexedSheets.getByIndex(0); + + //get cell A2 in first sheet + XCellRange xSpreadsheetCells = UnoRuntime.queryInterface( + XCellRange.class, sheet); + XCell xCell = xSpreadsheetCells.getCellByPosition(0,1); + XPropertySet xCellProps = UnoRuntime.queryInterface( + XPropertySet.class, xCell); + xCellProps.setPropertyValue("IsTextWrapped", Boolean.TRUE); + + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); + + manipulateText(xCellText); + manipulateTable(xSpreadsheetCells); + + // get internal service factory of the document + XMultiServiceFactory xCalcFactory = UnoRuntime.queryInterface( + XMultiServiceFactory.class, xCalcComponent); + // get Drawpage + XDrawPageSupplier xDrawPageSupplier = UnoRuntime.queryInterface(XDrawPageSupplier.class, sheet); + XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage(); + + // create and insert RectangleShape and get shape text, then manipulate text + Object calcShape = xCalcFactory.createInstance( + "com.sun.star.drawing.RectangleShape"); + XShape xCalcShape = UnoRuntime.queryInterface( + XShape.class, calcShape); + xCalcShape.setSize(new Size(10000, 10000)); + xCalcShape.setPosition(new Point(7000, 3000)); + + xDrawPage.add(xCalcShape); + + XPropertySet xShapeProps = UnoRuntime.queryInterface( + XPropertySet.class, calcShape); + // wrap text inside shape + xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE); + + + XText xShapeText = UnoRuntime.queryInterface(XText.class, calcShape); + + manipulateText(xShapeText); + manipulateShape(xCalcShape); + + } + catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 + xRemoteContext = null; + throw e; + } + + } + + protected void useDraw() throws java.lang.Exception { + try { + //create new draw document and insert ractangle shape + XComponent xDrawComponent = newDocComponent("sdraw"); + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xDrawComponent); + + Object drawPages = xDrawPagesSupplier.getDrawPages(); + XIndexAccess xIndexedDrawPages = UnoRuntime.queryInterface( + XIndexAccess.class, drawPages); + Object drawPage = xIndexedDrawPages.getByIndex(0); + XDrawPage xDrawPage = UnoRuntime.queryInterface(XDrawPage.class, drawPage); + + // get internal service factory of the document + XMultiServiceFactory xDrawFactory = + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDrawComponent); + + Object drawShape = xDrawFactory.createInstance( + "com.sun.star.drawing.RectangleShape"); + XShape xDrawShape = UnoRuntime.queryInterface(XShape.class, drawShape); + xDrawShape.setSize(new Size(10000, 20000)); + xDrawShape.setPosition(new Point(5000, 5000)); + xDrawPage.add(xDrawShape); + + XText xShapeText = UnoRuntime.queryInterface(XText.class, drawShape); + XPropertySet xShapeProps = UnoRuntime.queryInterface( + XPropertySet.class, drawShape); + + // wrap text inside shape + xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE); + + manipulateText(xShapeText); + manipulateShape(xDrawShape); + } + catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 + xRemoteContext = null; + throw e; + } + + + } + + protected void manipulateText(XText xText) throws com.sun.star.uno.Exception { + // simply set whole text as one string + 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 text cursor for selecting and formatting + XTextCursor xTextCursor = xText.createTextCursor(); + XPropertySet xCursorProps = UnoRuntime.queryInterface( + XPropertySet.class, xTextCursor); + + // use cursor to select "He lay" and apply bold italic + xTextCursor.gotoStart(false); + xTextCursor.goRight((short)6, true); + // from CharacterProperties + xCursorProps.setPropertyValue("CharPosture", + com.sun.star.awt.FontSlant.ITALIC); + xCursorProps.setPropertyValue("CharWeight", + Float.valueOf(com.sun.star.awt.FontWeight.BOLD)); + + // add more text at the end of the text using insertString + xTextCursor.gotoEnd(false); + xText.insertString(xTextCursor, " 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); + // after insertString the cursor is behind the inserted text, insert more text + xText.insertString(xTextCursor, "\n \"Is that the mill?\" he asked.", false); + } + + protected void manipulateTable(XCellRange xCellRange) throws com.sun.star.uno.Exception { + + String backColorPropertyName = ""; + XPropertySet xTableProps = null; + + // enter column titles and a cell value + XCell xCell = xCellRange.getCellByPosition(0,0); + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); + xCellText.setString("Quotation"); + xCell = xCellRange.getCellByPosition(1,0); + xCellText = UnoRuntime.queryInterface(XText.class, xCell); + xCellText.setString("Year"); + xCell = xCellRange.getCellByPosition(1,1); + xCell.setValue(1940); + XCellRange xSelectedCells = xCellRange.getCellRangeByName("A1:B1"); + XPropertySet xCellProps = UnoRuntime.queryInterface( + XPropertySet.class, xSelectedCells); + + // format table headers and table borders + // we need to distinguish text and sheet tables: + // property name for cell colors is different in text and sheet cells + // we want to apply TableBorder to whole text table, but only to sheet cells with content + XServiceInfo xServiceInfo = UnoRuntime.queryInterface( + XServiceInfo.class, xCellRange); + if (xServiceInfo.supportsService("com.sun.star.sheet.Spreadsheet")) { + backColorPropertyName = "CellBackColor"; + xSelectedCells = xCellRange.getCellRangeByName("A1:B2"); + xTableProps = UnoRuntime.queryInterface( + XPropertySet.class, xSelectedCells); + } + else if (xServiceInfo.supportsService("com.sun.star.text.TextTable")) { + backColorPropertyName = "BackColor"; + xTableProps = UnoRuntime.queryInterface( + XPropertySet.class, xCellRange); + } + // set cell background color + xCellProps.setPropertyValue(backColorPropertyName, Integer.valueOf(0x99CCFF)); + + // set table borders + // create description for blue line, width 10 + BorderLine theLine = new BorderLine(); + theLine.Color = 0x000099; + theLine.OuterLineWidth = 10; + // apply line description to all border lines and make them valid + TableBorder bord = new TableBorder(); + bord.VerticalLine = bord.HorizontalLine = + bord.LeftLine = bord.RightLine = + bord.TopLine = bord.BottomLine = + theLine; + bord.IsVerticalLineValid = bord.IsHorizontalLineValid = + bord.IsLeftLineValid = bord.IsRightLineValid = + bord.IsTopLineValid = bord.IsBottomLineValid = + true; + + xTableProps.setPropertyValue("TableBorder", bord); + + bord = (TableBorder)xTableProps.getPropertyValue("TableBorder"); + theLine = bord.TopLine; + int col = theLine.Color; + System.out.println(col); + } + + protected void manipulateShape(XShape xShape) throws com.sun.star.uno.Exception { + XPropertySet xShapeProps = UnoRuntime.queryInterface(XPropertySet.class, xShape); + xShapeProps.setPropertyValue("FillColor", Integer.valueOf(0x99CCFF)); + xShapeProps.setPropertyValue("LineColor", Integer.valueOf(0x000099)); + xShapeProps.setPropertyValue("RotateAngle", Integer.valueOf(3000)); + + xShapeProps.setPropertyValue("TextLeftDistance", Integer.valueOf(0)); + xShapeProps.setPropertyValue("TextRightDistance", Integer.valueOf(0)); + xShapeProps.setPropertyValue("TextUpperDistance", Integer.valueOf(0)); + xShapeProps.setPropertyValue("TextLowerDistance", Integer.valueOf(0)); + } + + + protected XComponent newDocComponent(String docType) throws java.lang.Exception { + String loadUrl = "private:factory/" + docType; + xRemoteServiceManager = this.getRemoteServiceManager(); + Object desktop = xRemoteServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", xRemoteContext); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface( + XComponentLoader.class, desktop); + PropertyValue[] loadProps = new PropertyValue[0]; + return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps); + } + + protected XMultiComponentFactory getRemoteServiceManager() throws java.lang.Exception { + if (xRemoteContext == null && xRemoteServiceManager == null) { + try { + // First step: get the remote office component context + xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + System.out.println("Connected to a running office ..."); + + xRemoteServiceManager = xRemoteContext.getServiceManager(); + } + catch( Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + return xRemoteServiceManager; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/Makefile b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/Makefile new file mode 100644 index 0000000000..615e86bf3f --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/java/Makefile @@ -0,0 +1,92 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the FirstSteps examples of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +EXAMPLE_NAME=HelloTextTableShape +OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME) + +APP_NAME=HelloTextTableShape +APP_JAR=$(OUT_APP_CLASS)/$(APP_NAME).jar + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(OUT_APP_CLASS)) + + +# Targets +.PHONY: ALL +ALL : \ + $(EXAMPLE_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_CLASS)/%.class : %.java + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $< + +$(OUT_APP_CLASS)/%.mf : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo Main-Class: com.sun.star.lib.loader.Loader> $@ + $(ECHOLINE)>> $@ + @echo Name: com/sun/star/lib/loader/Loader.class>> $@ + @echo Application-Class: $*>> $@ + +$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class + +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES) + +$(APP_JAR) : $(OUT_APP_CLASS)/$(APP_NAME).mf $(OUT_APP_CLASS)/$(APP_NAME).class + +$(EXAMPLE_NAME) : $(APP_JAR) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) $(APP_NAME).run + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_APP_CLASS)/%.jar + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS)) diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/python/HelloTextTableShape.py b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/python/HelloTextTableShape.py new file mode 100644 index 0000000000..a0a101e618 --- /dev/null +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/python/HelloTextTableShape.py @@ -0,0 +1,243 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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/. +# + +import sys +import traceback + +import uno +import officehelper + +from com.sun.star.lang import DisposedException +from com.sun.star.awt.FontSlant import ITALIC +from com.sun.star.awt.FontWeight import BOLD +from com.sun.star.table import BorderLine +from com.sun.star.table import TableBorder +from com.sun.star.awt import Size +from com.sun.star.awt import Point + + +class HelloTextTableShape: + + def __init__(self): + self.remote_context = None + self.remote_service_manager = None + + def use_documents(self) -> None: + self.use_writer() + self.use_calc() + self.use_draw() + + def get_remote_service_manager(self) -> None: + try: + self.remote_context = officehelper.bootstrap() + print("Connected to a running office ...") + return self.remote_context.ServiceManager + except Exception as e: + traceback.print_exc() + sys.exit(1) + + def new_doc_component(self, doc_type: str) -> None: + load_url = "private:factory/" + doc_type + self.remote_service_manager = self.get_remote_service_manager() + desktop = self.remote_service_manager.createInstanceWithContext( + "com.sun.star.frame.Desktop", self.remote_context + ) + return desktop.loadComponentFromURL(load_url, "_blank", 0, tuple([])) + + def use_writer(self) -> None: + try: + doc = self.new_doc_component("swriter") + xtext = doc.Text + self.manipulateText(xtext) + + # insert TextTable and get cell text, then manipulate text in cell + table = doc.createInstance("com.sun.star.text.TextTable") + xtext.insertTextContent(xtext.End, table, False) + + xcell = table[1, 0] + self.manipulateText(xcell) + self.manipulateTable(table) + + # insert RectangleShape and get shape text, then manipulate text + writer_shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + writer_shape.setSize(Size(10000, 10000)) + xtext.insertTextContent(xtext.End, writer_shape, False) + # wrap text inside shape + writer_shape.TextContourFrame = True + + self.manipulateText(writer_shape) + self.manipulateShape(writer_shape) + + bookmark = doc.createInstance("com.sun.star.text.Bookmark") + bookmark.Name = "MyUniqueBookmarkName" + # insert the bookmark at the end of the document + xtext.insertTextContent(xtext.End, bookmark, False) + + # Query the added bookmark and set a string + found_bookmark = doc.Bookmarks.getByName("MyUniqueBookmarkName") + found_bookmark.Anchor.String = ( + "The throat mike, glued to her neck, " + "looked as much as possible like an analgesic dermadisk." + ) + + for text_table in doc.TextTables: + text_table.BackColor = 0xC8FFB9 + except DisposedException: + self.remote_context = None + raise + + def use_calc(self) -> None: + try: + doc = self.new_doc_component("scalc") + sheet = doc.Sheets[0] + + # get cell A2 in first sheet + cell = sheet[1, 0] + cell.IsTextWrapped = True + + self.manipulateText(cell) + self.manipulateTable(sheet) + + # create and insert RectangleShape and get shape text, + # then manipulate text + shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + shape.Size = Size(10000, 10000) + shape.Position = Point(7000, 3000) + shape.TextContourFrame = True + sheet.DrawPage.add(shape) + + self.manipulateText(shape) + self.manipulateShape(shape) + except DisposedException: + self.remote_context = None + raise + + def use_draw(self) -> None: + try: + doc = self.new_doc_component("sdraw") + + draw_shape = doc.createInstance("com.sun.star.drawing.RectangleShape") + draw_shape.setSize(Size(10000, 20000)) + draw_shape.setPosition(Point(5000, 5000)) + doc.DrawPages[0].add(draw_shape) + + # wrap text inside shape + draw_shape.TextContourFrame = True + + self.manipulateText(draw_shape) + self.manipulateShape(draw_shape) + except DisposedException: + self.remote_context = None + raise + + def manipulateText(self, xtext) -> None: + """Insert text content + + :param xtext: object that implements com.sun.star.text.XText interface. + """ + # simply set whole text as one string + xtext.String = ( + "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 text cursor for selecting and formatting + text_cursor = xtext.createTextCursor() + # use cursor to select "He lay" and apply bold italic + text_cursor.gotoStart(False) + text_cursor.goRight(6, True) + # from CharacterProperties + text_cursor.CharPosture = ITALIC + text_cursor.CharWeight = BOLD + + # add more text at the end of the text using insertString + text_cursor.gotoEnd(False) + content = ( + " 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." + ) + xtext.insertString(text_cursor, content, False) + # after insertString the cursor is behind the inserted text, + # insert more text + content = "\n \"Is that the mill?\" he asked." + xtext.insertString(text_cursor, content, False) + + def manipulateTable(self, xcellrange) -> None: + """Format a table area + + :param xcellrange: object that implements com.sun.star.table.XCellRange interface. + """ + # enter column titles and a cell value + xcellrange[0, 0].String = "Quotation" + xcellrange[0, 1].String = "Year" + xcellrange[1, 1].Value = 1940 + + # format table headers and table borders + # we need to distinguish text and sheet tables: + # property name for cell colors is different in text and sheet cells + # we want to apply TableBorder to whole text table, but only to sheet + # cells with content + + background_color = 0x99CCFF + + # create description for blue line, width 10 + line = BorderLine() + line.Color = 0x000099 + line.OuterLineWidth = 10 + # apply line description to all border lines and make them valid + border = TableBorder() + border.VerticalLine = border.HorizontalLine = line + border.LeftLine = border.RightLine = line + border.TopLine = border.BottomLine = line + border.IsVerticalLineValid = border.IsHorizontalLineValid = True + border.IsLeftLineValid = border.IsRightLineValid = True + border.IsTopLineValid = border.IsBottomLineValid = True + + if xcellrange.supportsService("com.sun.star.sheet.Spreadsheet"): + selected_cells = xcellrange["A1:B2"] + selected_cells.CellBackColor = background_color + selected_cells.TableBorder = border + print(selected_cells.TableBorder.TopLine.Color) + elif xcellrange.supportsService("com.sun.star.text.TextTable"): + selected_cells = xcellrange["A1:B1"] + selected_cells.BackColor = background_color + xcellrange.TableBorder = border + print(xcellrange.TableBorder.TopLine.Color) + + def manipulateShape(self, xshape) -> None: + """Format a shape + + :param xshape: object that implements com.sun.star.drawing.XShape interface. + """ + xshape.FillColor = 0x99CCFF + xshape.LineColor = 0x000099 + xshape.RotateAngle = 3000 + + xshape.TextLeftDistance = 0 + xshape.TextRightDistance = 0 + xshape.TextUpperDistance = 0 + xshape.TextLowerDistance = 0 + + +def main() -> None: + try: + HelloTextTableShape().use_documents() + except Exception as e: + print(str(e)) + traceback.print_exc() + + +if __name__ == "__main__": + main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: |