From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- odk/examples/cpp/DocumentLoader/DocumentLoader.cxx | 150 ++++++ odk/examples/cpp/DocumentLoader/Makefile | 107 +++++ odk/examples/cpp/DocumentLoader/test.odt | Bin 0 -> 11176 bytes odk/examples/cpp/complextoolbarcontrols/Addons.xcu | 187 ++++++++ .../cpp/complextoolbarcontrols/CalcListener.cxx | 32 ++ .../cpp/complextoolbarcontrols/CalcWindowState.xcu | 38 ++ odk/examples/cpp/complextoolbarcontrols/Jobs.xcu | 39 ++ .../cpp/complextoolbarcontrols/ListenerHelper.cxx | 138 ++++++ .../cpp/complextoolbarcontrols/ListenerHelper.h | 85 ++++ odk/examples/cpp/complextoolbarcontrols/Makefile | 182 ++++++++ odk/examples/cpp/complextoolbarcontrols/MyJob.cxx | 97 ++++ odk/examples/cpp/complextoolbarcontrols/MyJob.h | 91 ++++ .../cpp/complextoolbarcontrols/MyListener.cxx | 134 ++++++ .../cpp/complextoolbarcontrols/MyListener.h | 116 +++++ .../complextoolbarcontrols/MyProtocolHandler.cxx | 501 +++++++++++++++++++++ .../cpp/complextoolbarcontrols/MyProtocolHandler.h | 161 +++++++ .../cpp/complextoolbarcontrols/ProtocolHandler.xcu | 27 ++ .../cpp/complextoolbarcontrols/WriterListener.cxx | 40 ++ .../complextoolbarcontrols/WriterWindowState.xcu | 38 ++ .../cpp/complextoolbarcontrols/description.xml | 26 ++ .../cpp/complextoolbarcontrols/exports.cxx | 68 +++ .../cpp/complextoolbarcontrols/logo_big.png | Bin 0 -> 616 bytes .../cpp/complextoolbarcontrols/logo_small.png | Bin 0 -> 585 bytes odk/examples/cpp/counter/Makefile | 174 +++++++ odk/examples/cpp/counter/XCountable.idl | 58 +++ odk/examples/cpp/counter/counter.cxx | 183 ++++++++ odk/examples/cpp/counter/countermain.cxx | 98 ++++ odk/examples/cpp/custompanel/CalcWindowState.xcu | 39 ++ odk/examples/cpp/custompanel/DrawWindowState.xcu | 39 ++ odk/examples/cpp/custompanel/Factories.xcu | 39 ++ .../cpp/custompanel/ImpressWindowState.xcu | 39 ++ odk/examples/cpp/custompanel/Makefile | 171 +++++++ odk/examples/cpp/custompanel/WriterWindowState.xcu | 53 +++ odk/examples/cpp/custompanel/ctp_factory.cxx | 126 ++++++ odk/examples/cpp/custompanel/ctp_factory.hxx | 70 +++ odk/examples/cpp/custompanel/ctp_panel.cxx | 243 ++++++++++ odk/examples/cpp/custompanel/ctp_panel.hxx | 108 +++++ odk/examples/cpp/custompanel/ctp_services.cxx | 63 +++ odk/examples/cpp/custompanel/description.xml | 33 ++ odk/examples/cpp/custompanel/manifest.xml | 35 ++ odk/examples/cpp/custompanel/panel.png | Bin 0 -> 202 bytes odk/examples/cpp/remoteclient/Makefile | 154 +++++++ odk/examples/cpp/remoteclient/remoteclient.cxx | 260 +++++++++++ 43 files changed, 4242 insertions(+) create mode 100644 odk/examples/cpp/DocumentLoader/DocumentLoader.cxx create mode 100644 odk/examples/cpp/DocumentLoader/Makefile create mode 100644 odk/examples/cpp/DocumentLoader/test.odt create mode 100644 odk/examples/cpp/complextoolbarcontrols/Addons.xcu create mode 100644 odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu create mode 100644 odk/examples/cpp/complextoolbarcontrols/Jobs.xcu create mode 100644 odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h create mode 100644 odk/examples/cpp/complextoolbarcontrols/Makefile create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyJob.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyJob.h create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyListener.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyListener.h create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h create mode 100644 odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu create mode 100644 odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu create mode 100644 odk/examples/cpp/complextoolbarcontrols/description.xml create mode 100644 odk/examples/cpp/complextoolbarcontrols/exports.cxx create mode 100644 odk/examples/cpp/complextoolbarcontrols/logo_big.png create mode 100644 odk/examples/cpp/complextoolbarcontrols/logo_small.png create mode 100644 odk/examples/cpp/counter/Makefile create mode 100644 odk/examples/cpp/counter/XCountable.idl create mode 100644 odk/examples/cpp/counter/counter.cxx create mode 100644 odk/examples/cpp/counter/countermain.cxx create mode 100644 odk/examples/cpp/custompanel/CalcWindowState.xcu create mode 100644 odk/examples/cpp/custompanel/DrawWindowState.xcu create mode 100644 odk/examples/cpp/custompanel/Factories.xcu create mode 100644 odk/examples/cpp/custompanel/ImpressWindowState.xcu create mode 100644 odk/examples/cpp/custompanel/Makefile create mode 100644 odk/examples/cpp/custompanel/WriterWindowState.xcu create mode 100644 odk/examples/cpp/custompanel/ctp_factory.cxx create mode 100644 odk/examples/cpp/custompanel/ctp_factory.hxx create mode 100644 odk/examples/cpp/custompanel/ctp_panel.cxx create mode 100644 odk/examples/cpp/custompanel/ctp_panel.hxx create mode 100644 odk/examples/cpp/custompanel/ctp_services.cxx create mode 100644 odk/examples/cpp/custompanel/description.xml create mode 100644 odk/examples/cpp/custompanel/manifest.xml create mode 100644 odk/examples/cpp/custompanel/panel.png create mode 100644 odk/examples/cpp/remoteclient/Makefile create mode 100644 odk/examples/cpp/remoteclient/remoteclient.cxx (limited to 'odk/examples/cpp') diff --git a/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx b/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx new file mode 100644 index 000000000..7e1f89cf3 --- /dev/null +++ b/odk/examples/cpp/DocumentLoader/DocumentLoader.cxx @@ -0,0 +1,150 @@ +/* -*- 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 +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +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 ::rtl::OUString; +using ::rtl::OUStringToOString; + + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + OUString sConnectionString("uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"); + + sal_Int32 nCount = (sal_Int32)rtl_getAppCommandArgCount(); + + if (nCount < 1) + { + printf("using: DocumentLoader -env:URE_MORE_TYPES= []\n\n" + "example: DocumentLoader -env:URE_MORE_TYPES=\"file:///.../program/offapi.rdb\" \"file:///e:/temp/test.odt\" \"uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager\"\n"); + 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 ) + { + printf("Error: cannot establish a connection using '%s':\n %s\n", + OUStringToOString(sConnectionString, RTL_TEXTENCODING_ASCII_US).getStr(), + OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr()); + 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..812d13332 --- /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)$(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 new file mode 100644 index 000000000..dc4efecac Binary files /dev/null and b/odk/examples/cpp/DocumentLoader/test.odt differ 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 @@ + + + + + + + + + vnd.demo.complextoolbarcontrols.demoaddon:ImageButtonCmd + + + Image Button + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + ImageButton + + + + + vnd.demo.complextoolbarcontrols.demoaddon:ComboboxCmd + + + ComboBox + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + Combobox + + + 200 + + + + + private:separator + + + + + vnd.demo.complextoolbarcontrols.demoaddon:SpinfieldCmd + + + Spinfield + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + Spinfield + + + 150 + + + + + private:separator + + + + + vnd.demo.complextoolbarcontrols.demoaddon:EditfieldCmd + + + Editfield + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + Editfield + + + 130 + + + + + private:separator + + + + + vnd.demo.complextoolbarcontrols.demoaddon:DropdownboxCmd + + + Dropdownbox + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + Dropdownbox + + + 80 + + + + + vnd.demo.complextoolbarcontrols.demoaddon:ToggleDropdownButtonCmd + + + Toggle Dropdown Button + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + ToggleDropdownButton + + + + + vnd.demo.complextoolbarcontrols.demoaddon:DropdownButtonCmd + + + Dropdown Button + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument + + + DropdownButton + + + + + + + + vnd.demo.complextoolbarcontrols.demoaddon:ImageButtonCmd + + + + %origin%/logo_small.png + + + %origin%/logo_big.png + + + + + + diff --git a/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx new file mode 100644 index 000000000..e02a5d695 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx @@ -0,0 +1,32 @@ +/* -*- 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 + +void SAL_CALL CalcListener::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) +{ +} + +void SAL_CALL CalcListener::disposing( const com::sun::star::lang::EventObject& aSource ) throw( com::sun::star::uno::RuntimeException ) +{ +} + +/* 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 @@ + + + + + + + + false + + + Complex Toolbar Controls + + + true + + + false + + + + + \ 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 @@ + + + + + + + vnd.demo.NewDocListener + + + + + + + + + + + + + + + + diff --git a/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx new file mode 100644 index 000000000..0ee09734a --- /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 + +#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& xFrame, + const Reference < XStatusListener > xControl, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i& xFrame, + const ::rtl::OUString& aCommand, + FeatureStateEvent& rEvent ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; istatusChanged( 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(); +} + +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) throw (RuntimeException) +{ + 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..f24150df7 --- /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 +#include + +#include +#include +#include + +#include +#include + +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 ) throw (com::sun::star::uno::RuntimeException); +}; + +#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)/$( $(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..656eb6942 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx @@ -0,0 +1,97 @@ +/* -*- 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 +#include +#include +#include + +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 ) + throw ( IllegalArgumentException, Exception, RuntimeException ) +{ + 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 () + throw (RuntimeException) +{ + return OUString( "com.sun.star.comp.Office.MyJob" ); +} + +#define SERVICE_NAME "com.sun.star.task.Job" + +Sequence< OUString > SAL_CALL MyJob_getSupportedServiceNames( ) + throw (RuntimeException) +{ + 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) + throw( Exception ) +{ + return (cppu::OWeakObject*) new MyJob( rSMgr ); +} + +// XServiceInfo +OUString SAL_CALL MyJob::getImplementationName( ) + throw (RuntimeException) +{ + return MyJob_getImplementationName(); +} + +sal_Bool SAL_CALL MyJob::supportsService( const OUString& rServiceName ) + throw (RuntimeException) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > SAL_CALL MyJob::getSupportedServiceNames( ) + throw (RuntimeException) +{ + 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..0741e5eed --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.h @@ -0,0 +1,91 @@ +/* -*- 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 +#include +#include +#include +#include + +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 ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); +}; + +::rtl::OUString MyJob_getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + +sal_Bool SAL_CALL MyJob_supportsService( const ::rtl::OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyJob_getSupportedServiceNames( ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::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) + throw ( ::com::sun::star::uno::Exception ); + +#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..82f8d01a3 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx @@ -0,0 +1,134 @@ +/* -*- 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 +#include +#include +#include +#include + +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) + throw (css::lang::IllegalArgumentException, + css::uno::Exception, + css::uno::RuntimeException) +{ + 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>= lEnv; + break; + } + } + + css::uno::Reference< css::frame::XModel > xModel; + + c = lEnv.getLength(); + p = lEnv.getConstArray(); + for (i=0; i>= 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() + throw (css::uno::RuntimeException) +{ + return ::rtl::OUString( MYLISTENER_IMPLEMENTATIONNAME ); +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL MyListener::getSupportedServiceNames() + throw (css::uno::RuntimeException) +{ + 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) + throw (css::uno::RuntimeException) +{ + 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..428693dac --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.h @@ -0,0 +1,116 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include + +#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) + throw (css::lang::IllegalArgumentException, + css::uno::Exception, + css::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName) + throw (css::uno::RuntimeException); + + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (css::uno::RuntimeException); + + 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) + throw (css::uno::RuntimeException); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw (css::uno::RuntimeException); +}; + +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) + throw (css::uno::RuntimeException); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw (css::uno::RuntimeException); +}; + +#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..4020953b6 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx @@ -0,0 +1,501 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 ) throw ( Exception, RuntimeException) +{ + 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 ) + throw( RuntimeException ) +{ + 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 ) + throw( RuntimeException ) +{ + sal_Int32 nCount = seqDescripts.getLength(); + Sequence < Reference < XDispatch > > lDispatcher( nCount ); + + for( sal_Int32 i=0; i SAL_CALL MyProtocolHandler_getSupportedServiceNames( ) + throw (RuntimeException) +{ + 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) + throw( Exception ) +{ + return (cppu::OWeakObject*) new MyProtocolHandler( rSMgr ); +} + +// XServiceInfo +::rtl::OUString SAL_CALL MyProtocolHandler::getImplementationName( ) + throw (RuntimeException) +{ + return MyProtocolHandler_getImplementationName(); +} + +sal_Bool SAL_CALL MyProtocolHandler::supportsService( const ::rtl::OUString& rServiceName ) + throw (RuntimeException) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler::getSupportedServiceNames( ) + throw (RuntimeException) +{ + return MyProtocolHandler_getSupportedServiceNames(); +} + +void SAL_CALL BaseDispatch::dispatch( const URL& aURL, const Sequence < PropertyValue >& lArgs ) throw (RuntimeException) +{ + /* 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 ) throw (RuntimeException) +{ + 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 ) throw (RuntimeException) +{ + aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path ); +} + +void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event ) throw (RuntimeException) +{ + 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..4ee22a0fe --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h @@ -0,0 +1,161 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#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 ) + throw( ::com::sun::star::uno::RuntimeException ); + 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 ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); +}; + +::rtl::OUString MyProtocolHandler_getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + +sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::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) + throw ( ::com::sun::star::uno::Exception ); + +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 ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException); + + // XControlNotificationListener + virtual void SAL_CALL controlEvent( const ::com::sun::star::frame::ControlEvent& Event ) + throw (::com::sun::star::uno::RuntimeException); +}; + +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 @@ + + + + + + + vnd.demo.complextoolbarcontrols.demoaddon:* + + + + diff --git a/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx b/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx new file mode 100644 index 000000000..31be46c6a --- /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 + +void SAL_CALL WriterListener::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) +{ +} + +void SAL_CALL WriterListener::disposing( const com::sun::star::lang::EventObject& aSource ) throw( com::sun::star::uno::RuntimeException ) +{ +} + +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 @@ + + + + + + + + false + + + Complex Toolbar Controls + + + true + + + false + + + + + \ 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 @@ + + + + + + + + Complex Toolbar Controls Demo + + 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 +#include + +#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 new file mode 100644 index 000000000..23dd24109 Binary files /dev/null and b/odk/examples/cpp/complextoolbarcontrols/logo_big.png differ diff --git a/odk/examples/cpp/complextoolbarcontrols/logo_small.png b/odk/examples/cpp/complextoolbarcontrols/logo_small.png new file mode 100644 index 000000000..c24b4e275 Binary files /dev/null and b/odk/examples/cpp/complextoolbarcontrols/logo_small.png differ diff --git a/odk/examples/cpp/counter/Makefile b/odk/examples/cpp/counter/Makefile new file mode 100644 index 000000000..b848adb02 --- /dev/null +++ b/odk/examples/cpp/counter/Makefile @@ -0,0 +1,174 @@ +#************************************************************************* +# +# 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)) + +GENURDFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/%.urd,$(IDLFILES)) + +TYPESLIST = -Tfoo.XCountable + +# Targets +.PHONY: ALL +ALL : \ + CppCounterExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_GEN)/%.urd : %.idl + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(IDLC) -I. -I$(IDL_DIR) -O$(OUT_COMP_GEN) $< + +# This example type library will be extended by the URE types +$(OUT_BIN)/%.rdb : $(GENURDFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + $(REGMERGE) $@ /UCR $(GENURDFILES) +# $(REGMERGE) $@ / $(URE_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 + +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..7e16b6a10 --- /dev/null +++ b/odk/examples/cpp/counter/counter.cxx @@ -0,0 +1,183 @@ +/* -*- 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 +#include +#include +#include +#include +#include +// generated c++ interfaces +#include +#include +#include +#include +#include + +#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 ) + { printf( "< MyCounterImpl ctor called >\n" ); } + ~MyCounterImpl() + { printf( "< MyCounterImpl dtor called >\n" ); } + + // 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 ) throw (RuntimeException) + { 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( ) throw(RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException); + static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ); + + // XCountable implementation + virtual sal_Int32 SAL_CALL getCount() throw (RuntimeException) + { return m_nCount; } + virtual void SAL_CALL setCount( sal_Int32 nCount ) throw (RuntimeException) + { m_nCount = nCount; } + virtual sal_Int32 SAL_CALL increment() throw (RuntimeException) + { return (++m_nCount); } + virtual sal_Int32 SAL_CALL decrement() throw (RuntimeException) + { return (--m_nCount); } +}; + +OUString SAL_CALL MyCounterImpl::getImplementationName( ) + throw(RuntimeException) +{ + return OUString( IMPLNAME ); +} + +sal_Bool SAL_CALL MyCounterImpl::supportsService( const OUString& ServiceName ) + throw(RuntimeException) +{ + return cppu::supportsService(this, ServiceName); +} + +Sequence SAL_CALL MyCounterImpl::getSupportedServiceNames( ) + throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +Sequence 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(static_cast(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 +#include + +#include +#include + +#include + +#include + +// generated c++ interfaces +#include +#include +#include + + +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 @@ + + + + + + + + + Soylent Blue + + + false + + + vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png + + + vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel + + + + + 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 @@ + + + + + + + + + Soylent Yellow + + + false + + + vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png + + + vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel + + + + + 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 @@ + + + + + + + + + toolpanel + + + org.openoffice.example.colorpanel + + + + + + org.openoffice.example.colorpanel.ToolPanelFactory + + + + + 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 @@ + + + + + + + + + Soylent Orange + + + false + + + vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png + + + vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel + + + + + 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)/$( $(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 @@ + + + + + + + + + Soylent Green + + + false + + + vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png + + + vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel + + + + + Soylent Red + + + false + + + vnd.sun.star.extension://org.apache.openoffice.custom-tool-panel/panel.png + + + vnd.sun.star.help://org.apache.openoffice.custom-tool-panel/colorpanel + + + + + 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 +#include + +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 +#include +#include + +#include +#include + + +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 +#include +#include +#include +#include +#include +#include +#include + +#include + + +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 +#include +#include +#include +#include + +#include +#include +#include + + +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 +#include + + +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 @@ + + + + + + + + + Custom Tool Panel Example + + + + + 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 @@ + + + + + + + + + + + + diff --git a/odk/examples/cpp/custompanel/panel.png b/odk/examples/cpp/custompanel/panel.png new file mode 100644 index 000000000..2438714af Binary files /dev/null and b/odk/examples/cpp/custompanel/panel.png differ diff --git a/odk/examples/cpp/remoteclient/Makefile b/odk/examples/cpp/remoteclient/Makefile new file mode 100644 index 000000000..238ec3ca2 --- /dev/null +++ b/odk/examples/cpp/remoteclient/Makefile @@ -0,0 +1,154 @@ +#************************************************************************* +# +# 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_RDB_NAME = $(COMP_NAME).uno.rdb +COMP_RDB = $(OUT_BIN)/$(COMP_RDB_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 + +# This example type library will be extended by the URE types +$(OUT_BIN)/%.rdb : + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + $(REGMERGE) $@ / $(URE_TYPES) + +$(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..7c70f5dfe --- /dev/null +++ b/odk/examples/cpp/remoteclient/remoteclient.cxx @@ -0,0 +1,260 @@ +/* -*- 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 +#include +#include +#include + +#include + +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +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 ) + throw(RuntimeException); + + +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 ) throw ( RuntimeException ) +{ + 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: */ -- cgit v1.2.3