fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / helper / vclstatusindicator.cxx
blob18f08294d489b809f00667b7cb79a256ec8ee89f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <vcl/svapp.hxx>
25 namespace framework {
27 VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::awt::XWindow >& xParentWindow)
28 : m_xParentWindow (xParentWindow )
29 , m_pStatusBar (0 )
30 , m_nRange (0 )
31 , m_nValue (0 )
33 if (!m_xParentWindow.is())
34 throw css::uno::RuntimeException(
35 OUString("Can't work without a parent window!"),
36 static_cast< css::task::XStatusIndicator* >(this));
39 VCLStatusIndicator::~VCLStatusIndicator()
43 void SAL_CALL VCLStatusIndicator::start(const OUString& sText ,
44 sal_Int32 nRange)
45 throw(css::uno::RuntimeException, std::exception)
47 SolarMutexGuard aSolarGuard;
49 vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(m_xParentWindow);
50 if (!m_pStatusBar)
51 m_pStatusBar = VclPtr<StatusBar>::Create(pParentWindow, WB_3DLOOK|WB_BORDER);
53 VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
55 m_pStatusBar->Show();
56 m_pStatusBar->StartProgressMode(sText);
57 m_pStatusBar->SetProgressValue(0);
59 // force repaint!
60 pParentWindow->Show();
61 pParentWindow->Invalidate(INVALIDATE_CHILDREN);
62 pParentWindow->Flush();
64 m_sText = sText;
65 m_nRange = nRange;
66 m_nValue = 0;
69 void SAL_CALL VCLStatusIndicator::reset()
70 throw(css::uno::RuntimeException, std::exception)
72 SolarMutexGuard aSolarGuard;
73 if (m_pStatusBar)
75 m_pStatusBar->SetProgressValue(0);
76 m_pStatusBar->SetText(OUString());
80 void SAL_CALL VCLStatusIndicator::end()
81 throw(css::uno::RuntimeException, std::exception)
83 SolarMutexGuard aSolarGuard;
85 m_sText.clear();
86 m_nRange = 0;
87 m_nValue = 0;
89 if (m_pStatusBar)
91 m_pStatusBar->EndProgressMode();
92 m_pStatusBar->Show(false);
94 m_pStatusBar.disposeAndClear();
98 void SAL_CALL VCLStatusIndicator::setText(const OUString& sText)
99 throw(css::uno::RuntimeException, std::exception)
101 SolarMutexGuard aSolarGuard;
102 m_sText = sText;
103 if (m_pStatusBar)
104 m_pStatusBar->SetText(sText);
107 void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
108 throw(css::uno::RuntimeException, std::exception)
110 SolarMutexGuard aSolarGuard;
112 if (nValue <= m_nRange)
113 m_nValue = nValue;
114 else
115 m_nValue = m_nRange;
117 sal_Int32 nRange = m_nRange;
118 nValue = m_nValue;
120 // normalize value to fit the range of 0-100%
121 sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
122 ::std::min(
123 ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
125 if (m_pStatusBar)
126 m_pStatusBar->SetProgressValue(nPercent);
129 void VCLStatusIndicator::impl_recalcLayout(vcl::Window* pStatusBar ,
130 vcl::Window* pParentWindow)
132 if (
133 (!pStatusBar ) ||
134 (!pParentWindow)
136 return;
138 Size aParentSize = pParentWindow->GetSizePixel();
139 pStatusBar->setPosSizePixel(0,
141 aParentSize.Width(),
142 aParentSize.Height());
145 } // namespace framework
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */