Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
30 : : #define __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
31 : :
32 : : // Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
33 : : // with solaris headers ...
34 : : #include <vector>
35 : :
36 : : //_______________________________________________
37 : : // include files of own module
38 : : #include <helper/wakeupthread.hxx>
39 : : #include <threadhelp/threadhelpbase.hxx>
40 : : #include <macros/xinterface.hxx>
41 : : #include <macros/xtypeprovider.hxx>
42 : : #include <macros/xserviceinfo.hxx>
43 : : #include <macros/debug.hxx>
44 : : #include <macros/generic.hxx>
45 : : #include <general.h>
46 : :
47 : : //_______________________________________________
48 : : // include uno interfaces
49 : : #include <com/sun/star/lang/XTypeProvider.hpp>
50 : : #include <com/sun/star/lang/XServiceInfo.hpp>
51 : : #include <com/sun/star/lang/XInitialization.hpp>
52 : : #include <com/sun/star/lang/XEventListener.hpp>
53 : : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
54 : : #include <com/sun/star/task/XStatusIndicator.hpp>
55 : : #include <com/sun/star/awt/XWindow.hpp>
56 : : #include <com/sun/star/awt/XWindowListener.hpp>
57 : : #include <com/sun/star/lang/EventObject.hpp>
58 : : #include <com/sun/star/awt/WindowEvent.hpp>
59 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60 : : #include <com/sun/star/frame/XFrame.hpp>
61 : :
62 : : #include <com/sun/star/util/XUpdatable.hpp>
63 : :
64 : : //_______________________________________________
65 : : // include others
66 : : #include <vcl/status.hxx>
67 : : #include <cppuhelper/weak.hxx>
68 : : #include <osl/thread.hxx>
69 : :
70 : :
71 : : namespace framework{
72 : :
73 : :
74 : : //===============================================
75 : : /**
76 : : @descr This struct hold some informations about all currently running progress proccesses.
77 : : Because the can be used on a stack, we must cache her states but must paint only
78 : : the top most one.
79 : : */
80 : 432 : struct IndicatorInfo
81 : : {
82 : : //-------------------------------------------
83 : : // member
84 : : public:
85 : :
86 : : /** @short points to the indicator child, where we hold its states
87 : : alive here. */
88 : : css::uno::Reference< css::task::XStatusIndicator > m_xIndicator;
89 : :
90 : : /** @short the last set text for this indicator */
91 : : ::rtl::OUString m_sText;
92 : :
93 : : /** @short the max range for this indicator. */
94 : : sal_Int32 m_nRange;
95 : :
96 : : /** @short the last set value for this indicator */
97 : : sal_Int32 m_nValue;
98 : :
99 : : //-------------------------------------------
100 : : // interface
101 : : public:
102 : :
103 : : //---------------------------------------
104 : : /** @short initialize new instance of this class
105 : :
106 : : @param xIndicator
107 : : the new child indiactor of our factory.
108 : :
109 : : @param sText
110 : : its initial text.
111 : :
112 : : @param nRange
113 : : the max range for this indicator.
114 : : */
115 : 432 : IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator,
116 : : const ::rtl::OUString& sText ,
117 : : sal_Int32 nRange )
118 : 432 : {
119 [ + - ]: 432 : m_xIndicator = xIndicator;
120 : 432 : m_sText = sText ;
121 : 432 : m_nRange = nRange ;
122 : 432 : m_nValue = 0 ;
123 : 432 : }
124 : :
125 : : //---------------------------------------
126 : : /** @short Don't forget to free used references!
127 : : */
128 : 864 : ~IndicatorInfo()
129 : 864 : {
130 : 864 : m_xIndicator.clear();
131 : 864 : }
132 : :
133 : : //---------------------------------------------------------------------------------------------------------
134 : : /** @short Used to locate an info struct inside a stl structure ...
135 : :
136 : : @descr The indicator object itself is used as key. Its values
137 : : are not interesting then. Because mor then one child
138 : : indicator can use the same values ...
139 : : */
140 : 14766 : sal_Bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator)
141 : : {
142 : 14766 : return (m_xIndicator == xIndicator);
143 : : }
144 : : };
145 : :
146 : : //===============================================
147 : : /** @descr Define a lits of child indicator objects and her data. */
148 : : typedef ::std::vector< IndicatorInfo > IndicatorStack;
149 : :
150 : : //===============================================
151 : : /** @short implement a factory service to create new status indicator objects
152 : :
153 : : @descr Internaly it uses:
154 : : - a vcl based
155 : : - or an uno based and by the frame layouted
156 : : progress implementation.
157 : :
158 : : This factory create different indicators and control his access
159 : : to a shared output device! Only the last activated component
160 : : can write his state to this device. All other requests will be
161 : : cached only.
162 : :
163 : : @devstatus ready to use
164 : : @threadsafe yes
165 : : */
166 : : class StatusIndicatorFactory : public css::lang::XTypeProvider
167 : : , public css::lang::XServiceInfo
168 : : , public css::lang::XInitialization
169 : : , public css::task::XStatusIndicatorFactory
170 : : , public css::util::XUpdatable
171 : : , private ThreadHelpBase
172 : : , public ::cppu::OWeakObject // => XInterface
173 : : {
174 : : //-------------------------------------------
175 : : // member
176 : : private:
177 : :
178 : : /** stack with all current indicator children. */
179 : : IndicatorStack m_aStack;
180 : :
181 : : /** uno service manager to create own needed uno resources. */
182 : : css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
183 : :
184 : : /** most active indicator child, which could work with our shared indicator window only. */
185 : : css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild;
186 : :
187 : : /** used to show the progress on the frame (layouted!) or
188 : : as a plugged vcl window. */
189 : : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
190 : :
191 : : /** points to the frame, where we show the progress (in case
192 : : m_xProgress points to a frame progress. */
193 : : css::uno::WeakReference< css::frame::XFrame > m_xFrame;
194 : :
195 : : /** points to an outside window, where we show the progress (in case
196 : : we are plugged into such window). */
197 : : css::uno::WeakReference< css::awt::XWindow > m_xPluggWindow;
198 : :
199 : : /** Notify us if a fix time is over. We use it to implement an
200 : : intelligent "Reschedule" ... */
201 : : WakeUpThread* m_pWakeUp;
202 : :
203 : : /** Our WakeUpThread calls us in our interface method "XUpdatable::update().
204 : : There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule()
205 : : method is called, we know, that an Application::Reschedule() should be made.
206 : : Because the last made Reschedule can be was taken long time ago ... may be.*/
207 : : sal_Bool m_bAllowReschedule;
208 : :
209 : : /** enable/disable automatic showing of our parent window. */
210 : : sal_Bool m_bAllowParentShow;
211 : :
212 : : /** enable/disable rescheduling. Default=enabled*/
213 : : sal_Bool m_bDisableReschedule;
214 : :
215 : : /** prevent recursive calling of Application::Reschedule(). */
216 : : static sal_Int32 m_nInReschedule;
217 : :
218 : : //-------------------------------------------
219 : : // interface
220 : :
221 : : public:
222 : :
223 : : //---------------------------------------
224 : : // ctor
225 : : StatusIndicatorFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
226 : :
227 : : //---------------------------------------
228 : : // XInterface, XTypeProvider, XServiceInfo
229 : : FWK_DECLARE_XINTERFACE
230 : : FWK_DECLARE_XTYPEPROVIDER
231 : : DECLARE_XSERVICEINFO
232 : :
233 : : //---------------------------------------
234 : : // XInitialization
235 : : virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
236 : : throw(css::uno::Exception ,
237 : : css::uno::RuntimeException);
238 : :
239 : : //---------------------------------------
240 : : // XStatusIndicatorFactory
241 : : virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator()
242 : : throw(css::uno::RuntimeException);
243 : :
244 : : //---------------------------------------
245 : : // XUpdatable
246 : : virtual void SAL_CALL update()
247 : : throw(css::uno::RuntimeException);
248 : :
249 : : //---------------------------------------
250 : : // similar (XStatusIndicator)
251 : : virtual void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
252 : : const ::rtl::OUString& sText ,
253 : : sal_Int32 nRange);
254 : :
255 : : virtual void SAL_CALL reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
256 : :
257 : : virtual void SAL_CALL end(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
258 : :
259 : : virtual void SAL_CALL setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
260 : : const ::rtl::OUString& sText );
261 : :
262 : : virtual void SAL_CALL setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
263 : : sal_Int32 nValue);
264 : :
265 : : //-------------------------------------------
266 : : // specials
267 : :
268 : : protected:
269 : :
270 : : virtual ~StatusIndicatorFactory();
271 : :
272 : : //-------------------------------------------
273 : : // helper
274 : : private:
275 : :
276 : : /** @short show the parent window of this progress ...
277 : : if it's allowed to do so.
278 : :
279 : :
280 : : @descr By default we show the parent window automaticly
281 : : if this progress is used.
282 : : If that isn't a valid operation, the user of this
283 : : progress can suppress this feature by initializaing
284 : : us with a special parameter.
285 : :
286 : : @seealso initialize()
287 : : */
288 : : void implts_makeParentVisibleIfAllowed();
289 : :
290 : : /** @short creates a new internal used progress.
291 : : @descr This factory does not paint the progress itself.
292 : : It uses helper for that. They can be vcl based or
293 : : layouted by the frame and provided as an uno interface.
294 : : */
295 : : void impl_createProgress();
296 : :
297 : : /** @short shows the internal used progress.
298 : : @descr This factory does not paint the progress itself.
299 : : It uses helper for that. They can be vcl based or
300 : : layouted by the frame and provided as an uno interface.
301 : : */
302 : : void impl_showProgress();
303 : :
304 : : /** @short hides the internal used progress.
305 : : @descr This factory does not paint the progress itself.
306 : : It uses helper for that. They can be vcl based or
307 : : layouted by the frame and provided as an uno interface.
308 : : */
309 : : void impl_hideProgress();
310 : :
311 : : /** @short try to "share the current thread in an intelligent manner" :-)
312 : :
313 : : @param Overwrites our algorithm for Reschedule and force it to be shure
314 : : that our progress was painted right.
315 : : */
316 : : void impl_reschedule(sal_Bool bForceUpdate);
317 : :
318 : : void impl_startWakeUpThread();
319 : : void impl_stopWakeUpThread();
320 : :
321 : : }; // class StatusIndicatorFactory
322 : :
323 : : } // namespace framework
324 : :
325 : : #endif // #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
326 : :
327 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|