Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / framework / inc / helper / statusindicatorfactory.hxx
blobc492a645f5bcc69f4f2e7cedad07f8052876173f
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 #pragma once
22 #include <sal/config.h>
24 #include <vector>
25 #include <mutex>
27 // include files of own module
28 #include <helper/wakeupthread.hxx>
30 // include uno interfaces
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
34 #include <com/sun/star/task/XStatusIndicator.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/frame/XFrame.hpp>
37 #include <com/sun/star/util/XUpdatable.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <cppuhelper/supportsservice.hxx>
41 #include <cppuhelper/implbase.hxx>
42 #include <rtl/ref.hxx>
44 namespace framework{
46 /**
47 @descr This struct hold some information about all currently running progress processes.
48 Because the can be used on a stack, we must cache her states but must paint only
49 the top most one.
51 struct IndicatorInfo
54 // member
55 public:
57 /** @short points to the indicator child, where we hold its states
58 alive here. */
59 css::uno::Reference< css::task::XStatusIndicator > m_xIndicator;
61 /** @short the last set text for this indicator */
62 OUString m_sText;
64 /** @short the last set value for this indicator */
65 sal_Int32 m_nValue;
67 // interface
68 public:
70 /** @short initialize new instance of this class
72 @param xIndicator
73 the new child indicator of our factory.
75 @param sText
76 its initial text.
78 @param nRange
79 the max range for this indicator.
81 IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator,
82 const OUString& sText )
84 m_xIndicator = xIndicator;
85 m_sText = sText;
86 m_nValue = 0;
89 /** @short Used to locate an info struct inside a stl structure...
91 @descr The indicator object itself is used as key. Its values
92 are not interesting then. Because more than one child
93 indicator can use the same values...
95 bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator) const
97 return (m_xIndicator == xIndicator);
101 /** @descr Define a list of child indicator objects and its data. */
102 typedef ::std::vector< IndicatorInfo > IndicatorStack;
104 /** @short implement a factory service to create new status indicator objects
106 @descr Internally it uses:
107 - a vcl based
108 - or a uno based and by the frame layouted
109 progress implementation.
111 This factory create different indicators and control his access
112 to a shared output device! Only the last activated component
113 can write its state to this device. All other requests will be
114 cached only.
116 @devstatus ready to use
117 @threadsafe yes
119 class StatusIndicatorFactory final : public ::cppu::WeakImplHelper<
120 css::lang::XServiceInfo
121 , css::lang::XInitialization
122 , css::task::XStatusIndicatorFactory
123 , css::util::XUpdatable >
126 // member
127 private:
128 std::mutex m_mutex;
130 /** stack with all current indicator children. */
131 IndicatorStack m_aStack;
133 /** uno service manager to create own needed uno resources. */
134 css::uno::Reference< css::uno::XComponentContext > m_xContext;
136 /** most active indicator child, which could work with our shared indicator window only. */
137 css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild;
139 /** used to show the progress on the frame (layouted!) or
140 as a plugged vcl window. */
141 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
143 /** points to the frame, where we show the progress (in case
144 m_xProgress points to a frame progress. */
145 css::uno::WeakReference< css::frame::XFrame > m_xFrame;
147 /** points to an outside window, where we show the progress (in case
148 we are plugged into such window). */
149 css::uno::WeakReference< css::awt::XWindow > m_xPluggWindow;
151 /** Notify us if a fix time is over. We use it to implement an
152 intelligent "Reschedule" ... */
153 rtl::Reference<WakeUpThread> m_pWakeUp;
155 /** Our WakeUpThread calls us in our interface method "XUpdatable::update().
156 There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule()
157 method is called, we know, that an Application::Reschedule() should be made.
158 Because the last made Reschedule can be was taken long time ago ... may be.*/
159 bool m_bAllowReschedule;
161 /** enable/disable automatic showing of our parent window. */
162 bool m_bAllowParentShow;
164 /** enable/disable rescheduling. Default=enabled*/
165 bool m_bDisableReschedule;
167 /** prevent recursive calling of Application::Reschedule(). */
168 static sal_Int32 m_nInReschedule;
170 // interface
172 public:
173 StatusIndicatorFactory(css::uno::Reference< css::uno::XComponentContext > xContext);
175 virtual OUString SAL_CALL getImplementationName() override
177 return "com.sun.star.comp.framework.StatusIndicatorFactory";
180 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
182 return cppu::supportsService(this, ServiceName);
185 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
187 return { "com.sun.star.task.StatusIndicatorFactory" };
190 // XInitialization
191 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) override;
193 // XStatusIndicatorFactory
194 virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator() override;
196 // XUpdatable
197 virtual void SAL_CALL update() override;
199 // similar (XStatusIndicator)
200 void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
201 const OUString& sText ,
202 sal_Int32 nRange);
204 void reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
206 void end(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
208 void setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
209 const OUString& sText );
211 void setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
212 sal_Int32 nValue);
214 // specials
216 private:
218 virtual ~StatusIndicatorFactory() override;
220 // helper
222 /** @short show the parent window of this progress ...
223 if it's allowed to do so.
225 @descr By default we show the parent window automatically
226 if this progress is used.
227 If that isn't a valid operation, the user of this
228 progress can suppress this feature by initializing
229 us with a special parameter.
231 @seealso initialize()
233 void implts_makeParentVisibleIfAllowed();
235 /** @short creates a new internal used progress.
236 @descr This factory does not paint the progress itself.
237 It uses helper for that. They can be vcl based or
238 layouted by the frame and provided as a uno interface.
240 void impl_createProgress();
242 /** @short shows the internal used progress.
243 @descr This factory does not paint the progress itself.
244 It uses helper for that. They can be vcl based or
245 layouted by the frame and provided as a uno interface.
247 void impl_showProgress();
249 /** @short hides the internal used progress.
250 @descr This factory does not paint the progress itself.
251 It uses helper for that. They can be vcl based or
252 layouted by the frame and provided as a uno interface.
254 void impl_hideProgress();
256 /** @short try to "share the current thread in an intelligent manner" :-)
258 @param Overwrites our algorithm for Reschedule and force it to be sure
259 that our progress was painted right.
261 void impl_reschedule(bool bForceUpdate);
263 void impl_startWakeUpThread();
264 void impl_stopWakeUpThread();
266 }; // class StatusIndicatorFactory
268 } // namespace framework
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */