merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / fields / textapi.cxx
blobff794a0b6b32059ce21bcc1cedee942c00b29a74
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textapi.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <textapi.hxx>
35 #include <doc.hxx>
36 #include <docsh.hxx>
37 #include <svx/eeitem.hxx>
38 #include <svx/editeng.hxx>
40 #include <com/sun/star/text/XTextField.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 using namespace com::sun::star;
46 static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet()
48 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
50 SVX_UNOEDIT_CHAR_PROPERTIES,
51 SVX_UNOEDIT_FONT_PROPERTIES,
52 SVX_UNOEDIT_OUTLINER_PROPERTIES,
53 SVX_UNOEDIT_PARA_PROPERTIES,
54 {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD, &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 },
55 {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE, &::getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 },
56 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
57 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
58 {0,0,0,0,0,0}
60 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap );
61 return &aSvxTextPortionPropertySet;
64 SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p )
65 : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
66 , pSource(p)
70 SwTextAPIObject::~SwTextAPIObject() throw()
72 pSource->Dispose();
73 delete pSource;
76 struct SwTextAPIEditSource_Impl
78 // needed for "internal" refcounting
79 SfxItemPool* mpPool;
80 SwDoc* mpDoc;
81 Outliner* mpOutliner;
82 SvxOutlinerForwarder* mpTextForwarder;
83 sal_Int32 mnRef;
86 SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
87 : SvxEditSource( *this )
89 // shallow copy; uses internal refcounting
90 pImpl = rSource.pImpl;
91 pImpl->mnRef++;
94 SvxEditSource* SwTextAPIEditSource::Clone() const
96 return new SwTextAPIEditSource( *this );
99 void SwTextAPIEditSource::UpdateData()
101 // data is kept in outliner all the time
104 SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
105 : pImpl(new SwTextAPIEditSource_Impl)
107 pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
108 pImpl->mpDoc = pDoc;
109 pImpl->mpOutliner = 0;
110 pImpl->mpTextForwarder = 0;
111 pImpl->mnRef = 1;
114 SwTextAPIEditSource::~SwTextAPIEditSource()
116 if (!--pImpl->mnRef)
117 delete pImpl;
120 void SwTextAPIEditSource::Dispose()
122 pImpl->mpPool=0;
123 pImpl->mpDoc=0;
124 DELETEZ(pImpl->mpTextForwarder);
125 DELETEZ(pImpl->mpOutliner);
128 SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
130 if( !pImpl->mpPool )
131 return 0; // mpPool == 0 can be used to flag this as disposed
133 if( !pImpl->mpOutliner )
135 //init draw model first
136 pImpl->mpDoc->GetOrCreateDrawModel();
137 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
138 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
141 if( !pImpl->mpTextForwarder )
142 pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, 0 );
144 return pImpl->mpTextForwarder;
147 void SwTextAPIEditSource::SetText( OutlinerParaObject& rText )
149 if ( pImpl->mpPool )
151 if( !pImpl->mpOutliner )
153 //init draw model first
154 pImpl->mpDoc->GetOrCreateDrawModel();
155 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
156 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
159 pImpl->mpOutliner->SetText( rText );
163 void SwTextAPIEditSource::SetString( const String& rText )
165 if ( pImpl->mpPool )
167 if( !pImpl->mpOutliner )
169 //init draw model first
170 pImpl->mpDoc->GetOrCreateDrawModel();
171 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
172 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
174 else
175 pImpl->mpOutliner->Clear();
176 pImpl->mpOutliner->Insert( rText );
180 OutlinerParaObject* SwTextAPIEditSource::CreateText()
182 if ( pImpl->mpPool && pImpl->mpOutliner )
183 return pImpl->mpOutliner->CreateParaObject();
184 else
185 return 0;
188 String SwTextAPIEditSource::GetText()
190 if ( pImpl->mpPool && pImpl->mpOutliner )
191 return pImpl->mpOutliner->GetEditEngine().GetText();
192 else
193 return String();