1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
39 class UndoTextAPIChanged
: public SdrUndoAction
42 UndoTextAPIChanged( SdrModel
& rModel
, TextApiObject
* pTextObj
);
43 virtual ~UndoTextAPIChanged();
45 virtual void Undo() SAL_OVERRIDE
;
46 virtual void Redo() SAL_OVERRIDE
;
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() )
58 , mxTextObj( pTextObj
)
62 UndoTextAPIChanged::~UndoTextAPIChanged()
68 void UndoTextAPIChanged::Undo()
71 mpNewText
= mxTextObj
->CreateText();
73 mxTextObj
->SetText( *mpOldText
);
76 void UndoTextAPIChanged::Redo()
80 mxTextObj
->SetText( *mpNewText
);
84 struct TextAPIEditSource_Impl
86 // needed for "internal" refcounting
87 SdDrawDocument
* mpDoc
;
89 SvxOutlinerForwarder
* mpTextForwarder
;
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
);
103 TextAPIEditSource(SdDrawDocument
* pDoc
);
104 virtual ~TextAPIEditSource();
107 void SetText( OutlinerParaObject
& rText
);
108 OutlinerParaObject
* CreateText();
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()
143 rtl::Reference
< TextApiObject
> TextApiObject::create( SdDrawDocument
* pDoc
)
145 rtl::Reference
< TextApiObject
> xRet( new TextApiObject( new TextAPIEditSource( pDoc
) ) );
149 void SAL_CALL
TextApiObject::dispose() throw(RuntimeException
)
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() );
185 pImpl
= dynamic_cast< TextApiObject
* >( SvxUnoTextBase::getImplementation( xText
) );
190 TextAPIEditSource::TextAPIEditSource( const TextAPIEditSource
& rSource
)
191 : SvxEditSource( *this )
193 // shallow copy; uses internal refcounting
194 pImpl
= rSource
.pImpl
;
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
)
212 pImpl
->mpOutliner
= 0;
213 pImpl
->mpTextForwarder
= 0;
217 TextAPIEditSource::~TextAPIEditSource()
223 void TextAPIEditSource::Dispose()
226 delete pImpl
->mpTextForwarder
;
227 pImpl
->mpTextForwarder
= 0;
229 delete pImpl
->mpOutliner
;
230 pImpl
->mpOutliner
= 0;
233 SvxTextForwarder
* TextAPIEditSource::GetTextForwarder()
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
)
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();
274 OUString
TextAPIEditSource::GetText()
276 if ( pImpl
->mpDoc
&& pImpl
->mpOutliner
)
277 return pImpl
->mpOutliner
->GetEditEngine().GetText();
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */