1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2008 by Sun Microsystems, Inc.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * $RCSfile: urltransformer.cxx,v $
10*cdf0e10cSrcweir  * $Revision: 1.17 $
11*cdf0e10cSrcweir  *
12*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir  *
18*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir  *
24*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir  *
29*cdf0e10cSrcweir  ************************************************************************/
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
32*cdf0e10cSrcweir #include "precompiled_framework.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35*cdf0e10cSrcweir //	my own includes
36*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "services.h"
39*cdf0e10cSrcweir #include "services/modelwinservice.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42*cdf0e10cSrcweir //	interface includes
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace ::com::sun::star;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50*cdf0e10cSrcweir //	namespace
51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace framework{
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
56*cdf0e10cSrcweir //	non exported definitions
57*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60*cdf0e10cSrcweir //	declarations
61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir class Impl_ModelWinService
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     public:
66*cdf0e10cSrcweir         ~Impl_ModelWinService();
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir         static Impl_ModelWinService* getSingleInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir         uno::Any getByName( const ::rtl::OUString& sName )
71*cdf0e10cSrcweir             throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > getElementNames()
74*cdf0e10cSrcweir             throw( uno::RuntimeException );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         sal_Bool hasByName( const ::rtl::OUString& sName )
77*cdf0e10cSrcweir             throw( uno::RuntimeException );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir         uno::Type getElementType()
80*cdf0e10cSrcweir             throw( css::uno::RuntimeException );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         sal_Bool hasElements()
83*cdf0e10cSrcweir             throw( css::uno::RuntimeException );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir         void registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         void deregisterModelForXWindow( const uno::Reference< awt::XWindow >& rWindow );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     private:
90*cdf0e10cSrcweir         typedef BaseHash< uno::WeakReference< awt::XControlModel > > ModelWinMap;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         Impl_ModelWinService();
93*cdf0e10cSrcweir         Impl_ModelWinService( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         static Impl_ModelWinService* m_pModelWinService;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
98*cdf0e10cSrcweir         ModelWinMap m_aModelMap;
99*cdf0e10cSrcweir };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir Impl_ModelWinService* Impl_ModelWinService::m_pModelWinService = 0;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir Impl_ModelWinService* Impl_ModelWinService::getSingleInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager )
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
106*cdf0e10cSrcweir     if ( !m_pModelWinService )
107*cdf0e10cSrcweir         m_pModelWinService = new Impl_ModelWinService( rServiceManager );
108*cdf0e10cSrcweir     return m_pModelWinService;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir Impl_ModelWinService::Impl_ModelWinService( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager ) :
112*cdf0e10cSrcweir     m_xServiceManager( rServiceManager )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir Impl_ModelWinService::Impl_ModelWinService()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir Impl_ModelWinService::~Impl_ModelWinService()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir void Impl_ModelWinService::registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     ::rtl::OUString sName = rtl::OUString::valueOf( reinterpret_cast< sal_Int64 >((void*)rWindow.get()));
129*cdf0e10cSrcweir     ModelWinMap::iterator pIter = m_aModelMap.find( sName );
130*cdf0e10cSrcweir     if ( pIter != m_aModelMap.end() )
131*cdf0e10cSrcweir         pIter->second = rModel;
132*cdf0e10cSrcweir     else
133*cdf0e10cSrcweir         m_aModelMap[sName] = rModel;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir void Impl_ModelWinService::deregisterModelForXWindow( const uno::Reference< awt::XWindow >& /*rWindow*/ )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir uno::Any Impl_ModelWinService::getByName( const ::rtl::OUString& sName )
141*cdf0e10cSrcweir throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     uno::Any aAny;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
146*cdf0e10cSrcweir     ModelWinMap::iterator pIter = m_aModelMap.find( sName );
147*cdf0e10cSrcweir     if ( pIter != m_aModelMap.end())
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         uno::Reference< awt::XControlModel > xModel( pIter->second );
150*cdf0e10cSrcweir         aAny = uno::makeAny(xModel);
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     return aAny;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > Impl_ModelWinService::getElementNames()
157*cdf0e10cSrcweir throw( uno::RuntimeException )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
160*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aResult( m_aModelMap.size() );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     sal_Int32 i = 0;
163*cdf0e10cSrcweir     ModelWinMap::const_iterator pIter = m_aModelMap.begin();
164*cdf0e10cSrcweir     while ( pIter != m_aModelMap.end())
165*cdf0e10cSrcweir         aResult[i++] = pIter->first;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     return aResult;
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir sal_Bool Impl_ModelWinService::hasByName( const ::rtl::OUString& sName )
171*cdf0e10cSrcweir throw( uno::RuntimeException )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
174*cdf0e10cSrcweir     ModelWinMap::iterator pIter = m_aModelMap.find( sName );
175*cdf0e10cSrcweir     if ( pIter != m_aModelMap.end())
176*cdf0e10cSrcweir         return true;
177*cdf0e10cSrcweir     else
178*cdf0e10cSrcweir         return false;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir uno::Type Impl_ModelWinService::getElementType()
182*cdf0e10cSrcweir throw( css::uno::RuntimeException )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     return ::getCppuType(( const uno::Reference< awt::XControlModel >*)NULL );
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir sal_Bool Impl_ModelWinService::hasElements()
188*cdf0e10cSrcweir throw( css::uno::RuntimeException )
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
191*cdf0e10cSrcweir     return (m_aModelMap.size() > 0);
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir //*****************************************************************************************************************
195*cdf0e10cSrcweir //	css::uno::XInterface, XTypeProvider, XServiceInfo
196*cdf0e10cSrcweir //*****************************************************************************************************************
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir DEFINE_XINTERFACE_4                 (   ModelWinService                                 ,
199*cdf0e10cSrcweir                                         OWeakObject                                     ,
200*cdf0e10cSrcweir                                         DIRECT_INTERFACE(css::lang::XTypeProvider       ),
201*cdf0e10cSrcweir                                         DIRECT_INTERFACE(css::lang::XServiceInfo        ),
202*cdf0e10cSrcweir                                         DIRECT_INTERFACE(css::container::XNameAccess    ),
203*cdf0e10cSrcweir                                         DIRECT_INTERFACE(css::container::XElementAccess )
204*cdf0e10cSrcweir 									)
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_4              (   ModelWinService                ,
207*cdf0e10cSrcweir                                         css::lang::XTypeProvider       ,
208*cdf0e10cSrcweir                                         css::lang::XServiceInfo        ,
209*cdf0e10cSrcweir                                         css::container::XNameAccess    ,
210*cdf0e10cSrcweir                                         css::container::XElementAccess
211*cdf0e10cSrcweir 									)
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE    (   ModelWinService                    ,
214*cdf0e10cSrcweir                                         OWeakObject                        ,
215*cdf0e10cSrcweir                                         SERVICENAME_MODELWINSERVICE        ,
216*cdf0e10cSrcweir                                         IMPLEMENTATIONNAME_MODELWINSERVICE
217*cdf0e10cSrcweir 									)
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir DEFINE_INIT_SERVICE                 (   ModelWinService,
220*cdf0e10cSrcweir                                         {
221*cdf0e10cSrcweir                                         }
222*cdf0e10cSrcweir                                     )
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir //*****************************************************************************************************************
225*cdf0e10cSrcweir //	constructor
226*cdf0e10cSrcweir //*****************************************************************************************************************
227*cdf0e10cSrcweir ModelWinService::ModelWinService(const uno::Reference< lang::XMultiServiceFactory >& rServiceManager ) :
228*cdf0e10cSrcweir     m_xServiceManager( rServiceManager )
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir ModelWinService::~ModelWinService()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir void ModelWinService::registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel )
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     Impl_ModelWinService::getSingleInstance(m_xServiceManager)->registerModelForXWindow( rWindow, rModel );
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void ModelWinService::deregisterModelForXWindow( const uno::Reference< awt::XWindow >& rWindow )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     Impl_ModelWinService::getSingleInstance(m_xServiceManager)->deregisterModelForXWindow( rWindow );
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir uno::Any SAL_CALL ModelWinService::getByName( const ::rtl::OUString& sName )
247*cdf0e10cSrcweir throw(	container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir     return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->getByName( sName );
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL ModelWinService::getElementNames()
253*cdf0e10cSrcweir throw( uno::RuntimeException )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->getElementNames( );
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir sal_Bool SAL_CALL ModelWinService::hasByName( const ::rtl::OUString& sName )
259*cdf0e10cSrcweir throw( uno::RuntimeException )
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir     return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->hasByName( sName );
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
265*cdf0e10cSrcweir //	XElementAccess
266*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
267*cdf0e10cSrcweir uno::Type SAL_CALL ModelWinService::getElementType()
268*cdf0e10cSrcweir throw( uno::RuntimeException )
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     return ::getCppuType( (const uno::Reference< awt::XControlModel > *)NULL );
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir sal_Bool SAL_CALL ModelWinService::hasElements()
274*cdf0e10cSrcweir throw( uno::RuntimeException )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->hasElements();
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir }
280