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