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