Coverage Report

Created: 2026-11-06 11:29

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