Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "notesuno.hxx"
21 :
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>
30 :
31 : #include "postit.hxx"
32 : #include "cellsuno.hxx"
33 : #include "docsh.hxx"
34 : #include "docfunc.hxx"
35 : #include "hints.hxx"
36 : #include "editsrc.hxx"
37 : #include "miscuno.hxx"
38 :
39 : using namespace com::sun::star;
40 :
41 10 : static const SvxItemPropertySet* lcl_GetAnnotationPropertySet()
42 : {
43 : static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
44 : {
45 196 : SVX_UNOEDIT_CHAR_PROPERTIES,
46 4 : SVX_UNOEDIT_FONT_PROPERTIES,
47 56 : SVX_UNOEDIT_PARA_PROPERTIES,
48 8 : SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
49 : { OUString(), 0, css::uno::Type(), 0, 0 }
50 278 : };
51 10 : static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
52 10 : return &aAnnotationPropertySet_Impl;
53 : }
54 :
55 0 : SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
56 : //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
57 :
58 24 : ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) :
59 : pDocShell( pDocSh ),
60 : aCellPos( rPos ),
61 24 : pUnoText( NULL )
62 : {
63 24 : pDocShell->GetDocument().AddUnoObject(*this);
64 :
65 : // pUnoText is allocated on demand (GetUnoText)
66 : // can't be aggregated because getString/setString is handled here
67 24 : }
68 :
69 72 : ScAnnotationObj::~ScAnnotationObj()
70 : {
71 24 : SolarMutexGuard g;
72 :
73 24 : if (pDocShell)
74 22 : pDocShell->GetDocument().RemoveUnoObject(*this);
75 :
76 24 : if (pUnoText)
77 10 : pUnoText->release();
78 48 : }
79 :
80 14 : void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
81 : {
82 14 : if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
83 : {
84 : // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
85 :
86 : //! Ref-Update
87 : }
88 28 : else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
89 14 : static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
90 : {
91 2 : pDocShell = NULL; // ungueltig geworden
92 : }
93 14 : }
94 :
95 : // XChild
96 :
97 0 : uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent() throw(uno::RuntimeException, std::exception)
98 : {
99 0 : SolarMutexGuard aGuard;
100 :
101 : // Parent der Notiz ist die zugehoerige Zelle
102 : //! existierendes Objekt finden und zurueckgeben ???
103 :
104 0 : if (pDocShell)
105 0 : return (cppu::OWeakObject*)new ScCellObj( pDocShell, aCellPos );
106 :
107 0 : return NULL;
108 : }
109 :
110 0 : void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
111 : throw(lang::NoSupportException, uno::RuntimeException, std::exception)
112 : {
113 : // hamma nich
114 : //! Exception oder so ??!
115 0 : }
116 :
117 : // XSimpleText
118 :
119 0 : uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
120 : throw(uno::RuntimeException, std::exception)
121 : {
122 0 : SolarMutexGuard aGuard;
123 : // Notizen brauchen keine Extrawurst
124 0 : return GetUnoText().createTextCursor();
125 : }
126 :
127 0 : uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
128 : const uno::Reference<text::XTextRange>& aTextPosition )
129 : throw(uno::RuntimeException, std::exception)
130 : {
131 0 : SolarMutexGuard aGuard;
132 : // Notizen brauchen keine Extrawurst
133 0 : return GetUnoText().createTextCursorByRange(aTextPosition);
134 : }
135 :
136 8 : OUString SAL_CALL ScAnnotationObj::getString() throw(uno::RuntimeException, std::exception)
137 : {
138 8 : SolarMutexGuard aGuard;
139 8 : return GetUnoText().getString();
140 : }
141 :
142 2 : void SAL_CALL ScAnnotationObj::setString( const OUString& aText ) throw(uno::RuntimeException, std::exception)
143 : {
144 2 : SolarMutexGuard aGuard;
145 2 : GetUnoText().setString(aText);
146 2 : }
147 :
148 0 : void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
149 : const OUString& aString, sal_Bool bAbsorb )
150 : throw(uno::RuntimeException, std::exception)
151 : {
152 0 : SolarMutexGuard aGuard;
153 0 : GetUnoText().insertString( xRange, aString, bAbsorb );
154 0 : }
155 :
156 0 : void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
157 : sal_Int16 nControlCharacter, sal_Bool bAbsorb )
158 : throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
159 : {
160 0 : SolarMutexGuard aGuard;
161 0 : GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
162 0 : }
163 :
164 0 : uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText() throw(uno::RuntimeException, std::exception)
165 : {
166 0 : SolarMutexGuard aGuard;
167 0 : return GetUnoText().getText();
168 : }
169 :
170 0 : uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart() throw(uno::RuntimeException, std::exception)
171 : {
172 0 : SolarMutexGuard aGuard;
173 0 : return GetUnoText().getStart();
174 : }
175 :
176 0 : uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd() throw(uno::RuntimeException, std::exception)
177 : {
178 0 : SolarMutexGuard aGuard;
179 0 : return GetUnoText().getEnd();
180 : }
181 :
182 : // XSheetAnnotation
183 :
184 10 : table::CellAddress SAL_CALL ScAnnotationObj::getPosition() throw(uno::RuntimeException, std::exception)
185 : {
186 10 : SolarMutexGuard aGuard;
187 10 : table::CellAddress aAdr;
188 10 : aAdr.Sheet = aCellPos.Tab();
189 10 : aAdr.Column = aCellPos.Col();
190 10 : aAdr.Row = aCellPos.Row();
191 10 : return aAdr;
192 : }
193 :
194 2 : OUString SAL_CALL ScAnnotationObj::getAuthor()
195 : throw(uno::RuntimeException, std::exception)
196 : {
197 2 : SolarMutexGuard aGuard;
198 2 : const ScPostIt* pNote = ImplGetNote();
199 2 : return pNote ? pNote->GetAuthor() : OUString();
200 : }
201 :
202 2 : OUString SAL_CALL ScAnnotationObj::getDate()
203 : throw(uno::RuntimeException, std::exception)
204 : {
205 2 : SolarMutexGuard aGuard;
206 2 : const ScPostIt* pNote = ImplGetNote();
207 2 : return pNote ? pNote->GetDate() : OUString();
208 : }
209 :
210 4 : sal_Bool SAL_CALL ScAnnotationObj::getIsVisible() throw(uno::RuntimeException, std::exception)
211 : {
212 4 : SolarMutexGuard aGuard;
213 4 : const ScPostIt* pNote = ImplGetNote();
214 4 : return pNote && pNote->IsCaptionShown();
215 : }
216 :
217 6 : void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible ) throw(uno::RuntimeException, std::exception)
218 : {
219 6 : SolarMutexGuard aGuard;
220 : // show/hide note with undo action
221 6 : if( pDocShell )
222 6 : pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
223 6 : }
224 :
225 : // XSheetAnnotationShapeSupplier
226 4 : uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
227 : throw(::com::sun::star::uno::RuntimeException,
228 : std::exception)
229 : {
230 4 : SolarMutexGuard aGuard;
231 4 : uno::Reference < drawing::XShape > xShape;
232 4 : if( const ScPostIt* pNote = ImplGetNote() )
233 4 : if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) )
234 4 : xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY );
235 4 : return xShape;
236 : }
237 :
238 10 : SvxUnoText& ScAnnotationObj::GetUnoText()
239 : {
240 10 : if (!pUnoText)
241 : {
242 10 : ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
243 : pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
244 10 : uno::Reference<text::XText>() );
245 10 : pUnoText->acquire();
246 : }
247 10 : return *pUnoText;
248 : }
249 :
250 12 : const ScPostIt* ScAnnotationObj::ImplGetNote() const
251 : {
252 12 : return pDocShell ? pDocShell->GetDocument().GetNote(aCellPos) : 0;
253 228 : }
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|