Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <helper/vclstatusindicator.hxx>
30 : :
31 : : #include <threadhelp/readguard.hxx>
32 : : #include <threadhelp/writeguard.hxx>
33 : :
34 : : #include <toolkit/unohlp.hxx>
35 : : #include <vcl/svapp.hxx>
36 : :
37 : :
38 : : namespace framework {
39 : :
40 : :
41 : : //-----------------------------------------------
42 [ # # ][ # # ]: 0 : DEFINE_XINTERFACE_1(VCLStatusIndicator ,
43 : : OWeakObject ,
44 : : DIRECT_INTERFACE(css::task::XStatusIndicator))
45 : :
46 : : //-----------------------------------------------
47 : 0 : VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
48 : : const css::uno::Reference< css::awt::XWindow >& xParentWindow)
49 [ # # ]: 0 : : ThreadHelpBase (&Application::GetSolarMutex())
50 : : , ::cppu::OWeakObject( )
51 : : , m_xSMGR (xSMGR )
52 : : , m_xParentWindow (xParentWindow )
53 : : , m_pStatusBar (0 )
54 : : , m_nRange (0 )
55 [ # # ]: 0 : , m_nValue (0 )
56 : : {
57 [ # # ]: 0 : if (!m_xParentWindow.is())
58 : : throw css::uno::RuntimeException(
59 : : ::rtl::OUString("Cant work without a parent window!"),
60 [ # # ][ # # ]: 0 : static_cast< css::task::XStatusIndicator* >(this));
61 : 0 : }
62 : :
63 : : //-----------------------------------------------
64 [ # # ][ # # ]: 0 : VCLStatusIndicator::~VCLStatusIndicator()
65 : : {
66 [ # # ]: 0 : }
67 : :
68 : : //-----------------------------------------------
69 : 0 : void SAL_CALL VCLStatusIndicator::start(const ::rtl::OUString& sText ,
70 : : sal_Int32 nRange)
71 : : throw(css::uno::RuntimeException)
72 : : {
73 : : // SAFE -> ----------------------------------
74 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
75 : 0 : css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow;
76 [ # # ]: 0 : aReadLock.unlock();
77 : : // <- SAFE ----------------------------------
78 : :
79 : : // SOLAR SAFE -> ----------------------------
80 : : {
81 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
82 : :
83 [ # # ]: 0 : Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
84 [ # # ]: 0 : if (!m_pStatusBar)
85 [ # # ][ # # ]: 0 : m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
86 : :
87 [ # # ]: 0 : VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
88 : :
89 [ # # ]: 0 : m_pStatusBar->Show();
90 [ # # ][ # # ]: 0 : m_pStatusBar->StartProgressMode(sText);
[ # # ]
91 [ # # ]: 0 : m_pStatusBar->SetProgressValue(0);
92 : :
93 : : // force repaint!
94 [ # # ]: 0 : pParentWindow->Show();
95 [ # # ]: 0 : pParentWindow->Invalidate(INVALIDATE_CHILDREN);
96 [ # # ][ # # ]: 0 : pParentWindow->Flush();
97 : : }
98 : : // <- SOLAR SAFE ----------------------------
99 : :
100 : : // SAFE -> ----------------------------------
101 [ # # ]: 0 : WriteGuard aWriteLock(m_aLock);
102 : 0 : m_sText = sText;
103 : 0 : m_nRange = nRange;
104 : 0 : m_nValue = 0;
105 [ # # ][ # # ]: 0 : aWriteLock.unlock();
[ # # ]
106 : : // <- SAFE ----------------------------------
107 : 0 : }
108 : :
109 : : //-----------------------------------------------
110 : 0 : void SAL_CALL VCLStatusIndicator::reset()
111 : : throw(css::uno::RuntimeException)
112 : : {
113 : : // SOLAR SAFE -> ----------------------------
114 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
115 [ # # ]: 0 : if (m_pStatusBar)
116 : : {
117 [ # # ]: 0 : m_pStatusBar->SetProgressValue(0);
118 [ # # ][ # # ]: 0 : m_pStatusBar->SetText(String());
[ # # ]
119 [ # # ]: 0 : }
120 : : // <- SOLAR SAFE ----------------------------
121 : 0 : }
122 : :
123 : : //-----------------------------------------------
124 : 0 : void SAL_CALL VCLStatusIndicator::end()
125 : : throw(css::uno::RuntimeException)
126 : : {
127 : : // SAFE -> ----------------------------------
128 [ # # ]: 0 : WriteGuard aWriteLock(m_aLock);
129 : 0 : m_sText = ::rtl::OUString();
130 : 0 : m_nRange = 0;
131 : 0 : m_nValue = 0;
132 [ # # ]: 0 : aWriteLock.unlock();
133 : : // <- SAFE ----------------------------------
134 : :
135 : : // SOLAR SAFE -> ----------------------------
136 : : {
137 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
138 [ # # ]: 0 : if (m_pStatusBar)
139 : : {
140 [ # # ]: 0 : m_pStatusBar->EndProgressMode();
141 [ # # ]: 0 : m_pStatusBar->Show(sal_False);
142 : :
143 [ # # ][ # # ]: 0 : delete m_pStatusBar;
144 : 0 : m_pStatusBar = 0;
145 [ # # ]: 0 : }
146 [ # # ]: 0 : }
147 : : // <- SOLAR SAFE ----------------------------
148 : 0 : }
149 : :
150 : : //-----------------------------------------------
151 : 0 : void SAL_CALL VCLStatusIndicator::setText(const ::rtl::OUString& sText)
152 : : throw(css::uno::RuntimeException)
153 : : {
154 : : // SAFE -> ----------------------------------
155 [ # # ]: 0 : WriteGuard aWriteLock(m_aLock);
156 : 0 : m_sText = sText;
157 [ # # ]: 0 : aWriteLock.unlock();
158 : : // <- SAFE ----------------------------------
159 : :
160 : : // SOLAR SAFE -> ----------------------------
161 : : {
162 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
163 [ # # ]: 0 : if (m_pStatusBar)
164 [ # # ][ # # ]: 0 : m_pStatusBar->SetText(sText);
[ # # ][ # # ]
165 [ # # ]: 0 : }
166 : : // <- SOLAR SAFE ----------------------------
167 : 0 : }
168 : :
169 : : //-----------------------------------------------
170 : 0 : void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
171 : : throw(css::uno::RuntimeException)
172 : : {
173 : : // SAFE -> ----------------------------------
174 [ # # ]: 0 : WriteGuard aWriteLock(m_aLock);
175 : :
176 [ # # ]: 0 : if (nValue <= m_nRange)
177 : 0 : m_nValue = nValue;
178 : : else
179 : 0 : m_nValue = m_nRange;
180 : :
181 : 0 : sal_Int32 nRange = m_nRange;
182 : 0 : nValue = m_nValue;
183 : :
184 [ # # ]: 0 : aWriteLock.unlock();
185 : : // <- SAFE ----------------------------------
186 : :
187 : : // normalize value to fit the range of 0-100 %
188 : : sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
189 : : ::std::min(
190 [ # # ][ # # ]: 0 : ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
191 : :
192 : : // SOLAR SAFE -> ----------------------------
193 : : {
194 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
195 [ # # ]: 0 : if (m_pStatusBar)
196 [ # # ][ # # ]: 0 : m_pStatusBar->SetProgressValue(nPercent);
197 [ # # ]: 0 : }
198 : : // <- SOLAR SAFE ----------------------------
199 : 0 : }
200 : :
201 : : //-----------------------------------------------
202 : 0 : void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar ,
203 : : Window* pParentWindow)
204 : : {
205 [ # # ][ # # ]: 0 : if (
206 : : (!pStatusBar ) ||
207 : : (!pParentWindow)
208 : : )
209 : 0 : return;
210 : :
211 [ # # ]: 0 : Size aParentSize = pParentWindow->GetSizePixel();
212 : : pStatusBar->SetPosSizePixel(0,
213 : : 0,
214 : 0 : aParentSize.Width(),
215 [ # # ]: 0 : aParentSize.Height());
216 : : }
217 : :
218 : : } // namespace framework
219 : :
220 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|