xref: /AOO41X/main/sc/source/ui/unoobj/notesuno.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "notesuno.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svl/smplhint.hxx>
30cdf0e10cSrcweir #include <editeng/unotext.hxx>
31cdf0e10cSrcweir #include <svx/svdpool.hxx>
32cdf0e10cSrcweir #include <svx/svdobj.hxx>
33cdf0e10cSrcweir #include <svx/unoshape.hxx>
34cdf0e10cSrcweir #include <svx/svdocapt.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "postit.hxx"
37cdf0e10cSrcweir #include "cellsuno.hxx"
38cdf0e10cSrcweir #include "docsh.hxx"
39cdf0e10cSrcweir #include "docfunc.hxx"
40cdf0e10cSrcweir #include "hints.hxx"
41cdf0e10cSrcweir #include "editsrc.hxx"
42cdf0e10cSrcweir #include "miscuno.hxx"
43cdf0e10cSrcweir #include "unoguard.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace com::sun::star;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //------------------------------------------------------------------------
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //	keine Properties fuer Text in Notizen
lcl_GetAnnotationPropertySet()50cdf0e10cSrcweir const SvxItemPropertySet* lcl_GetAnnotationPropertySet()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     static SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir         {0,0,0,0,0,0}
55cdf0e10cSrcweir 	};
56cdf0e10cSrcweir 	static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
57cdf0e10cSrcweir 	return &aAnnotationPropertySet_Impl;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //------------------------------------------------------------------------
61cdf0e10cSrcweir 
62cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
63cdf0e10cSrcweir //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //------------------------------------------------------------------------
66cdf0e10cSrcweir 
ScAnnotationObj(ScDocShell * pDocSh,const ScAddress & rPos)67cdf0e10cSrcweir ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) :
68cdf0e10cSrcweir 	pDocShell( pDocSh ),
69cdf0e10cSrcweir 	aCellPos( rPos ),
70cdf0e10cSrcweir 	pUnoText( NULL )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	//	pUnoText is allocated on demand (GetUnoText)
75cdf0e10cSrcweir 	//	can't be aggregated because getString/setString is handled here
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
~ScAnnotationObj()78cdf0e10cSrcweir ScAnnotationObj::~ScAnnotationObj()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	if (pDocShell)
81cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	if (pUnoText)
84cdf0e10cSrcweir 		pUnoText->release();
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)87cdf0e10cSrcweir void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	if ( rHint.ISA( ScUpdateRefHint ) )
90cdf0e10cSrcweir 	{
91cdf0e10cSrcweir //        const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		//!	Ref-Update
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 	else if ( rHint.ISA( SfxSimpleHint ) &&
96cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // XChild
104cdf0e10cSrcweir 
getParent()105cdf0e10cSrcweir uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent() throw(uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	ScUnoGuard aGuard;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//	Parent der Notiz ist die zugehoerige Zelle
110cdf0e10cSrcweir 	//!	existierendes Objekt finden und zurueckgeben ???
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	if (pDocShell)
113cdf0e10cSrcweir 		return (cppu::OWeakObject*)new ScCellObj( pDocShell, aCellPos );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	return NULL;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
setParent(const uno::Reference<uno::XInterface> &)118cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
119cdf0e10cSrcweir 									throw(lang::NoSupportException, uno::RuntimeException)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	//	hamma nich
122cdf0e10cSrcweir 	//!	Exception oder so ??!
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // XSimpleText
126cdf0e10cSrcweir 
createTextCursor()127cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
128cdf0e10cSrcweir 													throw(uno::RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	ScUnoGuard aGuard;
131cdf0e10cSrcweir 	//	Notizen brauchen keine Extrawurst
132cdf0e10cSrcweir 	return GetUnoText().createTextCursor();
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
createTextCursorByRange(const uno::Reference<text::XTextRange> & aTextPosition)135cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
136cdf0e10cSrcweir 									const uno::Reference<text::XTextRange>& aTextPosition )
137cdf0e10cSrcweir 													throw(uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	ScUnoGuard aGuard;
140cdf0e10cSrcweir 	//	Notizen brauchen keine Extrawurst
141cdf0e10cSrcweir 	return GetUnoText().createTextCursorByRange(aTextPosition);
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
getString()144cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getString() throw(uno::RuntimeException)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	ScUnoGuard aGuard;
147cdf0e10cSrcweir 	return GetUnoText().getString();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
setString(const rtl::OUString & aText)150cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	ScUnoGuard aGuard;
153cdf0e10cSrcweir     GetUnoText().setString(aText);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
insertString(const uno::Reference<text::XTextRange> & xRange,const rtl::OUString & aString,sal_Bool bAbsorb)156cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
157cdf0e10cSrcweir 											const rtl::OUString& aString, sal_Bool bAbsorb )
158cdf0e10cSrcweir 								throw(uno::RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	ScUnoGuard aGuard;
161cdf0e10cSrcweir 	GetUnoText().insertString( xRange, aString, bAbsorb );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
insertControlCharacter(const uno::Reference<text::XTextRange> & xRange,sal_Int16 nControlCharacter,sal_Bool bAbsorb)164cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
165cdf0e10cSrcweir 											sal_Int16 nControlCharacter, sal_Bool bAbsorb )
166cdf0e10cSrcweir 								throw(lang::IllegalArgumentException, uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	ScUnoGuard aGuard;
169cdf0e10cSrcweir 	GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
getText()172cdf0e10cSrcweir uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText() throw(uno::RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	ScUnoGuard aGuard;
175cdf0e10cSrcweir 	return GetUnoText().getText();
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
getStart()178cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart() throw(uno::RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	ScUnoGuard aGuard;
181cdf0e10cSrcweir 	return GetUnoText().getStart();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
getEnd()184cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd() throw(uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	ScUnoGuard aGuard;
187cdf0e10cSrcweir 	return GetUnoText().getEnd();
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir // XSheetAnnotation
191cdf0e10cSrcweir 
getPosition()192cdf0e10cSrcweir table::CellAddress SAL_CALL ScAnnotationObj::getPosition() throw(uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	ScUnoGuard aGuard;
195cdf0e10cSrcweir 	table::CellAddress aAdr;
196cdf0e10cSrcweir 	aAdr.Sheet	= aCellPos.Tab();
197cdf0e10cSrcweir 	aAdr.Column	= aCellPos.Col();
198cdf0e10cSrcweir 	aAdr.Row	= aCellPos.Row();
199cdf0e10cSrcweir 	return aAdr;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
getAuthor()202cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getAuthor() throw(uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     ScUnoGuard aGuard;
205cdf0e10cSrcweir     const ScPostIt* pNote = ImplGetNote();
206cdf0e10cSrcweir     return pNote ? pNote->GetAuthor() : rtl::OUString();
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
getDate()209cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getDate() throw(uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     ScUnoGuard aGuard;
212cdf0e10cSrcweir     const ScPostIt* pNote = ImplGetNote();
213cdf0e10cSrcweir     return pNote ? pNote->GetDate() : rtl::OUString();
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
getIsVisible()216cdf0e10cSrcweir sal_Bool SAL_CALL ScAnnotationObj::getIsVisible() throw(uno::RuntimeException)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     ScUnoGuard aGuard;
219cdf0e10cSrcweir     const ScPostIt* pNote = ImplGetNote();
220cdf0e10cSrcweir     return pNote && pNote->IsCaptionShown();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
setIsVisible(sal_Bool bIsVisible)223cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible ) throw(uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     ScUnoGuard aGuard;
226cdf0e10cSrcweir     // show/hide note with undo action
227cdf0e10cSrcweir     if( pDocShell )
228cdf0e10cSrcweir         pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir // XSheetAnnotationShapeSupplier
getAnnotationShape()232cdf0e10cSrcweir uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
233cdf0e10cSrcweir                                 throw(::com::sun::star::uno::RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     ScUnoGuard aGuard;
236cdf0e10cSrcweir     uno::Reference < drawing::XShape > xShape;
237cdf0e10cSrcweir     if( const ScPostIt* pNote = ImplGetNote() )
238cdf0e10cSrcweir         if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) )
239cdf0e10cSrcweir             xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY );
240cdf0e10cSrcweir 	return xShape;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
GetUnoText()243cdf0e10cSrcweir SvxUnoText& ScAnnotationObj::GetUnoText()
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     if (!pUnoText)
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
248cdf0e10cSrcweir         pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
249cdf0e10cSrcweir                                     uno::Reference<text::XText>() );
250cdf0e10cSrcweir         pUnoText->acquire();
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir     return *pUnoText;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
ImplGetNote() const255cdf0e10cSrcweir const ScPostIt* ScAnnotationObj::ImplGetNote() const
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     return pDocShell ? pDocShell->GetDocument()->GetNote( aCellPos ) : 0;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir //------------------------------------------------------------------------
261