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-17 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      157876 : 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         980 : DEFINE_XSERVICEINFO_MULTISERVICE(StatusIndicatorFactory                   ,
      73             :                                  ::cppu::OWeakObject                      ,
      74             :                                  SERVICENAME_STATUSINDICATORFACTORY       ,
      75             :                                  IMPLEMENTATIONNAME_STATUSINDICATORFACTORY)
      76             : 
      77         516 : 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         516 : 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         516 :     , m_bDisableReschedule(sal_False)
      96             : {
      97         516 : }
      98             : 
      99             : //-----------------------------------------------
     100         294 : StatusIndicatorFactory::~StatusIndicatorFactory()
     101             : {
     102          98 :     impl_stopWakeUpThread();
     103         196 : }
     104             : 
     105             : //-----------------------------------------------
     106         516 : void SAL_CALL StatusIndicatorFactory::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
     107             :     throw(css::uno::Exception       ,
     108             :           css::uno::RuntimeException)
     109             : {
     110         516 :     ::comphelper::SequenceAsHashMap lArgs(lArguments);
     111             : 
     112             :     // SAFE -> ----------------------------------
     113         516 :     WriteGuard aWriteLock(m_aLock);
     114             : 
     115         516 :     m_xFrame             = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_FRAME            , css::uno::Reference< css::frame::XFrame >());
     116         516 :     m_xPluggWindow       = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_WINDOW           , css::uno::Reference< css::awt::XWindow >() );
     117         516 :     m_bAllowParentShow   = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_ALLOWPARENTSHOW  , (sal_Bool)sal_False                        );
     118         516 :     m_bDisableReschedule = lArgs.getUnpackedValueOrDefault(STATUSINDICATORFACTORY_PROPNAME_DISABLERESCHEDULE, (sal_Bool)sal_False                        );
     119             : 
     120         516 :     aWriteLock.unlock();
     121             :     // <- SAFE ----------------------------------
     122             : 
     123         516 :     impl_createProgress();
     124         516 : }
     125             : 
     126             : //-----------------------------------------------
     127         508 : css::uno::Reference< css::task::XStatusIndicator > SAL_CALL StatusIndicatorFactory::createStatusIndicator()
     128             :     throw(css::uno::RuntimeException)
     129             : {
     130         508 :     StatusIndicator* pIndicator = new StatusIndicator(this);
     131         508 :     css::uno::Reference< css::task::XStatusIndicator > xIndicator(static_cast< ::cppu::OWeakObject* >(pIndicator), css::uno::UNO_QUERY_THROW);
     132             : 
     133         508 :     return xIndicator;
     134             : }
     135             : 
     136             : //-----------------------------------------------
     137        8493 : void SAL_CALL StatusIndicatorFactory::update()
     138             :     throw(css::uno::RuntimeException)
     139             : {
     140             :     // SAFE -> ----------------------------------
     141        8493 :     WriteGuard aWriteLock(m_aLock);
     142        8493 :     m_bAllowReschedule = sal_True;
     143        8493 :     aWriteLock.unlock();
     144             :     // <- SAFE ----------------------------------
     145        8493 : }
     146             : 
     147             : //-----------------------------------------------
     148         341 : void StatusIndicatorFactory::start(const css::uno::Reference< css::task::XStatusIndicator >& xChild,
     149             :                                    const ::rtl::OUString&                                    sText ,
     150             :                                          sal_Int32                                           nRange)
     151             : {
     152             :     // SAFE -> ----------------------------------
     153         341 :     WriteGuard aWriteLock(m_aLock);
     154             : 
     155             :     // create new info structure for this child or move it to the front of our stack
     156         341 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     157         341 :     if (pItem != m_aStack.end())
     158          16 :         m_aStack.erase(pItem);
     159         341 :     IndicatorInfo aInfo(xChild, sText, nRange);
     160         341 :     m_aStack.push_back (aInfo                );
     161             : 
     162         341 :     m_xActiveChild = xChild;
     163         341 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     164             : 
     165         341 :     aWriteLock.unlock();
     166             :     // <- SAFE ----------------------------------
     167             : 
     168         341 :     implts_makeParentVisibleIfAllowed();
     169             : 
     170         341 :     if (xProgress.is())
     171         341 :         xProgress->start(sText, nRange);
     172             : 
     173         341 :     impl_startWakeUpThread();
     174         341 :     impl_reschedule(sal_True);
     175         341 : }
     176             : 
     177             : //-----------------------------------------------
     178          61 : void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
     179             : {
     180             :     // SAFE -> ----------------------------------
     181          61 :     ReadGuard aReadLock(m_aLock);
     182             : 
     183             :     // reset the internal info structure related to this child
     184          61 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     185          61 :     if (pItem != m_aStack.end())
     186             :     {
     187          61 :         pItem->m_nValue = 0;
     188          61 :         pItem->m_sText  = ::rtl::OUString();
     189             :     }
     190             : 
     191          61 :     css::uno::Reference< css::task::XStatusIndicator > xActive   = m_xActiveChild;
     192          61 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     193             : 
     194          61 :     aReadLock.unlock();
     195             :     // <- SAFE ----------------------------------
     196             : 
     197             :     // not the top most child => dont change UI
     198             :     // But dont forget Reschedule!
     199         122 :     if (
     200          61 :         (xChild == xActive) &&
     201          61 :         (xProgress.is()   )
     202             :        )
     203          61 :         xProgress->reset();
     204             : 
     205          61 :     impl_reschedule(sal_True);
     206          61 : }
     207             : 
     208             : //-----------------------------------------------
     209         347 : void StatusIndicatorFactory::end(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
     210             : {
     211             :     // SAFE -> ----------------------------------
     212         347 :     WriteGuard aWriteLock(m_aLock);
     213             : 
     214             :     // remove this child from our stack
     215         347 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     216         347 :     if (pItem != m_aStack.end())
     217         325 :         m_aStack.erase(pItem);
     218             : 
     219             :     // activate next child ... or finish the progress if there is no further one.
     220         347 :     m_xActiveChild.clear();
     221         347 :     ::rtl::OUString                  sText;
     222         347 :     sal_Int32                        nValue = 0;
     223         347 :     IndicatorStack::reverse_iterator pNext  = m_aStack.rbegin();
     224         347 :     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         347 :     css::uno::Reference< css::task::XStatusIndicator > xActive   = m_xActiveChild;
     232         347 :     css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
     233             : 
     234         347 :     aWriteLock.unlock();
     235             :     // <- SAFE ----------------------------------
     236             : 
     237         347 :     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         347 :         if (xProgress.is())
     252         347 :             xProgress->end();
     253             :         // Now hide the progress bar again.
     254         347 :         impl_hideProgress();
     255             : 
     256         347 :         impl_stopWakeUpThread();
     257             :     }
     258             : 
     259         347 :     impl_reschedule(sal_True);
     260         347 : }
     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       11435 : void StatusIndicatorFactory::setValue( const css::uno::Reference< css::task::XStatusIndicator >& xChild ,
     294             :                                              sal_Int32                                           nValue )
     295             : {
     296             :     // SAFE -> ----------------------------------
     297       11435 :     WriteGuard aWriteLock(m_aLock);
     298             : 
     299       11435 :     sal_Int32 nOldValue = 0;
     300       11435 :     IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
     301       11435 :     if (pItem != m_aStack.end())
     302             :     {
     303       11435 :         nOldValue       = pItem->m_nValue;
     304       11435 :         pItem->m_nValue = nValue;
     305             :     }
     306             : 
     307       11435 :     css::uno::Reference< css::task::XStatusIndicator > xActive    = m_xActiveChild;
     308       11435 :     css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_xProgress;
     309             : 
     310       11435 :     aWriteLock.unlock();
     311             :     // SAFE -> ----------------------------------
     312             : 
     313       22172 :     if (
     314       11435 :         (xChild    == xActive) &&
     315             :         (nOldValue != nValue ) &&
     316       10737 :         (xProgress.is()      )
     317             :        )
     318             :     {
     319       10737 :         xProgress->setValue(nValue);
     320             :     }
     321             : 
     322       11435 :     impl_reschedule(sal_False);
     323       11435 : }
     324             : 
     325             : //-----------------------------------------------
     326         341 : void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed()
     327             : {
     328             :     // SAFE -> ----------------------------------
     329         341 :     ReadGuard aReadLock(m_aLock);
     330             : 
     331         341 :     if (!m_bAllowParentShow)
     332             :         return;
     333             : 
     334         341 :     css::uno::Reference< css::frame::XFrame > xFrame      (m_xFrame.get()      , css::uno::UNO_QUERY);
     335         341 :     css::uno::Reference< css::awt::XWindow >  xPluggWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     336         341 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xSMGR.get(), css::uno::UNO_QUERY);
     337             : 
     338         341 :     aReadLock.unlock();
     339             :     // <- SAFE ----------------------------------
     340             : 
     341         341 :     css::uno::Reference< css::awt::XWindow > xParentWindow;
     342         341 :     if (xFrame.is())
     343         341 :         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         341 :     css::uno::Reference< css::awt::XWindow2 > xVisibleCheck(xParentWindow, css::uno::UNO_QUERY);
     351         341 :     sal_Bool bIsVisible = sal_False;
     352         341 :     if (xVisibleCheck.is())
     353         341 :         bIsVisible = xVisibleCheck->isVisible();
     354             : 
     355         341 :     if (bIsVisible)
     356             :     {
     357          24 :         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         317 :     css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     364         317 :     if (xPropSet.is())
     365             :     {
     366         317 :         css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     367         317 :         xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     368         317 :         if (xLayoutManager.is())
     369             :         {
     370         317 :             if ( !xLayoutManager->isVisible() )
     371             :                 return;
     372         317 :         }
     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         317 :     sal_Bool bHiddenDoc = sal_False;
     382         317 :     if (xFrame.is())
     383             :     {
     384         317 :         css::uno::Reference< css::frame::XController > xController;
     385         317 :         css::uno::Reference< css::frame::XModel >      xModel     ;
     386         317 :         xController = xFrame->getController();
     387         317 :         if (xController.is())
     388           0 :             xModel = xController->getModel();
     389         317 :         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         317 :         }
     396             :     }
     397             : 
     398         317 :     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         317 :     impl_showProgress();
     407             : 
     408         317 :     SolarMutexGuard aSolarGuard;
     409         317 :     Window* pWindow = VCLUnoHelper::GetWindow(xParentWindow);
     410         317 :     if ( pWindow )
     411             :     {
     412         317 :         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         317 :             ::comphelper::ConfigurationHelper::E_READONLY) >>= bForceFrontAndFocus;
     419             : 
     420         317 :         pWindow->Show(sal_True, bForceFrontAndFocus ? SHOW_FOREGROUNDTASK : 0 );
     421         317 :     }
     422             : 
     423             : }
     424             : 
     425             : //-----------------------------------------------
     426         516 : void StatusIndicatorFactory::impl_createProgress()
     427             : {
     428             :     // SAFE -> ----------------------------------
     429         516 :     ReadGuard aReadLock(m_aLock);
     430             : 
     431         516 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     432         516 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     433         516 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     434             : 
     435         516 :     aReadLock.lock();
     436             :     // <- SAFE ----------------------------------
     437             : 
     438         516 :     css::uno::Reference< css::task::XStatusIndicator > xProgress;
     439             : 
     440         516 :     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         516 :     else if (xFrame.is())
     447             :     {
     448             :         // use frame layouted progress implementation
     449         516 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     450         516 :         if (xPropSet.is())
     451             :         {
     452         516 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     453         516 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     454         516 :             if (xLayoutManager.is())
     455             :             {
     456         516 :                 xLayoutManager->lock();
     457         516 :                 rtl::OUString sPROGRESS_RESOURCE(PROGRESS_RESOURCE);
     458         516 :                 xLayoutManager->createElement( sPROGRESS_RESOURCE );
     459         516 :                 xLayoutManager->hideElement( sPROGRESS_RESOURCE );
     460             : 
     461         516 :                 css::uno::Reference< css::ui::XUIElement > xProgressBar = xLayoutManager->getElement(sPROGRESS_RESOURCE);
     462         516 :                 if (xProgressBar.is())
     463         516 :                     xProgress = css::uno::Reference< css::task::XStatusIndicator >(xProgressBar->getRealInterface(), css::uno::UNO_QUERY);
     464         516 :                 xLayoutManager->unlock();
     465         516 :             }
     466         516 :         }
     467             :     }
     468             : 
     469             :     // SAFE -> ----------------------------------
     470         516 :     WriteGuard aWriteLock(m_aLock);
     471         516 :     m_xProgress = xProgress;
     472         516 :     aWriteLock.lock();
     473             :     // <- SAFE ----------------------------------
     474         516 : }
     475             : 
     476             : //-----------------------------------------------
     477         341 : void StatusIndicatorFactory::impl_showProgress()
     478             : {
     479             :     // SAFE -> ----------------------------------
     480         341 :     ReadGuard aReadLock(m_aLock);
     481             : 
     482         341 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     483         341 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     484         341 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     485             : 
     486         341 :     aReadLock.lock();
     487             :     // <- SAFE ----------------------------------
     488             : 
     489         341 :     css::uno::Reference< css::task::XStatusIndicator > xProgress;
     490             : 
     491         341 :     if (xFrame.is())
     492             :     {
     493             :         // use frame layouted progress implementation
     494         341 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     495         341 :         if (xPropSet.is())
     496             :         {
     497         341 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     498         341 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     499         341 :             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         341 :                 rtl::OUString sPROGRESS_RESOURCE(PROGRESS_RESOURCE);
     505         341 :                 xLayoutManager->createElement( sPROGRESS_RESOURCE );
     506         341 :                 xLayoutManager->showElement( sPROGRESS_RESOURCE );
     507             : 
     508         341 :                 css::uno::Reference< css::ui::XUIElement > xProgressBar = xLayoutManager->getElement(sPROGRESS_RESOURCE);
     509         341 :                 if (xProgressBar.is())
     510         341 :                     xProgress = css::uno::Reference< css::task::XStatusIndicator >(xProgressBar->getRealInterface(), css::uno::UNO_QUERY);
     511         341 :             }
     512             :         }
     513             : 
     514             :         // SAFE -> ----------------------------------
     515         341 :         WriteGuard aWriteLock(m_aLock);
     516         341 :         m_xProgress = xProgress;
     517         341 :         aWriteLock.lock();
     518             :         // <- SAFE ----------------------------------
     519         341 :     }
     520         341 : }
     521             : 
     522             : //-----------------------------------------------
     523         347 : void StatusIndicatorFactory::impl_hideProgress()
     524             : {
     525             :     // SAFE -> ----------------------------------
     526         347 :     ReadGuard aReadLock(m_aLock);
     527             : 
     528         347 :     css::uno::Reference< css::frame::XFrame >              xFrame (m_xFrame.get()      , css::uno::UNO_QUERY);
     529         347 :     css::uno::Reference< css::awt::XWindow >               xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
     530         347 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     531             : 
     532         347 :     aReadLock.lock();
     533             :     // <- SAFE ----------------------------------
     534             : 
     535         347 :     if (xFrame.is())
     536             :     {
     537             :         // use frame layouted progress implementation
     538         347 :         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
     539         347 :         if (xPropSet.is())
     540             :         {
     541         347 :             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
     542         347 :             xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
     543         347 :             if (xLayoutManager.is())
     544         347 :                 xLayoutManager->hideElement( rtl::OUString(PROGRESS_RESOURCE) );
     545         347 :         }
     546         347 :     }
     547         347 : }
     548             : 
     549             : //-----------------------------------------------
     550       12184 : void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce)
     551             : {
     552             :     // SAFE ->
     553       12184 :     ReadGuard aReadLock(m_aLock);
     554       12184 :     if (m_bDisableReschedule)
     555             :         return;
     556       12184 :     aReadLock.unlock();
     557             :     // <- SAFE
     558             : 
     559       12184 :     sal_Bool bReschedule = bForce;
     560       12184 :     if (!bReschedule)
     561             :     {
     562             :         // SAFE ->
     563       11435 :         WriteGuard aWriteLock(m_aLock);
     564       11435 :         bReschedule        = m_bAllowReschedule;
     565       11435 :         m_bAllowReschedule = sal_False;
     566       11435 :         aWriteLock.unlock();
     567             :         // <- SAFE
     568             :     }
     569             : 
     570       12184 :     if (!bReschedule)
     571             :         return;
     572             : 
     573             :     // SAFE ->
     574        1904 :     WriteGuard aGlobalLock(LockHelper::getGlobalLock());
     575             : 
     576        1904 :     if (m_nInReschedule == 0)
     577             :     {
     578        1904 :         ++m_nInReschedule;
     579        1904 :         aGlobalLock.unlock();
     580             :         // <- SAFE
     581             : 
     582        1904 :         Application::Reschedule(true);
     583             : 
     584             :         // SAFE ->
     585        1904 :         aGlobalLock.lock();
     586        1904 :         --m_nInReschedule;
     587        1904 :     }
     588             : }
     589             : 
     590             : //-----------------------------------------------
     591         341 : void StatusIndicatorFactory::impl_startWakeUpThread()
     592             : {
     593             :     // SAFE ->
     594         341 :     WriteGuard aWriteLock(m_aLock);
     595             : 
     596         341 :     if (m_bDisableReschedule)
     597         341 :         return;
     598             : 
     599         341 :     if (!m_pWakeUp)
     600             :     {
     601         325 :         m_pWakeUp = new WakeUpThread(this);
     602         325 :         m_pWakeUp->create();
     603             :     }
     604         341 :     aWriteLock.unlock();
     605             :     // <- SAFE
     606             : }
     607             : 
     608             : //-----------------------------------------------
     609         445 : void StatusIndicatorFactory::impl_stopWakeUpThread()
     610             : {
     611             :     // SAFE ->
     612         445 :     WriteGuard aWriteLock(m_aLock);
     613         445 :     if (m_pWakeUp)
     614             :     {
     615             :         // Thread kill itself after terminate()!
     616         325 :         m_pWakeUp->terminate();
     617         325 :         m_pWakeUp = 0;
     618             :     }
     619         445 :     aWriteLock.unlock();
     620             :     // <- SAFE
     621         445 : }
     622             : 
     623             : } // namespace framework
     624             : 
     625             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10