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 .
20 #include <textapi.hxx>
22 #include <IDocumentDrawModelAccess.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <editeng/editeng.hxx>
26 #include <editeng/outlobj.hxx>
27 #include <editeng/outliner.hxx>
28 #include <editeng/unoprnms.hxx>
29 #include <editeng/unoforou.hxx>
30 #include <editeng/unoipset.hxx>
32 #include <com/sun/star/text/XTextField.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/lang/Locale.hpp>
37 using namespace com::sun::star
;
39 static const SvxItemPropertySet
* ImplGetSvxTextPortionPropertySet()
41 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap
[] =
43 SVX_UNOEDIT_CHAR_PROPERTIES
,
44 SVX_UNOEDIT_FONT_PROPERTIES
,
45 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
46 SVX_UNOEDIT_PARA_PROPERTIES
,
47 {u
"TextField", EE_FEATURE_FIELD
,
48 cppu::UnoType
<text::XTextField
>::get(), beans::PropertyAttribute::READONLY
, 0 },
49 {u
"TextPortionType", WID_PORTIONTYPE
,
50 ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::READONLY
, 0 },
51 {u
"TextUserDefinedAttributes", EE_CHAR_XMLATTRIBS
,
52 cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
53 {u
"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS
,
54 cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
56 static SvxItemPropertySet
aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap
, EditEngine::GetGlobalItemPool() );
57 return &aSvxTextPortionPropertySet
;
60 SwTextAPIObject::SwTextAPIObject( std::unique_ptr
<SwTextAPIEditSource
> p
)
61 : SvxUnoText( p
.get(), ImplGetSvxTextPortionPropertySet(), uno::Reference
< text::XText
>() )
62 , m_pSource(std::move(p
))
66 SwTextAPIObject::~SwTextAPIObject() noexcept
72 struct SwTextAPIEditSource_Impl
74 // needed for "internal" refcounting
77 std::unique_ptr
<Outliner
> mpOutliner
;
78 std::unique_ptr
<SvxOutlinerForwarder
> mpTextForwarder
;
82 SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource
& rSource
)
83 : SvxEditSource( *this )
85 // shallow copy; uses internal refcounting
86 m_pImpl
= rSource
.m_pImpl
;
90 std::unique_ptr
<SvxEditSource
> SwTextAPIEditSource::Clone() const
92 return std::unique_ptr
<SvxEditSource
>(new SwTextAPIEditSource( *this ));
95 void SwTextAPIEditSource::UpdateData()
97 // data is kept in outliner all the time
100 SwTextAPIEditSource::SwTextAPIEditSource(SwDoc
* pDoc
)
101 : m_pImpl(new SwTextAPIEditSource_Impl
)
103 m_pImpl
->mpPool
= &pDoc
->GetDocShell()->GetPool();
104 m_pImpl
->mpDoc
= pDoc
;
108 SwTextAPIEditSource::~SwTextAPIEditSource()
110 if (!--m_pImpl
->mnRef
)
114 void SwTextAPIEditSource::Dispose()
116 m_pImpl
->mpPool
=nullptr;
117 m_pImpl
->mpDoc
=nullptr;
118 m_pImpl
->mpTextForwarder
.reset();
119 m_pImpl
->mpOutliner
.reset();
122 SvxTextForwarder
* SwTextAPIEditSource::GetTextForwarder()
124 if( !m_pImpl
->mpPool
)
125 return nullptr; // mpPool == 0 can be used to flag this as disposed
127 if( !m_pImpl
->mpOutliner
)
129 //init draw model first
130 m_pImpl
->mpDoc
->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
131 m_pImpl
->mpOutliner
.reset(new Outliner(m_pImpl
->mpPool
, OutlinerMode::TextObject
));
132 m_pImpl
->mpDoc
->SetCalcFieldValueHdl(m_pImpl
->mpOutliner
.get());
135 if( !m_pImpl
->mpTextForwarder
)
137 m_pImpl
->mpTextForwarder
.reset(new SvxOutlinerForwarder(*m_pImpl
->mpOutliner
, false));
140 return m_pImpl
->mpTextForwarder
.get();
143 void SwTextAPIEditSource::SetText( OutlinerParaObject
const & rText
)
145 if ( m_pImpl
->mpPool
)
147 if( !m_pImpl
->mpOutliner
)
149 //init draw model first
150 m_pImpl
->mpDoc
->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
151 m_pImpl
->mpOutliner
.reset(new Outliner(m_pImpl
->mpPool
, OutlinerMode::TextObject
));
152 m_pImpl
->mpDoc
->SetCalcFieldValueHdl(m_pImpl
->mpOutliner
.get());
155 m_pImpl
->mpOutliner
->SetText( rText
);
159 void SwTextAPIEditSource::SetString( const OUString
& rText
)
161 if ( !m_pImpl
->mpPool
)
164 if( !m_pImpl
->mpOutliner
)
166 //init draw model first
167 m_pImpl
->mpDoc
->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
168 m_pImpl
->mpOutliner
.reset(new Outliner(m_pImpl
->mpPool
, OutlinerMode::TextObject
));
169 m_pImpl
->mpDoc
->SetCalcFieldValueHdl(m_pImpl
->mpOutliner
.get());
172 m_pImpl
->mpOutliner
->Clear();
173 m_pImpl
->mpOutliner
->Insert( rText
);
176 std::optional
<OutlinerParaObject
> SwTextAPIEditSource::CreateText()
178 if ( m_pImpl
->mpPool
&& m_pImpl
->mpOutliner
)
179 return m_pImpl
->mpOutliner
->CreateParaObject();
184 OUString
SwTextAPIEditSource::GetText() const
186 if ( m_pImpl
->mpPool
&& m_pImpl
->mpOutliner
)
187 return m_pImpl
->mpOutliner
->GetEditEngine().GetText();
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */