1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <textapi.hxx> 32 #include <doc.hxx> 33 #include <docsh.hxx> 34 #include <editeng/eeitem.hxx> 35 #include <editeng/editeng.hxx> 36 37 #include <com/sun/star/text/XTextField.hpp> 38 #include <com/sun/star/container/XNameContainer.hpp> 39 #include <com/sun/star/beans/PropertyAttribute.hpp> 40 41 using namespace com::sun::star; 42 43 static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet() 44 { 45 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] = 46 { 47 SVX_UNOEDIT_CHAR_PROPERTIES, 48 SVX_UNOEDIT_FONT_PROPERTIES, 49 SVX_UNOEDIT_OUTLINER_PROPERTIES, 50 SVX_UNOEDIT_PARA_PROPERTIES, 51 {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD, &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 }, 52 {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE, &::getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, 53 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 54 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 55 {0,0,0,0,0,0} 56 }; 57 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() ); 58 return &aSvxTextPortionPropertySet; 59 } 60 61 SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p ) 62 : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() ) 63 , pSource(p) 64 { 65 } 66 67 SwTextAPIObject::~SwTextAPIObject() throw() 68 { 69 pSource->Dispose(); 70 delete pSource; 71 } 72 73 struct SwTextAPIEditSource_Impl 74 { 75 // needed for "internal" refcounting 76 SfxItemPool* mpPool; 77 SwDoc* mpDoc; 78 Outliner* mpOutliner; 79 SvxOutlinerForwarder* mpTextForwarder; 80 sal_Int32 mnRef; 81 }; 82 83 SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource ) 84 : SvxEditSource( *this ) 85 { 86 // shallow copy; uses internal refcounting 87 pImpl = rSource.pImpl; 88 pImpl->mnRef++; 89 } 90 91 SvxEditSource* SwTextAPIEditSource::Clone() const 92 { 93 return new SwTextAPIEditSource( *this ); 94 } 95 96 void SwTextAPIEditSource::UpdateData() 97 { 98 // data is kept in outliner all the time 99 } 100 101 SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc) 102 : pImpl(new SwTextAPIEditSource_Impl) 103 { 104 pImpl->mpPool = &pDoc->GetDocShell()->GetPool(); 105 pImpl->mpDoc = pDoc; 106 pImpl->mpOutliner = 0; 107 pImpl->mpTextForwarder = 0; 108 pImpl->mnRef = 1; 109 } 110 111 SwTextAPIEditSource::~SwTextAPIEditSource() 112 { 113 if (!--pImpl->mnRef) 114 delete pImpl; 115 } 116 117 void SwTextAPIEditSource::Dispose() 118 { 119 pImpl->mpPool=0; 120 pImpl->mpDoc=0; 121 DELETEZ(pImpl->mpTextForwarder); 122 DELETEZ(pImpl->mpOutliner); 123 } 124 125 SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder() 126 { 127 if( !pImpl->mpPool ) 128 return 0; // mpPool == 0 can be used to flag this as disposed 129 130 if( !pImpl->mpOutliner ) 131 { 132 //init draw model first 133 pImpl->mpDoc->GetOrCreateDrawModel(); 134 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 135 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 136 } 137 138 if( !pImpl->mpTextForwarder ) 139 pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, 0 ); 140 141 return pImpl->mpTextForwarder; 142 } 143 144 void SwTextAPIEditSource::SetText( OutlinerParaObject& rText ) 145 { 146 if ( pImpl->mpPool ) 147 { 148 if( !pImpl->mpOutliner ) 149 { 150 //init draw model first 151 pImpl->mpDoc->GetOrCreateDrawModel(); 152 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 153 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 154 } 155 156 pImpl->mpOutliner->SetText( rText ); 157 } 158 } 159 160 void SwTextAPIEditSource::SetString( const String& rText ) 161 { 162 if ( pImpl->mpPool ) 163 { 164 if( !pImpl->mpOutliner ) 165 { 166 //init draw model first 167 pImpl->mpDoc->GetOrCreateDrawModel(); 168 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 169 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 170 } 171 else 172 pImpl->mpOutliner->Clear(); 173 pImpl->mpOutliner->Insert( rText ); 174 } 175 } 176 177 OutlinerParaObject* SwTextAPIEditSource::CreateText() 178 { 179 if ( pImpl->mpPool && pImpl->mpOutliner ) 180 return pImpl->mpOutliner->CreateParaObject(); 181 else 182 return 0; 183 } 184 185 String SwTextAPIEditSource::GetText() 186 { 187 if ( pImpl->mpPool && pImpl->mpOutliner ) 188 return pImpl->mpOutliner->GetEditEngine().GetText(); 189 else 190 return String(); 191 } 192