Line data Source code
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 <vcl/svapp.hxx>
24 :
25 : namespace framework {
26 :
27 0 : VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::awt::XWindow >& xParentWindow)
28 : : m_xParentWindow (xParentWindow )
29 : , m_pStatusBar (0 )
30 : , m_nRange (0 )
31 0 : , m_nValue (0 )
32 : {
33 0 : if (!m_xParentWindow.is())
34 : throw css::uno::RuntimeException(
35 : OUString("Cant work without a parent window!"),
36 0 : static_cast< css::task::XStatusIndicator* >(this));
37 0 : }
38 :
39 0 : VCLStatusIndicator::~VCLStatusIndicator()
40 : {
41 0 : }
42 :
43 0 : void SAL_CALL VCLStatusIndicator::start(const OUString& sText ,
44 : sal_Int32 nRange)
45 : throw(css::uno::RuntimeException, std::exception)
46 : {
47 0 : SolarMutexGuard aSolarGuard;
48 :
49 0 : Window* pParentWindow = VCLUnoHelper::GetWindow(m_xParentWindow);
50 0 : if (!m_pStatusBar)
51 0 : m_pStatusBar = new StatusBar(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(INVALIDATE_CHILDREN);
62 0 : pParentWindow->Flush();
63 :
64 0 : m_sText = sText;
65 0 : m_nRange = nRange;
66 0 : m_nValue = 0;
67 0 : }
68 :
69 0 : void SAL_CALL VCLStatusIndicator::reset()
70 : throw(css::uno::RuntimeException, std::exception)
71 : {
72 0 : SolarMutexGuard aSolarGuard;
73 0 : if (m_pStatusBar)
74 : {
75 0 : m_pStatusBar->SetProgressValue(0);
76 0 : m_pStatusBar->SetText(OUString());
77 0 : }
78 0 : }
79 :
80 0 : void SAL_CALL VCLStatusIndicator::end()
81 : throw(css::uno::RuntimeException, std::exception)
82 : {
83 0 : SolarMutexGuard aSolarGuard;
84 :
85 0 : m_sText = OUString();
86 0 : m_nRange = 0;
87 0 : m_nValue = 0;
88 :
89 0 : if (m_pStatusBar)
90 : {
91 0 : m_pStatusBar->EndProgressMode();
92 0 : m_pStatusBar->Show(false);
93 :
94 0 : delete m_pStatusBar;
95 0 : m_pStatusBar = 0;
96 0 : }
97 0 : }
98 :
99 0 : void SAL_CALL VCLStatusIndicator::setText(const OUString& sText)
100 : throw(css::uno::RuntimeException, std::exception)
101 : {
102 0 : SolarMutexGuard aSolarGuard;
103 0 : m_sText = sText;
104 0 : if (m_pStatusBar)
105 0 : m_pStatusBar->SetText(sText);
106 0 : }
107 :
108 0 : void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
109 : throw(css::uno::RuntimeException, std::exception)
110 : {
111 0 : SolarMutexGuard aSolarGuard;
112 :
113 0 : if (nValue <= m_nRange)
114 0 : m_nValue = nValue;
115 : else
116 0 : m_nValue = m_nRange;
117 :
118 0 : sal_Int32 nRange = m_nRange;
119 0 : nValue = m_nValue;
120 :
121 : // normalize value to fit the range of 0-100 %
122 : sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
123 : ::std::min(
124 0 : ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
125 :
126 0 : if (m_pStatusBar)
127 0 : m_pStatusBar->SetProgressValue(nPercent);
128 0 : }
129 :
130 0 : void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar ,
131 : Window* pParentWindow)
132 : {
133 0 : if (
134 0 : (!pStatusBar ) ||
135 : (!pParentWindow)
136 : )
137 0 : return;
138 :
139 0 : Size aParentSize = pParentWindow->GetSizePixel();
140 : pStatusBar->setPosSizePixel(0,
141 : 0,
142 0 : aParentSize.Width(),
143 0 : aParentSize.Height());
144 : }
145 :
146 : } // namespace framework
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|