/src/libreoffice/framework/source/helper/vclstatusindicator.cxx
Line | Count | Source |
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 | | |
20 | | #include <helper/vclstatusindicator.hxx> |
21 | | |
22 | | #include <toolkit/helper/vclunohelper.hxx> |
23 | | #include <utility> |
24 | | #include <vcl/svapp.hxx> |
25 | | |
26 | | namespace framework { |
27 | | |
28 | | VCLStatusIndicator::VCLStatusIndicator(css::uno::Reference< css::awt::XWindow > xParentWindow) |
29 | 0 | : m_xParentWindow (std::move(xParentWindow )) |
30 | 0 | , m_pStatusBar (nullptr ) |
31 | 0 | , m_nRange (0 ) |
32 | 0 | , m_nValue (0 ) |
33 | 0 | { |
34 | 0 | if (!m_xParentWindow.is()) |
35 | 0 | throw css::uno::RuntimeException( |
36 | 0 | u"Can't work without a parent window!"_ustr, |
37 | 0 | static_cast< css::task::XStatusIndicator* >(this)); |
38 | 0 | } |
39 | | |
40 | | VCLStatusIndicator::~VCLStatusIndicator() |
41 | 0 | { |
42 | 0 | } |
43 | | |
44 | | void SAL_CALL VCLStatusIndicator::start(const OUString& sText , |
45 | | sal_Int32 nRange) |
46 | 0 | { |
47 | 0 | SolarMutexGuard aSolarGuard; |
48 | |
|
49 | 0 | VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(m_xParentWindow); |
50 | 0 | if (!m_pStatusBar) |
51 | 0 | m_pStatusBar = VclPtr<StatusBar>::Create(pParentWindow, WB_3DLOOK|WB_BORDER); |
52 | |
|
53 | 0 | VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow); |
54 | |
|
55 | 0 | m_pStatusBar->Show(); |
56 | 0 | m_pStatusBar->StartProgressMode(sText); |
57 | 0 | m_pStatusBar->SetProgressValue(0); |
58 | | |
59 | | // force repaint! |
60 | 0 | pParentWindow->Show(); |
61 | 0 | pParentWindow->Invalidate(InvalidateFlags::Children); |
62 | 0 | pParentWindow->GetOutDev()->Flush(); |
63 | |
|
64 | 0 | m_nRange = nRange; |
65 | 0 | m_nValue = 0; |
66 | 0 | } |
67 | | |
68 | | void SAL_CALL VCLStatusIndicator::reset() |
69 | 0 | { |
70 | 0 | SolarMutexGuard aSolarGuard; |
71 | 0 | if (m_pStatusBar) |
72 | 0 | { |
73 | 0 | m_pStatusBar->SetProgressValue(0); |
74 | 0 | m_pStatusBar->SetText(OUString()); |
75 | 0 | } |
76 | 0 | } |
77 | | |
78 | | void SAL_CALL VCLStatusIndicator::end() |
79 | 0 | { |
80 | 0 | SolarMutexGuard aSolarGuard; |
81 | |
|
82 | 0 | m_nRange = 0; |
83 | 0 | m_nValue = 0; |
84 | |
|
85 | 0 | if (m_pStatusBar) |
86 | 0 | { |
87 | 0 | m_pStatusBar->EndProgressMode(); |
88 | 0 | m_pStatusBar->Show(false); |
89 | |
|
90 | 0 | m_pStatusBar.disposeAndClear(); |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | void SAL_CALL VCLStatusIndicator::setText(const OUString& sText) |
95 | 0 | { |
96 | 0 | SolarMutexGuard aSolarGuard; |
97 | 0 | if (m_pStatusBar) |
98 | 0 | m_pStatusBar->SetText(sText); |
99 | 0 | } |
100 | | |
101 | | void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue) |
102 | 0 | { |
103 | 0 | SolarMutexGuard aSolarGuard; |
104 | |
|
105 | 0 | if (nValue <= m_nRange) |
106 | 0 | m_nValue = nValue; |
107 | 0 | else |
108 | 0 | m_nValue = m_nRange; |
109 | |
|
110 | 0 | sal_Int32 nRange = m_nRange; |
111 | 0 | nValue = m_nValue; |
112 | | |
113 | | // normalize value to fit the range of 0-100% |
114 | 0 | sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >( |
115 | 0 | ::std::min( |
116 | 0 | ((nValue*100) / ::std::max(nRange,sal_Int32(1))), sal_Int32(100))); |
117 | |
|
118 | 0 | if (m_pStatusBar) |
119 | 0 | m_pStatusBar->SetProgressValue(nPercent); |
120 | 0 | } |
121 | | |
122 | | void VCLStatusIndicator::impl_recalcLayout(vcl::Window* pStatusBar , |
123 | | vcl::Window const * pParentWindow) |
124 | 0 | { |
125 | 0 | if ( |
126 | 0 | (!pStatusBar ) || |
127 | 0 | (!pParentWindow) |
128 | 0 | ) |
129 | 0 | return; |
130 | | |
131 | 0 | Size aParentSize = pParentWindow->GetSizePixel(); |
132 | 0 | pStatusBar->setPosSizePixel(0, |
133 | 0 | 0, |
134 | 0 | aParentSize.Width(), |
135 | 0 | aParentSize.Height()); |
136 | 0 | } |
137 | | |
138 | | } // namespace framework |
139 | | |
140 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |