diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2012-06-15 00:35:04 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-12 16:11:50 +0100 |
commit | 379c7011157abae07ceb895cba22b85dcb67c8b9 (patch) | |
tree | 8944a6a5db0ccfe8e65495401d14b40c6396edea /odk/examples/cpp | |
parent | f94000bf5be0e1e0f9196306c6de5741707ad7b7 (diff) |
Move Custom Panel example to the SDK
(cherry picked from commit d0b30a0f10f506187fcff9775934d3594c140ead)
Change-Id: I898433cbdf9f779f425424d600ebb4f0946ccf20
Diffstat (limited to 'odk/examples/cpp')
-rw-r--r-- | odk/examples/cpp/custompanel/CalcWindowState.xcu | 39 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/DrawWindowState.xcu | 39 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/Factories.xcu | 39 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ImpressWindowState.xcu | 39 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/WriterWindowState.xcu | 53 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ctp_factory.cxx | 156 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ctp_factory.hxx | 74 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ctp_panel.cxx | 258 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ctp_panel.hxx | 117 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/ctp_services.cxx | 74 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/description.xml | 33 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/manifest.xml | 35 | ||||
-rw-r--r-- | odk/examples/cpp/custompanel/panel.png | bin | 0 -> 202 bytes |
13 files changed, 956 insertions, 0 deletions
diff --git a/odk/examples/cpp/custompanel/CalcWindowState.xcu b/odk/examples/cpp/custompanel/CalcWindowState.xcu new file mode 100644 index 000000000000..1a9cebb4e625 --- /dev/null +++ b/odk/examples/cpp/custompanel/CalcWindowState.xcu @@ -0,0 +1,39 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<oor:component-data oor:name="CalcWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/0000FF" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Blue</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://UPDATED_IDENTIFIER/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://UPDATED_IDENTIFIER/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/DrawWindowState.xcu b/odk/examples/cpp/custompanel/DrawWindowState.xcu new file mode 100644 index 000000000000..c8e63b172aec --- /dev/null +++ b/odk/examples/cpp/custompanel/DrawWindowState.xcu @@ -0,0 +1,39 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<oor:component-data oor:name="DrawWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FFFF00" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Yellow</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://UPDATED_IDENTIFIER/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://UPDATED_IDENTIFIER/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/Factories.xcu b/odk/examples/cpp/custompanel/Factories.xcu new file mode 100644 index 000000000000..05ce990a4577 --- /dev/null +++ b/odk/examples/cpp/custompanel/Factories.xcu @@ -0,0 +1,39 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<oor:component-data oor:name="Factories" oor:package="org.openoffice.Office.UI" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="Registered"> + <node oor:name="UIElementFactories"> + <node oor:name="org.openoffice.example.CustomToolPanel" oor:op="replace"> + <prop oor:name="Type"> + <value>toolpanel</value> + </prop> + <prop oor:name="Name"> + <value>org.openoffice.example.colorpanel</value> + </prop> + <prop oor:name="Module"> + <value/> + </prop> + <prop oor:name="FactoryImplementation"> + <value>org.openoffice.example.colorpanel.ToolPanelFactory</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/ImpressWindowState.xcu b/odk/examples/cpp/custompanel/ImpressWindowState.xcu new file mode 100644 index 000000000000..f1f393da1710 --- /dev/null +++ b/odk/examples/cpp/custompanel/ImpressWindowState.xcu @@ -0,0 +1,39 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<oor:component-data oor:name="ImpressWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FFCC99" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Orange</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://UPDATED_IDENTIFIER/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://UPDATED_IDENTIFIER/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/WriterWindowState.xcu b/odk/examples/cpp/custompanel/WriterWindowState.xcu new file mode 100644 index 000000000000..38cace901575 --- /dev/null +++ b/odk/examples/cpp/custompanel/WriterWindowState.xcu @@ -0,0 +1,53 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<oor:component-data oor:name="WriterWindowState" oor:package="org.openoffice.Office.UI" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/00FF00" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Green</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://UPDATED_IDENTIFIER/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://UPDATED_IDENTIFIER/colorpanel</value> + </prop> + </node> + <node oor:name="private:resource/toolpanel/org.openoffice.example.colorpanel/FF0000" oor:op="replace"> + <prop oor:name="UIName" oor:type="xs:string"> + <value>Soylent Red</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="ImageURL" oor:type="xs:string"> + <value>vnd.sun.star.extension://UPDATED_IDENTIFIER/panel.png</value> + </prop> + <prop oor:name="HelpURL" oor:type="xs:string"> + <value>vnd.sun.star.help://UPDATED_IDENTIFIER/colorpanel</value> + </prop> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/custompanel/ctp_factory.cxx b/odk/examples/cpp/custompanel/ctp_factory.cxx new file mode 100644 index 000000000000..1fb01a5136b2 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_factory.cxx @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "ctp_factory.hxx" +#include "ctp_panel.hxx" + +#include <com/sun/star/lang/NotInitializedException.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XComponent.hpp> + +//...................................................................................................................... +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::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::lang::NotInitializedException; + using ::com::sun::star::lang::IllegalArgumentException; + using ::com::sun::star::lang::XComponent; + 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::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.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "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 = sColor.toInt32( 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( + OUString( "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) + { + const Sequence< OUString > aServiceNames( getSupportedServiceNames() ); + for ( const OUString* serviceName = aServiceNames.getConstArray(); + serviceName != aServiceNames.getConstArray() + aServiceNames.getLength(); + ++serviceName + ) + { + if ( i_rServiceName == *serviceName ) + return sal_True; + } + return sal_False; + } + + //------------------------------------------------------------------------------------------------------------------ + 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] = OUString( "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 000000000000..2399807b2106 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_factory.hxx @@ -0,0 +1,74 @@ +/* -*- 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 SD_WORKBENCH_CTP_FACTORY_HXX +#define SD_WORKBENCH_CTP_FACTORY_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ui/XUIElementFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/basemutex.hxx> + +//...................................................................................................................... +namespace sd { namespace colortoolpanel +{ +//...................................................................................................................... + + //================================================================================================================== + //= ToolPanelFactory + //================================================================================================================== + 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 // SD_WORKBENCH_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 000000000000..98b58a8e95de --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_panel.cxx @@ -0,0 +1,258 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "ctp_panel.hxx" + +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <com/sun/star/awt/Toolkit.hpp> +#include <com/sun/star/awt/WindowClass.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XGraphics.hpp> +#include <com/sun/star/ui/UIElementType.hpp> + +#include <tools/diagnose_ex.h> + +//...................................................................................................................... +namespace sd { namespace colortoolpanel +{ +//...................................................................................................................... + + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + 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::XToolkit; + 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 + { + ENSURE_OR_THROW( 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 = OUString( "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& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return NULL; + } + } + //================================================================================================================== + //= class SingleColorPanel + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + 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& ) + { + DBG_UNHANDLED_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& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + m_xWindow.clear(); + } + + //================================================================================================================== + //= PanelUIElement + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + 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 000000000000..5ef7f19742f2 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_panel.hxx @@ -0,0 +1,117 @@ +/* -*- 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 SD_WORKBENCH_CTP_PANEL_HXX +#define SD_WORKBENCH_CTP_PANEL_HXX + +#include <com/sun/star/ui/XToolPanel.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/awt/XPaintListener.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/ui/XUIElement.hpp> + +#include <cppuhelper/compbase2.hxx> +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/basemutex.hxx> + +#include <boost/scoped_ptr.hpp> + +//...................................................................................................................... +namespace sd { namespace colortoolpanel +{ +//...................................................................................................................... + + //================================================================================================================== + //= SingleColorPanel + //================================================================================================================== + 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; + }; + + //================================================================================================================== + //= PanelUIElement + //================================================================================================================== + 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 // SD_WORKBENCH_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 000000000000..26bacd3bc603 --- /dev/null +++ b/odk/examples/cpp/custompanel/ctp_services.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "ctp_factory.hxx" + +#include <cppuhelper/implementationentry.hxx> + +//...................................................................................................................... +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::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + + //================================================================================================================== + //= 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_Bool SAL_CALL component_writeInfo( void * pServiceManager, void * pRegistryKey ) + { + return ::cppu::component_writeInfoHelper( pServiceManager, pRegistryKey, ::sd::colortoolpanel::s_aServiceEntries ); + } + + //------------------------------------------------------------------------------------------------------------------ + SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) + { + return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , ::sd::colortoolpanel::s_aServiceEntries ); + } +} + +/* 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 000000000000..b562508f447a --- /dev/null +++ b/odk/examples/cpp/custompanel/description.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> +<description + xmlns="http://openoffice.org/extensions/description/2006" + xmlns:d="http://openoffice.org/extensions/description/2006" + xmlns:xlink="http://www.w3.org/1999/xlink"> + + <identifier value="UPDATED_IDENTIFIER"/> + <version value="0.1" /> + <platform value="UPDATED_SUPPORTED_PLATFORM" /> + <display-name> + <name>Custom Tool Panel Example</name> + </display-name> + <dependencies> + <OpenOffice.org-minimal-version value="3.3" d:name="OpenOffice.org 3.3"/> + </dependencies> +</description> diff --git a/odk/examples/cpp/custompanel/manifest.xml b/odk/examples/cpp/custompanel/manifest.xml new file mode 100644 index 000000000000..fbb9fdcde2f3 --- /dev/null +++ b/odk/examples/cpp/custompanel/manifest.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd"> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> +<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest"> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=native" + manifest:full-path="custompanel.unoSHARED_EXTENSION"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="WriterWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="CalcWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="DrawWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="ImpressWindowState.xcu"/> + <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" + manifest:full-path="Factories.xcu"/> + <!-- <manifest:file-entry manifest:media-type="image/png" + manifest:full-path="panel.png"/>--> +</manifest:manifest> diff --git a/odk/examples/cpp/custompanel/panel.png b/odk/examples/cpp/custompanel/panel.png Binary files differnew file mode 100644 index 000000000000..2438714af8a6 --- /dev/null +++ b/odk/examples/cpp/custompanel/panel.png |