1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
21 #define INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
23 // Attention: stl headers must(!) be included at first. Otherwise it can make trouble
24 // with solaris headers ...
27 // include files of own module
28 #include <helper/wakeupthread.hxx>
29 #include <macros/xinterface.hxx>
30 #include <macros/xtypeprovider.hxx>
31 #include <macros/xserviceinfo.hxx>
32 #include <macros/generic.hxx>
35 // include uno interfaces
36 #include <com/sun/star/lang/XTypeProvider.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XEventListener.hpp>
40 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
41 #include <com/sun/star/task/XStatusIndicator.hpp>
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/awt/XWindowListener.hpp>
44 #include <com/sun/star/lang/EventObject.hpp>
45 #include <com/sun/star/awt/WindowEvent.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/frame/XFrame.hpp>
48 #include <com/sun/star/util/XUpdatable.hpp>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <vcl/status.hxx>
52 #include <cppuhelper/implbase4.hxx>
53 #include <osl/thread.hxx>
58 @descr This struct hold some information about all currently running progress proccesses.
59 Because the can be used on a stack, we must cache her states but must paint only
68 /** @short points to the indicator child, where we hold its states
70 css::uno::Reference
< css::task::XStatusIndicator
> m_xIndicator
;
72 /** @short the last set text for this indicator */
75 /** @short the max range for this indicator. */
78 /** @short the last set value for this indicator */
84 /** @short initialize new instance of this class
87 the new child indiactor of our factory.
93 the max range for this indicator.
95 IndicatorInfo(const css::uno::Reference
< css::task::XStatusIndicator
>& xIndicator
,
96 const OUString
& sText
,
99 m_xIndicator
= xIndicator
;
105 /** @short Don't forget to free used references!
109 m_xIndicator
.clear();
112 /** @short Used to locate an info struct inside a stl structure ...
114 @descr The indicator object itself is used as key. Its values
115 are not interesting then. Because mor then one child
116 indicator can use the same values ...
118 bool operator==(const css::uno::Reference
< css::task::XStatusIndicator
>& xIndicator
)
120 return (m_xIndicator
== xIndicator
);
124 /** @descr Define a lits of child indicator objects and her data. */
125 typedef ::std::vector
< IndicatorInfo
> IndicatorStack
;
127 /** @short implement a factory service to create new status indicator objects
129 @descr Internally it uses:
131 - or an uno based and by the frame layouted
132 progress implementation.
134 This factory create different indicators and control his access
135 to a shared output device! Only the last activated component
136 can write his state to this device. All other requests will be
139 @devstatus ready to use
142 class StatusIndicatorFactory
: public ::cppu::WeakImplHelper4
<
143 css::lang::XServiceInfo
144 , css::lang::XInitialization
145 , css::task::XStatusIndicatorFactory
146 , css::util::XUpdatable
>
153 /** stack with all current indicator children. */
154 IndicatorStack m_aStack
;
156 /** uno service manager to create own needed uno resources. */
157 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
159 /** most active indicator child, which could work with our shared indicator window only. */
160 css::uno::Reference
< css::task::XStatusIndicator
> m_xActiveChild
;
162 /** used to show the progress on the frame (layouted!) or
163 as a plugged vcl window. */
164 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
166 /** points to the frame, where we show the progress (in case
167 m_xProgress points to a frame progress. */
168 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
170 /** points to an outside window, where we show the progress (in case
171 we are plugged into such window). */
172 css::uno::WeakReference
< css::awt::XWindow
> m_xPluggWindow
;
174 /** Notify us if a fix time is over. We use it to implement an
175 intelligent "Reschedule" ... */
176 rtl::Reference
<WakeUpThread
> m_pWakeUp
;
178 /** Our WakeUpThread calls us in our interface method "XUpdatable::update().
179 There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule()
180 method is called, we know, that an Application::Reschedule() should be made.
181 Because the last made Reschedule can be was taken long time ago ... may be.*/
182 bool m_bAllowReschedule
;
184 /** enable/disable automatic showing of our parent window. */
185 bool m_bAllowParentShow
;
187 /** enable/disable rescheduling. Default=enabled*/
188 bool m_bDisableReschedule
;
190 /** prevent recursive calling of Application::Reschedule(). */
191 static sal_Int32 m_nInReschedule
;
196 StatusIndicatorFactory(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
198 virtual OUString SAL_CALL
getImplementationName()
199 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
201 return OUString("com.sun.star.comp.framework.StatusIndicatorFactory");
204 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
205 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
207 return cppu::supportsService(this, ServiceName
);
210 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
211 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
213 css::uno::Sequence
< OUString
> aSeq(1);
214 aSeq
[0] = "com.sun.star.task.StatusIndicatorFactory";
219 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
220 throw(css::uno::Exception
,
221 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
223 // XStatusIndicatorFactory
224 virtual css::uno::Reference
< css::task::XStatusIndicator
> SAL_CALL
createStatusIndicator()
225 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
228 virtual void SAL_CALL
update()
229 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
231 // similar (XStatusIndicator)
232 void start(const css::uno::Reference
< css::task::XStatusIndicator
>& xChild
,
233 const OUString
& sText
,
236 void SAL_CALL
reset(const css::uno::Reference
< css::task::XStatusIndicator
>& xChild
);
238 void SAL_CALL
end(const css::uno::Reference
< css::task::XStatusIndicator
>& xChild
);
240 void SAL_CALL
setText(const css::uno::Reference
< css::task::XStatusIndicator
>& xChild
,
241 const OUString
& sText
);
243 void SAL_CALL
setValue(const css::uno::Reference
< css::task::XStatusIndicator
>& xChild
,
250 virtual ~StatusIndicatorFactory();
255 /** @short show the parent window of this progress ...
256 if it's allowed to do so.
258 @descr By default we show the parent window automatically
259 if this progress is used.
260 If that isn't a valid operation, the user of this
261 progress can suppress this feature by initializaing
262 us with a special parameter.
264 @seealso initialize()
266 void implts_makeParentVisibleIfAllowed();
268 /** @short creates a new internal used progress.
269 @descr This factory does not paint the progress itself.
270 It uses helper for that. They can be vcl based or
271 layouted by the frame and provided as an uno interface.
273 void impl_createProgress();
275 /** @short shows the internal used progress.
276 @descr This factory does not paint the progress itself.
277 It uses helper for that. They can be vcl based or
278 layouted by the frame and provided as an uno interface.
280 void impl_showProgress();
282 /** @short hides the internal used progress.
283 @descr This factory does not paint the progress itself.
284 It uses helper for that. They can be vcl based or
285 layouted by the frame and provided as an uno interface.
287 void impl_hideProgress();
289 /** @short try to "share the current thread in an intelligent manner" :-)
291 @param Overwrites our algorithm for Reschedule and force it to be sure
292 that our progress was painted right.
294 void impl_reschedule(bool bForceUpdate
);
296 void impl_startWakeUpThread();
297 void impl_stopWakeUpThread();
299 }; // class StatusIndicatorFactory
301 } // namespace framework
303 #endif // INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */