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

Generated by: LCOV version 1.10