1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include <textapi.hxx> 28 #include <doc.hxx> 29 #include <docsh.hxx> 30 #include <editeng/eeitem.hxx> 31 #include <editeng/editeng.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 37 using namespace com::sun::star; 38 39 static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet() 40 { 41 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] = 42 { 43 SVX_UNOEDIT_CHAR_PROPERTIES, 44 SVX_UNOEDIT_FONT_PROPERTIES, 45 SVX_UNOEDIT_OUTLINER_PROPERTIES, 46 SVX_UNOEDIT_PARA_PROPERTIES, 47 {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD, &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 }, 48 {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE, &::getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, 49 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 50 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 51 {0,0,0,0,0,0} 52 }; 53 static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() ); 54 return &aSvxTextPortionPropertySet; 55 } 56 57 SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p ) 58 : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() ) 59 , pSource(p) 60 { 61 } 62 63 SwTextAPIObject::~SwTextAPIObject() throw() 64 { 65 pSource->Dispose(); 66 delete pSource; 67 } 68 69 struct SwTextAPIEditSource_Impl 70 { 71 // needed for "internal" refcounting 72 SfxItemPool* mpPool; 73 SwDoc* mpDoc; 74 Outliner* mpOutliner; 75 SvxOutlinerForwarder* mpTextForwarder; 76 sal_Int32 mnRef; 77 }; 78 79 SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource ) 80 : SvxEditSource( *this ) 81 { 82 // shallow copy; uses internal refcounting 83 pImpl = rSource.pImpl; 84 pImpl->mnRef++; 85 } 86 87 SvxEditSource* SwTextAPIEditSource::Clone() const 88 { 89 return new SwTextAPIEditSource( *this ); 90 } 91 92 void SwTextAPIEditSource::UpdateData() 93 { 94 // data is kept in outliner all the time 95 } 96 97 SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc) 98 : pImpl(new SwTextAPIEditSource_Impl) 99 { 100 pImpl->mpPool = &pDoc->GetDocShell()->GetPool(); 101 pImpl->mpDoc = pDoc; 102 pImpl->mpOutliner = 0; 103 pImpl->mpTextForwarder = 0; 104 pImpl->mnRef = 1; 105 } 106 107 SwTextAPIEditSource::~SwTextAPIEditSource() 108 { 109 if (!--pImpl->mnRef) 110 delete pImpl; 111 } 112 113 void SwTextAPIEditSource::Dispose() 114 { 115 pImpl->mpPool=0; 116 pImpl->mpDoc=0; 117 DELETEZ(pImpl->mpTextForwarder); 118 DELETEZ(pImpl->mpOutliner); 119 } 120 121 SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder() 122 { 123 if( !pImpl->mpPool ) 124 return 0; // mpPool == 0 can be used to flag this as disposed 125 126 if( !pImpl->mpOutliner ) 127 { 128 //init draw model first 129 pImpl->mpDoc->GetOrCreateDrawModel(); 130 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 131 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 132 } 133 134 if( !pImpl->mpTextForwarder ) 135 pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, 0 ); 136 137 return pImpl->mpTextForwarder; 138 } 139 140 void SwTextAPIEditSource::SetText( OutlinerParaObject& rText ) 141 { 142 if ( pImpl->mpPool ) 143 { 144 if( !pImpl->mpOutliner ) 145 { 146 //init draw model first 147 pImpl->mpDoc->GetOrCreateDrawModel(); 148 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 149 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 150 } 151 152 pImpl->mpOutliner->SetText( rText ); 153 } 154 } 155 156 void SwTextAPIEditSource::SetString( const String& rText ) 157 { 158 if ( pImpl->mpPool ) 159 { 160 if( !pImpl->mpOutliner ) 161 { 162 //init draw model first 163 pImpl->mpDoc->GetOrCreateDrawModel(); 164 pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT ); 165 pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner ); 166 } 167 else 168 pImpl->mpOutliner->Clear(); 169 pImpl->mpOutliner->Insert( rText ); 170 } 171 } 172 173 OutlinerParaObject* SwTextAPIEditSource::CreateText() 174 { 175 if ( pImpl->mpPool && pImpl->mpOutliner ) 176 return pImpl->mpOutliner->CreateParaObject(); 177 else 178 return 0; 179 } 180 181 String SwTextAPIEditSource::GetText() 182 { 183 if ( pImpl->mpPool && pImpl->mpOutliner ) 184 return pImpl->mpOutliner->GetEditEngine().GetText(); 185 else 186 return String(); 187 } 188