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