merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / helper / vclstatusindicator.cxx
blob3845c09ffb6fac2e54b31fd60379acbf8d5228aa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 #include <helper/vclstatusindicator.hxx>
32 //-----------------------------------------------
33 // includes of own modules
34 #include <threadhelp/readguard.hxx>
35 #include <threadhelp/writeguard.hxx>
37 //-----------------------------------------------
38 // includes of interfaces
40 //-----------------------------------------------
41 // includes of external modules
43 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
44 #include <toolkit/unohlp.hxx>
45 #endif
46 #include <vcl/svapp.hxx>
48 //-----------------------------------------------
49 // namespace
51 namespace framework {
53 //-----------------------------------------------
54 // definitions
56 //-----------------------------------------------
57 DEFINE_XINTERFACE_1(VCLStatusIndicator ,
58 OWeakObject ,
59 DIRECT_INTERFACE(css::task::XStatusIndicator))
61 //-----------------------------------------------
62 VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
63 const css::uno::Reference< css::awt::XWindow >& xParentWindow)
64 : ThreadHelpBase (&Application::GetSolarMutex())
65 , ::cppu::OWeakObject( )
66 , m_xSMGR (xSMGR )
67 , m_xParentWindow (xParentWindow )
68 , m_pStatusBar (0 )
69 , m_nRange (0 )
70 , m_nValue (0 )
72 if (!m_xParentWindow.is())
73 throw css::uno::RuntimeException(
74 ::rtl::OUString::createFromAscii("Cant work without a parent window!"),
75 static_cast< css::task::XStatusIndicator* >(this));
78 //-----------------------------------------------
79 VCLStatusIndicator::~VCLStatusIndicator()
83 //-----------------------------------------------
84 void SAL_CALL VCLStatusIndicator::start(const ::rtl::OUString& sText ,
85 sal_Int32 nRange)
86 throw(css::uno::RuntimeException)
88 // SAFE -> ----------------------------------
89 ReadGuard aReadLock(m_aLock);
90 css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow;
91 aReadLock.unlock();
92 // <- SAFE ----------------------------------
94 // SOLAR SAFE -> ----------------------------
95 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
97 Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
98 if (!m_pStatusBar)
99 m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
101 VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
103 m_pStatusBar->Show();
104 m_pStatusBar->StartProgressMode(sText);
105 m_pStatusBar->SetProgressValue(0);
107 // force repaint!
108 pParentWindow->Show();
109 pParentWindow->Invalidate(INVALIDATE_CHILDREN);
110 pParentWindow->Flush();
112 aSolarLock.clear();
113 // <- SOLAR SAFE ----------------------------
115 // SAFE -> ----------------------------------
116 WriteGuard aWriteLock(m_aLock);
117 m_sText = sText;
118 m_nRange = nRange;
119 m_nValue = 0;
120 aWriteLock.unlock();
121 // <- SAFE ----------------------------------
124 //-----------------------------------------------
125 void SAL_CALL VCLStatusIndicator::reset()
126 throw(css::uno::RuntimeException)
128 // SOLAR SAFE -> ----------------------------
129 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
130 if (m_pStatusBar)
132 m_pStatusBar->SetProgressValue(0);
133 m_pStatusBar->SetText(String());
135 aSolarLock.clear();
136 // <- SOLAR SAFE ----------------------------
139 //-----------------------------------------------
140 void SAL_CALL VCLStatusIndicator::end()
141 throw(css::uno::RuntimeException)
143 // SAFE -> ----------------------------------
144 WriteGuard aWriteLock(m_aLock);
145 m_sText = ::rtl::OUString();
146 m_nRange = 0;
147 m_nValue = 0;
148 aWriteLock.unlock();
149 // <- SAFE ----------------------------------
151 // SOLAR SAFE -> ----------------------------
152 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
153 if (m_pStatusBar)
155 m_pStatusBar->EndProgressMode();
156 m_pStatusBar->Show(sal_False);
158 delete m_pStatusBar;
159 m_pStatusBar = 0;
161 aSolarLock.clear();
162 // <- SOLAR SAFE ----------------------------
165 //-----------------------------------------------
166 void SAL_CALL VCLStatusIndicator::setText(const ::rtl::OUString& sText)
167 throw(css::uno::RuntimeException)
169 // SAFE -> ----------------------------------
170 WriteGuard aWriteLock(m_aLock);
171 m_sText = sText;
172 aWriteLock.unlock();
173 // <- SAFE ----------------------------------
175 // SOLAR SAFE -> ----------------------------
176 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
177 if (m_pStatusBar)
178 m_pStatusBar->SetText(sText);
179 aSolarLock.clear();
180 // <- SOLAR SAFE ----------------------------
183 //-----------------------------------------------
184 void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
185 throw(css::uno::RuntimeException)
187 // SAFE -> ----------------------------------
188 WriteGuard aWriteLock(m_aLock);
190 if (nValue <= m_nRange)
191 m_nValue = nValue;
192 else
193 m_nValue = m_nRange;
195 sal_Int32 nRange = m_nRange;
196 nValue = m_nValue;
198 aWriteLock.unlock();
199 // <- SAFE ----------------------------------
201 // normalize value to fit the range of 0-100 %
202 USHORT nPercent = sal::static_int_cast< USHORT >(
203 ::std::min(
204 ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
206 // SOLAR SAFE -> ----------------------------
207 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
208 if (m_pStatusBar)
209 m_pStatusBar->SetProgressValue(nPercent);
210 aSolarLock.clear();
211 // <- SOLAR SAFE ----------------------------
214 //-----------------------------------------------
215 void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar ,
216 Window* pParentWindow)
218 if (
219 (!pStatusBar ) ||
220 (!pParentWindow)
222 return;
224 Size aParentSize = pParentWindow->GetSizePixel();
225 pStatusBar->SetPosSizePixel(0,
227 aParentSize.Width(),
228 aParentSize.Height());
231 } // namespace framework