lok: status update - avoid SIGFPE on zero range.
[LibreOffice.git] / framework / source / helper / statusindicator.cxx
blob25d67694c5dfaa02ce9a69e61f180dd5dc3690f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/lok.hxx>
21 #include <helper/statusindicator.hxx>
23 namespace framework{
25 StatusIndicator::StatusIndicator(StatusIndicatorFactory* pFactory)
26 : m_xFactory(pFactory)
27 , m_nRange(100)
28 , m_nLastCallbackPercent(-1)
32 StatusIndicator::~StatusIndicator()
36 void SAL_CALL StatusIndicator::start(const OUString& sText ,
37 sal_Int32 nRange)
39 if (comphelper::LibreOfficeKit::isActive())
41 m_nRange = nRange;
42 m_nLastCallbackPercent = -1;
44 comphelper::LibreOfficeKit::statusIndicatorStart();
46 #if !defined(IOS) && !defined(ANDROID)
47 css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
48 if (xFactory.is())
50 StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
51 pFactory->start(this, sText, nRange);
53 #else
54 (void) sText;
55 #endif
58 void SAL_CALL StatusIndicator::end()
60 if (comphelper::LibreOfficeKit::isActive())
62 comphelper::LibreOfficeKit::statusIndicatorFinish();
64 #if !defined(IOS) && !defined(ANDROID)
65 css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
66 if (xFactory.is())
68 StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
69 pFactory->end(this);
71 #endif
74 void SAL_CALL StatusIndicator::reset()
76 if (comphelper::LibreOfficeKit::isActive())
77 return;
78 #if !defined(IOS) && !defined(ANDROID)
79 css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
80 if (xFactory.is())
82 StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
83 pFactory->reset(this);
85 #endif
88 void SAL_CALL StatusIndicator::setText(const OUString& sText)
90 if (comphelper::LibreOfficeKit::isActive())
91 return;
92 #if !defined(IOS) && !defined(ANDROID)
93 css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
94 if (xFactory.is())
96 StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
97 pFactory->setText(this, sText);
99 #else
100 (void) sText;
101 #endif
104 void SAL_CALL StatusIndicator::setValue(sal_Int32 nValue)
106 if (comphelper::LibreOfficeKit::isActive())
108 if (m_nRange > 0)
110 int nPercent = (100*nValue)/m_nRange;
111 if (nPercent >= m_nLastCallbackPercent)
113 comphelper::LibreOfficeKit::statusIndicatorSetValue(nPercent);
114 m_nLastCallbackPercent = nPercent;
117 return;
119 #if !defined(IOS) && !defined(ANDROID)
120 css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
121 if (xFactory.is())
123 StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
124 pFactory->setValue(this, nValue);
126 #endif
129 } // namespace framework
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */