| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 | * contributor license agreements. See the NOTICE file distributed |
| 13 | * with this work for additional information regarding copyright |
| 14 | * ownership. The ASF licenses this file to you under the Apache |
| 15 | * License, Version 2.0 (the "License"); you may not use this file |
| 16 | * except in compliance with the License. You may obtain a copy of |
| 17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 | */ |
| 19 | #pragma once |
| 20 | |
| 21 | #include <com/sun/star/drawing/XLayer.hpp> |
| 22 | #include <com/sun/star/drawing/XLayerManager.hpp> |
| 23 | |
| 24 | #include <cppuhelper/implbase.hxx> |
| 25 | #include <comphelper/servicehelper.hxx> |
| 26 | #include <rtl/ref.hxx> |
| 27 | |
| 28 | #include "unomodel.hxx" |
| 29 | |
| 30 | class SdrLayer; |
| 31 | class SdLayerManager; |
| 32 | class SvUnoWeakContainer; |
| 33 | |
| 34 | namespace sd { |
| 35 | class View; |
| 36 | } |
| 37 | enum LayerAttribute { VISIBLE, PRINTABLE, LOCKED }; |
| 38 | |
| 39 | /*********************************************************************** |
| 40 | * * |
| 41 | ***********************************************************************/ |
| 42 | class SdLayer final : public ::cppu::WeakImplHelper< css::drawing::XLayer, |
| 43 | css::lang::XServiceInfo, |
| 44 | css::container::XChild, |
| 45 | css::lang::XComponent > |
| 46 | { |
| 47 | public: |
| 48 | SdLayer(SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_); |
| 49 | virtual ~SdLayer() noexcept override; |
| 50 | |
| 51 | // internal |
| 52 | SdrLayer* GetSdrLayer() const noexcept { return pLayer; } |
| 53 | |
| 54 | // XServiceInfo |
| 55 | virtual OUString SAL_CALL getImplementationName() override; |
| 56 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
| 57 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
| 58 | |
| 59 | // css::beans::XPropertySet |
| 60 | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
| 61 | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; |
| 62 | virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
| 63 | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; |
| 64 | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; |
| 65 | virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
| 66 | virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
| 67 | |
| 68 | // css::container::XChild |
| 69 | |
| 70 | /** Returns the layer manager that manages this layer. |
| 71 | */ |
| 72 | virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override; |
| 73 | |
| 74 | // XComponent |
| 75 | virtual void SAL_CALL dispose( ) override; |
| 76 | virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override; |
| 77 | virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override; |
| 78 | |
| 79 | /** Not implemented. Always throws an exception. |
| 80 | @throws NoSupportException. |
| 81 | */ |
| 82 | virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override; |
| 83 | |
| 84 | private: |
| 85 | rtl::Reference<SdLayerManager> mxLayerManager; |
| 86 | SdrLayer* pLayer; |
| 87 | const SvxItemPropertySet* pPropSet; |
| 88 | |
| 89 | bool get( LayerAttribute what ) noexcept; |
| 90 | void set( LayerAttribute what, bool flag ) noexcept; |
| 91 | |
| 92 | }; |
| 93 | |
| 94 | /*********************************************************************** |
| 95 | * * |
| 96 | ***********************************************************************/ |
| 97 | |
| 98 | class SdLayerManager final : public ::cppu::WeakImplHelper< css::drawing::XLayerManager, |
| 99 | css::container::XNameAccess, |
| 100 | css::lang::XServiceInfo, |
| 101 | css::lang::XComponent > |
| 102 | { |
| 103 | friend class SdLayer; |
| 104 | |
| 105 | public: |
| 106 | explicit SdLayerManager( SdXImpressDocument& rMyModel ) noexcept; |
| 107 | virtual ~SdLayerManager() noexcept override; |
| 108 | |
| 109 | // XServiceInfo |
| 110 | virtual OUString SAL_CALL getImplementationName() override; |
| 111 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
| 112 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
| 113 | |
| 114 | // XLayerManager |
| 115 | virtual css::uno::Reference< css::drawing::XLayer > SAL_CALL insertNewByIndex( sal_Int32 nIndex ) override; |
| 116 | virtual void SAL_CALL remove( const css::uno::Reference< css::drawing::XLayer >& xLayer ) override; |
| 117 | virtual void SAL_CALL attachShapeToLayer( const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XLayer >& xLayer ) override; |
| 118 | virtual css::uno::Reference< css::drawing::XLayer > SAL_CALL getLayerForShape( const css::uno::Reference< css::drawing::XShape >& xShape ) override; |
| 119 | |
| 120 | // XIndexAccess |
| 121 | virtual sal_Int32 SAL_CALL getCount() override ; |
| 122 | virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
| 123 | |
| 124 | // XNameAccess |
| 125 | virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override; |
| 126 | virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override; |
| 127 | virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; |
| 128 | |
| 129 | // XElementAccess |
| 130 | virtual css::uno::Type SAL_CALL getElementType() override; |
| 131 | virtual sal_Bool SAL_CALL hasElements() override; |
| 132 | |
| 133 | /** Return the <type>XLayer</type> object that is associated with the |
| 134 | given <type>SdrLayer</type> object. If the requested object does |
| 135 | not yet exist it is created. All calls with the same argument |
| 136 | return the same object. |
| 137 | @param pLayer |
| 138 | The <type>SdrLayer</type> object for which to return the |
| 139 | associated <type>XLayer</type> object. |
| 140 | @return |
| 141 | The returned value is the unique <type>XLayer</type> object |
| 142 | associated with the specified argument. If no layer can be |
| 143 | created for the argument than an empty reference is returned. |
| 144 | */ |
| 145 | rtl::Reference<SdLayer> GetLayer (SdrLayer* pLayer); |
| 146 | |
| 147 | // XComponent |
| 148 | virtual void SAL_CALL dispose( ) override; |
| 149 | virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override; |
| 150 | virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override; |
| 151 | |
| 152 | private: |
| 153 | SdXImpressDocument* mpModel; |
| 154 | std::unique_ptr<SvUnoWeakContainer> mpLayers; |
| 155 | |
| 156 | ::sd::View* GetView() const noexcept; |
| 157 | ::sd::DrawDocShell* GetDocShell() const noexcept { return mpModel->mpDocShell; } |
| 158 | void UpdateLayerView() const noexcept; |
| 159 | }; |
| 160 | |
| 161 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |