diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /svx/source/unogallery | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'svx/source/unogallery')
-rw-r--r-- | svx/source/unogallery/unogalitem.cxx | 368 | ||||
-rw-r--r-- | svx/source/unogallery/unogalitem.hxx | 104 | ||||
-rw-r--r-- | svx/source/unogallery/unogaltheme.cxx | 362 | ||||
-rw-r--r-- | svx/source/unogallery/unogaltheme.hxx | 100 | ||||
-rw-r--r-- | svx/source/unogallery/unogalthemeprovider.cxx | 247 |
5 files changed, 1181 insertions, 0 deletions
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx new file mode 100644 index 000000000..5addd3226 --- /dev/null +++ b/svx/source/unogallery/unogalitem.cxx @@ -0,0 +1,368 @@ +/* -*- 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 "unogalitem.hxx" +#include "unogaltheme.hxx" +#include <svx/galtheme.hxx> +#include <svx/galmisc.hxx> +#include <svx/fmmodel.hxx> +#include <vcl/svapp.hxx> +#include <vcl/graph.hxx> +#include <svl/itempool.hxx> +#include <comphelper/servicehelper.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <galobj.hxx> + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/gallery/GalleryItemType.hpp> +#include <memory> + +#define UNOGALLERY_GALLERYITEMTYPE 1 +#define UNOGALLERY_URL 2 +#define UNOGALLERY_TITLE 3 +#define UNOGALLERY_THUMBNAIL 4 +#define UNOGALLERY_GRAPHIC 5 +#define UNOGALLERY_DRAWING 6 + +using namespace ::com::sun::star; + +namespace unogallery { + + +GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) : + ::comphelper::PropertySetHelper( createPropertySetInfo() ), + mpTheme( &rTheme ), + mpGalleryObject( &rObject ) +{ + mpTheme->implRegisterGalleryItem( *this ); +} + + +GalleryItem::~GalleryItem() + noexcept +{ + if( mpTheme ) + mpTheme->implDeregisterGalleryItem( *this ); +} + + +bool GalleryItem::isValid() const +{ + return( mpTheme != nullptr ); +} + + +uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType ) +{ + uno::Any aAny; + + if( rType == cppu::UnoType<lang::XServiceInfo>::get()) + aAny <<= uno::Reference< lang::XServiceInfo >(this); + else if( rType == cppu::UnoType<lang::XTypeProvider>::get()) + aAny <<= uno::Reference< lang::XTypeProvider >(this); + else if( rType == cppu::UnoType<gallery::XGalleryItem>::get()) + aAny <<= uno::Reference< gallery::XGalleryItem >(this); + else if( rType == cppu::UnoType<beans::XPropertySet>::get()) + aAny <<= uno::Reference< beans::XPropertySet >(this); + else if( rType == cppu::UnoType<beans::XPropertyState>::get()) + aAny <<= uno::Reference< beans::XPropertyState >(this); + else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get()) + aAny <<= uno::Reference< beans::XMultiPropertySet >(this); + else + aAny = OWeakAggObject::queryAggregation( rType ); + + return aAny; +} + + +uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType ) +{ + return OWeakAggObject::queryInterface( rType ); +} + + +void SAL_CALL GalleryItem::acquire() + noexcept +{ + OWeakAggObject::acquire(); +} + + +void SAL_CALL GalleryItem::release() + noexcept +{ + OWeakAggObject::release(); +} + + +OUString SAL_CALL GalleryItem::getImplementationName() +{ + return "com.sun.star.comp.gallery.GalleryItem"; +} + +sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames() +{ + return { "com.sun.star.gallery.GalleryItem" }; +} + +uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes() +{ + static const uno::Sequence aTypes { + cppu::UnoType<lang::XServiceInfo>::get(), + cppu::UnoType<lang::XTypeProvider>::get(), + cppu::UnoType<gallery::XGalleryItem>::get(), + cppu::UnoType<beans::XPropertySet>::get(), + cppu::UnoType<beans::XPropertyState>::get(), + cppu::UnoType<beans::XMultiPropertySet>::get() }; + return aTypes; +} + +uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + + +sal_Int8 SAL_CALL GalleryItem::getType() +{ + const SolarMutexGuard aGuard; + sal_Int8 nRet = gallery::GalleryItemType::EMPTY; + + if( isValid() ) + { + switch( implGetObject()->eObjKind ) + { + case SgaObjKind::Sound: + nRet = gallery::GalleryItemType::MEDIA; + break; + + case SgaObjKind::SvDraw: + nRet = gallery::GalleryItemType::DRAWING; + break; + + default: + nRet = gallery::GalleryItemType::GRAPHIC; + break; + } + } + + return nRet; +} + + +rtl::Reference<::comphelper::PropertySetInfo> GalleryItem::createPropertySetInfo() +{ + static ::comphelper::PropertyMapEntry const aEntries[] = + { + { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(), + beans::PropertyAttribute::READONLY, 0 }, + + { OUString("URL"), UNOGALLERY_URL, ::cppu::UnoType<OUString>::get(), + beans::PropertyAttribute::READONLY, 0 }, + + { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(), + 0, 0 }, + + { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL, cppu::UnoType<graphic::XGraphic>::get(), + beans::PropertyAttribute::READONLY, 0 }, + + { OUString("Graphic"), UNOGALLERY_GRAPHIC, cppu::UnoType<graphic::XGraphic>::get(), + beans::PropertyAttribute::READONLY, 0 }, + + { OUString("Drawing"), UNOGALLERY_DRAWING, cppu::UnoType<lang::XComponent>::get(), + beans::PropertyAttribute::READONLY, 0 }, + }; + + return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) ); +} + +void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues ) +{ + const SolarMutexGuard aGuard; + + while( *ppEntries ) + { + if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle ) + { + OUString aNewTitle; + + if( !(*pValues >>= aNewTitle) ) + { + throw lang::IllegalArgumentException(); + } + + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + + if( pGalTheme ) + { + std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryStorageEngine()->implReadSgaObject( implGetObject() )); + + if( pObj ) + { + if( pObj->GetTitle() != aNewTitle ) + { + pObj->SetTitle( aNewTitle ); + pGalTheme->InsertObject( *pObj ); + } + } + } + + } + + ++ppEntries; + ++pValues; + } +} + +void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue ) +{ + const SolarMutexGuard aGuard; + + while( *ppEntries ) + { + switch( (*ppEntries)->mnHandle ) + { + case UNOGALLERY_GALLERYITEMTYPE: + { + *pValue <<= getType(); + } + break; + + case UNOGALLERY_URL: + { + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + + if( pGalTheme ) + *pValue <<= implGetObject()->getURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ); + } + break; + + case UNOGALLERY_TITLE: + { + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + + if( pGalTheme ) + { + std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) ); + + if( pObj ) + { + *pValue <<= pObj->GetTitle(); + } + } + } + break; + + case UNOGALLERY_THUMBNAIL: + { + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + + if( pGalTheme ) + { + std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) ); + + if( pObj ) + { + Graphic aThumbnail; + + if( pObj->IsThumbBitmap() ) + aThumbnail = pObj->GetThumbBmp(); + else + aThumbnail = pObj->GetThumbMtf(); + + *pValue <<= aThumbnail.GetXGraphic(); + } + } + } + break; + + case UNOGALLERY_GRAPHIC: + { + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + Graphic aGraphic; + + if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) ) + *pValue <<= aGraphic.GetXGraphic(); + } + break; + + case UNOGALLERY_DRAWING: + { + if( gallery::GalleryItemType::DRAWING == getType() ) + { + ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); + FmFormModel* pModel = new FmFormModel(); + + pModel->GetItemPool().FreezeIdRanges(); + + if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) ) + { + uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) ); + + pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) ); + *pValue <<= xDrawing; + } + else + delete pModel; + } + } + break; + } + + ++ppEntries; + ++pValue; + } +} + + +void GalleryItem::implSetInvalid() +{ + if( mpTheme ) + { + mpTheme = nullptr; + mpGalleryObject = nullptr; + } +} + + +GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc ) + noexcept : + SvxUnoDrawingModel( pDoc ) +{ +} + + +GalleryDrawingModel::~GalleryDrawingModel() + noexcept +{ + delete GetDoc(); +} + + +UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel ); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unogallery/unogalitem.hxx b/svx/source/unogallery/unogalitem.hxx new file mode 100644 index 000000000..42bc0ba60 --- /dev/null +++ b/svx/source/unogallery/unogalitem.hxx @@ -0,0 +1,104 @@ +/* -*- 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_SVX_SOURCE_UNOGALLERY_UNOGALITEM_HXX +#define INCLUDED_SVX_SOURCE_UNOGALLERY_UNOGALITEM_HXX + +#include <svx/unomodel.hxx> +#include <comphelper/servicehelper.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/gallery/XGalleryItem.hpp> +#include <comphelper/propertysethelper.hxx> +#include <comphelper/propertysetinfo.hxx> +#include <cppuhelper/weakagg.hxx> + +class GalleryTheme; +struct GalleryObject; +namespace unogallery { class GalleryTheme; } + +namespace unogallery { + + +class GalleryItem final : public ::cppu::OWeakAggObject, + public css::lang::XServiceInfo, + public css::lang::XTypeProvider, + public css::gallery::XGalleryItem, + public ::comphelper::PropertySetHelper +{ + friend class ::unogallery::GalleryTheme; + +public: + + GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ); + virtual ~GalleryItem() noexcept override; + + bool isValid() const; + +private: + + // XInterface + virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type & rType ) override; + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; + + // XGalleryItem + virtual ::sal_Int8 SAL_CALL getType( ) override; + + // PropertySetHelper + virtual void _setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const css::uno::Any* pValues ) override; + virtual void _getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, css::uno::Any* pValue ) override; + + static rtl::Reference<::comphelper::PropertySetInfo> createPropertySetInfo(); + + const ::GalleryObject* implGetObject() const { return mpGalleryObject;} + void implSetInvalid(); + + GalleryItem( const GalleryItem& ) = delete; + GalleryItem& operator=( const GalleryItem& ) = delete; + + ::unogallery::GalleryTheme* mpTheme; + const ::GalleryObject* mpGalleryObject; +}; + + +class GalleryDrawingModel : public SvxUnoDrawingModel +{ +public: + + explicit GalleryDrawingModel( SdrModel* pDoc ) noexcept; + virtual ~GalleryDrawingModel() noexcept override; + + UNO3_GETIMPLEMENTATION_DECL( GalleryDrawingModel ) +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unogallery/unogaltheme.cxx b/svx/source/unogallery/unogaltheme.cxx new file mode 100644 index 000000000..b40cbc365 --- /dev/null +++ b/svx/source/unogallery/unogaltheme.cxx @@ -0,0 +1,362 @@ +/* -*- 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 <algorithm> + +#include "unogaltheme.hxx" +#include "unogalitem.hxx" +#include <svx/galtheme.hxx> +#include <svx/gallery1.hxx> +#include <svx/galmisc.hxx> +#include <svx/fmmodel.hxx> +#include <svx/svdpage.hxx> +#include <svx/unopage.hxx> +#include <vcl/svapp.hxx> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <cppuhelper/supportsservice.hxx> + +using namespace ::com::sun::star; + +namespace unogallery { + + +GalleryTheme::GalleryTheme( std::u16string_view rThemeName ) +{ + mpGallery = ::Gallery::GetGalleryInstance(); + mpTheme = ( mpGallery ? mpGallery->AcquireTheme( rThemeName, *this ) : nullptr ); + + if( mpGallery ) + StartListening( *mpGallery ); +} + + +GalleryTheme::~GalleryTheme() +{ + const SolarMutexGuard aGuard; + + DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" ); + + implReleaseItems( nullptr ); + + if( mpGallery ) + { + EndListening( *mpGallery ); + + if( mpTheme ) + mpGallery->ReleaseTheme( mpTheme, *this ); + } +} + + +OUString SAL_CALL GalleryTheme::getImplementationName() +{ + return "com.sun.star.comp.gallery.GalleryTheme"; +} + +sal_Bool SAL_CALL GalleryTheme::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService( this, ServiceName ); +} + +uno::Sequence< OUString > SAL_CALL GalleryTheme::getSupportedServiceNames() +{ + return { "com.sun.star.gallery.GalleryTheme" }; +} + +uno::Sequence< uno::Type > SAL_CALL GalleryTheme::getTypes() +{ + static const uno::Sequence aTypes { + cppu::UnoType<lang::XServiceInfo>::get(), + cppu::UnoType<lang::XTypeProvider>::get(), + cppu::UnoType<container::XElementAccess>::get(), + cppu::UnoType<container::XIndexAccess>::get(), + cppu::UnoType<gallery::XGalleryTheme>::get(), + }; + return aTypes; +} + +uno::Sequence< sal_Int8 > SAL_CALL GalleryTheme::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + + +uno::Type SAL_CALL GalleryTheme::getElementType() +{ + return cppu::UnoType<gallery::XGalleryItem>::get(); +} + + +sal_Bool SAL_CALL GalleryTheme::hasElements() +{ + const SolarMutexGuard aGuard; + + return( ( mpTheme != nullptr ) && ( mpTheme->GetObjectCount() > 0 ) ); +} + + +sal_Int32 SAL_CALL GalleryTheme::getCount() +{ + const SolarMutexGuard aGuard; + + return( mpTheme ? mpTheme->GetObjectCount() : 0 ); +} + + +uno::Any SAL_CALL GalleryTheme::getByIndex( ::sal_Int32 nIndex ) +{ + const SolarMutexGuard aGuard; + uno::Any aRet; + + if( mpTheme ) + { + if( ( nIndex < 0 ) || ( nIndex >= getCount() ) ) + { + throw lang::IndexOutOfBoundsException(); + } + const GalleryObject* pObj = mpTheme->maGalleryObjectCollection.getForPosition( nIndex ); + + if( pObj ) + aRet <<= uno::Reference< gallery::XGalleryItem >( new GalleryItem( *this, *pObj ) ); + } + + return aRet; +} + + +OUString SAL_CALL GalleryTheme::getName( ) +{ + const SolarMutexGuard aGuard; + OUString aRet; + + if( mpTheme ) + aRet = mpTheme->GetName(); + + return aRet; +} + + +void SAL_CALL GalleryTheme::update( ) +{ + const SolarMutexGuard aGuard; + + if( mpTheme ) + { + const Link<const INetURLObject&, void> aDummyLink; + mpTheme->Actualize( aDummyLink ); + } +} + + +::sal_Int32 SAL_CALL GalleryTheme::insertURLByIndex( + const OUString& rURL, ::sal_Int32 nIndex ) +{ + const SolarMutexGuard aGuard; + sal_Int32 nRet = -1; + + if( mpTheme ) + { + try + { + const INetURLObject aURL( rURL ); + + nIndex = std::clamp( nIndex, sal_Int32(0), getCount() ); + + if( ( aURL.GetProtocol() != INetProtocol::NotValid ) && mpTheme->InsertURL( aURL, nIndex ) ) + { + const GalleryObject* pObj = mpTheme->maGalleryObjectCollection.searchObjectWithURL( aURL ); + + if( pObj ) + nRet = mpTheme->maGalleryObjectCollection.searchPosWithObject( pObj ); + } + } + catch( ... ) + { + } + } + + return nRet; +} + + +::sal_Int32 SAL_CALL GalleryTheme::insertGraphicByIndex( + const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nIndex ) +{ + const SolarMutexGuard aGuard; + sal_Int32 nRet = -1; + + if( mpTheme ) + { + try + { + const Graphic aGraphic( rxGraphic ); + + nIndex = std::clamp( nIndex, sal_Int32(0), getCount() ); + + if( mpTheme->InsertGraphic( aGraphic, nIndex ) ) + nRet = nIndex; + } + catch( ... ) + { + } + } + + return nRet; +} + + +::sal_Int32 SAL_CALL GalleryTheme::insertDrawingByIndex( + const uno::Reference< lang::XComponent >& Drawing, sal_Int32 nIndex ) +{ + const SolarMutexGuard aGuard; + sal_Int32 nRet = -1; + + if( mpTheme ) + { + GalleryDrawingModel* pModel = comphelper::getFromUnoTunnel<GalleryDrawingModel>( Drawing ); + + if( pModel && dynamic_cast<const FmFormModel*>(pModel->GetDoc()) ) + { + // Here we're inserting something that's already a gallery theme drawing + nIndex = std::clamp( nIndex, sal_Int32(0), getCount() ); + + if( mpTheme->InsertModel( *static_cast< FmFormModel* >( pModel->GetDoc() ), nIndex ) ) + nRet = nIndex; + } + else if (!pModel) + { + // #i80184# Try to do the right thing and make a Gallery drawing out + // of an ordinary Drawing if possible. + try + { + uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( Drawing, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_SET_THROW ); + uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + SvxDrawPage* pUnoPage = xPage.is() ? comphelper::getFromUnoTunnel<SvxDrawPage>( xPage ) : nullptr; + SdrModel* pOrigModel = pUnoPage ? &pUnoPage->GetSdrPage()->getSdrModelFromSdrPage() : nullptr; + SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : nullptr; + + if (pOrigPage && pOrigModel) + { + FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool()); + // Clone to new target SdrModel + rtl::Reference<SdrPage> pNewPage = pOrigPage->CloneSdrPage(*pTmpModel); + pTmpModel->InsertPage(pNewPage.get(), 0); + + uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) ); + pTmpModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) ); + + nRet = insertDrawingByIndex( xDrawing, nIndex ); + return nRet; + } + } + catch (...) + { + } + } + } + + return nRet; +} + + +void SAL_CALL GalleryTheme::removeByIndex( sal_Int32 nIndex ) +{ + const SolarMutexGuard aGuard; + + if( mpTheme ) + { + if( ( nIndex < 0 ) || ( nIndex >= getCount() ) ) + throw lang::IndexOutOfBoundsException(); + mpTheme->RemoveObject( nIndex ); + } +} + + +void GalleryTheme::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + const SolarMutexGuard aGuard; + const GalleryHint& rGalleryHint = static_cast< const GalleryHint& >( rHint ); + + switch( rGalleryHint.GetType() ) + { + case GalleryHintType::CLOSE_THEME: + { + DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" ); + + implReleaseItems( nullptr ); + + if( mpGallery && mpTheme ) + { + mpGallery->ReleaseTheme( mpTheme, *this ); + mpTheme = nullptr; + } + } + break; + + case GalleryHintType::CLOSE_OBJECT: + { + GalleryObject* pObj = static_cast< GalleryObject* >( rGalleryHint.GetData1() ); + + if( pObj ) + implReleaseItems( pObj ); + } + break; + + default: + break; + } +} + + +void GalleryTheme::implReleaseItems( GalleryObject const * pObj ) +{ + const SolarMutexGuard aGuard; + + for( GalleryItemVector::iterator aIter = maItemVector.begin(); aIter != maItemVector.end(); ) + { + if( !pObj || ( (*aIter)->implGetObject() == pObj ) ) + { + (*aIter)->implSetInvalid(); + aIter = maItemVector.erase( aIter ); + } + else + ++aIter; + } +} + + +void GalleryTheme::implRegisterGalleryItem( ::unogallery::GalleryItem& rItem ) +{ + const SolarMutexGuard aGuard; + + maItemVector.push_back( &rItem ); +} + + +void GalleryTheme::implDeregisterGalleryItem( ::unogallery::GalleryItem& rItem ) +{ + const SolarMutexGuard aGuard; + + maItemVector.erase(std::remove(maItemVector.begin(), maItemVector.end(), &rItem), maItemVector.end()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unogallery/unogaltheme.hxx b/svx/source/unogallery/unogaltheme.hxx new file mode 100644 index 000000000..31cde7003 --- /dev/null +++ b/svx/source/unogallery/unogaltheme.hxx @@ -0,0 +1,100 @@ +/* -*- 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_SVX_SOURCE_UNOGALLERY_UNOGALTHEME_HXX +#define INCLUDED_SVX_SOURCE_UNOGALLERY_UNOGALTHEME_HXX + +#include <vector> + +#include <cppuhelper/implbase.hxx> +#include <svl/lstner.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/gallery/XGalleryTheme.hpp> + +class Gallery; +class GalleryTheme; +struct GalleryObject; +namespace unogallery { class GalleryItem; } + +namespace unogallery { + + +class GalleryTheme : public ::cppu::WeakImplHelper< + css::gallery::XGalleryTheme, + css::lang::XServiceInfo >, + public SfxListener +{ + friend class ::unogallery::GalleryItem; + +public: + + explicit GalleryTheme( std::u16string_view rThemeName ); + virtual ~GalleryTheme() override; + +protected: + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() override; + virtual sal_Bool SAL_CALL hasElements() override; + + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) override; + virtual css::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override; + + // XGalleryThemes + virtual OUString SAL_CALL getName( ) override; + virtual void SAL_CALL update( ) override; + virtual ::sal_Int32 SAL_CALL insertURLByIndex( const OUString& URL, ::sal_Int32 Index ) override; + virtual ::sal_Int32 SAL_CALL insertGraphicByIndex( const css::uno::Reference< css::graphic::XGraphic >& Graphic, ::sal_Int32 Index ) override; + virtual ::sal_Int32 SAL_CALL insertDrawingByIndex( const css::uno::Reference< css::lang::XComponent >& Drawing, ::sal_Int32 Index ) override; + virtual void SAL_CALL removeByIndex( ::sal_Int32 Index ) override; + + // SfxListener + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; + +private: + + typedef ::std::vector< ::unogallery::GalleryItem* > GalleryItemVector; + + GalleryItemVector maItemVector; + ::Gallery* mpGallery; + ::GalleryTheme* mpTheme; + + ::GalleryTheme* implGetTheme() const { return mpTheme;} + + void implReleaseItems( GalleryObject const * pObj ); + + void implRegisterGalleryItem( ::unogallery::GalleryItem& rItem ); + void implDeregisterGalleryItem( ::unogallery::GalleryItem& rItem ); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unogallery/unogalthemeprovider.cxx b/svx/source/unogallery/unogalthemeprovider.cxx new file mode 100644 index 000000000..638406e4d --- /dev/null +++ b/svx/source/unogallery/unogalthemeprovider.cxx @@ -0,0 +1,247 @@ +/* -*- 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 <sal/config.h> + +#include "unogaltheme.hxx" +#include <svx/gallery1.hxx> +#include <vcl/svapp.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <com/sun/star/container/ElementExistException.hpp> +#include <com/sun/star/gallery/XGalleryTheme.hpp> +#include <com/sun/star/gallery/XGalleryThemeProvider.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +using namespace ::com::sun::star; + +namespace { + +class GalleryThemeProvider : public ::cppu::WeakImplHelper< css::lang::XInitialization, + css::gallery::XGalleryThemeProvider, + css::lang::XServiceInfo > +{ +public: + + GalleryThemeProvider(); + +protected: + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() override; + virtual sal_Bool SAL_CALL hasElements() override; + + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override; + virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + // XGalleryThemeProvider + virtual css::uno::Reference< css::gallery::XGalleryTheme > SAL_CALL insertNewByName( const OUString& ThemeName ) override; + virtual void SAL_CALL removeByName( const OUString& ThemeName ) override; + +private: + + Gallery* mpGallery; + bool mbHiddenThemes; +}; + +GalleryThemeProvider::GalleryThemeProvider() : + mbHiddenThemes( false ) +{ + mpGallery = ::Gallery::GetGalleryInstance(); +} + +OUString SAL_CALL GalleryThemeProvider::getImplementationName() +{ + return "com.sun.star.comp.gallery.GalleryThemeProvider"; +} + +sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService( this, ServiceName ); +} + +uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames() +{ + uno::Sequence<OUString> aSeq { "com.sun.star.gallery.GalleryThemeProvider" }; + return aSeq; +} + +uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes() +{ + static const uno::Sequence aTypes { + cppu::UnoType<lang::XServiceInfo>::get(), + cppu::UnoType<lang::XTypeProvider>::get(), + cppu::UnoType<lang::XInitialization>::get(), + cppu::UnoType<container::XElementAccess>::get(), + cppu::UnoType<container::XNameAccess>::get(), + cppu::UnoType<gallery::XGalleryThemeProvider>::get() }; + + return aTypes; +} + +uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + +void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments ) +{ + uno::Sequence< beans::PropertyValue > aParams; + + for( const auto& rArgument : rArguments ) + { + if( rArgument >>= aParams ) + break; + } + + for( const beans::PropertyValue& rProp : std::as_const(aParams) ) + { + if ( rProp.Name == "ProvideHiddenThemes" ) + rProp.Value >>= mbHiddenThemes; + } +} + + +uno::Type SAL_CALL GalleryThemeProvider::getElementType() +{ + return cppu::UnoType<gallery::XGalleryTheme>::get(); +} + + +sal_Bool SAL_CALL GalleryThemeProvider::hasElements() +{ + const SolarMutexGuard aGuard; + + return( ( mpGallery != nullptr ) && ( mpGallery->GetThemeCount() > 0 ) ); +} + + +uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName ) +{ + const SolarMutexGuard aGuard; + uno::Any aRet; + + if( !mpGallery || !mpGallery->HasTheme( rName ) ) + { + throw container::NoSuchElementException(); + } + + aRet <<= uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ); + + return aRet; +} + + +uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames() +{ + const SolarMutexGuard aGuard; + sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0; + uno::Sequence< OUString > aSeq( nCount ); + auto aSeqRange = asNonConstRange(aSeq); + + for( ; i < nCount; ++i ) + { + const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i ); + + if( mbHiddenThemes || !pEntry->IsHidden() ) + aSeqRange[ nRealCount++ ] = pEntry->GetThemeName(); + } + + aSeq.realloc( nRealCount ); + + return aSeq; +} + + +sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName ) +{ + const SolarMutexGuard aGuard; + + bool bRet = false; + + if( mpGallery && mpGallery->HasTheme( rName ) ) + bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() ); + + return bRet; +} + + +uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName ) +{ + const SolarMutexGuard aGuard; + uno::Reference< gallery::XGalleryTheme > xRet; + + if( mpGallery ) + { + if( mpGallery->HasTheme( rThemeName ) ) + { + throw container::ElementExistException(); + } + else if( mpGallery->CreateTheme( rThemeName ) ) + { + xRet = new ::unogallery::GalleryTheme( rThemeName ); + } + } + + return xRet; +} + + +void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName ) +{ + const SolarMutexGuard aGuard; + + if( !mpGallery || + !mpGallery->HasTheme( rName ) || + ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) ) + { + throw container::NoSuchElementException(); + } + + mpGallery->RemoveTheme( rName ); +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence<css::uno::Any> const &) +{ + return cppu::acquire(new GalleryThemeProvider); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |