tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / notesuno.cxx
blob3869f24ffde680e477a6035d499362fc8e30a8e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <notesuno.hxx>
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>
31 #include <postit.hxx>
32 #include <cellsuno.hxx>
33 #include <docsh.hxx>
34 #include <docfunc.hxx>
35 #include <editsrc.hxx>
36 #include <miscuno.hxx>
38 using namespace com::sun::star;
40 static const SvxItemPropertySet* lcl_GetAnnotationPropertySet()
42 static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
44 SVX_UNOEDIT_CHAR_PROPERTIES,
45 SVX_UNOEDIT_FONT_PROPERTIES,
46 SVX_UNOEDIT_PARA_PROPERTIES,
47 SVX_UNOEDIT_NUMBERING_PROPERTY, // for completeness of service ParagraphProperties
49 static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
50 return &aAnnotationPropertySet_Impl;
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" )
56 ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) :
57 pDocShell( pDocSh ),
58 aCellPos( rPos )
60 pDocShell->GetDocument().AddUnoObject(*this);
62 // pUnoText is allocated on demand (GetUnoText)
63 // can't be aggregated because getString/setString is handled here
66 ScAnnotationObj::~ScAnnotationObj()
68 SolarMutexGuard g;
70 if (pDocShell)
71 pDocShell->GetDocument().RemoveUnoObject(*this);
74 void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
76 if ( rHint.GetId() == SfxHintId::Dying )
78 pDocShell = nullptr; // became invalid
82 // XChild
84 uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent()
86 SolarMutexGuard aGuard;
88 // parent of note is the related cell
89 //! find and reset existing object ???
91 if (pDocShell)
92 return cppu::getXWeak(new ScCellObj( pDocShell, aCellPos ));
94 return nullptr;
97 void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
99 // ain't there
100 //! exception or what ??!
103 // XSimpleText
105 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
107 SolarMutexGuard aGuard;
108 // notes does not need special treatment
109 return GetUnoText().createTextCursor();
112 uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
113 const uno::Reference<text::XTextRange>& aTextPosition )
115 SolarMutexGuard aGuard;
116 // notes does not need special treatment
117 return GetUnoText().createTextCursorByRange(aTextPosition);
120 OUString SAL_CALL ScAnnotationObj::getString()
122 SolarMutexGuard aGuard;
123 return GetUnoText().getString();
126 void SAL_CALL ScAnnotationObj::setString( const OUString& aText )
128 SolarMutexGuard aGuard;
129 GetUnoText().setString(aText);
132 void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
133 const OUString& aString, sal_Bool bAbsorb )
135 SolarMutexGuard aGuard;
136 GetUnoText().insertString( xRange, aString, bAbsorb );
139 void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
140 sal_Int16 nControlCharacter, sal_Bool bAbsorb )
142 SolarMutexGuard aGuard;
143 GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
146 uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText()
148 SolarMutexGuard aGuard;
149 return GetUnoText().getText();
152 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart()
154 SolarMutexGuard aGuard;
155 return GetUnoText().getStart();
158 uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd()
160 SolarMutexGuard aGuard;
161 return GetUnoText().getEnd();
164 // XSheetAnnotation
166 table::CellAddress SAL_CALL ScAnnotationObj::getPosition()
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;
176 OUString SAL_CALL ScAnnotationObj::getAuthor()
178 SolarMutexGuard aGuard;
179 const ScPostIt* pNote = ImplGetNote();
180 return pNote ? pNote->GetAuthor() : OUString();
183 OUString SAL_CALL ScAnnotationObj::getDate()
185 SolarMutexGuard aGuard;
186 const ScPostIt* pNote = ImplGetNote();
187 return pNote ? pNote->GetDate() : OUString();
190 sal_Bool SAL_CALL ScAnnotationObj::getIsVisible()
192 SolarMutexGuard aGuard;
193 const ScPostIt* pNote = ImplGetNote();
194 return pNote && pNote->IsCaptionShown();
197 void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible )
199 SolarMutexGuard aGuard;
200 // show/hide note with undo action
201 if( pDocShell )
202 pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
205 // XSheetAnnotationShapeSupplier
206 uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
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;
216 SvxUnoText& ScAnnotationObj::GetUnoText()
218 if (!pUnoText.is())
220 ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
221 pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
222 uno::Reference<text::XText>() );
224 return *pUnoText;
227 const ScPostIt* ScAnnotationObj::ImplGetNote() const
229 return pDocShell ? pDocShell->GetDocument().GetNote(aCellPos) : nullptr;
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */