1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <sal/config.h>
25 #include <editsrc.hxx>
27 #include <editeng/unofored.hxx>
28 #include <vcl/svapp.hxx>
29 #include <svx/svdocapt.hxx>
30 #include <editeng/outlobj.hxx>
31 #include <editeng/editobj.hxx>
32 #include <editeng/outliner.hxx>
33 #include <textuno.hxx>
34 #include <editutil.hxx>
38 #include <AccessibleText.hxx>
40 ScHeaderFooterEditSource::ScHeaderFooterEditSource(ScHeaderFooterTextData
& rData
) :
43 ScHeaderFooterEditSource::~ScHeaderFooterEditSource() {}
45 ScEditEngineDefaulter
* ScHeaderFooterEditSource::GetEditEngine()
47 return mrTextData
.GetEditEngine();
50 std::unique_ptr
<SvxEditSource
> ScHeaderFooterEditSource::Clone() const
52 return std::unique_ptr
<SvxEditSource
>(new ScHeaderFooterEditSource(mrTextData
));
55 SvxTextForwarder
* ScHeaderFooterEditSource::GetTextForwarder()
57 return mrTextData
.GetTextForwarder();
60 void ScHeaderFooterEditSource::UpdateData()
62 mrTextData
.UpdateData();
65 ScCellEditSource::ScCellEditSource(ScDocShell
* pDocSh
, const ScAddress
& rP
) :
66 pCellTextData(new ScCellTextData(pDocSh
, rP
)) {}
68 ScCellEditSource::~ScCellEditSource()
72 std::unique_ptr
<SvxEditSource
> ScCellEditSource::Clone() const
74 return std::unique_ptr
<SvxEditSource
>(new ScCellEditSource(pCellTextData
->GetDocShell(), pCellTextData
->GetCellPos()));
77 SvxTextForwarder
* ScCellEditSource::GetTextForwarder()
79 return pCellTextData
->GetTextForwarder();
82 void ScCellEditSource::UpdateData()
84 pCellTextData
->UpdateData();
87 void ScCellEditSource::SetDoUpdateData(bool bValue
)
89 pCellTextData
->SetDoUpdate(bValue
);
92 bool ScCellEditSource::IsDirty() const
94 return pCellTextData
->IsDirty();
97 ScEditEngineDefaulter
* ScCellEditSource::GetEditEngine()
99 return pCellTextData
->GetEditEngine();
102 ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell
* pDocSh
, const ScAddress
& rP
) :
108 pDocShell
->GetDocument().AddUnoObject(*this);
111 ScAnnotationEditSource::~ScAnnotationEditSource()
113 SolarMutexGuard aGuard
; // needed for EditEngine dtor
116 pDocShell
->GetDocument().RemoveUnoObject(*this);
122 std::unique_ptr
<SvxEditSource
> ScAnnotationEditSource::Clone() const
124 return std::unique_ptr
<SvxEditSource
>(new ScAnnotationEditSource( pDocShell
, aCellPos
));
127 SdrObject
* ScAnnotationEditSource::GetCaptionObj()
129 ScPostIt
* pNote
= pDocShell
->GetDocument().GetNote(aCellPos
);
130 return pNote
? pNote
->GetOrCreateCaption( aCellPos
) : nullptr;
133 SvxTextForwarder
* ScAnnotationEditSource::GetTextForwarder()
137 // notes don't have fields
140 pEditEngine
.reset( new ScNoteEditEngine( pDocShell
->GetDocument().GetNoteEngine() ) );
144 rtl::Reference
<SfxItemPool
> pEnginePool
= EditEngine::CreatePool();
145 pEditEngine
.reset( new ScEditEngineDefaulter( pEnginePool
.get(), true ) );
147 pForwarder
.reset( new SvxEditEngineForwarder(*pEditEngine
) );
151 return pForwarder
.get();
154 if ( ScPostIt
* pNote
= pDocShell
->GetDocument().GetNote(aCellPos
) )
155 if ( const EditTextObject
* pEditObj
= pNote
->GetEditTextObject() )
156 pEditEngine
->SetTextCurrentDefaults( *pEditObj
); // incl. breaks (line, etc.)
159 return pForwarder
.get();
162 void ScAnnotationEditSource::UpdateData()
164 if ( !(pDocShell
&& pEditEngine
) )
167 ScDocShellModificator
aModificator( *pDocShell
);
169 if( SdrObject
* pObj
= GetCaptionObj() )
171 OutlinerParaObject
aOPO( pEditEngine
->CreateTextObject() );
172 aOPO
.SetOutlinerMode( OutlinerMode::TextObject
);
173 pObj
->NbcSetOutlinerParaObject( std::move(aOPO
) );
174 pObj
->ActionChanged();
179 aModificator
.SetDocumentModified();
181 // SetDocumentModified will reset bDataValid
184 void ScAnnotationEditSource::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
186 if ( rHint
.GetId() == SfxHintId::ScUpdateRef
)
192 const SfxHintId nId
= rHint
.GetId();
193 if ( nId
== SfxHintId::Dying
)
198 pEditEngine
.reset(); // EditEngine uses document's pool
200 else if ( nId
== SfxHintId::DataChanged
)
201 bDataValid
= false; // text must be retrieved again
205 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder
* pForw
) :
208 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
209 // Text range and cursor keep a reference to their parent text, so the text object is
210 // always alive and the forwarder is valid as long as there are children.
213 ScSimpleEditSource::~ScSimpleEditSource()
217 std::unique_ptr
<SvxEditSource
> ScSimpleEditSource::Clone() const
219 return std::unique_ptr
<SvxEditSource
>(new ScSimpleEditSource( pForwarder
));
222 SvxTextForwarder
* ScSimpleEditSource::GetTextForwarder()
227 void ScSimpleEditSource::UpdateData()
232 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr
< ScAccessibleTextData
> && pAccessibleCellTextData
)
233 : mpAccessibleTextData(std::move(pAccessibleCellTextData
))
237 ScAccessibilityEditSource::~ScAccessibilityEditSource()
241 std::unique_ptr
<SvxEditSource
> ScAccessibilityEditSource::Clone() const
243 return std::unique_ptr
<SvxEditSource
>(new ScAccessibilityEditSource(::std::unique_ptr
< ScAccessibleTextData
> (mpAccessibleTextData
->Clone())));
246 SvxTextForwarder
* ScAccessibilityEditSource::GetTextForwarder()
248 return mpAccessibleTextData
->GetTextForwarder();
251 SvxViewForwarder
* ScAccessibilityEditSource::GetViewForwarder()
253 return mpAccessibleTextData
->GetViewForwarder();
256 SvxEditViewForwarder
* ScAccessibilityEditSource::GetEditViewForwarder( bool bCreate
)
258 return mpAccessibleTextData
->GetEditViewForwarder(bCreate
);
261 void ScAccessibilityEditSource::UpdateData()
263 mpAccessibleTextData
->UpdateData();
266 SfxBroadcaster
& ScAccessibilityEditSource::GetBroadcaster() const
268 return mpAccessibleTextData
->GetBroadcaster();
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */