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 #ifndef _FRM_FORMATTED_FIELD_WRAPPER_HXX_
29 #define _FRM_FORMATTED_FIELD_WRAPPER_HXX_
30 
31 #include "FormComponent.hxx"
32 #include <cppuhelper/implbase3.hxx>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/util/XCloneable.hpp>
35 
36 //.........................................................................
37 namespace frm
38 {
39 
40 class OEditModel;
41 //==================================================================
42 //= OFormattedFieldWrapper
43 //==================================================================
44 typedef ::cppu::WeakAggImplHelper3	<	::com::sun::star::io::XPersistObject
45 									,	::com::sun::star::lang::XServiceInfo
46 									,	::com::sun::star::util::XCloneable
47 									>	OFormattedFieldWrapper_Base;
48 
49 class OFormattedFieldWrapper : public OFormattedFieldWrapper_Base
50 {
51 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>	m_xServiceFactory;
52 
53 protected:
54 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation> 		m_xAggregate;
55 
56 	OEditModel*		m_pEditPart;
57 		// if we act as formatted this is used to write the EditModel part
58 	::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject> 	m_xFormattedPart;
59 		// if we act as formatted, this is the PersistObject interface of our aggregate, used
60 		// to read and write the FormattedModel part
61 
62 	OFormattedFieldWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory, sal_Bool _bActAsFormatted);
63 		// if _bActAsFormatted is sal_False, the state is undetermined until somebody calls ::read or does
64 		// anything which requires a living aggregate
65 	OFormattedFieldWrapper( const OFormattedFieldWrapper* _pCloneSource );
66 	virtual ~OFormattedFieldWrapper();
67 
68 	friend InterfaceRef SAL_CALL OFormattedFieldWrapper_CreateInstance_ForceFormatted(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
69 	friend InterfaceRef SAL_CALL OFormattedFieldWrapper_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
70 
71 public:
72 	// UNO
73 	DECLARE_UNO3_AGG_DEFAULTS(OFormattedFieldWrapper, OWeakAggObject);
74 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
75 
76     // XServiceInfo
77 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
78     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
79     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
80 
81 	// XPersistObject
82 	virtual ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException);
83 	virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
84 	virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
85 
86 	// XCloneable
87 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone(  ) throw (::com::sun::star::uno::RuntimeException);
88 
89 protected:
90 	/// ensure we're in a defined state, which means a FormattedModel _OR_ an EditModel
91 	void ensureAggregate();
92 };
93 
94 //.........................................................................
95 }
96 //.........................................................................
97 
98 #endif // _FRM_FORMATTED_FIELD_WRAPPER_HXX_
99 
100