LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/helper - statusindicatorfactory.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 14 100.0 %
Date: 2012-12-27 Functions: 4 5 80.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 __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
      21             : #define __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
      22             : 
      23             : // Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
      24             : // with solaris headers ...
      25             : #include <vector>
      26             : 
      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>
      37             : 
      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>
      52             : 
      53             : #include <com/sun/star/util/XUpdatable.hpp>
      54             : 
      55             : //_______________________________________________
      56             : // include others
      57             : #include <vcl/status.hxx>
      58             : #include <cppuhelper/weak.hxx>
      59             : #include <osl/thread.hxx>
      60             : 
      61             : 
      62             : namespace framework{
      63             : 
      64             : 
      65             : //===============================================
      66             : /**
      67             :     @descr  This struct hold some informations 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.
      70             :  */
      71         151 : struct IndicatorInfo
      72             : {
      73             :     //-------------------------------------------
      74             :     // member
      75             :     public:
      76             : 
      77             :         /** @short  points to the indicator child, where we hold its states
      78             :                     alive here. */
      79             :         css::uno::Reference< css::task::XStatusIndicator > m_xIndicator;
      80             : 
      81             :         /** @short  the last set text for this indicator */
      82             :         ::rtl::OUString m_sText;
      83             : 
      84             :         /** @short  the max range for this indicator. */
      85             :         sal_Int32 m_nRange;
      86             : 
      87             :         /** @short  the last set value for this indicator */
      88             :         sal_Int32 m_nValue;
      89             : 
      90             :     //-------------------------------------------
      91             :     // interface
      92             :     public:
      93             : 
      94             :         //---------------------------------------
      95             :         /** @short  initialize new instance of this class
      96             : 
      97             :             @param  xIndicator
      98             :                     the new child indiactor of our factory.
      99             : 
     100             :             @param  sText
     101             :                     its initial text.
     102             : 
     103             :             @param  nRange
     104             :                     the max range for this indicator.
     105             :          */
     106         151 :         IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator,
     107             :                       const ::rtl::OUString&                                    sText     ,
     108             :                             sal_Int32                                           nRange    )
     109         151 :         {
     110         151 :             m_xIndicator = xIndicator;
     111         151 :             m_sText      = sText     ;
     112         151 :             m_nRange     = nRange    ;
     113         151 :             m_nValue     = 0         ;
     114         151 :         }
     115             : 
     116             :         //---------------------------------------
     117             :         /** @short  Don't forget to free used references!
     118             :          */
     119         302 :         ~IndicatorInfo()
     120         302 :         {
     121         302 :             m_xIndicator.clear();
     122         302 :         }
     123             : 
     124             :         //---------------------------------------------------------------------------------------------------------
     125             :         /** @short  Used to locate an info struct inside a stl structure ...
     126             : 
     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 ...
     130             :          */
     131        5624 :         sal_Bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator)
     132             :         {
     133        5624 :             return (m_xIndicator == xIndicator);
     134             :         }
     135             : };
     136             : 
     137             : //===============================================
     138             : /** @descr  Define a lits of child indicator objects and her data. */
     139             : typedef ::std::vector< IndicatorInfo > IndicatorStack;
     140             : 
     141             : //===============================================
     142             : /** @short          implement a factory service to create new status indicator objects
     143             : 
     144             :     @descr          Internaly it uses:
     145             :                     - a vcl based
     146             :                     - or an uno based and by the frame layouted
     147             :                     progress implementation.
     148             : 
     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.
     153             : 
     154             :     @devstatus      ready to use
     155             :     @threadsafe     yes
     156             :  */
     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
     164             : {
     165             :     //-------------------------------------------
     166             :     // member
     167             :     private:
     168             : 
     169             :         /** stack with all current indicator children. */
     170             :         IndicatorStack m_aStack;
     171             : 
     172             :         /** uno service manager to create own needed uno resources. */
     173             :         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
     174             : 
     175             :         /** most active indicator child, which could work with our shared indicator window only. */
     176             :         css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild;
     177             : 
     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;
     181             : 
     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;
     185             : 
     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;
     189             : 
     190             :         /** Notify us if a fix time is over. We use it to implement an
     191             :             intelligent "Reschedule" ... */
     192             :         WakeUpThread* m_pWakeUp;
     193             : 
     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;
     199             : 
     200             :         /** enable/disable automatic showing of our parent window. */
     201             :         sal_Bool m_bAllowParentShow;
     202             : 
     203             :         /** enable/disable rescheduling. Default=enabled*/
     204             :         sal_Bool m_bDisableReschedule;
     205             : 
     206             :         /** prevent recursive calling of Application::Reschedule(). */
     207             :         static sal_Int32 m_nInReschedule;
     208             : 
     209             :     //-------------------------------------------
     210             :     // interface
     211             : 
     212             :     public:
     213             : 
     214             :         //---------------------------------------
     215             :         // ctor
     216             :         StatusIndicatorFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
     217             : 
     218             :         //---------------------------------------
     219             :         // XInterface, XTypeProvider, XServiceInfo
     220             :         FWK_DECLARE_XINTERFACE
     221             :         FWK_DECLARE_XTYPEPROVIDER
     222             :         DECLARE_XSERVICEINFO
     223             : 
     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);
     229             : 
     230             :         //---------------------------------------
     231             :         // XStatusIndicatorFactory
     232             :         virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator()
     233             :             throw(css::uno::RuntimeException);
     234             : 
     235             :         //---------------------------------------
     236             :         // XUpdatable
     237             :         virtual void SAL_CALL update()
     238             :             throw(css::uno::RuntimeException);
     239             : 
     240             :         //---------------------------------------
     241             :         // similar (XStatusIndicator)
     242             :         virtual void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     243             :                            const ::rtl::OUString&                                    sText ,
     244             :                                  sal_Int32                                           nRange);
     245             : 
     246             :         virtual void SAL_CALL reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
     247             : 
     248             :         virtual void SAL_CALL end(const css::uno::Reference< css::task::XStatusIndicator >& xChild);
     249             : 
     250             :         virtual void SAL_CALL setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     251             :                                       const ::rtl::OUString&                                    sText );
     252             : 
     253             :         virtual void SAL_CALL setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     254             :                                              sal_Int32                                           nValue);
     255             : 
     256             :     //-------------------------------------------
     257             :     // specials
     258             : 
     259             :     protected:
     260             : 
     261             :         virtual ~StatusIndicatorFactory();
     262             : 
     263             :     //-------------------------------------------
     264             :     // helper
     265             :     private:
     266             : 
     267             :         /** @short  show the parent window of this progress ...
     268             :                     if it's allowed to do so.
     269             : 
     270             : 
     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.
     276             : 
     277             :             @seealso    initialize()
     278             :          */
     279             :         void implts_makeParentVisibleIfAllowed();
     280             : 
     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.
     285             :          */
     286             :         void impl_createProgress();
     287             : 
     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.
     292             :          */
     293             :         void impl_showProgress();
     294             : 
     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.
     299             :          */
     300             :         void impl_hideProgress();
     301             : 
     302             :         /** @short  try to "share the current thread in an intelligent manner" :-)
     303             : 
     304             :             @param  Overwrites our algorithm for Reschedule and force it to be shure
     305             :                     that our progress was painted right.
     306             :          */
     307             :         void impl_reschedule(sal_Bool bForceUpdate);
     308             : 
     309             :         void impl_startWakeUpThread();
     310             :         void impl_stopWakeUpThread();
     311             : 
     312             : }; // class StatusIndicatorFactory
     313             : 
     314             : } // namespace framework
     315             : 
     316             : #endif // #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10