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 //------------------------------------------------------------------------
43 static const SvxItemPropertySet
* lcl_GetAnnotationPropertySet()
45 static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl
[] =
47 SVX_UNOEDIT_CHAR_PROPERTIES
,
48 SVX_UNOEDIT_FONT_PROPERTIES
,
49 SVX_UNOEDIT_PARA_PROPERTIES
,
50 SVX_UNOEDIT_NUMBERING_PROPERTIE
, // for completeness of service ParagraphProperties
53 static SvxItemPropertySet
aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl
, SdrObject::GetGlobalDrawObjectItemPool() );
54 return &aAnnotationPropertySet_Impl
;
57 //------------------------------------------------------------------------
59 SC_SIMPLE_SERVICE_INFO( ScAnnotationObj
, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
60 //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
62 //------------------------------------------------------------------------
64 ScAnnotationObj::ScAnnotationObj(ScDocShell
* pDocSh
, const ScAddress
& rPos
) :
69 pDocShell
->GetDocument()->AddUnoObject(*this);
71 // pUnoText is allocated on demand (GetUnoText)
72 // can't be aggregated because getString/setString is handled here
75 ScAnnotationObj::~ScAnnotationObj()
78 pDocShell
->GetDocument()->RemoveUnoObject(*this);
84 void ScAnnotationObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
86 if ( rHint
.ISA( ScUpdateRefHint
) )
88 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
92 else if ( rHint
.ISA( SfxSimpleHint
) &&
93 ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
95 pDocShell
= NULL
; // ungueltig geworden
102 uno::Reference
<uno::XInterface
> SAL_CALL
ScAnnotationObj::getParent() throw(uno::RuntimeException
)
104 SolarMutexGuard aGuard
;
106 // Parent der Notiz ist die zugehoerige Zelle
107 //! existierendes Objekt finden und zurueckgeben ???
110 return (cppu::OWeakObject
*)new ScCellObj( pDocShell
, aCellPos
);
115 void SAL_CALL
ScAnnotationObj::setParent( const uno::Reference
<uno::XInterface
>& /* Parent */ )
116 throw(lang::NoSupportException
, uno::RuntimeException
)
119 //! Exception oder so ??!
124 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursor()
125 throw(uno::RuntimeException
)
127 SolarMutexGuard aGuard
;
128 // Notizen brauchen keine Extrawurst
129 return GetUnoText().createTextCursor();
132 uno::Reference
<text::XTextCursor
> SAL_CALL
ScAnnotationObj::createTextCursorByRange(
133 const uno::Reference
<text::XTextRange
>& aTextPosition
)
134 throw(uno::RuntimeException
)
136 SolarMutexGuard aGuard
;
137 // Notizen brauchen keine Extrawurst
138 return GetUnoText().createTextCursorByRange(aTextPosition
);
141 OUString SAL_CALL
ScAnnotationObj::getString() throw(uno::RuntimeException
)
143 SolarMutexGuard aGuard
;
144 return GetUnoText().getString();
147 void SAL_CALL
ScAnnotationObj::setString( const OUString
& aText
) throw(uno::RuntimeException
)
149 SolarMutexGuard aGuard
;
150 GetUnoText().setString(aText
);
153 void SAL_CALL
ScAnnotationObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
154 const OUString
& aString
, sal_Bool bAbsorb
)
155 throw(uno::RuntimeException
)
157 SolarMutexGuard aGuard
;
158 GetUnoText().insertString( xRange
, aString
, bAbsorb
);
161 void SAL_CALL
ScAnnotationObj::insertControlCharacter( const uno::Reference
<text::XTextRange
>& xRange
,
162 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
163 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
165 SolarMutexGuard aGuard
;
166 GetUnoText().insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
169 uno::Reference
<text::XText
> SAL_CALL
ScAnnotationObj::getText() throw(uno::RuntimeException
)
171 SolarMutexGuard aGuard
;
172 return GetUnoText().getText();
175 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getStart() throw(uno::RuntimeException
)
177 SolarMutexGuard aGuard
;
178 return GetUnoText().getStart();
181 uno::Reference
<text::XTextRange
> SAL_CALL
ScAnnotationObj::getEnd() throw(uno::RuntimeException
)
183 SolarMutexGuard aGuard
;
184 return GetUnoText().getEnd();
189 table::CellAddress SAL_CALL
ScAnnotationObj::getPosition() throw(uno::RuntimeException
)
191 SolarMutexGuard aGuard
;
192 table::CellAddress aAdr
;
193 aAdr
.Sheet
= aCellPos
.Tab();
194 aAdr
.Column
= aCellPos
.Col();
195 aAdr
.Row
= aCellPos
.Row();
199 OUString SAL_CALL
ScAnnotationObj::getAuthor() throw(uno::RuntimeException
)
201 SolarMutexGuard aGuard
;
202 const ScPostIt
* pNote
= ImplGetNote();
203 return pNote
? pNote
->GetAuthor() : OUString();
206 OUString SAL_CALL
ScAnnotationObj::getDate() throw(uno::RuntimeException
)
208 SolarMutexGuard aGuard
;
209 const ScPostIt
* pNote
= ImplGetNote();
210 return pNote
? pNote
->GetDate() : OUString();
213 sal_Bool SAL_CALL
ScAnnotationObj::getIsVisible() throw(uno::RuntimeException
)
215 SolarMutexGuard aGuard
;
216 const ScPostIt
* pNote
= ImplGetNote();
217 return pNote
&& pNote
->IsCaptionShown();
220 void SAL_CALL
ScAnnotationObj::setIsVisible( sal_Bool bIsVisible
) throw(uno::RuntimeException
)
222 SolarMutexGuard aGuard
;
223 // show/hide note with undo action
225 pDocShell
->GetDocFunc().ShowNote( aCellPos
, bIsVisible
);
228 // XSheetAnnotationShapeSupplier
229 uno::Reference
< drawing::XShape
> SAL_CALL
ScAnnotationObj::getAnnotationShape()
230 throw(::com::sun::star::uno::RuntimeException
)
232 SolarMutexGuard aGuard
;
233 uno::Reference
< drawing::XShape
> xShape
;
234 if( const ScPostIt
* pNote
= ImplGetNote() )
235 if( SdrObject
* pCaption
= pNote
->GetOrCreateCaption( aCellPos
) )
236 xShape
.set( pCaption
->getUnoShape(), uno::UNO_QUERY
);
240 SvxUnoText
& ScAnnotationObj::GetUnoText()
244 ScAnnotationEditSource
aEditSource( pDocShell
, aCellPos
);
245 pUnoText
= new SvxUnoText( &aEditSource
, lcl_GetAnnotationPropertySet(),
246 uno::Reference
<text::XText
>() );
252 const ScPostIt
* ScAnnotationObj::ImplGetNote() const
254 return pDocShell
? pDocShell
->GetDocument()->GetNote(aCellPos
) : 0;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */