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 <docstyle.hxx>
25#include <strings.hrc>
26#include <SwStyleNameMapper.hxx>
27#include <unoprnms.hxx>
28#include <editeng/eeitem.hxx>
29#include <editeng/editeng.hxx>
30#include <editeng/outlobj.hxx>
31#include <editeng/outliner.hxx>
32#include <editeng/unoprnms.hxx>
33#include <editeng/unoforou.hxx>
34#include <editeng/unoipset.hxx>
35
36#include <com/sun/star/text/XTextField.hpp>
37#include <com/sun/star/container/XNameContainer.hpp>
38#include <com/sun/star/beans/PropertyAttribute.hpp>
39#include <com/sun/star/lang/Locale.hpp>
40
41using namespace com::sun::star;
42
44{
45 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
46 {
52 cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
53 {u"TextField", EE_FEATURE_FIELD,
54 cppu::UnoType<text::XTextField>::get(), beans::PropertyAttribute::READONLY, 0 },
55 {u"TextPortionType", WID_PORTIONTYPE,
56 ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
57 {u"TextUserDefinedAttributes", EE_CHAR_XMLATTRIBS,
59 {u"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS,
61 };
62 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
63 return &aSvxTextPortionPropertySet;
64}
65
66SwTextAPIObject::SwTextAPIObject( std::unique_ptr<SwTextAPIEditSource> p )
68, m_pSource(std::move(p))
69{
70}
71
73{
74 m_pSource->Dispose();
75 m_pSource.reset();
76}
77
79{
80 // needed for "internal" refcounting
83 std::unique_ptr<Outliner> mpOutliner;
84 std::unique_ptr<SvxOutlinerForwarder> mpTextForwarder;
85 sal_Int32 mnRef;
86};
87
88namespace {
89
90class SwTextAPIForwarder : public SvxOutlinerForwarder
91{
92public:
94 OUString GetStyleSheet(sal_Int32 nPara) const override
95 {
97 }
98
99 void SetStyleSheet(sal_Int32 nPara, const OUString& rStyleName) override
100 {
102 }
103};
104
105}
106
108: SvxEditSource( *this )
109{
110 // shallow copy; uses internal refcounting
111 m_pImpl = rSource.m_pImpl;
112 m_pImpl->mnRef++;
113}
114
115std::unique_ptr<SvxEditSource> SwTextAPIEditSource::Clone() const
116{
117 return std::unique_ptr<SvxEditSource>(new SwTextAPIEditSource( *this ));
118}
119
121{
122 // data is kept in outliner all the time
123}
124
127{
128 m_pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
129 m_pImpl->mpDoc = pDoc;
130 m_pImpl->mnRef = 1;
131}
132
134{
135 if (!--m_pImpl->mnRef)
136 delete m_pImpl;
137}
138
140{
141 m_pImpl->mpPool=nullptr;
142 m_pImpl->mpDoc=nullptr;
143 m_pImpl->mpTextForwarder.reset();
144 m_pImpl->mpOutliner.reset();
145}
146
148{
149 if( !m_pImpl->mpOutliner )
150 {
151 //init draw model first
153 m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject));
154 m_pImpl->mpOutliner->SetStyleSheetPool(
157 }
158}
159
161{
162 if( !m_pImpl->mpPool )
163 return nullptr; // mpPool == 0 can be used to flag this as disposed
164
166
168 {
169 m_pImpl->mpTextForwarder.reset(new SwTextAPIForwarder(*m_pImpl->mpOutliner, false));
170 }
171
172 return m_pImpl->mpTextForwarder.get();
173}
174
176{
177 if ( m_pImpl->mpPool )
178 {
180 m_pImpl->mpOutliner->SetText( rText );
181 }
182}
183
184void SwTextAPIEditSource::SetString( const OUString& rText )
185{
186 if ( !m_pImpl->mpPool )
187 return;
188
189 if ( m_pImpl->mpOutliner )
190 m_pImpl->mpOutliner->Clear();
191
193
194 if (auto pStyle = m_pImpl->mpOutliner->GetStyleSheetPool()->Find(SwResId(STR_POOLCOLL_COMMENT), SfxStyleFamily::Para))
195 m_pImpl->mpOutliner->SetStyleSheet(0, static_cast<SfxStyleSheet*>(pStyle));
196 m_pImpl->mpOutliner->Insert( rText );
197}
198
200{
201 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
202 return m_pImpl->mpOutliner->CreateParaObject();
203 else
204 return std::nullopt;
205}
206
208{
209 if ( m_pImpl->mpPool && m_pImpl->mpOutliner )
210 return m_pImpl->mpOutliner->GetEditEngine().GetText();
211 else
212 return OUString();
213}
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
static SfxItemPool & GetGlobalItemPool()
virtual SwDrawModel * GetOrCreateDrawModel()=0
SfxItemPool & GetPool() const
virtual OUString GetStyleSheet(sal_Int32 nPara) const override
virtual void SetStyleSheet(sal_Int32 nPara, const OUString &rStyleName) override
SvxOutlinerForwarder(Outliner &rOutl, bool bOutlText)
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1152
SfxStyleSheetPool * GetEEStyleSheetPool() const
Definition: docstyle.hxx:236
Definition: doc.hxx:197
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:169
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
void SetCalcFieldValueHdl(Outliner *pOutliner)
In the Outliner, set a link to the method for field display in edit objects.
Definition: docdraw.cxx:540
static const OUString & GetProgName(const OUString &rName, SwGetPoolIdFromName)
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
std::optional< OutlinerParaObject > CreateText()
Definition: textapi.cxx:199
OUString GetText() const
Definition: textapi.cxx:207
void SetText(OutlinerParaObject const &rText)
Definition: textapi.cxx:175
SwTextAPIEditSource_Impl * m_pImpl
Definition: textapi.hxx:32
void SetString(const OUString &rText)
Definition: textapi.cxx:184
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: textapi.cxx:115
virtual ~SwTextAPIEditSource() override
Definition: textapi.cxx:133
virtual void UpdateData() override
Definition: textapi.cxx:120
SwTextAPIEditSource(const SwTextAPIEditSource &rSource)
Definition: textapi.cxx:107
virtual SvxTextForwarder * GetTextForwarder() override
Definition: textapi.cxx:160
SwTextAPIObject(std::unique_ptr< SwTextAPIEditSource > p)
Definition: textapi.cxx:66
std::unique_ptr< SwTextAPIEditSource > m_pSource
Definition: textapi.hxx:53
virtual ~SwTextAPIObject() noexcept override
Definition: textapi.cxx:72
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:81
std::unique_ptr< SvxOutlinerForwarder > mpTextForwarder
Definition: textapi.cxx:84
std::unique_ptr< Outliner > mpOutliner
Definition: textapi.cxx:83
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
static const SvxItemPropertySet * ImplGetSvxTextPortionPropertySet()
Definition: textapi.cxx:43
constexpr OUStringLiteral UNO_NAME_PARA_STYLE_NAME
Definition: unoprnms.hxx:193
#define SVX_UNOEDIT_OUTLINER_PROPERTIES
#define SVX_UNOEDIT_CHAR_PROPERTIES
#define WID_PORTIONTYPE
#define SVX_UNOEDIT_PARA_PROPERTIES
#define WID_PARASTYLENAME
#define SVX_UNOEDIT_FONT_PROPERTIES