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