update credits
[LibreOffice.git] / framework / inc / helper / statusindicatorfactory.hxx
bloba5cfa5e61d39806fc5df5f45909972939e2ff0a2
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 #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
21 #define __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
23 // Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
24 // with solaris headers ...
25 #include <vector>
27 //_______________________________________________
28 // include files of own module
29 #include <helper/wakeupthread.hxx>
30 #include <threadhelp/threadhelpbase.hxx>
31 #include <macros/xinterface.hxx>
32 #include <macros/xtypeprovider.hxx>
33 #include <macros/xserviceinfo.hxx>
34 #include <macros/debug.hxx>
35 #include <macros/generic.hxx>
36 #include <general.h>
38 //_______________________________________________
39 // include uno interfaces
40 #include <com/sun/star/lang/XTypeProvider.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/lang/XEventListener.hpp>
44 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
45 #include <com/sun/star/task/XStatusIndicator.hpp>
46 #include <com/sun/star/awt/XWindow.hpp>
47 #include <com/sun/star/awt/XWindowListener.hpp>
48 #include <com/sun/star/lang/EventObject.hpp>
49 #include <com/sun/star/awt/WindowEvent.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/frame/XFrame.hpp>
53 #include <com/sun/star/util/XUpdatable.hpp>
55 //_______________________________________________
56 // include others
57 #include <vcl/status.hxx>
58 #include <cppuhelper/weak.hxx>
59 #include <osl/thread.hxx>
62 namespace framework{
65 //===============================================
66 /**
67 @descr This struct hold some information about all currently running progress proccesses.
68 Because the can be used on a stack, we must cache her states but must paint only
69 the top most one.
71 struct IndicatorInfo
73 //-------------------------------------------
74 // member
75 public:
77 /** @short points to the indicator child, where we hold its states
78 alive here. */
79 css::uno::Reference< css::task::XStatusIndicator > m_xIndicator;
81 /** @short the last set text for this indicator */
82 OUString m_sText;
84 /** @short the max range for this indicator. */
85 sal_Int32 m_nRange;
87 /** @short the last set value for this indicator */
88 sal_Int32 m_nValue;
90 //-------------------------------------------
91 // interface
92 public:
94 //---------------------------------------
95 /** @short initialize new instance of this class
97 @param xIndicator
98 the new child indiactor of our factory.
100 @param sText
101 its initial text.
103 @param nRange
104 the max range for this indicator.
106 IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator,
107 const OUString& sText ,
108 sal_Int32 nRange )
110 m_xIndicator = xIndicator;
111 m_sText = sText ;
112 m_nRange = nRange ;
113 m_nValue = 0 ;
116 //---------------------------------------
117 /** @short Don't forget to free used references!
119 ~IndicatorInfo()
121 m_xIndicator.clear();
124 //---------------------------------------------------------------------------------------------------------
125 /** @short Used to locate an info struct inside a stl structure ...
127 @descr The indicator object itself is used as key. Its values
128 are not interesting then. Because mor then one child
129 indicator can use the same values ...
131 sal_Bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator)
133 return (m_xIndicator == xIndicator);
137 //===============================================
138 /** @descr Define a lits of child indicator objects and her data. */
139 typedef ::std::vector< IndicatorInfo > IndicatorStack;
141 //===============================================
142 /** @short implement a factory service to create new status indicator objects
144 @descr Internaly it uses:
145 - a vcl based
146 - or an uno based and by the frame layouted
147 progress implementation.
149 This factory create different indicators and control his access
150 to a shared output device! Only the last activated component
151 can write his state to this device. All other requests will be
152 cached only.
154 @devstatus ready to use
155 @threadsafe yes
157 class StatusIndicatorFactory : public css::lang::XTypeProvider
158 , public css::lang::XServiceInfo
159 , public css::lang::XInitialization
160 , public css::task::XStatusIndicatorFactory
161 , public css::util::XUpdatable
162 , private ThreadHelpBase
163 , public ::cppu::OWeakObject // => XInterface
165 //-------------------------------------------
166 // member
167 private:
169 /** stack with all current indicator children. */
170 IndicatorStack m_aStack;
172 /** uno service manager to create own needed uno resources. */
173 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
175 /** most active indicator child, which could work with our shared indicator window only. */
176 css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild;
178 /** used to show the progress on the frame (layouted!) or
179 as a plugged vcl window. */
180 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
182 /** points to the frame, where we show the progress (in case
183 m_xProgress points to a frame progress. */
184 css::uno::WeakReference< css::frame::XFrame > m_xFrame;
186 /** points to an outside window, where we show the progress (in case
187 we are plugged into such window). */
188 css::uno::WeakReference< css::awt::XWindow > m_xPluggWindow;
190 /** Notify us if a fix time is over. We use it to implement an
191 intelligent "Reschedule" ... */
192 WakeUpThread* m_pWakeUp;
194 /** Our WakeUpThread calls us in our interface method "XUpdatable::update().
195 There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule()
196 method is called, we know, that an Application::Reschedule() should be made.
197 Because the last made Reschedule can be was taken long time ago ... may be.*/
198 sal_Bool m_bAllowReschedule;
200 /** enable/disable automatic showing of our parent window. */
201 sal_Bool m_bAllowParentShow;
203 /** enable/disable rescheduling. Default=enabled*/
204 sal_Bool m_bDisableReschedule;
206 /** prevent recursive calling of Application::Reschedule(). */
207 static sal_Int32 m_nInReschedule;
209 //-------------------------------------------
210 // interface
212 public:
214 //---------------------------------------
215 // ctor
216 StatusIndicatorFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
218 //---------------------------------------
219 // XInterface, XTypeProvider, XServiceInfo
220 FWK_DECLARE_XINTERFACE
221 FWK_DECLARE_XTYPEPROVIDER
222 DECLARE_XSERVICEINFO
224 //---------------------------------------
225 // XInitialization
226 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
227 throw(css::uno::Exception ,
228 css::uno::RuntimeException);
230 //---------------------------------------
231 // XStatusIndicatorFactory
232 virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator()
233 throw(css::uno::RuntimeException);
235 //---------------------------------------
236 // XUpdatable
237 virtual void SAL_CALL update()
238 throw(css::uno::RuntimeException);
240 //---------------------------------------
241 // similar (XStatusIndicator)
242 virtual void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
243 const OUString& sText ,
244 sal_Int32 nRange);
246 virtual void SAL_CALL reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
248 virtual void SAL_CALL end(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
250 virtual void SAL_CALL setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
251 const OUString& sText );
253 virtual void SAL_CALL setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
254 sal_Int32 nValue);
256 //-------------------------------------------
257 // specials
259 protected:
261 virtual ~StatusIndicatorFactory();
263 //-------------------------------------------
264 // helper
265 private:
267 /** @short show the parent window of this progress ...
268 if it's allowed to do so.
271 @descr By default we show the parent window automaticly
272 if this progress is used.
273 If that isn't a valid operation, the user of this
274 progress can suppress this feature by initializaing
275 us with a special parameter.
277 @seealso initialize()
279 void implts_makeParentVisibleIfAllowed();
281 /** @short creates a new internal used progress.
282 @descr This factory does not paint the progress itself.
283 It uses helper for that. They can be vcl based or
284 layouted by the frame and provided as an uno interface.
286 void impl_createProgress();
288 /** @short shows the internal used progress.
289 @descr This factory does not paint the progress itself.
290 It uses helper for that. They can be vcl based or
291 layouted by the frame and provided as an uno interface.
293 void impl_showProgress();
295 /** @short hides the internal used progress.
296 @descr This factory does not paint the progress itself.
297 It uses helper for that. They can be vcl based or
298 layouted by the frame and provided as an uno interface.
300 void impl_hideProgress();
302 /** @short try to "share the current thread in an intelligent manner" :-)
304 @param Overwrites our algorithm for Reschedule and force it to be shure
305 that our progress was painted right.
307 void impl_reschedule(sal_Bool bForceUpdate);
309 void impl_startWakeUpThread();
310 void impl_stopWakeUpThread();
312 }; // class StatusIndicatorFactory
314 } // namespace framework
316 #endif // #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */