1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unopage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
35 #include "sal/config.h"
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/office/XAnnotation.hpp>
39 #include <com/sun/star/drawing/XDrawPage.hpp>
41 #include <comphelper/processfactory.hxx>
42 #include <cppuhelper/propertysetmixin.hxx>
43 #include <cppuhelper/compbase1.hxx>
44 #include <cppuhelper/basemutex.hxx>
46 #include "drawdoc.hxx"
48 #include "textapi.hxx"
50 using ::rtl::OUString
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::office
;
55 using namespace ::com::sun::star::drawing
;
56 using namespace ::com::sun::star::geometry
;
57 using namespace ::com::sun::star::text
;
58 using namespace ::com::sun::star::util
;
59 using namespace ::com::sun::star
;
61 extern void NotifyDocumentEvent( SdDrawDocument
* pDocument
, const rtl::OUString
& rEventName
, const Reference
< XInterface
>& xSource
);
65 class Annotation
: private ::cppu::BaseMutex
,
66 public ::cppu::WeakComponentImplHelper1
< XAnnotation
>,
67 public ::cppu::PropertySetMixin
< XAnnotation
>
70 explicit Annotation( const Reference
< XComponentContext
>& context
, SdPage
* pPage
);
72 SdPage
* GetPage() const { return mpPage
; }
73 SdrModel
* GetModel() { return (mpPage
!= 0) ? mpPage
->GetModel() : 0; }
76 virtual Any SAL_CALL
queryInterface(Type
const & type
) throw (RuntimeException
);
77 virtual void SAL_CALL
acquire() throw () { ::cppu::WeakComponentImplHelper1
< XAnnotation
>::acquire(); }
78 virtual void SAL_CALL
release() throw () { ::cppu::WeakComponentImplHelper1
< XAnnotation
>::release(); }
80 // ::com::sun::star::beans::XPropertySet:
81 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw (RuntimeException
);
82 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const Any
& aValue
) throw (RuntimeException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
);
83 virtual Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
);
84 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
> & xListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
);
85 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
> & aListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
);
86 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
> & aListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
);
87 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
> & aListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
);
89 // ::com::sun::star::office::XAnnotation:
90 virtual ::com::sun::star::uno::Any SAL_CALL
getAnchor() throw (::com::sun::star::uno::RuntimeException
);
91 virtual RealPoint2D SAL_CALL
getPosition() throw (RuntimeException
);
92 virtual void SAL_CALL
setPosition(const RealPoint2D
& the_value
) throw (RuntimeException
);
93 virtual ::com::sun::star::geometry::RealSize2D SAL_CALL
getSize() throw (::com::sun::star::uno::RuntimeException
);
94 virtual void SAL_CALL
setSize( const ::com::sun::star::geometry::RealSize2D
& _size
) throw (::com::sun::star::uno::RuntimeException
);
95 virtual OUString SAL_CALL
getAuthor() throw (RuntimeException
);
96 virtual void SAL_CALL
setAuthor(const OUString
& the_value
) throw (RuntimeException
);
97 virtual util::DateTime SAL_CALL
getDateTime() throw (RuntimeException
);
98 virtual void SAL_CALL
setDateTime(const util::DateTime
& the_value
) throw (RuntimeException
);
99 virtual Reference
< XText
> SAL_CALL
getTextRange() throw (RuntimeException
);
102 Annotation(const Annotation
&); // not defined
103 Annotation
& operator=(const Annotation
&); // not defined
105 // destructor is private and will be called indirectly by the release call virtual ~Annotation() {}
107 void createChangeUndo();
109 // overload WeakComponentImplHelperBase::disposing()
110 // This function is called upon disposing the component,
111 // if your component needs special work when it becomes
112 // disposed, do it here.
113 virtual void SAL_CALL
disposing();
116 Reference
< XComponentContext
> m_xContext
;
117 mutable ::osl::Mutex m_aMutex
;
118 RealPoint2D m_Position
;
121 util::DateTime m_DateTime
;
122 rtl::Reference
< TextApiObject
> m_TextRange
;
125 class UndoInsertOrRemoveAnnotation
: public SdrUndoAction
128 UndoInsertOrRemoveAnnotation( Annotation
& rAnnotation
, bool bInsert
);
134 rtl::Reference
< Annotation
> mxAnnotation
;
139 struct AnnotationData
141 RealPoint2D m_Position
;
144 util::DateTime m_DateTime
;
146 void get( const rtl::Reference
< Annotation
>& xAnnotation
)
148 m_Position
= xAnnotation
->getPosition();
149 m_Size
= xAnnotation
->getSize();
150 m_Author
= xAnnotation
->getAuthor();
151 m_DateTime
= xAnnotation
->getDateTime();
154 void set( const rtl::Reference
< Annotation
>& xAnnotation
)
156 xAnnotation
->setPosition(m_Position
);
157 xAnnotation
->setSize(m_Size
);
158 xAnnotation
->setAuthor(m_Author
);
159 xAnnotation
->setDateTime(m_DateTime
);
163 class UndoAnnotation
: public SdrUndoAction
166 UndoAnnotation( Annotation
& rAnnotation
);
172 rtl::Reference
< Annotation
> mxAnnotation
;
173 AnnotationData maUndoData
;
174 AnnotationData maRedoData
;
177 void createAnnotation( Reference
< XAnnotation
>& xAnnotation
, SdPage
* pPage
)
179 Reference
<XComponentContext
> xContext (comphelper_getProcessComponentContext());
180 xAnnotation
.set( new Annotation(xContext
, pPage
) );
181 pPage
->addAnnotation(xAnnotation
);
184 Annotation::Annotation( const Reference
< XComponentContext
>& context
, SdPage
* pPage
)
185 : ::cppu::WeakComponentImplHelper1
< XAnnotation
>(m_aMutex
)
186 , ::cppu::PropertySetMixin
< XAnnotation
>(context
, static_cast< Implements
>(IMPLEMENTS_PROPERTY_SET
), Sequence
< ::rtl::OUString
>())
191 // overload WeakComponentImplHelperBase::disposing()
192 // This function is called upon disposing the component,
193 // if your component needs special work when it becomes
194 // disposed, do it here.
195 void SAL_CALL
Annotation::disposing()
198 if( m_TextRange
.is() )
200 m_TextRange
->dispose();
205 Any
Annotation::queryInterface(Type
const & type
) throw (RuntimeException
)
207 return ::cppu::WeakComponentImplHelper1
< XAnnotation
>::queryInterface(type
);
210 // com.sun.star.beans.XPropertySet:
211 Reference
< XPropertySetInfo
> SAL_CALL
Annotation::getPropertySetInfo() throw (RuntimeException
)
213 return ::cppu::PropertySetMixin
< XAnnotation
>::getPropertySetInfo();
216 void SAL_CALL
Annotation::setPropertyValue(const OUString
& aPropertyName
, const Any
& aValue
) throw (RuntimeException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
)
218 ::cppu::PropertySetMixin
< XAnnotation
>::setPropertyValue(aPropertyName
, aValue
);
221 Any SAL_CALL
Annotation::getPropertyValue(const OUString
& aPropertyName
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
)
223 return ::cppu::PropertySetMixin
< XAnnotation
>::getPropertyValue(aPropertyName
);
226 void SAL_CALL
Annotation::addPropertyChangeListener(const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
> & xListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
)
228 ::cppu::PropertySetMixin
< XAnnotation
>::addPropertyChangeListener(aPropertyName
, xListener
);
231 void SAL_CALL
Annotation::removePropertyChangeListener(const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
> & xListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
)
233 ::cppu::PropertySetMixin
< XAnnotation
>::removePropertyChangeListener(aPropertyName
, xListener
);
236 void SAL_CALL
Annotation::addVetoableChangeListener(const OUString
& aPropertyName
, const Reference
< XVetoableChangeListener
> & xListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
)
238 ::cppu::PropertySetMixin
< XAnnotation
>::addVetoableChangeListener(aPropertyName
, xListener
);
241 void SAL_CALL
Annotation::removeVetoableChangeListener(const OUString
& aPropertyName
, const Reference
< XVetoableChangeListener
> & xListener
) throw (RuntimeException
, UnknownPropertyException
, WrappedTargetException
)
243 ::cppu::PropertySetMixin
< XAnnotation
>::removeVetoableChangeListener(aPropertyName
, xListener
);
246 Any SAL_CALL
Annotation::getAnchor() throw (RuntimeException
)
248 osl::MutexGuard
g(m_aMutex
);
252 Reference
< XDrawPage
> xPage( mpPage
->getUnoPage(), UNO_QUERY
);
258 // ::com::sun::star::office::XAnnotation:
259 RealPoint2D SAL_CALL
Annotation::getPosition() throw (RuntimeException
)
261 osl::MutexGuard
g(m_aMutex
);
265 void SAL_CALL
Annotation::setPosition(const RealPoint2D
& the_value
) throw (RuntimeException
)
268 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Position")),
271 osl::MutexGuard
g(m_aMutex
);
273 m_Position
= the_value
;
277 // ::com::sun::star::office::XAnnotation:
278 RealSize2D SAL_CALL
Annotation::getSize() throw (RuntimeException
)
280 osl::MutexGuard
g(m_aMutex
);
284 void SAL_CALL
Annotation::setSize(const RealSize2D
& the_value
) throw (RuntimeException
)
287 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size")),
290 osl::MutexGuard
g(m_aMutex
);
296 OUString SAL_CALL
Annotation::getAuthor() throw (RuntimeException
)
298 osl::MutexGuard
g(m_aMutex
);
302 void SAL_CALL
Annotation::setAuthor(const OUString
& the_value
) throw (RuntimeException
)
305 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Author")),
308 osl::MutexGuard
g(m_aMutex
);
310 m_Author
= the_value
;
314 util::DateTime SAL_CALL
Annotation::getDateTime() throw (RuntimeException
)
316 osl::MutexGuard
g(m_aMutex
);
320 void SAL_CALL
Annotation::setDateTime(const util::DateTime
& the_value
) throw (RuntimeException
)
323 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DateTime")),
326 osl::MutexGuard
g(m_aMutex
);
328 m_DateTime
= the_value
;
332 void Annotation::createChangeUndo()
334 SdrModel
* pModel
= GetModel();
335 if( pModel
&& pModel
->IsUndoEnabled() )
336 pModel
->AddUndo( new UndoAnnotation( *this ) );
340 pModel
->SetChanged();
341 Reference
< XInterface
> xSource( static_cast<uno::XWeak
*>( this ) );
342 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), OUString( RTL_CONSTASCII_USTRINGPARAM("OnAnnotationChanged") ), xSource
);
346 Reference
< XText
> SAL_CALL
Annotation::getTextRange() throw (RuntimeException
)
348 osl::MutexGuard
g(m_aMutex
);
349 if( !m_TextRange
.is() && (mpPage
!= 0) )
351 m_TextRange
= TextApiObject::create( static_cast< SdDrawDocument
* >( mpPage
->GetModel() ) );
353 return Reference
< XText
>( m_TextRange
.get() );
356 SdrUndoAction
* CreateUndoInsertOrRemoveAnnotation( const Reference
< XAnnotation
>& xAnnotation
, bool bInsert
)
358 Annotation
* pAnnotation
= dynamic_cast< Annotation
* >( xAnnotation
.get() );
361 return new UndoInsertOrRemoveAnnotation( *pAnnotation
, bInsert
);
369 UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation( Annotation
& rAnnotation
, bool bInsert
)
370 : SdrUndoAction( *rAnnotation
.GetModel() )
371 , mxAnnotation( &rAnnotation
)
372 , mbInsert( bInsert
)
375 SdPage
* pPage
= rAnnotation
.GetPage();
378 Reference
< XAnnotation
> xAnnotation( &rAnnotation
);
380 const AnnotationVector
& rVec
= pPage
->getAnnotations();
381 for( AnnotationVector::const_iterator iter
= rVec
.begin(); iter
!= rVec
.end(); iter
++ )
383 if( (*iter
) == xAnnotation
)
391 void UndoInsertOrRemoveAnnotation::Undo()
393 SdPage
* pPage
= mxAnnotation
->GetPage();
394 SdrModel
* pModel
= mxAnnotation
->GetModel();
395 if( pPage
&& pModel
)
397 Reference
< XAnnotation
> xAnnotation( mxAnnotation
.get() );
400 pPage
->removeAnnotation( xAnnotation
);
404 pPage
->addAnnotation( xAnnotation
, mnIndex
);
409 void UndoInsertOrRemoveAnnotation::Redo()
411 SdPage
* pPage
= mxAnnotation
->GetPage();
412 SdrModel
* pModel
= mxAnnotation
->GetModel();
413 if( pPage
&& pModel
)
415 Reference
< XAnnotation
> xAnnotation( mxAnnotation
.get() );
419 pPage
->addAnnotation( xAnnotation
, mnIndex
);
423 pPage
->removeAnnotation( xAnnotation
);
428 UndoAnnotation::UndoAnnotation( Annotation
& rAnnotation
)
429 : SdrUndoAction( *rAnnotation
.GetModel() )
430 , mxAnnotation( &rAnnotation
)
432 maUndoData
.get( mxAnnotation
);
435 void UndoAnnotation::Undo()
437 maRedoData
.get( mxAnnotation
);
438 maUndoData
.set( mxAnnotation
);
441 void UndoAnnotation::Redo()
443 maUndoData
.get( mxAnnotation
);
444 maRedoData
.set( mxAnnotation
);