update dev300-m58
[ooovba.git] / framework / source / helper / vclstatusindicator.cxx
blob9c46b0e0822426c194c717eea486ff9035ce5607
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclstatusindicator.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <helper/vclstatusindicator.hxx>
35 //-----------------------------------------------
36 // includes of own modules
37 #include <threadhelp/readguard.hxx>
38 #include <threadhelp/writeguard.hxx>
40 //-----------------------------------------------
41 // includes of interfaces
43 //-----------------------------------------------
44 // includes of external modules
46 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
47 #include <toolkit/unohlp.hxx>
48 #endif
49 #include <vcl/svapp.hxx>
51 //-----------------------------------------------
52 // namespace
54 namespace framework {
56 //-----------------------------------------------
57 // definitions
59 //-----------------------------------------------
60 DEFINE_XINTERFACE_1(VCLStatusIndicator ,
61 OWeakObject ,
62 DIRECT_INTERFACE(css::task::XStatusIndicator))
64 //-----------------------------------------------
65 VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
66 const css::uno::Reference< css::awt::XWindow >& xParentWindow)
67 : ThreadHelpBase (&Application::GetSolarMutex())
68 , ::cppu::OWeakObject( )
69 , m_xSMGR (xSMGR )
70 , m_xParentWindow (xParentWindow )
71 , m_pStatusBar (0 )
72 , m_nRange (0 )
73 , m_nValue (0 )
75 if (!m_xParentWindow.is())
76 throw css::uno::RuntimeException(
77 ::rtl::OUString::createFromAscii("Cant work without a parent window!"),
78 static_cast< css::task::XStatusIndicator* >(this));
81 //-----------------------------------------------
82 VCLStatusIndicator::~VCLStatusIndicator()
86 //-----------------------------------------------
87 void SAL_CALL VCLStatusIndicator::start(const ::rtl::OUString& sText ,
88 sal_Int32 nRange)
89 throw(css::uno::RuntimeException)
91 // SAFE -> ----------------------------------
92 ReadGuard aReadLock(m_aLock);
93 css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow;
94 aReadLock.unlock();
95 // <- SAFE ----------------------------------
97 // SOLAR SAFE -> ----------------------------
98 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
100 Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
101 if (!m_pStatusBar)
102 m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
104 VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
106 m_pStatusBar->Show();
107 m_pStatusBar->StartProgressMode(sText);
108 m_pStatusBar->SetProgressValue(0);
110 // force repaint!
111 pParentWindow->Show();
112 pParentWindow->Invalidate(INVALIDATE_CHILDREN);
113 pParentWindow->Flush();
115 aSolarLock.clear();
116 // <- SOLAR SAFE ----------------------------
118 // SAFE -> ----------------------------------
119 WriteGuard aWriteLock(m_aLock);
120 m_sText = sText;
121 m_nRange = nRange;
122 m_nValue = 0;
123 aWriteLock.unlock();
124 // <- SAFE ----------------------------------
127 //-----------------------------------------------
128 void SAL_CALL VCLStatusIndicator::reset()
129 throw(css::uno::RuntimeException)
131 // SOLAR SAFE -> ----------------------------
132 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
133 if (m_pStatusBar)
135 m_pStatusBar->SetProgressValue(0);
136 m_pStatusBar->SetText(String());
138 aSolarLock.clear();
139 // <- SOLAR SAFE ----------------------------
142 //-----------------------------------------------
143 void SAL_CALL VCLStatusIndicator::end()
144 throw(css::uno::RuntimeException)
146 // SAFE -> ----------------------------------
147 WriteGuard aWriteLock(m_aLock);
148 m_sText = ::rtl::OUString();
149 m_nRange = 0;
150 m_nValue = 0;
151 aWriteLock.unlock();
152 // <- SAFE ----------------------------------
154 // SOLAR SAFE -> ----------------------------
155 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
156 if (m_pStatusBar)
158 m_pStatusBar->EndProgressMode();
159 m_pStatusBar->Show(sal_False);
161 delete m_pStatusBar;
162 m_pStatusBar = 0;
164 aSolarLock.clear();
165 // <- SOLAR SAFE ----------------------------
168 //-----------------------------------------------
169 void SAL_CALL VCLStatusIndicator::setText(const ::rtl::OUString& sText)
170 throw(css::uno::RuntimeException)
172 // SAFE -> ----------------------------------
173 WriteGuard aWriteLock(m_aLock);
174 m_sText = sText;
175 aWriteLock.unlock();
176 // <- SAFE ----------------------------------
178 // SOLAR SAFE -> ----------------------------
179 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
180 if (m_pStatusBar)
181 m_pStatusBar->SetText(sText);
182 aSolarLock.clear();
183 // <- SOLAR SAFE ----------------------------
186 //-----------------------------------------------
187 void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
188 throw(css::uno::RuntimeException)
190 // SAFE -> ----------------------------------
191 WriteGuard aWriteLock(m_aLock);
193 if (nValue <= m_nRange)
194 m_nValue = nValue;
195 else
196 m_nValue = m_nRange;
198 sal_Int32 nRange = m_nRange;
199 nValue = m_nValue;
201 aWriteLock.unlock();
202 // <- SAFE ----------------------------------
204 // normalize value to fit the range of 0-100 %
205 USHORT nPercent = sal::static_int_cast< USHORT >(
206 ::std::min(
207 ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
209 // SOLAR SAFE -> ----------------------------
210 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex());
211 if (m_pStatusBar)
212 m_pStatusBar->SetProgressValue(nPercent);
213 aSolarLock.clear();
214 // <- SOLAR SAFE ----------------------------
217 //-----------------------------------------------
218 void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar ,
219 Window* pParentWindow)
221 if (
222 (!pStatusBar ) ||
223 (!pParentWindow)
225 return;
227 Size aParentSize = pParentWindow->GetSizePixel();
228 pStatusBar->SetPosSizePixel(0,
230 aParentSize.Width(),
231 aParentSize.Height());
234 } // namespace framework