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