LibreOffice Module sd (master) 1
textapi.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/beans/PropertyAttribute.hpp>
21#include <com/sun/star/lang/Locale.hpp>
22#include <com/sun/star/text/XTextField.hpp>
23
24#include <textapi.hxx>
25#include <drawdoc.hxx>
26#include <editeng/eeitem.hxx>
27#include <editeng/editeng.hxx>
28#include <editeng/outlobj.hxx>
29#include <editeng/unoforou.hxx>
30#include <editeng/unoprnms.hxx>
31#include <editeng/unoipset.hxx>
32#include <Outliner.hxx>
33#include <svx/svdpool.hxx>
34#include <svx/svdundo.hxx>
35
36namespace com::sun::star::container { class XNameContainer; }
37
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::text;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::container;
42
43namespace sd {
44
45namespace {
46
47class UndoTextAPIChanged : public SdrUndoAction
48{
49public:
50 UndoTextAPIChanged( SdrModel& rModel, TextApiObject* pTextObj );
51
52 virtual void Undo() override;
53 virtual void Redo() override;
54
55protected:
59};
60
61}
62
63UndoTextAPIChanged::UndoTextAPIChanged(SdrModel& rModel, TextApiObject* pTextObj )
64: SdrUndoAction( rModel )
65, mpOldText( pTextObj->CreateText() )
66, mxTextObj( pTextObj )
67{
68}
69
70void UndoTextAPIChanged::Undo()
71{
72 if( !mpNewText )
73 mpNewText = mxTextObj->CreateText();
74
75 mxTextObj->SetText( *mpOldText );
76}
77
78void UndoTextAPIChanged::Redo()
79{
80 if( mpNewText )
81 {
82 mxTextObj->SetText( *mpNewText );
83 }
84}
85
86namespace {
87
88struct TextAPIEditSource_Impl
89{
90 SdDrawDocument* mpDoc;
91 Outliner* mpOutliner;
92 SvxOutlinerForwarder* mpTextForwarder;
93};
94
95}
96
98{
99 // refcounted
100 std::shared_ptr<TextAPIEditSource_Impl> m_xImpl;
101
102 virtual std::unique_ptr<SvxEditSource> Clone() const override;
103 virtual SvxTextForwarder* GetTextForwarder() override;
104 virtual void UpdateData() override;
105 explicit TextAPIEditSource( const TextAPIEditSource& rSource );
106
107public:
108 explicit TextAPIEditSource(SdDrawDocument* pDoc);
109
110 void Dispose();
111 void SetText( OutlinerParaObject const & rText );
113 OUString GetText() const;
114 SdDrawDocument* GetDoc() { return m_xImpl->mpDoc; }
115};
116
118{
119 static const SfxItemPropertyMapEntry aSdTextPortionPropertyEntries[] =
120 {
125 {u"TextField", EE_FEATURE_FIELD, cppu::UnoType<XTextField>::get(), PropertyAttribute::READONLY, 0 },
126 {u"TextPortionType", WID_PORTIONTYPE, ::cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
127 {u"TextUserDefinedAttributes", EE_CHAR_XMLATTRIBS, cppu::UnoType<XNameContainer>::get(), 0, 0},
128 {u"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS, cppu::UnoType<XNameContainer>::get(), 0, 0},
129 };
130 static SvxItemPropertySet aSdTextPortionPropertyMap( aSdTextPortionPropertyEntries, SdrObject::GetGlobalDrawObjectItemPool() );
131
132 return &aSdTextPortionPropertyMap;
133}
134
135TextApiObject::TextApiObject( std::unique_ptr<TextAPIEditSource> pEditSource )
136: SvxUnoText( pEditSource.get(), ImplGetSdTextPortionPropertyMap(), Reference < XText >() )
137, mpSource(std::move(pEditSource))
138{
139}
140
142{
143 dispose();
144}
145
147{
148 rtl::Reference< TextApiObject > xRet( new TextApiObject( std::make_unique<TextAPIEditSource>( pDoc ) ) );
149 return xRet;
150}
151
153{
154 if( mpSource )
155 {
156 mpSource->Dispose();
157 mpSource.reset();
158 }
159
160}
161
163{
164 return mpSource->CreateText();
165}
166
168{
169 SdrModel* pModel = mpSource->GetDoc();
170 if( pModel && pModel->IsUndoEnabled() )
171 pModel->AddUndo( std::make_unique<UndoTextAPIChanged>( *pModel, this ) );
172
173 mpSource->SetText( rText );
174 maSelection.nStartPara = EE_PARA_MAX_COUNT;
175}
176
178{
179 return mpSource->GetText();
180}
181
182TextApiObject* TextApiObject::getImplementation( const css::uno::Reference< css::text::XText >& xText )
183{
184 TextApiObject* pImpl = dynamic_cast< TextApiObject* >( xText.get() );
185
186 if( !pImpl )
187 pImpl = dynamic_cast< TextApiObject* >( comphelper::getFromUnoTunnel<SvxUnoTextBase>( xText ) );
188
189 return pImpl;
190}
191
193 : SvxEditSource(*this)
194 , m_xImpl(rSource.m_xImpl) // shallow copy; uses internal refcounting
195{
196}
197
198std::unique_ptr<SvxEditSource> TextAPIEditSource::Clone() const
199{
200 return std::unique_ptr<SvxEditSource>(new TextAPIEditSource( *this ));
201}
202
204{
205 // data is kept in outliner all the time
206}
207
209: m_xImpl(std::make_shared<TextAPIEditSource_Impl>())
210{
211 m_xImpl->mpDoc = pDoc;
212 m_xImpl->mpOutliner = nullptr;
213 m_xImpl->mpTextForwarder = nullptr;
214}
215
217{
218 m_xImpl->mpDoc=nullptr;
219 delete m_xImpl->mpTextForwarder;
220 m_xImpl->mpTextForwarder = nullptr;
221
222 delete m_xImpl->mpOutliner;
223 m_xImpl->mpOutliner = nullptr;
224}
225
227{
228 if(!m_xImpl->mpDoc)
229 return nullptr; // mpDoc == 0 can be used to flag this as disposed
230
231 if (!m_xImpl->mpOutliner)
232 {
233 //init draw model first
234 m_xImpl->mpOutliner = new SdOutliner(m_xImpl->mpDoc, OutlinerMode::TextObject);
236 }
237
238 if (!m_xImpl->mpTextForwarder)
239 m_xImpl->mpTextForwarder = new SvxOutlinerForwarder(*m_xImpl->mpOutliner, false);
240
241 return m_xImpl->mpTextForwarder;
242}
243
245{
246 if (m_xImpl->mpDoc)
247 {
248 if (!m_xImpl->mpOutliner)
249 {
250 //init draw model first
251 m_xImpl->mpOutliner = new SdOutliner(m_xImpl->mpDoc, OutlinerMode::TextObject);
253 }
254
255 m_xImpl->mpOutliner->SetText( rText );
256 }
257}
258
260{
261 if (m_xImpl->mpDoc && m_xImpl->mpOutliner)
262 return m_xImpl->mpOutliner->CreateParaObject();
263 else
264 return std::nullopt;
265}
266
268{
269 if (m_xImpl->mpDoc && m_xImpl->mpOutliner)
270 return m_xImpl->mpOutliner->GetEditEngine().GetText();
271 else
272 return OUString();
273}
274
275} // namespace sd
276
277/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SAL_DLLPRIVATE void SetCalcFieldValueHdl(::Outliner *pOutliner)
Definition: drawdoc.cxx:1079
The main purpose of this class is searching and replacing as well as spelling of impress documents.
Definition: Outliner.hxx:123
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
bool IsUndoEnabled() const
static SdrItemPool & GetGlobalDrawObjectItemPool()
css::uno::Type const & get()
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: textapi.cxx:198
TextAPIEditSource(const TextAPIEditSource &rSource)
Definition: textapi.cxx:192
OUString GetText() const
Definition: textapi.cxx:267
void SetText(OutlinerParaObject const &rText)
Definition: textapi.cxx:244
virtual void UpdateData() override
Definition: textapi.cxx:203
SdDrawDocument * GetDoc()
Definition: textapi.cxx:114
std::shared_ptr< TextAPIEditSource_Impl > m_xImpl
Definition: textapi.cxx:100
std::optional< OutlinerParaObject > CreateText()
Definition: textapi.cxx:259
virtual SvxTextForwarder * GetTextForwarder() override
Definition: textapi.cxx:226
std::unique_ptr< TextAPIEditSource > mpSource
Definition: textapi.hxx:49
std::optional< OutlinerParaObject > CreateText()
Definition: textapi.cxx:162
static rtl::Reference< TextApiObject > create(SdDrawDocument *pDoc)
Definition: textapi.cxx:146
OUString GetText() const
Definition: textapi.cxx:177
void SetText(OutlinerParaObject const &rText)
Definition: textapi.cxx:167
virtual ~TextApiObject() noexcept override
Definition: textapi.cxx:141
static TextApiObject * getImplementation(const css::uno::Reference< css::text::XText > &)
Definition: textapi.cxx:182
TextApiObject(std::unique_ptr< TextAPIEditSource > pEditSource)
Definition: textapi.cxx:135
virtual void SetText(const OUString &rStr) override
float u
#define EE_PARA_MAX_COUNT
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
constexpr TypedWhichId< SvXMLAttrContainerItem > EE_PARA_XMLATTRIBS(EE_PARA_START+1)
constexpr TypedWhichId< SvXMLAttrContainerItem > EE_CHAR_XMLATTRIBS(EE_CHAR_START+28)
void Dispose(const T &xInterface)
Reference
std::shared_ptr< T > make_shared(Args &&... args)
static const SvxItemPropertySet * ImplGetSdTextPortionPropertyMap()
Definition: textapi.cxx:117
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define SVX_UNOEDIT_OUTLINER_PROPERTIES
#define SVX_UNOEDIT_CHAR_PROPERTIES
#define WID_PORTIONTYPE
#define SVX_UNOEDIT_PARA_PROPERTIES
#define SVX_UNOEDIT_FONT_PROPERTIES