LibreOffice Module framework (master) 1
vclstatusindicator.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
23#include <utility>
24#include <vcl/svapp.hxx>
25
26namespace framework {
27
28VCLStatusIndicator::VCLStatusIndicator(css::uno::Reference< css::awt::XWindow > xParentWindow)
29 : m_xParentWindow (std::move(xParentWindow ))
30 , m_pStatusBar (nullptr )
31 , m_nRange (0 )
32 , m_nValue (0 )
33{
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));
38}
39
41{
42}
43
44void SAL_CALL VCLStatusIndicator::start(const OUString& sText ,
45 sal_Int32 nRange)
46{
47 SolarMutexGuard aSolarGuard;
48
50 if (!m_pStatusBar)
52
54
55 m_pStatusBar->Show();
56 m_pStatusBar->StartProgressMode(sText);
57 m_pStatusBar->SetProgressValue(0);
58
59 // force repaint!
60 pParentWindow->Show();
61 pParentWindow->Invalidate(InvalidateFlags::Children);
62 pParentWindow->GetOutDev()->Flush();
63
64 m_nRange = nRange;
65 m_nValue = 0;
66}
67
69{
70 SolarMutexGuard aSolarGuard;
71 if (m_pStatusBar)
72 {
73 m_pStatusBar->SetProgressValue(0);
74 m_pStatusBar->SetText(OUString());
75 }
76}
77
79{
80 SolarMutexGuard aSolarGuard;
81
82 m_nRange = 0;
83 m_nValue = 0;
84
85 if (m_pStatusBar)
86 {
87 m_pStatusBar->EndProgressMode();
88 m_pStatusBar->Show(false);
89
91 }
92}
93
94void SAL_CALL VCLStatusIndicator::setText(const OUString& sText)
95{
96 SolarMutexGuard aSolarGuard;
97 if (m_pStatusBar)
98 m_pStatusBar->SetText(sText);
99}
100
101void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
102{
103 SolarMutexGuard aSolarGuard;
104
105 if (nValue <= m_nRange)
107 else
109
110 sal_Int32 nRange = m_nRange;
112
113 // normalize value to fit the range of 0-100%
114 sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
115 ::std::min(
116 ((nValue*100) / ::std::max(nRange,sal_Int32(1))), sal_Int32(100)));
117
118 if (m_pStatusBar)
119 m_pStatusBar->SetProgressValue(nPercent);
120}
121
123 vcl::Window const * pParentWindow)
124{
125 if (
126 (!pStatusBar ) ||
127 (!pParentWindow)
128 )
129 return;
130
131 Size aParentSize = pParentWindow->GetSizePixel();
132 pStatusBar->setPosSizePixel(0,
133 0,
134 aParentSize.Width(),
135 aParentSize.Height());
136}
137
138} // namespace framework
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SAL_CALL start(const OUString &sText, sal_Int32 nRange) override
XStatusIndicator.
static void impl_recalcLayout(vcl::Window *pStatusBar, vcl::Window const *pParentWindow)
virtual void SAL_CALL end() override
virtual void SAL_CALL setText(const OUString &sText) override
virtual void SAL_CALL setValue(sal_Int32 nValue) override
VclPtr< StatusBar > m_pStatusBar
shows the progress.
css::uno::Reference< css::awt::XWindow > m_xParentWindow
points to the parent window of this progress and hold it alive.
VCLStatusIndicator(css::uno::Reference< css::awt::XWindow > xParentWindow)
ctor
virtual ~VCLStatusIndicator() override
dtor
sal_Int32 m_nValue
knows the current value of the progress.
virtual void SAL_CALL reset() override
sal_Int32 m_nRange
knows the current range of the progress.
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
virtual Size GetSizePixel() const
sal_Int16 nValue
WinBits const WB_3DLOOK
WinBits const WB_BORDER