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>
25 #include <editeng/eeitem.hxx>
26 #include <editeng/editeng.hxx>
27 #include <editeng/outlobj.hxx>
28 #include <editeng/outliner.hxx>
29 #include <editeng/unoprnms.hxx>
30 #include <editeng/unoforou.hxx>
31 #include <editeng/unoipset.hxx>
32 
33 #include <com/sun/star/text/XTextField.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/lang/Locale.hpp>
37 
38 using namespace com::sun::star;
39 
41 {
42  static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
43  {
48  {OUString("TextField"), EE_FEATURE_FIELD,
49  cppu::UnoType<text::XTextField>::get(), beans::PropertyAttribute::READONLY, 0 },
50  {OUString("TextPortionType"), WID_PORTIONTYPE,
51  ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
52  {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS,
54  {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS,
56  { OUString(), 0, css::uno::Type(), 0, 0 }
57  };
58  static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
59  return &aSvxTextPortionPropertySet;
60 }
61 
62 SwTextAPIObject::SwTextAPIObject( std::unique_ptr<SwTextAPIEditSource> p )
64 , pSource(std::move(p))
65 {
66 }
67 
69 {
70  pSource->Dispose();
71  pSource.reset();
72 }
73 
75 {
76  // needed for "internal" refcounting
79  std::unique_ptr<Outliner> mpOutliner;
80  std::unique_ptr<SvxOutlinerForwarder> mpTextForwarder;
81  sal_Int32 mnRef;
82 };
83 
85 : SvxEditSource( *this )
86 {
87  // shallow copy; uses internal refcounting
88  pImpl = rSource.pImpl;
89  pImpl->mnRef++;
90 }
91 
92 std::unique_ptr<SvxEditSource> SwTextAPIEditSource::Clone() const
93 {
94  return std::unique_ptr<SvxEditSource>(new SwTextAPIEditSource( *this ));
95 }
96 
98 {
99  // data is kept in outliner all the time
100 }
101 
103 : pImpl(new SwTextAPIEditSource_Impl)
104 {
105  pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
106  pImpl->mpDoc = pDoc;
107  pImpl->mnRef = 1;
108 }
109 
111 {
112  if (!--pImpl->mnRef)
113  delete pImpl;
114 }
115 
117 {
118  pImpl->mpPool=nullptr;
119  pImpl->mpDoc=nullptr;
120  pImpl->mpTextForwarder.reset();
121  pImpl->mpOutliner.reset();
122 }
123 
125 {
126  if( !pImpl->mpPool )
127  return nullptr; // mpPool == 0 can be used to flag this as disposed
128 
129  if( !pImpl->mpOutliner )
130  {
131  //init draw model first
133  pImpl->mpOutliner.reset(new Outliner(pImpl->mpPool, OutlinerMode::TextObject));
135  }
136 
137  if( !pImpl->mpTextForwarder )
138  {
140  }
141 
142  return pImpl->mpTextForwarder.get();
143 }
144 
146 {
147  if ( pImpl->mpPool )
148  {
149  if( !pImpl->mpOutliner )
150  {
151  //init draw model first
153  pImpl->mpOutliner.reset(new Outliner(pImpl->mpPool, OutlinerMode::TextObject));
155  }
156 
157  pImpl->mpOutliner->SetText( rText );
158  }
159 }
160 
161 void SwTextAPIEditSource::SetString( const OUString& rText )
162 {
163  if ( pImpl->mpPool )
164  {
165  if( !pImpl->mpOutliner )
166  {
167  //init draw model first
169  pImpl->mpOutliner.reset(new Outliner(pImpl->mpPool, OutlinerMode::TextObject));
171  }
172  else
173  pImpl->mpOutliner->Clear();
174  pImpl->mpOutliner->Insert( rText );
175  }
176 }
177 
178 std::unique_ptr<OutlinerParaObject> SwTextAPIEditSource::CreateText()
179 {
180  if ( pImpl->mpPool && pImpl->mpOutliner )
181  return pImpl->mpOutliner->CreateParaObject();
182  else
183  return nullptr;
184 }
185 
187 {
188  if ( pImpl->mpPool && pImpl->mpOutliner )
189  return pImpl->mpOutliner->GetEditEngine().GetText();
190  else
191  return OUString();
192 }
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SwDocShell * GetDocShell()
Definition: doc.hxx:1340
Definition: doc.hxx:185
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:491
#define SVX_UNOEDIT_OUTLINER_PROPERTIES
virtual void UpdateData() override
Definition: textapi.cxx:97
virtual SvxTextForwarder * GetTextForwarder() override
Definition: textapi.cxx:124
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:187
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: textapi.cxx:92
OUString GetText()
Definition: textapi.cxx:186
std::unique_ptr< SwTextAPIEditSource > pSource
Definition: textapi.hxx:52
SfxItemPool & GetPool() const
#define EE_PARA_XMLATTRIBS
std::unique_ptr< Outliner > mpOutliner
Definition: textapi.cxx:79
std::unique_ptr< SvxOutlinerForwarder > mpTextForwarder
Definition: textapi.cxx:80
#define EE_FEATURE_FIELD
#define EE_CHAR_XMLATTRIBS
SwTextAPIEditSource(const SwTextAPIEditSource &rSource)
Definition: textapi.cxx:84
css::uno::Type const & get()
SwTextAPIObject(std::unique_ptr< SwTextAPIEditSource > p)
Definition: textapi.cxx:62
#define SVX_UNOEDIT_FONT_PROPERTIES
static const SvxItemPropertySet * ImplGetSvxTextPortionPropertySet()
Definition: textapi.cxx:40
#define SVX_UNOEDIT_PARA_PROPERTIES
virtual SwDrawModel * GetOrCreateDrawModel()=0
SfxItemPool * mpPool
Definition: textapi.cxx:77
def text(shape, st)
void SetString(const OUString &rText)
Definition: textapi.cxx:161
static SfxItemPool & GetGlobalItemPool()
std::unique_ptr< OutlinerParaObject > CreateText()
Definition: textapi.cxx:178
virtual ~SwTextAPIObject() override
Definition: textapi.cxx:68
virtual ~SwTextAPIEditSource() override
Definition: textapi.cxx:110
void SetText(OutlinerParaObject const &rText)
Definition: textapi.cxx:145
#define SVX_UNOEDIT_CHAR_PROPERTIES
#define WID_PORTIONTYPE