LibreOffice Module framework (master) 1
progressbarwrapper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
23
24#include <com/sun/star/ui/UIElementType.hpp>
25#include <com/sun/star/lang/DisposedException.hpp>
26
27#include <vcl/status.hxx>
28#include <vcl/svapp.hxx>
30
31using namespace ::com::sun::star;
32
33namespace framework{
34
36UIElementWrapperBase( css::ui::UIElementType::PROGRESSBAR )
37 , m_bOwnsInstance( false )
38 , m_nRange( 100 )
39 , m_nValue( 0 )
40{
41}
42
44{
45}
46
47// public interfaces
48void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, bool bOwnsInstance )
49{
51
52 if ( m_bDisposed )
53 return;
54
55 if ( m_bOwnsInstance )
56 {
57 // dispose XWindow reference of our status bar
58 try
59 {
60 if ( m_xStatusBar.is() )
61 m_xStatusBar->dispose();
62 }
63 catch ( const uno::Exception& )
64 {
65 }
66 m_xStatusBar.clear();
67 }
68
69 m_bOwnsInstance = bOwnsInstance;
70 m_xStatusBar = rStatusBar;
71}
72
73uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
74{
76
77 if ( m_bDisposed )
78 return uno::Reference< awt::XWindow >();
79
80 return m_xStatusBar;
81}
82
83// wrapped methods of css::task::XStatusIndicator
84void ProgressBarWrapper::start( const OUString& Text, ::sal_Int32 Range )
85{
86 uno::Reference< awt::XWindow > xWindow;
87 sal_Int32 nValue( 0 );
88
89 {
91
92 if ( m_bDisposed )
93 return;
94
95 xWindow = m_xStatusBar;
96 m_nValue = 0;
99 }
100
101 if ( !xWindow.is() )
102 return;
103
104 SolarMutexGuard aSolarMutexGuard;
105 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
106 if ( !(pWindow && pWindow->GetType() == WindowType::STATUSBAR) )
107 return;
108
109 StatusBar* pStatusBar = static_cast<StatusBar *>(pWindow.get());
110 if ( !pStatusBar->IsProgressMode() )
111 pStatusBar->StartProgressMode( Text );
112 else
113 {
114 pStatusBar->SetUpdateMode( false );
115 pStatusBar->EndProgressMode();
116 pStatusBar->StartProgressMode( Text );
117 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
118 pStatusBar->SetUpdateMode( true );
119 }
120 pStatusBar->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate );
121}
122
124{
125 uno::Reference< awt::XWindow > xWindow;
126
127 {
129
130 if ( m_bDisposed )
131 return;
132
133 xWindow = m_xStatusBar;
134 m_nRange = 100;
135 m_nValue = 0;
136 }
137
138 if ( xWindow.is() )
139 {
140 SolarMutexGuard aSolarMutexGuard;
141 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
142 if ( pWindow && pWindow->GetType() == WindowType::STATUSBAR )
143 {
144 StatusBar* pStatusBar = static_cast<StatusBar *>(pWindow.get());
145 if ( pStatusBar->IsProgressMode() )
146 pStatusBar->EndProgressMode();
147 }
148 }
149}
150
151void ProgressBarWrapper::setText( const OUString& Text )
152{
153 uno::Reference< awt::XWindow > xWindow;
154 sal_Int32 nValue( 0 );
155
156 {
158
159 if ( m_bDisposed )
160 return;
161
162 xWindow = m_xStatusBar;
163 m_aText = Text;
165 }
166
167 if ( !xWindow.is() )
168 return;
169
170 SolarMutexGuard aSolarMutexGuard;
171 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
172 if ( !(pWindow && pWindow->GetType() == WindowType::STATUSBAR) )
173 return;
174
175 StatusBar* pStatusBar = static_cast<StatusBar *>(pWindow.get());
176 if( pStatusBar->IsProgressMode() )
177 {
178 pStatusBar->SetUpdateMode( false );
179 pStatusBar->EndProgressMode();
180 pStatusBar->StartProgressMode( Text );
181 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
182 pStatusBar->SetUpdateMode( true );
183 }
184 else
185 pStatusBar->SetText( Text );
186}
187
188void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
189{
190 uno::Reference< awt::XWindow > xWindow;
191 OUString aText;
192 bool bSetValue( false );
193
194 {
196
197 if ( m_bDisposed )
198 return;
199
200 xWindow = m_xStatusBar;
201
202 double fVal( 0 );
203 if ( m_nRange > 0 )
204 {
205 fVal = ( double( nValue ) / double( m_nRange )) * 100;
206 fVal = std::clamp( fVal, 0.0, 100.0 );
207 }
208
209 if ( m_nValue != sal_Int32( fVal ))
210 {
211 m_nValue = sal_Int32( fVal );
212 bSetValue = true;
213 }
214
216 aText = m_aText;
217 }
218
219 if ( xWindow.is() && bSetValue )
220 {
221 SolarMutexGuard aSolarMutexGuard;
222 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
223 if ( pWindow && pWindow->GetType() == WindowType::STATUSBAR )
224 {
225 StatusBar* pStatusBar = static_cast<StatusBar *>(pWindow.get());
226 if ( !pStatusBar->IsProgressMode() )
227 pStatusBar->StartProgressMode( aText );
228 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
229 }
230 }
231}
232
234{
235 setText( OUString() );
236 setValue( 0 );
237}
238
239// XInitialization
240void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
241{
242 // dummy - do nothing
243}
244
245// XUpdatable
247{
248 // dummy - do nothing
249}
250
251// XComponent
253{
254 uno::Reference< lang::XComponent > xThis(this);
255
256 {
258
259 if ( m_bDisposed )
260 return;
261 }
262
263 {
264 lang::EventObject aEvent( xThis );
266
268 if ( m_bOwnsInstance )
269 {
270 try
271 {
272 if ( m_xStatusBar.is() )
273 m_xStatusBar->dispose();
274 }
275 catch ( const lang::DisposedException& )
276 {
277 }
278 }
279
280 m_xStatusBar.clear();
281 m_bDisposed = true;
282 }
283}
284
285// XUIElement
286uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
287{
289
290 if ( m_bDisposed )
291 return uno::Reference< uno::XInterface >();
292 else
293 {
294 uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
295 if ( !xComp.is() )
296 {
298 new StatusIndicatorInterfaceWrapper( uno::Reference< lang::XComponent >(this) );
299 xComp.set(static_cast< cppu::OWeakObject* >( pWrapper.get() ),
300 uno::UNO_QUERY );
302 }
303
304 return xComp;
305 }
306}
307
308} // namespace framework
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
void StartProgressMode(const OUString &rText)
void SetText(const OUString &rText) override
void EndProgressMode()
void SetProgressValue(sal_uInt16 nPercent)
bool IsProgressMode() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
reference_type * get() const
void disposeAndClear(const css::lang::EventObject &rEvt)
virtual ~ProgressBarWrapper() override
virtual void SAL_CALL update() override
virtual void SAL_CALL dispose() override
void start(const OUString &Text, ::sal_Int32 Range)
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRealInterface() override
css::uno::WeakReference< css::uno::XInterface > m_xProgressBarIfacWrapper
css::uno::Reference< css::awt::XWindow > getStatusBar() const
void setValue(::sal_Int32 Value)
void setText(const OUString &Text)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
void setStatusBar(const css::uno::Reference< css::awt::XWindow > &rStatusBar, bool bOwnsInstance=false)
css::uno::Reference< css::awt::XWindow > m_xStatusBar
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer
void SetUpdateMode(bool bUpdate)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
sal_Int16 nValue
const sal_Int16 PROGRESSBAR