LCOV - code coverage report
Current view: top level - framework/inc/helper - statusindicatorfactory.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 22 63.6 %
Date: 2015-06-13 12:38:46 Functions: 4 8 50.0 %
Legend: Lines: hit not hit

          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             : #ifndef INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
      21             : #define INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
      22             : 
      23             : // Attention: stl headers must(!) be included at first. Otherwise it can make trouble
      24             : // with solaris headers ...
      25             : #include <vector>
      26             : 
      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>
      33             : #include <general.h>
      34             : 
      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>
      49             : 
      50             : #include <cppuhelper/supportsservice.hxx>
      51             : #include <vcl/status.hxx>
      52             : #include <cppuhelper/implbase4.hxx>
      53             : #include <osl/thread.hxx>
      54             : 
      55             : namespace framework{
      56             : 
      57             : /**
      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
      60             :             the top most one.
      61             :  */
      62        2408 : struct IndicatorInfo
      63             : {
      64             : 
      65             :     // member
      66             :     public:
      67             : 
      68             :         /** @short  points to the indicator child, where we hold its states
      69             :                     alive here. */
      70             :         css::uno::Reference< css::task::XStatusIndicator > m_xIndicator;
      71             : 
      72             :         /** @short  the last set text for this indicator */
      73             :         OUString m_sText;
      74             : 
      75             :         /** @short  the max range for this indicator. */
      76             :         sal_Int32 m_nRange;
      77             : 
      78             :         /** @short  the last set value for this indicator */
      79             :         sal_Int32 m_nValue;
      80             : 
      81             :     // interface
      82             :     public:
      83             : 
      84             :         /** @short  initialize new instance of this class
      85             : 
      86             :             @param  xIndicator
      87             :                     the new child indiactor of our factory.
      88             : 
      89             :             @param  sText
      90             :                     its initial text.
      91             : 
      92             :             @param  nRange
      93             :                     the max range for this indicator.
      94             :          */
      95        2408 :         IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator,
      96             :                       const OUString&                                    sText     ,
      97             :                             sal_Int32                                           nRange    )
      98        2408 :         {
      99        2408 :             m_xIndicator = xIndicator;
     100        2408 :             m_sText      = sText;
     101        2408 :             m_nRange     = nRange;
     102        2408 :             m_nValue     = 0;
     103        2408 :         }
     104             : 
     105             :         /** @short  Don't forget to free used references!
     106             :          */
     107        4816 :         ~IndicatorInfo()
     108        4816 :         {
     109        4816 :             m_xIndicator.clear();
     110        4816 :         }
     111             : 
     112             :         /** @short  Used to locate an info struct inside a stl structure ...
     113             : 
     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 ...
     117             :          */
     118       37977 :         bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator)
     119             :         {
     120       37977 :             return (m_xIndicator == xIndicator);
     121             :         }
     122             : };
     123             : 
     124             : /** @descr  Define a lits of child indicator objects and her data. */
     125             : typedef ::std::vector< IndicatorInfo > IndicatorStack;
     126             : 
     127             : /** @short          implement a factory service to create new status indicator objects
     128             : 
     129             :     @descr          Internally it uses:
     130             :                     - a vcl based
     131             :                     - or an uno based and by the frame layouted
     132             :                     progress implementation.
     133             : 
     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
     137             :                     cached only.
     138             : 
     139             :     @devstatus      ready to use
     140             :     @threadsafe     yes
     141             :  */
     142             : class StatusIndicatorFactory : public  ::cppu::WeakImplHelper4<
     143             :                                              css::lang::XServiceInfo
     144             :                                            , css::lang::XInitialization
     145             :                                            , css::task::XStatusIndicatorFactory
     146             :                                            , css::util::XUpdatable >
     147             : {
     148             : 
     149             :     // member
     150             :     private:
     151             :         osl::Mutex m_mutex;
     152             : 
     153             :         /** stack with all current indicator children. */
     154             :         IndicatorStack m_aStack;
     155             : 
     156             :         /** uno service manager to create own needed uno resources. */
     157             :         css::uno::Reference< css::uno::XComponentContext > m_xContext;
     158             : 
     159             :         /** most active indicator child, which could work with our shared indicator window only. */
     160             :         css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild;
     161             : 
     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;
     165             : 
     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;
     169             : 
     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;
     173             : 
     174             :         /** Notify us if a fix time is over. We use it to implement an
     175             :             intelligent "Reschedule" ... */
     176             :         rtl::Reference<WakeUpThread> m_pWakeUp;
     177             : 
     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;
     183             : 
     184             :         /** enable/disable automatic showing of our parent window. */
     185             :         bool m_bAllowParentShow;
     186             : 
     187             :         /** enable/disable rescheduling. Default=enabled*/
     188             :         bool m_bDisableReschedule;
     189             : 
     190             :         /** prevent recursive calling of Application::Reschedule(). */
     191             :         static sal_Int32 m_nInReschedule;
     192             : 
     193             :     // interface
     194             : 
     195             :     public:
     196             :         StatusIndicatorFactory(const css::uno::Reference< css::uno::XComponentContext >& xContext);
     197             : 
     198           0 :         virtual OUString SAL_CALL getImplementationName()
     199             :             throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     200             :         {
     201           0 :             return OUString("com.sun.star.comp.framework.StatusIndicatorFactory");
     202             :         }
     203             : 
     204           0 :         virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
     205             :             throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     206             :         {
     207           0 :             return cppu::supportsService(this, ServiceName);
     208             :         }
     209             : 
     210           0 :         virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
     211             :             throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     212             :         {
     213           0 :             css::uno::Sequence< OUString > aSeq(1);
     214           0 :             aSeq[0] = "com.sun.star.task.StatusIndicatorFactory";
     215           0 :             return aSeq;
     216             :         }
     217             : 
     218             :         // XInitialization
     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;
     222             : 
     223             :         // XStatusIndicatorFactory
     224             :         virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator()
     225             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     226             : 
     227             :         // XUpdatable
     228             :         virtual void SAL_CALL update()
     229             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     230             : 
     231             :         // similar (XStatusIndicator)
     232             :         void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     233             :                            const OUString&                                    sText ,
     234             :                                  sal_Int32                                           nRange);
     235             : 
     236             :         void SAL_CALL reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
     237             : 
     238             :         void SAL_CALL end(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
     239             : 
     240             :         void SAL_CALL setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     241             :                                       const OUString&                                    sText );
     242             : 
     243             :         void SAL_CALL setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     244             :                                              sal_Int32                                           nValue);
     245             : 
     246             :     // specials
     247             : 
     248             :     protected:
     249             : 
     250             :         virtual ~StatusIndicatorFactory();
     251             : 
     252             :     // helper
     253             :     private:
     254             : 
     255             :         /** @short  show the parent window of this progress ...
     256             :                     if it's allowed to do so.
     257             : 
     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.
     263             : 
     264             :             @seealso    initialize()
     265             :          */
     266             :         void implts_makeParentVisibleIfAllowed();
     267             : 
     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.
     272             :          */
     273             :         void impl_createProgress();
     274             : 
     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.
     279             :          */
     280             :         void impl_showProgress();
     281             : 
     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.
     286             :          */
     287             :         void impl_hideProgress();
     288             : 
     289             :         /** @short  try to "share the current thread in an intelligent manner" :-)
     290             : 
     291             :             @param  Overwrites our algorithm for Reschedule and force it to be sure
     292             :                     that our progress was painted right.
     293             :          */
     294             :         void impl_reschedule(bool bForceUpdate);
     295             : 
     296             :         void impl_startWakeUpThread();
     297             :         void impl_stopWakeUpThread();
     298             : 
     299             : }; // class StatusIndicatorFactory
     300             : 
     301             : } // namespace framework
     302             : 
     303             : #endif // INCLUDED_FRAMEWORK_INC_HELPER_STATUSINDICATORFACTORY_HXX
     304             : 
     305             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11