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>
46 #include <vcl/svapp.hxx>
48 //-----------------------------------------------
53 //-----------------------------------------------
56 //-----------------------------------------------
57 DEFINE_XINTERFACE_1(VCLStatusIndicator
,
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( )
67 , m_xParentWindow (xParentWindow
)
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
,
86 throw(css::uno::RuntimeException
)
88 // SAFE -> ----------------------------------
89 ReadGuard
aReadLock(m_aLock
);
90 css::uno::Reference
< css::awt::XWindow
> xParentWindow
= m_xParentWindow
;
92 // <- SAFE ----------------------------------
94 // SOLAR SAFE -> ----------------------------
95 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
97 Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
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);
108 pParentWindow
->Show();
109 pParentWindow
->Invalidate(INVALIDATE_CHILDREN
);
110 pParentWindow
->Flush();
113 // <- SOLAR SAFE ----------------------------
115 // SAFE -> ----------------------------------
116 WriteGuard
aWriteLock(m_aLock
);
121 // <- SAFE ----------------------------------
124 //-----------------------------------------------
125 void SAL_CALL
VCLStatusIndicator::reset()
126 throw(css::uno::RuntimeException
)
128 // SOLAR SAFE -> ----------------------------
129 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
132 m_pStatusBar
->SetProgressValue(0);
133 m_pStatusBar
->SetText(String());
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();
149 // <- SAFE ----------------------------------
151 // SOLAR SAFE -> ----------------------------
152 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
155 m_pStatusBar
->EndProgressMode();
156 m_pStatusBar
->Show(sal_False
);
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
);
173 // <- SAFE ----------------------------------
175 // SOLAR SAFE -> ----------------------------
176 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
178 m_pStatusBar
->SetText(sText
);
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
)
195 sal_Int32 nRange
= m_nRange
;
199 // <- SAFE ----------------------------------
201 // normalize value to fit the range of 0-100 %
202 USHORT nPercent
= sal::static_int_cast
< USHORT
>(
204 ((nValue
*100) / ::std::max(nRange
,(sal_Int32
)1)), (sal_Int32
)100));
206 // SOLAR SAFE -> ----------------------------
207 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
209 m_pStatusBar
->SetProgressValue(nPercent
);
211 // <- SOLAR SAFE ----------------------------
214 //-----------------------------------------------
215 void VCLStatusIndicator::impl_recalcLayout(Window
* pStatusBar
,
216 Window
* pParentWindow
)
224 Size aParentSize
= pParentWindow
->GetSizePixel();
225 pStatusBar
->SetPosSizePixel(0,
228 aParentSize
.Height());
231 } // namespace framework