2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-11-26 13:30:58 +00:00
|
|
|
|
|
|
|
#include <helper/vclstatusindicator.hxx>
|
|
|
|
|
2013-06-28 04:38:06 +02:00
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
2004-11-26 13:30:58 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
|
|
|
|
namespace framework {
|
|
|
|
|
2013-05-27 15:35:24 +02:00
|
|
|
VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::awt::XWindow >& xParentWindow)
|
2014-03-18 15:12:03 +01:00
|
|
|
: m_xParentWindow (xParentWindow )
|
2004-11-26 13:30:58 +00:00
|
|
|
, m_pStatusBar (0 )
|
|
|
|
, m_nRange (0 )
|
|
|
|
, m_nValue (0 )
|
|
|
|
{
|
|
|
|
if (!m_xParentWindow.is())
|
|
|
|
throw css::uno::RuntimeException(
|
2014-04-29 19:05:05 +00:00
|
|
|
OUString("Can't work without a parent window!"),
|
2004-11-26 13:30:58 +00:00
|
|
|
static_cast< css::task::XStatusIndicator* >(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
VCLStatusIndicator::~VCLStatusIndicator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL VCLStatusIndicator::start(const OUString& sText ,
|
2004-11-26 13:30:58 +00:00
|
|
|
sal_Int32 nRange)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2014-03-18 15:12:03 +01:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(m_xParentWindow);
|
2014-03-18 15:12:03 +01:00
|
|
|
if (!m_pStatusBar)
|
|
|
|
m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-03-18 15:12:03 +01:00
|
|
|
VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-03-18 15:12:03 +01:00
|
|
|
m_pStatusBar->Show();
|
|
|
|
m_pStatusBar->StartProgressMode(sText);
|
|
|
|
m_pStatusBar->SetProgressValue(0);
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-03-18 15:12:03 +01:00
|
|
|
// force repaint!
|
|
|
|
pParentWindow->Show();
|
|
|
|
pParentWindow->Invalidate(INVALIDATE_CHILDREN);
|
|
|
|
pParentWindow->Flush();
|
2004-11-26 13:30:58 +00:00
|
|
|
|
|
|
|
m_sText = sText;
|
|
|
|
m_nRange = nRange;
|
|
|
|
m_nValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL VCLStatusIndicator::reset()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-11-26 13:30:58 +00:00
|
|
|
if (m_pStatusBar)
|
|
|
|
{
|
|
|
|
m_pStatusBar->SetProgressValue(0);
|
2013-09-16 09:58:03 +02:00
|
|
|
m_pStatusBar->SetText(OUString());
|
2004-11-26 13:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL VCLStatusIndicator::end()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2014-03-18 15:12:03 +01:00
|
|
|
SolarMutexGuard aSolarGuard;
|
|
|
|
|
2014-11-12 14:24:10 +05:30
|
|
|
m_sText.clear();
|
2004-11-26 13:30:58 +00:00
|
|
|
m_nRange = 0;
|
|
|
|
m_nValue = 0;
|
|
|
|
|
2014-03-18 15:12:03 +01:00
|
|
|
if (m_pStatusBar)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2014-03-18 15:12:03 +01:00
|
|
|
m_pStatusBar->EndProgressMode();
|
|
|
|
m_pStatusBar->Show(false);
|
|
|
|
|
|
|
|
delete m_pStatusBar;
|
|
|
|
m_pStatusBar = 0;
|
2004-11-26 13:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL VCLStatusIndicator::setText(const OUString& sText)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2014-03-18 15:12:03 +01:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-11-26 13:30:58 +00:00
|
|
|
m_sText = sText;
|
2014-03-18 15:12:03 +01:00
|
|
|
if (m_pStatusBar)
|
|
|
|
m_pStatusBar->SetText(sText);
|
2004-11-26 13:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
2014-03-18 15:12:03 +01:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-11-26 13:30:58 +00:00
|
|
|
|
|
|
|
if (nValue <= m_nRange)
|
|
|
|
m_nValue = nValue;
|
|
|
|
else
|
|
|
|
m_nValue = m_nRange;
|
|
|
|
|
|
|
|
sal_Int32 nRange = m_nRange;
|
2014-03-18 15:12:03 +01:00
|
|
|
nValue = m_nValue;
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-05-05 22:27:38 +02:00
|
|
|
// normalize value to fit the range of 0-100%
|
2010-11-05 10:31:15 +08:00
|
|
|
sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
|
2006-10-12 09:40:31 +00:00
|
|
|
::std::min(
|
|
|
|
((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
|
2004-11-26 13:30:58 +00:00
|
|
|
|
2014-03-18 15:12:03 +01:00
|
|
|
if (m_pStatusBar)
|
|
|
|
m_pStatusBar->SetProgressValue(nPercent);
|
2004-11-26 13:30:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
void VCLStatusIndicator::impl_recalcLayout(vcl::Window* pStatusBar ,
|
|
|
|
vcl::Window* pParentWindow)
|
2004-11-26 13:30:58 +00:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
(!pStatusBar ) ||
|
|
|
|
(!pParentWindow)
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Size aParentSize = pParentWindow->GetSizePixel();
|
2012-08-24 12:34:22 +01:00
|
|
|
pStatusBar->setPosSizePixel(0,
|
2004-11-26 13:30:58 +00:00
|
|
|
0,
|
|
|
|
aParentSize.Width(),
|
|
|
|
aParentSize.Height());
|
|
|
|
}
|
|
|
|
|
2006-06-19 10:20:36 +00:00
|
|
|
} // namespace framework
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|