1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_PROGRESSBARWRAPPER_HXX_
28cdf0e10cSrcweir #include <uielement/progressbarwrapper.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir //	my own includes
33cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34cdf0e10cSrcweir #include <helper/statusindicator.hxx>
35cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
36cdf0e10cSrcweir #include <uielement/statusindicatorinterfacewrapper.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir //	interface includes
40cdf0e10cSrcweir //_________________________________________________________________________________________________________________
41cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
42cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir //	includes of other projects
46cdf0e10cSrcweir //_________________________________________________________________________________________________________________
47cdf0e10cSrcweir #include <vcl/svapp.hxx>
48cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir //	namespace
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir using namespace ::com::sun::star;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir namespace framework{
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58cdf0e10cSrcweir //	non exported const
59cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir //	non exported definitions
63cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //_________________________________________________________________________________________________________________
66cdf0e10cSrcweir //	declarations
67cdf0e10cSrcweir //_________________________________________________________________________________________________________________
68cdf0e10cSrcweir 
ProgressBarWrapper()69cdf0e10cSrcweir ProgressBarWrapper::ProgressBarWrapper() :
70cdf0e10cSrcweir UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR )
71cdf0e10cSrcweir     ,   m_bOwnsInstance( sal_False )
72cdf0e10cSrcweir     ,   m_nRange( 100 )
73cdf0e10cSrcweir     ,   m_nValue( 0 )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
~ProgressBarWrapper()77cdf0e10cSrcweir ProgressBarWrapper::~ProgressBarWrapper()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // public interfaces
setStatusBar(const uno::Reference<awt::XWindow> & rStatusBar,sal_Bool bOwnsInstance)82cdf0e10cSrcweir void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, sal_Bool bOwnsInstance )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     if ( m_bDisposed )
87cdf0e10cSrcweir         return;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     if ( m_bOwnsInstance )
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         // dispose XWindow reference our our status bar
92cdf0e10cSrcweir         uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
93cdf0e10cSrcweir         try
94cdf0e10cSrcweir         {
95cdf0e10cSrcweir             if ( xComponent.is() )
96cdf0e10cSrcweir                 xComponent->dispose();
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         catch ( uno::Exception& )
99cdf0e10cSrcweir         {
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir         m_xStatusBar.clear();
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     m_bOwnsInstance = bOwnsInstance;
105cdf0e10cSrcweir     m_xStatusBar    = rStatusBar;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
getStatusBar() const108cdf0e10cSrcweir uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     if ( m_bDisposed )
113cdf0e10cSrcweir         return uno::Reference< awt::XWindow >();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     return m_xStatusBar;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir // wrapped methods of ::com::sun::star::task::XStatusIndicator
start(const::rtl::OUString & Text,::sal_Int32 Range)119cdf0e10cSrcweir void ProgressBarWrapper::start( const ::rtl::OUString& Text, ::sal_Int32 Range )
120cdf0e10cSrcweir throw (uno::RuntimeException)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
123cdf0e10cSrcweir     sal_Int32                      nValue( 0 );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         if ( m_bDisposed )
129cdf0e10cSrcweir             return;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         xWindow  = m_xStatusBar;
132cdf0e10cSrcweir         m_nValue = 0;
133cdf0e10cSrcweir         m_nRange = Range;
134cdf0e10cSrcweir         nValue   = m_nValue;
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     if ( xWindow.is() )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
140cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
141cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             StatusBar* pStatusBar = (StatusBar *)pWindow;
144cdf0e10cSrcweir             if ( !pStatusBar->IsProgressMode() )
145cdf0e10cSrcweir                 pStatusBar->StartProgressMode( Text );
146cdf0e10cSrcweir             else
147cdf0e10cSrcweir             {
148cdf0e10cSrcweir 			    pStatusBar->SetUpdateMode( sal_False );
149cdf0e10cSrcweir 			    pStatusBar->EndProgressMode();
150cdf0e10cSrcweir                 pStatusBar->StartProgressMode( Text );
151cdf0e10cSrcweir 			    pStatusBar->SetProgressValue( sal_uInt16( nValue ));
152cdf0e10cSrcweir                 pStatusBar->SetUpdateMode( sal_True );
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir             pStatusBar->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
end()159cdf0e10cSrcweir void ProgressBarWrapper::end()
160cdf0e10cSrcweir throw (uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         if ( m_bDisposed )
168cdf0e10cSrcweir             return;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         xWindow  = m_xStatusBar;
171cdf0e10cSrcweir         m_nRange = 100;
172cdf0e10cSrcweir         m_nValue = 0;
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if ( xWindow.is() )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
178cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
179cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             StatusBar* pStatusBar = (StatusBar *)pWindow;
182cdf0e10cSrcweir             if ( pStatusBar->IsProgressMode() )
183cdf0e10cSrcweir                 pStatusBar->EndProgressMode();
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
setText(const::rtl::OUString & Text)188cdf0e10cSrcweir void ProgressBarWrapper::setText( const ::rtl::OUString& Text )
189cdf0e10cSrcweir throw (uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
192cdf0e10cSrcweir     sal_Int32 nValue( 0 );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         if ( m_bDisposed )
198cdf0e10cSrcweir             return;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         xWindow  = m_xStatusBar;
201cdf0e10cSrcweir         m_aText  = Text;
202cdf0e10cSrcweir         nValue   = m_nValue;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     if ( xWindow.is() )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
208cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
209cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             StatusBar* pStatusBar = (StatusBar *)pWindow;
212cdf0e10cSrcweir 			if( pStatusBar->IsProgressMode() )
213cdf0e10cSrcweir             {
214cdf0e10cSrcweir 			    pStatusBar->SetUpdateMode( sal_False );
215cdf0e10cSrcweir 			    pStatusBar->EndProgressMode();
216cdf0e10cSrcweir                 pStatusBar->StartProgressMode( Text );
217cdf0e10cSrcweir 			    pStatusBar->SetProgressValue( sal_uInt16( nValue ));
218cdf0e10cSrcweir                 pStatusBar->SetUpdateMode( sal_True );
219cdf0e10cSrcweir             }
220cdf0e10cSrcweir             else
221cdf0e10cSrcweir                 pStatusBar->SetText( Text );
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
setValue(::sal_Int32 nValue)226cdf0e10cSrcweir void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
227cdf0e10cSrcweir throw (uno::RuntimeException)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
230cdf0e10cSrcweir     rtl::OUString aText;
231cdf0e10cSrcweir     sal_Bool      bSetValue( sal_False );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         if ( m_bDisposed )
237cdf0e10cSrcweir             return;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         xWindow  = m_xStatusBar;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         double fVal( 0 );
242cdf0e10cSrcweir         if ( m_nRange > 0 )
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             fVal = ( double( nValue ) / double( m_nRange )) * 100;
245cdf0e10cSrcweir             fVal = std::max( double( 0 ), std::min( fVal, double( 100 )));
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         if ( m_nValue != sal_Int32( fVal ))
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             m_nValue = sal_Int32( fVal );
251cdf0e10cSrcweir             bSetValue = sal_True;
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         nValue   = m_nValue;
255cdf0e10cSrcweir         aText    = m_aText;
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     if ( xWindow.is() && bSetValue )
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
261cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
262cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             StatusBar* pStatusBar = (StatusBar *)pWindow;
265cdf0e10cSrcweir             if ( !pStatusBar->IsProgressMode() )
266cdf0e10cSrcweir                 pStatusBar->StartProgressMode( aText );
267cdf0e10cSrcweir             pStatusBar->SetProgressValue( sal_uInt16( nValue ));
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
reset()272cdf0e10cSrcweir void ProgressBarWrapper::reset()
273cdf0e10cSrcweir throw (uno::RuntimeException)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     setText( rtl::OUString() );
276cdf0e10cSrcweir     setValue( 0 );
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // XInitialization
initialize(const uno::Sequence<uno::Any> &)280cdf0e10cSrcweir void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
281cdf0e10cSrcweir throw (uno::Exception, uno::RuntimeException)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     // dummy - do nothing
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir // XUpdatable
update()287cdf0e10cSrcweir void SAL_CALL ProgressBarWrapper::update()
288cdf0e10cSrcweir throw (uno::RuntimeException)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     // dummy - do nothing
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir // XComponent
dispose()294cdf0e10cSrcweir void SAL_CALL ProgressBarWrapper::dispose()
295cdf0e10cSrcweir throw (uno::RuntimeException)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     uno::Reference< lang::XComponent > xThis(
298cdf0e10cSrcweir         static_cast< cppu::OWeakObject* >(this),
299cdf0e10cSrcweir         uno::UNO_QUERY );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         ResetableGuard aLock( m_aLock );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir         if ( m_bDisposed )
305cdf0e10cSrcweir             return;
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         lang::EventObject aEvent( xThis );
310cdf0e10cSrcweir         m_aListenerContainer.disposeAndClear( aEvent );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir         ResetableGuard aLock( m_aLock );
313cdf0e10cSrcweir         if ( m_bOwnsInstance )
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             try
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
318cdf0e10cSrcweir                 if ( xComponent.is() )
319cdf0e10cSrcweir                     xComponent->dispose();
320cdf0e10cSrcweir             }
321cdf0e10cSrcweir             catch ( lang::DisposedException& )
322cdf0e10cSrcweir             {
323cdf0e10cSrcweir             }
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         m_xStatusBar.clear();
327cdf0e10cSrcweir         m_bDisposed = sal_True;
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir // XUIElement
getRealInterface()332cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
333cdf0e10cSrcweir throw (uno::RuntimeException)
334cdf0e10cSrcweir {
335cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
336cdf0e10cSrcweir     // Ready for multithreading
337cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     if ( m_bDisposed )
340cdf0e10cSrcweir         return uno::Reference< uno::XInterface >();
341cdf0e10cSrcweir     else
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
344cdf0e10cSrcweir         if ( !xComp.is() )
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             StatusIndicatorInterfaceWrapper* pWrapper =
347cdf0e10cSrcweir                 new StatusIndicatorInterfaceWrapper(
348cdf0e10cSrcweir                     uno::Reference< lang::XComponent >(
349cdf0e10cSrcweir                         static_cast< cppu::OWeakObject* >( this ),
350cdf0e10cSrcweir                         uno::UNO_QUERY ));
351cdf0e10cSrcweir                 xComp = uno::Reference< uno::XInterface >(
352cdf0e10cSrcweir                     static_cast< cppu::OWeakObject* >( pWrapper ),
353cdf0e10cSrcweir                     uno::UNO_QUERY );
354cdf0e10cSrcweir              m_xProgressBarIfacWrapper = xComp;
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         return xComp;
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir }		//	namespace framework
362