LCOV - code coverage report
Current view: top level - libreoffice/framework/source/helper - statusindicatorfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 238 266 89.5 %
Date: 2012-12-27 Functions: 25 31 80.6 %
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             : #include <algorithm>
      21             : #include <helper/statusindicatorfactory.hxx>
      22             : #include <helper/statusindicator.hxx>
      23             : #include <helper/vclstatusindicator.hxx>
      24             : #include <threadhelp/writeguard.hxx>
      25             : #include <threadhelp/readguard.hxx>
      26             : #include <services.h>
      27             : #include <properties.h>
      28             : 
      29             : #include <com/sun/star/awt/Rectangle.hpp>
      30             : 
      31             : #include <com/sun/star/awt/XControl.hpp>
      32             : #include <com/sun/star/awt/XLayoutConstrains.hpp>
      33             : #include <com/sun/star/awt/DeviceInfo.hpp>
      34             : #include <com/sun/star/awt/PosSize.hpp>
      35             : #include <com/sun/star/awt/WindowAttribute.hpp>
      36             : #include <com/sun/star/awt/XTopWindow.hpp>
      37             : #include <com/sun/star/awt/XWindow2.hpp>
      38             : #include <com/sun/star/beans/XPropertySet.hpp>
      39             : #include <com/sun/star/frame/XLayoutManager.hpp>
      40             : 
      41             : #include <toolkit/unohlp.hxx>
      42             : 
      43             : #include <comphelper/sequenceashashmap.hxx>
      44             : #include <comphelper/mediadescriptor.hxx>
      45             : #include <comphelper/configurationhelper.hxx>
      46             : #include <vcl/svapp.hxx>
      47             : #include <osl/mutex.hxx>
      48             : 
      49             : 
      50             : namespace framework{
      51             : 
      52             : 
      53             : sal_Int32 StatusIndicatorFactory::m_nInReschedule = 0;  /// static counter for rescheduling
      54             : const char PROGRESS_RESOURCE[] = "private:resource/progressbar/progressbar";
      55             : 
      56             : //-----------------------------------------------
      57       68620 : DEFINE_XINTERFACE_5(StatusIndicatorFactory                              ,
      58             :                     OWeakObject                                         ,
      59             :                     DIRECT_INTERFACE(css::lang::XTypeProvider          ),
      60             :                     DIRECT_INTERFACE(css::lang::XServiceInfo           ),
      61             :                     DIRECT_INTERFACE(css::lang::XInitialization        ),
      62             :                     DIRECT_INTERFACE(css::task::XStatusIndicatorFactory),
      63             :                     DIRECT_INTERFACE(css::util::XUpdatable             ))
      64             : 
      65           0 : DEFINE_XTYPEPROVIDER_5(StatusIndicatorFactory            ,
      66             :                        css::lang::XTypeProvider          ,
      67             :                        css::lang::XServiceInfo           ,
      68             :                        css::lang::XInitialization        ,
      69             :                        css::task::XStatusIndicatorFactory,
      70             :                        css::util::XUpdatable             )
      71             : 
      72         339 : DEFINE_XSERVICEINFO_MULTISERVICE(StatusIndicatorFactory                   ,
      73             :                                  ::cppu::OWeakObject                      ,
      74             :                                  SERVICENAME_STATUSINDICATORFACTORY       ,
      75             :                                  IMPLEMENTATIONNAME_STATUSINDICATORFACTORY)
      76             : 
      77         240 : DEFINE_INIT_SERVICE(StatusIndicatorFactory,
      78             :                     {
      79             :                         /*Attention
      80             :                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
      81             :                             to create a new instance of this class by our own supported service factory.
      82             :                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
      83             :                         */
      84             :                     }
      85             :                    )
      86             : 
      87             : //-----------------------------------------------
      88         240 : StatusIndicatorFactory::StatusIndicatorFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      89             :     : ThreadHelpBase      (         )
      90             :     , ::cppu::OWeakObject (         )
      91             :     , m_xSMGR             (xSMGR    )
      92             :     , m_pWakeUp           (0        )
      93             :     , m_bAllowReschedule  (sal_False)
      94             :     , m_bAllowParentShow  (sal_False)
      95         240 :     , m_bDisableReschedule(sal_False)
      96             : {
      97         240 : }
      98             : 
      99             : //-----------------------------------------------
     100         189 : StatusIndicatorFactory::~StatusIndicatorFactory()
     101             : {
     102          63 :     impl_stopWakeUpThread();
     103         126 : }
     104             : 
     105             : //-----------------------------------------------
     106         240 : void SAL_CALL StatusIndicatorFactory::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
     107             :     throw(css::uno::Exception       ,
     108             :           css::uno::RuntimeException)
     109             : {
     110         240 :     ::comphelper::SequenceAsHashMap lArgs(lArguments);
     111             : 
     112             :     // SAFE -> ----------------------------------
     113         240 :     WriteGuard aWriteLock(m_aLock);
     114             : 
     115         240 :     m_xFrame             = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_FRAME            , css::uno::Reference< css::frame::XFrame >());
     116         240 :     m_xPluggWindow       = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_WINDOW           , css::uno::Reference< css::awt::XWindow >() );
     117         240 :     m_bAllowParentShow   = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_ALLOWPARENTSHOW  , (sal_Bool)sal_False                        );
     118         240 :     m_bDisableReschedule = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_DISABLERESCHEDULE, (sal_Bool)sal_False                        );
     119             : 
     120         240 :     aWriteLock.unlock();
     121             :     // <- SAFE ----------------------------------
     122             : 
     123         240 :     impl_createProgress();
     124         240 : }
     125             : 
     126             : //-----------------------------------------------
     127         236 : css::uno::Reference< css::task::XStatusIndicator > SAL_CALL StatusIndicatorFactory::createStatusIndicator()
     128             :     throw(css::uno::RuntimeException)
     129             : {
     130         236 :     StatusIndicator* pIndicator = new StatusIndicator(this);
     131         236 :     css::uno::Reference< css::task::XStatusIndicator > xIndicator(static_cast< ::cppu::OWeakObject* >(pIndicator), css::uno::UNO_QUERY_THROW);
     132             : 
     133         236 :     return xIndicator;
     134             : }
     135             : 
     136             : //-----------------------------------------------
     137        3171 : void SAL_CALL StatusIndicatorFactory::update()
     138             :     throw(css::uno::RuntimeException)
     139             : {
     140             :     // SAFE -> ----------------------------------
     141        3171 :     WriteGuard aWriteLock(m_aLock);
     142        3171 :     m_bAllowReschedule = sal_True;
     143        3171 :     aWriteLock.unlock();
     144             :     // <- SAFE ----------------------------------
     145        3171 : }
     146             : 
     147             : //-----------------------------------------------
     148         151 : void StatusIndicatorFactory::start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     149             :                                    const ::rtl::OUString&                                    sText ,
     150             :                                          sal_Int32                                           nRange)
     151             : {
     152             :     // SAFE -> ----------------------------------
     153         151 :     WriteGuard aWriteLock(m_aLock);
     154             : 
     155             :     // create new info structure for this child or move it to the front of our stack
     156         151 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     157         151 :     if (pItem != m_aStack.end())
     158           9 :         m_aStack.erase(pItem);
     159         151 :     IndicatorInfo aInfo(xChild, sText, nRange);
     160         151 :     m_aStack.push_back (aInfo                );
     161             : 
     162         151 :     m_xActiveChild = xChild;
     163         151 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     164             : 
     165         151 :     aWriteLock.unlock();
     166             :     // <- SAFE ----------------------------------
     167             : 
     168         151 :     implts_makeParentVisibleIfAllowed();
     169             : 
     170         151 :     if (xProgress.is())
     171         151 :         xProgress->start(sText, nRange);
     172             : 
     173         151 :     impl_startWakeUpThread();
     174         151 :     impl_reschedule(sal_True);
     175         151 : }
     176             : 
     177             : //-----------------------------------------------
     178          18 : void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
     179             : {
     180             :     // SAFE -> ----------------------------------
     181          18 :     ReadGuard aReadLock(m_aLock);
     182             : 
     183             :     // reset the internal info structure related to this child
     184          18 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     185          18 :     if (pItem != m_aStack.end())
     186             :     {
     187          18 :         pItem->m_nValue = 0;
     188          18 :         pItem->m_sText  = ::rtl::OUString();
     189             :     }
     190             : 
     191          18 :     css::uno::Reference< css::task::XStatusIndicator > xActive   = m_xActiveChild;
     192          18 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     193             : 
     194          18 :     aReadLock.unlock();
     195             :     // <- SAFE ----------------------------------
     196             : 
     197             :     // not the top most child => dont change UI
     198             :     // But dont forget Reschedule!
     199          36 :     if (
     200          18 :         (xChild == xActive) &&
     201          18 :         (xProgress.is()   )
     202             :        )
     203          18 :         xProgress->reset();
     204             : 
     205          18 :     impl_reschedule(sal_True);
     206          18 : }
     207             : 
     208             : //-----------------------------------------------
     209         142 : void StatusIndicatorFactory::end(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
     210             : {
     211             :     // SAFE -> ----------------------------------
     212         142 :     WriteGuard aWriteLock(m_aLock);
     213             : 
     214             :     // remove this child from our stack
     215         142 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     216         142 :     if (pItem != m_aStack.end())
     217         142 :         m_aStack.erase(pItem);
     218             : 
     219             :     // activate next child ... or finish the progress if there is no further one.
     220         142 :     m_xActiveChild.clear();
     221         142 :     ::rtl::OUString                  sText;
     222         142 :     sal_Int32                        nValue = 0;
     223         142 :     IndicatorStack::reverse_iterator pNext  = m_aStack.rbegin();
     224         142 :     if (pNext != m_aStack.rend())
     225             :     {
     226           0 :         m_xActiveChild = pNext->m_xIndicator;
     227           0 :         sText          = pNext->m_sText;
     228           0 :         nValue         = pNext->m_nValue;
     229             :     }
     230             : 
     231         142 :     css::uno::Reference< css::task::XStatusIndicator > xActive   = m_xActiveChild;
     232         142 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     233             : 
     234         142 :     aWriteLock.unlock();
     235             :     // <- SAFE ----------------------------------
     236             : 
     237         142 :     if (xActive.is())
     238             :     {
     239             :         // There is at least one further child indicator.
     240             :         // Actualize our progress, so it shows these values from now.
     241           0 :         if (xProgress.is())
     242             :         {
     243           0 :             xProgress->setText (sText );
     244           0 :             xProgress->setValue(nValue);
     245             :         }
     246             :     }
     247             :     else
     248             :     {
     249             :         // Our stack is empty. No further child exists.
     250             :         // Se we must "end" our progress realy
     251         142 :         if (xProgress.is())
     252         142 :             xProgress->end();
     253             :         // Now hide the progress bar again.
     254         142 :         impl_hideProgress();
     255             : 
     256         142 :         impl_stopWakeUpThread();
     257             :     }
     258             : 
     259         142 :     impl_reschedule(sal_True);
     260         142 : }
     261             : 
     262             : //-----------------------------------------------
     263           0 : void StatusIndicatorFactory::setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     264             :                                      const ::rtl::OUString&                                    sText )
     265             : {
     266             :     // SAFE -> ----------------------------------
     267           0 :     WriteGuard aWriteLock(m_aLock);
     268             : 
     269           0 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     270           0 :     if (pItem != m_aStack.end())
     271           0 :         pItem->m_sText = sText;
     272             : 
     273           0 :     css::uno::Reference< css::task::XStatusIndicator > xActive   = m_xActiveChild;
     274           0 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     275             : 
     276           0 :     aWriteLock.unlock();
     277             :     // SAFE -> ----------------------------------
     278             : 
     279             :     // paint only the top most indicator
     280             :     // but dont forget to Reschedule!
     281           0 :     if (
     282           0 :         (xChild == xActive) &&
     283           0 :         (xProgress.is()   )
     284             :        )
     285             :     {
     286           0 :         xProgress->setText(sText);
     287             :     }
     288             : 
     289           0 :     impl_reschedule(sal_True);
     290           0 : }
     291             : 
     292             : //-----------------------------------------------
     293        5455 : void StatusIndicatorFactory::setValue( const css::uno::Reference< css::task::XStatusIndicator >& xChild ,
     294             :                                              sal_Int32                                           nValue )
     295             : {
     296             :     // SAFE -> ----------------------------------
     297        5455 :     WriteGuard aWriteLock(m_aLock);
     298             : 
     299        5455 :     sal_Int32 nOldValue = 0;
     300        5455 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     301        5455 :     if (pItem != m_aStack.end())
     302             :     {
     303        5455 :         nOldValue       = pItem->m_nValue;
     304        5455 :         pItem->m_nValue = nValue;
     305             :     }
     306             : 
     307        5455 :     css::uno::Reference< css::task::XStatusIndicator > xActive    = m_xActiveChild;
     308        5455 :     css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_xProgress;
     309             : 
     310        5455 :     aWriteLock.unlock();
     311             :     // SAFE -> ----------------------------------
     312             : 
     313       10608 :     if (
     314        5455 :         (xChild    == xActive) &&
     315             :         (nOldValue != nValue ) &&
     316        5153 :         (xProgress.is()      )
     317             :        )
     318             :     {
     319        5153 :         xProgress->setValue(nValue);
     320             :     }
     321             : 
     322        5455 :     impl_reschedule(sal_False);
     323        5455 : }
     324             : 
     325             : //-----------------------------------------------
     326         151 : void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed()
     327             : {
     328             :     // SAFE -> ----------------------------------
     329         151 :     ReadGuard aReadLock(m_aLock);
     330             : 
     331         151 :     if (!m_bAllowParentShow)
     332             :         return;
     333             : 
     334         151 :     css::uno::Reference< css::frame::XFrame > xFrame      (m_xFrame.get()      , css::uno::UNO_QUERY);
     335         151 :     css::uno::Reference< css::awt::XWindow >  xPluggWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     336         151 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xSMGR.get(), css::uno::UNO_QUERY);
     337             : 
     338         151 :     aReadLock.unlock();
     339             :     // <- SAFE ----------------------------------
     340             : 
     341         151 :     css::uno::Reference< css::awt::XWindow > xParentWindow;
     342         151 :     if (xFrame.is())
     343         151 :         xParentWindow = xFrame->getContainerWindow();
     344             :     else
     345           0 :         xParentWindow = xPluggWindow;
     346             : 
     347             :     // dont disturb user in case he put the loading document into the background!
     348             :     // Supress any setVisible() or toFront() call in case the initial show was
     349             :     // already made.
     350         151 :     css::uno::Reference< css::awt::XWindow2 > xVisibleCheck(xParentWindow, css::uno::UNO_QUERY);
     351         151 :     sal_Bool bIsVisible = sal_False;
     352         151 :     if (xVisibleCheck.is())
     353         151 :         bIsVisible = xVisibleCheck->isVisible();
     354             : 
     355         151 :     if (bIsVisible)
     356             :     {
     357           9 :         impl_showProgress();
     358             :         return;
     359             :     }
     360             : 
     361             :     // Check if the layout manager has been set to invisible state. It this case we are also
     362             :     // not allowed to set the frame visible!
     363         142 :     css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     364         142 :     if (xPropSet.is())
     365             :     {
     366         142 :         css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     367         142 :         xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     368         142 :         if (xLayoutManager.is())
     369             :         {
     370         142 :             if ( !xLayoutManager->isVisible() )
     371             :                 return;
     372         142 :         }
     373             :     }
     374             : 
     375             :     // Ok the window should be made visible ... becuase it isnt currently visible.
     376             :     // BUT ..!
     377             :     // We need a Hack for our applications: They get her progress from the frame directly
     378             :     // on saving documents. Because there is no progress set on the MediaDescriptor.
     379             :     // But that's wrong. In case the document was opened hidden, they shouldnt use any progress .-(
     380             :     // They only possible workaround: dont show the parent window here, if the document was opened hidden.
     381         142 :     sal_Bool bHiddenDoc = sal_False;
     382         142 :     if (xFrame.is())
     383             :     {
     384         142 :         css::uno::Reference< css::frame::XController > xController;
     385         142 :         css::uno::Reference< css::frame::XModel >      xModel     ;
     386         142 :         xController = xFrame->getController();
     387         142 :         if (xController.is())
     388           0 :             xModel = xController->getModel();
     389         142 :         if (xModel.is())
     390             :         {
     391           0 :             ::comphelper::MediaDescriptor lDocArgs(xModel->getArgs());
     392             :             bHiddenDoc = lDocArgs.getUnpackedValueOrDefault(
     393           0 :                 ::comphelper::MediaDescriptor::PROP_HIDDEN(),
     394           0 :                 (sal_Bool)sal_False);
     395         142 :         }
     396             :     }
     397             : 
     398         142 :     if (bHiddenDoc)
     399             :         return;
     400             : 
     401             :     // OK: The document was not opened in hidden mode ...
     402             :     // and the window isnt already visible.
     403             :     // Show it and bring it to front.
     404             :     // But before we have to be sure, that our internal used helper progress
     405             :     // is visible too.
     406         142 :     impl_showProgress();
     407             : 
     408         142 :     SolarMutexGuard aSolarGuard;
     409         142 :     Window* pWindow = VCLUnoHelper::GetWindow(xParentWindow);
     410         142 :     if ( pWindow )
     411             :     {
     412         142 :         bool bForceFrontAndFocus(false);
     413             :         ::comphelper::ConfigurationHelper::readDirectKey(
     414             :             comphelper::getComponentContext(xSMGR),
     415             :             ::rtl::OUString("org.openoffice.Office.Common/View"),
     416             :             ::rtl::OUString("NewDocumentHandling"),
     417             :             ::rtl::OUString("ForceFocusAndToFront"),
     418         142 :             ::comphelper::ConfigurationHelper::E_READONLY) >>= bForceFrontAndFocus;
     419             : 
     420         142 :         pWindow->Show(sal_True, bForceFrontAndFocus ? SHOW_FOREGROUNDTASK : 0 );
     421         142 :     }
     422             : 
     423             : }
     424             : 
     425             : //-----------------------------------------------
     426         240 : void StatusIndicatorFactory::impl_createProgress()
     427             : {
     428             :     // SAFE -> ----------------------------------
     429         240 :     ReadGuard aReadLock(m_aLock);
     430             : 
     431         240 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     432         240 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     433         240 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     434             : 
     435         240 :     aReadLock.lock();
     436             :     // <- SAFE ----------------------------------
     437             : 
     438         240 :     css::uno::Reference< css::task::XStatusIndicator > xProgress;
     439             : 
     440         240 :     if (xWindow.is())
     441             :     {
     442             :         // use vcl based progress implementation in plugged mode
     443           0 :         VCLStatusIndicator* pVCLProgress = new VCLStatusIndicator(xSMGR, xWindow);
     444           0 :         xProgress = css::uno::Reference< css::task::XStatusIndicator >(static_cast< css::task::XStatusIndicator* >(pVCLProgress), css::uno::UNO_QUERY);
     445             :     }
     446         240 :     else if (xFrame.is())
     447             :     {
     448             :         // use frame layouted progress implementation
     449         240 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     450         240 :         if (xPropSet.is())
     451             :         {
     452         240 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     453         240 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     454         240 :             if (xLayoutManager.is())
     455             :             {
     456         240 :                 xLayoutManager->lock();
     457         240 :                 rtl::OUString sPROGRESS_RESOURCE(PROGRESS_RESOURCE);
     458         240 :                 xLayoutManager->createElement( sPROGRESS_RESOURCE );
     459         240 :                 xLayoutManager->hideElement( sPROGRESS_RESOURCE );
     460             : 
     461         240 :                 css::uno::Reference< css::ui::XUIElement > xProgressBar = xLayoutManager->getElement(sPROGRESS_RESOURCE);
     462         240 :                 if (xProgressBar.is())
     463         240 :                     xProgress = css::uno::Reference< css::task::XStatusIndicator >(xProgressBar->getRealInterface(), css::uno::UNO_QUERY);
     464         240 :                 xLayoutManager->unlock();
     465         240 :             }
     466         240 :         }
     467             :     }
     468             : 
     469             :     // SAFE -> ----------------------------------
     470         240 :     WriteGuard aWriteLock(m_aLock);
     471         240 :     m_xProgress = xProgress;
     472         240 :     aWriteLock.lock();
     473             :     // <- SAFE ----------------------------------
     474         240 : }
     475             : 
     476             : //-----------------------------------------------
     477         151 : void StatusIndicatorFactory::impl_showProgress()
     478             : {
     479             :     // SAFE -> ----------------------------------
     480         151 :     ReadGuard aReadLock(m_aLock);
     481             : 
     482         151 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     483         151 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     484         151 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     485             : 
     486         151 :     aReadLock.lock();
     487             :     // <- SAFE ----------------------------------
     488             : 
     489         151 :     css::uno::Reference< css::task::XStatusIndicator > xProgress;
     490             : 
     491         151 :     if (xFrame.is())
     492             :     {
     493             :         // use frame layouted progress implementation
     494         151 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     495         151 :         if (xPropSet.is())
     496             :         {
     497         151 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     498         151 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     499         151 :             if (xLayoutManager.is())
     500             :             {
     501             :                 // Be sure that we have always a progress. It can be that our frame
     502             :                 // was recycled and therefore the progress was destroyed!
     503             :                 // CreateElement does nothing if there is already a valid progress.
     504         151 :                 rtl::OUString sPROGRESS_RESOURCE(PROGRESS_RESOURCE);
     505         151 :                 xLayoutManager->createElement( sPROGRESS_RESOURCE );
     506         151 :                 xLayoutManager->showElement( sPROGRESS_RESOURCE );
     507             : 
     508         151 :                 css::uno::Reference< css::ui::XUIElement > xProgressBar = xLayoutManager->getElement(sPROGRESS_RESOURCE);
     509         151 :                 if (xProgressBar.is())
     510         151 :                     xProgress = css::uno::Reference< css::task::XStatusIndicator >(xProgressBar->getRealInterface(), css::uno::UNO_QUERY);
     511         151 :             }
     512             :         }
     513             : 
     514             :         // SAFE -> ----------------------------------
     515         151 :         WriteGuard aWriteLock(m_aLock);
     516         151 :         m_xProgress = xProgress;
     517         151 :         aWriteLock.lock();
     518             :         // <- SAFE ----------------------------------
     519         151 :     }
     520         151 : }
     521             : 
     522             : //-----------------------------------------------
     523         142 : void StatusIndicatorFactory::impl_hideProgress()
     524             : {
     525             :     // SAFE -> ----------------------------------
     526         142 :     ReadGuard aReadLock(m_aLock);
     527             : 
     528         142 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     529         142 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     530         142 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     531             : 
     532         142 :     aReadLock.lock();
     533             :     // <- SAFE ----------------------------------
     534             : 
     535         142 :     if (xFrame.is())
     536             :     {
     537             :         // use frame layouted progress implementation
     538         142 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     539         142 :         if (xPropSet.is())
     540             :         {
     541         142 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     542         142 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     543         142 :             if (xLayoutManager.is())
     544         142 :                 xLayoutManager->hideElement( rtl::OUString(PROGRESS_RESOURCE) );
     545         142 :         }
     546         142 :     }
     547         142 : }
     548             : 
     549             : //-----------------------------------------------
     550        5766 : void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce)
     551             : {
     552             :     // SAFE ->
     553        5766 :     ReadGuard aReadLock(m_aLock);
     554        5766 :     if (m_bDisableReschedule)
     555             :         return;
     556        5766 :     aReadLock.unlock();
     557             :     // <- SAFE
     558             : 
     559        5766 :     sal_Bool bReschedule = bForce;
     560        5766 :     if (!bReschedule)
     561             :     {
     562             :         // SAFE ->
     563        5455 :         WriteGuard aWriteLock(m_aLock);
     564        5455 :         bReschedule        = m_bAllowReschedule;
     565        5455 :         m_bAllowReschedule = sal_False;
     566        5455 :         aWriteLock.unlock();
     567             :         // <- SAFE
     568             :     }
     569             : 
     570        5766 :     if (!bReschedule)
     571             :         return;
     572             : 
     573             :     // SAFE ->
     574         839 :     WriteGuard aGlobalLock(LockHelper::getGlobalLock());
     575             : 
     576         839 :     if (m_nInReschedule == 0)
     577             :     {
     578         839 :         ++m_nInReschedule;
     579         839 :         aGlobalLock.unlock();
     580             :         // <- SAFE
     581             : 
     582         839 :         Application::Reschedule(true);
     583             : 
     584             :         // SAFE ->
     585         839 :         aGlobalLock.lock();
     586         839 :         --m_nInReschedule;
     587         839 :     }
     588             : }
     589             : 
     590             : //-----------------------------------------------
     591         151 : void StatusIndicatorFactory::impl_startWakeUpThread()
     592             : {
     593             :     // SAFE ->
     594         151 :     WriteGuard aWriteLock(m_aLock);
     595             : 
     596         151 :     if (m_bDisableReschedule)
     597         151 :         return;
     598             : 
     599         151 :     if (!m_pWakeUp)
     600             :     {
     601         142 :         m_pWakeUp = new WakeUpThread(this);
     602         142 :         m_pWakeUp->create();
     603             :     }
     604         151 :     aWriteLock.unlock();
     605             :     // <- SAFE
     606             : }
     607             : 
     608             : //-----------------------------------------------
     609         205 : void StatusIndicatorFactory::impl_stopWakeUpThread()
     610             : {
     611             :     // SAFE ->
     612         205 :     WriteGuard aWriteLock(m_aLock);
     613         205 :     if (m_pWakeUp)
     614             :     {
     615             :         // Thread kill itself after terminate()!
     616         142 :         m_pWakeUp->terminate();
     617         142 :         m_pWakeUp = 0;
     618             :     }
     619         205 :     aWriteLock.unlock();
     620             :     // <- SAFE
     621         205 : }
     622             : 
     623             : } // namespace framework
     624             : 
     625             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10