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 <comphelper/lok.hxx>
21 : #include <helper/statusindicator.hxx>
22 :
23 : namespace framework{
24 :
25 3188 : StatusIndicator::StatusIndicator(StatusIndicatorFactory* pFactory)
26 : : m_xFactory(pFactory)
27 : , m_nRange(100)
28 3188 : , m_nLastCallbackPercent(-1)
29 : {
30 3188 : }
31 :
32 6370 : StatusIndicator::~StatusIndicator()
33 : {
34 6370 : }
35 :
36 2411 : void SAL_CALL StatusIndicator::start(const OUString& sText ,
37 : sal_Int32 nRange)
38 : throw(css::uno::RuntimeException, std::exception)
39 : {
40 2411 : if (comphelper::LibreOfficeKit::isActive())
41 : {
42 3 : m_nRange = nRange;
43 3 : m_nLastCallbackPercent = -1;
44 :
45 3 : comphelper::LibreOfficeKit::statusIndicatorStart();
46 2414 : return;
47 : }
48 :
49 2408 : css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
50 2408 : if (xFactory.is())
51 : {
52 2408 : StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
53 2408 : pFactory->start(this, sText, nRange);
54 2408 : }
55 : }
56 :
57 2531 : void SAL_CALL StatusIndicator::end()
58 : throw(css::uno::RuntimeException, std::exception)
59 : {
60 2531 : if (comphelper::LibreOfficeKit::isActive())
61 : {
62 3 : comphelper::LibreOfficeKit::statusIndicatorFinish();
63 2534 : return;
64 : }
65 :
66 2528 : css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
67 2528 : if (xFactory.is())
68 : {
69 2528 : StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
70 2528 : pFactory->end(this);
71 2528 : }
72 : }
73 :
74 355 : void SAL_CALL StatusIndicator::reset()
75 : throw(css::uno::RuntimeException, std::exception)
76 : {
77 355 : if (comphelper::LibreOfficeKit::isActive())
78 357 : return;
79 :
80 353 : css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
81 353 : if (xFactory.is())
82 : {
83 353 : StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
84 353 : pFactory->reset(this);
85 353 : }
86 : }
87 :
88 0 : void SAL_CALL StatusIndicator::setText(const OUString& sText)
89 : throw(css::uno::RuntimeException, std::exception)
90 : {
91 0 : if (comphelper::LibreOfficeKit::isActive())
92 0 : return;
93 :
94 0 : css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
95 0 : if (xFactory.is())
96 : {
97 0 : StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
98 0 : pFactory->setText(this, sText);
99 0 : }
100 : }
101 :
102 35296 : void SAL_CALL StatusIndicator::setValue(sal_Int32 nValue)
103 : throw(css::uno::RuntimeException, std::exception)
104 : {
105 35296 : if (comphelper::LibreOfficeKit::isActive())
106 : {
107 79 : int nPercent = (100*nValue)/m_nRange;
108 79 : if (nPercent != m_nLastCallbackPercent)
109 : {
110 74 : comphelper::LibreOfficeKit::statusIndicatorSetValue(nPercent);
111 74 : m_nLastCallbackPercent = nPercent;
112 : }
113 158 : return;
114 : }
115 :
116 35217 : css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
117 35217 : if (xFactory.is())
118 : {
119 35217 : StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
120 35217 : pFactory->setValue(this, nValue);
121 35217 : }
122 : }
123 :
124 : } // namespace framework
125 :
126 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|