1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ac9096f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ac9096f4SAndrew Rist  * distributed with this work for additional information
6*ac9096f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ac9096f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ac9096f4SAndrew Rist  *
11*ac9096f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist  *
13*ac9096f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist  * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ac9096f4SAndrew Rist  * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist  * under the License.
19*ac9096f4SAndrew Rist  *
20*ac9096f4SAndrew Rist  *************************************************************/
21*ac9096f4SAndrew Rist 
22*ac9096f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir 								TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderManager.hpp>
37cdf0e10cSrcweir #include <osl/mutex.hxx>
38cdf0e10cSrcweir #include <ucbhelper/commandenvironmentproxy.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace com::sun::star::lang;
41cdf0e10cSrcweir using namespace com::sun::star::task;
42cdf0e10cSrcweir using namespace com::sun::star::ucb;
43cdf0e10cSrcweir using namespace com::sun::star::uno;
44cdf0e10cSrcweir using namespace rtl;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace ucbhelper
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //=========================================================================
50cdf0e10cSrcweir //=========================================================================
51cdf0e10cSrcweir //
52cdf0e10cSrcweir // struct CommandEnvironmentProxy_Impl.
53cdf0e10cSrcweir //
54cdf0e10cSrcweir //=========================================================================
55cdf0e10cSrcweir //=========================================================================
56cdf0e10cSrcweir 
57cdf0e10cSrcweir struct CommandEnvironmentProxy_Impl
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	osl::Mutex 						 m_aMutex;
60cdf0e10cSrcweir 	Reference< XCommandEnvironment > m_xEnv;
61cdf0e10cSrcweir 	Reference< XInteractionHandler > m_xInteractionHandler;
62cdf0e10cSrcweir 	Reference< XProgressHandler >    m_xProgressHandler;
63cdf0e10cSrcweir 	sal_Bool m_bGotInteractionHandler;
64cdf0e10cSrcweir 	sal_Bool m_bGotProgressHandler;
65cdf0e10cSrcweir 
CommandEnvironmentProxy_Implucbhelper::CommandEnvironmentProxy_Impl66cdf0e10cSrcweir 	CommandEnvironmentProxy_Impl(
67cdf0e10cSrcweir 		const Reference< XCommandEnvironment >&	rxEnv )
68cdf0e10cSrcweir 	: m_xEnv( rxEnv ), m_bGotInteractionHandler( sal_False ),
69cdf0e10cSrcweir 	  m_bGotProgressHandler( sal_False ) {}
70cdf0e10cSrcweir };
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //=========================================================================
73cdf0e10cSrcweir //=========================================================================
74cdf0e10cSrcweir //
75cdf0e10cSrcweir // CommandEnvironmentProxy Implementation.
76cdf0e10cSrcweir //
77cdf0e10cSrcweir //=========================================================================
78cdf0e10cSrcweir //=========================================================================
79cdf0e10cSrcweir 
CommandEnvironmentProxy(const Reference<XCommandEnvironment> & rxEnv)80cdf0e10cSrcweir CommandEnvironmentProxy::CommandEnvironmentProxy(
81cdf0e10cSrcweir 						const Reference< XCommandEnvironment >& rxEnv )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	m_pImpl = new CommandEnvironmentProxy_Impl( rxEnv );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //=========================================================================
87cdf0e10cSrcweir // virtual
~CommandEnvironmentProxy()88cdf0e10cSrcweir CommandEnvironmentProxy::~CommandEnvironmentProxy()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	delete m_pImpl;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //=========================================================================
94cdf0e10cSrcweir //
95cdf0e10cSrcweir // XInterface methods
96cdf0e10cSrcweir //
97cdf0e10cSrcweir //=========================================================================
98cdf0e10cSrcweir 
99cdf0e10cSrcweir XINTERFACE_IMPL_2( CommandEnvironmentProxy,
100cdf0e10cSrcweir 				   XTypeProvider,
101cdf0e10cSrcweir 				   XCommandEnvironment );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //=========================================================================
104cdf0e10cSrcweir //
105cdf0e10cSrcweir // XTypeProvider methods
106cdf0e10cSrcweir //
107cdf0e10cSrcweir //=========================================================================
108cdf0e10cSrcweir 
109cdf0e10cSrcweir XTYPEPROVIDER_IMPL_2( CommandEnvironmentProxy,
110cdf0e10cSrcweir 					  XTypeProvider,
111cdf0e10cSrcweir 					  XCommandEnvironment );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir //=========================================================================
114cdf0e10cSrcweir //
115cdf0e10cSrcweir // XCommandEnvironemnt methods.
116cdf0e10cSrcweir //
117cdf0e10cSrcweir //=========================================================================
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // virtual
120cdf0e10cSrcweir Reference< XInteractionHandler > SAL_CALL
getInteractionHandler()121cdf0e10cSrcweir CommandEnvironmentProxy::getInteractionHandler()
122cdf0e10cSrcweir 	throw ( RuntimeException )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	if ( m_pImpl->m_xEnv.is() )
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		if ( !m_pImpl->m_bGotInteractionHandler )
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			osl::MutexGuard aGuard( m_pImpl->m_aMutex );
129cdf0e10cSrcweir 			if ( !m_pImpl->m_bGotInteractionHandler )
130cdf0e10cSrcweir 			{
131cdf0e10cSrcweir 				m_pImpl->m_xInteractionHandler
132cdf0e10cSrcweir 								= m_pImpl->m_xEnv->getInteractionHandler();
133cdf0e10cSrcweir 				m_pImpl->m_bGotInteractionHandler = sal_True;
134cdf0e10cSrcweir 			}
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 	return m_pImpl->m_xInteractionHandler;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //=========================================================================
141cdf0e10cSrcweir // virtual
142cdf0e10cSrcweir Reference< XProgressHandler > SAL_CALL
getProgressHandler()143cdf0e10cSrcweir CommandEnvironmentProxy::getProgressHandler()
144cdf0e10cSrcweir 	throw ( RuntimeException )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	if ( m_pImpl->m_xEnv.is() )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir 		if ( !m_pImpl->m_bGotProgressHandler )
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			osl::MutexGuard aGuard( m_pImpl->m_aMutex );
151cdf0e10cSrcweir 			if ( !m_pImpl->m_bGotProgressHandler )
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				m_pImpl->m_xProgressHandler
154cdf0e10cSrcweir 								= m_pImpl->m_xEnv->getProgressHandler();
155cdf0e10cSrcweir 				m_pImpl->m_bGotProgressHandler = sal_True;
156cdf0e10cSrcweir 			}
157cdf0e10cSrcweir 		}
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 	return m_pImpl->m_xProgressHandler;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir } /* namespace ucbhelper */
163cdf0e10cSrcweir 
164