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 #ifndef _FORMS_LIMITED_FORMATS_HXX_
25 #define _FORMS_LIMITED_FORMATS_HXX_
26 
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/beans/XFastPropertySet.hpp>
31 
32 //.........................................................................
33 namespace frm
34 {
35 //.........................................................................
36 
37 	//=====================================================================
38 	//= OLimitedFormats
39 	//=====================================================================
40 	/** maintains translation tables format key <-> enum value
41 		<p>Used for controls which provide a limited number for (standard) formats, which
42 		should be available as format keys.</p>
43 	*/
44 	class OLimitedFormats
45 	{
46 	private:
47 		static sal_Int32	s_nInstanceCount;
48 		static ::osl::Mutex	s_aMutex;
49 		static ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >
50 							s_xStandardFormats;
51 
52 	protected:
53 		sal_Int32			m_nFormatEnumPropertyHandle;
54 		const sal_Int16		m_nTableId;
55 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet >
56 							m_xAggregate;
57 
58 	protected:
59 		/** ctor
60 			<p>The class id is used to determine the translation table to use. All instances which
61 			pass the same value here share one table.</p>
62 		*/
63 		OLimitedFormats(
64 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
65 			const sal_Int16 _nClassId
66 			);
67 		~OLimitedFormats();
68 
69 	protected:
70 		void setAggregateSet(
71 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet >& _rxAggregate,
72 			sal_Int32 _nOriginalPropertyHandle
73 		);
74 
75 	protected:
76 		void		getFormatKeyPropertyValue( ::com::sun::star::uno::Any& _rValue ) const;
77 		sal_Bool	convertFormatKeyPropertyValue(
78 						::com::sun::star::uno::Any& _rConvertedValue,
79 						::com::sun::star::uno::Any& _rOldValue,
80 				const	::com::sun::star::uno::Any& _rNewValue
81 			);
82 		void		setFormatKeyPropertyValue( const ::com::sun::star::uno::Any& _rNewValue );
83 		// setFormatKeyPropertyValue should only be called with a value got from convertFormatKeyPropertyValue!
84 
85 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >
getFormatsSupplier() const86 					getFormatsSupplier() const { return s_xStandardFormats; }
87 
88 	private:
89 		void acquireSupplier(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB);
90 		void releaseSupplier();
91 
92 		static void ensureTableInitialized(const sal_Int16 _nTableId);
93 		static void clearTable(const sal_Int16 _nTableId);
94 	};
95 
96 //.........................................................................
97 }	// namespace frm
98 //.........................................................................
99 
100 #endif // _FORMS_LIMITED_FORMATS_HXX_
101 
102