LCOV - code coverage report
Current view: top level - sd/source/core/annotations - Annotation.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 162 0.0 %
Date: 2014-04-14 Functions: 0 43 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : 
      21             : #include "osl/time.h"
      22             : #include "sal/config.h"
      23             : 
      24             : #include <com/sun/star/uno/XComponentContext.hpp>
      25             : #include <com/sun/star/office/XAnnotation.hpp>
      26             : #include <com/sun/star/drawing/XDrawPage.hpp>
      27             : 
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <cppuhelper/propertysetmixin.hxx>
      30             : #include <cppuhelper/compbase1.hxx>
      31             : #include <cppuhelper/basemutex.hxx>
      32             : 
      33             : #include "drawdoc.hxx"
      34             : #include "sdpage.hxx"
      35             : #include "textapi.hxx"
      36             : 
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::office;
      41             : using namespace ::com::sun::star::drawing;
      42             : using namespace ::com::sun::star::geometry;
      43             : using namespace ::com::sun::star::text;
      44             : using namespace ::com::sun::star::util;
      45             : using namespace ::com::sun::star;
      46             : 
      47             : extern void NotifyDocumentEvent( SdDrawDocument* pDocument, const OUString& rEventName, const Reference< XInterface >& xSource );
      48             : 
      49             : namespace sd {
      50             : 
      51           0 : class Annotation : private ::cppu::BaseMutex,
      52             :                    public ::cppu::WeakComponentImplHelper1< XAnnotation>,
      53             :                    public ::cppu::PropertySetMixin< XAnnotation >
      54             : {
      55             : public:
      56             :     explicit Annotation( const Reference< XComponentContext >& context, SdPage* pPage );
      57             : 
      58           0 :     SdPage* GetPage() const { return mpPage; }
      59           0 :     SdrModel* GetModel() { return (mpPage != 0) ? mpPage->GetModel() : 0; }
      60             : 
      61             :     // XInterface:
      62             :     virtual Any SAL_CALL queryInterface(Type const & type) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      63           0 :     virtual void SAL_CALL acquire() throw () SAL_OVERRIDE { ::cppu::WeakComponentImplHelper1< XAnnotation >::acquire(); }
      64           0 :     virtual void SAL_CALL release() throw () SAL_OVERRIDE { ::cppu::WeakComponentImplHelper1< XAnnotation >::release(); }
      65             : 
      66             :     // ::com::sun::star::beans::XPropertySet:
      67             :     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      68             :     virtual void SAL_CALL setPropertyValue(const OUString & aPropertyName, const Any & aValue) throw (RuntimeException, UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      69             :     virtual Any SAL_CALL getPropertyValue(const OUString & PropertyName) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      70             :     virtual void SAL_CALL addPropertyChangeListener(const OUString & aPropertyName, const Reference< XPropertyChangeListener > & xListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      71             :     virtual void SAL_CALL removePropertyChangeListener(const OUString & aPropertyName, const Reference< XPropertyChangeListener > & aListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      72             :     virtual void SAL_CALL addVetoableChangeListener(const OUString & PropertyName, const Reference< XVetoableChangeListener > & aListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      73             :     virtual void SAL_CALL removeVetoableChangeListener(const OUString & PropertyName, const Reference< XVetoableChangeListener > & aListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception) SAL_OVERRIDE;
      74             : 
      75             :     // ::com::sun::star::office::XAnnotation:
      76             :     virtual ::com::sun::star::uno::Any SAL_CALL getAnchor() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual RealPoint2D SAL_CALL getPosition() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      78             :     virtual void SAL_CALL setPosition(const RealPoint2D & the_value) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      79             :     virtual ::com::sun::star::geometry::RealSize2D SAL_CALL getSize() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      80             :     virtual void SAL_CALL setSize( const ::com::sun::star::geometry::RealSize2D& _size ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      81             :     virtual OUString SAL_CALL getAuthor() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      82             :     virtual void SAL_CALL setAuthor(const OUString & the_value) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      83             :     virtual util::DateTime SAL_CALL getDateTime() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      84             :     virtual void SAL_CALL setDateTime(const util::DateTime & the_value) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      85             :     virtual Reference< XText > SAL_CALL getTextRange() throw (RuntimeException, std::exception) SAL_OVERRIDE;
      86             : 
      87             : private:
      88             :     Annotation(const Annotation &); // not defined
      89             :     Annotation& operator=(const Annotation &); // not defined
      90             : 
      91             :     // destructor is private and will be called indirectly by the release call    virtual ~Annotation() {}
      92             : 
      93             :     void createChangeUndo();
      94             : 
      95             :     // overload WeakComponentImplHelperBase::disposing()
      96             :     // This function is called upon disposing the component,
      97             :     // if your component needs special work when it becomes
      98             :     // disposed, do it here.
      99             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     100             : 
     101             :     SdPage* mpPage;
     102             :     Reference< XComponentContext > m_xContext;
     103             :     mutable ::osl::Mutex m_aMutex;
     104             :     RealPoint2D m_Position;
     105             :     RealSize2D m_Size;
     106             :     OUString m_Author;
     107             :     util::DateTime m_DateTime;
     108             :     rtl::Reference< TextApiObject > m_TextRange;
     109             : };
     110             : 
     111           0 : class UndoInsertOrRemoveAnnotation : public SdrUndoAction
     112             : {
     113             : public:
     114             :     UndoInsertOrRemoveAnnotation( Annotation& rAnnotation, bool bInsert );
     115             : 
     116             :     virtual void Undo() SAL_OVERRIDE;
     117             :     virtual void Redo() SAL_OVERRIDE;
     118             : 
     119             : protected:
     120             :     rtl::Reference< Annotation > mxAnnotation;
     121             :     bool mbInsert;
     122             :     int mnIndex;
     123             : };
     124             : 
     125           0 : struct AnnotationData
     126             : {
     127             :     RealPoint2D m_Position;
     128             :     RealSize2D m_Size;
     129             :     OUString m_Author;
     130             :     util::DateTime m_DateTime;
     131             : 
     132           0 :     void get( const rtl::Reference< Annotation >& xAnnotation )
     133             :     {
     134           0 :         m_Position = xAnnotation->getPosition();
     135           0 :         m_Size = xAnnotation->getSize();
     136           0 :         m_Author = xAnnotation->getAuthor();
     137           0 :         m_DateTime = xAnnotation->getDateTime();
     138           0 :     }
     139             : 
     140           0 :     void set( const rtl::Reference< Annotation >& xAnnotation )
     141             :     {
     142           0 :         xAnnotation->setPosition(m_Position);
     143           0 :         xAnnotation->setSize(m_Size);
     144           0 :         xAnnotation->setAuthor(m_Author);
     145           0 :         xAnnotation->setDateTime(m_DateTime);
     146           0 :     }
     147             : };
     148             : 
     149           0 : class UndoAnnotation : public SdrUndoAction
     150             : {
     151             : public:
     152             :     UndoAnnotation( Annotation& rAnnotation );
     153             : 
     154             :     virtual void Undo() SAL_OVERRIDE;
     155             :     virtual void Redo() SAL_OVERRIDE;
     156             : 
     157             : protected:
     158             :     rtl::Reference< Annotation > mxAnnotation;
     159             :     AnnotationData maUndoData;
     160             :     AnnotationData maRedoData;
     161             : };
     162             : 
     163           0 : void createAnnotation( Reference< XAnnotation >& xAnnotation, SdPage* pPage )
     164             : {
     165             :     xAnnotation.set(
     166           0 :         new Annotation(comphelper::getProcessComponentContext(), pPage));
     167           0 :     pPage->addAnnotation(xAnnotation);
     168           0 : }
     169             : 
     170           0 : Annotation::Annotation( const Reference< XComponentContext >& context, SdPage* pPage )
     171             : : ::cppu::WeakComponentImplHelper1< XAnnotation >(m_aMutex)
     172             : , ::cppu::PropertySetMixin< XAnnotation >(context, static_cast< Implements >(IMPLEMENTS_PROPERTY_SET), Sequence< OUString >())
     173           0 : , mpPage( pPage )
     174             : {
     175           0 : }
     176             : 
     177             : // overload WeakComponentImplHelperBase::disposing()
     178             : // This function is called upon disposing the component,
     179             : // if your component needs special work when it becomes
     180             : // disposed, do it here.
     181           0 : void SAL_CALL Annotation::disposing()
     182             : {
     183           0 :     mpPage = 0;
     184           0 :     if( m_TextRange.is() )
     185             :     {
     186           0 :         m_TextRange->dispose();
     187           0 :         m_TextRange.clear();
     188             :     }
     189           0 : }
     190             : 
     191           0 : Any Annotation::queryInterface(Type const & type) throw (RuntimeException, std::exception)
     192             : {
     193           0 :     return ::cppu::WeakComponentImplHelper1< XAnnotation>::queryInterface(type);
     194             : }
     195             : 
     196             : // com.sun.star.beans.XPropertySet:
     197           0 : Reference< XPropertySetInfo > SAL_CALL Annotation::getPropertySetInfo() throw (RuntimeException, std::exception)
     198             : {
     199           0 :     return ::cppu::PropertySetMixin< XAnnotation >::getPropertySetInfo();
     200             : }
     201             : 
     202           0 : void SAL_CALL Annotation::setPropertyValue(const OUString & aPropertyName, const Any & aValue) throw (RuntimeException, UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, std::exception)
     203             : {
     204           0 :     ::cppu::PropertySetMixin< XAnnotation >::setPropertyValue(aPropertyName, aValue);
     205           0 : }
     206             : 
     207           0 : Any SAL_CALL Annotation::getPropertyValue(const OUString & aPropertyName) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
     208             : {
     209           0 :     return ::cppu::PropertySetMixin< XAnnotation >::getPropertyValue(aPropertyName);
     210             : }
     211             : 
     212           0 : void SAL_CALL Annotation::addPropertyChangeListener(const OUString & aPropertyName, const Reference< XPropertyChangeListener > & xListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
     213             : {
     214           0 :     ::cppu::PropertySetMixin< XAnnotation >::addPropertyChangeListener(aPropertyName, xListener);
     215           0 : }
     216             : 
     217           0 : void SAL_CALL Annotation::removePropertyChangeListener(const OUString & aPropertyName, const Reference< XPropertyChangeListener > & xListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
     218             : {
     219           0 :     ::cppu::PropertySetMixin< XAnnotation >::removePropertyChangeListener(aPropertyName, xListener);
     220           0 : }
     221             : 
     222           0 : void SAL_CALL Annotation::addVetoableChangeListener(const OUString & aPropertyName, const Reference< XVetoableChangeListener > & xListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
     223             : {
     224           0 :     ::cppu::PropertySetMixin< XAnnotation >::addVetoableChangeListener(aPropertyName, xListener);
     225           0 : }
     226             : 
     227           0 : void SAL_CALL Annotation::removeVetoableChangeListener(const OUString & aPropertyName, const Reference< XVetoableChangeListener > & xListener) throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
     228             : {
     229           0 :     ::cppu::PropertySetMixin< XAnnotation >::removeVetoableChangeListener(aPropertyName, xListener);
     230           0 : }
     231             : 
     232           0 : Any SAL_CALL Annotation::getAnchor() throw (RuntimeException, std::exception)
     233             : {
     234           0 :     osl::MutexGuard g(m_aMutex);
     235           0 :     Any aRet;
     236           0 :     if( mpPage )
     237             :     {
     238           0 :         Reference< XDrawPage > xPage( mpPage->getUnoPage(), UNO_QUERY );
     239           0 :         aRet <<= xPage;
     240             :     }
     241           0 :     return aRet;
     242             : }
     243             : 
     244             : // ::com::sun::star::office::XAnnotation:
     245           0 : RealPoint2D SAL_CALL Annotation::getPosition() throw (RuntimeException, std::exception)
     246             : {
     247           0 :     osl::MutexGuard g(m_aMutex);
     248           0 :     return m_Position;
     249             : }
     250             : 
     251           0 : void SAL_CALL Annotation::setPosition(const RealPoint2D & the_value) throw (RuntimeException, std::exception)
     252             : {
     253           0 :     prepareSet("Position", Any(), Any(), 0);
     254             :     {
     255           0 :         osl::MutexGuard g(m_aMutex);
     256           0 :         createChangeUndo();
     257           0 :         m_Position = the_value;
     258             :     }
     259           0 : }
     260             : 
     261             : // ::com::sun::star::office::XAnnotation:
     262           0 : RealSize2D SAL_CALL Annotation::getSize() throw (RuntimeException, std::exception)
     263             : {
     264           0 :     osl::MutexGuard g(m_aMutex);
     265           0 :     return m_Size;
     266             : }
     267             : 
     268           0 : void SAL_CALL Annotation::setSize(const RealSize2D & the_value) throw (RuntimeException, std::exception)
     269             : {
     270           0 :     prepareSet("Size", Any(), Any(), 0);
     271             :     {
     272           0 :         osl::MutexGuard g(m_aMutex);
     273           0 :         createChangeUndo();
     274           0 :         m_Size = the_value;
     275             :     }
     276           0 : }
     277             : 
     278           0 : OUString SAL_CALL Annotation::getAuthor() throw (RuntimeException, std::exception)
     279             : {
     280           0 :     osl::MutexGuard g(m_aMutex);
     281           0 :     return m_Author;
     282             : }
     283             : 
     284           0 : void SAL_CALL Annotation::setAuthor(const OUString & the_value) throw (RuntimeException, std::exception)
     285             : {
     286           0 :     prepareSet("Author", Any(), Any(), 0);
     287             :     {
     288           0 :         osl::MutexGuard g(m_aMutex);
     289           0 :         createChangeUndo();
     290           0 :         m_Author = the_value;
     291             :     }
     292           0 : }
     293             : 
     294           0 : util::DateTime SAL_CALL Annotation::getDateTime() throw (RuntimeException, std::exception)
     295             : {
     296           0 :     osl::MutexGuard g(m_aMutex);
     297           0 :     return m_DateTime;
     298             : }
     299             : 
     300           0 : void SAL_CALL Annotation::setDateTime(const util::DateTime & the_value) throw (RuntimeException, std::exception)
     301             : {
     302           0 :     prepareSet("DateTime", Any(), Any(), 0);
     303             :     {
     304           0 :         osl::MutexGuard g(m_aMutex);
     305           0 :         createChangeUndo();
     306           0 :         m_DateTime = the_value;
     307             :     }
     308           0 : }
     309             : 
     310           0 : void Annotation::createChangeUndo()
     311             : {
     312           0 :     SdrModel* pModel = GetModel();
     313           0 :     if( pModel && pModel->IsUndoEnabled() )
     314           0 :         pModel->AddUndo( new UndoAnnotation( *this ) );
     315             : 
     316           0 :     if( pModel )
     317             :     {
     318           0 :         pModel->SetChanged();
     319           0 :         Reference< XInterface > xSource( static_cast<uno::XWeak*>( this ) );
     320           0 :         NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), "OnAnnotationChanged" , xSource );
     321             :     }
     322           0 : }
     323             : 
     324           0 : Reference< XText > SAL_CALL Annotation::getTextRange() throw (RuntimeException, std::exception)
     325             : {
     326           0 :     osl::MutexGuard g(m_aMutex);
     327           0 :     if( !m_TextRange.is() && (mpPage != 0) )
     328             :     {
     329           0 :         m_TextRange = TextApiObject::create( static_cast< SdDrawDocument* >( mpPage->GetModel() ) );
     330             :     }
     331           0 :     return Reference< XText >( m_TextRange.get() );
     332             : }
     333             : 
     334           0 : SdrUndoAction* CreateUndoInsertOrRemoveAnnotation( const Reference< XAnnotation >& xAnnotation, bool bInsert )
     335             : {
     336           0 :     Annotation* pAnnotation = dynamic_cast< Annotation* >( xAnnotation.get() );
     337           0 :     if( pAnnotation )
     338             :     {
     339           0 :         return new UndoInsertOrRemoveAnnotation( *pAnnotation, bInsert );
     340             :     }
     341             :     else
     342             :     {
     343           0 :         return 0;
     344             :     }
     345             : }
     346             : 
     347           0 : UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation( Annotation& rAnnotation, bool bInsert )
     348           0 : : SdrUndoAction( *rAnnotation.GetModel() )
     349             : , mxAnnotation( &rAnnotation )
     350             : , mbInsert( bInsert )
     351           0 : , mnIndex( 0 )
     352             : {
     353           0 :     SdPage* pPage = rAnnotation.GetPage();
     354           0 :     if( pPage )
     355             :     {
     356           0 :         Reference< XAnnotation > xAnnotation( &rAnnotation );
     357             : 
     358           0 :         const AnnotationVector& rVec = pPage->getAnnotations();
     359           0 :         for( AnnotationVector::const_iterator iter = rVec.begin(); iter != rVec.end(); ++iter )
     360             :         {
     361           0 :             if( (*iter) == xAnnotation )
     362           0 :                 break;
     363             : 
     364           0 :             mnIndex++;
     365           0 :         }
     366             :     }
     367           0 : }
     368             : 
     369           0 : void UndoInsertOrRemoveAnnotation::Undo()
     370             : {
     371           0 :     SdPage* pPage = mxAnnotation->GetPage();
     372           0 :     SdrModel* pModel = mxAnnotation->GetModel();
     373           0 :     if( pPage && pModel )
     374             :     {
     375           0 :         Reference< XAnnotation > xAnnotation( mxAnnotation.get() );
     376           0 :         if( mbInsert )
     377             :         {
     378           0 :             pPage->removeAnnotation( xAnnotation );
     379             :         }
     380             :         else
     381             :         {
     382           0 :             pPage->addAnnotation( xAnnotation, mnIndex );
     383           0 :         }
     384             :     }
     385           0 : }
     386             : 
     387           0 : void UndoInsertOrRemoveAnnotation::Redo()
     388             : {
     389           0 :     SdPage* pPage = mxAnnotation->GetPage();
     390           0 :     SdrModel* pModel = mxAnnotation->GetModel();
     391           0 :     if( pPage && pModel )
     392             :     {
     393           0 :         Reference< XAnnotation > xAnnotation( mxAnnotation.get() );
     394             : 
     395           0 :         if( mbInsert )
     396             :         {
     397           0 :             pPage->addAnnotation( xAnnotation, mnIndex );
     398             :         }
     399             :         else
     400             :         {
     401           0 :             pPage->removeAnnotation( xAnnotation );
     402           0 :         }
     403             :     }
     404           0 : }
     405             : 
     406           0 : UndoAnnotation::UndoAnnotation( Annotation& rAnnotation )
     407           0 : : SdrUndoAction( *rAnnotation.GetModel() )
     408           0 : , mxAnnotation( &rAnnotation )
     409             : {
     410           0 :     maUndoData.get( mxAnnotation );
     411           0 : }
     412             : 
     413           0 : void UndoAnnotation::Undo()
     414             : {
     415           0 :     maRedoData.get( mxAnnotation );
     416           0 :     maUndoData.set( mxAnnotation );
     417           0 : }
     418             : 
     419           0 : void UndoAnnotation::Redo()
     420             : {
     421           0 :     maUndoData.get( mxAnnotation );
     422           0 :     maRedoData.set( mxAnnotation );
     423           0 : }
     424             : 
     425             : } // namespace sd
     426             : 
     427             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10