xref: /trunk/main/svl/source/numbers/numuno.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
103     ::osl::MutexGuard aGuard( pImpl->aMutex );
104 
105     return new SvNumberFormatSettingsObj( *this, pImpl->aMutex );
106 }
107 
getNumberFormats()108 uno::Reference<util::XNumberFormats> SAL_CALL SvNumberFormatsSupplierObj::getNumberFormats()
109 {
110     ::osl::MutexGuard aGuard( pImpl->aMutex );
111 
112     return new SvNumberFormatsObj( *this, pImpl->aMutex );
113 }
114 
115 // XUnoTunnel
116 
getSomething(const uno::Sequence<sal_Int8> & rId)117 sal_Int64 SAL_CALL SvNumberFormatsSupplierObj::getSomething(
118                 const uno::Sequence<sal_Int8 >& rId )
119 {
120     if ( rId.getLength() == 16 &&
121           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
122                                     rId.getConstArray(), 16 ) )
123     {
124         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
125     }
126     return 0;
127 }
128 
129 // static
getUnoTunnelId()130 const uno::Sequence<sal_Int8>& SvNumberFormatsSupplierObj::getUnoTunnelId()
131 {
132     static uno::Sequence<sal_Int8> * pSeq = 0;
133     if( !pSeq )
134     {
135         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
136         if( !pSeq )
137         {
138             static uno::Sequence< sal_Int8 > aSeq( 16 );
139             rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
140             pSeq = &aSeq;
141         }
142     }
143     return *pSeq;
144 }
145 
146 // static
getImplementation(const uno::Reference<util::XNumberFormatsSupplier> xObj)147 SvNumberFormatsSupplierObj* SvNumberFormatsSupplierObj::getImplementation(
148                                 const uno::Reference<util::XNumberFormatsSupplier> xObj )
149 {
150     SvNumberFormatsSupplierObj* pRet = NULL;
151     uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
152     if (xUT.is())
153         pRet = reinterpret_cast<SvNumberFormatsSupplierObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( getUnoTunnelId() )));
154     return pRet;
155 }
156 
157 
158 //------------------------------------------------------------------------
159