nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / fields / textapi.cxx
blob511f5df9e87c570e610d76d2b9cba01751a4ed5a
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 <textapi.hxx>
21 #include <doc.hxx>
22 #include <IDocumentDrawModelAccess.hxx>
23 #include <docsh.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},
55 { u"", 0, css::uno::Type(), 0, 0 }
57 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
58 return &aSvxTextPortionPropertySet;
61 SwTextAPIObject::SwTextAPIObject( std::unique_ptr<SwTextAPIEditSource> p )
62 : SvxUnoText( p.get(), ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
63 , m_pSource(std::move(p))
67 SwTextAPIObject::~SwTextAPIObject() throw()
69 m_pSource->Dispose();
70 m_pSource.reset();
73 struct SwTextAPIEditSource_Impl
75 // needed for "internal" refcounting
76 SfxItemPool* mpPool;
77 SwDoc* mpDoc;
78 std::unique_ptr<Outliner> mpOutliner;
79 std::unique_ptr<SvxOutlinerForwarder> mpTextForwarder;
80 sal_Int32 mnRef;
83 SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
84 : SvxEditSource( *this )
86 // shallow copy; uses internal refcounting
87 m_pImpl = rSource.m_pImpl;
88 m_pImpl->mnRef++;
91 std::unique_ptr<SvxEditSource> SwTextAPIEditSource::Clone() const
93 return std::unique_ptr<SvxEditSource>(new SwTextAPIEditSource( *this ));
96 void SwTextAPIEditSource::UpdateData()
98 // data is kept in outliner all the time
101 SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
102 : m_pImpl(new SwTextAPIEditSource_Impl)
104 m_pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
105 m_pImpl->mpDoc = pDoc;
106 m_pImpl->mnRef = 1;
109 SwTextAPIEditSource::~SwTextAPIEditSource()
111 if (!--m_pImpl->mnRef)
112 delete m_pImpl;
115 void SwTextAPIEditSource::Dispose()
117 m_pImpl->mpPool=nullptr;
118 m_pImpl->mpDoc=nullptr;
119 m_pImpl->mpTextForwarder.reset();
120 m_pImpl->mpOutliner.reset();
123 SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
125 if( !m_pImpl->mpPool )
126 return nullptr; // mpPool == 0 can be used to flag this as disposed
128 if( !m_pImpl->mpOutliner )
130 //init draw model first
131 m_pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
132 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
133 m_pImpl->mpDoc->SetCalcFieldValueHdl(m_pImpl->mpOutliner.get());
136 if( !m_pImpl->mpTextForwarder )
138 m_pImpl->mpTextForwarder.reset(new SvxOutlinerForwarder(*m_pImpl->mpOutliner, false));
141 return m_pImpl->mpTextForwarder.get();
144 void SwTextAPIEditSource::SetText( OutlinerParaObject const & rText )
146 if ( m_pImpl->mpPool )
148 if( !m_pImpl->mpOutliner )
150 //init draw model first
151 m_pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
152 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
153 m_pImpl->mpDoc->SetCalcFieldValueHdl(m_pImpl->mpOutliner.get());
156 m_pImpl->mpOutliner->SetText( rText );
160 void SwTextAPIEditSource::SetString( const OUString& rText )
162 if ( !m_pImpl->mpPool )
163 return;
165 if( !m_pImpl->mpOutliner )
167 //init draw model first
168 m_pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
169 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
170 m_pImpl->mpDoc->SetCalcFieldValueHdl(m_pImpl->mpOutliner.get());
172 else
173 m_pImpl->mpOutliner->Clear();
174 m_pImpl->mpOutliner->Insert( rText );
177 std::unique_ptr<OutlinerParaObject> SwTextAPIEditSource::CreateText()
179 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
180 return m_pImpl->mpOutliner->CreateParaObject();
181 else
182 return nullptr;
185 OUString SwTextAPIEditSource::GetText() const
187 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
188 return m_pImpl->mpOutliner->GetEditEngine().GetText();
189 else
190 return OUString();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */