1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclstatusindicator.cxx,v $
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>
49 #include <vcl/svapp.hxx>
51 //-----------------------------------------------
56 //-----------------------------------------------
59 //-----------------------------------------------
60 DEFINE_XINTERFACE_1(VCLStatusIndicator
,
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( )
70 , m_xParentWindow (xParentWindow
)
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
,
89 throw(css::uno::RuntimeException
)
91 // SAFE -> ----------------------------------
92 ReadGuard
aReadLock(m_aLock
);
93 css::uno::Reference
< css::awt::XWindow
> xParentWindow
= m_xParentWindow
;
95 // <- SAFE ----------------------------------
97 // SOLAR SAFE -> ----------------------------
98 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
100 Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
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);
111 pParentWindow
->Show();
112 pParentWindow
->Invalidate(INVALIDATE_CHILDREN
);
113 pParentWindow
->Flush();
116 // <- SOLAR SAFE ----------------------------
118 // SAFE -> ----------------------------------
119 WriteGuard
aWriteLock(m_aLock
);
124 // <- SAFE ----------------------------------
127 //-----------------------------------------------
128 void SAL_CALL
VCLStatusIndicator::reset()
129 throw(css::uno::RuntimeException
)
131 // SOLAR SAFE -> ----------------------------
132 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
135 m_pStatusBar
->SetProgressValue(0);
136 m_pStatusBar
->SetText(String());
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();
152 // <- SAFE ----------------------------------
154 // SOLAR SAFE -> ----------------------------
155 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
158 m_pStatusBar
->EndProgressMode();
159 m_pStatusBar
->Show(sal_False
);
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
);
176 // <- SAFE ----------------------------------
178 // SOLAR SAFE -> ----------------------------
179 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
181 m_pStatusBar
->SetText(sText
);
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
)
198 sal_Int32 nRange
= m_nRange
;
202 // <- SAFE ----------------------------------
204 // normalize value to fit the range of 0-100 %
205 USHORT nPercent
= sal::static_int_cast
< USHORT
>(
207 ((nValue
*100) / ::std::max(nRange
,(sal_Int32
)1)), (sal_Int32
)100));
209 // SOLAR SAFE -> ----------------------------
210 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
212 m_pStatusBar
->SetProgressValue(nPercent
);
214 // <- SOLAR SAFE ----------------------------
217 //-----------------------------------------------
218 void VCLStatusIndicator::impl_recalcLayout(Window
* pStatusBar
,
219 Window
* pParentWindow
)
227 Size aParentSize
= pParentWindow
->GetSizePixel();
228 pStatusBar
->SetPosSizePixel(0,
231 aParentSize
.Height());
234 } // namespace framework