1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_framework.hxx"
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
28*b1cdbd2cSJim Jagielski // my own includes
29*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski #include "services.h"
32*b1cdbd2cSJim Jagielski #include "services/modelwinservice.hxx"
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
35*b1cdbd2cSJim Jagielski // interface includes
36*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski #include <com/sun/star/awt/XControlModel.hpp>
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski using namespace ::com::sun::star;
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
43*b1cdbd2cSJim Jagielski // namespace
44*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
45*b1cdbd2cSJim Jagielski
46*b1cdbd2cSJim Jagielski namespace framework{
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
49*b1cdbd2cSJim Jagielski // non exported definitions
50*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
53*b1cdbd2cSJim Jagielski // declarations
54*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
55*b1cdbd2cSJim Jagielski
56*b1cdbd2cSJim Jagielski class Impl_ModelWinService
57*b1cdbd2cSJim Jagielski {
58*b1cdbd2cSJim Jagielski public:
59*b1cdbd2cSJim Jagielski ~Impl_ModelWinService();
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski static Impl_ModelWinService* getSingleInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski uno::Any getByName( const ::rtl::OUString& sName )
64*b1cdbd2cSJim Jagielski throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException );
65*b1cdbd2cSJim Jagielski
66*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > getElementNames()
67*b1cdbd2cSJim Jagielski throw( uno::RuntimeException );
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski sal_Bool hasByName( const ::rtl::OUString& sName )
70*b1cdbd2cSJim Jagielski throw( uno::RuntimeException );
71*b1cdbd2cSJim Jagielski
72*b1cdbd2cSJim Jagielski uno::Type getElementType()
73*b1cdbd2cSJim Jagielski throw( css::uno::RuntimeException );
74*b1cdbd2cSJim Jagielski
75*b1cdbd2cSJim Jagielski sal_Bool hasElements()
76*b1cdbd2cSJim Jagielski throw( css::uno::RuntimeException );
77*b1cdbd2cSJim Jagielski
78*b1cdbd2cSJim Jagielski void registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel );
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski void deregisterModelForXWindow( const uno::Reference< awt::XWindow >& rWindow );
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski private:
83*b1cdbd2cSJim Jagielski typedef BaseHash< uno::WeakReference< awt::XControlModel > > ModelWinMap;
84*b1cdbd2cSJim Jagielski
85*b1cdbd2cSJim Jagielski Impl_ModelWinService();
86*b1cdbd2cSJim Jagielski Impl_ModelWinService( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski static Impl_ModelWinService* m_pModelWinService;
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
91*b1cdbd2cSJim Jagielski ModelWinMap m_aModelMap;
92*b1cdbd2cSJim Jagielski };
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski Impl_ModelWinService* Impl_ModelWinService::m_pModelWinService = 0;
95*b1cdbd2cSJim Jagielski
getSingleInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & rServiceManager)96*b1cdbd2cSJim Jagielski Impl_ModelWinService* Impl_ModelWinService::getSingleInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager )
97*b1cdbd2cSJim Jagielski {
98*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
99*b1cdbd2cSJim Jagielski if ( !m_pModelWinService )
100*b1cdbd2cSJim Jagielski m_pModelWinService = new Impl_ModelWinService( rServiceManager );
101*b1cdbd2cSJim Jagielski return m_pModelWinService;
102*b1cdbd2cSJim Jagielski }
103*b1cdbd2cSJim Jagielski
Impl_ModelWinService(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & rServiceManager)104*b1cdbd2cSJim Jagielski Impl_ModelWinService::Impl_ModelWinService( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager ) :
105*b1cdbd2cSJim Jagielski m_xServiceManager( rServiceManager )
106*b1cdbd2cSJim Jagielski {
107*b1cdbd2cSJim Jagielski }
108*b1cdbd2cSJim Jagielski
Impl_ModelWinService()109*b1cdbd2cSJim Jagielski Impl_ModelWinService::Impl_ModelWinService()
110*b1cdbd2cSJim Jagielski {
111*b1cdbd2cSJim Jagielski }
112*b1cdbd2cSJim Jagielski
~Impl_ModelWinService()113*b1cdbd2cSJim Jagielski Impl_ModelWinService::~Impl_ModelWinService()
114*b1cdbd2cSJim Jagielski {
115*b1cdbd2cSJim Jagielski }
116*b1cdbd2cSJim Jagielski
registerModelForXWindow(const uno::Reference<awt::XWindow> & rWindow,const uno::Reference<awt::XControlModel> & rModel)117*b1cdbd2cSJim Jagielski void Impl_ModelWinService::registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel )
118*b1cdbd2cSJim Jagielski {
119*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
120*b1cdbd2cSJim Jagielski
121*b1cdbd2cSJim Jagielski ::rtl::OUString sName = rtl::OUString::valueOf( reinterpret_cast< sal_Int64 >((void*)rWindow.get()));
122*b1cdbd2cSJim Jagielski ModelWinMap::iterator pIter = m_aModelMap.find( sName );
123*b1cdbd2cSJim Jagielski if ( pIter != m_aModelMap.end() )
124*b1cdbd2cSJim Jagielski pIter->second = rModel;
125*b1cdbd2cSJim Jagielski else
126*b1cdbd2cSJim Jagielski m_aModelMap[sName] = rModel;
127*b1cdbd2cSJim Jagielski }
128*b1cdbd2cSJim Jagielski
deregisterModelForXWindow(const uno::Reference<awt::XWindow> &)129*b1cdbd2cSJim Jagielski void Impl_ModelWinService::deregisterModelForXWindow( const uno::Reference< awt::XWindow >& /*rWindow*/ )
130*b1cdbd2cSJim Jagielski {
131*b1cdbd2cSJim Jagielski }
132*b1cdbd2cSJim Jagielski
getByName(const::rtl::OUString & sName)133*b1cdbd2cSJim Jagielski uno::Any Impl_ModelWinService::getByName( const ::rtl::OUString& sName )
134*b1cdbd2cSJim Jagielski throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
135*b1cdbd2cSJim Jagielski {
136*b1cdbd2cSJim Jagielski uno::Any aAny;
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
139*b1cdbd2cSJim Jagielski ModelWinMap::iterator pIter = m_aModelMap.find( sName );
140*b1cdbd2cSJim Jagielski if ( pIter != m_aModelMap.end())
141*b1cdbd2cSJim Jagielski {
142*b1cdbd2cSJim Jagielski uno::Reference< awt::XControlModel > xModel( pIter->second );
143*b1cdbd2cSJim Jagielski aAny = uno::makeAny(xModel);
144*b1cdbd2cSJim Jagielski }
145*b1cdbd2cSJim Jagielski
146*b1cdbd2cSJim Jagielski return aAny;
147*b1cdbd2cSJim Jagielski }
148*b1cdbd2cSJim Jagielski
getElementNames()149*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > Impl_ModelWinService::getElementNames()
150*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
151*b1cdbd2cSJim Jagielski {
152*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
153*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > aResult( m_aModelMap.size() );
154*b1cdbd2cSJim Jagielski
155*b1cdbd2cSJim Jagielski sal_Int32 i = 0;
156*b1cdbd2cSJim Jagielski ModelWinMap::const_iterator pIter = m_aModelMap.begin();
157*b1cdbd2cSJim Jagielski while ( pIter != m_aModelMap.end())
158*b1cdbd2cSJim Jagielski aResult[i++] = pIter->first;
159*b1cdbd2cSJim Jagielski
160*b1cdbd2cSJim Jagielski return aResult;
161*b1cdbd2cSJim Jagielski }
162*b1cdbd2cSJim Jagielski
hasByName(const::rtl::OUString & sName)163*b1cdbd2cSJim Jagielski sal_Bool Impl_ModelWinService::hasByName( const ::rtl::OUString& sName )
164*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
165*b1cdbd2cSJim Jagielski {
166*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
167*b1cdbd2cSJim Jagielski ModelWinMap::iterator pIter = m_aModelMap.find( sName );
168*b1cdbd2cSJim Jagielski if ( pIter != m_aModelMap.end())
169*b1cdbd2cSJim Jagielski return true;
170*b1cdbd2cSJim Jagielski else
171*b1cdbd2cSJim Jagielski return false;
172*b1cdbd2cSJim Jagielski }
173*b1cdbd2cSJim Jagielski
getElementType()174*b1cdbd2cSJim Jagielski uno::Type Impl_ModelWinService::getElementType()
175*b1cdbd2cSJim Jagielski throw( css::uno::RuntimeException )
176*b1cdbd2cSJim Jagielski {
177*b1cdbd2cSJim Jagielski return ::getCppuType(( const uno::Reference< awt::XControlModel >*)NULL );
178*b1cdbd2cSJim Jagielski }
179*b1cdbd2cSJim Jagielski
hasElements()180*b1cdbd2cSJim Jagielski sal_Bool Impl_ModelWinService::hasElements()
181*b1cdbd2cSJim Jagielski throw( css::uno::RuntimeException )
182*b1cdbd2cSJim Jagielski {
183*b1cdbd2cSJim Jagielski osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
184*b1cdbd2cSJim Jagielski return (m_aModelMap.size() > 0);
185*b1cdbd2cSJim Jagielski }
186*b1cdbd2cSJim Jagielski
187*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
188*b1cdbd2cSJim Jagielski // css::uno::XInterface, XTypeProvider, XServiceInfo
189*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
190*b1cdbd2cSJim Jagielski
DEFINE_XINTERFACE_4(ModelWinService,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::container::XNameAccess),DIRECT_INTERFACE (css::container::XElementAccess))191*b1cdbd2cSJim Jagielski DEFINE_XINTERFACE_4 ( ModelWinService ,
192*b1cdbd2cSJim Jagielski OWeakObject ,
193*b1cdbd2cSJim Jagielski DIRECT_INTERFACE(css::lang::XTypeProvider ),
194*b1cdbd2cSJim Jagielski DIRECT_INTERFACE(css::lang::XServiceInfo ),
195*b1cdbd2cSJim Jagielski DIRECT_INTERFACE(css::container::XNameAccess ),
196*b1cdbd2cSJim Jagielski DIRECT_INTERFACE(css::container::XElementAccess )
197*b1cdbd2cSJim Jagielski )
198*b1cdbd2cSJim Jagielski
199*b1cdbd2cSJim Jagielski DEFINE_XTYPEPROVIDER_4 ( ModelWinService ,
200*b1cdbd2cSJim Jagielski css::lang::XTypeProvider ,
201*b1cdbd2cSJim Jagielski css::lang::XServiceInfo ,
202*b1cdbd2cSJim Jagielski css::container::XNameAccess ,
203*b1cdbd2cSJim Jagielski css::container::XElementAccess
204*b1cdbd2cSJim Jagielski )
205*b1cdbd2cSJim Jagielski
206*b1cdbd2cSJim Jagielski DEFINE_XSERVICEINFO_MULTISERVICE ( ModelWinService ,
207*b1cdbd2cSJim Jagielski OWeakObject ,
208*b1cdbd2cSJim Jagielski SERVICENAME_MODELWINSERVICE ,
209*b1cdbd2cSJim Jagielski IMPLEMENTATIONNAME_MODELWINSERVICE
210*b1cdbd2cSJim Jagielski )
211*b1cdbd2cSJim Jagielski
212*b1cdbd2cSJim Jagielski DEFINE_INIT_SERVICE ( ModelWinService,
213*b1cdbd2cSJim Jagielski {
214*b1cdbd2cSJim Jagielski }
215*b1cdbd2cSJim Jagielski )
216*b1cdbd2cSJim Jagielski
217*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
218*b1cdbd2cSJim Jagielski // constructor
219*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
220*b1cdbd2cSJim Jagielski ModelWinService::ModelWinService(const uno::Reference< lang::XMultiServiceFactory >& rServiceManager ) :
221*b1cdbd2cSJim Jagielski m_xServiceManager( rServiceManager )
222*b1cdbd2cSJim Jagielski {
223*b1cdbd2cSJim Jagielski }
224*b1cdbd2cSJim Jagielski
~ModelWinService()225*b1cdbd2cSJim Jagielski ModelWinService::~ModelWinService()
226*b1cdbd2cSJim Jagielski {
227*b1cdbd2cSJim Jagielski }
228*b1cdbd2cSJim Jagielski
registerModelForXWindow(const uno::Reference<awt::XWindow> & rWindow,const uno::Reference<awt::XControlModel> & rModel)229*b1cdbd2cSJim Jagielski void ModelWinService::registerModelForXWindow( const uno::Reference< awt::XWindow >& rWindow, const uno::Reference< awt::XControlModel >& rModel )
230*b1cdbd2cSJim Jagielski {
231*b1cdbd2cSJim Jagielski Impl_ModelWinService::getSingleInstance(m_xServiceManager)->registerModelForXWindow( rWindow, rModel );
232*b1cdbd2cSJim Jagielski }
233*b1cdbd2cSJim Jagielski
deregisterModelForXWindow(const uno::Reference<awt::XWindow> & rWindow)234*b1cdbd2cSJim Jagielski void ModelWinService::deregisterModelForXWindow( const uno::Reference< awt::XWindow >& rWindow )
235*b1cdbd2cSJim Jagielski {
236*b1cdbd2cSJim Jagielski Impl_ModelWinService::getSingleInstance(m_xServiceManager)->deregisterModelForXWindow( rWindow );
237*b1cdbd2cSJim Jagielski }
238*b1cdbd2cSJim Jagielski
getByName(const::rtl::OUString & sName)239*b1cdbd2cSJim Jagielski uno::Any SAL_CALL ModelWinService::getByName( const ::rtl::OUString& sName )
240*b1cdbd2cSJim Jagielski throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
241*b1cdbd2cSJim Jagielski {
242*b1cdbd2cSJim Jagielski return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->getByName( sName );
243*b1cdbd2cSJim Jagielski }
244*b1cdbd2cSJim Jagielski
getElementNames()245*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > SAL_CALL ModelWinService::getElementNames()
246*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
247*b1cdbd2cSJim Jagielski {
248*b1cdbd2cSJim Jagielski return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->getElementNames( );
249*b1cdbd2cSJim Jagielski }
250*b1cdbd2cSJim Jagielski
hasByName(const::rtl::OUString & sName)251*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL ModelWinService::hasByName( const ::rtl::OUString& sName )
252*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
253*b1cdbd2cSJim Jagielski {
254*b1cdbd2cSJim Jagielski return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->hasByName( sName );
255*b1cdbd2cSJim Jagielski }
256*b1cdbd2cSJim Jagielski
257*b1cdbd2cSJim Jagielski //---------------------------------------------------------------------------------------------------------
258*b1cdbd2cSJim Jagielski // XElementAccess
259*b1cdbd2cSJim Jagielski //---------------------------------------------------------------------------------------------------------
getElementType()260*b1cdbd2cSJim Jagielski uno::Type SAL_CALL ModelWinService::getElementType()
261*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
262*b1cdbd2cSJim Jagielski {
263*b1cdbd2cSJim Jagielski return ::getCppuType( (const uno::Reference< awt::XControlModel > *)NULL );
264*b1cdbd2cSJim Jagielski }
265*b1cdbd2cSJim Jagielski
hasElements()266*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL ModelWinService::hasElements()
267*b1cdbd2cSJim Jagielski throw( uno::RuntimeException )
268*b1cdbd2cSJim Jagielski {
269*b1cdbd2cSJim Jagielski return Impl_ModelWinService::getSingleInstance(m_xServiceManager)->hasElements();
270*b1cdbd2cSJim Jagielski }
271*b1cdbd2cSJim Jagielski
272*b1cdbd2cSJim Jagielski }
273