LibreOffice Module sc (master)  1
notesuno.cxx
Go to the documentation of this file.
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/hint.hxx>
24 #include <editeng/unoipset.hxx>
25 #include <editeng/unotext.hxx>
26 #include <editeng/unoprnms.hxx>
27 #include <svx/svdpool.hxx>
28 #include <svx/svdobj.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 <editsrc.hxx>
36 #include <miscuno.hxx>
37 
38 using namespace com::sun::star;
39 
41 {
42  static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
43  {
47  SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
48  { u"", 0, css::uno::Type(), 0, 0 }
49  };
50  static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
51  return &aAnnotationPropertySet_Impl;
52 }
53 
54 SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
55 //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
56 
58  pDocShell( pDocSh ),
59  aCellPos( rPos )
60 {
61  pDocShell->GetDocument().AddUnoObject(*this);
62 
63  // pUnoText is allocated on demand (GetUnoText)
64  // can't be aggregated because getString/setString is handled here
65 }
66 
68 {
70 
71  if (pDocShell)
72  pDocShell->GetDocument().RemoveUnoObject(*this);
73 }
74 
76 {
77  if ( rHint.GetId() == SfxHintId::Dying )
78  {
79  pDocShell = nullptr; // became invalid
80  }
81 }
82 
83 // XChild
84 
85 uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent()
86 {
87  SolarMutexGuard aGuard;
88 
89  // parent of note is the related cell
91 
92  if (pDocShell)
93  return static_cast<cppu::OWeakObject*>(new ScCellObj( pDocShell, aCellPos ));
94 
95  return nullptr;
96 }
97 
98 void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
99 {
100  // ain't there
102 }
103 
104 // XSimpleText
105 
106 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
107 {
108  SolarMutexGuard aGuard;
109  // notes does not need special treatment
110  return GetUnoText().createTextCursor();
111 }
112 
113 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
114  const uno::Reference<text::XTextRange>& aTextPosition )
115 {
116  SolarMutexGuard aGuard;
117  // notes does not need special treatment
118  return GetUnoText().createTextCursorByRange(aTextPosition);
119 }
120 
121 OUString SAL_CALL ScAnnotationObj::getString()
122 {
123  SolarMutexGuard aGuard;
124  return GetUnoText().getString();
125 }
126 
127 void SAL_CALL ScAnnotationObj::setString( const OUString& aText )
128 {
129  SolarMutexGuard aGuard;
130  GetUnoText().setString(aText);
131 }
132 
133 void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
134  const OUString& aString, sal_Bool bAbsorb )
135 {
136  SolarMutexGuard aGuard;
137  GetUnoText().insertString( xRange, aString, bAbsorb );
138 }
139 
140 void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
141  sal_Int16 nControlCharacter, sal_Bool bAbsorb )
142 {
143  SolarMutexGuard aGuard;
144  GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
145 }
146 
147 uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText()
148 {
149  SolarMutexGuard aGuard;
150  return GetUnoText().getText();
151 }
152 
153 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart()
154 {
155  SolarMutexGuard aGuard;
156  return GetUnoText().getStart();
157 }
158 
159 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd()
160 {
161  SolarMutexGuard aGuard;
162  return GetUnoText().getEnd();
163 }
164 
165 // XSheetAnnotation
166 
167 table::CellAddress SAL_CALL ScAnnotationObj::getPosition()
168 {
169  SolarMutexGuard aGuard;
170  table::CellAddress aAdr;
171  aAdr.Sheet = aCellPos.Tab();
172  aAdr.Column = aCellPos.Col();
173  aAdr.Row = aCellPos.Row();
174  return aAdr;
175 }
176 
177 OUString SAL_CALL ScAnnotationObj::getAuthor()
178 {
179  SolarMutexGuard aGuard;
180  const ScPostIt* pNote = ImplGetNote();
181  return pNote ? pNote->GetAuthor() : OUString();
182 }
183 
184 OUString SAL_CALL ScAnnotationObj::getDate()
185 {
186  SolarMutexGuard aGuard;
187  const ScPostIt* pNote = ImplGetNote();
188  return pNote ? pNote->GetDate() : OUString();
189 }
190 
192 {
193  SolarMutexGuard aGuard;
194  const ScPostIt* pNote = ImplGetNote();
195  return pNote && pNote->IsCaptionShown();
196 }
197 
198 void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible )
199 {
200  SolarMutexGuard aGuard;
201  // show/hide note with undo action
202  if( pDocShell )
203  pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
204 }
205 
206 // XSheetAnnotationShapeSupplier
207 uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
208 {
209  SolarMutexGuard aGuard;
210  uno::Reference < drawing::XShape > xShape;
211  if( const ScPostIt* pNote = ImplGetNote() )
212  if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) )
213  xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY );
214  return xShape;
215 }
216 
218 {
219  if (!pUnoText.is())
220  {
221  ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
222  pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
223  uno::Reference<text::XText>() );
224  }
225  return *pUnoText;
226 }
227 
229 {
230  return pDocShell ? pDocShell->GetDocument().GetNote(aCellPos) : nullptr;
231 }
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:214
virtual OUString SAL_CALL getAuthor() override
Definition: notesuno.cxx:177
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: notesuno.cxx:153
virtual css::table::CellAddress SAL_CALL getPosition() override
XSheetAnnotation.
Definition: notesuno.cxx:167
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
XTextRange.
Definition: notesuno.cxx:147
SfxHintId GetId() const
virtual ~ScAnnotationObj() override
Definition: notesuno.cxx:67
Additional class containing cell annotation data.
Definition: postit.hxx:160
virtual OUString SAL_CALL getString() override
Definition: notesuno.cxx:121
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: notesuno.cxx:75
virtual css::uno::Reference< css::drawing::XShape > SAL_CALL getAnnotationShape() override
XSheetAnnotationShapeSupplier.
Definition: notesuno.cxx:207
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
XChild.
Definition: notesuno.cxx:85
virtual void SAL_CALL setString(const OUString &aString) override
Definition: notesuno.cxx:127
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
XSimpleText.
Definition: notesuno.cxx:106
#define SVX_UNOEDIT_NUMBERING_PROPERTIE
SvxUnoText & GetUnoText()
Definition: notesuno.cxx:217
float u
unsigned char sal_Bool
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: notesuno.cxx:133
#define SVX_UNOEDIT_FONT_PROPERTIES
virtual void SAL_CALL setIsVisible(sal_Bool bIsVisible) override
Definition: notesuno.cxx:198
const ScPostIt * ImplGetNote() const
Definition: notesuno.cxx:228
static SdrItemPool & GetGlobalDrawObjectItemPool()
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: notesuno.cxx:140
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
Definition: notesuno.cxx:98
#define SVX_UNOEDIT_PARA_PROPERTIES
really derive cell from range?
Definition: cellsuno.hxx:634
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:209
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: notesuno.cxx:159
#define SVX_UNOEDIT_CHAR_PROPERTIES
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: notesuno.cxx:113
virtual OUString SAL_CALL getDate() override
Definition: notesuno.cxx:184
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:255
static const SvxItemPropertySet * lcl_GetAnnotationPropertySet()
Definition: notesuno.cxx:40
virtual sal_Bool SAL_CALL getIsVisible() override
Definition: notesuno.cxx:191