xref: /trunk/main/svl/source/numbers/numuno.cxx (revision 40df464e)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 #ifndef GCC
27 #endif
28 
29 #define _ZFORLIST_DECLARE_TABLE
30 
31 #include <tools/color.hxx>
32 #include <tools/debug.hxx>
33 #include <vos/mutex.hxx>
34 #include <osl/mutex.hxx>
35 #include <rtl/uuid.h>
36 
37 #include <svl/numuno.hxx>
38 #include "numfmuno.hxx"
39 #include <svl/zforlist.hxx>
40 
41 using namespace com::sun::star;
42 
43 //------------------------------------------------------------------------
44 
45 class SvNumFmtSuppl_Impl
46 {
47 public:
48 	SvNumberFormatter*                  pFormatter;
49     mutable ::comphelper::SharedMutex   aMutex;
50 
SvNumFmtSuppl_Impl(SvNumberFormatter * p)51 	SvNumFmtSuppl_Impl(SvNumberFormatter* p) :
52         pFormatter(p) {}
53 };
54 
55 //------------------------------------------------------------------------
56 
57 // Default-ctor fuer getReflection
SvNumberFormatsSupplierObj()58 SvNumberFormatsSupplierObj::SvNumberFormatsSupplierObj()
59 {
60 	pImpl = new SvNumFmtSuppl_Impl(NULL);
61 }
62 
SvNumberFormatsSupplierObj(SvNumberFormatter * pForm)63 SvNumberFormatsSupplierObj::SvNumberFormatsSupplierObj(SvNumberFormatter* pForm)
64 {
65 	pImpl = new SvNumFmtSuppl_Impl(pForm);
66 }
67 
~SvNumberFormatsSupplierObj()68 SvNumberFormatsSupplierObj::~SvNumberFormatsSupplierObj()
69 {
70 	delete pImpl;
71 }
72 
getSharedMutex() const73 ::comphelper::SharedMutex& SvNumberFormatsSupplierObj::getSharedMutex() const
74 {
75     return pImpl->aMutex;
76 }
77 
GetNumberFormatter() const78 SvNumberFormatter* SvNumberFormatsSupplierObj::GetNumberFormatter() const
79 {
80 	return pImpl->pFormatter;
81 }
82 
SetNumberFormatter(SvNumberFormatter * pNew)83 void SvNumberFormatsSupplierObj::SetNumberFormatter(SvNumberFormatter* pNew)
84 {
85 	//	der alte Numberformatter ist ungueltig geworden, nicht mehr darauf zugreifen!
86 	pImpl->pFormatter = pNew;
87 }
88 
NumberFormatDeleted(sal_uInt32)89 void SvNumberFormatsSupplierObj::NumberFormatDeleted(sal_uInt32)
90 {
91 	//	Basis-Implementierung tut nix...
92 }
93 
SettingsChanged()94 void SvNumberFormatsSupplierObj::SettingsChanged()
95 {
96 	//	Basis-Implementierung tut nix...
97 }
98 
99 // XNumberFormatsSupplier
100 
getNumberFormatSettings()101 uno::Reference<beans::XPropertySet> SAL_CALL SvNumberFormatsSupplierObj::getNumberFormatSettings()
102 										throw(uno::RuntimeException)
103 {
104     ::osl::MutexGuard aGuard( pImpl->aMutex );
105 
106 	return new SvNumberFormatSettingsObj( *this, pImpl->aMutex );
107 }
108 
getNumberFormats()109 uno::Reference<util::XNumberFormats> SAL_CALL SvNumberFormatsSupplierObj::getNumberFormats()
110 										throw(uno::RuntimeException)
111 {
112     ::osl::MutexGuard aGuard( pImpl->aMutex );
113 
114 	return new SvNumberFormatsObj( *this, pImpl->aMutex );
115 }
116 
117 // XUnoTunnel
118 
getSomething(const uno::Sequence<sal_Int8> & rId)119 sal_Int64 SAL_CALL SvNumberFormatsSupplierObj::getSomething(
120 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
121 {
122 	if ( rId.getLength() == 16 &&
123           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
124 									rId.getConstArray(), 16 ) )
125 	{
126         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
127 	}
128 	return 0;
129 }
130 
131 // static
getUnoTunnelId()132 const uno::Sequence<sal_Int8>& SvNumberFormatsSupplierObj::getUnoTunnelId()
133 {
134 	static uno::Sequence<sal_Int8> * pSeq = 0;
135 	if( !pSeq )
136 	{
137 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
138 		if( !pSeq )
139 		{
140 			static uno::Sequence< sal_Int8 > aSeq( 16 );
141 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
142 			pSeq = &aSeq;
143 		}
144 	}
145 	return *pSeq;
146 }
147 
148 // static
getImplementation(const uno::Reference<util::XNumberFormatsSupplier> xObj)149 SvNumberFormatsSupplierObj* SvNumberFormatsSupplierObj::getImplementation(
150 								const uno::Reference<util::XNumberFormatsSupplier> xObj )
151 {
152 	SvNumberFormatsSupplierObj* pRet = NULL;
153 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
154 	if (xUT.is())
155 		pRet = reinterpret_cast<SvNumberFormatsSupplierObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( getUnoTunnelId() )));
156 	return pRet;
157 }
158 
159 
160 //------------------------------------------------------------------------
161 
162 
163 
164