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 <threadhelp/readguard.hxx>
23 : #include <threadhelp/writeguard.hxx>
24 :
25 : #include <toolkit/helper/vclunohelper.hxx>
26 : #include <vcl/svapp.hxx>
27 :
28 :
29 : namespace framework {
30 :
31 :
32 : //-----------------------------------------------
33 0 : DEFINE_XINTERFACE_1(VCLStatusIndicator ,
34 : OWeakObject ,
35 : DIRECT_INTERFACE(css::task::XStatusIndicator))
36 :
37 : //-----------------------------------------------
38 0 : VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::awt::XWindow >& xParentWindow)
39 0 : : ThreadHelpBase (&Application::GetSolarMutex())
40 : , ::cppu::OWeakObject( )
41 : , m_xParentWindow (xParentWindow )
42 : , m_pStatusBar (0 )
43 : , m_nRange (0 )
44 0 : , m_nValue (0 )
45 : {
46 0 : if (!m_xParentWindow.is())
47 : throw css::uno::RuntimeException(
48 : OUString("Cant work without a parent window!"),
49 0 : static_cast< css::task::XStatusIndicator* >(this));
50 0 : }
51 :
52 : //-----------------------------------------------
53 0 : VCLStatusIndicator::~VCLStatusIndicator()
54 : {
55 0 : }
56 :
57 : //-----------------------------------------------
58 0 : void SAL_CALL VCLStatusIndicator::start(const OUString& sText ,
59 : sal_Int32 nRange)
60 : throw(css::uno::RuntimeException)
61 : {
62 : // SAFE -> ----------------------------------
63 0 : ReadGuard aReadLock(m_aLock);
64 0 : css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow;
65 0 : aReadLock.unlock();
66 : // <- SAFE ----------------------------------
67 :
68 : // SOLAR SAFE -> ----------------------------
69 : {
70 0 : SolarMutexGuard aSolarGuard;
71 :
72 0 : Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
73 0 : if (!m_pStatusBar)
74 0 : m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
75 :
76 0 : VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
77 :
78 0 : m_pStatusBar->Show();
79 0 : m_pStatusBar->StartProgressMode(sText);
80 0 : m_pStatusBar->SetProgressValue(0);
81 :
82 : // force repaint!
83 0 : pParentWindow->Show();
84 0 : pParentWindow->Invalidate(INVALIDATE_CHILDREN);
85 0 : pParentWindow->Flush();
86 : }
87 : // <- SOLAR SAFE ----------------------------
88 :
89 : // SAFE -> ----------------------------------
90 0 : WriteGuard aWriteLock(m_aLock);
91 0 : m_sText = sText;
92 0 : m_nRange = nRange;
93 0 : m_nValue = 0;
94 0 : aWriteLock.unlock();
95 : // <- SAFE ----------------------------------
96 0 : }
97 :
98 : //-----------------------------------------------
99 0 : void SAL_CALL VCLStatusIndicator::reset()
100 : throw(css::uno::RuntimeException)
101 : {
102 : // SOLAR SAFE -> ----------------------------
103 0 : SolarMutexGuard aSolarGuard;
104 0 : if (m_pStatusBar)
105 : {
106 0 : m_pStatusBar->SetProgressValue(0);
107 0 : m_pStatusBar->SetText(String());
108 0 : }
109 : // <- SOLAR SAFE ----------------------------
110 0 : }
111 :
112 : //-----------------------------------------------
113 0 : void SAL_CALL VCLStatusIndicator::end()
114 : throw(css::uno::RuntimeException)
115 : {
116 : // SAFE -> ----------------------------------
117 0 : WriteGuard aWriteLock(m_aLock);
118 0 : m_sText = OUString();
119 0 : m_nRange = 0;
120 0 : m_nValue = 0;
121 0 : aWriteLock.unlock();
122 : // <- SAFE ----------------------------------
123 :
124 : // SOLAR SAFE -> ----------------------------
125 : {
126 0 : SolarMutexGuard aSolarGuard;
127 0 : if (m_pStatusBar)
128 : {
129 0 : m_pStatusBar->EndProgressMode();
130 0 : m_pStatusBar->Show(sal_False);
131 :
132 0 : delete m_pStatusBar;
133 0 : m_pStatusBar = 0;
134 0 : }
135 0 : }
136 : // <- SOLAR SAFE ----------------------------
137 0 : }
138 :
139 : //-----------------------------------------------
140 0 : void SAL_CALL VCLStatusIndicator::setText(const OUString& sText)
141 : throw(css::uno::RuntimeException)
142 : {
143 : // SAFE -> ----------------------------------
144 0 : WriteGuard aWriteLock(m_aLock);
145 0 : m_sText = sText;
146 0 : aWriteLock.unlock();
147 : // <- SAFE ----------------------------------
148 :
149 : // SOLAR SAFE -> ----------------------------
150 : {
151 0 : SolarMutexGuard aSolarGuard;
152 0 : if (m_pStatusBar)
153 0 : m_pStatusBar->SetText(sText);
154 0 : }
155 : // <- SOLAR SAFE ----------------------------
156 0 : }
157 :
158 : //-----------------------------------------------
159 0 : void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
160 : throw(css::uno::RuntimeException)
161 : {
162 : // SAFE -> ----------------------------------
163 0 : WriteGuard aWriteLock(m_aLock);
164 :
165 0 : if (nValue <= m_nRange)
166 0 : m_nValue = nValue;
167 : else
168 0 : m_nValue = m_nRange;
169 :
170 0 : sal_Int32 nRange = m_nRange;
171 0 : nValue = m_nValue;
172 :
173 0 : aWriteLock.unlock();
174 : // <- SAFE ----------------------------------
175 :
176 : // normalize value to fit the range of 0-100 %
177 : sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
178 : ::std::min(
179 0 : ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
180 :
181 : // SOLAR SAFE -> ----------------------------
182 : {
183 0 : SolarMutexGuard aSolarGuard;
184 0 : if (m_pStatusBar)
185 0 : m_pStatusBar->SetProgressValue(nPercent);
186 0 : }
187 : // <- SOLAR SAFE ----------------------------
188 0 : }
189 :
190 : //-----------------------------------------------
191 0 : void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar ,
192 : Window* pParentWindow)
193 : {
194 0 : if (
195 0 : (!pStatusBar ) ||
196 : (!pParentWindow)
197 : )
198 0 : return;
199 :
200 0 : Size aParentSize = pParentWindow->GetSizePixel();
201 : pStatusBar->setPosSizePixel(0,
202 : 0,
203 0 : aParentSize.Width(),
204 0 : aParentSize.Height());
205 : }
206 :
207 402 : } // namespace framework
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|