1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_forms.hxx" 30*cdf0e10cSrcweir #include "FormattedFieldWrapper.hxx" 31*cdf0e10cSrcweir #include "Edit.hxx" 32*cdf0e10cSrcweir #include "FormattedField.hxx" 33*cdf0e10cSrcweir #include <tools/debug.hxx> 34*cdf0e10cSrcweir #include "EditBase.hxx" 35*cdf0e10cSrcweir #include "services.hxx" 36*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 37*cdf0e10cSrcweir #include <vcl/svapp.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //......................................................................... 40*cdf0e10cSrcweir namespace frm 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 44*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 45*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 46*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47*cdf0e10cSrcweir using namespace ::com::sun::star::container; 48*cdf0e10cSrcweir using namespace ::com::sun::star::form; 49*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 50*cdf0e10cSrcweir using namespace ::com::sun::star::io; 51*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52*cdf0e10cSrcweir using namespace ::com::sun::star::util; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //================================================================== 55*cdf0e10cSrcweir // OFormattedFieldWrapper 56*cdf0e10cSrcweir //================================================================== 57*cdf0e10cSrcweir DBG_NAME(OFormattedFieldWrapper) 58*cdf0e10cSrcweir //------------------------------------------------------------------ 59*cdf0e10cSrcweir InterfaceRef SAL_CALL OFormattedFieldWrapper_CreateInstance_ForceFormatted(const Reference<XMultiServiceFactory>& _rxFactory) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir return *(new OFormattedFieldWrapper(_rxFactory, sal_True)); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //------------------------------------------------------------------ 65*cdf0e10cSrcweir InterfaceRef SAL_CALL OFormattedFieldWrapper_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir return *(new OFormattedFieldWrapper(_rxFactory, sal_False)); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //------------------------------------------------------------------ 71*cdf0e10cSrcweir OFormattedFieldWrapper::OFormattedFieldWrapper(const Reference<XMultiServiceFactory>& _rxFactory, sal_Bool _bActAsFormatted) 72*cdf0e10cSrcweir :m_xServiceFactory(_rxFactory) 73*cdf0e10cSrcweir ,m_pEditPart(NULL) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir DBG_CTOR(OFormattedFieldWrapper, NULL); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir if (_bActAsFormatted) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir increment(m_refCount); 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // instantiate an FormattedModel 82*cdf0e10cSrcweir InterfaceRef xFormattedModel; 83*cdf0e10cSrcweir // (instantiate it directly ..., as the OFormattedModel isn't registered for any service names anymore) 84*cdf0e10cSrcweir OFormattedModel* pModel = new OFormattedModel(m_xServiceFactory); 85*cdf0e10cSrcweir query_interface(static_cast<XWeak*>(pModel), xFormattedModel); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir m_xAggregate = Reference<XAggregation> (xFormattedModel, UNO_QUERY); 88*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::OFormattedFieldWrapper : the OFormattedModel didn't have an XAggregation interface !"); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // _before_ setting the delegator, give it to the member references 91*cdf0e10cSrcweir query_interface(xFormattedModel, m_xFormattedPart); 92*cdf0e10cSrcweir m_pEditPart = new OEditModel(m_xServiceFactory); 93*cdf0e10cSrcweir m_pEditPart->acquire(); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir if (m_xAggregate.is()) 96*cdf0e10cSrcweir { // has to be in it's own block because of the temporary variable created by *this 97*cdf0e10cSrcweir m_xAggregate->setDelegator(static_cast<XWeak*>(this)); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir decrement(m_refCount); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //------------------------------------------------------------------ 104*cdf0e10cSrcweir OFormattedFieldWrapper::OFormattedFieldWrapper( const OFormattedFieldWrapper* _pCloneSource ) 105*cdf0e10cSrcweir :m_xServiceFactory( _pCloneSource->m_xServiceFactory ) 106*cdf0e10cSrcweir ,m_pEditPart( NULL ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir Reference< XCloneable > xCloneAccess; 109*cdf0e10cSrcweir query_aggregation( _pCloneSource->m_xAggregate, xCloneAccess ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // clone the aggregate 112*cdf0e10cSrcweir if ( xCloneAccess.is() ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir increment( m_refCount ); 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir Reference< XCloneable > xClone = xCloneAccess->createClone(); 117*cdf0e10cSrcweir m_xAggregate = Reference< XAggregation >( xClone, UNO_QUERY ); 118*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::OFormattedFieldWrapper : invalid aggregate clone!"); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir query_interface( Reference< XInterface >( xClone.get() ), m_xFormattedPart ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if ( _pCloneSource->m_pEditPart ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir m_pEditPart = new OEditModel( _pCloneSource->m_pEditPart, _pCloneSource->m_xServiceFactory ); 125*cdf0e10cSrcweir m_pEditPart->acquire(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir if ( m_xAggregate.is() ) 129*cdf0e10cSrcweir { // has to be in it's own block because of the temporary variable created by *this 130*cdf0e10cSrcweir m_xAggregate->setDelegator( static_cast< XWeak* >( this ) ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir decrement( m_refCount ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir else 135*cdf0e10cSrcweir { // the clone source does not yet have an aggregate -> we don't yet need one, too 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //------------------------------------------------------------------ 140*cdf0e10cSrcweir OFormattedFieldWrapper::~OFormattedFieldWrapper() 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir // release the aggregated object (if any) 143*cdf0e10cSrcweir if (m_xAggregate.is()) 144*cdf0e10cSrcweir m_xAggregate->setDelegator(InterfaceRef ()); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if (m_pEditPart) 147*cdf0e10cSrcweir m_pEditPart->release(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir DBG_DTOR(OFormattedFieldWrapper, NULL); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //------------------------------------------------------------------ 153*cdf0e10cSrcweir Any SAL_CALL OFormattedFieldWrapper::queryAggregation(const Type& _rType) throw (RuntimeException) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir Any aReturn; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if (_rType.equals( ::getCppuType( static_cast< Reference< XTypeProvider >* >(NULL) ) ) ) 158*cdf0e10cSrcweir { // a XTypeProvider interface needs a working aggregate - we don't want to give the type provider 159*cdf0e10cSrcweir // of our base class (OFormattedFieldWrapper_Base) to the caller as it supplies nearly nothing 160*cdf0e10cSrcweir ensureAggregate(); 161*cdf0e10cSrcweir if (m_xAggregate.is()) 162*cdf0e10cSrcweir aReturn = m_xAggregate->queryAggregation(_rType); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir if (!aReturn.hasValue()) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir aReturn = OFormattedFieldWrapper_Base::queryAggregation(_rType); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if ((_rType.equals( ::getCppuType( static_cast< Reference< XServiceInfo >* >(NULL) ) ) ) && aReturn.hasValue()) 170*cdf0e10cSrcweir { // somebody requested an XServiceInfo interface and our base class provided it 171*cdf0e10cSrcweir // check our aggregate if it has one, too 172*cdf0e10cSrcweir ensureAggregate(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir if (!aReturn.hasValue()) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir aReturn = ::cppu::queryInterface( _rType, 178*cdf0e10cSrcweir static_cast< XPersistObject* >( this ), 179*cdf0e10cSrcweir static_cast< XCloneable* >( this ) 180*cdf0e10cSrcweir ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir if (!aReturn.hasValue()) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir // somebody requests an interface other than the basics (XInterface) and other than 185*cdf0e10cSrcweir // the two we can supply without an aggregate. So ensure 186*cdf0e10cSrcweir // the aggregate exists. 187*cdf0e10cSrcweir ensureAggregate(); 188*cdf0e10cSrcweir if (m_xAggregate.is()) 189*cdf0e10cSrcweir aReturn = m_xAggregate->queryAggregation(_rType); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir return aReturn; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir //------------------------------------------------------------------ 198*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFormattedFieldWrapper::getServiceName() throw(RuntimeException) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir // return the old compatibility name for an EditModel 201*cdf0e10cSrcweir return FRM_COMPONENT_EDIT; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir //------------------------------------------------------------------ 205*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFormattedFieldWrapper::getImplementationName( ) throw (RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.forms.OFormattedFieldWrapper"); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir //------------------------------------------------------------------ 211*cdf0e10cSrcweir sal_Bool SAL_CALL OFormattedFieldWrapper::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::supportsService: should never have made it 'til here without an aggregate!"); 214*cdf0e10cSrcweir Reference< XServiceInfo > xSI; 215*cdf0e10cSrcweir m_xAggregate->queryAggregation(::getCppuType(static_cast< Reference< XServiceInfo >* >(NULL))) >>= xSI; 216*cdf0e10cSrcweir return xSI->supportsService(_rServiceName); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir //------------------------------------------------------------------ 220*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OFormattedFieldWrapper::getSupportedServiceNames( ) throw (RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::getSupportedServiceNames: should never have made it 'til here without an aggregate!"); 223*cdf0e10cSrcweir Reference< XServiceInfo > xSI; 224*cdf0e10cSrcweir m_xAggregate->queryAggregation(::getCppuType(static_cast< Reference< XServiceInfo >* >(NULL))) >>= xSI; 225*cdf0e10cSrcweir return xSI->getSupportedServiceNames(); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir //------------------------------------------------------------------ 229*cdf0e10cSrcweir void SAL_CALL OFormattedFieldWrapper::write(const Reference<XObjectOutputStream>& _rxOutStream) throw( IOException, RuntimeException ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir // can't write myself 232*cdf0e10cSrcweir ensureAggregate(); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // if we act as real edit field, we can simple forward this write request 235*cdf0e10cSrcweir if (!m_xFormattedPart.is()) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir Reference<XPersistObject> xAggregatePersistence; 238*cdf0e10cSrcweir query_aggregation(m_xAggregate, xAggregatePersistence); 239*cdf0e10cSrcweir DBG_ASSERT(xAggregatePersistence.is(), "OFormattedFieldWrapper::write : don't know how to handle this : can't write !"); 240*cdf0e10cSrcweir // oops ... We gave an XPersistObject interface to the caller but now we aren't an XPersistObject ... 241*cdf0e10cSrcweir if (xAggregatePersistence.is()) 242*cdf0e10cSrcweir xAggregatePersistence->write(_rxOutStream); 243*cdf0e10cSrcweir return; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir // else we have to write an edit part first 247*cdf0e10cSrcweir DBG_ASSERT(m_pEditPart, "OFormattedFieldWrapper::write : formatted part without edit part ?"); 248*cdf0e10cSrcweir if ( !m_pEditPart ) 249*cdf0e10cSrcweir throw RuntimeException( ::rtl::OUString(), *this ); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // for this we transfer the current props of the formatted part to the edit part 252*cdf0e10cSrcweir Reference<XPropertySet> xFormatProps(m_xFormattedPart, UNO_QUERY); 253*cdf0e10cSrcweir Reference<XPropertySet> xEditProps; 254*cdf0e10cSrcweir query_interface(static_cast<XWeak*>(m_pEditPart), xEditProps); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir Locale aAppLanguage = Application::GetSettings().GetUILocale(); 257*cdf0e10cSrcweir dbtools::TransferFormComponentProperties(xFormatProps, xEditProps, aAppLanguage); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // then write the edit part, after switching to "fake mode" 260*cdf0e10cSrcweir m_pEditPart->enableFormattedWriteFake(); 261*cdf0e10cSrcweir m_pEditPart->write(_rxOutStream); 262*cdf0e10cSrcweir m_pEditPart->disableFormattedWriteFake(); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // and finally write the formatted part we're really interested in 265*cdf0e10cSrcweir m_xFormattedPart->write(_rxOutStream); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir //------------------------------------------------------------------ 269*cdf0e10cSrcweir void SAL_CALL OFormattedFieldWrapper::read(const Reference<XObjectInputStream>& _rxInStream) throw( IOException, RuntimeException ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir if (m_xAggregate.is()) 272*cdf0e10cSrcweir { // we alread did a decision if we're an EditModel or a FormattedModel 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // if we act as formatted, we have to read the edit part first 275*cdf0e10cSrcweir if (m_xFormattedPart.is()) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir // two possible cases: 278*cdf0e10cSrcweir // a) the stuff was written by a version which didn't work with an Edit header (all intermediate 279*cdf0e10cSrcweir // versions >5.1 && <=568) 280*cdf0e10cSrcweir // b) it was written by a version using edit headers 281*cdf0e10cSrcweir // as we can distinguish a) from b) only after we have read the edit part, we need to remember the 282*cdf0e10cSrcweir // position 283*cdf0e10cSrcweir Reference<XMarkableStream> xInMarkable(_rxInStream, UNO_QUERY); 284*cdf0e10cSrcweir DBG_ASSERT(xInMarkable.is(), "OFormattedFieldWrapper::read : can only work with markable streams !"); 285*cdf0e10cSrcweir sal_Int32 nBeforeEditPart = xInMarkable->createMark(); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir m_pEditPart->read(_rxInStream); 288*cdf0e10cSrcweir // this only works because an edit model can read the stuff written by a formatted model (maybe with 289*cdf0e10cSrcweir // some assertions) , but not vice versa 290*cdf0e10cSrcweir if (!m_pEditPart->lastReadWasFormattedFake()) 291*cdf0e10cSrcweir { // case a), written with a version without the edit part fake, so seek to the start position, again 292*cdf0e10cSrcweir xInMarkable->jumpToMark(nBeforeEditPart); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir xInMarkable->deleteMark(nBeforeEditPart); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir Reference<XPersistObject> xAggregatePersistence; 298*cdf0e10cSrcweir query_aggregation(m_xAggregate, xAggregatePersistence); 299*cdf0e10cSrcweir DBG_ASSERT(xAggregatePersistence.is(), "OFormattedFieldWrapper::read : don't know how to handle this : can't read !"); 300*cdf0e10cSrcweir // oops ... We gave an XPersistObject interface to the caller but now we aren't an XPersistObject ... 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if (xAggregatePersistence.is()) 303*cdf0e10cSrcweir xAggregatePersistence->read(_rxInStream); 304*cdf0e10cSrcweir return; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // we have to decide from the data within the stream whether we should be an EditModel or a FormattedModel 308*cdf0e10cSrcweir OEditBaseModel* pNewAggregate = NULL; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir // let an OEditModel do the reading 311*cdf0e10cSrcweir OEditModel* pBasicReader = new OEditModel(m_xServiceFactory); 312*cdf0e10cSrcweir Reference< XInterface > xHoldBasicReaderAlive( *pBasicReader ); 313*cdf0e10cSrcweir pBasicReader->read(_rxInStream); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // was it really an edit model ? 316*cdf0e10cSrcweir if (!pBasicReader->lastReadWasFormattedFake()) 317*cdf0e10cSrcweir // yes -> all fine 318*cdf0e10cSrcweir pNewAggregate = pBasicReader; 319*cdf0e10cSrcweir else 320*cdf0e10cSrcweir { // no -> substitute it with a formatted model 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // let the formmatted model do the reading 323*cdf0e10cSrcweir OFormattedModel* pFormattedReader = new OFormattedModel(m_xServiceFactory); 324*cdf0e10cSrcweir Reference< XInterface > xHoldAliveWhileRead( *pFormattedReader ); 325*cdf0e10cSrcweir pFormattedReader->read(_rxInStream); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // for the next write (if any) : the FormattedModel and the EditModel parts 328*cdf0e10cSrcweir query_interface(static_cast<XWeak*>(pFormattedReader), m_xFormattedPart); 329*cdf0e10cSrcweir m_pEditPart = pBasicReader; 330*cdf0e10cSrcweir m_pEditPart->acquire(); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir // aggregate the formatted part below 333*cdf0e10cSrcweir pNewAggregate = pFormattedReader; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // do the aggregation 337*cdf0e10cSrcweir increment(m_refCount); 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir query_interface(static_cast<XWeak*>(pNewAggregate), m_xAggregate); 340*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::read : the OEditModel didn't have an XAggregation interface !"); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir if (m_xAggregate.is()) 343*cdf0e10cSrcweir { // has to be in it's own block because of the temporary variable created by *this 344*cdf0e10cSrcweir m_xAggregate->setDelegator(static_cast<XWeak*>(this)); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir decrement(m_refCount); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir //------------------------------------------------------------------ 350*cdf0e10cSrcweir Reference< XCloneable > SAL_CALL OFormattedFieldWrapper::createClone( ) throw (RuntimeException) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir ensureAggregate(); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir return new OFormattedFieldWrapper( this ); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //------------------------------------------------------------------ 358*cdf0e10cSrcweir void OFormattedFieldWrapper::ensureAggregate() 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir if (m_xAggregate.is()) 361*cdf0e10cSrcweir return; 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir increment(m_refCount); 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir // instantiate an EditModel (the only place where we are allowed to decide that we're an FormattedModel 366*cdf0e10cSrcweir // is in ::read) 367*cdf0e10cSrcweir InterfaceRef xEditModel = m_xServiceFactory->createInstance(FRM_SUN_COMPONENT_TEXTFIELD); 368*cdf0e10cSrcweir if (!xEditModel.is()) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir // arghhh ... instantiate it directly ... it's dirty, but we really need this aggregate 371*cdf0e10cSrcweir OEditModel* pModel = new OEditModel(m_xServiceFactory); 372*cdf0e10cSrcweir query_interface(static_cast<XWeak*>(pModel), xEditModel); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir m_xAggregate = Reference<XAggregation> (xEditModel, UNO_QUERY); 376*cdf0e10cSrcweir DBG_ASSERT(m_xAggregate.is(), "OFormattedFieldWrapper::ensureAggregate : the OEditModel didn't have an XAggregation interface !"); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir Reference< XServiceInfo > xSI(m_xAggregate, UNO_QUERY); 380*cdf0e10cSrcweir if (!xSI.is()) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir DBG_ERROR("OFormattedFieldWrapper::ensureAggregate: the aggregate has no XServiceInfo!"); 383*cdf0e10cSrcweir m_xAggregate.clear(); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir if (m_xAggregate.is()) 388*cdf0e10cSrcweir { // has to be in it's own block because of the temporary variable created by *this 389*cdf0e10cSrcweir m_xAggregate->setDelegator(static_cast<XWeak*>(this)); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir decrement(m_refCount); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir //......................................................................... 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir //......................................................................... 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir 399