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 _FORMS_FORMATTEDFIELD_HXX_
29 #define _FORMS_FORMATTEDFIELD_HXX_
30 
31 #include "EditBase.hxx"
32 #include <comphelper/propmultiplex.hxx>
33 #include <cppuhelper/implbase1.hxx>
34 #include "errorbroadcaster.hxx"
35 
36 //.........................................................................
37 namespace frm
38 {
39 
40 	//==================================================================
41 	//= OFormattedModel
42 	//==================================================================
43 
44 	class OFormattedModel
45 					:public OEditBaseModel
46 					,public OErrorBroadcaster
47 	{
48 		// das Original, falls ich die Format-Properties meines aggregierten Models gefaket, d.h. von dem Feld, an das
49 		// ich gebunden bin, weitergereicht habe (nur gueltig wenn loaded)
50 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>	m_xOriginalFormatter;
51 		::com::sun::star::util::Date		m_aNullDate;
52 		::com::sun::star::uno::Any			m_aSaveValue;
53 
54 		sal_Int32							m_nFieldType;
55 		sal_Int16							m_nKeyType;
56 		sal_Bool							m_bOriginalNumeric		: 1,
57 											m_bNumeric				: 1;	// analog fuer TreatAsNumeric-Property
58 
59 	protected:
60 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcDefaultFormatsSupplier() const;
61 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcFormFormatsSupplier() const;
62 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcFormatsSupplier() const;
63 
64 		DECLARE_DEFAULT_LEAF_XTOR( OFormattedModel );
65 
66 		friend class OFormattedFieldWrapper;
67 
68 	protected:
69 	// XInterface
70 		DECLARE_UNO3_AGG_DEFAULTS( OFormattedModel, OEditBaseModel );
71 
72 	// XTypeProvider
73 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
74 
75 	// XAggregation
76 		virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
77 
78 	// OComponentHelper
79 		virtual void SAL_CALL disposing();
80 
81 	// XServiceInfo
82 		IMPLEMENTATION_NAME(OFormattedModel);
83 		virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
84 
85 	// XPersistObject
86 		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);
87 		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);
88 		virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException);
89 
90 	// XPropertySet
91 		virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
92 		virtual sal_Bool SAL_CALL convertFastPropertyValue(::com::sun::star::uno::Any& rConvertedValue, ::com::sun::star::uno::Any& rOldValue,
93 											  sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
94 											throw(::com::sun::star::lang::IllegalArgumentException);
95 		virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw ( ::com::sun::star::uno::Exception);
96 
97 	// XLoadListener
98 		virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& rEvent) throw ( ::com::sun::star::uno::RuntimeException);
99 
100 	// XPropertyState
101 		void setPropertyToDefaultByHandle(sal_Int32 nHandle);
102 		::com::sun::star::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const;
103 
104 		void SAL_CALL setPropertyToDefault(const ::rtl::OUString& aPropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
105 		::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
106 
107         // OControlModel's property handling
108 	    virtual void describeFixedProperties(
109 			::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
110         ) const;
111         virtual void describeAggregateProperties(
112 		    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
113         ) const;
114 
115 	// XPropertyChangeListener
116 		virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException);
117 
118     // prevent method hiding
119         using OEditBaseModel::disposing;
120         using OEditBaseModel::getFastPropertyValue;
121 
122 	protected:
123 		virtual sal_uInt16 getPersistenceFlags() const;
124 			// as we have an own version handling for persistence
125 
126         // OBoundControlModel overridables
127         virtual ::com::sun::star::uno::Any
128                             translateDbColumnToControlValue( );
129         virtual sal_Bool    commitControlValueToDbColumn( bool _bPostReset );
130 
131         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
132                             getSupportedBindingTypes();
133         virtual ::com::sun::star::uno::Any
134                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
135         virtual ::com::sun::star::uno::Any
136                             translateControlValueToExternalValue( ) const;
137         virtual void onConnectedExternalValue( );
138 
139         virtual ::com::sun::star::uno::Any
140                             getDefaultForReset() const;
141 	    virtual void        resetNoBroadcast();
142 
143 		virtual void        onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
144 		virtual void        onDisconnectedDbColumn();
145 
146     private:
147 		DECLARE_XCLONEABLE();
148 
149 		void implConstruct();
150 
151         void    updateFormatterNullDate();
152 	};
153 
154 	//==================================================================
155 	//= OFormattedControl
156 	//==================================================================
157 	typedef ::cppu::ImplHelper1< ::com::sun::star::awt::XKeyListener> OFormattedControl_BASE;
158 	class OFormattedControl :	 public OBoundControl
159 								,public OFormattedControl_BASE
160 	{
161 		sal_uInt32				m_nKeyEvent;
162 
163 	public:
164 		OFormattedControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
165 		virtual ~OFormattedControl();
166 
167 		DECLARE_UNO3_AGG_DEFAULTS(OFormattedControl, OBoundControl);
168 		virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
169 
170 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
171 
172 	// ::com::sun::star::lang::XServiceInfo
173 		IMPLEMENTATION_NAME(OFormattedControl);
174 		virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
175 
176 	// ::com::sun::star::lang::XEventListener
177 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
178 
179 	// ::com::sun::star::awt::XKeyListener
180 		virtual void SAL_CALL keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
181 		virtual void SAL_CALL keyReleased(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
182 
183 	// ::com::sun::star::awt::XControl
184 		virtual void SAL_CALL setDesignMode(sal_Bool bOn) throw ( ::com::sun::star::uno::RuntimeException);
185 
186     // disambiguation
187         using OBoundControl::disposing;
188 
189 	private:
190 		DECL_LINK( OnKeyPressed, void* );
191 	};
192 
193 //.........................................................................
194 }
195 //.........................................................................
196 
197 #endif // _FORMS_FORMATTEDFIELD_HXX_
198 
199