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

Generated by: LCOV version 1.10