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