From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- 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 14 files changed, 1058 insertions(+) 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 (limited to 'odk/examples/cpp/custompanel') diff --git a/odk/examples/cpp/custompanel/CalcWindowState.xcu b/odk/examples/cpp/custompanel/CalcWindowState.xcu new file mode 100644 index 0000000000..427734289c --- /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 0000000000..ca7037a9cf --- /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 0000000000..05ce990a45 --- /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 0000000000..372ac726ed --- /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 0000000000..b19c5a1721 --- /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) $(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 0000000000..c0ca084a6e --- /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 0000000000..e2e29ee0d5 --- /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 0000000000..a3aa5ddd87 --- /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 0000000000..a6f03e247e --- /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 0000000000..c811f24e6f --- /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 0000000000..5c795f695b --- /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 0000000000..431305fd5d --- /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 0000000000..fbb9fdcde2 --- /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 0000000000..2438714af8 Binary files /dev/null and b/odk/examples/cpp/custompanel/panel.png differ -- cgit v1.2.3