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()
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 {
120 // hamma nich
121 //! Exception oder so ??!
122 }
123
124 // XSimpleText
125
createTextCursor()126 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
127 {
128 ScUnoGuard aGuard;
129 // Notizen brauchen keine Extrawurst
130 return GetUnoText().createTextCursor();
131 }
132
createTextCursorByRange(const uno::Reference<text::XTextRange> & aTextPosition)133 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
134 const uno::Reference<text::XTextRange>& aTextPosition )
135 {
136 ScUnoGuard aGuard;
137 // Notizen brauchen keine Extrawurst
138 return GetUnoText().createTextCursorByRange(aTextPosition);
139 }
140
getString()141 rtl::OUString SAL_CALL ScAnnotationObj::getString()
142 {
143 ScUnoGuard aGuard;
144 return GetUnoText().getString();
145 }
146
setString(const rtl::OUString & aText)147 void SAL_CALL ScAnnotationObj::setString( const rtl::OUString& aText )
148 {
149 ScUnoGuard aGuard;
150 GetUnoText().setString(aText);
151 }
152
insertString(const uno::Reference<text::XTextRange> & xRange,const rtl::OUString & aString,sal_Bool bAbsorb)153 void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
154 const rtl::OUString& aString, sal_Bool bAbsorb )
155 {
156 ScUnoGuard aGuard;
157 GetUnoText().insertString( xRange, aString, bAbsorb );
158 }
159
insertControlCharacter(const uno::Reference<text::XTextRange> & xRange,sal_Int16 nControlCharacter,sal_Bool bAbsorb)160 void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
161 sal_Int16 nControlCharacter, sal_Bool bAbsorb )
162 {
163 ScUnoGuard aGuard;
164 GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
165 }
166
getText()167 uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText()
168 {
169 ScUnoGuard aGuard;
170 return GetUnoText().getText();
171 }
172
getStart()173 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart()
174 {
175 ScUnoGuard aGuard;
176 return GetUnoText().getStart();
177 }
178
getEnd()179 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd()
180 {
181 ScUnoGuard aGuard;
182 return GetUnoText().getEnd();
183 }
184
185 // XSheetAnnotation
186
getPosition()187 table::CellAddress SAL_CALL ScAnnotationObj::getPosition()
188 {
189 ScUnoGuard aGuard;
190 table::CellAddress aAdr;
191 aAdr.Sheet = aCellPos.Tab();
192 aAdr.Column = aCellPos.Col();
193 aAdr.Row = aCellPos.Row();
194 return aAdr;
195 }
196
getAuthor()197 rtl::OUString SAL_CALL ScAnnotationObj::getAuthor()
198 {
199 ScUnoGuard aGuard;
200 const ScPostIt* pNote = ImplGetNote();
201 return pNote ? pNote->GetAuthor() : rtl::OUString();
202 }
203
getDate()204 rtl::OUString SAL_CALL ScAnnotationObj::getDate()
205 {
206 ScUnoGuard aGuard;
207 const ScPostIt* pNote = ImplGetNote();
208 return pNote ? pNote->GetDate() : rtl::OUString();
209 }
210
getIsVisible()211 sal_Bool SAL_CALL ScAnnotationObj::getIsVisible()
212 {
213 ScUnoGuard aGuard;
214 const ScPostIt* pNote = ImplGetNote();
215 return pNote && pNote->IsCaptionShown();
216 }
217
setIsVisible(sal_Bool bIsVisible)218 void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible )
219 {
220 ScUnoGuard aGuard;
221 // show/hide note with undo action
222 if( pDocShell )
223 pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
224 }
225
226 // XSheetAnnotationShapeSupplier
getAnnotationShape()227 uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
228 {
229 ScUnoGuard aGuard;
230 uno::Reference < drawing::XShape > xShape;
231 if( const ScPostIt* pNote = ImplGetNote() )
232 if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) )
233 xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY );
234 return xShape;
235 }
236
GetUnoText()237 SvxUnoText& ScAnnotationObj::GetUnoText()
238 {
239 if (!pUnoText)
240 {
241 ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
242 pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
243 uno::Reference<text::XText>() );
244 pUnoText->acquire();
245 }
246 return *pUnoText;
247 }
248
ImplGetNote() const249 const ScPostIt* ScAnnotationObj::ImplGetNote() const
250 {
251 return pDocShell ? pDocShell->GetDocument()->GetNote( aCellPos ) : 0;
252 }
253
254 //------------------------------------------------------------------------
255