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
38using namespace com::sun::star;
39
41{
42 static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
43 {
47 SVX_UNOEDIT_NUMBERING_PROPERTY, // 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
54SC_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)
73}
74
76{
77 if ( rHint.GetId() == SfxHintId::Dying )
78 {
79 pDocShell = nullptr; // became invalid
80 }
81}
82
83// XChild
84
85uno::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
98void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
99{
100 // ain't there
102}
103
104// XSimpleText
105
106uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
107{
108 SolarMutexGuard aGuard;
109 // notes does not need special treatment
110 return GetUnoText().createTextCursor();
111}
112
113uno::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
121OUString SAL_CALL ScAnnotationObj::getString()
122{
123 SolarMutexGuard aGuard;
124 return GetUnoText().getString();
125}
126
127void SAL_CALL ScAnnotationObj::setString( const OUString& aText )
128{
129 SolarMutexGuard aGuard;
130 GetUnoText().setString(aText);
131}
132
133void 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
140void 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
147uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText()
148{
149 SolarMutexGuard aGuard;
150 return GetUnoText().getText();
151}
152
153uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart()
154{
155 SolarMutexGuard aGuard;
156 return GetUnoText().getStart();
157}
158
159uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd()
160{
161 SolarMutexGuard aGuard;
162 return GetUnoText().getEnd();
163}
164
165// XSheetAnnotation
166
167table::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
177OUString SAL_CALL ScAnnotationObj::getAuthor()
178{
179 SolarMutexGuard aGuard;
180 const ScPostIt* pNote = ImplGetNote();
181 return pNote ? pNote->GetAuthor() : OUString();
182}
183
184OUString 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
198void 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
207uno::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 {
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: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SvxUnoText & GetUnoText()
Definition: notesuno.cxx:217
ScAddress aCellPos
Definition: notesuno.hxx:100
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
Definition: notesuno.cxx:98
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
XSimpleText.
Definition: notesuno.cxx:106
virtual css::uno::Reference< css::drawing::XShape > SAL_CALL getAnnotationShape() override
XSheetAnnotationShapeSupplier.
Definition: notesuno.cxx:207
virtual void SAL_CALL setIsVisible(sal_Bool bIsVisible) override
Definition: notesuno.cxx:198
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
XChild.
Definition: notesuno.cxx:85
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: notesuno.cxx:133
virtual sal_Bool SAL_CALL getIsVisible() override
Definition: notesuno.cxx:191
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: notesuno.cxx:153
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
XTextRange.
Definition: notesuno.cxx:147
virtual css::table::CellAddress SAL_CALL getPosition() override
XSheetAnnotation.
Definition: notesuno.cxx:167
ScDocShell * pDocShell
Definition: notesuno.hxx:99
virtual OUString SAL_CALL getDate() override
Definition: notesuno.cxx:184
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: notesuno.cxx:159
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: notesuno.cxx:75
virtual ~ScAnnotationObj() override
Definition: notesuno.cxx:67
virtual void SAL_CALL setString(const OUString &aString) override
Definition: notesuno.cxx:127
rtl::Reference< SvxUnoText > pUnoText
Definition: notesuno.hxx:101
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: notesuno.cxx:113
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 OUString SAL_CALL getString() override
Definition: notesuno.cxx:121
const ScPostIt * ImplGetNote() const
Definition: notesuno.cxx:228
virtual OUString SAL_CALL getAuthor() override
Definition: notesuno.cxx:177
really derive cell from range?
Definition: cellsuno.hxx:645
SC_DLLPUBLIC bool ShowNote(const ScAddress &rPos, bool bShow)
Definition: docfunc.cxx:1288
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:222
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6723
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
Additional class containing cell annotation data.
Definition: postit.hxx:161
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:209
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:214
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:255
static SdrItemPool & GetGlobalDrawObjectItemPool()
SfxHintId GetId() const
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
virtual void SAL_CALL setString(const OUString &aString) override
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
virtual OUString SAL_CALL getString() override
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
float u
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
static const SvxItemPropertySet * lcl_GetAnnotationPropertySet()
Definition: notesuno.cxx:40
unsigned char sal_Bool
#define SVX_UNOEDIT_CHAR_PROPERTIES
#define SVX_UNOEDIT_NUMBERING_PROPERTY
#define SVX_UNOEDIT_PARA_PROPERTIES
#define SVX_UNOEDIT_FONT_PROPERTIES