1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_framework.hxx" 26 #include <helper/vclstatusindicator.hxx> 27 28 //----------------------------------------------- 29 // includes of own modules 30 #include <threadhelp/readguard.hxx> 31 #include <threadhelp/writeguard.hxx> 32 33 //----------------------------------------------- 34 // includes of interfaces 35 36 //----------------------------------------------- 37 // includes of external modules 38 39 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 40 #include <toolkit/helper/vclunohelper.hxx> 41 #endif 42 #include <vcl/svapp.hxx> 43 44 //----------------------------------------------- 45 // namespace 46 47 namespace framework { 48 49 //----------------------------------------------- 50 // definitions 51 52 //----------------------------------------------- 53 DEFINE_XINTERFACE_1(VCLStatusIndicator , 54 OWeakObject , 55 DIRECT_INTERFACE(css::task::XStatusIndicator)) 56 57 //----------------------------------------------- 58 VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 59 const css::uno::Reference< css::awt::XWindow >& xParentWindow) 60 : ThreadHelpBase (&Application::GetSolarMutex()) 61 , ::cppu::OWeakObject( ) 62 , m_xSMGR (xSMGR ) 63 , m_xParentWindow (xParentWindow ) 64 , m_pStatusBar (0 ) 65 , m_nRange (0 ) 66 , m_nValue (0 ) 67 { 68 if (!m_xParentWindow.is()) 69 throw css::uno::RuntimeException( 70 ::rtl::OUString::createFromAscii("Can't work without a parent window!"), 71 static_cast< css::task::XStatusIndicator* >(this)); 72 } 73 74 //----------------------------------------------- 75 VCLStatusIndicator::~VCLStatusIndicator() 76 { 77 } 78 79 //----------------------------------------------- 80 void SAL_CALL VCLStatusIndicator::start(const ::rtl::OUString& sText , 81 sal_Int32 nRange) 82 { 83 // SAFE -> ---------------------------------- 84 ReadGuard aReadLock(m_aLock); 85 css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow; 86 aReadLock.unlock(); 87 // <- SAFE ---------------------------------- 88 89 // SOLAR SAFE -> ---------------------------- 90 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex()); 91 92 Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 93 if (!m_pStatusBar) 94 m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER); 95 96 VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow); 97 98 m_pStatusBar->Show(); 99 m_pStatusBar->StartProgressMode(sText); 100 m_pStatusBar->SetProgressValue(0); 101 102 // force repaint! 103 pParentWindow->Show(); 104 pParentWindow->Invalidate(INVALIDATE_CHILDREN); 105 pParentWindow->Flush(); 106 107 aSolarLock.clear(); 108 // <- SOLAR SAFE ---------------------------- 109 110 // SAFE -> ---------------------------------- 111 WriteGuard aWriteLock(m_aLock); 112 m_sText = sText; 113 m_nRange = nRange; 114 m_nValue = 0; 115 aWriteLock.unlock(); 116 // <- SAFE ---------------------------------- 117 } 118 119 //----------------------------------------------- 120 void SAL_CALL VCLStatusIndicator::reset() 121 { 122 // SOLAR SAFE -> ---------------------------- 123 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex()); 124 if (m_pStatusBar) 125 { 126 m_pStatusBar->SetProgressValue(0); 127 m_pStatusBar->SetText(String()); 128 } 129 aSolarLock.clear(); 130 // <- SOLAR SAFE ---------------------------- 131 } 132 133 //----------------------------------------------- 134 void SAL_CALL VCLStatusIndicator::end() 135 { 136 // SAFE -> ---------------------------------- 137 WriteGuard aWriteLock(m_aLock); 138 m_sText = ::rtl::OUString(); 139 m_nRange = 0; 140 m_nValue = 0; 141 aWriteLock.unlock(); 142 // <- SAFE ---------------------------------- 143 144 // SOLAR SAFE -> ---------------------------- 145 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex()); 146 if (m_pStatusBar) 147 { 148 m_pStatusBar->EndProgressMode(); 149 m_pStatusBar->Show(sal_False); 150 151 delete m_pStatusBar; 152 m_pStatusBar = 0; 153 } 154 aSolarLock.clear(); 155 // <- SOLAR SAFE ---------------------------- 156 } 157 158 //----------------------------------------------- 159 void SAL_CALL VCLStatusIndicator::setText(const ::rtl::OUString& sText) 160 { 161 // SAFE -> ---------------------------------- 162 WriteGuard aWriteLock(m_aLock); 163 m_sText = sText; 164 aWriteLock.unlock(); 165 // <- SAFE ---------------------------------- 166 167 // SOLAR SAFE -> ---------------------------- 168 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex()); 169 if (m_pStatusBar) 170 m_pStatusBar->SetText(sText); 171 aSolarLock.clear(); 172 // <- SOLAR SAFE ---------------------------- 173 } 174 175 //----------------------------------------------- 176 void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue) 177 { 178 // SAFE -> ---------------------------------- 179 WriteGuard aWriteLock(m_aLock); 180 181 if (nValue <= m_nRange) 182 m_nValue = nValue; 183 else 184 m_nValue = m_nRange; 185 186 sal_Int32 nRange = m_nRange; 187 nValue = m_nValue; 188 189 aWriteLock.unlock(); 190 // <- SAFE ---------------------------------- 191 192 // normalize value to fit the range of 0-100 % 193 sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >( 194 ::std::min( 195 ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100)); 196 197 // SOLAR SAFE -> ---------------------------- 198 ::vos::OClearableGuard aSolarLock(Application::GetSolarMutex()); 199 if (m_pStatusBar) 200 m_pStatusBar->SetProgressValue(nPercent); 201 aSolarLock.clear(); 202 // <- SOLAR SAFE ---------------------------- 203 } 204 205 //----------------------------------------------- 206 void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar , 207 Window* pParentWindow) 208 { 209 if ( 210 (!pStatusBar ) || 211 (!pParentWindow) 212 ) 213 return; 214 215 Size aParentSize = pParentWindow->GetSizePixel(); 216 pStatusBar->SetPosSizePixel(0, 217 0, 218 aParentSize.Width(), 219 aParentSize.Height()); 220 } 221 222 } // namespace framework 223