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: notesuno.cxx,v $
10 * $Revision: 1.11.128.4 $
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_sc.hxx"
33 #include <svtools/smplhint.hxx>
36 #include "rangelst.hxx"
37 #include <svx/unotext.hxx>
39 #include "notesuno.hxx"
40 #include "textuno.hxx"
41 #include "cellsuno.hxx" // getParent
43 #include "docfunc.hxx"
45 #include "editsrc.hxx"
46 #include "miscuno.hxx"
49 #include <svx/svdundo.hxx>
50 #include "drwlayer.hxx"
51 #include "detfunc.hxx"
52 #include "undocell.hxx"
53 #include "unoguard.hxx"
54 #include "userdat.hxx"
55 #include <svx/outlobj.hxx>
56 #include <svx/unoshape.hxx>
57 #include <svx/svdocapt.hxx>
58 #include <svx/svditer.hxx>
59 #include <svx/svdpage.hxx>
60 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
62 using namespace com::sun::star
;
64 //------------------------------------------------------------------------
66 // keine Properties fuer Text in Notizen
67 const SfxItemPropertyMap
* lcl_GetAnnotationPropertyMap()
69 static SfxItemPropertyMap aAnnotationPropertyMap_Impl
[] =
73 return aAnnotationPropertyMap_Impl
;
76 //------------------------------------------------------------------------
78 SC_SIMPLE_SERVICE_INFO( ScAnnotationObj
, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
79 SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj
, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
81 //------------------------------------------------------------------------
83 ScAnnotationObj::ScAnnotationObj(ScDocShell
* pDocSh
, const ScAddress
& rPos
) :
88 pDocShell
->GetDocument()->AddUnoObject(*this);
90 // pUnoText is allocated on demand (GetUnoText)
91 // can't be aggregated because getString/setString is handled here
94 ScAnnotationObj::~ScAnnotationObj()
97 pDocShell
->GetDocument()->RemoveUnoObject(*this);
103 void ScAnnotationObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
105 if ( rHint
.ISA( ScUpdateRefHint
) )
107 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
111 else if ( rHint
.ISA( SfxSimpleHint
) &&
112 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
114 pDocShell
= NULL
; // ungueltig geworden
121 uno::Reference
<uno::XInterface
> SAL_CALL
ScAnnotationObj::getParent() throw(uno::RuntimeException
)
125 // Parent der Notiz ist die zugehoerige Zelle
126 //! existierendes Objekt finden und zurueckgeben ???
129 return (cppu::OWeakObject
*)new ScCellObj( pDocShell
, aCellPos
);
134 void SAL_CALL
ScAnnotationObj::setParent( const uno::Reference
<uno::XInterface
>& /* Parent */ )
135 throw(lang::NoSupportException
, uno::RuntimeException
)
138 //! Exception oder so ??!
143 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursor()
144 throw(uno::RuntimeException
)
147 // Notizen brauchen keine Extrawurst
148 return GetUnoText().createTextCursor();
151 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursorByRange(
152 const uno::Reference
<text::XTextRange
>& aTextPosition
)
153 throw(uno::RuntimeException
)
156 // Notizen brauchen keine Extrawurst
157 return GetUnoText().createTextCursorByRange(aTextPosition
);
160 rtl::OUString SAL_CALL
ScAnnotationObj::getString() throw(uno::RuntimeException
)
163 return GetUnoText().getString();
166 void SAL_CALL
ScAnnotationObj::setString( const rtl::OUString
& aText
) throw(uno::RuntimeException
)
169 GetUnoText().setString(aText
);
172 void SAL_CALL
ScAnnotationObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
173 const rtl::OUString
& aString
, sal_Bool bAbsorb
)
174 throw(uno::RuntimeException
)
177 GetUnoText().insertString( xRange
, aString
, bAbsorb
);
180 void SAL_CALL
ScAnnotationObj::insertControlCharacter( const uno::Reference
<text::XTextRange
>& xRange
,
181 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
182 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
185 GetUnoText().insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
188 uno::Reference
<text::XText
> SAL_CALL
ScAnnotationObj::getText() throw(uno::RuntimeException
)
191 return GetUnoText().getText();
194 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getStart() throw(uno::RuntimeException
)
197 return GetUnoText().getStart();
200 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getEnd() throw(uno::RuntimeException
)
203 return GetUnoText().getEnd();
208 table::CellAddress SAL_CALL
ScAnnotationObj::getPosition() throw(uno::RuntimeException
)
211 table::CellAddress aAdr
;
212 aAdr
.Sheet
= aCellPos
.Tab();
213 aAdr
.Column
= aCellPos
.Col();
214 aAdr
.Row
= aCellPos
.Row();
218 rtl::OUString SAL_CALL
ScAnnotationObj::getAuthor() throw(uno::RuntimeException
)
221 const ScPostIt
* pNote
= ImplGetNote();
222 return pNote
? pNote
->GetAuthor() : EMPTY_STRING
;
225 rtl::OUString SAL_CALL
ScAnnotationObj::getDate() throw(uno::RuntimeException
)
228 const ScPostIt
* pNote
= ImplGetNote();
229 return pNote
? pNote
->GetDate() : EMPTY_STRING
;
232 sal_Bool SAL_CALL
ScAnnotationObj::getIsVisible() throw(uno::RuntimeException
)
235 const ScPostIt
* pNote
= ImplGetNote();
236 return pNote
&& pNote
->IsCaptionShown();
239 void SAL_CALL
ScAnnotationObj::setIsVisible( sal_Bool bIsVisible
) throw(uno::RuntimeException
)
242 // show/hide note with undo action
244 pDocShell
->GetDocFunc().ShowNote( aCellPos
, bIsVisible
);
247 // XSheetAnnotationShapeSupplier
248 uno::Reference
< drawing::XShape
> SAL_CALL
ScAnnotationObj::getAnnotationShape()
249 throw(::com::sun::star::uno::RuntimeException
)
252 return new ScAnnotationShapeObj(pDocShell
, aCellPos
);
255 SvxUnoText
& ScAnnotationObj::GetUnoText()
259 ScAnnotationEditSource
aEditSource( pDocShell
, aCellPos
);
260 pUnoText
= new SvxUnoText( &aEditSource
, lcl_GetAnnotationPropertyMap(),
261 uno::Reference
<text::XText
>() );
267 const ScPostIt
* ScAnnotationObj::ImplGetNote() const
269 return pDocShell
? pDocShell
->GetDocument()->GetNote( aCellPos
) : 0;
272 //------------------------------------------------------------------------
274 ScAnnotationShapeObj::ScAnnotationShapeObj(ScDocShell
* pDocSh
, const ScAddress
& rPos
) :
279 pDocShell
->GetDocument()->AddUnoObject(*this);
281 // pUnoText is allocated on demand (GetUnoText)
282 // can't be aggregated because getString/setString is handled here
285 SvxUnoText
& ScAnnotationShapeObj::GetUnoText()
289 ScAnnotationEditSource
aEditSource( pDocShell
, aCellPos
);
290 pUnoText
= new SvxUnoText( &aEditSource
, lcl_GetAnnotationPropertyMap(),
291 uno::Reference
<text::XText
>() );
297 uno::Reference
< drawing::XShape
> ScAnnotationShapeObj::GetXShape()
300 if( ScPostIt
* pNote
= pDocShell
->GetDocument()->GetNote( aCellPos
) )
301 if( SdrObject
* pCaption
= pNote
->GetCaption() )
302 xShape
.set( pCaption
->getUnoShape(), uno::UNO_QUERY
);
306 ScAnnotationShapeObj::~ScAnnotationShapeObj()
309 pDocShell
->GetDocument()->RemoveUnoObject(*this);
314 void ScAnnotationShapeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
316 if ( rHint
.ISA( ScUpdateRefHint
) )
318 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
322 else if ( rHint
.ISA( SfxSimpleHint
) &&
323 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
325 pDocShell
= NULL
; // ungueltig geworden
332 uno::Reference
<uno::XInterface
> SAL_CALL
ScAnnotationShapeObj::getParent() throw(uno::RuntimeException
)
336 // Parent der Notiz ist die zugehoerige Zelle
337 //! existierendes Objekt finden und zurueckgeben ???
340 return (cppu::OWeakObject
*)new ScCellObj( pDocShell
, aCellPos
);
345 void SAL_CALL
ScAnnotationShapeObj::setParent( const uno::Reference
<uno::XInterface
>& /* Parent */ )
346 throw(lang::NoSupportException
, uno::RuntimeException
)
349 //! Exception oder so ??!
353 uno::Type SAL_CALL
ScAnnotationShapeObj::getElementType( ) throw (uno::RuntimeException
)
357 return GetUnoText().getElementType();
360 sal_Bool SAL_CALL
ScAnnotationShapeObj::hasElements( ) throw (uno::RuntimeException
)
364 return GetUnoText().hasElements();
367 // XEnumerationAccess
368 uno::Reference
< container::XEnumeration
> SAL_CALL
ScAnnotationShapeObj::createEnumeration( ) throw (uno::RuntimeException
)
372 return GetUnoText().createEnumeration();
376 void SAL_CALL
ScAnnotationShapeObj::moveTextRange( const uno::Reference
< text::XTextRange
>& xRange
, sal_Int16 nParagraphs
)
377 throw (uno::RuntimeException
)
381 GetUnoText().moveTextRange( xRange
, nParagraphs
);
385 void SAL_CALL
ScAnnotationShapeObj::insertTextContent( const uno::Reference
< text::XTextRange
>& xRange
,
386 const uno::Reference
< text::XTextContent
>& xContent
, sal_Bool bAbsorb
)
387 throw (lang::IllegalArgumentException
,
388 uno::RuntimeException
)
392 GetUnoText().insertTextContent( xRange
, xContent
, bAbsorb
);
395 void SAL_CALL
ScAnnotationShapeObj::removeTextContent( const uno::Reference
< text::XTextContent
>& xContent
)
396 throw (container::NoSuchElementException
,
397 uno::RuntimeException
)
401 GetUnoText().removeTextContent( xContent
);
406 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationShapeObj::createTextCursor()
407 throw(uno::RuntimeException
)
410 // Notizen brauchen keine Extrawurst
411 return GetUnoText().createTextCursor();
414 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationShapeObj::createTextCursorByRange(
415 const uno::Reference
<text::XTextRange
>& aTextPosition
)
416 throw(uno::RuntimeException
)
419 // Notizen brauchen keine Extrawurst
420 return GetUnoText().createTextCursorByRange(aTextPosition
);
423 rtl::OUString SAL_CALL
ScAnnotationShapeObj::getString() throw(uno::RuntimeException
)
426 return GetUnoText().getString();
429 void SAL_CALL
ScAnnotationShapeObj::setString( const rtl::OUString
& aText
) throw(uno::RuntimeException
)
432 GetUnoText().setString(aText
);
435 void SAL_CALL
ScAnnotationShapeObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
436 const rtl::OUString
& aString
, sal_Bool bAbsorb
)
437 throw(uno::RuntimeException
)
440 GetUnoText().insertString( xRange
, aString
, bAbsorb
);
443 void SAL_CALL
ScAnnotationShapeObj::insertControlCharacter( const uno::Reference
<text::XTextRange
>& xRange
,
444 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
445 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
448 GetUnoText().insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
451 uno::Reference
<text::XText
> SAL_CALL
ScAnnotationShapeObj::getText() throw(uno::RuntimeException
)
454 return GetUnoText().getText();
457 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationShapeObj::getStart() throw(uno::RuntimeException
)
460 return GetUnoText().getStart();
463 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationShapeObj::getEnd() throw(uno::RuntimeException
)
466 return GetUnoText().getEnd();
470 ::rtl::OUString SAL_CALL
ScAnnotationShapeObj::getShapeType( )
471 throw (uno::RuntimeException
)
474 uno::Reference
< drawing::XShapeDescriptor
> xDesc(GetXShape(), uno::UNO_QUERY
);
476 return xDesc
->getShapeType();
477 return rtl::OUString();
481 awt::Point SAL_CALL
ScAnnotationShapeObj::getPosition( )
482 throw (uno::RuntimeException
)
486 return xShape
.is() ? xShape
->getPosition() : awt::Point();
489 void SAL_CALL
ScAnnotationShapeObj::setPosition( const awt::Point
& aPosition
)
490 throw (uno::RuntimeException
)
495 xShape
->setPosition(aPosition
);
498 awt::Size SAL_CALL
ScAnnotationShapeObj::getSize( )
499 throw (uno::RuntimeException
)
503 return xShape
.is() ? xShape
->getSize() : awt::Size();
506 void SAL_CALL
ScAnnotationShapeObj::setSize( const awt::Size
& aSize
)
507 throw (beans::PropertyVetoException
, uno::RuntimeException
)
512 xShape
->setSize(aSize
);
516 beans::PropertyState SAL_CALL
ScAnnotationShapeObj::getPropertyState( const rtl::OUString
& PropertyName
)
517 throw (beans::UnknownPropertyException
,
518 uno::RuntimeException
)
521 uno::Reference
< beans::XPropertyState
> xState (GetXShape(), uno::UNO_QUERY
);
523 return xState
->getPropertyState( PropertyName
);
524 return beans::PropertyState();
527 uno::Sequence
< beans::PropertyState
> SAL_CALL
ScAnnotationShapeObj::getPropertyStates(
528 const uno::Sequence
< rtl::OUString
>& aPropertyName
)
529 throw (beans::UnknownPropertyException
,
530 uno::RuntimeException
)
533 uno::Reference
< beans::XPropertyState
> xState (GetXShape(), uno::UNO_QUERY
);
535 return xState
->getPropertyStates( aPropertyName
);
536 return uno::Sequence
< beans::PropertyState
>();
539 void SAL_CALL
ScAnnotationShapeObj::setPropertyToDefault( const ::rtl::OUString
& PropertyName
)
540 throw (::com::sun::star::beans::UnknownPropertyException
,
541 ::com::sun::star::uno::RuntimeException
)
544 uno::Reference
< beans::XPropertyState
> xState (GetXShape(), uno::UNO_QUERY
);
546 xState
->setPropertyToDefault( PropertyName
);
549 uno::Any SAL_CALL
ScAnnotationShapeObj::getPropertyDefault( const rtl::OUString
& aPropertyName
)
550 throw (beans::UnknownPropertyException
,
551 lang::WrappedTargetException
, uno::RuntimeException
)
554 uno::Reference
< beans::XPropertyState
> xState (GetXShape(), uno::UNO_QUERY
);
556 return xState
->getPropertyDefault( aPropertyName
);
561 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ScAnnotationShapeObj::getPropertySetInfo( )
562 throw (uno::RuntimeException
)
565 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
567 return xProp
->getPropertySetInfo();
568 return uno::Reference
< beans::XPropertySetInfo
>();
571 void SAL_CALL
ScAnnotationShapeObj::setPropertyValue( const rtl::OUString
& aPropertyName
, const uno::Any
& aValue
)
572 throw (beans::UnknownPropertyException
,
573 beans::PropertyVetoException
,
574 lang::IllegalArgumentException
,
575 lang::WrappedTargetException
,
576 uno::RuntimeException
)
579 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
581 xProp
->setPropertyValue( aPropertyName
, aValue
);
584 uno::Any SAL_CALL
ScAnnotationShapeObj::getPropertyValue( const rtl::OUString
& PropertyName
)
585 throw (beans::UnknownPropertyException
,
586 lang::WrappedTargetException
,
587 uno::RuntimeException
)
590 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
592 return xProp
->getPropertyValue( PropertyName
);
596 void SAL_CALL
ScAnnotationShapeObj::addPropertyChangeListener( const rtl::OUString
& aPropertyName
,
597 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
598 throw (beans::UnknownPropertyException
,
599 lang::WrappedTargetException
,
600 uno::RuntimeException
)
603 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
605 return xProp
->addPropertyChangeListener( aPropertyName
, xListener
);
608 void SAL_CALL
ScAnnotationShapeObj::removePropertyChangeListener( const rtl::OUString
& aPropertyName
,
609 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
610 throw (beans::UnknownPropertyException
,
611 lang::WrappedTargetException
,
612 uno::RuntimeException
)
615 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
617 return xProp
->removePropertyChangeListener( aPropertyName
, aListener
);
620 void SAL_CALL
ScAnnotationShapeObj::addVetoableChangeListener( const rtl::OUString
& PropertyName
,
621 const uno::Reference
< beans::XVetoableChangeListener
>& aListener
)
622 throw (beans::UnknownPropertyException
,
623 lang::WrappedTargetException
,
624 uno::RuntimeException
)
627 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
629 return xProp
->addVetoableChangeListener( PropertyName
, aListener
);
632 void SAL_CALL
ScAnnotationShapeObj::removeVetoableChangeListener( const rtl::OUString
& PropertyName
,
633 const uno::Reference
< beans::XVetoableChangeListener
>& aListener
)
634 throw (beans::UnknownPropertyException
,
635 lang::WrappedTargetException
,
636 uno::RuntimeException
)
639 uno::Reference
< beans::XPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
641 return xProp
->removeVetoableChangeListener( PropertyName
, aListener
);
645 void SAL_CALL
ScAnnotationShapeObj::setPropertyValues( const uno::Sequence
< rtl::OUString
>& aPropertyNames
,
646 const uno::Sequence
< uno::Any
>& aValues
)
647 throw (beans::PropertyVetoException
,
648 lang::IllegalArgumentException
,
649 lang::WrappedTargetException
,
650 uno::RuntimeException
)
653 uno::Reference
< beans::XMultiPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
655 xProp
->setPropertyValues( aPropertyNames
, aValues
);
658 uno::Sequence
< uno::Any
> SAL_CALL
ScAnnotationShapeObj::getPropertyValues(
659 const uno::Sequence
< rtl::OUString
>& aPropertyNames
)
660 throw (uno::RuntimeException
)
663 uno::Reference
< beans::XMultiPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
665 return xProp
->getPropertyValues( aPropertyNames
);
666 return uno::Sequence
< uno::Any
>();
669 void SAL_CALL
ScAnnotationShapeObj::addPropertiesChangeListener( const uno::Sequence
< rtl::OUString
>& aPropertyNames
,
670 const uno::Reference
< beans::XPropertiesChangeListener
>& xListener
)
671 throw (uno::RuntimeException
)
674 uno::Reference
< beans::XMultiPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
676 xProp
->addPropertiesChangeListener( aPropertyNames
, xListener
);
679 void SAL_CALL
ScAnnotationShapeObj::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& xListener
)
680 throw (uno::RuntimeException
)
683 uno::Reference
< beans::XMultiPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
685 xProp
->removePropertiesChangeListener( xListener
);
688 void SAL_CALL
ScAnnotationShapeObj::firePropertiesChangeEvent( const uno::Sequence
< rtl::OUString
>& aPropertyNames
,
689 const uno::Reference
< beans::XPropertiesChangeListener
>& xListener
)
690 throw (uno::RuntimeException
)
693 uno::Reference
< beans::XMultiPropertySet
> xProp (GetXShape(), uno::UNO_QUERY
);
695 xProp
->firePropertiesChangeEvent( aPropertyNames
, xListener
);
699 void SAL_CALL
ScAnnotationShapeObj::dispose( ) throw (uno::RuntimeException
)
702 uno::Reference
< lang::XComponent
> xComp (GetXShape(), uno::UNO_QUERY
);
709 void SAL_CALL
ScAnnotationShapeObj::addEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
710 throw (uno::RuntimeException
)
713 uno::Reference
< lang::XComponent
> xComp (GetXShape(), uno::UNO_QUERY
);
715 xComp
->addEventListener( xListener
);
718 void SAL_CALL
ScAnnotationShapeObj::removeEventListener( const uno::Reference
< lang::XEventListener
>& aListener
)
719 throw (uno::RuntimeException
)
722 uno::Reference
< lang::XComponent
> xComp (GetXShape(), uno::UNO_QUERY
);
724 xComp
->removeEventListener( aListener
);
727 //------------------------------------------------------------------------