diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /odk/examples/cpp | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/cpp')
48 files changed, 4683 insertions, 0 deletions
diff --git a/odk/examples/cpp/Convertor/Convertor.cxx b/odk/examples/cpp/Convertor/Convertor.cxx new file mode 100644 index 000000000..765a28317 --- /dev/null +++ b/odk/examples/cpp/Convertor/Convertor.cxx @@ -0,0 +1,116 @@ +/* -*- 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 <rtl/bootstrap.hxx> + +#include <osl/file.hxx> +#include <osl/process.h> +#include <rtl/process.h> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + +using namespace cppu; +using namespace rtl; +using namespace css::uno; +using namespace css::beans; +using namespace css::bridge; +using namespace css::frame; +using namespace css::lang; +using namespace css::text; + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + OUString sInputFileName, sOutputFileName; + OUString sConnectionString("uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"); + + sal_Int32 nCount = rtl_getAppCommandArgCount(); + + if (nCount < 1) + { + std::cout + << "using: Convertor -env:URE_MORE_TYPES=<office_types_rdb_url> <file_url> " + "[<uno_connection_url>]" + << std::endl + << std::endl + << "example: Convertor -env:URE_MORE_TYPES=\"file:///.../program/offapi.rdb\" test.odt" + "\"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager\"" + << std::endl; + exit(1); + } + + auto xComponentContext(defaultBootstrap_InitialComponentContext()); + auto xMultiComponentFactoryClient(xComponentContext->getServiceManager()); + auto xInterface = xMultiComponentFactoryClient->createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", xComponentContext); + auto resolver = Reference<XUnoUrlResolver>(xInterface, UNO_QUERY); + try + { + xInterface = Reference<XInterface>(resolver->resolve(sConnectionString), UNO_QUERY_THROW); + } + catch (Exception& e) + { + std::cout << "Error: cannot establish a connection using '" << sConnectionString << "'" + << std::endl + << e.Message << std::endl; + std::exit(1); + } + + auto xPropSet = Reference<XPropertySet>(xInterface, UNO_QUERY); + xPropSet->getPropertyValue("DefaultContext") >>= xComponentContext; + auto xMultiComponentFactoryServer(xComponentContext->getServiceManager()); + auto xComponentLoader = Desktop::create(xComponentContext); + Sequence<PropertyValue> loadProperties(1); + loadProperties[0].Name = "Hidden"; + loadProperties[0].Value <<= true; + try + { + OUString sInputUrl, sAbsoluteInputUrl, sOutputUrl, sAbsoluteOutputUrl, sWorkingDir; + osl_getProcessWorkingDir(&sWorkingDir.pData); + rtl_getAppCommandArg(0, &sInputFileName.pData); + + osl::FileBase::getFileURLFromSystemPath(sInputFileName, sInputUrl); + osl::FileBase::getAbsoluteFileURL(sWorkingDir, sInputUrl, sAbsoluteInputUrl); + std::cout << sAbsoluteInputUrl << std::endl; + + osl::FileBase::getFileURLFromSystemPath("output.pdf", sOutputUrl); + osl::FileBase::getAbsoluteFileURL(sWorkingDir, sOutputUrl, sAbsoluteOutputUrl); + std::cout << sAbsoluteOutputUrl << std::endl; + + auto xComponent = xComponentLoader->loadComponentFromURL(sAbsoluteInputUrl, "_blank", 0, + loadProperties); + auto xDocument = Reference<XTextDocument>(xComponent, UNO_QUERY_THROW); + auto xStorable = Reference<XStorable>(xDocument, UNO_QUERY_THROW); + auto storeProps = Sequence<PropertyValue>(3); + storeProps[0].Name = "FilterName"; + storeProps[0].Value <<= OUString("writer_pdf_Export"); + storeProps[1].Name = "Overwrite"; + storeProps[1].Value <<= true; + storeProps[2].Name = "SelectPdfVersion"; + storeProps[2].Value <<= sal_Int32(1); + xStorable->storeToURL(sAbsoluteOutputUrl, storeProps); + Reference<XComponent>::query(xMultiComponentFactoryClient)->dispose(); + std::cout << "Output output.pdf generated." << std::endl; + } + catch (Exception& e) + { + std::cout << "Can not open the input file." << std::endl << e.Message << std::endl; + } + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/Convertor/Makefile b/odk/examples/cpp/Convertor/Makefile new file mode 100644 index 000000000..32bec8f7d --- /dev/null +++ b/odk/examples/cpp/Convertor/Makefile @@ -0,0 +1,83 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/. +# + +# Builds the C++ Convertor example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMPONENT_NAME=Convertor + +OUT_COMP_INC = $(OUT_INC)/$(COMPONENT_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMPONENT_NAME) +OUT_COMP_OBJ=$(OUT_OBJ)/$(COMPONENT_NAME) + +CXXFILES = Convertor.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES)) + +ENV_OFFICE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(OFFICE_TYPES) + +# Targets +.PHONY: ALL +ALL : \ + CppConvertorExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_BIN)/Convertor$(EXE_EXT) : $(OUT_COMP_OBJ)/Convertor.$(OBJ_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) +ifeq "$(OS)" "WIN" + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_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 + +CppConvertorExample : $(OUT_BIN)/Convertor$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo The example loads the "$(QM)test.odt$(QM)" document in the Convertor example directory + @echo and convert it to test.pdf + @echo - + @echo Use the following command to execute the example! + @echo - + @echo $(MAKE) Convertor.run + @echo - + @echo NOTE: This example does not use the new UNO bootstrap mechanism, it uses still a socket + @echo $(SQM) $(SQM)connection. The example use the defaultBootstrap_InitialComponentContext method and provides + @echo $(SQM) $(SQM)the additional office types via the UNO environment variable -env:URE_MORE_TYPES=... + @echo $(SQM) $(SQM)Before you can run this example you have to start your office in listening mode. + @echo - + @echo $(SQM) $(SQM)soffice "$(QM)--accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager$(QM)" + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/Convertor$(EXE_EXT) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) $(ENV_OFFICE_TYPES) $(subst \\,/,$(subst /,$(PS),"$(OO_SDK_HOME)/examples/cpp/Convertor/test.odt")) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_OBJ)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/Convertor*)) + +# vim: set noet sw=4 ts=4: diff --git a/odk/examples/cpp/Convertor/test.odt b/odk/examples/cpp/Convertor/test.odt Binary files differnew file mode 100644 index 000000000..dc4efecac --- /dev/null +++ b/odk/examples/cpp/Convertor/test.odt diff --git a/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx b/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx new file mode 100644 index 000000000..38b661e03 --- /dev/null +++ b/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +// Simple client application using the UnoUrlResolver service. +#include <iostream> +#include <sal/main.h> +#include <cppuhelper/bootstrap.hxx> + +#include <osl/file.hxx> +#include <osl/process.h> +#include <rtl/process.h> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/registry/XSimpleRegistry.hpp> + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::bridge; +using namespace com::sun::star::frame; +using namespace com::sun::star::registry; + +using namespace rtl; + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + OUString sConnectionString("uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"); + + sal_Int32 nCount = rtl_getAppCommandArgCount(); + + if (nCount < 1) + { + std::cout << "using: DocumentLoader -env:URE_MORE_TYPES=<office_types_rdb_url> <file_url> " + "[<uno_connection_url>]" + << std::endl + << std::endl + << "example: DocumentLoader -env:URE_MORE_TYPES=\"file:///.../program/offapi.rdb\" " + "\"file:///e:/temp/test.odt\" " + "\"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager\"" + << std::endl; + exit(1); + } + if (nCount == 2) + { + rtl_getAppCommandArg(1, &sConnectionString.pData); + } + + Reference< XComponentContext > xComponentContext(::cppu::defaultBootstrap_InitialComponentContext()); + + /* Gets the service manager instance to be used (or null). This method has + been added for convenience, because the service manager is an often used + object. + */ + Reference< XMultiComponentFactory > xMultiComponentFactoryClient( + xComponentContext->getServiceManager() ); + + /* Creates an instance of a component which supports the services specified + by the factory. + */ + Reference< XInterface > xInterface = + xMultiComponentFactoryClient->createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", + xComponentContext ); + + Reference< XUnoUrlResolver > resolver( xInterface, UNO_QUERY ); + + // Resolves the component context from the office, on the uno URL given by argv[1]. + try + { + xInterface = Reference< XInterface >( + resolver->resolve( sConnectionString ), UNO_QUERY ); + } + catch ( Exception& e ) + { + std::cout << "Error: cannot establish a connection using " + << sConnectionString << std::endl << e.Message << std::endl; + exit(1); + } + + // gets the server component context as property of the office component factory + Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY ); + xPropSet->getPropertyValue("DefaultContext") >>= xComponentContext; + + // gets the service manager from the office + Reference< XMultiComponentFactory > xMultiComponentFactoryServer( + xComponentContext->getServiceManager() ); + + /* Creates an instance of a component which supports the services specified + by the factory. Important: using the office component context. + */ + Reference < XDesktop2 > xComponentLoader = Desktop::create(xComponentContext); + + /* Loads a component specified by a URL into the specified new or existing + frame. + */ + OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl, sArgDocUrl; + rtl_getAppCommandArg(0, &sArgDocUrl.pData); + + osl_getProcessWorkingDir(&sWorkingDir.pData); + osl::FileBase::getFileURLFromSystemPath( sArgDocUrl, sDocPathUrl); + osl::FileBase::getAbsoluteFileURL( sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); + + Reference< XComponent > xComponent = xComponentLoader->loadComponentFromURL( + sAbsoluteDocUrl, OUString( "_blank" ), 0, + Sequence < ::com::sun::star::beans::PropertyValue >() ); + + // dispose the local service manager + Reference< XComponent >::query( xMultiComponentFactoryClient )->dispose(); + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/DocumentLoader/Makefile b/odk/examples/cpp/DocumentLoader/Makefile new file mode 100644 index 000000000..56e370bec --- /dev/null +++ b/odk/examples/cpp/DocumentLoader/Makefile @@ -0,0 +1,107 @@ +#************************************************************************* +# +# 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 C++ DocumentLoader example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMPONENT_NAME=DocumentLoader + +OUT_COMP_INC = $(OUT_INC)/$(COMPONENT_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMPONENT_NAME) +OUT_COMP_OBJ=$(OUT_OBJ)/$(COMPONENT_NAME) + +CXXFILES = DocumentLoader.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES)) + +ENV_OFFICE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(OFFICE_TYPES) + +# Targets +.PHONY: ALL +ALL : \ + CppDocumentLoaderExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_BIN)/DocumentLoader$(EXE_EXT) : $(OUT_COMP_OBJ)/DocumentLoader.$(OBJ_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) +ifeq "$(OS)" "WIN" + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_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 + +CppDocumentLoaderExample : $(OUT_BIN)/DocumentLoader$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo The example loads the "$(QM)test.odt$(QM)" document in the DocumentLoader example directory. + @echo If you want to load your own document, please use: + @echo $(SQM) $(SQM)DocumentLoader -env:URE_MORE_TYPES="$(QM)<fileurl_office_types_rdb>$(QM)" "$(QM)filename$(QM)" [connection_url] + @echo - + @echo Use the following command to execute the example! + @echo - + @echo $(MAKE) DocumentLoader.run + @echo - + @echo NOTE: This example does not use the new UNO bootstrap mechanism, it uses still a socket + @echo $(SQM) $(SQM)connection. The example use the defaultBootstrap_InitialComponentContext method and provides + @echo $(SQM) $(SQM)the additional office types via the UNO environment variable -env:URE_MORE_TYPES=... + @echo $(SQM) $(SQM)Before you can run this example you have to start your office in listening mode. + @echo - + @echo $(SQM) $(SQM)soffice "$(QM)--accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager$(QM)" + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/DocumentLoader$(EXE_EXT) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) $(ENV_OFFICE_TYPES) $(subst \\,/,$(subst /,$(PS),"$(OO_SDK_HOME)/examples/cpp/DocumentLoader/test.odt")) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_OBJ)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/DocumentLoader*)) diff --git a/odk/examples/cpp/DocumentLoader/test.odt b/odk/examples/cpp/DocumentLoader/test.odt Binary files differnew file mode 100644 index 000000000..dc4efecac --- /dev/null +++ b/odk/examples/cpp/DocumentLoader/test.odt diff --git a/odk/examples/cpp/Draw/Draw.cxx b/odk/examples/cpp/Draw/Draw.cxx new file mode 100644 index 000000000..843bdd553 --- /dev/null +++ b/odk/examples/cpp/Draw/Draw.cxx @@ -0,0 +1,235 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#include <iostream> + +#include <cppuhelper/bootstrap.hxx> +#include <rtl/bootstrap.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XShapeGrouper.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/util/Color.hpp> + +using namespace cppu; +using namespace rtl; +using namespace css::uno; +using namespace css::beans; +using namespace css::bridge; +using namespace css::frame; +using namespace css::lang; +using namespace css::text; +using namespace css::drawing; +using namespace css::awt; +using namespace css::container; + +css::util::Color getCol(int r, int g, int b); +Reference<XComponent> openDraw(Reference<XComponentContext> xComponentContext); +Reference<XShape> createShape(Reference<XComponent> xDocComp, int height, int width, int x, int y, + OUString kind, css::util::Color col); +Reference<XShapeGroup> createSequence(Reference<XComponent> xDocComp, Reference<XDrawPage> xDP); + +int main() +{ + Reference<XComponentContext> xContext = NULL; + + try + { + // get the remote office component context + xContext = bootstrap(); + } + catch (Exception& e) + { + std::cout << "Error: cannot do bootstraping." << std::endl << e.Message << std::endl; + exit(1); + } + + Reference<XComponent> xDrawDoc = NULL; + Reference<XDrawPage> xDrawPage = NULL; + + xDrawDoc = openDraw(xContext); + + try + { + // getting the draw page + Reference<XDrawPagesSupplier> xDPS(xDrawDoc, UNO_QUERY); + Reference<XDrawPages> xDPn = xDPS->getDrawPages(); + Reference<XIndexAccess> xDPi(xDPn, UNO_QUERY); + xDrawPage = Reference<XDrawPage>(xDPi->getByIndex(0), UNO_QUERY); + } + catch (Exception& e) + { + std::cout << "Error: Document creation was not possible" << std::endl; + exit(1); + } + + createSequence(xDrawDoc, xDrawPage); + + // Drawing some shapes + Reference<XShapes> xShapes(xDrawPage, UNO_QUERY); + xShapes->add(createShape(xDrawDoc, 1000, 1300, 2000, 2000, "Line", getCol(0, 0, 0))); + xShapes->add(createShape(xDrawDoc, 2000, 4000, 15000, 2000, "Ellipse", getCol(0, 200, 200))); + xShapes->add(createShape(xDrawDoc, 3000, 2500, 5500, 4000, "Rectangle", getCol(100, 100, 200))); + + exit(0); +} + +Reference<XComponent> openDraw(Reference<XComponentContext> xContext) +{ + Reference<XComponent> xComp; + + try + { + // getting the remote LibreOffice service manager + Reference<XMultiComponentFactory> xMCF = xContext->getServiceManager(); + + Reference<XInterface> oDesktop + = xMCF->createInstanceWithContext("com.sun.star.frame.Desktop", xContext); + Reference<XComponentLoader> xCLoader(oDesktop, UNO_QUERY); + Sequence<PropertyValue> szEmptyArgs(0); + OUString strDoc("private:factory/sdraw"); + xComp = xCLoader->loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs); + } + catch (Exception e) + { + std::cout << "Error opening draw." << std::endl << e.Message << std::endl; + exit(1); + } + + return xComp; +} + +Reference<XShape> createShape(Reference<XComponent> xDocComp, int height, int width, int x, int y, + OUString kind, css::util::Color col) +{ + // kind can be either 'Ellipse', 'Line' or 'Rectangle' + Size size; + Point position; + Reference<XShape> xShape; + + // get the multiservice factory + Reference<XMultiServiceFactory> xDocMSF(xDocComp, UNO_QUERY); + + try + { + Reference<XInterface> oInt + = xDocMSF->createInstance("com.sun.star.drawing." + kind + "Shape"); + xShape = Reference<XShape>(oInt, UNO_QUERY); + + size.Height = height; + size.Width = width; + position.X = x; + position.Y = y; + xShape->setSize(size); + xShape->setPosition(position); + } + catch (Exception e) + { + std::cout << "Could not create instance." << std::endl << e.Message << std::endl; + exit(1); + } + + Reference<XPropertySet> xSPS(xShape, UNO_QUERY); + + try + { + xSPS->setPropertyValue("FillColor", Any(col)); + } + catch (Exception e) + { + std::cout << "Can not change the shape colors." << std::endl << e.Message << std::endl; + exit(1); + } + + return xShape; +} + +Reference<XShapeGroup> createSequence(Reference<XComponent> xDocComp, Reference<XDrawPage> xDP) +{ + Size size; + Point position; + Reference<XShape> xShape; + Reference<XShapes> xShapes(xDP, UNO_QUERY); + int height = 2000; + int width = 2500; + int x = 1800; + int y = 22000; + Reference<XInterface> oInt; + int r = 30; + int g = 0; + int b = 70; + + // getting the multiservice factory + Reference<XMultiServiceFactory> xDocMSF(xDocComp, UNO_QUERY); + + for (int i = 0; i < 380; i = i + 30) + { + try + { + oInt = xDocMSF->createInstance("com.sun.star.drawing.EllipseShape"); + xShape = Reference<XShape>(oInt, UNO_QUERY); + size.Height = height; + size.Width = width; + position.X = x + (i * 40); + position.Y = y + (i * 40) % 4000; + xShape->setSize(size); + xShape->setPosition(position); + } + catch (Exception e) + { + // Some exception occurs.FAILED + std::cout << "Could not get Shape." << std::endl << e.Message << std::endl; + exit(1); + } + + b = b + 8; + + Reference<XPropertySet> xSPS(xShape, UNO_QUERY); + + try + { + xSPS->setPropertyValue("FillColor", Any(getCol(r, g, b))); + xSPS->setPropertyValue("Shadow", Any(true)); + } + catch (Exception e) + { + std::cout << "Can not change shape colors." << std::endl << e.Message << std::endl; + exit(1); + } + xShapes->add(xShape); + } + + Reference<XShapeGrouper> xSGrouper(xDP, UNO_QUERY); + + return xSGrouper->group(xShapes); +} + +css::util::Color getCol(int r, int g, int b) { return r * 65536 + g * 256 + b; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/Draw/Makefile b/odk/examples/cpp/Draw/Makefile new file mode 100644 index 000000000..333a3a467 --- /dev/null +++ b/odk/examples/cpp/Draw/Makefile @@ -0,0 +1,84 @@ +# +# 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 . +# + +# Builds the C++ Draw example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMPONENT_NAME=Draw + +OUT_COMP_INC = $(OUT_INC)/$(COMPONENT_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMPONENT_NAME) +OUT_COMP_OBJ=$(OUT_OBJ)/$(COMPONENT_NAME) + +CXXFILES = Draw.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES)) + +ENV_OFFICE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(OFFICE_TYPES) + +# Targets +.PHONY: ALL +ALL : \ + CppDrawExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_BIN)/Draw$(EXE_EXT) : $(OUT_COMP_OBJ)/Draw.$(OBJ_EXT) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) +ifeq "$(OS)" "WIN" + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_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 + +CppDrawExample : $(OUT_BIN)/Draw$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo The example connects to the office server, create an empty documents and puts some + @echo shapes on it. + @echo - + @echo Use the following command to execute the example! + @echo - + @echo $(MAKE) Draw.run + @echo - + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/Draw$(EXE_EXT) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) $(ENV_OFFICE_TYPES) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_OBJ)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/Draw*)) diff --git a/odk/examples/cpp/complextoolbarcontrols/Addons.xcu b/odk/examples/cpp/complextoolbarcontrols/Addons.xcu new file mode 100644 index 000000000..786c3ad29 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Addons.xcu @@ -0,0 +1,187 @@ +<?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 . +--> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office"> + <node oor:name="AddonUI"> + <node oor:name="OfficeToolBar"> + <node oor:name="com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <node oor:name="m1" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:ImageButtonCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Image Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>ImageButton</value> + </prop> + </node> + <node oor:name="m2" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:ComboboxCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">ComboBox</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Combobox</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>200</value> + </prop> + </node> + <node oor:name="m3" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m4" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:SpinfieldCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Spinfield</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Spinfield</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>150</value> + </prop> + </node> + <node oor:name="m5" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m6" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:EditfieldCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Editfield</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Editfield</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>130</value> + </prop> + </node> + <node oor:name="m7" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m8" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:DropdownboxCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Dropdownbox</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Dropdownbox</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>80</value> + </prop> + </node> + <node oor:name="m9" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:ToggleDropdownButtonCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Toggle Dropdown Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>ToggleDropdownButton</value> + </prop> + </node> + <node oor:name="m10" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:DropdownButtonCmd</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Dropdown Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>DropdownButton</value> + </prop> + </node> + </node> + </node> + <node oor:name="Images"> + <node oor:name="vnd.demo.complextoolbarcontrols.image1" oor:op="replace"> + <prop oor:name="URL"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:ImageButtonCmd</value> + </prop> + <node oor:name="UserDefinedImages"> + <prop oor:name="ImageSmallURL" oor:type="xs:string"> + <value>%origin%/logo_small.png</value> + </prop> + <prop oor:name="ImageBigURL" oor:type="xs:string"> + <value>%origin%/logo_big.png</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx new file mode 100644 index 000000000..0b5b0ca1e --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#include "MyListener.h" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +void SAL_CALL CalcListener::notifyEvent(const ::com::sun::star::document::EventObject& aEvent) {} + +void SAL_CALL CalcListener::disposing(const com::sun::star::lang::EventObject& aSource) {} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu b/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu new file mode 100644 index 000000000..4d9f71c29 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu @@ -0,0 +1,38 @@ +<?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 . +--> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcWindowState" oor:package="org.openoffice.Office.UI"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolbar/addon_com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <prop oor:name="ContextSensitive" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Complex Toolbar Controls</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>true</value> + </prop> + <prop oor:name="Docked" oor:type="xs:boolean"> + <value>false</value> + </prop> + </node> + </node> + </node> +</oor:component-data>
\ No newline at end of file diff --git a/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu b/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu new file mode 100644 index 000000000..976e48434 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu @@ -0,0 +1,39 @@ +<?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 . +--> +<oor:component-data oor:name="Jobs" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="Jobs"> + <node oor:name="DemoAddOn" oor:op="replace"> + <prop oor:name="Service"> + <value>vnd.demo.NewDocListener</value> + </prop> + </node> + </node> + <node oor:name="Events"> + <node oor:name="OnNew" oor:op="replace"> + <node oor:name="JobList"> + <node oor:name="DemoAddOn" oor:op="replace"/> + </node> + </node> + <node oor:name="OnLoad" oor:op="replace"> + <node oor:name="JobList"> + <node oor:name="DemoAddOn" oor:op="replace"/> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx new file mode 100644 index 000000000..a36e80138 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#include <osl/diagnose.h> + +#include "ListenerHelper.h" + +using com::sun::star::frame::XFrame; +using com::sun::star::frame::XDispatch; +using com::sun::star::frame::XStatusListener; +using com::sun::star::lang::EventObject; +using com::sun::star::uno::Reference; +using com::sun::star::uno::RuntimeException; +using com::sun::star::frame::FeatureStateEvent; + +static AllListeners aListeners; + +void ListenerHelper::AddListener( + const Reference < XFrame >& xFrame, + const Reference < XStatusListener > xControl, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 i=0; + sal_uInt32 nSize = aListeners.size(); + for ( i=0; i<nSize; i++ ) + if ( aListeners[i].xFrame == xFrame ) + break; + + OSL_ENSURE( i<nSize, "No dispatch found for this listener!" ); + aListeners[i].aContainer[aCommand].push_back( xControl ); +} + +void ListenerHelper::RemoveListener( + const Reference < XFrame >& xFrame, + const Reference < XStatusListener > xControl, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + { + StatusListeners& aL = aListeners[i].aContainer[aCommand]; + StatusListeners::iterator aIter = aL.begin(); + while ( aIter != aL.end() ) + { + if ( (*aIter) == xControl ) + { + aL.erase( aIter ); + break; + } + + ++aIter; + } + } + } +} + +void ListenerHelper::Notify( + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand, + FeatureStateEvent& rEvent ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + { + rEvent.Source = aListeners[i].xDispatch; + StatusListeners& aL = aListeners[i].aContainer[aCommand]; + StatusListeners::iterator aIter = aL.begin(); + while ( aIter != aL.end() ) + { + (*aIter)->statusChanged( rEvent ); + ++aIter; + } + } + } +} + +com::sun::star::uno::Reference < XDispatch > ListenerHelper::GetDispatch( + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + return aListeners[i].xDispatch; + } + + return Reference < XDispatch >(); +} + +void ListenerHelper::AddDispatch( + const Reference < XDispatch > xDispatch, + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand ) +{ + ListenerItem aItem; + aItem.xFrame = xFrame; + aItem.xDispatch = xDispatch; + aListeners.push_back( aItem ); + xFrame->addEventListener( new ListenerItemEventListener( xFrame ) ); +} + +void SAL_CALL ListenerItemEventListener::disposing( const EventObject& aEvent) +{ + AllListeners::iterator aIter = aListeners.begin(); + while ( aIter != aListeners.end() ) + { + if ( (*aIter).xFrame == mxFrame ) + { + aListeners.erase( aIter ); + break; + } + + ++aIter; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h new file mode 100644 index 000000000..b053ccef3 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_LISTENERHELPER_H +#define INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_LISTENERHELPER_H + +#include <map> +#include <vector> + +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XDispatch.hpp> + +#include <rtl/ustring.hxx> +#include <cppuhelper/implbase1.hxx> + +typedef std::vector < com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > > StatusListeners; + +typedef std::map < ::rtl::OUString, StatusListeners > ListenerMap; + +// For every frame there is *one* Dispatch object for all possible commands +// this struct contains an array of listeners for every supported command +// these arrays are accessed by a std::map (with the command string as index) +struct ListenerItem +{ + ListenerMap aContainer; + ::com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > xDispatch; + ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame; +}; + +typedef std::vector < ListenerItem > AllListeners; + +class ListenerHelper +{ +public: + void AddListener( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl, + const ::rtl::OUString& aCommand ); + void RemoveListener( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl, + const ::rtl::OUString& aCommand ); + void Notify( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand, + com::sun::star::frame::FeatureStateEvent& rEvent ); + com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > GetDispatch( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand ); + void AddDispatch( + const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xDispatch, + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand ); +}; + +class ListenerItemEventListener : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener > +{ + ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > mxFrame; +public: + ListenerItemEventListener( const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame) + : mxFrame(xFrame) + {} + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/Makefile b/odk/examples/cpp/complextoolbarcontrols/Makefile new file mode 100644 index 000000000..ad75987cf --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Makefile @@ -0,0 +1,182 @@ + #************************************************************************* +# +# 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 complextoolbarcontrols C++ component example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk +include $(SETTINGS)/platform.mk + +# Define non-platform/compiler specific settings +COMP_NAME=complextoolbarcontrols +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml +COMP_UNOPKG_DESCRIPTION = $(OUT_COMP_GEN)/$(COMPONENT_NAME)/description.xml +COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components +COMP_REGISTERFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_register_component.flag +COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag + +CXXFILES = \ + MyProtocolHandler.cxx \ + MyJob.cxx \ + MyListener.cxx \ + WriterListener.cxx \ + CalcListener.cxx \ + ListenerHelper.cxx \ + exports.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + + +# Targets +.PHONY: ALL +ALL : \ + Example + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib $(LIBO_SDK_LDFLAGS_STDLIBS) + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +# rule for extension description.xml +$(COMP_UNOPKG_DESCRIPTION) : description.xml + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_CAT) $< | $(SDK_SED) -e "s/#EXTENSION_PLATFORM#/$(EXTENSION_PLATFORM)/" > $@ + +# rule for component package manifest +$(OUT_COMP_GEN)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)Addons.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)WriterWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)CalcWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)ProtocolHandler.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + +# @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@ +# @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +$(COMP_COMPONENTS) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)vnd.My.impl.NewDocListener$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)vnd.My.NewDocListener$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)vnd.demo.Impl.ProtocolHandler$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)vnd.demo.ProtocolHandler$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) Addons.xcu ProtocolHandler.xcu WriterWindowState.xcu CalcWindowState.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) $(COMP_UNOPKG_DESCRIPTION) + -$(MKDIR) $(subst /,$(PS),$(@D)) && $(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(CD) $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_NAME).components description.xml + $(CD) $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F) + $(SDK_ZIP) -u $@ Addons.xcu ProtocolHandler.xcu WriterWindowState.xcu CalcWindowState.xcu logo_small.png logo_big.png + $(CD) $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +Example : $(COMP_REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The "$(QM)ProtocolHandler$(QM)" addon component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You can use this component inside your office installation, see the example + @echo description. + @echo -------------------------------------------------------------------------------- + +run: $(COMP1_COMP_REGISTERFLAG) + "$(OFFICE_PROGRAM_PATH)$(PS)soffice" --writer + + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) diff --git a/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx b/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx new file mode 100644 index 000000000..b67d3c93f --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "MyJob.h" + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <cppuhelper/supportsservice.hxx> + +using rtl::OUString; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::Reference; +using com::sun::star::uno::Any; +using com::sun::star::uno::UNO_QUERY; +using com::sun::star::uno::XInterface; +using com::sun::star::uno::Exception; +using com::sun::star::uno::RuntimeException; +using com::sun::star::lang::IllegalArgumentException; +using com::sun::star::lang::XMultiServiceFactory; +using com::sun::star::beans::NamedValue; +using com::sun::star::document::XEventBroadcaster; + +Any SAL_CALL MyJob::execute( const Sequence< NamedValue >& aArguments ) +{ + Reference < XEventBroadcaster > xBrd( mxMSF->createInstance( + "com.sun.star.frame.GlobalEventBroadcaster" ), UNO_QUERY ); + Reference < com::sun::star::document::XEventListener > xLstner( mxMSF->createInstance( + "com.sun.star.comp.Office.MyListener" ), UNO_QUERY ); + if ( xBrd.is() ) + xBrd->addEventListener( xLstner ); + return Any(); +} + +OUString MyJob_getImplementationName () +{ + return OUString( "com.sun.star.comp.Office.MyJob" ); +} + +#define SERVICE_NAME "com.sun.star.task.Job" + +Sequence< OUString > SAL_CALL MyJob_getSupportedServiceNames( ) +{ + Sequence < OUString > aRet(1); + OUString* pArray = aRet.getArray(); + pArray[0] = OUString( SERVICE_NAME ); + return aRet; +} + +#undef SERVICE_NAME + +Reference< XInterface > SAL_CALL MyJob_createInstance( const Reference< XMultiServiceFactory > & rSMgr) +{ + return (cppu::OWeakObject*) new MyJob( rSMgr ); +} + +// XServiceInfo +OUString SAL_CALL MyJob::getImplementationName( ) +{ + return MyJob_getImplementationName(); +} + +sal_Bool SAL_CALL MyJob::supportsService( const OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > SAL_CALL MyJob::getSupportedServiceNames( ) +{ + return MyJob_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyJob.h b/odk/examples/cpp/complextoolbarcontrols/MyJob.h new file mode 100644 index 000000000..e9f505f1c --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.h @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYJOB_H +#define INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYJOB_H + +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace com +{ + namespace sun + { + namespace star + { + namespace frame + { + class XModel; + class XFrame; + } + namespace beans + { + struct NamedValue; + } + } + } +} + +class MyJob : public cppu::WeakImplHelper2 +< + com::sun::star::task::XJob, + com::sun::star::lang::XServiceInfo +> +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + +public: + MyJob( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) {} + virtual ~MyJob() {} + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); +}; + +::rtl::OUString MyJob_getImplementationName(); + +sal_Bool SAL_CALL MyJob_supportsService( const ::rtl::OUString& ServiceName ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyJob_getSupportedServiceNames( ); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL MyJob_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx b/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx new file mode 100644 index 000000000..c49083a97 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "MyListener.h" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <cppuhelper/supportsservice.hxx> + +MyListener::MyListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) + : m_xSMGR(xSMGR) +{} + +MyListener::~MyListener() +{} + +css::uno::Any SAL_CALL MyListener::execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) +{ + css::uno::Sequence< css::beans::NamedValue > lEnv; + + sal_Int32 i = 0; + sal_Int32 c = lArguments.getLength(); + const css::beans::NamedValue* p = lArguments.getConstArray(); + for (i=0; i<c; ++i) + { + if ( p[i].Name == "Environment" ) + { + p[i].Value >>= lEnv; + break; + } + } + + css::uno::Reference< css::frame::XModel > xModel; + + c = lEnv.getLength(); + p = lEnv.getConstArray(); + for (i=0; i<c; ++i) + { + if ( p[i].Name == "Model" ) + { + p[i].Value >>= xModel; + break; + } + if ( p[i].Name == "Frame" ) + { + css::uno::Reference< css::frame::XController > xController; + css::uno::Reference< css::frame::XFrame > xFrame; + p[i].Value >>= xFrame; + if (xFrame.is()) + xController = xFrame->getController(); + if (xController.is()) + xModel = xController->getModel(); + break; + } + } + + if (!xModel.is()) + return css::uno::Any(); + + css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY); + sal_Bool bCalc = xInfo->supportsService("com.sun.star.sheet.SpreadsheetDocument"); + sal_Bool bWriter = ( xInfo->supportsService("com.sun.star.text.TextDocument") && + !xInfo->supportsService("com.sun.star.text.WebDocument") && + !xInfo->supportsService("com.sun.star.text.GlobalDocument") ); + + // We are interested only in Writer and Calc. However, here we are + // notified of all newly opened Documents... + if (!bCalc && !bWriter) + return css::uno::Any(); + + void* pListener = 0; + if (bCalc) + pListener = (void*)(new CalcListener(m_xSMGR)); + else + if (bWriter) + pListener = (void*)(new WriterListener(m_xSMGR)); + + css::uno::Reference< css::document::XEventListener > xDocListener (static_cast< css::document::XEventListener* >(pListener), css::uno::UNO_QUERY); + css::uno::Reference< css::document::XEventBroadcaster > xDocBroadcaster (xModel , css::uno::UNO_QUERY); + + xDocBroadcaster->addEventListener(xDocListener); + + return css::uno::Any(); +} + +::rtl::OUString SAL_CALL MyListener::getImplementationName() +{ + return ::rtl::OUString( MYLISTENER_IMPLEMENTATIONNAME ); +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL MyListener::getSupportedServiceNames() +{ + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = ::rtl::OUString( MYLISTENER_SERVICENAME ); + return lNames; +} + +sal_Bool SAL_CALL MyListener::supportsService(const ::rtl::OUString& sServiceName) +{ + return cppu::supportsService(this, sServiceName); +} + +css::uno::Reference< css::uno::XInterface > MyListener::st_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) +{ + MyListener* pListener = new MyListener(xSMGR); + css::uno::Reference< css::uno::XInterface > xListener(static_cast< css::task::XJob* >(pListener), css::uno::UNO_QUERY); + return xListener; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyListener.h b/odk/examples/cpp/complextoolbarcontrols/MyListener.h new file mode 100644 index 000000000..203c81e0b --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.h @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYLISTENER_H +#define INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYLISTENER_H + +#include <sal/config.h> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/document/XEventListener.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> + +#define MYLISTENER_IMPLEMENTATIONNAME "vnd.My.impl.NewDocListener" +#define MYLISTENER_SERVICENAME "vnd.My.NewDocListener" + +/** + * Register in the Office configuration as job. + * This is called automatically for all new opened documents. You receive + * a reference of the opened document and then you can check if it's a + * supported format. (We are only interested in Writer/Calc documents.) + * + * @see CalcListener + * @see WriterListener + */ +class MyListener : public cppu::WeakImplHelper2< css::task::XJob , + css::lang::XServiceInfo > +{ + private: + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + public: + MyListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + virtual ~MyListener(); + + // XJob + virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName(); + + virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName); + + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); + + public: + + static css::uno::Reference< css::uno::XInterface > st_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); +}; + +class CalcListener : public cppu::WeakImplHelper1< css::document::XEventListener > +{ + private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + + + public: + CalcListener(const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) + {} + + virtual ~CalcListener() + {} + + // document.XEventListener + virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent); +}; + +class WriterListener : public cppu::WeakImplHelper1< css::document::XEventListener > +{ + private: + css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + + public: + WriterListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& rxMSF); + + virtual ~WriterListener() + {} + + // document.XEventListener + virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx new file mode 100644 index 000000000..3fd70340a --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx @@ -0,0 +1,493 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "ListenerHelper.h" +#include "MyProtocolHandler.h" + +#include <com/sun/star/awt/MessageBoxButtons.hpp> +#include <com/sun/star/awt/Toolkit.hpp> +#include <com/sun/star/awt/XMessageBoxFactory.hpp> +#include <com/sun/star/frame/ControlCommand.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/system/SystemShellExecute.hpp> +#include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <com/sun/star/system/XSystemShellExecute.hpp> +#include <cppuhelper/supportsservice.hxx> + +using namespace com::sun::star::awt; +using namespace com::sun::star::frame; +using namespace com::sun::star::system; +using namespace com::sun::star::uno; + +using com::sun::star::beans::NamedValue; +using com::sun::star::beans::PropertyValue; +using com::sun::star::sheet::XSpreadsheetView; +using com::sun::star::text::XTextViewCursorSupplier; +using com::sun::star::util::URL; + +ListenerHelper aListenerHelper; + +void BaseDispatch::ShowMessageBox( const Reference< XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText ) +{ + if ( !mxToolkit.is() ) + mxToolkit = Toolkit::create(mxContext); + Reference< XMessageBoxFactory > xMsgBoxFactory( mxToolkit, UNO_QUERY ); + if ( rFrame.is() && xMsgBoxFactory.is() ) + { + Reference< XMessageBox > xMsgBox = xMsgBoxFactory->createMessageBox( + Reference< XWindowPeer >( rFrame->getContainerWindow(), UNO_QUERY ), + com::sun::star::awt::MessageBoxType_INFOBOX, + MessageBoxButtons::BUTTONS_OK, + aTitle, + aMsgText ); + + if ( xMsgBox.is() ) + xMsgBox->execute(); + } +} + +void BaseDispatch::SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled ) +{ + Reference < XDispatch > xDispatch = + aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + + FeatureStateEvent aEvent; + + aEvent.FeatureURL = aURL; + aEvent.Source = xDispatch; + aEvent.IsEnabled = bEnabled; + aEvent.Requery = sal_False; + + ControlCommand aCtrlCmd; + aCtrlCmd.Command = rCommand; + aCtrlCmd.Arguments = rArgs; + + aEvent.State <<= aCtrlCmd; + aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent ); +} + +void BaseDispatch::SendCommandTo( const Reference< XStatusListener >& xControl, const URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled ) +{ + FeatureStateEvent aEvent; + + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = bEnabled; + aEvent.Requery = sal_False; + + ControlCommand aCtrlCmd; + aCtrlCmd.Command = rCommand; + aCtrlCmd.Arguments = rArgs; + + aEvent.State <<= aCtrlCmd; + xControl->statusChanged( aEvent ); +} + +void SAL_CALL MyProtocolHandler::initialize( const Sequence< Any >& aArguments ) +{ + Reference < XFrame > xFrame; + if ( aArguments.getLength() ) + { + // the first Argument is always the Frame, as a ProtocolHandler needs to have access + // to the context in which it is invoked. + aArguments[0] >>= xFrame; + mxFrame = xFrame; + } +} + +Reference< XDispatch > SAL_CALL MyProtocolHandler::queryDispatch( const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) +{ + Reference < XDispatch > xRet; + if ( !mxFrame.is() ) + return 0; + + Reference < XController > xCtrl = mxFrame->getController(); + if ( xCtrl.is() && aURL.Protocol == "vnd.demo.complextoolbarcontrols.demoaddon:" ) + { + Reference < XTextViewCursorSupplier > xCursor( xCtrl, UNO_QUERY ); + Reference < XSpreadsheetView > xView( xCtrl, UNO_QUERY ); + if ( !xCursor.is() && !xView.is() ) + // without an appropriate corresponding document the handler doesn't function + return xRet; + + if ( aURL.Path == "ImageButtonCmd" || + aURL.Path == "ComboboxCmd" || + aURL.Path == "ToggleDropdownButtonCmd" || + aURL.Path == "DropdownButtonCmd" || + aURL.Path == "SpinfieldCmd" || + aURL.Path == "EditfieldCmd" || + aURL.Path == "DropdownboxCmd" ) + { + xRet = aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + if ( !xRet.is() ) + { + xRet = xCursor.is() ? (BaseDispatch*) new WriterDispatch( mxContext, mxFrame ) : + (BaseDispatch*) new CalcDispatch( mxContext, mxFrame ); + aListenerHelper.AddDispatch( xRet, mxFrame, aURL.Path ); + } + } + } + + return xRet; +} + +Sequence < Reference< XDispatch > > SAL_CALL MyProtocolHandler::queryDispatches( const Sequence < DispatchDescriptor >& seqDescripts ) +{ + sal_Int32 nCount = seqDescripts.getLength(); + Sequence < Reference < XDispatch > > lDispatcher( nCount ); + + for( sal_Int32 i=0; i<nCount; ++i ) + lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); + + return lDispatcher; +} + +::rtl::OUString MyProtocolHandler_getImplementationName () +{ + return ::rtl::OUString( MYPROTOCOLHANDLER_IMPLEMENTATIONNAME ); +} + +Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( ) +{ + Sequence < ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( MYPROTOCOLHANDLER_SERVICENAME ); + return aRet; +} + +#undef SERVICE_NAME + +Reference< XInterface > SAL_CALL MyProtocolHandler_createInstance( const Reference< XComponentContext > & rSMgr) +{ + return (cppu::OWeakObject*) new MyProtocolHandler( rSMgr ); +} + +// XServiceInfo +::rtl::OUString SAL_CALL MyProtocolHandler::getImplementationName( ) +{ + return MyProtocolHandler_getImplementationName(); +} + +sal_Bool SAL_CALL MyProtocolHandler::supportsService( const ::rtl::OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler::getSupportedServiceNames( ) +{ + return MyProtocolHandler_getSupportedServiceNames(); +} + +void SAL_CALL BaseDispatch::dispatch( const URL& aURL, const Sequence < PropertyValue >& lArgs ) +{ + /* It's necessary to hold this object alive, till this method finishes. + May the outside dispatch cache (implemented by the menu/toolbar!) + forget this instance during de-/activation of frames (focus!). + + E.g. An open db beamer in combination with the My-Dialog + can force such strange situation :-( + */ + Reference< XInterface > xSelfHold(static_cast< XDispatch* >(this), UNO_QUERY); + + if ( aURL.Protocol == "vnd.demo.complextoolbarcontrols.demoaddon:" ) + { + if ( aURL.Path == "ImageButtonCmd" ) + { + // open the LibreOffice web page + ::rtl::OUString sURL("http://www.libreoffice.org"); + Reference< XSystemShellExecute > xSystemShellExecute( + SystemShellExecute::create(mxContext) ); + try + { + xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY ); + } + catch( Exception& rEx ) + { + (void)rEx; + } + } + else if ( aURL.Path == "ComboboxCmd" ) + { + // remove the text if it's in our list + Sequence< NamedValue > aRemoveArgs( 1 ); + aRemoveArgs[0].Name = rtl::OUString( "Text" ); + aRemoveArgs[0].Value <<= maComboBoxText; + SendCommand( aURL, ::rtl::OUString( "RemoveEntryText" ), aRemoveArgs, sal_True ); + + // add the new text to the start of the list + Sequence< NamedValue > aInsertArgs( 2 ); + aInsertArgs[0].Name = rtl::OUString( "Pos" ); + aInsertArgs[0].Value <<= sal_Int32( 0 ); + aInsertArgs[1].Name = rtl::OUString( "Text" ); + aInsertArgs[1].Value <<= maComboBoxText; + SendCommand( aURL, ::rtl::OUString("InsertEntry"), aInsertArgs, sal_True ); + } + else if ( aURL.Path == "InsertEntry" ) + { + // Retrieve the text argument from the sequence property value + rtl::OUString aText; + for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ ) + { + if ( lArgs[i].Name == "Text" ) + { + lArgs[i].Value >>= aText; + break; + } + } + + // create new URL to address the combox box + URL aCmdURL; + aCmdURL.Path = "ComboboxCmd"; + aCmdURL.Protocol = "vnd.demo.complextoolbarcontrols.demoaddon:"; + aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol; + + // set the selected item as text into the combobox + Sequence< NamedValue > aArgs( 1 ); + aArgs[0].Name = "Text"; + aArgs[0].Value <<= aText; + SendCommand( aCmdURL, ::rtl::OUString( "SetText" ), aArgs, sal_True ); + } + else if ( aURL.Path == "DropdownButtonCmd" ) + { + // Retrieve the text argument from the sequence property value + rtl::OUString aText; + for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ ) + { + if ( lArgs[i].Name == "Text" ) + { + lArgs[i].Value >>= aText; + break; + } + } + + // just enable this command + + // set enable flag according to selection + if ( aText == "Button Disabled" ) + mbButtonEnabled = sal_False; + else + mbButtonEnabled = sal_True; + + // create new URL to address the image button + URL aCmdURL; + aCmdURL.Path = "Command1"; + aCmdURL.Protocol = "vnd.demo.complextoolbarcontrols.demoaddon:"; + aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol; + + // create and initialize FeatureStateEvent with IsEnabled + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aCmdURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = mbButtonEnabled; + aEvent.Requery = sal_False; + aEvent.State = Any(); + + // Notify listener about new state + Reference < XDispatch > xDispatch = aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent ); + } + else if ( aURL.Path == "SpinfieldCmd" ) + { + } + else if ( aURL.Path == "DropdownboxCmd" ) + { + // Retrieve the text argument from the sequence property value + rtl::OUString aText; + for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ ) + { + if ( lArgs[i].Name == "Text" ) + { + lArgs[i].Value >>= aText; + break; + } + } + } + } +} + +void SAL_CALL BaseDispatch::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) +{ + if ( aURL.Protocol == "vnd.demo.complextoolbarcontrols.demoaddon:" ) + { + if ( aURL.Path == "ImageButtonCmd" ) + { + // just enable this command + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = mbButtonEnabled; + aEvent.Requery = sal_False; + aEvent.State = Any(); + xControl->statusChanged( aEvent ); + } + else if ( aURL.Path == "ComboboxCmd" ) + { + // just enable this command + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = sal_True; + aEvent.Requery = sal_False; + aEvent.State = Any(); + xControl->statusChanged( aEvent ); + } + else if ( aURL.Path == "ToggleDropdownButtonCmd" ) + { + // A toggle dropdown box is normally used for a group of commands + // where the user can select the last issued command easily. + // E.g. a typical command group would be "Insert shape" + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aContextMenu( 3 ); + aContextMenu[0] = "Command 1"; + aContextMenu[1] = "Command 2"; + aContextMenu[2] = "Command 3"; + + aArgs[0].Name = "List"; + aArgs[0].Value <<= aContextMenu; + SendCommandTo( xControl, aURL, rtl::OUString( "SetList" ), aArgs, sal_True ); + + // send command to check item on pos=0 + aArgs[0].Name = rtl::OUString( "Pos" ); + aArgs[0].Value <<= sal_Int32( 0 ); + SendCommandTo( xControl, aURL, ::rtl::OUString( "CheckItemPos" ), aArgs, sal_True ); + } + else if ( aURL.Path == "DropdownButtonCmd" ) + { + // A dropdown box is normally used for a group of dependent modes, where + // the user can only select one. The modes cannot be combined. + // E.g. a typical group would be left,right,center,block. + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aContextMenu( 2 ); + aContextMenu[0] = "Button Enabled"; + aContextMenu[1] = "Button Disabled"; + + aArgs[0].Name = "List"; + aArgs[0].Value <<= aContextMenu; + SendCommandTo( xControl, aURL, rtl::OUString( "SetList" ), aArgs, sal_True ); + + // set position according to enable/disable state of button + sal_Int32 nPos( mbButtonEnabled ? 0 : 1 ); + + // send command to check item on pos=0 + aArgs[0].Name = "Pos"; + aArgs[0].Value <<= nPos; + SendCommandTo( xControl, aURL, ::rtl::OUString( "CheckItemPos" ), aArgs, sal_True ); + } + else if ( aURL.Path == "SpinfieldCmd" ) + { + // A spin button + Sequence< NamedValue > aArgs( 5 ); + + // send command to initialize spin button + aArgs[0].Name = "Value"; + aArgs[0].Value <<= double( 0.0 ); + aArgs[1].Name = "UpperLimit"; + aArgs[1].Value <<= double( 10.0 ); + aArgs[2].Name = "LowerLimit"; + aArgs[2].Value <<= double( 0.0 ); + aArgs[3].Name = "Step"; + aArgs[3].Value <<= double( 0.1 ); + aArgs[4].Name = "OutputFormat"; + aArgs[4].Value <<= rtl::OUString("%.2f cm"); + + SendCommandTo( xControl, aURL, rtl::OUString( "SetValues" ), aArgs, sal_True ); + } + else if ( aURL.Path == "DropdownboxCmd" ) + { + // A dropdown box is normally used for a group of commands + // where the user can select one of a defined set. + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aList( 10 ); + aList[0] = "White"; + aList[1] = "Black"; + aList[2] = "Red"; + aList[3] = "Blue"; + aList[4] = "Green"; + aList[5] = "Grey"; + aList[6] = "Yellow"; + aList[7] = "Orange"; + aList[8] = "Brown"; + aList[9] = "Pink"; + + aArgs[0].Name = "List"; + aArgs[0].Value <<= aList; + SendCommandTo( xControl, aURL, rtl::OUString( "SetList" ), aArgs, sal_True ); + } + + aListenerHelper.AddListener( mxFrame, xControl, aURL.Path ); + } +} + +void SAL_CALL BaseDispatch::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) +{ + aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path ); +} + +void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event ) +{ + if ( Event.aURL.Protocol == "vnd.demo.complextoolbarcontrols.demoaddon:" ) + { + if ( Event.aURL.Path == "ComboboxCmd" ) + { + // We get notifications whenever the text inside the combobox has been changed. + // We store the new text into a member. + if ( Event.Event == "TextChanged" ) + { + rtl::OUString aNewText; + sal_Bool bHasText( sal_False ); + for ( sal_Int32 i = 0; i < Event.aInformation.getLength(); i++ ) + { + if ( Event.aInformation[i].Name == "Text" ) + { + bHasText = Event.aInformation[i].Value >>= aNewText; + break; + } + } + + if ( bHasText ) + maComboBoxText = aNewText; + } + } + } +} + +BaseDispatch::BaseDispatch( const Reference< XComponentContext > &rxContext, + const Reference< XFrame >& xFrame, + const ::rtl::OUString& rServiceName ) + : mxContext( rxContext ) + , mxFrame( xFrame ) + , msDocService( rServiceName ) + , mbButtonEnabled( sal_True ) +{ +} + +BaseDispatch::~BaseDispatch() +{ + mxFrame.clear(); + mxContext.clear(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h new file mode 100644 index 000000000..49a2a4ece --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYPROTOCOLHANDLER_H +#define INCLUDED_EXAMPLES_COMPLEXTOOLBARCONTROLS_MYPROTOCOLHANDLER_H + +#include <com/sun/star/awt/XToolkit2.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XControlNotificationListener.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> + +#define MYPROTOCOLHANDLER_IMPLEMENTATIONNAME "vnd.demo.Impl.ProtocolHandler" +#define MYPROTOCOLHANDLER_SERVICENAME "vnd.demo.ProtocolHandler" + +namespace com +{ + namespace sun + { + namespace star + { + namespace frame + { + class XModel; + class XFrame; + } + namespace uno { class XComponentContext; } + } + } +} + + +class MyProtocolHandler : public cppu::WeakImplHelper3 +< + com::sun::star::frame::XDispatchProvider, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo +> +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame; + +public: + MyProtocolHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) + : mxContext( rxContext ) {} + + // XDispatchProvider + virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > + SAL_CALL queryDispatch( const ::com::sun::star::util::URL& aURL, + const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ); + virtual ::com::sun::star::uno::Sequence < ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > + SAL_CALL queryDispatches( + const ::com::sun::star::uno::Sequence < ::com::sun::star::frame::DispatchDescriptor >& seqDescriptor ); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); +}; + +::rtl::OUString MyProtocolHandler_getImplementationName(); + +sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( ); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL MyProtocolHandler_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rContext); + +class BaseDispatch : public cppu::WeakImplHelper2 +< + ::com::sun::star::frame::XDispatch, + ::com::sun::star::frame::XControlNotificationListener +> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit2 > mxToolkit; + ::rtl::OUString msDocService; + ::rtl::OUString maComboBoxText; + sal_Bool mbButtonEnabled; + +public: + BaseDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rServiceName ); + + virtual ~BaseDispatch(); + + void ShowMessageBox( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText ); + void SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled ); + void SendCommandTo( const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener >& xControl, const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled ); + + // XDispatch + virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs ); + virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ); + virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ); + + // XControlNotificationListener + virtual void SAL_CALL controlEvent( const ::com::sun::star::frame::ControlEvent& Event ); +}; + +class WriterDispatch : public BaseDispatch +{ +public: + WriterDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) + : BaseDispatch( rxContext, xFrame, rtl::OUString( "com.sun.star.text.TextDocument" ) ) + {} +}; + +class CalcDispatch : public BaseDispatch +{ +public: + CalcDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) + : BaseDispatch( rxContext, xFrame, rtl::OUString( "com.sun.star.sheet.SpreadSheetDocument" ) ) + {} +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu b/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu new file mode 100644 index 000000000..293e0185c --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu @@ -0,0 +1,27 @@ +<?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 . +--> +<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="HandlerSet"> + <node oor:name="vnd.demo.ProtocolHandler" oor:op="replace"> + <prop oor:name="Protocols" oor:type="oor:string-list"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:*</value> + </prop> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx b/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx new file mode 100644 index 000000000..018ec1c8f --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "MyListener.h" + + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +void SAL_CALL WriterListener::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) +{ +} + +void SAL_CALL WriterListener::disposing( const com::sun::star::lang::EventObject& aSource ) +{ +} + +WriterListener::WriterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu b/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu new file mode 100644 index 000000000..e590f6545 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu @@ -0,0 +1,38 @@ +<?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 . +--> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="WriterWindowState" oor:package="org.openoffice.Office.UI"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolbar/addon_com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <prop oor:name="ContextSensitive" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Complex Toolbar Controls</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>true</value> + </prop> + <prop oor:name="Docked" oor:type="xs:boolean"> + <value>false</value> + </prop> + </node> + </node> + </node> +</oor:component-data>
\ No newline at end of file diff --git a/odk/examples/cpp/complextoolbarcontrols/description.xml b/odk/examples/cpp/complextoolbarcontrols/description.xml new file mode 100644 index 000000000..40539382b --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/description.xml @@ -0,0 +1,26 @@ +<?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 . +--> +<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:d="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink"> + <version value="0.0.1"/> + <identifier value="org.apache.openoffice.framework.complextoolbarcontrols"/> + <platform value="#EXTENSION_PLATFORM#"/> + <display-name> + <name lang="en-US">Complex Toolbar Controls Demo</name> + </display-name> +</description> diff --git a/odk/examples/cpp/complextoolbarcontrols/exports.cxx b/odk/examples/cpp/complextoolbarcontrols/exports.cxx new file mode 100644 index 000000000..c88013b64 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/exports.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#include <cppuhelper/factory.hxx> +#include <uno/lbnames.h> + +#include "MyProtocolHandler.h" +#include "MyListener.h" + +extern "C" +{ + +SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const char* pImplName , + void* pServiceManager, + void* pRegistryKey ) +{ + if ( !pServiceManager || !pImplName ) + return 0; + + css::uno::Reference< css::uno::XInterface > xFactory ; + css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY); + ::rtl::OUString sImplName = ::rtl::OUString::createFromAscii(pImplName); + + if (sImplName == MYLISTENER_IMPLEMENTATIONNAME) + { + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = MYLISTENER_IMPLEMENTATIONNAME; + xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames); + } + else if (sImplName == MYPROTOCOLHANDLER_IMPLEMENTATIONNAME) + { + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = MYPROTOCOLHANDLER_SERVICENAME; + xFactory = ::cppu::createSingleComponentFactory(MyProtocolHandler_createInstance, sImplName, lNames); + } + + if (!xFactory.is()) + return 0; + + xFactory->acquire(); + return xFactory.get(); +} + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +} // extern C + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/logo_big.png b/odk/examples/cpp/complextoolbarcontrols/logo_big.png Binary files differnew file mode 100644 index 000000000..23dd24109 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/logo_big.png diff --git a/odk/examples/cpp/complextoolbarcontrols/logo_small.png b/odk/examples/cpp/complextoolbarcontrols/logo_small.png Binary files differnew file mode 100644 index 000000000..c24b4e275 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/logo_small.png diff --git a/odk/examples/cpp/counter/Makefile b/odk/examples/cpp/counter/Makefile new file mode 100644 index 000000000..1694c9d44 --- /dev/null +++ b/odk/examples/cpp/counter/Makefile @@ -0,0 +1,166 @@ +#************************************************************************* +# +# 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 C++ counter example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMP_NAME=counter +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +COMP_IMPL=$(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) +COMP_RDB_NAME = $(COMP_NAME).uno.rdb +COMP_RDB = $(OUT_BIN)/$(COMP_RDB_NAME) +OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME) +OUT_COMP_OBJ = $(OUT_OBJ)/$(COMP_NAME) +OUT_COMP_SLO = $(OUT_SLO)/$(COMP_NAME) +COMP_SERVICES=$(SHAREDLIB_OUT)/counterservices.rdb + +ENV_EXAMPLE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(COMP_RDB) +ENV_COMP_SERVICES=-env:URE_MORE_SERVICES=$(URLPREFIX)$(COMP_SERVICES) + +COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag + +IDLFILES = XCountable.idl + +COMPCXXFILES = counter.cxx + +CXXFILES = countermain.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(COMPCXXFILES)) +OBJFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +TYPESLIST = -Tfoo.XCountable + +# Targets +.PHONY: ALL +ALL : \ + CppCounterExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_BIN)/%.rdb : $(IDLFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) $< $@ + +$(COMP_TYPEFLAG) : $(COMP_RDB) $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + $(CPPUMAKER) -Gc -O$(OUT_COMP_INC) $(TYPESLIST) $(COMP_RDB) -X $(URE_TYPES) + echo flagged > $@ + +$(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(OUT_OBJ)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(OUT_SLO)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib $(LIBO_SDK_LDFLAGS_STDLIBS) + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +$(OUT_BIN)/countermain$(EXE_EXT) : $(OUT_COMP_OBJ)/countermain.$(OBJ_EXT) $(SHAREDLIB_OUT)/counter.uno.$(SHAREDLIB_EXT) +ifeq "$(OS)" "WIN" + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_GEN)/$(basename $(@F)).map \ + $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) +else + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $< \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STDC++LIB) +endif + +$(COMP_SERVICES) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)com.sun.star.comp.example.cpp.Counter$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)foo.Counter$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + + +CppCounterExample : $(OUT_BIN)/countermain$(EXE_EXT) $(COMP_IMPL) $(COMP_SERVICES) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) countermain.run + @echo - + @echo NOTE: The example makes use of the URE and use the defaultBootstrap_InitialComponentContext method. + @echo $(SQM) $(SQM)The additional example IDL types are provided via the UNO environment variable -env:URE_MORE_TYPES=... + @echo $(SQM) $(SQM)and the example component is made available via -env:URE_MORE_SERVICES=... + @echo $(SQM) $(SQM)Please check the generated $(QM)$(COMP_SERVICES)$(QM) to see how you can specify your own components in such an environment + @echo $(SQM) $(SQM)and how to use the passive UNO registration. + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_BIN)/countermain$(EXE_EXT) $(COMP_IMPL) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) $(ENV_EXAMPLE_TYPES) $(ENV_COMP_SERVICES) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_OBJ)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_RDB))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/countermain*)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_SERVICES))) diff --git a/odk/examples/cpp/counter/XCountable.idl b/odk/examples/cpp/counter/XCountable.idl new file mode 100644 index 000000000..c7ed299fa --- /dev/null +++ b/odk/examples/cpp/counter/XCountable.idl @@ -0,0 +1,58 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#include <com/sun/star/uno/XInterface.idl> + +module foo +{ + /** + * Interface to count things. + */ + interface XCountable : com::sun::star::uno::XInterface + { + long getCount(); + void setCount( [in] long nCount ); + long increment(); + long decrement(); + }; + + service Counter + { + // exported interfaces: + interface XCountable; + }; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/counter/counter.cxx b/odk/examples/cpp/counter/counter.cxx new file mode 100644 index 000000000..667c04a70 --- /dev/null +++ b/odk/examples/cpp/counter/counter.cxx @@ -0,0 +1,180 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +/* + * service implementation: foo.Counter + * exported interfaces: foo.XCounter + * + * simple example component implementing a counter + */ + +#include <iostream> +#include <rtl/ustring.hxx> +#include <uno/lbnames.h> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/supportsservice.hxx> +// generated c++ interfaces +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <foo/XCountable.hpp> + +#define SERVICENAME "foo.Counter" +#define IMPLNAME "com.sun.star.comp.example.cpp.Counter" + +using namespace ::rtl; +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::foo; + +class MyCounterImpl + : public XCountable + , public XServiceInfo +{ + // to obtain other services if needed + Reference< XMultiServiceFactory > m_xServiceManager; + + sal_Int32 m_nRefCount; + sal_Int32 m_nCount; + +public: + MyCounterImpl( const Reference< XMultiServiceFactory > & xServiceManager ) + : m_xServiceManager( xServiceManager ), m_nRefCount( 0 ) + { std::cout << "< MyCounterImpl ctor called >" << std::endl; } + ~MyCounterImpl() + { std::cout << "< MyCounterImpl dtor called >" << std::endl; } + + // XInterface implementation + virtual void SAL_CALL acquire() throw () + { ++m_nRefCount; } + virtual void SAL_CALL release() throw () + { if (! --m_nRefCount) delete this; } + virtual Any SAL_CALL queryInterface( const Type & rType ) + { return cppu::queryInterface(rType, + static_cast< XInterface* >( static_cast< XServiceInfo* >( this ) ), + static_cast< XCountable* >( this ), + static_cast< XServiceInfo* >( this ) ); } + + // XServiceInfo implementation + virtual OUString SAL_CALL getImplementationName( ); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ); + static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ); + + // XCountable implementation + virtual sal_Int32 SAL_CALL getCount() + { return m_nCount; } + virtual void SAL_CALL setCount( sal_Int32 nCount ) + { m_nCount = nCount; } + virtual sal_Int32 SAL_CALL increment() + { return (++m_nCount); } + virtual sal_Int32 SAL_CALL decrement() + { return (--m_nCount); } +}; + +OUString SAL_CALL MyCounterImpl::getImplementationName( ) +{ + return OUString( IMPLNAME ); +} + +sal_Bool SAL_CALL MyCounterImpl::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +Sequence<OUString> SAL_CALL MyCounterImpl::getSupportedServiceNames( ) +{ + return getSupportedServiceNames_Static(); +} + +Sequence<OUString> SAL_CALL MyCounterImpl::getSupportedServiceNames_Static( ) +{ + OUString aName( SERVICENAME ); + return Sequence< OUString >( &aName, 1 ); +} + +/** + * Function to create a new component instance; is needed by factory helper implementation. + * @param xMgr service manager to if the components needs other component instances + */ +Reference< XInterface > SAL_CALL MyCounterImpl_create( + const Reference< XMultiServiceFactory > & xMgr ) +{ + return Reference<XInterface>(static_cast<XCountable*>(new MyCounterImpl(xMgr))); +} + +/** + * This function is called to get service factories for an implementation. + * + * @param pImplName name of implementation + * @param pServiceManager a service manager, need for component creation + * @param pRegistryKey the registry key for this component, need for persistent data + * @return a component factory + */ +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const char * pImplName, void * pServiceManager, void * pRegistryKey) +{ + void * pRet = 0; + + if (rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString( IMPLNAME ), + MyCounterImpl_create, + MyCounterImpl::getSupportedServiceNames_Static() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL +component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/counter/countermain.cxx b/odk/examples/cpp/counter/countermain.cxx new file mode 100644 index 000000000..5a613f588 --- /dev/null +++ b/odk/examples/cpp/counter/countermain.cxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +// simple client application registering and using the counter component. +#include "sal/config.h" + +#include <cstdlib> +#include <stdio.h> + +#include <sal/main.h> +#include <rtl/ustring.hxx> + +#include <osl/diagnose.h> + +#include <cppuhelper/bootstrap.hxx> + +// generated c++ interfaces +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <foo/XCountable.hpp> + + +using namespace foo; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; + +using namespace ::rtl; + + +SAL_IMPLEMENT_MAIN() +{ + try { + + Reference< XComponentContext > xContext(::cppu::defaultBootstrap_InitialComponentContext()); + OSL_ENSURE( xContext.is(), "### bootstrap failed!" ); + + Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager(); + OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" ); + + Reference< XInterface > xx = xMgr->createInstanceWithContext( "foo.Counter", xContext); + + OSL_ENSURE( xx.is(), "### cannot get service instance of \"foo.Counter\"!" ); + + Reference< XCountable > xCount( xx, UNO_QUERY ); + OSL_ENSURE( xCount.is(), "### cannot query XCountable interface of service instance \"foo.Counter\"!" ); + + if (xCount.is()) + { + xCount->setCount( 42 ); + fprintf( stdout , "%d," , (int)xCount->getCount() ); + fprintf( stdout , "%d," , (int)xCount->increment() ); + fprintf( stdout , "%d\n" , (int)xCount->decrement() ); + } + + Reference< XComponent >::query( xContext )->dispose(); + return EXIT_SUCCESS; + + } catch( Exception& e) { + printf("Error: caught exception:\n %s\n", + OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr()); + return EXIT_FAILURE; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/CalcWindowState.xcu b/odk/examples/cpp/custompanel/CalcWindowState.xcu new file mode 100644 index 000000000..427734289 --- /dev/null +++ b/odk/examples/cpp/custompanel/CalcWindowState.xcu @@ -0,0 +1,39 @@ +<?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 . + --> + +<oor:component-data oor:name="CalcWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/0000FF" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Blue</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/DrawWindowState.xcu b/odk/examples/cpp/custompanel/DrawWindowState.xcu new file mode 100644 index 000000000..ca7037a9c --- /dev/null +++ b/odk/examples/cpp/custompanel/DrawWindowState.xcu @@ -0,0 +1,39 @@ +<?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 . + --> + +<oor:component-data oor:name="DrawWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FFFF00" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Yellow</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/Factories.xcu b/odk/examples/cpp/custompanel/Factories.xcu new file mode 100644 index 000000000..05ce990a4 --- /dev/null +++ b/odk/examples/cpp/custompanel/Factories.xcu @@ -0,0 +1,39 @@ +<?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 . + --> + +<oor:component-data oor:name="Factories" oor:package="org.openoffice.Office.UI" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="Registered"> + <node oor:name="UIElementFactories"> + <node oor:name="org.openoffice.example.CustomToolPanel" oor:op="replace"> + <prop oor:name="Type"> + <value>toolpanel</value> + </prop> + <prop oor:name="Name"> + <value>org.openoffice.example.colorpanel</value> + </prop> + <prop oor:name="Module"> + <value/> + </prop> + <prop oor:name="FactoryImplementation"> + <value>org.openoffice.example.colorpanel.ToolPanelFactory</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/ImpressWindowState.xcu b/odk/examples/cpp/custompanel/ImpressWindowState.xcu new file mode 100644 index 000000000..372ac726e --- /dev/null +++ b/odk/examples/cpp/custompanel/ImpressWindowState.xcu @@ -0,0 +1,39 @@ +<?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 . + --> + +<oor:component-data oor:name="ImpressWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FFCC99" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Orange</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/Makefile b/odk/examples/cpp/custompanel/Makefile new file mode 100644 index 000000000..fcbcd20dc --- /dev/null +++ b/odk/examples/cpp/custompanel/Makefile @@ -0,0 +1,171 @@ +# +# 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 . +# + +# Builds the custom-tool-panel C++ component example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk +include $(SETTINGS)/dk.mk + +# Define non-platform/compiler specific settings +COMP_NAME=custom-tool-panel +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml +COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map +COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components +COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag + +# Allow deploying the extension when running it + +#this should be in odk/settings/std.mk +OUT_DEPLOY=$(OUT)/deploy + +OUT_COMP_DEPLOY=$(OUT_DEPLOY)/$(COMP_NAME) +OUT_DEPLOY_DIR=$(subst /,$(PS),$(OUT_COMP_DEPLOY)) +OUT_DEPLOY_URL=$(URLPREFIX)$(OUT_COMP_DEPLOY) +ENV_USER_INSTALL=-env:"UserInstallation=$(OUT_DEPLOY_URL)" +OFFICE_START_OPTIONS=-nologo -norestore -writer +OXT_DEPLOYEDFLAG=$(OUT_MISC)/cpp_$(COMP_NAME)_deployed_oxt.flag + +CXXFILES = \ + ctp_factory.cxx \ + ctp_panel.cxx \ + ctp_services.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +# Add OSL_DEBUG_LEVEL to compiler the flags (for OSL_TRACE et. al.) +ifeq "$(DEBUG)" "yes" +CC_FLAGS += -DOSL_DEBUG_LEVEL=2 +endif + +# Targets +.PHONY: ALL +ALL : \ + CustomToolPanelExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + + +#$(COMP_MAPFILE) : $(SLOFILES) +# -$(MKDIR) $(subst /,$(PS),$(@D)) +# cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE) +#ifeq "$(OS)" "MACOSX" +# nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE) +#endif + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib + $(LINK_MANIFEST) +else +#$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE) +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +# rule for component package manifest +$(OUT_COMP_GEN)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)CalcWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)DrawWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)ImpressWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)WriterWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)Factories.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +$(COMP_COMPONENTS) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)org.openoffice.comp.example.custompanel.ToolPanelFactory$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)org.openoffice.example.colorpanel.ToolPanelFactory$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) WriterWindowState.xcu CalcWindowState.xcu DrawWindowState.xcu ImpressWindowState.xcu Factories.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) + -$(MKDIR) $(subst /,$(PS),$(@D)) && $(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_NAME).components + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F) + $(SDK_ZIP) -u $@ WriterWindowState.xcu CalcWindowState.xcu DrawWindowState.xcu ImpressWindowState.xcu Factories.xcu panel.png + cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +CustomToolPanelExample : $(COMP_PACKAGE) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to deploy the example! + @echo - + @echo $(MAKE) CustomToolPanelExample.run + @echo - + @echo -------------------------------------------------------------------------------- + +CustomToolPanelExample.run: $(OXT_DEPLOYEDFLAG) + "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(OFFICE_START_OPTIONS) $(ENV_USER_INSTALL) + +$(OXT_DEPLOYEDFLAG) : $(COMP_PACKAGE) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(OUT_DEPLOY)) + -$(MKDIR) $(subst /,$(PS),$(OUT_DEPLOY_DIR)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) $(ENV_USER_INSTALL) + @echo flagged > $(subst /,$(PS),$@) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_DEPLOY_DIR)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OXT_DEPLOYEDFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) diff --git a/odk/examples/cpp/custompanel/WriterWindowState.xcu b/odk/examples/cpp/custompanel/WriterWindowState.xcu new file mode 100644 index 000000000..c0ca084a6 --- /dev/null +++ b/odk/examples/cpp/custompanel/WriterWindowState.xcu @@ -0,0 +1,53 @@ +<?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 . + --> + +<oor:component-data oor:name="WriterWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/00FF00" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Green</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel</value> + </prop> + </node> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FF0000" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Red</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/ctp_factory.cxx b/odk/examples/cpp/custompanel/ctp_factory.cxx new file mode 100644 index 000000000..e2e29ee0d --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_factory.cxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "ctp_factory.hxx" +#include "ctp_panel.hxx" + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <cppuhelper/supportsservice.hxx> + +namespace sd { namespace colortoolpanel +{ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::lang::IllegalArgumentException; + using ::com::sun::star::ui::XUIElement; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::container::NoSuchElementException; + using ::com::sun::star::awt::XWindow; + + ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext ) + :m_xContext( i_rContext ) + { + } + + + ToolPanelFactory::~ToolPanelFactory() + { + } + + + Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !i_rResourceURL.startsWith( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) ) + throw NoSuchElementException( i_rResourceURL, *this ); + + const OUString sColor( i_rResourceURL.copy( i_rResourceURL.lastIndexOf( '/' ) + 1 ) ); + const sal_Int32 nPanelColor = static_cast< sal_Int32 >( sColor.toUInt32( 16 ) ); + + // retrieve the parent window + Reference< XWindow > xParentWindow; + const PropertyValue* pArg = i_rArgs.getConstArray(); + const PropertyValue* pArgEnd = i_rArgs.getConstArray() + i_rArgs.getLength(); + for ( ; pArg != pArgEnd; ++pArg ) + { + if ( pArg->Name == "ParentWindow" ) + { + xParentWindow.set( pArg->Value, UNO_QUERY ); + break; + } + } + if ( !xParentWindow.is() ) + { + OSL_FAIL( "ToolPanelFactory::createUIElement: no parent window in the args!" ); + throw IllegalArgumentException( + "No parent window provided in the creation arguments. Cannot create tool panel.", + *this, + 2 + ); + } + + /// create the panel + Reference< XUIElement > xUIElement( new PanelUIElement( m_xContext, xParentWindow, i_rResourceURL, nPanelColor ) ); + return xUIElement; + } + + OUString SAL_CALL ToolPanelFactory::getImplementationName( ) throw (RuntimeException) + { + return getImplementationName_static(); + } + + OUString SAL_CALL ToolPanelFactory::getImplementationName_static( ) throw (RuntimeException) + { + return OUString( "org.openoffice.comp.example.custompanel.ToolPanelFactory" ); + } + + sal_Bool SAL_CALL ToolPanelFactory::supportsService( const OUString& i_rServiceName ) throw (RuntimeException) + { + return cppu::supportsService(this, i_rServiceName); + } + + Sequence< OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException) + { + return getSupportedServiceNames_static(); + } + + Sequence< OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException) + { + Sequence< OUString > aServiceNames(1); + aServiceNames[0] = "org.openoffice.example.colorpanel.ToolPanelFactory"; + return aServiceNames; + } + + + Reference< XInterface > SAL_CALL ToolPanelFactory::Create( const Reference< XComponentContext >& i_rContext ) throw (RuntimeException) + { + return *( new ToolPanelFactory( i_rContext ) ); + } + + +} } // namespace sd::colortoolpanel + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/ctp_factory.hxx b/odk/examples/cpp/custompanel/ctp_factory.hxx new file mode 100644 index 000000000..a3aa5ddd8 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_factory.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_FACTORY_HXX +#define INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_FACTORY_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ui/XUIElementFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/basemutex.hxx> + + +namespace sd { namespace colortoolpanel +{ + + typedef ::cppu::WeakImplHelper2 < ::com::sun::star::ui::XUIElementFactory + , ::com::sun::star::lang::XServiceInfo + > ToolPanelFactory_Base; + class ToolPanelFactory :public ::cppu::BaseMutex + ,public ToolPanelFactory_Base + { + public: + ToolPanelFactory( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext + ); + ~ToolPanelFactory(); + + // XUIElementFactory + virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > SAL_CALL createUIElement( const OUString& i_rResourceURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rArgs ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo - static versions + static OUString SAL_CALL getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext ) throw (::com::sun::star::uno::RuntimeException); + + private: + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + }; + + +} } // namespace sd::colortoolpanel + + +#endif // INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_FACTORY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/ctp_panel.cxx b/odk/examples/cpp/custompanel/ctp_panel.cxx new file mode 100644 index 000000000..a6f03e247 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_panel.cxx @@ -0,0 +1,243 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + + +#include "ctp_panel.hxx" + +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <com/sun/star/awt/WindowClass.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XGraphics.hpp> +#include <com/sun/star/ui/UIElementType.hpp> + +#include <osl/diagnose.h> + + +namespace sd { namespace colortoolpanel +{ + + + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Type; + using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::awt::XWindow; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::awt::XWindowPeer; + using ::com::sun::star::lang::XMultiComponentFactory; + using ::com::sun::star::awt::WindowDescriptor; + using ::com::sun::star::awt::WindowClass_SIMPLE; + using ::com::sun::star::awt::Rectangle; + using ::com::sun::star::awt::PaintEvent; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::awt::XDevice; + using ::com::sun::star::awt::XGraphics; + using ::com::sun::star::accessibility::XAccessible; + using ::com::sun::star::frame::XFrame; + + namespace WindowAttribute = ::com::sun::star::awt::WindowAttribute; + namespace PosSize = ::com::sun::star::awt::PosSize; + namespace UIElementType = ::com::sun::star::ui::UIElementType; + + + //= helpers + + namespace + { + Reference< XWindow > lcl_createPlainWindow_nothrow( const Reference< XComponentContext >& i_rContext, + const Reference< XWindowPeer >& i_rParentWindow ) + { + try + { + OSL_ENSURE( i_rContext.is(), "illegal component context" ); + Reference< XMultiComponentFactory > xFactory( i_rContext->getServiceManager(), UNO_SET_THROW ); + Reference< XToolkit2 > xToolkit = Toolkit::create(i_rContext); + + WindowDescriptor aWindow; + aWindow.Type = WindowClass_SIMPLE; + aWindow.WindowServiceName = "window"; + aWindow.Parent = i_rParentWindow; + aWindow.WindowAttributes = WindowAttribute::BORDER; + + Reference< XWindowPeer > xWindow( xToolkit->createWindow( aWindow ), UNO_SET_THROW ); + return Reference< XWindow >( xWindow, UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + } + return NULL; + } + } + + SingleColorPanel::SingleColorPanel( const Reference< XComponentContext >& i_rContext, const Reference< XWindow >& i_rParentWindow, const ::sal_Int32 i_nPanelColor ) + :SingleColorPanel_Base( m_aMutex ) + ,m_xWindow() + ,m_nPanelColor( i_nPanelColor ) + { + // retrieve the parent window for our to-be-created pane window + Reference< XWindowPeer > xParentPeer( i_rParentWindow, UNO_QUERY ); + + osl_atomic_increment( &m_refCount ); + if ( xParentPeer.is() ) + { + m_xWindow = lcl_createPlainWindow_nothrow( i_rContext, xParentPeer ); + m_xWindow->addPaintListener( this ); + if ( m_xWindow.is() ) + { + const Rectangle aPanelAnchorSize( i_rParentWindow->getPosSize() ); + m_xWindow->setPosSize( 0, 0, aPanelAnchorSize.Width, aPanelAnchorSize.Height, PosSize::POSSIZE ); + m_xWindow->setVisible( sal_True ); + } + } + osl_atomic_decrement( &m_refCount ); + } + + + SingleColorPanel::~SingleColorPanel() + { + } + + + Reference< XWindow > SAL_CALL SingleColorPanel::getWindow() throw (RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + throw DisposedException( OUString(), *this ); + return m_xWindow; + } + + + Reference< XAccessible > SAL_CALL SingleColorPanel::createAccessible( const Reference< XAccessible >& i_rParentAccessible ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + throw DisposedException( OUString(), *this ); + + // TODO: the following is wrong, since it doesn't respect i_rParentAccessible. In a real extension, you should + // implement this correctly :) + (void)i_rParentAccessible; + return Reference< XAccessible >( getWindow(), UNO_QUERY ); + } + + + void SAL_CALL SingleColorPanel::windowPaint( const PaintEvent& i_rEvent ) throw (RuntimeException) + { + try + { + const Reference< XDevice > xDevice( i_rEvent.Source, UNO_QUERY_THROW ); + const Reference< XGraphics > xGraphics( xDevice->createGraphics(), UNO_SET_THROW ); + xGraphics->setFillColor( m_nPanelColor ); + xGraphics->setLineColor( 0x00FFFFFF ); + + const Reference< XWindow > xWindow( i_rEvent.Source, UNO_QUERY_THROW ); + const Rectangle aWindowRect( xWindow->getPosSize() ); + xGraphics->drawRect( 0, 0, aWindowRect.Width - 1, aWindowRect.Height - 1 ); + } + catch( const Exception& ) + { + } + } + + + void SAL_CALL SingleColorPanel::disposing( const EventObject& i_rSource ) throw (RuntimeException) + { + (void)i_rSource; + } + + + void SAL_CALL SingleColorPanel::disposing() + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + // already disposed + return; + m_xWindow->removePaintListener( this ); + try + { + Reference< XComponent > xWindowComp( m_xWindow, UNO_QUERY_THROW ); + xWindowComp->dispose(); + } + catch( const Exception& ) + { + } + m_xWindow.clear(); + } + + PanelUIElement::PanelUIElement( const Reference< XComponentContext >& i_rContext, const Reference< XWindow >& i_rParentWindow, + const OUString& i_rResourceURL, const ::sal_Int32 i_nPanelColor ) + :PanelUIElement_Base( m_aMutex ) + ,m_sResourceURL( i_rResourceURL ) + ,m_xToolPanel( new SingleColorPanel( i_rContext, i_rParentWindow, i_nPanelColor ) ) + { + } + + + PanelUIElement::~PanelUIElement() + { + } + + + Reference< XFrame > SAL_CALL PanelUIElement::getFrame() throw (RuntimeException) + { + // TODO + return NULL; + } + + + OUString SAL_CALL PanelUIElement::getResourceURL() throw (RuntimeException) + { + return m_sResourceURL; + } + + + ::sal_Int16 SAL_CALL PanelUIElement::getType() throw (RuntimeException) + { + return UIElementType::TOOLPANEL; + } + + + Reference< XInterface > SAL_CALL PanelUIElement::getRealInterface( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xToolPanel.is() ) + throw DisposedException(); + return m_xToolPanel; + } + + + void SAL_CALL PanelUIElement::disposing() + { + Reference< XComponent > xPanelComponent( m_xToolPanel, UNO_QUERY_THROW ); + m_xToolPanel.clear(); + xPanelComponent->dispose(); + } + + +} } // namespace sd::colortoolpanel + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/ctp_panel.hxx b/odk/examples/cpp/custompanel/ctp_panel.hxx new file mode 100644 index 000000000..c811f24e6 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_panel.hxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#ifndef INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_PANEL_HXX +#define INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_PANEL_HXX + +#include <com/sun/star/ui/XToolPanel.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/awt/XPaintListener.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/ui/XUIElement.hpp> + +#include <cppuhelper/compbase2.hxx> +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/basemutex.hxx> + + +namespace sd { namespace colortoolpanel +{ + + typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::ui::XToolPanel + , ::com::sun::star::awt::XPaintListener + > SingleColorPanel_Base; + class SingleColorPanel :public ::cppu::BaseMutex + ,public SingleColorPanel_Base + { + public: + SingleColorPanel( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& i_rParentWindow, + const ::sal_Int32 i_nPanelColor + ); + + // XToolPanel + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getWindow() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL createAccessible( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& i_rParentAccessible ) throw (::com::sun::star::uno::RuntimeException); + + // XPaintListener + virtual void SAL_CALL windowPaint( const ::com::sun::star::awt::PaintEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent equivalents + virtual void SAL_CALL disposing(); + + protected: + ~SingleColorPanel(); + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xWindow; + const sal_Int32 m_nPanelColor; + }; + + typedef ::cppu::WeakComponentImplHelper1 < ::com::sun::star::ui::XUIElement + > PanelUIElement_Base; + class PanelUIElement :public ::cppu::BaseMutex + ,public PanelUIElement_Base + { + public: + PanelUIElement( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& i_rParentWindow, + const OUString& i_rResourceURL, + const ::sal_Int32 i_nPanelColor + ); + + // XUIElement + virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame() throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getResourceURL() throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL getType() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getRealInterface( ) throw (::com::sun::star::uno::RuntimeException); + + // OComponentHelper + virtual void SAL_CALL disposing(); + + protected: + ~PanelUIElement(); + + private: + const OUString m_sResourceURL; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::XToolPanel > + m_xToolPanel; + }; + + +} } // namespace sd::colortoolpanel + + +#endif // INCLUDED_EXAMPLES_CUSTOMPANEL_CTP_PANEL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/ctp_services.cxx b/odk/examples/cpp/custompanel/ctp_services.cxx new file mode 100644 index 000000000..5c795f695 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_services.cxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * 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 . + */ + +#include "ctp_factory.hxx" + +#include <cppuhelper/implementationentry.hxx> +#include <uno/lbnames.h> + + +namespace sd { namespace colortoolpanel +{ + + + //= descriptors for the services implemented in this component + + static struct ::cppu::ImplementationEntry s_aServiceEntries[] = + { + { + ToolPanelFactory::Create, + ToolPanelFactory::getImplementationName_static, + ToolPanelFactory::getSupportedServiceNames_static, + ::cppu::createSingleComponentFactory, NULL, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; + + +} } // namespace sd::colortoolpanel + + +extern "C" +{ + + SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const char * pImplName, void * pServiceManager, void * pRegistryKey ) + { + return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , ::sd::colortoolpanel::s_aServiceEntries ); + } + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/custompanel/description.xml b/odk/examples/cpp/custompanel/description.xml new file mode 100644 index 000000000..431305fd5 --- /dev/null +++ b/odk/examples/cpp/custompanel/description.xml @@ -0,0 +1,33 @@ +<?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 . + --> +<description + xmlns="http://openoffice.org/extensions/description/2006" + xmlns:d="http://openoffice.org/extensions/description/2006" + xmlns:xlink="http://www.w3.org/1999/xlink"> + + <identifier value="org.apache.openoffice.custom-tool-panel"/> + <version value="0.1" /> + <platform value="UPDATED_SUPPORTED_PLATFORM" /> + <display-name> + <name>Custom Tool Panel Example</name> + </display-name> + <dependencies> + <OpenOffice.org-minimal-version value="3.4" d:name="OpenOffice.org 3.4"/> + </dependencies> +</description> diff --git a/odk/examples/cpp/custompanel/manifest.xml b/odk/examples/cpp/custompanel/manifest.xml new file mode 100644 index 000000000..fbb9fdcde --- /dev/null +++ b/odk/examples/cpp/custompanel/manifest.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd"> +<!-- + * 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 . + --> +<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest"> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=native" + manifest:full-path="custompanel.unoSHARED_EXTENSION"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="WriterWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="CalcWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="DrawWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="ImpressWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="Factories.xcu"/> + <!-- <manifest:file-entry manifest:media-type="image/png" + manifest:full-path="panel.png"/>--> +</manifest:manifest> diff --git a/odk/examples/cpp/custompanel/panel.png b/odk/examples/cpp/custompanel/panel.png Binary files differnew file mode 100644 index 000000000..2438714af --- /dev/null +++ b/odk/examples/cpp/custompanel/panel.png diff --git a/odk/examples/cpp/remoteclient/Makefile b/odk/examples/cpp/remoteclient/Makefile new file mode 100644 index 000000000..956243a5d --- /dev/null +++ b/odk/examples/cpp/remoteclient/Makefile @@ -0,0 +1,146 @@ +#************************************************************************* +# +# 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 C++ remoteclient example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMP_NAME=remoteclientsample +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +COMP_IMPL=$(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) +COMP_SERVICES=$(SHAREDLIB_OUT)/remoteclientsample.rdb + +ENV_COMP_SERVICES=-env:URE_MORE_SERVICES=$(URLPREFIX)$(COMP_SERVICES) + +OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) + +COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag + +CXXFILES = remoteclient.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + CppClientExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib $(LIBO_SDK_LDFLAGS_STDLIBS) + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +$(COMP_SERVICES) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)com.sun.star.comp.product.example.RemoteClientSample$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)com.sun.star.bridge.example.RemoteClientSample$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + + +#CppClientExample : $(COMP_IMPL) $(COMP_ENV_FLAG) +CppClientExample : $(COMP_IMPL) $(COMP_SERVICES) + @echo -------------------------------------------------------------------------------- + @echo The remoteclient C++ component can be used by using the uno binary. Use the + @echo the following command to start the example. The run target starts a remote + @echo server and connect with the client to this server. + @echo - + @echo $(MAKE) remoteclient.run + @echo - + @echo NOTE: The example uses the $(QM)uno$(QM) tool to prepare a working UNO environment. + @echo $(SQM) $(SQM)The example component is made available via -env:URE_MORE_SERVICES=... + @echo $(SQM) $(SQM)Please check the generated $(QM)$(COMP_SERVICES)$(QM) to see how you can specify your own components in such an environment + @echo $(SQM) $(SQM)and how to use the passive UNO registration. + @echo -------------------------------------------------------------------------------- + +%.run: $(COMP_IMPL) + @echo Start the remote server process ... + @echo - +ifeq "$(OS)" "WIN" + start uno $(ENV_COMP_SERVICES) --singleaccept -s com.sun.star.io.Pipe \ + -u "uno:socket,host=localhost,port=2083;urp;MyPipe" +else + uno $(ENV_COMP_SERVICES) --singleaccept -s com.sun.star.io.Pipe \ + -u "uno:socket,host=localhost,port=2083;urp;MyPipe" & + @echo waiting on the server process ... + sleep 5 +endif + @echo - + @echo ... remote server process runs ... + @echo - + @echo Start remote client process ... + @echo - + uno $(ENV_COMP_SERVICES) -s com.sun.star.bridge.example.RemoteClientSample \ + -- "uno:socket,host=localhost,port=2083;urp;MyPipe" + @echo - + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_SERVICES))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) +# -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/remoteserver.rdb)) diff --git a/odk/examples/cpp/remoteclient/remoteclient.cxx b/odk/examples/cpp/remoteclient/remoteclient.cxx new file mode 100644 index 000000000..98a16e38b --- /dev/null +++ b/odk/examples/cpp/remoteclient/remoteclient.cxx @@ -0,0 +1,259 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#include <stdio.h> +#include <osl/mutex.hxx> +#include <uno/lbnames.h> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/uno/XNamingService.hpp> + +#include <com/sun/star/connection/XConnector.hpp> + +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> + +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> + +#include <cppuhelper/implbase1.hxx> + +using namespace ::rtl; +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::connection; +using namespace ::com::sun::star::bridge; +using namespace ::com::sun::star::io; + + +namespace remotebridges_officeclient { + +class PipeClientMain : public WeakImplHelper1< XMain > +{ +public: + PipeClientMain( const Reference< XMultiServiceFactory > &r ) : + m_xSMgr( r ) + {} +public: // Methods + + + virtual sal_Int32 SAL_CALL run( const Sequence< OUString >& aArguments ); + + +private: // helper methods + void testPipe( const Reference < XInterface > & rComponent ); + Reference< XMultiServiceFactory > m_xSMgr; +}; + +void PipeClientMain::testPipe( const Reference< XInterface > & rxInterface ) +{ + // ask for the input stream + Reference< XInputStream > rInputStream( rxInterface, UNO_QUERY ); + + // ask for the output stream + Reference< XOutputStream > rOutputStream( rxInterface, UNO_QUERY ); + + if( rInputStream.is() && rOutputStream.is() ) + { + printf( "got inputstream and outputstream from remote process\n" ); + + sal_Int8 a[] = { 5,4,3,2,1,0 }; + Sequence< sal_Int8 > seq( a , 6 ); + rOutputStream->writeBytes( seq ); + rOutputStream->closeOutput(); + + Sequence< sal_Int8> seqRead; + if( rInputStream->readBytes( seqRead ,3 ) != 3 ) + { + printf( "error : Couldn't read the expected number of bytes\n" ); + return; + } + + if( seqRead.getConstArray()[0] != 5 || + seqRead.getConstArray()[1] != 4 || + seqRead.getConstArray()[2] != 3 ) + { + printf( "error : The array doesn't contain the expected values\n" ); + return; + } + + // try to read more bytes than written + if( rInputStream->readBytes( seqRead , 4 ) != 3 ) + { + printf( "error : Got an unexpected number of bytes\n" ); + return; + } + + if( seqRead.getConstArray()[0] != 2 || + seqRead.getConstArray()[1] != 1 || + seqRead.getConstArray()[2] != 0 ) + { + printf( "error : The array doesn't contain the expected values\n" ); + return; + } + + printf( "pipe test worked perfect\n" ); + } + else + { + printf( "Couldn't get inputstream and outputstream\n" ); + } +} + + +sal_Int32 PipeClientMain::run( const Sequence< OUString > & aArguments ) +{ + printf( "Connecting...\n" ); + + if( aArguments.getLength() == 1 ) + { + try { + Reference < XInterface > r = + m_xSMgr->createInstance("com.sun.star.bridge.UnoUrlResolver"); + Reference < XUnoUrlResolver > rResolver( r , UNO_QUERY ); + + // connect to the remote process and retrieve the initial object + r = rResolver->resolve( aArguments.getConstArray()[0] ); + + if( r.is() ) + { + printf( "got the remote initial object\n" ); + testPipe( r ); + } + else + { + printf( "error : didn't get the initial object\n" ); + } + } + catch( ConnectionSetupException &e ) + { + OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); + printf( "%s\n", o.pData->buffer ); + printf( "couldn't access local resource (possible security reasons)\n" ); + } + catch( NoConnectException &e ) + { + OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); + printf( "%s\n", o.pData->buffer ); + printf( "no server listening on the resource\n" ); + } + catch( IllegalArgumentException &e ) + { + OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); + printf( "%s\n", o.pData->buffer ); + printf( "uno url invalid\n" ); + } + catch( RuntimeException & e ) + { + OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); + printf( "%s\n", o.pData->buffer ); + printf( "a remote call was aborted\n" ); + } + } + else + { + printf( "usage: (uno remoteclient-component --) uno-url\n" + "e.g.: uno:socket,host=localhost,port=2083;urp;MyPipe\n" ); + return 1; + } + return 0; +} + +Reference< XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r) +{ + return Reference< XInterface > ( ( OWeakObject * ) new PipeClientMain(r) ); +} + +Sequence< OUString > getSupportedServiceNames() +{ + static Sequence < OUString > *pNames = 0; + if( ! pNames ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !pNames ) + { + static Sequence< OUString > seqNames(1); + seqNames[0] = "com.sun.star.bridge.example.RemoteClientSample"; + pNames = &seqNames; + } + } + return *pNames; +} + +} + +using namespace remotebridges_officeclient; +#define IMPLEMENTATION_NAME "com.sun.star.comp.product.example.RemoteClientSample" + + +extern "C" +{ +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString::createFromAscii( pImplName ), + CreateInstance, getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |