update emoji autocorrect entries from po-files
[LibreOffice.git] / sd / source / core / text / textapi.cxx
blob98a06fec314c36f473514d91b673dbd3eab67da6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/text/XTextField.hpp>
21 #include <com/sun/star/container/XNameContainer.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
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 "Outliner.hxx"
30 #include <svx/svdpool.hxx>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::text;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
37 namespace sd {
39 class UndoTextAPIChanged : public SdrUndoAction
41 public:
42 UndoTextAPIChanged( SdrModel& rModel, TextApiObject* pTextObj );
43 virtual ~UndoTextAPIChanged();
45 virtual void Undo() SAL_OVERRIDE;
46 virtual void Redo() SAL_OVERRIDE;
48 protected:
49 OutlinerParaObject* mpOldText;
50 OutlinerParaObject* mpNewText;
51 rtl::Reference< TextApiObject > mxTextObj;
54 UndoTextAPIChanged::UndoTextAPIChanged(SdrModel& rModel, TextApiObject* pTextObj )
55 : SdrUndoAction( rModel )
56 , mpOldText( pTextObj->CreateText() )
57 , mpNewText( 0 )
58 , mxTextObj( pTextObj )
62 UndoTextAPIChanged::~UndoTextAPIChanged()
64 delete mpOldText;
65 delete mpNewText;
68 void UndoTextAPIChanged::Undo()
70 if( !mpNewText )
71 mpNewText = mxTextObj->CreateText();
73 mxTextObj->SetText( *mpOldText );
76 void UndoTextAPIChanged::Redo()
78 if( mpNewText )
80 mxTextObj->SetText( *mpNewText );
84 struct TextAPIEditSource_Impl
86 // needed for "internal" refcounting
87 SdDrawDocument* mpDoc;
88 Outliner* mpOutliner;
89 SvxOutlinerForwarder* mpTextForwarder;
90 sal_Int32 mnRef;
93 class TextAPIEditSource : public SvxEditSource
95 TextAPIEditSource_Impl* pImpl;
97 virtual SvxEditSource* Clone() const SAL_OVERRIDE;
98 virtual SvxTextForwarder* GetTextForwarder() SAL_OVERRIDE;
99 virtual void UpdateData() SAL_OVERRIDE;
100 explicit TextAPIEditSource( const TextAPIEditSource& rSource );
102 public:
103 TextAPIEditSource(SdDrawDocument* pDoc);
104 virtual ~TextAPIEditSource();
106 void Dispose();
107 void SetText( OutlinerParaObject& rText );
108 OutlinerParaObject* CreateText();
109 OUString GetText();
110 SdDrawDocument* GetDoc() { return pImpl->mpDoc; }
113 const SvxItemPropertySet* ImplGetSdTextPortionPropertyMap()
115 static const SfxItemPropertyMapEntry aSdTextPortionPropertyEntries[] =
117 SVX_UNOEDIT_CHAR_PROPERTIES,
118 SVX_UNOEDIT_FONT_PROPERTIES,
119 SVX_UNOEDIT_OUTLINER_PROPERTIES,
120 SVX_UNOEDIT_PARA_PROPERTIES,
121 {OUString("TextField"), EE_FEATURE_FIELD, cppu::UnoType<XTextField>::get(), PropertyAttribute::READONLY, 0 },
122 {OUString("TextPortionType"), WID_PORTIONTYPE, ::cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
123 {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, cppu::UnoType<XNameContainer>::get(), 0, 0},
124 {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, cppu::UnoType<XNameContainer>::get(), 0, 0},
125 { OUString(), 0, css::uno::Type(), 0, 0 }
127 static SvxItemPropertySet aSdTextPortionPropertyMap( aSdTextPortionPropertyEntries, SdrObject::GetGlobalDrawObjectItemPool() );
129 return &aSdTextPortionPropertyMap;
132 TextApiObject::TextApiObject( TextAPIEditSource* pEditSource )
133 : SvxUnoText( pEditSource, ImplGetSdTextPortionPropertyMap(), Reference < XText >() )
134 , mpSource(pEditSource)
138 TextApiObject::~TextApiObject() throw()
140 dispose();
143 rtl::Reference< TextApiObject > TextApiObject::create( SdDrawDocument* pDoc )
145 rtl::Reference< TextApiObject > xRet( new TextApiObject( new TextAPIEditSource( pDoc ) ) );
146 return xRet;
149 void SAL_CALL TextApiObject::dispose() throw(RuntimeException)
151 if( mpSource )
153 mpSource->Dispose();
154 delete mpSource;
155 mpSource = 0;
160 OutlinerParaObject* TextApiObject::CreateText()
162 return mpSource->CreateText();
165 void TextApiObject::SetText( OutlinerParaObject& rText )
167 SdrModel* pModel = mpSource->GetDoc();
168 if( pModel && pModel->IsUndoEnabled() )
169 pModel->AddUndo( new UndoTextAPIChanged( *pModel, this ) );
171 mpSource->SetText( rText );
172 maSelection.nStartPara = EE_PARA_MAX_COUNT;
175 OUString TextApiObject::GetText()
177 return mpSource->GetText();
180 TextApiObject* TextApiObject::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& xText )
182 TextApiObject* pImpl = dynamic_cast< TextApiObject* >( xText.get() );
184 if( !pImpl )
185 pImpl = dynamic_cast< TextApiObject* >( SvxUnoTextBase::getImplementation( xText ) );
187 return pImpl;
190 TextAPIEditSource::TextAPIEditSource( const TextAPIEditSource& rSource )
191 : SvxEditSource( *this )
193 // shallow copy; uses internal refcounting
194 pImpl = rSource.pImpl;
195 pImpl->mnRef++;
198 SvxEditSource* TextAPIEditSource::Clone() const
200 return new TextAPIEditSource( *this );
203 void TextAPIEditSource::UpdateData()
205 // data is kept in outliner all the time
208 TextAPIEditSource::TextAPIEditSource(SdDrawDocument* pDoc)
209 : pImpl(new TextAPIEditSource_Impl)
211 pImpl->mpDoc = pDoc;
212 pImpl->mpOutliner = 0;
213 pImpl->mpTextForwarder = 0;
214 pImpl->mnRef = 1;
217 TextAPIEditSource::~TextAPIEditSource()
219 if (!--pImpl->mnRef)
220 delete pImpl;
223 void TextAPIEditSource::Dispose()
225 pImpl->mpDoc=0;
226 delete pImpl->mpTextForwarder;
227 pImpl->mpTextForwarder = 0;
229 delete pImpl->mpOutliner;
230 pImpl->mpOutliner = 0;
233 SvxTextForwarder* TextAPIEditSource::GetTextForwarder()
235 if( !pImpl->mpDoc )
236 return 0; // mpDoc == 0 can be used to flag this as disposed
238 if( !pImpl->mpOutliner )
240 //init draw model first
241 pImpl->mpOutliner = new Outliner( pImpl->mpDoc, OUTLINERMODE_TEXTOBJECT );
242 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
245 if( !pImpl->mpTextForwarder )
246 pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, false );
248 return pImpl->mpTextForwarder;
251 void TextAPIEditSource::SetText( OutlinerParaObject& rText )
253 if ( pImpl->mpDoc )
255 if( !pImpl->mpOutliner )
257 //init draw model first
258 pImpl->mpOutliner = new Outliner( pImpl->mpDoc, OUTLINERMODE_TEXTOBJECT );
259 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
262 pImpl->mpOutliner->SetText( rText );
266 OutlinerParaObject* TextAPIEditSource::CreateText()
268 if ( pImpl->mpDoc && pImpl->mpOutliner )
269 return pImpl->mpOutliner->CreateParaObject();
270 else
271 return 0;
274 OUString TextAPIEditSource::GetText()
276 if ( pImpl->mpDoc && pImpl->mpOutliner )
277 return pImpl->mpOutliner->GetEditEngine().GetText();
278 else
279 return OUString();
282 } // namespace sd
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */