1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "notesuno.hxx"
22 #include <vcl/svapp.hxx>
23 #include <svl/smplhint.hxx>
24 #include <editeng/unotext.hxx>
25 #include <editeng/unoprnms.hxx>
26 #include <svx/svdpool.hxx>
27 #include <svx/svdobj.hxx>
28 #include <svx/unoshape.hxx>
29 #include <svx/svdocapt.hxx>
32 #include "cellsuno.hxx"
34 #include "docfunc.hxx"
36 #include "editsrc.hxx"
37 #include "miscuno.hxx"
39 using namespace com::sun::star
;
41 static const SvxItemPropertySet
* lcl_GetAnnotationPropertySet()
43 static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl
[] =
45 SVX_UNOEDIT_CHAR_PROPERTIES
,
46 SVX_UNOEDIT_FONT_PROPERTIES
,
47 SVX_UNOEDIT_PARA_PROPERTIES
,
48 SVX_UNOEDIT_NUMBERING_PROPERTIE
, // for completeness of service ParagraphProperties
49 { OUString(), 0, css::uno::Type(), 0, 0 }
51 static SvxItemPropertySet
aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl
, SdrObject::GetGlobalDrawObjectItemPool() );
52 return &aAnnotationPropertySet_Impl
;
55 SC_SIMPLE_SERVICE_INFO( ScAnnotationObj
, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
56 //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
58 ScAnnotationObj::ScAnnotationObj(ScDocShell
* pDocSh
, const ScAddress
& rPos
) :
63 pDocShell
->GetDocument().AddUnoObject(*this);
65 // pUnoText is allocated on demand (GetUnoText)
66 // can't be aggregated because getString/setString is handled here
69 ScAnnotationObj::~ScAnnotationObj()
74 pDocShell
->GetDocument().RemoveUnoObject(*this);
80 void ScAnnotationObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
82 if ( dynamic_cast<const ScUpdateRefHint
*>(&rHint
) )
84 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
88 else if ( dynamic_cast<const SfxSimpleHint
*>(&rHint
) &&
89 static_cast<const SfxSimpleHint
&>(rHint
).GetId() == SFX_HINT_DYING
)
91 pDocShell
= NULL
; // ungueltig geworden
97 uno::Reference
<uno::XInterface
> SAL_CALL
ScAnnotationObj::getParent() throw(uno::RuntimeException
, std::exception
)
99 SolarMutexGuard aGuard
;
101 // Parent der Notiz ist die zugehoerige Zelle
102 //! existierendes Objekt finden und zurueckgeben ???
105 return (cppu::OWeakObject
*)new ScCellObj( pDocShell
, aCellPos
);
110 void SAL_CALL
ScAnnotationObj::setParent( const uno::Reference
<uno::XInterface
>& /* Parent */ )
111 throw(lang::NoSupportException
, uno::RuntimeException
, std::exception
)
114 //! Exception oder so ??!
119 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursor()
120 throw(uno::RuntimeException
, std::exception
)
122 SolarMutexGuard aGuard
;
123 // Notizen brauchen keine Extrawurst
124 return GetUnoText().createTextCursor();
127 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursorByRange(
128 const uno::Reference
<text::XTextRange
>& aTextPosition
)
129 throw(uno::RuntimeException
, std::exception
)
131 SolarMutexGuard aGuard
;
132 // Notizen brauchen keine Extrawurst
133 return GetUnoText().createTextCursorByRange(aTextPosition
);
136 OUString SAL_CALL
ScAnnotationObj::getString() throw(uno::RuntimeException
, std::exception
)
138 SolarMutexGuard aGuard
;
139 return GetUnoText().getString();
142 void SAL_CALL
ScAnnotationObj::setString( const OUString
& aText
) throw(uno::RuntimeException
, std::exception
)
144 SolarMutexGuard aGuard
;
145 GetUnoText().setString(aText
);
148 void SAL_CALL
ScAnnotationObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
149 const OUString
& aString
, sal_Bool bAbsorb
)
150 throw(uno::RuntimeException
, std::exception
)
152 SolarMutexGuard aGuard
;
153 GetUnoText().insertString( xRange
, aString
, bAbsorb
);
156 void SAL_CALL
ScAnnotationObj::insertControlCharacter( const uno::Reference
<text::XTextRange
>& xRange
,
157 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
158 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
160 SolarMutexGuard aGuard
;
161 GetUnoText().insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
164 uno::Reference
<text::XText
> SAL_CALL
ScAnnotationObj::getText() throw(uno::RuntimeException
, std::exception
)
166 SolarMutexGuard aGuard
;
167 return GetUnoText().getText();
170 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getStart() throw(uno::RuntimeException
, std::exception
)
172 SolarMutexGuard aGuard
;
173 return GetUnoText().getStart();
176 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getEnd() throw(uno::RuntimeException
, std::exception
)
178 SolarMutexGuard aGuard
;
179 return GetUnoText().getEnd();
184 table::CellAddress SAL_CALL
ScAnnotationObj::getPosition() throw(uno::RuntimeException
, std::exception
)
186 SolarMutexGuard aGuard
;
187 table::CellAddress aAdr
;
188 aAdr
.Sheet
= aCellPos
.Tab();
189 aAdr
.Column
= aCellPos
.Col();
190 aAdr
.Row
= aCellPos
.Row();
194 OUString SAL_CALL
ScAnnotationObj::getAuthor()
195 throw(uno::RuntimeException
, std::exception
)
197 SolarMutexGuard aGuard
;
198 const ScPostIt
* pNote
= ImplGetNote();
199 return pNote
? pNote
->GetAuthor() : OUString();
202 OUString SAL_CALL
ScAnnotationObj::getDate()
203 throw(uno::RuntimeException
, std::exception
)
205 SolarMutexGuard aGuard
;
206 const ScPostIt
* pNote
= ImplGetNote();
207 return pNote
? pNote
->GetDate() : OUString();
210 sal_Bool SAL_CALL
ScAnnotationObj::getIsVisible() throw(uno::RuntimeException
, std::exception
)
212 SolarMutexGuard aGuard
;
213 const ScPostIt
* pNote
= ImplGetNote();
214 return pNote
&& pNote
->IsCaptionShown();
217 void SAL_CALL
ScAnnotationObj::setIsVisible( sal_Bool bIsVisible
) throw(uno::RuntimeException
, std::exception
)
219 SolarMutexGuard aGuard
;
220 // show/hide note with undo action
222 pDocShell
->GetDocFunc().ShowNote( aCellPos
, bIsVisible
);
225 // XSheetAnnotationShapeSupplier
226 uno::Reference
< drawing::XShape
> SAL_CALL
ScAnnotationObj::getAnnotationShape()
227 throw(::com::sun::star::uno::RuntimeException
,
230 SolarMutexGuard aGuard
;
231 uno::Reference
< drawing::XShape
> xShape
;
232 if( const ScPostIt
* pNote
= ImplGetNote() )
233 if( SdrObject
* pCaption
= pNote
->GetOrCreateCaption( aCellPos
) )
234 xShape
.set( pCaption
->getUnoShape(), uno::UNO_QUERY
);
238 SvxUnoText
& ScAnnotationObj::GetUnoText()
242 ScAnnotationEditSource
aEditSource( pDocShell
, aCellPos
);
243 pUnoText
= new SvxUnoText( &aEditSource
, lcl_GetAnnotationPropertySet(),
244 uno::Reference
<text::XText
>() );
250 const ScPostIt
* ScAnnotationObj::ImplGetNote() const
252 return pDocShell
? pDocShell
->GetDocument().GetNote(aCellPos
) : 0;
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */