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 SfxItemPool
* pEnginePool
= EditEngine::CreatePool();
145 pEnginePool
->FreezeIdRanges();
146 pEditEngine
.reset( new ScEditEngineDefaulter( pEnginePool
, true ) );
148 pForwarder
.reset( new SvxEditEngineForwarder(*pEditEngine
) );
152 return pForwarder
.get();
155 if ( ScPostIt
* pNote
= pDocShell
->GetDocument().GetNote(aCellPos
) )
156 if ( const EditTextObject
* pEditObj
= pNote
->GetEditTextObject() )
157 pEditEngine
->SetText( *pEditObj
); // incl. breaks (line, etc.)
160 return pForwarder
.get();
163 void ScAnnotationEditSource::UpdateData()
165 if ( pDocShell
&& pEditEngine
)
167 ScDocShellModificator
aModificator( *pDocShell
);
169 if( SdrObject
* pObj
= GetCaptionObj() )
171 std::unique_ptr
<EditTextObject
> pEditObj
= pEditEngine
->CreateTextObject();
172 std::unique_ptr
<OutlinerParaObject
> pOPO( new OutlinerParaObject( *pEditObj
) );
174 pOPO
->SetOutlinerMode( OutlinerMode::TextObject
);
175 pObj
->NbcSetOutlinerParaObject( std::move(pOPO
) );
176 pObj
->ActionChanged();
181 aModificator
.SetDocumentModified();
183 // SetDocumentModified will reset bDataValid
187 void ScAnnotationEditSource::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
189 if ( dynamic_cast<const ScUpdateRefHint
*>(&rHint
) )
195 const SfxHintId nId
= rHint
.GetId();
196 if ( nId
== SfxHintId::Dying
)
201 pEditEngine
.reset(); // EditEngine uses document's pool
203 else if ( nId
== SfxHintId::DataChanged
)
204 bDataValid
= false; // text must be retrieved again
208 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder
* pForw
) :
211 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
212 // Text range and cursor keep a reference to their parent text, so the text object is
213 // always alive and the forwarder is valid as long as there are children.
216 ScSimpleEditSource::~ScSimpleEditSource()
220 std::unique_ptr
<SvxEditSource
> ScSimpleEditSource::Clone() const
222 return std::unique_ptr
<SvxEditSource
>(new ScSimpleEditSource( pForwarder
));
225 SvxTextForwarder
* ScSimpleEditSource::GetTextForwarder()
230 void ScSimpleEditSource::UpdateData()
235 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr
< ScAccessibleTextData
> && pAccessibleCellTextData
)
236 : mpAccessibleTextData(std::move(pAccessibleCellTextData
))
240 ScAccessibilityEditSource::~ScAccessibilityEditSource()
244 std::unique_ptr
<SvxEditSource
> ScAccessibilityEditSource::Clone() const
246 return std::unique_ptr
<SvxEditSource
>(new ScAccessibilityEditSource(::std::unique_ptr
< ScAccessibleTextData
> (mpAccessibleTextData
->Clone())));
249 SvxTextForwarder
* ScAccessibilityEditSource::GetTextForwarder()
251 return mpAccessibleTextData
->GetTextForwarder();
254 SvxViewForwarder
* ScAccessibilityEditSource::GetViewForwarder()
256 return mpAccessibleTextData
->GetViewForwarder();
259 SvxEditViewForwarder
* ScAccessibilityEditSource::GetEditViewForwarder( bool bCreate
)
261 return mpAccessibleTextData
->GetEditViewForwarder(bCreate
);
264 void ScAccessibilityEditSource::UpdateData()
266 mpAccessibleTextData
->UpdateData();
269 SfxBroadcaster
& ScAccessibilityEditSource::GetBroadcaster() const
271 return mpAccessibleTextData
->GetBroadcaster();
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */