LibreOffice Module sw (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 <textapi.hxx>
21#include <doc.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>
31
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>
36
37using namespace com::sun::star;
38
40{
41 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
42 {
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,
53 {u"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS,
55 };
56 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
57 return &aSvxTextPortionPropertySet;
58}
59
60SwTextAPIObject::SwTextAPIObject( std::unique_ptr<SwTextAPIEditSource> p )
62, m_pSource(std::move(p))
63{
64}
65
67{
68 m_pSource->Dispose();
69 m_pSource.reset();
70}
71
73{
74 // needed for "internal" refcounting
77 std::unique_ptr<Outliner> mpOutliner;
78 std::unique_ptr<SvxOutlinerForwarder> mpTextForwarder;
79 sal_Int32 mnRef;
80};
81
83: SvxEditSource( *this )
84{
85 // shallow copy; uses internal refcounting
86 m_pImpl = rSource.m_pImpl;
87 m_pImpl->mnRef++;
88}
89
90std::unique_ptr<SvxEditSource> SwTextAPIEditSource::Clone() const
91{
92 return std::unique_ptr<SvxEditSource>(new SwTextAPIEditSource( *this ));
93}
94
96{
97 // data is kept in outliner all the time
98}
99
102{
103 m_pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
104 m_pImpl->mpDoc = pDoc;
105 m_pImpl->mnRef = 1;
106}
107
109{
110 if (!--m_pImpl->mnRef)
111 delete m_pImpl;
112}
113
115{
116 m_pImpl->mpPool=nullptr;
117 m_pImpl->mpDoc=nullptr;
118 m_pImpl->mpTextForwarder.reset();
119 m_pImpl->mpOutliner.reset();
120}
121
123{
124 if( !m_pImpl->mpPool )
125 return nullptr; // mpPool == 0 can be used to flag this as disposed
126
127 if( !m_pImpl->mpOutliner )
128 {
129 //init draw model first
131 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
133 }
134
136 {
138 }
139
140 return m_pImpl->mpTextForwarder.get();
141}
142
144{
145 if ( m_pImpl->mpPool )
146 {
147 if( !m_pImpl->mpOutliner )
148 {
149 //init draw model first
151 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
153 }
154
155 m_pImpl->mpOutliner->SetText( rText );
156 }
157}
158
159void SwTextAPIEditSource::SetString( const OUString& rText )
160{
161 if ( !m_pImpl->mpPool )
162 return;
163
164 if( !m_pImpl->mpOutliner )
165 {
166 //init draw model first
168 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
170 }
171 else
172 m_pImpl->mpOutliner->Clear();
173 m_pImpl->mpOutliner->Insert( rText );
174}
175
177{
178 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
179 return m_pImpl->mpOutliner->CreateParaObject();
180 else
181 return std::nullopt;
182}
183
185{
186 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
187 return m_pImpl->mpOutliner->GetEditEngine().GetText();
188 else
189 return OUString();
190}
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
static SfxItemPool & GetGlobalItemPool()
virtual SwDrawModel * GetOrCreateDrawModel()=0
SfxItemPool & GetPool() const
Definition: doc.hxx:195
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:163
SwDocShell * GetDocShell()
Definition: doc.hxx:1364
void SetCalcFieldValueHdl(Outliner *pOutliner)
In the Outliner, set a link to the method for field display in edit objects.
Definition: docdraw.cxx:540
std::optional< OutlinerParaObject > CreateText()
Definition: textapi.cxx:176
OUString GetText() const
Definition: textapi.cxx:184
void SetText(OutlinerParaObject const &rText)
Definition: textapi.cxx:143
SwTextAPIEditSource_Impl * m_pImpl
Definition: textapi.hxx:32
void SetString(const OUString &rText)
Definition: textapi.cxx:159
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: textapi.cxx:90
virtual ~SwTextAPIEditSource() override
Definition: textapi.cxx:108
virtual void UpdateData() override
Definition: textapi.cxx:95
SwTextAPIEditSource(const SwTextAPIEditSource &rSource)
Definition: textapi.cxx:82
virtual SvxTextForwarder * GetTextForwarder() override
Definition: textapi.cxx:122
SwTextAPIObject(std::unique_ptr< SwTextAPIEditSource > p)
Definition: textapi.cxx:60
std::unique_ptr< SwTextAPIEditSource > m_pSource
Definition: textapi.hxx:52
virtual ~SwTextAPIObject() noexcept override
Definition: textapi.cxx:66
css::uno::Type const & get()
float u
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 * p
def text(shape, orig_st)
Reference
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SfxItemPool * mpPool
Definition: textapi.cxx:75
std::unique_ptr< SvxOutlinerForwarder > mpTextForwarder
Definition: textapi.cxx:78
std::unique_ptr< Outliner > mpOutliner
Definition: textapi.cxx:77
static const SvxItemPropertySet * ImplGetSvxTextPortionPropertySet()
Definition: textapi.cxx:39
#define SVX_UNOEDIT_OUTLINER_PROPERTIES
#define SVX_UNOEDIT_CHAR_PROPERTIES
#define WID_PORTIONTYPE
#define SVX_UNOEDIT_PARA_PROPERTIES
#define SVX_UNOEDIT_FONT_PROPERTIES