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