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