1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <helper/vclstatusindicator.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
24 #include <vcl/svapp.hxx>
28 VCLStatusIndicator::VCLStatusIndicator(css::uno::Reference
< css::awt::XWindow
> xParentWindow
)
29 : m_xParentWindow (std::move(xParentWindow
))
30 , m_pStatusBar (nullptr )
34 if (!m_xParentWindow
.is())
35 throw css::uno::RuntimeException(
36 "Can't work without a parent window!",
37 static_cast< css::task::XStatusIndicator
* >(this));
40 VCLStatusIndicator::~VCLStatusIndicator()
44 void SAL_CALL
VCLStatusIndicator::start(const OUString
& sText
,
47 SolarMutexGuard aSolarGuard
;
49 VclPtr
<vcl::Window
> pParentWindow
= VCLUnoHelper::GetWindow(m_xParentWindow
);
51 m_pStatusBar
= VclPtr
<StatusBar
>::Create(pParentWindow
, WB_3DLOOK
|WB_BORDER
);
53 VCLStatusIndicator::impl_recalcLayout(m_pStatusBar
, pParentWindow
);
56 m_pStatusBar
->StartProgressMode(sText
);
57 m_pStatusBar
->SetProgressValue(0);
60 pParentWindow
->Show();
61 pParentWindow
->Invalidate(InvalidateFlags::Children
);
62 pParentWindow
->GetOutDev()->Flush();
68 void SAL_CALL
VCLStatusIndicator::reset()
70 SolarMutexGuard aSolarGuard
;
73 m_pStatusBar
->SetProgressValue(0);
74 m_pStatusBar
->SetText(OUString());
78 void SAL_CALL
VCLStatusIndicator::end()
80 SolarMutexGuard aSolarGuard
;
87 m_pStatusBar
->EndProgressMode();
88 m_pStatusBar
->Show(false);
90 m_pStatusBar
.disposeAndClear();
94 void SAL_CALL
VCLStatusIndicator::setText(const OUString
& sText
)
96 SolarMutexGuard aSolarGuard
;
98 m_pStatusBar
->SetText(sText
);
101 void SAL_CALL
VCLStatusIndicator::setValue(sal_Int32 nValue
)
103 SolarMutexGuard aSolarGuard
;
105 if (nValue
<= m_nRange
)
110 sal_Int32 nRange
= m_nRange
;
113 // normalize value to fit the range of 0-100%
114 sal_uInt16 nPercent
= sal::static_int_cast
< sal_uInt16
>(
116 ((nValue
*100) / ::std::max(nRange
,sal_Int32(1))), sal_Int32(100)));
119 m_pStatusBar
->SetProgressValue(nPercent
);
122 void VCLStatusIndicator::impl_recalcLayout(vcl::Window
* pStatusBar
,
123 vcl::Window
const * pParentWindow
)
131 Size aParentSize
= pParentWindow
->GetSizePixel();
132 pStatusBar
->setPosSizePixel(0,
135 aParentSize
.Height());
138 } // namespace framework
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */